Skip to content
Tcl Source Code History Of Ticket 1893052
Login

History Of Ticket 1893052

Artifacts Associated With Ticket 1893052

  1. Ticket change [72b3680d07] (rid 100907) by nobody on 2008-02-13 20:02:31:

    1. assignee initialized to: "msofer"
    2. cmimetype initialized to: "text/plain"
    3. 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.
      
    4. foundin initialized to: "None"
    5. is_private initialized to: "0"
    6. priority initialized to: "5 Medium"
    7. resolution initialized to: "None"
    8. status initialized to: "Open"
    9. submitter initialized to: "nobody"
    10. subsystem initialized to: "47. Bytecode Compiler"
    11. title initialized to:
      Object type info can be lost after comparison (e.g. INST_EQ)
      
    12. type initialized to: "Bug"
  2. Ticket change [817e244269] (rid 117046) by dgp on 2008-02-14 03:20:44:

    1. assignee changed to: "dgp"
    2. closedate changed to: "2008-02-13T20:20:44"
    3. closer changed to: "dgp"
    4. 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.
      
      
      
    5. login: "dgp"
    6. mimetype: "text/plain"
    7. resolution changed to: "Invalid"
    8. status changed to: "Pending"
    9. username: "dgp"
  3. Ticket change [7c17d24e52] (rid 97021) by hobbs on 2008-02-14 04:28:54:

    1. 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.
      
      
    2. login: "hobbs"
    3. mimetype: "text/plain"
    4. username: "hobbs"
  4. Ticket change [1a77bb873d] (rid 122981) by nobody on 2008-02-14 08:08:04:

    1. 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".
      
      
    2. login: "nobody"
    3. mimetype: "text/plain"
    4. username: "nobody"
  5. Ticket change [b6c082ffbc] (rid 125472) by nobody on 2008-02-14 08:08:05:

    1. status changed to: "Open"
  6. Ticket change [04628d358e] (rid 119993) by dgp on 2008-02-14 23:13:56:

    1. closedate changed to: "2008-02-14T16:13:56"
    2. closer changed to: "dgp"
    3. 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} {...}
      
      
      
    4. login: "dgp"
    5. mimetype: "text/plain"
    6. status changed to: "Closed"
    7. username: "dgp"