exit(qh_ERRnone); } qh_init_A(stdin, stdout, stderr, argc, argv); /* sets qh qhull_command */ exitcode= setjmp(qh errexit); /* simple statement for CRAY J916 */ if (!exitcode) { qh_option("Halfspace", NULL, NULL); qh HALFspace= True; /* 'H' */ qh_checkflags(qh qhull_command, hidden_options); qh_initflags(qh qhull_command); if (qh SCALEinput) { fprintf(qh ferr, "\ qhull error: options 'Qbk:n' and 'QBk:n' are not used with qhalf.\n\ Use 'Qbk:0Bk:0 to drop dimension k.\n"); qh_errexit(qh_ERRinput, NULL, NULL); } points= qh_readpoints(&numpoints, &dim, &ismalloc); if (dim >= 5) { qh_option("Qxact_merge", NULL, NULL); qh MERGEexact= True; /* 'Qx' always */ } qh_init_B(points, numpoints, dim, ismalloc); qh_qhull(); qh_check_output(); qh_produce_output(); if (qh VERIFYoutput && !qh FORCEoutput && !qh STOPpoint && !qh STOPcone) qh_check_points(); exitcode= qh_ERRnone; } qh NOerrexit= True; /* no more setjmp */ #ifdef qh_NOmem qh_freeqhull( True);
static PyObject* py_qconvex(PyObject *self, PyObject *args) { const char *arg; const char *data; int curlong, totlong; /* used !qh_NOmem */ int exitcode, numpoints, dim; coordT *points; boolT ismalloc; char* argv[10]; int argc = 1; char *rest; char *token; /* Defensively copy the string first */ char tempstr[30]; char* ptr; char *bp; size_t size; FILE* fin; FILE* fout; if (!PyArg_ParseTuple(args, "ss", &arg, &data)) return NULL; strcpy(tempstr, arg); ptr = tempstr; while(token = strtok_r(ptr, " ", &rest)) { argv[argc] = token; ptr = rest; argc += 1; } argv[0] = "qconvex"; /* Because qhull uses stdin and stdout streams for io, we need to create FILE* stream to simulate these io streams.*/ fin = fmemopen(data, strlen(data), "r"); fout = open_memstream(&bp, &size); if ((fin != NULL) && (fout != NULL)) { /* Now do the usual qhull code (modified from qconvex.c). */ qh_init_A(fin, fout, stderr, argc, argv); exitcode= setjmp(qh errexit); if (!exitcode) { qh_checkflags(qh qhull_command, hidden_options); qh_initflags(qh qhull_command); points= qh_readpoints(&numpoints, &dim, &ismalloc); if (dim >= 5) { qh_option("Qxact_merge", NULL, NULL); qh MERGEexact= True; } qh_init_B(points, numpoints, dim, ismalloc); qh_qhull(); qh_check_output(); qh_produce_output(); if (qh VERIFYoutput && !qh FORCEoutput && !qh STOPpoint && !qh STOPcone) qh_check_points(); exitcode= qh_ERRnone; } qh NOerrexit= True; /* no more setjmp */ #ifdef qh_NOmem qh_freeqhull( True); #else qh_freeqhull( False); qh_memfreeshort(&curlong, &totlong); if (curlong || totlong) fprintf(stderr, "qhull internal warning (main): did not free %d bytes of long memory(%d pieces)\n", totlong, curlong); #endif fclose(fin); fclose(fout); return Py_BuildValue("s", bp); } else { return NULL; } }