Re: [Cython] User Question - Questions and 'Cannot convert to Python Object'...

2009-03-16 Thread Robert Bradshaw
On Mar 15, 2009, at 2:48 PM, Greg Ewing wrote: > Stefan Behnel wrote: >> Carl Witty wrote: >> >>> Hmm... I hope that eventually Cython will allow overriding >>> __new__, at >>> which point calling an extension type won't necessarily return a >>> value >>> of that type. >> >> I'm not sure. This

Re: [Cython] User Question - Questions and 'Cannot convert to Python Object'...

2009-03-15 Thread Greg Ewing
Stefan Behnel wrote: > Carl Witty wrote: > >>Hmm... I hope that eventually Cython will allow overriding __new__, at >>which point calling an extension type won't necessarily return a value >>of that type. > > I'm not sure. This should certainly be supported for Python classes, but > for extension

Re: [Cython] User Question - Questions and 'Cannot convert to Python Object'...

2009-03-13 Thread Robert Bradshaw
On Mar 13, 2009, at 12:39 PM, Santiago Aguiar wrote: > Lisandro Dalcin wrote: >> Santiago, have you considered writing a simple script to generate >> Cython code :-) ?? You could parse a simple txt file with metadata >> about your C-level structs (name, field types, fieldname, and even >> default

Re: [Cython] User Question - Questions and 'Cannot convert to Python Object'...

2009-03-13 Thread Santiago Aguiar
Lisandro Dalcin wrote: > Santiago, have you considered writing a simple script to generate > Cython code :-) ?? You could parse a simple txt file with metadata > about your C-level structs (name, field types, fieldname, and even > default field values), then you could easily dump Cython code > auto

Re: [Cython] User Question - Questions and 'Cannot convert to Python Object'...

2009-03-13 Thread Stefan Behnel
Robert Bradshaw wrote: > On Mar 13, 2009, at 10:24 AM, Carl Witty wrote: >> How about this? In the hypothetical future version of Cython that >> allows overriding __new__, say that the overrides have to be declared >> in the .pxd file, with >> >> cdef TYPE __new__(self, foo, bar) >> >> (where T

Re: [Cython] User Question - Questions and 'Cannot convert to Python Object'...

2009-03-13 Thread Robert Bradshaw
On Mar 13, 2009, at 12:53 AM, Stefan Behnel wrote: > > Santiago Aguiar wrote: >> I've started to use Cython just yesterday, and I'm facing some >> difficulties ;). I'm sorry to ask this on the dev list, but I didn't >> found a user specific one... >> >> I have a struct-dense C source code that def

Re: [Cython] User Question - Questions and 'Cannot convert to Python Object'...

2009-03-13 Thread Robert Bradshaw
On Mar 13, 2009, at 10:24 AM, Carl Witty wrote: > On Fri, Mar 13, 2009 at 10:11 AM, Lisandro Dalcin > wrote: >> On Fri, Mar 13, 2009 at 2:39 PM, Stefan Behnel >> wrote: >>> So, can't we just require that ExtType.__new__() returns an >>> instance of >>> ExtType (or its subtypes)? >> >> As a

Re: [Cython] User Question - Questions and 'Cannot convert to Python Object'...

2009-03-13 Thread Carl Witty
On Fri, Mar 13, 2009 at 10:11 AM, Lisandro Dalcin wrote: > On Fri, Mar 13, 2009 at 2:39 PM, Stefan Behnel wrote: >> So, can't we just require that ExtType.__new__() returns an instance of >> ExtType (or its subtypes)? > > As a first approach, it could be like that... > > ? Or is there a use case

Re: [Cython] User Question - Questions and 'Cannot convert to Python Object'...

2009-03-13 Thread Lisandro Dalcin
Santiago, have you considered writing a simple script to generate Cython code :-) ?? You could parse a simple txt file with metadata about your C-level structs (name, field types, fieldname, and even default field values), then you could easily dump Cython code automating the member, __cinit__() me

Re: [Cython] User Question - Questions and 'Cannot convert to Python Object'...

2009-03-13 Thread Lisandro Dalcin
On Fri, Mar 13, 2009 at 2:39 PM, Stefan Behnel wrote: >> >> comm = MPI.Comm(MPI.COMM_WORLD) >> assert comm is MPI.COMM_WORLD >> >> and the assertion will succeed... > > Am I right in guessing that Comm is an extension type here and that > COMM_WORLD is an instance? > Yes, you are right... > So y

Re: [Cython] User Question - Questions and 'Cannot convert to Python Object'...

