Created
May 26, 2009 03:33
-
-
Save macournoyer/117874 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/vm/gc.c b/vm/gc.c | |
index baec8c5..88a462d 100644 | |
--- a/vm/gc.c | |
+++ b/vm/gc.c | |
@@ -1,17 +1,17 @@ | |
#include "tr.h" | |
-OBJ GC_alloc(void* type){ | |
- OBJ data = calloc(1, sizeof(type)); | |
+OBJ GC_alloc(int size){ | |
+ OBJ data = calloc(1, size); | |
if (data == NULL) | |
return NULL; | |
- data->refCount = 1; | |
+ TR_COBJECT(data)->refCount = 1; | |
return data; | |
} | |
void GC_updateRef(OBJ l, OBJ r){ | |
if (r != TR_NIL) | |
- r->refCount++; | |
+ TR_COBJECT(r)->refCount++; | |
GC_releaseRef(l); | |
l = r; | |
@@ -20,8 +20,8 @@ void GC_updateRef(OBJ l, OBJ r){ | |
void GC_releaseRef(OBJ o){ | |
if (o == TR_NIL) return; | |
- o->refCount--; | |
- if (o->refCount == 0) | |
+ TR_COBJECT(o)->refCount--; | |
+ if (TR_COBJECT(o)->refCount == 0) | |
{ | |
//khiter_t k; | |
//khash_t(OBJ) *h = o->ivars; | |
diff --git a/vm/tr.h b/vm/tr.h | |
index bd32d1a..2323777 100644 | |
--- a/vm/tr.h | |
+++ b/vm/tr.h | |
@@ -117,7 +117,7 @@ | |
/* core classes macros */ | |
#define TR_INIT_CORE_OBJECT(T) ({ \ | |
- Tr##T *o = GC_alloc(Tr##T); \ | |
+ Tr##T *o = (Tr##T *)GC_alloc(sizeof(Tr##T)); \ | |
o->type = TR_T_##T; \ | |
o->class = vm->classes[TR_T_##T]; \ | |
o->ivars = kh_init(OBJ); \ | |
@@ -409,7 +409,7 @@ TrBlock *TrBlock_compile(VM, char *code, char *fn, size_t lineno); | |
void TrBlock_dump(VM, TrBlock *b); | |
/* GC */ | |
-OBJ GC_alloc(void* type); | |
+OBJ GC_alloc(int size); | |
void GC_updateRef(OBJ l, OBJ r); | |
void GC_releaseRef(OBJ o); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment