| File: | _helpermod.c |
| Warning: | line 287, column 5 PyObject ownership leak with reference count of 1 |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* | |||
| 2 | Expose all functions as pointers in a dedicated C extension. | |||
| 3 | */ | |||
| 4 | #include "cext/cext.h" | |||
| 5 | /* Import _pymodule.h first, for a recent _POSIX_C_SOURCE */ | |||
| 6 | #include "_pymodule.h" | |||
| 7 | ||||
| 8 | #include <math.h> | |||
| 9 | #ifdef _MSC_VER | |||
| 10 | #define false0 0 | |||
| 11 | #define true1 1 | |||
| 12 | #define bool_Bool int | |||
| 13 | #else | |||
| 14 | #include <stdbool.h> | |||
| 15 | #endif | |||
| 16 | ||||
| 17 | /* | |||
| 18 | Include C-extension here | |||
| 19 | */ | |||
| 20 | #include "cext/cext.h" | |||
| 21 | ||||
| 22 | /* Numba C helpers */ | |||
| 23 | #include "_helperlib.c" | |||
| 24 | ||||
| 25 | /* Numpy C math function exports */ | |||
| 26 | #include "_npymath_exports.c" | |||
| 27 | ||||
| 28 | static PyObject * | |||
| 29 | build_c_helpers_dict(void) | |||
| 30 | { | |||
| 31 | PyObject *dct = PyDict_New(); | |||
| 32 | if (dct == NULL((void*)0)) | |||
| 33 | goto error; | |||
| 34 | ||||
| 35 | #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 { \ | |||
| 36 | PyObject *o = PyLong_FromVoidPtr(value); \ | |||
| 37 | if (o == NULL((void*)0)) goto error; \ | |||
| 38 | if (PyDict_SetItemString(dct, name, o)) { \ | |||
| 39 | Py_DECREF(o)_Py_DECREF(((PyObject*)(o))); \ | |||
| 40 | goto error; \ | |||
| 41 | } \ | |||
| 42 | Py_DECREF(o)_Py_DECREF(((PyObject*)(o))); \ | |||
| 43 | } while (0) | |||
| 44 | ||||
| 45 | #define declmethod(func) _declpointer(#func, &numba_##func)do { PyObject *o = PyLong_FromVoidPtr(&numba_##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) | |||
| 46 | ||||
| 47 | #define declpointer(ptr)do { PyObject *o = PyLong_FromVoidPtr(&numba_ptr); if (o == ((void*)0)) goto error; if (PyDict_SetItemString(dct, "ptr", o)) { _Py_DECREF(((PyObject*)(o))); goto error; } _Py_DECREF (((PyObject*)(o))); } while (0) _declpointer(#ptr, &numba_##ptr)do { PyObject *o = PyLong_FromVoidPtr(&numba_##ptr); if ( o == ((void*)0)) goto error; if (PyDict_SetItemString(dct, #ptr , o)) { _Py_DECREF(((PyObject*)(o))); goto error; } _Py_DECREF (((PyObject*)(o))); } while (0) | |||
| 48 | ||||
| 49 | declmethod(fixed_fmod); | |||
| 50 | declmethod(fixed_fmodf); | |||
| 51 | declmethod(set_fnclex); | |||
| 52 | ||||
| 53 | declmethod(sdiv); | |||
| 54 | declmethod(srem); | |||
| 55 | declmethod(udiv); | |||
| 56 | declmethod(urem); | |||
| 57 | declmethod(frexp); | |||
| 58 | declmethod(frexpf); | |||
| 59 | declmethod(ldexp); | |||
| 60 | declmethod(ldexpf); | |||
| 61 | declmethod(cpow); | |||
| 62 | declmethod(cpowf); | |||
| 63 | declmethod(erf); | |||
| 64 | declmethod(erff); | |||
| 65 | declmethod(erfc); | |||
| 66 | declmethod(erfcf); | |||
| 67 | declmethod(gamma); | |||
| 68 | declmethod(gammaf); | |||
| 69 | declmethod(lgamma); | |||
| 70 | declmethod(lgammaf); | |||
| 71 | declmethod(signbit); | |||
| 72 | declmethod(signbitf); | |||
| 73 | declmethod(complex_adaptor); | |||
| 74 | declmethod(adapt_ndarray); | |||
| 75 | declmethod(ndarray_new); | |||
| 76 | declmethod(extract_record_data); | |||
| 77 | declmethod(get_buffer); | |||
| 78 | declmethod(adapt_buffer); | |||
| 79 | declmethod(release_buffer); | |||
| 80 | declmethod(extract_np_datetime); | |||
| 81 | declmethod(create_np_datetime); | |||
| 82 | declmethod(extract_np_timedelta); | |||
| 83 | declmethod(create_np_timedelta); | |||
| 84 | declmethod(recreate_record); | |||
| 85 | declmethod(fptoui); | |||
| 86 | declmethod(fptouif); | |||
| 87 | declmethod(gil_ensure); | |||
| 88 | declmethod(gil_release); | |||
| 89 | declmethod(fatal_error); | |||
| 90 | declmethod(py_type); | |||
| 91 | declmethod(unpack_slice); | |||
| 92 | declmethod(do_raise); | |||
| 93 | declmethod(unpickle); | |||
| 94 | declmethod(attempt_nocopy_reshape); | |||
| 95 | declmethod(get_pyobject_private_data); | |||
| 96 | declmethod(set_pyobject_private_data); | |||
| 97 | declmethod(reset_pyobject_private_data); | |||
| 98 | ||||
| 99 | /* BLAS / LAPACK */ | |||
| 100 | declmethod(xxgemm); | |||
| 101 | declmethod(xxgemv); | |||
| 102 | declmethod(xxdot); | |||
| 103 | declmethod(xxgetrf); | |||
| 104 | declmethod(ez_xxgetri); | |||
| 105 | declmethod(xxpotrf); | |||
| 106 | declmethod(ez_rgeev); | |||
| 107 | declmethod(ez_cgeev); | |||
| 108 | declmethod(ez_xxxevd); | |||
| 109 | declmethod(ez_gesdd); | |||
| 110 | declmethod(ez_geqrf); | |||
| 111 | declmethod(ez_xxgqr); | |||
| 112 | declmethod(ez_gelsd); | |||
| 113 | declmethod(xgesv); | |||
| 114 | declmethod(xxnrm2); | |||
| 115 | ||||
| 116 | /* PRNG support */ | |||
| 117 | declmethod(get_py_random_state); | |||
| 118 | declmethod(get_np_random_state); | |||
| 119 | declmethod(rnd_shuffle); | |||
| 120 | declmethod(rnd_init); | |||
| 121 | declmethod(poisson_ptrs); | |||
| 122 | ||||
| 123 | /* Unicode string support */ | |||
| 124 | declmethod(extract_unicode); | |||
| 125 | declmethod(gettyperecord); | |||
| 126 | declmethod(get_PyUnicode_ExtendedCase); | |||
| 127 | ||||
| 128 | /* for gdb breakpoint */ | |||
| 129 | declmethod(gdb_breakpoint); | |||
| 130 | ||||
| 131 | /* for dictionary support */ | |||
| 132 | declmethod(test_dict); | |||
| 133 | declmethod(dict_new_minsize); | |||
| 134 | declmethod(dict_set_method_table); | |||
| 135 | declmethod(dict_free); | |||
| 136 | declmethod(dict_length); | |||
| 137 | declmethod(dict_lookup); | |||
| 138 | declmethod(dict_insert); | |||
| 139 | declmethod(dict_insert_ez); | |||
| 140 | declmethod(dict_delitem); | |||
| 141 | declmethod(dict_popitem); | |||
| 142 | declmethod(dict_iter_sizeof); | |||
| 143 | declmethod(dict_iter); | |||
| 144 | declmethod(dict_iter_next); | |||
| 145 | declmethod(dict_dump); | |||
| 146 | ||||
| 147 | /* for list support */ | |||
| 148 | declmethod(test_list); | |||
| 149 | declmethod(list_new); | |||
| 150 | declmethod(list_set_method_table); | |||
| 151 | declmethod(list_free); | |||
| 152 | declmethod(list_base_ptr); | |||
| 153 | declmethod(list_size_address); | |||
| 154 | declmethod(list_length); | |||
| 155 | declmethod(list_allocated); | |||
| 156 | declmethod(list_is_mutable); | |||
| 157 | declmethod(list_set_is_mutable); | |||
| 158 | declmethod(list_setitem); | |||
| 159 | declmethod(list_getitem); | |||
| 160 | declmethod(list_append); | |||
| 161 | declmethod(list_delitem); | |||
| 162 | declmethod(list_delete_slice); | |||
| 163 | declmethod(list_iter_sizeof); | |||
| 164 | declmethod(list_iter); | |||
| 165 | declmethod(list_iter_next); | |||
| 166 | ||||
| 167 | #define MATH_UNARY(F, R, A) declmethod(F); | |||
| 168 | #define MATH_BINARY(F, R, A, B) declmethod(F); | |||
| 169 | #include "mathnames.h" | |||
| 170 | #undef MATH_UNARY | |||
| 171 | #undef MATH_BINARY | |||
| 172 | ||||
| 173 | #undef declmethod | |||
| 174 | return dct; | |||
| 175 | error: | |||
| 176 | Py_XDECREF(dct)_Py_XDECREF(((PyObject*)(dct))); | |||
| 177 | return NULL((void*)0); | |||
| 178 | } | |||
| 179 | ||||
| 180 | static int | |||
| 181 | register_npymath_exports(PyObject *dct) | |||
| 182 | { | |||
| 183 | size_t count = sizeof(npymath_exports) / sizeof(npymath_exports[0]); | |||
| 184 | size_t i; | |||
| 185 | ||||
| 186 | for (i = 0; i < count; ++i) { | |||
| 187 | PyObject *ptr = PyLong_FromVoidPtr(npymath_exports[i].func); | |||
| 188 | if (ptr == NULL((void*)0)) | |||
| 189 | return -1; | |||
| 190 | if (PyDict_SetItemString(dct, npymath_exports[i].name, ptr) < 0) { | |||
| 191 | Py_DECREF(ptr)_Py_DECREF(((PyObject*)(ptr))); | |||
| 192 | return -1; | |||
| 193 | } | |||
| 194 | Py_DECREF(ptr)_Py_DECREF(((PyObject*)(ptr))); | |||
| 195 | } | |||
| 196 | ||||
| 197 | return 0; | |||
| 198 | } | |||
| 199 | ||||
| 200 | static PyObject * | |||
| 201 | build_npymath_exports_dict(void) | |||
| 202 | { | |||
| 203 | PyObject *dct = PyDict_New(); | |||
| 204 | if (dct != NULL((void*)0)) { | |||
| 205 | if (register_npymath_exports(dct) < 0) | |||
| 206 | Py_CLEAR(dct)do { PyObject *_py_tmp = ((PyObject*)(dct)); if (_py_tmp != ( (void*)0)) { (dct) = ((void*)0); _Py_DECREF(((PyObject*)(_py_tmp ))); } } while (0); | |||
| 207 | } | |||
| 208 | return dct; | |||
| 209 | } | |||
| 210 | ||||
| 211 | ||||
| 212 | /* | |||
| 213 | * Helper to deal with flushing stdout | |||
| 214 | */ | |||
| 215 | PyAPI_FUNC(void)void _numba_flush_stdout(void) ; | |||
| 216 | ||||
| 217 | void | |||
| 218 | _numba_flush_stdout(void) { | |||
| 219 | fflush(stdoutstdout); | |||
| 220 | } | |||
| 221 | ||||
| 222 | ||||
| 223 | static PyMethodDef ext_methods[] = { | |||
| 224 | { "rnd_get_state", (PyCFunction) _numba_rnd_get_state, METH_O0x0008, NULL((void*)0) }, | |||
| 225 | { "rnd_get_py_state_ptr", (PyCFunction) _numba_rnd_get_py_state_ptr, METH_NOARGS0x0004, NULL((void*)0) }, | |||
| 226 | { "rnd_get_np_state_ptr", (PyCFunction) _numba_rnd_get_np_state_ptr, METH_NOARGS0x0004, NULL((void*)0) }, | |||
| 227 | { "rnd_seed", (PyCFunction) _numba_rnd_seed, METH_VARARGS0x0001, NULL((void*)0) }, | |||
| 228 | { "rnd_set_state", (PyCFunction) _numba_rnd_set_state, METH_VARARGS0x0001, NULL((void*)0) }, | |||
| 229 | { "rnd_shuffle", (PyCFunction) _numba_rnd_shuffle, METH_O0x0008, NULL((void*)0) }, | |||
| 230 | { "_import_cython_function", (PyCFunction) _numba_import_cython_function, METH_VARARGS0x0001, NULL((void*)0) }, | |||
| 231 | { NULL((void*)0) }, | |||
| 232 | }; | |||
| 233 | ||||
| 234 | /* | |||
| 235 | * These functions are exported by the module's DLL, to exercise ctypes / cffi | |||
| 236 | * without relying on libc availability (see https://bugs.python.org/issue23606) | |||
| 237 | */ | |||
| 238 | ||||
| 239 | PyAPI_FUNC(double)double _numba_test_sin(double x); | |||
| 240 | PyAPI_FUNC(double)double _numba_test_cos(double x); | |||
| 241 | PyAPI_FUNC(double)double _numba_test_exp(double x); | |||
| 242 | PyAPI_FUNC(void)void _numba_test_vsquare(int n, double *x, double *out); | |||
| 243 | PyAPI_FUNC(double)double _numba_test_funcptr(double (*func)(double)); | |||
| 244 | PyAPI_FUNC(bool)_Bool _numba_test_boolean(void); | |||
| 245 | ||||
| 246 | double _numba_test_sin(double x) | |||
| 247 | { | |||
| 248 | return sin(x); | |||
| 249 | } | |||
| 250 | ||||
| 251 | double _numba_test_cos(double x) | |||
| 252 | { | |||
| 253 | return cos(x); | |||
| 254 | } | |||
| 255 | ||||
| 256 | double _numba_test_exp(double x) | |||
| 257 | { | |||
| 258 | return exp(x); | |||
| 259 | } | |||
| 260 | ||||
| 261 | void _numba_test_vsquare(int n, double *x, double *out) | |||
| 262 | { | |||
| 263 | int i; | |||
| 264 | for (i = 0; i < n; i++) | |||
| 265 | out[i] = pow(x[i], 2.0); | |||
| 266 | } | |||
| 267 | ||||
| 268 | void _numba_test_vcube(int n, double *x, double *out) | |||
| 269 | { | |||
| 270 | int i; | |||
| 271 | for (i = 0; i < n; i++) | |||
| 272 | out[i] = pow(x[i], 3.0); | |||
| 273 | } | |||
| 274 | ||||
| 275 | double _numba_test_funcptr(double (*func)(double)) | |||
| 276 | { | |||
| 277 | return func(1.5); | |||
| 278 | } | |||
| 279 | ||||
| 280 | bool_Bool _numba_test_boolean() | |||
| 281 | { | |||
| 282 | return true1; | |||
| 283 | } | |||
| 284 | ||||
| 285 | MOD_INIT(_helperlib)PyObject* PyInit__helperlib(void) { | |||
| 286 | PyObject *m; | |||
| 287 | MOD_DEF(m, "_helperlib", "No docs", ext_methods){ static struct PyModuleDef moduledef = { { { 1, ((void*)0) } , ((void*)0), 0, ((void*)0), }, "_helperlib", "No docs", -1, ext_methods , ((void*)0), ((void*)0), ((void*)0), ((void*)0) }; m = PyModule_Create2 (&moduledef, 1013); } | |||
| ||||
| ||||
| 288 | if (m == NULL((void*)0)) | |||
| 289 | return MOD_ERROR_VAL((void*)0); | |||
| 290 | ||||
| 291 | import_array(){if (_import_array() < 0) {PyErr_Print(); PyErr_SetString( PyExc_ImportError, "numpy.core.multiarray failed to import"); return ((void*)0); } }; | |||
| 292 | ||||
| 293 | PyModule_AddObject(m, "c_helpers", build_c_helpers_dict()); | |||
| 294 | PyModule_AddObject(m, "npymath_exports", build_npymath_exports_dict()); | |||
| 295 | PyModule_AddIntConstant(m, "long_min", LONG_MIN(-9223372036854775807L -1L)); | |||
| 296 | PyModule_AddIntConstant(m, "long_max", LONG_MAX9223372036854775807L); | |||
| 297 | PyModule_AddIntConstant(m, "py_buffer_size", sizeof(Py_buffer)); | |||
| 298 | PyModule_AddIntConstant(m, "py_gil_state_size", sizeof(PyGILState_STATE)); | |||
| 299 | PyModule_AddIntConstant(m, "py_unicode_1byte_kind", PyUnicode_1BYTE_KIND); | |||
| 300 | PyModule_AddIntConstant(m, "py_unicode_2byte_kind", PyUnicode_2BYTE_KIND); | |||
| 301 | PyModule_AddIntConstant(m, "py_unicode_4byte_kind", PyUnicode_4BYTE_KIND); | |||
| 302 | PyModule_AddIntConstant(m, "py_unicode_wchar_kind", PyUnicode_WCHAR_KIND); | |||
| 303 | numba_rnd_ensure_global_init(); | |||
| 304 | ||||
| 305 | return MOD_SUCCESS_VAL(m)m; | |||
| 306 | } |
| 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 |