| 67 | */ |
| 68 | |
| 69 | NPY_NO_EXPORT int |
| 70 | _error_handler(int method, PyObject *errobj, char *errtype, int retstatus, int *first) |
| 71 | { |
| 72 | PyObject *pyfunc, *ret, *args; |
| 73 | char *name = PyBytes_AS_STRING(PyTuple_GET_ITEM(errobj,0)); |
| 74 | char msg[100]; |
| 75 | |
| 76 | NPY_ALLOW_C_API_DEF |
| 77 | |
| 78 | /* don't need C API for a simple ignore */ |
| 79 | if (method == UFUNC_ERR_IGNORE) { |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | /* don't need C API for a simple print */ |
| 84 | if (method == UFUNC_ERR_PRINT) { |
| 85 | if (*first) { |
| 86 | fprintf(stderr, "Warning: %s encountered in %s\n", errtype, name); |
| 87 | *first = 0; |
| 88 | } |
| 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | NPY_ALLOW_C_API; |
| 93 | switch(method) { |
| 94 | case UFUNC_ERR_WARN: |
| 95 | PyOS_snprintf(msg, sizeof(msg), "%s encountered in %s", errtype, name); |
| 96 | if (PyErr_Warn(PyExc_RuntimeWarning, msg) < 0) { |
| 97 | goto fail; |
| 98 | } |
| 99 | break; |
| 100 | case UFUNC_ERR_RAISE: |
| 101 | PyErr_Format(PyExc_FloatingPointError, "%s encountered in %s", |
| 102 | errtype, name); |
| 103 | goto fail; |
| 104 | case UFUNC_ERR_CALL: |
| 105 | pyfunc = PyTuple_GET_ITEM(errobj, 1); |
| 106 | if (pyfunc == Py_None) { |
| 107 | PyErr_Format(PyExc_NameError, |
| 108 | "python callback specified for %s (in " \ |
| 109 | " %s) but no function found.", |
| 110 | errtype, name); |
| 111 | goto fail; |
| 112 | } |
| 113 | args = Py_BuildValue("NN", PyUnicode_FromString(errtype), |
| 114 | PyLong_FromLong((long) retstatus)); |
| 115 | if (args == NULL) { |
| 116 | goto fail; |
| 117 | } |
| 118 | ret = PyObject_CallObject(pyfunc, args); |
| 119 | Py_DECREF(args); |
| 120 | if (ret == NULL) { |
| 121 | goto fail; |
| 122 | } |
| 123 | Py_DECREF(ret); |
| 124 | break; |
| 125 | case UFUNC_ERR_LOG: |
| 126 | if (first) { |
nothing calls this directly
no outgoing calls
no test coverage detected