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

Guido van Rossum python-dev@python.org
Mon, 24 Apr 2000 11:41:18 -0400 (EDT)


Update of /projects/cvsroot/python/dist/src/Include
In directory eric:/projects/python/develop/guido/src/Include

Modified Files:
	object.h 
Log Message:
Christian Tismer -- total rewrite on trashcan code.

Improvements:
- does no longer need any extra memory
- has no relationship to tstate
- works in debug mode
- can easily be modified for free threading (hi Greg:)

Side effects:
Trashcan does change the order of object destruction.
Prevending that would be quite an immense effort, as
my attempts have shown. This version works always
the same, with debug mode or not. The slightly
changed destruction order should therefore be no problem.

Algorithm:
While the old idea of delaying the destruction of some
obejcts at a certain recursion level was kept, we now
no longer aloocate an object to hold these objects.
The delayed objects are instead chained together
via their ob_type field. The type is encoded via
ob_refcnt. When it comes to the destruction of the
chain of waiting objects, the topmost object is popped
off the chain and revived with type and refcount 1,
then it gets a normal Py_DECREF.

I am confident that this solution is near optimum
for minimizing side effects and code bloat.



Index: object.h
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Include/object.h,v
retrieving revision 2.53
retrieving revision 2.54
diff -C2 -r2.53 -r2.54
*** object.h	2000/04/14 19:13:07	2.53
--- object.h	2000/04/24 15:40:45	2.54
***************
*** 537,540 ****
--- 537,545 ----
    Unfortunately, deallocations also take place when
    the thread state is undefined.
+ 
+   CT 2k0422 complete rewrite.
+   There is no need to allocate new objects.
+   Everything is done vialob_refcnt and ob_type now.
+   Adding support for free-threading should be easy, too.
  */
  
***************
*** 552,560 ****
  		--_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;
--- 557,565 ----
  		--_PyTrash_delete_nesting; \
  		if (_PyTrash_delete_later && _PyTrash_delete_nesting <= 0) \
! 			_PyTrash_destroy_chain(); \
  	} \
  
  extern DL_IMPORT(void) _PyTrash_deposit_object Py_PROTO((PyObject*));
! extern DL_IMPORT(void) _PyTrash_destroy_chain Py_PROTO(());
  
  extern DL_IMPORT(int) _PyTrash_delete_nesting;
***************
*** 565,568 ****
--- 570,574 ----
  #define xxPy_TRASHCAN_SAFE_BEGIN(op) 
  #define xxPy_TRASHCAN_SAFE_END(op) ;
+ 
  #ifdef __cplusplus
  }