From 562c5b135cc0835b2fd83844a8f47a1d1e9dd6ab Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Thu, 17 Apr 2008 14:20:58 +0200 Subject: [PATCH] lattice_point.cc: multi_monom/lattice_points: return malloc'd evalue(s) --- barvinok.cc | 12 ++++-------- lattice_point.cc | 17 +++++------------ lexmin.cc | 16 +++++++--------- testlib.cc | 3 +-- 4 files changed, 17 insertions(+), 31 deletions(-) diff --git a/barvinok.cc b/barvinok.cc index 74e196b..7272ea8 100644 --- a/barvinok.cc +++ b/barvinok.cc @@ -1065,10 +1065,8 @@ void ienumerator::handle(const signed_cone& sc, barvinok_options *options) free_evalue_refs(&one); for (int i = 0; i < dim; ++i) - if (E_vertex[i]) { - free_evalue_refs(E_vertex[i]); - delete E_vertex[i]; - } + if (E_vertex[i]) + evalue_free(E_vertex[i]); } struct bfenumerator : public vertex_decomposer, public bf_base, @@ -1254,10 +1252,8 @@ void bfenumerator::handle(const signed_cone& sc, barvinok_options *options) reduce(factors, v, options); for (int i = 0; i < enumerator_base::dim; ++i) - if (E_vertex[i]) { - free_evalue_refs(E_vertex[i]); - delete E_vertex[i]; - } + if (E_vertex[i]) + evalue_free(E_vertex[i]); } static evalue* barvinok_enumerate_ev_f(Polyhedron *P, Polyhedron* C, diff --git a/lattice_point.cc b/lattice_point.cc index 7322663..4a75495 100644 --- a/lattice_point.cc +++ b/lattice_point.cc @@ -40,7 +40,7 @@ static evalue *term(int param, ZZ& c, Value *den = NULL) */ evalue *multi_monom(vec_ZZ& p) { - evalue *X = new evalue(); + evalue *X = ALLOC(evalue); value_init(X->d); value_init(X->x.n); unsigned nparam = p.length()-1; @@ -237,8 +237,7 @@ evalue *fractional_part(Value *coef, Value denom, int nvar, Polyhedron *PD) } free_evalue_refs(&EV); - free_evalue_refs(E); - delete E; + evalue_free(E); } free_evalue_refs(&tmp); @@ -290,15 +289,10 @@ evalue* bv_ceil3(Value *coef, int len, Value d, Polyhedron *P) eadd(f, EP); evalue_free(f); - /* copy EP to malloc'ed evalue */ - evalue *E = ALLOC(evalue); - *E = *EP; - delete EP; - free_evalue_refs(&tmp); Vector_Free(val); - return E; + return EP; } void lattice_point_fixed(Value *vertex, Value *vertex_res, @@ -525,7 +519,7 @@ static evalue **lattice_point_fractional(const mat_ZZ& rays, vec_ZZ& lambda, Vector *row = Vector_Alloc(nparam+1); FORALL_COSETS(det, D, i, k) Vector_Matrix_Product(k->p, T2, lambda->p); - E[i] = new evalue(); + E[i] = ALLOC(evalue); value_init(E[i]->d); evalue_copy(E[i], EP); for (int j = 0; j < L->NbRows; ++j) { @@ -546,8 +540,7 @@ static evalue **lattice_point_fractional(const mat_ZZ& rays, vec_ZZ& lambda, Matrix_Free(D); value_clear(denom); - free_evalue_refs(EP); - delete EP; + evalue_free(EP); } value_clear(tmp); diff --git a/lexmin.cc b/lexmin.cc index 0ac3f08..1738703 100644 --- a/lexmin.cc +++ b/lexmin.cc @@ -42,6 +42,8 @@ using std::cout; using std::endl; using std::ostream; +#define ALLOC(type) (type*)malloc(sizeof(type)) + #define EMPTINESS_CHECK (BV_OPT_LAST+1) #define NO_REDUCTION (BV_OPT_LAST+2) @@ -146,10 +148,8 @@ struct indicator_term { } ~indicator_term() { unsigned dim = den.NumCols(); - for (int i = 0; i < dim; ++i) { - free_evalue_refs(vertex[i]); - delete vertex[i]; - } + for (int i = 0; i < dim; ++i) + evalue_free(vertex[i]); delete [] vertex; } void print(ostream& os, char **p) const; @@ -384,10 +384,8 @@ void indicator_term::substitute(Matrix *T) } } free_evalue_refs(&factor); - for (int i = 0; i < dim; ++i) { - free_evalue_refs(vertex[i]); - delete vertex[i]; - } + for (int i = 0; i < dim; ++i) + evalue_free(vertex[i]); delete [] vertex; vertex = newvertex; } @@ -558,7 +556,7 @@ void indicator_constructor::handle(const signed_cone& sc, barvinok_options *opti for (int i = 0; i < dim; ++i) { if (!term->vertex[i]) { - term->vertex[i] = new evalue(); + term->vertex[i] = ALLOC(evalue); value_init(term->vertex[i]->d); value_init(term->vertex[i]->x.n); zz2value(vertex[i], term->vertex[i]->x.n); diff --git a/testlib.cc b/testlib.cc index 88345b0..4818924 100644 --- a/testlib.cc +++ b/testlib.cc @@ -298,8 +298,7 @@ int test_lattice_points(struct barvinok_options *options) for (int i = 0; i < 4; ++i) { assert(eequal(num.E[i], point[i])); evalue_free(point[i]); - free_evalue_refs(num.E[i]); - delete num.E[i]; + evalue_free(num.E[i]); } delete [] num.E; } -- 2.11.4.GIT