FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-44347: [doc] clarify meaning of shutil.copytree's dirs_exist_ok kwarg by jdevries3133 · Pull Request #26643 · python/cpython · GitHub

Repository navigation

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
74727b9
bpo-44347: [doc] clarify meaning of shutil.copytree's dirs_exist_ok …
jdevries3133 Jun 9, 2021
0fa96d1
bpo-44347: [doc] clarify shutil.copytree dirs_exist_ok kwarg
jdevries3133 Jun 10, 2021
318a99c
Merge branch 'main' of github.com:python/cpython into bpo-44347
jdevries3133 Jun 10, 2021
9b262b8
bpo-44347: [doc|fix]: add NEWS.d entry, remove use of default context
jdevries3133 Jun 10, 2021
952dbf1
Merge branch 'main' of github.com:python/cpython into bpo-44347
jdevries3133 Jun 10, 2021
e365e52
bpo-44347: [doc] better document argument shutil.copytree(dirs_exist_…
jdevries3133 Jun 11, 2021
eb3ee6f
Merge branch 'main' of github.com:python/cpython into bpo-44347
jdevries3133 Jun 11, 2021
d340c87
bpo-44347: [doc|fix]: add missed updated docstring from previous commit
jdevries3133 Jun 11, 2021
dd2f5c3
bpo-44381: Windows build now allows enabling control flow guard (GH-2…
zooba Jun 11, 2021
d8837d8
bpo-40128: Fix IDLE autocomplete on macOS (GH-26672)
thsubaku9 Jun 11, 2021
869f2fa
bpo-44339: Fix math.pow corner case to comply with IEEE 754 (GH-26606)
mdickinson Jun 12, 2021
29584b7
bpo-43475: Fix the Python implementation of hash of Decimal NaN (GH-2…
serhiy-storchaka Jun 12, 2021
b63a793
Add more const modifiers. (GH-26691)
serhiy-storchaka Jun 12, 2021
feca673
bpo-44376 - reduce pow() overhead for small exponents (GH-26662)
tim-one Jun 12, 2021
b1e8a39
bpo-44396: Update multi-line-start location when reallocating tokeniz…
pablogsal Jun 12, 2021
732ecab
bpo-44389: Remove duplicate SSL_OP_NO_TLSv1_2 flag (GH-26680)
Jun 12, 2021
2a93215
bpo-43425: Update test_c_parser not to use TempdirManager (GH-26693)
corona10 Jun 12, 2021
50aee65
Fix typos in multiple files (GH-26689)
enjoy-binbin Jun 13, 2021
6966890
Fix a potential reference-counting bug in long_pow (GH-26690)
mdickinson Jun 13, 2021
d1a2233
bpo-44389: Fix deprecation of OP_NO_TLSv1_3 (GH-26700)
tiran Jun 13, 2021
67d241b
bpo-44310: Note that lru_cache keep references to both arguments and…
rhettinger Jun 14, 2021
0208b06
bpo-44338: Port LOAD_GLOBAL to PEP 659 adaptive interpreter (GH-26638)
markshannon Jun 14, 2021
ad667a2
Remove accidentally duplicated STAT_INC (GH-26718)
markshannon Jun 14, 2021
6109bfa
bpo-38291: Remove mention of typing.io and typing.re again (GH-26113)
srittau Jun 14, 2021
101dc7e
Fix typo in lnotab_notes.txt (GH-26711)
P403n1x87 Jun 14, 2021
ed3d0b5
bpo-44409: Fix error location in tokenizer errors that happen during …
pablogsal Jun 14, 2021
44d2ad8
Fix a typo in _make_class_unpicklable() docstring (GH-26729)
akulakov Jun 15, 2021
77b67cb
Add extra stats for attribute misses (GH-26732)
markshannon Jun 15, 2021
1628fb8
bpo-42064: Move sqlite3 types to global state (GH-26537)
Jun 15, 2021
c60a9c6
bpo-42972: _thread.RLock implements the GH protocol (GH-26734)
vstinner Jun 15, 2021
1d63579
bpo-44422: Fix threading.enumerate() reentrant call (GH-26727)
vstinner Jun 15, 2021
3e45844
[Enum] improve test, add andrei kulakov to ACKS (GH-26726)
ethanfurman Jun 15, 2021
3e2e824
bpo-43475: Add what's new entry for NaN hash changes (GH-26725)
mdickinson Jun 15, 2021
fc3ca19
bpo-43693: Eliminate unused "fast locals". (gh-26587)
ericsnowcurrently Jun 15, 2021
949a2b7
bpo-44342: [Enum] sync current docs to 3.10 (GH-26750)
ethanfurman Jun 16, 2021
b7f3aca
bpo-43795: Don't list private names in the limited API (GH-26740)
encukou Jun 16, 2021
8fc6dd3
bpo-44422: threading.Thread reuses the _delete() method (GH-26741)
vstinner Jun 16, 2021
66eab7a
bpo-38211: Clean up type_init() (GH-16257)
sir-sigurd Jun 16, 2021
e78f506
bpo-44392: Add Py_GenericAlias to C API docs (GH-26724)
Fidget-Spinner Jun 16, 2021
66c976d
bpo-44426: Use of 'complex' as a C variable name confuses Sphinx; cha…
mdickinson Jun 16, 2021
439482a
bpo-44389: Fix typo in ssl deprecation warning message (GH-26754)
j178 Jun 17, 2021
76bed3a
bpo-43908: Make heap types converted during 3.10 alpha immutable (GH-…
Jun 17, 2021
f446866
Do not clear globals or builtins when calling clear() on a frame obje…
markshannon Jun 17, 2021
3010391
bpo-43024: improve signature (in help, etc) for functions taking sent…
iritkatriel Jun 17, 2021
6e231c0
bpo-44310: Add a FAQ entry for caching method calls (GH-26731)
rhettinger Jun 17, 2021
9ad9fd7
bpo-44032: Move pointer to code object from frame-object to frame spe…
markshannon Jun 18, 2021
95aa9d6
Reorganize the pattern matching suite (GH-26661)
brandtbucher Jun 18, 2021
d808829
bpo-44451: Reset DeprecationWarning filters in test_importlib.test_en…
hroncok Jun 18, 2021
f3dd96a
bpo-43945: [Enum] reduce scope of new format() behavior (GH-26752)
ethanfurman Jun 18, 2021
d4b87bc
Add a note about NameError/AttributeError suggestions with custom err…
pablogsal Jun 18, 2021
32fd669
Remove dubious suggestion (GH-26789)
rhettinger Jun 19, 2021
df719d4
bpo-38820: Test with OpenSSL 3.0.0-beta1 (GH-26769)
tiran Jun 19, 2021
0cf3409
bpo-43298: Improved error message when building without the Windows S…
zooba Jun 19, 2021
07f631d
bpo-44426: Fix use of the C keyword 'default' as a variable name (GH-…
mdickinson Jun 19, 2021
f879593
Merge remote-tracking branch 'upstream/main' into pr_26643
terryjreedy Jun 19, 2021
d035783
commit suggested change from @terryjreedy
jdevries3133 Jun 20, 2021
a1f767c
commit suggested change from @terryjreedy
jdevries3133 Jun 20, 2021
7151b46
commit suggested change from @terryjreedy
jdevries3133 Jun 20, 2021
a0a46be
commit suggested change from @terryjreedy
jdevries3133 Jun 20, 2021
e02e998
bpo-38291: DeprecationWarning when importing typing.{io,re} (#26719)
srittau Jun 19, 2021
82ae9d6
bpo-44347: fix spelling
jdevries3133 Jun 20, 2021
568c773
Merge remote-tracking branch 'upstream/main' into pr_26643
terryjreedy Jun 20, 2021
b2d7cc0
bpo-44347: add note to further clarify edge case
jdevries3133 Jun 21, 2021
a07b324
bpo-44347: (small fix) remove redundant line from example
jdevries3133 Jun 21, 2021
48f30ee
bpo-44347: highlight relationship to os.makedirs
jdevries3133 Jun 21, 2021
5b8366a
small rewording fix
jdevries3133 Jul 1, 2021
60a0eb6
Merge branch 'main' of github.com:python/cpython into bpo-44347
jdevries3133 Apr 8, 2022
8303dc5
revise old changes
jdevries3133 Apr 8, 2022
c169b1d
apply @JelleZijlstra's feedback
jdevries3133 Apr 9, 2022
ac3f837
update docstring
jdevries3133 Apr 10, 2022
File filter

Filter by extension

Filter by extension .c  (5) .h  (4) .py  (2) .rst  (1) All 4 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
Prev Previous commit
Next Next commit
bpo-43693: Eliminate unused "fast locals". (gh-26587)
Currently, if an arg value escapes (into the closure for an inner function) we end up allocating two indices in the fast locals even though only one gets used.  Additionally, using the lower index would be better in some cases, such as with no-arg `super()`.  To address this, we update the compiler to fix the offsets so each variable only gets one "fast local".  As a consequence, now some cell offsets are interspersed with the locals (only when an arg escapes to an inner function).

https://bugs.python.org/issue43693
  • Loading branch information
ericsnowcurrently authored and jdevries3133 committed Jun 19, 2021
commit fc3ca199dcae375c63fadb2b1023173dcb16ea60
8 changes: 2 additions & 6 deletions Include/cpython/code.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ struct PyCodeObject {

/* These fields are set with computed values on new code objects. */

int *co_cell2arg; /* Maps cell vars which are arguments. */
// redundant values (derived from co_localsplusnames and co_localspluskinds)
int co_nlocalsplus; /* number of local + cell + free variables */
int co_nlocals; /* number of local variables */
int co_ncellvars; /* number of cell variables */
int co_nplaincellvars; /* number of non-arg cell variables */
int co_ncellvars; /* total number of cell variables */
int co_nfreevars; /* number of free variables */
// lazily-computed values
PyObject *co_varnames; /* tuple of strings (local variable names) */
Expand Down Expand Up @@ -142,10 +142,6 @@ struct PyCodeObject {
#define CO_FUTURE_GENERATOR_STOP 0x800000
#define CO_FUTURE_ANNOTATIONS 0x1000000

/* This value is found in the co_cell2arg array when the associated cell
variable does not correspond to an argument. */
#define CO_CELL_NOT_AN_ARG (-1)

/* This should be defined if a future statement modifies the syntax.
For example, when a keyword is added.
*/
Expand Down
2 changes: 0 additions & 2 deletions Include/internal/pycore_frame.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ _PyFrame_GetBuiltins(PyFrameObject *f)

int _PyFrame_TakeLocals(PyFrameObject *f);

PyAPI_FUNC(int) _PyFrame_OpAlreadyRan(PyFrameObject *f, int opcode, int oparg);

#ifdef __cplusplus
}
#endif
Expand Down
3 changes: 2 additions & 1 deletion Lib/importlib/_bootstrap_external.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ def _write_atomic(path, data, mode=0o666):
# Python 3.11a1 3453 (add co_fastlocalnames and co_fastlocalkinds)
# Python 3.11a1 3454 (compute cell offsets relative to locals bpo-43693)
# Python 3.11a1 3455 (add MAKE_CELL bpo-43693)
# Python 3.11a1 3456 (interleave cell args bpo-43693)

#
# MAGIC must change whenever the bytecode emitted by the compiler may no
Expand All @@ -367,7 +368,7 @@ def _write_atomic(path, data, mode=0o666):
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
# in PC/launcher.c must also be updated.

MAGIC_NUMBER = (3455).to_bytes(2, 'little') + b'\r\n'
MAGIC_NUMBER = (3456).to_bytes(2, 'little') + b'\r\n'
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c

_PYCACHE = '__pycache__'
Expand Down
42 changes: 21 additions & 21 deletions Lib/test/test_dis.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,9 @@ def foo(x):
return foo

dis_nested_0 = """\
0 MAKE_CELL 2 (y)
0 MAKE_CELL 0 (y)

%3d 2 LOAD_CLOSURE 2 (y)
%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')
Expand All @@ -446,14 +446,14 @@ def foo(x):

dis_nested_1 = """%s
Disassembly of <code object foo at 0x..., file "%s", line %d>:
0 MAKE_CELL 1 (x)
0 MAKE_CELL 0 (x)

%3d 2 LOAD_CLOSURE 1 (x)
%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 2 (y)
12 LOAD_DEREF 1 (y)
14 GET_ITER
16 CALL_FUNCTION 1
18 RETURN_VALUE
Expand Down Expand Up @@ -966,19 +966,19 @@ def jumpy():

Instruction = dis.Instruction
expected_opinfo_outer = [
Instruction(opname='MAKE_CELL', opcode=135, arg=3, argval='a', argrepr='a', offset=0, starts_line=None, is_jump_target=False),
Instruction(opname='MAKE_CELL', opcode=135, arg=4, argval='b', argrepr='b', offset=2, starts_line=None, is_jump_target=False),
Instruction(opname='MAKE_CELL', opcode=135, arg=0, argval='a', argrepr='a', offset=0, starts_line=None, is_jump_target=False),
Instruction(opname='MAKE_CELL', opcode=135, arg=1, argval='b', argrepr='b', offset=2, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_CONST', opcode=100, arg=8, argval=(3, 4), argrepr='(3, 4)', offset=4, starts_line=2, is_jump_target=False),
Instruction(opname='LOAD_CLOSURE', opcode=136, arg=3, argval='a', argrepr='a', offset=6, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_CLOSURE', opcode=136, arg=4, argval='b', argrepr='b', offset=8, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_CLOSURE', opcode=136, arg=0, argval='a', argrepr='a', offset=6, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_CLOSURE', opcode=136, arg=1, argval='b', argrepr='b', offset=8, starts_line=None, is_jump_target=False),
Instruction(opname='BUILD_TUPLE', opcode=102, arg=2, argval=2, argrepr='', offset=10, starts_line=None, is_jump_target=False),
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),
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),
Instruction(opname='MAKE_FUNCTION', opcode=132, arg=9, argval=9, argrepr='defaults, closure', offset=16, starts_line=None, is_jump_target=False),
Instruction(opname='STORE_FAST', opcode=125, arg=2, argval='f', argrepr='f', offset=18, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_GLOBAL', opcode=116, arg=0, argval='print', argrepr='print', offset=20, starts_line=7, is_jump_target=False),
Instruction(opname='LOAD_DEREF', opcode=137, arg=3, argval='a', argrepr='a', offset=22, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_DEREF', opcode=137, arg=4, argval='b', argrepr='b', offset=24, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_DEREF', opcode=137, arg=0, argval='a', argrepr='a', offset=22, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_DEREF', opcode=137, arg=1, argval='b', argrepr='b', offset=24, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_CONST', opcode=100, arg=5, argval='', argrepr="''", offset=26, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_CONST', opcode=100, arg=6, argval=1, argrepr='1', offset=28, starts_line=None, is_jump_target=False),
Instruction(opname='BUILD_LIST', opcode=103, arg=0, argval=0, argrepr='', offset=30, starts_line=None, is_jump_target=False),
Expand All @@ -991,23 +991,23 @@ def jumpy():
]

expected_opinfo_f = [
Instruction(opname='MAKE_CELL', opcode=135, arg=3, argval='c', argrepr='c', offset=0, starts_line=None, is_jump_target=False),
Instruction(opname='MAKE_CELL', opcode=135, arg=4, argval='d', argrepr='d', offset=2, starts_line=None, is_jump_target=False),
Instruction(opname='MAKE_CELL', opcode=135, arg=0, argval='c', argrepr='c', offset=0, starts_line=None, is_jump_target=False),
Instruction(opname='MAKE_CELL', opcode=135, arg=1, argval='d', argrepr='d', offset=2, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_CONST', opcode=100, arg=5, argval=(5, 6), argrepr='(5, 6)', offset=4, starts_line=3, is_jump_target=False),
Instruction(opname='LOAD_CLOSURE', opcode=136, arg=5, argval='a', argrepr='a', offset=6, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_CLOSURE', opcode=136, arg=6, argval='b', argrepr='b', offset=8, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_CLOSURE', opcode=136, arg=3, argval='c', argrepr='c', offset=10, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_CLOSURE', opcode=136, arg=4, argval='d', argrepr='d', offset=12, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_CLOSURE', opcode=136, arg=3, argval='a', argrepr='a', offset=6, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_CLOSURE', opcode=136, arg=4, argval='b', argrepr='b', offset=8, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_CLOSURE', opcode=136, arg=0, argval='c', argrepr='c', offset=10, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_CLOSURE', opcode=136, arg=1, argval='d', argrepr='d', offset=12, starts_line=None, is_jump_target=False),
Instruction(opname='BUILD_TUPLE', opcode=102, arg=4, argval=4, argrepr='', offset=14, starts_line=None, is_jump_target=False),
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),
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),
Instruction(opname='MAKE_FUNCTION', opcode=132, arg=9, argval=9, argrepr='defaults, closure', offset=20, starts_line=None, is_jump_target=False),
Instruction(opname='STORE_FAST', opcode=125, arg=2, argval='inner', argrepr='inner', offset=22, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_GLOBAL', opcode=116, arg=0, argval='print', argrepr='print', offset=24, starts_line=5, is_jump_target=False),
Instruction(opname='LOAD_DEREF', opcode=137, arg=5, argval='a', argrepr='a', offset=26, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_DEREF', opcode=137, arg=6, argval='b', argrepr='b', offset=28, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_DEREF', opcode=137, arg=3, argval='c', argrepr='c', offset=30, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_DEREF', opcode=137, arg=4, argval='d', argrepr='d', offset=32, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_DEREF', opcode=137, arg=3, argval='a', argrepr='a', offset=26, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_DEREF', opcode=137, arg=4, argval='b', argrepr='b', offset=28, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_DEREF', opcode=137, arg=0, argval='c', argrepr='c', offset=30, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_DEREF', opcode=137, arg=1, argval='d', argrepr='d', offset=32, starts_line=None, is_jump_target=False),
Instruction(opname='CALL_FUNCTION', opcode=131, arg=4, argval=4, argrepr='', offset=34, starts_line=None, is_jump_target=False),
Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=36, starts_line=None, is_jump_target=False),
Instruction(opname='LOAD_FAST', opcode=124, arg=2, argval='inner', argrepr='inner', offset=38, starts_line=6, is_jump_target=False),
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Computation of the offsets of cell variables is done in the compiler instead
of at runtime. This reduces the overhead of handling cell and free
variables, especially in the case where a variable is both an argument and
cell variable.
110 changes: 36 additions & 74 deletions Objects/codeobject.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -162,43 +162,28 @@ _Py_set_localsplus_info(int offset, PyObject *name, _PyLocalsPlusKind kind,
Py_INCREF(name);
PyTuple_SET_ITEM(names, offset, name);
kinds[offset] = kind;

if (kind == CO_FAST_CELL) {
// Cells can overlap with args, so mark those cases.
int nlocalsplus = (int)PyTuple_GET_SIZE(names);
for (int i = 0; i < nlocalsplus; i++) {
_PyLocalsPlusKind kind = kinds[i];
if (kind && !(kind & CO_FAST_LOCAL)) {
// We've moved past the locals.
break;
}
PyObject *varname = PyTuple_GET_ITEM(names, i);
int cmp = PyUnicode_Compare(name, varname);
if (cmp == 0) {
kinds[i] |= CO_FAST_CELL;
break;
}
assert(cmp > 0 || !PyErr_Occurred());
}
}
}

static void
get_localsplus_counts(PyObject *names, _PyLocalsPlusKinds kinds,
int *pnlocals, int *pncellvars,
int *pnlocals, int *pnplaincellvars, int *pncellvars,
int *pnfreevars)
{
int nlocals = 0;
int nplaincellvars = 0;
int ncellvars = 0;
int nfreevars = 0;
int nlocalsplus = Py_SAFE_DOWNCAST(PyTuple_GET_SIZE(names),
Py_ssize_t, int);
Py_ssize_t nlocalsplus = PyTuple_GET_SIZE(names);
for (int i = 0; i < nlocalsplus; i++) {
if (kinds[i] & CO_FAST_LOCAL) {
nlocals += 1;
if (kinds[i] & CO_FAST_CELL) {
ncellvars += 1;
}
}
else if (kinds[i] & CO_FAST_CELL) {
ncellvars += 1;
nplaincellvars += 1;
}
else if (kinds[i] & CO_FAST_FREE) {
nfreevars += 1;
Expand All @@ -207,6 +192,9 @@ get_localsplus_counts(PyObject *names, _PyLocalsPlusKinds kinds,
if (pnlocals != NULL) {
*pnlocals = nlocals;
}
if (pnplaincellvars != NULL) {
*pnplaincellvars = nplaincellvars;
}
if (pncellvars != NULL) {
*pncellvars = ncellvars;
}
Expand All @@ -227,10 +215,6 @@ get_localsplus_names(PyCodeObject *co, _PyLocalsPlusKind kind, int num)
if ((co->co_localspluskinds[offset] & kind) == 0) {
continue;
}
// For now there may be duplicates, which we ignore.
if (kind == CO_FAST_CELL && co->co_localspluskinds[offset] != kind) {
continue;
}
assert(index < num);
PyObject *name = PyTuple_GET_ITEM(co->co_localsplusnames, offset);
Py_INCREF(name);
Expand Down Expand Up @@ -283,7 +267,7 @@ _PyCode_Validate(struct _PyCodeConstructor *con)
* here to avoid the possibility of overflow (however remote). */
int nlocals;
get_localsplus_counts(con->localsplusnames, con->localspluskinds,
&nlocals, NULL, NULL);
&nlocals, NULL, NULL, NULL);
int nplainlocals = nlocals -
con->argcount -
con->kwonlyargcount -
Expand All @@ -301,9 +285,9 @@ static void
init_code(PyCodeObject *co, struct _PyCodeConstructor *con)
{
int nlocalsplus = (int)PyTuple_GET_SIZE(con->localsplusnames);
int nlocals, ncellvars, nfreevars;
int nlocals, nplaincellvars, ncellvars, nfreevars;
get_localsplus_counts(con->localsplusnames, con->localspluskinds,
&nlocals, &ncellvars, &nfreevars);
&nlocals, &nplaincellvars, &ncellvars, &nfreevars);

Py_INCREF(con->filename);
co->co_filename = con->filename;
Expand Down Expand Up @@ -338,9 +322,9 @@ init_code(PyCodeObject *co, struct _PyCodeConstructor *con)
co->co_exceptiontable = con->exceptiontable;

/* derived values */
co->co_cell2arg = NULL; // This will be set soon.
co->co_nlocalsplus = nlocalsplus;
co->co_nlocals = nlocals;
co->co_nplaincellvars = nplaincellvars;
co->co_ncellvars = ncellvars;
co->co_nfreevars = nfreevars;
co->co_varnames = NULL;
Expand Down Expand Up @@ -392,44 +376,6 @@ _PyCode_New(struct _PyCodeConstructor *con)
co->co_flags &= ~CO_NOFREE;
}

/* Create mapping between cells and arguments if needed. */
if (co->co_ncellvars) {
int totalargs = co->co_argcount +
co->co_kwonlyargcount +
((co->co_flags & CO_VARARGS) != 0) +
((co->co_flags & CO_VARKEYWORDS) != 0);
assert(totalargs <= co->co_nlocals);
/* Find cells which are also arguments. */
for (int i = 0; i < co->co_ncellvars; i++) {
PyObject *cellname = PyTuple_GET_ITEM(co->co_localsplusnames,
i + co->co_nlocals);
for (int j = 0; j < totalargs; j++) {
PyObject *argname = PyTuple_GET_ITEM(co->co_localsplusnames, j);
int cmp = PyUnicode_Compare(cellname, argname);
if (cmp == -1 && PyErr_Occurred()) {
Py_DECREF(co);
return NULL;
}
if (cmp == 0) {
if (co->co_cell2arg == NULL) {
co->co_cell2arg = PyMem_NEW(int, co->co_ncellvars);
if (co->co_cell2arg == NULL) {
Py_DECREF(co);
PyErr_NoMemory();
return NULL;
}
for (int k = 0; k < co->co_ncellvars; k++) {
co->co_cell2arg[k] = CO_CELL_NOT_AN_ARG;
}
}
co->co_cell2arg[i] = j;
// Go to the next cell name.
break;
}
}
}
}

return co;
}

Expand Down Expand Up @@ -478,6 +424,23 @@ PyCode_NewWithPosOnlyArgs(int argcount, int posonlyargcount, int kwonlyargcount,
}
for (int i = 0; i < ncellvars; i++, offset++) {
PyObject *name = PyTuple_GET_ITEM(cellvars, i);
int argoffset = -1;
for (int j = 0; j < nvarnames; j++) {
int cmp = PyUnicode_Compare(PyTuple_GET_ITEM(varnames, j),
name);
assert(!PyErr_Occurred());
if (cmp == 0) {
argoffset = j;
break;
}
}
if (argoffset >= 0) {
// Merge the localsplus indices.
nlocalsplus -= 1;
offset -= 1;
localspluskinds[argoffset] |= CO_FAST_CELL;
continue;
}
_Py_set_localsplus_info(offset, name, CO_FAST_CELL,
localsplusnames, localspluskinds);
}
Expand All @@ -486,6 +449,11 @@ PyCode_NewWithPosOnlyArgs(int argcount, int posonlyargcount, int kwonlyargcount,
_Py_set_localsplus_info(offset, name, CO_FAST_FREE,
localsplusnames, localspluskinds);
}
// If any cells were args then nlocalsplus will have shrunk.
// We don't bother resizing localspluskinds.
if (_PyTuple_Resize(&localsplusnames, nlocalsplus) < 0) {
goto error;
}

struct _PyCodeConstructor con = {
.filename = filename,
Expand Down Expand Up @@ -1182,8 +1150,6 @@ code_dealloc(PyCodeObject *co)
Py_XDECREF(co->co_name);
Py_XDECREF(co->co_linetable);
Py_XDECREF(co->co_exceptiontable);
if (co->co_cell2arg != NULL)
PyMem_Free(co->co_cell2arg);
if (co->co_weakreflist != NULL)
PyObject_ClearWeakRefs((PyObject*)co);
if (co->co_quickened) {
Expand Down Expand Up @@ -1377,10 +1343,6 @@ code_sizeof(PyCodeObject *co, PyObject *Py_UNUSED(args))
(co_extra->ce_size-1) * sizeof(co_extra->ce_extras[0]);
}

if (co->co_cell2arg != NULL && co->co_cellvars != NULL) {
res += co->co_ncellvars * sizeof(Py_ssize_t);
}

if (co->co_quickened != NULL) {
Py_ssize_t count = co->co_quickened[0].entry.zero.cache_count;
count += (PyBytes_GET_SIZE(co->co_code)+sizeof(SpecializedCacheEntry)-1)/
Expand Down
Loading

Back | FazBrowse Home | New Git URL