arigato 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 | mac OS and Fedora are not Windows
xcm has quit [Remote host closed the connection]
xcm has joined #pypy
jcea has quit [Quit: jcea]
dddddd has quit [Remote host closed the connection]
xcm has quit [Remote host closed the connection]
xcm has joined #pypy
xcm has quit [Remote host closed the connection]
xcm has joined #pypy
dansan has quit [Read error: Connection reset by peer]
dansan has joined #pypy
xcm has quit [Remote host closed the connection]
xcm has joined #pypy
andi- has quit [Ping timeout: 250 seconds]
dddddd has joined #pypy
dansan_ has joined #pypy
dansan has quit [Ping timeout: 268 seconds]
dansan_ is now known as dansan
andi- has joined #pypy
rubdos has quit [Quit: WeeChat 2.4]
xcm has quit [Remote host closed the connection]
xcm has joined #pypy
Rhy0lite has joined #pypy
dddddd has quit [Remote host closed the connection]
<kenaan> rlamy apptest-file 0cc7bfd94fd8 /pypy/doc/contributing.rst: fix option name
Kipras_ has joined #pypy
kipras has joined #pypy
Kipras_ has quit [Ping timeout: 245 seconds]
marky1991 has joined #pypy
xcm has quit [Remote host closed the connection]
xcm has joined #pypy
marky1991 has quit [Ping timeout: 248 seconds]
xcm has quit [Remote host closed the connection]
ionelmc has joined #pypy
<ionelmc> is there anything to pretty print contents of cdata objects (from cffi)?
xcm has joined #pypy
rubdos has joined #pypy
marky1991 has joined #pypy
<arigato> No
xcm has quit [Remote host closed the connection]
xcm has joined #pypy
xcm has quit [Remote host closed the connection]
xcm has joined #pypy
marky1991 has quit [Ping timeout: 246 seconds]
marky1991 has joined #pypy
<arigato> ionelmc: sorry for the short answer. the longer one is the same: there is no built-in way to print, say, the content of an array of ints. Maybe try list(x), which turns such an array into a list
xcm has quit [Remote host closed the connection]
xcm has joined #pypy
jcea has joined #pypy
BPL has joined #pypy
<kenaan> rlamy apptest-file d8e5b6784927 /rename_moduledef.py: remove one-shot helper script
<BPL> Hi everyone, first time I'm using cffi and i'm trying to figure out how to convert an array('f', []) to `float*`, any idea? Thx in advance
tsaka__ has joined #pypy
<kenaan> rlamy py3tests f97eefdfc74e /rename_moduledef.py: remove one-shot helper script
<BPL> I've tried If I try to do `cffi_lib.foo(ctypes.POINTER(ctypes.c_float).from_buffer(my_python_array))` but I'll get "TypeError: initializer for ctype 'float *' must be a cdata pointer, not LP_c_float", any suggestion?
tsaka__ has quit [Ping timeout: 250 seconds]
<LarstiQ> BPL: how about cffi_lib.foo(my_python_array)?
<LarstiQ> "Working with pointers, structures and arrays"
<BPL> LarstiQ: Hey, no, that wouldn't work, yeah, i've read briefly that section but didn't understand all the gritty details. Right now I was using ctypes directly but I'm getting some nice access violation reading when using something like this https://bpaste.net/show/5cZo
<LarstiQ> I would stay far away from ctypes
<BPL> sure, that was my intention... but i've got stuck with this trivial attempt to wrap a very little function so i thought it'd be good to check if casting with ctypes would be easier
<LarstiQ> BPL: where does the array come from? How about `ffi.new("float[<length>]")`
<LarstiQ> BPL: answer, no :)
<BPL> LarstiQ: The real array would be a huge interleaved chunk of topological data. The whole idea would be casting that whole memory area in C with as little overhead as possible
<BPL> anyway, let me paste my snippet using cffi... maybe you'll see what's the mistake
<BPL> LarstiQ: Ok, here https://bpaste.net/show/LzE9 , line #28 will give this error => TypeError: initializer for ctype 'float *' must be a cdata pointer, not LP_c_float
<BPL> LarstiQ: I'm gonna try that ffi.new("float[<length>]") suggestion... but this smells like it's gonna reallocate new memory and I'd like to avoid that (if possible)
<LarstiQ> BPL: use that instead of the `from array import array` though
<LarstiQ> that is what I was asking with "where does the array come from"
<LarstiQ> maybe you snippet isn't representative for that?
<BPL> LarstiQ: Ok, first thing first, using ffi.new would work out of the box. That said, my original code has a bunch of datatypes inheriting from array.array where the whole memory allocation is done... so my question is, isn't there any way to cast that memory to something suitable to cffi?
<BPL> or in the worst case scenario, isn't there a fast memcpy from array.array=>cffi ?
<LarstiQ> there might be
<BPL> also... i'm still wondering why when using ctypes I'd get access reading violation with this code `foo(ctypes.cast(c_float_p.from_buffer(verts), c_float_p), len(verts))`
<BPL> checking, ty
<LarstiQ> BPL: I don't know, imo the right answer is nearly always "don't touch ctypes"
<LarstiQ> if you really want to know you'd need to dig or talk to someone whos knows the cffi codebase
<BPL> LarstiQ: Fair enough :) , actually for years I've been using swig... but today I feel I'd like to use directly the good old dlls with ctypes or cffi
speeder39_ has joined #pypy
<BPL> LarstiQ: \:O/ I've got lucky ==> clib.foo(ffi.cast("float*", ffi.from_buffer(verts)), len(verts))
<LarstiQ> this seems to work? `verts = array.array('f', [1, 2, 3]); cdata = ffi.from_buffer(verts)`
<BPL> ;)
<LarstiQ> might not even need the cast?
<BPL> let m check
<BPL> LarstiQ: Wow, awesome, it works without casting, tyvm!
<BPL> LarstiQ: Hopefully that from_buffer won't be too expensive
<LarstiQ> I expect it isn't, let me see if I can find the implementation
<BPL> https://cffi.readthedocs.io/en/latest/ref.html#ffi-buffer-ffi-from-buffer "these built-in functions read from or write to the raw memory directly, without needing an extra copy."
<LarstiQ> BPL: anyway, seems you have what you need now?
<BPL> LarstiQ: Yeah, idd, tyvm... everything fine now... also, I'm thinking I seriously should learn more about this CFFI library, I've read the https://cffi.readthedocs.io/en/latest/using.html and it looks an awesome project
<LarstiQ> It is :)
<BPL> btw, what'd you say is the "cleanest" way to create python bindings for c++ classes using cffi? So far I've just seen this trivial example https://gist.github.com/tonyseek/7821993 . But it'd be cool to see some example dealing with more complex classes (templates/operators/...)
<LarstiQ> BPL: have you looked at cppyy mentioned from https://cffi.readthedocs.io/en/latest/goals.html ?
marky1991 has quit [Ping timeout: 268 seconds]
<BPL> LarstiQ: Wow, awesome... reading now, i didn't know about this one at all :O ... and i thought i knew all existing python libraries to help you creating wrappers, ty!
<LarstiQ> the basics is indeed to expose a C compatible api with the `extern "C"` as in https://gist.github.com/tonyseek/7821993, then you're back in C land
<BPL> LarstiQ: Sure, that's why i asked the "cleanest" way... although i guess exposing a C compatible API for a large project would involve automating the "C compatible API" creation somehow with some c++ parser
<LarstiQ> and at that point "cppyy: Automatic Python-C++ bindings" starts sounding attractive :)
tsaka__ has joined #pypy
lritter has joined #pypy
Rhy0lite has quit [Quit: Leaving]
dddddd has joined #pypy
speeder39_ has quit [Quit: Connection closed for inactivity]
tsaka__ has quit [Quit: Konversation terminated!]
tsaka__ has joined #pypy
<ionelmc> ooooof ... doesn't cffi support bitfield structs?
<ionelmc> arigato: still around?
<ionelmc> i have these weird headers
<ionelmc> for some reason cffi thinks that struct makes up 24 bytes but that seems wrong
BPL has quit [Ping timeout: 245 seconds]
BPL has joined #pypy
lritter has quit [Quit: Leaving]
alexge50 has joined #pypy
<cfbolz> ionelmc: I vaguely recall a restriction of cffi around structs with bitfields
<cfbolz> ionelmc: note however that the size of this struct is indeed 24 bytes on 64 bit platforms
<cfbolz> because of alignment
<ionelmc> well that explains my confusion
<ionelmc> can i make cffi pretend i'm on 32bit?
<cfbolz> probably not
<ionelmc> or at least what to change to make it behave as it would be on 32bit platform
<cfbolz> (the bitfield restriction seems to be that you can't pass structs with bitfields by value: https://bitbucket.org/cffi/cffi/issues/150/structs-with-bit-fields-as-arguments )
<ionelmc> i don't need to pass them, just need to take data out of them
<cfbolz> why do you want to pretend to be on a 32bit platform?
<ionelmc> cfbolz: i basically want to load a bunch of data using those contrived structs and display it or something
<ionelmc> all i got is a bunch of really messed up c sources (which i can't really use)
<ionelmc> the headers seem usable tho
<cfbolz> just out of curiosity, what's the C library?
<ionelmc> errr... seemed
<ionelmc> something internal
<ionelmc> i'd be calling it out if it was public lol
<ionelmc> so any suggestion on how to deal with that struct?
<cfbolz> Right
<ionelmc> i don't really want to convert those many structs to stdlib struct.unpack :|
<ionelmc> i'm obviously incompetent about alignment and such lol
<cfbolz> I still don't quite get why things go wrong with 32 vs 64
<ionelmc> well i guess i could try it with a 32bit python and see what happens but that still won't solve my problem right away
<cfbolz> ionelmc: OK, but the library is compiled as a 64 bit library. So why are the structs that it gives you not 24 bytes large?
<ionelmc> no it was compiled on 32bits
<ionelmc> i doubt it would even build there
<cfbolz> ionelmc: OK, then I would indeed try a 32 bit python
<ionelmc> yes but note that i can't deploy on that
<cfbolz> Then I am out of ideas and you should wait for Armin tomorrow ;-)
<ionelmc> alright, beeeer time
<cfbolz> Sounds right to meeee
alexge50 has quit [Quit: ZNC 1.7.4 - https://znc.in]
alexge50 has joined #pypy
<BPL> LarstiQ: Wow, I've been playing 5 minutes with the library you suggested me and I can just say that's a truly awesome project :O ... do you know if there is any irc channel available?
<BPL> meh, n.mind, I'll just use the bitbucket repo :) , https://bitbucket.org/wlav/cppyy/issues/135/when-loading-libcppyy_backenddll-spawned
dmalcolm has quit [Remote host closed the connection]
tsaka__ has quit [Ping timeout: 248 seconds]
tsaka__ has joined #pypy