| File: | core/runtime/_nrt_pythonmod.c |
| Warning: | line 193, column 5 PyObject ownership leak with reference count of 1 |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | #define NUMBA_EXPORT_FUNC(_rettype)static _rettype static _rettype | |||
| 2 | #define NUMBA_EXPORT_DATA(_vartype)static _vartype static _vartype | |||
| 3 | ||||
| 4 | #include "_nrt_python.c" | |||
| 5 | ||||
| 6 | static PyObject * | |||
| 7 | memsys_shutdown(PyObject *self, PyObject *args) { | |||
| 8 | NRT_MemSys_shutdown(); | |||
| 9 | Py_RETURN_NONEreturn _Py_INCREF(((PyObject*)((&_Py_NoneStruct)))), (& _Py_NoneStruct); | |||
| 10 | } | |||
| 11 | ||||
| 12 | static PyObject * | |||
| 13 | memsys_use_cpython_allocator(PyObject *self, PyObject *args) { | |||
| 14 | NRT_MemSys_set_allocator(PyMem_RawMalloc, | |||
| 15 | PyMem_RawRealloc, | |||
| 16 | PyMem_RawFree); | |||
| 17 | Py_RETURN_NONEreturn _Py_INCREF(((PyObject*)((&_Py_NoneStruct)))), (& _Py_NoneStruct); | |||
| 18 | } | |||
| 19 | ||||
| 20 | static PyObject * | |||
| 21 | memsys_set_atomic_inc_dec(PyObject *self, PyObject *args) { | |||
| 22 | PyObject *addr_inc_obj, *addr_dec_obj; | |||
| 23 | void *addr_inc, *addr_dec; | |||
| 24 | if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "OO", &addr_inc_obj, &addr_dec_obj)) { | |||
| 25 | return NULL((void*)0); | |||
| 26 | } | |||
| 27 | addr_inc = PyLong_AsVoidPtr(addr_inc_obj); | |||
| 28 | if(PyErr_Occurred()) return NULL((void*)0); | |||
| 29 | addr_dec = PyLong_AsVoidPtr(addr_dec_obj); | |||
| 30 | if(PyErr_Occurred()) return NULL((void*)0); | |||
| 31 | NRT_MemSys_set_atomic_inc_dec(addr_inc, addr_dec); | |||
| 32 | Py_RETURN_NONEreturn _Py_INCREF(((PyObject*)((&_Py_NoneStruct)))), (& _Py_NoneStruct); | |||
| 33 | } | |||
| 34 | ||||
| 35 | static PyObject * | |||
| 36 | memsys_set_atomic_cas(PyObject *self, PyObject *args) { | |||
| 37 | PyObject *addr_cas_obj; | |||
| 38 | void *addr_cas; | |||
| 39 | if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "O", &addr_cas_obj)) { | |||
| 40 | return NULL((void*)0); | |||
| 41 | } | |||
| 42 | addr_cas = PyLong_AsVoidPtr(addr_cas_obj); | |||
| 43 | if(PyErr_Occurred()) return NULL((void*)0); | |||
| 44 | NRT_MemSys_set_atomic_cas(addr_cas); | |||
| 45 | Py_RETURN_NONEreturn _Py_INCREF(((PyObject*)((&_Py_NoneStruct)))), (& _Py_NoneStruct); | |||
| 46 | } | |||
| 47 | ||||
| 48 | static PyObject * | |||
| 49 | memsys_get_stats_alloc(PyObject *self, PyObject *args) { | |||
| 50 | return PyLong_FromSize_t(NRT_MemSys_get_stats_alloc()); | |||
| 51 | } | |||
| 52 | ||||
| 53 | static PyObject * | |||
| 54 | memsys_get_stats_free(PyObject *self, PyObject *args) { | |||
| 55 | return PyLong_FromSize_t(NRT_MemSys_get_stats_free()); | |||
| 56 | } | |||
| 57 | ||||
| 58 | static PyObject * | |||
| 59 | memsys_get_stats_mi_alloc(PyObject *self, PyObject *args) { | |||
| 60 | return PyLong_FromSize_t(NRT_MemSys_get_stats_mi_alloc()); | |||
| 61 | } | |||
| 62 | ||||
| 63 | static PyObject * | |||
| 64 | memsys_get_stats_mi_free(PyObject *self, PyObject *args) { | |||
| 65 | return PyLong_FromSize_t(NRT_MemSys_get_stats_mi_free()); | |||
| 66 | } | |||
| 67 | ||||
| 68 | ||||
| 69 | /* | |||
| 70 | * Create a new MemInfo with a owner PyObject | |||
| 71 | */ | |||
| 72 | static PyObject * | |||
| 73 | meminfo_new(PyObject *self, PyObject *args) { | |||
| 74 | PyObject *addr_data_obj; | |||
| 75 | void *addr_data; | |||
| 76 | PyObject *ownerobj; | |||
| 77 | NRT_MemInfo *mi; | |||
| 78 | if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "OO", &addr_data_obj, &ownerobj)) { | |||
| 79 | return NULL((void*)0); | |||
| 80 | } | |||
| 81 | addr_data = PyLong_AsVoidPtr(addr_data_obj); | |||
| 82 | if (PyErr_Occurred()) | |||
| 83 | return NULL((void*)0); | |||
| 84 | mi = NRT_meminfo_new_from_pyobject(addr_data, ownerobj); | |||
| 85 | return PyLong_FromVoidPtr(mi); | |||
| 86 | } | |||
| 87 | ||||
| 88 | /* | |||
| 89 | * Create a new MemInfo with a new NRT allocation | |||
| 90 | */ | |||
| 91 | static PyObject * | |||
| 92 | meminfo_alloc(PyObject *self, PyObject *args) { | |||
| 93 | NRT_MemInfo *mi; | |||
| 94 | Py_ssize_t size; | |||
| 95 | if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "n", &size)) { | |||
| 96 | return NULL((void*)0); | |||
| 97 | } | |||
| 98 | mi = NRT_MemInfo_alloc(size); | |||
| 99 | return PyLong_FromVoidPtr(mi); | |||
| 100 | } | |||
| 101 | ||||
| 102 | /* | |||
| 103 | * Like meminfo_alloc but set memory to zero after allocation and before | |||
| 104 | * deallocation. | |||
| 105 | */ | |||
| 106 | static PyObject * | |||
| 107 | meminfo_alloc_safe(PyObject *self, PyObject *args) { | |||
| 108 | NRT_MemInfo *mi; | |||
| 109 | Py_ssize_t size; | |||
| 110 | if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "n", &size)) { | |||
| 111 | return NULL((void*)0); | |||
| 112 | } | |||
| 113 | mi = NRT_MemInfo_alloc_safe(size); | |||
| 114 | return PyLong_FromVoidPtr(mi); | |||
| 115 | } | |||
| 116 | ||||
| 117 | static PyMethodDef ext_methods[] = { | |||
| 118 | #define declmethod(func) { #func , ( PyCFunction )func , METH_VARARGS0x0001 , NULL((void*)0) } | |||
| 119 | #define declmethod_noargs(func){ "func" , ( PyCFunction )func , 0x0004, ((void*)0) } { #func , ( PyCFunction )func , METH_NOARGS0x0004, NULL((void*)0) } | |||
| 120 | declmethod_noargs(memsys_use_cpython_allocator){ "memsys_use_cpython_allocator" , ( PyCFunction )memsys_use_cpython_allocator , 0x0004, ((void*)0) }, | |||
| 121 | declmethod_noargs(memsys_shutdown){ "memsys_shutdown" , ( PyCFunction )memsys_shutdown , 0x0004 , ((void*)0) }, | |||
| 122 | declmethod(memsys_set_atomic_inc_dec), | |||
| 123 | declmethod(memsys_set_atomic_cas), | |||
| 124 | declmethod_noargs(memsys_get_stats_alloc){ "memsys_get_stats_alloc" , ( PyCFunction )memsys_get_stats_alloc , 0x0004, ((void*)0) }, | |||
| 125 | declmethod_noargs(memsys_get_stats_free){ "memsys_get_stats_free" , ( PyCFunction )memsys_get_stats_free , 0x0004, ((void*)0) }, | |||
| 126 | declmethod_noargs(memsys_get_stats_mi_alloc){ "memsys_get_stats_mi_alloc" , ( PyCFunction )memsys_get_stats_mi_alloc , 0x0004, ((void*)0) }, | |||
| 127 | declmethod_noargs(memsys_get_stats_mi_free){ "memsys_get_stats_mi_free" , ( PyCFunction )memsys_get_stats_mi_free , 0x0004, ((void*)0) }, | |||
| 128 | declmethod(meminfo_new), | |||
| 129 | declmethod(meminfo_alloc), | |||
| 130 | declmethod(meminfo_alloc_safe), | |||
| 131 | { NULL((void*)0) }, | |||
| 132 | #undef declmethod | |||
| 133 | }; | |||
| 134 | ||||
| 135 | ||||
| 136 | ||||
| 137 | static PyObject * | |||
| 138 | build_c_helpers_dict(void) | |||
| 139 | { | |||
| 140 | PyObject *dct = PyDict_New(); | |||
| 141 | if (dct == NULL((void*)0)) | |||
| 142 | goto error; | |||
| 143 | ||||
| 144 | #define _declpointer(name, value)do { PyObject *o = PyLong_FromVoidPtr(value); if (o == ((void *)0)) goto error; if (PyDict_SetItemString(dct, name, o)) { _Py_DECREF (((PyObject*)(o))); goto error; } _Py_DECREF(((PyObject*)(o)) ); } while (0) do { \ | |||
| 145 | PyObject *o = PyLong_FromVoidPtr(value); \ | |||
| 146 | if (o == NULL((void*)0)) goto error; \ | |||
| 147 | if (PyDict_SetItemString(dct, name, o)) { \ | |||
| 148 | Py_DECREF(o)_Py_DECREF(((PyObject*)(o))); \ | |||
| 149 | goto error; \ | |||
| 150 | } \ | |||
| 151 | Py_DECREF(o)_Py_DECREF(((PyObject*)(o))); \ | |||
| 152 | } while (0) | |||
| 153 | ||||
| 154 | #define declmethod(func) _declpointer(#func, &NRT_##func)do { PyObject *o = PyLong_FromVoidPtr(&NRT_##func); if (o == ((void*)0)) goto error; if (PyDict_SetItemString(dct, #func , o)) { _Py_DECREF(((PyObject*)(o))); goto error; } _Py_DECREF (((PyObject*)(o))); } while (0) | |||
| 155 | #define declmethod_internal(func) _declpointer(#func, &func)do { PyObject *o = PyLong_FromVoidPtr(&func); if (o == (( void*)0)) goto error; if (PyDict_SetItemString(dct, #func, o) ) { _Py_DECREF(((PyObject*)(o))); goto error; } _Py_DECREF((( PyObject*)(o))); } while (0) | |||
| 156 | ||||
| 157 | declmethod(adapt_ndarray_from_python); | |||
| 158 | declmethod(adapt_ndarray_to_python_acqref); | |||
| 159 | declmethod(adapt_buffer_from_python); | |||
| 160 | declmethod(meminfo_new_from_pyobject); | |||
| 161 | declmethod(meminfo_as_pyobject); | |||
| 162 | declmethod(meminfo_from_pyobject); | |||
| 163 | declmethod(MemInfo_alloc); | |||
| 164 | declmethod(MemInfo_alloc_safe); | |||
| 165 | declmethod(MemInfo_alloc_aligned); | |||
| 166 | declmethod(MemInfo_alloc_safe_aligned); | |||
| 167 | declmethod(MemInfo_alloc_safe_aligned_external); | |||
| 168 | declmethod_internal(_nrt_get_sample_external_allocator); | |||
| 169 | declmethod(MemInfo_alloc_dtor_safe); | |||
| 170 | declmethod(MemInfo_call_dtor); | |||
| 171 | declmethod(MemInfo_new_varsize); | |||
| 172 | declmethod(MemInfo_new_varsize_dtor); | |||
| 173 | declmethod(MemInfo_varsize_alloc); | |||
| 174 | declmethod(MemInfo_data); | |||
| 175 | declmethod(MemInfo_varsize_free); | |||
| 176 | declmethod(MemInfo_varsize_realloc); | |||
| 177 | declmethod(MemInfo_release); | |||
| 178 | declmethod(Allocate); | |||
| 179 | declmethod(Free); | |||
| 180 | declmethod(get_api); | |||
| 181 | ||||
| 182 | ||||
| 183 | #undef declmethod | |||
| 184 | #undef declmethod_internal | |||
| 185 | return dct; | |||
| 186 | error: | |||
| 187 | Py_XDECREF(dct)_Py_XDECREF(((PyObject*)(dct))); | |||
| 188 | return NULL((void*)0); | |||
| 189 | } | |||
| 190 | ||||
| 191 | MOD_INIT(_nrt_python)PyObject* PyInit__nrt_python(void) { | |||
| 192 | PyObject *m; | |||
| 193 | MOD_DEF(m, "_nrt_python", "No docs", ext_methods){ static struct PyModuleDef moduledef = { { { 1, ((void*)0) } , ((void*)0), 0, ((void*)0), }, "_nrt_python", "No docs", -1, ext_methods, ((void*)0), ((void*)0), ((void*)0), ((void*)0) } ; m = PyModule_Create2(&moduledef, 1013); } | |||
| ||||
| ||||
| 194 | if (m == NULL((void*)0)) | |||
| 195 | return MOD_ERROR_VAL((void*)0); | |||
| 196 | import_array(){if (_import_array() < 0) {PyErr_Print(); PyErr_SetString( PyExc_ImportError, "numpy.core.multiarray failed to import"); return ((void*)0); } }; | |||
| 197 | NRT_MemSys_init(); | |||
| 198 | if (init_nrt_python_module(m)) | |||
| 199 | return MOD_ERROR_VAL((void*)0); | |||
| 200 | ||||
| 201 | Py_INCREF(&MemInfoType)_Py_INCREF(((PyObject*)(&MemInfoType))); | |||
| 202 | PyModule_AddObject(m, "_MemInfo", (PyObject *) (&MemInfoType)); | |||
| 203 | ||||
| 204 | PyModule_AddObject(m, "c_helpers", build_c_helpers_dict()); | |||
| 205 | ||||
| 206 | return MOD_SUCCESS_VAL(m)m; | |||
| 207 | } |
| 1 | #ifndef PyModule_Create2 |
| 2 | PyObject* clang_analyzer_PyObject_New_Reference(); |
| 3 | PyObject* PyModule_Create2(PyModuleDef *def, int module_api_version) { |
| 4 | return clang_analyzer_PyObject_New_Reference(); |
| 5 | } |
| 6 | #else |
| 7 | #warning "API PyModule_Create2 is defined as a macro." |
| 8 | #endif |