Passing a enum element to a C library

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

Passing a enum element to a C library

GLASS mailing list
Hi,

How to pass an enum element to a C library.
C function signature:
int ssh_options_set(ssh_session session, enum ssh_options_e type, const
void *value)

The enum is defined as:
enum ssh_options_e {
   SSH_OPTIONS_HOST,
   SSH_OPTIONS_PORT}

An any C call is like:
ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, "localhost");

GS generated wrapper:
ssh_options_set_: session _: type _: value
     "Interpreted as #int32 from #( #'ptr' #'ptr' #'ptr' )"
     ^Functionssh_options_set callWith: { session. type. value }

In GS i tried something like:
myLibrary ssh_options_set_: session _: optionHost _: hostName
where
session: is created in another successful call to myLibrary

optionHost:
cStructPointer := CByteArray gcMalloc: 8.
cStructPointer uint64At: 0 put: 0. "0 correspond to SSH_OPTIONS_HOST -
maybe i'm wrong"

hostName: CByteArray withAll: 'localhost'

But it seems that something is wrong. The chapter 18 do something like
this with another library.
So [optionHost] or [hostName] has a wrong value...
For now no successful call passing an enum element.

Now back to fight with C :)

regards,
bruno

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

Re: Passing a enum element to a C library

GLASS mailing list
It seems to me that the function should be interpreted as (#’ptr’ #’int’ #’ptr’) since an enum is simply an integer. Try passing it just 0 and see if that goes through.

James

> On Jul 1, 2020, at 4:41 PM, bruno buzzi brassesco via Glass <[hidden email]> wrote:
>
> Hi,
>
> How to pass an enum element to a C library.
> C function signature:
> int ssh_options_set(ssh_session session, enum ssh_options_e type, const void *value)
>
> The enum is defined as:
> enum ssh_options_e {
>  SSH_OPTIONS_HOST,
>  SSH_OPTIONS_PORT}
>
> An any C call is like:
> ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, "localhost");
>
> GS generated wrapper:
> ssh_options_set_: session _: type _: value
>    "Interpreted as #int32 from #( #'ptr' #'ptr' #'ptr' )"
>    ^Functionssh_options_set callWith: { session. type. value }
>
> In GS i tried something like:
> myLibrary ssh_options_set_: session _: optionHost _: hostName
> where
> session: is created in another successful call to myLibrary
>
> optionHost:
> cStructPointer := CByteArray gcMalloc: 8.
> cStructPointer uint64At: 0 put: 0. "0 correspond to SSH_OPTIONS_HOST - maybe i'm wrong"
>
> hostName: CByteArray withAll: 'localhost'
>
> But it seems that something is wrong. The chapter 18 do something like this with another library.
> So [optionHost] or [hostName] has a wrong value...
> For now no successful call passing an enum element.
>
> Now back to fight with C :)
>
> 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
Reply | Threaded
Open this post in threaded view
|

Re: Passing a enum element to a C library

GLASS mailing list
In reply to this post by GLASS mailing list
James,
I already tried that but the "function call" answer an argument type
mismatch:
a ArgumentError occurred (error 2718), arg 2 is neither nil, a CPointer
nor a CByteArray

ArgumentError (AbstractException) >> _signalWith: @5 line 25
ArgumentError (AbstractException) >> signal: @3 line 7
ArgumentError class (AbstractException class) >> signal: @3 line 4
CCallout >> callWith: @3 line 28
GS_libssh_4_8_5 >> ssh_options_set_:_:_: @2 line 7
Libssh485 >> basicSetHostName: @5 line 7
Libssh485Test >> testBasicSetHostName @2 line 3

regards,
bruno

On 1/7/2020 20:52, James Foster wrote:

