/* * object.C: Object management. * Rights to this code are documented in doc/LICENSE. * * Copyright © 2005-2007 Atheme Project (http://www.atheme.org) */ static char const rcsid[] = "$Id"; #include "atheme.h" /* * object_init * * Populates the object manager part of an object. * * Inputs: * - pointer to object manager area * - (optional) name of object * - (optional) custom destructor * * Outputs: * - none * * Side Effects: * - none */ void object_init (object_t * obj, const char *name, destructor_t des) { return_if_fail (obj != NULL); // if (name != NULL) // obj->name = sstrdup (name); obj->destructor = des; obj->refcount = 1; } /* * object_ref * * Increment the reference counter on an object. * * Inputs: * - the object to refcount * * Outputs: * - none * * Side Effects: * - none */ void * object_ref (void *object) { return_val_if_fail (object != NULL, NULL); asobject (object)->refcount++; return object; } /* * object_unref * * Decrement the reference counter on an object. * * Inputs: * - the object to refcount * * Outputs: * - none * * Side Effects: * - if the refcount is 0, the object is destroyed. */ void object_unref (void *object) { object_t *obj; return_if_fail (object != NULL); obj = asobject (object); obj->refcount--; if (obj->refcount <= 0) { if (obj->name != NULL) free (obj->name); if (obj->destructor != NULL) obj->destructor (obj); else free (obj); } } /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs * vim:ts=8 * vim:sw=8 * vim:noexpandtab */