Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2004
    Posts
    13

    Unanswered: 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 14:07.

  2. #2
    Join Date
    Jun 2009
    Location
    Lisboa, Portugal
    Posts
    78
    What do that function that as to be in C?
    LS

  3. #3
    Join Date
    Jul 2004
    Posts
    13
    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

  4. #4
    Join Date
    Jun 2009
    Location
    Lisboa, Portugal
    Posts
    78
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •