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 10:41:56 -0400
Thread-index: AcZ+bMIIh60c+KsoRCSdVLKAvmFhvAA82NVgACFIdBAABl2AIAAA/OkQAAB+GLA=
Thread-topic: C call - memory problem

Sorry Dave... but I have no such files under my C:\Program Files\splus45\include directory. When I grep for S_alloc, only one result is found and it is the one I mentionned in my last email (file S.h).  By the way, I found something on the net (June 1998) that seems to be related to my problem. It is a message from Oliver Klinger (klinger@lkn.e-technik.tu-muenchen.de) named “[S] Corrupt C/C++ Macros???”. I put the contents of this message below, maybe it will remind to someone an answer that was posted at that time.

Patrick

**************************************************

 

When programming under MS Visual C++ 5.0 it's impossible to access any
of the Macros defined in <S.h>
Up to now I encountered problems with the follwoing macros (I'm sure
there are some more problems to follow, if I tried other mcros):
S_alloc(),
Calloc(),
PRINT_IT(),
MESSAGE(),
WARNING(), and
RECOVER().

The compiler alwas ends with the error: "Too many arguments in function
xxx"

My include-section looks as follows:

# if defined DLL_LOAD
# include <windows.h>
BOOL __stdcall
DllMain (HINSTANCE hDllInstance, DWORD dwReason, LPVOID lpReserved) {
switch (dwReason) {
case DLL_PROCESS_ATTACH:
break;
case DLL_PROCESS_DETACH:
break;
}
return(TRUE);
}
#endif
# include <S.h>
# include <newredef.h>
# include <math.h>
# include <string.h>
# include <stdlib.h>

 

 


From: david.jessop@ubs.com [mailto:david.jessop@ubs.com]
Sent: Thursday, May 25, 2006 9:57 AM
To: Agin, Patrick; s-news@lists.biostat.wustl.edu
Subject: RE: 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

 

 

 

 

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