Eobj: Fixed wref bugs and improve it's tests.

SVN revision: 70584
This commit is contained in:
Tom Hacohen 2012-05-01 14:00:14 +00:00
parent e1efeae7a4
commit 18eda16fa2
2 changed files with 30 additions and 4 deletions

View File

@ -164,13 +164,13 @@ _wref_del(const Eo *obj, const void *class_data, va_list *list)
if (!pd->wrefs)
{
ERR("There are no weak refs for object %p", obj);
*wref = NULL;
return;
}
/* Move the last item in the array instead of the current wref. */
count = _wref_count(pd);
if (count > 1)
{
Eo ***itr;
for (itr = pd->wrefs ; *itr ; itr++)
@ -182,9 +182,19 @@ _wref_del(const Eo *obj, const void *class_data, va_list *list)
}
}
if (!*itr)
{
ERR("Wref %p is not associated with object %p", wref, obj);
*wref = NULL;
return;
}
}
if (count > 1)
{
// No count--; because of the NULL that is not included in the count. */
pd->wrefs = realloc(pd->wrefs, sizeof(*pd->wrefs) * count);
pd->wrefs[count] = NULL;
pd->wrefs[count - 1] = NULL;
}
else
{

View File

@ -70,7 +70,7 @@ START_TEST(eo_weak_reference)
Eo *obj = eo_add(SIMPLE_CLASS, NULL);
Eo *obj2 = eo_add(SIMPLE_CLASS, NULL);
Eo *wref;
Eo *wref, *wref2, *wref3;
eo_do(obj, eo_wref_add(&wref));
fail_if(!wref);
@ -103,7 +103,23 @@ START_TEST(eo_weak_reference)
wref = obj;
eo_do(obj, eo_wref_del(&wref));
fail_if(wref != obj);
fail_if(wref);
wref = wref2 = wref3 = NULL;
eo_do(obj, eo_wref_add(&wref), eo_wref_add(&wref2), eo_wref_add(&wref3));
fail_if(!wref);
fail_if(!wref2);
fail_if(!wref3);
eo_do(obj, eo_wref_del(&wref), eo_wref_del(&wref2), eo_wref_del(&wref3));
fail_if(wref);
fail_if(wref2);
fail_if(wref3);
eo_do(obj, eo_wref_add(&wref2), eo_wref_add(&wref3));
wref = obj;
eo_do(obj, eo_wref_del(&wref));
fail_if(wref);
eo_do(obj, eo_wref_del(&wref2), eo_wref_del(&wref3));
eo_unref(obj);
eo_unref(obj2);