Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Transmit Parameters to C-Program

89 views
Skip to first unread message

Jens

unread,
Jun 14, 2021, 5:19:21 AM6/14/21
to
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

Sam Habiel

unread,
Jun 14, 2021, 9:52:20 AM6/14/21
to
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

Jens

unread,
Jun 15, 2021, 3:24:11 AM6/15/21
to
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


K.S. Bhaskar

unread,
Jun 16, 2021, 3:02:57 PM6/16/21
to
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

Jens

unread,
Jun 18, 2021, 8:25:03 AM6/18/21
to
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

K.S. Bhaskar

unread,
Jun 18, 2021, 9:54:37 AM6/18/21
to
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

Sam Habiel

unread,
Jun 18, 2021, 10:49:14 AM6/18/21
to
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

Jens

unread,
Jun 18, 2021, 12:24:18 PM6/18/21
to
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

0 new messages