[Stackless-checkins] r51101 - in stackless/trunk/Stackless: embedemo/watchdog-c module/channelobject.c module/taskletobject.c platf/switch_ppc_macosx.h unittests/test_pickle.py

richard.tew python-checkins at python.org
Fri Aug 4 16:28:41 CEST 2006


Author: richard.tew
Date: Fri Aug  4 16:28:40 2006
New Revision: 51101

Added:
   stackless/trunk/Stackless/embedemo/watchdog-c/
      - copied from r51096, stackless/Python-2.4.3/dev/Stackless/embedemo/watchdog-c/
Modified:
   stackless/trunk/Stackless/module/channelobject.c
   stackless/trunk/Stackless/module/taskletobject.c
   stackless/trunk/Stackless/platf/switch_ppc_macosx.h
   stackless/trunk/Stackless/unittests/test_pickle.py
Log:
Changes merged in from the Stackless 2.4.3 branch..

Revision 47178: If your tasklet subclass was pickled, it would be reduced with the tasklet class rather than the subclass itself.  This meant when it was unpickled, it would be an instance of tasklet, rather than your subclass.  Now reduce uses the type of the tasklet, rather than being hardcoded to use the tasklet class itself.

Revision 47195: An example of using the watchdog in C.  Also implements a BeNice yielding function, but uses soft switching, so any tasklets which are blocked on it can be pickled.  Needs a Sleep function, and perhaps some more work.

Revision 47196: Changed the __reduce__ function for channels so that subclasses will get their class persisted and will be unpickled with the same custom class (rather than forced to have the tasklet class).

Revision 47240: Patch from Jeff Senn to fix OS X compilation problems.  One prevented Stackless from being compiled because one of the registers preserved was now clobbered in the generated assembly code.  The other was a warning because of the types used in slp_switch.


