Skip to content
Tcl Source Code Artifact [8497d2b6b7]
Login

Artifact [8497d2b6b7]

Artifact 8497d2b6b76da8ee87ad20a4e20b4681c57abf7f053aed9499b09ac0d03b38d0:

Ticket change [8497d2b6b7] - Ticket [e9a2715d912d8644|e9a2715d91] <i>Tcl 8.6.11: Incompatible Tcl_GetRange()</i> status still Closed with 5 other changes by dgp on 2022-03-12 23:33:48.
D 2022-03-12T23:33:48.187
J closedate 2459651.48180772
J closer dgp
J icomment \r\nI\swent\sthrough\sthe\shistory,\sand\sfound\smany\sthings\sto\smake\sme\sunhappy.\r\nBad\sdesign\smade\sworse\sby\sbad\sdocumentation.\s\sBut\sI'll\sspare\syou\sa\slong\r\nrant\sat\severy\sturn\sof\sthe\srabbit\shole.\r\n\r\nI\smade\sno\snote\sof\sthis\schange\sin\sthe\s8.6.11\srelease\snotes\sbecause\sI\r\nhonestly\shad\sno\sidea\sthis\sfunctionality\sexisted,\slet\salone\ssomeone\r\nmight\sbe\susing\sit.\s\sIf\sit\shad\sbeen\scalled\sto\smy\sattention\sI\swould\shave\r\nconsidered\sit\sa\sbug.\s\sI\struly\sassumed\sthe\sadded\sargument\schecking\swas\sjust\r\nformalizing\sthe\srules\sany\ssensible\scaller\swas\salready\sfollowing.\sAs\r\nthe\scomment\ssaid\s"The\sfirst\sand\slast\sindices\sare\sassumed\sto\sbe\sin\sthe\r\nappropriate\srange."\r\n\r\nThat\ssaid,\sit\sdid\sexist,\sand\sit\sdid\sget\suse.\r\n\r\nI\shave\sto\scaution\sthat\sthe\smental\smodel\sthat\sa\svalue\sof\s-1\sfor\sthe\r\n"last"\sargument\scauses\sthe\sreturn\sof\sa\ssuffix\ssubstring\sstarting\sat\r\nindex\s"first"\sand\scontinuing\sall\sthe\sway\sto\sthe\send\sof\sthe\sstring\r\nis\snot\sreliably\scorrect.\s\sIt\sfails\sin\sthree\sways.\r\n\r\n1)\sTcl_GetRange(objPtr,\s0,\s-1)\sreturns\san\sempty\sstring,\sbecause\r\nthen\s(last\s-\sfirst\s+\s1)\sis\s0,\swhich\sis\snot\snegative,\sso\sthe\sspecial\r\nmodes\sof\sTcl_NewStringObj()\sand\sTcl_NewUnicodeObj()\sare\snot\sengaged.\r\n\r\n2)\sSince\s8.6b1\s(2009),\sTcl_GetRange\sprocesses\spure\sbyte\sarray\r\nvalues\sdifferently.\s\sA\svalue\sof\s-1\sfor\s"last"\scan\slead\sto\sa\scall\sto\r\nTcl_NewByteArrayObj(bytes,\slength)\swith\slength\s<\s0,\swhich\sis\sdocumented\r\nas\sinvalid.\s\sIn\spractice,\sTcl_NewByteArrayObj()\sconverts\sto\slength\s==\s0\sand\r\nthe\sresult\sis\san\sempty\svalue.\s\sThis\sis\san\sEIAS\sviolation,\swhere\sTcl_GetRange()\r\nproduces\sdifferent\sresults\son\sthe\ssame\svalue\sdiffering\sonly\sin\sits\r\ninternals.\s\sThe\swork\son\sthe\sbranch\stip\stries\sto\sfix\sthe\sEIAS\sviolation\sby\r\nnoticing\sthe\snegative\svalue\sfor\s"last"\sand\sfixing\sup\sthe\slength\sargument,\r\nwhich\smight\swork\sexcept\sfor...\r\n\r\n3)\sWhen\sthe\sroutines\sTcl_New(String|Unicode)Obj()\sare\spassed\snegative\r\n"length"\sor\s"numChars"\sarguments,\sthey\sdo\snot\sin\sfact\schange\sto\sa\r\n"take\sthe\swhole\sstring"\smode.\s\sPrecisely,\sthey\schange\sto\sa\r\n"take\severything\sup\sto\sthe\sfirst\sNUL"\smode.\s\sBoth\sthe\sinternal\sUtf\r\nand\sthe\sTcl_UniChar\sarray\srepresentations\scan\scontain\sNUL\sbytes\r\ninterior\sto\sthe\sstring\svalues.\s\sWe\scan\scook\sup\stest\scases\sfor\sboth\r\nscenarios,\sand\sthen\sthose\swould\sbe\sEIAS\sviolations\swith\sthe\srevised\r\nbytearray\sprocessing.\r\n\r\nI'm\sambivalent\show\sbest\sto\smove\sforward.\s\sWhatever\swe\ssettle\son\swe\sshould\r\nbe\ssure\sto\sget\sdocumented\sfar\smore\sclearly.\r\n\r\nI\swill\smention\sthat\sNUL\stermination\stends\sto\sget\sin\sthe\sway\sof\sadopting\r\nsome\salternative\sdata\sstructures.\s\sDoing\saway\swith\sit\smight\sopen\sthe\sdoor\r\nfor\sallowing\ssubstrings\sand\sstrings\sto\sshare\sstorage\smore\soften\sfor\sexample.\r\nThe\sTcl_GetRange()\sbehavior\snoted\shere\sis\sall\swrapped\sup\sin\sthat\srepresentation.\r\nEven\sif\swe\spreserve\sthis\sfeature\snow,\sI\smight\sstill\sseek\sto\seliminate\sit\r\nfor\sTcl\s9\sto\sopen\sup\smore\sfuture\simplementation\soptions.\r\n\r\nFinally,\sI\scan\smention\sthat\sany\scode\sthat\shas\sbeen\scalling\r\n\r\n\s\s\s\sTcl_GetRange(\sobjPtr,\sfirst,\s-1);\r\n\r\nin\sTcl\sreleases\s8.2.0\sthrough\s8.6.10\scould\sbe\srevised\sto\scall\r\n\r\n\s\s\s\sTcl_NewUnicodeObj(\sTcl_GetUnicode(objPtr)\s+\sfirst,\s-1\s);\r\n\r\nto\sget\sthe\ssame\sbehavior\sin\sall\sthose\sreleases\sand\salso\sunchanged\r\nin\s8.6.11\sand\slater.\r\n\r\nHope\sthat\shelps.
J login dgp
J mimetype text/plain
K e9a2715d912d86448a2ed18b2d25788cd50769b4
U dgp
Z fca8de2ac0a4efe414002dde9df66886