void nodedic_add(NODEDIC* pnodelist, SYMBOL_NODE* symbol, NODE* pnode) { NODE** pnewitems; NODE** polditems = pnodelist->items; SYMBOL_NODE** pnewsymbols; SYMBOL_NODE** poldsymbols = pnodelist->symbols; int count = pnodelist->count + 1; pnewitems = (NODE**)GC_MALLOC(sizeof(NODE*) * count); if( polditems != NULL ) { memcpy(pnewitems, polditems, sizeof(NODE*) * (count-1)); GC_FREE(polditems); polditems = NULL; } pnewitems[count-1] = pnode; pnode->refcount++; pnodelist->items = pnewitems; pnewsymbols = (SYMBOL_NODE**)GC_MALLOC(sizeof(SYMBOL_NODE*) * count); if( poldsymbols != NULL ) { memcpy(pnewsymbols, poldsymbols, sizeof(SYMBOL_NODE*) * (count-1)); GC_FREE(poldsymbols); poldsymbols = NULL; } pnewsymbols[count-1] = symbol; symbol->node.refcount++; pnodelist->symbols = pnewsymbols; pnodelist->count = count; }
String *sConcat(const String *s, const String *t) { size_t len; String *n = NULL; char *p; const String *vs, *vt; if (s == NULL) { vs = new_String(""); } else { vs = s; } if (t == NULL) { vt = new_String(""); } else { vt = t; } len = sLength(vs) + sLength(vt); if ((p = (char *) GC_MALLOC(sizeof(char) * len + 1)) != NULL) { strcpy(p, vs->characters); strcat(p, vt->characters); if ((n = (String *) GC_MALLOC(sizeof(struct String_))) != NULL) { n->cls = CLS_STRING; n->characters = p; n->length = len; } else { GC_FREE(p); } } return n; }
String *new_String(const char *s) { String *n; size_t len; char *validatedS; if (s == NULL) { validatedS = (char *) ""; } else { validatedS = (char *) s; } len = strlen(validatedS); n = (String *) GC_MALLOC(sizeof(struct String_)); if (n != NULL) { n->cls = CLS_STRING; n->length = len; n->characters = (char *) GC_MALLOC(sizeof(char) * len + 1); if (n->characters != NULL) { strcpy(n->characters, validatedS); } else { GC_FREE(n); n = NULL; } } return n; }
void ILGCFreePersistent(void *block) { if(block) { GC_FREE(block); } }
stash::~stash() { acquireSpinLock(&list_spinlock); while (slabs != NULL) { slab *p = slabs; slabs = slabs->next; GC_FREE(p); // this dramatically improves our memory usage //printf("removed %p\n", p); } /* assert(stash_list != NULL); if (stash_list == this) stash_list = next; else { for (stash *q = stash_list; q->next != NULL; q = q->next) if (q->next == this) { q->next = next; next = NULL; return; } assert(0); }*/ }
double node_getvalue(NODE* node) { char *tmp; assert(node != NULL); if( func_getvalue[node->nodetype] != NULL ) { return func_getvalue[node->nodetype](node); } switch(node->nodetype) { case N_CONSTANT: return constant_node_getvalue((CONSTANT_NODE*)node); case N_FUNCTION: return function_node_getvalue((FUNCTION_NODE*)node); case N_STOCHASTIC: return stochastic_node_getvalue((STOCHASTIC_NODE*)node); case N_NODE: printf("node_getvalue: can't get value [node type:N_NODE]\n"); break; case N_ARRAY: tmp = node_tostring(node); printf("node_getvalue: can't get value [node type:N_ARRAY] expressoin=%s\n", tmp); GC_FREE(tmp); break; case N_RANGE: printf("node_getvalue: can't get value [node type:N_RANGE]\n"); break; case N_SYMBOL: printf("node_getvalue: can't get value [node type:N_SYMBOL; '%s']\n", symbol_node_tostring((SYMBOL_NODE*)node)); break; } return 0.0; }
void sfree(void* ptr) { #ifndef DONT_USE_GC GC_FREE(ptr); #else free(ptr); #endif }
RUN_TIME_API void MMFreeMisc(void *old, size_t size) { unused(size); GC_FREE(old); }
NODE* nodedic_findnode_byliteral(NODEDIC* dic, char* literal) { // printf("nodedic_findnode_byliteral: begin\n"); int i, n; assert( dic != NULL && literal != NULL ); n = dic->count; for( i = 0 ; i < n ; i++ ) { char *s = symbol_node_tostring(dic->symbols[i]); if( strcmp(s, literal) == 0 ) { GC_FREE(s); return dic->items[i]; } GC_FREE(s); } return NULL; }
void function_node_free(FUNCTION_NODE* fnode) { assert( fnode != NULL ); fnode->node.refcount--; if( fnode->node.refcount <= 0 ) { node_destroy((NODE*)fnode); GC_FREE(fnode); } }
/* Deallocate some heap data */ void triolet_dealloc(TrioletPtr p) { #ifdef CHATTY_ALLOC fprintf(stderr, "Deallocating %p\n", p); #endif #if 1 GC_FREE(p); #endif }
void env_free(ENV* env) { int i, sz; assert( env != NULL ); sz = env->count; for( i = 0 ; i < sz ; i++ ) { GC_FREE(env->names[i]); node_free(env->nodes[i]); } GC_FREE(env->names); GC_FREE(env->nodes); env->names = NULL; env->nodes = NULL; GC_FREE(env); }
void freeHeap(void *mem, size_t n) { #if ALLOC_DEBUG if ( mem ) memset(mem, ALLOC_FREE_MAGIC, n); #endif GC_FREE(mem); }
void env_setsymbol(ENV* env, const char* name, NODE* node) { int i, l, sz; assert(env != NULL); assert(name != NULL); NODE_CHECK(node); l = strlen(name); i= env_getindex(env, name); if( i>= 0 ) { //redefine the environment value NODE* oldnode; if( env->names[i] != NULL ) GC_FREE(env->names[i]); sz = sizeof(char) * (strlen(name)+1); env->names[i] = GC_MALLOC_ATOMIC(sz); assert(env->names[i] != NULL); memcpy(env->names[i], name, sz); env->names[i][sz-1] = '\0'; NODE_CHECK(node); oldnode = env->nodes[i]; env->nodes[i] = node; node_free(oldnode); node->refcount++; } else if( env->count < env->size ) { i = env->count; env->count = env->count + 1; sz = sizeof(char) * (strlen(name)+1); env->names[i] = GC_MALLOC_ATOMIC(sizeof(char) * (strlen(name)+1)); assert(env->names[i] != NULL); memcpy(env->names[i], name, sz); env->names[i][sz-1] = '\0'; NODE_CHECK(node); env->nodes[i] = node; node->refcount++; //char *tmp = node_tostring(node); //printf("env_setsymbol: '%s'(%d) = %s\n", name, strlen(name), tmp); //GC_FREE(tmp); } else { printf("env_setsymbol: buffer overflow.\n"); exit(1); } node->refcount++; }
void nodelist_free(NODELIST* list) { int i; if( list != NULL ) { for( i = 0 ; i < list->count ; i++ ) { node_free(list->items[i]); list->items[i] = NULL; } GC_FREE(list); } }
void chain_free(CHAIN* chain) { int i; for( i = 0 ; i < chain->nchain ;i++ ) { CHAINCORE* core = &chain->core[i]; compiler_free(core->compiler); if( core->monitor_buff != NULL ) { GC_FREE(core->monitor_buff); } } }
void nodedic_free(NODEDIC* dic) { int i; assert(dic!= NULL); for( i = 0 ; i < dic->count ; i++ ) { symbol_node_free(dic->symbols[i]); node_free(dic->items[i]); dic->symbols[i] = NULL; dic->items[i] = NULL; } GC_FREE(dic); }
static dfsch_object_t* regex_substrings(regex_t* regex, char* string, int sub_count, int flags){ regmatch_t *match; int i; int count; dfsch_object_t* vector; match = GC_MALLOC_ATOMIC(sizeof(regmatch_t)*sub_count); if (regexec(regex, string, sub_count, match, flags) == REG_NOMATCH){ GC_FREE(match); return NULL; } count = 0; for (i = 0; i < sub_count; i++){ if (match[i].rm_so == -1) // No more substring matches break; count ++; } vector = dfsch_make_vector(count, NULL); for (i = 0; i < count; i++){ dfsch_vector_set(vector, i, dfsch_vector(3, dfsch_make_number_from_long(match[i].rm_so), dfsch_make_number_from_long(match[i].rm_eo), dfsch_make_string_buf(string+match[i].rm_so, match[i].rm_eo-match[i].rm_so))); } GC_FREE(match); return vector; }
char* dfsch_getcwd(){ char* buf; char* ret; size_t len = pathconf(".", _PC_PATH_MAX); if (len == -1){ len = 65536; // Insane default } buf = GC_MALLOC_ATOMIC(len+1); ret = getcwd(buf, len+1); if (!ret){ int err = errno; GC_FREE(buf); dfsch_operating_system_error_saved(err, "getcwd"); } return ret; }
// greebo: Checks for a named process, modeled loosely after // http://developer.apple.com/library/mac/#qa/qa2001/qa1123.html bool FindProcessByName(const char* processName) { int name[4] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0 }; size_t length = 0; // Call sysctl with a NULL buffer. int err = sysctl(name, 4, NULL, &length, NULL, 0); if (err == -1) { TraceLog::WriteLine(LOG_ERROR, "Failed to receive buffer size for process list."); return false; } GC_INIT(); kinfo_proc* procList = static_cast<kinfo_proc*>(GC_MALLOC(length)); if (procList == NULL) { TraceLog::WriteLine(LOG_ERROR, "Out of Memory trying to allocate process buffer"); return false; } // Load process info sysctl(name, 4, procList, &length, NULL, 0); size_t procCount = length / sizeof(kinfo_proc); bool result = false; for (size_t i = 0; i < procCount; ++i) { //TraceLog::WriteLine(LOG_STANDARD, procList[i].kp_proc.p_comm); if (strcmp(procList[i].kp_proc.p_comm, processName) == 0) { result = true; break; } } GC_FREE(procList); return result; }
void nodelist_add(NODELIST* pnodelist, NODE* pnode) { NODE** pnewitems; NODE** polditems = pnodelist->items; int count = pnodelist->count + 1; pnewitems = (NODE**)GC_MALLOC(sizeof(NODE*) * count); if( polditems != NULL ) { memcpy(pnewitems, polditems, sizeof(NODE*) * (count-1)); GC_FREE(polditems); polditems = NULL; } pnewitems[count-1] = pnode; pnode->refcount++; pnodelist->items = pnewitems; pnodelist->count = count; }
String *sConcatCharArray(const String *s, const char *t) { size_t len; String *n = NULL; char *p; const String *validatedS; char *validatedT; if (s == NULL) { validatedS = new_String(""); } else { validatedS = s; } if (t == NULL) { validatedT = ""; } else { validatedT = (char *) t; } len = sLength(validatedS) + strlen(validatedT); if ((p = (char *) GC_MALLOC(sizeof(char) * len + 1)) != NULL) { strcpy(p, validatedS->characters); strcat(p, validatedT); if ((n = (String *) GC_MALLOC(sizeof(struct String_))) != NULL) { n->cls = CLS_STRING; n->characters = p; n->length = len; } else { GC_FREE(p); } } return n; }
void rvmFreeUncollectable(Env* env, void* m) { GC_FREE(m); }
/* * Repeatedly reverse lists built out of very different sized cons cells. * Check that we didn't lose anything. */ void *GC_CALLBACK reverse_test_inner(void *data) { int i; sexpr b; sexpr c; sexpr d; sexpr e; sexpr *f, *g, *h; if (data == 0) { /* This stack frame is not guaranteed to be scanned. */ return GC_call_with_gc_active(reverse_test_inner, (void*)(word)1); } # if /*defined(MSWIN32) ||*/ defined(MACOS) /* Win32S only allows 128K stacks */ # define BIG 1000 # elif defined(PCR) /* PCR default stack is 100K. Stack frames are up to 120 bytes. */ # define BIG 700 # elif defined(MSWINCE) || defined(RTEMS) /* WinCE only allows 64K stacks */ # define BIG 500 # elif defined(OSF1) /* OSF has limited stack space by default, and large frames. */ # define BIG 200 # elif defined(__MACH__) && defined(__ppc64__) # define BIG 2500 # else # define BIG 4500 # endif A.dummy = 17; a = ints(1, 49); b = ints(1, 50); c = ints(1, BIG); d = uncollectable_ints(1, 100); e = uncollectable_ints(1, 1); /* Check that realloc updates object descriptors correctly */ collectable_count++; f = (sexpr *)GC_MALLOC(4 * sizeof(sexpr)); realloc_count++; f = (sexpr *)GC_REALLOC((void *)f, 6 * sizeof(sexpr)); f[5] = ints(1,17); collectable_count++; g = (sexpr *)GC_MALLOC(513 * sizeof(sexpr)); realloc_count++; g = (sexpr *)GC_REALLOC((void *)g, 800 * sizeof(sexpr)); g[799] = ints(1,18); collectable_count++; h = (sexpr *)GC_MALLOC(1025 * sizeof(sexpr)); realloc_count++; h = (sexpr *)GC_REALLOC((void *)h, 2000 * sizeof(sexpr)); # ifdef GC_GCJ_SUPPORT h[1999] = gcj_ints(1,200); for (i = 0; i < 51; ++i) h[1999] = gcj_reverse(h[1999]); /* Leave it as the reveresed list for now. */ # else h[1999] = ints(1,200); # endif /* Try to force some collections and reuse of small list elements */ for (i = 0; i < 10; i++) { (void)ints(1, BIG); } /* Superficially test interior pointer recognition on stack */ c = (sexpr)((char *)c + sizeof(char *)); d = (sexpr)((char *)d + sizeof(char *)); GC_FREE((void *)e); check_ints(b,1,50); check_ints(a,1,49); for (i = 0; i < 50; i++) { check_ints(b,1,50); b = reverse(reverse(b)); } check_ints(b,1,50); check_ints(a,1,49); for (i = 0; i < 60; i++) { # if defined(GC_PTHREADS) || defined(GC_WIN32_THREADS) if (i % 10 == 0) fork_a_thread(); # endif /* This maintains the invariant that a always points to a list of */ /* 49 integers. Thus this is thread safe without locks, */ /* assuming atomic pointer assignments. */ a = reverse(reverse(a)); # if !defined(AT_END) && !defined(THREADS) /* This is not thread safe, since realloc explicitly deallocates */ if (i & 1) { a = (sexpr)GC_REALLOC((void *)a, 500); } else { a = (sexpr)GC_REALLOC((void *)a, 8200); } # endif } check_ints(a,1,49); check_ints(b,1,50); /* Restore c and d values. */ c = (sexpr)((char *)c - sizeof(char *)); d = (sexpr)((char *)d - sizeof(char *)); check_ints(c,1,BIG); check_uncollectable_ints(d, 1, 100); check_ints(f[5], 1,17); check_ints(g[799], 1,18); # ifdef GC_GCJ_SUPPORT h[1999] = gcj_reverse(h[1999]); # endif check_ints(h[1999], 1,200); # ifndef THREADS a = 0; # endif *(volatile void **)&b = 0; *(volatile void **)&c = 0; return 0; }
void Allocator_free(void *mem) { GC_FREE(mem); }
static void load_thread_info_destroy(void* ptr){ if (ptr){ GC_FREE(ptr); } }
static inline void operator delete[](void *obj) { TRAPCHK(obj); if (obj != NULL) GC_FREE(obj); }
inline static void GC_free2 (void *s, size_t old) { GC_FREE(s); }
void lua_gcobject( lua_State *L ){ void *p; p=lua_touserdata( L,1 ); struct BBObjectContainer * uc = *(struct BBObjectContainer**)p; GC_FREE(uc); }
void xfree(void *ptr) { GC_FREE(ptr); }