Re: passing method's args to extern func
Bartosz SKOWRON <[email protected]> Wed, 10 Jun 2009 21:02:16 +0100
| Newsgroups | gmane.comp.python.pyrex |
|---|---|
| Message-ID | <[email protected]> |
On Wed, Jun 10, 2009 at 7:19 AM, Stefan Behnel<[email protected]> wrote: >> /home/xsx/__usrsrc__/pypcap/pcap.pyx:235:18: Cannot convert Python >> object to 'pcap_pkthdr *' > Maybe you could add some info about what kind of type 'pcap_pkthdr' is? > Most likely, you will have to convert the data manually in some way. Propably - yes. This is a struct: struct pcap_pkthdr { struct timeval ts; /* time stamp */ bpf_u_int32 caplen; /* length of portion present */ bpf_u_int32 len; /* length this packet (off wire) */ }; I tried to define it as ctypedef, but..hmm maybe i should cast something later? > You can cast the object to <char*> first to let Pyrex do the conversion, > and then re-cast that to <unsigned char*> to make the C compiler happy, i.e. > > cdef unsigned char* c_val > c_val = <unsigned char*><char*>some_python_byte_string > > Note that this will not work with unicode strings, just plain byte strings. There will be not a problem with unicode. It should works as you shown. Thanks!