Weird little glitch in wrapper code

Was looking into mitigating some of the slowdown from the recent fix, mainly be rewriting this little function:

@classmethod
def from_param( cls, instance, typeCode=None ):
try:
pointer = cls.dataPointer( instance )
except TypeError, err:
array = cls.asArray( instance, typeCode )
pp = ctypes.c_void_p( cls.dataPointer( array ) )
pp._temporary_array_ = (array,)
return pp
else:
return ctypes.c_void_p( pointer )

With this little bit of Cython:

cdef class FromParam:
    cdef public object dataPointer, asArray
    cdef list converted
    def __init__( self, dataPointer, asArray ):
        self.dataPointer = dataPointer
        self.asArray = asArray
    def __call__( self, cls, instance, typeCode=None ):
        try:
            pointer = self.dataPointer( instance )
        except TypeError, err:
            array = self.asArray( instance, typeCode )
            dp = self.dataPointer( array )
            pp = c_void_p( dp )
            pp.temporary_array = array
            return pp
        else:
            return c_void_p( pointer )

But if I use the C version I get a failure from deep within the code saying that there's a problem with deallocating the array.  I gather there's something subtly different about the two mechanisms, but I haven't as yet figured out what that would be.  I'm thinking maybe it's interacting poorly with OpenGLContext's weakref-based cache system or something similarly freaky.

Comments

Comments are closed.

Pingbacks

Pingbacks are closed.