void luaS_resize (lua_State *L, int newsize) { GCObject **newhash; stringtable *tb; int i; if (G(L)->gcstate == GCSsweepstring) return; /* cannot resize during GC traverse */ newhash = luaM_newvector(L, newsize, GCObject *); tb = &G(L)->strt; for (i=0; i<newsize; i++) newhash[i] = NULL; /* rehash */ for (i=0; i<tb->size; i++) { GCObject *p = tb->hash[i]; while (p) { /* for each node in the list */ GCObject *next = p->gch.next; /* save next */ unsigned int h = gco2ts(p)->hash; int h1 = lmod(h, newsize); /* new position */ lua_assert(cast_int(h%newsize) == lmod(h, newsize)); p->gch.next = newhash[h1]; /* chain it */ newhash[h1] = p; p = next; } } luaM_freearray(L, tb->hash, tb->size, TString *); tb->size = newsize; tb->hash = newhash; }
int libgncmod_gnome_utils_gnc_module_init(int refcount) { /* load the engine (we depend on it) */ if (!gnc_module_load("gnucash/engine", 0)) { return FALSE; } if (!gnc_module_load("gnucash/app-utils", 0)) { return FALSE; } scm_init_sw_gnome_utils_module(); lmod("(sw_gnome_utils)"); lmod("(gnucash gnome-utils)"); /* Initialize the options-ui database */ if (refcount == 0) { gnc_options_ui_initialize (); } return TRUE; }
int libgncmod_tax_us_gnc_module_init(int refcount) { /* This is a very simple hack that loads the (new, special) German tax definition file in a German locale, or (default) loads the US tax file. */ # ifdef G_OS_WIN32 gchar *thislocale = g_win32_getlocale(); gboolean is_de_DE = (strncmp(thislocale, "de_DE", 5) == 0); g_free(thislocale); # else /* !G_OS_WIN32 */ const char *thislocale = setlocale(LC_ALL, NULL); gboolean is_de_DE = (strncmp(thislocale, "de_DE", 5) == 0); # endif /* G_OS_WIN32 */ if (is_de_DE) lmod("(gnucash tax de_DE)"); else lmod("(gnucash tax us)"); return TRUE; }
int libgncmod_app_utils_gnc_module_init(int refcount) { /* load the engine (we depend on it) */ if (!gnc_module_load("gnucash/engine", 0)) { return FALSE; } scm_init_sw_app_utils_module(); /* publish swig bindings */ /* load the scheme code */ lmod("(sw_app_utils)"); lmod("(gnucash app-utils)"); if (refcount == 0) { gnc_component_manager_init (); gnc_hook_add_dangler(HOOK_STARTUP, (GFunc)gnc_exp_parser_init, NULL); gnc_hook_add_dangler(HOOK_SHUTDOWN, (GFunc)app_utils_shutdown, NULL); } return TRUE; }
static TString *newlstr (lua_State *L, const char *str, size_t l, unsigned int h) { TString *ts; stringtable *tb; if (l+1 > (MAX_SIZET - sizeof(TString))/sizeof(char)) luaM_toobig(L); ts = cast(TString *, luaM_malloc(L, (l+1)*sizeof(char)+sizeof(TString))); ts->tsv.len = l; ts->tsv.hash = h; ts->tsv.marked = luaC_white(G(L)); ts->tsv.tt = LUA_TSTRING; ts->tsv.reserved = 0; memcpy(ts+1, str, l*sizeof(char)); ((char *)(ts+1))[l] = '\0'; /* ending 0 */ tb = &G(L)->strt; h = lmod(h, tb->size); ts->tsv.next = tb->hash[h]; /* chain new entry */ tb->hash[h] = obj2gco(ts); tb->nuse++; if (tb->nuse > cast(lu_int32, tb->size) && tb->size <= MAX_INT/2) luaS_resize(L, tb->size*2); /* too crowded */ return ts; }