[Python-checkins] CVS: python/dist/src/Include object.h,2.50,2.51

Guido van Rossum guido@cnri.reston.va.us
Mon, 13 Mar 2000 11:01:48 -0500 (EST)


Update of /projects/cvsroot/python/dist/src/Include
In directory eric:/home/guido/hp/mal/py-patched/Include

Modified Files:
	object.h 
Log Message:
Christian Tismer's "trashcan" patch:

Added wrapping macros to dictobject.c, listobject.c, tupleobject.c,
frameobject.c, traceback.c that safely prevends core dumps 
on stack overflow. Macros and functions in object.c, object.h.
The method is an "elevator destructor" that turns cascading
deletes into tail recursive behavior when some limit is hit.


Index: object.h
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Include/object.h,v
retrieving revision 2.50
retrieving revision 2.51
diff -C2 -r2.50 -r2.51
*** object.h	2000/03/01 15:06:53	2.50
--- object.h	2000/03/13 16:01:15	2.51
***************
*** 515,518 ****
--- 515,565 ----
  */
  
+ /*
+   trashcan
+   CT 2k0130
+   non-recursively destroy nested objects
+ 
+   CT 2k0223
+   redefinition for better locality and less overhead.
+ 
+   Objects that want to be recursion safe need to use
+   the macroes 
+ 		Py_TRASHCAN_SAFE_BEGIN(name)
+   and
+ 		Py_TRASHCAN_SAFE_END(name)
+   surrounding their actual deallocation code.
+ 
+   It would be nice to do this using the thread state.
+   Also, we could do an exact stack measure then.
+   Unfortunately, deallocations also take place when
+   the thread state is undefined.
+ */
+ 
+ #define PyTrash_UNWIND_LEVEL 50
+ 
+ #define Py_TRASHCAN_SAFE_BEGIN(op) \
+ 	{ \
+ 		++_PyTrash_delete_nesting; \
+ 		if (_PyTrash_delete_nesting < PyTrash_UNWIND_LEVEL) { \
+ 
+ #define Py_TRASHCAN_SAFE_END(op) \
+ 		;} \
+ 		else \
+ 			_PyTrash_deposit_object((PyObject*)op);\
+ 		--_PyTrash_delete_nesting; \
+ 		if (_PyTrash_delete_later && _PyTrash_delete_nesting <= 0) \
+ 			_PyTrash_destroy_list(); \
+ 	} \
+ 
+ extern DL_IMPORT(void) _PyTrash_deposit_object Py_PROTO((PyObject*));
+ extern DL_IMPORT(void) _PyTrash_destroy_list Py_PROTO(());
+ 
+ extern DL_IMPORT(int) _PyTrash_delete_nesting;
+ extern DL_IMPORT(PyObject *) _PyTrash_delete_later;
+ 
+ /* swap the "xx" to check the speed loss */
+ 
+ #define xxPy_TRASHCAN_SAFE_BEGIN(op) 
+ #define xxPy_TRASHCAN_SAFE_END(op) ;
  #ifdef __cplusplus
  }