> What I tried is:
> cdef extern from "Python.h":
>        Py_INCREF(obj)
>        Py_DECREF(obj)
>

It may not make a difference, but try (object) instead.

To use Py_INCREF you need to be holding the GIL.  Same for DECREF.
You also need to call these /before/ the respective object can be
garbage collected.  This means if the object in question is passed via
property, before that property __set__ returns you have to INCREF it.

If you're putting it in a hash table from a nogil function, then
however the Python function got passed in to be stored for use by that
function, you have to INCREF it before that setting function returns.

I can't give much more advice without seeing how you're using it in
context, but some sample code from PySoy's use of glib merged with
your line of code:

You probably have this already:
  ctypedef void*           gpointer
  cdef void        g_hash_table_insert            ( GHashTable*,
gpointer, gpointer )

A typical use case would be as follows:

def foo(key, dataElement) :
  cdef glib.gchar* _key
  _key = glib.g_strdup(key)
  Py_INCREF(dataElement)
  g_hash_table_insert(mapping, _key, <void*> dataElement)
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to