mirror of https://github.com/python/cpython
Issue #25856: The __module__ attribute of extension classes and functions
now is interned. This leads to more compact pickle data with protocol 4.
This commit is contained in:
parent
ae8b69c410
commit
7c19affdce
|
@ -10,6 +10,9 @@ What's New in Python 3.6.0 beta 1
|
||||||
Core and Builtins
|
Core and Builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Issue #25856: The __module__ attribute of extension classes and functions
|
||||||
|
now is interned. This leads to more compact pickle data with protocol 4.
|
||||||
|
|
||||||
- Issue #27213: Rework CALL_FUNCTION* opcodes to produce shorter and more
|
- Issue #27213: Rework CALL_FUNCTION* opcodes to produce shorter and more
|
||||||
efficient bytecode. Patch by Demur Rumed, design by Serhiy Storchaka,
|
efficient bytecode. Patch by Demur Rumed, design by Serhiy Storchaka,
|
||||||
reviewed by Serhiy Storchaka and Victor Stinner.
|
reviewed by Serhiy Storchaka and Victor Stinner.
|
||||||
|
|
|
@ -454,27 +454,30 @@ type_set_qualname(PyTypeObject *type, PyObject *value, void *context)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
type_module(PyTypeObject *type, void *context)
|
type_module(PyTypeObject *type, void *context)
|
||||||
{
|
{
|
||||||
char *s;
|
PyObject *mod;
|
||||||
|
|
||||||
if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) {
|
if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) {
|
||||||
PyObject *mod = _PyDict_GetItemId(type->tp_dict, &PyId___module__);
|
mod = _PyDict_GetItemId(type->tp_dict, &PyId___module__);
|
||||||
if (!mod) {
|
if (mod == NULL) {
|
||||||
PyErr_Format(PyExc_AttributeError, "__module__");
|
PyErr_Format(PyExc_AttributeError, "__module__");
|
||||||
return 0;
|
return NULL;
|
||||||
}
|
}
|
||||||
Py_INCREF(mod);
|
Py_INCREF(mod);
|
||||||
return mod;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PyObject *name;
|
const char *s = strrchr(type->tp_name, '.');
|
||||||
s = strrchr(type->tp_name, '.');
|
if (s != NULL) {
|
||||||
if (s != NULL)
|
mod = PyUnicode_FromStringAndSize(
|
||||||
return PyUnicode_FromStringAndSize(
|
|
||||||
type->tp_name, (Py_ssize_t)(s - type->tp_name));
|
type->tp_name, (Py_ssize_t)(s - type->tp_name));
|
||||||
name = _PyUnicode_FromId(&PyId_builtins);
|
if (mod != NULL)
|
||||||
Py_XINCREF(name);
|
PyUnicode_InternInPlace(&mod);
|
||||||
return name;
|
}
|
||||||
|
else {
|
||||||
|
mod = _PyUnicode_FromId(&PyId_builtins);
|
||||||
|
Py_XINCREF(mod);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
Loading…
Reference in New Issue