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

Igor Stasenko siguctua at gmail.com
Tue May 15 01:09:53 UTC 2012


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