Commit 5dc88013 authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

miniobj: Add a FINI_OBJ() macro

It operates on a pointer like FREE_OBJ() and clears it.
parent f8974400
......@@ -425,8 +425,7 @@ ses_handle(struct waited *wp, enum wait_event ev, vtim_real now)
CAST_OBJ_NOTNULL(xp, (const void*)wp->priv2, TRANSPORT_MAGIC);
AN(wp->priv2);
assert(WS_Reservation(sp->ws) == wp);
wp->magic = 0;
wp = NULL;
FINI_OBJ(wp);
/* The WS was reserved in SES_Wait() */
WS_Release(sp->ws, 0);
......
......@@ -122,7 +122,7 @@ vht_trim(struct vht_table *tbl, ssize_t max)
assert(e->offset == u);
u += ENTRYLEN(e);
v++;
e->magic = 0;
FINI_OBJ(e);
} else {
/* Fixup offset */
assert(e->offset >= u);
......@@ -257,7 +257,7 @@ VHT_NewEntry_Indexed(struct vht_table *tbl, unsigned idx)
assert(e->offset == 0);
lname = e->namelen;
lentry = ENTRYLEN(e);
e->magic = 0;
FINI_OBJ(e);
memmove(TBLENTRY(tbl, 1), TBLENTRY(tbl, 0), (tbl->n - 1) * sizeof *e);
tbl->n--;
......@@ -462,7 +462,7 @@ VHT_Init(struct vht_table *tbl, size_t protomax)
INIT_OBJ(tbl, VHT_TABLE_MAGIC);
r = VHT_SetProtoMax(tbl, protomax);
if (r) {
tbl->magic = 0;
FINI_OBJ(tbl);
return (r);
}
tbl->maxsize = tbl->protomax;
......
......@@ -216,7 +216,7 @@ h2h_decode_fini(const struct h2_sess *h2)
ret = H2CE_COMPRESSION_ERROR;
} else
ret = d->error;
d->magic = 0;
FINI_OBJ(d);
return (ret);
}
......
......@@ -252,18 +252,21 @@ sml_slim(struct worker *wrk, struct objcore *oc)
static void v_matchproto_(objfree_f)
sml_objfree(struct worker *wrk, struct objcore *oc)
{
struct storage *st;
struct object *o;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
sml_slim(wrk, oc);
CAST_OBJ_NOTNULL(o, oc->stobj->priv, OBJECT_MAGIC);
o->magic = 0;
st = o->objstore;
CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC);
FINI_OBJ(o);
if (oc->boc == NULL && oc->stobj->stevedore->lru != NULL)
LRU_Remove(oc);
sml_stv_free(oc->stobj->stevedore, o->objstore);
sml_stv_free(oc->stobj->stevedore, st);
memset(oc->stobj, 0, sizeof oc->stobj);
......
......@@ -17,6 +17,12 @@
(to)->magic = (type_magic); \
} while (0)
#define FINI_OBJ(to) \
do { \
ZERO_OBJ(&(to)->magic, sizeof (to)->magic); \
to = NULL; \
} while (0)
#define ALLOC_OBJ(to, type_magic) \
do { \
(to) = calloc(1, sizeof *(to)); \
......
......@@ -337,8 +337,8 @@ VEV_Stop(struct vev_root *evb, struct vev *e)
es->happened = 0;
}
e->magic = 0;
e->__vevb = NULL;
FINI_OBJ(e);
}
/*--------------------------------------------------------------------*/
......
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