[Python-checkins] r45316 - in python/trunk: Include/genobject.h Objects/genobject.c
phillip.eby
python-checkins at python.org
Wed Apr 12 21:07:15 CEST 2006
Author: phillip.eby
Date: Wed Apr 12 21:07:15 2006
New Revision: 45316
Modified:
python/trunk/Include/genobject.h
python/trunk/Objects/genobject.c
Log:
Don't set gi_frame to Py_None, use NULL instead, eliminating some insane
pointer dereferences.
Modified: python/trunk/Include/genobject.h
==============================================================================
--- python/trunk/Include/genobject.h (original)
+++ python/trunk/Include/genobject.h Wed Apr 12 21:07:15 2006
@@ -13,6 +13,7 @@
PyObject_HEAD
/* The gi_ prefix is intended to remind of generator-iterator. */
+ /* Note: gi_frame can be NULL if the generator is "finished" */
struct _frame *gi_frame;
/* True if generator is being executed. */
Modified: python/trunk/Objects/genobject.c
==============================================================================
--- python/trunk/Objects/genobject.c (original)
+++ python/trunk/Objects/genobject.c Wed Apr 12 21:07:15 2006
@@ -10,7 +10,8 @@
static int
gen_traverse(PyGenObject *gen, visitproc visit, void *arg)
{
- return visit((PyObject *)gen->gi_frame, arg);
+ Py_VISIT(gen->gi_frame);
+ return 0;
}
static void
@@ -26,7 +27,7 @@
_PyObject_GC_TRACK(self);
- if (gen->gi_frame->f_stacktop!=NULL) {
+ if (gen->gi_frame!=NULL && gen->gi_frame->f_stacktop!=NULL) {
/* Generator is paused, so we need to close */
gen->ob_type->tp_del(self);
if (self->ob_refcnt > 0)
@@ -51,7 +52,7 @@
"generator already executing");
return NULL;
}
- if ((PyObject *)f == Py_None || f->f_stacktop == NULL) {
+ if (f==NULL || f->f_stacktop == NULL) {
/* Only set exception if called from send() */
if (arg && !exc) PyErr_SetNone(PyExc_StopIteration);
return NULL;
@@ -98,8 +99,7 @@
if (!result || f->f_stacktop == NULL) {
/* generator can't be rerun, so release the frame */
Py_DECREF(f);
- gen->gi_frame = (PyFrameObject *)Py_None;
- Py_INCREF(Py_None);
+ gen->gi_frame = NULL;
}
return result;
@@ -147,7 +147,7 @@
PyObject *error_type, *error_value, *error_traceback;
PyGenObject *gen = (PyGenObject *)self;
- if ((PyObject *)gen->gi_frame == Py_None || gen->gi_frame->f_stacktop==NULL)
+ if (!gen->gi_frame || gen->gi_frame->f_stacktop==NULL)
/* Generator isn't paused, so no need to close */
return;
@@ -366,7 +366,7 @@
int i;
PyFrameObject *f = gen->gi_frame;
- if ((PyObject *)f == Py_None || f->f_stacktop==NULL || f->f_iblock<=0)
+ if (f == NULL || f->f_stacktop==NULL || f->f_iblock<=0)
return 0; /* no frame or no blockstack == no finalization */
for (i=f->f_iblock; i>=0; i--) {
More information about the Python-checkins
mailing list