mirror of
https://github.com/python/cpython.git
synced 2025-11-03 11:23:31 +00:00
Issue #19437: Use an identifier for "__name__" string in pickle to improve
error handling
The following code didn't handle correctly the failure of
PyUnicode_InternFromString("__name__").
if (newobj_str == NULL) {
newobj_str = PyUnicode_InternFromString("__newobj__");
name_str = PyUnicode_InternFromString("__name__");
if (newobj_str == NULL || name_str == NULL)
return -1;
}
This commit is contained in:
parent
c82729e44f
commit
804e05e800
1 changed files with 5 additions and 12 deletions
|
|
@ -136,6 +136,7 @@ static PyObject *empty_tuple = NULL;
|
||||||
/* For looking up name pairs in copyreg._extension_registry. */
|
/* For looking up name pairs in copyreg._extension_registry. */
|
||||||
static PyObject *two_tuple = NULL;
|
static PyObject *two_tuple = NULL;
|
||||||
|
|
||||||
|
_Py_IDENTIFIER(__name__);
|
||||||
_Py_IDENTIFIER(modules);
|
_Py_IDENTIFIER(modules);
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
@ -2599,7 +2600,6 @@ save_dict(PicklerObject *self, PyObject *obj)
|
||||||
static int
|
static int
|
||||||
save_global(PicklerObject *self, PyObject *obj, PyObject *name)
|
save_global(PicklerObject *self, PyObject *obj, PyObject *name)
|
||||||
{
|
{
|
||||||
static PyObject *name_str = NULL;
|
|
||||||
PyObject *global_name = NULL;
|
PyObject *global_name = NULL;
|
||||||
PyObject *module_name = NULL;
|
PyObject *module_name = NULL;
|
||||||
PyObject *module = NULL;
|
PyObject *module = NULL;
|
||||||
|
|
@ -2608,18 +2608,12 @@ save_global(PicklerObject *self, PyObject *obj, PyObject *name)
|
||||||
|
|
||||||
const char global_op = GLOBAL;
|
const char global_op = GLOBAL;
|
||||||
|
|
||||||
if (name_str == NULL) {
|
|
||||||
name_str = PyUnicode_InternFromString("__name__");
|
|
||||||
if (name_str == NULL)
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (name) {
|
if (name) {
|
||||||
global_name = name;
|
global_name = name;
|
||||||
Py_INCREF(global_name);
|
Py_INCREF(global_name);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
global_name = PyObject_GetAttr(obj, name_str);
|
global_name = _PyObject_GetAttrId(obj, &PyId___name__);
|
||||||
if (global_name == NULL)
|
if (global_name == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
@ -3016,17 +3010,16 @@ save_reduce(PicklerObject *self, PyObject *args, PyObject *obj)
|
||||||
/* Protocol 2 special case: if callable's name is __newobj__, use
|
/* Protocol 2 special case: if callable's name is __newobj__, use
|
||||||
NEWOBJ. */
|
NEWOBJ. */
|
||||||
if (use_newobj) {
|
if (use_newobj) {
|
||||||
static PyObject *newobj_str = NULL, *name_str = NULL;
|
static PyObject *newobj_str = NULL;
|
||||||
PyObject *name;
|
PyObject *name;
|
||||||
|
|
||||||
if (newobj_str == NULL) {
|
if (newobj_str == NULL) {
|
||||||
newobj_str = PyUnicode_InternFromString("__newobj__");
|
newobj_str = PyUnicode_InternFromString("__newobj__");
|
||||||
name_str = PyUnicode_InternFromString("__name__");
|
if (newobj_str == NULL)
|
||||||
if (newobj_str == NULL || name_str == NULL)
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
name = PyObject_GetAttr(callable, name_str);
|
name = _PyObject_GetAttrId(callable, &PyId___name__);
|
||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
if (PyErr_ExceptionMatches(PyExc_AttributeError))
|
if (PyErr_ExceptionMatches(PyExc_AttributeError))
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue