From fc3fdf8ad866cfef228bf3413df87f2679cb32f4 Mon Sep 17 00:00:00 2001 From: maedoc Date: Wed, 3 Feb 2016 16:55:26 +0100 Subject: [PATCH] fix various warnings --- src/conn.c | 2 ++ src/sch_cb.c | 1 + src/sd_rng.c | 2 +- src/sd_test.c | 8 ++++---- src/sys_net.c | 4 ++-- src/sys_regmap.c | 20 ++++++++++++++++++++ src/sys_wc.c | 40 ++++++++++++++++++++++++++++++++++++---- test/test.h | 4 ++-- 8 files changed, 68 insertions(+), 13 deletions(-) diff --git a/src/conn.c b/src/conn.c index 2f76348..ecd10f0 100644 --- a/src/conn.c +++ b/src/conn.c @@ -19,7 +19,9 @@ typedef struct connd , * restrict d; } connd; +/* static bool have_delays(sd_conn *conn) { return ((connd*)conn)->d_not_null; } +*/ diff --git a/src/sch_cb.c b/src/sch_cb.c index 56fce3c..75c1e9a 100644 --- a/src/sch_cb.c +++ b/src/sch_cb.c @@ -44,6 +44,7 @@ sd_sch_new_cb(uint32_t nx, void *user_data, uint32_t nc, double * restrict c) ) { + (void) nx; data *d; if ((d = sd_malloc(sizeof(data))) == NULL) { diff --git a/src/sd_rng.c b/src/sd_rng.c index 75cc831..964288a 100644 --- a/src/sd_rng.c +++ b/src/sd_rng.c @@ -55,7 +55,7 @@ static sd_rng rng_default = { sd_rng *sd_rng_new_default() { - sd_rng *r, z = { 0 }; + sd_rng *r; if ((r = sd_malloc (sizeof(sd_rng))) == NULL || (*r = rng_default, 0) || (r->ptr = sd_malloc (sizeof(struct rng_data))) == NULL) diff --git a/src/sd_test.c b/src/sd_test.c index cbd0dfc..e7b730e 100644 --- a/src/sd_test.c +++ b/src/sd_test.c @@ -8,7 +8,7 @@ static test *tests; static uint32_t ntest=0, nfail=0, tests_len=0; -static char *cpstr(char *str) +static char *cpstr(const char *str) { uint32_t nc = strlen(str) + 1; char *out = sd_malloc(sizeof(char) * nc); @@ -16,7 +16,7 @@ static char *cpstr(char *str) return out; } -static void test_record(bool cond, char *scond, char *fname, int lineno, char *func) +static void test_record(bool cond, const char *scond, const char *fname, int lineno, const char *func) { test t = {.pass=cond, .l=lineno}; t.f = cpstr(fname); @@ -80,14 +80,14 @@ static void dump_junit_xml() fprintf(fd, "\n"); } -void sd_test_failed(char *scond, char *fname, int lineno) +void sd_test_failed(const char *scond, const char *fname, int lineno) { nfail++; fprintf(stderr, "[sd_test] FAILURE %d/%d %s:%d `%s'\n", nfail, ntest, fname, lineno, scond); } -void sd_test_true(bool cond, char *scond, char *fname, int lineno, char *func) +void sd_test_true(bool cond, const char *scond, const char *fname, int lineno, const char *func) { test_record(cond, scond, fname, lineno, func); ntest++; diff --git a/src/sys_net.c b/src/sys_net.c index 6874e15..039b602 100644 --- a/src/sys_net.c +++ b/src/sys_net.c @@ -135,8 +135,8 @@ static void free_sys(sd_sys *sys) { free_ptr(sys->ptr); } static uint32_t sys_ndim(sd_sys*sys) { return ((netd*)sys->ptr)->ns; } static uint32_t sys_ndc(sd_sys*sys) { return ((netd*)sys->ptr)->nnz; } static uint32_t sys_nobs(sd_sys*sys) { return ((netd*)sys->ptr)->ne; } -static uint32_t sys_nrpar(sd_sys*sys){ return 0; } -static uint32_t sys_nipar(sd_sys*sys){ return 0; } +static uint32_t sys_nrpar(sd_sys*sys){ (void) sys; return 0; } +static uint32_t sys_nipar(sd_sys*sys){ (void) sys; return 0; } static sd_sys net_sys_defaults = { .ndim = &sys_ndim, diff --git a/src/sys_regmap.c b/src/sys_regmap.c index 7656516..3c0cd70 100644 --- a/src/sys_regmap.c +++ b/src/sys_regmap.c @@ -3,6 +3,7 @@ #include "sddekit.h" typedef struct regmapd { + sd_sys sys; uint32_t i, *n; /* n=1 for sum instead of averaging */ } regmapd; @@ -18,3 +19,22 @@ static sd_stat apply(sd_sys *sys, sd_sys_in *in, sd_sys_out *out) out->o[0] = in->x[0] / d->n[d->i]; return SD_OK; } + +static sd_sys defaults = { + .apply = &apply +}; + +sd_sys * +sd_regmap_new() +{ + regmapd z={0}, *d = sd_malloc(sizeof(regmapd)); + if (d == NULL) + { + sd_err("alloc regmapd failed."); + return NULL; + } + *d = z; + d->sys = defaults; + d->sys.ptr = d; + return &(d->sys); +} diff --git a/src/sys_wc.c b/src/sys_wc.c index c03bff3..58eaaca 100644 --- a/src/sys_wc.c +++ b/src/sys_wc.c @@ -2,14 +2,15 @@ #include "sddekit.h" -struct data { +typedef struct { + sd_sys sys; double k_e, k_i, r_e, r_i, tau_e, tau_i, c_1, c_2, c_3, c_4, a_e, a_i, b_e, b_i, theta_e, theta_i, alpha_e, alpha_i, P, Q, c_e, c_i, c_ee, c_ie, c_ei, c_ii; double D, k; -}; +} data; -struct data pars_sl14 = { +static data pars_sl14 = { /* Sanz-Leon 2014 */ .k_e = 1.0, .k_i = 1.0, .r_e = 0.0, .r_i = 0.0, @@ -36,7 +37,7 @@ static uint32_t nipar(sd_sys *s) { (void) s; return 0; } static sd_stat apply(sd_sys *s, sd_sys_in *in, sd_sys_out *out) { - struct data *d = s->ptr; + data *d = s->ptr; double *x = in->x, *c = in->i, *f = out->f, *g = out->g, *o = out->o; f[0] = d->alpha_e * (d->c_ee * x[0] - d->c_ei * x[1] + d->P - d->theta_e + d->k*(c[0] + c[1])); @@ -54,3 +55,34 @@ apply(sd_sys *s, sd_sys_in *in, sd_sys_out *out) { o[1] = x[1]; return SD_OK; } + +static void wcfree(sd_sys *s) +{ + sd_free(s->ptr); +} + +static sd_sys defaults = { + .ptr = NULL, + .ndim = &ndim, + .ndc = &ndc, + .nobs = &nobs, + .nrpar = &nrpar, + .nipar = &nipar, + .apply = &apply, + .free = &wcfree +}; + +sd_sys * +sd_sys_wc_new() +{ + data *d = sd_malloc(sizeof(data)); + if (d == NULL) + { + sd_err("alloc wc data failed."); + return NULL; + } + *d = pars_sl14; + d->sys = defaults; + d->sys.ptr = d; + return &(d->sys); +} diff --git a/test/test.h b/test/test.h index 3248cd9..d1c5fb5 100644 --- a/test/test.h +++ b/test/test.h @@ -1,8 +1,8 @@ /* copyright 2016 Apache 2 sddekit authors */ -void sd_test_true(bool cond, char *scond, char *fname, int lineno, char *func); +void sd_test_true(bool cond, const char *scond, const char *fname, int lineno, const char *func); -void sd_test_failed(char *scond, char *fname, int lineno); +void sd_test_failed(const char *scond, const char *fname, int lineno); int sd_test_report(); -- 2.11.4.GIT