s-news
[Top] [All Lists]

Re: C call - memory problem

To: <Agin.Patrick@hydro.qc.ca>, <s-news@lists.biostat.wustl.edu>
Subject: Re: C call - memory problem
From: <david.jessop@ubs.com>
Date: Thu, 25 May 2006 14:56:47 +0100
In-reply-to: <30258329AD9B574EB1BBFF02CFB7E66B8D316C@WPMSXC04.hydroqc.hydro.qc.ca>
Thread-index: AcZ+bMIIh60c+KsoRCSdVLKAvmFhvAA82NVgACFIdBAABl2AIAAA/OkQ
Thread-topic: C call - memory problem
Patrick,
 
Try looking in S_extern.h and S_define.h where in my version (6.2) I find
 
S_define.h(28): #define Salloc(n, t) (t *)S_alloc(n, sizeof(t),S_evaluator)
S_extern.h(66): LibExtern void * S_STDCALL S_alloc(long n, size_t size, s_evaluator *S_evaluator);
If I look in my language reference I find exactly the same as you do.
 
David
 


From: Agin.Patrick@hydro.qc.ca [mailto:Agin.Patrick@hydro.qc.ca]
Sent: 25 May 2006 14:32
To: Jessop, David; s-news@lists.biostat.wustl.edu
Subject: RE: C call - memory problem

Excuse me David, I forgot to mention in my last message one thing. When I say that S_alloc has two arguments, it’s because I found a topic on that function in the help of the S-Plus language reference. In my version 4.5, here is the usage : char *S_alloc(nelem, elsize). I suppose that the 3rd argument came in later versions only. The question remains : how can I plug the arguments if the compiler expects no one?

Patrick

 


From: david.jessop@ubs.com [mailto:david.jessop@ubs.com]
Sent: Thursday, May 25, 2006 6:27 AM
To: Agin, Patrick; s-news@lists.biostat.wustl.edu
Subject: RE: C call - memory problem

 

Patrick,

 

I think you've come up against the famous "not quite accurate documentation" problem.  I'm running with a later version than you, but my version of S needs three parameters, e.g.:

 

 char *pcName = (char *) S_alloc (iMaxNameLen, sizeof (char), S_evaluator);

I only found this by searching through the header files with grep (or your favourite text search routine) for the prototype.

 

Hope this helps, 

 

David

 

 


From: Agin.Patrick@hydro.qc.ca [mailto:Agin.Patrick@hydro.qc.ca]
Sent: 24 May 2006 20:04
To: s-news@lists.biostat.wustl.edu
Subject: C call - memory problem

Dear all,

 

I built a DLL (under VC++) and loaded it in S-Plus (version 4.5, Windows XP) with dll.load(). When I do the call to my C function, S-Plus crashes and the following message appears:

 

SPLUS.EXE – Application Error

The instruction at {xxx}

 referenced memory at {yyy}. The memory could not be “read”.

 

The crash occurs between the end of the C function and the return to S-Plus. I suspect problems with the malloc/free calls so I wanted to replace them with S_alloc calls only but the compiler does not like it: “S_alloc function does not take 2 arguments” yet I included the header <S.h> as mentionned in the Programmer’s Guide. What am I doing wrong? Is the problem elsewhere? What could it be? I must admit that after reading topics in the S-news about C calls from S-Plus, I’m quite confused because some elements seem to apply only to more recent versions of my “good-old” S-Plus 4.5.

 

Any hints would be very appreciated.

Patrick

 

 

 

 

Visit our website at http://www.ubs.com

This message contains confidential information and is intended only 
for the individual named.  If you are not the named addressee you 
should not disseminate, distribute or copy this e-mail.  Please 
notify the sender immediately by e-mail if you have received this 
e-mail by mistake and delete this e-mail from your system.

E-mail transmission cannot be guaranteed to be secure or error-free 
as information could be intercepted, corrupted, lost, destroyed, 
arrive late or incomplete, or contain viruses.  The sender therefore 
does not accept liability for any errors or omissions in the contents 
of this message which arise as a result of e-mail transmission.  If 
verification is required please request a hard-copy version.  This 
message is provided for informational purposes and should not be 
construed as a solicitation or offer to buy or sell any securities or 
related financial instruments.
<Prev in Thread] Current Thread [Next in Thread>