antocuni changed the topic of #pypy to: PyPy, the flexible snake (IRC logs: https://botbot.me/freenode/pypy/ ) | use cffi for calling C | "PyPy: the Gradual Reduction of Magic (tm)"
<ionelmc>
seems that trying stuff with a dirty build dir yields weird results
<antocuni>
you are probably missing the #include
<ionelmc>
i don't have the header file
<ionelmc>
actually, is the `#include "mysrc.h"` really necessary?
<antocuni>
well, you are the author of mysrc.c, so you can write mysrc.h as well
<antocuni>
yes
<antocuni>
suppose you want to use a 3rd party library
<antocuni>
like math.h
<antocuni>
in cdef(), you write the prototypes you are interested in
<antocuni>
so, ffi.cdef("double fabs(double, double)")
<antocuni>
but this is "fake C"
<antocuni>
in the sense that it's used only by cffi+pycparser internally, it's never passed to GCC
<antocuni>
then, in set_source(), you need to tell GCC where to find these actual C declarations
<ionelmc>
so i need the headers cause there are going to be two object files (one for the binding and one for mysrc) yes?
<antocuni>
and usually you do it with an include file
<antocuni>
so, ffi.set_source('#include <math.h>')
<antocuni>
you need a header for each file that you put in sources=[...]
<antocuni>
or, alternatively, you can write the function declaration manually in set_source, if you don't want the header file
<antocuni>
basically, you need to do it properly as you would do in C
<antocuni>
if you develop a C program, you write a .h for each .c
<ionelmc>
seems like a pain in the ass
<antocuni>
then, cffi generates one additional .c file under the hood, but you need to include the .h to get the declaration of all the functions you use
<antocuni>
well, it's C
<antocuni>
it works this way, sorry :)
<ionelmc>
what's the disadvantage of just reading the c file and passing it in?
<antocuni>
if it's one, probably not too much
<antocuni>
if you start to have more, using sources=[...] it's just clearer, IMHO
<antocuni>
anyway, I need to go now, sorry
<ionelmc>
so basically it doesn't scale
<ionelmc>
i get it
<ionelmc>
thanks
<antocuni>
np
<antocuni>
bye
antocuni has quit [Ping timeout: 240 seconds]
exarkun has quit [Ping timeout: 240 seconds]
exarkun has joined #pypy
jcea has joined #pypy
antocuni has joined #pypy
TheAdversary has joined #pypy
oberstet has quit [Ping timeout: 255 seconds]
exarkun has quit [Ping timeout: 240 seconds]
exarkun has joined #pypy
jcea has quit [Remote host closed the connection]
jcea has joined #pypy
oberstet has joined #pypy
<ionelmc>
antocuni: still around?
<antocuni>
yes
<antocuni>
ionelmc: ^^
<ionelmc>
hmmm actually hold on i wanna feel less stupid and figure it out on my own lol
<ionelmc>
antocuni: so is size_t same as int?
<antocuni>
not necessarily
<antocuni>
it depends on the platform
<antocuni>
actually, on linux64 I'd guess it's the same as long
<antocuni>
but for best portability, you should use size_t (and ssize_t, for signed values) whenever necessary
<arigato>
...or more precisely "unsigned long"
<arigato>
(hi)
<antocuni>
arigato: whooo, you are alive :)
<ionelmc>
so i have a _ffi.new('size_t*') how do i make it an int?
<arigato>
antocuni: barely
<antocuni>
ionelmc: do you want to know how to get a python int? Or how to convert it to a C int*?
<ionelmc>
get the int from the pointer (first way)
<arigato>
ionelmc: if 'p' is the pointer, it's p[0]
<arigato>
(which makes a bit of sense if you're used to C)
<antocuni>
ionelmc: yes, in the code you pasted it should be outlen[0]
<antocuni>
(too bad that python has a '+' unary operator, but not a '*' one)
<ionelmc>
ah lol, dunno why i expected magic :)
<kenaan>
mattip default 7dec6a241b75 /: fix issue #2682, split firstword on any whitespace
<kenaan>
mattip py3.5 7d0732ed45b9 /: merge default into py3.5
<antocuni>
ionelmc: cffi tries to stick as close as possible to C semantics
<antocuni>
so, if you use it with the C mindset, often things just work as you would expect
<ionelmc>
antocuni: rest of the code looks fine? the signature is int unlzw(unsigned const char *in, size_t inlen, unsigned char **out, size_t *outlen)
<arigato>
let's make cffi the first and only python library which has an actual usage for "+", by allowing "+p" to stand for "*p" :-)
<ionelmc>
what
<antocuni>
arigato: I was thinking the same... but please don't
demonimin has quit [Remote host closed the connection]
demonimin has joined #pypy
demonimin has quit [Remote host closed the connection]
demonimin has joined #pypy
<antocuni>
mattip: cpyext-refactor-methodobject has already been merged to cpyext-avoid-roundtrip
<antocuni>
cpyext-avoid-roundtrip is basically a never-ending task, because there are tons of things to improve
<antocuni>
however, I think that right now it's in a state which can be merged to default
<antocuni>
but I'd like arigato review first
oberstet has joined #pypy
demonimin has quit [Remote host closed the connection]
demonimin has joined #pypy
<mattip>
cool
ronny has quit [Ping timeout: 240 seconds]
manjaroDeepin has joined #pypy
<manjaroDeepin>
Hello guys! I'm a new guy who wants to help and contribute to PyPy3. Any advise on how to proceed or just a direction to where i may find some beginner friendly issues ?
<kenaan>
mattip default 94ab09b73962 /pypy/module/cpyext/: test, fix issue #2677 copy pure c PyBuffer_{From,To}Contiguous from cpython
<simpson>
manjaroDeepin: Are there perhaps specific pieces of code that you'd like to run? That might be a place to start.
ronny has joined #pypy
<manjaroDeepin>
I was looking at prospective projects on GSOC 17 Ideas List and i would like to contribute on either of these projects "Make bytearray type fast" or "port other modules to PyPy".
<manjaroDeepin>
Is there some place where i can track it's development/issues specifically ?
<simpson>
Okay. I don't know about the GSoC project ideas, but hopefully a core dev is around.