void freeoptions(Options *options) { if (!options) return; freemap(options->usernames); freemap(options->groupnames); freecolors(options->colors); free(options); }
File *getfinaltarget(File *file) { Map *linkmap = newmap(); if (!linkmap) { errorf("Out of memory?\n"); return NULL; } File *target = NULL; while (isstat(file) && islink(file)) { target = gettarget(file); if (!target) { errorf("Cannot determine target of %s for %s\n", getname(file)); break; } if (inmap(linkmap, getinode(target))) { errorf("Symlink loop in %s\n", getname(file)); /* no file to stat, but want to print the name field */ target = NULL; break; } else { set(linkmap, (uintmax_t)getinode(target), NULL); } file = target; } freemap(linkmap); return target; }
/* Exm finalization * Remove any left over allocations, but we don't destroy the lock--XXX */ static void exm_finalize () { #if defined(DEBUG) || defined(DEBUG1) syslog (LOG_DEBUG, "finalize READY=%d\n", READY); #endif struct map *m, *tmp; pid_t pid; omp_set_nest_lock (&lock); READY = 0; HASH_ITER (hh, flexmap, m, tmp) { #if defined(DEBUG) || defined(DEBUG1) syslog (LOG_DEBUG, "finalize unmap address %p of size %lu\n", m->addr, (unsigned long int) m->length); #endif munmap (m->addr, m->length); pid = getpid (); if (pid == m->pid) { #if defined(DEBUG) || defined(DEBUG1) syslog (LOG_DEBUG, "finalize unlink %p:%s\n", m->addr, m->path); #endif unlink (m->path); HASH_DEL (flexmap, m); freemap (m); } }
void CWordMatch::freemap(word_map* wordmap) { for(word_map::iterator it = (*wordmap).begin(); it != (*wordmap).end(); ++it) freemap(&(*it).second->next); }
void setmap(SYMBOL * var, SYMBOL * map) { SYMBOL *sym; if (var->name) { sym = getsym(var->name); if (sym) { sym->v.p = freemap(sym->v.p); sym->v.p = map->v.p; } } freemap(var->v.p); var->v.p = NULL; freesym(var); printmap(map); map->v.p = NULL; freesym(map); }
int main(int argc, char* argv[]) { printf("Generating vmap...\n"); FMAP vmap = genmap_sin(.8, 440.0, 0.1, 2.0, 1e-5); printf("Generated.\n"); if (!savemap(vmap, "test")) { printf("Could not save...\n"); return 1; } freemap(vmap); printf("Finished!\n"); return 0; }
void freereqpool(Reqpool *p) { freemap(p->map, (void(*)(void*))p->destroy); free(p); }
/* Main */ int main (int argc, char **argv) { unsigned long long perf; tsp_path_t path; tsp_path_t sol; int sol_len; long long int cuts = 0; struct tsp_queue q; struct timespec t1, t2; /* lire les arguments */ int opt; while ((opt = getopt(argc, argv, "s")) != -1) { switch (opt) { case 's': affiche_sol = true; break; default: usage(argv[0]); break; } } if (optind != argc-3) usage(argv[0]); nb_towns = atoi(argv[optind]); myseed = atol(argv[optind+1]); nb_threads = atoi(argv[optind+2]); assert(nb_towns > 0); assert(nb_threads > 0); minimum = INT_MAX; /* generer la carte et la matrice de distance */ fprintf (stderr, "ncities = %3d\n", nb_towns); genmap (); init_queue (&q); clock_gettime (CLOCK_REALTIME, &t1); memset (path, -1, MAX_TOWNS * sizeof (int)); path[0] = 0; /* mettre les travaux dans la file d'attente */ generate_tsp_jobs (&q, 1, 0, path, &cuts, sol, & sol_len, 3); no_more_jobs (&q); /* calculer chacun des travaux */ tsp_path_t solution; memset (solution, -1, MAX_TOWNS * sizeof (int)); solution[0] = 0; ThreadCell* list = NULL; ThreadCell* cur = NULL; for (int i = 0; i < nb_threads; i++) { ThreadCell* cell = (ThreadCell*) malloc(sizeof(ThreadCell)); cell->next = NULL; WorkerArgs* args = (WorkerArgs*) malloc(sizeof(WorkerArgs)); args->q = &q; memcpy(args->solution, solution, sizeof(tsp_path_t)); args->cuts = &cuts; memcpy(args->sol, sol, sizeof(tsp_path_t)); args->sol_len = &sol_len; pthread_create(&(cell->tid), NULL, tsp_worker, (void*) args); if (!list) { list = cell; cur = list; } else { cur->next = cell; cur = cur->next; } } void * status; while (list != NULL) { pthread_join(list->tid, &status); if (status == PTHREAD_CANCELED) { printf("Thread cancelled"); exit(EXIT_FAILURE); } ThreadCell* tmp = list; list = list->next; free(tmp); } clock_gettime (CLOCK_REALTIME, &t2); if (affiche_sol) print_solution_svg (sol, sol_len); perf = TIME_DIFF (t1,t2); printf("<!-- # = %d seed = %ld len = %d threads = %d time = %lld.%03lld ms ( %lld coupures ) -->\n", nb_towns, myseed, sol_len, nb_threads, perf/1000000ll, perf%1000000ll, cuts); freemap(); return 0 ; }
/* * Write an ELF coredump for the given pid to the given fd. */ void elf_coredump(int fd, pid_t pid) { vm_map_entry_t map; struct sseg_closure seginfo; void *hdr; size_t hdrsize; char memname[64]; int memfd; Elf_Phdr *php; int i; /* Get the program's memory map. */ map = readmap(pid); /* Size the program segments. */ seginfo.count = 0; seginfo.size = 0; each_writable_segment(map, cb_size_segment, &seginfo); /* * Calculate the size of the core file header area by making * a dry run of generating it. Nothing is written, but the * size is calculated. */ hdrsize = 0; elf_puthdr(map, NULL, &hdrsize, NULL, NULL, NULL, seginfo.count); /* * Allocate memory for building the header, fill it up, * and write it out. */ hdr = malloc(hdrsize); if ((hdr = malloc(hdrsize)) == NULL) errx(1, "out of memory"); elf_corehdr(fd, pid, map, seginfo.count, hdr, hdrsize); /* Write the contents of all of the writable segments. */ snprintf(memname, sizeof memname, "/proc/%d/mem", pid); if ((memfd = open(memname, O_RDONLY)) == -1) err(1, "cannot open %s", memname); php = (Elf_Phdr *)((char *)hdr + sizeof(Elf_Ehdr)) + 1; for (i = 0; i < seginfo.count; i++) { int nleft = php->p_filesz; lseek(memfd, (off_t)php->p_vaddr, SEEK_SET); while (nleft > 0) { char buf[8*1024]; int nwant; int ngot; nwant = nleft; if (nwant > sizeof buf) nwant = sizeof buf; ngot = read(memfd, buf, nwant); if (ngot == -1) err(1, "read from %s", memname); if (ngot < nwant) errx(1, "short read from %s:" " wanted %d, got %d\n", memname, nwant, ngot); ngot = write(fd, buf, nwant); if (ngot == -1) err(1, "write of segment %d failed", i); if (ngot != nwant) errx(1, "short write"); nleft -= nwant; } php++; } close(memfd); free(hdr); freemap(map); }
CWordMatch::~CWordMatch() { freemap(&wordmap.next); }
PyObject * main_python(PyObject *self, PyObject *args) { static double glyphptsize = STDPAGE_GLYPH_PTSIZE; static opt_Option opt[] = { {"-u", opt_Call, showUsage}, {"-h", opt_Call, showHelp}, {"-ht", opt_Call, sfntTableSpecificUsage}, {"-l", opt_Flag}, {"-O", opt_Flag}, {"-r", opt_Flag}, {"-n", opt_Flag}, {"-nc", opt_Flag}, {"-T", opt_Flag}, {"-F", opt_Flag}, {"-f", opt_Flag}, {"-G", opt_Flag}, {"-V", opt_Flag}, {"-m", opt_Flag}, {"-d", opt_Flag}, {"-br", opt_Flag}, {"-i", resIdScan}, {"-o", sfntTTCScan}, {"-t", sfntTagScan}, {"-P", sfntFeatScan}, {"-A", sfntFeatScan}, {"-p", proofPolicyScan}, {"-a", opt_Flag}, {"-R", opt_Flag}, {"-c", opt_Flag}, {"-g", glyfGlyphScan}, {"-b", glyfBBoxScan}, {"-s", glyfScaleScan}, {"-@", opt_Double, &glyphptsize}, {"-C", opt_Int, &cmapSelected}, #if AUTOSCRIPT {"-X", opt_String, scriptfilename}, #endif {"-ag", opt_String, &glyphaliasfilename}, {"-of", opt_String, &outputfilebase}, }; char **argv, **argfree; int strIndex, argc, argtotal, tries; char * argString, *outfilename; IntX files; IntN argi; Byte8 *filename = NULL; Card32 value; int i = 0; #if AUTOSCRIPT cmdlinetype *cmdl; Byte8 foundXswitch = 0; #endif IntN status; #ifdef SUNOS { /* To allow gdb to attach to process */ char* do_debug_sleep; do_debug_sleep = getenv("STOP_OTFPROOF_FOR_GDB"); while (do_debug_sleep != NULL) sleep(1); } #endif /* Resetting globals*/ gcr.reportNumber=0; aliasfromfileinit = 0; /* freopen("OTFProof.std.log", "w", stdout);*/ value = setjmp(mark); if(value==-1){ PyErr_SetString(ErrorObject, "Fatal Error"); if (PyOutFile != NULL) { fclose(PyOutFile); PyOutFile = NULL; } freemap(); return NULL; } if(!PyArg_ParseTuple(args, "ss", &argString, &outfilename)){ freemap(); return NULL; } if (PyOutFile == NULL) PyOutFile = fopen(outfilename, "w"); else PyOutFile = freopen(outfilename, "w", PyOutFile); VORGfound=0; strIndex=0; argfree= (char **) memNew(MAX_ARGS*sizeof(char *)); argv=(char **) memNew(MAX_ARGS*sizeof(char *)); for(i=0; i<MAX_ARGS; i++){ argfree[i]=argv[i]=NextToken(argString, &strIndex); if(argv[i]==NULL) { argtotal=argc=i; break; }else{ /*fprintf(OUTPUTBUFF, ">>%s<<\n", argv[i]);*/ } } status = setjmp(global.env); if (status) { #if AUTOSCRIPT if (global.doingScripting) { goto scriptAbEnd; } else #endif if(status==2){ PyErr_SetString(ErrorObject, "Fatal Error"); if (PyOutFile != NULL) { fclose(PyOutFile); PyOutFile = NULL; } freemap(); argFree(argfree, argv); return NULL; }else{ if (PyOutFile != NULL) { fclose(PyOutFile); PyOutFile = NULL; } freemap(); argFree(argfree, argv); return Py_None; } } da_SetMemFuncs(memNew, memResize, memFree); global.progname = "OTFproof"; #if AUTOSCRIPT scriptfilename[0]='\0'; for (i = 0; i < argc; i++) { if (strcmp(argv[i], "-X") == 0) { if ((argv[i+1] != NULL) && (argv[i+1][0] != '\0')) { strcpy(scriptfilename, argv[i+1]); foundXswitch = 1; } break; } } #endif proofResetPolicies(); argi = opt_Scan(argc, argv, opt_NOPTS(opt), opt, NULL, NULL); if (opt_hasError()) { if (PyOutFile != NULL) { fclose(PyOutFile); PyOutFile = NULL; } freemap(); argFree(argfree, argv); return Py_None; } if (opt_Present("-@")) proofSetGlyphSize(glyphptsize); if (opt_Present("-V")) /* equivalent to "-p6" */ proofSetPolicy(6, 1); files = argc - argi; for (; argi < argc; argi++) { filename = argv[argi]; fileOpen(filename); if (!fileIsOpened()) { warning(SPOT_MSG_BADFILE, filename); fileClose(); continue; } /* fprintf(OUTPUTBUFF, "\nProofing %s.\n", filename); */ tries = 0; /* See if we can recognize the file type */ value = fileSniff(); switch (value) { case bits_: case typ1_: case true_: case mor0_: case OTTO_: case VERSION(1,0): sfntRead(0, -1); /* Read plain sfnt file */ sfntDump(); sfntFree(1); break; case ttcf_: sfntTTCRead(0); /* Read TTC file */ continue; break; case 256: SEEK_ABS(0); /* Raw resource file as a data fork */ resRead(0); /* Read and dump Macintosh resource file */ continue; break; case sig_AppleSingle: case sig_AppleDouble: doASDFormats((ctlTag)value); break; default: warning(SPOT_MSG_BADFILE, filename); fileClose(); continue; } fileClose(); freemap(); argFree(argfree, argv); #if MEMCHECK memReport(); #endif fclose(PyOutFile); PyOutFile = NULL; return Py_None; } #if AUTOSCRIPT execscript: { char * end; end=strrchr(scriptfilename, '\\'); if(end==NULL) sourcepath=""; else{ char *scurr = scriptfilename; char *dcurr; sourcepath=(char *)memNew(strlen(scriptfilename)); dcurr = sourcepath; while(scurr!=end) { *dcurr++=*scurr++; } *dcurr=0; } } for (i = 0; i < script.cmdline.cnt ; i++) { char * tempfilename; cmdl = da_INDEX(script.cmdline, i); if (cmdl->args.cnt < 2) continue; proofResetPolicies(); { IntX a; inform(SPOT_MSG_EOLN); message(SPOT_MSG_ECHOSCRIPTCMD); for (a = 1; a < cmdl->args.cnt; a++) { inform(SPOT_MSG_RAWSTRING, cmdl->args.array[a]); } inform(SPOT_MSG_EOLN); } argi = opt_Scan(cmdl->args.cnt, cmdl->args.array, opt_NOPTS(opt), opt, NULL, NULL); if (opt_hasError()) { if (PyOutFile != NULL) { fclose(PyOutFile); PyOutFile = NULL; } freemap(); argFree(argfree, argv); return Py_None; } if (opt_Present("-@")) proofSetGlyphSize(glyphptsize); if (opt_Present("-V")) /* equivalent to "-p6" */ proofSetPolicy(6, 1); tempfilename = MakeFullPath(cmdl->args.array[cmdl->args.cnt-1]); if (fileExists(tempfilename) ) { /* (new) font filename on cmdline */ memFree(tempfilename); if (filename != NULL) /* not first time */ { fileClose(); /* previous font file */ sfntFree(1); } if(sourcepath[0]!='\0') filename=MakeFullPath(cmdl->args.array[cmdl->args.cnt-1]); else filename = cmdl->args.array[cmdl->args.cnt-1]; fileOpen(filename); tries=0; retry: /* See if we can recognize the file type */ value = fileSniff(); switch (value) { case bits_: case typ1_: case true_: case mor0_: case OTTO_: case VERSION(1,0): sfntRead(0, -1); /* Read plain sfnt file */ break; case ttcf_: sfntTTCRead(0); /* Read TTC file */ continue; break; case 256: resRead(0); /* Read Macintosh resource file */ continue; break; default: warning(SPOT_MSG_BADFILE, filename); fileClose(); continue; } } else { /* none specified */ fatal(SPOT_MSG_MISSINGFILENAME); memFree(tempfilename); continue; } sfntDump(); scriptAbEnd: sfntFree(1); fileClose(); } global.doingScripting = 0; #endif /*fprintf(stderr, "\nDone.\n");*/ fileClose(); freemap(); argFree(argfree, argv); #if MEMCHECK memReport(); #endif fclose(PyOutFile); PyOutFile = NULL; return Py_None; }
PyObject * proof_complement(PyObject *self, PyObject *args) { static double glyphptsize = STDPAGE_GLYPH_PTSIZE; static opt_Option opt[] = { {"-u", opt_Call, showUsage}, {"-h", opt_Call, showHelp}, {"-ht", opt_Call, sfntTableSpecificUsage}, {"-l", opt_Flag}, {"-O", opt_Flag}, {"-r", opt_Flag}, {"-n", opt_Flag}, {"-nc", opt_Flag}, {"-T", opt_Flag}, {"-F", opt_Flag}, {"-G", opt_Flag}, {"-V", opt_Flag}, {"-m", opt_Flag}, {"-d", opt_Flag}, {"-br", opt_Flag}, {"-i", resIdScan}, {"-o", sfntTTCScan}, {"-t", sfntTagScan}, {"-P", sfntFeatScan}, {"-A", sfntFeatScan}, {"-p", proofPolicyScan}, {"-a", opt_Flag}, {"-R", opt_Flag}, {"-c", opt_Flag}, {"-g", glyfGlyphScan}, {"-b", glyfBBoxScan}, {"-s", glyfScaleScan}, {"-@", opt_Double, &glyphptsize}, {"-C", opt_Int, &cmapSelected}, }; IntN argi; Card32 value; char *outfilename; char *infilenameorig; IntN status; char *argv[30]; int argc; int startIndex=0; int infilesSize; int useStdOut = 0; int i; { /* To allow gdb to attach to process */ char* do_debug_sleep; do_debug_sleep = getenv("STOP_GLYPH_PROOFER"); while (do_debug_sleep != NULL) sleep(1); } value = setjmp(mark); if(value==-1){ PyErr_SetString(ErrorObject, "Fatal Error"); if (PyOutFile != NULL) { fclose(PyOutFile); PyOutFile = NULL; } freemap(); return NULL; } if(!PyArg_ParseTuple(args, "s#iisiii", &infilename, &infilesSize, &(gcr.synOnly), &(gcr.numFonts), &outfilename, &(gcr.maxNumGlyphs), &(gcr.byname), &useStdOut)){ freemap(); return NULL; } if (PyOutFile != NULL) freopen(outfilename, "w", PyOutFile); else PyOutFile = fopen(outfilename, "w"); infilenameorig=infilename; gcr.reportNumber=0; gcr.startGlyph=0; gcr.numGlyphs=2; gcr.endGlyph=1; VORGfound=0; status = setjmp(global.env); if (status) { if(status==2){ PyErr_SetString(ErrorObject, "Fatal Error"); if (PyOutFile != NULL) { fclose(PyOutFile); PyOutFile = NULL; } freemap(); return NULL; }else{ if (PyOutFile != NULL) { fclose(PyOutFile); PyOutFile = NULL; } freemap(); return Py_None; } } da_SetMemFuncs(memNew, memResize, memFree); global.progname = "Glyph_Proofer"; outputfilebase = "glyphproofer"; fprintf(OUTPUTBUFF, "%s-library v.%s\n\n", global.progname, libversion); while(gcr.endGlyph!=0 && gcr.endGlyph<gcr.numGlyphs) { int newstart=gcr.endGlyph; infilename=infilenameorig; if (newstart==1) newstart=0; /*fprintf(stderr, "Starting again with %d of %d\n", gcr.endGlyph, gcr.numGlyphs);*/ gcr.endGlyph=0; for (i=0; i<gcr.numFonts; i++) { gcr.startGlyph=newstart; /*fprintf(OUTPUTBUFF, "Processing %s\n", infilename);*/ argc = 0; argv[argc++]=global.progname; if (useStdOut) argv[argc++]="-O"; argv[argc++]="-tCFF_=9"; argv[argc++]="-d"; argv[argc++]="-l"; argv[argc++]=infilename; argi = opt_Scan(argc, argv, opt_NOPTS(opt), opt, NULL, NULL); if (opt_hasError()) { if (PyOutFile != NULL) { fclose(PyOutFile); PyOutFile = NULL; } freemap(); return NULL; } fileOpen(infilename); if (!fileIsOpened()) { warning(SPOT_MSG_BADFILE, infilename); fileClose(); if (PyOutFile != NULL) { fclose(PyOutFile); PyOutFile = NULL; } freemap(); return NULL; }else{ /* See if we can recognize the file type */ value = fileSniff(); switch (value) { case bits_: case typ1_: case true_: case mor0_: case OTTO_: case VERSION(1,0): sfntRead(0, -1); /* Read plain sfnt file */ sfntDump(); sfntFree(1); break; case ttcf_: sfntTTCRead(0); /* Read TTC file */ break; case 256: SEEK_ABS(0); /* Raw resource file as a data fork */ resRead(0); /* Read and dump Macintosh resource file */ break; default: warning(SPOT_MSG_BADFILE, infilename); PyErr_SetString(ErrorObject, "Fatal Error: Not a valid font file"); fileClose(); if (PyOutFile != NULL) { fclose(PyOutFile); PyOutFile = NULL; } freemap(); return NULL; } fileClose(); } while(*infilename) infilename++; infilename++; /*Gets us past the next NULL character*/ } } CFF_SynopsisFinish(); fclose(PyOutFile); PyOutFile = NULL; freemap(); return Py_None; }