cpython: edefd3450834 (original) (raw)

Mercurial > cpython

changeset 83771:edefd3450834

Backout c89febab4648 following private feedback by Guido. (Issue #17807: Generators can now be finalized even when they are part of a reference cycle) [#17807]

Antoine Pitrou solipsis@pitrou.net
date Tue, 14 May 2013 20:37:52 +0200
parents 85ecc4761a6c
children bb8093e427f9
files Include/frameobject.h Include/genobject.h Lib/test/test_generators.py Lib/test/test_sys.py Misc/NEWS Modules/gcmodule.c Objects/frameobject.c Objects/genobject.c
diffstat 8 files changed, 244 insertions(+), 334 deletions(-)[+] [-] Include/frameobject.h 9 Include/genobject.h 1 Lib/test/test_generators.py 53 Lib/test/test_sys.py 2 Misc/NEWS 3 Modules/gcmodule.c 5 Objects/frameobject.c 254 Objects/genobject.c 251

line wrap: on

line diff

--- a/Include/frameobject.h +++ b/Include/frameobject.h @@ -36,8 +36,6 @@ typedef struct _frame { non-generator frames. See the save_exc_state and swap_exc_state functions in ceval.c for details of their use. */ PyObject *f_exc_type, *f_exc_value, *f_exc_traceback;

PyThreadState f_tstate; int f_lasti; / Last instruction if called / @@ -86,13 +84,6 @@ PyAPI_FUNC(void) _PyFrame_DebugMallocSta / Return the line of code the frame is currently executing. */ PyAPI_FUNC(int) PyFrame_GetLineNumber(PyFrameObject ); -/ Generator support */ -PyAPI_FUNC(PyObject *) _PyFrame_YieldingFrom(PyFrameObject *); -PyAPI_FUNC(PyObject *) _PyFrame_GeneratorSend(PyFrameObject *, PyObject *, int exc); -PyAPI_FUNC(PyObject *) _PyFrame_Finalize(PyFrameObject *); -PyAPI_FUNC(int) _PyFrame_CloseIterator(PyObject *); - - #ifdef __cplusplus } #endif

--- a/Include/genobject.h +++ b/Include/genobject.h @@ -33,7 +33,6 @@ PyAPI_DATA(PyTypeObject) PyGen_Type; #define PyGen_CheckExact(op) (Py_TYPE(op) == &PyGen_Type) PyAPI_FUNC(PyObject *) PyGen_New(struct _frame ); -/ Deprecated, kept for backwards compatibility. */ PyAPI_FUNC(int) PyGen_NeedsFinalizing(PyGenObject *); PyAPI_FUNC(int) _PyGen_FetchStopIterationValue(PyObject **); PyObject *_PyGen_Send(PyGenObject *, PyObject *);

--- a/Lib/test/test_generators.py +++ b/Lib/test/test_generators.py @@ -1,55 +1,3 @@ -import gc -import sys -import unittest -import weakref - -from test import support - - -class FinalizationTest(unittest.TestCase): -

-

-

-

- - tutorial_tests = """ Let's try a simple generator: @@ -1932,7 +1880,6 @@ test_generators just happened to be the

so this works as expected in both ways of running regrtest.

def test_main(verbose=None): from test import support, test_generators

This part isn't needed for regrtest, but for running the test directly.

--- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -764,7 +764,7 @@ class SizeofTest(unittest.TestCase): nfrees = len(x.f_code.co_freevars) extras = x.f_code.co_stacksize + x.f_code.co_nlocals +[](#l4.5) ncells + nfrees - 1

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -15,9 +15,6 @@ Core and Builtins

--- a/Modules/gcmodule.c +++ b/Modules/gcmodule.c @@ -524,7 +524,10 @@ untrack_dicts(PyGC_Head *head) static int has_finalizer(PyObject *op) {

} /* Move the objects in unreachable with del methods into finalizers.

--- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -31,195 +31,6 @@ frame_getlocals(PyFrameObject *f, void return f->f_locals; } -/

-

-

-} - -PyObject * -_PyFrame_GeneratorSend(PyFrameObject *f, PyObject *arg, int exc) -{

-

-

-

-

-

-

-

-

-} - -int -_PyFrame_CloseIterator(PyObject *yf) -{

-

-} - -PyObject * -_PyFrame_Finalize(PyFrameObject *f) -{

-

-} - -/*

#define PyFrame_MAXFREELIST 200 static void -frame_clear(PyFrameObject *f); - -static void frame_dealloc(PyFrameObject *f) {

-#ifdef COUNT_ALLOCS

-#endif

- PyObject_GC_UnTrack(f); Py_TRASHCAN_SAFE_BEGIN(f)

+

Py_XDECREF(f->f_back); Py_DECREF(f->f_builtins); Py_DECREF(f->f_globals); Py_CLEAR(f->f_locals);

co = f->f_code; if (co->co_zombieframe == NULL) @@ -697,25 +497,12 @@ frame_clear(PyFrameObject *f) { PyObject **fastlocals, **p, **oldtop; Py_ssize_t i, slots;

-

_PyObject_GC_TRACK(f); return f;

--- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -19,50 +19,112 @@ static void gen_dealloc(PyGenObject *gen) { PyObject *self = (PyObject *) gen;

_PyObject_GC_UNTRACK(gen); if (gen->gi_weakreflist != NULL) PyObject_ClearWeakRefs(self);

+

+ static PyObject * gen_send_ex(PyGenObject *gen, PyObject *arg, int exc) {

+

+

+

+

+

+

} PyDoc_STRVAR(send_doc, @@ -83,33 +145,146 @@ PyDoc_STRVAR(close_doc,

+

+} + static PyObject * gen_yf(PyGenObject *gen) {

+

+

+

} static PyObject * gen_close(PyGenObject *gen, PyObject *args) {

+} + +static void +gen_del(PyObject *self) +{

+

+

+

+

+

+

+

+

+#ifdef COUNT_ALLOCS

+#endif } + + PyDoc_STRVAR(throw_doc, "throw(typ[,val[,tb]]) -> raise exception in generator,\n[](#l8.291) return next yielded value or raise StopIteration."); @@ -131,7 +306,7 @@ gen_throw(PyGenObject *gen, PyObject *ar int err; if (PyErr_GivenExceptionMatches(typ, PyExc_GeneratorExit)) { gen->gi_running = 1;

@@ -369,6 +544,7 @@ PyTypeObject PyGen_Type = { 0, /* tp_cache / 0, / tp_subclasses / 0, / tp_weaklist */

}; PyObject * @@ -380,7 +556,6 @@ PyGen_New(PyFrameObject *f) return NULL; } gen->gi_frame = f;

+

+

+