Changeset adeddd8 in git for external/tcl/tclObj.c
- Timestamp:
- May 29, 2019, 2:53:12 PM (5 years ago)
- Branches:
- ImprovedOutputFile, Timing, master
- Children:
- 969eb19
- Parents:
- e15936c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
external/tcl/tclObj.c
re15936c radeddd8 36 36 37 37 char *tclEmptyStringRep = NULL; 38 39 /*40 * Count of the number of Tcl objects every allocated (by Tcl_NewObj) and41 * freed (by TclFreeObj).42 */43 44 #ifdef TCL_COMPILE_STATS45 long tclObjsAlloced = 0;46 long tclObjsFreed = 0;47 #endif /* TCL_COMPILE_STATS */48 38 49 39 /* … … 417 407 * Tcl_NewObj -- 418 408 * 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. 427 413 * 428 414 * Results: … … 431 417 * is set to 0. 432 418 * 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 */ 450 421 451 422 Tcl_Obj * … … 468 439 objPtr->length = 0; 469 440 objPtr->typePtr = NULL; 470 #ifdef TCL_COMPILE_STATS471 tclObjsAlloced++;472 #endif /* TCL_COMPILE_STATS */473 441 return objPtr; 474 442 } 475 #endif /* TCL_MEM_DEBUG */476 477 478 /*479 *----------------------------------------------------------------------480 *481 * Tcl_DbNewObj --482 *483 * This procedure is normally called when debugging: i.e., when484 * TCL_MEM_DEBUG is defined. It creates new Tcl objects that denote the485 * empty string. It is the same as the Tcl_NewObj procedure above486 * except that it calls Tcl_DbCkalloc directly with the file name and487 * line number from its caller. This simplifies debugging since then488 * the checkmem command will report the correct file name and line489 * number when reporting objects that haven't been freed.490 *491 * When TCL_MEM_DEBUG is not defined, this procedure just returns the492 * 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 increments500 * the global count of allocated objects (tclObjsAlloced).501 *502 *----------------------------------------------------------------------503 */504 505 #ifdef TCL_MEM_DEBUG506 507 Tcl_Obj *508 Tcl_DbNewObj(file, line)509 register char *file; /* The name of the source file calling this510 * procedure; used for debugging. */511 register int line; /* Line number in the source file; used512 * 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_STATS527 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 this537 * procedure; used for debugging. */538 int line; /* Line number in the source file; used539 * for debugging. */540 {541 return Tcl_NewObj();542 }543 #endif /* TCL_MEM_DEBUG */544 443 545 444 … … 609 508 * after deallocating the string representation and calling the 610 509 * 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. 614 511 * 615 512 *---------------------------------------------------------------------- … … 622 519 register Tcl_ObjType *typePtr = objPtr->typePtr; 623 520 624 #ifdef TCL_MEM_DEBUG625 if ((objPtr)->refCount < -1) {626 panic("Reference count for %lx was negative", objPtr);627 }628 #endif /* TCL_MEM_DEBUG */629 630 521 Tcl_InvalidateStringRep(objPtr); 631 522 if ((typePtr != NULL) && (typePtr->freeIntRepProc != NULL)) { … … 634 525 635 526 /* 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 638 528 * Tcl_Objs we maintain. 639 529 */ 640 530 641 #ifdef TCL_MEM_DEBUG642 ckfree((char *) objPtr);643 #else644 531 objPtr->internalRep.otherValuePtr = (VOID *) tclFreeObjList; 645 532 tclFreeObjList = objPtr; 646 #endif /* TCL_MEM_DEBUG */647 648 #ifdef TCL_COMPILE_STATS649 tclObjsFreed++;650 #endif /* TCL_COMPILE_STATS */651 533 } 652 534 … … 794 676 * Tcl_NewBooleanObj -- 795 677 * 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. 803 680 * 804 681 * Results: … … 811 688 *---------------------------------------------------------------------- 812 689 */ 813 814 #ifdef TCL_MEM_DEBUG815 #undef Tcl_NewBooleanObj816 690 817 691 Tcl_Obj * … … 819 693 register int boolValue; /* Boolean used to initialize new object. */ 820 694 { 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 {830 695 register Tcl_Obj *objPtr; 831 696 … … 837 702 return objPtr; 838 703 } 839 #endif /* TCL_MEM_DEBUG */840 841 842 /*843 *----------------------------------------------------------------------844 *845 * Tcl_DbNewBooleanObj --846 *847 * This procedure is normally called when debugging: i.e., when848 * TCL_MEM_DEBUG is defined. It creates new boolean objects. It is the849 * same as the Tcl_NewBooleanObj procedure above except that it calls850 * Tcl_DbCkalloc directly with the file name and line number from its851 * caller. This simplifies debugging since then the checkmem command852 * will report the correct file name and line number when reporting853 * objects that haven't been freed.854 *855 * When TCL_MEM_DEBUG is not defined, this procedure just returns the856 * result of calling Tcl_NewBooleanObj.857 *858 * Results:859 * The newly created object is returned. This object will have an860 * invalid string representation. The returned object has ref count 0.861 *862 * Side effects:863 * None.864 *865 *----------------------------------------------------------------------866 */867 868 #ifdef TCL_MEM_DEBUG869 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 this874 * procedure; used for debugging. */875 int line; /* Line number in the source file; used876 * 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 this894 * procedure; used for debugging. */895 int line; /* Line number in the source file; used896 * for debugging. */897 {898 return Tcl_NewBooleanObj(boolValue);899 }900 #endif /* TCL_MEM_DEBUG */901 704 902 705 … … 1178 981 * Tcl_NewDoubleObj -- 1179 982 * 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. 1186 985 * 1187 986 * Results: … … 1194 993 *---------------------------------------------------------------------- 1195 994 */ 1196 1197 #ifdef TCL_MEM_DEBUG1198 #undef Tcl_NewDoubleObj1199 995 1200 996 Tcl_Obj * … … 1202 998 register double dblValue; /* Double used to initialize the object. */ 1203 999 { 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 {1213 1000 register Tcl_Obj *objPtr; 1214 1001 … … 1220 1007 return objPtr; 1221 1008 } 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., when1231 * TCL_MEM_DEBUG is defined. It creates new double objects. It is the1232 * same as the Tcl_NewDoubleObj procedure above except that it calls1233 * Tcl_DbCkalloc directly with the file name and line number from its1234 * caller. This simplifies debugging since then the checkmem command1235 * will report the correct file name and line number when reporting1236 * objects that haven't been freed.1237 *1238 * When TCL_MEM_DEBUG is not defined, this procedure just returns the1239 * result of calling Tcl_NewDoubleObj.1240 *1241 * Results:1242 * The newly created object is returned. This object will have an1243 * invalid string representation. The returned object has ref count 0.1244 *1245 * Side effects:1246 * None.1247 *1248 *----------------------------------------------------------------------1249 */1250 1251 #ifdef TCL_MEM_DEBUG1252 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 this1257 * procedure; used for debugging. */1258 int line; /* Line number in the source file; used1259 * 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 this1277 * procedure; used for debugging. */1278 int line; /* Line number in the source file; used1279 * for debugging. */1280 {1281 return Tcl_NewDoubleObj(dblValue);1282 }1283 #endif /* TCL_MEM_DEBUG */1284 1009 1285 1010 … … 1531 1256 * Tcl_NewIntObj -- 1532 1257 * 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 1539 1259 * Tcl_NewIntObj implementations below. We provide two implementations 1540 1260 * so that the Tcl core can be compiled to do memory debugging of the … … 1556 1276 */ 1557 1277 1558 #ifdef TCL_MEM_DEBUG1559 #undef Tcl_NewIntObj1560 1561 1278 Tcl_Obj * 1562 1279 Tcl_NewIntObj(intValue) 1563 1280 register int intValue; /* Int used to initialize the new object. */ 1564 1281 { 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 {1574 1282 register Tcl_Obj *objPtr; 1575 1283 … … 1581 1289 return objPtr; 1582 1290 } 1583 #endif /* if TCL_MEM_DEBUG */1584 1291 1585 1292 … … 1856 1563 * Tcl_NewLongObj -- 1857 1564 * 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 1864 1566 * Tcl_NewLongObj implementations below. We provide two implementations 1865 1567 * so that the Tcl core can be compiled to do memory debugging of the … … 1881 1583 */ 1882 1584 1883 #ifdef TCL_MEM_DEBUG1884 #undef Tcl_NewLongObj1885 1886 1585 Tcl_Obj * 1887 1586 Tcl_NewLongObj(longValue) … … 1889 1588 * new object. */ 1890 1589 { 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 the1899 * new object. */1900 {1901 1590 register Tcl_Obj *objPtr; 1902 1591 … … 1908 1597 return objPtr; 1909 1598 } 1910 #endif /* if TCL_MEM_DEBUG */1911 1599 1912 1600 … … 1916 1604 * Tcl_DbNewLongObj -- 1917 1605 * 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. 1934 1607 * 1935 1608 * Results: … … 1943 1616 *---------------------------------------------------------------------- 1944 1617 */ 1945 1946 #ifdef TCL_MEM_DEBUG1947 1618 1948 1619 Tcl_Obj * … … 1955 1626 * for debugging. */ 1956 1627 { 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 the1972 * new object. */1973 char *file; /* The name of the source file calling this1974 * procedure; used for debugging. */1975 int line; /* Line number in the source file; used1976 * for debugging. */1977 {1978 1628 return Tcl_NewLongObj(longValue); 1979 1629 } 1980 #endif /* TCL_MEM_DEBUG */1981 1630 1982 1631 … … 2060 1709 return result; 2061 1710 } 2062 2063 2064 /*2065 *----------------------------------------------------------------------2066 *2067 * Tcl_DbIncrRefCount --2068 *2069 * This procedure is normally called when debugging: i.e., when2070 * TCL_MEM_DEBUG is defined. This checks to see whether or not2071 * the memory has been freed before incrementing the ref count.2072 *2073 * When TCL_MEM_DEBUG is not defined, this procedure just increments2074 * 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 void2086 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 this2089 * procedure; used for debugging. */2090 int line; /* Line number in the source file; used2091 * for debugging. */2092 {2093 #ifdef TCL_MEM_DEBUG2094 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 #endif2100 ++(objPtr)->refCount;2101 }2102 2103 2104 /*2105 *----------------------------------------------------------------------2106 *2107 * Tcl_DbDecrRefCount --2108 *2109 * This procedure is normally called when debugging: i.e., when2110 * TCL_MEM_DEBUG is defined. This checks to see whether or not2111 * the memory has been freed before incrementing the ref count.2112 *2113 * When TCL_MEM_DEBUG is not defined, this procedure just increments2114 * 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 void2126 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 this2129 * procedure; used for debugging. */2130 int line; /* Line number in the source file; used2131 * for debugging. */2132 {2133 #ifdef TCL_MEM_DEBUG2134 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 #endif2140 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., when2152 * TCL_MEM_DEBUG is defined. This checks to see whether or not2153 * the memory has been freed before incrementing the ref count.2154 *2155 * When TCL_MEM_DEBUG is not defined, this procedure just decrements2156 * the reference count of the object and throws it away if the count2157 * 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 int2169 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 this2172 * procedure; used for debugging. */2173 int line; /* Line number in the source file; used2174 * for debugging. */2175 {2176 #ifdef TCL_MEM_DEBUG2177 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 #endif2183 return ((objPtr)->refCount > 1);2184 }
Note:
See TracChangeset
for help on using the changeset viewer.