[pypy-dev] For embedding pypy, how to deal with None value

Ryan Gonzalez rymg19 at gmail.com
Wed May 20 18:30:34 CEST 2015



On May 20, 2015 1:39:57 AM CDT, Armin Rigo <arigo at tunes.org> wrote:
>Hi Ryan,
>
>On 19 May 2015 at 20:09, Ryan Gonzalez <rymg19 at gmail.com> wrote:
>> Why not return a pointer to a double? Like (UNTESTED!):
>>
>> d = ffi.new('double*')
>> d[0] = 9.0
>> return d
>
>This doesn't work!  You can't return a ffi.new() pointer, because the
>'d' variable is not kept alive.

*slaps self* Right. I feel smart...

>
>>>> The document Embedding PyPy shows good examples, but did not tell
>how to
>>>> deal with None value.
>
>I'm still unsure I understand the question.  You need to know at least
>a bit of C in order to use cffi.  In C you can't write a function that
>returns either a double or NULL.  First start by thinking about a
>valid C interface, and then use cffi to implement it.  Maybe you want
>something like
>
>    int foo(int argument, double *result);
>
>which returns a status code as an integer (e.g. 0=ok, -1=error), and
>in the ok case, fills in "*result".
>
>
>A bientôt,
>
>Armin.

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.


More information about the pypy-dev mailing list