Re: passing method's args to extern func
Robert Bradshaw <[email protected]> Thu, 11 Jun 2009 22:35:22 -0700
| Newsgroups | gmane.comp.python.pyrex |
|---|---|
| Message-ID | <[email protected]> |
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<[email protected]> 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 =3D a x.b =3D 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 =3D o" which does do the automatic conversion in both dialects.) - Robert