X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Flib_tparm.c;h=3fe42399855215f9ba1bc42408afdf21cc42658d;hp=00380151f835e1b129c06c08e7aa2e986d4e7246;hb=312665d3aaaf5d8e3ba34d80fdd650abf758272a;hpb=790a85dbd4a81d5f5d8dd02a44d84f01512ef443 diff --git a/ncurses/tinfo/lib_tparm.c b/ncurses/tinfo/lib_tparm.c index 00380151..3fe42399 100644 --- a/ncurses/tinfo/lib_tparm.c +++ b/ncurses/tinfo/lib_tparm.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2018-2019,2020 Thomas E. Dickey * + * Copyright 2018-2020,2021 Thomas E. Dickey * * Copyright 1998-2016,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -53,7 +53,7 @@ #include #include -MODULE_ID("$Id: lib_tparm.c,v 1.126 2020/05/31 00:02:03 tom Exp $") +MODULE_ID("$Id: lib_tparm.c,v 1.131 2021/04/03 22:05:59 tom Exp $") /* * char * @@ -135,8 +135,8 @@ typedef struct { } TPARM_DATA; #if HAVE_TSEARCH -static void *cached_tparm; -static int count_tparm; +#define MyCache _nc_globals.cached_tparm +#define MyCount _nc_globals.count_tparm #if NO_LEAKS static int which_tparm; static TPARM_DATA **delete_tparm; @@ -172,20 +172,22 @@ NCURSES_EXPORT(void) _nc_free_tparm(void) { #if HAVE_TSEARCH - if (count_tparm != 0) { - delete_tparm = typeMalloc(TPARM_DATA *, count_tparm); + if (MyCount != 0) { + delete_tparm = typeCalloc(TPARM_DATA *, MyCount); which_tparm = 0; - twalk(cached_tparm, visit_nodes); - for (which_tparm = 0; which_tparm < count_tparm; ++which_tparm) { + twalk(MyCache, visit_nodes); + for (which_tparm = 0; which_tparm < MyCount; ++which_tparm) { TPARM_DATA *ptr = delete_tparm[which_tparm]; - tdelete(ptr, &cached_tparm, cmp_format); - free((char *) ptr->format); - free(ptr); + if (ptr != NULL) { + tdelete(ptr, &MyCache, cmp_format); + free((char *) ptr->format); + free(ptr); + } } which_tparm = 0; - twalk(cached_tparm, visit_nodes); + twalk(MyCache, visit_nodes); FreeAndNull(delete_tparm); - count_tparm = 0; + MyCount = 0; which_tparm = 0; } #endif @@ -405,7 +407,7 @@ parse_format(const char *s, char *format, int *len) * may be cases that we cannot see the explicit parameter numbers. */ NCURSES_EXPORT(int) -_nc_tparm_analyze(const char *string, char *p_is_s[NUM_PARM], int *popcount) +_nc_tparm_analyze(const char *string, char **p_is_s, int *popcount) { size_t len2; int i; @@ -555,7 +557,7 @@ tparm_setup(const char *string, TPARM_DATA * result) void *ft; result->format = string; - if ((ft = tfind(result, &cached_tparm, cmp_format)) != 0) { + if ((ft = tfind(result, &MyCache, cmp_format)) != 0) { fs = *(TPARM_DATA **) ft; *result = *fs; } else @@ -589,12 +591,14 @@ tparm_setup(const char *string, TPARM_DATA * result) if ((fs = typeCalloc(TPARM_DATA, 1)) != 0) { *fs = *result; if ((fs->format = strdup(string)) != 0) { - if ((ft = tsearch(fs, &cached_tparm, cmp_format)) != 0) { - ++count_tparm; + if (tsearch(fs, &MyCache, cmp_format) != 0) { + ++MyCount; } else { + free(fs); rc = ERR; } } else { + free(fs); rc = ERR; } } else { @@ -966,6 +970,13 @@ tparam_internal(const char *string, TPARM_DATA * data) get_space((size_t) 1); TPS(out_buff)[TPS(out_used)] = '\0'; + if (TPS(stack_ptr) && !_nc_tparm_err) { + DEBUG(2, ("tparm: stack has %d item%s on return", + TPS(stack_ptr), + TPS(stack_ptr) == 1 ? "" : "s")); + _nc_tparm_err++; + } + T((T_RETURN("%s"), _nc_visbuf(TPS(out_buff)))); return (TPS(out_buff)); } @@ -976,7 +987,6 @@ NCURSES_EXPORT(char *) tparm(const char *string, ...) { TPARM_DATA myData; - va_list ap; char *result = NULL; _nc_tparm_err = 0; @@ -985,6 +995,7 @@ tparm(const char *string, ...) #endif /* TRACE */ if (tparm_setup(string, &myData) == OK) { + va_list ap; va_start(ap, string); tparm_copy_valist(&myData, TRUE, ap); @@ -1040,7 +1051,6 @@ NCURSES_EXPORT(char *) tiparm(const char *string, ...) { TPARM_DATA myData; - va_list ap; char *result = NULL; _nc_tparm_err = 0; @@ -1049,6 +1059,7 @@ tiparm(const char *string, ...) #endif /* TRACE */ if (tparm_setup(string, &myData) == OK) { + va_list ap; va_start(ap, string); tparm_copy_valist(&myData, FALSE, ap); @@ -1066,7 +1077,6 @@ NCURSES_EXPORT(char *) _nc_tiparm(int expected, const char *string, ...) { TPARM_DATA myData; - va_list ap; char *result = NULL; _nc_tparm_err = 0; @@ -1077,6 +1087,7 @@ _nc_tiparm(int expected, const char *string, ...) if (tparm_setup(string, &myData) == OK && myData.num_actual <= expected && myData.tparm_type == 0) { + va_list ap; va_start(ap, string); tparm_copy_valist(&myData, FALSE, ap);