> It seems to me that the function should be interpreted as (#’ptr’ #’int’ #’ptr’) since an enum is simply an integer. Try passing it just 0 and see if that goes through.
>
> James
>
>> On Jul 1, 2020, at 4:41 PM, bruno buzzi brassesco via Glass <[hidden email]> wrote:
>>
>> Hi,
>>
>> How to pass an enum element to a C library.
>> C function signature:
>> int ssh_options_set(ssh_session session, enum ssh_options_e type, const void *value)
>>
>> The enum is defined as:
>> enum ssh_options_e {
>>    SSH_OPTIONS_HOST,
>>    SSH_OPTIONS_PORT}
>>
>> An any C call is like:
>> ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, "localhost");
>>
>> GS generated wrapper:
>> ssh_options_set_: session _: type _: value
>>      "Interpreted as #int32 from #( #'ptr' #'ptr' #'ptr' )"
>>      ^Functionssh_options_set callWith: { session. type. value }
>>
>> In GS i tried something like:
>> myLibrary ssh_options_set_: session _: optionHost _: hostName
>> where
>> session: is created in another successful call to myLibrary
>>
>> optionHost:
>> cStructPointer := CByteArray gcMalloc: 8.
>> cStructPointer uint64At: 0 put: 0. "0 correspond to SSH_OPTIONS_HOST - maybe i'm wrong"
>>
>> hostName: CByteArray withAll: 'localhost'
>>
>> But it seems that something is wrong. The chapter 18 do something like this with another library.
>> So [optionHost] or [hostName] has a wrong value...
>> For now no successful call passing an enum element.
>>
>> Now back to fight with C :)
>>
>> 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
Reply | Threaded
Open this post in threaded view
|

Re: Passing a enum element to a C library

GLASS mailing list
In reply to this post by GLASS mailing list
James,
Tomorrow i will change #'ptr' for #'int' or #'int32' and see the results...
In my previous response i did not realize the proposed change :)

regards,
bruno

On 1/7/2020 21:27, [hidden email] wrote:

> It seems to me that the function should be interpreted as (#’ptr’ #’int’ #’ptr’) since an enum is simply an integer. Try passing it just 0 and see if that goes through.
>
> James
>
>> On Jul 1, 2020, at 4:41 PM, bruno buzzi brassesco via Glass <[hidden email]> wrote:
>>
>> Hi,
>>
>> How to pass an enum element to a C library.
>> C function signature:
>> int ssh_options_set(ssh_session session, enum ssh_options_e type, const void *value)
>>
>> The enum is defined as:
>> enum ssh_options_e {
>>   SSH_OPTIONS_HOST,
>>   SSH_OPTIONS_PORT}
>>
>> An any C call is like:
>> ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, "localhost");
>>
>> GS generated wrapper:
>> ssh_options_set_: session _: type _: value
>>     "Interpreted as #int32 from #( #'ptr' #'ptr' #'ptr' )"
>>     ^Functionssh_options_set callWith: { session. type. value }
>>
>> In GS i tried something like:
>> myLibrary ssh_options_set_: session _: optionHost _: hostName
>> where
>> session: is created in another successful call to myLibrary
>>
>> optionHost:
>> cStructPointer := CByteArray gcMalloc: 8.
>> cStructPointer uint64At: 0 put: 0. "0 correspond to SSH_OPTIONS_HOST - maybe i'm wrong"
>>
>> hostName: CByteArray withAll: 'localhost'
>>
>> But it seems that something is wrong. The chapter 18 do something like this with another library.
>> So [optionHost] or [hostName] has a wrong value...
>> For now no successful call passing an enum element.
>>
>> Now back to fight with C :)
>>
>> 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
Reply | Threaded
Open this post in threaded view
|

Re: Passing a enum element to a C library

GLASS mailing list
In reply to this post by GLASS mailing list
James,

After replacing #'prt' with #'uint32' and initializing the wrapper the C
call work as expected :)
Excellent !
regards,
bruno

On 1/7/2020 21:27, [hidden email] wrote:

> It seems to me that the function should be interpreted as (#’ptr’ #’int’ #’ptr’) since an enum is simply an integer. Try passing it just 0 and see if that goes through.
>
> James
>
>> On Jul 1, 2020, at 4:41 PM, bruno buzzi brassesco via Glass <[hidden email]> wrote:
>>
>> Hi,
>>
>> How to pass an enum element to a C library.
>> C function signature:
>> int ssh_options_set(ssh_session session, enum ssh_options_e type, const void *value)
>>
>> The enum is defined as:
>> enum ssh_options_e {
>>   SSH_OPTIONS_HOST,
>>   SSH_OPTIONS_PORT}
>>
>> An any C call is like:
>> ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, "localhost");
>>
>> GS generated wrapper:
>> ssh_options_set_: session _: type _: value
>>     "Interpreted as #int32 from #( #'ptr' #'ptr' #'ptr' )"
>>     ^Functionssh_options_set callWith: { session. type. value }
>>
>> In GS i tried something like:
>> myLibrary ssh_options_set_: session _: optionHost _: hostName
>> where
>> session: is created in another successful call to myLibrary
>>
>> optionHost:
>> cStructPointer := CByteArray gcMalloc: 8.
>> cStructPointer uint64At: 0 put: 0. "0 correspond to SSH_OPTIONS_HOST - maybe i'm wrong"
>>
>> hostName: CByteArray withAll: 'localhost'
>>
>> But it seems that something is wrong. The chapter 18 do something like this with another library.
>> So [optionHost] or [hostName] has a wrong value...
>> For now no successful call passing an enum element.
>>
>> Now back to fight with C :)
>>
>> 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
Reply | Threaded
Open this post in threaded view
|

