diff options
author | Guido van Rossum <guido@python.org> | 2000-03-13 16:01:29 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2000-03-13 16:01:29 (GMT) |
commit | d724b23420f8e9d73a656c941c45b234e08ff9d6 (patch) | |
tree | a87fcb839783274d3d0fee3c9609793189a83d8e /Include | |
parent | 96a45adf808ee9798d0c2637aeed2c895fa8e929 (diff) | |
download | cpython-d724b23420f8e9d73a656c941c45b234e08ff9d6.zip cpython-d724b23420f8e9d73a656c941c45b234e08ff9d6.tar.gz cpython-d724b23420f8e9d73a656c941c45b234e08ff9d6.tar.bz2 |
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.
Diffstat (limited to 'Include')
-rw-r--r-- | Include/object.h | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/Include/object.h b/Include/object.h index f718509..243de29 100644 --- a/Include/object.h +++ b/Include/object.h @@ -514,6 +514,53 @@ it carefully, it may save lots of calls to Py_INCREF() and Py_DECREF() at times. */ +/* + 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 } #endif |