[squeak-dev] Fun with spock (NativeBoost FFI)

Igor Stasenko siguctua at gmail.com
Tue May 15 02:16:41 UTC 2012


On 15 May 2012 03:49, Lawson English <lenglish5 at cox.net> wrote:
> The problem I am having is I don't know how to pass in mp_exp_t *expptr
>
>
> I keep getting Error: coma expected
>
>>>prim___gmpf_get_strWithExp:exp
>
>
> "Function: char * mpf_get_str (char *str, mp_exp_t *expptr, int base, size_t
> n_digits, mpf_t op)"
> <primitive: #primitiveNativeCall module: #NativeBoostPlugin error:
> errorCode>
>
>    ^ self nbCall: #( String __gmpf_get_str (ulong 0,  NBSignedLong * exp,
> long 10, long 0, mpf_t gmpf))
>

don't denote constants with type IIRC it doesn't works that way.
don't use 'String' as result value type. If you use this function in
manner as you shown, you forming a memory leak. Check documentation,
it says that if you pass a string, then you allocate it
otherwise a library will allocate it. But then you will need to
manually free it.

> I've tried passing in  4 byte arrays and such, but nothing seems to work.
>
concerting mpexp_t * argument, you should pass a pointer to the buffer
big enough to fit mpexp_t
type value.
You can allocate a bytearray (sizeof(mp_exp_t) and pass it. But doc
says nothing about it..

>
> L
>
> On 5/14/12 6:09 PM, Igor Stasenko wrote:
>>
>> On 15 May 2012 02:38, Lawson English<lenglish5 at cox.net>  wrote:
>>>
>>> I am trying to implement an asString method for gmp floats but I don't
>>> quite
>>> see how.
>>>
>>>
>>> Prototype for getting a string is:
>>>
>>>
>>> "Function: char * mpf_get_str (char *str, mp_exp_t *expptr, int base,
>>> size_t
>>> n_digits, mpf_t op)"
>>>
>>> where mp_exp_t *expptr   is just a pointer to a long, and size_t is just
>>> a
>>> long.  I don't get how to set up the primitive call and how to evoke it
>>> in
>>> the asString method.
>>>
>> just do as it says -
>> create a string, long enough to hold n_digits + 2 characters, i.e.
>>
>> str := ByteString new: ndigits + 2.
>>
>> self mpf_get_str: str exp:.. .....
>>
>> since you passing the string, you can ignore return value (just change the
>> return type of function signature to be void).
>> As result, a function should fill your string with numbers.
>> And don't use 'String' as type, leave 'char*' , like that NB will pass
>> a pointer to first byte
>> of your preallocated string, without converting it to C string which
>> is temporary buffer on stack.
>>
>> void mpf_get_str (char *str, mp_exp_t *expptr, int base, size_t
>> n_digits, mpf_t op)
>>
>>
>
>
> --
> Squeak from the very start (introduction to Squeak and Pharo Smalltalk for
> the (almost) complete and compleate beginner).
> https://www.youtube.com/playlist?list=PL6601A198DF14788D&feature=view_all
>
>



-- 
Best regards,
Igor Stasenko.


More information about the Squeak-dev mailing list