From: Michael D. Lowis Date: Fri, 25 Sep 2015 01:59:29 +0000 (-0400) Subject: added get and set functions for object X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=8a0afd353df9f15384342f63c7836814e1b75591;p=proto%2Fgir.git added get and set functions for object --- diff --git a/source/gir.c b/source/gir.c index 1c224c8..6961037 100644 --- a/source/gir.c +++ b/source/gir.c @@ -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)