[Pyrex] Ugly reference counting problem ahead!

Florian Schulze florian.proff.schulze at gmx.net
Sat Jul 19 00:47:07 CEST 2003


Hi!

I got a problem with self generated objects and reference counting. 
Function test1 leaks memory and in test2 I fixed that, but it's ugly. Can 
this be done easier? I use this in my own file like class and this is the 
most efficent way I found. I can send I the full class on request. Or you 
can look in python/Objects/fileobject.c in the file_read function. I 
closely follow it.

Regards,
Florian Schulze

cdef extern from "Python.h":
    ctypedef extern struct PyObject

    PyObject *PyString_FromStringAndSize(char *v, int len)
    void Py_DECREF(PyObject *)

def test1():
    cdef PyObject *rv

    rv = PyString_FromStringAndSize(NULL, 200000)
    return <object>rv

def test2():
    cdef PyObject *rv
    cdef object dummy

    rv = PyString_FromStringAndSize(NULL, 200000)
    dummy = <object>rv
    Py_DECREF(<PyObject *>dummy)
    return dummy






More information about the Pyrex mailing list