[Info-vax] calloc fails with access violation
VAXman- at SendSpamHere.ORG
VAXman- at SendSpamHere.ORG
Mon Aug 24 16:53:41 EDT 2009
In article <7447c5b2-7ae5-488d-a2a8-099088796bd2 at r42g2000yqj.googlegroups.com>, Jose Cuevas <jcuevas at mac.com> writes:
>On Aug 24, 3:01=A0pm, JF Mezei <jfmezei.spam... at vaxination.ca> wrote:
>> Jose Cuevas wrote:
>> > In the above code I can printf the pointer sIn and do a strlen without
>> > problems,
>>
>> strlen counts bytes until it encounters a null character. It may run
>> fine but return some gigantic number.
>>
>> The COBOL strings passed do not contain a null to indicate end of
>> string. you "strlen" would work only because somewhere in accessible
>> memory of the process, the strlen would encounter a null character.
>>
>> The C program must either be told explicitely (hardcoded or though an
>> argument) the size of a string, or you must pass the COBO strings BY
>> DESCRIPTOR and have the C program expect a descriptor structure at which
>> point it can examine the structure to find the length of the string
>> (allocated length) and the address where it is located.
>
>
>1. Im not a VMS expert but by my interpretation the SHOW PROC shows a
>constant memory usage. Our sys admin thinks the same.
>
>2. As far as the information I have found (not much) Cobol passes
>strings "By Reference" by default. I wrote a few C functions to
>inspect the parameters received by the C code. I found that the string
>length matches the COBOL picture. The pointers received from COBOL are
>NULL terminated strings. Only char/void pointers work as function
>arguments in C.
Pass the data from COBOL to your C routines as descriptors. Your C routine
will receive the accress of a data structure that is, generally speaking, a
word (unsigned short) length, two byte (char) fields that signify the class
and type of data passed and then a pointer (a longword) to the actual data.
calloc (unsigned short) descriptor+dsc$w_length bytes of data and then you
can copy from descriptor+dsc$apointer to the calloced region. You might be
wise to add a few bytes to allow for maintaining a null terminator for the
C routines which then massage your passed data.
COBOL does not, AFAIK, create NULL terminated strings when passing data by
reference. In fact, I have written many Macro32 routines for people using
COBOL and I've not seen a null terminated string. You might see data with
a null but that is NOT guaranteed. John Reagan, compiler droogie, may be
lurking and can better address this.
--
VAXman- A Bored Certified VMS Kernel Mode Hacker VAXman(at)TMESIS(dot)ORG
http://www.quirkfactory.com/popart/asskey/eqn2.png
"Well my son, life is like a beanstalk, isn't it?"
More information about the Info-vax
mailing list