X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fnasal%2Fmisc.c;h=a249fce70332fb186e991fddb46a9d863acec7db;hb=9fecb69b842814f0953d73727b2f538281c7e00a;hp=6e0e92398d7e4fcb2e3561667df700dc8418f4f5;hpb=b05e32fa8c11e6d66bb70850751e170dc472a1a3;p=simgear.git diff --git a/simgear/nasal/misc.c b/simgear/nasal/misc.c index 6e0e9239..a249fce7 100644 --- a/simgear/nasal/misc.c +++ b/simgear/nasal/misc.c @@ -5,17 +5,9 @@ #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) @@ -85,8 +77,9 @@ naRef naNew(struct Context* c, int type) 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; } @@ -114,6 +107,24 @@ naRef naNewCCode(struct Context* c, naCFunction fptr) { naRef r = naNew(c, T_CCODE); PTR(r).ccode->fptr = fptr; + PTR(r).ccode->fptru = 0; + return r; +} + +naRef naNewCCodeU(struct Context* c, naCFunctionU fptr, void* user_data) +{ + return naNewCCodeUD(c, fptr, user_data, 0); +} + +naRef naNewCCodeUD( struct Context* c, + naCFunctionU fptr, + void* user_data, + void (*destroy)(void*) ) +{ + naRef r = naNew(c, T_CCODE); + PTR(r).ccode->fptru = fptr; + PTR(r).ccode->user_data = user_data; + PTR(r).ccode->destroy = destroy; return r; } @@ -128,12 +139,25 @@ naRef naNewFunc(struct Context* c, naRef code) 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; @@ -185,12 +209,13 @@ int naEqual(naRef a, naRef b) 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; ilen; i++) - if(PTR(a).str->data[i] != PTR(b).str->data[i]) + ap = naStr_data(a); + bp = naStr_data(b); + for(i=0; i