Re: Passing a enum element to a C library

GLASS mailing list
Bruno,

I’m glad you got it working. And you properly interpreted my first suggestion (which didn’t work). I was going to investigate a bit more before making any further suggestions, but you anticipated where I was going. I’ll look further into the problem but I’m glad you have a work-around.

James

> On Jul 1, 2020, at 6:51 PM, bruno buzzi brassesco <[hidden email]> wrote:
>
> James,
>
> After replacing #'prt' with #'uint32' and initializing the wrapper the C call work as expected :)
> Excellent !
> regards,
> bruno
>
> On 1/7/2020 21:27, [hidden email] wrote:
>> It seems to me that the function should be interpreted as (#’ptr’ #’int’ #’ptr’) since an enum is simply an integer. Try passing it just 0 and see if that goes through.
>>
>> James
>>
>>> On Jul 1, 2020, at 4:41 PM, bruno buzzi brassesco via Glass <[hidden email]> wrote:
>>>
>>> Hi,
>>>
>>> How to pass an enum element to a C library.
>>> C function signature:
>>> int ssh_options_set(ssh_session session, enum ssh_options_e type, const void *value)
>>>
>>> The enum is defined as:
>>> enum ssh_options_e {
>>>  SSH_OPTIONS_HOST,
>>>  SSH_OPTIONS_PORT}
>>>
>>> An any C call is like:
>>> ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, "localhost");
>>>
>>> GS generated wrapper:
>>> ssh_options_set_: session _: type _: value
>>>    "Interpreted as #int32 from #( #'ptr' #'ptr' #'ptr' )"
>>>    ^Functionssh_options_set callWith: { session. type. value }
>>>
>>> In GS i tried something like:
>>> myLibrary ssh_options_set_: session _: optionHost _: hostName
>>> where
>>> session: is created in another successful call to myLibrary
>>>
>>> optionHost:
>>> cStructPointer := CByteArray gcMalloc: 8.
>>> cStructPointer uint64At: 0 put: 0. "0 correspond to SSH_OPTIONS_HOST - maybe i'm wrong"
>>>
>>> hostName: CByteArray withAll: 'localhost'
>>>
>>> But it seems that something is wrong. The chapter 18 do something like this with another library.
>>> So [optionHost] or [hostName] has a wrong value...
>>> For now no successful call passing an enum element.
>>>
>>> Now back to fight with C :)
>>>
>>> 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
Reply | Threaded
Open this post in threaded view
|

Re: Passing a enum element to a C library

GLASS mailing list
James,
Should be this reported as a bug ? Or at least a warning in
documentation at chapter 18 (FFI) ?

regards,
bruno

On 1/7/2020 23:00, [hidden email] wrote:

