8000 Backport PR #14491 on branch v3.1.x (Fix uses of PyObject_IsTrue.) by meeseeksmachine · Pull Request #14497 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Backport PR #14491 on branch v3.1.x (Fix uses of PyObject_IsTrue.) #14497

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
Show file tree
Hide file tree
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
16 changes: 12 additions & 4 deletions src/_path_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,12 @@ static PyObject *Py_cleanup_path(PyObject *self, PyObject *args, PyObject *kwds)

if (simplifyobj == Py_None) {
simplify = path.should_simplify();
} else if (PyObject_IsTrue(simplifyobj)) {
simplify = true;
} else {
switch (PyObject_IsTrue(simplifyobj)) {
case 0: simplify = false; break;
case 1: simplify = true; break;
default: return NULL; // errored.
}
}

bool do_clip = (clip_rect.x1 < clip_rect.x2 && clip_rect.y1 < clip_rect.y2);
Expand Down Expand Up @@ -709,8 +713,12 @@ static PyObject *Py_convert_to_string(PyObject *self, PyObject *args, PyObject *

if (simplifyobj == Py_None) {
simplify = path.should_simplify();
} else if (PyObject_IsTrue(simplifyobj)) {
simplify = true;
} else {
switch (PyObject_IsTrue(simplifyobj)) {
case 0: simplify = false; break;
case 1: simplify = true; break;
default: return NULL; // errored.
}
}

CALL_CPP("convert_to_string",
Expand Down
27 changes: 14 additions & 13 deletions src/py_converters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,11 @@ int convert_double(PyObject *obj, void *p)
int convert_bool(PyObject *obj, void *p)
{
bool *val = (bool *)p;
int ret;

ret = PyObject_IsTrue(obj);
if (ret == -1) {
return 0;
switch (PyObject_IsTrue(obj)) {
case 0: *val = false; break;
case 1: *val = true; break;
default: return 0; // errored.
}
*val = ret != 0;

return 1;
}

Expand Down Expand Up @@ -389,7 +386,11 @@ int convert_path(PyObject *obj, void *pathp)
if (should_simplify_obj == NULL) {
goto exit;
}
should_simplify = PyObject_IsTrue(should_simplify_obj) != 0;
switch (PyObject_IsTrue(should_simplify_obj)) {
case 0: should_simplify = 0; break;
case 1: should_simplify = 1; break;
default: goto exit; // errored.
}

simplify_threshold_obj = PyObject_GetAttrString(obj, "simplify_threshold");
if (simplify_threshold_obj == NULL) {
Expand Down Expand Up @@ -438,15 +439,15 @@ int convert_clippath(PyObject *clippath_tuple, void *clippathp)
int convert_snap(PyObject *obj, void *snapp)
{
e_snap_mode *snap = (e_snap_mode *)snapp;

if (obj == NULL || obj == Py_None) {
*snap = SNAP_AUTO;
} else if (PyObject_IsTrue(obj)) {
*snap = SNAP_TRUE;
} else {
*snap = SNAP_FALSE;
switch (PyObject_IsTrue(obj)) {
case 0: *snap = SNAP_FALSE; break;
case 1: *snap = SNAP_TRUE; break;
default: return 0; // errored.
}
}

return 1;
}

Expand Down
0