Humm interesting, I wonder why it works in Cpython, when I get the chance I will try making those changes and see if pypy works.
On 06/09/11 23:57, Amaury Forgeot d'Arc wrote:
2011/9/7 Greg Bowyer <gbow...@fastmail.co.uk <mailto:gbow...@fastmail.co.uk>>

    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


The pcap module has an important issue; pcap_open_live() contains this code:
    error=c_char_p()
    handle=pcap_c_funcs.pcap_open_live(source,snaplen,promisc,to_ms,error)
Which is wrong: according to the man page, the "error" parameter
"is assumed to be able to hold at least PCAP_ERRBUF_SIZE chars"
which is not the case here, NULL is passed instead and bad things will happen at runtime.

pcap should be modified, probably with something like "error = create_string_buffer(256)"

--
Amaury Forgeot d'Arc

_______________________________________________
pypy-dev mailing list
pypy-dev@python.org
http://mail.python.org/mailman/listinfo/pypy-dev

Reply via email to