/************************************************************************** v m D e l e t e ** Free all memory allocated to the specified VM and its subordinate ** structures. **************************************************************************/ void vmDelete (FICL_VM *pVM) { if (pVM) { ficlFree(pVM->pStack); ficlFree(pVM->rStack); #if FICL_WANT_FLOAT ficlFree(pVM->fStack); #endif ficlFree(pVM); } return; }
void ficlUnsetenv(FICL_VM *pVM) { #ifndef TESTMAIN char *name; #endif char *namep; int names; #if FICL_ROBUST > 1 vmCheckStack(pVM, 2, 0); #endif names = stackPopINT(pVM->pStack); namep = (char*) stackPopPtr(pVM->pStack); #ifndef TESTMAIN name = (char*) ficlMalloc(names+1); if (!name) vmThrowErr(pVM, "Error: out of memory"); strncpy(name, namep, names); name[names] = '\0'; unsetenv(name); ficlFree(name); #endif return; }
void ficlGetenv(FICL_VM *pVM) { #ifndef TESTMAIN char *name; #endif char *namep, *value; int names; #if FICL_ROBUST > 1 vmCheckStack(pVM, 2, 2); #endif names = stackPopINT(pVM->pStack); namep = (char*) stackPopPtr(pVM->pStack); #ifndef TESTMAIN name = (char*) ficlMalloc(names+1); if (!name) vmThrowErr(pVM, "Error: out of memory"); strncpy(name, namep, names); name[names] = '\0'; value = getenv(name); ficlFree(name); if(value != NULL) { stackPushPtr(pVM->pStack, value); stackPushINT(pVM->pStack, strlen(value)); } else #endif stackPushINT(pVM->pStack, -1); return; }
/************************************************************************** f i c l T e r m S y s t e m ** Tear the system down by deleting the dictionaries and all VMs. ** This saves you from having to keep track of all that stuff. **************************************************************************/ void ficlSystemDestroy(ficlSystem *system) { if (system->dictionary) ficlDictionaryDestroy(system->dictionary); system->dictionary = NULL; if (system->environment) ficlDictionaryDestroy(system->environment); system->environment = NULL; #if FICL_WANT_LOCALS if (system->locals) ficlDictionaryDestroy(system->locals); system->locals = NULL; #endif while (system->vmList != NULL) { ficlVm *vm = system->vmList; system->vmList = system->vmList->link; ficlVmDestroy(vm); } ficlFree(system); system = NULL; if (ficlSystemGlobal == system) ficlSystemGlobal = NULL; return; }
/************************************************************************** f i c l T e r m S y s t e m ** Tear the system down by deleting the dictionaries and all VMs. ** This saves you from having to keep track of all that stuff. **************************************************************************/ void ficlTermSystem(FICL_SYSTEM *pSys) { if (pSys->dp) dictDelete(pSys->dp); pSys->dp = NULL; if (pSys->envp) dictDelete(pSys->envp); pSys->envp = NULL; #if FICL_WANT_LOCALS if (pSys->localp) dictDelete(pSys->localp); pSys->localp = NULL; #endif while (pSys->vmList != NULL) { FICL_VM *pVM = pSys->vmList; pSys->vmList = pSys->vmList->link; vmDelete(pVM); } ficlFree(pSys); pSys = NULL; return; }
void ficlUuidFromString(FICL_VM *pVM) { #ifndef TESTMAIN char *uuid; uint32_t status; #endif char *uuidp; int uuids; uuid_t *u; #if FICL_ROBUST > 1 vmCheckStack(pVM, 2, 0); #endif uuids = stackPopINT(pVM->pStack); uuidp = (char *) stackPopPtr(pVM->pStack); #ifndef TESTMAIN uuid = (char *)ficlMalloc(uuids + 1); if (!uuid) vmThrowErr(pVM, "Error: out of memory"); strncpy(uuid, uuidp, uuids); uuid[uuids] = '\0'; u = (uuid_t *)ficlMalloc(sizeof (*u)); uuid_from_string(uuid, u, &status); ficlFree(uuid); if (status != uuid_s_ok) { ficlFree(u); u = NULL; } #else u = NULL; #endif stackPushPtr(pVM->pStack, u); return; }
void ficlSetenvq(FICL_VM *pVM) { #ifndef TESTMAIN char *name, *value; #endif char *namep, *valuep; int names, values, overwrite; #if FICL_ROBUST > 1 vmCheckStack(pVM, 5, 0); #endif overwrite = stackPopINT(pVM->pStack); names = stackPopINT(pVM->pStack); namep = (char*) stackPopPtr(pVM->pStack); values = stackPopINT(pVM->pStack); valuep = (char*) stackPopPtr(pVM->pStack); #ifndef TESTMAIN name = (char*) ficlMalloc(names+1); if (!name) vmThrowErr(pVM, "Error: out of memory"); strncpy(name, namep, names); name[names] = '\0'; value = (char*) ficlMalloc(values+1); if (!value) vmThrowErr(pVM, "Error: out of memory"); strncpy(value, valuep, values); value[values] = '\0'; setenv(name, value, overwrite); ficlFree(name); ficlFree(value); #endif return; }
void stackDelete(FICL_STACK *pStack) { if (pStack) ficlFree(pStack); return; }
/* * d i c t D e l e t e * Free all memory allocated for the given dictionary */ void ficlDictionaryDestroy(ficlDictionary *dictionary) { FICL_DICTIONARY_ASSERT(dictionary, dictionary != NULL); ficlFree(dictionary); }
/************************************************************************** d i c t D e l e t e ** Free all memory allocated for the given dictionary **************************************************************************/ void dictDelete(FICL_DICT *pDict) { assert(pDict); ficlFree(pDict); return; }