From 49ac101ce5d896839e37521100e3c18a25dd6dcb Mon Sep 17 00:00:00 2001 From: Angel Ortega Date: Fri, 17 Oct 2008 10:30:56 +0200 Subject: [PATCH] When a value is destroyed, is marked with the MPDM_DELETED flag. --- RELEASE_NOTES | 1 + mpdm.h | 1 + mpdm_v.c | 8 ++++++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/RELEASE_NOTES b/RELEASE_NOTES index 9456a1f..f19c4dc 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -9,6 +9,7 @@ MPDM Release Notes none is set. * If the third argument to sregex() is a hash, the values can now also be executable ones. + * New internal flag for values to mark them as deleted. 1.0.5 ----- diff --git a/mpdm.h b/mpdm.h index f3f27fa..9b3a312 100644 --- a/mpdm.h +++ b/mpdm.h @@ -29,6 +29,7 @@ extern "C" { #define MPDM_STRING 0x00000001 /* data can be string-compared */ #define MPDM_MULTIPLE 0x00000002 /* data is multiple */ #define MPDM_FREE 0x00000004 /* free data at destroy */ +#define MPDM_DELETED 0x00000008 /* value is deleted */ #define MPDM_IVAL 0x00000010 /* integer value cached in .ival */ #define MPDM_RVAL 0x00000020 /* real value cached in .rval */ diff --git a/mpdm_v.c b/mpdm_v.c index 80039bf..a256c53 100644 --- a/mpdm_v.c +++ b/mpdm_v.c @@ -55,6 +55,7 @@ static void cleanup_value(mpdm_t v) if (v->data != NULL && v->flags & MPDM_FREE) { mpdm->memory_usage -= v->size; free((void *)v->data); + v->data = NULL; } } @@ -62,8 +63,8 @@ static void cleanup_value(mpdm_t v) int mpdm_destroy(mpdm_t v) /* destroys a value */ { - /* if still referenced, don't do it */ - if (v->ref) + /* if still referenced or deleted, do nothing */ + if (v->ref || v->flags & MPDM_DELETED) return 0; /* dequeue */ @@ -83,6 +84,9 @@ int mpdm_destroy(mpdm_t v) cleanup_value(v); + /* mark as deleted */ + v->flags |= MPDM_DELETED; + return 1; } -- 2.11.4.GIT