#include "nasal.h"
#include "code.h"
-static void* chkptr(void* p)
-{
- naRef foo;
- SETPTR(foo, p);
- if(PTR(foo).obj != p) *(int*)0=0;
- return p;
-}
-
void naFree(void* m) { free(m); }
-void* naAlloc(int n) { return chkptr(malloc(n)); }
-void* naRealloc(void* b, int n) { return chkptr(realloc(b, n)); }
+void* naAlloc(int n) { return malloc(n); }
+void* naRealloc(void* b, int n) { return realloc(b, n); }
void naBZero(void* m, int n) { memset(m, 0, n); }
void naTempSave(naContext c, naRef r)
naRef naNewString(struct Context* c)
{
naRef s = naNew(c, T_STR);
- PTR(s).str->len = 0;
- PTR(s).str->data = 0;
+ PTR(s).str->emblen = 0;
+ PTR(s).str->data.ref.len = 0;
+ PTR(s).str->data.ref.ptr = 0;
PTR(s).str->hashcode = 0;
return s;
}
naRef naNewGhost(naContext c, naGhostType* type, void* ptr)
{
- naRef ghost = naNew(c, T_GHOST);
+ naRef ghost;
+ // ensure 'simple' ghost users don't see garbage for these fields
+ type->get_member = 0;
+ type->set_member = 0;
+
+ ghost = naNew(c, T_GHOST);
PTR(ghost).ghost->gtype = type;
PTR(ghost).ghost->ptr = ptr;
return ghost;
}
+naRef naNewGhost2(naContext c, naGhostType* t, void* ptr)
+{
+ naRef ghost = naNew(c, T_GHOST);
+ PTR(ghost).ghost->gtype = t;
+ PTR(ghost).ghost->ptr = ptr;
+ return ghost;
+}
+
naGhostType* naGhost_type(naRef ghost)
{
if(!IS_GHOST(ghost)) return 0;
int naStrEqual(naRef a, naRef b)
{
int i;
- if(!(IS_STR(a) && IS_STR(b)))
- return 0;
- if(PTR(a).str->len != PTR(b).str->len)
+ char *ap, *bp;
+ if(!IS_STR(a) || !IS_STR(b) || naStr_len(a) != naStr_len(b))
return 0;
- for(i=0; i<PTR(a).str->len; i++)
- if(PTR(a).str->data[i] != PTR(b).str->data[i])
+ ap = naStr_data(a);
+ bp = naStr_data(b);
+ for(i=0; i<naStr_len(a); i++)
+ if(ap[i] != bp[i])
return 0;
return 1;
}