changeset 1452:9ecbbe1f33d8

Fixed reentrancy bug.
author Marcel Keller <mkeller@cs.au.dk>
date Tue, 20 Jul 2010 13:30:49 +0200
parents 422bb9776aee
children 2d537c1b8dbe
files viff/cdefer.c
diffstat 1 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/viff/cdefer.c	Mon Jul 19 20:01:12 2010 +0200
+++ b/viff/cdefer.c	Tue Jul 20 13:30:49 2010 +0200
@@ -62,6 +62,7 @@
     cdefer_Callback *last_callback;
     PyObject *debuginfo;
     int called;
+    int runningCallbacks;
 } cdefer_Deferred;
 
 /* Prototypes */
@@ -169,7 +170,7 @@
     return (PyObject *)self;
 }
 
-inline cdefer_Callback* cdefer_Callback_free(cdefer_Callback *callback) {
+static cdefer_Callback* cdefer_Callback_free(cdefer_Callback *callback) {
     cdefer_Callback* next = callback->next;
     Py_DECREF(callback->func);
     Py_DECREF(callback->args);
@@ -265,6 +266,8 @@
     }
 
     self->paused = 0;
+    self->called = 0;
+    self->runningCallbacks = 0;
     self->callbacks = NULL;
     self->last_callback = NULL;
     return 0;
@@ -531,6 +534,11 @@
     PyObject *tmp;
     PyObject *result;
 
+    if (self->runningCallbacks) {
+	Py_INCREF(Py_None);
+	return Py_None;
+    }
+
     if (!self->paused) {
         while(self->callbacks) {
 	    /*
@@ -578,11 +586,16 @@
                 newArgs = NULL;
             }
 
+	    self->runningCallbacks = 1;
+
             if (kwargs == Py_None) {
                 tmp = PyObject_Call(callback, newArgs2, NULL);
             } else {
                 tmp = PyObject_Call(callback, newArgs2, kwargs);
             }
+
+	    self->runningCallbacks = 0;
+
             Py_DECREF(self->result);
             self->result = tmp;