File tree Expand file tree Collapse file tree 3 files changed +39
-8
lines changed
Expand file tree Collapse file tree 3 files changed +39
-8
lines changed Original file line number Diff line number Diff line change 1+ The following are the changes from calc version 2.16.1.1 to date:
2+
3+ Fixed a bug where the calc command history was not being properly
4+ saved in the history file. Thanks go to the GitHub user @Vekhir
5+ for both reporting this problem and helping come up with a solution.
6+
7+ Per request, we expanded number of entries to save from 1024 to 4096.
8+
9+
110The following are the changes from calc version 2.16.1.0 to 2.16.1.1:
211
312 Fix compiler warning for `custom/u_pfe.c`.
Original file line number Diff line number Diff line change 11/*
22 * hist - interactive readline module
33 *
4- * Copyright (C) 1999-2007,2021-2023 David I. Bell
4+ * Copyright (C) 1999-2007,2021-2023,2026 David I. Bell
55 *
66 * Calc is open software; you can redistribute it and/or modify it under
77 * the terms of the version 2.1 of the GNU Lesser General Public License
@@ -1485,7 +1485,7 @@ quit_calc(int UNUSED(ch))
14851485
14861486#if defined(USE_READLINE )
14871487
1488- # define HISTORY_LEN (1024 ) /* number of entries to save */
1488+ # define HISTORY_LEN (4096 ) /* number of entries to save */
14891489
14901490# include <readline/readline.h>
14911491# include <readline/history.h>
@@ -1574,6 +1574,20 @@ my_stifle_history(void)
15741574 }
15751575}
15761576
1577+ /*
1578+ * close down and complete history and free the calc_history value allocated by initenv().
1579+ */
1580+ S_FUNC void
1581+ hist_finish (void )
1582+ {
1583+ /* only save last number of entries */
1584+ my_stifle_history ();
1585+ if (calc_history != NULL ) {
1586+ free (calc_history );
1587+ calc_history = NULL ;
1588+ }
1589+ }
1590+
15771591int
15781592hist_init (char * UNUSED (filename ))
15791593{
@@ -1605,7 +1619,8 @@ hist_init(char *UNUSED(filename))
16051619 /* read previous history */
16061620 read_history (calc_history );
16071621
1608- atexit (my_stifle_history );
1622+ /* setup how history is closed down and synced when exiting */
1623+ atexit (hist_finish );
16091624
16101625 return HIST_SUCCESS ;
16111626}
Original file line number Diff line number Diff line change 11/*
22 * lib_calc - calc link library initialization and shutdown routines
33 *
4- * Copyright (C) 1999-2007,2018,2021-2023 Landon Curt Noll
4+ * Copyright (C) 1999-2007,2018,2021-2023,2026 Landon Curt Noll
55 *
66 * Calc is open software; you can redistribute it and/or modify it under
77 * the terms of the version 2.1 of the GNU Lesser General Public License
@@ -722,10 +722,17 @@ libcalc_call_me_last(void)
722722 free (shell );
723723 shell = NULL ;
724724 }
725- if (calc_history != NULL ) {
726- free (calc_history );
727- calc_history = NULL ;
728- }
725+ /*
726+ * IMPORT NOTE: Do NOT free calc_history here !!!
727+ *
728+ * If you do, this will cause the history you have made to be lost!
729+ *
730+ * FYI In hist.c:
731+ *
732+ * The hist_finish() function, which is invoked due to a call to
733+ * atexit(hist_finish) in hist_init() will take care of freeing
734+ * the calc_history storage, if it was allocated in initenv().
735+ */
729736 if (calc_helpdir != NULL ) {
730737 free (calc_helpdir );
731738 calc_helpdir = NULL ;
You can’t perform that action at this time.
0 commit comments