[NB] Passing a null value to a const char* parameter

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

[NB] Passing a null value to a const char* parameter

Jan van de Sandt
Hello,

NativeBoost doesn't allow me to pass a nil value instead of a String as a parameter for a 'const char*' function argument. When I use nil I get a failure with lastError=1

Is this by design? If so, is there an alternative?

Jan.
Reply | Threaded
Open this post in threaded view
|

Re: [NB] Passing a null value to a const char* parameter

Igor Stasenko
On 24 August 2012 17:00, Jan van de Sandt <[hidden email]> wrote:
> Hello,
>
> NativeBoost doesn't allow me to pass a nil value instead of a String as a
> parameter for a 'const char*' function argument. When I use nil I get a
> failure with lastError=1
>
> Is this by design? If so, is there an alternative?
>
yess..

by default if you use in signature a 'String' as argument type
then the FFI routine will only accept an instances of variable-byte
objects (which a ByteStrings are).
But there is an option #optStringOrNull
which will also allows passing a nil object as argument (which will be
converted to NULL pointer value)

so, in your binding you must specify this option:

mymethod: string
 <...>
  ^ self nbCall: #( void whatever(String string)) options: #( optStringOrNull )

so, for passing null , you can simply pass a nil as argument:

self mymethod: nil.

> Jan.



--
Best regards,
Igor Stasenko.

Reply | Threaded
Open this post in threaded view
|

Re: [NB] Passing a null value to a const char* parameter

Stéphane Ducasse
Igor

we should collect all the emails of Jan and turn them into a section in the FFI chapter.

Stef

On Aug 24, 2012, at 5:36 PM, Igor Stasenko wrote:

> On 24 August 2012 17:00, Jan van de Sandt <[hidden email]> wrote:
>> Hello,
>>
>> NativeBoost doesn't allow me to pass a nil value instead of a String as a
>> parameter for a 'const char*' function argument. When I use nil I get a
>> failure with lastError=1
>>
>> Is this by design? If so, is there an alternative?
>>
> yess..
>
> by default if you use in signature a 'String' as argument type
> then the FFI routine will only accept an instances of variable-byte
> objects (which a ByteStrings are).
> But there is an option #optStringOrNull
> which will also allows passing a nil object as argument (which will be
> converted to NULL pointer value)
>
> so, in your binding you must specify this option:
>
> mymethod: string
> <...>
>  ^ self nbCall: #( void whatever(String string)) options: #( optStringOrNull )
>
> so, for passing null , you can simply pass a nil as argument:
>
> self mymethod: nil.
>
>> Jan.
>
>
>
> --
> Best regards,
> Igor Stasenko.
>


Reply | Threaded
Open this post in threaded view
|

Re: [NB] Passing a null value to a const char* parameter

Igor Stasenko
On 24 August 2012 17:46, Stéphane Ducasse <[hidden email]> wrote:
> Igor
>
> we should collect all the emails of Jan and turn them into a section in the FFI chapter.
>
sure.
meanwhile i will write a section about strings and structures on NB-Help.

> Stef
>
> On Aug 24, 2012, at 5:36 PM, Igor Stasenko wrote:
>
>> On 24 August 2012 17:00, Jan van de Sandt <[hidden email]> wrote:
>>> Hello,
>>>
>>> NativeBoost doesn't allow me to pass a nil value instead of a String as a
>>> parameter for a 'const char*' function argument. When I use nil I get a
>>> failure with lastError=1
>>>
>>> Is this by design? If so, is there an alternative?
>>>
>> yess..
>>
>> by default if you use in signature a 'String' as argument type
>> then the FFI routine will only accept an instances of variable-byte
>> objects (which a ByteStrings are).
>> But there is an option #optStringOrNull
>> which will also allows passing a nil object as argument (which will be
>> converted to NULL pointer value)
>>
>> so, in your binding you must specify this option:
>>
>> mymethod: string
>> <...>
>>  ^ self nbCall: #( void whatever(String string)) options: #( optStringOrNull )
>>
>> so, for passing null , you can simply pass a nil as argument:
>>
>> self mymethod: nil.
>>
>>> Jan.
>>
>>
>>
>> --
>> Best regards,
>> Igor Stasenko.
>>
>
>



--
Best regards,
Igor Stasenko.

Reply | Threaded
Open this post in threaded view
|

Re: [NB] Passing a null value to a const char* parameter

Stéphane Ducasse

On Aug 24, 2012, at 5:49 PM, Igor Stasenko wrote:

> On 24 August 2012 17:46, Stéphane Ducasse <[hidden email]> wrote:
>> Igor
>>
>> we should collect all the emails of Jan and turn them into a section in the FFI chapter.
>>
> sure.
> meanwhile i will write a section about strings and structures on NB-Help.


excellent idea.
This evening I will read it if I do not fall asleep before since I should read mariano's paper ;D


Stef

>
>> Stef
>>
>> On Aug 24, 2012, at 5:36 PM, Igor Stasenko wrote:
>>
>>> On 24 August 2012 17:00, Jan van de Sandt <[hidden email]> wrote:
>>>> Hello,
>>>>
>>>> NativeBoost doesn't allow me to pass a nil value instead of a String as a
>>>> parameter for a 'const char*' function argument. When I use nil I get a
>>>> failure with lastError=1
>>>>
>>>> Is this by design? If so, is there an alternative?
>>>>
>>> yess..
>>>
>>> by default if you use in signature a 'String' as argument type
>>> then the FFI routine will only accept an instances of variable-byte
>>> objects (which a ByteStrings are).
>>> But there is an option #optStringOrNull
>>> which will also allows passing a nil object as argument (which will be
>>> converted to NULL pointer value)
>>>
>>> so, in your binding you must specify this option:
>>>
>>> mymethod: string
>>> <...>
>>> ^ self nbCall: #( void whatever(String string)) options: #( optStringOrNull )
>>>
>>> so, for passing null , you can simply pass a nil as argument:
>>>
>>> self mymethod: nil.
>>>
>>>> Jan.
>>>
>>>
>>>
>>> --
>>> Best regards,
>>> Igor Stasenko.
>>>
>>
>>
>
>
>
> --
> Best regards,
> Igor Stasenko.
>