[pypy-dev] Errors running pypy with ctype library
Greg Bowyer
gbowyer at fastmail.co.uk
Wed Sep 7 01:43:53 CEST 2011
Hi all, I have a rather interesting in house networking tool that uses
pcap to sniff packets, take them into twisted and replay them against a
target.
Internally the tight loop for packet reassembly is currently run via
twisted and some custom parsing and packet reconstruction code, I have
been investigating if I can make this code faster _without_
reimplementing the capture part in C, as such I think I have two options:
* Pypy (which I would prefer as it means that I hopefully will gain
performance improvements over time, as well as JIT acceleration
throughout the code)
* Cython (which will let me change the main loop to be mostly C without
having to write a lot of C)
The tool currently uses an old style cPython c extension to bind python
to pcap, since this will be slow in pypy I found the first semi
implemented ctype pcap binding from google code here
(http://code.google.com/p/pcap/) (I didnt write it so it may be broken)
The following test code works fine on cPython2.7
--------------- %< ---------------
from pycap import pycap
pp = pycap.open_live('eth0', 1596, True, 250)
bpf = pycap.compile(r'tcp dst port 80')
bpf = pycap.compile(pp, 'tcp', True, 0)
def process(user, pkthdr, packet):
print 'callback'
print 'pkthdr[0:7]', pkthdr.contents.len
cb = pycap.CALLBACK(process)
pycap.loop(pp, 100, cb, "greg")
--------------- >% ---------------
but fails with the following error on pypy trunk
--------------- %< ---------------
greg at localhost ~/projects/pcap-read-only/packet $
/home/greg/projects/pypy/pypy/translator/goal/pypy-c
Python 2.7.1 (ddff981df9d5, Sep 06 2011, 19:21:21)
[PyPy 1.6.0-dev1 with GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``this is a self-referential
channel topic''
>>>> import pycap
>>>> from pycap import pycap
>>>> pp = pycap.open_live('eth0', 1596, True, 250)
pycap/__buildin_funcs__/pcap_native_funcs.py:188: RuntimeWarning: C
function without declared arguments called
handle=pcap_c_funcs.pcap_open_live(source,snaplen,promisc,to_ms,error)
Segmentation fault
--------------- >% ---------------
The segmentation fault might be down to pcap being very twitchy about
its inputs rather than pypy itself having a segfault
Any ideas whats wrong in the ctypes binding here ?
-- Greg
More information about the pypy-dev
mailing list