void freeReferenceList(ObjectNode *objList) { if (objList != NULL) { freeObject(objList->object); freeReferenceList(objList->next); objList = NULL; } }
void regenerate_geometry() { int subdivs; subdivs = 1 << (tessellation); /* Free previous object */ if (object) freeObject(object); //printf("Generating %ix%i... ", subdivs, subdivs); fflush(stdout); if (renderstate.shaders) { object = createObject(parametricGrid, subdivs + 1, subdivs + 1); } else { switch (renderstate.object) { case TORUS: object = createObject(parametricTorus, subdivs + 1, subdivs + 1, 1.0, 0.5); break; default: assert(renderstate.object == WAVE); object = createObject(parametricWave, subdivs + 1, subdivs + 1, 2.0, 2.0, time_s); } } //printf("done.\n"); fflush(stdout); }
extern void * realloc(void *ptr, size_t size) { pthread_mutex_lock(&mutex); increaseReallocCalls(); // Allocate new object void * newptr = allocateObject( size ); // Copy old object only if ptr != 0 if ( ptr != 0 ) { // copy only the minimum number of bytes size_t sizeToCopy = objectSize( ptr ); if ( sizeToCopy > size ) { sizeToCopy = size; } memcpy( newptr, ptr, sizeToCopy ); // Free old object freeObject( ptr ); } return newptr; }
void cleanSymTab(void) { freeObject(symtab->program); freeObjectList(symtab->globalObjectList); free(symtab); freeType(intType); freeType(charType); }
/* obj_freeObjects Free all loaded objects. */ void obj_freeObjects(void) { extern ObjContainer the_objects; int l, x, y; /* In case there are any stray objects that were created but not put into the object container, put them in now: */ obj_handleSignals(); /* Loop through all of the layers */ for (l = 0; l < the_objects.n_layers; l++) { /* Loop through all the sectors */ for (x = 0; x < the_objects.layers[l].w; x++) { for (y = 0; y < the_objects.layers[l].h; y++) { //free all of the objects in this sector while (OBJ_AT(l, x, y) != NULL) { freeObject(OBJ_AT(l, x, y)); } } } /* Free the layer */ dyn_arrayFree ((void **) the_objects.layers[l].obj_array, the_objects.layers[l].w); } /* Free the array of layers */ dyn_1dArrayFree(the_objects.layers); }
void cleanup() { /* Delete the shader */ glDeleteProgram(shader); /* Free object data */ if (object) freeObject(object); }
static status unlinkView(View v) { Editor e = v->editor; unlinkWindow((PceWindow) v); assign(v, editor, NIL); freeObject(e); succeed; }
void freeObjectList(ObjectNode *objList) { ObjectNode* list = objList; while (list != NULL) { ObjectNode* node = list; list = list->next; freeObject(node->object); free(node); } }
static Area getIntersectionArea(Area a, Area b) { Area c; c = answerObject(ClassArea, a->x, a->y, a->w, a->h, EAV); if ( intersectionArea(c, b) ) answer(c); freeObject(c); fail; }
extern void free(void *ptr) { pthread_mutex_lock(&mutex); increaseFreeCalls(); if ( ptr == 0 ) { // No object to free pthread_mutex_unlock(&mutex); return; } freeObject( ptr ); }
/** * Remove a PKCS11 object from a linked list of objects * The object is removed and allocated memory freed * * @param list address of the pointer to the first entry in the list * @param handle the handle of the object to be removed * @return CKR_OK or CKR_OBJECT_HANDLE_INVALID */ int removeObjectFromList(struct p11Object_t **list, CK_OBJECT_HANDLE handle) { struct p11Object_t *object; while (*list && ((*list)->handle != handle)) { list = &((*list)->next); } if (*list == NULL) return CKR_OBJECT_HANDLE_INVALID; object = *list; *list = (*list)->next; freeObject(object); return CKR_OK; }
static status deleteRowTable(Table tab, TableRow row, BoolObj keep) { int i, rown = valInt(row->index); int rmin, rmax; table_row_range(tab, &rmin, &rmax); /* deal with cells spanned over */ /* this row */ for_vector_i(row, TableCell cell, i, { if ( notNil(cell) && i == valInt(cell->column) ) { if ( cell->row_span != ONE ) { if ( cell->row == row->index ) assign(cell, row, inc(cell->row)); assign(cell, row_span, dec(cell->row_span)); } else if ( cell->row == row->index && notNil(cell->image) ) { removeCellImageTable(tab, cell, keep); } freeObject(cell); } });
/* obj_handleSignals Handle signals that have accumulated in the module's queue. Such signals may include object killing or spawning signals. */ void obj_handleSignals(void) { extern SigQ signals; Signal sig; while (sig_poll(&signals, &sig)) { switch (sig.type) { case SPAWN_KILL_SIG: switch (sig.sig.sk.todo) { case SPAWN_OBJECT: insertObj((Object *) sig.sig.sk.obj); break; case KILL_OBJECT: freeObject((Object *) sig.sig.sk.obj); break; } break; } } }
//=========================================================================== bool Curvature::minimalCurvatureRadius(const SplineCurve& curve, double& mincurv, double& pos) //=========================================================================== { // Find the spline function for the numerator in the derivate of the square of the curvature BsplineBasis basis = curve.basis(); int order = basis.order(); int new_order = 6 * order - 14; mincurv = MAXDOUBLE; pos = (basis.startparam() + basis.endparam()) / 2.0; if (new_order < 0) // Straight line { return false; } vector<double> knots_simple; vector<double> new_knots; basis.knotsSimple(knots_simple); for (size_t i = 0; i < knots_simple.size(); ++i) { int old_mult = basis.knotMultiplicity(knots_simple[i]); int new_mult = 5 * order - 11 + old_mult; if (old_mult >= order-2) new_mult -= 3 - order + old_mult; for (int j = 0; j < new_mult; ++j) new_knots.push_back(knots_simple[i]); } int num_coefs = (int)new_knots.size() - new_order; BsplineBasis new_basis(new_order, new_knots.begin(), new_knots.end()); vector<double> coefs_par; // Parameter values for the coefs (Greville) vector<double> coefs; shared_ptr<SplineCurve> d_curve(curve.derivCurve(1)); shared_ptr<SplineCurve> dd_curve(d_curve->derivCurve(1)); shared_ptr<SplineCurve> ddd_curve(dd_curve->derivCurve(1)); for (int i = 0; i < num_coefs; ) { int knot_pos = i + 1; while (knot_pos < int(new_knots.size()) && new_knots[knot_pos-1] == new_knots[knot_pos]) ++knot_pos; double step = (new_knots[knot_pos] - new_knots[knot_pos-1]) / double(knot_pos - i); double tpar = new_knots[knot_pos-1] + step/2.0; for (;i < knot_pos; ++i) { coefs_par.push_back(tpar); tpar += step; } } for (int i = 0; i < num_coefs; ++i) { double tpar = coefs_par[i]; Point d_p, dd_p, ddd_p; d_curve->point(d_p, tpar); dd_curve->point(dd_p, tpar); ddd_curve->point(ddd_p, tpar); coefs.push_back( (d_p % dd_p) * (d_p % (ddd_p * (d_p * d_p) - dd_p * 3 * (d_p * dd_p))) ); } vector<double> numerator_coefs; vector<double> dummy_tangents; vector<int> dummy_index; SplineInterpolator interpolator; interpolator.setBasis(new_basis); interpolator.interpolate(coefs_par, coefs, dummy_index, dummy_tangents, numerator_coefs); shared_ptr<SplineCurve> numerator_curve( new SplineCurve(num_coefs, new_order, interpolator.basis().begin(), numerator_coefs.begin(), 1)); bool mincurvFound = false; vector<double> extremalParametervalues; extremalParametervalues.push_back(knots_simple[0]); for (size_t kr=1; kr<knots_simple.size(); ++kr) { extremalParametervalues.push_back(knots_simple[kr]); shared_ptr<SplineCurve> sub_numerator(numerator_curve->subCurve(knots_simple[kr-1], knots_simple[kr])); SISLCurve *num_sisl = Curve2SISL(*(sub_numerator.get()), false); SISLObject *qo1 = 0; SISLObject *qo2 = 0; SISLPoint *qp = 0; double spoint[1]; spoint[0] = 0.0; int kstat = 0; SISLIntdat *qintdat = 0; double aepsge = 1.0e-6; // 1.0e-9; // Normalize large values double min_val = std::numeric_limits<double>::max(); double max_val = -std::numeric_limits<double>::max(); for (int kr=0; kr<num_sisl->in; ++kr) { min_val = std::min(min_val, num_sisl->ecoef[kr]); max_val = std::max(max_val, num_sisl->ecoef[kr]); } double lim = 100.0; if (max_val-min_val > lim && max_val > 0.0 && min_val < 0.0) { double fac = lim/(max_val-min_val); for (int kr=0; kr<num_sisl->in; ++kr) num_sisl->ecoef[kr] *= fac; } if (!(qo1 = newObject(SISLCURVE))) continue; qo1 -> c1 = num_sisl; qo1 -> o1 = qo1; if (!(qo2 = newObject(SISLPOINT))) { if (qo1) freeObject(qo1); continue; } spoint[0] = 0.0; if(!(qp = newPoint(spoint,1,1))) { if (qo1) freeObject(qo1); if (qo2) freeObject(qo2); continue; } qo2 -> p1 = qp; sh1761(qo1,qo2,aepsge,&qintdat,&kstat); if (kstat < 0) { if (qo1) freeObject(qo1); if (qo2) freeObject(qo2); if (qintdat) freeIntdat(qintdat); continue; } if (qintdat) { for (int i = 0; i < qintdat->ipoint; ++i) extremalParametervalues.push_back(qintdat->vpoint[i]->epar[0]); } if (qo1) freeObject(qo1); if (qo2) freeObject(qo2); if (qintdat) freeIntdat(qintdat); } for (size_t i = 0; i < extremalParametervalues.size(); ++i) { Point d_p, dd_p; d_curve->point(d_p, extremalParametervalues[i]); dd_curve->point(dd_p, extremalParametervalues[i]); double curv_numerator = (d_p % dd_p).length(); double curv_denominator = d_p.length(); curv_denominator = curv_denominator * curv_denominator * curv_denominator; if (curv_numerator <= curv_denominator * 1.0e-9) continue; double curvatureRadius = curv_denominator/curv_numerator; // Same as 1/curvature if (!mincurvFound || curvatureRadius < mincurv) { mincurvFound = true; mincurv = curvatureRadius; pos = extremalParametervalues[i]; } } return (extremalParametervalues.size() > 0); }
void runRandomTests(int count, unsigned int seed, int n, ListPtr list) { int i; int test; NodePtr node; ObjectPtr job; ObjectPtr searchJob; int *tests; tests = (int *) malloc(sizeof(int)*NUM_TESTS); for (i=0; i<NUM_TESTS; i++) tests[i]=0; srandom(seed); for (i=0; i<count; i++) { test = (int) (NUM_TESTS * (double) rand()/RAND_MAX); tests[test]++; switch (test) { case 0: if (DEBUG_LEVEL > 1) fprintf(stderr,"addAtFront\n"); n++; job = createObject(n, "some info"); node = createNode(job); addAtFront(list, node); break; case 1: if (DEBUG_LEVEL > 1) fprintf(stderr,"addAtRear\n"); n++; job = createObject(n, "some info"); node = createNode(job); addAtRear(list, node); break; case 2: if (DEBUG_LEVEL > 1) fprintf(stderr,"removeFront\n"); node = removeFront(list); freeNode(node, freeObject); break; case 3: if (DEBUG_LEVEL > 1) fprintf(stderr,"removeRear\n"); node = removeRear(list); freeNode(node, freeObject); break; case 4: if (DEBUG_LEVEL > 1) fprintf(stderr,"removeNode\n"); searchJob = createObject(i,"foo"); node = removeNode(list, search(list, searchJob)); freeNode(node, freeObject); freeObject(searchJob); break; case 5: if (DEBUG_LEVEL > 1) fprintf(stderr,"reverseList\n"); reverseList(list); break; case 6: if (DEBUG_LEVEL > 1) fprintf(stderr,"searchList\n"); searchJob = createObject(i,"foo"); node = search(list, searchJob); freeObject(searchJob); break; default: break; } } print_stats(tests); free(tests); }
void freeObject(object* obj) { int i; for (i = 0; i < obj->children.used; i++) freeObject(obj->children.data[i]); free(obj); }
static status unlinkToHyper(Hyper h) { return freeObject(h); }
//=========================================================================== void Curvature::curvatureRadiusPoints(const SplineCurve& curve, double curveRad, vector<double>& pos) //=========================================================================== { BsplineBasis basis = curve.basis(); int order = basis.order(); int new_order = 6 * order - 11; vector<double> knots_simple; vector<double> new_knots; basis.knotsSimple(knots_simple); for (size_t i = 0; i < knots_simple.size(); ++i) { int old_mult = basis.knotMultiplicity(knots_simple[i]); int new_mult = 5 * order - 9 + old_mult; if (old_mult >= order-1) new_mult -= 2 - order + old_mult; for (int j = 0; j < new_mult; ++j) new_knots.push_back(knots_simple[i]); } int num_coefs = (int)new_knots.size() - new_order; BsplineBasis new_basis(new_order, new_knots.begin(), new_knots.end()); vector<double> coefs_par; // Parameter values for the coefs (Greville) vector<double> coefs; shared_ptr<SplineCurve> d_curve(curve.derivCurve(1)); shared_ptr<SplineCurve> dd_curve(d_curve->derivCurve(1)); for (int i = 0; i < num_coefs; ) { int knot_pos = i + 1; while (knot_pos < int(new_knots.size()) && new_knots[knot_pos-1] == new_knots[knot_pos]) ++knot_pos; double step = (new_knots[knot_pos] - new_knots[knot_pos-1]) / double(knot_pos - i); double tpar = new_knots[knot_pos-1] + step/2.0; for (;i < knot_pos; ++i) { coefs_par.push_back(tpar); tpar += step; } } for (int i = 0; i < num_coefs; ++i) { double tpar = coefs_par[i]; Point d_p, dd_p; d_curve->point(d_p, tpar); dd_curve->point(dd_p, tpar); double d_p_length2 = d_p.length2(); coefs.push_back( (d_p % dd_p).length2() * curveRad * curveRad - d_p_length2*d_p_length2*d_p_length2); } vector<double> curvature_coefs; vector<double> dummy_tangents; vector<int> dummy_index; SplineInterpolator interpolator; interpolator.setBasis(new_basis); interpolator.interpolate(coefs_par, coefs, dummy_index, dummy_tangents, curvature_coefs); // Normalize large values double min_val = std::numeric_limits<double>::max(); double max_val = -std::numeric_limits<double>::max(); for (size_t kr=0; kr<curvature_coefs.size(); ++kr) { min_val = std::min(min_val, curvature_coefs[kr]); max_val = std::max(max_val, curvature_coefs[kr]); } double lim = 100.0; if (max_val-min_val > lim && max_val > 0.0 && min_val < 0.0) { double fac = lim/(max_val-min_val); for (size_t kr=0; kr<curvature_coefs.size(); ++kr) curvature_coefs[kr] *= fac; } shared_ptr<SplineCurve> curvature_curve( new SplineCurve(num_coefs, new_order, interpolator.basis().begin(), curvature_coefs.begin(), 1)); SISLCurve *num_sisl = Curve2SISL(*(curvature_curve.get()), false); SISLObject *qo1 = 0; SISLObject *qo2 = 0; SISLPoint *qp = 0; double spoint[1]; spoint[0] = 0.0; int kstat = 0; SISLIntdat *qintdat = 0; double aepsge = 1.0e-6; //1.0e-9; if (!(qo1 = newObject(SISLCURVE))) goto error101; qo1 -> c1 = num_sisl; qo1 -> o1 = qo1; if (!(qo2 = newObject(SISLPOINT))) goto error101; spoint[0] = 0.0; if(!(qp = newPoint(spoint,1,1))) goto error101; qo2 -> p1 = qp; sh1761(qo1,qo2,aepsge,&qintdat,&kstat); if (kstat < 0) goto error101; if (qintdat) { for (int i = 0; i < qintdat->ipoint; ++i) pos.push_back(qintdat->vpoint[i]->epar[0]); } error101: if (qo1) freeObject(qo1); if (qo2) freeObject(qo2); if (qintdat) freeIntdat(qintdat); }
void freeObjectVoid(void *o) { freeObject(o); }
/* Try to encode a string object in order to save space */ robj *tryObjectEncoding(robj *o) { long value; sds s = o->ptr; size_t len; /* Make sure this is a string object, the only type we encode * in this function. Other types use encoded memory efficient * representations but are handled by the commands implementing * the type. */ serverAssertWithInfo(NULL,o,o->type == OBJ_STRING); /* We try some specialized encoding only for objects that are * RAW or EMBSTR encoded, in other words objects that are still * in represented by an actually array of chars. */ if (!sdsEncodedObject(o)) return o; /* It's constant object, not encode it. */ if (o->constant) return o; /* Check if we can represent this string as a long integer. * Note that we are sure that a string larger than 21 chars is not * representable as a 32 nor 64 bit integer. */ len = sdslen(s); if (len <= 21 && string2l(s,len,&value)) { /* This object is encodable as a long. Try to use a shared object. * Note that we avoid using shared integers when maxmemory is used * because every object needs to have a private LRU field for the LRU * algorithm to work well. * Now we do not support LRU, so just comment it. */ if (/*(server.maxmemory == 0 || (server.maxmemory_policy != MAXMEMORY_VOLATILE_LRU && server.maxmemory_policy != MAXMEMORY_ALLKEYS_LRU)) && */ value >= 0 && value < OBJ_SHARED_INTEGERS) { freeObject(o); return shared.integers[value]; } else { if (o->encoding == OBJ_ENCODING_RAW) sdsfree(o->ptr); o->encoding = OBJ_ENCODING_INT; o->ptr = (void*) value; return o; } } /* If the string is small and is still RAW encoded, * try the EMBSTR encoding which is more efficient. * In this representation the object and the SDS string are allocated * in the same chunk of memory to save space and cache misses. */ if (len <= OBJ_ENCODING_EMBSTR_SIZE_LIMIT) { robj *emb; if (o->encoding == OBJ_ENCODING_EMBSTR) return o; emb = createEmbeddedStringObject(s,sdslen(s)); freeObject(o); return emb; } /* We can't encode the object... * * Do the last try, and at least optimize the SDS string inside * the string object to require little space, in case there * is more than 10% of free space at the end of the SDS string. * * We do that only for relatively large strings as this branch * is only entered if the length of the string is greater than * OBJ_ENCODING_EMBSTR_SIZE_LIMIT. */ if (o->encoding == OBJ_ENCODING_RAW && sdsavail(s) > len/10) { o->ptr = sdsRemoveFreeSpace(o->ptr); } /* Return the original object. */ return o; }