Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
The following are the changes from calc version 2.16.1.1 to 2.16.1.2:

Fixed a bug where the calc command history was not being properly
saved in the history file. Thanks go to the GitHub user @Vekhir
for both reporting this problem and helping come up with a solution.

Per request, we expanded number of entries to save from 1024 to 4096.


The following are the changes from calc version 2.16.1.0 to 2.16.1.1:

Fix compiler warning for `custom/u_pfe.c`.
Expand Down
2 changes: 1 addition & 1 deletion Makefile.config
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ EXT=

# The calc version in the form of x.y.z.w
#
VERSION= 2.16.1.1
VERSION= 2.16.1.2

# The calc major version in the form of x.y.z
#
Expand Down
21 changes: 18 additions & 3 deletions hist.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* hist - interactive readline module
*
* Copyright (C) 1999-2007,2021-2023 David I. Bell
* Copyright (C) 1999-2007,2021-2023,2026 David I. Bell
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
Expand Down Expand Up @@ -1485,7 +1485,7 @@ quit_calc(int UNUSED(ch))

#if defined(USE_READLINE)

# define HISTORY_LEN (1024) /* number of entries to save */
# define HISTORY_LEN (4096) /* number of entries to save */

# include <readline/readline.h>
# include <readline/history.h>
Expand Down Expand Up @@ -1574,6 +1574,20 @@ my_stifle_history(void)
}
}

/*
* close down and complete history and free the calc_history value allocated by initenv().
*/
S_FUNC void
hist_finish(void)
{
/* only save last number of entries */
my_stifle_history();
if (calc_history != NULL) {
free(calc_history);
calc_history = NULL;
}
}

int
hist_init(char *UNUSED(filename))
{
Expand Down Expand Up @@ -1605,7 +1619,8 @@ hist_init(char *UNUSED(filename))
/* read previous history */
read_history(calc_history);

atexit(my_stifle_history);
/* setup how history is closed down and synced when exiting */
atexit(hist_finish);

return HIST_SUCCESS;
}
Expand Down
17 changes: 12 additions & 5 deletions lib_calc.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* lib_calc - calc link library initialization and shutdown routines
*
* Copyright (C) 1999-2007,2018,2021-2023 Landon Curt Noll
* Copyright (C) 1999-2007,2018,2021-2023,2026 Landon Curt Noll
*
* Calc is open software; you can redistribute it and/or modify it under
* the terms of the version 2.1 of the GNU Lesser General Public License
Expand Down Expand Up @@ -722,10 +722,17 @@ libcalc_call_me_last(void)
free(shell);
shell = NULL;
}
if (calc_history != NULL) {
free(calc_history);
calc_history = NULL;
}
/*
* IMPORT NOTE: Do NOT free calc_history here !!!
*
* If you do, this will cause the history you have made to be lost!
*
* FYI In hist.c:
*
* The hist_finish() function, which is invoked due to a call to
* atexit(hist_finish) in hist_init() will take care of freeing
* the calc_history storage, if it was allocated in initenv().
*/
if (calc_helpdir != NULL) {
free(calc_helpdir);
calc_helpdir = NULL;
Expand Down
2 changes: 1 addition & 1 deletion version.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
# define MAJOR_VER 2 /* level 1: major library version */
# define MINOR_VER 16 /* level 2: minor library version */
# define MAJOR_PATCH 1 /* level 3: major software version level */
# define MINOR_PATCH 1 /* level 4: minor software version level */
# define MINOR_PATCH 2 /* level 4: minor software version level */

/*
* Defining PERMIT_DANGEROUS_ADDRESS_ARITHMETIC is NOT supported!
Expand Down