From 34a2cdb12420d64a0150f2a4bc60e2da86416627 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Fri, 8 Jan 2016 20:10:23 +0000 Subject: [PATCH] memory-managment tweak in mv_format_val --- c/containers/mlrval.c | 21 ++++++++++++--------- c/todo.txt | 11 +++++------ 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/c/containers/mlrval.c b/c/containers/mlrval.c index 399db37f9..7212c31bc 100644 --- a/c/containers/mlrval.c +++ b/c/containers/mlrval.c @@ -97,37 +97,40 @@ char* mv_alloc_format_val(mv_t* pval) { // The caller should free the return value if the free-flag is non-zero after return char* mv_format_val(mv_t* pval, char* pfree_flags) { + char* rv = NULL; switch(pval->type) { case MT_NULL: *pfree_flags = NO_FREE; - return ""; + rv = ""; break; case MT_ERROR: *pfree_flags = NO_FREE; - return "(error)"; + rv = "(error)"; break; case MT_BOOL: *pfree_flags = NO_FREE; - return pval->u.boolv ? "true" : "false"; + rv = pval->u.boolv ? "true" : "false"; break; case MT_FLOAT: *pfree_flags = FREE_ENTRY_VALUE; - return mlr_alloc_string_from_double(pval->u.fltv, MLR_GLOBALS.ofmt); + rv = mlr_alloc_string_from_double(pval->u.fltv, MLR_GLOBALS.ofmt); break; case MT_INT: *pfree_flags = FREE_ENTRY_VALUE; - return mlr_alloc_string_from_ll(pval->u.intv); + rv = mlr_alloc_string_from_ll(pval->u.intv); break; case MT_STRING: - // xxx need a transfer-ownership mechanism; invalidation; two API func? something. - *pfree_flags = NO_FREE; - return pval->u.strv; + // Ownership transfer to the caller + *pfree_flags = FREE_ENTRY_VALUE; + rv = pval->u.strv; + *pval = MV_NULL; break; default: *pfree_flags = NO_FREE; - return "???"; + rv = "???"; break; } + return rv; } char* mv_describe_val(mv_t val) { diff --git a/c/todo.txt b/c/todo.txt index a99c9b53e..f85301b0c 100644 --- a/c/todo.txt +++ b/c/todo.txt @@ -9,8 +9,12 @@ TOP OF LIST * mv_format_val in case string is allocated. modify semantics to nullify the arg? * join: final sllv_free in destructor (lo-pri) +* stats1/stats2 sliding-window feature? and/or with decay-coefficients (much easier) + - mean/stddev/var; skew/kurt? + - linregs; corr/cov? + ? also, option of weighted stats w/ explicit weights field? + * light edit on utf8 page -* --mmap/--no-mmap @ mlr -h * debian screenshot * ruby @ optextdep @ mld; poki+mkman @@ -31,11 +35,6 @@ TOP OF LIST ? redhat ? ? other ? -* stats1/stats2 sliding-window feature? and/or with decay-coefficients (much easier) - - mean/stddev/var; skew/kurt? - - linregs; corr/cov? - ? also, option of weighted stats w/ explicit weights field? - * flight misc: .screenrc -> dotfiles; more dotfile currency ----------------------------------------------------------------