Pass a const struct argument to a C function

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Pass a const struct argument to a C function

GLASS mailing list
Implementing some FFI i reached the following situation:

1) int ssh_pki_import_pubkey_file     (const char * filename, ssh_key * pkey) | in GS #( #'const char*' #'ptr')
This functions populate a ssh_key struct (a GS CPointer instance) and is working ok.

Now i want to call the following function:
2) int ssh_userauth_try_publickey (ssh_session session, const char * username, const ssh_key pubkey) | in GS #( #'ptr' #'const char*' #'ptr' )

The ssh_key struct is the same but with const instead of a *.

If the result of 1) (aCPointer) is passed as received from FFI to function 2) --> function 2) fail.
In this case at GS level the struct is #'ptr'.

Then i tried to modify the FFI call with #'&ptr' to get the value of the pointer (so i can match const ssh_key) but it also fail.

How i should update a CPointer of 1)  instance to match const ssh_key of 2) ? (where ssh_key is a struct)

regards,
bruno

_______________________________________________
Glass mailing list
[hidden email]
https://lists.gemtalksystems.com/mailman/listinfo/glass
Reply | Threaded
Open this post in threaded view
|

Re: Pass a const struct argument to a C function

GLASS mailing list

Hi,


I think this problem has been fixed (more tests needed) but it seems that #'&ptr' must be defined in function 1) rather than function 2).

After more testing i will confirm if it has been fixed.


regards,
bruno



De: "smalltalk--- via Glass" <[hidden email]>
Para: [hidden email]
Enviados: Lunes, 27 de Julio 2020 14:29:35
Asunto: [Glass] Pass a const struct argument to a C function

Implementing some FFI i reached the following situation:

1) int ssh_pki_import_pubkey_file     (const char * filename, ssh_key * pkey) | in GS #( #'const char*' #'ptr')
This functions populate a ssh_key struct (a GS CPointer instance) and is working ok.

Now i want to call the following function:
2) int ssh_userauth_try_publickey (ssh_session session, const char * username, const ssh_key pubkey) | in GS #( #'ptr' #'const char*' #'ptr' )

The ssh_key struct is the same but with const instead of a *.

If the result of 1) (aCPointer) is passed as received from FFI to function 2) --> function 2) fail.
In this case at GS level the struct is #'ptr'.

Then i tried to modify the FFI call with #'&ptr' to get the value of the pointer (so i can match const ssh_key) but it also fail.

How i should update a CPointer of 1)  instance to match const ssh_key of 2) ? (where ssh_key is a struct)

regards,
bruno

_______________________________________________
Glass mailing list
[hidden email]
https://lists.gemtalksystems.com/mailman/listinfo/glass


_______________________________________________
Glass mailing list
[hidden email]
https://lists.gemtalksystems.com/mailman/listinfo/glass