Re: passing method's args to extern func

Stefan Behnel <[email protected]> Wed, 10 Jun 2009 08:19:39 +0200
Newsgroups gmane.comp.python.pyrex
Message-ID <[email protected]>
Bartosz SKOWRON wrote:
> i have a question which the answer is described here:
> http://ldots.org/pyrex-guide/5-python-wrapper.html#std
> 
> The problem is, what with more complex data types than char* ? e.g.
> defined structures or unsigned char *?
> i need both and get this:
> pyrexc pcap.pyx
> /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.


> /home/xsx/__usrsrc__/pypcap/pcap.pyx:236:16: Cannot convert Python
> object to 'unsigned char *'

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.

Stefan