mirror of
https://github.com/opencv/opencv.git
synced 2025-07-26 07:07:37 +08:00
Merge pull request #23350 from spikethehobbitmage:4.x
Fix reference counting errors in registerNewType
This commit is contained in:
commit
66a5ecb7ec
@ -284,6 +284,7 @@ static bool init_submodule(PyObject * root, const char * name, PyMethodDef * met
|
|||||||
static inline
|
static inline
|
||||||
bool registerTypeInModuleScope(PyObject* module, const char* type_name, PyObject* type_obj)
|
bool registerTypeInModuleScope(PyObject* module, const char* type_name, PyObject* type_obj)
|
||||||
{
|
{
|
||||||
|
Py_INCREF(type_obj); /// Give PyModule_AddObject a reference to steal.
|
||||||
if (PyModule_AddObject(module, type_name, type_obj) < 0)
|
if (PyModule_AddObject(module, type_name, type_obj) < 0)
|
||||||
{
|
{
|
||||||
PyErr_Format(PyExc_ImportError,
|
PyErr_Format(PyExc_ImportError,
|
||||||
|
@ -338,8 +338,10 @@ PyObject* pyopencv_from(const TYPE& src)
|
|||||||
if (!registerNewType(m, #EXPORT_NAME, (PyObject*)pyopencv_##CLASS_ID##_TypePtr, SCOPE)) \
|
if (!registerNewType(m, #EXPORT_NAME, (PyObject*)pyopencv_##CLASS_ID##_TypePtr, SCOPE)) \
|
||||||
{ \
|
{ \
|
||||||
printf("Failed to register a new type: " #EXPORT_NAME ", base (" #BASE ") in " SCOPE " \n"); \
|
printf("Failed to register a new type: " #EXPORT_NAME ", base (" #BASE ") in " SCOPE " \n"); \
|
||||||
|
Py_DECREF(pyopencv_##CLASS_ID##_TypePtr); \
|
||||||
ERROR_HANDLER; \
|
ERROR_HANDLER; \
|
||||||
} \
|
} \
|
||||||
|
Py_DECREF(pyopencv_##CLASS_ID##_TypePtr); \
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debug module load:
|
// Debug module load:
|
||||||
|
Loading…
Reference in New Issue
Block a user