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

Lawson English lenglish5 at cox.net
Tue May 15 01:49:42 UTC 2012


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))

I've tried passing in  4 byte arrays and such, but nothing seems to work.


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



More information about the Squeak-dev mailing list