[Stackless-checkins] CVS: slpdev/src/2.3/dev/Stackless/core slp_transfer.c, 1.25, 1.26 stackless_impl.h, 1.93, 1.94 stacklesseval.c, 1.154, 1.155

Christian Tismer tismer at centera.de
Thu Jun 3 19:34:23 CEST 2004


Update of /home/cvs/slpdev/src/2.3/dev/Stackless/core
In directory centera.de:/tmp/cvs-serv15605/Stackless/core

Modified Files:
	slp_transfer.c stackless_impl.h stacklesseval.c 
Log Message:
moved more things into slp_transfer.c, to prevend inlining
and optimization (gcc 3.3.2 problem)

Index: slp_transfer.c
===================================================================
RCS file: /home/cvs/slpdev/src/2.3/dev/Stackless/core/slp_transfer.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** slp_transfer.c	3 Jun 2004 17:25:17 -0000	1.25
--- slp_transfer.c	3 Jun 2004 17:34:21 -0000	1.26
***************
*** 48,51 ****
--- 48,249 ----
  /* these functions must be here, too, to prevend inlining */
  
+ /******************************************************
+ 
+   The C Stack
+ 
+  ******************************************************/
+ 
+ static PyCStackObject *cstack_cache[CSTACK_SLOTS] = { NULL };
+ static int cstack_cachecount = 0;
+ 
+ /* this function will get called by PyStacklessEval_Fini */
+ void slp_cstack_cacheclear(void)
+ {
+ 	int i;
+ 	PyCStackObject *stack;
+ 
+ 	for (i=0; i < CSTACK_SLOTS; i++) {
+ 		while (cstack_cache[i] != NULL) {
+ 			stack = cstack_cache[i];
+ 			cstack_cache[i] = (PyCStackObject *) stack->startaddr;
+ 			PyMem_Free(stack);
+ 		}
+ 	}
+ 	cstack_cachecount = 0;
+ }
+ 
+ static void
+ cstack_dealloc(PyCStackObject *cst)
+ {
+ 	slp_cstack_chain = cst;
+ 	SLP_CHAIN_REMOVE(PyCStackObject, &slp_cstack_chain, cst, next, 
+ 			 prev);
+ 	if (cst->ob_size >= CSTACK_SLOTS) {
+ 		PyMem_Free(cst);
+ 	}
+ 	else {
+ 		if (cstack_cachecount >= CSTACK_MAXCACHE)
+ 		slp_cstack_cacheclear();
+ 		cst->startaddr = (int *) cstack_cache[cst->ob_size];
+ 		cstack_cache[cst->ob_size] = cst;
+ 		++cstack_cachecount;
+ 	}
+ }
+ 
+ 
+ /* slp_cstack_save/restore moved to slp_transfer */
+ 
+ static char cstack_doc[] =
+ "A CStack object serves to save the stack slice which is involved\n\
+ during a recursive Python call. It will also be used for pickling\n\
+ of program state. This structure is highly platform dependant.\n\
+ Note: For inspection, str() can dump it as a string.\
+ ";
+ 
+ #if SIZEOF_VOIDP == SIZEOF_INT
+ #define T_ADDR T_UINT
+ #else
+ #define T_ADDR T_ULONG
+ #endif
+ 
+ 
+ static PyMemberDef cstack_members[] = {
+ 	{"size", T_INT, offsetof(PyCStackObject, ob_size), READONLY},
+ 	{"next", T_OBJECT, offsetof(PyCStackObject, next), READONLY},
+ 	{"prev", T_OBJECT, offsetof(PyCStackObject, prev), READONLY},
+ 	{"task", T_OBJECT, offsetof(PyCStackObject, task), READONLY},
+ 	{"startaddr", T_ADDR, offsetof(PyCStackObject, startaddr), READONLY},
+ 	{0}
+ };
+ 
+ /* simple string interface for inspection */
+ 
+ static PyObject *
+ cstack_str(PyObject *o)
+ {
+ 	PyCStackObject *cst = (PyCStackObject*)o;
+ 	return PyString_FromStringAndSize((char*)&cst->stack,
+ 	    cst->ob_size*sizeof(cst->stack[0]));
+ }
+ 
+ PyTypeObject PyCStack_Type = {
+ 	PyObject_HEAD_INIT(&PyType_Type)
+ 	0,
+ 	"stackless.cstack",
+ 	sizeof(PyCStackObject),
+ 	sizeof(PyObject *),
+ 	(destructor)cstack_dealloc,	/* tp_dealloc */
+ 	0,				/* tp_print */
+ 	0,				/* tp_getattr */
+ 	0,				/* tp_setattr */
+ 	0,				/* tp_compare */
+ 	0,				/* tp_repr */
+ 	0,				/* tp_as_number */
+ 	0,				/* tp_as_sequence */
+ 	0,				/* tp_as_mapping */
+ 	0,				/* tp_hash */
+ 	0,				/* tp_call */
+ 	(reprfunc)cstack_str,		/* tp_str */
+ 	PyObject_GenericGetAttr,	/* tp_getattro */
+ 	PyObject_GenericSetAttr,	/* tp_setattro */
+ 	0,				/* tp_as_buffer */
+ 	Py_TPFLAGS_DEFAULT,		/* tp_flags */
+ 	cstack_doc,			/* tp_doc */
+ 	0,				/* tp_traverse */
+ 	0,				/* tp_clear */
+ 	0,				/* tp_richcompare */
+ 	0,				/* tp_weaklistoffset */
+ 	0,				/* tp_iter */
+ 	0,				/* tp_iternext */
+ 	0,				/* tp_methods */
+ 	cstack_members,			/* tp_members */
+ };
+ 
+ /* 
+  * slp_eval_frame moved to slp_transfer.c
+  * to avoid optimization in gcc 3.3.2
+  */
+ 
+ void slp_kill_tasks_with_stacks(PyThreadState *ts)
+ {
+ 	int count = 0;
+ 
+ 	while (1) {
+ 		PyCStackObject *csfirst = slp_cstack_chain, *cs;
+ 		PyTaskletObject *t;
+ 
+ 		if (csfirst == NULL)
+ 			break;
+ 		for (cs = csfirst; ; cs = cs->next) {
+ 			if (count && cs == csfirst) {
+ 				/* nothing found */
+ 				return;
+ 			}
+ 			++count;
+ 			if (cs->task == NULL)
+ 				continue;
+ 			if (ts != NULL && cs->tstate != ts)
+ 				continue;
+ 			break;
+ 		} 
+ 		count = 0;
+ 		t = cs->task;
+ 		Py_INCREF(t);
+ 
+ 		PyTasklet_Kill(t);
+ 		PyErr_Clear();
+ 
+ 		if (t->f.frame == 0) {
+ 			/* ensure a valid tstate */
+ 			t->cstate->tstate = slp_initial_tstate;
+ 		}
+ 		Py_DECREF(t);
+ 	}
+ }
+ 
+ PyCStackObject *
+ slp_cstack_new(PyCStackObject **cst, int *stackref, PyTaskletObject *task)
+ {
+ 	PyThreadState *ts = PyThreadState_GET();
+ 	int *stackbase = ts->st.cstack_base;
+ 	int size = stackbase - stackref;
+ 
+ 	if (size < 0)
+ 		RUNTIME_ERROR("negative stack size", NULL);
+ 	if (*cst && (*cst)->ob_size == size && (*cst)->ob_refcnt == 1) {
+ 		/* reuse it */
+ 		(*cst)->task = task;
+ 		return *cst;
+ 	}
+ 	    
+ 	if (*cst != NULL) {
+ 		if ((*cst)->task == task)
+ 			(*cst)->task = NULL;
+ 		Py_DECREF(*cst);
+ 	}
+ 	if (size < CSTACK_SLOTS && ((*cst) = cstack_cache[size])) {
+ 		/* take stack from cache */
+ 		cstack_cache[size] = (PyCStackObject *) (*cst)->startaddr;
+ 		--cstack_cachecount;
+ 	}
+ 	else {
+ 		/* PyObject_NewVar is inlined */
+ 		*cst = (PyCStackObject *)
+ 		       PyObject_MALLOC(sizeof(PyCStackObject) + 
+ 				       (size-1) * sizeof(int*));
+ 		if (*cst == NULL) return NULL;
+ 	}
+ 	(void) PyObject_INIT_VAR(*cst, &PyCStack_Type, size);
+ 
+ 	(*cst)->startaddr = stackbase;
+ 	(*cst)->next = (*cst)->prev = NULL;
+ 	SLP_CHAIN_INSERT(PyCStackObject, &slp_cstack_chain, *cst, next, prev);
+ 	(*cst)->serial = ts->st.serial;
+ 	(*cst)->task = task;
+ 	(*cst)->tstate = ts;
+ 	(*cst)->nesting_level = ts->st.nesting_level;
+ 	return *cst;
+ }
+ 
  int
  slp_cstack_save(PyCStackObject *cstprev)

