changeset 1451:422bb9776aee

cdefer: Call C functions more directly.
author Marcel Keller <mkeller@cs.au.dk>
date Mon, 19 Jul 2010 20:01:12 +0200
parents d611209ceeaa
children 9ecbbe1f33d8
files viff/cdefer.c
diffstat 1 files changed, 16 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/viff/cdefer.c	Mon Jul 19 18:30:11 2010 +0200
+++ b/viff/cdefer.c	Mon Jul 19 20:01:12 2010 +0200
@@ -870,11 +870,13 @@
   {0, 0, 0, 0, 0}
 };
 
+static int cdefer_Share__init(cdefer_Share *self, PyObject* runtime,
+			      PyObject* field, PyObject* value);
+
 static int cdefer_Share_init(cdefer_Share *self, PyObject *args,
 			     PyObject *kwargs)
 {
     PyObject *runtime, *field, *value = NULL;
-    PyObject *result, *tmp;
     static char *argnames[] = {"runtime", "field", "value", NULL};
     if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|O", argnames,
 				     &runtime, &field, &value))
@@ -892,6 +894,14 @@
 	return -1;
     }
 
+    return cdefer_Share__init(self, runtime, field, value);
+}
+
+static int cdefer_Share__init(cdefer_Share *self, PyObject* runtime,
+			      PyObject* field, PyObject* value)
+{
+    PyObject *result, *tmp;
+
     Py_INCREF(Py_None);
     if (cdefer_Deferred___init__(&self->deferred, Py_None, Py_None) < 0)
 	return -1;
@@ -908,9 +918,7 @@
     Py_XDECREF(tmp);
 
     if (value != NULL) {
-	result = PyObject_CallMethodObjArgs((PyObject *)&self->deferred,
-					    Py_BuildValue("s", "callback"),
-					    value, NULL);
+	result = cdefer_Deferred__startRunCallbacks(&self->deferred, value);
 
 	if (result)
 	    Py_DECREF(result);
@@ -1282,15 +1290,8 @@
     }
 
     first_item = (cdefer_Share *)PyList_GET_ITEM(shares, 0);
-    args = Py_BuildValue("(OO)", first_item->runtime, first_item->field);
-    kwargs = PyDict_New();
-
-    if (!args || !kwargs)
-	return -1;
-
-    cdefer_Share_init(&(self->share), args, kwargs);
-    Py_DECREF(args);
-    Py_DECREF(kwargs);
+    cdefer_Share__init(&(self->share), first_item->runtime,
+		       first_item->field, NULL);
 
     Py_XDECREF(self->results);
     self->results = PyList_New(n_shares);
@@ -1351,12 +1352,8 @@
     self->missing_shares--;
 
     if (!self->share.deferred.called && self->missing_shares == 0) {
-	args = Py_BuildValue("(O)", self->results);
-	kwargs = PyDict_New();
-	tmp = cdefer_Deferred_callback((cdefer_Deferred *)self,
-				       args, kwargs);
-	Py_DECREF(args);
-	Py_DECREF(kwargs);
+	tmp = cdefer_Deferred__startRunCallbacks(&self->share.deferred,
+						 self->results);
 
 	if (!tmp)
 	    return NULL;