mirror of https://github.com/python/cpython
bpo-44530: Add co_qualname field to PyCodeObject (GH-26941)
This commit is contained in:
parent
32096df0e0
commit
2f180ce2cb
|
@ -36,15 +36,16 @@ There are a few functions specific to Python functions.
|
|||
|
||||
The function's docstring and name are retrieved from the code object. *__module__*
|
||||
is retrieved from *globals*. The argument defaults, annotations and closure are
|
||||
set to ``NULL``. *__qualname__* is set to the same value as the function's name.
|
||||
set to ``NULL``. *__qualname__* is set to the same value as the code object's
|
||||
``co_qualname`` field.
|
||||
|
||||
|
||||
.. c:function:: PyObject* PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname)
|
||||
|
||||
As :c:func:`PyFunction_New`, but also allows setting the function object's
|
||||
``__qualname__`` attribute. *qualname* should be a unicode object or ``NULL``;
|
||||
if ``NULL``, the ``__qualname__`` attribute is set to the same value as its
|
||||
``__name__`` attribute.
|
||||
if ``NULL``, the ``__qualname__`` attribute is set to the same value as the
|
||||
code object's ``co_qualname`` field.
|
||||
|
||||
.. versionadded:: 3.3
|
||||
|
||||
|
|
|
@ -75,6 +75,7 @@ struct PyCodeObject {
|
|||
PyObject *co_localspluskinds; /* Bytes mapping to local kinds (one byte per variable) */
|
||||
PyObject *co_filename; /* unicode (where it was loaded from) */
|
||||
PyObject *co_name; /* unicode (name, for reference) */
|
||||
PyObject *co_qualname; /* unicode (qualname, for reference) */
|
||||
PyObject *co_linetable; /* bytes (encoding addr<->lineno mapping) See
|
||||
Objects/lnotab_notes.txt for details. */
|
||||
PyObject *co_endlinetable; /* bytes object that holds end lineno for
|
||||
|
@ -154,14 +155,14 @@ PyAPI_DATA(PyTypeObject) PyCode_Type;
|
|||
PyAPI_FUNC(PyCodeObject *) PyCode_New(
|
||||
int, int, int, int, int, PyObject *, PyObject *,
|
||||
PyObject *, PyObject *, PyObject *, PyObject *,
|
||||
PyObject *, PyObject *, int, PyObject *, PyObject *,
|
||||
PyObject *, PyObject *);
|
||||
PyObject *, PyObject *, PyObject *, int, PyObject *,
|
||||
PyObject *, PyObject *, PyObject *);
|
||||
|
||||
PyAPI_FUNC(PyCodeObject *) PyCode_NewWithPosOnlyArgs(
|
||||
int, int, int, int, int, int, PyObject *, PyObject *,
|
||||
PyObject *, PyObject *, PyObject *, PyObject *,
|
||||
PyObject *, PyObject *, int, PyObject *, PyObject *,
|
||||
PyObject *, PyObject *);
|
||||
PyObject *, PyObject *, PyObject *, int, PyObject *,
|
||||
PyObject *, PyObject *, PyObject *);
|
||||
/* same as struct above */
|
||||
|
||||
/* Creates a new empty code object with the specified source location. */
|
||||
|
|
|
@ -212,6 +212,7 @@ struct _PyCodeConstructor {
|
|||
/* metadata */
|
||||
PyObject *filename;
|
||||
PyObject *name;
|
||||
PyObject *qualname;
|
||||
int flags;
|
||||
|
||||
/* the code */
|
||||
|
|
|
@ -80,9 +80,9 @@ class PythonValuesTestCase(unittest.TestCase):
|
|||
continue
|
||||
items.append((entry.name.decode("ascii"), entry.size))
|
||||
|
||||
expected = [("__hello__", 159),
|
||||
("__phello__", -159),
|
||||
("__phello__.spam", 159),
|
||||
expected = [("__hello__", 164),
|
||||
("__phello__", -164),
|
||||
("__phello__.spam", 164),
|
||||
]
|
||||
self.assertEqual(items, expected, "PyImport_FrozenModules example "
|
||||
"in Doc/library/ctypes.rst may be out of date")
|
||||
|
|
|
@ -362,6 +362,7 @@ _code_type = type(_write_atomic.__code__)
|
|||
# Python 3.11a1 3457 (Change localsplus to a bytes object bpo-43693)
|
||||
# Python 3.11a1 3458 (imported objects now don't use LOAD_METHOD/CALL_METHOD)
|
||||
# Python 3.11a1 3459 (PEP 657: add end line numbers and column offsets for instructions)
|
||||
# Python 3.11a1 3460 (Add co_qualname field to PyCodeObject bpo-44530)
|
||||
|
||||
#
|
||||
# MAGIC must change whenever the bytecode emitted by the compiler may no
|
||||
|
@ -371,7 +372,7 @@ _code_type = type(_write_atomic.__code__)
|
|||
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
|
||||
# in PC/launcher.c must also be updated.
|
||||
|
||||
MAGIC_NUMBER = (3459).to_bytes(2, 'little') + b'\r\n'
|
||||
MAGIC_NUMBER = (3460).to_bytes(2, 'little') + b'\r\n'
|
||||
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c
|
||||
|
||||
_PYCACHE = '__pycache__'
|
||||
|
|
|
@ -17,7 +17,7 @@ cellvars: ('x',)
|
|||
freevars: ()
|
||||
nlocals: 2
|
||||
flags: 3
|
||||
consts: ('None', '<code object g>', "'f.<locals>.g'")
|
||||
consts: ('None', '<code object g>')
|
||||
|
||||
>>> dump(f(4).__code__)
|
||||
name: g
|
||||
|
@ -223,6 +223,7 @@ class CodeTest(unittest.TestCase):
|
|||
co.co_varnames,
|
||||
co.co_filename,
|
||||
co.co_name,
|
||||
co.co_qualname,
|
||||
co.co_firstlineno,
|
||||
co.co_lnotab,
|
||||
co.co_endlinetable,
|
||||
|
@ -231,6 +232,12 @@ class CodeTest(unittest.TestCase):
|
|||
co.co_freevars,
|
||||
co.co_cellvars)
|
||||
|
||||
def test_qualname(self):
|
||||
self.assertEqual(
|
||||
CodeTest.test_qualname.__code__.co_qualname,
|
||||
CodeTest.test_qualname.__qualname__
|
||||
)
|
||||
|
||||
def test_replace(self):
|
||||
def func():
|
||||
x = 1
|
||||
|
@ -297,6 +304,7 @@ class CodeTest(unittest.TestCase):
|
|||
co.co_varnames,
|
||||
co.co_filename,
|
||||
co.co_name,
|
||||
co.co_qualname,
|
||||
co.co_firstlineno,
|
||||
co.co_lnotab,
|
||||
co.co_endlinetable,
|
||||
|
|
|
@ -149,17 +149,16 @@ def bug1333982(x=[]):
|
|||
dis_bug1333982 = """\
|
||||
%3d 0 LOAD_ASSERTION_ERROR
|
||||
2 LOAD_CONST 2 (<code object <listcomp> at 0x..., file "%s", line %d>)
|
||||
4 LOAD_CONST 3 ('bug1333982.<locals>.<listcomp>')
|
||||
6 MAKE_FUNCTION 0
|
||||
8 LOAD_FAST 0 (x)
|
||||
10 GET_ITER
|
||||
12 CALL_FUNCTION 1
|
||||
4 MAKE_FUNCTION 0
|
||||
6 LOAD_FAST 0 (x)
|
||||
8 GET_ITER
|
||||
10 CALL_FUNCTION 1
|
||||
|
||||
%3d 14 LOAD_CONST 4 (1)
|
||||
%3d 12 LOAD_CONST 3 (1)
|
||||
|
||||
%3d 16 BINARY_ADD
|
||||
18 CALL_FUNCTION 1
|
||||
20 RAISE_VARARGS 1
|
||||
%3d 14 BINARY_ADD
|
||||
16 CALL_FUNCTION 1
|
||||
18 RAISE_VARARGS 1
|
||||
""" % (bug1333982.__code__.co_firstlineno + 1,
|
||||
__file__,
|
||||
bug1333982.__code__.co_firstlineno + 1,
|
||||
|
@ -432,12 +431,11 @@ dis_nested_0 = """\
|
|||
%3d 2 LOAD_CLOSURE 0 (y)
|
||||
4 BUILD_TUPLE 1
|
||||
6 LOAD_CONST 1 (<code object foo at 0x..., file "%s", line %d>)
|
||||
8 LOAD_CONST 2 ('_h.<locals>.foo')
|
||||
10 MAKE_FUNCTION 8 (closure)
|
||||
12 STORE_FAST 1 (foo)
|
||||
8 MAKE_FUNCTION 8 (closure)
|
||||
10 STORE_FAST 1 (foo)
|
||||
|
||||
%3d 14 LOAD_FAST 1 (foo)
|
||||
16 RETURN_VALUE
|
||||
%3d 12 LOAD_FAST 1 (foo)
|
||||
14 RETURN_VALUE
|
||||
""" % (_h.__code__.co_firstlineno + 1,
|
||||
__file__,
|
||||
_h.__code__.co_firstlineno + 1,
|
||||
|
@ -451,12 +449,11 @@ Disassembly of <code object foo at 0x..., file "%s", line %d>:
|
|||
%3d 2 LOAD_CLOSURE 0 (x)
|
||||
4 BUILD_TUPLE 1
|
||||
6 LOAD_CONST 1 (<code object <listcomp> at 0x..., file "%s", line %d>)
|
||||
8 LOAD_CONST 2 ('_h.<locals>.foo.<locals>.<listcomp>')
|
||||
10 MAKE_FUNCTION 8 (closure)
|
||||
12 LOAD_DEREF 1 (y)
|
||||
14 GET_ITER
|
||||
16 CALL_FUNCTION 1
|
||||
18 RETURN_VALUE
|
||||
8 MAKE_FUNCTION 8 (closure)
|
||||
10 LOAD_DEREF 1 (y)
|
||||
12 GET_ITER
|
||||
14 CALL_FUNCTION 1
|
||||
16 RETURN_VALUE
|
||||
""" % (dis_nested_0,
|
||||
__file__,
|
||||
_h.__code__.co_firstlineno + 1,
|
||||
|
@ -747,7 +744,6 @@ Flags: OPTIMIZED, NEWLOCALS, VARARGS, VARKEYWORDS, GENERATOR
|
|||
Constants:
|
||||
0: None
|
||||
1: <code object f at (.*), file "(.*)", line (.*)>
|
||||
2: 'tricky.<locals>.f'
|
||||
Variable names:
|
||||
0: a
|
||||
1: b
|
||||
|
@ -975,51 +971,49 @@ Instruction = dis.Instruction
|
|||
expected_opinfo_outer = [
|
||||
Instruction(opname='MAKE_CELL', opcode=135, arg=0, argval='a', argrepr='a', offset=0, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='MAKE_CELL', opcode=135, arg=1, argval='b', argrepr='b', offset=2, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_CONST', opcode=100, arg=8, argval=(3, 4), argrepr='(3, 4)', offset=4, starts_line=2, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_CONST', opcode=100, arg=7, argval=(3, 4), argrepr='(3, 4)', offset=4, starts_line=2, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_CLOSURE', opcode=136, arg=0, argval='a', argrepr='a', offset=6, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_CLOSURE', opcode=136, arg=1, argval='b', argrepr='b', offset=8, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='BUILD_TUPLE', opcode=102, arg=2, argval=2, argrepr='', offset=10, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_CONST', opcode=100, arg=3, argval=code_object_f, argrepr=repr(code_object_f), offset=12, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_CONST', opcode=100, arg=4, argval='outer.<locals>.f', argrepr="'outer.<locals>.f'", offset=14, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='MAKE_FUNCTION', opcode=132, arg=9, argval=9, argrepr='defaults, closure', offset=16, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='STORE_FAST', opcode=125, arg=2, argval='f', argrepr='f', offset=18, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_GLOBAL', opcode=116, arg=0, argval='print', argrepr='print', offset=20, starts_line=7, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_DEREF', opcode=137, arg=0, argval='a', argrepr='a', offset=22, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_DEREF', opcode=137, arg=1, argval='b', argrepr='b', offset=24, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_CONST', opcode=100, arg=5, argval='', argrepr="''", offset=26, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_CONST', opcode=100, arg=6, argval=1, argrepr='1', offset=28, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='BUILD_LIST', opcode=103, arg=0, argval=0, argrepr='', offset=30, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='BUILD_MAP', opcode=105, arg=0, argval=0, argrepr='', offset=32, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_CONST', opcode=100, arg=7, argval='Hello world!', argrepr="'Hello world!'", offset=34, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='CALL_FUNCTION', opcode=131, arg=7, argval=7, argrepr='', offset=36, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=38, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_FAST', opcode=124, arg=2, argval='f', argrepr='f', offset=40, starts_line=8, is_jump_target=False, positions=None),
|
||||
Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=42, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='MAKE_FUNCTION', opcode=132, arg=9, argval=9, argrepr='defaults, closure', offset=14, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='STORE_FAST', opcode=125, arg=2, argval='f', argrepr='f', offset=16, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_GLOBAL', opcode=116, arg=0, argval='print', argrepr='print', offset=18, starts_line=7, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_DEREF', opcode=137, arg=0, argval='a', argrepr='a', offset=20, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_DEREF', opcode=137, arg=1, argval='b', argrepr='b', offset=22, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_CONST', opcode=100, arg=4, argval='', argrepr="''", offset=24, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_CONST', opcode=100, arg=5, argval=1, argrepr='1', offset=26, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='BUILD_LIST', opcode=103, arg=0, argval=0, argrepr='', offset=28, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='BUILD_MAP', opcode=105, arg=0, argval=0, argrepr='', offset=30, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_CONST', opcode=100, arg=6, argval='Hello world!', argrepr="'Hello world!'", offset=32, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='CALL_FUNCTION', opcode=131, arg=7, argval=7, argrepr='', offset=34, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=36, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_FAST', opcode=124, arg=2, argval='f', argrepr='f', offset=38, starts_line=8, is_jump_target=False, positions=None),
|
||||
Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=40, starts_line=None, is_jump_target=False, positions=None),
|
||||
]
|
||||
|
||||
|
||||
expected_opinfo_f = [
|
||||
Instruction(opname='MAKE_CELL', opcode=135, arg=0, argval='c', argrepr='c', offset=0, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='MAKE_CELL', opcode=135, arg=1, argval='d', argrepr='d', offset=2, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_CONST', opcode=100, arg=5, argval=(5, 6), argrepr='(5, 6)', offset=4, starts_line=3, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_CONST', opcode=100, arg=4, argval=(5, 6), argrepr='(5, 6)', offset=4, starts_line=3, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_CLOSURE', opcode=136, arg=3, argval='a', argrepr='a', offset=6, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_CLOSURE', opcode=136, arg=4, argval='b', argrepr='b', offset=8, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_CLOSURE', opcode=136, arg=0, argval='c', argrepr='c', offset=10, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_CLOSURE', opcode=136, arg=1, argval='d', argrepr='d', offset=12, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='BUILD_TUPLE', opcode=102, arg=4, argval=4, argrepr='', offset=14, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_CONST', opcode=100, arg=3, argval=code_object_inner, argrepr=repr(code_object_inner), offset=16, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_CONST', opcode=100, arg=4, argval='outer.<locals>.f.<locals>.inner', argrepr="'outer.<locals>.f.<locals>.inner'", offset=18, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='MAKE_FUNCTION', opcode=132, arg=9, argval=9, argrepr='defaults, closure', offset=20, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='STORE_FAST', opcode=125, arg=2, argval='inner', argrepr='inner', offset=22, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_GLOBAL', opcode=116, arg=0, argval='print', argrepr='print', offset=24, starts_line=5, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_DEREF', opcode=137, arg=3, argval='a', argrepr='a', offset=26, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_DEREF', opcode=137, arg=4, argval='b', argrepr='b', offset=28, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_DEREF', opcode=137, arg=0, argval='c', argrepr='c', offset=30, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_DEREF', opcode=137, arg=1, argval='d', argrepr='d', offset=32, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='CALL_FUNCTION', opcode=131, arg=4, argval=4, argrepr='', offset=34, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=36, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_FAST', opcode=124, arg=2, argval='inner', argrepr='inner', offset=38, starts_line=6, is_jump_target=False, positions=None),
|
||||
Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=40, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='MAKE_FUNCTION', opcode=132, arg=9, argval=9, argrepr='defaults, closure', offset=18, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='STORE_FAST', opcode=125, arg=2, argval='inner', argrepr='inner', offset=20, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_GLOBAL', opcode=116, arg=0, argval='print', argrepr='print', offset=22, starts_line=5, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_DEREF', opcode=137, arg=3, argval='a', argrepr='a', offset=24, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_DEREF', opcode=137, arg=4, argval='b', argrepr='b', offset=26, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_DEREF', opcode=137, arg=0, argval='c', argrepr='c', offset=28, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_DEREF', opcode=137, arg=1, argval='d', argrepr='d', offset=30, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='CALL_FUNCTION', opcode=131, arg=4, argval=4, argrepr='', offset=32, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=34, starts_line=None, is_jump_target=False, positions=None),
|
||||
Instruction(opname='LOAD_FAST', opcode=124, arg=2, argval='inner', argrepr='inner', offset=36, starts_line=6, is_jump_target=False, positions=None),
|
||||
Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=38, starts_line=None, is_jump_target=False, positions=None),
|
||||
]
|
||||
|
||||
expected_opinfo_inner = [
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
Added the ``co_qualname`` to the ``PyCodeObject`` structure to propagate the
|
||||
qualified name from the compiler to code objects.
|
||||
|
||||
Patch by Gabriele N. Tornetta
|
|
@ -5,8 +5,8 @@ preserve
|
|||
PyDoc_STRVAR(code_new__doc__,
|
||||
"code(argcount, posonlyargcount, kwonlyargcount, nlocals, stacksize,\n"
|
||||
" flags, codestring, constants, names, varnames, filename, name,\n"
|
||||
" firstlineno, linetable, endlinetable, columntable, exceptiontable,\n"
|
||||
" freevars=(), cellvars=(), /)\n"
|
||||
" qualname, firstlineno, linetable, endlinetable, columntable,\n"
|
||||
" exceptiontable, freevars=(), cellvars=(), /)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Create a code object. Not for the faint of heart.");
|
||||
|
@ -16,9 +16,10 @@ code_new_impl(PyTypeObject *type, int argcount, int posonlyargcount,
|
|||
int kwonlyargcount, int nlocals, int stacksize, int flags,
|
||||
PyObject *code, PyObject *consts, PyObject *names,
|
||||
PyObject *varnames, PyObject *filename, PyObject *name,
|
||||
int firstlineno, PyObject *linetable, PyObject *endlinetable,
|
||||
PyObject *columntable, PyObject *exceptiontable,
|
||||
PyObject *freevars, PyObject *cellvars);
|
||||
PyObject *qualname, int firstlineno, PyObject *linetable,
|
||||
PyObject *endlinetable, PyObject *columntable,
|
||||
PyObject *exceptiontable, PyObject *freevars,
|
||||
PyObject *cellvars);
|
||||
|
||||
static PyObject *
|
||||
code_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
||||
|
@ -36,6 +37,7 @@ code_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|||
PyObject *varnames;
|
||||
PyObject *filename;
|
||||
PyObject *name;
|
||||
PyObject *qualname;
|
||||
int firstlineno;
|
||||
PyObject *linetable;
|
||||
PyObject *endlinetable;
|
||||
|
@ -48,7 +50,7 @@ code_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|||
!_PyArg_NoKeywords("code", kwargs)) {
|
||||
goto exit;
|
||||
}
|
||||
if (!_PyArg_CheckPositional("code", PyTuple_GET_SIZE(args), 17, 19)) {
|
||||
if (!_PyArg_CheckPositional("code", PyTuple_GET_SIZE(args), 18, 20)) {
|
||||
goto exit;
|
||||
}
|
||||
argcount = _PyLong_AsInt(PyTuple_GET_ITEM(args, 0));
|
||||
|
@ -111,38 +113,38 @@ code_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|||
goto exit;
|
||||
}
|
||||
name = PyTuple_GET_ITEM(args, 11);
|
||||
firstlineno = _PyLong_AsInt(PyTuple_GET_ITEM(args, 12));
|
||||
if (!PyUnicode_Check(PyTuple_GET_ITEM(args, 12))) {
|
||||
_PyArg_BadArgument("code", "argument 13", "str", PyTuple_GET_ITEM(args, 12));
|
||||
goto exit;
|
||||
}
|
||||
if (PyUnicode_READY(PyTuple_GET_ITEM(args, 12)) == -1) {
|
||||
goto exit;
|
||||
}
|
||||
qualname = PyTuple_GET_ITEM(args, 12);
|
||||
firstlineno = _PyLong_AsInt(PyTuple_GET_ITEM(args, 13));
|
||||
if (firstlineno == -1 && PyErr_Occurred()) {
|
||||
goto exit;
|
||||
}
|
||||
if (!PyBytes_Check(PyTuple_GET_ITEM(args, 13))) {
|
||||
_PyArg_BadArgument("code", "argument 14", "bytes", PyTuple_GET_ITEM(args, 13));
|
||||
goto exit;
|
||||
}
|
||||
linetable = PyTuple_GET_ITEM(args, 13);
|
||||
if (!PyBytes_Check(PyTuple_GET_ITEM(args, 14))) {
|
||||
_PyArg_BadArgument("code", "argument 15", "bytes", PyTuple_GET_ITEM(args, 14));
|
||||
goto exit;
|
||||
}
|
||||
endlinetable = PyTuple_GET_ITEM(args, 14);
|
||||
linetable = PyTuple_GET_ITEM(args, 14);
|
||||
if (!PyBytes_Check(PyTuple_GET_ITEM(args, 15))) {
|
||||
_PyArg_BadArgument("code", "argument 16", "bytes", PyTuple_GET_ITEM(args, 15));
|
||||
goto exit;
|
||||
}
|
||||
columntable = PyTuple_GET_ITEM(args, 15);
|
||||
endlinetable = PyTuple_GET_ITEM(args, 15);
|
||||
if (!PyBytes_Check(PyTuple_GET_ITEM(args, 16))) {
|
||||
_PyArg_BadArgument("code", "argument 17", "bytes", PyTuple_GET_ITEM(args, 16));
|
||||
goto exit;
|
||||
}
|
||||
exceptiontable = PyTuple_GET_ITEM(args, 16);
|
||||
if (PyTuple_GET_SIZE(args) < 18) {
|
||||
goto skip_optional;
|
||||
}
|
||||
if (!PyTuple_Check(PyTuple_GET_ITEM(args, 17))) {
|
||||
_PyArg_BadArgument("code", "argument 18", "tuple", PyTuple_GET_ITEM(args, 17));
|
||||
columntable = PyTuple_GET_ITEM(args, 16);
|
||||
if (!PyBytes_Check(PyTuple_GET_ITEM(args, 17))) {
|
||||
_PyArg_BadArgument("code", "argument 18", "bytes", PyTuple_GET_ITEM(args, 17));
|
||||
goto exit;
|
||||
}
|
||||
freevars = PyTuple_GET_ITEM(args, 17);
|
||||
exceptiontable = PyTuple_GET_ITEM(args, 17);
|
||||
if (PyTuple_GET_SIZE(args) < 19) {
|
||||
goto skip_optional;
|
||||
}
|
||||
|
@ -150,9 +152,17 @@ code_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|||
_PyArg_BadArgument("code", "argument 19", "tuple", PyTuple_GET_ITEM(args, 18));
|
||||
goto exit;
|
||||
}
|
||||
cellvars = PyTuple_GET_ITEM(args, 18);
|
||||
freevars = PyTuple_GET_ITEM(args, 18);
|
||||
if (PyTuple_GET_SIZE(args) < 20) {
|
||||
goto skip_optional;
|
||||
}
|
||||
if (!PyTuple_Check(PyTuple_GET_ITEM(args, 19))) {
|
||||
_PyArg_BadArgument("code", "argument 20", "tuple", PyTuple_GET_ITEM(args, 19));
|
||||
goto exit;
|
||||
}
|
||||
cellvars = PyTuple_GET_ITEM(args, 19);
|
||||
skip_optional:
|
||||
return_value = code_new_impl(type, argcount, posonlyargcount, kwonlyargcount, nlocals, stacksize, flags, code, consts, names, varnames, filename, name, firstlineno, linetable, endlinetable, columntable, exceptiontable, freevars, cellvars);
|
||||
return_value = code_new_impl(type, argcount, posonlyargcount, kwonlyargcount, nlocals, stacksize, flags, code, consts, names, varnames, filename, name, qualname, firstlineno, linetable, endlinetable, columntable, exceptiontable, freevars, cellvars);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
|
@ -164,8 +174,8 @@ PyDoc_STRVAR(code_replace__doc__,
|
|||
" co_flags=-1, co_firstlineno=-1, co_code=None, co_consts=None,\n"
|
||||
" co_names=None, co_varnames=None, co_freevars=None,\n"
|
||||
" co_cellvars=None, co_filename=None, co_name=None,\n"
|
||||
" co_linetable=None, co_endlinetable=None, co_columntable=None,\n"
|
||||
" co_exceptiontable=None)\n"
|
||||
" co_qualname=None, co_linetable=None, co_endlinetable=None,\n"
|
||||
" co_columntable=None, co_exceptiontable=None)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Return a copy of the code object with new values for the specified fields.");
|
||||
|
@ -181,7 +191,8 @@ code_replace_impl(PyCodeObject *self, int co_argcount,
|
|||
PyObject *co_consts, PyObject *co_names,
|
||||
PyObject *co_varnames, PyObject *co_freevars,
|
||||
PyObject *co_cellvars, PyObject *co_filename,
|
||||
PyObject *co_name, PyBytesObject *co_linetable,
|
||||
PyObject *co_name, PyObject *co_qualname,
|
||||
PyBytesObject *co_linetable,
|
||||
PyBytesObject *co_endlinetable,
|
||||
PyBytesObject *co_columntable,
|
||||
PyBytesObject *co_exceptiontable);
|
||||
|
@ -190,9 +201,9 @@ static PyObject *
|
|||
code_replace(PyCodeObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
static const char * const _keywords[] = {"co_argcount", "co_posonlyargcount", "co_kwonlyargcount", "co_nlocals", "co_stacksize", "co_flags", "co_firstlineno", "co_code", "co_consts", "co_names", "co_varnames", "co_freevars", "co_cellvars", "co_filename", "co_name", "co_linetable", "co_endlinetable", "co_columntable", "co_exceptiontable", NULL};
|
||||
static const char * const _keywords[] = {"co_argcount", "co_posonlyargcount", "co_kwonlyargcount", "co_nlocals", "co_stacksize", "co_flags", "co_firstlineno", "co_code", "co_consts", "co_names", "co_varnames", "co_freevars", "co_cellvars", "co_filename", "co_name", "co_qualname", "co_linetable", "co_endlinetable", "co_columntable", "co_exceptiontable", NULL};
|
||||
static _PyArg_Parser _parser = {NULL, _keywords, "replace", 0};
|
||||
PyObject *argsbuf[19];
|
||||
PyObject *argsbuf[20];
|
||||
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
|
||||
int co_argcount = self->co_argcount;
|
||||
int co_posonlyargcount = self->co_posonlyargcount;
|
||||
|
@ -209,6 +220,7 @@ code_replace(PyCodeObject *self, PyObject *const *args, Py_ssize_t nargs, PyObje
|
|||
PyObject *co_cellvars = self->co_cellvars;
|
||||
PyObject *co_filename = self->co_filename;
|
||||
PyObject *co_name = self->co_name;
|
||||
PyObject *co_qualname = self->co_qualname;
|
||||
PyBytesObject *co_linetable = (PyBytesObject *)self->co_linetable;
|
||||
PyBytesObject *co_endlinetable = (PyBytesObject *)self->co_endlinetable;
|
||||
PyBytesObject *co_columntable = (PyBytesObject *)self->co_columntable;
|
||||
|
@ -371,42 +383,55 @@ code_replace(PyCodeObject *self, PyObject *const *args, Py_ssize_t nargs, PyObje
|
|||
}
|
||||
}
|
||||
if (args[15]) {
|
||||
if (!PyBytes_Check(args[15])) {
|
||||
_PyArg_BadArgument("replace", "argument 'co_linetable'", "bytes", args[15]);
|
||||
if (!PyUnicode_Check(args[15])) {
|
||||
_PyArg_BadArgument("replace", "argument 'co_qualname'", "str", args[15]);
|
||||
goto exit;
|
||||
}
|
||||
co_linetable = (PyBytesObject *)args[15];
|
||||
if (PyUnicode_READY(args[15]) == -1) {
|
||||
goto exit;
|
||||
}
|
||||
co_qualname = args[15];
|
||||
if (!--noptargs) {
|
||||
goto skip_optional_kwonly;
|
||||
}
|
||||
}
|
||||
if (args[16]) {
|
||||
if (!PyBytes_Check(args[16])) {
|
||||
_PyArg_BadArgument("replace", "argument 'co_endlinetable'", "bytes", args[16]);
|
||||
_PyArg_BadArgument("replace", "argument 'co_linetable'", "bytes", args[16]);
|
||||
goto exit;
|
||||
}
|
||||
co_endlinetable = (PyBytesObject *)args[16];
|
||||
co_linetable = (PyBytesObject *)args[16];
|
||||
if (!--noptargs) {
|
||||
goto skip_optional_kwonly;
|
||||
}
|
||||
}
|
||||
if (args[17]) {
|
||||
if (!PyBytes_Check(args[17])) {
|
||||
_PyArg_BadArgument("replace", "argument 'co_columntable'", "bytes", args[17]);
|
||||
_PyArg_BadArgument("replace", "argument 'co_endlinetable'", "bytes", args[17]);
|
||||
goto exit;
|
||||
}
|
||||
co_columntable = (PyBytesObject *)args[17];
|
||||
co_endlinetable = (PyBytesObject *)args[17];
|
||||
if (!--noptargs) {
|
||||
goto skip_optional_kwonly;
|
||||
}
|
||||
}
|
||||
if (!PyBytes_Check(args[18])) {
|
||||
_PyArg_BadArgument("replace", "argument 'co_exceptiontable'", "bytes", args[18]);
|
||||
if (args[18]) {
|
||||
if (!PyBytes_Check(args[18])) {
|
||||
_PyArg_BadArgument("replace", "argument 'co_columntable'", "bytes", args[18]);
|
||||
goto exit;
|
||||
}
|
||||
co_columntable = (PyBytesObject *)args[18];
|
||||
if (!--noptargs) {
|
||||
goto skip_optional_kwonly;
|
||||
}
|
||||
}
|
||||
if (!PyBytes_Check(args[19])) {
|
||||
_PyArg_BadArgument("replace", "argument 'co_exceptiontable'", "bytes", args[19]);
|
||||
goto exit;
|
||||
}
|
||||
co_exceptiontable = (PyBytesObject *)args[18];
|
||||
co_exceptiontable = (PyBytesObject *)args[19];
|
||||
skip_optional_kwonly:
|
||||
return_value = code_replace_impl(self, co_argcount, co_posonlyargcount, co_kwonlyargcount, co_nlocals, co_stacksize, co_flags, co_firstlineno, co_code, co_consts, co_names, co_varnames, co_freevars, co_cellvars, co_filename, co_name, co_linetable, co_endlinetable, co_columntable, co_exceptiontable);
|
||||
return_value = code_replace_impl(self, co_argcount, co_posonlyargcount, co_kwonlyargcount, co_nlocals, co_stacksize, co_flags, co_firstlineno, co_code, co_consts, co_names, co_varnames, co_freevars, co_cellvars, co_filename, co_name, co_qualname, co_linetable, co_endlinetable, co_columntable, co_exceptiontable);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
|
@ -448,4 +473,4 @@ code__varname_from_oparg(PyCodeObject *self, PyObject *const *args, Py_ssize_t n
|
|||
exit:
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=a75c9ca013d9bf7d input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=12b394f0212b1c1e input=a9049054013a1b77]*/
|
||||
|
|
|
@ -242,6 +242,7 @@ _PyCode_Validate(struct _PyCodeConstructor *con)
|
|||
PyTuple_GET_SIZE(con->localsplusnames)
|
||||
!= PyBytes_GET_SIZE(con->localspluskinds) ||
|
||||
con->name == NULL || !PyUnicode_Check(con->name) ||
|
||||
con->qualname == NULL || !PyUnicode_Check(con->qualname) ||
|
||||
con->filename == NULL || !PyUnicode_Check(con->filename) ||
|
||||
con->linetable == NULL || !PyBytes_Check(con->linetable) ||
|
||||
con->endlinetable == NULL ||
|
||||
|
@ -300,6 +301,8 @@ init_code(PyCodeObject *co, struct _PyCodeConstructor *con)
|
|||
co->co_filename = con->filename;
|
||||
Py_INCREF(con->name);
|
||||
co->co_name = con->name;
|
||||
Py_INCREF(con->qualname);
|
||||
co->co_qualname = con->qualname;
|
||||
co->co_flags = con->flags;
|
||||
|
||||
Py_INCREF(con->code);
|
||||
|
@ -359,6 +362,9 @@ _PyCode_New(struct _PyCodeConstructor *con)
|
|||
if (PyUnicode_READY(con->name) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
if (PyUnicode_READY(con->qualname) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
if (PyUnicode_READY(con->filename) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -393,7 +399,8 @@ PyCode_NewWithPosOnlyArgs(int argcount, int posonlyargcount, int kwonlyargcount,
|
|||
int nlocals, int stacksize, int flags,
|
||||
PyObject *code, PyObject *consts, PyObject *names,
|
||||
PyObject *varnames, PyObject *freevars, PyObject *cellvars,
|
||||
PyObject *filename, PyObject *name, int firstlineno,
|
||||
PyObject *filename, PyObject *name,
|
||||
PyObject *qualname, int firstlineno,
|
||||
PyObject *linetable, PyObject *endlinetable,
|
||||
PyObject *columntable, PyObject *exceptiontable)
|
||||
{
|
||||
|
@ -465,6 +472,7 @@ PyCode_NewWithPosOnlyArgs(int argcount, int posonlyargcount, int kwonlyargcount,
|
|||
struct _PyCodeConstructor con = {
|
||||
.filename = filename,
|
||||
.name = name,
|
||||
.qualname = qualname,
|
||||
.flags = flags,
|
||||
|
||||
.code = code,
|
||||
|
@ -522,15 +530,15 @@ PyCode_New(int argcount, int kwonlyargcount,
|
|||
int nlocals, int stacksize, int flags,
|
||||
PyObject *code, PyObject *consts, PyObject *names,
|
||||
PyObject *varnames, PyObject *freevars, PyObject *cellvars,
|
||||
PyObject *filename, PyObject *name, int firstlineno,
|
||||
PyObject *linetable, PyObject *endlinetable,
|
||||
PyObject *filename, PyObject *name, PyObject *qualname,
|
||||
int firstlineno, PyObject *linetable, PyObject *endlinetable,
|
||||
PyObject *columntable, PyObject *exceptiontable)
|
||||
{
|
||||
return PyCode_NewWithPosOnlyArgs(argcount, 0, kwonlyargcount, nlocals,
|
||||
stacksize, flags, code, consts, names,
|
||||
varnames, freevars, cellvars, filename,
|
||||
name, firstlineno, linetable, endlinetable,
|
||||
columntable, exceptiontable);
|
||||
name, qualname, firstlineno, linetable,
|
||||
endlinetable, columntable, exceptiontable);
|
||||
}
|
||||
|
||||
PyCodeObject *
|
||||
|
@ -562,6 +570,7 @@ PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno)
|
|||
struct _PyCodeConstructor con = {
|
||||
.filename = filename_ob,
|
||||
.name = funcname_ob,
|
||||
.qualname = funcname_ob,
|
||||
.code = emptystring,
|
||||
.firstlineno = firstlineno,
|
||||
.linetable = emptystring,
|
||||
|
@ -1210,6 +1219,7 @@ code.__new__ as code_new
|
|||
varnames: object(subclass_of="&PyTuple_Type")
|
||||
filename: unicode
|
||||
name: unicode
|
||||
qualname: unicode
|
||||
firstlineno: int
|
||||
linetable: object(subclass_of="&PyBytes_Type")
|
||||
endlinetable: object(subclass_of="&PyBytes_Type")
|
||||
|
@ -1227,10 +1237,11 @@ code_new_impl(PyTypeObject *type, int argcount, int posonlyargcount,
|
|||
int kwonlyargcount, int nlocals, int stacksize, int flags,
|
||||
PyObject *code, PyObject *consts, PyObject *names,
|
||||
PyObject *varnames, PyObject *filename, PyObject *name,
|
||||
int firstlineno, PyObject *linetable, PyObject *endlinetable,
|
||||
PyObject *columntable, PyObject *exceptiontable,
|
||||
PyObject *freevars, PyObject *cellvars)
|
||||
/*[clinic end generated code: output=014e77ed052be1a9 input=b22afe3c31be0b6e]*/
|
||||
PyObject *qualname, int firstlineno, PyObject *linetable,
|
||||
PyObject *endlinetable, PyObject *columntable,
|
||||
PyObject *exceptiontable, PyObject *freevars,
|
||||
PyObject *cellvars)
|
||||
/*[clinic end generated code: output=e1d2086aa8da7c08 input=ba12d68bd8fa0620]*/
|
||||
{
|
||||
PyObject *co = NULL;
|
||||
PyObject *ournames = NULL;
|
||||
|
@ -1238,8 +1249,8 @@ code_new_impl(PyTypeObject *type, int argcount, int posonlyargcount,
|
|||
PyObject *ourfreevars = NULL;
|
||||
PyObject *ourcellvars = NULL;
|
||||
|
||||
if (PySys_Audit("code.__new__", "OOOiiiiii",
|
||||
code, filename, name, argcount, posonlyargcount,
|
||||
if (PySys_Audit("code.__new__", "OOOOiiiiii",
|
||||
code, filename, name, qualname, argcount, posonlyargcount,
|
||||
kwonlyargcount, nlocals, stacksize, flags) < 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
@ -1296,9 +1307,9 @@ code_new_impl(PyTypeObject *type, int argcount, int posonlyargcount,
|
|||
code, consts, ournames,
|
||||
ourvarnames, ourfreevars,
|
||||
ourcellvars, filename,
|
||||
name, firstlineno, linetable,
|
||||
endlinetable, columntable,
|
||||
exceptiontable
|
||||
name, qualname, firstlineno,
|
||||
linetable, endlinetable,
|
||||
columntable, exceptiontable
|
||||
);
|
||||
cleanup:
|
||||
Py_XDECREF(ournames);
|
||||
|
@ -1336,6 +1347,7 @@ code_dealloc(PyCodeObject *co)
|
|||
Py_XDECREF(co->co_cellvars);
|
||||
Py_XDECREF(co->co_filename);
|
||||
Py_XDECREF(co->co_name);
|
||||
Py_XDECREF(co->co_qualname);
|
||||
Py_XDECREF(co->co_linetable);
|
||||
Py_XDECREF(co->co_endlinetable);
|
||||
Py_XDECREF(co->co_columntable);
|
||||
|
@ -1474,6 +1486,7 @@ static PyMemberDef code_memberlist[] = {
|
|||
{"co_names", T_OBJECT, OFF(co_names), READONLY},
|
||||
{"co_filename", T_OBJECT, OFF(co_filename), READONLY},
|
||||
{"co_name", T_OBJECT, OFF(co_name), READONLY},
|
||||
{"co_qualname", T_OBJECT, OFF(co_qualname), READONLY},
|
||||
{"co_firstlineno", T_INT, OFF(co_firstlineno), READONLY},
|
||||
{"co_linetable", T_OBJECT, OFF(co_linetable), READONLY},
|
||||
{"co_endlinetable", T_OBJECT, OFF(co_endlinetable), READONLY},
|
||||
|
@ -1570,6 +1583,7 @@ code.replace
|
|||
co_cellvars: object(subclass_of="&PyTuple_Type", c_default="self->co_cellvars") = None
|
||||
co_filename: unicode(c_default="self->co_filename") = None
|
||||
co_name: unicode(c_default="self->co_name") = None
|
||||
co_qualname: unicode(c_default="self->co_qualname") = None
|
||||
co_linetable: PyBytesObject(c_default="(PyBytesObject *)self->co_linetable") = None
|
||||
co_endlinetable: PyBytesObject(c_default="(PyBytesObject *)self->co_endlinetable") = None
|
||||
co_columntable: PyBytesObject(c_default="(PyBytesObject *)self->co_columntable") = None
|
||||
|
@ -1586,11 +1600,12 @@ code_replace_impl(PyCodeObject *self, int co_argcount,
|
|||
PyObject *co_consts, PyObject *co_names,
|
||||
PyObject *co_varnames, PyObject *co_freevars,
|
||||
PyObject *co_cellvars, PyObject *co_filename,
|
||||
PyObject *co_name, PyBytesObject *co_linetable,
|
||||
PyObject *co_name, PyObject *co_qualname,
|
||||
PyBytesObject *co_linetable,
|
||||
PyBytesObject *co_endlinetable,
|
||||
PyBytesObject *co_columntable,
|
||||
PyBytesObject *co_exceptiontable)
|
||||
/*[clinic end generated code: output=1189cc8699162b11 input=29c8d25567d86c0d]*/
|
||||
/*[clinic end generated code: output=da699b6261fddc13 input=a8e93823df0aec35]*/
|
||||
{
|
||||
#define CHECK_INT_ARG(ARG) \
|
||||
if (ARG < 0) { \
|
||||
|
@ -1609,8 +1624,8 @@ code_replace_impl(PyCodeObject *self, int co_argcount,
|
|||
|
||||
#undef CHECK_INT_ARG
|
||||
|
||||
if (PySys_Audit("code.__new__", "OOOiiiiii",
|
||||
co_code, co_filename, co_name, co_argcount,
|
||||
if (PySys_Audit("code.__new__", "OOOOiiiiii",
|
||||
co_code, co_filename, co_name, co_qualname, co_argcount,
|
||||
co_posonlyargcount, co_kwonlyargcount, co_nlocals,
|
||||
co_stacksize, co_flags) < 0) {
|
||||
return NULL;
|
||||
|
@ -1646,8 +1661,9 @@ code_replace_impl(PyCodeObject *self, int co_argcount,
|
|||
co_argcount, co_posonlyargcount, co_kwonlyargcount, co_nlocals,
|
||||
co_stacksize, co_flags, (PyObject*)co_code, co_consts, co_names,
|
||||
co_varnames, co_freevars, co_cellvars, co_filename, co_name,
|
||||
co_firstlineno, (PyObject*)co_linetable, (PyObject*)co_endlinetable,
|
||||
(PyObject*)co_columntable, (PyObject*)co_exceptiontable);
|
||||
co_qualname, co_firstlineno, (PyObject*)co_linetable,
|
||||
(PyObject*)co_endlinetable, (PyObject*)co_columntable,
|
||||
(PyObject*)co_exceptiontable);
|
||||
|
||||
error:
|
||||
Py_XDECREF(varnames);
|
||||
|
|
|
@ -22,9 +22,11 @@ PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname
|
|||
PyObject *name = code_obj->co_name;
|
||||
assert(name != NULL);
|
||||
Py_INCREF(name);
|
||||
|
||||
if (!qualname) {
|
||||
qualname = name;
|
||||
qualname = code_obj->co_qualname;
|
||||
}
|
||||
assert(qualname != NULL);
|
||||
Py_INCREF(qualname);
|
||||
|
||||
PyObject *consts = code_obj->co_consts;
|
||||
|
|
|
@ -840,7 +840,7 @@ gen_new_with_qualname(PyTypeObject *type, PyFrameObject *f,
|
|||
if (qualname != NULL)
|
||||
gen->gi_qualname = qualname;
|
||||
else
|
||||
gen->gi_qualname = gen->gi_name;
|
||||
gen->gi_qualname = gen->gi_code->co_qualname;
|
||||
Py_INCREF(gen->gi_qualname);
|
||||
_PyObject_GC_TRACK(gen);
|
||||
return (PyObject *)gen;
|
||||
|
|
|
@ -21,14 +21,15 @@ unsigned char M_test_frozenmain[] = {
|
|||
103,118,90,11,103,101,116,95,99,111,110,102,105,103,115,114,
|
||||
2,0,0,0,218,3,107,101,121,169,0,243,0,0,0,0,
|
||||
250,18,116,101,115,116,95,102,114,111,122,101,110,109,97,105,
|
||||
110,46,112,121,218,8,60,109,111,100,117,108,101,62,1,0,
|
||||
0,0,115,16,0,0,0,8,3,8,1,8,2,12,1,12,
|
||||
1,8,1,26,7,4,249,115,18,0,0,0,8,3,8,1,
|
||||
8,2,12,1,12,1,2,7,4,1,2,249,30,7,115,86,
|
||||
0,0,0,1,11,1,11,1,11,1,11,1,25,1,25,1,
|
||||
25,1,25,1,6,7,27,1,28,1,28,1,6,7,17,19,
|
||||
22,19,27,1,28,1,28,10,27,10,39,10,41,42,50,10,
|
||||
51,1,7,12,2,1,42,1,42,5,8,5,10,11,41,21,
|
||||
24,11,41,11,41,28,34,35,38,28,39,11,41,11,41,5,
|
||||
42,5,42,5,42,1,42,1,42,114,9,0,0,0,
|
||||
110,46,112,121,218,8,60,109,111,100,117,108,101,62,114,11,
|
||||
0,0,0,1,0,0,0,115,16,0,0,0,8,3,8,1,
|
||||
8,2,12,1,12,1,8,1,26,7,4,249,115,18,0,0,
|
||||
0,8,3,8,1,8,2,12,1,12,1,2,7,4,1,2,
|
||||
249,30,7,115,86,0,0,0,1,11,1,11,1,11,1,11,
|
||||
1,25,1,25,1,25,1,25,1,6,7,27,1,28,1,28,
|
||||
1,6,7,17,19,22,19,27,1,28,1,28,10,27,10,39,
|
||||
10,41,42,50,10,51,1,7,12,2,1,42,1,42,5,8,
|
||||
5,10,11,41,21,24,11,41,11,41,28,34,35,38,28,39,
|
||||
11,41,11,41,5,42,5,42,5,42,1,42,1,42,114,9,
|
||||
0,0,0,
|
||||
};
|
||||
|
|
|
@ -4161,13 +4161,11 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
|
|||
}
|
||||
|
||||
case TARGET(MAKE_FUNCTION): {
|
||||
PyObject *qualname = POP();
|
||||
PyObject *codeobj = POP();
|
||||
PyFunctionObject *func = (PyFunctionObject *)
|
||||
PyFunction_NewWithQualName(codeobj, GLOBALS(), qualname);
|
||||
PyFunction_New(codeobj, GLOBALS());
|
||||
|
||||
Py_DECREF(codeobj);
|
||||
Py_DECREF(qualname);
|
||||
if (func == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
|
|
@ -1195,7 +1195,7 @@ stack_effect(int opcode, int oparg, int jump)
|
|||
case CALL_FUNCTION_EX:
|
||||
return -1 - ((oparg & 0x01) != 0);
|
||||
case MAKE_FUNCTION:
|
||||
return -1 - ((oparg & 0x01) != 0) - ((oparg & 0x02) != 0) -
|
||||
return 0 - ((oparg & 0x01) != 0) - ((oparg & 0x02) != 0) -
|
||||
((oparg & 0x04) != 0) - ((oparg & 0x08) != 0);
|
||||
case BUILD_SLICE:
|
||||
if (oparg == 3)
|
||||
|
@ -2138,7 +2138,6 @@ compiler_make_closure(struct compiler *c, PyCodeObject *co, Py_ssize_t flags,
|
|||
ADDOP_I(c, BUILD_TUPLE, co->co_nfreevars);
|
||||
}
|
||||
ADDOP_LOAD_CONST(c, (PyObject*)co);
|
||||
ADDOP_LOAD_CONST(c, qualname);
|
||||
ADDOP_I(c, MAKE_FUNCTION, flags);
|
||||
return 1;
|
||||
}
|
||||
|
@ -7389,7 +7388,6 @@ makecode(struct compiler *c, struct assembler *a, PyObject *constslist,
|
|||
PyObject *consts = NULL;
|
||||
PyObject *localsplusnames = NULL;
|
||||
PyObject *localspluskinds = NULL;
|
||||
PyObject *name = NULL;
|
||||
|
||||
names = dict_keys_inorder(c->u->u_names, 0);
|
||||
if (!names) {
|
||||
|
@ -7433,6 +7431,7 @@ makecode(struct compiler *c, struct assembler *a, PyObject *constslist,
|
|||
struct _PyCodeConstructor con = {
|
||||
.filename = c->c_filename,
|
||||
.name = c->u->u_name,
|
||||
.qualname = c->u->u_qualname ? c->u->u_qualname : c->u->u_name,
|
||||
.flags = flags,
|
||||
|
||||
.code = a->a_bytecode,
|
||||
|
@ -7475,7 +7474,6 @@ makecode(struct compiler *c, struct assembler *a, PyObject *constslist,
|
|||
Py_XDECREF(consts);
|
||||
Py_XDECREF(localsplusnames);
|
||||
Py_XDECREF(localspluskinds);
|
||||
Py_XDECREF(name);
|
||||
return co;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,8 @@ const unsigned char _Py_M__hello[] = {
|
|||
105,110,105,116,105,97,108,105,122,101,100,218,5,112,114,105,
|
||||
110,116,169,0,243,0,0,0,0,122,14,60,102,114,111,122,
|
||||
101,110,32,104,101,108,108,111,62,218,8,60,109,111,100,117,
|
||||
108,101,62,1,0,0,0,243,4,0,0,0,4,0,12,1,
|
||||
114,4,0,0,0,115,16,0,0,0,15,19,1,12,1,6,
|
||||
7,21,1,22,1,22,1,22,1,22,114,2,0,0,0,
|
||||
108,101,62,114,3,0,0,0,1,0,0,0,243,4,0,0,
|
||||
0,4,0,12,1,114,4,0,0,0,115,16,0,0,0,15,
|
||||
19,1,12,1,6,7,21,1,22,1,22,1,22,1,22,114,
|
||||
2,0,0,0,
|
||||
};
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -522,6 +522,7 @@ w_complex_object(PyObject *v, char flag, WFILE *p)
|
|||
w_object(co->co_localspluskinds, p);
|
||||
w_object(co->co_filename, p);
|
||||
w_object(co->co_name, p);
|
||||
w_object(co->co_qualname, p);
|
||||
w_long(co->co_firstlineno, p);
|
||||
w_object(co->co_linetable, p);
|
||||
w_object(co->co_endlinetable, p);
|
||||
|
@ -1315,6 +1316,7 @@ r_object(RFILE *p)
|
|||
PyObject *localspluskinds = NULL;
|
||||
PyObject *filename = NULL;
|
||||
PyObject *name = NULL;
|
||||
PyObject *qualname = NULL;
|
||||
int firstlineno;
|
||||
PyObject *linetable = NULL;
|
||||
PyObject* endlinetable = NULL;
|
||||
|
@ -1365,6 +1367,9 @@ r_object(RFILE *p)
|
|||
name = r_object(p);
|
||||
if (name == NULL)
|
||||
goto code_error;
|
||||
qualname = r_object(p);
|
||||
if (qualname == NULL)
|
||||
goto code_error;
|
||||
firstlineno = (int)r_long(p);
|
||||
if (firstlineno == -1 && PyErr_Occurred())
|
||||
break;
|
||||
|
@ -1384,6 +1389,7 @@ r_object(RFILE *p)
|
|||
struct _PyCodeConstructor con = {
|
||||
.filename = filename,
|
||||
.name = name,
|
||||
.qualname = qualname,
|
||||
.flags = flags,
|
||||
|
||||
.code = code,
|
||||
|
@ -1426,6 +1432,7 @@ r_object(RFILE *p)
|
|||
Py_XDECREF(localspluskinds);
|
||||
Py_XDECREF(filename);
|
||||
Py_XDECREF(name);
|
||||
Py_XDECREF(qualname);
|
||||
Py_XDECREF(linetable);
|
||||
Py_XDECREF(endlinetable);
|
||||
Py_XDECREF(columntable);
|
||||
|
|
Loading…
Reference in New Issue