summaryrefslogtreecommitdiffstats
path: root/Objects/object.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2000-03-13 16:01:29 (GMT)
committerGuido van Rossum <guido@python.org>2000-03-13 16:01:29 (GMT)
commitd724b23420f8e9d73a656c941c45b234e08ff9d6 (patch)
treea87fcb839783274d3d0fee3c9609793189a83d8e /Objects/object.c
parent96a45adf808ee9798d0c2637aeed2c895fa8e929 (diff)
downloadcpython-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 'Objects/object.c')
-rw-r--r--Objects/object.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/Objects/object.c b/Objects/object.c
index 7a41aa2..d2aa542 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -906,3 +906,48 @@ Py_ReprLeave(obj)
}
}
}
+
+/*
+ trashcan
+ CT 2k0130
+ non-recursively destroy nested objects
+
+ CT 2k0223
+ everything is now done in a macro.
+
+ CT 2k0305
+ modified to use functions, after Tim Peter's suggestion.
+
+ CT 2k0309
+ modified to restore a possible error.
+*/
+
+int _PyTrash_delete_nesting = 0;
+PyObject * _PyTrash_delete_later = NULL;
+
+void
+_PyTrash_deposit_object(op)
+ PyObject *op;
+{
+ PyObject *error_type, *error_value, *error_traceback;
+ PyErr_Fetch(&error_type, &error_value, &error_traceback);
+
+ if (!_PyTrash_delete_later)
+ _PyTrash_delete_later = PyList_New(0);
+ if (_PyTrash_delete_later)
+ PyList_Append(_PyTrash_delete_later, (PyObject *)op);
+
+ PyErr_Restore(error_type, error_value, error_traceback);
+}
+
+void
+_PyTrash_destroy_list()
+{
+ while (_PyTrash_delete_later) {
+ PyObject *shredder = _PyTrash_delete_later;
+ _PyTrash_delete_later = NULL;
+ ++_PyTrash_delete_nesting;
+ Py_DECREF(shredder);
+ --_PyTrash_delete_nesting;
+ }
+}