Why not return a pointer to a double? Like (UNTESTED!):
d = ffi.new('double*')
d[0] = 9.0
return d
Then you could return None, which is converted to a C NULL (same thing other
way around).
On May 19, 2015 11:27:28 AM CDT, Yicong Huang <hengha....@gmail.com> wrote:
>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....@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
>>
>>
>>
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>pypy-dev mailing list
>pypy-dev@python.org
>https://mail.python.org/mailman/listinfo/pypy-dev
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
_______________________________________________
pypy-dev mailing list
pypy-dev@python.org
https://mail.python.org/mailman/listinfo/pypy-dev