> I was wrong.  A buffer of the type
> cdef object[int] myhash
> can only be declared locally inside some function or method.


Then write an extension class that wraps the buffer, and store one on
module scope. Something like this (not tested):


DEF BUF_SIZE = 32

import myclass # your extension class

from python cimport PyObject, Py_INCREF, Py_DECREF

cdef class bufferwrapper:

    cdef PyObject *buffer[BUF_SIZE]

    def __cinit__(bufferwrapper self):
        cdef int n
        for n in range(BUF_SIZE):
            self.buffer[n] = NULL

    def __init__(bufferwrapper self):
        cdef int n
        cdef object tmp
        for n in range(BUF_SIZE):
            tmp = myclass.myclass()
            Py_INCREF(tmp)
            self.buffer[n] = <PyObject*> tmp

    def __dealloc__(bufferwrapper self):
        cdef int n
        for n in range(BUF_SIZE):
            if self.buffer[n] != NULL:
                Py_DECREF(<object> self.buffer[n])

cdef bufferwrapper _buffer = bufferwrapper()

def foobar(int hashvalue):
    cdef object obj
    obj = <object> _buffer.buffer[hashvalue]



Regards,
Sturla Molden




_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to