diff options
-rw-r--r-- | jim-aio.c | 42 | ||||
-rw-r--r-- | jim-clock.c | 3 | ||||
-rw-r--r-- | jim-eventloop.c | 16 | ||||
-rw-r--r-- | jim-eventloop.h | 18 | ||||
-rw-r--r-- | jim-exec.c | 47 | ||||
-rw-r--r-- | jim-file.c | 17 | ||||
-rw-r--r-- | jim-format.c | 1 | ||||
-rw-r--r-- | jim-history.c | 2 | ||||
-rw-r--r-- | jim-interactive.c | 2 | ||||
-rw-r--r-- | jim-regexp.c | 6 | ||||
-rw-r--r-- | jim-signal.h | 34 | ||||
-rw-r--r-- | jim-subcmd.c | 7 | ||||
-rw-r--r-- | jim-subcmd.h | 4 | ||||
-rw-r--r-- | jim-syslog.c | 1 | ||||
-rw-r--r-- | jim-win32compat.h | 8 | ||||
-rw-r--r-- | jim.c | 366 | ||||
-rw-r--r-- | jim.h | 85 | ||||
-rw-r--r-- | jimregexp.c | 7 | ||||
-rw-r--r-- | jimregexp.h | 26 | ||||
-rw-r--r-- | nshelper.tcl | 6 | ||||
-rw-r--r-- | stdlib.tcl | 2 | ||||
-rw-r--r-- | tclcompat.tcl | 6 | ||||
-rw-r--r-- | utf8.h | 9 |
23 files changed, 334 insertions, 381 deletions
@@ -54,7 +54,6 @@ #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> -#include <unistd.h> #ifdef HAVE_SYS_UN_H #include <sys/un.h> #endif @@ -112,7 +111,7 @@ typedef struct AioFile FILE *fp; Jim_Obj *filename; int type; - int OpenFlags; /* AIO_KEEPOPEN? keep FILE* */ + int openFlags; /* AIO_KEEPOPEN? keep FILE* */ int fd; Jim_Obj *rEvent; Jim_Obj *wEvent; @@ -284,7 +283,7 @@ static void JimAioDelProc(Jim_Interp *interp, void *privData) JIM_NOTUSED(interp); - if (!(af->OpenFlags & AIO_KEEPOPEN)) { + if (!(af->openFlags & AIO_KEEPOPEN)) { fclose(af->fp); } @@ -1023,26 +1022,26 @@ static int JimAioOpenCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { const char *mode; - const char *filename; - if (argc != 2 && argc != 3) { + if (argc != 2 && argc != 3) Jim_WrongNumArgs(interp, 1, argv, "filename ?mode?"); - return JIM_ERR; - } mode = (argc == 3) ? Jim_String(argv[2]) : "r"; - filename = Jim_String(argv[1]); #ifdef jim_ext_tclcompat - /* If the filename starts with '|', use popen instead */ - if (*filename == '|') { - Jim_Obj *evalObj[3]; + { + const char *filename = Jim_String(argv[1]); + + /* If the filename starts with '|', use popen instead */ + if (*filename == '|') { + Jim_Obj *evalObj[3]; - evalObj[0] = Jim_NewStringObj(interp, "::popen", -1); - evalObj[1] = Jim_NewStringObj(interp, filename + 1, -1); - evalObj[2] = Jim_NewStringObj(interp, mode, -1); + evalObj[0] = Jim_NewStringObj(interp, "::popen", -1); + evalObj[1] = Jim_NewStringObj(interp, filename + 1, -1); + evalObj[2] = Jim_NewStringObj(interp, mode, -1); - return Jim_EvalObjVector(interp, 3, evalObj); + return Jim_EvalObjVector(interp, 3, evalObj); + } } #endif return JimMakeChannel(interp, NULL, -1, argv[1], "aio.handle%ld", 0, mode); @@ -1051,8 +1050,8 @@ static int JimAioOpenCommand(Jim_Interp *interp, int argc, /** * Creates a channel for fh/fd/filename. * - * If fh is not NULL, uses that as the channel (and set AIO_KEEPOPEN). - * Otherwise, if fd is >= 0, uses that as the chanel. + * If fh is not NULL, uses that as the channel (and sets AIO_KEEPOPEN). + * Otherwise, if fd is >= 0, uses that as the channel. * Otherwise opens 'filename' with mode 'mode'. * * hdlfmt is a sprintf format for the filehandle. Anything with %ld at the end will do. @@ -1065,11 +1064,11 @@ static int JimMakeChannel(Jim_Interp *interp, FILE *fh, int fd, Jim_Obj *filenam { AioFile *af; char buf[AIO_CMD_LEN]; - int OpenFlags = 0; + int openFlags = 0; if (fh) { filename = Jim_NewStringObj(interp, hdlfmt, -1); - OpenFlags = AIO_KEEPOPEN; + openFlags = AIO_KEEPOPEN; } Jim_IncrRefCount(filename); @@ -1102,11 +1101,11 @@ static int JimMakeChannel(Jim_Interp *interp, FILE *fh, int fd, Jim_Obj *filenam af->fd = fileno(fh); af->filename = filename; #ifdef FD_CLOEXEC - if ((OpenFlags & AIO_KEEPOPEN) == 0) { + if ((openFlags & AIO_KEEPOPEN) == 0) { fcntl(af->fd, F_SETFD, FD_CLOEXEC); } #endif - af->OpenFlags = OpenFlags; + af->openFlags = openFlags; af->addr_family = family; snprintf(buf, sizeof(buf), hdlfmt, Jim_GetId(interp)); Jim_CreateCommand(interp, buf, JimAioSubCmdProc, af, JimAioDelProc); @@ -1413,6 +1412,7 @@ FILE *Jim_AioFilehandle(Jim_Interp *interp, Jim_Obj *command) { Jim_Cmd *cmdPtr = Jim_GetCommand(interp, command, JIM_ERRMSG); + /* XXX: There ought to be a supported API for this */ if (cmdPtr && !cmdPtr->isproc && cmdPtr->u.native.cmdProc == JimAioSubCmdProc) { return ((AioFile *) cmdPtr->u.native.privData)->fp; } diff --git a/jim-clock.c b/jim-clock.c index 97f73b4..69fb966 100644 --- a/jim-clock.c +++ b/jim-clock.c @@ -1,6 +1,5 @@ - /* - * tcl_clock.c + * jim-clock.c * * Implements the clock command */ diff --git a/jim-eventloop.c b/jim-eventloop.c index 936103b..22ca5ff 100644 --- a/jim-eventloop.c +++ b/jim-eventloop.c @@ -1,4 +1,3 @@ - /* Jim - A small embeddable Tcl interpreter * * Copyright 2005 Salvatore Sanfilippo <antirez@invece.org> @@ -84,8 +83,7 @@ typedef struct Jim_FileEvent typedef struct Jim_TimeEvent { jim_wide id; /* time event identifier. */ - int mode; /* restart, repetitive .. UK */ - long initialms; /* initial relativ timer value UK */ + long initialms; /* initial relative timer value */ jim_wide when; /* milliseconds */ Jim_TimeProc *timeProc; Jim_EventFinalizerProc *finalizerProc; @@ -207,7 +205,6 @@ jim_wide Jim_CreateTimeHandler(Jim_Interp *interp, jim_wide milliseconds, te = Jim_Alloc(sizeof(*te)); te->id = id; - te->mode = 0; te->initialms = milliseconds; te->when = JimGetTime(eventLoop) + milliseconds; te->timeProc = proc; @@ -323,17 +320,16 @@ jim_wide Jim_DeleteTimeHandler(Jim_Interp *interp, jim_wide id) /* Process every pending time event, then every pending file event * (that may be registered by time event callbacks just processed). - * Without special flags the function sleeps until some file event - * fires, or when the next time event occurrs (if any). + * The behaviour depends upon the setting of flags: * * If flags is 0, the function does nothing and returns. - * if flags has JIM_ALL_EVENTS set, all the kind of events are processed. + * if flags has JIM_ALL_EVENTS set, all event types are processed. * if flags has JIM_FILE_EVENTS set, file events are processed. * if flags has JIM_TIME_EVENTS set, time events are processed. - * if flags has JIM_DONT_WAIT set the function returns ASAP until all - * the events that's possible to process without to wait are processed. + * if flags has JIM_DONT_WAIT set, the function returns as soon as all + * the events that are possible to process without waiting are processed. * - * The function returns the number of events processed or -1 if + * Returns the number of events processed or -1 if * there are no matching handlers, or -2 on error. */ int Jim_ProcessEvents(Jim_Interp *interp, int flags) diff --git a/jim-eventloop.h b/jim-eventloop.h index 52ec4e8..3e20e6f 100644 --- a/jim-eventloop.h +++ b/jim-eventloop.h @@ -36,20 +36,18 @@ * are those of the authors and should not be interpreted as representing * official policies, either expressed or implied, of the Jim Tcl Project. **/ + /* ------ USAGE ------- - * - * In order to use this file from other extensions include it in every - * file where you need to call the eventloop API, also in the init - * function of your extension call Jim_ImportEventloopAPI(interp) - * after the Jim_InitExtension() call. - * - * See the UDP extension as example. + * See jim-aio.c as an example of an event provider. */ - #ifndef __JIM_EVENTLOOP_H__ #define __JIM_EVENTLOOP_H__ +#ifdef __cplusplus +extern "C" { +#endif + #include <stdio.h> typedef int Jim_FileProc(Jim_Interp *interp, void *clientData, int mask); @@ -84,4 +82,8 @@ JIM_EXPORT int Jim_EvalObjBackground (Jim_Interp *interp, Jim_Obj *scriptObjPtr) int Jim_eventloopInit(Jim_Interp *interp); +#ifdef __cplusplus +} +#endif + #endif /* __JIM_EVENTLOOP_H__ */ @@ -81,6 +81,7 @@ int Jim_execInit(Jim_Interp *interp) { if (Jim_PackageProvide(interp, "exec", "1.0", JIM_ERRMSG)) return JIM_ERR; + Jim_CreateCommand(interp, "exec", Jim_ExecCmd, NULL, NULL); return JIM_OK; } @@ -239,6 +240,7 @@ static char **JimBuildEnv(Jim_Interp *interp) /* Calculate the required size */ num = Jim_ListLength(interp, objPtr); if (num % 2) { + /* Silently drop the last element if not a valid dictionary */ num--; } /* We need one \0 and one equal sign for each element. @@ -284,10 +286,10 @@ static void JimFreeEnv(char **env, char **original_environ) } /* - * Create error messages for unusual process exits. An - * extra newline gets appended to each error message, but - * it gets removed below (in the same fashion that an - * extra newline in the command's output is removed). + * Create and store an appropriate value for the global variable $::errorCode + * Based on pid and waitStatus. + * + * Returns JIM_OK for a normal exit with code 0, otherwise returns JIM_ERR. */ static int JimCheckWaitStatus(Jim_Interp *interp, pidtype pid, int waitStatus) { @@ -343,15 +345,15 @@ static int JimCheckWaitStatus(Jim_Interp *interp, pidtype pid, int waitStatus) struct WaitInfo { - pidtype pid; /* Process id of child. */ + pidtype pid; /* Process id of child. */ int status; /* Status returned when child exited or suspended. */ int flags; /* Various flag bits; see below for definitions. */ }; struct WaitInfoTable { - struct WaitInfo *info; - int size; - int used; + struct WaitInfo *info; /* Table of outstanding processes */ + int size; /* Size of the allocated table */ + int used; /* Number of entries in use */ }; /* @@ -388,15 +390,13 @@ static struct WaitInfoTable *JimAllocWaitInfoTable(void) */ static int Jim_ExecCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { - fdtype outputId; /* File id for output pipe. -1 - * means command overrode. */ - fdtype errorId; /* File id for temporary file - * containing error output. */ + fdtype outputId; /* File id for output pipe. -1 means command overrode. */ + fdtype errorId; /* File id for temporary file containing error output. */ pidtype *pidPtr; int numPids, result; /* - * See if the command is to be run in background; if so, create + * See if the command is to be run in the background; if so, create * the command, detach it, and return. */ if (argc > 1 && Jim_CompareStringImmediate(interp, argv[argc - 1], "&")) { @@ -507,24 +507,11 @@ static pidtype JimWaitForProcess(struct WaitInfoTable *table, pidtype pid, int * return JIM_BAD_PID; } -/* - *---------------------------------------------------------------------- - * - * JimDetachPids -- - * - * This procedure is called to indicate that one or more child - * processes have been placed in background and are no longer - * cared about. These children can be cleaned up with JimReapDetachedPids(). - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- +/** + * Indicates that one or more child processes have been placed in + * background and are no longer cared about. + * These children can be cleaned up with JimReapDetachedPids(). */ - static void JimDetachPids(Jim_Interp *interp, int numPids, const pidtype *pidPtr) { int j; @@ -351,10 +351,7 @@ static int file_cmd_join(Jim_Interp *interp, int argc, Jim_Obj *const *argv) static int file_access(Jim_Interp *interp, Jim_Obj *filename, int mode) { - const char *path = Jim_String(filename); - int rc = access(path, mode); - - Jim_SetResultBool(interp, rc != -1); + Jim_SetResultBool(interp, access(Jim_String(filename), mode) != -1); return JIM_OK; } @@ -374,9 +371,7 @@ static int file_cmd_executable(Jim_Interp *interp, int argc, Jim_Obj *const *arg #ifdef X_OK return file_access(interp, argv[0], X_OK); #else - /* XXX: X_OK doesn't work under Windows. - * In any case, may need to add .exe, etc. so just lie! - */ + /* If no X_OK, just assume true. */ Jim_SetResultBool(interp, 1); return JIM_OK; #endif @@ -930,11 +925,11 @@ static int Jim_CdCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv) static int Jim_PwdCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { - const int cwd_len = 2048; - char *cwd = malloc(cwd_len); + char *cwd = Jim_Alloc(MAXPATHLEN); - if (getcwd(cwd, cwd_len) == NULL) { + if (getcwd(cwd, MAXPATHLEN) == NULL) { Jim_SetResultString(interp, "Failed to get pwd", -1); + Jim_Free(cwd); return JIM_ERR; } #if defined(__MINGW32__) || defined(_MSC_VER) @@ -949,7 +944,7 @@ static int Jim_PwdCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv) Jim_SetResultString(interp, cwd, -1); - free(cwd); + Jim_Free(cwd); return JIM_OK; } diff --git a/jim-format.c b/jim-format.c index 9ea0b51..dc6f8ae 100644 --- a/jim-format.c +++ b/jim-format.c @@ -45,7 +45,6 @@ #include <jim.h> #include "utf8.h" -#define JIM_UTF_MAX 3 #define JIM_INTEGER_SPACE 24 #define MAX_FLOAT_WIDTH 320 diff --git a/jim-history.c b/jim-history.c index 370769d..9a56e04 100644 --- a/jim-history.c +++ b/jim-history.c @@ -11,7 +11,7 @@ static int history_cmd_getline(Jim_Interp *interp, int argc, Jim_Obj *const *arg Jim_Obj *objPtr; char *line = Jim_HistoryGetline(Jim_String(argv[0])); - /* On EOF returns -1 if varName was specified, or the empty string. */ + /* On EOF returns -1 if varName was specified; otherwise the empty string. */ if (line == NULL) { if (argc == 2) { Jim_SetResultInt(interp, -1); diff --git a/jim-interactive.c b/jim-interactive.c index 17e43d2..f07eea1 100644 --- a/jim-interactive.c +++ b/jim-interactive.c @@ -87,7 +87,7 @@ int Jim_InteractivePrompt(Jim_Interp *interp) } #endif - printf("Welcome to Jim version %d.%d" JIM_NL, + printf("Welcome to Jim version %d.%d\n", JIM_VERSION / 100, JIM_VERSION % 100); Jim_SetVariableStrWithStr(interp, JIM_INTERACTIVE, "1"); diff --git a/jim-regexp.c b/jim-regexp.c index de28b93..25ffd21 100644 --- a/jim-regexp.c +++ b/jim-regexp.c @@ -49,8 +49,12 @@ #include <string.h> #include "jimautoconf.h" +#if defined(JIM_REGEXP) + #include "jimregexp.h" +#else + #include <regex.h> +#endif #include "jim.h" -#include "jimregexp.h" static void FreeRegexpInternalRep(Jim_Interp *interp, Jim_Obj *objPtr) { diff --git a/jim-signal.h b/jim-signal.h index 92e080d..84dcd8b 100644 --- a/jim-signal.h +++ b/jim-signal.h @@ -1,24 +1,26 @@ #ifndef JIM_SIGNAL_H #define JIM_SIGNAL_H -/* - *---------------------------------------------------------------------- - * - * Tcl_SignalId -- - * - * Return a textual identifier for a signal number. - * - * Results: - * This procedure returns a machine-readable textual identifier - * that corresponds to sig. The identifier is the same as the - * #define name in signal.h. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Returns the canonical name for the given signal, + * e.g. "SIGTERM", "SIGINT" */ const char *Jim_SignalId(int sig); + +/** + * If available, returns a short description of the given signal. + * e.g. "Terminated", "Interrupted" + * + * Otherwise returns the same as Jim_SignalId() + */ const char *Jim_SignalName(int sig); +#ifdef __cplusplus +} +#endif + #endif diff --git a/jim-subcmd.c b/jim-subcmd.c index bd6e050..c522830 100644 --- a/jim-subcmd.c +++ b/jim-subcmd.c @@ -1,3 +1,10 @@ +/* + * Makes it easy to support "ensembles". i.e. commands with subcommands + * like [string] and [array] + * + * (c) 2008 Steve Bennett <steveb@workware.net.au> + * + */ #include <stdio.h> #include <string.h> diff --git a/jim-subcmd.h b/jim-subcmd.h index f10f5f6..ab30f37 100644 --- a/jim-subcmd.h +++ b/jim-subcmd.h @@ -20,12 +20,12 @@ extern "C" { * Returns JIM_OK if OK, JIM_ERR (etc.) on error, break, continue, etc. * Returns -1 if invalid args. */ -typedef int tclmod_cmd_function(Jim_Interp *interp, int argc, Jim_Obj *const *argv); +typedef int jim_subcmd_function(Jim_Interp *interp, int argc, Jim_Obj *const *argv); typedef struct { const char *cmd; /* Name of the (sub)command */ const char *args; /* Textual description of allowed args */ - tclmod_cmd_function *function; /* Function implementing the subcommand */ + jim_subcmd_function *function; /* Function implementing the subcommand */ short minargs; /* Minimum required arguments */ short maxargs; /* Maximum allowed arguments or -1 if no limit */ unsigned short flags; /* JIM_MODFLAG_... plus custom flags */ diff --git a/jim-syslog.c b/jim-syslog.c index bd373b8..9e279ef 100644 --- a/jim-syslog.c +++ b/jim-syslog.c @@ -1,4 +1,3 @@ - /* Syslog interface for tcl * Copyright Victor Wagner <vitus@ice.ru> at * http://www.ice.ru/~vitus/works/tcl.html#syslog diff --git a/jim-win32compat.h b/jim-win32compat.h index 080cda0..23a3dfe 100644 --- a/jim-win32compat.h +++ b/jim-win32compat.h @@ -3,6 +3,10 @@ /* Compatibility for Windows (mingw and msvc, not cygwin */ +#ifdef __cplusplus +extern "C" { +#endif + /* Note that at this point we don't yet have access to jimautoconf.h */ #if defined(_WIN32) || defined(WIN32) @@ -70,4 +74,8 @@ struct dirent *readdir(DIR *dir); #endif /* WIN32 */ +#ifdef __cplusplus +} +#endif + #endif @@ -126,7 +126,6 @@ static char JimEmptyStringRep[] = ""; /* ----------------------------------------------------------------------------- * Required prototypes of not exported functions * ---------------------------------------------------------------------------*/ -static void JimChangeCallFrameId(Jim_Interp *interp, Jim_CallFrame *cf); static void JimFreeCallFrame(Jim_Interp *interp, Jim_CallFrame *cf, int action); static int ListSetIndex(Jim_Interp *interp, Jim_Obj *listPtr, int listindex, Jim_Obj *newObjPtr, int flags); @@ -578,7 +577,7 @@ static jim_wide JimPowWide(jim_wide b, jim_wide e) * Special functions * ---------------------------------------------------------------------------*/ #ifdef JIM_DEBUG_PANIC -void JimPanicDump(int condition, const char *fmt, ...) +static void JimPanicDump(int condition, const char *fmt, ...) { va_list ap; @@ -588,9 +587,9 @@ void JimPanicDump(int condition, const char *fmt, ...) va_start(ap, fmt); - fprintf(stderr, JIM_NL "JIM INTERPRETER PANIC: "); + fprintf(stderr, "\nJIM INTERPRETER PANIC: "); vfprintf(stderr, fmt, ap); - fprintf(stderr, JIM_NL JIM_NL); + fprintf(stderr, "\n\n"); va_end(ap); #ifdef HAVE_BACKTRACE @@ -602,9 +601,9 @@ void JimPanicDump(int condition, const char *fmt, ...) size = backtrace(array, 40); strings = backtrace_symbols(array, size); for (i = 0; i < size; i++) - fprintf(stderr, "[backtrace] %s" JIM_NL, strings[i]); - fprintf(stderr, "[backtrace] Include the above lines and the output" JIM_NL); - fprintf(stderr, "[backtrace] of 'nm <executable>' in the bug report." JIM_NL); + fprintf(stderr, "[backtrace] %s\n", strings[i]); + fprintf(stderr, "[backtrace] Include the above lines and the output\n"); + fprintf(stderr, "[backtrace] of 'nm <executable>' in the bug report.\n"); } #endif @@ -3838,8 +3837,8 @@ static int JimCreateCommand(Jim_Interp *interp, const char *name, Jim_Cmd *cmd) if (he && interp->local) { /* Push this command over the top of the previous one */ - cmd->prevCmd = he->u.val; - he->u.val = cmd; + cmd->prevCmd = Jim_GetHashEntryVal(he); + Jim_SetHashVal(&interp->commands, he, cmd); } else { if (he) { @@ -3882,17 +3881,17 @@ static int JimCreateProcedureStatics(Jim_Interp *interp, Jim_Cmd *cmdPtr, Jim_Ob cmdPtr->u.proc.staticVars = Jim_Alloc(sizeof(Jim_HashTable)); Jim_InitHashTable(cmdPtr->u.proc.staticVars, &JimVariablesHashTableType, interp); for (i = 0; i < len; i++) { - Jim_Obj *objPtr = NULL, *initObjPtr = NULL, *nameObjPtr = NULL; + Jim_Obj *objPtr, *initObjPtr, *nameObjPtr; Jim_Var *varPtr; int subLen; - Jim_ListIndex(interp, staticsListObjPtr, i, &objPtr, JIM_NONE); + objPtr = Jim_ListGetIndex(interp, staticsListObjPtr, i); /* Check if it's composed of two elements. */ subLen = Jim_ListLength(interp, objPtr); if (subLen == 1 || subLen == 2) { /* Try to get the variable value from the current * environment. */ - Jim_ListIndex(interp, objPtr, 0, &nameObjPtr, JIM_NONE); + nameObjPtr = Jim_ListGetIndex(interp, objPtr, 0); if (subLen == 1) { initObjPtr = Jim_GetVariable(interp, nameObjPtr, JIM_NONE); if (initObjPtr == NULL) { @@ -3903,7 +3902,7 @@ static int JimCreateProcedureStatics(Jim_Interp *interp, Jim_Cmd *cmdPtr, Jim_Ob } } else { - Jim_ListIndex(interp, objPtr, 1, &initObjPtr, JIM_NONE); + initObjPtr = Jim_ListGetIndex(interp, objPtr, 1); } if (JimValidName(interp, "static variable", nameObjPtr) != JIM_OK) { return JIM_ERR; @@ -3989,7 +3988,7 @@ static Jim_Cmd *JimCreateProcedureCmd(Jim_Interp *interp, Jim_Obj *argListObjPtr int len; /* Examine a parameter */ - Jim_ListIndex(interp, argListObjPtr, i, &argPtr, JIM_NONE); + argPtr = Jim_ListGetIndex(interp, argListObjPtr, i); len = Jim_ListLength(interp, argPtr); if (len == 0) { Jim_SetResultString(interp, "argument with no name", -1); @@ -4004,8 +4003,8 @@ err: if (len == 2) { /* Optional parameter */ - Jim_ListIndex(interp, argPtr, 0, &nameObjPtr, JIM_NONE); - Jim_ListIndex(interp, argPtr, 1, &defaultObjPtr, JIM_NONE); + nameObjPtr = Jim_ListGetIndex(interp, argPtr, 0); + defaultObjPtr = Jim_ListGetIndex(interp, argPtr, 1); } else { /* Required parameter */ @@ -4083,7 +4082,7 @@ int Jim_RenameCommand(Jim_Interp *interp, const char *oldName, const char *newNa } else { /* Add the new name first */ - cmdPtr = he->u.val; + cmdPtr = Jim_GetHashEntryVal(he); JimIncrCmdRefCount(cmdPtr); JimUpdateProcNamespace(interp, cmdPtr, fqnew); Jim_AddHashEntry(&interp->commands, fqnew, cmdPtr); @@ -4182,7 +4181,7 @@ Jim_Cmd *Jim_GetCommand(Jim_Interp *interp, Jim_Obj *objPtr, int flags) #ifdef jim_ext_namespace found: #endif - cmd = (Jim_Cmd *)he->u.val; + cmd = Jim_GetHashEntryVal(he); /* Free the old internal repr and set the new one. */ Jim_FreeIntRep(interp, objPtr); @@ -4305,7 +4304,7 @@ static int SetVariableFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr) Jim_FreeIntRep(interp, objPtr); objPtr->typePtr = &variableObjType; objPtr->internalRep.varValue.callFrameId = framePtr->id; - objPtr->internalRep.varValue.varPtr = he->u.val; + objPtr->internalRep.varValue.varPtr = Jim_GetHashEntryVal(he); objPtr->internalRep.varValue.global = global; return JIM_OK; } @@ -4641,7 +4640,7 @@ int Jim_UnsetVariable(Jim_Interp *interp, Jim_Obj *nameObjPtr, int flags) retval = Jim_DeleteHashEntry(&framePtr->vars, name); if (retval == JIM_OK) { /* Change the callframe id, invalidating var lookup caching */ - JimChangeCallFrameId(interp, framePtr); + framePtr->id = interp->callFrameEpoch++; } } } @@ -4884,12 +4883,6 @@ static Jim_CallFrame *JimCreateCallFrame(Jim_Interp *interp, Jim_CallFrame *pare return cf; } -/* Used to invalidate every caching related to callframe stability. */ -static void JimChangeCallFrameId(Jim_Interp *interp, Jim_CallFrame *cf) -{ - cf->id = interp->callFrameEpoch++; -} - static int JimDeleteLocalProcs(Jim_Interp *interp, Jim_Stack *localCommands) { /* Delete any local procs */ @@ -4899,13 +4892,14 @@ static int JimDeleteLocalProcs(Jim_Interp *interp, Jim_Stack *localCommands) while ((cmdNameObj = Jim_StackPop(localCommands)) != NULL) { Jim_HashEntry *he; Jim_Obj *fqObjName; + Jim_HashTable *ht = &interp->commands; const char *fqname = JimQualifyName(interp, Jim_String(cmdNameObj), &fqObjName); - he = Jim_FindHashEntry(&interp->commands, fqname); + he = Jim_FindHashEntry(ht, fqname); if (he) { - Jim_Cmd *cmd = he->u.val; + Jim_Cmd *cmd = Jim_GetHashEntryVal(he); if (cmd->prevCmd) { Jim_Cmd *prevCmd = cmd->prevCmd; cmd->prevCmd = NULL; @@ -4914,10 +4908,10 @@ static int JimDeleteLocalProcs(Jim_Interp *interp, Jim_Stack *localCommands) JimDecrCmdRefCount(interp, cmd); /* And restore the original */ - he->u.val = prevCmd; + Jim_SetHashVal(ht, he, prevCmd); } else { - Jim_DeleteHashEntry(&interp->commands, fqname); + Jim_DeleteHashEntry(ht, fqname); Jim_InterpIncrProcEpoch(interp); } } @@ -4952,11 +4946,11 @@ static void JimFreeCallFrame(Jim_Interp *interp, Jim_CallFrame *cf, int action) he = table[i]; while (he != NULL) { Jim_HashEntry *nextEntry = he->next; - Jim_Var *varPtr = (void *)he->u.val; + Jim_Var *varPtr = Jim_GetHashEntryVal(he); Jim_DecrRefCount(interp, varPtr->objPtr); - Jim_Free(he->u.val); - Jim_Free((void *)he->key); /* ATTENTION: const cast */ + Jim_Free(Jim_GetHashEntryKey(he)); + Jim_Free(varPtr); Jim_Free(he); table[i] = NULL; he = nextEntry; @@ -5040,7 +5034,7 @@ static const Jim_HashTableType JimReferencesHashTableType = { * to make the GC faster. The first is that every reference starts * with a non common character '<', in order to make the string matching * faster. The second is that the reference string rep is 42 characters - * in length, this allows to avoid to check every object with a string + * in length, this means that it is not necessary to check any object with a string * repr < 42, and usually there aren't many of these objects. */ #define JIM_REFERENCE_SPACE (35+JIM_REFERENCE_TAGLEN) @@ -5063,7 +5057,7 @@ static const Jim_ObjType referenceObjType = { JIM_TYPE_REFERENCES, }; -void UpdateStringOfReference(struct Jim_Obj *objPtr) +static void UpdateStringOfReference(struct Jim_Obj *objPtr) { char buf[JIM_REFERENCE_SPACE + 1]; @@ -5125,7 +5119,7 @@ static int SetReferenceFromAny(Jim_Interp *interp, Jim_Obj *objPtr) Jim_SetResultFormatted(interp, "invalid reference id \"%#s\"", objPtr); return JIM_ERR; } - refPtr = he->u.val; + refPtr = Jim_GetHashEntryVal(he); /* Free the old internal repr and set the new one. */ Jim_FreeIntRep(interp, objPtr); objPtr->typePtr = &referenceObjType; @@ -5257,7 +5251,7 @@ int Jim_Collect(Jim_Interp *interp) if (objPtr->typePtr == &referenceObjType) { Jim_AddHashEntry(&marks, &objPtr->internalRep.refValue.id, NULL); #ifdef JIM_DEBUG_GC - printf("MARK (reference): %d refcount: %d" JIM_NL, + printf("MARK (reference): %d refcount: %d\n", (int)objPtr->internalRep.refValue.id, objPtr->refCount); #endif objPtr = objPtr->nextObjPtr; @@ -5293,7 +5287,7 @@ int Jim_Collect(Jim_Interp *interp) * was found. Mark it. */ Jim_AddHashEntry(&marks, &id, NULL); #ifdef JIM_DEBUG_GC - printf("MARK: %d" JIM_NL, (int)id); + printf("MARK: %d\n", (int)id); #endif p += JIM_REFERENCE_SPACE; } @@ -5313,12 +5307,12 @@ int Jim_Collect(Jim_Interp *interp) * this reference. */ if (Jim_FindHashEntry(&marks, refId) == NULL) { #ifdef JIM_DEBUG_GC - printf("COLLECTING %d" JIM_NL, (int)*refId); + printf("COLLECTING %d\n", (int)*refId); #endif collected++; /* Drop the reference, but call the * finalizer first if registered. */ - refPtr = he->u.val; + refPtr = Jim_GetHashEntryVal(he); if (refPtr->finalizerCmdNamePtr) { char *refstr = Jim_Alloc(JIM_REFERENCE_SPACE + 1); Jim_Obj *objv[3], *oldResult; @@ -5478,30 +5472,29 @@ void Jim_FreeInterp(Jim_Interp *i) * there is a memory leak. */ #ifdef JIM_MAINTAINER if (i->liveList != NULL) { - printf(JIM_NL "-------------------------------------" JIM_NL); - printf("Objects still in the free list:" JIM_NL); - objPtr = i->liveList; + printf("\n-------------------------------------\n"); + printf("Objects still in the free list:\n"); while (objPtr) { const char *type = objPtr->typePtr ? objPtr->typePtr->name : "string"; if (objPtr->bytes && strlen(objPtr->bytes) > 20) { - printf("%p (%d) %-10s: '%.20s...'" JIM_NL, + printf("%p (%d) %-10s: '%.20s...'\n", (void *)objPtr, objPtr->refCount, type, objPtr->bytes); } else { - printf("%p (%d) %-10s: '%s'" JIM_NL, + printf("%p (%d) %-10s: '%s'\n", (void *)objPtr, objPtr->refCount, type, objPtr->bytes ? objPtr->bytes : "(null)"); } if (objPtr->typePtr == &sourceObjType) { - printf("FILE %s LINE %d" JIM_NL, + printf("FILE %s LINE %d\n", Jim_String(objPtr->internalRep.sourceValue.fileNameObj), objPtr->internalRep.sourceValue.lineNumber); } objPtr = objPtr->nextObjPtr; } - printf("-------------------------------------" JIM_NL JIM_NL); + printf("-------------------------------------\n\n"); JimPanic((1, "Live list non empty freeing the interpreter! Leak?")); } #endif @@ -5519,16 +5512,15 @@ void Jim_FreeInterp(Jim_Interp *i) } /* Returns the call frame relative to the level represented by - * levelObjPtr. If levelObjPtr == NULL, the * level is assumed to be '1'. + * levelObjPtr. If levelObjPtr == NULL, the level is assumed to be '1'. * * This function accepts the 'level' argument in the form * of the commands [uplevel] and [upvar]. * - * For a function accepting a relative integer as level suitable - * for implementation of [info level ?level?] check the - * JimGetCallFrameByInteger() function. - * * Returns NULL on error. + * + * Note: for a function accepting a relative integer as level suitable + * for implementation of [info level ?level?], see JimGetCallFrameByInteger() */ Jim_CallFrame *Jim_GetCallFrameByLevel(Jim_Interp *interp, Jim_Obj *levelObjPtr) { @@ -5636,7 +5628,6 @@ static void JimSetStackTrace(Jim_Interp *interp, Jim_Obj *stackTraceObj) } } -/* Returns 1 if the stack trace information was used or 0 if not */ static void JimAppendStackTrace(Jim_Interp *interp, const char *procname, Jim_Obj *fileNameObj, int linenr) { @@ -5694,8 +5685,7 @@ void *Jim_GetAssocData(Jim_Interp *interp, const char *key) Jim_HashEntry *entryPtr = Jim_FindHashEntry(&interp->assocData, key); if (entryPtr != NULL) { - AssocDataValue *assocEntryPtr = (AssocDataValue *) entryPtr->u.val; - + AssocDataValue *assocEntryPtr = Jim_GetHashEntryVal(entryPtr); return assocEntryPtr->data; } return NULL; @@ -5775,7 +5765,7 @@ static void UpdateStringOfInt(struct Jim_Obj *objPtr) JimSetStringBytes(objPtr, buf); } -int SetIntFromAny(Jim_Interp *interp, Jim_Obj *objPtr, int flags) +static int SetIntFromAny(Jim_Interp *interp, Jim_Obj *objPtr, int flags) { jim_wide wideValue; const char *str; @@ -5879,7 +5869,7 @@ static const Jim_ObjType doubleObjType = { #define isinf(X) (1.0 / (X) == 0.0) #endif -void UpdateStringOfDouble(struct Jim_Obj *objPtr) +static void UpdateStringOfDouble(struct Jim_Obj *objPtr) { double value = objPtr->internalRep.doubleValue; @@ -5927,7 +5917,7 @@ void UpdateStringOfDouble(struct Jim_Obj *objPtr) } } -int SetDoubleFromAny(Jim_Interp *interp, Jim_Obj *objPtr) +static int SetDoubleFromAny(Jim_Interp *interp, Jim_Obj *objPtr) { double doubleValue; jim_wide wideValue; @@ -6542,7 +6532,7 @@ static void ListRemoveDuplicates(Jim_Obj *listObjPtr, int (*comp)(Jim_Obj **lhs, listObjPtr->internalRep.listValue.len = dst; } -/* Sort a list *in place*. MUST be called with non-shared objects. */ +/* Sort a list *in place*. MUST be called with a non-shared list. */ static int ListSortElements(Jim_Interp *interp, Jim_Obj *listObjPtr, struct lsort_info *info) { struct lsort_info *prev_info; @@ -6553,7 +6543,7 @@ static int ListSortElements(Jim_Interp *interp, Jim_Obj *listObjPtr, struct lsor int len; int rc; - JimPanic((Jim_IsShared(listObjPtr), "Jim_ListSortElements called with shared object")); + JimPanic((Jim_IsShared(listObjPtr), "ListSortElements called with shared object")); SetListFromAny(interp, listObjPtr); /* Allow lsort to be called reentrantly */ @@ -6605,7 +6595,7 @@ static int ListSortElements(Jim_Interp *interp, Jim_Obj *listObjPtr, struct lsor /* This is the low-level function to insert elements into a list. * The higher-level Jim_ListInsertElements() performs shared object - * check and invalidate the string repr. This version is used + * check and invalidates the string repr. This version is used * in the internals of the List Object and is not exported. * * NOTE: this function can be called only against objects @@ -6742,10 +6732,10 @@ static int ListSetIndex(Jim_Interp *interp, Jim_Obj *listPtr, int idx, return JIM_OK; } -/* Modify the list stored into the variable named 'varNamePtr' +/* Modify the list stored in the variable named 'varNamePtr' * setting the element specified by the 'indexc' indexes objects in 'indexv', - * with the new element 'newObjptr'. */ -int Jim_SetListIndex(Jim_Interp *interp, Jim_Obj *varNamePtr, + * with the new element 'newObjptr'. (implements the [lset] command) */ +int Jim_ListSetIndex(Jim_Interp *interp, Jim_Obj *varNamePtr, Jim_Obj *const *indexv, int indexc, Jim_Obj *newObjPtr) { Jim_Obj *varObjPtr, *objPtr, *listObjPtr; @@ -6793,10 +6783,7 @@ Jim_Obj *Jim_ListJoin(Jim_Interp *interp, Jim_Obj *listObjPtr, const char *joinS Jim_Obj *resObjPtr = Jim_NewEmptyStringObj(interp); for (i = 0; i < listLen; ) { - Jim_Obj *objPtr; - - Jim_ListIndex(interp, listObjPtr, i, &objPtr, JIM_NONE); - Jim_AppendObj(interp, resObjPtr, objPtr); + Jim_AppendObj(interp, resObjPtr, Jim_ListGetIndex(interp, listObjPtr, i)); if (++i != listLen) { Jim_AppendString(interp, resObjPtr, joinStr, joinStrLen); } @@ -6829,8 +6816,7 @@ Jim_Obj *Jim_ConcatObj(Jim_Interp *interp, int objc, Jim_Obj *const *objv) /* Compute the length */ for (i = 0; i < objc; i++) { - Jim_GetString(objv[i], &objLen); - len += objLen; + len += Jim_Length(objv[i]); } if (objc) len += objc - 1; @@ -6840,14 +6826,13 @@ Jim_Obj *Jim_ConcatObj(Jim_Interp *interp, int objc, Jim_Obj *const *objv) const char *s = Jim_GetString(objv[i], &objLen); /* Remove leading space */ - while (objLen && (*s == ' ' || *s == '\t' || *s == '\n')) { + while (objLen && isspace(UCHAR(*s))) { s++; objLen--; len--; } /* And trailing space */ - while (objLen && (s[objLen - 1] == ' ' || - s[objLen - 1] == '\n' || s[objLen - 1] == '\t')) { + while (objLen && isspace(UCHAR(s[objLen - 1]))) { /* Handle trailing backslash-space case */ if (objLen > 1 && s[objLen - 2] == '\\') { break; @@ -6857,13 +6842,14 @@ Jim_Obj *Jim_ConcatObj(Jim_Interp *interp, int objc, Jim_Obj *const *objv) } memcpy(p, s, objLen); p += objLen; - if (objLen && i + 1 != objc) { - *p++ = ' '; - } - else if (i + 1 != objc) { - /* Drop the space calcuated for this - * element that is instead null. */ - len--; + if (i + 1 != objc) { + if (objLen) + *p++ = ' '; + else { + /* Drop the space calcuated for this + * element that is instead null. */ + len--; + } } } *p = '\0'; @@ -6994,8 +6980,8 @@ static Jim_Obj **JimDictPairs(Jim_Obj *dictPtr, int *len) JimInitHashTableIterator(ht, &htiter); i = 0; while ((he = Jim_NextHashEntry(&htiter)) != NULL) { - objv[i++] = (Jim_Obj *)he->key; - objv[i++] = he->u.val; + objv[i++] = Jim_GetHashEntryKey(he); + objv[i++] = Jim_GetHashEntryVal(he); } *len = i; return objv; @@ -7007,6 +6993,7 @@ static void UpdateStringOfDict(struct Jim_Obj *objPtr) int len; Jim_Obj **objv = JimDictPairs(objPtr, &len); + /* And now generate the string rep as a list */ JimMakeListStringRep(objPtr, objv, len); Jim_Free(objv); @@ -7034,7 +7021,7 @@ static int SetDictFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr) return JIM_ERR; } else { - /* Now it is easy to convert to a dict from a list, and it can't fail */ + /* Converting from a list to a dict can't fail */ Jim_HashTable *ht; int i; @@ -7042,11 +7029,8 @@ static int SetDictFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr) Jim_InitHashTable(ht, &JimDictHashTableType, interp); for (i = 0; i < listlen; i += 2) { - Jim_Obj *keyObjPtr; - Jim_Obj *valObjPtr; - - Jim_ListIndex(interp, objPtr, i, &keyObjPtr, JIM_NONE); - Jim_ListIndex(interp, objPtr, i + 1, &valObjPtr, JIM_NONE); + Jim_Obj *keyObjPtr = Jim_ListGetIndex(interp, objPtr, i); + Jim_Obj *valObjPtr = Jim_ListGetIndex(interp, objPtr, i + 1); Jim_ReplaceHashEntry(ht, keyObjPtr, valObjPtr); } @@ -7084,15 +7068,12 @@ static int DictAddElement(Jim_Interp *interp, Jim_Obj *objPtr, int Jim_DictAddElement(Jim_Interp *interp, Jim_Obj *objPtr, Jim_Obj *keyObjPtr, Jim_Obj *valueObjPtr) { - int retcode; - JimPanic((Jim_IsShared(objPtr), "Jim_DictAddElement called with shared object")); if (SetDictFromAny(interp, objPtr) != JIM_OK) { return JIM_ERR; } - retcode = DictAddElement(interp, objPtr, keyObjPtr, valueObjPtr); Jim_InvalidateStringRep(objPtr); - return retcode; + return DictAddElement(interp, objPtr, keyObjPtr, valueObjPtr); } Jim_Obj *Jim_NewDictObj(Jim_Interp *interp, Jim_Obj *const *elements, int len) @@ -7245,6 +7226,7 @@ int Jim_SetDictKeysVector(Jim_Interp *interp, Jim_Obj *varNamePtr, DictAddElement(interp, dictObjPtr, keyv[i], objPtr); } } + /* XXX: Is this necessary? */ Jim_InvalidateStringRep(objPtr); Jim_InvalidateStringRep(varObjPtr); if (Jim_SetVariable(interp, varNamePtr, varObjPtr) != JIM_OK) { @@ -7273,7 +7255,7 @@ static const Jim_ObjType indexObjType = { JIM_TYPE_NONE, }; -void UpdateStringOfIndex(struct Jim_Obj *objPtr) +static void UpdateStringOfIndex(struct Jim_Obj *objPtr) { if (objPtr->internalRep.intValue == -1) { JimSetStringBytes(objPtr, "end"); @@ -7291,7 +7273,7 @@ void UpdateStringOfIndex(struct Jim_Obj *objPtr) } } -int SetIndexFromAny(Jim_Interp *interp, Jim_Obj *objPtr) +static int SetIndexFromAny(Jim_Interp *interp, Jim_Obj *objPtr) { int idx, end = 0; const char *str; @@ -7393,8 +7375,6 @@ static const char * const jimReturnCodes[] = { #define jimReturnCodesSize (sizeof(jimReturnCodes)/sizeof(*jimReturnCodes)) -static int SetReturnCodeFromAny(Jim_Interp *interp, Jim_Obj *objPtr); - static const Jim_ObjType returnCodeObjType = { "return-code", NULL, @@ -7416,7 +7396,7 @@ const char *Jim_ReturnCode(int code) } } -int SetReturnCodeFromAny(Jim_Interp *interp, Jim_Obj *objPtr) +static int SetReturnCodeFromAny(Jim_Interp *interp, Jim_Obj *objPtr) { int returnCode; jim_wide wideValue; @@ -7571,20 +7551,17 @@ static Jim_Obj *ExprPop(struct JimExprState *e) static int JimExprOpNumUnary(Jim_Interp *interp, struct JimExprState *e) { - int intresult = 0; + int intresult = 1; int rc = JIM_OK; Jim_Obj *A = ExprPop(e); double dA, dC = 0; jim_wide wA, wC = 0; if ((A->typePtr != &doubleObjType || A->bytes) && JimGetWideNoErr(interp, A, &wA) == JIM_OK) { - intresult = 1; - switch (e->opcode) { case JIM_EXPROP_FUNC_INT: - wC = wA; - break; case JIM_EXPROP_FUNC_ROUND: + case JIM_EXPROP_UNARYPLUS: wC = wA; break; case JIM_EXPROP_FUNC_DOUBLE: @@ -7597,9 +7574,6 @@ static int JimExprOpNumUnary(Jim_Interp *interp, struct JimExprState *e) case JIM_EXPROP_UNARYMINUS: wC = -wA; break; - case JIM_EXPROP_UNARYPLUS: - wC = wA; - break; case JIM_EXPROP_NOT: wC = !wA; break; @@ -7611,27 +7585,25 @@ static int JimExprOpNumUnary(Jim_Interp *interp, struct JimExprState *e) switch (e->opcode) { case JIM_EXPROP_FUNC_INT: wC = dA; - intresult = 1; break; case JIM_EXPROP_FUNC_ROUND: wC = dA < 0 ? (dA - 0.5) : (dA + 0.5); - intresult = 1; break; case JIM_EXPROP_FUNC_DOUBLE: + case JIM_EXPROP_UNARYPLUS: dC = dA; + intresult = 0; break; case JIM_EXPROP_FUNC_ABS: dC = dA >= 0 ? dA : -dA; + intresult = 0; break; case JIM_EXPROP_UNARYMINUS: dC = -dA; - break; - case JIM_EXPROP_UNARYPLUS: - dC = dA; + intresult = 0; break; case JIM_EXPROP_NOT: wC = !dA; - intresult = 1; break; default: abort(); @@ -7854,7 +7826,7 @@ static int JimExprOpIntBin(Jim_Interp *interp, struct JimExprState *e) /* A binary operation on two ints or two doubles (or two strings for some ops) */ static int JimExprOpBin(Jim_Interp *interp, struct JimExprState *e) { - int intresult = 0; + int intresult = 1; int rc = JIM_OK; double dA, dB, dC = 0; jim_wide wA, wB, wC = 0; @@ -7868,8 +7840,6 @@ static int JimExprOpBin(Jim_Interp *interp, struct JimExprState *e) /* Both are ints */ - intresult = 1; - switch (e->opcode) { case JIM_EXPROP_POW: case JIM_EXPROP_FUNC_POW: @@ -7931,6 +7901,7 @@ static int JimExprOpBin(Jim_Interp *interp, struct JimExprState *e) } } else if (Jim_GetDouble(interp, A, &dA) == JIM_OK && Jim_GetDouble(interp, B, &dB) == JIM_OK) { + intresult = 0; switch (e->opcode) { case JIM_EXPROP_POW: case JIM_EXPROP_FUNC_POW: @@ -7993,11 +7964,9 @@ static int JimExprOpBin(Jim_Interp *interp, struct JimExprState *e) else { /* Handle the string case */ - /* REVISIT: Could optimise the eq/ne case by checking lengths */ + /* XXX: Could optimise the eq/ne case by checking lengths */ int i = Jim_StringCompareObj(interp, A, B, 0); - intresult = 1; - switch (e->opcode) { case JIM_EXPROP_LT: wC = i < 0; @@ -8045,11 +8014,7 @@ static int JimSearchList(Jim_Interp *interp, Jim_Obj *listObjPtr, Jim_Obj *valOb listlen = Jim_ListLength(interp, listObjPtr); for (i = 0; i < listlen; i++) { - Jim_Obj *objPtr; - - Jim_ListIndex(interp, listObjPtr, i, &objPtr, JIM_NONE); - - if (Jim_StringEqObj(objPtr, valObj)) { + if (Jim_StringEqObj(Jim_ListGetIndex(interp, listObjPtr, i), valObj)) { return 1; } } @@ -8250,94 +8215,96 @@ enum * * This array *must* be kept in sync with the JIM_EXPROP enum. * - * The following macro pre-computes the string length at compile time. + * The following macros pre-compute the string length at compile time. */ -#define OPRINIT(N, P, A, F, L) {N, F, P, A, L, sizeof(N) - 1} +#define OPRINIT(N, P, A, F) {N, F, P, A, LAZY_NONE, sizeof(N) - 1} +#define OPRINIT_LAZY(N, P, A, F, L) {N, F, P, A, L, sizeof(N) - 1} static const struct Jim_ExprOperator Jim_ExprOperators[] = { - OPRINIT("*", 110, 2, JimExprOpBin, LAZY_NONE), - OPRINIT("/", 110, 2, JimExprOpBin, LAZY_NONE), - OPRINIT("%", 110, 2, JimExprOpIntBin, LAZY_NONE), + OPRINIT("*", 110, 2, JimExprOpBin), + OPRINIT("/", 110, 2, JimExprOpBin), + OPRINIT("%", 110, 2, JimExprOpIntBin), - OPRINIT("-", 100, 2, JimExprOpBin, LAZY_NONE), - OPRINIT("+", 100, 2, JimExprOpBin, LAZY_NONE), + OPRINIT("-", 100, 2, JimExprOpBin), + OPRINIT("+", 100, 2, JimExprOpBin), - OPRINIT("<<", 90, 2, JimExprOpIntBin, LAZY_NONE), - OPRINIT(">>", 90, 2, JimExprOpIntBin, LAZY_NONE), + OPRINIT("<<", 90, 2, JimExprOpIntBin), + OPRINIT(">>", 90, 2, JimExprOpIntBin), - OPRINIT("<<<", 90, 2, JimExprOpIntBin, LAZY_NONE), - OPRINIT(">>>", 90, 2, JimExprOpIntBin, LAZY_NONE), + OPRINIT("<<<", 90, 2, JimExprOpIntBin), + OPRINIT(">>>", 90, 2, JimExprOpIntBin), - OPRINIT("<", 80, 2, JimExprOpBin, LAZY_NONE), - OPRINIT(">", 80, 2, JimExprOpBin, LAZY_NONE), - OPRINIT("<=", 80, 2, JimExprOpBin, LAZY_NONE), - OPRINIT(">=", 80, 2, JimExprOpBin, LAZY_NONE), + OPRINIT("<", 80, 2, JimExprOpBin), + OPRINIT(">", 80, 2, JimExprOpBin), + OPRINIT("<=", 80, 2, JimExprOpBin), + OPRINIT(">=", 80, 2, JimExprOpBin), - OPRINIT("==", 70, 2, JimExprOpBin, LAZY_NONE), - OPRINIT("!=", 70, 2, JimExprOpBin, LAZY_NONE), + OPRINIT("==", 70, 2, JimExprOpBin), + OPRINIT("!=", 70, 2, JimExprOpBin), - OPRINIT("&", 50, 2, JimExprOpIntBin, LAZY_NONE), - OPRINIT("^", 49, 2, JimExprOpIntBin, LAZY_NONE), - OPRINIT("|", 48, 2, JimExprOpIntBin, LAZY_NONE), + OPRINIT("&", 50, 2, JimExprOpIntBin), + OPRINIT("^", 49, 2, JimExprOpIntBin), + OPRINIT("|", 48, 2, JimExprOpIntBin), - OPRINIT("&&", 10, 2, NULL, LAZY_OP), - OPRINIT(NULL, 10, 2, JimExprOpAndLeft, LAZY_LEFT), - OPRINIT(NULL, 10, 2, JimExprOpAndOrRight, LAZY_RIGHT), + OPRINIT_LAZY("&&", 10, 2, NULL, LAZY_OP), + OPRINIT_LAZY(NULL, 10, 2, JimExprOpAndLeft, LAZY_LEFT), + OPRINIT_LAZY(NULL, 10, 2, JimExprOpAndOrRight, LAZY_RIGHT), - OPRINIT("||", 9, 2, NULL, LAZY_OP), - OPRINIT(NULL, 9, 2, JimExprOpOrLeft, LAZY_LEFT), - OPRINIT(NULL, 9, 2, JimExprOpAndOrRight, LAZY_RIGHT), + OPRINIT_LAZY("||", 9, 2, NULL, LAZY_OP), + OPRINIT_LAZY(NULL, 9, 2, JimExprOpOrLeft, LAZY_LEFT), + OPRINIT_LAZY(NULL, 9, 2, JimExprOpAndOrRight, LAZY_RIGHT), - OPRINIT("?", 5, 2, JimExprOpNull, LAZY_OP), - OPRINIT(NULL, 5, 2, JimExprOpTernaryLeft, LAZY_LEFT), - OPRINIT(NULL, 5, 2, JimExprOpNull, LAZY_RIGHT), + OPRINIT_LAZY("?", 5, 2, JimExprOpNull, LAZY_OP), + OPRINIT_LAZY(NULL, 5, 2, JimExprOpTernaryLeft, LAZY_LEFT), + OPRINIT_LAZY(NULL, 5, 2, JimExprOpNull, LAZY_RIGHT), - OPRINIT(":", 5, 2, JimExprOpNull, LAZY_OP), - OPRINIT(NULL, 5, 2, JimExprOpColonLeft, LAZY_LEFT), - OPRINIT(NULL, 5, 2, JimExprOpNull, LAZY_RIGHT), + OPRINIT_LAZY(":", 5, 2, JimExprOpNull, LAZY_OP), + OPRINIT_LAZY(NULL, 5, 2, JimExprOpColonLeft, LAZY_LEFT), + OPRINIT_LAZY(NULL, 5, 2, JimExprOpNull, LAZY_RIGHT), - OPRINIT("**", 250, 2, JimExprOpBin, LAZY_NONE), + OPRINIT("**", 250, 2, JimExprOpBin), - OPRINIT("eq", 60, 2, JimExprOpStrBin, LAZY_NONE), - OPRINIT("ne", 60, 2, JimExprOpStrBin, LAZY_NONE), + OPRINIT("eq", 60, 2, JimExprOpStrBin), + OPRINIT("ne", 60, 2, JimExprOpStrBin), - OPRINIT("in", 55, 2, JimExprOpStrBin, LAZY_NONE), - OPRINIT("ni", 55, 2, JimExprOpStrBin, LAZY_NONE), + OPRINIT("in", 55, 2, JimExprOpStrBin), + OPRINIT("ni", 55, 2, JimExprOpStrBin), - OPRINIT("!", 150, 1, JimExprOpNumUnary, LAZY_NONE), - OPRINIT("~", 150, 1, JimExprOpIntUnary, LAZY_NONE), - OPRINIT(NULL, 150, 1, JimExprOpNumUnary, LAZY_NONE), - OPRINIT(NULL, 150, 1, JimExprOpNumUnary, LAZY_NONE), + OPRINIT("!", 150, 1, JimExprOpNumUnary), + OPRINIT("~", 150, 1, JimExprOpIntUnary), + OPRINIT(NULL, 150, 1, JimExprOpNumUnary), + OPRINIT(NULL, 150, 1, JimExprOpNumUnary), - OPRINIT("int", 200, 1, JimExprOpNumUnary, LAZY_NONE), - OPRINIT("abs", 200, 1, JimExprOpNumUnary, LAZY_NONE), - OPRINIT("double", 200, 1, JimExprOpNumUnary, LAZY_NONE), - OPRINIT("round", 200, 1, JimExprOpNumUnary, LAZY_NONE), - OPRINIT("rand", 200, 0, JimExprOpNone, LAZY_NONE), - OPRINIT("srand", 200, 1, JimExprOpIntUnary, LAZY_NONE), + OPRINIT("int", 200, 1, JimExprOpNumUnary), + OPRINIT("abs", 200, 1, JimExprOpNumUnary), + OPRINIT("double", 200, 1, JimExprOpNumUnary), + OPRINIT("round", 200, 1, JimExprOpNumUnary), + OPRINIT("rand", 200, 0, JimExprOpNone), + OPRINIT("srand", 200, 1, JimExprOpIntUnary), #ifdef JIM_MATH_FUNCTIONS - OPRINIT("sin", 200, 1, JimExprOpDoubleUnary, LAZY_NONE), - OPRINIT("cos", 200, 1, JimExprOpDoubleUnary, LAZY_NONE), - OPRINIT("tan", 200, 1, JimExprOpDoubleUnary, LAZY_NONE), - OPRINIT("asin", 200, 1, JimExprOpDoubleUnary, LAZY_NONE), - OPRINIT("acos", 200, 1, JimExprOpDoubleUnary, LAZY_NONE), - OPRINIT("atan", 200, 1, JimExprOpDoubleUnary, LAZY_NONE), - OPRINIT("sinh", 200, 1, JimExprOpDoubleUnary, LAZY_NONE), - OPRINIT("cosh", 200, 1, JimExprOpDoubleUnary, LAZY_NONE), - OPRINIT("tanh", 200, 1, JimExprOpDoubleUnary, LAZY_NONE), - OPRINIT("ceil", 200, 1, JimExprOpDoubleUnary, LAZY_NONE), - OPRINIT("floor", 200, 1, JimExprOpDoubleUnary, LAZY_NONE), - OPRINIT("exp", 200, 1, JimExprOpDoubleUnary, LAZY_NONE), - OPRINIT("log", 200, 1, JimExprOpDoubleUnary, LAZY_NONE), - OPRINIT("log10", 200, 1, JimExprOpDoubleUnary, LAZY_NONE), - OPRINIT("sqrt", 200, 1, JimExprOpDoubleUnary, LAZY_NONE), - OPRINIT("pow", 200, 2, JimExprOpBin, LAZY_NONE), + OPRINIT("sin", 200, 1, JimExprOpDoubleUnary), + OPRINIT("cos", 200, 1, JimExprOpDoubleUnary), + OPRINIT("tan", 200, 1, JimExprOpDoubleUnary), + OPRINIT("asin", 200, 1, JimExprOpDoubleUnary), + OPRINIT("acos", 200, 1, JimExprOpDoubleUnary), + OPRINIT("atan", 200, 1, JimExprOpDoubleUnary), + OPRINIT("sinh", 200, 1, JimExprOpDoubleUnary), + OPRINIT("cosh", 200, 1, JimExprOpDoubleUnary), + OPRINIT("tanh", 200, 1, JimExprOpDoubleUnary), + OPRINIT("ceil", 200, 1, JimExprOpDoubleUnary), + OPRINIT("floor", 200, 1, JimExprOpDoubleUnary), + OPRINIT("exp", 200, 1, JimExprOpDoubleUnary), + OPRINIT("log", 200, 1, JimExprOpDoubleUnary), + OPRINIT("log10", 200, 1, JimExprOpDoubleUnary), + OPRINIT("sqrt", 200, 1, JimExprOpDoubleUnary), + OPRINIT("pow", 200, 2, JimExprOpBin), #endif }; #undef OPRINIT +#undef OPRINIT_LAZY #define JIM_EXPR_OPERATORS_NUM \ (sizeof(Jim_ExprOperators)/sizeof(struct Jim_ExprOperator)) @@ -9125,7 +9092,7 @@ static int SetExprFromAny(Jim_Interp *interp, struct Jim_Obj *objPtr) #ifdef DEBUG_SHOW_EXPR_TOKENS { int i; - printf("==== Expr Tokens ====\n"); + printf("==== Expr Tokens (%s) ====\n", Jim_String(fileNameObj)); for (i = 0; i < tokenlist.count; i++) { printf("[%2d]@%d %s '%.*s'\n", i, tokenlist.list[i].line, jim_tt_name(tokenlist.list[i].type), tokenlist.list[i].len, tokenlist.list[i].token); @@ -9512,7 +9479,7 @@ void DupScanFmtInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr) dupPtr->typePtr = &scanFmtStringObjType; } -void UpdateStringOfScanFmt(Jim_Obj *objPtr) +static void UpdateStringOfScanFmt(Jim_Obj *objPtr) { JimSetStringBytes(objPtr, ((ScanFmtStringObj *) objPtr->internalRep.ptr)->stringRep); } @@ -9745,7 +9712,6 @@ static int ScanOneEntry(Jim_Interp *interp, const char *str, int pos, int strLen if (descr->prefix) { /* There was a prefix given before the conversion, skip it and adjust * the string-to-be-parsed accordingly */ - /* XXX: Should be checking strLen, not str[pos] */ for (i = 0; pos < strLen && descr->prefix[i]; ++i) { /* If prefix require, skip WS */ if (isspace(UCHAR(descr->prefix[i]))) @@ -11243,7 +11209,7 @@ static Jim_Obj *JimHashtablePatternMatch(Jim_Interp *interp, Jim_HashTable *ht, static void JimCommandMatch(Jim_Interp *interp, Jim_Obj *listObjPtr, Jim_HashEntry *he, int type) { - Jim_Cmd *cmdPtr = (Jim_Cmd *)he->u.val; + Jim_Cmd *cmdPtr = Jim_GetHashEntryVal(he); Jim_Obj *objPtr; if (type == JIM_CMDLIST_PROCS && !cmdPtr->isproc) { @@ -11279,7 +11245,7 @@ static Jim_Obj *JimCommandsList(Jim_Interp *interp, Jim_Obj *patternObjPtr, int static void JimVariablesMatch(Jim_Interp *interp, Jim_Obj *listObjPtr, Jim_HashEntry *he, int type) { - Jim_Var *varPtr = (Jim_Var *)he->u.val; + Jim_Var *varPtr = Jim_GetHashEntryVal(he); if (type != JIM_VARLIST_LOCALS || varPtr->linkFramePtr == NULL) { Jim_ListAppendElement(interp, listObjPtr, Jim_NewStringObj(interp, he->key, -1)); @@ -12329,10 +12295,9 @@ static int Jim_LsearchCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const * listlen = Jim_ListLength(interp, argv[0]); for (i = 0; i < listlen; i++) { - Jim_Obj *objPtr; int eq = 0; + Jim_Obj *objPtr = Jim_ListGetIndex(interp, argv[0], i); - Jim_ListIndex(interp, argv[0], i, &objPtr, JIM_NONE); switch (opt_match) { case OPT_EXACT: eq = Jim_StringCompareObj(interp, argv[1], objPtr, opt_nocase) == 0; @@ -12529,15 +12494,13 @@ static int Jim_LsetCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *arg return JIM_ERR; } else if (argc == 3) { + /* With no indexes, simply implements [set] */ if (Jim_SetVariable(interp, argv[1], argv[2]) != JIM_OK) return JIM_ERR; Jim_SetResult(interp, argv[2]); return JIM_OK; } - if (Jim_SetListIndex(interp, argv[1], argv + 2, argc - 3, argv[argc - 1]) - == JIM_ERR) - return JIM_ERR; - return JIM_OK; + return Jim_ListSetIndex(interp, argv[1], argv + 2, argc - 3, argv[argc - 1]); } /* [lsort] */ @@ -13378,7 +13341,7 @@ static Jim_Obj *JimStringMap(Jim_Interp *interp, Jim_Obj *mapListObjPtr, const char *k; int kl; - Jim_ListIndex(interp, mapListObjPtr, i, &objPtr, JIM_NONE); + objPtr = Jim_ListGetIndex(interp, mapListObjPtr, i); k = Jim_String(objPtr); kl = Jim_Utf8Length(interp, objPtr); @@ -13390,8 +13353,7 @@ static Jim_Obj *JimStringMap(Jim_Interp *interp, Jim_Obj *mapListObjPtr, Jim_AppendString(interp, resultObjPtr, noMatchStart, str - noMatchStart); noMatchStart = NULL; } - Jim_ListIndex(interp, mapListObjPtr, i + 1, &objPtr, JIM_NONE); - Jim_AppendObj(interp, resultObjPtr, objPtr); + Jim_AppendObj(interp, resultObjPtr, Jim_ListGetIndex(interp, mapListObjPtr, i + 1)); str += utf8_index(str, kl); strLen -= kl; break; @@ -14038,7 +14000,7 @@ static int JimInfoReferences(Jim_Interp *interp, int argc, Jim_Obj *const *argv) JimInitHashTableIterator(&interp->references, &htiter); while ((he = Jim_NextHashEntry(&htiter)) != NULL) { char buf[JIM_REFERENCE_SPACE + 1]; - Jim_Reference *refPtr = he->u.val; + Jim_Reference *refPtr = Jim_GetHashEntryVal(he); const unsigned long *refId = he->key; JimFormatReference(buf, refPtr, *refId); @@ -14072,7 +14034,7 @@ static void JimDictMatchKeys(Jim_Interp *interp, Jim_Obj *listObjPtr, Jim_HashEn { Jim_ListAppendElement(interp, listObjPtr, (Jim_Obj *)he->key); if (type & JIM_DICTMATCH_VALUES) { - Jim_ListAppendElement(interp, listObjPtr, (Jim_Obj *)he->u.val); + Jim_ListAppendElement(interp, listObjPtr, Jim_GetHashEntryVal(he)); } } @@ -15134,7 +15096,7 @@ static int Jim_RandCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *arg static const struct { const char *name; - Jim_CmdProc cmdProc; + Jim_CmdProc *cmdProc; } Jim_CoreCommandsTable[] = { {"alias", Jim_AliasCoreCommand}, {"set", Jim_SetCoreCommand}, @@ -140,14 +140,17 @@ extern "C" { /* Some function get an integer argument with flags to change * the behaviour. */ -#define JIM_NONE 0 /* no flags set */ -#define JIM_ERRMSG 1 /* set an error message in the interpreter. */ -#define JIM_UNSHARED 4 /* Flag to Jim_GetVariable() */ -#define JIM_MUSTEXIST 8 /* Flag to Jim_SetDictKeysVector() - fail if non-existent */ +/* Starting from 1 << 20 flags are reserved for private uses of + * different calls. This way the same 'flags' argument may be used + * to pass both global flags and private flags. */ +#define JIM_PRIV_FLAG_SHIFT 20 -/* Internal flags */ -#define JIM_GLOBAL_ONLY 0x100 +#define JIM_NONE 0 /* no flags set */ +#define JIM_ERRMSG 1 /* set an error message in the interpreter. */ +#define JIM_ENUM_ABBREV 2 /* Jim_GetEnum() - Allow unambiguous abbreviation */ +#define JIM_UNSHARED 4 /* Jim_GetVariable() - return unshared object */ +#define JIM_MUSTEXIST 8 /* Jim_SetDictKeysVector() - fail if non-existent */ /* Flags for Jim_SubstObj() */ #define JIM_SUBST_NOVAR 1 /* don't perform variables substitutions */ @@ -155,12 +158,6 @@ extern "C" { #define JIM_SUBST_NOESC 4 /* don't perform escapes substitutions */ #define JIM_SUBST_FLAG 128 /* flag to indicate that this is a real substition object */ -/* Unused arguments generate annoying warnings... */ -#define JIM_NOTUSED(V) ((void) V) - -/* Flags for Jim_GetEnum() */ -#define JIM_ENUM_ABBREV 2 /* Allow unambiguous abbreviation */ - /* Flags used by API calls getting a 'nocase' argument. */ #define JIM_CASESENS 0 /* case sensitive */ #define JIM_NOCASE 1 /* no case */ @@ -168,12 +165,8 @@ extern "C" { /* Filesystem related */ #define JIM_PATH_LEN 1024 -/* Newline, some embedded system may need -DJIM_CRLF */ -#ifdef JIM_CRLF -#define JIM_NL "\r\n" -#else -#define JIM_NL "\n" -#endif +/* Unused arguments generate annoying warnings... */ +#define JIM_NOTUSED(V) ((void) V) #define JIM_LIBPATH "auto_path" #define JIM_INTERACTIVE "tcl_interactive" @@ -213,18 +206,18 @@ typedef struct Jim_HashTableType { typedef struct Jim_HashTable { Jim_HashEntry **table; const Jim_HashTableType *type; + void *privdata; unsigned int size; unsigned int sizemask; unsigned int used; unsigned int collisions; unsigned int uniq; - void *privdata; } Jim_HashTable; typedef struct Jim_HashTableIterator { Jim_HashTable *ht; - int index; Jim_HashEntry *entry, *nextEntry; + int index; } Jim_HashTableIterator; /* This is the initial size of every hash table */ @@ -237,9 +230,9 @@ typedef struct Jim_HashTableIterator { #define Jim_SetHashVal(ht, entry, _val_) do { \ if ((ht)->type->valDup) \ - entry->u.val = (ht)->type->valDup((ht)->privdata, _val_); \ + (entry)->u.val = (ht)->type->valDup((ht)->privdata, (_val_)); \ else \ - entry->u.val = (_val_); \ + (entry)->u.val = (_val_); \ } while(0) #define Jim_FreeEntryKey(ht, entry) \ @@ -248,14 +241,14 @@ typedef struct Jim_HashTableIterator { #define Jim_SetHashKey(ht, entry, _key_) do { \ if ((ht)->type->keyDup) \ - entry->key = (ht)->type->keyDup((ht)->privdata, _key_); \ + (entry)->key = (ht)->type->keyDup((ht)->privdata, (_key_)); \ else \ - entry->key = (void *)(_key_); \ + (entry)->key = (void *)(_key_); \ } while(0) #define Jim_CompareHashKeys(ht, key1, key2) \ (((ht)->type->keyCompare) ? \ - (ht)->type->keyCompare((ht)->privdata, key1, key2) : \ + (ht)->type->keyCompare((ht)->privdata, (key1), (key2)) : \ (key1) == (key2)) #define Jim_HashKey(ht, key) ((ht)->type->hashFunction(key) + (ht)->uniq) @@ -302,15 +295,15 @@ typedef struct Jim_Obj { } twoPtrValue; /* Variable object */ struct { - unsigned long callFrameId; /* for caching */ struct Jim_Var *varPtr; + unsigned long callFrameId; /* for caching */ int global; /* If the variable name is globally scoped with :: */ } varValue; /* Command object */ struct { - unsigned long procEpoch; /* for caching */ struct Jim_Obj *nsObj; struct Jim_Cmd *cmdPtr; + unsigned long procEpoch; /* for caching */ } cmdValue; /* List object */ struct { @@ -340,8 +333,8 @@ typedef struct Jim_Obj { } dictSubstValue; /* Regular expression pattern */ struct { - unsigned flags; void *compre; /* really an allocated (regex_t *) */ + unsigned flags; } regexpValue; struct { int line; @@ -385,17 +378,18 @@ typedef struct Jim_Obj { (o)->internalRep.ptr = (p) /* The object type structure. - * There are four methods. + * There are three methods. * - * - FreeIntRep is used to free the internal representation of the object. + * - freeIntRepProc is used to free the internal representation of the object. * Can be NULL if there is nothing to free. - * - DupIntRep is used to duplicate the internal representation of the object. + * + * - dupIntRepProc is used to duplicate the internal representation of the object. * If NULL, when an object is duplicated, the internalRep union is * directly copied from an object to another. * Note that it's up to the caller to free the old internal repr of the * object before to call the Dup method. - * - UpdateString is used to create the string from the internal repr. - * - setFromAny is used to convert the current object into one of this type. + * + * - updateStringProc is used to create the string from the internal repr. */ struct Jim_Interp; @@ -461,13 +455,13 @@ typedef struct Jim_Var { } Jim_Var; /* The cmd structure. */ -typedef int (*Jim_CmdProc)(struct Jim_Interp *interp, int argc, +typedef int Jim_CmdProc(struct Jim_Interp *interp, int argc, Jim_Obj *const *argv); -typedef void (*Jim_DelCmdProc)(struct Jim_Interp *interp, void *privData); +typedef void Jim_DelCmdProc(struct Jim_Interp *interp, void *privData); -/* A command is implemented in C if funcPtr is != NULL, otherwise +/* A command is implemented in C if isproc is 0, otherwise * it's a Tcl procedure with the arglist and body represented by the * two objects referenced by arglistObjPtr and bodyoObjPtr. */ typedef struct Jim_Cmd { @@ -477,8 +471,8 @@ typedef struct Jim_Cmd { union { struct { /* native (C) command */ - Jim_CmdProc cmdProc; /* The command implementation */ - Jim_DelCmdProc delProc; /* Called when the command is deleted if != NULL */ + Jim_CmdProc *cmdProc; /* The command implementation */ + Jim_DelCmdProc *delProc; /* Called when the command is deleted if != NULL */ void *privData; /* command-private data available via Jim_CmdPrivData() */ } native; struct { @@ -605,20 +599,7 @@ typedef struct Jim_Reference { * Exported API prototypes. * ---------------------------------------------------------------------------*/ -/* Macros that are common for extensions and core. */ #define Jim_NewEmptyStringObj(i) Jim_NewStringObj(i, "", 0) - -/* The core includes real prototypes, extensions instead - * include a global function pointer for every function exported. - * Once the extension calls Jim_InitExtension(), the global - * functon pointers are set to the value of the STUB table - * contained in the Jim_Interp structure. - * - * This makes Jim able to load extensions even if it is statically - * linked itself, and to load extensions compiled with different - * versions of Jim (as long as the API is still compatible.) */ - -/* Macros are common for core and extensions */ #define Jim_FreeHashTableIterator(iter) Jim_Free(iter) #define JIM_EXPORT @@ -901,6 +882,7 @@ JIM_EXPORT void Jim_HistoryShow(void); JIM_EXPORT int Jim_InitStaticExtensions(Jim_Interp *interp); JIM_EXPORT int Jim_StringToWide(const char *str, jim_wide *widePtr, int base); JIM_EXPORT int Jim_IsBigEndian(void); + /** * Returns 1 if a signal has been received while * in a catch -signal {} clause. @@ -914,7 +896,6 @@ JIM_EXPORT void Jim_FreeLoadHandles(Jim_Interp *interp); /* jim-aio.c */ JIM_EXPORT FILE *Jim_AioFilehandle(Jim_Interp *interp, Jim_Obj *command); - /* type inspection - avoid where possible */ JIM_EXPORT int Jim_IsDict(Jim_Obj *objPtr); JIM_EXPORT int Jim_IsList(Jim_Obj *objPtr); diff --git a/jimregexp.c b/jimregexp.c index d32f316..9c7d70c 100644 --- a/jimregexp.c +++ b/jimregexp.c @@ -51,18 +51,19 @@ * precedence is structured in regular expressions. Serious changes in * regular-expression syntax might require a total rethink. */ + +#include "jimautoconf.h" + +#if defined(JIM_REGEXP) #include <stdio.h> #include <ctype.h> #include <stdlib.h> #include <string.h> #include "jim.h" -#include "jimautoconf.h" #include "jimregexp.h" #include "utf8.h" -#if !defined(HAVE_REGCOMP) || defined(JIM_REGEXP) - /* An arbitrary limit, but this seems enough. Must be less than 1000. */ #define REG_MAX_PAREN 100 diff --git a/jimregexp.h b/jimregexp.h index 79a87e5..b7598d4 100644 --- a/jimregexp.h +++ b/jimregexp.h @@ -1,27 +1,17 @@ #ifndef JIMREGEXP_H #define JIMREGEXP_H -#ifndef _JIMAUTOCONF_H -#error Need jimautoconf.h -#endif - -#if defined(HAVE_REGCOMP) && !defined(JIM_REGEXP) -/* Use POSIX regex */ -#include <regex.h> +/** regexp(3)-compatible regular expression implementation for Jim. + * + * See jimregexp.c for details + */ -#else +#ifdef __cplusplus +extern "C" { +#endif #include <stdlib.h> -/* - * Definitions etc. for regexp(3) routines. - * - * Caveat: this is V8 regexp(3) [actually, a reimplementation thereof], - * not the System V one. - * - * 11/04/02 (seiwald) - const-ing for string literals - */ - typedef struct { int rm_so; int rm_eo; @@ -112,6 +102,8 @@ int regexec(regex_t *preg, const char *string, size_t nmatch, regmatch_t pmat size_t regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size); void regfree(regex_t *preg); +#ifdef __cplusplus +} #endif #endif diff --git a/nshelper.tcl b/nshelper.tcl index c91973f..33acb51 100644 --- a/nshelper.tcl +++ b/nshelper.tcl @@ -1,3 +1,9 @@ +# Implements script-based implementations of various namespace +# subcommands +# +# (c) 2011 Steve Bennett <steveb@workware.net.au> +# + proc {namespace delete} {args} { foreach name $args { if {$name ni {:: ""}} { @@ -1,3 +1,5 @@ +# Implements script-based standard commands for Jim Tcl + # Creates an anonymous procedure proc lambda {arglist args} { tailcall proc [ref {} function lambda.finalizer] $arglist {*}$args diff --git a/tclcompat.tcl b/tclcompat.tcl index 84d9d25..2a5560c 100644 --- a/tclcompat.tcl +++ b/tclcompat.tcl @@ -1,12 +1,14 @@ -# (c) 2008 Steve Bennett <steveb@workware.net.au> -# # Loads some Tcl-compatible features. # I/O commands, case, lassign, parray, errorInfo, ::tcl_platform, ::env # try, throw, file copy, file delete -force +# +# (c) 2008 Steve Bennett <steveb@workware.net.au> + # Set up the ::env array set env [env] +# Provide Tcl-compatible I/O commands if {[info commands stdout] ne ""} { # Tcl-compatible I/O commands foreach p {gets flush close eof seek tell} { @@ -1,5 +1,10 @@ #ifndef UTF8_UTIL_H #define UTF8_UTIL_H + +#ifdef __cplusplus +extern "C" { +#endif + /** * UTF-8 utility functions * @@ -124,4 +129,8 @@ int utf8_lower(int uc); #endif +#ifdef __cplusplus +} +#endif + #endif |