8000 bpo-39465: Don't access directly _Py_Identifier members by vstinner · Pull Request #20043 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-39465: Don't access directly _Py_Identifier members #20043

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
merged 1 commit into from
May 11, 2020
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
bpo-39465: Don't access directly _Py_Identifier members
* Replace id->object with _PyUnicode_FromId(&id)
* Use _Py_static_string_init(str) macro to initialize statically
  name_op in typeobject.c.
  • Loading branch information
vstinner committed May 11, 2020
commit 4812f7b44110d9a106afd2e07fc69f0113378439
4 changes: 2 additions & 2 deletions Modules/_cursesmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3814,7 +3814,7 @@ update_lines_cols(void)
return 0;
}
/* PyId_LINES.object will be initialized here. */
if (PyDict_SetItem(ModDict, PyId_LINES.object, o)) {
if (PyDict_SetItem(ModDict, _PyUnicode_FromId(&PyId_LINES), o)) {
Py_DECREF(m);
Py_DECREF(o);
return 0;
Expand All @@ -3830,7 +3830,7 @@ update_lines_cols(void)
Py_DECREF(o);
return 0;
}
if (PyDict_SetItem(ModDict, PyId_COLS.object, o)) {
if (PyDict_SetItem(ModDict, _PyUnicode_FromId(&PyId_COLS), o)) {
Py_DECREF(m);
Py_DECREF(o);
return 0;
Expand Down
2 changes: 1 addition & 1 deletion Objects/abstract.c
Original file line number Diff line number Diff line change
Expand Up @@ -2287,7 +2287,7 @@ method_output_as_list(PyObject *o, _Py_Identifier *meth_id)
PyErr_Format(PyExc_TypeError,
"%.200s.%U() returned a non-iterable (type %.200s)",
Py_TYPE(o)->tp_name,
meth_id->object,
_PyUnicode_FromId(meth_id),
Py_TYPE(meth_output)->tp_name);
}
Py_DECREF(meth_output);
Expand Down
14 changes: 7 additions & 7 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,7 @@ lookup_method(PyObject *self, _Py_Identifier *attrid, int *unbound)
{
PyObject *res = lookup_maybe_method(self, attrid, unbound);
if (res == NULL && !PyErr_Occurred()) {
PyErr_SetObject(PyExc_AttributeError, attrid->object);
PyErr_SetObject(PyExc_AttributeError, _PyUnicode_FromId(attrid));
}
return res;
}
Expand Down Expand Up @@ -6864,12 +6864,12 @@ slot_tp_setattro(PyObject *self, PyObject *name, PyObject *value)
}

static _Py_Identifier name_op[] = {
{0, "__lt__", 0},
{0, "__le__", 0},
{0, "__eq__", 0},
{0, "__ne__", 0},
{0, "__gt__", 0},
{0, "__ge__", 0}
_Py_static_string_init("__lt__"),
_Py_static_string_init("__le__"),
_Py_static_string_init("__eq__"),
_Py_static_string_init("__ne__"),
_Py_static_string_init("__gt__"),
_Py_static_string_init("__ge__"),
};

static PyObject *
Expand Down
2 changes: 1 addition & 1 deletion Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -4414,7 +4414,7 @@ special_lookup(PyThreadState *tstate, PyObject *o, _Py_Identifier *id)
PyObject *res;
res = _PyObject_LookupSpecial(o, id);
if (res == NULL && !_PyErr_Occurred(tstate)) {
_PyErr_SetObject(tstate, PyExc_AttributeError, id->object);
_PyErr_SetObject(tstate, PyExc_AttributeError, _PyUnicode_FromId(id));
return NULL;
}
return res;
Expand Down
0