From 8a4a37b5bbcafebd5930486c752fb52e25cbdb71 Mon Sep 17 00:00:00 2001 From: rlar Date: Mon, 28 Dec 2015 20:25:22 +0100 Subject: [PATCH] dvec abstraction, #4/11, emphasise `ZERO(dvec)' initialisation --- src/frontend/com_compose.c | 1 - src/frontend/com_fft.c | 4 ---- src/frontend/com_let.c | 1 - src/frontend/define.c | 1 - src/frontend/dvec.c | 5 +++++ src/frontend/evaluate.c | 4 ---- src/frontend/fourier.c | 1 - src/frontend/parse.c | 2 -- src/frontend/rawfile.c | 1 - src/frontend/spec.c | 3 --- src/frontend/vectors.c | 2 -- src/maths/cmaths/cmath4.c | 2 -- 12 files changed, 5 insertions(+), 22 deletions(-) diff --git a/src/frontend/com_compose.c b/src/frontend/com_compose.c index 2f1c763e9..aabd82a0c 100644 --- a/src/frontend/com_compose.c +++ b/src/frontend/com_compose.c @@ -452,7 +452,6 @@ com_compose(wordlist *wl) } result = dvec_alloc(); - ZERO(result, struct dvec); result->v_name = resname; result->v_type = type; diff --git a/src/frontend/com_fft.c b/src/frontend/com_fft.c index ae2a1663e..9cdef191b 100644 --- a/src/frontend/com_fft.c +++ b/src/frontend/com_fft.c @@ -129,7 +129,6 @@ com_fft(wordlist *wl) plot_cur->pl_date = copy(datestring()); f = dvec_alloc(); - ZERO(f, struct dvec); f->v_name = copy("frequency"); f->v_type = SV_FREQUENCY; f->v_flags = (VF_REAL | VF_PERMANENT | VF_PRINT); @@ -150,7 +149,6 @@ com_fft(wordlist *wl) for (i = 0, vec = vlist; iv_realdata; /* real input data */ f = dvec_alloc(); - ZERO(f, struct dvec); f->v_name = vec_basename(vec); f->v_type = SV_NOTYPE; f->v_flags = (VF_COMPLEX | VF_PERMANENT); @@ -355,7 +353,6 @@ com_psd(wordlist *wl) plot_cur->pl_date = copy(datestring()); f = dvec_alloc(); - ZERO(f, struct dvec); f->v_name = copy("frequency"); f->v_type = SV_FREQUENCY; f->v_flags = (VF_REAL | VF_PERMANENT | VF_PRINT); @@ -377,7 +374,6 @@ com_psd(wordlist *wl) for (i = 0, vec = vlist; iv_realdata; /* real input data */ f = dvec_alloc(); - ZERO(f, struct dvec); f->v_name = vec_basename(vec); f->v_type = SV_NOTYPE; //vec->v_type; f->v_flags = (VF_COMPLEX | VF_PERMANENT); diff --git a/src/frontend/com_let.c b/src/frontend/com_let.c index 2c0336e71..22abd6368 100644 --- a/src/frontend/com_let.c +++ b/src/frontend/com_let.c @@ -162,7 +162,6 @@ com_let(wordlist *wl) /* create and assign a new vector */ n = dvec_alloc(); - ZERO(n, struct dvec); n->v_name = copy(p); n->v_type = t->v_type; n->v_flags = (t->v_flags | VF_PERMANENT); diff --git a/src/frontend/define.c b/src/frontend/define.c index a41de2748..0cc7263fd 100644 --- a/src/frontend/define.c +++ b/src/frontend/define.c @@ -162,7 +162,6 @@ savetree(struct pnode *pn) d = pn->pn_value; if ((d->v_length != 0) || eq(d->v_name, "list")) { pn->pn_value = dvec_alloc(); - ZERO(pn->pn_value, struct dvec); pn->pn_value->v_name = copy(d->v_name); pn->pn_value->v_length = d->v_length; pn->pn_value->v_type = d->v_type; diff --git a/src/frontend/dvec.c b/src/frontend/dvec.c index f253f4937..f2d0e980b 100644 --- a/src/frontend/dvec.c +++ b/src/frontend/dvec.c @@ -7,5 +7,10 @@ dvec_alloc(void) { struct dvec *rv = TMALLOC(struct dvec, 1); + if (!rv) + return NULL; + + ZERO(rv, struct dvec); + return rv; } diff --git a/src/frontend/evaluate.c b/src/frontend/evaluate.c index a6a9adfbc..e0647f8da 100644 --- a/src/frontend/evaluate.c +++ b/src/frontend/evaluate.c @@ -319,7 +319,6 @@ doop(char what, return (NULL); /* Make up the new vector. */ res = dvec_alloc(); - ZERO(res, struct dvec); if (relflag || (isreal(v1) && isreal(v2) && (func != cx_comma))) { res->v_type = SV_NOTYPE; res->v_flags = (v1->v_flags | v2->v_flags | @@ -616,7 +615,6 @@ op_range(struct pnode *arg1, struct pnode *arg2) } res = dvec_alloc(); - ZERO(res, struct dvec); res->v_name = mkcname('R', v->v_name, ind->v_name); res->v_type = v->v_type; res->v_flags = v->v_flags; @@ -772,7 +770,6 @@ op_ind(struct pnode *arg1, struct pnode *arg2) /* Make up the new vector. */ res = dvec_alloc(); - ZERO(res, struct dvec); res->v_name = mkcname('[', v->v_name, ind->v_name); res->v_type = v->v_type; res->v_flags = v->v_flags; @@ -942,7 +939,6 @@ apply_func(struct func *func, struct pnode *arg) name = mkcname('b', v->v_name, NULL); t = dvec_alloc(); - ZERO(t, struct dvec); t->v_name = name; t->v_flags = (v->v_flags & ~VF_COMPLEX & ~VF_REAL & diff --git a/src/frontend/fourier.c b/src/frontend/fourier.c index 2d69a11ed..59f7dd6cc 100644 --- a/src/frontend/fourier.c +++ b/src/frontend/fourier.c @@ -193,7 +193,6 @@ fourier(wordlist *wl, struct plot *current_plot) /* with size 3 * nfreqs in current plot */ /* generate name for new vector, using vec->name */ n = dvec_alloc(); - ZERO(n, struct dvec); n->v_name = tprintf("fourier%d%d", callstof, newveccount); n->v_type = SV_NOTYPE; diff --git a/src/frontend/parse.c b/src/frontend/parse.c index 5dd7e7579..4262b4df8 100644 --- a/src/frontend/parse.c +++ b/src/frontend/parse.c @@ -331,7 +331,6 @@ PP_mknnode(double number) struct dvec *v; v = dvec_alloc(); - ZERO(v, struct dvec); /* We don't use printnum because it screws up PP_mkfnode above. We have * to be careful to deal properly with node numbers that are quite @@ -369,7 +368,6 @@ PP_mksnode(const char *string) v = vec_get(string); if (v == NULL) { nv = dvec_alloc(); - ZERO(nv, struct dvec); nv->v_name = copy(string); p->pn_value = nv; return (p); diff --git a/src/frontend/rawfile.c b/src/frontend/rawfile.c index 51073aa79..7aace4f41 100644 --- a/src/frontend/rawfile.c +++ b/src/frontend/rawfile.c @@ -469,7 +469,6 @@ raw_read(char *name) { * be dangerous if the file is invalid. */ v = dvec_alloc(); - ZERO(v, struct dvec); v->v_type = SV_NOTYPE; v->v_flags = (short)flags; v->v_length = npoints; diff --git a/src/frontend/spec.c b/src/frontend/spec.c index 6cefc8a82..f98455bbb 100644 --- a/src/frontend/spec.c +++ b/src/frontend/spec.c @@ -208,7 +208,6 @@ com_spec(wordlist *wl) plot_cur->pl_date = copy(datestring()); f = dvec_alloc(); - ZERO(f, struct dvec); f->v_name = copy("frequency"); f->v_type = SV_FREQUENCY; f->v_flags = (VF_REAL | VF_PERMANENT | VF_PRINT); @@ -222,7 +221,6 @@ com_spec(wordlist *wl) for (i = 0, vec = vlist; i < ngood; i++) { tdvec[i] = vec->v_realdata; f = dvec_alloc(); - ZERO(f, struct dvec); f->v_name = vec_basename(vec); f->v_type = vec->v_type; f->v_flags = (VF_COMPLEX | VF_PERMANENT); @@ -282,7 +280,6 @@ com_spec(wordlist *wl) #ifdef KEEPWINDOW f = dvec_alloc(); - ZERO(f, struct dvec); f->v_name = copy("win"); f->v_type = SV_NOTYPE; f->v_flags = (VF_REAL | VF_PERMANENT); diff --git a/src/frontend/vectors.c b/src/frontend/vectors.c index 3174912c0..965663352 100644 --- a/src/frontend/vectors.c +++ b/src/frontend/vectors.c @@ -523,7 +523,6 @@ vec_get(const char *vec_name) } d = dvec_alloc(); - ZERO(d, struct dvec); d->v_name = copy(whole); /* MW. The same as word before */ d->v_type = SV_NOTYPE; d->v_flags |= VF_REAL; /* No complex values yet... */ @@ -1123,7 +1122,6 @@ vec_mkfamily(struct dvec *v) indexstring(count, v->v_numdims - 1, buf2); d = dvec_alloc(); - ZERO(d, struct dvec); d->v_name = tprintf("%s%s", v->v_name, buf2); d->v_type = v->v_type; diff --git a/src/maths/cmaths/cmath4.c b/src/maths/cmaths/cmath4.c index e42f0a870..cad70a52b 100644 --- a/src/maths/cmaths/cmath4.c +++ b/src/maths/cmaths/cmath4.c @@ -627,7 +627,6 @@ cx_fft(void *data, short int type, int length, int *newlength, short int *newtyp /* create a new scale vector */ sv = dvec_alloc(); - ZERO(sv, struct dvec); sv->v_name = copy("fft_scale"); sv->v_type = SV_FREQUENCY; sv->v_flags = (VF_REAL | VF_PERMANENT | VF_PRINT); @@ -864,7 +863,6 @@ cx_ifft(void *data, short int type, int length, int *newlength, short int *newty /* create a new scale vector */ sv = dvec_alloc(); - ZERO(sv, struct dvec); sv->v_name = copy("ifft_scale"); sv->v_type = SV_TIME; sv->v_flags = (VF_REAL | VF_PERMANENT | VF_PRINT);