bpo-40941: Unify implicit and explicit state in the frame and generat… · python/cpython@cb9879b · GitHub
Skip to content

Commit cb9879b

Browse files
authored
bpo-40941: Unify implicit and explicit state in the frame and generator objects into a single value. (GH-20803)
* Merge gen and frame state variables into one. * Replace stack pointer with depth in PyFrameObject. Makes code easier to read and saves a word of memory.
1 parent 8e836bb commit cb9879b

9 files changed

Lines changed: 155 additions & 95 deletions

File tree

Include/cpython/frameobject.h

Lines changed: 28 additions & 5 deletions

Include/genobject.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ extern "C" {
1616
PyObject_HEAD \
1717
/* Note: gi_frame can be NULL if the generator is "finished" */ \
1818
PyFrameObject *prefix##_frame; \
19-
/* True if generator is being executed. */ \
20-
char prefix##_running; \
2119
/* The code object backing the generator */ \
2220
PyObject *prefix##_code; \
2321
/* List of weak reference. */ \

Lib/test/test_generators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ def b():
881881
>>> i.gi_running = 42
882882
Traceback (most recent call last):
883883
...
884-
AttributeError: readonly attribute
884+
AttributeError: attribute 'gi_running' of 'generator' objects is not writable
885885
>>> def g():
886886
... yield me.gi_running
887887
>>> me = g()

Lib/test/test_sys.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ class C(object): pass
12361236
nfrees = len(x.f_code.co_freevars)
12371237
extras = x.f_code.co_stacksize + x.f_code.co_nlocals +\
12381238
ncells + nfrees - 1
1239-
check(x, vsize('5P2c4P3ic' + CO_MAXBLOCKS*'3i' + 'P' + extras*'P'))
1239+
check(x, vsize('4Pi2c4P3ic' + CO_MAXBLOCKS*'3i' + 'P' + extras*'P'))
12401240
# function
12411241
def func(): pass
12421242
check(func, size('13P'))
@@ -1253,7 +1253,7 @@ def bar(cls):
12531253
check(bar, size('PP'))
12541254
# generator
12551255
def get_gen(): yield 1
1256-
check(get_gen(), size('Pb2PPP4P'))
1256+
check(get_gen(), size('P2PPP4P'))
12571257
# iterator
12581258
check(iter('abc'), size('lP'))
12591259
# callable-iterator

Lib/test/test_yield_from.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,9 @@ def two():
938938
res.append(g1.throw(MyErr))
939939
except StopIteration:
940940
pass
941+
except:
942+
self.assertEqual(res, [0, 1, 2, 3])
943+
raise
941944
# Check with close
942945
class MyIt(object):
943946
def __iter__(self):

Modules/_xxsubinterpretersmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1847,7 +1847,7 @@ _is_running(PyInterpreterState *interp)
18471847
return 0;
18481848
}
18491849

1850-
int executing = (int)(frame->f_executing);
1850+
int executing = _PyFrame_IsExecuting(frame);
18511851
Py_DECREF(frame);
18521852

18531853
return executing;

Objects/frameobject.c

Lines changed: 45 additions & 45 deletions

0 commit comments

Comments
 (0)