Skip to content
Tcl Source Code Artifact [e8a918cd1c]
Login

Artifact [e8a918cd1c]

Artifact e8a918cd1cd5a49713d75d9bd694bb841f025b66f65041734dc128bc0812c161:

Ticket change [e8a918cd1c] - Closed ticket [6e156333bcf233a2|6e156333bc]: <i>Contradiction in Tcl_GetSring/Tcl_GetStringFromObj vs Tcl_UpdateStringProc</i> plus 6 other changes by sebres on 2019-07-22 21:31:16.
D 2019-07-22T21:31:16.214
J closedate 2458687.39671544
J closer sebres
J icomment <i>>\sobjPtr's\sbytes\smember\sis\salways\sNULL\swhen\sit\sis\scalled.</i>\r\n\r\nmeans\s<b>BEFORE</b>,\sso\sthe\s<code>updateStringProc</code>\sis\snever\scalled\sif\s<code>objPtr->bytes</code>\sis\snot\sNULL\sand\svice\sversa\s(only\scalled\sif\sit\sis\sNULL).\r\n\r\nSee\s[https://core.tcl-lang.org/tcl/artifact?name=be4f8c6174676167&ln=1624|tclObj.c#Tcl_GetString]\sfor\smore\sinfo.\r\n\r\nThree\smain\sthings\sare\simportant\shere:\r\n\r\n1.\sThe\shandler\sused\sto\supdate\sthe\sstring\srepresentation\sonly\sif\sit\sis\sNULL\s(and\snever\sif\sit\sis\snot\sNULL);\r\n\r\n2.\sIt\s<b>must\sALWAYS</b>\supdate\sit\s(so\sset\sto\snot\sNULL):\r\n<ul>\r\n<li>either\sset\sit\sto\ssome\sbuffer\s(allocated\sby\sckalloc)\sand\sfill\swith\sNTS\scorresponding\syour\sinternal\srepresentation\sand\sset\sobjPtr->length\sto\sproper\slength\sof\sthat,\sso\sfollow\s[https://wiki.tcl-lang.org/page/everything+is+a+string|EIAS].\r\n</li>\r\n<li>or\sset\sit\sto\s<code>tclEmptyStringRep</code>\sif\syou\sdon't\s"need"\sto\sfollow\sEIAS\s(and\sif\syou\shave\stcl-internal's\sor\sobtained\s<code>tclEmptyStringRep</code>\spointer\sfrom\ssome\sfunction).<br/>\r\nIf\syou\swould\snot\screate\sit,\sso\safter\scall\sof\s<code>updateStringProc</code>\sit\sis\sstill\sNULL\s-\sthen\sthe\sonly\sthing\syou'd\sget\shereafter\sis\sa\s<b>SEGFAULT</b>\s(or\sat\sleast\spanic\swith\s"failed\sto\screate\sa\svalid\sstring\srep"\son\stcl\sbefore\s9.0).\r\n</li>\r\n</ul>\r\n3.\sOnce\screated,\sit\sremains\squasi\simmutable\s(at\sleast\sit\sshould),\syou\scan\sfree\sthe\sstring\srepresentation\s(e.\sg.\susing\s<code>Tcl_InvalidateStringRep</code>)\sbut\sonly\sif\sthe\sobject\sis\snot\sshared\sor\syou\shave\sit\sonly\sunder\syour\scontrol,\se.\sg.\syou\sknow\sall\sthe\sreferences\sare\syours\s(see\s[https://stackoverflow.com/questions/54337750/shouldnt-tclinvalidatestringrep-reset-length/54369232#54369232|my\sanswer\sfor\ssuch\squestion\son\sSO]).\r\n\r\nThus\sclosed\sas\sinvalid,\splease\sreopen\sif\sI'm\swrong.
J login sebres
J mimetype text/x-fossil-wiki
J resolution Invalid
J status Closed
K 6e156333bcf233a26216e3ee3e94f2761e97a34b
U sebres
Z fe0ae86eea753320fdb6176372ffc02c