[Python-checkins] cpython: Issue #19741: cleanup tracemalloc_realloc()
victor.stinner
python-checkins at python.org
Sun Nov 24 12:28:31 CET 2013
http://hg.python.org/cpython/rev/dadb5ed301c7
changeset: 87497:dadb5ed301c7
user: Victor Stinner <victor.stinner at gmail.com>
date: Sun Nov 24 12:27:59 2013 +0100
summary:
Issue #19741: cleanup tracemalloc_realloc()
Explain that unhandled error case is very unlikely
files:
Modules/_tracemalloc.c | 23 +++++++++++++++--------
1 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c
--- a/Modules/_tracemalloc.c
+++ b/Modules/_tracemalloc.c
@@ -563,20 +563,27 @@
ptr2 = alloc->realloc(alloc->ctx, ptr, new_size);
if (ptr2 != NULL) {
- if (ptr != NULL)
+ if (ptr != NULL) {
+ /* resize */
tracemalloc_log_free(ptr);
- if (tracemalloc_log_alloc(ptr2, new_size) < 0) {
- if (ptr == NULL) {
+ if (tracemalloc_log_alloc(ptr2, new_size) < 0) {
+ /* Memory allocation failed. The error cannot be reported to
+ the caller, because realloc() may already have shrinked the
+ memory block and so removed bytes.
+
+ This case is very unlikely since we just released an hash
+ entry, so we have enough free bytes to allocate the new
+ entry. */
+ }
+ }
+ else {
+ /* new allocation */
+ if (tracemalloc_log_alloc(ptr2, new_size) < 0) {
/* Memory allocation failed */
alloc->free(alloc->ctx, ptr2);
ptr2 = NULL;
}
- else {
- /* Memory allocation failed. The error cannot be reported to
- the caller, because realloc() may already have shrinked the
- memory block and so removed bytes. */
- }
}
}
set_reentrant(0);
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list