8000 Some cleanups in _hpy_check_ufunc_fperr · mattip/numpy@a60debf · GitHub
[go: up one dir, main page]

10000 Skip to content

Commit a60debf

Browse files
committed
Some cleanups in _hpy_check_ufunc_fperr
1 parent 0f28fc6 commit a60debf

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

numpy/core/src/umath/extobj.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,9 @@ _hpy_extract_pyvals(HPyContext *ctx, HPy h_ref, const char *name, int *bufsize,
291291
*errmask = UFUNC_ERR_DEFAULT;
292292
}
293293
if (errobj) {
294-
*errobj = HPy_BuildValue(ctx, "NO", HPyBytes_FromString(ctx, name), ctx->h_None);
294+
HPy h_name = HPyBytes_FromString(ctx, name);
295+
*errobj = HPy_BuildValue(ctx, "OO", h_name, ctx->h_None);
296+
HPy_Close(ctx, h_name);
295297
}
296298
if (bufsize) {
297299
*bufsize = NPY_BUFSIZE;
@@ -305,13 +307,12 @@ _hpy_extract_pyvals(HPyContext *ctx, HPy h_ref, const char *name, int *bufsize,
305307
if (errobj) {
306308
PyObject *py_errobj = NULL;
307309
result = _extract_pyvals(py_ref, name, bufsize, errmask, &py_errobj);
308-
Py_DECREF(py_ref);
309310
*errobj = HPy_FromPyObject(ctx, py_errobj);
310-
Py_DECREF(py_errobj);
311+
Py_XDECREF(py_errobj);
311312
} else {
312313
result = _extract_pyvals(py_ref, name, bufsize, errmask, NULL);
313-
Py_DECREF(py_ref);
314314
}
315+
Py_DECREF(py_ref);
315316
return result;
316317
}
317318

@@ -334,7 +335,7 @@ _check_ufunc_fperr(int errmask, PyObject *extobj, const char *ufunc_name) {
334335
NPY_NO_EXPORT int
335336
_hpy_check_ufunc_fperr(HPyContext *ctx, int errmask, HPy extobj, const char *ufunc_name) {
336337
int fperr;
337-
// HPy errobj = HPy_NULL;
338+
HPy errobj = HPy_NULL;
338339
int ret;
339340
int first = 1;
340341
int close_extobj = 0;
@@ -347,28 +348,25 @@ _hpy_check_ufunc_fperr(HPyContext *ctx, int errmask, HPy extobj, const char *ufu
347348
return 0;
348349
}
349350

350-
CAPI_WARN("_hpy_check_ufunc_fperr");
351-
352351
/* Get error object globals */
353352
if (HPy_IsNull(extobj)) {
354-
extobj = HPy_FromPyObject(ctx, get_global_ext_obj());
353+
extobj = hpy_get_global_ext_obj(ctx);
355354
if (HPy_IsNull(extobj) && HPyErr_Occurred(ctx)) {
356355
return -1;
357356
}
358357
close_extobj = 1;
359358
}
360-
PyObject *py_extobj = HPy_AsPyObject(ctx, extobj);
361-
PyObject *py_errobj = NULL;
362-
int r = _extract_pyvals(py_extobj, ufunc_name, NULL, NULL, &py_errobj);
359+
int r = _hpy_extract_pyvals(ctx, extobj, ufunc_name, NULL, NULL, &errobj);
363360
if (close_extobj) {
364361
HPy_Close(ctx, extobj);
365362
}
366363
if (r < 0) {
367-
// HPy_Close(ctx, errobj);
368-
Py_XDECREF(py_errobj);
364+
HPy_Close(ctx, errobj);
369365
return -1;
370366
}
371367

368+
CAPI_WARN("_hpy_check_ufunc_fperr");
369+
PyObject *py_errobj = HPy_IsNull(errobj) ? NULL : HPy_AsPyObject(ctx, errobj);
372370
ret = PyUFunc_handlefperr(errmask, py_errobj, fperr, &first);
373371
// HPy_Close(ctx, errobj);
374372
Py_XDECREF(py_errobj);
@@ -414,4 +412,4 @@ _hpy_get_bufsize_errmask(HPyContext *ctx, HPy extobj, const char *ufunc_name,
414412
}
415413

416414
return 0;
417-
}
415+
}

0 commit comments

Comments
 (0)
0