Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix some more instances of redundant PyBool_Checks
Browse files Browse the repository at this point in the history
mdboom committed Aug 29, 2024

Unverified

This user has not yet uploaded their public signing key.
1 parent 15b187e commit c9a5962
Showing 3 changed files with 12 additions and 13 deletions.
11 changes: 5 additions & 6 deletions Objects/frameobject.c
Original file line number Diff line number Diff line change
@@ -889,20 +889,19 @@ frame_gettrace_opcodes(PyFrameObject *f, void *closure)
static int
frame_settrace_opcodes(PyFrameObject *f, PyObject* value, void *Py_UNUSED(ignored))
{
if (!PyBool_Check(value)) {
PyErr_SetString(PyExc_TypeError,
"attribute value type must be bool");
return -1;
}
if (value == Py_True) {
f->f_trace_opcodes = 1;
if (f->f_trace) {
return _PyEval_SetOpcodeTrace(f, true);
}
}
else {
else if (value == Py_False) {
f->f_trace_opcodes = 0;
return _PyEval_SetOpcodeTrace(f, false);
} else {
PyErr_SetString(PyExc_TypeError,
"attribute value type must be bool");
return -1;
}
return 0;
}
4 changes: 2 additions & 2 deletions Objects/listobject.c
Original file line number Diff line number Diff line change
@@ -2665,8 +2665,8 @@ unsafe_object_compare(PyObject *v, PyObject *w, MergeState *ms)
if (res_obj == NULL)
return -1;

if (PyBool_Check(res_obj)) {
res = (res_obj == Py_True);
if (res_obj == Py_True) {
res = 1;
}
else {
res = PyObject_IsTrue(res_obj);
10 changes: 5 additions & 5 deletions Python/structmember.c
Original file line number Diff line number Diff line change
@@ -163,15 +163,15 @@ PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v)
}
switch (l->type) {
case Py_T_BOOL:{
if (!PyBool_Check(v)) {
if (v == Py_True)
*(char*)addr = (char) 1;
else if (v == Py_False)
*(char*)addr = (char) 0;
else {
PyErr_SetString(PyExc_TypeError,
"attribute value type must be bool");
return -1;
}
if (v == Py_True)
*(char*)addr = (char) 1;
else
*(char*)addr = (char) 0;
break;
}
case Py_T_BYTE:{

0 comments on commit c9a5962

Please sign in to comment.