Skip to content

Commit 4804b5b

Browse files
authored
bpo-39465: Don't access directly _Py_Identifier members (GH-20043)
* Replace id->object with _PyUnicode_FromId(&id) * Use _Py_static_string_init(str) macro to initialize statically name_op in typeobject.c.
1 parent 27c0d9b commit 4804b5b

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

Modules/_cursesmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3814,7 +3814,7 @@ update_lines_cols(void)
38143814
return 0;
38153815
}
38163816
/* PyId_LINES.object will be initialized here. */
3817-
if (PyDict_SetItem(ModDict, PyId_LINES.object, o)) {
3817+
if (PyDict_SetItem(ModDict, _PyUnicode_FromId(&PyId_LINES), o)) {
38183818
Py_DECREF(m);
38193819
Py_DECREF(o);
38203820
return 0;
@@ -3830,7 +3830,7 @@ update_lines_cols(void)
38303830
Py_DECREF(o);
38313831
return 0;
38323832
}
3833-
if (PyDict_SetItem(ModDict, PyId_COLS.object, o)) {
3833+
if (PyDict_SetItem(ModDict, _PyUnicode_FromId(&PyId_COLS), o)) {
38343834
Py_DECREF(m);
38353835
Py_DECREF(o);
38363836
return 0;

Objects/abstract.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2287,7 +2287,7 @@ method_output_as_list(PyObject *o, _Py_Identifier *meth_id)
22872287
PyErr_Format(PyExc_TypeError,
22882288
"%.200s.%U() returned a non-iterable (type %.200s)",
22892289
Py_TYPE(o)->tp_name,
2290-
meth_id->object,
2290+
_PyUnicode_FromId(meth_id),
22912291
Py_TYPE(meth_output)->tp_name);
22922292
}
22932293
Py_DECREF(meth_output);

Objects/typeobject.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,7 @@ lookup_method(PyObject *self, _Py_Identifier *attrid, int *unbound)
15191519
{
15201520
PyObject *res = lookup_maybe_method(self, attrid, unbound);
15211521
if (res == NULL && !PyErr_Occurred()) {
1522-
PyErr_SetObject(PyExc_AttributeError, attrid->object);
1522+
PyErr_SetObject(PyExc_AttributeError, _PyUnicode_FromId(attrid));
15231523
}
15241524
return res;
15251525
}
@@ -6864,12 +6864,12 @@ slot_tp_setattro(PyObject *self, PyObject *name, PyObject *value)
68646864
}
68656865

68666866
static _Py_Identifier name_op[] = {
6867-
{0, "__lt__", 0},
6868-
{0, "__le__", 0},
6869-
{0, "__eq__", 0},
6870-
{0, "__ne__", 0},
6871-
{0, "__gt__", 0},
6872-
{0, "__ge__", 0}
6867+
_Py_static_string_init("__lt__"),
6868+
_Py_static_string_init("__le__"),
6869+
_Py_static_string_init("__eq__"),
6870+
_Py_static_string_init("__ne__"),
6871+
_Py_static_string_init("__gt__"),
6872+
_Py_static_string_init("__ge__"),
68736873
};
68746874

68756875
static PyObject *

Python/ceval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4414,7 +4414,7 @@ special_lookup(PyThreadState *tstate, PyObject *o, _Py_Identifier *id)
44144414
PyObject *res;
44154415
res = _PyObject_LookupSpecial(o, id);
44164416
if (res == NULL && !_PyErr_Occurred(tstate)) {
4417-
_PyErr_SetObject(tstate, PyExc_AttributeError, id->object);
4417+
_PyErr_SetObject(tstate, PyExc_AttributeError, _PyUnicode_FromId(id));
44184418
return NULL;
44194419
}
44204420
return res;

0 commit comments

Comments
 (0)