Commit 9c760852 authored by Pekka Pessi's avatar Pekka Pessi
Browse files

Fixed stupid bug with su_home_desctructor().

darcs-hash:20060324153939-65a35-0f5f59055a6692f14f8a83f1b3f2a9228a5223d4.gz
parent 226691ae
......@@ -399,6 +399,7 @@ void *sub_alloc(su_home_t *home,
b2->sub_prsize = sub->sub_prsize;
b2->sub_prused = sub->sub_prused;
b2->sub_preauto = sub->sub_preauto;
b2->sub_destructor = sub->sub_destructor;
/* auto_all is not copied! */
b2->sub_stats = sub->sub_stats;
}
......@@ -901,6 +902,8 @@ void su_home_deinit(su_home_t *home)
* error. It uses a temporary home and moves the blocks from temporary to a
* proper home when successful, but frees the temporary home upon an error.
*
* If @src has destructor, it is called before starting to move.
*
* @param dst destination home
* @param src source home
*
......@@ -919,6 +922,13 @@ int su_home_move(su_home_t *dst, su_home_t *src)
s = MEMLOCK(src); d = MEMLOCK(dst);
if (s && s->sub_n) {
if (s->sub_destructor) {
void (*destructor)(void *) = s->sub_destructor;
s->sub_destructor = NULL;
destructor(src);
}
if (d)
used = s->sub_used + d->sub_used;
else
......
......@@ -73,6 +73,7 @@ static int test_alloc(void)
void *m0[N], *m1[N], *m;
char *c, *c0, *p0, *p1;
int i;
enum { destructed_once = 1 };
int d0, d1, d2, d3;
BEGIN();
......@@ -88,10 +89,20 @@ static int test_alloc(void)
TEST_1(h2 = su_home_ref(h0->home));
su_home_unref(h0->home);
TEST(d0, 0);
for (i = 0; i < 128; i++)
TEST_1(su_alloc(h0->home, 16));
for (i = 0; i < 128; i++)
TEST_1(su_alloc(h1->home, 16));
for (i = 0; i < 128; i++)
TEST_1(su_alloc(h2->home, 16));
su_home_unref(h2->home); /* Should call destructor of cloned home, too */
TEST(d0, 1);
TEST(d1, 1);
TEST(d0, destructed_once);
TEST(d1, destructed_once);
TEST_1(h0 = su_home_new(sizeof(*h0)));
TEST_1(h1 = su_home_clone(h0->home, sizeof(*h1)));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment