Artifacts Associated With Ticket 1893052
Ticket change [72b3680d07] (rid 100907) by nobody on 2008-02-13 20:02:31:
- assignee initialized to: "msofer"
- cmimetype initialized to: "text/plain"
- comment initialized to:
set a ... set b ... if {$a == $b} { ... } Regardless of the actual types of objects a and b, numerical comparison is coerced by Tcl engine if at all possible, which includes the case when string representations of both objects look like numbers. Both arguments are then converted to numeric types (e.g. via Tcl_GetWideIntFromObj), and the original object type information is irretrievably lost. This is a problem when custom type of an object cannot be restored from its string representation. - foundin initialized to: "None"
- is_private initialized to: "0"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "nobody"
- subsystem initialized to: "47. Bytecode Compiler"
- title initialized to:
Object type info can be lost after comparison (e.g. INST_EQ)
- type initialized to: "Bug"
Ticket change [817e244269] (rid 117046) by dgp on 2008-02-14 03:20:44:
- assignee changed to: "dgp"
- closedate changed to: "2008-02-13T20:20:44"
- closer changed to: "dgp"
- icomment:
Logged In: YES user_id=80530 Originator: NO Of course, strictly speaking, all Tcl values are string-based in their semantics, so an inability to restore from string rep is an unsupported (ab)use of the Tcl_ObjType system. That said, folks do make this sort of thing work acceptably well. Due to what is reported here, and other places where the core may shimmer intreps, if you have such a value that isn't fully specified by the string rep you have chosen, it is best if you choose a string rep that can't be converted to the known core types. You can only have your fragile value get converted via Tcl_GetWideIntFromObj() if you've chosen a string rep that is a valid wide integer. Don't Do That.
- login: "dgp"
- mimetype: "text/plain"
- resolution changed to: "Invalid"
- status changed to: "Pending"
- username: "dgp"
Ticket change [7c17d24e52] (rid 97021) by hobbs on 2008-02-14 04:28:54:
- icomment:
Logged In: YES user_id=72656 Originator: NO In addition, this is commonly handled by creating the string rep in the form of sprintf(buf, "foo%p", internalPtrVal), recognizing your handle by scan of the same and caching it in a hash table. You have to deal with refcounting and such, but this is just the nature of custom Tcl_Objs.
- login: "hobbs"
- mimetype: "text/plain"
- username: "hobbs"
- icomment:
Ticket change [1a77bb873d] (rid 122981) by nobody on 2008-02-14 08:08:04:
- icomment:
Logged In: NO A couple of comments: 1. I have a feeling that semantically read-only operations, such as comparison, have no right whatsoever to erase type information in an object of an unknown type, because there is no guarantee that the type conversion is reversible. To the best of my understanding, there is nothing in the Tcl library reference that would suggest that Tcl_SetFromAnyProc MUST always succeed. 2. Any assumption about performance gain due to conversion to integer, although generally correct for plain strings, may prove very wrong when applied universally to custom types, even if the conversion is reversible. 3. String representation of an object of a custom type may, in fact, be meaningful, as opposed to "foo%p".
- login: "nobody"
- mimetype: "text/plain"
- username: "nobody"
- icomment:
Ticket change [b6c082ffbc] (rid 125472) by nobody on 2008-02-14 08:08:05:
- status changed to: "Open"
Ticket change [04628d358e] (rid 119993) by dgp on 2008-02-14 23:13:56:
- closedate changed to: "2008-02-14T16:13:56"
- closer changed to: "dgp"
- icomment:
Logged In: YES user_id=80530 Originator: NO Your error is in thinking about this as "type information". That's not what it is. Tcl values are untyped, or string typed if you prefer. The internal rep is only a cache of the most recent conversion done so that if that same conversion is needed again (frequently the case) it need not be repeated. The objPtr->typePtr indicates which kind of conversion has been cached; nothing more. From this perspective, your claim "there is no guarantee that the type conversion is reversible" is simply false. The string value is the value. If you can't do what you need with the string value alone (plus possibly some state you've arranged to associate with the interp), then at best you have an abuse of the Tcl_Obj system, which might work if you take special care and jump through some hoops, but isn't the supported model. One hoop you can jump through that will help avoid this issue is to craft string reps that are not valid values of other known Tcl_ObjTypes. Finally, back to your original post, it may well be that you can avoid the immediate problem by using the "eq" operator instead of the "==" operator: set a ... set b ... if {$a eq $b} {...} - login: "dgp"
- mimetype: "text/plain"
- status changed to: "Closed"
- username: "dgp"