From d8a0b3bf957799656f7b8d88910164643f2810df Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Mon, 24 Jun 2019 12:10:57 +0200 Subject: [PATCH] Revert ":art: Poolize args" This reverts commit 512cc9c75e5979a267b7d6c458782c79a5b3be8c. --- include/arg.h | 4 +-- src/arg.c | 66 ++++++++++++++++++++++++++--------------------- src/gwion.c | 21 +++++---------- src/main.c | 1 + src/vm/vm_shred.c | 2 +- 5 files changed, 47 insertions(+), 47 deletions(-) diff --git a/include/arg.h b/include/arg.h index 69996a5c..336cfdc6 100644 --- a/include/arg.h +++ b/include/arg.h @@ -13,6 +13,6 @@ typedef struct Arg_ { m_bool memoize; } Arg; -ANN void arg_release(MemPool p, Arg*); -ANN void arg_parse(MemPool p, Arg*); +ANN void arg_release(Arg*); +ANN void arg_parse(Arg*); #endif diff --git a/src/arg.c b/src/arg.c index 44cdd039..4a06f7d2 100644 --- a/src/arg.c +++ b/src/arg.c @@ -4,38 +4,42 @@ #include "soundinfo.h" #define GWIONRC ".gwionrc" -ANN static inline void config_end(MemPool p, const Vector config) { +/* use before MemPool allocation */ +ANN static inline void config_end(const Vector config) { for(m_uint i = 0; i < vector_size(config); ++i) { const Vector v = (Vector)vector_at(config, i); - free_mstr(p, (m_str)vector_front(v)); - free_vector(p, v); + for(m_uint i = 1; i < vector_size(v); ++i) + xfree((m_str)vector_at(v, i)); + vector_release(v); + xfree(v); } } -ANN static m_str plug_dir(MemPool p) { +ANN static m_str plug_dir(void) { const m_str home = getenv("HOME"); const size_t sz = strlen(home); const m_str pdir = "/.gwplug"; - m_str plug_dir = (m_str)_mp_malloc(p, sz + strlen(pdir) + 1); + m_str plug_dir = (m_str)xmalloc(sz + strlen(pdir) + 1); strcpy(plug_dir, home); strcpy(plug_dir + sz, pdir); return plug_dir; } -ANN static void arg_init(MemPool p, Arg* arg) { +ANN static void arg_init(Arg* arg) { vector_init(&arg->add); vector_init(&arg->lib); vector_init(&arg->mod); vector_init(&arg->config); - vector_add(&arg->lib, (vtype)plug_dir(p)); +// vector_add(&arg->lib, (vtype)GWPLUG_DIR); + vector_add(&arg->lib, (vtype)plug_dir()); } -ANN void arg_release(MemPool p, Arg* arg) { +ANN void arg_release(Arg* arg) { vector_release(&arg->add); - free_mstr(p, (m_str)vector_front(&arg->lib)); + xfree((m_str)vector_front(&arg->lib)); vector_release(&arg->lib); vector_release(&arg->mod); - config_end(p, &arg->config); + config_end(&arg->config); vector_release(&arg->config); } @@ -52,19 +56,19 @@ static const char usage[] = " -z : set memoization limit\n" " -m : load module (and arguments)\n"; -ANN static void config_parse(MemPool p, Arg* arg, const m_str name); +ANN static void config_parse(Arg* arg, const m_str name); #define CASE(a,b) case a: (b) ; break; #define get_arg(a) (a[i][2] == '\0' ? arg->argv[++i] : a[i] + 2) #define ARG2INT(a) strtol(get_arg(a), NULL, 10) -ANN void _arg_parse(MemPool p, Arg* arg) { +ANN void _arg_parse(Arg* arg) { for(int i = 1; i < arg->argc; ++i) { if(arg->argv[i][0] == '-') { switch(arg->argv[i][1]) { CASE('h', gw_err(usage)) CASE('k', gw_err("CFLAGS: %s\nLDFLAGS: %s\n", CFLAGS, LDFLAGS)) - CASE('c', config_parse(p, arg, get_arg(arg->argv))) + CASE('c', config_parse(arg, get_arg(arg->argv))) CASE('p', vector_add(&arg->lib, (vtype)get_arg(arg->argv))) CASE('m', vector_add(&arg->mod, (vtype)get_arg(arg->argv))) CASE('l', arg->loop = (m_bool)ARG2INT(arg->argv) > 0 ? 1 : -1) @@ -79,57 +83,59 @@ ANN void _arg_parse(MemPool p, Arg* arg) { } } -ANN static void split_line(MemPool p, const m_str line, const Vector v) { - m_str d = mstrdup(p, line); +ANN static void split_line(const m_str line, const Vector v) { + m_str d = strdup(line), c = d; while(d) { const m_str str = strsep(&d, " "); const size_t sz = strlen(str); - if(str[sz-1] == '\n') - str[sz-1] = '\0'; - vector_add(v, (vtype)str); + const m_bool arg = (str[sz-1] == '\n'); + vector_add(v, (vtype)strndup(str, arg ? sz - 1 : sz)); } + free(d); + free(c); } -ANN static Vector get_config(MemPool p, const m_str name) { +ANN static Vector get_config(const m_str name) { char *line = NULL; size_t len = 0; ssize_t nread; FILE *f = fopen(name, "r"); CHECK_OO(f) - const Vector v = new_vector(p); + const Vector v = (Vector)xmalloc(sizeof(struct Vector_)); + vector_init(v); vector_add(v, (vtype)name); while((nread = getline(&line, &len, f)) != -1) { if(line[0] != '#') - split_line(p, line, v); + split_line(line, v); } free(line); fclose(f); return v; } -ANN static void config_parse(MemPool p, Arg* arg, const m_str name) { - const Vector v = get_config(p, name); +ANN static void config_parse(Arg* arg, const m_str name) { + const Vector v = get_config(name); if(v) { int argc = arg->argc; char** argv = arg->argv; arg->argc = vector_size(v); arg->argv = (m_str*)(v->ptr + OFFSET); - _arg_parse(p, arg); + _arg_parse(arg); arg->argc = argc; arg->argv = argv; vector_add(&arg->config, (vtype)v); } } -ANN static void config_default(MemPool p, Arg* arg) { +ANN static void config_default(Arg* arg) { char* home = getenv("HOME"); char c[strlen(home) + strlen(GWIONRC) + 2]; sprintf(c, "%s/%s", home, GWIONRC); - config_parse(p, arg, c); + config_parse(arg, c); } -ANN void arg_parse(MemPool p, Arg* a) { - arg_init(p, a); - config_default(p, a); - _arg_parse(p, a); +ANN void arg_parse(Arg* a) { + arg_init(a); + config_default(a); + _arg_parse(a); } diff --git a/src/gwion.c b/src/gwion.c index b1012961..b6d62bce 100644 --- a/src/gwion.c +++ b/src/gwion.c @@ -57,16 +57,6 @@ ANN VM* gwion_cpy(const VM* src) { return gwion->vm; } - -ANN m_bool start(const Gwion gwion, Arg* arg) { - if(gwion_audio(gwion) > 0 && gwion_engine(gwion)) { - gwion_compile(gwion, &arg->add); - plug_run(gwion, &arg->mod); - return GW_OK; - } - return GW_ERROR; -} - ANN m_bool gwion_ini(const Gwion gwion, Arg* arg) { gwion->mp = mempool_ini((sizeof(VM_Shred) + SIZEOF_REG + SIZEOF_MEM) / SZ_INT); gwion->st = new_symbol_table(gwion->mp, 65347); @@ -79,14 +69,17 @@ ANN m_bool gwion_ini(const Gwion gwion, Arg* arg) { gwion->env->gwion = gwion; gwion->vm->bbq->si = new_soundinfo(gwion->mp); arg->si = gwion->vm->bbq->si; - arg_parse(gwion->mp, arg); + arg_parse(arg); gwion->emit->memoize = arg->memoize; gwion->plug = new_plug(gwion->mp, &arg->lib); gwion->data = new_gwiondata(gwion->mp); shreduler_set_loop(gwion->vm->shreduler, arg->loop); - const m_bool ret = start(gwion, arg); - arg_release(gwion->mp, arg); - return ret; + if(gwion_audio(gwion) > 0 && gwion_engine(gwion)) { + gwion_compile(gwion, &arg->add); + plug_run(gwion, &arg->mod); + return GW_OK; + } + return GW_ERROR; } ANN void gwion_run(const Gwion gwion) { diff --git a/src/main.c b/src/main.c index d63f5240..281e6a2a 100644 --- a/src/main.c +++ b/src/main.c @@ -21,6 +21,7 @@ int main(int argc, char** argv) { signal(SIGTERM, sig); struct Gwion_ gwion = { .plug=NULL }; const m_bool ini = gwion_ini(&gwion, &arg); + arg_release(&arg); if(ini > 0) gwion_run(&gwion); gwion_end(&gwion); diff --git a/src/vm/vm_shred.c b/src/vm/vm_shred.c index 0c24674a..c755ab8a 100644 --- a/src/vm/vm_shred.c +++ b/src/vm/vm_shred.c @@ -27,7 +27,7 @@ static inline void free_shredinfo(MemPool mp, struct ShredInfo_ *info) { const Vector v = info->args; LOOP_OPTIM for(m_uint i = vector_size(v) + 1; --i;) - free_mstr(mp, (void*)vector_at(v, i - 1)); + xfree((void*)vector_at(v, i - 1)); free_vector(mp, v); } mp_free(mp, ShredInfo, info); // ??? info->p -- 2.43.0