Fork me on GitHub

Changeset adeddd8 in git for external/tcl/tclObj.c


Ignore:
Timestamp:
May 29, 2019, 2:53:12 PM (5 years ago)
Author:
Pavel Demin <pavel-demin@…>
Branches:
ImprovedOutputFile, Timing, master
Children:
969eb19
Parents:
e15936c
Message:

remove debug code from Tcl

File:
1 edited

Legend:

Unmodified
Added
Removed
  • external/tcl/tclObj.c

    re15936c radeddd8  
    3636
    3737char *tclEmptyStringRep = NULL;
    38 
    39 /*
    40  * Count of the number of Tcl objects every allocated (by Tcl_NewObj) and
    41  * freed (by TclFreeObj).
    42  */
    43 
    44 #ifdef TCL_COMPILE_STATS
    45 long tclObjsAlloced = 0;
    46 long tclObjsFreed = 0;
    47 #endif /* TCL_COMPILE_STATS */
    4838
    4939/*
     
    417407 * Tcl_NewObj --
    418408 *
    419  *      This procedure is normally called when not debugging: i.e., when
    420  *      TCL_MEM_DEBUG is not defined. It creates new Tcl objects that denote
    421  *      the empty string. These objects have a NULL object type and NULL
    422  *      string representation byte pointer. Type managers call this routine
    423  *      to allocate new objects that they further initialize.
    424  *
    425  *      When TCL_MEM_DEBUG is defined, this procedure just returns the
    426  *      result of calling the debugging version Tcl_DbNewObj.
     409 *      This procedure creates new Tcl objects that denote the empty string.
     410 *      These objects have a NULL object type and NULL string representation
     411 *      byte pointer. Type managers call this routine to allocate new objects
     412 *      that they further initialize.
    427413 *
    428414 * Results:
     
    431417 *      is set to 0.
    432418 *
    433  * Side effects:
    434  *      If compiling with TCL_COMPILE_STATS, this procedure increments
    435  *      the global count of allocated objects (tclObjsAlloced).
    436  *
    437  *----------------------------------------------------------------------
    438  */
    439 
    440 #ifdef TCL_MEM_DEBUG
    441 #undef Tcl_NewObj
    442 
    443 Tcl_Obj *
    444 Tcl_NewObj()
    445 {
    446     return Tcl_DbNewObj("unknown", 0);
    447 }
    448 
    449 #else /* if not TCL_MEM_DEBUG */
     419 *----------------------------------------------------------------------
     420 */
    450421
    451422Tcl_Obj *
     
    468439    objPtr->length   = 0;
    469440    objPtr->typePtr  = NULL;
    470 #ifdef TCL_COMPILE_STATS
    471     tclObjsAlloced++;
    472 #endif /* TCL_COMPILE_STATS */
    473441    return objPtr;
    474442}
    475 #endif /* TCL_MEM_DEBUG */
    476 
    477 
    478 /*
    479  *----------------------------------------------------------------------
    480  *
    481  * Tcl_DbNewObj --
    482  *
    483  *      This procedure is normally called when debugging: i.e., when
    484  *      TCL_MEM_DEBUG is defined. It creates new Tcl objects that denote the
    485  *      empty string. It is the same as the Tcl_NewObj procedure above
    486  *      except that it calls Tcl_DbCkalloc directly with the file name and
    487  *      line number from its caller. This simplifies debugging since then
    488  *      the checkmem command will report the correct file name and line
    489  *      number when reporting objects that haven't been freed.
    490  *
    491  *      When TCL_MEM_DEBUG is not defined, this procedure just returns the
    492  *      result of calling Tcl_NewObj.
    493  *
    494  * Results:
    495  *      The result is a newly allocated that represents the empty string.
    496  *      The new object's typePtr is set NULL and its ref count is set to 0.
    497  *
    498  * Side effects:
    499  *      If compiling with TCL_COMPILE_STATS, this procedure increments
    500  *      the global count of allocated objects (tclObjsAlloced).
    501  *
    502  *----------------------------------------------------------------------
    503  */
    504 
    505 #ifdef TCL_MEM_DEBUG
    506 
    507 Tcl_Obj *
    508 Tcl_DbNewObj(file, line)
    509     register char *file;        /* The name of the source file calling this
    510                                  * procedure; used for debugging. */
    511     register int line;          /* Line number in the source file; used
    512                                  * for debugging. */
    513 {
    514     register Tcl_Obj *objPtr;
    515 
    516     /*
    517      * If debugging Tcl's memory usage, allocate the object using ckalloc.
    518      * Otherwise, allocate it using the list of free Tcl_Objs we maintain.
    519      */
    520 
    521     objPtr = (Tcl_Obj *) Tcl_DbCkalloc(sizeof(Tcl_Obj), file, line);
    522     objPtr->refCount = 0;
    523     objPtr->bytes    = tclEmptyStringRep;
    524     objPtr->length   = 0;
    525     objPtr->typePtr  = NULL;
    526 #ifdef TCL_COMPILE_STATS
    527     tclObjsAlloced++;
    528 #endif /* TCL_COMPILE_STATS */
    529     return objPtr;
    530 }
    531 
    532 #else /* if not TCL_MEM_DEBUG */
    533 
    534 Tcl_Obj *
    535 Tcl_DbNewObj(file, line)
    536     char *file;                 /* The name of the source file calling this
    537                                  * procedure; used for debugging. */
    538     int line;                   /* Line number in the source file; used
    539                                  * for debugging. */
    540 {
    541     return Tcl_NewObj();
    542 }
    543 #endif /* TCL_MEM_DEBUG */
    544443
    545444
     
    609508 *      after deallocating the string representation and calling the
    610509 *      type-specific Tcl_FreeInternalRepProc to deallocate the object's
    611  *      internal representation. If compiling with TCL_COMPILE_STATS,
    612  *      this procedure increments the global count of freed objects
    613  *      (tclObjsFreed).
     510 *      internal representation.
    614511 *
    615512 *----------------------------------------------------------------------
     
    622519    register Tcl_ObjType *typePtr = objPtr->typePtr;
    623520   
    624 #ifdef TCL_MEM_DEBUG
    625     if ((objPtr)->refCount < -1) {
    626         panic("Reference count for %lx was negative", objPtr);
    627     }
    628 #endif /* TCL_MEM_DEBUG */
    629 
    630521    Tcl_InvalidateStringRep(objPtr);
    631522    if ((typePtr != NULL) && (typePtr->freeIntRepProc != NULL)) {
     
    634525
    635526    /*
    636      * If debugging Tcl's memory usage, deallocate the object using ckfree.
    637      * Otherwise, deallocate it by adding it onto the list of free
     527     * Deallocate the object by adding it onto the list of free
    638528     * Tcl_Objs we maintain.
    639529     */
    640530   
    641 #ifdef TCL_MEM_DEBUG
    642     ckfree((char *) objPtr);
    643 #else
    644531    objPtr->internalRep.otherValuePtr = (VOID *) tclFreeObjList;
    645532    tclFreeObjList = objPtr;
    646 #endif /* TCL_MEM_DEBUG */
    647 
    648 #ifdef TCL_COMPILE_STATS   
    649     tclObjsFreed++;
    650 #endif /* TCL_COMPILE_STATS */   
    651533}
    652534
     
    794676 * Tcl_NewBooleanObj --
    795677 *
    796  *      This procedure is normally called when not debugging: i.e., when
    797  *      TCL_MEM_DEBUG is not defined. It creates a new boolean object and
    798  *      initializes it from the argument boolean value. A nonzero
    799  *      "boolValue" is coerced to 1.
    800  *
    801  *      When TCL_MEM_DEBUG is defined, this procedure just returns the
    802  *      result of calling the debugging version Tcl_DbNewBooleanObj.
     678 *      This procedure creates a new boolean object and initializes it from
     679 *      the argument boolean value. A nonzero "boolValue" is coerced to 1.
    803680 *
    804681 * Results:
     
    811688 *----------------------------------------------------------------------
    812689 */
    813 
    814 #ifdef TCL_MEM_DEBUG
    815 #undef Tcl_NewBooleanObj
    816690
    817691Tcl_Obj *
     
    819693    register int boolValue;     /* Boolean used to initialize new object. */
    820694{
    821     return Tcl_DbNewBooleanObj(boolValue, "unknown", 0);
    822 }
    823 
    824 #else /* if not TCL_MEM_DEBUG */
    825 
    826 Tcl_Obj *
    827 Tcl_NewBooleanObj(boolValue)
    828     register int boolValue;     /* Boolean used to initialize new object. */
    829 {
    830695    register Tcl_Obj *objPtr;
    831696
     
    837702    return objPtr;
    838703}
    839 #endif /* TCL_MEM_DEBUG */
    840 
    841 
    842 /*
    843  *----------------------------------------------------------------------
    844  *
    845  * Tcl_DbNewBooleanObj --
    846  *
    847  *      This procedure is normally called when debugging: i.e., when
    848  *      TCL_MEM_DEBUG is defined. It creates new boolean objects. It is the
    849  *      same as the Tcl_NewBooleanObj procedure above except that it calls
    850  *      Tcl_DbCkalloc directly with the file name and line number from its
    851  *      caller. This simplifies debugging since then the checkmem command
    852  *      will report the correct file name and line number when reporting
    853  *      objects that haven't been freed.
    854  *
    855  *      When TCL_MEM_DEBUG is not defined, this procedure just returns the
    856  *      result of calling Tcl_NewBooleanObj.
    857  *
    858  * Results:
    859  *      The newly created object is returned. This object will have an
    860  *      invalid string representation. The returned object has ref count 0.
    861  *
    862  * Side effects:
    863  *      None.
    864  *
    865  *----------------------------------------------------------------------
    866  */
    867 
    868 #ifdef TCL_MEM_DEBUG
    869 
    870 Tcl_Obj *
    871 Tcl_DbNewBooleanObj(boolValue, file, line)
    872     register int boolValue;     /* Boolean used to initialize new object. */
    873     char *file;                 /* The name of the source file calling this
    874                                  * procedure; used for debugging. */
    875     int line;                   /* Line number in the source file; used
    876                                  * for debugging. */
    877 {
    878     register Tcl_Obj *objPtr;
    879 
    880     TclDbNewObj(objPtr, file, line);
    881     objPtr->bytes = NULL;
    882    
    883     objPtr->internalRep.longValue = (boolValue? 1 : 0);
    884     objPtr->typePtr = &tclBooleanType;
    885     return objPtr;
    886 }
    887 
    888 #else /* if not TCL_MEM_DEBUG */
    889 
    890 Tcl_Obj *
    891 Tcl_DbNewBooleanObj(boolValue, file, line)
    892     register int boolValue;     /* Boolean used to initialize new object. */
    893     char *file;                 /* The name of the source file calling this
    894                                  * procedure; used for debugging. */
    895     int line;                   /* Line number in the source file; used
    896                                  * for debugging. */
    897 {
    898     return Tcl_NewBooleanObj(boolValue);
    899 }
    900 #endif /* TCL_MEM_DEBUG */
    901704
    902705
     
    1178981 * Tcl_NewDoubleObj --
    1179982 *
    1180  *      This procedure is normally called when not debugging: i.e., when
    1181  *      TCL_MEM_DEBUG is not defined. It creates a new double object and
    1182  *      initializes it from the argument double value.
    1183  *
    1184  *      When TCL_MEM_DEBUG is defined, this procedure just returns the
    1185  *      result of calling the debugging version Tcl_DbNewDoubleObj.
     983 *      This procedure creates a new double object and initializes it from
     984 *      the argument double value.
    1186985 *
    1187986 * Results:
     
    1194993 *----------------------------------------------------------------------
    1195994 */
    1196 
    1197 #ifdef TCL_MEM_DEBUG
    1198 #undef Tcl_NewDoubleObj
    1199995
    1200996Tcl_Obj *
     
    1202998    register double dblValue;   /* Double used to initialize the object. */
    1203999{
    1204     return Tcl_DbNewDoubleObj(dblValue, "unknown", 0);
    1205 }
    1206 
    1207 #else /* if not TCL_MEM_DEBUG */
    1208 
    1209 Tcl_Obj *
    1210 Tcl_NewDoubleObj(dblValue)
    1211     register double dblValue;   /* Double used to initialize the object. */
    1212 {
    12131000    register Tcl_Obj *objPtr;
    12141001
     
    12201007    return objPtr;
    12211008}
    1222 #endif /* if TCL_MEM_DEBUG */
    1223 
    1224 
    1225 /*
    1226  *----------------------------------------------------------------------
    1227  *
    1228  * Tcl_DbNewDoubleObj --
    1229  *
    1230  *      This procedure is normally called when debugging: i.e., when
    1231  *      TCL_MEM_DEBUG is defined. It creates new double objects. It is the
    1232  *      same as the Tcl_NewDoubleObj procedure above except that it calls
    1233  *      Tcl_DbCkalloc directly with the file name and line number from its
    1234  *      caller. This simplifies debugging since then the checkmem command
    1235  *      will report the correct file name and line number when reporting
    1236  *      objects that haven't been freed.
    1237  *
    1238  *      When TCL_MEM_DEBUG is not defined, this procedure just returns the
    1239  *      result of calling Tcl_NewDoubleObj.
    1240  *
    1241  * Results:
    1242  *      The newly created object is returned. This object will have an
    1243  *      invalid string representation. The returned object has ref count 0.
    1244  *
    1245  * Side effects:
    1246  *      None.
    1247  *
    1248  *----------------------------------------------------------------------
    1249  */
    1250 
    1251 #ifdef TCL_MEM_DEBUG
    1252 
    1253 Tcl_Obj *
    1254 Tcl_DbNewDoubleObj(dblValue, file, line)
    1255     register double dblValue;   /* Double used to initialize the object. */
    1256     char *file;                 /* The name of the source file calling this
    1257                                  * procedure; used for debugging. */
    1258     int line;                   /* Line number in the source file; used
    1259                                  * for debugging. */
    1260 {
    1261     register Tcl_Obj *objPtr;
    1262 
    1263     TclDbNewObj(objPtr, file, line);
    1264     objPtr->bytes = NULL;
    1265    
    1266     objPtr->internalRep.doubleValue = dblValue;
    1267     objPtr->typePtr = &tclDoubleType;
    1268     return objPtr;
    1269 }
    1270 
    1271 #else /* if not TCL_MEM_DEBUG */
    1272 
    1273 Tcl_Obj *
    1274 Tcl_DbNewDoubleObj(dblValue, file, line)
    1275     register double dblValue;   /* Double used to initialize the object. */
    1276     char *file;                 /* The name of the source file calling this
    1277                                  * procedure; used for debugging. */
    1278     int line;                   /* Line number in the source file; used
    1279                                  * for debugging. */
    1280 {
    1281     return Tcl_NewDoubleObj(dblValue);
    1282 }
    1283 #endif /* TCL_MEM_DEBUG */
    12841009
    12851010
     
    15311256 * Tcl_NewIntObj --
    15321257 *
    1533  *      If a client is compiled with TCL_MEM_DEBUG defined, calls to
    1534  *      Tcl_NewIntObj to create a new integer object end up calling the
    1535  *      debugging procedure Tcl_DbNewLongObj instead.
    1536  *
    1537  *      Otherwise, if the client is compiled without TCL_MEM_DEBUG defined,
    1538  *      calls to Tcl_NewIntObj result in a call to one of the two
     1258 *      Calls to Tcl_NewIntObj result in a call to one of the two
    15391259 *      Tcl_NewIntObj implementations below. We provide two implementations
    15401260 *      so that the Tcl core can be compiled to do memory debugging of the
     
    15561276 */
    15571277
    1558 #ifdef TCL_MEM_DEBUG
    1559 #undef Tcl_NewIntObj
    1560 
    15611278Tcl_Obj *
    15621279Tcl_NewIntObj(intValue)
    15631280    register int intValue;      /* Int used to initialize the new object. */
    15641281{
    1565     return Tcl_DbNewLongObj((long)intValue, "unknown", 0);
    1566 }
    1567 
    1568 #else /* if not TCL_MEM_DEBUG */
    1569 
    1570 Tcl_Obj *
    1571 Tcl_NewIntObj(intValue)
    1572     register int intValue;      /* Int used to initialize the new object. */
    1573 {
    15741282    register Tcl_Obj *objPtr;
    15751283
     
    15811289    return objPtr;
    15821290}
    1583 #endif /* if TCL_MEM_DEBUG */
    15841291
    15851292
     
    18561563 * Tcl_NewLongObj --
    18571564 *
    1858  *      If a client is compiled with TCL_MEM_DEBUG defined, calls to
    1859  *      Tcl_NewLongObj to create a new long integer object end up calling
    1860  *      the debugging procedure Tcl_DbNewLongObj instead.
    1861  *
    1862  *      Otherwise, if the client is compiled without TCL_MEM_DEBUG defined,
    1863  *      calls to Tcl_NewLongObj result in a call to one of the two
     1565 *      Calls to Tcl_NewLongObj result in a call to one of the two
    18641566 *      Tcl_NewLongObj implementations below. We provide two implementations
    18651567 *      so that the Tcl core can be compiled to do memory debugging of the
     
    18811583 */
    18821584
    1883 #ifdef TCL_MEM_DEBUG
    1884 #undef Tcl_NewLongObj
    1885 
    18861585Tcl_Obj *
    18871586Tcl_NewLongObj(longValue)
     
    18891588                                 * new object. */
    18901589{
    1891     return Tcl_DbNewLongObj(longValue, "unknown", 0);
    1892 }
    1893 
    1894 #else /* if not TCL_MEM_DEBUG */
    1895 
    1896 Tcl_Obj *
    1897 Tcl_NewLongObj(longValue)
    1898     register long longValue;    /* Long integer used to initialize the
    1899                                  * new object. */
    1900 {
    19011590    register Tcl_Obj *objPtr;
    19021591
     
    19081597    return objPtr;
    19091598}
    1910 #endif /* if TCL_MEM_DEBUG */
    19111599
    19121600
     
    19161604 * Tcl_DbNewLongObj --
    19171605 *
    1918  *      If a client is compiled with TCL_MEM_DEBUG defined, calls to
    1919  *      Tcl_NewIntObj and Tcl_NewLongObj to create new integer or
    1920  *      long integer objects end up calling the debugging procedure
    1921  *      Tcl_DbNewLongObj instead. We provide two implementations of
    1922  *      Tcl_DbNewLongObj so that whether the Tcl core is compiled to do
    1923  *      memory debugging of the core is independent of whether a client
    1924  *      requests debugging for itself.
    1925  *
    1926  *      When the core is compiled with TCL_MEM_DEBUG defined,
    1927  *      Tcl_DbNewLongObj calls Tcl_DbCkalloc directly with the file name and
    1928  *      line number from its caller. This simplifies debugging since then
    1929  *      the checkmem command will report the caller's file name and line
    1930  *      number when reporting objects that haven't been freed.
    1931  *
    1932  *      Otherwise, when the core is compiled without TCL_MEM_DEBUG defined,
    1933  *      this procedure just returns the result of calling Tcl_NewLongObj.
     1606 *      This procedure just returns the result of calling Tcl_NewLongObj.
    19341607 *
    19351608 * Results:
     
    19431616 *----------------------------------------------------------------------
    19441617 */
    1945 
    1946 #ifdef TCL_MEM_DEBUG
    19471618
    19481619Tcl_Obj *
     
    19551626                                 * for debugging. */
    19561627{
    1957     register Tcl_Obj *objPtr;
    1958 
    1959     TclDbNewObj(objPtr, file, line);
    1960     objPtr->bytes = NULL;
    1961    
    1962     objPtr->internalRep.longValue = longValue;
    1963     objPtr->typePtr = &tclIntType;
    1964     return objPtr;
    1965 }
    1966 
    1967 #else /* if not TCL_MEM_DEBUG */
    1968 
    1969 Tcl_Obj *
    1970 Tcl_DbNewLongObj(longValue, file, line)
    1971     register long longValue;    /* Long integer used to initialize the
    1972                                  * new object. */
    1973     char *file;                 /* The name of the source file calling this
    1974                                  * procedure; used for debugging. */
    1975     int line;                   /* Line number in the source file; used
    1976                                  * for debugging. */
    1977 {
    19781628    return Tcl_NewLongObj(longValue);
    19791629}
    1980 #endif /* TCL_MEM_DEBUG */
    19811630
    19821631
     
    20601709    return result;
    20611710}
    2062 
    2063 
    2064 /*
    2065  *----------------------------------------------------------------------
    2066  *
    2067  * Tcl_DbIncrRefCount --
    2068  *
    2069  *      This procedure is normally called when debugging: i.e., when
    2070  *      TCL_MEM_DEBUG is defined. This checks to see whether or not
    2071  *      the memory has been freed before incrementing the ref count.
    2072  *
    2073  *      When TCL_MEM_DEBUG is not defined, this procedure just increments
    2074  *      the reference count of the object.
    2075  *
    2076  * Results:
    2077  *      None.
    2078  *
    2079  * Side effects:
    2080  *      The object's ref count is incremented.
    2081  *
    2082  *----------------------------------------------------------------------
    2083  */
    2084 
    2085 void
    2086 Tcl_DbIncrRefCount(objPtr, file, line)
    2087     register Tcl_Obj *objPtr;   /* The object we are adding a reference to. */
    2088     char *file;                 /* The name of the source file calling this
    2089                                  * procedure; used for debugging. */
    2090     int line;                   /* Line number in the source file; used
    2091                                  * for debugging. */
    2092 {
    2093 #ifdef TCL_MEM_DEBUG
    2094     if (objPtr->refCount == 0x61616161) {
    2095         fprintf(stderr, "file = %s, line = %d\n", file, line);
    2096         fflush(stderr);
    2097         panic("Trying to increment refCount of previously disposed object.");
    2098     }
    2099 #endif
    2100     ++(objPtr)->refCount;
    2101 }
    2102 
    2103 
    2104 /*
    2105  *----------------------------------------------------------------------
    2106  *
    2107  * Tcl_DbDecrRefCount --
    2108  *
    2109  *      This procedure is normally called when debugging: i.e., when
    2110  *      TCL_MEM_DEBUG is defined. This checks to see whether or not
    2111  *      the memory has been freed before incrementing the ref count.
    2112  *
    2113  *      When TCL_MEM_DEBUG is not defined, this procedure just increments
    2114  *      the reference count of the object.
    2115  *
    2116  * Results:
    2117  *      None.
    2118  *
    2119  * Side effects:
    2120  *      The object's ref count is incremented.
    2121  *
    2122  *----------------------------------------------------------------------
    2123  */
    2124 
    2125 void
    2126 Tcl_DbDecrRefCount(objPtr, file, line)
    2127     register Tcl_Obj *objPtr;   /* The object we are adding a reference to. */
    2128     char *file;                 /* The name of the source file calling this
    2129                                  * procedure; used for debugging. */
    2130     int line;                   /* Line number in the source file; used
    2131                                  * for debugging. */
    2132 {
    2133 #ifdef TCL_MEM_DEBUG
    2134     if (objPtr->refCount == 0x61616161) {
    2135         fprintf(stderr, "file = %s, line = %d\n", file, line);
    2136         fflush(stderr);
    2137         panic("Trying to decrement refCount of previously disposed object.");
    2138     }
    2139 #endif
    2140     if (--(objPtr)->refCount <= 0) {
    2141         TclFreeObj(objPtr);
    2142     }
    2143 }
    2144 
    2145 
    2146 /*
    2147  *----------------------------------------------------------------------
    2148  *
    2149  * Tcl_DbIsShared --
    2150  *
    2151  *      This procedure is normally called when debugging: i.e., when
    2152  *      TCL_MEM_DEBUG is defined. This checks to see whether or not
    2153  *      the memory has been freed before incrementing the ref count.
    2154  *
    2155  *      When TCL_MEM_DEBUG is not defined, this procedure just decrements
    2156  *      the reference count of the object and throws it away if the count
    2157  *      is 0 or less.
    2158  *
    2159  * Results:
    2160  *      None.
    2161  *
    2162  * Side effects:
    2163  *      The object's ref count is incremented.
    2164  *
    2165  *----------------------------------------------------------------------
    2166  */
    2167 
    2168 int
    2169 Tcl_DbIsShared(objPtr, file, line)
    2170     register Tcl_Obj *objPtr;   /* The object we are adding a reference to. */
    2171     char *file;                 /* The name of the source file calling this
    2172                                  * procedure; used for debugging. */
    2173     int line;                   /* Line number in the source file; used
    2174                                  * for debugging. */
    2175 {
    2176 #ifdef TCL_MEM_DEBUG
    2177     if (objPtr->refCount == 0x61616161) {
    2178         fprintf(stderr, "file = %s, line = %d\n", file, line);
    2179         fflush(stderr);
    2180         panic("Trying to check whether previously disposed object is shared.");
    2181     }
    2182 #endif
    2183     return ((objPtr)->refCount > 1);
    2184 }
Note: See TracChangeset for help on using the changeset viewer.