Home > Software engineering >  Cython: Linked List of Extension Type
Cython: Linked List of Extension Type

Time:11-05

I need a linked list using Cython extension type ie. cdef class but the Cython compiler complains about Python object.

cdef class Item:
    cdef Item* prev
    cdef Item* next

Cython error: Pointer base type cannot be a Python object

It would be cdef struct but any work-around for using cdef class? (coz I need methods and OOP convention)

CodePudding user response:

cdef class is like any other Python object and is stored/passed by reference.

This means that it isn't necessary to use pointers here: the internal representation is already stored with pointers. Therefore just use cdef Item.

As with any other Python object, your Item will be reference counted and will be automatically reallocated when no other reference exists to it.

  • Related