code.putln("PyObject* %s;" % Naming.retval_cname)
tempdecl_code = code.insertion_point()
- code.put_setup_refcount_context(header3)
+ code.putln("#ifdef CYTHON_REFNANNY")
+ code.putln("void* __pyx_refchk = NULL;")
+ code.putln("__Pyx_Refnanny = (__Pyx_RefnannyAPIStruct*) PyCObject_Import((char *)\"refnanny\", (char *)\"RefnannyAPI\");")
+ code.putln("if (!__Pyx_Refnanny) Py_FatalError(\"failed to import refnanny module\");")
+ code.putln("__pyx_refchk = __Pyx_Refnanny->NewContext(\"%s\", __LINE__);"% header3)
+ code.putln("#endif")
code.putln("%s = PyTuple_New(0); %s" % (Naming.empty_tuple, code.error_goto_if_null(Naming.empty_tuple, self.pos)));
refcount_utility_code = UtilityCode(proto="""
#ifdef CYTHON_REFNANNY
-__PYX_EXTERN_C void __Pyx_Refnanny_INCREF(void*, PyObject*, int);
-__PYX_EXTERN_C void __Pyx_Refnanny_GOTREF(void*, PyObject*, int);
-__PYX_EXTERN_C void __Pyx_Refnanny_GIVEREF(void*, PyObject*, int);
-__PYX_EXTERN_C void __Pyx_Refnanny_INCREF(void*, PyObject*, int);
-__PYX_EXTERN_C void __Pyx_Refnanny_DECREF(void*, PyObject*, int);
-__PYX_EXTERN_C void* __Pyx_Refnanny_NewContext(char*, int);
-__PYX_EXTERN_C int __Pyx_Refnanny_FinishContext(void*);
-#define __Pyx_INCREF(r) __Pyx_Refnanny_INCREF(__pyx_refchk, r, __LINE__)
-#define __Pyx_GOTREF(r) __Pyx_Refnanny_GOTREF(__pyx_refchk, r, __LINE__)
-#define __Pyx_GIVEREF(r) __Pyx_Refnanny_GIVEREF(__pyx_refchk, r, __LINE__)
-#define __Pyx_DECREF(r) __Pyx_Refnanny_DECREF(__pyx_refchk, r, __LINE__)
+typedef struct {
+ void (*INCREF)(void*, PyObject*, int);
+ void (*DECREF)(void*, PyObject*, int);
+ void (*GOTREF)(void*, PyObject*, int);
+ void (*GIVEREF)(void*, PyObject*, int);
+ void* (*NewContext)(const char*, int);
+ int (*FinishContext)(void*);
+} __Pyx_RefnannyAPIStruct;
+static __Pyx_RefnannyAPIStruct* __Pyx_Refnanny = NULL;
+#define __Pyx_INCREF(r) __Pyx_Refnanny->INCREF(__pyx_refchk, (r), __LINE__)
+#define __Pyx_DECREF(r) __Pyx_Refnanny->DECREF(__pyx_refchk, (r), __LINE__)
#define __Pyx_XDECREF(r) if((r) == NULL) ; else __Pyx_DECREF(r)
+#define __Pyx_GOTREF(r) __Pyx_Refnanny->GOTREF(__pyx_refchk, (r), __LINE__)
+#define __Pyx_GIVEREF(r) __Pyx_Refnanny->GIVEREF(__pyx_refchk, (r), __LINE__)
#define __Pyx_SetupRefcountContext(name) \
- void* __pyx_refchk = __Pyx_Refnanny_NewContext((char*)name, __LINE__)
-#define __Pyx_FinishRefcountContext() __Pyx_Refnanny_FinishContext(__pyx_refchk)
+ void* __pyx_refchk = __Pyx_Refnanny->NewContext((name), __LINE__)
+#define __Pyx_FinishRefcountContext() __Pyx_Refnanny->FinishContext(__pyx_refchk)
#else
#define __Pyx_INCREF(r) Py_INCREF(r)
-#define __Pyx_GOTREF(r)
-#define __Pyx_GIVEREF(r)
#define __Pyx_DECREF(r) Py_DECREF(r)
#define __Pyx_XDECREF(r) Py_XDECREF(r)
+#define __Pyx_GOTREF(r)
+#define __Pyx_GIVEREF(r)
#define __Pyx_SetupRefcountContext(name)
#define __Pyx_FinishRefcountContext() 0
#endif /* CYTHON_REFNANNY */
# print self.errors
raise RefnannyException("\n".join(self.errors))
-cdef public void* __Pyx_Refnanny_NewContext(char* funcname, int lineno) except NULL:
+cdef void* Refnanny_NewContext(char* funcname, int lineno) except NULL:
if exc.PyErr_Occurred() != NULL:
print "error flag set on newcontext?"
return NULL
Py_INCREF(ctx)
return <void*>ctx
-cdef public void __Pyx_Refnanny_GOTREF(void* ctx, void* p_obj, int lineno):
- cdef exc.PyObject* type, *value, *tb
+cdef public void Refnanny_GOTREF(void* ctx, void* p_obj, int lineno):
+ cdef exc.PyObject* type = NULL, *value = NULL, *tb = NULL
if ctx == NULL: return
exc.PyErr_Fetch(&type, &value, &tb)
try:
Py_XDECREF(<object>tb)
raise
-cdef public void __Pyx_Refnanny_GIVEREF(void* ctx, void* p_obj, int lineno):
- cdef exc.PyObject* type, *value, *tb
+cdef public void Refnanny_GIVEREF(void* ctx, void* p_obj, int lineno):
+ cdef exc.PyObject* type = NULL, *value = NULL, *tb = NULL
if ctx == NULL: return
exc.PyErr_Fetch(&type, &value, &tb)
try:
Py_XDECREF(<object>tb)
raise
-cdef public void __Pyx_Refnanny_INCREF(void* ctx, void* obj, int lineno):
+cdef public void Refnanny_INCREF(void* ctx, void* obj, int lineno):
if obj is not NULL: Py_INCREF(<object>obj)
- __Pyx_Refnanny_GOTREF(ctx, obj, lineno)
+ Refnanny_GOTREF(ctx, obj, lineno)
-cdef public void __Pyx_Refnanny_DECREF(void* ctx, void* obj, int lineno):
+cdef public void Refnanny_DECREF(void* ctx, void* obj, int lineno):
# GIVEREF raises exception if we hit 0
#
- __Pyx_Refnanny_GIVEREF(ctx, obj, lineno)
+ Refnanny_GIVEREF(ctx, obj, lineno)
if obj is not NULL: Py_DECREF(<object>obj)
-cdef public int __Pyx_Refnanny_FinishContext(void* ctx) except -1:
- cdef exc.PyObject* type, *value, *tb
+cdef public int Refnanny_FinishContext(void* ctx) except -1:
+ cdef exc.PyObject* type = NULL, *value = NULL, *tb = NULL
if ctx == NULL:
assert False
exc.PyErr_Fetch(&type, &value, &tb)
return 0
+
+
+cdef extern from "Python.h":
+ object PyCObject_FromVoidPtr(void *, void (*)(void*))
+
+ctypedef struct RefnannyAPIStruct:
+ void (*INCREF)(void*, void*, int)
+ void (*DECREF)(void*, void*, int)
+ void (*GOTREF)(void*, void*, int)
+ void (*GIVEREF)(void*, void*, int)
+ void* (*NewContext)(char*, int) except NULL
+ int (*FinishContext)(void*) except -1
+
+cdef RefnannyAPIStruct api
+api.INCREF = Refnanny_INCREF
+api.DECREF = Refnanny_DECREF
+api.GOTREF = Refnanny_GOTREF
+api.GIVEREF = Refnanny_GIVEREF
+api.NewContext = Refnanny_NewContext
+api.FinishContext = Refnanny_FinishContext
+
+RefnannyAPI = PyCObject_FromVoidPtr(&api, NULL)