> Bruno,
>
> I’m glad you got it working. And you properly interpreted my first suggestion (which didn’t work). I was going to investigate a bit more before making any further suggestions, but you anticipated where I was going. I’ll look further into the problem but I’m glad you have a work-around.
>
> James
>
>> On Jul 1, 2020, at 6:51 PM, bruno buzzi brassesco <[hidden email]> wrote:
>>
>> James,
>>
>> After replacing #'prt' with #'uint32' and initializing the wrapper the C call work as expected :)
>> Excellent !
>> regards,
>> bruno
>>
>> On 1/7/2020 21:27, [hidden email] wrote:
>>> It seems to me that the function should be interpreted as (#’ptr’ #’int’ #’ptr’) since an enum is simply an integer. Try passing it just 0 and see if that goes through.
>>>
>>> James
>>>
>>>> On Jul 1, 2020, at 4:41 PM, bruno buzzi brassesco via Glass <[hidden email]> wrote:
>>>>
>>>> Hi,
>>>>
>>>> How to pass an enum element to a C library.
>>>> C function signature:
>>>> int ssh_options_set(ssh_session session, enum ssh_options_e type, const void *value)
>>>>
>>>> The enum is defined as:
>>>> enum ssh_options_e {
>>>>   SSH_OPTIONS_HOST,
>>>>   SSH_OPTIONS_PORT}
>>>>
>>>> An any C call is like:
>>>> ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, "localhost");
>>>>
>>>> GS generated wrapper:
>>>> ssh_options_set_: session _: type _: value
>>>>     "Interpreted as #int32 from #( #'ptr' #'ptr' #'ptr' )"
>>>>     ^Functionssh_options_set callWith: { session. type. value }
>>>>
>>>> In GS i tried something like:
>>>> myLibrary ssh_options_set_: session _: optionHost _: hostName
>>>> where
>>>> session: is created in another successful call to myLibrary
>>>>
>>>> optionHost:
>>>> cStructPointer := CByteArray gcMalloc: 8.
>>>> cStructPointer uint64At: 0 put: 0. "0 correspond to SSH_OPTIONS_HOST - maybe i'm wrong"
>>>>
>>>> hostName: CByteArray withAll: 'localhost'
>>>>
>>>> But it seems that something is wrong. The chapter 18 do something like this with another library.
>>>> So [optionHost] or [hostName] has a wrong value...
>>>> For now no successful call passing an enum element.
>>>>
>>>> Now back to fight with C :)
>>>>
>>>> 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
Reply | Threaded
Open this post in threaded view
|

Re: Passing a enum element to a C library

GLASS mailing list
Bruno,

I’ve entered #48867 to track this internally.

James

> On Jul 2, 2020, at 4:03 AM, bruno buzzi brassesco <[hidden email]> wrote:
>
> James,
> Should be this reported as a bug ? Or at least a warning in documentation at chapter 18 (FFI) ?
>
> regards,
> bruno
>
> On 1/7/2020 23:00, [hidden email] wrote:
>> Bruno,
>>
>> I’m glad you got it working. And you properly interpreted my first suggestion (which didn’t work). I was going to investigate a bit more before making any further suggestions, but you anticipated where I was going. I’ll look further into the problem but I’m glad you have a work-around.
>>
>> James
>>
>>> On Jul 1, 2020, at 6:51 PM, bruno buzzi brassesco <[hidden email]> wrote:
>>>
>>> James,
>>>
>>> After replacing #'prt' with #'uint32' and initializing the wrapper the C call work as expected :)
>>> Excellent !
>>> regards,
>>> bruno
>>>
>>> On 1/7/2020 21:27, [hidden email] wrote:
>>>> It seems to me that the function should be interpreted as (#’ptr’ #’int’ #’ptr’) since an enum is simply an integer. Try passing it just 0 and see if that goes through.
>>>>
>>>> James
>>>>
>>>>> On Jul 1, 2020, at 4:41 PM, bruno buzzi brassesco via Glass <[hidden email]> wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>> How to pass an enum element to a C library.
>>>>> C function signature:
>>>>> int ssh_options_set(ssh_session session, enum ssh_options_e type, const void *value)
>>>>>
>>>>> The enum is defined as:
>>>>> enum ssh_options_e {
>>>>>  SSH_OPTIONS_HOST,
>>>>>  SSH_OPTIONS_PORT}
>>>>>
>>>>> An any C call is like:
>>>>> ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, "localhost");
>>>>>
>>>>> GS generated wrapper:
>>>>> ssh_options_set_: session _: type _: value
>>>>>    "Interpreted as #int32 from #( #'ptr' #'ptr' #'ptr' )"
>>>>>    ^Functionssh_options_set callWith: { session. type. value }
>>>>>
>>>>> In GS i tried something like:
>>>>> myLibrary ssh_options_set_: session _: optionHost _: hostName
>>>>> where
>>>>> session: is created in another successful call to myLibrary
>>>>>
>>>>> optionHost:
>>>>> cStructPointer := CByteArray gcMalloc: 8.
>>>>> cStructPointer uint64At: 0 put: 0. "0 correspond to SSH_OPTIONS_HOST - maybe i'm wrong"
>>>>>
>>>>> hostName: CByteArray withAll: 'localhost'
>>>>>
>>>>> But it seems that something is wrong. The chapter 18 do something like this with another library.
>>>>> So [optionHost] or [hostName] has a wrong value...
>>>>> For now no successful call passing an enum element.
>>>>>
>>>>> Now back to fight with C :)
>>>>>
>>>>> 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