If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Informix > Linux: 4GL calling C function - memory fault

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-26-11, 10:31
nsinha nsinha is offline
Registered User
 
Join Date: Jul 2004
Posts: 12
Linux: 4GL calling C function - memory fault

Hi

I am using IDS 11.50.FC7IE on RHEL 2.6.18.

I have a 4GL function and it calls the C function by

Code:
call c_func(x,y,z)
where x,y & z are the parameters.

But it is giving memory fault (coredump).

If I don't pass the parameters, then the program is working fine. Even in HP unix the program is working fine even with argument passing. Only in RHEL I am facing this issue.

The C function uses popvchar, popint and popquote to get the arguments passed to it. But when I am passing arguments, the program is failing even before call to these functions. So these functions should not be the root cause of the problem. The problem must be lying with argument passing mechanism.

Can you please let me know what can be the root cause of the problem and how to solve it?

Thanks in advance ...

Last edited by nsinha; 04-26-11 at 13:07.
Reply With Quote
  #2 (permalink)  
Old 04-27-11, 19:26
Luis Santos Luis Santos is offline
Registered User
 
Join Date: Jun 2009
Location: Lisboa, Portugal
Posts: 51
What do that function that as to be in C?
__________________
LS
Reply With Quote
  #3 (permalink)  
Old 05-02-11, 02:42
nsinha nsinha is offline
Registered User
 
Join Date: Jul 2004
Posts: 12
Hi

Thanks for paying attention to the problem.

Actually problem was lying in the popvchar function call. The 4GL funtion calls the C function and passes "str" and "len" as arguments. The C function function then calls popvchar(str,len); this will be used to extract the "str" string of "len" legth from the stack.

But here the the "len" variable is not passed correctly as an argument to the popvchar function.

Check here for details -

Help - IBM

Both popquote( ) and popvchar( ) copy exactly len bytes into the string buffer *qv. Here popquote( ) pads with spaces as necessary, but popvchar( ) does not pad to the full length. The final byte copied to the buffer is a null byte to terminate the string, so the maximum string data length is len-1. If the stacked argument is longer than len-1, its trailing bytes are lost and it can't retrieve the argument from the stack and memory fault occurs.

So we have to call the popvchar() by popvchar(str,len-1).

Hope this will help the others facing the similar problem.

Thanks
Reply With Quote
  #4 (permalink)  
Old 05-10-11, 17:13
Luis Santos Luis Santos is offline
Registered User
 
Join Date: Jun 2009
Location: Lisboa, Portugal
Posts: 51
Hi again,

The exemple you´ve you shown and the link for IBM help page is how to call a C function with EGL programing and not with 4GL.
The 4GL reference PDF manual on http://publib.boulder.ibm.com/epubs/pdf/8776.pdf on Appendix C calling "Using C with INFORMX-4GL" it is the similar explication:

extern void popvchar(int1 *qv, mint len)

where as you said you can catch the information and yes... the mint len as to be the all bytes of the string minus one.
However it seams your file is not in binary or is it?
If not, you could all made with 4GL is no need to use C functions.

Hope it was useful.
__________________
LS
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On