Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Use Tcl's built-in Tcl_GetIntForIndex() function (TIP #544) in stead of Thread's own built-in SvGetIntForIndex(). When running on Tcl <= 8.6, use TclGetIntForIndex() in stead (runtime switched) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | thread-2-8-branch |
Files: | files | file ages | folders |
SHA3-256: |
91cf470a77c32a0c73f32c63adf1be05 |
User & Date: | jan.nijtmans 2019-06-29 14:38:18.933 |
Context
2019-07-02
| ||
13:38 | Make everything compile with a C++ compiler check-in: 98e6ef4220 user: jan.nijtmans tags: thread-2-8-branch | |
2019-06-29
| ||
14:39 | Merge 2.8 branch check-in: 629db64158 user: jan.nijtmans tags: trunk | |
14:38 | Use Tcl's built-in Tcl_GetIntForIndex() function (TIP #544) in stead of Thread's own built-in SvGetIntForIndex(). When running on Tcl <= 8.6, use TclGetIntForIndex() in stead (runtime switched) check-in: 91cf470a77 user: jan.nijtmans tags: thread-2-8-branch | |
2019-05-17
| ||
12:27 | Doc improvements, backported from trunk. check-in: d3520adc0e user: jan.nijtmans tags: thread-2-8-branch | |
Changes
Changes to generic/tclThreadInt.h.
︙ | ︙ | |||
20 21 22 23 24 25 26 | #include <string.h> /* For memset and friends */ /* * MSVC 8.0 started to mark many standard C library functions depreciated * including the *printf family and others. Tell it to shut up. * (_MSC_VER is 1200 for VC6, 1300 or 1310 for vc7.net, 1400 for 8.0) */ | | > | | > | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #include <string.h> /* For memset and friends */ /* * MSVC 8.0 started to mark many standard C library functions depreciated * including the *printf family and others. Tell it to shut up. * (_MSC_VER is 1200 for VC6, 1300 or 1310 for vc7.net, 1400 for 8.0) */ #if defined(_MSC_VER) # pragma warning(disable:4244) # if _MSC_VER >= 1400 # pragma warning(disable:4267) # pragma warning(disable:4996) # endif #endif /* * Used to tag functions that are only to be visible within the module being * built and not outside it (where this is supported by the linker). */ |
︙ | ︙ |
Changes to generic/threadSvListCmd.c.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | /* * Implementation of most standard Tcl list processing commands * suitable for operation on thread shared (list) variables. * * Copyright (c) 2002 by Zoran Vasiljevic. * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * ---------------------------------------------------------------------------- */ #include "threadSvCmd.h" #include "threadSvListCmd.h" /* * Implementation of list commands for shared variables. * Most of the standard Tcl list commands are implemented. * There are also two new commands: "lpop" and "lpush". * Those are very convenient for simple stack operations. * | > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | /* * Implementation of most standard Tcl list processing commands * suitable for operation on thread shared (list) variables. * * Copyright (c) 2002 by Zoran Vasiljevic. * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * ---------------------------------------------------------------------------- */ #include "threadSvCmd.h" #include "threadSvListCmd.h" #if TCL_MAJOR_VERSION > 8 #define tclSizeT size_t #elif defined(USE_TCL_STUBS) #define tclSizeT int /* Little hack to eliminate the need for "tclInt.h" here: Just copy a small portion of TclIntStubs, just enough to make it work */ typedef struct { int magic; void *hooks; void (*dummy[34]) (void); /* dummy entries 0-33, not used */ int (*tclGetIntForIndex) (Tcl_Interp *interp, Tcl_Obj *objPtr, int endValue, int *indexPtr); /* 34 */ } TclIntStubs; extern const TclIntStubs *tclIntStubsPtr; # undef Tcl_GetIntForIndex # define Tcl_GetIntForIndex(interp, obj, max, ptr) ((threadTclVersion>86)? \ ((int (*)(Tcl_Interp*, Tcl_Obj *, int, int*))((&(tclStubsPtr->tcl_PkgProvideEx))[645]))((interp), (obj), (max), (ptr)): \ tclIntStubsPtr->tclGetIntForIndex((interp), (obj), (max), (ptr))) #elif TCL_MINOR_VERSION < 7 extern int TclGetIntForIndex(Tcl_Interp*, Tcl_Obj *, int, int*); # define Tcl_GetIntForIndex TclGetIntForIndex #endif /* * Implementation of list commands for shared variables. * Most of the standard Tcl list commands are implemented. * There are also two new commands: "lpop" and "lpush". * Those are very convenient for simple stack operations. * |
︙ | ︙ | |||
31 32 33 34 35 36 37 | static Tcl_ObjCmdProc SvLlengthObjCmd; /* llength */ static Tcl_ObjCmdProc SvLindexObjCmd; /* lindex */ static Tcl_ObjCmdProc SvLinsertObjCmd; /* linsert */ static Tcl_ObjCmdProc SvLrangeObjCmd; /* lrange */ static Tcl_ObjCmdProc SvLsearchObjCmd; /* lsearch */ static Tcl_ObjCmdProc SvLsetObjCmd; /* lset */ | < < < < < < < < < | 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | static Tcl_ObjCmdProc SvLlengthObjCmd; /* llength */ static Tcl_ObjCmdProc SvLindexObjCmd; /* lindex */ static Tcl_ObjCmdProc SvLinsertObjCmd; /* linsert */ static Tcl_ObjCmdProc SvLrangeObjCmd; /* lrange */ static Tcl_ObjCmdProc SvLsearchObjCmd; /* lsearch */ static Tcl_ObjCmdProc SvLsetObjCmd; /* lset */ /* * Inefficient list duplicator function which, * however, produces deep list copies, unlike * the original, which just makes shallow copies. */ static void DupListObjShared(Tcl_Obj*, Tcl_Obj*); |
︙ | ︙ | |||
135 136 137 138 139 140 141 | static int SvLpopObjCmd (arg, interp, objc, objv) ClientData arg; Tcl_Interp *interp; int objc; Tcl_Obj *const objv[]; { | | > | 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | static int SvLpopObjCmd (arg, interp, objc, objv) ClientData arg; Tcl_Interp *interp; int objc; Tcl_Obj *const objv[]; { int ret, off, llen, iarg = 0; tclSizeT index = 0; Tcl_Obj *elPtr = NULL; Container *svObj = (Container*)arg; /* * Syntax: * tsv::lpop array key ?index? * $list lpop ?index? |
︙ | ︙ | |||
161 162 163 164 165 166 167 | iarg = off; } ret = Tcl_ListObjLength(interp, svObj->tclObj, &llen); if (ret != TCL_OK) { goto cmd_err; } if (iarg) { | | | 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | iarg = off; } ret = Tcl_ListObjLength(interp, svObj->tclObj, &llen); if (ret != TCL_OK) { goto cmd_err; } if (iarg) { ret = Tcl_GetIntForIndex(interp, objv[iarg], llen-1, &index); if (ret != TCL_OK) { goto cmd_err; } } if (index < 0 || index >= llen) { goto cmd_ok; /* Ignore out-of bounds, like Tcl does */ } |
︙ | ︙ | |||
214 215 216 217 218 219 220 | static int SvLpushObjCmd (arg, interp, objc, objv) ClientData arg; Tcl_Interp *interp; int objc; Tcl_Obj *const objv[]; { | | > | 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | static int SvLpushObjCmd (arg, interp, objc, objv) ClientData arg; Tcl_Interp *interp; int objc; Tcl_Obj *const objv[]; { int off, ret, flg, llen; tclSizeT index = 0; Tcl_Obj *args[1]; Container *svObj = (Container*)arg; /* * Syntax: * tsv::lpush array key element ?index? * $list lpush element ?index? |
︙ | ︙ | |||
238 239 240 241 242 243 244 | goto cmd_err; } ret = Tcl_ListObjLength(interp, svObj->tclObj, &llen); if (ret != TCL_OK) { goto cmd_err; } if ((objc - off) == 2) { | | | 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | goto cmd_err; } ret = Tcl_ListObjLength(interp, svObj->tclObj, &llen); if (ret != TCL_OK) { goto cmd_err; } if ((objc - off) == 2) { ret = Tcl_GetIntForIndex(interp, objv[off+1], llen, &index); if (ret != TCL_OK) { goto cmd_err; } if (index < 0) { index = 0; } else if (index > llen) { index = llen; |
︙ | ︙ | |||
348 349 350 351 352 353 354 | ClientData arg; Tcl_Interp *interp; int objc; Tcl_Obj *const objv[]; { const char *firstArg; size_t argLen; | | > | 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 | ClientData arg; Tcl_Interp *interp; int objc; Tcl_Obj *const objv[]; { const char *firstArg; size_t argLen; int ret, off, llen, ndel, nargs, i, j; tclSizeT first, last; Tcl_Obj **args = NULL; Container *svObj = (Container*)arg; /* * Syntax: * tsv::lreplace array key first last ?element ...? * $list lreplace first last ?element ...? |
︙ | ︙ | |||
370 371 372 373 374 375 376 | Tcl_WrongNumArgs(interp, off, objv, "first last ?element ...?"); goto cmd_err; } ret = Tcl_ListObjLength(interp, svObj->tclObj, &llen); if (ret != TCL_OK) { goto cmd_err; } | | | | 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 | Tcl_WrongNumArgs(interp, off, objv, "first last ?element ...?"); goto cmd_err; } ret = Tcl_ListObjLength(interp, svObj->tclObj, &llen); if (ret != TCL_OK) { goto cmd_err; } ret = Tcl_GetIntForIndex(interp, objv[off], llen-1, &first); if (ret != TCL_OK) { goto cmd_err; } ret = Tcl_GetIntForIndex(interp, objv[off+1], llen-1, &last); if (ret != TCL_OK) { goto cmd_err; } firstArg = Tcl_GetString(objv[off]); argLen = objv[off]->length; if (first < 0) { |
︙ | ︙ | |||
445 446 447 448 449 450 451 | static int SvLrangeObjCmd (arg, interp, objc, objv) ClientData arg; Tcl_Interp *interp; int objc; Tcl_Obj *const objv[]; { | | > | 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | static int SvLrangeObjCmd (arg, interp, objc, objv) ClientData arg; Tcl_Interp *interp; int objc; Tcl_Obj *const objv[]; { int ret, off, llen, nargs, i, j; tclSizeT first, last; Tcl_Obj **elPtrs, **args; Container *svObj = (Container*)arg; /* * Syntax: * tsv::lrange array key first last * $list lrange first last |
︙ | ︙ | |||
467 468 469 470 471 472 473 | Tcl_WrongNumArgs(interp, off, objv, "first last"); goto cmd_err; } ret = Tcl_ListObjGetElements(interp, svObj->tclObj, &llen, &elPtrs); if (ret != TCL_OK) { goto cmd_err; } | | | | 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 | Tcl_WrongNumArgs(interp, off, objv, "first last"); goto cmd_err; } ret = Tcl_ListObjGetElements(interp, svObj->tclObj, &llen, &elPtrs); if (ret != TCL_OK) { goto cmd_err; } ret = Tcl_GetIntForIndex(interp, objv[off], llen-1, &first); if (ret != TCL_OK) { goto cmd_err; } ret = Tcl_GetIntForIndex(interp, objv[off+1], llen-1, &last); if (ret != TCL_OK) { goto cmd_err; } if (first < 0) { first = 0; } if (last >= llen) { |
︙ | ︙ | |||
526 527 528 529 530 531 532 | static int SvLinsertObjCmd (arg, interp, objc, objv) ClientData arg; Tcl_Interp *interp; int objc; Tcl_Obj *const objv[]; { | | > | 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 | static int SvLinsertObjCmd (arg, interp, objc, objv) ClientData arg; Tcl_Interp *interp; int objc; Tcl_Obj *const objv[]; { int off, ret, flg, llen, nargs, i, j; tclSizeT index = 0; Tcl_Obj **args; Container *svObj = (Container*)arg; /* * Syntax: * tsv::linsert array key index element ?element ...? * $list linsert element ?element ...? |
︙ | ︙ | |||
549 550 551 552 553 554 555 | Tcl_WrongNumArgs(interp, off, objv, "index element ?element ...?"); goto cmd_err; } ret = Tcl_ListObjLength(interp, svObj->tclObj, &llen); if (ret != TCL_OK) { goto cmd_err; } | | | 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 | Tcl_WrongNumArgs(interp, off, objv, "index element ?element ...?"); goto cmd_err; } ret = Tcl_ListObjLength(interp, svObj->tclObj, &llen); if (ret != TCL_OK) { goto cmd_err; } ret = Tcl_GetIntForIndex(interp, objv[off], llen, &index); if (ret != TCL_OK) { goto cmd_err; } if (index < 0) { index = 0; } else if (index > llen) { index = llen; |
︙ | ︙ | |||
761 762 763 764 765 766 767 | SvLindexObjCmd (arg, interp, objc, objv) ClientData arg; Tcl_Interp *interp; int objc; Tcl_Obj *const objv[]; { Tcl_Obj **elPtrs; | | > | | 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 | SvLindexObjCmd (arg, interp, objc, objv) ClientData arg; Tcl_Interp *interp; int objc; Tcl_Obj *const objv[]; { Tcl_Obj **elPtrs; int ret, off, llen; tclSizeT index; Container *svObj = (Container*)arg; /* * Syntax: * tsv::lindex array key index * $list lindex index */ ret = Sv_GetContainer(interp, objc, objv, &svObj, &off, 0); if (ret != TCL_OK) { return TCL_ERROR; } if ((objc - off) != 1) { Tcl_WrongNumArgs(interp, off, objv, "index"); goto cmd_err; } ret = Tcl_ListObjGetElements(interp, svObj->tclObj, &llen, &elPtrs); if (ret != TCL_OK) { goto cmd_err; } ret = Tcl_GetIntForIndex(interp, objv[off], llen-1, &index); if (ret != TCL_OK) { goto cmd_err; } if (index >= 0 && index < llen) { Tcl_SetObjResult(interp, Sv_DuplicateObj(elPtrs[index])); } |
︙ | ︙ | |||
903 904 905 906 907 908 909 | newObjList[i] = Sv_DuplicateObj(elObj); } Tcl_SetListObj(copyPtr, llen, newObjList); ckfree((char*)newObjList); } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 925 926 927 928 929 930 931 932 933 934 935 936 937 938 | newObjList[i] = Sv_DuplicateObj(elObj); } Tcl_SetListObj(copyPtr, llen, newObjList); ckfree((char*)newObjList); } /* *---------------------------------------------------------------------- * * SvLsetFlat -- * * Almost exact copy from the TclLsetFlat found in tclListObj.c. |
︙ | ︙ | |||
1038 1039 1040 1041 1042 1043 1044 | SvLsetFlat(interp, listPtr, indexCount, indexArray, valuePtr) Tcl_Interp *interp; /* Tcl interpreter */ Tcl_Obj *listPtr; /* Pointer to the list being modified */ int indexCount; /* Number of index args */ Tcl_Obj **indexArray; Tcl_Obj *valuePtr; /* Value arg to 'lset' */ { | | > | 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 | SvLsetFlat(interp, listPtr, indexCount, indexArray, valuePtr) Tcl_Interp *interp; /* Tcl interpreter */ Tcl_Obj *listPtr; /* Pointer to the list being modified */ int indexCount; /* Number of index args */ Tcl_Obj **indexArray; Tcl_Obj *valuePtr; /* Value arg to 'lset' */ { int elemCount, result, i; tclSizeT index; Tcl_Obj **elemPtrs, *chainPtr, *subListPtr; /* * Determine whether the index arg designates a list * or a single index. */ |
︙ | ︙ | |||
1094 1095 1096 1097 1098 1099 1100 | listPtr->internalRep.twoPtrValue.ptr2 = (void*)chainPtr; /* * Determine the index of the requested element. */ | | | 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 | listPtr->internalRep.twoPtrValue.ptr2 = (void*)chainPtr; /* * Determine the index of the requested element. */ result = Tcl_GetIntForIndex(interp, indexArray[i], elemCount-1, &index); if (result != TCL_OK) { break; } /* * Check that the index is in range. */ |
︙ | ︙ |