• Transmit Parameters to C-Program

    From Jens@21:1/5 to All on Mon Jun 14 02:19:20 2021
    Hi,
    I'm experimenting with calls from M to C but my C-experience is very small.

    I've done this:
    S VAR1="BCB",VAR2="DEF"
    D &test.hello(VAR1,VAR2)

    test.xc:
    /home/aut/test.so
    hello: ydb_status_t hello(I:ydb_string_t* ,I:ydb_string_t* )

    test.c:
    #include <stdio.h>
    #include "libyottadb.h"

    int hello(int argc, ydb_string_t stringA, ydb_string_t stringB)
    {
    printf("\nHello\n");
    printf("\n");
    printf("%s%d", "\nLength 1 ", stringA.length);
    printf("%s%d", "\nLength 2 ", stringB.length);
    printf("%s%d", "\nArguments ", argc);
    printf("%s%s", "\nText 1 ", stringA.address);
    printf("%s%s", "\nText 2 ", stringB.address);
    return 0;
    }

    Result:

    Hello


    Length 1 2073116
    Length 2 3
    Arguments 2
    Text 1
    Text 2 BCBDEF

    Why is the first length incorrect and the first text not shown?
    Can anyone help?
    Does anyone have an example with parameter transfer from an to M?
    Jens

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Sam Habiel@21:1/5 to Jens on Mon Jun 14 06:52:19 2021
    On Monday, June 14, 2021 at 3:19:21 AM UTC-6, Jens wrote:
    Hi,
    I'm experimenting with calls from M to C but my C-experience is very small.

    I've done this:
    S VAR1="BCB",VAR2="DEF"
    D &test.hello(VAR1,VAR2)

    test.xc:
    /home/aut/test.so
    hello: ydb_status_t hello(I:ydb_string_t* ,I:ydb_string_t* )

    test.c:
    #include <stdio.h>
    #include "libyottadb.h"

    int hello(int argc, ydb_string_t stringA, ydb_string_t stringB)
    {
    printf("\nHello\n");
    printf("\n");
    printf("%s%d", "\nLength 1 ", stringA.length);
    printf("%s%d", "\nLength 2 ", stringB.length);
    printf("%s%d", "\nArguments ", argc);
    printf("%s%s", "\nText 1 ", stringA.address);
    printf("%s%s", "\nText 2 ", stringB.address);
    return 0;
    }

    Result:

    Hello


    Length 1 2073116
    Length 2 3
    Arguments 2
    Text 1
    Text 2 BCBDEF

    Why is the first length incorrect and the first text not shown?
    Can anyone help?
    Does anyone have an example with parameter transfer from an to M?
    Jens

    Let's start with that your C parameters need to be pointers, but are not. You don't have * in the type name.

    Some examples of call-outs:
    https://gitlab.com/YottaDB/Util/YDBPosix https://gitlab.com/YottaDB/Util/YDBZlib

    Documentation here: https://docs.yottadb.com/ProgrammersGuide/extrout.html

    The Call-out documentation I would admit is not satisfactory. Let me know how it can be improved.

    --Sam

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jens@21:1/5 to All on Tue Jun 15 00:24:10 2021
    Sam, Thank you for your hints. The zlib-example helped me much. If there was a link to this C-code in the documentation it would be a help for others too I guess.

    Jens

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From K.S. Bhaskar@21:1/5 to Jens on Wed Jun 16 12:02:56 2021
    On Tuesday, June 15, 2021 at 3:24:11 AM UTC-4, Jens wrote:
    Sam, Thank you for your hints. The zlib-example helped me much. If there was a link to this C-code in the documentation it would be a help for others too I guess.

    Jens

    Thank you for the suggestion to improve the documentation, Jens. https://gitlab.com/YottaDB/DB/YDBDoc/-/issues/243 has been created to track the suggestion.

    Regards
    – Bhaskar

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jens@21:1/5 to All on Fri Jun 18 05:25:01 2021
    One extended question to this topic:
    If I call the C-subroutine like this:

    D &test.hello(VAR1,.VAR2)

    int hello(int argc, ydb_string_t stringA, ydb_string_t stringB)

    Is it possible to send back an array to VAR2?

    I know about ydb_set_s(), but the C-program doesn't know the name "VAR2" to add nodes to it.

    Jens

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From K.S. Bhaskar@21:1/5 to Jens on Fri Jun 18 06:54:36 2021
    On Friday, June 18, 2021 at 8:25:03 AM UTC-4, Jens wrote:
    One extended question to this topic:
    If I call the C-subroutine like this:

    D &test.hello(VAR1,.VAR2)
    int hello(int argc, ydb_string_t stringA, ydb_string_t stringB)
    Is it possible to send back an array to VAR2?

    I know about ydb_set_s(), but the C-program doesn't know the name "VAR2" to add nodes to it.

    Jens

    Jens, can you pass the name of the variable in VAR2? By receiving the variable name in stringB, the C code can then populate the variable.

    Regards
    – Bhaskar

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Sam Habiel@21:1/5 to Jens on Fri Jun 18 07:49:12 2021
    On Friday, June 18, 2021 at 6:25:03 AM UTC-6, Jens wrote:
    One extended question to this topic:
    If I call the C-subroutine like this:

    D &test.hello(VAR1,.VAR2)
    int hello(int argc, ydb_string_t stringA, ydb_string_t stringB)
    Is it possible to send back an array to VAR2?

    I know about ydb_set_s(), but the C-program doesn't know the name "VAR2" to add nodes to it.

    Jens
    Jens,

    I don't think that's possible. Back when I wrote this: https://github.com/shabiel/fis-gtm-plugins/blob/master/libcurl/libcurl_ydb_wrapper.c, I wish I could do that for GT.M code, but I couldn't; and I ran up against the limit for strings.

    If you can't provide a delimited output that can be parsed back by M into an array, you will have to use ydb_set_s. It is somewhat difficult to use. You can send out the variable you would like to set in stringB, and use it.

    I wrote this recently for my job: https://gitlab.com/shabiel/YDBAIM/-/blob/ydbaim-c-api/ydbaim.c#L109

    You can read there exactly how to do what you want.

    --Sam

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jens@21:1/5 to Sam Habiel on Fri Jun 18 09:24:17 2021
    Sam Habiel schrieb am Freitag, 18. Juni 2021 um 16:49:14 UTC+2:
    On Friday, June 18, 2021 at 6:25:03 AM UTC-6, Jens wrote:
    One extended question to this topic:
    If I call the C-subroutine like this:

    D &test.hello(VAR1,.VAR2)
    int hello(int argc, ydb_string_t stringA, ydb_string_t stringB)
    Is it possible to send back an array to VAR2?

    I know about ydb_set_s(), but the C-program doesn't know the name "VAR2" to add nodes to it.

    Jens
    Jens,

    I don't think that's possible. Back when I wrote this: https://github.com/shabiel/fis-gtm-plugins/blob/master/libcurl/libcurl_ydb_wrapper.c, I wish I could do that for GT.M code, but I couldn't; and I ran up against the limit for strings.

    If you can't provide a delimited output that can be parsed back by M into an array, you will have to use ydb_set_s. It is somewhat difficult to use. You can send out the variable you would like to set in stringB, and use it.

    I wrote this recently for my job: https://gitlab.com/shabiel/YDBAIM/-/blob/ydbaim-c-api/ydbaim.c#L109

    You can read there exactly how to do what you want.

    --Sam

    Hi Bhaskar, hi Sam,

    thank you for your quick replies. I was thinking about transferring the variable-name as string too, but it 'felt wrong'.
    I'll try it this way now.

    Have a nice weekend!

    Jens

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)