Skip to content

Commit 3a69400

Browse files
committed
fix throw / close propagate to subgenerator
1 parent d1fdcb4 commit 3a69400

6 files changed

Lines changed: 37 additions & 176 deletions

File tree

CPythonLib.includes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,5 @@ wsgiref/*.py
188188
xdrlib.py
189189
xmllib.py
190190
xmlrpclib.py
191+
zipapp.py
192+
zipfile.py

Lib/test/support/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,20 @@ def rmtree(path):
266266
if e.errno not in (errno.ENOENT, errno.ESRCH):
267267
raise
268268

269+
def make_legacy_pyc(source):
270+
"""Move a PEP 3147/488 pyc file to its legacy pyc location.
271+
272+
:param source: The file system path to the source file. The source file
273+
does not need to exist, however the PEP 3147/488 pyc file must exist.
274+
:return: The file system path to the legacy pyc file.
275+
"""
276+
pyc_file = importlib.util.cache_from_source(source)
277+
up_one = os.path.dirname(os.path.abspath(source))
278+
legacy_pyc = os.path.join(up_one, source + 'c')
279+
os.rename(pyc_file, legacy_pyc)
280+
return legacy_pyc
281+
282+
269283
def forget(modname):
270284
'''"Forget" a module was ever imported by removing it from sys.modules and
271285
deleting any .pyc and .pyo files.'''

Lib/test/test_traceback.py

Lines changed: 0 additions & 171 deletions
This file was deleted.

src/org/python/compiler/CodeCompiler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,7 @@ public Object visitYieldFrom(YieldFrom node) throws Exception {
707707
code.label(restart);
708708
restoreLocals();
709709
restoreStack(stackState);
710+
710711
loadFrame();
711712
code.getfield(p(PyFrame.class), "f_yieldfrom", ci(PyObject.class));
712713
code.invokestatic(p(Py.class), "yieldFrom", sig(PyObject.class, PyObject.class));

src/org/python/core/PyFrame.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import org.python.expose.ExposedDelete;
88
import org.python.expose.ExposedGet;
9+
import org.python.expose.ExposedMethod;
910
import org.python.expose.ExposedSet;
1011
import org.python.expose.ExposedType;
1112

@@ -341,6 +342,16 @@ public void delglobal(String index) {
341342
}
342343
}
343344

345+
public PyObject clear() {
346+
return frame_clear();
347+
}
348+
349+
@ExposedMethod(doc = BuiltinDocs.frame_clear_doc)
350+
final PyObject frame_clear() {
351+
// XXX clean associated generator?
352+
return Py.None;
353+
}
354+
344355
// nested scopes helpers
345356

346357
public PyObject getclosure(int index) {

src/org/python/core/PyGenerator.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,13 @@ private PyObject raiseException(PyException ex) {
114114
gi_frame = null;
115115
throw ex;
116116
}
117-
gi_frame.setGeneratorInput(ex);
118-
return next();
117+
PyObject yf = gi_frame.f_yieldfrom;
118+
if (yf != null) {
119+
return ((PyGenerator) yf).raiseException(ex);
120+
} else {
121+
gi_frame.setGeneratorInput(ex);
122+
return next();
123+
}
119124
}
120125

121126
@Override
@@ -161,15 +166,14 @@ private PyObject send_gen_exp(ThreadState state, PyObject value) {
161166
}
162167
gi_running = true;
163168
PyObject result = null;
164-
PyObject yf = gi_frame.f_yieldfrom;
165169
try {
166170
result = gi_frame.f_code.call(state, gi_frame, closure);
167171
} catch (PyException pye) {
168172
if (!(pye.type == Py.StopIteration || pye.type == Py.GeneratorExit)) {
169173
gi_frame = null;
170174
throw pye;
171175
} else {
172-
if (yf != null) {
176+
if (gi_frame.f_yieldfrom != null) {
173177
gi_frame.f_yieldfrom = null;
174178
gi_frame.f_lasti++;
175179
return __iternext__();
@@ -181,7 +185,7 @@ private PyObject send_gen_exp(ThreadState state, PyObject value) {
181185
} finally {
182186
gi_running = false;
183187
}
184-
if (result == null && yf != null) {
188+
if (result == null && gi_frame.f_yieldfrom != null) {
185189
gi_frame.f_yieldfrom = null;
186190
gi_frame.f_lasti++;
187191
return __iternext__();

0 commit comments

Comments
 (0)