From cd034550642034bd5b4eabf2e0ea1cd5cf06719c Mon Sep 17 00:00:00 2001 From: dkf Date: Thu, 28 Jan 2010 10:25:03 +0000 Subject: Improvements to destructor handling. Stop crashes from odd destruction routes. --- ChangeLog | 307 +++++++++++++++++++++++++++------------------------ generic/tclOO.c | 87 ++++++++++++--- generic/tclOOBasic.c | 18 ++- generic/tclOOInt.h | 4 +- tests/oo.test | 112 ++++++++++++++++++- 5 files changed, 362 insertions(+), 166 deletions(-) diff --git a/ChangeLog b/ChangeLog index 86c49d2..a0eab4e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,21 @@ +2010-01-28 Donal K. Fellows + + * generic/tclOOBasic.c (TclOO_Object_Destroy): Move the execution of + destructors to a point where they can produce an error. This will not + work for all destructors, but it does mean that more failing calls of + them will be caught. + * generic/tclOO.c (AllocObject, MyDeletedTrace, ObjectRenamedTrace): + (ObjectNamespaceDeleted): Stop various ways of getting at commands + with dangling pointers to the object. Also increases the reliability + of calling of destructors (though most destructors won't benefit; when + an object is deleted namespace-first, its destructors are not run in a + nice state as the namespace is partially gone). + 2010-01-25 Jan Nijtmans - * generic/tclOOStubInit.c Remove double includes (which causes a - * generic/tclOOStubLib.c warning in CYGWIN compiles) - * unix/.cvsignore add confdefs.h + * generic/tclOOStubInit.c: Remove double includes (which causes a + * generic/tclOOStubLib.c: warning in CYGWIN compiles) + * unix/.cvsignore: add confdefs.h 2010-01-22 Donal K. Fellows @@ -19,9 +32,9 @@ places. * win/tclWinError.c * win/tclWinPipe.c - * win/tcl.m4 Make cygwin configuration error into - * win/configure.in a warning: CYGWIN compilation works - * win/configure although there still are test failures. + * win/tcl.m4: Make cygwin configuration error into + * win/configure.in: a warning: CYGWIN compilation works + * win/configure: although there still are test failures. 2010-01-22 Donal K. Fellows @@ -221,7 +234,7 @@ definition in WINAPI's nb30.h * generic/rege_dfa.c: Fix macro conflict on CYGWIN: don't use "small". - * generic/tcl.h Include before on + * generic/tcl.h: Include before on CYGWIN * generic/tclPathObj.c * generic/tclPort.h @@ -229,8 +242,8 @@ special meaning on CYGWIN (both in UNIX and WIN32 mode!) * generic/tclPlatDecls.h: Include through tclPlatDecls.h - * win/tclWinPort.h stricmp -> strcasecmp - * win/tclWinDde.c _wcsicmp -> wcscasecmp + * win/tclWinPort.h: stricmp -> strcasecmp + * win/tclWinDde.c: _wcsicmp -> wcscasecmp * win/tclWinFile.c * win/tclWinPipe.c * win/tclWinSock.c @@ -719,7 +732,7 @@ TclContinuationsEnter(). Forward port from Tcl 8.5 branch, change by Don Porter. -2009-11-09 Stuart Cassoff +2009-11-09 Stuart Cassoff * win/README: [bug 2459744]: Removed outdated Msys + Mingw info. @@ -1749,7 +1762,7 @@ * generic/tclBasic.c (TclObjInvoke): [Bug 2486550]: Make sure that a null objProc is not used, use Tcl_NRCallObjProc instead. -2009-05-01 Jan Nijtmans +2009-05-01 Jan Nijtmans * win/configure.in Fix 64-bit detection for zlib on Win64 * win/configure (regenerated) @@ -1766,13 +1779,13 @@ different when rendered through groff or as HTML, but it was still wrong both ways.) -2009-04-27 Jan Nijtmans +2009-04-27 Jan Nijtmans * generic/tclIndexObj.c: Reset internal INTERP_ALTERNATE_WRONG_ARGS * generic/tclIOCmd.c flag inside the Tcl_WrongNumArgs function, so the caller no longer has to do the reset. -2009-04-24 Stuart Cassoff +2009-04-24 Stuart Cassoff * unix/Makefile.in: [Patch 2769530]: Don't chmod/exec installManPage. @@ -1855,7 +1868,7 @@ * tests/http.test: [Bug 26245326]: Added specific check for problem * tests/httpd: (return incomplete HTTP response header). -2009-04-08 Kevin B. Kenny +2009-04-08 Kevin B. Kenny * tools/tclZIC.tcl: Always emit files with Unix line termination. * library/tzdata: Olson's tzdata2009e @@ -2404,7 +2417,7 @@ Added protections against callers asking for negative lengths. It is likely when this happens that an integer overflow is to blame. -2009-02-01 David Gravereaux +2009-02-01 David Gravereaux * win/makefile.vc: Allow nmake flags such as -a (rebuild all) to pass down to the pkgs targets, too. @@ -2518,7 +2531,7 @@ [Patch 907924]. * unix/configure: Autoconf 2.59 -2009-01-19 David Gravereaux +2009-01-19 David Gravereaux * win/build.vc.bat: Improved tools detection and error message * win/makefile.vc: Reorganized the $(TCLOBJ) file list into seperate @@ -2608,7 +2621,7 @@ instead to focus on what methods add to it; that's really what the test is about anyway. -2009-01-06 Don Porter +2009-01-06 Don Porter * tests/stringObj.test: Revise tests that demand a NULL Tcl_ObjType in certain values to construct those values with [testdstring] so @@ -2639,7 +2652,7 @@ * generic/tclCmdAH.c: Tidy up spacing and code style. -2009-01-03 Kevin B. Kenny : +2009-01-03 Kevin B. Kenny * library/clock.tcl (tcl::clock::add): Fixed error message formatting in the case where [clock add] is presented with a bad switch. @@ -2655,7 +2668,7 @@ the mkstemp() function, which is apparently needed on some platforms. [Bug 741967] -2008-12-31 Don Porter +2008-12-31 Don Porter * unix/Makefile.in: Set TCLLIBPATH in SHELL_ENV so that targets like `make shell` have access to builds of bundled packages. @@ -2755,7 +2768,7 @@ msys on Windows. (Apparently the gcc used doesn't like a / at the end of a -I argument...) -2008-12-20 Don Porter +2008-12-20 Don Porter * changes: Updates for 8.6b1 release. @@ -2773,7 +2786,7 @@ * unix/configure: autoconf-2.59 -2008-12-19 Don Porter +2008-12-19 Don Porter * doc/NRE.3: Formatting errors found by `make html` * doc/Tcl_Main.3: @@ -2831,7 +2844,7 @@ done. Removed the explicits calls to [flush], now that [close] handles this correctly. -2008-12-18 Don Porter +2008-12-18 Don Porter * tests/chanio.test: Replaced [chan event] handlers that returned TCL_RETURN return code, with more conventional ones that return TCL_OK @@ -2860,7 +2873,7 @@ * generic/tclDecls.h: (regenerated) * generic/tclIntDecls.h: -2008-12-18 Alexandre Ferrieux +2008-12-18 Alexandre Ferrieux TIP #332 IMPLEMENTATION - Half-Close for Bidirectional Channels @@ -2888,7 +2901,7 @@ * tests/namespace-old.test (namespace-old-9.5): dependent on the global namespace's particular imports. [Bug 2433936] -2008-12-17 Don Porter +2008-12-17 Don Porter * unix/Makefile.in: Modify the distclean-packages target so that empty build directories are deleted. @@ -2921,7 +2934,7 @@ in TIP. This implementation is in Tcl and is a stop-gap until higher-performance ones can be written. -2008-12-16 Don Porter +2008-12-16 Don Porter * generic/tcl.h: Add TIP 338 routines to stub table. * generic/tcl.decls: [Bug 2431338] @@ -2934,13 +2947,13 @@ * generic/tclExecute.c (TEBC:INST_DICT_GET): Make sure that the result is empty when generating an error message. [Bug 2431847] -2008-12-15 Alexandre Ferrieux +2008-12-15 Alexandre Ferrieux * generic/tclBinary.c: Redefine non-strict decoding to ignore only * doc/binary.n: whitespace. [Bug 2380293] * tests/binary.test: -2008-12-15 Don Porter +2008-12-15 Don Porter * doc/AddErrInfo.3: Documented Tcl_(Set|Get)ErrorLine (TIP 336). * doc/CrtCommand.3: Various other documentation updates to @@ -2997,7 +3010,7 @@ version of zlib is not capable enough, and automagic to detect when that is the case. [Bug 2421265] -2008-12-12 Alexandre Ferrieux +2008-12-12 Alexandre Ferrieux * unix/tclUnixNotfy.c: Fix missing CLOEXEC on internal pipes [2417695] * unix/tclUnixPipe.c: Fix missing CLOEXEC on [chan pipe] fds. @@ -3009,7 +3022,7 @@ (Tcl_ZlibInflate): Ensure that gzip header extraction is done correctly. -2008-12-12 Kevin Kenny +2008-12-12 Kevin Kenny TIP #322 IMPLEMENTATION @@ -3070,7 +3083,7 @@ * library/tzdata/*: Update from Olson's tzdata2008i. -2008-12-10 Alexandre Ferrieux +2008-12-10 Alexandre Ferrieux TIP #343 IMPLEMENTATION - A Binary Specifier for [format/scan] @@ -3099,7 +3112,7 @@ * generic/tclIntDecls.h: make genstubs * generic/tclStubInit.c: -2008-12-09 Don Porter +2008-12-09 Don Porter TIP #337 IMPLEMENTATION @@ -3146,7 +3159,7 @@ * generic/tcl.decls: TclTransferResult. Added * doc/SetResult.3: to public stubs table. -2008-12-04 Don Porter +2008-12-04 Don Porter * generic/tclPathObj.c (Tcl_FSGetNormalizedPath): Added another flag value TCLPATH_NEEDNORM to mark those intreps which need more @@ -3157,13 +3170,13 @@ * win/tclWinPipe.c (TclpOpenTemporaryFile): Avoid an infinite loop due to GetTempFileName/CreateFile interaction. [Bug 2380318] -2008-12-03 Don Porter +2008-12-03 Don Porter * generic/tclFileName.c (DoGlob): One of the Tcl_FSMatchInDirectory calls did not have its return code checked. This caused error messages returned by some Tcl_Filesystem drivers to be swallowed. -2008-12-02 Don Porter +2008-12-02 Don Porter TIP #336 IMPLEMENTATION @@ -3191,7 +3204,7 @@ Ferrieux's first patch for [Bug 2270477] with a gentler version, also supplied by him. -2008-12-01 Don Porter +2008-12-01 Don Porter * generic/tclParse.c: Coding standards fixups. @@ -3224,7 +3237,7 @@ more comments and explanation of what is going on. Reduce the amount of locking required. -2008-11-27 Alexandre Ferrieux +2008-11-27 Alexandre Ferrieux * generic/tcl.h: Alternate fix for [Bug 2251175]: missing * generic/tclCompile.c: backslash substitution on expanded literals. @@ -3284,7 +3297,7 @@ * generic/tclDictObj.c: Convert Tcl_SetResult call to Tcl_SetObjResult. -2008-11-17 Alexandre Ferrieux +2008-11-17 Alexandre Ferrieux * tests/for.test: Check for uncompiled-for-continue [Bug 2186888] fixed earlier. @@ -3311,7 +3324,7 @@ * generic/tclLoad.c: Fixed [Bug 2269431]: Load of shared objects leaves temporary files on windows. -2008-11-12 Pat Thoyts +2008-11-12 Pat Thoyts * tests/registry.test: Use HKCU to avoid requiring admin access for registry testing on Vista/Server2008 @@ -3338,7 +3351,7 @@ * win/Makefile.in: package to version 1.1.4. Added cross-references to the relevant parts of the code to avoid future desynchronization. -2008-11-07 Pat Thoyts +2008-11-07 Pat Thoyts * generic/tclInt.h: Applied [Patch 2215022] from Duoas to clean up * generic/tclBinary.c: the binary ensemble initiailization code. @@ -3352,7 +3365,7 @@ * generic/tclIO.c: Eliminate an 'array index out of bounds' warning on HP-UX. -2008-11-04 Jeff Hobbs +2008-11-04 Jeff Hobbs * generic/tclPort.h: Remove the ../win/ header dir as the build system already has it, and it confuses builds when used with private headers @@ -3387,7 +3400,7 @@ * generic/tclEnv.c: Eliminate some -Wwrite-strings warnings * generic/tclLink.c: -2008-10-27 Don Porter +2008-10-27 Don Porter * generic/tclEncoding.c: Use "iso8859-1" and not "identity" as the default and original [encoding system] value. Since "iso8859-1" is @@ -3399,7 +3412,7 @@ other code expecting a particular value for Tcl's default system encoding *** -2008-10-24 Pat Thoyts +2008-10-24 Pat Thoyts * library/http/http.tcl: Fixed a failure to read SHOUTcast streams with the new 2.7 package. Introduced a new intial state as the first @@ -3430,7 +3443,7 @@ * generic/tclIntDecls.h: (regenerated) * tools/genStubs.tcl: CONST -> const and white-spacing -2008-10-19 Don Porter +2008-10-19 Don Porter * generic/tclProc.c: Reset -level and -code values to defaults after they are used. [Bug 2152286] @@ -3456,7 +3469,7 @@ * generic/tclIORTrans.c (DeleteReflectedTransformMap): Removed debug output in C++ comment. -2008-10-17 Don Porter +2008-10-17 Don Porter * generic/tclCompile.h: Declare the internal tclInstructionTable to * generic/tclExecute.c: simply be "const", not CONST86. @@ -3507,7 +3520,7 @@ * win/tclWinInit.c * win/tclWinTest.c -2008-10-16 Don Porter +2008-10-16 Don Porter * library/init.tcl: Revised [unknown] so that it carefully preserves the state of the ::errorInfo and ::errorCode variables at @@ -3548,7 +3561,7 @@ * doc/binary.n: Formatting fix. -2008-10-14 Don Porter +2008-10-14 Don Porter * README: Bump version number to 8.6a4 * generic/tcl.h: @@ -3572,7 +3585,7 @@ direct people to the correct manual pages for specific channel types, suitable for the hard-of-reading. Following discussion on tcl-core. -2008-10-13 Pat Thoyts +2008-10-13 Pat Thoyts * win/tclWinThrd.c (TclpThreadCreate): We need to initialize the thread id variable to 0 as on 64 bit windows this is a pointer sized @@ -3595,7 +3608,7 @@ Tcl, but were met during development of L. Thanks go to Robert Netzer for diagnosis and fix. -2008-10-10 Don Porter +2008-10-10 Don Porter *** 8.6a3 TAGGED FOR RELEASE *** @@ -3620,7 +3633,7 @@ when a coroutine is running but the resume command has been deleted. [Bug 2153080] -2008-10-08 Don Porter +2008-10-08 Don Porter * generic/tclTrace.c: Corrected handling of errors returned by variable traces so that the errorInfo value contains the original @@ -3650,7 +3663,7 @@ * doc/chan.n, doc/transchan.n: Documented the channel transformation API of TIP #230. -2008-10-06 Pat Thoyts +2008-10-06 Pat Thoyts * tests/winFCmd.test: Fixed some erroneous tests on Vista+. * generic/tclFCmd.c: Fix constness for msvc of last commit @@ -3794,7 +3807,7 @@ tcltest less specific to accept both .tcl and .tm variants of the file during matching. [Bug 2129828] -2008-10-02 Don Porter +2008-10-02 Don Porter TIP #330 IMPLEMENTATION @@ -3819,7 +3832,7 @@ * win/makefile.vc: Fix the HtmlHelp and WinHelp targets to not be mutually exclusive. -2008-09-29 Don Porter +2008-09-29 Don Porter TIP #323 IMPLEMENTATION (partial) @@ -3882,7 +3895,7 @@ case where the combination of number of elements and repeat count causes the resulting list to be too large. [Bug 2130992] -2008-09-26 Don Porter +2008-09-26 Don Porter TIP #323 IMPLEMENTATION (partial) @@ -3910,7 +3923,7 @@ * generic/tclOO.h (TCLOO_VERSION): Bump the version. -2008-09-25 Don Porter +2008-09-25 Don Porter TIP #323 IMPLEMENTATION (partial) @@ -3937,7 +3950,7 @@ * tests/oo.test (oo-25.2): Revise call chain cache management so that it takes into account class-wide caching correctly. [Bug 2120903] -2008-09-24 Don Porter +2008-09-24 Don Porter TIP #323 IMPLEMENTATION (partial) @@ -3983,7 +3996,7 @@ get the body of a procedure-like method. Reduces the amount of "poking inside the abstraction" that is done by the introspection code. -2008-09-22 Alexandre Ferrieux +2008-09-22 Alexandre Ferrieux * doc/chan.n: Clean up paragraph order. @@ -3993,7 +4006,7 @@ * generic/tclInt.h (TCL_CT_ASSERT): New compile-time assertions, adapted from www.pixelbeat.org/programming/gcc/static_assert.html -2008-09-17 Don Porter +2008-09-17 Don Porter * generic/tclInt.h: Correct the TclGetLongFromObj, TclGetIntFromObj, and TclGetIntForIndexM macros so that they retrieve the longValue @@ -4071,7 +4084,7 @@ * generic/tclExecute.c (CACHE_STACK_INFO): * tests/unsupported.test: Restore execEnv's bottomPtr. [Bug 2093188] -2008-09-02 Don Porter +2008-09-02 Don Porter * generic/tcl.h: Stripped "callers" of the _ANSI_ARGS_ macro * compat/dirent2.h: to support a TCL_NO_DEPRECATED build. @@ -4111,7 +4124,7 @@ * win/makefile.bc: * win/makefile.vc: -2008-08-28 Don Porter +2008-08-28 Don Porter * README: Bump version number to 8.6a3 * generic/tcl.h: @@ -4172,7 +4185,7 @@ * generic/tclExecute.c: Set special errocodes: COROUTINE_BUSY, COROUTINE_CANT_YIELD, COROUTINE_ILLEGAL_YIELD. -2008-08-22 Don Porter +2008-08-22 Don Porter *** 8.6a2 TAGGED FOR RELEASE *** @@ -4194,13 +4207,13 @@ * generic/tclInt.h: * tests/unsupported.test: -2008-08-21 Jeff Hobbs +2008-08-21 Jeff Hobbs * tests/regexp.test, tests/regexpComp.test: Correct re2glob ***= * generic/tclUtil.c (TclReToGlob): translation from exact to anywhere-in-string match. [Bug 2065115] -2008-08-21 Don Porter +2008-08-21 Don Porter * generic/tcl.h: Reduced the use of CONST86 and eliminated * generic/tcl.decls: the use of CONST86_RETURN to support source @@ -4224,7 +4237,7 @@ * generic/tclProc.c (Tcl_DisassembleObjCmd): Added ability to disassemble TclOO methods. The code to do this is very ugly. -2008-08-21 Pat Thoyts +2008-08-21 Pat Thoyts * generic/tclOOMethod.c: Added casts to make MSVC happy * generic/tclBasic.c: @@ -4269,7 +4282,7 @@ * generic/tclExecute.c: Better cmdFrame management -2008-08-14 Don Porter +2008-08-14 Don Porter * tests/fileName.test: Revise new tests for portability to case insensitive filesystems. @@ -4315,18 +4328,18 @@ * tests/nre.test: Added test for large {*}-expansion effects -2008-08-13 Don Porter +2008-08-13 Don Porter * generic/tclFileName.c: Fix for errors handling -types {} * tests/fileName.test: option to [glob]. [Bug 1750300] Thanks to Matthias Kraft and George Peter Staplin. -2008-08-12 Jeff Hobbs +2008-08-12 Jeff Hobbs * generic/tclOOInfo.c (InfoObjectDefnCmd, InfoObjectMixinsCmd): Fix # args displayed. [Bug 2048676] -2008-08-08 Don Porter S +2008-08-08 Don Porter * generic/tclOOMethod.c (PushMethodCallFrame): Added missing check for bytecode validity. [Bug 2037727] @@ -4349,7 +4362,7 @@ * changes: Updates for 8.6a2 release. -2008-08-11 Pat Thoyts +2008-08-11 Pat Thoyts * library/http/http.tcl: Remove 8.5 requirement. * library/http/pkgIndex.tcl: @@ -4371,7 +4384,7 @@ test case demonstrating the leak before the fix. Fixed a few spelling errors in test descriptions as well. -2008-08-11 Don Porter +2008-08-11 Don Porter * library/http/http.tcl: Bump http version to 2.7.1 to account * library/http/pkgIndex.tcl: for [Bug 2046486] bug fix. This @@ -4380,7 +4393,7 @@ * win/makefile.bc: use the unsigned formats in the * win/makefile.vc: [binary scan] command. -2008-08-11 Pat Thoyts +2008-08-11 Pat Thoyts * library/http/http.tcl: CRC field from zlib data should be treated as unsigned for 64bit support. [Bug 2046846] @@ -4407,11 +4420,11 @@ * tests/lrange.test (lrange-1.17): Add test cleanup; whitespace. -2008-08-08 Don Porter +2008-08-08 Don Porter * changes: Updates for 8.6a2 release. -2008-08-08 Kevin Kenny +2008-08-08 Kevin Kenny * library/tzdata/CET: * library/tzdata/MET: @@ -4433,7 +4446,7 @@ * generic/tclExecute.c: Tcl_EvalEx. [Bug 2017946] * generic/tclInt.h: -2008-08-06 Don Porter S +2008-08-06 Don Porter * generic/tclOO.c: Revised TclOO's check for an interp being deleted during handling of object command deletion. The old code was @@ -4459,7 +4472,7 @@ else load the tiny script in that patch by themselves (rewrite ::unknown). Note that it is a script-only patch. -2008-08-05 Joe English +2008-08-05 Joe English * unix/tclUnixChan.c: Streamline async connect logic [Patch 1994512] @@ -4480,7 +4493,7 @@ * generic/tclProc.c: * tests/unsupported.test: -2008-08-04 Don Porter +2008-08-04 Don Porter * generic/tclExecute.c: Stopped faulty double-logging of errors to * tests/execute.test: stack trace when a compile epoch bump triggers @@ -4503,7 +4516,7 @@ * tests/nre.test (new): separating core functionality from the * tests/unsupported.test (new): experimental commands. -2008-08-01 Jeff Hobbs +2008-08-01 Jeff Hobbs * doc/Exit.3: Do not call Tcl_Finalize implicitly * generic/tclEvent.c: on DLL_PROCESS_DETACH as it may lead @@ -4511,7 +4524,7 @@ explicitly calling Tcl_Finalize before unloading regardless. Clarify the docs to note the explicit need in embedded use. -2008-08-01 Don Porter +2008-08-01 Don Porter * generic/tclBasic.c: Revised timing of the CmdFrame stack * tests/info.test: management in TclEvalEx so that the CmdFrame @@ -4676,7 +4689,7 @@ This change complies with TIP #27 ***POTENTIAL INCOMPATIBILITY*** -2008-07-23 Alexandre Ferrieux +2008-07-23 Alexandre Ferrieux * tests/lrange.test: Added relative speed test to check for lrange in-place optimization committed 2008-06-30. @@ -4724,7 +4737,7 @@ * generic/tclExecute.c: GetCommandSource use it. This solves [Bug * generic/tclInt.h: 2017146]. Thx dgp for the analysis. -2008-07-21 Andreas Kupries +2008-07-21 Andreas Kupries * generic/tclBasic.c: Extended the existing TIP #280 system (info * generic/tclCmdAH.c: frame), added the ability to track the absolute @@ -4744,7 +4757,7 @@ * win/tclWinTest.c * tests/*.test -2008-07-21 Alexandre Ferrieux +2008-07-21 Alexandre Ferrieux TIP #304 IMPLEMENTATION @@ -4756,7 +4769,7 @@ * tests/ioCmd.test: Modernized checks * tests/ioTrans.test: -2008-07-21 Pat Thoyts +2008-07-21 Pat Thoyts * generic/tclFCmd.c: Inodes on windows are unreliable. [Bug 2015723] * tests/winFCmd.test: test rename with inode collision @@ -4870,7 +4883,7 @@ (DictUpdateCmd, FinalizeDictUpdate): Similarly for the non-compiled version of [dict update]. -2008-07-16 George Peter Staplin +2008-07-16 George Peter Staplin * win/tclWinThrd.c: Test for TLS_OUT_OF_INDEXES to make certain that thread key creation is successful. @@ -4984,7 +4997,7 @@ * unix/tclUnixTest.c: * win/tclWin32Dll.c: -2008-07-08 Don Porter +2008-07-08 Don Porter * generic/tclGet.c: Corrected out of date comments and removed * generic/tclInt.decls: internal routine TclGetLong() that's no @@ -5020,7 +5033,7 @@ reported in [Bug 1987821]. Thanks to Miguel for the report and Don Porter for tracking the cause down. -2008-07-03 Don Porter +2008-07-03 Don Porter * library/package.tcl: Removed [file readable] testing from [tclPkgUnknown] and friends. We find out soon enough whether a file is @@ -5042,12 +5055,12 @@ * doc/ObjectType.3: Clean up typedef formatting. -2008-06-30 Don Porter +2008-06-30 Don Porter * doc/ObjectType.3: Updated documentation of the Tcl_ObjType struct to match expectations of Tcl 8.5. [Bug 1917650] -2008-06-30 Alexandre Ferrieux +2008-06-30 Alexandre Ferrieux * generic/tclCmdIL.c: Lrange cleanup and in-place optimization. [Patch 1890831] @@ -5061,7 +5074,7 @@ change bars and cleaning up the formatting of typedefs. Added a few missing bits of documentation in the process. -2008-06-29 Don Porter +2008-06-29 Don Porter * generic/tclPathObj.c: Plug memory leak in [Bug 1999176] fix. Thanks to Rolf Ade for detecting. @@ -5074,7 +5087,7 @@ * doc/object.n (EXAMPLES): Fix incorrect usage of oo::define to be done with oo::objdefine instead. [Bug 2004480] -2008-06-28 Don Porter +2008-06-28 Don Porter * generic/tclPathObj.c: Plug memory leak in [Bug 1972879] fix. Thanks to Rolf Ade for detecting and Dan Steffen for the fix. [Bug 2004654] @@ -5086,7 +5099,7 @@ conditional on interpreter safeness as well. Thanks to Daniel Steffen for reminding me of that code. -2008-06-25 Don Porter +2008-06-25 Don Porter *** 8.6a1 TAGGED FOR RELEASE *** @@ -5101,22 +5114,22 @@ * library/init.tcl: enabling requiring Tcl Modules in safe * tests/safe.test: interpreters. [Bug 1999119] -2008-06-25 Pat Thoyts +2008-06-25 Pat Thoyts * win/rules.vc: Fix versions of dde and registry dlls * win/makefile.vc: Fix problem building with staticpkg option -2008-06-24 Don Porter +2008-06-24 Don Porter * generic/tclPathObj.c: Fixed some internals management in the "path" Tcl_ObjType for the empty string value. Problem led to a crash in the command [glob -dir {} a]. [Bug 1999176] -2008-06-24 Pat Thoyts +2008-06-24 Pat Thoyts * doc/fileevent.n: Fix examples and comment on eof use. [Bug 1995063] -2008-06-23 Don Porter +2008-06-23 Don Porter * generic/tclPathObj.c: Fixed bug in Tcl_GetTranslatedPath() when operating on the "Special path" variant of the "path" Tcl_ObjType @@ -5124,7 +5137,7 @@ relative paths to absolute, contrary to what the function of producing the "translated path" is supposed to do. [Bug 1972879] -2008-06-20 Don Porter +2008-06-20 Don Porter * changes: Updates for 8.6a1 release. @@ -5152,7 +5165,7 @@ * tests/oo.test (oo-14.8): that class mixins are processed in the documented order. [Bug 1998221] -2008-06-19 Don Porter +2008-06-19 Don Porter * changes: Updates for 8.6a1 release. @@ -5179,7 +5192,7 @@ new (underscored) form of environment variable names, but make it the encouraged form as well. [Bug 1914604] -2008-06-17 Kevin Kenny +2008-06-17 Kevin Kenny * generic/tclClock.c (ConvertLocalToUTC): * tests/clock.test (clock-63.1): Fixed a bug where the internal @@ -5202,7 +5215,7 @@ iortrans.tf-11.*, cleanup of temp file, making this a followup to the entry on 2008-06-10 by myself. -2008-06-13 David Gravereaux +2008-06-13 David Gravereaux * win/rules.vc: SYMBOLS macro is now being set to zero when $(OPTS) is not available. @@ -5298,7 +5311,7 @@ * macosx/Tcl.xcode/project.pbxproj: Sync Tcl.xcodeproj changes. * macosx/README: Document new build configs. -2008-06-10 Joe English +2008-06-10 Joe English * generic/tclEncoding.c(UtfToUtfProc): Avoid unwanted sign extension when converting incomplete UTF-8 sequences. See [Bug 1908443] for @@ -5361,7 +5374,7 @@ over both modules and see which of the common parts we can factor out and share. -2008-06-04 Pat Thoyts +2008-06-04 Pat Thoyts * generic/tclBinary.c: TIP #317 implementation * tests/binary.test: @@ -5452,7 +5465,7 @@ TclOO to sit directly inside Tcl. Note that this is incomplete (e.g. no build support yet for Windows). -2008-05-26 Jeff Hobbs +2008-05-26 Jeff Hobbs * tests/io.test (io-53.9): Need to close chan before removing file. @@ -5474,13 +5487,13 @@ the supported range are now clipped to nearest boundary instead of ignored. -2008-05-22 Don Porter +2008-05-22 Don Porter * generic/tclNamesp.c (Tcl_LogCommandInfo): Restored ability to handle the argument value length = -1. Thanks to Chris Darroch for discovering the bug and providing the fix. [Bug 1968245] -2008-05-21 Don Porter +2008-05-21 Don Porter * generic/tclParse.c (ParseComment): The new TclParseAllWhiteSpace * tests/parse.test (parse-15.60): routine has no mechanism to @@ -5499,7 +5512,7 @@ * generic/tclCompile.c: Fix crash with tcl_traceExec. Found and fixed by Alexander Pasadyn. [Bug 1964803] -2008-05-15 Pat Thoyts +2008-05-15 Pat Thoyts * win/makefile.vc: We should use the thread allocator for threaded * win/rules.vc: builds. Added 'tclalloc' option to disable. @@ -5539,7 +5552,7 @@ one error that caused a crash every time a compiled 'dict append' with more than one argument was used. Found by Colin McCormack. -2008-05-02 Pat Thoyts +2008-05-02 Pat Thoyts * generic/tclBasic.c: Converted the [binary] command into an * generic/tclBinary.c: ensemble. @@ -5556,7 +5569,7 @@ files allow building things that link against Tcl with really ancient compilers still; the requirement is just when building Tcl itself.) -2008-04-26 Zoran Vasiljevic +2008-04-26 Zoran Vasiljevic * generic/tclAsync.c: Tcl_AsyncDelete(): panic if attempt to locate handler token fails. Happens when some other thread attempts to delete @@ -5577,7 +5590,7 @@ * generic/tclIORChan.c: Fixed the bugs exposed by the new testcases, redone most of the cleanup and exit handling. -2008-04-21 Don Porter +2008-04-21 Don Porter * generic/tclIOUtil.c: Removed all code delimited by * generic/tclTest.c: USE_OBSOLETE_FS_HOOKS, completing @@ -5587,7 +5600,7 @@ Tcl 8.5, and now completely gone for Tcl 8.6). Also removed all tests relevant only to the removed interfaces. -2008-04-19 George Peter Staplin +2008-04-19 George Peter Staplin * doc/Ensemble.3: Fix a typo: s/defiend/defined/ Thanks to hat0 for spotting this. @@ -5621,7 +5634,7 @@ * unix/Makefile.in: Adjust tclDTrace.h dependencies for removal of tclStubLib.o from TCL_OBJS. [Bug 1942795] -2008-04-14 Kevin B. Kenny +2008-04-14 Kevin B. Kenny * unix/tclUnixTime.c (NativeGetTime): Removed obsolete use of 'struct timezone' in the call to 'gettimeofday'. [Bug 1942197] @@ -5786,7 +5799,7 @@ * unix/tcl.m4: setup on solaris x86, native cc), provided by Michael Schlenker. -2008-04-01 Don Porter +2008-04-01 Don Porter * generic/tclStubLib.c: Removed needless #ifdef complexity. @@ -5823,7 +5836,7 @@ * generic/tclPlatDecls.h: * generic/tclTomMathDecls.h: -2008-03-30 Kevin Kenny +2008-03-30 Kevin Kenny * generic/tclInt.h (TclIsNaN): * unix/configure.in: Added code to the configurator to check for a @@ -5840,7 +5853,7 @@ deal with (slightly buggy) math libraries in which pow() returns an incorrectly rounded result. [Bug 1808174] -2008-03-26 Don Porter +2008-03-26 Don Porter *** 8.5.2 TAGGED FOR RELEASE *** @@ -5863,7 +5876,7 @@ buggy tests fixed, including one where the result of the previous test was being checked! -2008-03-27 Kevin B. Kenny +2008-03-27 Kevin B. Kenny * library/tzdata/America/Marigot: * library/tztata/America/St_Barthelemy: @@ -5897,11 +5910,11 @@ * unix/configure: autoconf-2.59 -2008-03-26 Don Porter +2008-03-26 Don Porter * changes: Updated for 8.5.2 release. -2008-03-24 Pat Thoyts +2008-03-24 Pat Thoyts * generic/tclBinary.c: [Bug 1923966] - crash in binary format * tests/binary.test: Added tests for the above crash condition. @@ -5944,7 +5957,7 @@ ***INCOMPATIBILITY*** for all Tcl Modules already written in non-utf-8 compatible encodings. -2008-03-18 Don Porter +2008-03-18 Don Porter * generic/tclExecute.c: Patch from Miguel Sofer to correct the alignment of memory allocated by GrowEvaluationStack(). [Bug 1914503] @@ -5966,7 +5979,7 @@ * doc/lreplace.n: Clarified documentation of what happens with negative indices. [Bug 1905809] Added example, tidied up formatting. -2008-03-14 Don Porter +2008-03-14 Don Porter * generic/tclBasic.c (OldMathFuncProc): Same workaround protection from bad TclStackAlloc() alignment. Thanks George Peter Staplin. @@ -5986,7 +5999,7 @@ * unix/tcl.m4: for lib paths in tclConfig.sh. [Bug 1913622] * unix/configure: autoconf-2.59 -2008-03-13 Don Porter +2008-03-13 Don Porter * changes: Updated for 8.5.2 release. @@ -6000,11 +6013,11 @@ * macosx/Tcl.xcodeproj/default.pbxuser: CODE_SIGN_IDENTITY and * macosx/Tcl-Common.xcconfig: 'xcodebuild install'. -2008-03-12 Andreas Kupries +2008-03-12 Andreas Kupries * doc/info.n: Replaced {expand} with {*}. -2008-03-12 Jeff Hobbs +2008-03-12 Jeff Hobbs * unix/Makefile.in (install-libraries): Bump http to 2.7 * win/Makefile.in (install-libraries): Added -myaddr option to allow @@ -6017,7 +6030,7 @@ Added -strict option to control URL validation on per-call basis. [Bug 1560506] -2008-03-11 Jeff Hobbs +2008-03-11 Jeff Hobbs * library/http/http.tcl (http::geturl): Add -method option to support * tests/http.test (http-3.1): http PUT and DELETE requests. @@ -6073,7 +6086,7 @@ when unset traces recreated the var, as reported by Julian Noble. [Bug 1911919] -2008-03-10 Don Porter +2008-03-10 Don Porter * changes: Updated for 8.5.2 release. @@ -6101,7 +6114,7 @@ finalization ordering and attendant issues. For now we choose the lesser evil. -2008-03-07 Don Porter +2008-03-07 Don Porter * generic/tclExecute.c (Tcl_ExprObj): Revised expression bytecode compiling so that bytecodes invalid due to changing context or due to @@ -6123,7 +6136,7 @@ * doc/namespace.n: Minor tidying up. [Bug 1909019] -2008-03-04 Don Porter +2008-03-04 Don Porter * tests/execute.test (6.3,4): Added tests for [Bug 1899164]. @@ -6138,7 +6151,7 @@ * tests/interp.test (interp-28.2): Spoil the intrep of an nsNameType obj when the reference crosses interpreter boundaries. -2008-02-29 Don Porter +2008-02-29 Don Porter * generic/tclResult.c (Tcl_SetReturnOptions): Revised the refcount management of Tcl_SetReturnOptions to become that of a conventional @@ -6158,19 +6171,19 @@ one caller within Tcl itself which passes a non-0-count value to Tcl_AppendObjToErrorInfo(). -2008-02-28 Joe English +2008-02-28 Joe English * unix/tclPort.h, unix/tclCompat.h, unix/tclUnixChan.h: Reduce scope of and #includes. [Patch 1903339] -2008-02-28 Joe English +2008-02-28 Joe English * unix/tclUnixChan.c, unix/tclUnixNotfy.c, unix/tclUnixPipe.c: Consolidate all code conditionalized on -DUSE_FIONBIO into one place. * unix/tclUnixPort.h, unix/tclUnixCompat.c: New routine TclUnixSetBlockingMode(). [Patch 1903339] -2008-02-28 Don Porter +2008-02-28 Don Porter * generic/tclBasic.c (TclEvalObjvInternal): Plug memory leak when an enter trace deletes or changes the command, prompting a reparsing. @@ -6187,7 +6200,7 @@ to optimize compiled [return -level 0 $x] [RFE 1794073] introduced a memory leak of the return options dictionary. Fixing that. -2008-02-27 Pat Thoyts +2008-02-27 Pat Thoyts * library/http/http.tcl: [Bug 705956] - fix inverted logic when cleaning up socket error in geturl. @@ -6205,49 +6218,49 @@ * tests/clock.test (clock-61.*, clock-62.1): Regression tests for [Bug 1862555] and [Bug 1902423]. -2008-02-26 Joe English +2008-02-26 Joe English * generic/tclIOUtil.c, unix/tclUnixPort.h, unix/tclUnixChan.c: Remove dead/unused portability-related #defines and unused conditional code. See [Patch 1901828] for discussion. -2008-02-26 Joe English +2008-02-26 Joe English * generic/tclIORChan.c (enum MethodName), * generic/tclCompExpr.c (enum Marks): More stray trailing ","s -2008-02-26 Joe English +2008-02-26 Joe English * unix/configure.in(socklen_t test): Define socklen_t as "int" if missing, not "unsigned". Use AC_TRY_COMPILE instead of AC_EGREP_HEADER. * unix/configure: regenerated. -2008-02-26 Joe English +2008-02-26 Joe English * generic/tclCompile.h: Remove stray trailing "," from enum InstOperandType definition (C99ism). -2008-02-26 Jeff Hobbs +2008-02-26 Jeff Hobbs * generic/tclUtil.c (TclReToGlob): Fix the handling of the last star * tests/regexpComp.test: possibly being escaped in determining right anchor. [Bug 1902436] -2008-02-26 Pat Thoyts +2008-02-26 Pat Thoyts * library/http/pkgIndex.tcl: Set version 2.5.5 * library/http/http.tcl: It is better to do the [eof] check after trying to read from the socket. No clashes found in testing. Added http::meta command to access the http headers. [Bug 1868845] -2008-02-22 Pat Thoyts +2008-02-22 Pat Thoyts * library/http/pkgIndex.tcl: Set version 2.5.4 * library/http/http.tcl: Always check that the state array exists in the http::status command. [Bug 1818565] -2008-02-13 Don Porter +2008-02-13 Don Porter * generic/tcl.h: Bump version number to 8.5.2b1 to distinguish * library/init.tcl: CVS development snapshots from the 8.5.1 and @@ -6279,7 +6292,7 @@ [lassign] in place of [foreach], avoiding [namespace which] for command resolution). -2008-02-04 Don Porter +2008-02-04 Don Porter *** 8.5.1 TAGGED FOR RELEASE *** @@ -6323,11 +6336,11 @@ Ttk to have its "standard options" on a manual page that is not called "options". [Tk Bug 1876493] -2008-01-25 Don Porter +2008-01-25 Don Porter * changes: Updated for 8.5.1 release. -2008-01-23 Don Porter +2008-01-23 Don Porter * generic/tclInt.h: New macro TclGrowParseTokenArray() to * generic/tclCompCmds.c: simplify code that might need to grow @@ -6349,7 +6362,7 @@ * generic/tclIntDecls.h: make genstubs * generic/tclStubInit.c: -2008-01-22 Don Porter +2008-01-22 Don Porter * generic/tclTimer.c (AfterProc): Replace Tcl_EvalEx() with Tcl_EvalObjEx() to evaluate [after] callbacks. Part of trend to favor @@ -6361,14 +6374,14 @@ * tests/cmdIL.test (cmdIL-7.7): Fix crash on reversing an empty list. [Bug 1876793] -2008-01-20 Jeff Hobbs +2008-01-20 Jeff Hobbs * unix/README: Minor typo fixes [Bug 1853072] * generic/tclIO.c (TclGetsObjBinary): Operate on topmost channel. [Bug 1869405] (Ficicchia) -2008-01-17 Don Porter +2008-01-17 Don Porter * generic/tclCompExpr.c: Revision to preserve parsed intreps of numeric and boolean literals when compiling expressions with (optimize @@ -6395,7 +6408,7 @@ * generic/tclCompExpr.c: struct TclOpCmdClientData to accommodate C++ * generic/tclCompile.h: compilers. [Bug 1855644] -2008-01-13 Jeff Hobbs +2008-01-13 Jeff Hobbs * win/tclWinSerial.c (SerialCloseProc, TclWinOpenSerialChannel): Use critical section for read & write side. [Bug 1353846] (newman) @@ -6408,17 +6421,17 @@ * unix/tclUnixThrd.c (TclpThreadGetStackSize): Fix for crash in freebsd. [Bug 1860425] -2008-01-10 Don Porter +2008-01-10 Don Porter * generic/tclStringObj.c (Tcl_AppendFormatToObj): Correct failure to * tests/format.test: account for big.used == 0 corner case in the %ll(idox) format directives. [Bug 1867855] -2008-01-09 George Peter Staplin +2008-01-09 George Peter Staplin * doc/vwait.n: Add a missing be to fix a typo. -2008-01-04 Jeff Hobbs +2008-01-04 Jeff Hobbs * tools/tcltk-man2html.tcl (make-man-pages): Make man page title use more specific info on lhs to improve tabbed browser view titles. @@ -6429,7 +6442,7 @@ reordered documentation to discourage people from using the hex formatter that is hardly ever useful. -2008-01-02 Don Porter +2008-01-02 Don Porter * generic/tcl.h: Bump version number to 8.5.1b1 to distinguish * library/init.tcl: CVS development snapshots from the 8.5.0 and diff --git a/generic/tclOO.c b/generic/tclOO.c index 242496f..a428aba 100644 --- a/generic/tclOO.c +++ b/generic/tclOO.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclOO.c,v 1.26 2009/11/24 12:00:08 dkf Exp $ + * RCS: @(#) $Id: tclOO.c,v 1.27 2010/01/28 10:25:04 dkf Exp $ */ #ifdef HAVE_CONFIG_H @@ -84,6 +84,9 @@ static int FinalizeObjectCall(ClientData data[], static void InitFoundation(Tcl_Interp *interp); static void KillFoundation(ClientData clientData, Tcl_Interp *interp); +static void MyDeletedTrace(ClientData clientData, + Tcl_Interp *interp, const char *oldName, + const char *newName, int flags); static void ObjectNamespaceDeleted(ClientData clientData); static void ObjectRenamedTrace(ClientData clientData, Tcl_Interp *interp, const char *oldName, @@ -558,6 +561,7 @@ AllocObject( { register Command *cmdPtr = (Command *) ckalloc(sizeof(Command)); + register CommandTrace *tracePtr; memset(cmdPtr, 0, sizeof(Command)); cmdPtr->nsPtr = (Namespace *) oPtr->namespacePtr; @@ -570,6 +574,14 @@ AllocObject( cmdPtr->clientData = cmdPtr; cmdPtr->nreProc = PrivateNRObjectCmd; Tcl_SetHashValue(cmdPtr->hPtr, cmdPtr); + oPtr->myCommand = (Tcl_Command) cmdPtr; + cmdPtr->tracePtr = trace = (CommandTrace *) + ckalloc(sizeof(CommandTrace)); + tracePtr->traceProc = MyDeletedTrace; + tracePtr->clientData = oPtr; + tracePtr->flags = TCL_TRACE_DELETE; + tracePtr->nextPtr = NULL; + tracePtr->refCount = 1; } Tcl_TraceCommand(interp, TclGetString(TclOOObjectName(interp, oPtr)), @@ -581,6 +593,33 @@ AllocObject( /* * ---------------------------------------------------------------------- * + * MyDeletedTrace -- + * + * This callback is triggered when the object's [my] command is deleted + * by any mechanism. It just marks the object as not having a [my] + * command, and so prevents cleanup of that when the object itself is + * deleted. + * + * ---------------------------------------------------------------------- + */ + +static void +MyDeletedTrace( + ClientData clientData, /* Reference to the object whose [my] has been + * squelched. */ + Tcl_Interp *interp, /* ignored */ + const char *oldName, /* ignored */ + const char *newName, /* ignored */ + int flags) /* ignored */ +{ + register Object *oPtr = clientData; + + oPtr->myCommand = NULL; +} + +/* + * ---------------------------------------------------------------------- + * * ObjectRenamedTrace -- * * This callback is triggered when the object is deleted by any @@ -620,26 +659,35 @@ ObjectRenamedTrace( * Oh dear, the object really is being deleted. Handle this by running the * destructors and deleting the object's namespace, which in turn causes * the real object structures to be deleted. + * + * Note that it is possible for the namespace to be deleted before the + * command. Because of that case, we must take care here to mark the + * command as being deleted so that if we return here we don't run into + * reentrancy problems. */ AddRef(oPtr); + oPtr->command = NULL; oPtr->flags |= OBJECT_DELETED; - contextPtr = TclOOGetCallContext(oPtr, NULL, DESTRUCTOR, NULL); - if (contextPtr != NULL) { - int result; - Tcl_InterpState state; + if (!(oPtr->flags & DESTRUCTOR_CALLED)) { + contextPtr = TclOOGetCallContext(oPtr, NULL, DESTRUCTOR, NULL); + oPtr->flags |= DESTRUCTOR_CALLED; + if (contextPtr != NULL) { + int result; + Tcl_InterpState state; - contextPtr->callPtr->flags |= DESTRUCTOR; - contextPtr->skip = 0; - state = Tcl_SaveInterpState(interp, TCL_OK); - result = Tcl_NRCallObjProc(interp, TclOOInvokeContext, contextPtr, 0, - NULL); - if (result != TCL_OK) { - Tcl_BackgroundError(interp); + contextPtr->callPtr->flags |= DESTRUCTOR; + contextPtr->skip = 0; + state = Tcl_SaveInterpState(interp, TCL_OK); + result = Tcl_NRCallObjProc(interp, TclOOInvokeContext, + contextPtr, 0, NULL); + if (result != TCL_OK) { + Tcl_BackgroundError(interp); + } + Tcl_RestoreInterpState(interp, state); + TclOODeleteContext(contextPtr); } - Tcl_RestoreInterpState(interp, state); - TclOODeleteContext(contextPtr); } /* @@ -819,8 +867,18 @@ ObjectNamespaceDeleted( /* * Instruct everyone to no longer use any allocated fields of the object. + * Also delete the commands that refer to the object at this point (if + * they still exist) because otherwise their references to the object + * point into freed memory, allowing crashes. */ + oPtr->flags |= OBJECT_DELETED; + if (oPtr->command) { + Tcl_DeleteCommandFromToken(oPtr->fPtr->interp, oPtr->command); + } + if (oPtr->myCommand) { + Tcl_DeleteCommandFromToken(oPtr->fPtr->interp, oPtr->myCommand); + } if (preserved) { AddRef(oPtr); if (clsPtr != NULL) { @@ -828,7 +886,6 @@ ObjectNamespaceDeleted( ReleaseClassContents(NULL, oPtr); } } - oPtr->flags |= OBJECT_DELETED; /* * Splice the object out of its context. After this, we must *not* call diff --git a/generic/tclOOBasic.c b/generic/tclOOBasic.c index e064928..eedbf5a 100644 --- a/generic/tclOOBasic.c +++ b/generic/tclOOBasic.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclOOBasic.c,v 1.20 2009/11/27 06:33:40 dkf Exp $ + * RCS: @(#) $Id: tclOOBasic.c,v 1.21 2010/01/28 10:25:05 dkf Exp $ */ #ifdef HAVE_CONFIG_H @@ -259,14 +259,28 @@ TclOO_Object_Destroy( int objc, /* Number of arguments. */ Tcl_Obj *const *objv) /* The actual arguments. */ { + Object *oPtr = (Object *) Tcl_ObjectContextObject(context); + int result = TCL_OK; + if (objc != Tcl_ObjectContextSkippedArgs(context)) { Tcl_WrongNumArgs(interp, Tcl_ObjectContextSkippedArgs(context), objv, NULL); return TCL_ERROR; } + if (!(oPtr->flags & DESTRUCTOR_CALLED)) { + CallContext *contextPtr = TclOOGetCallContext(oPtr, NULL, DESTRUCTOR); + + oPtr->flags |= DESTRUCTOR_CALLED; + if (contextPtr != NULL) { + contextPtr->callPtr->flags |= DESTRUCTOR; + contextPtr->skip = 0; + result = TclOOInvokeContext(interp, contextPtr, 0, NULL); + TclOODeleteContext(contextPtr); + } + } Tcl_DeleteCommandFromToken(interp, Tcl_GetObjectCommand(Tcl_ObjectContextObject(context))); - return TCL_OK; + return result; } /* diff --git a/generic/tclOOInt.h b/generic/tclOOInt.h index 86bc9d3..aea18e2 100644 --- a/generic/tclOOInt.h +++ b/generic/tclOOInt.h @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclOOInt.h,v 1.13 2009/12/21 23:25:39 nijtmans Exp $ + * RCS: @(#) $Id: tclOOInt.h,v 1.14 2010/01/28 10:25:05 dkf Exp $ */ #ifndef TCL_OO_INTERNAL_H @@ -199,6 +199,8 @@ typedef struct Object { #define OBJECT_DELETED 1 /* Flag to say that an object has been * destroyed. */ +#define DESTRUCTOR_CALLED 2 /* Flag to say that the destructor has been + * called. */ #define ROOT_OBJECT 0x1000 /* Flag to say that this object is the root of * the class hierarchy and should be treated * specially during teardown. */ diff --git a/tests/oo.test b/tests/oo.test index e42c2ca..6fdc344 100644 --- a/tests/oo.test +++ b/tests/oo.test @@ -7,7 +7,7 @@ # See the file "license.terms" for information on usage and redistribution of # this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: oo.test,v 1.34 2009/12/09 18:40:47 dgp Exp $ +# RCS: @(#) $Id: oo.test,v 1.35 2010/01/28 10:25:05 dkf Exp $ package require -exact TclOO 0.6.2 ;# Must match value in generic/tclOO.h if {[lsearch [namespace children] ::tcltest] == -1} { @@ -221,6 +221,18 @@ test oo-1.18 {OO: create object in NS with same name as global cmd} -setup { rename test-oo-1.18 {} A destroy } -result ::C +test oo-1.19 {basic test of OO functionality: teardown order} -body { + oo::object create o + namespace delete [info object namespace o] + o destroy + # Crashes on error +} -returnCodes error -result {invalid command name "o"} +test oo-1.20 {basic test of OO functionality: my teardown post rename} -body { + oo::object create obj + rename [info object namespace obj]::my ::AGlobalName + obj destroy + info commands ::AGlobalName +} -result {} test oo-2.1 {basic test of OO functionality: constructor} -setup { # This is a bit complex because it needs to run in a sub-interp as @@ -330,6 +342,104 @@ test oo-3.2 {basic test of OO functionality: destructor} -setup { } -cleanup { interp delete subinterp } -result {1 ::foo died 2 {}} +test oo-3.3 {basic test of OO functionality: destructor} -setup { + oo::class create foo + set result {} +} -cleanup { + foo destroy +} -body { + oo::define foo { + constructor {} {lappend ::result made} + destructor {lappend ::result died} + } + namespace delete [info object namespace [foo new]] + return $result +} -result {made died} +test oo-3.4 {basic test of OO functionality: my exists in destructor} -setup { + oo::class create cls + set result {} +} -cleanup { + cls destroy +} -body { + oo::define cls { + variable state + constructor {} { + proc localcmdexists {} {} + set state ok + } + forward Report lappend ::result + destructor { + objmy Report [catch {set state} msg] $msg + objmy Report [namespace which -var state] + objmy Report [info commands localcmdexists] + } + } + cls create obj + rename [info object namespace obj]::my ::objmy + obj destroy + lappend result [info commands ::objmy] +} -match glob -result {0 ok *::state localcmdexists {}} +# Compare with previous test; the differences are because here the destructor +# is run with the namespace partially squelched. +test oo-3.5 {basic test of OO functionality: my exists in destructor} -setup { + oo::class create cls + set result {} +} -cleanup { + cls destroy +} -body { + # Order of destruction of commands relative to namespace is complex, but + # we want to make sure that the order from the perspective of TclOO is + # solid. + oo::define cls { + variable state + constructor {} { + proc localcmdexists {} {} + set state ok + } + forward Report lappend ::result + destructor { + objmy Report [catch {set state} msg] $msg + objmy Report [namespace which -var state] + objmy Report [info commands localcmdexists] + } + } + cls create obj + rename [info object namespace obj]::my ::objmy + namespace delete [info object namespace obj] + lappend result [info commands ::objmy] +} -match glob -result {1 {can't read "state": no such variable} *::state {} {}} +test oo-3.6 {basic test of OO functionality: errors in destructor} -setup { + oo::class create cls +} -cleanup { + cls destroy +} -body { + oo::define cls destructor {error foo} + list [catch {[cls create obj] destroy} msg] $msg [info commands obj] +} -result {1 foo {}} +test oo-3.7 {basic test of OO functionality: errors in destructor} -setup { + oo::class create cls + set result {} + proc bgerror msg {lappend ::result $msg} +} -cleanup { + cls destroy + rename bgerror {} +} -body { + oo::define cls destructor {error foo} + list [rename [cls create obj] {}] \ + [update idletasks] $result [info commands obj] +} -result {{} {} foo {}} +test oo-3.8 {basic test of OO functionality: errors in destructor} -setup { + oo::class create cls + set result {} + proc bgerror msg {lappend ::result $msg} +} -cleanup { + cls destroy + rename bgerror {} +} -body { + oo::define cls destructor {error foo} + list [namespace delete [info object namespace [cls create obj]]] \ + [update idletasks] $result [info commands obj] +} -result {{} {} foo {}} test oo-4.1 {basic test of OO functionality: export} { set o [oo::object new] -- cgit v0.12