|
29 | 29 | #include "Python.h" |
30 | 30 | #include "pycore_ast.h" // _PyAST_GetDocString() |
31 | 31 | #include "pycore_code.h" // _PyCode_New() |
32 | | -#include "pycore_compile.h" // _PyFuture_FromAST() |
| 32 | +#include "pycore_compile.h" |
33 | 33 | #include "pycore_intrinsics.h" |
34 | 34 | #include "pycore_long.h" // _PyLong_GetZero() |
35 | 35 | #include "pycore_opcode.h" // _PyOpcode_Caches |
36 | 36 | #include "pycore_pymem.h" // _PyMem_IsPtrFreed() |
37 | | -#include "pycore_symtable.h" // PySTEntryObject |
| 37 | +#include "pycore_symtable.h" // PySTEntryObject, _PyFuture_FromAST() |
38 | 38 |
|
39 | 39 | #include "opcode_metadata.h" // _PyOpcode_opcode_metadata, _PyOpcode_num_popped/pushed |
40 | 40 |
|
@@ -569,72 +569,6 @@ static PyCodeObject *assemble(struct compiler *, int addNone); |
569 | 569 |
|
570 | 570 | #define CAPSULE_NAME "compile.c compiler unit" |
571 | 571 |
|
572 | | -PyObject * |
573 | | -_Py_Mangle(PyObject *privateobj, PyObject *ident) |
574 | | -{ |
575 | | - /* Name mangling: __private becomes _classname__private. |
576 | | - This is independent from how the name is used. */ |
577 | | - PyObject *result; |
578 | | - size_t nlen, plen, ipriv; |
579 | | - Py_UCS4 maxchar; |
580 | | - if (privateobj == NULL || !PyUnicode_Check(privateobj) || |
581 | | - PyUnicode_READ_CHAR(ident, 0) != '_' || |
582 | | - PyUnicode_READ_CHAR(ident, 1) != '_') { |
583 | | - return Py_NewRef(ident); |
584 | | - } |
585 | | - nlen = PyUnicode_GET_LENGTH(ident); |
586 | | - plen = PyUnicode_GET_LENGTH(privateobj); |
587 | | - /* Don't mangle __id__ or names with dots. |
588 | | -
|
589 | | - The only time a name with a dot can occur is when |
590 | | - we are compiling an import statement that has a |
591 | | - package name. |
592 | | -
|
593 | | - TODO(jhylton): Decide whether we want to support |
594 | | - mangling of the module name, e.g. __M.X. |
595 | | - */ |
596 | | - if ((PyUnicode_READ_CHAR(ident, nlen-1) == '_' && |
597 | | - PyUnicode_READ_CHAR(ident, nlen-2) == '_') || |
598 | | - PyUnicode_FindChar(ident, '.', 0, nlen, 1) != -1) { |
599 | | - return Py_NewRef(ident); /* Don't mangle __whatever__ */ |
600 | | - } |
601 | | - /* Strip leading underscores from class name */ |
602 | | - ipriv = 0; |
603 | | - while (PyUnicode_READ_CHAR(privateobj, ipriv) == '_') |
604 | | - ipriv++; |
605 | | - if (ipriv == plen) { |
606 | | - return Py_NewRef(ident); /* Don't mangle if class is just underscores */ |
607 | | - } |
608 | | - plen -= ipriv; |
609 | | - |
610 | | - if (plen + nlen >= PY_SSIZE_T_MAX - 1) { |
611 | | - PyErr_SetString(PyExc_OverflowError, |
612 | | - "private identifier too large to be mangled"); |
613 | | - return NULL; |
614 | | - } |
615 | | - |
616 | | - maxchar = PyUnicode_MAX_CHAR_VALUE(ident); |
617 | | - if (PyUnicode_MAX_CHAR_VALUE(privateobj) > maxchar) |
618 | | - maxchar = PyUnicode_MAX_CHAR_VALUE(privateobj); |
619 | | - |
620 | | - result = PyUnicode_New(1 + nlen + plen, maxchar); |
621 | | - if (!result) { |
622 | | - return NULL; |
623 | | - } |
624 | | - /* ident = "_" + priv[ipriv:] + ident # i.e. 1+plen+nlen bytes */ |
625 | | - PyUnicode_WRITE(PyUnicode_KIND(result), PyUnicode_DATA(result), 0, '_'); |
626 | | - if (PyUnicode_CopyCharacters(result, 1, privateobj, ipriv, plen) < 0) { |
627 | | - Py_DECREF(result); |
628 | | - return NULL; |
629 | | - } |
630 | | - if (PyUnicode_CopyCharacters(result, plen+1, ident, 0, nlen) < 0) { |
631 | | - Py_DECREF(result); |
632 | | - return NULL; |
633 | | - } |
634 | | - assert(_PyUnicode_CheckConsistency(result, 1)); |
635 | | - return result; |
636 | | -} |
637 | | - |
638 | 572 |
|
639 | 573 | static int |
640 | 574 | compiler_setup(struct compiler *c, mod_ty mod, PyObject *filename, |
|
0 commit comments