| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 65c1b46 commit b4df670
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,6 +13,7 @@ typedef struct { | |||
| 13 | 13 | PyObject_HEAD | |
| 14 | 14 | /* The gi_ prefix is intended to remind of generator-iterator. */ | |
| 15 | 15 | ||
| 16 | + /* Note: gi_frame can be NULL if the generator is "finished" */ | ||
| 16 | 17 | struct _frame *gi_frame; | |
| 17 | 18 | ||
| 18 | 19 | /* True if generator is being executed. */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,7 +10,8 @@ | |||
| 10 | 10 | static int | |
| 11 | 11 | gen_traverse(PyGenObject *gen, visitproc visit, void *arg) | |
| 12 | 12 | { | |
| 13 | - return visit((PyObject *)gen->gi_frame, arg); | ||
| 13 | + Py_VISIT(gen->gi_frame); | ||
| 14 | + return 0; | ||
| 14 | 15 | } | |
| 15 | 16 | ||
| 16 | 17 | static void | |
@@ -26,7 +27,7 @@ gen_dealloc(PyGenObject *gen) | |||
| 26 | 27 | ||
| 27 | 28 | _PyObject_GC_TRACK(self); | |
| 28 | 29 | ||
| 29 | - if (gen->gi_frame->f_stacktop!=NULL) { | ||
| 30 | + if (gen->gi_frame!=NULL && gen->gi_frame->f_stacktop!=NULL) { | ||
| 30 | 31 | /* Generator is paused, so we need to close */ | |
| 31 | 32 | gen->ob_type->tp_del(self); | |
| 32 | 33 | if (self->ob_refcnt > 0) | |
@@ -51,7 +52,7 @@ gen_send_ex(PyGenObject *gen, PyObject *arg, int exc) | |||
| 51 | 52 | "generator already executing"); | |
| 52 | 53 | return NULL; | |
| 53 | 54 | } | |
| 54 | - if ((PyObject *)f == Py_None || f->f_stacktop == NULL) { | ||
| 55 | + if (f==NULL || f->f_stacktop == NULL) { | ||
| 55 | 56 | /* Only set exception if called from send() */ | |
| 56 | 57 | if (arg && !exc) PyErr_SetNone(PyExc_StopIteration); | |
| 57 | 58 | return NULL; | |
@@ -98,8 +99,7 @@ gen_send_ex(PyGenObject *gen, PyObject *arg, int exc) | |||
| 98 | 99 | if (!result || f->f_stacktop == NULL) { | |
| 99 | 100 | /* generator can't be rerun, so release the frame */ | |
| 100 | 101 | Py_DECREF(f); | |
| 101 | - gen->gi_frame = (PyFrameObject *)Py_None; | ||
| 102 | - Py_INCREF(Py_None); | ||
| 102 | + gen->gi_frame = NULL; | ||
| 103 | 103 | } | |
| 104 | 104 | ||
| 105 | 105 | return result; | |
@@ -147,7 +147,7 @@ gen_del(PyObject *self) | |||
| 147 | 147 | PyObject *error_type, *error_value, *error_traceback; | |
| 148 | 148 | PyGenObject *gen = (PyGenObject *)self; | |
| 149 | 149 | ||
| 150 | - if ((PyObject *)gen->gi_frame == Py_None || gen->gi_frame->f_stacktop==NULL) | ||
| 150 | + if (!gen->gi_frame || gen->gi_frame->f_stacktop==NULL) | ||
| 151 | 151 | /* Generator isn't paused, so no need to close */ | |
| 152 | 152 | return; | |
| 153 | 153 | ||
@@ -366,7 +366,7 @@ PyGen_NeedsFinalizing(PyGenObject *gen) | |||
| 366 | 366 | int i; | |
| 367 | 367 | PyFrameObject *f = gen->gi_frame; | |
| 368 | 368 | ||
| 369 | - if ((PyObject *)f == Py_None || f->f_stacktop==NULL || f->f_iblock<=0) | ||
| 369 | + if (f == NULL || f->f_stacktop==NULL || f->f_iblock<=0) | ||
| 370 | 370 | return 0; /* no frame or no blockstack == no finalization */ | |
| 371 | 371 | ||
| 372 | 372 | for (i=f->f_iblock; i>=0; i--) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments