cfbolz changed the topic of #pypy to: PyPy, the flexible snake (IRC logs: https://quodlibet.duckdns.org/irc/pypy/latest.log.html#irc-end ) | use cffi for calling C | if a pep adds a mere 25-30 [C-API] functions or so, it's a drop in the ocean (cough) - Armin
jcea has quit [Ping timeout: 264 seconds]
jcea has joined #pypy
Gustavo6046 has quit [Ping timeout: 265 seconds]
Gustavo6046 has joined #pypy
jcea has quit [Ping timeout: 260 seconds]
Gustavo6046 has quit [Ping timeout: 256 seconds]
Gustavo6046 has joined #pypy
asmeurer__ has joined #pypy
Gustavo6046 has quit [Quit: ZNC 1.8.2 - https://znc.in]
Gustavo6046 has joined #pypy
otisolsen70 has joined #pypy
otisolsen70 has quit [Quit: Leaving]
asmeurer__ has quit [Quit: asmeurer__]
<mattip> here is another silly syntax error it would be nice to detect: when you define a property on a class,
<mattip> but the class has an attribute with the property name and the property function tries to lookup the attribute on the class
oberstet has joined #pypy
otisolsen70 has joined #pypy
<cfbolz> mattip: good idea. put it in an issue so we don't lose it?
otisolsen70 has quit [Quit: Leaving]
mcon has joined #pypy
<mcon> Hi, I'm trying to use CFFI to build bindings to a "standard" Linux lib ("ell/ell.h", actually a I need bindings for a small part of it: "ell/settings.h"). I get errors each time a CPP directive is encountered (e.g.: cffi.CDefError: cannot parse "#ifndef __ELL_SETTINGS_H" //<cdef source string>:23:1: Directives not supported yet) I *could* pipe through `gcc -E` but that doesn't seem the right thing to do. What am I missing?
jcea has joined #pypy
<mcon> ... if I actually use `gcc -E` I get a nastier error: "/usr/lib/gcc/x86_64-linux-gnu/9/include/stddef.h:416:28: before: __attribute__" since I cannot believe nobody tried to `#include <stddef.h>` I must be missing something really basic. Can someone point me to the right docs, please?
<mattip> mcon: this is one of the difficulties with trying to guess what the actual function signature/structures are.
<mattip> what structure/function are you actually interested in?
<mcon> Ok, it *seems* (I would appreciate confirmation) "cdef()" only accepts plain definitions.
<mcon> I have been able to generate and compile my interface.
<mcon> Next problem is: some C functions return "char *"; if I call them I dutifully get: "<cdata 'char *' 0x16787c0>". How do I convert to Python str ?
<mcon> More importantly: is there some way to convince cffi to directly return str, so I don't have to write another layer for ease of use?
<mattip> ffi.string
<mattip> will return bytes from a char *
<mattip> be careful of object lifetime, who allocates/frees the char * ?
<mcon> mattip: That would be next question. Right now I have problems finding `ffi.string` In my est program I did a "from ell.lib import *" (ell.so is my lib) and I do not see it around :( what should I import?
<mattip> dunno how you built ell. It should have an ffi
<mcon> mattip: Yup! found. I need `from ell import ffi`
<mattip> that gives you the interface needed to interact with ell.lib
<mattip> ffi.string, ffi.new, ffi.buffer, ...
<mcon> Back to your question: in plain C ell functions allocate strings and you are supposed to call `l_free(string`
<mcon> mattip: what is the right sequence there? keep around a reference to `char*` and later use that to `l_free()`it?
<mattip> yes, you must manage the object lifetime yourself in this case. Once you convert it to bytes with ffi.string() you can free it,
<mattip> but you must call l_free yourself, there is no automatic gc
<mattip> so if you do result = ffi.string(ell.lib.myfunc()) you loose the opportunity to free it
<mcon> mattip: Yup. understood. Next question ;) where can i find a list of functions provided by `ffi`? Now I need something to convert `char **` to a list of strings... and I assume I've better to stop pestering you for trivial matters ...
<mcon> mattip: I found the docs for the ffi functions, but I fail to understand what I should use in this case. The function returns a `char **`, i.e.: an array of pointers to strings. Problem is I don't know the length as the list is supposed to have a NULL sentinel. I tried using `cffi.buffer()` and I get a "buffer:8" which is consistent since it should have a single pointer (+sentinel), but now I need to convert that to an useful stri
<mattip> i = 0; s=[]; while ret[i] != ffi.NULL: s.append(ffi.string(ret[i]); i++
jevinskie[m] has joined #pypy
jacob22 has joined #pypy
jacob22_ has joined #pypy
jacob22 has quit [Ping timeout: 265 seconds]
jacob22_ has quit [Read error: Connection reset by peer]
dmalcolm_ has joined #pypy
dmalcolm has quit [Quit: Leaving]
dmalcolm_ has quit [Remote host closed the connection]