Skip to content

Commit 74bfd6a

Browse files
Issue #29190: Fixed possible errors in comparing strings in the pickle module.
2 parents a4a489b + 0e8df33 commit 74bfd6a

1 file changed

Lines changed: 6 additions & 12 deletions

File tree

Modules/_pickle.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,9 +1560,9 @@ memo_put(PicklerObject *self, PyObject *obj)
15601560
}
15611561

15621562
static PyObject *
1563-
get_dotted_path(PyObject *obj, PyObject *name) {
1563+
get_dotted_path(PyObject *obj, PyObject *name)
1564+
{
15641565
_Py_static_string(PyId_dot, ".");
1565-
_Py_static_string(PyId_locals, "<locals>");
15661566
PyObject *dotted_path;
15671567
Py_ssize_t i, n;
15681568

@@ -1573,12 +1573,7 @@ get_dotted_path(PyObject *obj, PyObject *name) {
15731573
assert(n >= 1);
15741574
for (i = 0; i < n; i++) {
15751575
PyObject *subpath = PyList_GET_ITEM(dotted_path, i);
1576-
PyObject *result = PyUnicode_RichCompare(
1577-
subpath, _PyUnicode_FromId(&PyId_locals), Py_EQ);
1578-
int is_equal = (result == Py_True);
1579-
assert(PyBool_Check(result));
1580-
Py_DECREF(result);
1581-
if (is_equal) {
1576+
if (_PyUnicode_EqualToASCIIString(subpath, "<locals>")) {
15821577
if (obj == NULL)
15831578
PyErr_Format(PyExc_AttributeError,
15841579
"Can't pickle local object %R", name);
@@ -3552,12 +3547,11 @@ save_reduce(PicklerObject *self, PyObject *args, PyObject *obj)
35523547
}
35533548
else if (PyUnicode_Check(name)) {
35543549
_Py_IDENTIFIER(__newobj_ex__);
3555-
use_newobj_ex = PyUnicode_Compare(
3556-
name, _PyUnicode_FromId(&PyId___newobj_ex__)) == 0;
3550+
use_newobj_ex = _PyUnicode_EqualToASCIIId(
3551+
name, &PyId___newobj_ex__);
35573552
if (!use_newobj_ex) {
35583553
_Py_IDENTIFIER(__newobj__);
3559-
use_newobj = PyUnicode_Compare(
3560-
name, _PyUnicode_FromId(&PyId___newobj__)) == 0;
3554+
use_newobj = _PyUnicode_EqualToASCIIId(name, &PyId___newobj__);
35613555
}
35623556
}
35633557
Py_XDECREF(name);

0 commit comments

Comments
 (0)