Skip to content
Tcl Source Code History Of Ticket 218420
Login

History Of Ticket 218420

Artifacts Associated With Ticket 218420

  1. Ticket change [86a7efa796] (rid 131552) by nobody on 2000-10-26 00:57:24:

    1. assignee initialized to: "nobody"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      OriginalBugID: 5664 Bug
      Version: 8.2
      SubmitDate: '2000-05-24'
      LastModified: '2000-06-19'
      Severity: LOW
      Status: Closed
      Submitter: techsupp
      ChangedBy: ericm
      OS: Windows NT
      OSVersion: 4.0
      Machine: PC 300pl
      FixedDate: '2000-10-25'
      ClosedDate: '2000-06-19'
      
      
      Name:
      Hillel Avni
      
      ReproducibleScript:
      C++:
      The part that cause error:
      
      #include "tcl_class.h"
      
      int Tcl_cop_test_result(ClientData, Tcl_Interp *ti, int ac, Tcl_Obj *const av[])
      {
          Tcl_Obj       *result = Tcl_NewObj();
       unsigned long buf = 0xefbeadde;
      Tcl_AppendToObj(result, (char *)&buf, 4);
          Tcl_SetObjResult(ti, result);
      return TCL_OK;
      }
      
      main ()
      {
      Tcl            t;
         t.CreateObjCommand("tcop_test_result",           Tcl_cop_test_result);
      t.EvalFile(av[1]);
      }
      
      TCL part:
      
      test.tcl:
      #### For DEBUG
      
      proc tr {} {
         set memory [tcop_test_result]
        binary scan $memory  H* DEBUG_unit
        puts "DEBUG: DEBUG_unit in TR = $DEBUG_unit\n"
      
      }
      tr
      
      C++ sources:
      
      tcl_class.h:
      #ifndef __TCL_H
      #define __TCL_H
      
      #include <string.h>
      #include <tcl.h>
      
      #define TCL_NOT_COMPLETED -1
      
      class Tcl
      {
      private:
          Tcl_Interp  *ti;
          Tcl_DString internal_cmd;
      public:
          char   *result;
          Tcl()
          {
              ti = Tcl_CreateInterp();
              Tcl_DStringInit(&internal_cmd);
              result = ti->result;
          };
          ~Tcl()
          {
              Tcl_DStringFree(&internal_cmd);
              // Why Tcl fails if I delete interpreter in the destructor ???
              // I have no idea. Don't forget to take care about it after
              // other urgent tasks. Meanwhile, the next kludge is works...
      
              //Tcl_DeleteInterp(ti);
          };
          Tcl_Interp *GetInterp()                { return ti; };
          int  SingleEval(const char *script)
          {
              int rc = Tcl_Eval(ti, (char *)script);
              result = ti->result;
              return rc;
          };
          int  SplitList(const char *list, int *ac, char ***av)
          {
              if (list)
                  return Tcl_SplitList(ti, (char *)list, ac, av);
              *ac = 0;
              *av = NULL;
              return TCL_OK;
          };
          int  Eval(const char *script, Tcl_DString *cmd = (Tcl_DString *)0);
          int  GetInt(const char *name, const int flags=TCL_GLOBAL_ONLY);
          int  EvalFile(const char *filename)
          {
              int rc = Tcl_EvalFile(ti, (char *)filename);
              result = ti->result;
              return rc;
          };
      
          int  GetExplicInt(const char *s, int *val)
          {
              return Tcl_GetInt(ti, (char *)s, val);
          };
      
          void CreateCommand(const char *name, Tcl_CmdProc *proc)
          {
              Tcl_CreateCommand(ti, (char *)name, proc, (ClientData) this, NULL);
          };
      
      //DEBUG
          void CreateObjCommand(char *name, Tcl_ObjCmdProc *proc)
          {
              Tcl_CreateObjCommand(ti, (char *)name, proc, (ClientData) this, NULL);
          };
      //
          void SetResult(const char *res)
          {
              Tcl_SetResult(ti, (char *)res, TCL_VOLATILE);
          };
      
          void AppResult(const char *res)
          {
              Tcl_AppendResult(ti, (char *)res, NULL);
          };
      
          int GetLongFromObj(Tcl_Obj *ob, long *res)
          {
              return Tcl_GetLongFromObj(ti, ob, res);
          };
      
          int GetDoubleFromObj(Tcl_Obj *ob, double *res)
          {
              return Tcl_GetDoubleFromObj(ti, ob, res);
          };
      
          char *GetVar(const char *name, const int flags=TCL_GLOBAL_ONLY)
          {
              return Tcl_GetVar(ti, (char *)name, flags);
          };
      
          Tcl_Obj *ObjGetVar(const char *name, const int flags=TCL_GLOBAL_ONLY)
          {
              Tcl_Obj *rc, *p1 = Tcl_NewStringObj((char *)name, -1);
              rc = Tcl_ObjGetVar2(ti, p1, NULL, flags);
              Tcl_DecrRefCount(p1);
              return rc;
          };
      
          int GetVarAsInt(const char *name, int *val, const int flags=TCL_GLOBAL_ONLY)
          {
              char *var = Tcl_GetVar(ti, (char *)name, flags);
              if (var)
                  return Tcl_GetInt(ti, var, val);
              else
                  return TCL_ERROR;
          };
          char *GetVar2(const char *name1, const char *name2,
                        const int flags=TCL_GLOBAL_ONLY)
          {
              return Tcl_GetVar2(ti, (char *)name1, (char *)name2, flags);
          };
      
      /*DEBUG
          Tcl_Obj *ObjGetVar2(const char *name1, const char *name2,
                              const int flags=TCL_GLOBAL_ONLY)
          {
              Tcl_Obj *rc, *p1 = Tcl_NewStringObj((char *)name1, -1),
                  *p2 = Tcl_NewStringObj((char *%2ÿ9name2, -1);
              rc = Tcl_ObjGetVar2(ti, p1, p2, flags);
              Tcl_DecrRefCount(p1);
              Tcl_DecrRefCount(p2);
              return rc;
          };
      */
          int GetVar2AsInt(const char *name1, const char *name2, int *val,
                           const int flags=TCL_GLOBAL_ONLY)
          {
              char *var = Tcl_GetVar2(ti, (char *)name1, (char *)name2, flags);
              if (var)
                  return Tcl_GetInt(ti, var, val);
              else
                  return TCL_ERROR;
          };
          char *SetVar(const char *name, const char *v,
                       const int flags=TCL_GLOBAL_ONLY)
          {
              return Tcl_SetVar(ti, (char *)name, (char *)v, flags);
          };
          char *SetVar2(const char *name1, const char *name2, const char *v,
                        const int flags=TCL_GLOBAL_ONLY)
          {
              return Tcl_SetVar2(ti, (char *)name1, (char *)name2, (char *)v, flags);
          };
      
          Tcl_Obj *ObjSetVar(const char *name, Tcl_Obj *v,
                             const int flags=TCL_GLOBAL_ONLY)
          {
              Tcl_Obj *rc, *p1 = Tcl_NewStringObj((char *)name, -1);
              rc = Tcl_ObjSetVar2(ti, p1, NULL, v, flags);
              Tcl_DecrRefCount(p1);
              return rc;
          };
      
      /* ALREADY DEFINED
       Tcl_Obj *ObjSetVar2(const char *name1, const char *name2, Tcl_Obj *v,
                              const int flags=TCL_GLOBAL_ONLY)
          {
              Tcl_Obj *rc, *p1 = Tcl_NewStringObj((char *)name1, -1),
                  *p2 = Tcl_NewStringObj((char *)name2, -1);
              rc = Tcl_ObjSetVar2(ti, p1, p2, v, flags);
              Tcl_DecrRefCount(p1);
              Tcl_DecrRefCount(p2);
              return rc;
          };
      */
          int  UnSetVar(const char *name, const int flags=TCL_GLOBAL_ONLY)
               { return Tcl_UnsetVar(ti, (char *)name, flags);     };
      };
      
      class TclString
      {
      private:
          Tcl_DString s;
      public:
          TclString()                 { Tcl_DStringInit(&s); };
          ~TclString()                { Tcl_DStringFree(&s); };
          TclString(const char *str)
          {
              Tcl_DStringInit(&s);
              Tcl_DStringAppend(&s, (char *)str, -1);
          };
          TclString(TclString& old)
          {
              Tcl_DStringInit(&s);
              app(old.s.string, old.s.length);
          };
          void reset()
          {
              Tcl_DStringFree(&s);
              Tcl_DStringInit(&s);
          };
          void empty()                    { reset(); };
       ÿ   void app(const char *a)         { Tcl_DStringAppend(&s, (char *)a, -1); };
          void app(const char *a, int l)  { Tcl_DStringAppend(&s, (char *)a, l);  };
          void set(const char *a)         { empty(); app(a);                      };
          void set(const char *a, int l)  { empty(); app(a, l);                   };
          int  len()                      { return s.length;                      };
          char *get()                     { return s.string;                      };
          void operator+= (const char *a) { app(a);                               };
          void operator= (const char *a)  { set(a);                               };
          void operator= (const int *i)   { if (i==0) empty();                    };
          operator long ()                { return (long)len();                   };
          operator int ()                 { return len();                         };
          operator char* ()               { return get();                         };
          operator unsigned char* ()      { return (unsigned char*)get();         };
      };
      
      template <class D> class TclArray
      {
      private:
          D              NullObject;
          Tcl_HashTable  h;      // Hash table
          Tcl_HashEntry  *it;    // Iterator (hash entry pointer)
          Tcl_HashSearch hs;     // Hash search
          void DelAllMembers()
          {
              D *d;
      
              for (first(); fetch_data(d); next())
                  delete d;
          };
      public:
          TclArray(D null_object)
          {
              NullObject = null_object;
              Tcl_InitHashTable(&h, TCL_STRING_KEYS);
          };
          ~TclArray()                { DelAllMembers(); Tcl_DeleteHashTable(&h); };
          TclArray(TclArray& old)
          {
              char *k;
              D    *pd;
      
              Tcl_InitHashTable(&h, TCL_STRING_KEYS);
              for (old.first(); old.fetch(&k, pd); old.next())
                  insert(k, *pd);
          };
          void reset()
          {
              DelAllMembers();
              Tcl_DeleteHashTable(&h);
              Tcl_InitHashTable(&h, TCL_STRING_KEYS);
          };
          void empty()                    { reset(); };
          int replace(const char *key, const D& data)
          {
              return insert(key, data, 1);
          };
          int count()
          {
              int i=0;
      
              for (first(); fetch(); next())
                  i++;
              return i;
          };
      
          // Primary access methods
          int insert(const char *key, const D& data, int overwrite=0);
          int remove(const char *key);
          int get(const char *key, D& data);
          int get(const char *key, D* &pdata);
      
          // Operators ...
          void operator-= (const char *key)   { remove(key);          };
          operator long ()                    { return (long)count(); };
          operator int ()                     { return count();       };
          D& operator[] (const char *key)
          {
              D *pd;
      
              if (get(key, pd) == TCL_OK)
                  return *pd;
              pd = &NullObject;
              insert(key, *pd);
              if (get(key, pd) != TCL_OK)
                  // Error
                  return NullObject;
              return *pd;
          };
      
          /*
           * Iterations
           * ----------
           */
      
          // FIRST
          int first()
          {
              it = (Tcl_HashEntry *)0;
              next();
              return fetch();
          };
          int first(char *key)
          {
              if (first())
                  return fetch(key);
              else
                  return 0;
          };
          int first(char **pkey)
          {
              if (first())
                  return fetch(pkey);
              else
                  return 0;
          };
          int first_data(D& data)
          {
              if (first())
                  return fetch_data(data);
              else
                  return 0;
          };
          int first_data(D* &pdata)
          {
              if (first())
                  return fetch_data(pdata);
              else
                  return 0;
          };
          int first(char *key, D& data)
          {
              if (first())
                  return fetch(key, data);
              else
                  return 0;
          };
          int first(char **pkey, D* &pdata)
          {
              if (first())
                  return fetch(pkey, pdata);
              else
                  return 0;
          };
      
          // FETCH
          int fetch()
          {
              if (it)
                  return 1;
              return 0;
          };
          int fetch(char *key)
          {
              if (fetch())
              {
                  strcpy(key, Tcl_GetHashKey(&h, it));
                  return 1;
              }
              else
                  return 0;
          };
          int fetch(char **pkey)
          {
              if (fetch())
              {
                  *pkey = Tcl_GetHashKey(&h, it);
                  return 1;
              }
              else
                  return 0;
          };
          int fetch_data(D& data)
          {
              if (fetch())
              {
                  data = *((D *)Tcl_GetHashValue(it));
                  return 1;
              }
              else
                  return 0;
          };
          int fetch_data(D* &pdata)
          {
              if (fetch())
              {
                  pdata = (D *)Tcl_GetHashValue(it);
                  return 1;
              }
              else
                  return 0;
          };
          int fetch(char *key, D& data)
          {
              if (fetch())
              {
                  strcpy(key, Tcl_GetHashKey(&h, it));
                  data = *((D *)Tcl_GetHashValue(it));
                  return 1;
              }
              else
                  return 0;
          };
          int fetch(char **pkey, D* &pdata)
          {
              if (fetch())
              {
                  *pkey = Tcl_GetHashKey(&h, it);
                  pdata = (D *)Tcl_GetHashValue(it);
                  return 1;
              }
              else
                  return 0;
          };
      
          // NEXT
          void next()
          {
              if (it)
                  it = Tcl_NextHashEntry(&hs);
              else
                  it = Tcl_FirstHashEntry(&h, &hs);
          };
      };
      
      template <class D> int
      TclArray<D>::insert(const char *key, const D& data, int overwrite)
      {
          int is_new = 0;
          D *d = new D(data);
      
          Tcl_HashEntry *e = Tcl_CreateHashEntry(&h, (char *)key, &is_new);
          if (!is_new && !overwrite)
              return TCL_ERROR;
          Tcl_SetHashValue(e, d);
          return TCL_OK;
      }
      
      template <class D> int
      TclArray<D>::remove(const char *key)
      {
          D *d;
          Tcl_HashEntry *e = Tcl_FindHashEntry(&h, (char *)key);
          if (e)
          {
              d = (D *)Tcl_GetHashValue(e);
              delete d;
              Tcl_DeleteHashEntry(e);
              return TCL_OK;
          }
          else
              return TCL_ERROR;
      }
      
      template <class D> int
      TclArray<D>::get(const char *key, D& data)
      {
          Tcl_HashEntry *e = Tcl_FindHashEntry(&h, (char *)key);
          if (e)
          {
              data = *((D *)Tcl_GetHashValue(e));
              return TCL_OK;
          }
          else
              return TCL_ERROR;
      }
      
      template <class D> int
      TclArray<D>::get(const char *key, D* &pdata)
      {
          Tcl_HashEntry *e = Tcl_FindHashEntry(&h, (char *)key);
          if (e)
          {
              pdata = (D *)Tcl_GetHashValue(e);
              return TCL_OK;
          }
          else
              return TCL_ERROR;
      }
      
      #endif
      
      tcl_class.cpp:
      #include "tcl_class.h"
      
      int Tcl::GetInt(const char *name, const int flags)
      {
          int  rc;
          char *val = GetVar(name, flags);
      
          if (val)
              if (Tcl_GetInt(ti, val, &rc) == TCL_OK)
                return rc;
          return 0;
      }
      
      int Tcl::Eval(const char *script, Tcl_DString *cmd)
      {
          int rc;
      
          if (cmd == (Tcl_DString *)0)
              cmd = &internal_cmd;
      
          Tcl_DStringAppend(cmd, (char *)script, -1);
          if (Tcl_CommandComplete(cmd->string))
          {
              rc = Tcl_RecordAndEval(ti, cmd->string, 0);
              Tcl_DStringFree(cmd);
              Tcl_DStringInit(cmd);
              result = ti->result;
              return rc;
          }
          else
              return TCL_NOT_COMPLETED;
      }
      
      ObservedBehavior:
      I Tcl_SetObjResult 0xdeadbeef, but when I binary scan it. I get adbeef, i.e, first byte disapears.
      
      DesiredBehavior:
      I except to get 0xdeadbeef in the binary scan.
      
      
      
      The problem is that when you use "Tcl_AppendToObj", Tcl is performing UTF conversions on the data.  Since your data is binary, you want to avoid that conversion.  You should use
      
      Tcl_SetByteArrayObj(result, (char *)&buf, 4)
      
      instead.  This will avoid the conversion and give you the results you are expecting.
      
      - eric
      
      -- 06/19/2000 ericm
      
      
      
    4. foundin initialized to: "obsolete: 8.2"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. status initialized to: "Open"
    8. submitter initialized to: "nobody"
    9. subsystem initialized to: "69. Other"
    10. title initialized to: "Tcl_SetObjResult error"
    11. type initialized to: "Bug"
  2. Ticket change [232a905b46] (rid 130874) by welch on 2000-10-26 08:21:19:

    1. closedate changed to: "2000-10-26T01:21:19"
    2. closer changed to: "welch"
    3. priority changed to: "2"
    4. resolution changed to: "Fixed"
    5. status changed to: "Closed"
  3. Ticket change [c81e1c873d] (rid 122057) by dgp on 2001-04-19 02:59:14:

    1. closedate changed to: "2001-04-18T19:59:14"
    2. closer changed to: "dgp"
    3. subsystem changed to: "45. Parsing and Eval"