From 6a08ed60e2d72052efede544e34a8fa281f6a3f7 Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Fri, 28 Apr 2023 11:46:46 -0700 Subject: [PATCH 1/2] gh-103978: avoid using 'class' as an identifier --- Include/internal/pycore_code.h | 2 +- Python/specialize.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Include/internal/pycore_code.h b/Include/internal/pycore_code.h index 7d5d5e03de9e41..f15328fd8efd66 100644 --- a/Include/internal/pycore_code.h +++ b/Include/internal/pycore_code.h @@ -226,7 +226,7 @@ extern int _PyLineTable_PreviousAddressRange(PyCodeAddressRange *range); /* Specialization functions */ -extern void _Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *class, PyObject *self, +extern void _Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *klass, PyObject *self, _Py_CODEUNIT *instr, PyObject *name, int load_method); extern void _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name); diff --git a/Python/specialize.c b/Python/specialize.c index 33a3c4561c7ca2..2201061acef588 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -515,7 +515,7 @@ specialize_module_load_attr( /* Attribute specialization */ void -_Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *class, PyObject *self, +_Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *klass, PyObject *self, _Py_CODEUNIT *instr, PyObject *name, int load_method) { assert(ENABLE_SPECIALIZATION); assert(_PyOpcode_Caches[LOAD_SUPER_ATTR] == INLINE_CACHE_ENTRIES_LOAD_SUPER_ATTR); @@ -528,11 +528,11 @@ _Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *class, PyObject * SPECIALIZATION_FAIL(LOAD_SUPER_ATTR, SPEC_FAIL_SUPER_SHADOWED); goto fail; } - if (!PyType_Check(class)) { + if (!PyType_Check(klass)) { SPECIALIZATION_FAIL(LOAD_SUPER_ATTR, SPEC_FAIL_SUPER_BAD_CLASS); goto fail; } - PyTypeObject *tp = (PyTypeObject *)class; + PyTypeObject *tp = (PyTypeObject *)klass; PyObject *res = _PySuper_LookupDescr(tp, self, name); if (res == NULL) { SPECIALIZATION_FAIL(LOAD_SUPER_ATTR, SPEC_FAIL_SUPER_ERROR_OR_NOT_FOUND); From 8d652a33a720722ee479d3b8412d17030edab273 Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Fri, 28 Apr 2023 11:50:31 -0700 Subject: [PATCH 2/2] prefer cls over klass --- Include/internal/pycore_code.h | 2 +- Python/specialize.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Include/internal/pycore_code.h b/Include/internal/pycore_code.h index f15328fd8efd66..86fd48b63ef8e4 100644 --- a/Include/internal/pycore_code.h +++ b/Include/internal/pycore_code.h @@ -226,7 +226,7 @@ extern int _PyLineTable_PreviousAddressRange(PyCodeAddressRange *range); /* Specialization functions */ -extern void _Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *klass, PyObject *self, +extern void _Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *cls, PyObject *self, _Py_CODEUNIT *instr, PyObject *name, int load_method); extern void _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name); diff --git a/Python/specialize.c b/Python/specialize.c index 2201061acef588..fbdb435082cece 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -515,7 +515,7 @@ specialize_module_load_attr( /* Attribute specialization */ void -_Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *klass, PyObject *self, +_Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *cls, PyObject *self, _Py_CODEUNIT *instr, PyObject *name, int load_method) { assert(ENABLE_SPECIALIZATION); assert(_PyOpcode_Caches[LOAD_SUPER_ATTR] == INLINE_CACHE_ENTRIES_LOAD_SUPER_ATTR); @@ -528,11 +528,11 @@ _Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *klass, PyObject * SPECIALIZATION_FAIL(LOAD_SUPER_ATTR, SPEC_FAIL_SUPER_SHADOWED); goto fail; } - if (!PyType_Check(klass)) { + if (!PyType_Check(cls)) { SPECIALIZATION_FAIL(LOAD_SUPER_ATTR, SPEC_FAIL_SUPER_BAD_CLASS); goto fail; } - PyTypeObject *tp = (PyTypeObject *)klass; + PyTypeObject *tp = (PyTypeObject *)cls; PyObject *res = _PySuper_LookupDescr(tp, self, name); if (res == NULL) { SPECIALIZATION_FAIL(LOAD_SUPER_ATTR, SPEC_FAIL_SUPER_ERROR_OR_NOT_FOUND);