Skip to content

Commit

Permalink
fixed logical operation
Browse files Browse the repository at this point in the history
  • Loading branch information
blhsing committed Jul 11, 2024
1 parent 18dad2b commit 35ada07
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -7258,15 +7258,15 @@ _PyObjectDict_SetItem(PyTypeObject *tp, PyObject *obj, PyObject **dictptr,
return -1;
}

Py_BEGIN_CRITICAL_SECTION(dict);
if (PyDict_Check(dict)) {
Py_BEGIN_CRITICAL_SECTION(dict);
res = _PyDict_SetItem_LockHeld((PyDictObject *)dict, key, value);
ASSERT_CONSISTENT(dict);
Py_END_CRITICAL_SECTION();
}
else {
res = PyObject_SetItem(dict, key, value);
}
Py_END_CRITICAL_SECTION();
return res;
}

Expand Down
11 changes: 7 additions & 4 deletions Objects/moduleobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -709,10 +709,12 @@ _PyModule_ClearDict(PyObject *d)
if (filter) { \
if (verbose > 1) { \
const char *s = PyUnicode_AsUTF8(key); \
if (s != NULL) \
if (s != NULL) { \
PySys_WriteStderr("# clear[" phase "] %s\n", s); \
else \
} \
else { \
PyErr_Clear(); \
} \
} \
int r; \
_Py_DICT_OR_MAPPING_SETITEM(d, key, Py_None, r) \
Expand All @@ -733,7 +735,7 @@ _PyModule_ClearDict(PyObject *d)
/* Next, clear all names except for __builtins__ */
_Py_MODULE_CLEARDICT_ITER_DICT(
_Py_MODULE_CLEARDICT_BY(
PyUnicode_READ_CHAR(key, 0) != '_' &&
PyUnicode_READ_CHAR(key, 0) != '_' ||
!_PyUnicode_EqualToASCIIString(key, "__builtins__"), "2"))
}
else {
Expand All @@ -749,8 +751,9 @@ _PyModule_ClearDict(PyObject *d)
/* Next, clear all names except for __builtins__ */
_Py_MODULE_CLEARDICT_ITER_MAPPING(
_Py_MODULE_CLEARDICT_BY(
PyUnicode_READ_CHAR(key, 0) != '_' &&
PyUnicode_READ_CHAR(key, 0) != '_' ||
!_PyUnicode_EqualToASCIIString(key, "__builtins__"), "2"))

Py_DECREF(items);
}

Expand Down
2 changes: 1 addition & 1 deletion Python/pythonrun.c
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,7 @@ run_eval_code_obj(PyThreadState *tstate, PyCodeObject *co, PyObject *globals, Py
goto error;
}
else _Py_DICT_OR_MAPPING_CONTAINS_ELSE(globals, &_Py_ID(__builtins__),
has_builtins,
has_builtins,
{
error:
PyErr_SetString(PyExc_SystemError, "globals must be a mapping");
Expand Down

0 comments on commit 35ada07

Please sign in to comment.