s-news
[Top] [All Lists]

Re: C call - memory problem

To: <david.jessop@ubs.com>, <s-news@lists.biostat.wustl.edu>
Subject: Re: C call - memory problem
From: <Agin.Patrick@hydro.qc.ca>
Date: Thu, 25 May 2006 09:31:51 -0400
Thread-index: AcZ+bMIIh60c+KsoRCSdVLKAvmFhvAA82NVgACFIdBAABl2AIA==
Thread-topic: 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

 

 

 

 

<Prev in Thread] Current Thread [Next in Thread>