[Pyrex] passing method's args to extern func
Robert Bradshaw
robertwb at math.washington.edu
Fri Jun 12 07:35:22 CEST 2009
On Jun 11, 2009, at 6:49 PM, Bartosz SKOWRON wrote:
> Hi,
>
> I don't know why you answered to me directly but I'm keeping it.
>
> On Thu, Jun 11, 2009 at 8:36 AM, Robert
> Bradshaw<robertwb at math.washington.edu> wrote:
>
>> The point is that there is no Python object that corresponds
>> naturally to a
>> pcap_pkthdr, so pcap_pkthdr <-> object isn't automatic.
>>
>> What you'll have to do is set the fields manually, or write a
>> conversion
>> function yourself. Either that or never treat it as an object
>> (i.e. it can't
>> be used as an argument in a Python method).
>
> OK, can you direct me to the documentation point? I read tutorial nad
> Language Overview. And in both cases there is only about automatic
> conversion. I can't find any information how to make this conversion
> manually.
If I have
struct foo:
int a
float b
I could write
cdef foo create_foo_from_parts(a, b):
cdef foo x
x.a = a
x.b = b
return x
>> Note that <char*>some_python_byte_string works differently in
>> Cython and
>> Pyrex (in the later, unless things have changed, it is like
>> <char*><PyObject*>some_python_byte_string).
>
> Hmm, not sure if I understood it correctly. But, if i will have some
> weird behaviours, I will try to understand it more deeply :)
Python objects are stored as pointers to a location in memory. In
Pyrex, <char*>o creates a char* pointing to the same location that o
resides, it does *not* actually extract that char* from the object o
like you want. (Cython treats <char*>o in the same way as "cdef char*
s; s = o" which does do the automatic conversion in both dialects.)
- Robert
More information about the Pyrex
mailing list