aboutsummaryrefslogtreecommitdiff
path: root/jim.c
AgeCommit message (Collapse)AuthorFilesLines
2018-09-21lreplace: Implement TIP #505Steve Bennett1-12/+5
More consistent behaviour of replacing past end of list Signed-off-by: Steve Bennett <steveb@workware.net.au>
2018-09-04Tidy some signed/unsigned comparisonsSteve Bennett1-2/+2
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2018-07-08foreach: Avoid memory leak in case of errorSteve Bennett1-1/+2
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2018-07-05expr: Fix compiler warning on older gccSteve Bennett1-1/+1
jim/jim.c: In function ‘SetExprFromAny’: jim/jim.c:9109:16: error: ‘top’ may be used uninitialized in this function [-Werror=maybe-uninitialized] expr->expr = top; ^ jim/jim.c:9075:25: note: ‘top’ was declared here struct JimExprNode *top; Signed-off-by: Steve Bennett <steveb@workware.net.au>
2018-06-08jim.c: Allow Jim_WrongNumArgs() to accept NULL for msgSteve Bennett1-1/+1
For consistency with Tcl Reported-by: Stuart Cassoff <stwo@bell.net> Signed-off-by: Steve Bennett <steveb@workware.net.au>
2018-06-03jim.c: Jim_Length/Jim_String internal checksSteve Bennett1-5/+2
Perform the same internal checks as Jim_GetString() when the string rep needs to be generated by calling Jim_GetString() Reported-by: Stuart Cassoff <stwo@bell.net> Signed-off-by: Steve Bennett <steveb@workware.net.au>
2018-01-18expr: prevent stack overflowSteve Bennett1-1/+4
Limit the depth of the expressions to a reasonable level to prevent stack overflow Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-12-02jim.c: Various minor cleanupsSteve Bennett1-69/+67
Small improvements to code for clarity and code reduction. Improve comments. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-10-16jim: cmdPrivData needs to be saved and restoredSteve Bennett1-0/+3
If a C command invokes another C command (including indirectly), cmdPrivData was being changed but not restored
2017-09-22scan: make some structure members constSteve Bennett1-2/+2
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-09-21jim.c: minor code cleanups in [switch]Steve Bennett1-24/+16
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-09-16perf: cache successful Jim_GetEnum() resultsSteve Bennett1-3/+33
When Jim_GetEnum() succeeds, cache the result in the object to speed up subsequent identical calls to Jim_GetEnum() Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-09-16defer: fast lookup existence of $jim::deferSteve Bennett1-2/+9
This speeds up call frame destruction in the common case that $jim::defer does not exist. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-09-15Implement defer, $jim::deferSteve Bennett1-1/+53
Allows commands to run when a proc or interpreter exits. If the $jim::defer variables exists at proc or interp exit, it is treated as a list of scripts to evaluate (in reverse order). The [defer] command is a helper to add scripts to $jim::defer See tests/defer.test Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-08-11expr: remove leftover debugging printfSteve Bennett1-1/+0
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-08-07jim: Fix ref count issue with dict-substSteve Bennett1-1/+11
When a dict-subst object is duplicated, ref counts need to be adjusted. Reported-by: Ryan Whitworth <me@ryanwhitworth.com> Signed-off-by: Steve Bennett <steveb@workware.net.au
2017-08-07expr: Fix refcount issue converting invalid booleanSteve Bennett1-6/+12
Reported-by: Ryan Whitworth <me@ryanwhitworth.com> Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-08-07expr: Check for missing operand to operatorSteve Bennett1-0/+14
Reported-by: Ryan Whitworth <me@ryanwhitworth.com> Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-08-03Error on extra characters after close braceSteve Bennett1-3/+17
In scripts, like Tcl does. Signed-off-by: Steve Bennett <steveb@workware.net.au> Reported-by: tcler.yin
2017-05-30expr: Ensure that non-zero return codes are passed throughSteve Bennett1-28/+31
Non-zero return codes (e.g. break, continue, exit) were all being converted to the error code. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-05-26scan: validate -ve XPG3 specifierSteve Bennett1-0/+5
Reported-by: Ryan Whitworth <me@ryanwhitworth.com> Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-05-23expr: Replace expression engineSteve Bennett1-932/+597
Rework the expression engine to use recursive descent evaluation rather than a shunting yard algorithm. Among other things, it is easier to make lazy operators and the ternary operator work correctly. In particular, the following expression no longer crashes: $(99?9,99?9:*9:999)?9) And the code is now smaller. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-05-23optimisation: when converting to double, may not need stringrepSteve Bennett1-6/+5
Minor optimisation Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-05-23optimisation: Reuse ExprBool in Jim_GetBoolFromExpr()Steve Bennett1-26/+15
Removes some duplicate code Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-05-12scan: Ensure format is converted to string formSteve Bennett1-2/+2
Must have a stringrep before parsing. Reported-by: Ryan Whitworth <me@ryanwhitworth.com> Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-05-12lsort -unique: Fix case with no duplicatesSteve Bennett1-2/+6
In this case the final element was written a second time. Reported-by: Ryan Whitworth <me@ryanwhitworth.com> Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-05-12scan: error on missing conversion charSteve Bennett1-1/+6
Don't read invalid memory Reported-by: Ryan Whitworth <me@ryanwhitworth.com> Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-05-12jim: Fix ref count problem with interpolated dict substSteve Bennett1-17/+17
When duplicating interpolated object type, need to increment ref count of the key to offset the decrement during free. Also remove type-specific dup for dict-substitution which is not needed since it does nothing different from the default dup. Reported-by: Ryan Whitworth <me@ryanwhitworth.com> Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-05-12lsort: Fix a refcount issueSteve Bennett1-2/+5
Only duplicate a shared object Reported-by: Ryan Whitworth <me@ryanwhitworth.com> Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-04-08jimsh: Fix crash with "throw 8"Steve Bennett1-1/+1
Off by one for length of the return code name array. Found with afl-fuzz. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-04-07expr: Add better checks for invalid ternary expressionSteve Bennett1-5/+13
Reported-by: Ryan Whitworth <me@ryanwhitworth.com> Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-04-07expr: Add assertion for stack underflowSteve Bennett1-0/+1
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-04-07Fix ref count for interpolation/expressionSteve Bennett1-1/+2
Ref count may be wrong when an expression is used in interpolation. Reported-by: Ryan Whitworth <me@ryanwhitworth.com> Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-04-07expr: fix crash on invalid ternary orderSteve Bennett1-1/+5
expr {1 : 2 ? 3} Reported-by: Ryan Whitworth <me@ryanwhitworth.com> Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-04-07Fix / command: divide by zeroSteve Bennett1-1/+6
Avoid exception on integer divided by zero Reported-by: Ryan Whitworth <me@ryanwhitworth.com> Signed-off-by: Steve Bennett <steveb@workware.net.au>
2017-03-03Fix some declarations after codeSteve Bennett1-2/+3
For the benefit of C89 compilers. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2016-11-14dict: Fix [dict values] with duplicate valuesSteve Bennett1-38/+30
The script implementation of dict values was not correctly handling the case where a dictionary had duplicate values. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2016-10-12Array fixes and testsEvan Hunter1-10/+29
Changed 'array exists' to actually check if the variable is an array (matches tclsh) Fix Jim_DictInfo to avoid using printf() and make output match tclsh Added some more tests for array command - checked these work with tclsh
2016-10-09jim.c: Fix Object leak in zlib supportSteve Bennett1-3/+10
Change Jim_SetResultFormatted() to increment/decrement the ref count of any %#s parameters. This allows zero refcount objects to be passed in and be freed automatically. Reported-by: Evan Hunter <evan@ozhiker.com> Signed-off-by: Steve Bennett <steveb@workware.net.au>
2016-10-09Avoid re-defining _GNU_SOURCEEvan Hunter1-0/+2
pkgconfig for SDL causes _GNU_SOURCE to be defined on the commandline, hence causing an error when these source files re-define it.
2016-10-06jim.c: Use UCHAR() with isxxx() functionsSteve Bennett1-1/+1
For systems with signed char Signed-off-by: Steve Bennett <steveb@workware.net.au>
2016-09-29Add support for "-commands" to many commandsSteve Bennett1-15/+52
This option returns a list of support subcommands and is useful for command line completion. Support added to: socket, namespace, tcl::prefix, string, dict, info Signed-off-by: Steve Bennett <steveb@workware.net.au>
2016-09-28jim.c: Replace 'dict with' with a C versionSteve Bennett1-0/+66
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2016-09-28jim.c: replace 'dict merge' with a C versionSteve Bennett1-5/+35
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2016-09-05Fix a crash due to cached local command resolutionSteve Bennett1-1/+1
When a 'local' command is deleted, the proc epoch needs to increase to ensure that subsequent lookups are re-resolved. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2016-09-04Trim bootstrap jimsh0.77Steve Bennett1-7/+5
No need for references support Signed-off-by: Steve Bennett <steveb@workware.net.au>
2016-08-29Fix some minor compiler warnings.Steve Bennett1-7/+5
Mostly from -Wshadow Signed-off-by: Steve Bennett <steveb@workware.net.au>
2016-08-29expr: use fabs() for double abs if --math is specifiedSteve Bennett1-0/+4
Signed-off-by: Steve Bennett <steveb@workware.net.au>
2016-08-28zlib: Fix arg error checkingSteve Bennett1-1/+5
It is wrong to call Jim_WrongNumArgs() with argc == 0. Instead -1 should be returned from the subcmd function to display the standard error message. Add a --maintainer check for this condition in Jim_WrongNumArgs() and fix the zlib unit tests. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2016-08-17Don't unconditionally define _GNU_SOURCESteve Bennett1-3/+10
Also, fix build if JIM_OPTIMIZATION is disabled Signed-off-by: Steve Bennett <steveb@workware.net.au>