Modified: stackless/trunk/Stackless/module/channelobject.c
==============================================================================
--- stackless/trunk/Stackless/module/channelobject.c	(original)
+++ stackless/trunk/Stackless/module/channelobject.c	Fri Aug  4 16:28:40 2006
@@ -16,7 +16,7 @@
 {
 	PyChannelObject *ch = (PyChannelObject *) ob;
 
-	/* 
+	/*
 	 * remove all tasklets and hope they will die.
 	 * Note that the channel might receive new actions
 	 * during tasklet deallocation, so we don't even know
@@ -24,7 +24,7 @@
 	 */
 	while (ch->balance) {
 		int dir = ch->balance > 0 ? 1 : -1;
-		
+
 		ob = (PyObject *) slp_channel_remove(ch, dir);
 		Py_DECREF(ob);
 	}
@@ -84,7 +84,7 @@
 /* the special case to remove a specific tasklet */
 
 PyTaskletObject *
-slp_channel_remove_specific(PyChannelObject *channel, int dir, 
+slp_channel_remove_specific(PyChannelObject *channel, int dir,
 			    PyTaskletObject *task)
 {
 	/* note: we assume that the task is in the channel! */
@@ -315,22 +315,22 @@
 	PyObject *args, *ret;
 	PyObject *type, *value, *traceback;
 	args = ret = NULL;
-  
+
 	args = Py_BuildValue("(OOii)", channel, task, sending, willblock);
 	if (args != NULL) {
-    
+
 		PyErr_Fetch(&type, &value, &traceback);
 		ret = PyObject_Call(channel_hook, args, NULL);
-    
+
 		if (ret != NULL) {
 			PyErr_Restore(type, value, traceback);
-		} 
+		}
 		else {
 			Py_XDECREF(type);
 			Py_XDECREF(value);
 			Py_XDECREF(traceback);
 		}
-    
+
 		Py_XDECREF(ret);
 		Py_DECREF(args);
 	}
@@ -368,7 +368,7 @@
 static PyObject *
 PyChannel_Send_M(PyChannelObject *self, PyObject *arg)
 {
-	return PyStackless_CallMethod_Main((PyObject *) self, "send", "(O)", 
+	return PyStackless_CallMethod_Main((PyObject *) self, "send", "(O)",
 					   arg);
 }
 
@@ -390,7 +390,7 @@
 }
 
 
-/* 
+/*
  * This generic function exchanges values over a channel.
  * the action can be either send or receive.
  * Note that this works even across threads. The insert action
@@ -527,7 +527,7 @@
 
 static CHANNEL_SEND_EXCEPTION_HEAD(wrap_channel_send_exception)
 {
-	return PyObject_CallMethod((PyObject *) self, "send_exception", 
+	return PyObject_CallMethod((PyObject *) self, "send_exception",
 				   "(OO)", klass, args);
 }
 
@@ -654,11 +654,11 @@
 	  # got nested structure
 	  ch.send_sequence(parser())
 
-    parser()    
+    parser()
 
  *********************************************************/
 
-	
+
 /*
  * iterator extension.
  * This is probably the fastest way to run through a channel
@@ -697,7 +697,7 @@
 over the channel. Combined with a generator, this is\n\
 a very efficient way to build fast pipes.";
 
-/* 
+/*
  * this is the traight-forward and simple implementation,
  * but here we have almost no speedup, since all switches
  * are hard.
@@ -818,7 +818,7 @@
 	ts->frame = f->f_back;
 	Py_DECREF(f);
 	return retval;
-}	
+}
 
 static PyObject *
 channel_send_sequence(PyChannelObject *self, PyObject *v)
@@ -900,7 +900,7 @@
 		t = t->next;
 	}
 	tup = Py_BuildValue("(O()(iiO))",
-			    &PyChannel_Type,
+			    ch->ob_type,
 			    ch->balance,
 			    ch->flags,
 			    lis
@@ -925,7 +925,7 @@
 
 	if (!PyArg_ParseTuple(args, "iiO!:channel",
 			      &balance,
-			      &flags, 
+			      &flags,
 			      &PyList_Type, &lis))
 		return NULL;
 
@@ -1053,7 +1053,7 @@
 	PyTypeObject *t = &_PyChannel_Type;
 
 	if ( (t = PyFlexType_Build("stackless", "channel", t->tp_doc,
-				   t, sizeof(PyChannel_HeapType), 
+				   t, sizeof(PyChannel_HeapType),
 				   channel_cmethods) ) == NULL)
 		return -1;
 	PyChannel_TypePtr = t;

Modified: stackless/trunk/Stackless/module/taskletobject.c
==============================================================================
--- stackless/trunk/Stackless/module/taskletobject.c	(original)
+++ stackless/trunk/Stackless/module/taskletobject.c	Fri Aug  4 16:28:40 2006
@@ -277,7 +277,7 @@
 	if (PyList_Reverse(lis)) goto err_exit;
 	assert(t->cstate != NULL);
 	tup = Py_BuildValue("(O()(" TASKLET_TUPLEFMT "))",
-			    &PyTasklet_Type,
+			    t->ob_type,
 			    t->flags,
 			    t->tempval,
 			    t->cstate->nesting_level,

Modified: stackless/trunk/Stackless/platf/switch_ppc_macosx.h
==============================================================================
--- stackless/trunk/Stackless/platf/switch_ppc_macosx.h	(original)
+++ stackless/trunk/Stackless/platf/switch_ppc_macosx.h	Fri Aug  4 16:28:40 2006
@@ -33,14 +33,15 @@
 #define STACK_MAGIC 3
 
 #define REGS_TO_SAVE "r13", "r14", "r15", "r16", "r17", "r18", "r19", "r20", \
-       "r21", "r22", "r23", "r24", "r25", "r26", "r27", "r28", "r29", "r31", \
+       "r21", "r22", "r23", "r24", "r25", "r26", "r27", "r28", "r29", \
        "cr2", "cr3", "cr4"
 
 static int
 slp_switch(void)
 {
 	static int x = 0;
-	register int *stackref, stsizediff;
+	register intptr_t *stackref;
+	register int stsizediff;
 	__asm__ volatile (
 	    "; asm block 1\n"
 	    : /* no outputs */
@@ -70,7 +71,7 @@
  * further self-processing support
  */
 
-/* 
+/*
  * if you want to add self-inspection tools, place them
  * here. See the x86_msvc for the necessary defines.
  * These features are highly experimental und not

Modified: stackless/trunk/Stackless/unittests/test_pickle.py
==============================================================================
--- stackless/trunk/Stackless/unittests/test_pickle.py	(original)
+++ stackless/trunk/Stackless/unittests/test_pickle.py	Fri Aug  4 16:28:40 2006
@@ -10,6 +10,9 @@
 VERBOSE = False
 glist = []
 
+def nothing():
+    pass
+
 def accumulate(ident, func, *args):
     rval = (ident, func(*args))
     glist.append(rval)
@@ -39,6 +42,9 @@
     def run(self):
         self.channel.receive()
 
+class CustomTasklet(tasklet):
+    __slots__ = [ "name" ]
+
 def listtest(n, when):
     for i in range(n):
         if i == when:
@@ -175,6 +181,12 @@
         have_fromkeys = False
 
 class TestConcretePickledTasklets(TestPickledTasklets):
+    def testClassPersistence(self):
+        t1 = CustomTasklet(nothing)()
+        s = pickle.dumps(t1)
+        t2 = pickle.loads(s)
+        self.assertEquals(t1.__class__, t2.__class__)
+
     def testGenerator(self):
         self.run_pickled(genoutertest, 20, 13)
 

_______________________________________________
Stackless-checkins mailing list
Stackless-checkins at stackless.com
http://www.stackless.com/mailman/listinfo/stackless-checkins



More information about the Stackless-checkins mailing list