int main() { Hash *h = HashCreateN(1024); HashSet(h, (String) { "abc", 3 }, "def"); printf("%s\n", (char*) HashGet(h, (String) { GC_STRDUP("abc"), 3 })); }
int module_import0(module_t *Module, const char *Symbol, int *IsRef, void **Data) { //pthread_t Thread = pthread_self(); //printf("<thread @ %x> Entering module_import0:%d(%s, %s)\n", Thread, __LINE__, Module->Name, Symbol); pthread_mutex_lock(Module->Lock); export_t *Export = stringtable_get(Module->Symbols, Symbol); if (Export) { *IsRef = Export->IsRef; *Data = Export->Data; pthread_mutex_unlock(Module->Lock); //printf("<thread @ %x> Leaving module_import0:%d(%s, %s)\n", Thread, __LINE__, Module->Name, Symbol); return 1; }; Symbol = GC_STRDUP(Symbol); for (module_provider_t *Provider = Module->Providers; Provider; Provider = Provider->Next) { if (!Provider->HasImports) continue; if (Provider->ImportFunc == directory_import) continue; if (Provider->ImportFunc(Provider->ImportInfo, Symbol, IsRef, Data)) { export_t *Export = new(export_t); Export->IsRef = *IsRef; Export->Data = *Data; stringtable_put(Module->Symbols, Symbol, Export); pthread_mutex_unlock(Module->Lock); //printf("<thread @ %x> Leaving module_import0:%d(%s, %s)\n", Thread, __LINE__, Module->Name, Symbol); return 1; }; }; pthread_mutex_unlock(Module->Lock); //printf("<thread @ %x> Leaving module_import0:%d(%s, %s)\n", Thread, __LINE__, Module->Name, Symbol); return 0; };
/* create a new, empty production with the given name */ static struct Production *newProduction(const unsigned char *name) { struct Production *ret = GC_NEW(struct Production); ret->name = (unsigned char *) GC_STRDUP((char *) name); return ret; }
/* remove all productions with the given name */ void delProduction(const unsigned char *name) { /* find the relevant production */ struct Production *curp = getProduction(name), *curp_left = curp->left, *curp_right = curp->right; /* and blank it */ memset(curp, 0, sizeof(struct Production)); curp->name = (unsigned char *) GC_STRDUP((char *) name); curp->left = curp_left; curp->right = curp_right; }
XftColor *ColorGetXftColor(const char *name) { for (int i = 0; i < num_xft_colors; i++) { if (strcmp(xft_color_table[i].name, name) == 0) { return &xft_color_table[i].color; } } if (num_xft_colors == MAX_COLORS) { fprintf(stderr, "color table full"); exit(1); } xft_color_table[num_xft_colors].name = GC_STRDUP(name); XftColorAllocName(disp, visual, colormap, name, &xft_color_table[num_xft_colors].color); return &xft_color_table[num_xft_colors++].color; }
void * entry (void *arg) { pthread_setspecific(key, (void *)GC_HIDE_POINTER(GC_STRDUP("hello, world"))); return arg; }