Skip to content
Tcl Source Code Artifact [176aa23486]
Login

Artifact [176aa23486]

Artifact 176aa2348643839a84ca2f1491d961a7bd31c9c89b650dd9311a0f0a27cb3315:

Ticket change [176aa23486] - Ticket [e58d7e19e937496f|e58d7e19e9] <i>Upwards compatibility of TclObjTypeHasProc()</i> status still Open with 3 other changes by apnadkarni on 2023-07-28 09:38:28.
D 2023-07-28T09:38:28.770
J icomment The\srationale\sof\sTIP\s644\swas\sto\spermit\sthe\s`Tcl_ObjType`\sto\sbe\sextended\swithin\s**minor**\sversions\sof\sTcl\sand\sallow\sTcl\s**extensions**\sto\swork\s**without\sneeding\srecompilation**.\sThis\sis\show\sthe\sTcl_Channel\sworks\sas\sJan\sdescribed\spreviously.\r\n\r\nNow\sboth\smodels\sof\sversioning\sbeing\sdebated\sneed\sto\ssupport\sthe\sabove\srequirement.\r\n\r\nSuppose\sin\s9.1\sa\snew\smethod\s`Tcl_DictObjLookupProc\s*dictLookup`\swere\sadded\sto\s`Tcl_ObjType`\sat\sthe\send\sof\sthe\sstruct\swith\sversion\sbumped.\sWhat\swould\sbe\sneeded\sfor\sthe\sfollowing\scall\sto\swork\r\n\r\n```\r\nTclObjTypeHasProc(objPtr,\sdictLookup);\r\n```\r\n\r\nJan's\sversion\sneeds\sno\smodification\sat\sall\sthat\sI\scan\ssee.\r\n\r\nOn\sthe\sother\shand,\sthe\smacro\sin\sthe\strunk\swill\sfail\sin\sits\scurrent\sform\sas\sit\sdoes\snot\scheck\sfor\sV3\sand\shas\sto\sbe\smodified.\s(I\swill\signore\sthe\ssmall\sbit\sof\swork\shaving\sto\supdate\sall\sthe\s`TCL_OBJTYPE_VX`\smacros.)\sA\sredefinition\slike\r\n\r\n```\r\n#define\sTclObjTypeHasProc(objPtr,\sproc)\t\t\\\r\n\s\s\s\s(((objPtr)->typePtr\t\t\t\t\\\r\n\s\s\s\s\s\s&&\s(\s\s\s(objPtr)->typePtr->version\s==\s1\t\\\r\n\t\s\s||\s(objPtr)->typePtr->version\s==\s2))\t\\\r\n\t\s\s||\s(objPtr)->typePtr->version\s==\s3))\t\\\r\n\s\s\s\s\s?\t((objPtr)->typePtr)->proc\t\t\\\r\n\s\s\s\s\s:\sNULL)\r\n```\r\n\r\nwill\snot\sonly\sbegin\sto\slook\sugly\sas\sversion\s4,\s5,\setc\sare\sadded\sand\shas\sperformance\simplications\son\severy\scall,\sbut\sthe\sbigger\sproblem\sis\sthat\sit\sis\snot\scorrect.\r\n\r\nConsider\san\sextension\s**built\sfor\s9.0**\sthat\shas\sa\sV2\s`Tcl_ObjType`\sloaded\sinto\sTcl\s9.1.\sWhen\sthe\smacro\s`TclObjTypeHasProc(objPtr,\sdictLookup)`\s(within\sTcl\s9.1\score,\snot\sthe\sextension)\sis\scalled,\sit\sis\sgoing\sto\ssee\sversion\sas\s2,\sand\sthus\scheck\s`objPtr->typePtr->proc`\swhich\sis\sa\sgarbage\slocation\s(remembering\sthat\sthe\ssize\sof\sstructure\sin\sthe\sextension\sis\sthe\s9.0\sV2\ssize,\sNOT\sthe\s9.1\ssize\sand\sthe\s9.0\s`TCL_OBJTYPE_V2`\smacro,\snot\sthe\s9.1,\swould\shave\sbeen\sused\sto\sinitialize\sit).\s\r\n\r\nThe\sproblem\sis\sthat\s`proc`\svalues\sthat\sare\sdefined\sonly\sin\sV3\sshould\sonly\sbe\schecked\sif\sthe\sversion\sis\sV3\sbut\sthe\spreprocessor\swill\snot\slet\syou\sdo\sthat\s(remember\sneither\sobjPtr\snor\sproc\sare\sconstants)\sin\sany\sway\sthat\sI\scan\ssee.\r\n\r\nThe\sonly\sway\sout\sthen\sis\sto\shave\sa\sseparate\smacro\sfor\seach\sversion\sof\s`Tcl_ObjType`\s-\s`TclObjTypeHasProcV1`,\s`TclObjTypeHasProcV2`\setc.\sthat\sdo\schecks\sspecific\sto\sthe\smethods\sdefined\sfor\sthat\sversion.\sThis\sis\smore\swork\sand\smore\scomplicated\sfor\sthe\sprogrammer\swho\snow\shas\sto\strack\swhich\smacro\sneeds\sto\sbe\sused\sfor\swhich\smethod\scall.\sAnd\sfor\sno\sfunctional\sbenefit.\r\n\r\nNote\sthis\sproblem\salready\sexists\sbetween\sV0\sV1\sV2\sexcept\sthat\sthere\sare\sno\sextensions\sout\sthere\sbuilt\swith\solder\sversioned\sstructures.\r\n\r\nIn\sterms\sof\slimiting\schanges\sto\s`Tcl_ObjType`\sto\sonly\sadding\sfunctions\sat\sthe\send,\sthat\sis\sa\sgiven\sfor\sexactly\sthe\ssame\sreasons\sas\sabove.\sUnless\sone\sis\swilling\sto\swrite\sseparate\smacros\sfor\seach\sversion.\sI\sdon't\ssee\sadding\sat\sthe\send\slimiting\sin\sany\ssignificant\sfashion\sanyways\sfor\smany\sreasons.\r\n\r\nThus\sI\sdon't\scurrently\ssee\sthe\scurrent\strunk\sdefinition\sas\sbeing\sworkable.\r\n\r\nOne\sfinal\snote\sabout\sBrian's\scomment\s"There's\sno\sguarantee\sthat\sthe\saddress\safter\sthe\send\sin\sthe\solder\scompiled\scode\sis\sa\svalid\saddress."\s-\sI\sdo\snot\ssee\show\sthat\smacro\saccesses\sa\spotentially\sinvalid\saddress\sat\sall.\sIt\sis\sonly\scalculating\sstructure\soffsets\swhich\sis\sperfectly\slegitimate.\r\n\r\n/Ashok
J login apnadkarni
J mimetype text/x-markdown
K e58d7e19e937496f179fe711345b415f3f3d31b2
U apnadkarni
Z 69f35ebf02bb81bf37dc1ffb55bf260e