Index: stackless_impl.h
===================================================================
RCS file: /home/cvs/slpdev/src/2.3/dev/Stackless/core/stackless_impl.h,v
retrieving revision 1.93
retrieving revision 1.94
diff -C2 -d -r1.93 -r1.94
*** stackless_impl.h	3 Jun 2004 17:18:06 -0000	1.93
--- stackless_impl.h	3 Jun 2004 17:34:21 -0000	1.94
***************
*** 43,46 ****
--- 43,47 ----
  PyAPI_FUNC(int) slp_cstack_save(PyCStackObject *cstprev);
  PyAPI_FUNC(void) slp_cstack_restore(PyCStackObject *cst);
+ PyAPI_FUNC(void) slp_cstack_cacheclear(void);
  
  PyAPI_FUNC(int) slp_transfer(PyCStackObject **cstprev, PyCStackObject *cst,

Index: stacklesseval.c
===================================================================
RCS file: /home/cvs/slpdev/src/2.3/dev/Stackless/core/stacklesseval.c,v
retrieving revision 1.154
retrieving revision 1.155
diff -C2 -d -r1.154 -r1.155
*** stacklesseval.c	3 Jun 2004 17:25:17 -0000	1.154
--- stacklesseval.c	3 Jun 2004 17:34:21 -0000	1.155
***************
*** 37,238 ****
  
  
- /******************************************************
- 
-   The C Stack
- 
-  ******************************************************/
- 
- static PyCStackObject *cstack_cache[CSTACK_SLOTS] = { NULL };
- static int cstack_cachecount = 0;
- 
- /* this function will get called by PyStacklessEval_Fini */
- static void slp_cstack_cacheclear(void)
- {
- 	int i;
- 	PyCStackObject *stack;
- 
- 	for (i=0; i < CSTACK_SLOTS; i++) {
- 		while (cstack_cache[i] != NULL) {
- 			stack = cstack_cache[i];
- 			cstack_cache[i] = (PyCStackObject *) stack->startaddr;
- 			PyMem_Free(stack);
- 		}
- 	}
- 	cstack_cachecount = 0;
- }
- 
- static void
- cstack_dealloc(PyCStackObject *cst)
- {
- 	slp_cstack_chain = cst;
- 	SLP_CHAIN_REMOVE(PyCStackObject, &slp_cstack_chain, cst, next, 
- 			 prev);
- 	if (cst->ob_size >= CSTACK_SLOTS) {
- 		PyMem_Free(cst);
- 	}
- 	else {
- 		if (cstack_cachecount >= CSTACK_MAXCACHE)
- 		slp_cstack_cacheclear();
- 		cst->startaddr = (int *) cstack_cache[cst->ob_size];
- 		cstack_cache[cst->ob_size] = cst;
- 		++cstack_cachecount;
- 	}
- }
- 
- 
- PyCStackObject *
- slp_cstack_new(PyCStackObject **cst, int *stackref, PyTaskletObject *task)
- {
- 	PyThreadState *ts = PyThreadState_GET();
- 	int *stackbase = ts->st.cstack_base;
- 	int size = stackbase - stackref;
- 
- 	if (size < 0)
- 		RUNTIME_ERROR("negative stack size", NULL);
- 	if (*cst && (*cst)->ob_size == size && (*cst)->ob_refcnt == 1) {
- 		/* reuse it */
- 		(*cst)->task = task;
- 		return *cst;
- 	}
- 	    
- 	if (*cst != NULL) {
- 		if ((*cst)->task == task)
- 			(*cst)->task = NULL;
- 		Py_DECREF(*cst);
- 	}
- 	if (size < CSTACK_SLOTS && ((*cst) = cstack_cache[size])) {
- 		/* take stack from cache */
- 		cstack_cache[size] = (PyCStackObject *) (*cst)->startaddr;
- 		--cstack_cachecount;
- 	}
- 	else {
- 		/* PyObject_NewVar is inlined */
- 		*cst = (PyCStackObject *)
- 		       PyObject_MALLOC(sizeof(PyCStackObject) + 
- 				       (size-1) * sizeof(int*));
- 		if (*cst == NULL) return NULL;
- 	}
- 	(void) PyObject_INIT_VAR(*cst, &PyCStack_Type, size);
- 
- 	(*cst)->startaddr = stackbase;
- 	(*cst)->next = (*cst)->prev = NULL;
- 	SLP_CHAIN_INSERT(PyCStackObject, &slp_cstack_chain, *cst, next, prev);
- 	(*cst)->serial = ts->st.serial;
- 	(*cst)->task = task;
- 	(*cst)->tstate = ts;
- 	(*cst)->nesting_level = ts->st.nesting_level;
- 	return *cst;
- }
- 
- /* slp_cstack_save/restore moved to slp_transfer */
- 
- static char cstack_doc[] =
- "A CStack object serves to save the stack slice which is involved\n\
- during a recursive Python call. It will also be used for pickling\n\
- of program state. This structure is highly platform dependant.\n\
- Note: For inspection, str() can dump it as a string.\
- ";
- 
- #if SIZEOF_VOIDP == SIZEOF_INT
- #define T_ADDR T_UINT
- #else
- #define T_ADDR T_ULONG
- #endif
- 
- 
- static PyMemberDef cstack_members[] = {
- 	{"size", T_INT, offsetof(PyCStackObject, ob_size), READONLY},
- 	{"next", T_OBJECT, offsetof(PyCStackObject, next), READONLY},
- 	{"prev", T_OBJECT, offsetof(PyCStackObject, prev), READONLY},
- 	{"task", T_OBJECT, offsetof(PyCStackObject, task), READONLY},
- 	{"startaddr", T_ADDR, offsetof(PyCStackObject, startaddr), READONLY},
- 	{0}
- };
- 
- /* simple string interface for inspection */
- 
- static PyObject *
- cstack_str(PyObject *o)
- {
- 	PyCStackObject *cst = (PyCStackObject*)o;
- 	return PyString_FromStringAndSize((char*)&cst->stack,
- 	    cst->ob_size*sizeof(cst->stack[0]));
- }
- 
- PyTypeObject PyCStack_Type = {
- 	PyObject_HEAD_INIT(&PyType_Type)
- 	0,
- 	"stackless.cstack",
- 	sizeof(PyCStackObject),
- 	sizeof(PyObject *),
- 	(destructor)cstack_dealloc,	/* tp_dealloc */
- 	0,				/* tp_print */
- 	0,				/* tp_getattr */
- 	0,				/* tp_setattr */
- 	0,				/* tp_compare */
- 	0,				/* tp_repr */
- 	0,				/* tp_as_number */
- 	0,				/* tp_as_sequence */
- 	0,				/* tp_as_mapping */
- 	0,				/* tp_hash */
- 	0,				/* tp_call */
- 	(reprfunc)cstack_str,		/* tp_str */
- 	PyObject_GenericGetAttr,	/* tp_getattro */
- 	PyObject_GenericSetAttr,	/* tp_setattro */
- 	0,				/* tp_as_buffer */
- 	Py_TPFLAGS_DEFAULT,		/* tp_flags */
- 	cstack_doc,			/* tp_doc */
- 	0,				/* tp_traverse */
- 	0,				/* tp_clear */
- 	0,				/* tp_richcompare */
- 	0,				/* tp_weaklistoffset */
- 	0,				/* tp_iter */
- 	0,				/* tp_iternext */
- 	0,				/* tp_methods */
- 	cstack_members,			/* tp_members */
- };
- 
- /* 
-  * slp_eval_frame moved to slp_transfer.c
-  * to avoid optimization in gcc 3.3.2
-  */
- 
- void slp_kill_tasks_with_stacks(PyThreadState *ts)
- {
- 	int count = 0;
- 
- 	while (1) {
- 		PyCStackObject *csfirst = slp_cstack_chain, *cs;
- 		PyTaskletObject *t;
- 
- 		if (csfirst == NULL)
- 			break;
- 		for (cs = csfirst; ; cs = cs->next) {
- 			if (count && cs == csfirst) {
- 				/* nothing found */
- 				return;
- 			}
- 			++count;
- 			if (cs->task == NULL)
- 				continue;
- 			if (ts != NULL && cs->tstate != ts)
- 				continue;
- 			break;
- 		} 
- 		count = 0;
- 		t = cs->task;
- 		Py_INCREF(t);
- 
- 		PyTasklet_Kill(t);
- 		PyErr_Clear();
- 
- 		if (t->f.frame == 0) {
- 			/* ensure a valid tstate */
- 			t->cstate->tstate = slp_initial_tstate;
- 		}
- 		Py_DECREF(t);
- 	}
- }
- 
  void PyStackless_kill_tasks_with_stacks(int allthreads)
  {
--- 37,40 ----


_______________________________________________
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