On Fri, Apr 17, 2009 at 10:51 AM, Riccardo Murri
<[email protected]> wrote:
> Hi,
>
> I cannot get the documented method to work::
>
>  $ cat t.pyx
>  cdef extern from "tupleobject.h":
>      ctypedef class __builtin__.tuple [object PyTupleObject]:
>          pass
>
>  cdef class MyTuple(tuple):
>      pass
>

Tuples are a different beast... They are PyObject_VAR_HEAD structures
(like strings in Py2, and perhaps in Py3 in the future, no right
now)...

typedef struct {
    PyObject_VAR_HEAD
    PyObject *ob_item[1];
} PyTupleObject;

Cython cannot currently handle this...

Perhaps the error message could be made more explicit in this case (by
checking if tp_itemsize != 0 ) ... ?


>  $ cython t.pyx
>  warning: /tmp/t.pyx:2:4: tuple already a builtin Cython type
>  $ gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall
> -Wstrict-prototypes -fPIC -I/usr/include/python2.5 -c t.c -o t.o
>  $ gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions t.o -o t.so
>
>  $ python
>  Python 2.5.2 (r252:60911, Oct  5 2008, 19:24:49)
>  [GCC 4.3.2] on linux2
>  Type "help", "copyright", "credits" or "license" for more information.
>  >>> import t
>  Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
>    File "t.pyx", line 2, in t (t.c:610)
>      ctypedef class __builtin__.tuple [object PyTupleObject]:
>  ValueError: __builtin__.tuple does not appear to be the correct type object
>
> Relevant lines in t.c are::
>
>  $ sed -e '547,551!d' t.c
>    /*--- Function export code ---*/
>    /*--- Type init code ---*/
>    __pyx_ptype_1t_tuple = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME,
> "tuple", sizeof(PyTupleObject)); if (unlikely(!__pyx_ptype_1t_tuple))
> {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno =
> __LINE__; goto __pyx_L1_error;}
>    __pyx_type_1t_MyTuple.tp_base = __pyx_ptype_1t_tuple;
>    if (PyType_Ready(&__pyx_type_1t_MyTuple) < 0) {__pyx_filename =
> __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto
> __pyx_L1_error;}
>
> I'm using Cython 0.11.1; thanks for any help!
>
> Best regards,
> Riccardo
>
> --
> Riccardo Murri, via Rossée 17, 6987 Caslano (CH)
> _______________________________________________
> Cython-dev mailing list
> [email protected]
> http://codespeak.net/mailman/listinfo/cython-dev
>



-- 
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to