[pypy-dev] For embedding pypy, how to deal with None value
Armin Rigo
arigo at tunes.org
Wed May 20 08:39:57 CEST 2015
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.
>>> 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.
More information about the pypy-dev
mailing list