8000 BUG: Avoid SystemErrors by checking the return value of PyPrint by eric-wieser · Pull Request #12266 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: Avoid SystemErrors by checking the return value of PyPrint #12266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 1, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions numpy/core/src/multiarray/dtype_transfer.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@
#endif
/**********************************************/

#if NPY_DT_DBG_TRACING
/*
* Thin wrapper around print that ignores exceptions
*/
static void
_safe_print(PyObject *obj)
{
if (PyObject_Print(obj, stdout, 0) < 0) {
PyErr_Clear();
printf("<error during print>");
}
}
#endif

/*
* Returns a transfer function which DECREFs any references in src_type.
*
Expand Down Expand Up @@ -1042,9 +1056,9 @@ get_nbo_cast_datetime_transfer_function(int aligned,

#if NPY_DT_DBG_TRACING
printf("Dtype transfer from ");
PyObject_Print((PyObject *)src_dtype, stdout, 0);
_safe_print((PyObject *)src_dtype);
printf(" to ");
PyObject_Print((PyObject *)dst_dtype, stdout, 0);
_safe_print((PyObject *)dst_dtype);
printf("\n");
printf("has conversion fraction %lld/%lld\n", num, denom);
#endif
Expand Down Expand Up @@ -1089,9 +1103,9 @@ get_nbo_datetime_to_string_transfer_function(int aligned,

#if NPY_DT_DBG_TRACING
printf("Dtype transfer from ");
PyObject_Print((PyObject *)src_dtype, stdout, 0);
_safe_print((PyObject *)src_dtype);
printf(" to ");
PyObject_Print((PyObject *)dst_dtype, stdout, 0);
_safe_print((PyObject *)dst_dtype);
printf("\n");
#endif

Expand Down Expand Up @@ -1211,9 +1225,9 @@ get_nbo_string_to_datetime_transfer_function(int aligned,

#if NPY_DT_DBG_TRACING
printf("Dtype transfer from ");
PyObject_Print((PyObject *)src_dtype, stdout, 0);
_safe_print((PyObject *)src_dtype);
printf(" to ");
PyObject_Print((PyObject *)dst_dtype, stdout, 0);
_safe_print((PyObject *)dst_dtype);
printf("\n");
#endif

Expand Down Expand Up @@ -3421,9 +3435,13 @@ PyArray_GetDTypeTransferFunction(int aligned,

#if NPY_DT_DBG_TRACING
printf("Calculating dtype transfer from ");
PyObject_Print((PyObject *)src_dtype, stdout, 0);
if (PyObject_Print((PyObject *)src_dtype, stdout, 0) < 0) {
return NPY_FAIL;
}
printf(" to ");
PyObject_Print((PyObject *)dst_dtype, stdout, 0);
if (PyObject_Print((PyObject *)dst_dtype, stdout, 0) < 0) {
return NPY_FAIL;
}
printf("\n");
#endif

Expand Down
0