]> git.mdlowis.com Git - proto/gir.git/commitdiff
added get and set functions for object
authorMichael D. Lowis <mike@mdlowis.com>
Fri, 25 Sep 2015 01:59:29 +0000 (21:59 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Fri, 25 Sep 2015 01:59:29 +0000 (21:59 -0400)
source/gir.c

index 1c224c86c6e9154bc610008c1caa941e080b8471..69610374a4cc31c88600f62c96ba2a6cd3539d68 100644 (file)
@@ -50,7 +50,7 @@ static int slot_cmp(void* a, void* b) {
 
 /* Base Object Definition
  *****************************************************************************/
-Obj* mkobject(uint32_t type, size_t datasz) {
+Obj* obj_new(uint32_t type, size_t datasz) {
     Obj* obj    = (Obj*)malloc(sizeof(struct Obj) + datasz);
     obj->type   = type;
     obj->size   = datasz;
@@ -59,6 +59,19 @@ Obj* mkobject(uint32_t type, size_t datasz) {
     return obj;
 }
 
+void obj_set(Obj* obj, uintptr_t sel, Obj* val) {
+    Slot* slot = (Slot*)malloc(sizeof(Slot));
+    slot->sel  = sel;
+    slot->val  = val;
+    hamt_insert(&(obj->slots), slot);
+}
+
+Obj* obj_get(Obj* obj, uintptr_t sel) {
+    Slot slot = { sel, NULL };
+    Slot* entry = hamt_lookup(&(obj->slots), &slot);
+    return (entry != NULL) ? entry->val : NULL;
+}
+
 /* Main API
  *****************************************************************************/
 GirCtx* gir_init(void)