Hi,
On 8 December 2016 at 16:42, Андрей Парамонов <
cmr....@gmail.com> wrote:
> On 64-bit systems I presume? It worked for me on 32-bit process.
Yes, it works on 32-bit because "int" is an integer type that happens
to be as big as pointers on 32-bit.
> Your suggestion to use ffi.buffer didn't work, unfortunately. With or
> without byref() I get, respectively:
Indeed. I could only get it to work with:
ctypes.cast(int(ffi.cast("intptr_t", p)), ctypes.c_void_p)
which is quite a number of casts but at least doesn't require a
complete memmove.
> (It would be really surprising for me if ctypes could consume generic buffer
> object!)
I've stopped long ago being surprised by what ctypes can and can't do.
It can do quite an unexpected number of things---just apparently not
this one. In general I tend to think about ctypes as an interface
that tries to do everything under the sun for you, which works in 95%
of the cases and leaves you wondering why the remaining 5% crash
obscurely. CFFI is not necessarily better, because it crashes in
other ways, but it strives to be more minimal---so the crashes you get
with CFFI are typically crashes that you'd also get if you were
writing the same thing in C. E.g. you "should know" from C that
casting a pointer to "int" is the wrong thing to do :-)
A bientôt,
Armin.