8000 MAINT: Allow errors to escape from InitOperators · numpy/numpy@477bbc0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 477bbc0

Browse files
committed
MAINT: Allow errors to escape from InitOperators
1 parent e3c7433 commit 477bbc0

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

numpy/core/code_generators/generate_umath.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,10 @@ def make_ufuncs(funcdict):
10451045
{name}_functions, {name}_data, {name}_signatures, {nloops},
10461046
{nin}, {nout}, {identity}, "{name}",
10471047
"{doc}", 0
1048-
);""")
1048+
);
1049+
if (f == NULL) {{
1050+
return -1;
1051+
}}""")
10491052
mlist.append(fmt.format(
10501053
name=name, nloops=len(uf.type_descriptions),
10511054
nin=uf.nin, nout=uf.nout, identity=uf.identity, doc=docstring
@@ -1073,12 +1076,14 @@ def make_code(funcdict, filename):
10731076
10741077
%s
10751078
1076-
static void
1079+
static int
10771080
InitOperators(PyObject *dictionary) {
10781081
PyObject *f;
10791082
10801083
%s
10811084
%s
1085+
1086+
return 0;
10821087
}
10831088
""") % (filename, code1, code2, code3)
10841089
return code

numpy/core/src/umath/umathmodule.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,9 @@ PyMODINIT_FUNC initumath(void)
364364
Py_DECREF(s);
365365

366366
/* Load the ufunc operators into the array module's namespace */
367-
InitOperators(d);
367+
if (InitOperators(d) < 0) {
368+
goto err;
369+
}
368370

369371
PyDict_SetItemString(d, "pi", s = PyFloat_FromDouble(NPY_PI));
370372
Py_DECREF(s);

0 commit comments

Comments
 (0)
0