2009-03-13 Thread Santiago Aguiar
Stefan Behnel wrote: > Why don't you reference the struct itself here? Do you really need these > fields to be public? > I could, but in that case I would need to write getters/setters for each attribute. In my code, almost all the struct fields are relevant, since they represent fields in th

Re: [Cython] User Question - Questions and 'Cannot convert to Python Object'...

2009-03-13 Thread Carl Witty
On Fri, Mar 13, 2009 at 9:39 AM, Stefan Behnel wrote: > So, can't we just require that ExtType.__new__() returns an instance of > ExtType (or its subtypes)? Or is there a use case that would benefit from > returning arbitrary things? I have code (currently in pure Python, but if I ever transition

Re: [Cython] User Question - Questions and 'Cannot convert to Python Object'...

2009-03-13 Thread Stefan Behnel
Lisandro Dalcin wrote: > On Fri, Mar 13, 2009 at 12:46 PM, Stefan Behnel wrote: >> Carl Witty wrote: >>> Hmm... I hope that eventually Cython will allow overriding __new__, at >>> which point calling an extension type won't necessarily return a value >>> of that type. >> >> I'm not sure. This shoul

Re: [Cython] User Question - Questions and 'Cannot convert to Python Object'...

2009-03-13 Thread Stefan Behnel
Lisandro Dalcin wrote: > On Fri, Mar 13, 2009 at 12:42 PM, Carl Witty wrote: >> On Fri, Mar 13, 2009 at 12:53 AM, Stefan Behnel >> wrote: I don't understand why I'm getting the error. If I call a cdef function instead of a cdef method, it works OK; but shouldn't I be able to call >

Re: [Cython] User Question - Questions and 'Cannot convert to Python Object'...

2009-03-13 Thread Lisandro Dalcin
On Fri, Mar 13, 2009 at 12:46 PM, Stefan Behnel wrote: > Carl Witty wrote: >> Hmm... I hope that eventually Cython will allow overriding __new__, at >> which point calling an extension type won't necessarily return a value >> of that type. > > I'm not sure. This should certainly be supported for P

Re: [Cython] User Question - Questions and 'Cannot convert to Python Object'...

2009-03-13 Thread Lisandro Dalcin
On Fri, Mar 13, 2009 at 12:42 PM, Carl Witty wrote: > On Fri, Mar 13, 2009 at 12:53 AM, Stefan Behnel wrote: >>> I don't understand why I'm getting the error. If I call a cdef function >>> instead of a cdef method, it works OK; but shouldn't I be able to call a >>> cdef method and passing a C typ

Re: [Cython] User Question - Questions and 'Cannot convert to Python Object'...

2009-03-13 Thread Stefan Behnel
Carl Witty wrote: > On Fri, Mar 13, 2009 at 12:53 AM, Stefan Behnel wrote: >>> I don't understand why I'm getting the error. If I call a cdef function >>> instead of a cdef method, it works OK; but shouldn't I be able to call >>> a >>> cdef method and passing a C type instead of a Python type? Othe

Re: [Cython] User Question - Questions and 'Cannot convert to Python Object'...

2009-03-13 Thread Carl Witty
On Fri, Mar 13, 2009 at 12:53 AM, Stefan Behnel wrote: >> I don't understand why I'm getting the error. If I call a cdef function >> instead of a cdef method, it works OK; but shouldn't I be able to call a >> cdef method and passing a C type instead of a Python type? Otherwise, I >> will need to a

Re: [Cython] User Question - Questions and 'Cannot convert to Python Object'...

2009-03-13 Thread Greg Ewing
Stefan Behnel wrote: > Santiago Aguiar wrote: > >> return Msg1().from_c(&msg.data.msg_1) >> >> I get an error message saying that: 'Cannot convert >>'msg1_c_struct *' to Python object' where I do the Msg1().from_c. > > I consider this a deficiency of Cython. It should know the type of t

Re: [Cython] User Question - Questions and 'Cannot convert to Python Object'...

2009-03-13 Thread Stefan Behnel
Santiago Aguiar wrote: > I've started to use Cython just yesterday, and I'm facing some > difficulties ;). I'm sorry to ask this on the dev list, but I didn't > found a user specific one... > > I have a struct-dense C source code that defines the PDU of a network > protocol and functions to re

[Cython] User Question - Questions and 'Cannot convert to Python Object'...

2009-03-12 Thread Santiago Aguiar
Hello, I've started to use Cython just yesterday, and I'm facing some difficulties ;). I'm sorry to ask this on the dev list, but I didn't found a user specific one... I have a struct-dense C source code that defines the PDU of a network protocol and functions to read/write from a buffer struc