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

Yicong Huang hengha.mao at gmail.com
Tue May 19 18:27:28 CEST 2015


One approach we thought of is to use additional int pointer to indicate
whether the value is None.

ffi.cdef('''struct API {    double (*add_numbers)(double x, double y);

    int *ret};

And then wrap the python function, if the return value is None, set ret[0] to 1.



On Tue, May 19, 2015 at 11:06 PM, Yicong Huang <hengha.mao at gmail.com> wrote:

> The document Embedding PyPy shows good examples, but did not tell how to
> deal with None value.
> As Python support None value, it might bring some troubles:
> 1. How to pass NULL from C to python for None?
> 2. If python function return None, how to handle the issue in C?
>
> For the above cases, we observed errors like these:
>
> From cffi callback <function add_numbersInt at 0x00007f25f313e110>:
> Trying to convert the result back to C:
> TypeError: expected integer, got NoneType object
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20150520/9d086714/attachment.html>


More information about the pypy-dev mailing list