Artifacts Associated With Ticket 752814ffff
Ticket change [bb8bf74191] (rid 129504) by ysutjandra on 2003-06-11 18:54:42:
- assignee initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
Hi, I found that regexp changes the object type to string type. I see this behavior in Tcl8.3.5 but not in Tcl8.1. The stack trace when it calls the registered function to free the old internal representation looks as follows: #1 0x9d2a4 in SetStringFromAny (interp=0x0, objPtr=0x11ebf8) at ./../generic/tclStringObj.c:1505 #2 0x9bc3c in Tcl_GetCharLength (objPtr=0x11ebf8) at ./../generic/tclStringObj.c:329 #3 0x2fab4 in Tcl_RegexpObjCmd (dummy=0x0, interp=0xfdd68, objc=2, objv=0xffdac) at ./../generic/tclCmdMZ.c:227 The question is why Tcl_GetCharLength requires changing the internal representation to string object. It should simply call Tcl_GetStringFromObj and does a strlen on the return C-string. Looking at the code tclCmdMZ.c, it has the following comment... Get the length of the string that we are matching before getting the regexp to avoid shimmering problems. -- Yohan
- foundin initialized to: "final: 8.3.5"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "ysutjandra"
- subsystem initialized to: "43. Regexp"
- title initialized to: "Regexp change Tcl_Obj type to string"
- type initialized to: "RFE"
Ticket change [be9315ce2e] (rid 102093) by hobbs on 2003-06-12 03:37:20:
- status changed to: "Pending"
Ticket change [4a99492b03] (rid 126564) by hobbs on 2003-06-12 03:37:21:
- closedate changed to: "2003-06-11T20:37:21"
- closer changed to: "hobbs"
- icomment:
Logged In: YES user_id=72656 Er ... so? Why is this a bug report? In any case, the RE works with Unicode string objects, not utf-8 string objects. The code comments are accurate.
- login: "hobbs"
- mimetype: "text/plain"
- resolution changed to: "Invalid"
- username: "hobbs"
Ticket change [a19814b613] (rid 109751) by ysutjandra on 2003-06-12 03:48:59:
- icomment:
Logged In: YES user_id=799156 At the very least, it should check whether the Tcl_Obj is shared or not, and create a utf-8 string object on a new Tcl_obj. Don't you think? Just curious, what is shimmering problem? Where can I get reference to understand shimmering problem...?
- login: "ysutjandra"
- mimetype: "text/plain"
- status changed to: "Open"
- username: "ysutjandra"
- icomment:
Ticket change [6fc52f5cfb] (rid 100369) by dkf on 2003-06-12 04:06:46:
- assignee changed to: "dkf"
- closedate changed to: "2003-06-11T21:06:46"
- closer changed to: "dkf"
- icomment:
Logged In: YES user_id=79902 At the moment, I'm tempted to say that the modification in behaviour in a place which is not generally exposed visibly at the script level is a consequence of a bug getting fixed. Please describe why you believe this to be a problem. Object types are implementation features; mere caches of representations, and not something deeper.
- login: "dkf"
- mimetype: "text/plain"
- status changed to: "Pending"
- subsystem changed to: "18. Commands M-Z"
- username: "dkf"
Ticket change [03f98bb41c] (rid 119915) by dgp on 2003-06-12 04:08:16:
- assignee changed to: "nobody"
- icomment:
Logged In: YES user_id=80530 Tcl_GetCharLength() returns the number of characters in the string, not the number of bytes. strlen(Tcl_GetStringFromObj) returns the number of bytes in the string, not the number of characters. They do not do the same thing, so you can't propose the latter as a replacement for the former.
- login: "dgp"
- mimetype: "text/plain"
- status changed to: "Open"
- subsystem changed to: "43. Regexp"
- username: "dgp"
Ticket change [b3048b0445] (rid 98445) by ysutjandra on 2003-06-12 05:20:52:
- icomment:
Logged In: YES user_id=799156 I'm sorry I said the wrong thing. I said.. At the very least, it should check whether the Tcl_Obj is shared or not, and create a utf-8 string object on a new Tcl_obj. I meant to say, At the very least, it should check whether the Tcl_Obj is shared or not, and create a unicode string object on a new Tcl_obj. I guess it's fine if it's a requirement that regexp will change any object type to a string. I understand from your explanation that the regexp has to operate on an object with unicode type, leading to converting the old representation (of the type I registered) to the unicode representation and leads to freeing the old representation. I am trying to make use of Tcl memory management on Tcl_Obj by registering my own object type so that it will call the registered free function once it knows the object is not needed anymore. In other words, I registered a new object-type, and I want the Tcl_Obj that holds my object to stay as is throughout its lifespan. ie. it will only call the free function when the refCount is zero. Now I want to stop users from executing commands that will convert the object of my type to something else. Probably something like: set a [newMyType] regexp {hello} $a --> Illegal operation on variable a, --> converting 'MyType' to 'string' is prohibited incr a --> Illegal operation on variable a, --> converting 'MyType' to 'int' is prohibited Currently, I know only how to detect this by implementing a free function that detects whether the refCount is already zero or not. But this function returns void and I cannot stop the users from doing this. I'm okay if there is a way to prevent users from using such commands on my obj. Is there a way to return an error at a situation like this now. - login: "ysutjandra"
- mimetype: "text/plain"
- username: "ysutjandra"
- icomment:
Ticket change [2cc2937711] (rid 118962) by dkf on 2003-06-12 15:28:32:
- foundin changed to: "None"
- icomment:
Logged In: YES user_id=79902 That's not a supported mode of operation, though it's one that I know I would like to support. However, the core is not currently up to it and is not likely to change in this respect in 8.* as it would require both non-trivial alterations to the Tcl_ObjType structure and a thorough code-review of a large fraction of the core to ensure that there aren't any holes where something could slip through. The current policy is that internal representations are just caches of what can be derived (possibly in some context) from the utf-8 string version of the object. BTW, I've done "magic objects" in the past and it works fairly well so long as you don't look at them in any way that doesn't understand exactly what they are. Putting them into variables and lists is fine. Treating them as strings or ints and you are on dangerous ground. This is a FRQ, not a bug.
- login: "dkf"
- mimetype: "text/plain"
- subsystem changed to: "None"
- username: "dkf"
Ticket change [47ce7609de] (rid 99767) by dkf on 2003-06-12 15:29:52:
- assignee changed to: "dkf"
- resolution changed to: "Later"
- subsystem changed to: "10. Objects"
Ticket change [5c2a02fc88] (rid 115249) by dkf on 2003-06-25 03:07:30:
- title changed to: "Inhibit some type conversions"
Ticket change [4d2a74d66b] (rid 127017) by dkf on 2004-06-16 05:06:01:
- icomment:
Logged In: YES user_id=79902 See also RFE 219162
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment: