Changes in external/tcl/tclObj.c [adeddd8:d7d2da3] in git
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
external/tcl/tclObj.c
radeddd8 rd7d2da3 36 36 37 37 char *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 */ 38 48 39 49 /* … … 407 417 * Tcl_NewObj -- 408 418 * 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. 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. 413 427 * 414 428 * Results: … … 417 431 * is set to 0. 418 432 * 419 *---------------------------------------------------------------------- 420 */ 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 */ 421 450 422 451 Tcl_Obj * … … 439 468 objPtr->length = 0; 440 469 objPtr->typePtr = NULL; 470 #ifdef TCL_COMPILE_STATS 471 tclObjsAlloced++; 472 #endif /* TCL_COMPILE_STATS */ 441 473 return objPtr; 442 474 } 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 */ 443 544 444 545 … … 508 609 * after deallocating the string representation and calling the 509 610 * type-specific Tcl_FreeInternalRepProc to deallocate the object's 510 * internal representation. 611 * internal representation. If compiling with TCL_COMPILE_STATS, 612 * this procedure increments the global count of freed objects 613 * (tclObjsFreed). 511 614 * 512 615 *---------------------------------------------------------------------- … … 519 622 register Tcl_ObjType *typePtr = objPtr->typePtr; 520 623 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 521 630 Tcl_InvalidateStringRep(objPtr); 522 631 if ((typePtr != NULL) && (typePtr->freeIntRepProc != NULL)) { … … 525 634 526 635 /* 527 * Deallocate the object by adding it onto the list of free 636 * If debugging Tcl's memory usage, deallocate the object using ckfree. 637 * Otherwise, deallocate it by adding it onto the list of free 528 638 * Tcl_Objs we maintain. 529 639 */ 530 640 641 #ifdef TCL_MEM_DEBUG 642 ckfree((char *) objPtr); 643 #else 531 644 objPtr->internalRep.otherValuePtr = (VOID *) tclFreeObjList; 532 645 tclFreeObjList = objPtr; 646 #endif /* TCL_MEM_DEBUG */ 647 648 #ifdef TCL_COMPILE_STATS 649 tclObjsFreed++; 650 #endif /* TCL_COMPILE_STATS */ 533 651 } 534 652 … … 676 794 * Tcl_NewBooleanObj -- 677 795 * 678 * This procedure creates a new boolean object and initializes it from 679 * the argument boolean value. A nonzero "boolValue" is coerced to 1. 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. 680 803 * 681 804 * Results: … … 688 811 *---------------------------------------------------------------------- 689 812 */ 813 814 #ifdef TCL_MEM_DEBUG 815 #undef Tcl_NewBooleanObj 690 816 691 817 Tcl_Obj * … … 693 819 register int boolValue; /* Boolean used to initialize new object. */ 694 820 { 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 { 695 830 register Tcl_Obj *objPtr; 696 831 … … 702 837 return objPtr; 703 838 } 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 */ 704 901 705 902 … … 981 1178 * Tcl_NewDoubleObj -- 982 1179 * 983 * This procedure creates a new double object and initializes it from 984 * the argument double value. 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. 985 1186 * 986 1187 * Results: … … 993 1194 *---------------------------------------------------------------------- 994 1195 */ 1196 1197 #ifdef TCL_MEM_DEBUG 1198 #undef Tcl_NewDoubleObj 995 1199 996 1200 Tcl_Obj * … … 998 1202 register double dblValue; /* Double used to initialize the object. */ 999 1203 { 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 { 1000 1213 register Tcl_Obj *objPtr; 1001 1214 … … 1007 1220 return objPtr; 1008 1221 } 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 */ 1009 1284 1010 1285 … … 1256 1531 * Tcl_NewIntObj -- 1257 1532 * 1258 * Calls to Tcl_NewIntObj result in a call to one of the two 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 1259 1539 * Tcl_NewIntObj implementations below. We provide two implementations 1260 1540 * so that the Tcl core can be compiled to do memory debugging of the … … 1276 1556 */ 1277 1557 1558 #ifdef TCL_MEM_DEBUG 1559 #undef Tcl_NewIntObj 1560 1278 1561 Tcl_Obj * 1279 1562 Tcl_NewIntObj(intValue) 1280 1563 register int intValue; /* Int used to initialize the new object. */ 1281 1564 { 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 { 1282 1574 register Tcl_Obj *objPtr; 1283 1575 … … 1289 1581 return objPtr; 1290 1582 } 1583 #endif /* if TCL_MEM_DEBUG */ 1291 1584 1292 1585 … … 1563 1856 * Tcl_NewLongObj -- 1564 1857 * 1565 * Calls to Tcl_NewLongObj result in a call to one of the two 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 1566 1864 * Tcl_NewLongObj implementations below. We provide two implementations 1567 1865 * so that the Tcl core can be compiled to do memory debugging of the … … 1583 1881 */ 1584 1882 1883 #ifdef TCL_MEM_DEBUG 1884 #undef Tcl_NewLongObj 1885 1585 1886 Tcl_Obj * 1586 1887 Tcl_NewLongObj(longValue) … … 1588 1889 * new object. */ 1589 1890 { 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 { 1590 1901 register Tcl_Obj *objPtr; 1591 1902 … … 1597 1908 return objPtr; 1598 1909 } 1910 #endif /* if TCL_MEM_DEBUG */ 1599 1911 1600 1912 … … 1604 1916 * Tcl_DbNewLongObj -- 1605 1917 * 1606 * This procedure just returns the result of calling Tcl_NewLongObj. 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. 1607 1934 * 1608 1935 * Results: … … 1616 1943 *---------------------------------------------------------------------- 1617 1944 */ 1945 1946 #ifdef TCL_MEM_DEBUG 1618 1947 1619 1948 Tcl_Obj * … … 1626 1955 * for debugging. */ 1627 1956 { 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 { 1628 1978 return Tcl_NewLongObj(longValue); 1629 1979 } 1980 #endif /* TCL_MEM_DEBUG */ 1630 1981 1631 1982 … … 1709 2060 return result; 1710 2061 } 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.