BarryServer : Git

All the code for all my projects
// BarryServer : Git / libBLOC / commit / c5a8d166e141bc66615bbf6d3f16e6c1ab6accf6 / object.c

// Related

libBLOC

Barry Adding object metadata functions c5a8d16 (2 years, 11 months ago)
diff --git a/object.c b/object.c
index f51dbbd..52fbe89 100644
--- a/object.c
+++ b/object.c
@@ -33,11 +33,20 @@
 #include "../assert.h"
 #include "object.h"
 
-/* Count the number of reference an object has */
+/* Verify that a pointer points to a valid object */
+int
+obj_verify(void *addr)
+{
+	struct ObjectHeader *obj = object_header(addr);
+	return (int) (obj->magic == OBJECT_MAGIC);
+}
+
+/* Count the number of references an object has */
 unsigned int
 obj_usage(void *addr)
 {
 	struct ObjectHeader *obj = object_header(addr);
+	ASSERT(obj->magic == OBJECT_MAGIC);
 	return (unsigned int) obj->usage;
 }
 
@@ -89,6 +98,15 @@ obj_new(struct ObjectType *type)
 	return obj_get(body);
 }
 
+/* Return the object type of an object */
+struct ObjectType *
+obj_type(void *addr)
+{
+	struct ObjectHeader *obj = object_header(addr);
+	ASSERT(obj->magic == OBJECT_MAGIC);
+	return obj->type;
+}
+
 /* Lock an object */
 void
 obj_lock(void *addr)