cpython: 861ddad3e0c1 (original) (raw)
Mercurial > cpython
changeset 103470:861ddad3e0c1
Issue #25856: The __module__ attribute of extension classes and functions now is interned. This leads to more compact pickle data with protocol 4. [#25856]
Serhiy Storchaka storchaka@gmail.com | |
---|---|
date | Sat, 10 Sep 2016 00:53:02 +0300 |
parents | a25c39873d93 |
children | 66afc449efa9 |
files | Misc/NEWS Objects/typeobject.c |
diffstat | 2 files changed, 19 insertions(+), 13 deletions(-)[+] [-] Misc/NEWS 3 Objects/typeobject.c 29 |
line wrap: on
line diff
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ What's New in Python 3.6.0 beta 1 Core and Builtins ----------------- +- Issue #25856: The module attribute of extension classes and functions
- Issue #27213: Rework CALL_FUNCTION* opcodes to produce shorter and more efficient bytecode. Patch by Demur Rumed, design by Serhiy Storchaka, reviewed by Serhiy Storchaka and Victor Stinner.
--- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -454,27 +454,30 @@ type_set_qualname(PyTypeObject *type, Py static PyObject * type_module(PyTypeObject *type, void *context) {
if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) {
PyObject *mod = _PyDict_GetItemId(type->tp_dict, &PyId___module__);[](#l2.11)
if (!mod) {[](#l2.12)
mod = _PyDict_GetItemId(type->tp_dict, &PyId___module__);[](#l2.13)
if (mod == NULL) {[](#l2.14) PyErr_Format(PyExc_AttributeError, "__module__");[](#l2.15)
return 0;[](#l2.16)
return NULL;[](#l2.17) }[](#l2.18) Py_INCREF(mod);[](#l2.19)
} else {return mod;[](#l2.20)
PyObject *name;[](#l2.23)
s = strrchr(type->tp_name, '.');[](#l2.24)
if (s != NULL)[](#l2.25)
return PyUnicode_FromStringAndSize([](#l2.26)
const char *s = strrchr(type->tp_name, '.');[](#l2.27)
if (s != NULL) {[](#l2.28)
mod = PyUnicode_FromStringAndSize([](#l2.29) type->tp_name, (Py_ssize_t)(s - type->tp_name));[](#l2.30)
name = _PyUnicode_FromId(&PyId_builtins);[](#l2.31)
Py_XINCREF(name);[](#l2.32)
return name;[](#l2.33)
- }