You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3655 lines
93 KiB

32 years ago
31 years ago
31 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
Merged revisions 70578,70599,70641-70642,70650,70660-70661,70674,70691,70697-70698,70700,70704 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r70578 | benjamin.peterson | 2009-03-23 22:24:56 -0500 (Mon, 23 Mar 2009) | 1 line this is better written using assertRaises ........ r70599 | benjamin.peterson | 2009-03-25 16:42:51 -0500 (Wed, 25 Mar 2009) | 1 line this can be slightly less ugly ........ r70641 | guilherme.polo | 2009-03-27 16:43:08 -0500 (Fri, 27 Mar 2009) | 3 lines Adjusted _tkinter to compile without warnings when WITH_THREAD is not defined (part of issue #5035) ........ r70642 | georg.brandl | 2009-03-27 19:48:48 -0500 (Fri, 27 Mar 2009) | 1 line Fix typo. ........ r70650 | benjamin.peterson | 2009-03-28 14:16:10 -0500 (Sat, 28 Mar 2009) | 1 line give os.symlink and os.link() better parameter names #5564 ........ r70660 | georg.brandl | 2009-03-28 14:52:58 -0500 (Sat, 28 Mar 2009) | 1 line Switch to fixed Sphinx version. ........ r70661 | georg.brandl | 2009-03-28 14:57:36 -0500 (Sat, 28 Mar 2009) | 2 lines Add section numbering to some of the larger subdocuments. ........ r70674 | guilherme.polo | 2009-03-29 05:19:05 -0500 (Sun, 29 Mar 2009) | 1 line Typo fix. ........ r70691 | raymond.hettinger | 2009-03-29 13:51:11 -0500 (Sun, 29 Mar 2009) | 1 line Make life easier for non-CPython implementations. ........ r70697 | benjamin.peterson | 2009-03-29 16:22:35 -0500 (Sun, 29 Mar 2009) | 1 line this has been fixed since 2.6 (I love removing these) ........ r70698 | benjamin.peterson | 2009-03-29 16:31:05 -0500 (Sun, 29 Mar 2009) | 1 line thanks to guido's bytecode verifier, this is fixed ........ r70700 | benjamin.peterson | 2009-03-29 16:50:14 -0500 (Sun, 29 Mar 2009) | 1 line use the awesome new status iterator ........ r70704 | benjamin.peterson | 2009-03-29 21:49:32 -0500 (Sun, 29 Mar 2009) | 1 line there's actually three methods here #5600 ........
17 years ago
Merged revisions 70578,70599,70641-70642,70650,70660-70661,70674,70691,70697-70698,70700,70704 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r70578 | benjamin.peterson | 2009-03-23 22:24:56 -0500 (Mon, 23 Mar 2009) | 1 line this is better written using assertRaises ........ r70599 | benjamin.peterson | 2009-03-25 16:42:51 -0500 (Wed, 25 Mar 2009) | 1 line this can be slightly less ugly ........ r70641 | guilherme.polo | 2009-03-27 16:43:08 -0500 (Fri, 27 Mar 2009) | 3 lines Adjusted _tkinter to compile without warnings when WITH_THREAD is not defined (part of issue #5035) ........ r70642 | georg.brandl | 2009-03-27 19:48:48 -0500 (Fri, 27 Mar 2009) | 1 line Fix typo. ........ r70650 | benjamin.peterson | 2009-03-28 14:16:10 -0500 (Sat, 28 Mar 2009) | 1 line give os.symlink and os.link() better parameter names #5564 ........ r70660 | georg.brandl | 2009-03-28 14:52:58 -0500 (Sat, 28 Mar 2009) | 1 line Switch to fixed Sphinx version. ........ r70661 | georg.brandl | 2009-03-28 14:57:36 -0500 (Sat, 28 Mar 2009) | 2 lines Add section numbering to some of the larger subdocuments. ........ r70674 | guilherme.polo | 2009-03-29 05:19:05 -0500 (Sun, 29 Mar 2009) | 1 line Typo fix. ........ r70691 | raymond.hettinger | 2009-03-29 13:51:11 -0500 (Sun, 29 Mar 2009) | 1 line Make life easier for non-CPython implementations. ........ r70697 | benjamin.peterson | 2009-03-29 16:22:35 -0500 (Sun, 29 Mar 2009) | 1 line this has been fixed since 2.6 (I love removing these) ........ r70698 | benjamin.peterson | 2009-03-29 16:31:05 -0500 (Sun, 29 Mar 2009) | 1 line thanks to guido's bytecode verifier, this is fixed ........ r70700 | benjamin.peterson | 2009-03-29 16:50:14 -0500 (Sun, 29 Mar 2009) | 1 line use the awesome new status iterator ........ r70704 | benjamin.peterson | 2009-03-29 21:49:32 -0500 (Sun, 29 Mar 2009) | 1 line there's actually three methods here #5600 ........
17 years ago
32 years ago
Merged revisions 70578,70599,70641-70642,70650,70660-70661,70674,70691,70697-70698,70700,70704 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r70578 | benjamin.peterson | 2009-03-23 22:24:56 -0500 (Mon, 23 Mar 2009) | 1 line this is better written using assertRaises ........ r70599 | benjamin.peterson | 2009-03-25 16:42:51 -0500 (Wed, 25 Mar 2009) | 1 line this can be slightly less ugly ........ r70641 | guilherme.polo | 2009-03-27 16:43:08 -0500 (Fri, 27 Mar 2009) | 3 lines Adjusted _tkinter to compile without warnings when WITH_THREAD is not defined (part of issue #5035) ........ r70642 | georg.brandl | 2009-03-27 19:48:48 -0500 (Fri, 27 Mar 2009) | 1 line Fix typo. ........ r70650 | benjamin.peterson | 2009-03-28 14:16:10 -0500 (Sat, 28 Mar 2009) | 1 line give os.symlink and os.link() better parameter names #5564 ........ r70660 | georg.brandl | 2009-03-28 14:52:58 -0500 (Sat, 28 Mar 2009) | 1 line Switch to fixed Sphinx version. ........ r70661 | georg.brandl | 2009-03-28 14:57:36 -0500 (Sat, 28 Mar 2009) | 2 lines Add section numbering to some of the larger subdocuments. ........ r70674 | guilherme.polo | 2009-03-29 05:19:05 -0500 (Sun, 29 Mar 2009) | 1 line Typo fix. ........ r70691 | raymond.hettinger | 2009-03-29 13:51:11 -0500 (Sun, 29 Mar 2009) | 1 line Make life easier for non-CPython implementations. ........ r70697 | benjamin.peterson | 2009-03-29 16:22:35 -0500 (Sun, 29 Mar 2009) | 1 line this has been fixed since 2.6 (I love removing these) ........ r70698 | benjamin.peterson | 2009-03-29 16:31:05 -0500 (Sun, 29 Mar 2009) | 1 line thanks to guido's bytecode verifier, this is fixed ........ r70700 | benjamin.peterson | 2009-03-29 16:50:14 -0500 (Sun, 29 Mar 2009) | 1 line use the awesome new status iterator ........ r70704 | benjamin.peterson | 2009-03-29 21:49:32 -0500 (Sun, 29 Mar 2009) | 1 line there's actually three methods here #5600 ........
17 years ago
Merged revisions 70578,70599,70641-70642,70650,70660-70661,70674,70691,70697-70698,70700,70704 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r70578 | benjamin.peterson | 2009-03-23 22:24:56 -0500 (Mon, 23 Mar 2009) | 1 line this is better written using assertRaises ........ r70599 | benjamin.peterson | 2009-03-25 16:42:51 -0500 (Wed, 25 Mar 2009) | 1 line this can be slightly less ugly ........ r70641 | guilherme.polo | 2009-03-27 16:43:08 -0500 (Fri, 27 Mar 2009) | 3 lines Adjusted _tkinter to compile without warnings when WITH_THREAD is not defined (part of issue #5035) ........ r70642 | georg.brandl | 2009-03-27 19:48:48 -0500 (Fri, 27 Mar 2009) | 1 line Fix typo. ........ r70650 | benjamin.peterson | 2009-03-28 14:16:10 -0500 (Sat, 28 Mar 2009) | 1 line give os.symlink and os.link() better parameter names #5564 ........ r70660 | georg.brandl | 2009-03-28 14:52:58 -0500 (Sat, 28 Mar 2009) | 1 line Switch to fixed Sphinx version. ........ r70661 | georg.brandl | 2009-03-28 14:57:36 -0500 (Sat, 28 Mar 2009) | 2 lines Add section numbering to some of the larger subdocuments. ........ r70674 | guilherme.polo | 2009-03-29 05:19:05 -0500 (Sun, 29 Mar 2009) | 1 line Typo fix. ........ r70691 | raymond.hettinger | 2009-03-29 13:51:11 -0500 (Sun, 29 Mar 2009) | 1 line Make life easier for non-CPython implementations. ........ r70697 | benjamin.peterson | 2009-03-29 16:22:35 -0500 (Sun, 29 Mar 2009) | 1 line this has been fixed since 2.6 (I love removing these) ........ r70698 | benjamin.peterson | 2009-03-29 16:31:05 -0500 (Sun, 29 Mar 2009) | 1 line thanks to guido's bytecode verifier, this is fixed ........ r70700 | benjamin.peterson | 2009-03-29 16:50:14 -0500 (Sun, 29 Mar 2009) | 1 line use the awesome new status iterator ........ r70704 | benjamin.peterson | 2009-03-29 21:49:32 -0500 (Sun, 29 Mar 2009) | 1 line there's actually three methods here #5600 ........
17 years ago
32 years ago
32 years ago
Merged revisions 70578,70599,70641-70642,70650,70660-70661,70674,70691,70697-70698,70700,70704 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r70578 | benjamin.peterson | 2009-03-23 22:24:56 -0500 (Mon, 23 Mar 2009) | 1 line this is better written using assertRaises ........ r70599 | benjamin.peterson | 2009-03-25 16:42:51 -0500 (Wed, 25 Mar 2009) | 1 line this can be slightly less ugly ........ r70641 | guilherme.polo | 2009-03-27 16:43:08 -0500 (Fri, 27 Mar 2009) | 3 lines Adjusted _tkinter to compile without warnings when WITH_THREAD is not defined (part of issue #5035) ........ r70642 | georg.brandl | 2009-03-27 19:48:48 -0500 (Fri, 27 Mar 2009) | 1 line Fix typo. ........ r70650 | benjamin.peterson | 2009-03-28 14:16:10 -0500 (Sat, 28 Mar 2009) | 1 line give os.symlink and os.link() better parameter names #5564 ........ r70660 | georg.brandl | 2009-03-28 14:52:58 -0500 (Sat, 28 Mar 2009) | 1 line Switch to fixed Sphinx version. ........ r70661 | georg.brandl | 2009-03-28 14:57:36 -0500 (Sat, 28 Mar 2009) | 2 lines Add section numbering to some of the larger subdocuments. ........ r70674 | guilherme.polo | 2009-03-29 05:19:05 -0500 (Sun, 29 Mar 2009) | 1 line Typo fix. ........ r70691 | raymond.hettinger | 2009-03-29 13:51:11 -0500 (Sun, 29 Mar 2009) | 1 line Make life easier for non-CPython implementations. ........ r70697 | benjamin.peterson | 2009-03-29 16:22:35 -0500 (Sun, 29 Mar 2009) | 1 line this has been fixed since 2.6 (I love removing these) ........ r70698 | benjamin.peterson | 2009-03-29 16:31:05 -0500 (Sun, 29 Mar 2009) | 1 line thanks to guido's bytecode verifier, this is fixed ........ r70700 | benjamin.peterson | 2009-03-29 16:50:14 -0500 (Sun, 29 Mar 2009) | 1 line use the awesome new status iterator ........ r70704 | benjamin.peterson | 2009-03-29 21:49:32 -0500 (Sun, 29 Mar 2009) | 1 line there's actually three methods here #5600 ........
17 years ago
Merged revisions 70578,70599,70641-70642,70650,70660-70661,70674,70691,70697-70698,70700,70704 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r70578 | benjamin.peterson | 2009-03-23 22:24:56 -0500 (Mon, 23 Mar 2009) | 1 line this is better written using assertRaises ........ r70599 | benjamin.peterson | 2009-03-25 16:42:51 -0500 (Wed, 25 Mar 2009) | 1 line this can be slightly less ugly ........ r70641 | guilherme.polo | 2009-03-27 16:43:08 -0500 (Fri, 27 Mar 2009) | 3 lines Adjusted _tkinter to compile without warnings when WITH_THREAD is not defined (part of issue #5035) ........ r70642 | georg.brandl | 2009-03-27 19:48:48 -0500 (Fri, 27 Mar 2009) | 1 line Fix typo. ........ r70650 | benjamin.peterson | 2009-03-28 14:16:10 -0500 (Sat, 28 Mar 2009) | 1 line give os.symlink and os.link() better parameter names #5564 ........ r70660 | georg.brandl | 2009-03-28 14:52:58 -0500 (Sat, 28 Mar 2009) | 1 line Switch to fixed Sphinx version. ........ r70661 | georg.brandl | 2009-03-28 14:57:36 -0500 (Sat, 28 Mar 2009) | 2 lines Add section numbering to some of the larger subdocuments. ........ r70674 | guilherme.polo | 2009-03-29 05:19:05 -0500 (Sun, 29 Mar 2009) | 1 line Typo fix. ........ r70691 | raymond.hettinger | 2009-03-29 13:51:11 -0500 (Sun, 29 Mar 2009) | 1 line Make life easier for non-CPython implementations. ........ r70697 | benjamin.peterson | 2009-03-29 16:22:35 -0500 (Sun, 29 Mar 2009) | 1 line this has been fixed since 2.6 (I love removing these) ........ r70698 | benjamin.peterson | 2009-03-29 16:31:05 -0500 (Sun, 29 Mar 2009) | 1 line thanks to guido's bytecode verifier, this is fixed ........ r70700 | benjamin.peterson | 2009-03-29 16:50:14 -0500 (Sun, 29 Mar 2009) | 1 line use the awesome new status iterator ........ r70704 | benjamin.peterson | 2009-03-29 21:49:32 -0500 (Sun, 29 Mar 2009) | 1 line there's actually three methods here #5600 ........
17 years ago
Merge the rest of the trunk. Merged revisions 46490-46494,46496,46498,46500,46506,46521,46538,46558,46563-46567,46570-46571,46583,46593,46595-46598,46604,46606,46609-46753 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r46610 | martin.v.loewis | 2006-06-03 09:42:26 +0200 (Sat, 03 Jun 2006) | 2 lines Updated version (win32-icons2.zip) from #1490384. ........ r46612 | andrew.kuchling | 2006-06-03 20:09:41 +0200 (Sat, 03 Jun 2006) | 1 line [Bug #1472084] Fix description of do_tag ........ r46614 | andrew.kuchling | 2006-06-03 20:33:35 +0200 (Sat, 03 Jun 2006) | 1 line [Bug #1475554] Strengthen text to say 'must' instead of 'should' ........ r46616 | andrew.kuchling | 2006-06-03 20:41:28 +0200 (Sat, 03 Jun 2006) | 1 line [Bug #1441864] Clarify description of 'data' argument ........ r46617 | andrew.kuchling | 2006-06-03 20:43:24 +0200 (Sat, 03 Jun 2006) | 1 line Minor rewording ........ r46619 | andrew.kuchling | 2006-06-03 21:02:35 +0200 (Sat, 03 Jun 2006) | 9 lines [Bug #1497414] _self is a reserved word in the WATCOM 10.6 C compiler. Fix by renaming the variable. In a different module, Neal fixed it by renaming _self to self. There's already a variable named 'self' here, so I used selfptr. (I'm committing this on a Mac without Tk, but it's a simple search-and-replace. <crosses fingers>, so I'll watch the buildbots and see what happens.) ........ r46621 | fredrik.lundh | 2006-06-03 23:56:05 +0200 (Sat, 03 Jun 2006) | 5 lines "_self" is a said to be a reserved word in Watcom C 10.6. I'm not sure that's really standard compliant behaviour, but I guess we have to fix that anyway... ........ r46622 | andrew.kuchling | 2006-06-04 00:44:42 +0200 (Sun, 04 Jun 2006) | 1 line Update readme ........ r46623 | andrew.kuchling | 2006-06-04 00:59:23 +0200 (Sun, 04 Jun 2006) | 1 line Drop 0 parameter ........ r46624 | andrew.kuchling | 2006-06-04 00:59:59 +0200 (Sun, 04 Jun 2006) | 1 line Some code tidying; use curses.wrapper ........ r46625 | andrew.kuchling | 2006-06-04 01:02:15 +0200 (Sun, 04 Jun 2006) | 1 line Use True; value returned from main is unused ........ r46626 | andrew.kuchling | 2006-06-04 01:07:21 +0200 (Sun, 04 Jun 2006) | 1 line Use true division, and the True value ........ r46627 | andrew.kuchling | 2006-06-04 01:09:58 +0200 (Sun, 04 Jun 2006) | 1 line Docstring fix; use True ........ r46628 | andrew.kuchling | 2006-06-04 01:15:56 +0200 (Sun, 04 Jun 2006) | 1 line Put code in a main() function; loosen up the spacing to match current code style ........ r46629 | andrew.kuchling | 2006-06-04 01:39:07 +0200 (Sun, 04 Jun 2006) | 1 line Use functions; modernize code ........ r46630 | andrew.kuchling | 2006-06-04 01:43:22 +0200 (Sun, 04 Jun 2006) | 1 line This demo requires Medusa (not just asyncore); remove it ........ r46631 | andrew.kuchling | 2006-06-04 01:46:36 +0200 (Sun, 04 Jun 2006) | 2 lines Remove xmlrpc demo -- it duplicates the SimpleXMLRPCServer module. ........ r46632 | andrew.kuchling | 2006-06-04 01:47:22 +0200 (Sun, 04 Jun 2006) | 1 line Remove xmlrpc/ directory ........ r46633 | andrew.kuchling | 2006-06-04 01:51:21 +0200 (Sun, 04 Jun 2006) | 1 line Remove dangling reference ........ r46634 | andrew.kuchling | 2006-06-04 01:59:36 +0200 (Sun, 04 Jun 2006) | 1 line Add more whitespace; use a better socket name ........ r46635 | tim.peters | 2006-06-04 03:22:53 +0200 (Sun, 04 Jun 2006) | 2 lines Whitespace normalization. ........ r46637 | tim.peters | 2006-06-04 05:26:02 +0200 (Sun, 04 Jun 2006) | 16 lines In a PYMALLOC_DEBUG build obmalloc adds extra debugging info to each allocated block. This was using 4 bytes for each such piece of info regardless of platform. This didn't really matter before (proof: no bug reports, and the debug-build obmalloc would have assert-failed if it was ever asked for a chunk of memory >= 2**32 bytes), since container indices were plain ints. But after the Py_ssize_t changes, it's at least theoretically possible to allocate a list or string whose guts exceed 2**32 bytes, and the PYMALLOC_DEBUG routines would fail then (having only 4 bytes to record the originally requested size). Now we use sizeof(size_t) bytes for each of a PYMALLOC_DEBUG build's extra debugging fields. This won't make any difference on 32-bit boxes, but will add 16 bytes to each allocation in a debug build on a 64-bit box. ........ r46638 | tim.peters | 2006-06-04 05:38:04 +0200 (Sun, 04 Jun 2006) | 4 lines _PyObject_DebugMalloc(): The return value should add 2*sizeof(size_t) now, not 8. This probably accounts for current disasters on the 64-bit buildbot slaves. ........ r46639 | neal.norwitz | 2006-06-04 08:19:31 +0200 (Sun, 04 Jun 2006) | 1 line SF #1499797, Fix for memory leak in WindowsError_str ........ r46640 | andrew.macintyre | 2006-06-04 14:31:09 +0200 (Sun, 04 Jun 2006) | 2 lines Patch #1454481: Make thread stack size runtime tunable. ........ r46641 | andrew.macintyre | 2006-06-04 14:59:59 +0200 (Sun, 04 Jun 2006) | 2 lines clean up function declarations to conform to PEP-7 style. ........ r46642 | martin.blais | 2006-06-04 15:49:49 +0200 (Sun, 04 Jun 2006) | 15 lines Fixes in struct and socket from merge reviews. - Following Guido's comments, renamed * pack_to -> pack_into * recv_buf -> recv_into * recvfrom_buf -> recvfrom_into - Made fixes to _struct.c according to Neal Norwitz comments on the checkins list. - Converted some ints into the appropriate -- I hope -- ssize_t and size_t. ........ r46643 | ronald.oussoren | 2006-06-04 16:05:28 +0200 (Sun, 04 Jun 2006) | 3 lines "Import" LDFLAGS in Mac/OSX/Makefile.in to ensure pythonw gets build with the right compiler flags. ........ r46644 | ronald.oussoren | 2006-06-04 16:24:59 +0200 (Sun, 04 Jun 2006) | 2 lines Drop Mac wrappers for the WASTE library. ........ r46645 | tim.peters | 2006-06-04 17:49:07 +0200 (Sun, 04 Jun 2006) | 3 lines s_methods[]: Stop compiler warnings by casting s_unpack_from to PyCFunction. ........ r46646 | george.yoshida | 2006-06-04 19:04:12 +0200 (Sun, 04 Jun 2006) | 2 lines Remove a redundant word ........ r46647 | george.yoshida | 2006-06-04 19:17:25 +0200 (Sun, 04 Jun 2006) | 2 lines Markup fix ........ r46648 | martin.v.loewis | 2006-06-04 21:36:28 +0200 (Sun, 04 Jun 2006) | 2 lines Patch #1359618: Speed-up charmap encoder. ........ r46649 | georg.brandl | 2006-06-04 23:46:16 +0200 (Sun, 04 Jun 2006) | 3 lines Repair refleaks in unicodeobject. ........ r46650 | georg.brandl | 2006-06-04 23:56:52 +0200 (Sun, 04 Jun 2006) | 4 lines Patch #1346214: correctly optimize away "if 0"-style stmts (thanks to Neal for review) ........ r46651 | georg.brandl | 2006-06-05 00:15:37 +0200 (Mon, 05 Jun 2006) | 2 lines Bug #1500293: fix memory leaks in _subprocess module. ........ r46654 | tim.peters | 2006-06-05 01:43:53 +0200 (Mon, 05 Jun 2006) | 2 lines Whitespace normalization. ........ r46655 | tim.peters | 2006-06-05 01:52:47 +0200 (Mon, 05 Jun 2006) | 16 lines Revert revisions: 46640 Patch #1454481: Make thread stack size runtime tunable. 46647 Markup fix The first is causing many buildbots to fail test runs, and there are multiple causes with seemingly no immediate prospects for repairing them. See python-dev discussion. Note that a branch can (and should) be created for resolving these problems, like svn copy svn+ssh://svn.python.org/python/trunk -r46640 svn+ssh://svn.python.org/python/branches/NEW_BRANCH followed by merging rev 46647 to the new branch. ........ r46656 | andrew.kuchling | 2006-06-05 02:08:09 +0200 (Mon, 05 Jun 2006) | 1 line Mention second encoding speedup ........ r46657 | gregory.p.smith | 2006-06-05 02:31:01 +0200 (Mon, 05 Jun 2006) | 7 lines bugfix: when log_archive was called with the DB_ARCH_REMOVE flag present in BerkeleyDB >= 4.2 it tried to construct a list out of an uninitialized char **log_list. feature: export the DB_ARCH_REMOVE flag by name in the module on BerkeleyDB >= 4.2. ........ r46658 | gregory.p.smith | 2006-06-05 02:33:35 +0200 (Mon, 05 Jun 2006) | 5 lines fix a bug in the previous commit. don't leak empty list on error return and fix the additional rare (out of memory only) bug that it was supposed to fix of not freeing log_list when the python allocator failed. ........ r46660 | tim.peters | 2006-06-05 02:55:26 +0200 (Mon, 05 Jun 2006) | 9 lines "Flat is better than nested." Move the long-winded, multiply-nested -R support out of runtest() and into some module-level helper functions. This makes runtest() and the -R code easier to follow. That in turn allowed seeing some opportunities for code simplification, and made it obvious that reglog.txt never got closed. ........ r46661 | hyeshik.chang | 2006-06-05 02:59:54 +0200 (Mon, 05 Jun 2006) | 3 lines Fix a potentially invalid memory access of CJKCodecs' shift-jis decoder. (found by Neal Norwitz) ........ r46663 | gregory.p.smith | 2006-06-05 03:39:52 +0200 (Mon, 05 Jun 2006) | 3 lines * support DBEnv.log_stat() method on BerkeleyDB >= 4.0 [patch #1494885] ........ r46664 | tim.peters | 2006-06-05 03:43:03 +0200 (Mon, 05 Jun 2006) | 3 lines Remove doctest.testmod's deprecated (in 2.4) `isprivate` argument. A lot of hair went into supporting that! ........ r46665 | tim.peters | 2006-06-05 03:47:24 +0200 (Mon, 05 Jun 2006) | 2 lines Whitespace normalization. ........ r46666 | tim.peters | 2006-06-05 03:48:21 +0200 (Mon, 05 Jun 2006) | 2 lines Make doctest news more accurate. ........ r46667 | gregory.p.smith | 2006-06-05 03:56:15 +0200 (Mon, 05 Jun 2006) | 3 lines * support DBEnv.lsn_reset() method on BerkeleyDB >= 4.4 [patch #1494902] ........ r46668 | gregory.p.smith | 2006-06-05 04:02:25 +0200 (Mon, 05 Jun 2006) | 3 lines mention the just committed bsddb changes ........ r46671 | gregory.p.smith | 2006-06-05 19:38:04 +0200 (Mon, 05 Jun 2006) | 3 lines * add support for DBSequence objects [patch #1466734] ........ r46672 | gregory.p.smith | 2006-06-05 20:20:07 +0200 (Mon, 05 Jun 2006) | 3 lines forgot to add this file in previous commit ........ r46673 | tim.peters | 2006-06-05 20:36:12 +0200 (Mon, 05 Jun 2006) | 2 lines Whitespace normalization. ........ r46674 | tim.peters | 2006-06-05 20:36:54 +0200 (Mon, 05 Jun 2006) | 2 lines Add missing svn:eol-style property to text files. ........ r46675 | gregory.p.smith | 2006-06-05 20:48:21 +0200 (Mon, 05 Jun 2006) | 4 lines * fix DBCursor.pget() bug with keyword argument names when no data= is supplied [SF pybsddb bug #1477863] ........ r46676 | andrew.kuchling | 2006-06-05 21:05:32 +0200 (Mon, 05 Jun 2006) | 1 line Remove use of Trove name, which isn't very helpful to users ........ r46677 | andrew.kuchling | 2006-06-05 21:08:25 +0200 (Mon, 05 Jun 2006) | 1 line [Bug #1470026] Include link to list of classifiers ........ r46679 | tim.peters | 2006-06-05 22:48:49 +0200 (Mon, 05 Jun 2006) | 10 lines Access _struct attributes directly instead of mucking with getattr. string_reverse(): Simplify. assertRaises(): Raise TestFailed on failure. test_unpack_from(), test_pack_into(), test_pack_into_fn(): never use `assert` to test for an expected result (it doesn't test anything when Python is run with -O). ........ r46680 | tim.peters | 2006-06-05 22:49:27 +0200 (Mon, 05 Jun 2006) | 2 lines Add missing svn:eol-style property to text files. ........ r46681 | gregory.p.smith | 2006-06-06 01:38:06 +0200 (Tue, 06 Jun 2006) | 3 lines add depends = ['md5.h'] to the _md5 module extension for correctness sake. ........ r46682 | brett.cannon | 2006-06-06 01:51:55 +0200 (Tue, 06 Jun 2006) | 4 lines Add 3 more bytes to a buffer to cover constants in string and null byte on top of 10 possible digits for an int. Closes bug #1501223. ........ r46684 | gregory.p.smith | 2006-06-06 01:59:37 +0200 (Tue, 06 Jun 2006) | 5 lines - bsddb: the __len__ method of a DB object has been fixed to return correct results. It could previously incorrectly return 0 in some cases. Fixes SF bug 1493322 (pybsddb bug 1184012). ........ r46686 | tim.peters | 2006-06-06 02:25:07 +0200 (Tue, 06 Jun 2006) | 7 lines _PySys_Init(): It's rarely a good idea to size a buffer to the exact maximum size someone guesses is needed. In this case, if we're really worried about extreme integers, then "cp%d" can actually need 14 bytes (2 for "cp" + 1 for \0 at the end + 11 for -(2**31-1)). So reserve 128 bytes instead -- nothing is actually saved by making a stack-local buffer tiny. ........ r46687 | neal.norwitz | 2006-06-06 09:22:08 +0200 (Tue, 06 Jun 2006) | 1 line Remove unused variable (and stop compiler warning) ........ r46688 | neal.norwitz | 2006-06-06 09:23:01 +0200 (Tue, 06 Jun 2006) | 1 line Fix a bunch of parameter strings ........ r46689 | thomas.heller | 2006-06-06 13:34:33 +0200 (Tue, 06 Jun 2006) | 6 lines Convert CFieldObject tp_members to tp_getset, since there is no structmember typecode for Py_ssize_t fields. This should fix some of the errors on the PPC64 debian machine (64-bit, big endian). Assigning to readonly fields now raises AttributeError instead of TypeError, so the testcase has to be changed as well. ........ r46690 | thomas.heller | 2006-06-06 13:54:32 +0200 (Tue, 06 Jun 2006) | 1 line Damn - the sentinel was missing. And fix another silly mistake. ........ r46691 | martin.blais | 2006-06-06 14:46:55 +0200 (Tue, 06 Jun 2006) | 13 lines Normalized a few cases of whitespace in function declarations. Found them using:: find . -name '*.py' | while read i ; do grep 'def[^(]*( ' $i /dev/null ; done find . -name '*.py' | while read i ; do grep ' ):' $i /dev/null ; done (I was doing this all over my own code anyway, because I'd been using spaces in all defs, so I thought I'd make a run on the Python code as well. If you need to do such fixes in your own code, you can use xx-rename or parenregu.el within emacs.) ........ r46693 | thomas.heller | 2006-06-06 17:34:18 +0200 (Tue, 06 Jun 2006) | 1 line Specify argtypes for all test functions. Maybe that helps on strange ;-) architectures ........ r46694 | tim.peters | 2006-06-06 17:50:17 +0200 (Tue, 06 Jun 2006) | 5 lines BSequence_set_range(): Rev 46688 ("Fix a bunch of parameter strings") changed this function's signature seemingly by mistake, which is causing buildbots to fail test_bsddb3. Restored the pre-46688 signature. ........ r46695 | tim.peters | 2006-06-06 17:52:35 +0200 (Tue, 06 Jun 2006) | 4 lines On python-dev Thomas Heller said these were committed by mistake in rev 46693, so reverting this part of rev 46693. ........ r46696 | andrew.kuchling | 2006-06-06 19:10:41 +0200 (Tue, 06 Jun 2006) | 1 line Fix comment typo ........ r46697 | brett.cannon | 2006-06-06 20:08:16 +0200 (Tue, 06 Jun 2006) | 2 lines Fix coding style guide bug. ........ r46698 | thomas.heller | 2006-06-06 20:50:46 +0200 (Tue, 06 Jun 2006) | 2 lines Add a hack so that foreign functions returning float now do work on 64-bit big endian platforms. ........ r46699 | thomas.heller | 2006-06-06 21:25:13 +0200 (Tue, 06 Jun 2006) | 3 lines Use the same big-endian hack as in _ctypes/callproc.c for callback functions. This fixes the callback function tests that return float. ........ r46700 | ronald.oussoren | 2006-06-06 21:50:24 +0200 (Tue, 06 Jun 2006) | 5 lines * Ensure that "make altinstall" works when the tree was configured with --enable-framework * Also for --enable-framework: allow users to use --prefix to specify the location of the compatibility symlinks (such as /usr/local/bin/python) ........ r46701 | ronald.oussoren | 2006-06-06 21:56:00 +0200 (Tue, 06 Jun 2006) | 3 lines A quick hack to ensure the right key-bindings for IDLE on osx: install patched configuration files during a framework install. ........ r46702 | tim.peters | 2006-06-07 03:04:59 +0200 (Wed, 07 Jun 2006) | 4 lines dash_R_cleanup(): Clear filecmp._cache. This accounts for different results across -R runs (at least on Windows) of test_filecmp. ........ r46705 | tim.peters | 2006-06-07 08:57:51 +0200 (Wed, 07 Jun 2006) | 17 lines SF patch 1501987: Remove randomness from test_exceptions, from ?iga Seilnacht (sorry about the name, but Firefox on my box can't display the first character of the name -- the SF "Unix name" is zseil). This appears to cure the oddball intermittent leaks across runs when running test_exceptions under -R. I'm not sure why, but I'm too sleepy to care ;-) The thrust of the SF patch was to remove randomness in the pickle protocol used. I changed the patch to use range(pickle.HIGHEST_PROTOCOL + 1), to try both pickle and cPickle, and randomly mucked with other test lines to put statements on their own lines. Not a bugfix candidate (this is fiddling new-in-2.5 code). ........ r46706 | andrew.kuchling | 2006-06-07 15:55:33 +0200 (Wed, 07 Jun 2006) | 1 line Add an SQLite introduction, taken from the 'What's New' text ........ r46708 | andrew.kuchling | 2006-06-07 19:02:52 +0200 (Wed, 07 Jun 2006) | 1 line Mention other placeholders ........ r46709 | andrew.kuchling | 2006-06-07 19:03:46 +0200 (Wed, 07 Jun 2006) | 1 line Add an item; also, escape % ........ r46710 | andrew.kuchling | 2006-06-07 19:04:01 +0200 (Wed, 07 Jun 2006) | 1 line Mention other placeholders ........ r46716 | ronald.oussoren | 2006-06-07 20:57:44 +0200 (Wed, 07 Jun 2006) | 2 lines Move Mac/OSX/Tools one level up ........ r46717 | ronald.oussoren | 2006-06-07 20:58:01 +0200 (Wed, 07 Jun 2006) | 2 lines Move Mac/OSX/PythonLauncher one level up ........ r46718 | ronald.oussoren | 2006-06-07 20:58:42 +0200 (Wed, 07 Jun 2006) | 2 lines mv Mac/OSX/BuildScript one level up ........ r46719 | ronald.oussoren | 2006-06-07 21:02:03 +0200 (Wed, 07 Jun 2006) | 2 lines Move Mac/OSX/* one level up ........ r46720 | ronald.oussoren | 2006-06-07 21:06:01 +0200 (Wed, 07 Jun 2006) | 2 lines And the last bit: move IDLE one level up and adjust makefiles ........ r46723 | ronald.oussoren | 2006-06-07 21:38:53 +0200 (Wed, 07 Jun 2006) | 4 lines - Patch the correct version of python in the Info.plists at build time, instead of relying on a maintainer to update them before releases. - Remove the now empty Mac/OSX directory ........ r46727 | ronald.oussoren | 2006-06-07 22:18:44 +0200 (Wed, 07 Jun 2006) | 7 lines * If BuildApplet.py is used as an applet it starts with a version of sys.exutable that isn't usuable on an #!-line. That results in generated applets that don't actually work. Work around this problem by resetting sys.executable. * argvemulator.py didn't work on intel macs. This patch fixes this (bug #1491468) ........ r46728 | tim.peters | 2006-06-07 22:40:06 +0200 (Wed, 07 Jun 2006) | 2 lines Whitespace normalization. ........ r46729 | tim.peters | 2006-06-07 22:40:54 +0200 (Wed, 07 Jun 2006) | 2 lines Add missing svn:eol-style property to text files. ........ r46730 | thomas.heller | 2006-06-07 22:43:06 +0200 (Wed, 07 Jun 2006) | 7 lines Fix for foreign functions returning small structures on 64-bit big endian machines. Should fix the remaininf failure in the PPC64 Debian buildbot. Thanks to Matthias Klose for providing access to a machine to debug and test this. ........ r46731 | brett.cannon | 2006-06-07 23:48:17 +0200 (Wed, 07 Jun 2006) | 2 lines Clarify documentation for bf_getcharbuffer. ........ r46735 | neal.norwitz | 2006-06-08 07:12:45 +0200 (Thu, 08 Jun 2006) | 1 line Fix a refleak in recvfrom_into ........ r46736 | gregory.p.smith | 2006-06-08 07:17:08 +0200 (Thu, 08 Jun 2006) | 9 lines - bsddb: the bsddb.dbtables Modify method now raises the proper error and aborts the db transaction safely when a modifier callback fails. Fixes SF python patch/bug #1408584. Also cleans up the bsddb.dbtables docstrings since thats the only documentation that exists for that unadvertised module. (people really should really just use sqlite3) ........ r46737 | gregory.p.smith | 2006-06-08 07:38:11 +0200 (Thu, 08 Jun 2006) | 4 lines * Turn the deadlock situation described in SF bug #775414 into a DBDeadLockError exception. * add the test case for my previous dbtables commit. ........ r46738 | gregory.p.smith | 2006-06-08 07:39:54 +0200 (Thu, 08 Jun 2006) | 2 lines pasted set_lk_detect line in wrong spot in previous commit. fixed. passes tests this time. ........ r46739 | armin.rigo | 2006-06-08 12:56:24 +0200 (Thu, 08 Jun 2006) | 6 lines (arre, arigo) SF bug #1350060 Give a consistent behavior for comparison and hashing of method objects (both user- and built-in methods). Now compares the 'self' recursively. The hash was already asking for the hash of 'self'. ........ r46740 | andrew.kuchling | 2006-06-08 13:56:44 +0200 (Thu, 08 Jun 2006) | 1 line Typo fix ........ r46741 | georg.brandl | 2006-06-08 14:45:01 +0200 (Thu, 08 Jun 2006) | 2 lines Bug #1502750: Fix getargs "i" format to use LONG_MIN and LONG_MAX for bounds checking. ........ r46743 | georg.brandl | 2006-06-08 14:54:13 +0200 (Thu, 08 Jun 2006) | 2 lines Bug #1502728: Correctly link against librt library on HP-UX. ........ r46745 | georg.brandl | 2006-06-08 14:55:47 +0200 (Thu, 08 Jun 2006) | 3 lines Add news for recent bugfix. ........ r46746 | georg.brandl | 2006-06-08 15:31:07 +0200 (Thu, 08 Jun 2006) | 4 lines Argh. "integer" is a very confusing word ;) Actually, checking for INT_MAX and INT_MIN is correct since the format code explicitly handles a C "int". ........ r46748 | nick.coghlan | 2006-06-08 15:54:49 +0200 (Thu, 08 Jun 2006) | 1 line Add functools.update_wrapper() and functools.wraps() as described in PEP 356 ........ r46751 | georg.brandl | 2006-06-08 16:50:21 +0200 (Thu, 08 Jun 2006) | 4 lines Bug #1502805: don't alias file.__exit__ to file.close since the latter can return something that's true. ........ r46752 | georg.brandl | 2006-06-08 16:50:53 +0200 (Thu, 08 Jun 2006) | 3 lines Convert test_file to unittest. ........
20 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
Merged revisions 70578,70599,70641-70642,70650,70660-70661,70674,70691,70697-70698,70700,70704 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r70578 | benjamin.peterson | 2009-03-23 22:24:56 -0500 (Mon, 23 Mar 2009) | 1 line this is better written using assertRaises ........ r70599 | benjamin.peterson | 2009-03-25 16:42:51 -0500 (Wed, 25 Mar 2009) | 1 line this can be slightly less ugly ........ r70641 | guilherme.polo | 2009-03-27 16:43:08 -0500 (Fri, 27 Mar 2009) | 3 lines Adjusted _tkinter to compile without warnings when WITH_THREAD is not defined (part of issue #5035) ........ r70642 | georg.brandl | 2009-03-27 19:48:48 -0500 (Fri, 27 Mar 2009) | 1 line Fix typo. ........ r70650 | benjamin.peterson | 2009-03-28 14:16:10 -0500 (Sat, 28 Mar 2009) | 1 line give os.symlink and os.link() better parameter names #5564 ........ r70660 | georg.brandl | 2009-03-28 14:52:58 -0500 (Sat, 28 Mar 2009) | 1 line Switch to fixed Sphinx version. ........ r70661 | georg.brandl | 2009-03-28 14:57:36 -0500 (Sat, 28 Mar 2009) | 2 lines Add section numbering to some of the larger subdocuments. ........ r70674 | guilherme.polo | 2009-03-29 05:19:05 -0500 (Sun, 29 Mar 2009) | 1 line Typo fix. ........ r70691 | raymond.hettinger | 2009-03-29 13:51:11 -0500 (Sun, 29 Mar 2009) | 1 line Make life easier for non-CPython implementations. ........ r70697 | benjamin.peterson | 2009-03-29 16:22:35 -0500 (Sun, 29 Mar 2009) | 1 line this has been fixed since 2.6 (I love removing these) ........ r70698 | benjamin.peterson | 2009-03-29 16:31:05 -0500 (Sun, 29 Mar 2009) | 1 line thanks to guido's bytecode verifier, this is fixed ........ r70700 | benjamin.peterson | 2009-03-29 16:50:14 -0500 (Sun, 29 Mar 2009) | 1 line use the awesome new status iterator ........ r70704 | benjamin.peterson | 2009-03-29 21:49:32 -0500 (Sun, 29 Mar 2009) | 1 line there's actually three methods here #5600 ........
17 years ago
Merged revisions 70578,70599,70641-70642,70650,70660-70661,70674,70691,70697-70698,70700,70704 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r70578 | benjamin.peterson | 2009-03-23 22:24:56 -0500 (Mon, 23 Mar 2009) | 1 line this is better written using assertRaises ........ r70599 | benjamin.peterson | 2009-03-25 16:42:51 -0500 (Wed, 25 Mar 2009) | 1 line this can be slightly less ugly ........ r70641 | guilherme.polo | 2009-03-27 16:43:08 -0500 (Fri, 27 Mar 2009) | 3 lines Adjusted _tkinter to compile without warnings when WITH_THREAD is not defined (part of issue #5035) ........ r70642 | georg.brandl | 2009-03-27 19:48:48 -0500 (Fri, 27 Mar 2009) | 1 line Fix typo. ........ r70650 | benjamin.peterson | 2009-03-28 14:16:10 -0500 (Sat, 28 Mar 2009) | 1 line give os.symlink and os.link() better parameter names #5564 ........ r70660 | georg.brandl | 2009-03-28 14:52:58 -0500 (Sat, 28 Mar 2009) | 1 line Switch to fixed Sphinx version. ........ r70661 | georg.brandl | 2009-03-28 14:57:36 -0500 (Sat, 28 Mar 2009) | 2 lines Add section numbering to some of the larger subdocuments. ........ r70674 | guilherme.polo | 2009-03-29 05:19:05 -0500 (Sun, 29 Mar 2009) | 1 line Typo fix. ........ r70691 | raymond.hettinger | 2009-03-29 13:51:11 -0500 (Sun, 29 Mar 2009) | 1 line Make life easier for non-CPython implementations. ........ r70697 | benjamin.peterson | 2009-03-29 16:22:35 -0500 (Sun, 29 Mar 2009) | 1 line this has been fixed since 2.6 (I love removing these) ........ r70698 | benjamin.peterson | 2009-03-29 16:31:05 -0500 (Sun, 29 Mar 2009) | 1 line thanks to guido's bytecode verifier, this is fixed ........ r70700 | benjamin.peterson | 2009-03-29 16:50:14 -0500 (Sun, 29 Mar 2009) | 1 line use the awesome new status iterator ........ r70704 | benjamin.peterson | 2009-03-29 21:49:32 -0500 (Sun, 29 Mar 2009) | 1 line there's actually three methods here #5600 ........
17 years ago
Merged revisions 70578,70599,70641-70642,70650,70660-70661,70674,70691,70697-70698,70700,70704 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r70578 | benjamin.peterson | 2009-03-23 22:24:56 -0500 (Mon, 23 Mar 2009) | 1 line this is better written using assertRaises ........ r70599 | benjamin.peterson | 2009-03-25 16:42:51 -0500 (Wed, 25 Mar 2009) | 1 line this can be slightly less ugly ........ r70641 | guilherme.polo | 2009-03-27 16:43:08 -0500 (Fri, 27 Mar 2009) | 3 lines Adjusted _tkinter to compile without warnings when WITH_THREAD is not defined (part of issue #5035) ........ r70642 | georg.brandl | 2009-03-27 19:48:48 -0500 (Fri, 27 Mar 2009) | 1 line Fix typo. ........ r70650 | benjamin.peterson | 2009-03-28 14:16:10 -0500 (Sat, 28 Mar 2009) | 1 line give os.symlink and os.link() better parameter names #5564 ........ r70660 | georg.brandl | 2009-03-28 14:52:58 -0500 (Sat, 28 Mar 2009) | 1 line Switch to fixed Sphinx version. ........ r70661 | georg.brandl | 2009-03-28 14:57:36 -0500 (Sat, 28 Mar 2009) | 2 lines Add section numbering to some of the larger subdocuments. ........ r70674 | guilherme.polo | 2009-03-29 05:19:05 -0500 (Sun, 29 Mar 2009) | 1 line Typo fix. ........ r70691 | raymond.hettinger | 2009-03-29 13:51:11 -0500 (Sun, 29 Mar 2009) | 1 line Make life easier for non-CPython implementations. ........ r70697 | benjamin.peterson | 2009-03-29 16:22:35 -0500 (Sun, 29 Mar 2009) | 1 line this has been fixed since 2.6 (I love removing these) ........ r70698 | benjamin.peterson | 2009-03-29 16:31:05 -0500 (Sun, 29 Mar 2009) | 1 line thanks to guido's bytecode verifier, this is fixed ........ r70700 | benjamin.peterson | 2009-03-29 16:50:14 -0500 (Sun, 29 Mar 2009) | 1 line use the awesome new status iterator ........ r70704 | benjamin.peterson | 2009-03-29 21:49:32 -0500 (Sun, 29 Mar 2009) | 1 line there's actually three methods here #5600 ........
17 years ago
Merged revisions 70578,70599,70641-70642,70650,70660-70661,70674,70691,70697-70698,70700,70704 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r70578 | benjamin.peterson | 2009-03-23 22:24:56 -0500 (Mon, 23 Mar 2009) | 1 line this is better written using assertRaises ........ r70599 | benjamin.peterson | 2009-03-25 16:42:51 -0500 (Wed, 25 Mar 2009) | 1 line this can be slightly less ugly ........ r70641 | guilherme.polo | 2009-03-27 16:43:08 -0500 (Fri, 27 Mar 2009) | 3 lines Adjusted _tkinter to compile without warnings when WITH_THREAD is not defined (part of issue #5035) ........ r70642 | georg.brandl | 2009-03-27 19:48:48 -0500 (Fri, 27 Mar 2009) | 1 line Fix typo. ........ r70650 | benjamin.peterson | 2009-03-28 14:16:10 -0500 (Sat, 28 Mar 2009) | 1 line give os.symlink and os.link() better parameter names #5564 ........ r70660 | georg.brandl | 2009-03-28 14:52:58 -0500 (Sat, 28 Mar 2009) | 1 line Switch to fixed Sphinx version. ........ r70661 | georg.brandl | 2009-03-28 14:57:36 -0500 (Sat, 28 Mar 2009) | 2 lines Add section numbering to some of the larger subdocuments. ........ r70674 | guilherme.polo | 2009-03-29 05:19:05 -0500 (Sun, 29 Mar 2009) | 1 line Typo fix. ........ r70691 | raymond.hettinger | 2009-03-29 13:51:11 -0500 (Sun, 29 Mar 2009) | 1 line Make life easier for non-CPython implementations. ........ r70697 | benjamin.peterson | 2009-03-29 16:22:35 -0500 (Sun, 29 Mar 2009) | 1 line this has been fixed since 2.6 (I love removing these) ........ r70698 | benjamin.peterson | 2009-03-29 16:31:05 -0500 (Sun, 29 Mar 2009) | 1 line thanks to guido's bytecode verifier, this is fixed ........ r70700 | benjamin.peterson | 2009-03-29 16:50:14 -0500 (Sun, 29 Mar 2009) | 1 line use the awesome new status iterator ........ r70704 | benjamin.peterson | 2009-03-29 21:49:32 -0500 (Sun, 29 Mar 2009) | 1 line there's actually three methods here #5600 ........
17 years ago
Merge the rest of the trunk. Merged revisions 46490-46494,46496,46498,46500,46506,46521,46538,46558,46563-46567,46570-46571,46583,46593,46595-46598,46604,46606,46609-46753 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r46610 | martin.v.loewis | 2006-06-03 09:42:26 +0200 (Sat, 03 Jun 2006) | 2 lines Updated version (win32-icons2.zip) from #1490384. ........ r46612 | andrew.kuchling | 2006-06-03 20:09:41 +0200 (Sat, 03 Jun 2006) | 1 line [Bug #1472084] Fix description of do_tag ........ r46614 | andrew.kuchling | 2006-06-03 20:33:35 +0200 (Sat, 03 Jun 2006) | 1 line [Bug #1475554] Strengthen text to say 'must' instead of 'should' ........ r46616 | andrew.kuchling | 2006-06-03 20:41:28 +0200 (Sat, 03 Jun 2006) | 1 line [Bug #1441864] Clarify description of 'data' argument ........ r46617 | andrew.kuchling | 2006-06-03 20:43:24 +0200 (Sat, 03 Jun 2006) | 1 line Minor rewording ........ r46619 | andrew.kuchling | 2006-06-03 21:02:35 +0200 (Sat, 03 Jun 2006) | 9 lines [Bug #1497414] _self is a reserved word in the WATCOM 10.6 C compiler. Fix by renaming the variable. In a different module, Neal fixed it by renaming _self to self. There's already a variable named 'self' here, so I used selfptr. (I'm committing this on a Mac without Tk, but it's a simple search-and-replace. <crosses fingers>, so I'll watch the buildbots and see what happens.) ........ r46621 | fredrik.lundh | 2006-06-03 23:56:05 +0200 (Sat, 03 Jun 2006) | 5 lines "_self" is a said to be a reserved word in Watcom C 10.6. I'm not sure that's really standard compliant behaviour, but I guess we have to fix that anyway... ........ r46622 | andrew.kuchling | 2006-06-04 00:44:42 +0200 (Sun, 04 Jun 2006) | 1 line Update readme ........ r46623 | andrew.kuchling | 2006-06-04 00:59:23 +0200 (Sun, 04 Jun 2006) | 1 line Drop 0 parameter ........ r46624 | andrew.kuchling | 2006-06-04 00:59:59 +0200 (Sun, 04 Jun 2006) | 1 line Some code tidying; use curses.wrapper ........ r46625 | andrew.kuchling | 2006-06-04 01:02:15 +0200 (Sun, 04 Jun 2006) | 1 line Use True; value returned from main is unused ........ r46626 | andrew.kuchling | 2006-06-04 01:07:21 +0200 (Sun, 04 Jun 2006) | 1 line Use true division, and the True value ........ r46627 | andrew.kuchling | 2006-06-04 01:09:58 +0200 (Sun, 04 Jun 2006) | 1 line Docstring fix; use True ........ r46628 | andrew.kuchling | 2006-06-04 01:15:56 +0200 (Sun, 04 Jun 2006) | 1 line Put code in a main() function; loosen up the spacing to match current code style ........ r46629 | andrew.kuchling | 2006-06-04 01:39:07 +0200 (Sun, 04 Jun 2006) | 1 line Use functions; modernize code ........ r46630 | andrew.kuchling | 2006-06-04 01:43:22 +0200 (Sun, 04 Jun 2006) | 1 line This demo requires Medusa (not just asyncore); remove it ........ r46631 | andrew.kuchling | 2006-06-04 01:46:36 +0200 (Sun, 04 Jun 2006) | 2 lines Remove xmlrpc demo -- it duplicates the SimpleXMLRPCServer module. ........ r46632 | andrew.kuchling | 2006-06-04 01:47:22 +0200 (Sun, 04 Jun 2006) | 1 line Remove xmlrpc/ directory ........ r46633 | andrew.kuchling | 2006-06-04 01:51:21 +0200 (Sun, 04 Jun 2006) | 1 line Remove dangling reference ........ r46634 | andrew.kuchling | 2006-06-04 01:59:36 +0200 (Sun, 04 Jun 2006) | 1 line Add more whitespace; use a better socket name ........ r46635 | tim.peters | 2006-06-04 03:22:53 +0200 (Sun, 04 Jun 2006) | 2 lines Whitespace normalization. ........ r46637 | tim.peters | 2006-06-04 05:26:02 +0200 (Sun, 04 Jun 2006) | 16 lines In a PYMALLOC_DEBUG build obmalloc adds extra debugging info to each allocated block. This was using 4 bytes for each such piece of info regardless of platform. This didn't really matter before (proof: no bug reports, and the debug-build obmalloc would have assert-failed if it was ever asked for a chunk of memory >= 2**32 bytes), since container indices were plain ints. But after the Py_ssize_t changes, it's at least theoretically possible to allocate a list or string whose guts exceed 2**32 bytes, and the PYMALLOC_DEBUG routines would fail then (having only 4 bytes to record the originally requested size). Now we use sizeof(size_t) bytes for each of a PYMALLOC_DEBUG build's extra debugging fields. This won't make any difference on 32-bit boxes, but will add 16 bytes to each allocation in a debug build on a 64-bit box. ........ r46638 | tim.peters | 2006-06-04 05:38:04 +0200 (Sun, 04 Jun 2006) | 4 lines _PyObject_DebugMalloc(): The return value should add 2*sizeof(size_t) now, not 8. This probably accounts for current disasters on the 64-bit buildbot slaves. ........ r46639 | neal.norwitz | 2006-06-04 08:19:31 +0200 (Sun, 04 Jun 2006) | 1 line SF #1499797, Fix for memory leak in WindowsError_str ........ r46640 | andrew.macintyre | 2006-06-04 14:31:09 +0200 (Sun, 04 Jun 2006) | 2 lines Patch #1454481: Make thread stack size runtime tunable. ........ r46641 | andrew.macintyre | 2006-06-04 14:59:59 +0200 (Sun, 04 Jun 2006) | 2 lines clean up function declarations to conform to PEP-7 style. ........ r46642 | martin.blais | 2006-06-04 15:49:49 +0200 (Sun, 04 Jun 2006) | 15 lines Fixes in struct and socket from merge reviews. - Following Guido's comments, renamed * pack_to -> pack_into * recv_buf -> recv_into * recvfrom_buf -> recvfrom_into - Made fixes to _struct.c according to Neal Norwitz comments on the checkins list. - Converted some ints into the appropriate -- I hope -- ssize_t and size_t. ........ r46643 | ronald.oussoren | 2006-06-04 16:05:28 +0200 (Sun, 04 Jun 2006) | 3 lines "Import" LDFLAGS in Mac/OSX/Makefile.in to ensure pythonw gets build with the right compiler flags. ........ r46644 | ronald.oussoren | 2006-06-04 16:24:59 +0200 (Sun, 04 Jun 2006) | 2 lines Drop Mac wrappers for the WASTE library. ........ r46645 | tim.peters | 2006-06-04 17:49:07 +0200 (Sun, 04 Jun 2006) | 3 lines s_methods[]: Stop compiler warnings by casting s_unpack_from to PyCFunction. ........ r46646 | george.yoshida | 2006-06-04 19:04:12 +0200 (Sun, 04 Jun 2006) | 2 lines Remove a redundant word ........ r46647 | george.yoshida | 2006-06-04 19:17:25 +0200 (Sun, 04 Jun 2006) | 2 lines Markup fix ........ r46648 | martin.v.loewis | 2006-06-04 21:36:28 +0200 (Sun, 04 Jun 2006) | 2 lines Patch #1359618: Speed-up charmap encoder. ........ r46649 | georg.brandl | 2006-06-04 23:46:16 +0200 (Sun, 04 Jun 2006) | 3 lines Repair refleaks in unicodeobject. ........ r46650 | georg.brandl | 2006-06-04 23:56:52 +0200 (Sun, 04 Jun 2006) | 4 lines Patch #1346214: correctly optimize away "if 0"-style stmts (thanks to Neal for review) ........ r46651 | georg.brandl | 2006-06-05 00:15:37 +0200 (Mon, 05 Jun 2006) | 2 lines Bug #1500293: fix memory leaks in _subprocess module. ........ r46654 | tim.peters | 2006-06-05 01:43:53 +0200 (Mon, 05 Jun 2006) | 2 lines Whitespace normalization. ........ r46655 | tim.peters | 2006-06-05 01:52:47 +0200 (Mon, 05 Jun 2006) | 16 lines Revert revisions: 46640 Patch #1454481: Make thread stack size runtime tunable. 46647 Markup fix The first is causing many buildbots to fail test runs, and there are multiple causes with seemingly no immediate prospects for repairing them. See python-dev discussion. Note that a branch can (and should) be created for resolving these problems, like svn copy svn+ssh://svn.python.org/python/trunk -r46640 svn+ssh://svn.python.org/python/branches/NEW_BRANCH followed by merging rev 46647 to the new branch. ........ r46656 | andrew.kuchling | 2006-06-05 02:08:09 +0200 (Mon, 05 Jun 2006) | 1 line Mention second encoding speedup ........ r46657 | gregory.p.smith | 2006-06-05 02:31:01 +0200 (Mon, 05 Jun 2006) | 7 lines bugfix: when log_archive was called with the DB_ARCH_REMOVE flag present in BerkeleyDB >= 4.2 it tried to construct a list out of an uninitialized char **log_list. feature: export the DB_ARCH_REMOVE flag by name in the module on BerkeleyDB >= 4.2. ........ r46658 | gregory.p.smith | 2006-06-05 02:33:35 +0200 (Mon, 05 Jun 2006) | 5 lines fix a bug in the previous commit. don't leak empty list on error return and fix the additional rare (out of memory only) bug that it was supposed to fix of not freeing log_list when the python allocator failed. ........ r46660 | tim.peters | 2006-06-05 02:55:26 +0200 (Mon, 05 Jun 2006) | 9 lines "Flat is better than nested." Move the long-winded, multiply-nested -R support out of runtest() and into some module-level helper functions. This makes runtest() and the -R code easier to follow. That in turn allowed seeing some opportunities for code simplification, and made it obvious that reglog.txt never got closed. ........ r46661 | hyeshik.chang | 2006-06-05 02:59:54 +0200 (Mon, 05 Jun 2006) | 3 lines Fix a potentially invalid memory access of CJKCodecs' shift-jis decoder. (found by Neal Norwitz) ........ r46663 | gregory.p.smith | 2006-06-05 03:39:52 +0200 (Mon, 05 Jun 2006) | 3 lines * support DBEnv.log_stat() method on BerkeleyDB >= 4.0 [patch #1494885] ........ r46664 | tim.peters | 2006-06-05 03:43:03 +0200 (Mon, 05 Jun 2006) | 3 lines Remove doctest.testmod's deprecated (in 2.4) `isprivate` argument. A lot of hair went into supporting that! ........ r46665 | tim.peters | 2006-06-05 03:47:24 +0200 (Mon, 05 Jun 2006) | 2 lines Whitespace normalization. ........ r46666 | tim.peters | 2006-06-05 03:48:21 +0200 (Mon, 05 Jun 2006) | 2 lines Make doctest news more accurate. ........ r46667 | gregory.p.smith | 2006-06-05 03:56:15 +0200 (Mon, 05 Jun 2006) | 3 lines * support DBEnv.lsn_reset() method on BerkeleyDB >= 4.4 [patch #1494902] ........ r46668 | gregory.p.smith | 2006-06-05 04:02:25 +0200 (Mon, 05 Jun 2006) | 3 lines mention the just committed bsddb changes ........ r46671 | gregory.p.smith | 2006-06-05 19:38:04 +0200 (Mon, 05 Jun 2006) | 3 lines * add support for DBSequence objects [patch #1466734] ........ r46672 | gregory.p.smith | 2006-06-05 20:20:07 +0200 (Mon, 05 Jun 2006) | 3 lines forgot to add this file in previous commit ........ r46673 | tim.peters | 2006-06-05 20:36:12 +0200 (Mon, 05 Jun 2006) | 2 lines Whitespace normalization. ........ r46674 | tim.peters | 2006-06-05 20:36:54 +0200 (Mon, 05 Jun 2006) | 2 lines Add missing svn:eol-style property to text files. ........ r46675 | gregory.p.smith | 2006-06-05 20:48:21 +0200 (Mon, 05 Jun 2006) | 4 lines * fix DBCursor.pget() bug with keyword argument names when no data= is supplied [SF pybsddb bug #1477863] ........ r46676 | andrew.kuchling | 2006-06-05 21:05:32 +0200 (Mon, 05 Jun 2006) | 1 line Remove use of Trove name, which isn't very helpful to users ........ r46677 | andrew.kuchling | 2006-06-05 21:08:25 +0200 (Mon, 05 Jun 2006) | 1 line [Bug #1470026] Include link to list of classifiers ........ r46679 | tim.peters | 2006-06-05 22:48:49 +0200 (Mon, 05 Jun 2006) | 10 lines Access _struct attributes directly instead of mucking with getattr. string_reverse(): Simplify. assertRaises(): Raise TestFailed on failure. test_unpack_from(), test_pack_into(), test_pack_into_fn(): never use `assert` to test for an expected result (it doesn't test anything when Python is run with -O). ........ r46680 | tim.peters | 2006-06-05 22:49:27 +0200 (Mon, 05 Jun 2006) | 2 lines Add missing svn:eol-style property to text files. ........ r46681 | gregory.p.smith | 2006-06-06 01:38:06 +0200 (Tue, 06 Jun 2006) | 3 lines add depends = ['md5.h'] to the _md5 module extension for correctness sake. ........ r46682 | brett.cannon | 2006-06-06 01:51:55 +0200 (Tue, 06 Jun 2006) | 4 lines Add 3 more bytes to a buffer to cover constants in string and null byte on top of 10 possible digits for an int. Closes bug #1501223. ........ r46684 | gregory.p.smith | 2006-06-06 01:59:37 +0200 (Tue, 06 Jun 2006) | 5 lines - bsddb: the __len__ method of a DB object has been fixed to return correct results. It could previously incorrectly return 0 in some cases. Fixes SF bug 1493322 (pybsddb bug 1184012). ........ r46686 | tim.peters | 2006-06-06 02:25:07 +0200 (Tue, 06 Jun 2006) | 7 lines _PySys_Init(): It's rarely a good idea to size a buffer to the exact maximum size someone guesses is needed. In this case, if we're really worried about extreme integers, then "cp%d" can actually need 14 bytes (2 for "cp" + 1 for \0 at the end + 11 for -(2**31-1)). So reserve 128 bytes instead -- nothing is actually saved by making a stack-local buffer tiny. ........ r46687 | neal.norwitz | 2006-06-06 09:22:08 +0200 (Tue, 06 Jun 2006) | 1 line Remove unused variable (and stop compiler warning) ........ r46688 | neal.norwitz | 2006-06-06 09:23:01 +0200 (Tue, 06 Jun 2006) | 1 line Fix a bunch of parameter strings ........ r46689 | thomas.heller | 2006-06-06 13:34:33 +0200 (Tue, 06 Jun 2006) | 6 lines Convert CFieldObject tp_members to tp_getset, since there is no structmember typecode for Py_ssize_t fields. This should fix some of the errors on the PPC64 debian machine (64-bit, big endian). Assigning to readonly fields now raises AttributeError instead of TypeError, so the testcase has to be changed as well. ........ r46690 | thomas.heller | 2006-06-06 13:54:32 +0200 (Tue, 06 Jun 2006) | 1 line Damn - the sentinel was missing. And fix another silly mistake. ........ r46691 | martin.blais | 2006-06-06 14:46:55 +0200 (Tue, 06 Jun 2006) | 13 lines Normalized a few cases of whitespace in function declarations. Found them using:: find . -name '*.py' | while read i ; do grep 'def[^(]*( ' $i /dev/null ; done find . -name '*.py' | while read i ; do grep ' ):' $i /dev/null ; done (I was doing this all over my own code anyway, because I'd been using spaces in all defs, so I thought I'd make a run on the Python code as well. If you need to do such fixes in your own code, you can use xx-rename or parenregu.el within emacs.) ........ r46693 | thomas.heller | 2006-06-06 17:34:18 +0200 (Tue, 06 Jun 2006) | 1 line Specify argtypes for all test functions. Maybe that helps on strange ;-) architectures ........ r46694 | tim.peters | 2006-06-06 17:50:17 +0200 (Tue, 06 Jun 2006) | 5 lines BSequence_set_range(): Rev 46688 ("Fix a bunch of parameter strings") changed this function's signature seemingly by mistake, which is causing buildbots to fail test_bsddb3. Restored the pre-46688 signature. ........ r46695 | tim.peters | 2006-06-06 17:52:35 +0200 (Tue, 06 Jun 2006) | 4 lines On python-dev Thomas Heller said these were committed by mistake in rev 46693, so reverting this part of rev 46693. ........ r46696 | andrew.kuchling | 2006-06-06 19:10:41 +0200 (Tue, 06 Jun 2006) | 1 line Fix comment typo ........ r46697 | brett.cannon | 2006-06-06 20:08:16 +0200 (Tue, 06 Jun 2006) | 2 lines Fix coding style guide bug. ........ r46698 | thomas.heller | 2006-06-06 20:50:46 +0200 (Tue, 06 Jun 2006) | 2 lines Add a hack so that foreign functions returning float now do work on 64-bit big endian platforms. ........ r46699 | thomas.heller | 2006-06-06 21:25:13 +0200 (Tue, 06 Jun 2006) | 3 lines Use the same big-endian hack as in _ctypes/callproc.c for callback functions. This fixes the callback function tests that return float. ........ r46700 | ronald.oussoren | 2006-06-06 21:50:24 +0200 (Tue, 06 Jun 2006) | 5 lines * Ensure that "make altinstall" works when the tree was configured with --enable-framework * Also for --enable-framework: allow users to use --prefix to specify the location of the compatibility symlinks (such as /usr/local/bin/python) ........ r46701 | ronald.oussoren | 2006-06-06 21:56:00 +0200 (Tue, 06 Jun 2006) | 3 lines A quick hack to ensure the right key-bindings for IDLE on osx: install patched configuration files during a framework install. ........ r46702 | tim.peters | 2006-06-07 03:04:59 +0200 (Wed, 07 Jun 2006) | 4 lines dash_R_cleanup(): Clear filecmp._cache. This accounts for different results across -R runs (at least on Windows) of test_filecmp. ........ r46705 | tim.peters | 2006-06-07 08:57:51 +0200 (Wed, 07 Jun 2006) | 17 lines SF patch 1501987: Remove randomness from test_exceptions, from ?iga Seilnacht (sorry about the name, but Firefox on my box can't display the first character of the name -- the SF "Unix name" is zseil). This appears to cure the oddball intermittent leaks across runs when running test_exceptions under -R. I'm not sure why, but I'm too sleepy to care ;-) The thrust of the SF patch was to remove randomness in the pickle protocol used. I changed the patch to use range(pickle.HIGHEST_PROTOCOL + 1), to try both pickle and cPickle, and randomly mucked with other test lines to put statements on their own lines. Not a bugfix candidate (this is fiddling new-in-2.5 code). ........ r46706 | andrew.kuchling | 2006-06-07 15:55:33 +0200 (Wed, 07 Jun 2006) | 1 line Add an SQLite introduction, taken from the 'What's New' text ........ r46708 | andrew.kuchling | 2006-06-07 19:02:52 +0200 (Wed, 07 Jun 2006) | 1 line Mention other placeholders ........ r46709 | andrew.kuchling | 2006-06-07 19:03:46 +0200 (Wed, 07 Jun 2006) | 1 line Add an item; also, escape % ........ r46710 | andrew.kuchling | 2006-06-07 19:04:01 +0200 (Wed, 07 Jun 2006) | 1 line Mention other placeholders ........ r46716 | ronald.oussoren | 2006-06-07 20:57:44 +0200 (Wed, 07 Jun 2006) | 2 lines Move Mac/OSX/Tools one level up ........ r46717 | ronald.oussoren | 2006-06-07 20:58:01 +0200 (Wed, 07 Jun 2006) | 2 lines Move Mac/OSX/PythonLauncher one level up ........ r46718 | ronald.oussoren | 2006-06-07 20:58:42 +0200 (Wed, 07 Jun 2006) | 2 lines mv Mac/OSX/BuildScript one level up ........ r46719 | ronald.oussoren | 2006-06-07 21:02:03 +0200 (Wed, 07 Jun 2006) | 2 lines Move Mac/OSX/* one level up ........ r46720 | ronald.oussoren | 2006-06-07 21:06:01 +0200 (Wed, 07 Jun 2006) | 2 lines And the last bit: move IDLE one level up and adjust makefiles ........ r46723 | ronald.oussoren | 2006-06-07 21:38:53 +0200 (Wed, 07 Jun 2006) | 4 lines - Patch the correct version of python in the Info.plists at build time, instead of relying on a maintainer to update them before releases. - Remove the now empty Mac/OSX directory ........ r46727 | ronald.oussoren | 2006-06-07 22:18:44 +0200 (Wed, 07 Jun 2006) | 7 lines * If BuildApplet.py is used as an applet it starts with a version of sys.exutable that isn't usuable on an #!-line. That results in generated applets that don't actually work. Work around this problem by resetting sys.executable. * argvemulator.py didn't work on intel macs. This patch fixes this (bug #1491468) ........ r46728 | tim.peters | 2006-06-07 22:40:06 +0200 (Wed, 07 Jun 2006) | 2 lines Whitespace normalization. ........ r46729 | tim.peters | 2006-06-07 22:40:54 +0200 (Wed, 07 Jun 2006) | 2 lines Add missing svn:eol-style property to text files. ........ r46730 | thomas.heller | 2006-06-07 22:43:06 +0200 (Wed, 07 Jun 2006) | 7 lines Fix for foreign functions returning small structures on 64-bit big endian machines. Should fix the remaininf failure in the PPC64 Debian buildbot. Thanks to Matthias Klose for providing access to a machine to debug and test this. ........ r46731 | brett.cannon | 2006-06-07 23:48:17 +0200 (Wed, 07 Jun 2006) | 2 lines Clarify documentation for bf_getcharbuffer. ........ r46735 | neal.norwitz | 2006-06-08 07:12:45 +0200 (Thu, 08 Jun 2006) | 1 line Fix a refleak in recvfrom_into ........ r46736 | gregory.p.smith | 2006-06-08 07:17:08 +0200 (Thu, 08 Jun 2006) | 9 lines - bsddb: the bsddb.dbtables Modify method now raises the proper error and aborts the db transaction safely when a modifier callback fails. Fixes SF python patch/bug #1408584. Also cleans up the bsddb.dbtables docstrings since thats the only documentation that exists for that unadvertised module. (people really should really just use sqlite3) ........ r46737 | gregory.p.smith | 2006-06-08 07:38:11 +0200 (Thu, 08 Jun 2006) | 4 lines * Turn the deadlock situation described in SF bug #775414 into a DBDeadLockError exception. * add the test case for my previous dbtables commit. ........ r46738 | gregory.p.smith | 2006-06-08 07:39:54 +0200 (Thu, 08 Jun 2006) | 2 lines pasted set_lk_detect line in wrong spot in previous commit. fixed. passes tests this time. ........ r46739 | armin.rigo | 2006-06-08 12:56:24 +0200 (Thu, 08 Jun 2006) | 6 lines (arre, arigo) SF bug #1350060 Give a consistent behavior for comparison and hashing of method objects (both user- and built-in methods). Now compares the 'self' recursively. The hash was already asking for the hash of 'self'. ........ r46740 | andrew.kuchling | 2006-06-08 13:56:44 +0200 (Thu, 08 Jun 2006) | 1 line Typo fix ........ r46741 | georg.brandl | 2006-06-08 14:45:01 +0200 (Thu, 08 Jun 2006) | 2 lines Bug #1502750: Fix getargs "i" format to use LONG_MIN and LONG_MAX for bounds checking. ........ r46743 | georg.brandl | 2006-06-08 14:54:13 +0200 (Thu, 08 Jun 2006) | 2 lines Bug #1502728: Correctly link against librt library on HP-UX. ........ r46745 | georg.brandl | 2006-06-08 14:55:47 +0200 (Thu, 08 Jun 2006) | 3 lines Add news for recent bugfix. ........ r46746 | georg.brandl | 2006-06-08 15:31:07 +0200 (Thu, 08 Jun 2006) | 4 lines Argh. "integer" is a very confusing word ;) Actually, checking for INT_MAX and INT_MIN is correct since the format code explicitly handles a C "int". ........ r46748 | nick.coghlan | 2006-06-08 15:54:49 +0200 (Thu, 08 Jun 2006) | 1 line Add functools.update_wrapper() and functools.wraps() as described in PEP 356 ........ r46751 | georg.brandl | 2006-06-08 16:50:21 +0200 (Thu, 08 Jun 2006) | 4 lines Bug #1502805: don't alias file.__exit__ to file.close since the latter can return something that's true. ........ r46752 | georg.brandl | 2006-06-08 16:50:53 +0200 (Thu, 08 Jun 2006) | 3 lines Convert test_file to unittest. ........
20 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
Merged revisions 70578,70599,70641-70642,70650,70660-70661,70674,70691,70697-70698,70700,70704 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r70578 | benjamin.peterson | 2009-03-23 22:24:56 -0500 (Mon, 23 Mar 2009) | 1 line this is better written using assertRaises ........ r70599 | benjamin.peterson | 2009-03-25 16:42:51 -0500 (Wed, 25 Mar 2009) | 1 line this can be slightly less ugly ........ r70641 | guilherme.polo | 2009-03-27 16:43:08 -0500 (Fri, 27 Mar 2009) | 3 lines Adjusted _tkinter to compile without warnings when WITH_THREAD is not defined (part of issue #5035) ........ r70642 | georg.brandl | 2009-03-27 19:48:48 -0500 (Fri, 27 Mar 2009) | 1 line Fix typo. ........ r70650 | benjamin.peterson | 2009-03-28 14:16:10 -0500 (Sat, 28 Mar 2009) | 1 line give os.symlink and os.link() better parameter names #5564 ........ r70660 | georg.brandl | 2009-03-28 14:52:58 -0500 (Sat, 28 Mar 2009) | 1 line Switch to fixed Sphinx version. ........ r70661 | georg.brandl | 2009-03-28 14:57:36 -0500 (Sat, 28 Mar 2009) | 2 lines Add section numbering to some of the larger subdocuments. ........ r70674 | guilherme.polo | 2009-03-29 05:19:05 -0500 (Sun, 29 Mar 2009) | 1 line Typo fix. ........ r70691 | raymond.hettinger | 2009-03-29 13:51:11 -0500 (Sun, 29 Mar 2009) | 1 line Make life easier for non-CPython implementations. ........ r70697 | benjamin.peterson | 2009-03-29 16:22:35 -0500 (Sun, 29 Mar 2009) | 1 line this has been fixed since 2.6 (I love removing these) ........ r70698 | benjamin.peterson | 2009-03-29 16:31:05 -0500 (Sun, 29 Mar 2009) | 1 line thanks to guido's bytecode verifier, this is fixed ........ r70700 | benjamin.peterson | 2009-03-29 16:50:14 -0500 (Sun, 29 Mar 2009) | 1 line use the awesome new status iterator ........ r70704 | benjamin.peterson | 2009-03-29 21:49:32 -0500 (Sun, 29 Mar 2009) | 1 line there's actually three methods here #5600 ........
17 years ago
Merged revisions 70578,70599,70641-70642,70650,70660-70661,70674,70691,70697-70698,70700,70704 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r70578 | benjamin.peterson | 2009-03-23 22:24:56 -0500 (Mon, 23 Mar 2009) | 1 line this is better written using assertRaises ........ r70599 | benjamin.peterson | 2009-03-25 16:42:51 -0500 (Wed, 25 Mar 2009) | 1 line this can be slightly less ugly ........ r70641 | guilherme.polo | 2009-03-27 16:43:08 -0500 (Fri, 27 Mar 2009) | 3 lines Adjusted _tkinter to compile without warnings when WITH_THREAD is not defined (part of issue #5035) ........ r70642 | georg.brandl | 2009-03-27 19:48:48 -0500 (Fri, 27 Mar 2009) | 1 line Fix typo. ........ r70650 | benjamin.peterson | 2009-03-28 14:16:10 -0500 (Sat, 28 Mar 2009) | 1 line give os.symlink and os.link() better parameter names #5564 ........ r70660 | georg.brandl | 2009-03-28 14:52:58 -0500 (Sat, 28 Mar 2009) | 1 line Switch to fixed Sphinx version. ........ r70661 | georg.brandl | 2009-03-28 14:57:36 -0500 (Sat, 28 Mar 2009) | 2 lines Add section numbering to some of the larger subdocuments. ........ r70674 | guilherme.polo | 2009-03-29 05:19:05 -0500 (Sun, 29 Mar 2009) | 1 line Typo fix. ........ r70691 | raymond.hettinger | 2009-03-29 13:51:11 -0500 (Sun, 29 Mar 2009) | 1 line Make life easier for non-CPython implementations. ........ r70697 | benjamin.peterson | 2009-03-29 16:22:35 -0500 (Sun, 29 Mar 2009) | 1 line this has been fixed since 2.6 (I love removing these) ........ r70698 | benjamin.peterson | 2009-03-29 16:31:05 -0500 (Sun, 29 Mar 2009) | 1 line thanks to guido's bytecode verifier, this is fixed ........ r70700 | benjamin.peterson | 2009-03-29 16:50:14 -0500 (Sun, 29 Mar 2009) | 1 line use the awesome new status iterator ........ r70704 | benjamin.peterson | 2009-03-29 21:49:32 -0500 (Sun, 29 Mar 2009) | 1 line there's actually three methods here #5600 ........
17 years ago
32 years ago
32 years ago
32 years ago
Merged revisions 70578,70599,70641-70642,70650,70660-70661,70674,70691,70697-70698,70700,70704 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r70578 | benjamin.peterson | 2009-03-23 22:24:56 -0500 (Mon, 23 Mar 2009) | 1 line this is better written using assertRaises ........ r70599 | benjamin.peterson | 2009-03-25 16:42:51 -0500 (Wed, 25 Mar 2009) | 1 line this can be slightly less ugly ........ r70641 | guilherme.polo | 2009-03-27 16:43:08 -0500 (Fri, 27 Mar 2009) | 3 lines Adjusted _tkinter to compile without warnings when WITH_THREAD is not defined (part of issue #5035) ........ r70642 | georg.brandl | 2009-03-27 19:48:48 -0500 (Fri, 27 Mar 2009) | 1 line Fix typo. ........ r70650 | benjamin.peterson | 2009-03-28 14:16:10 -0500 (Sat, 28 Mar 2009) | 1 line give os.symlink and os.link() better parameter names #5564 ........ r70660 | georg.brandl | 2009-03-28 14:52:58 -0500 (Sat, 28 Mar 2009) | 1 line Switch to fixed Sphinx version. ........ r70661 | georg.brandl | 2009-03-28 14:57:36 -0500 (Sat, 28 Mar 2009) | 2 lines Add section numbering to some of the larger subdocuments. ........ r70674 | guilherme.polo | 2009-03-29 05:19:05 -0500 (Sun, 29 Mar 2009) | 1 line Typo fix. ........ r70691 | raymond.hettinger | 2009-03-29 13:51:11 -0500 (Sun, 29 Mar 2009) | 1 line Make life easier for non-CPython implementations. ........ r70697 | benjamin.peterson | 2009-03-29 16:22:35 -0500 (Sun, 29 Mar 2009) | 1 line this has been fixed since 2.6 (I love removing these) ........ r70698 | benjamin.peterson | 2009-03-29 16:31:05 -0500 (Sun, 29 Mar 2009) | 1 line thanks to guido's bytecode verifier, this is fixed ........ r70700 | benjamin.peterson | 2009-03-29 16:50:14 -0500 (Sun, 29 Mar 2009) | 1 line use the awesome new status iterator ........ r70704 | benjamin.peterson | 2009-03-29 21:49:32 -0500 (Sun, 29 Mar 2009) | 1 line there's actually three methods here #5600 ........
17 years ago
Merged revisions 70578,70599,70641-70642,70650,70660-70661,70674,70691,70697-70698,70700,70704 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r70578 | benjamin.peterson | 2009-03-23 22:24:56 -0500 (Mon, 23 Mar 2009) | 1 line this is better written using assertRaises ........ r70599 | benjamin.peterson | 2009-03-25 16:42:51 -0500 (Wed, 25 Mar 2009) | 1 line this can be slightly less ugly ........ r70641 | guilherme.polo | 2009-03-27 16:43:08 -0500 (Fri, 27 Mar 2009) | 3 lines Adjusted _tkinter to compile without warnings when WITH_THREAD is not defined (part of issue #5035) ........ r70642 | georg.brandl | 2009-03-27 19:48:48 -0500 (Fri, 27 Mar 2009) | 1 line Fix typo. ........ r70650 | benjamin.peterson | 2009-03-28 14:16:10 -0500 (Sat, 28 Mar 2009) | 1 line give os.symlink and os.link() better parameter names #5564 ........ r70660 | georg.brandl | 2009-03-28 14:52:58 -0500 (Sat, 28 Mar 2009) | 1 line Switch to fixed Sphinx version. ........ r70661 | georg.brandl | 2009-03-28 14:57:36 -0500 (Sat, 28 Mar 2009) | 2 lines Add section numbering to some of the larger subdocuments. ........ r70674 | guilherme.polo | 2009-03-29 05:19:05 -0500 (Sun, 29 Mar 2009) | 1 line Typo fix. ........ r70691 | raymond.hettinger | 2009-03-29 13:51:11 -0500 (Sun, 29 Mar 2009) | 1 line Make life easier for non-CPython implementations. ........ r70697 | benjamin.peterson | 2009-03-29 16:22:35 -0500 (Sun, 29 Mar 2009) | 1 line this has been fixed since 2.6 (I love removing these) ........ r70698 | benjamin.peterson | 2009-03-29 16:31:05 -0500 (Sun, 29 Mar 2009) | 1 line thanks to guido's bytecode verifier, this is fixed ........ r70700 | benjamin.peterson | 2009-03-29 16:50:14 -0500 (Sun, 29 Mar 2009) | 1 line use the awesome new status iterator ........ r70704 | benjamin.peterson | 2009-03-29 21:49:32 -0500 (Sun, 29 Mar 2009) | 1 line there's actually three methods here #5600 ........
17 years ago
32 years ago
32 years ago
32 years ago
Merged revisions 70578,70599,70641-70642,70650,70660-70661,70674,70691,70697-70698,70700,70704 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r70578 | benjamin.peterson | 2009-03-23 22:24:56 -0500 (Mon, 23 Mar 2009) | 1 line this is better written using assertRaises ........ r70599 | benjamin.peterson | 2009-03-25 16:42:51 -0500 (Wed, 25 Mar 2009) | 1 line this can be slightly less ugly ........ r70641 | guilherme.polo | 2009-03-27 16:43:08 -0500 (Fri, 27 Mar 2009) | 3 lines Adjusted _tkinter to compile without warnings when WITH_THREAD is not defined (part of issue #5035) ........ r70642 | georg.brandl | 2009-03-27 19:48:48 -0500 (Fri, 27 Mar 2009) | 1 line Fix typo. ........ r70650 | benjamin.peterson | 2009-03-28 14:16:10 -0500 (Sat, 28 Mar 2009) | 1 line give os.symlink and os.link() better parameter names #5564 ........ r70660 | georg.brandl | 2009-03-28 14:52:58 -0500 (Sat, 28 Mar 2009) | 1 line Switch to fixed Sphinx version. ........ r70661 | georg.brandl | 2009-03-28 14:57:36 -0500 (Sat, 28 Mar 2009) | 2 lines Add section numbering to some of the larger subdocuments. ........ r70674 | guilherme.polo | 2009-03-29 05:19:05 -0500 (Sun, 29 Mar 2009) | 1 line Typo fix. ........ r70691 | raymond.hettinger | 2009-03-29 13:51:11 -0500 (Sun, 29 Mar 2009) | 1 line Make life easier for non-CPython implementations. ........ r70697 | benjamin.peterson | 2009-03-29 16:22:35 -0500 (Sun, 29 Mar 2009) | 1 line this has been fixed since 2.6 (I love removing these) ........ r70698 | benjamin.peterson | 2009-03-29 16:31:05 -0500 (Sun, 29 Mar 2009) | 1 line thanks to guido's bytecode verifier, this is fixed ........ r70700 | benjamin.peterson | 2009-03-29 16:50:14 -0500 (Sun, 29 Mar 2009) | 1 line use the awesome new status iterator ........ r70704 | benjamin.peterson | 2009-03-29 21:49:32 -0500 (Sun, 29 Mar 2009) | 1 line there's actually three methods here #5600 ........
17 years ago
Merged revisions 70578,70599,70641-70642,70650,70660-70661,70674,70691,70697-70698,70700,70704 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r70578 | benjamin.peterson | 2009-03-23 22:24:56 -0500 (Mon, 23 Mar 2009) | 1 line this is better written using assertRaises ........ r70599 | benjamin.peterson | 2009-03-25 16:42:51 -0500 (Wed, 25 Mar 2009) | 1 line this can be slightly less ugly ........ r70641 | guilherme.polo | 2009-03-27 16:43:08 -0500 (Fri, 27 Mar 2009) | 3 lines Adjusted _tkinter to compile without warnings when WITH_THREAD is not defined (part of issue #5035) ........ r70642 | georg.brandl | 2009-03-27 19:48:48 -0500 (Fri, 27 Mar 2009) | 1 line Fix typo. ........ r70650 | benjamin.peterson | 2009-03-28 14:16:10 -0500 (Sat, 28 Mar 2009) | 1 line give os.symlink and os.link() better parameter names #5564 ........ r70660 | georg.brandl | 2009-03-28 14:52:58 -0500 (Sat, 28 Mar 2009) | 1 line Switch to fixed Sphinx version. ........ r70661 | georg.brandl | 2009-03-28 14:57:36 -0500 (Sat, 28 Mar 2009) | 2 lines Add section numbering to some of the larger subdocuments. ........ r70674 | guilherme.polo | 2009-03-29 05:19:05 -0500 (Sun, 29 Mar 2009) | 1 line Typo fix. ........ r70691 | raymond.hettinger | 2009-03-29 13:51:11 -0500 (Sun, 29 Mar 2009) | 1 line Make life easier for non-CPython implementations. ........ r70697 | benjamin.peterson | 2009-03-29 16:22:35 -0500 (Sun, 29 Mar 2009) | 1 line this has been fixed since 2.6 (I love removing these) ........ r70698 | benjamin.peterson | 2009-03-29 16:31:05 -0500 (Sun, 29 Mar 2009) | 1 line thanks to guido's bytecode verifier, this is fixed ........ r70700 | benjamin.peterson | 2009-03-29 16:50:14 -0500 (Sun, 29 Mar 2009) | 1 line use the awesome new status iterator ........ r70704 | benjamin.peterson | 2009-03-29 21:49:32 -0500 (Sun, 29 Mar 2009) | 1 line there's actually three methods here #5600 ........
17 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
  1. /***********************************************************
  2. Copyright (C) 1994 Steen Lumholt.
  3. All Rights Reserved
  4. ******************************************************************/
  5. /* _tkinter.c -- Interface to libtk.a and libtcl.a. */
  6. /* TCL/TK VERSION INFO:
  7. Only Tcl/Tk 8.4 and later are supported. Older versions are not
  8. supported. Use Python 3.4 or older if you cannot upgrade your
  9. Tcl/Tk libraries.
  10. */
  11. /* XXX Further speed-up ideas, involving Tcl 8.0 features:
  12. - Register a new Tcl type, "Python callable", which can be called more
  13. efficiently and passed to Tcl_EvalObj() directly (if this is possible).
  14. */
  15. #define PY_SSIZE_T_CLEAN
  16. #include "Python.h"
  17. #include <ctype.h>
  18. #ifdef WITH_THREAD
  19. #include "pythread.h"
  20. #endif
  21. #ifdef MS_WINDOWS
  22. #include <windows.h>
  23. #endif
  24. #define CHECK_SIZE(size, elemsize) \
  25. ((size_t)(size) <= Py_MIN((size_t)INT_MAX, UINT_MAX / (size_t)(elemsize)))
  26. /* If Tcl is compiled for threads, we must also define TCL_THREAD. We define
  27. it always; if Tcl is not threaded, the thread functions in
  28. Tcl are empty. */
  29. #define TCL_THREADS
  30. #ifdef TK_FRAMEWORK
  31. #include <Tcl/tcl.h>
  32. #include <Tk/tk.h>
  33. #else
  34. #include <tcl.h>
  35. #include <tk.h>
  36. #endif
  37. #include "tkinter.h"
  38. #if TK_HEX_VERSION < 0x08040200
  39. #error "Tk older than 8.4 not supported"
  40. #endif
  41. #if TK_HEX_VERSION >= 0x08050208 && TK_HEX_VERSION < 0x08060000 || \
  42. TK_HEX_VERSION >= 0x08060200
  43. #define HAVE_LIBTOMMAMTH
  44. #include <tclTomMath.h>
  45. #endif
  46. #if !(defined(MS_WINDOWS) || defined(__CYGWIN__))
  47. #define HAVE_CREATEFILEHANDLER
  48. #endif
  49. #ifdef HAVE_CREATEFILEHANDLER
  50. /* This bit is to ensure that TCL_UNIX_FD is defined and doesn't interfere
  51. with the proper calculation of FHANDLETYPE == TCL_UNIX_FD below. */
  52. #ifndef TCL_UNIX_FD
  53. # ifdef TCL_WIN_SOCKET
  54. # define TCL_UNIX_FD (! TCL_WIN_SOCKET)
  55. # else
  56. # define TCL_UNIX_FD 1
  57. # endif
  58. #endif
  59. /* Tcl_CreateFileHandler() changed several times; these macros deal with the
  60. messiness. In Tcl 8.0 and later, it is not available on Windows (and on
  61. Unix, only because Jack added it back); when available on Windows, it only
  62. applies to sockets. */
  63. #ifdef MS_WINDOWS
  64. #define FHANDLETYPE TCL_WIN_SOCKET
  65. #else
  66. #define FHANDLETYPE TCL_UNIX_FD
  67. #endif
  68. /* If Tcl can wait for a Unix file descriptor, define the EventHook() routine
  69. which uses this to handle Tcl events while the user is typing commands. */
  70. #if FHANDLETYPE == TCL_UNIX_FD
  71. #define WAIT_FOR_STDIN
  72. #endif
  73. #endif /* HAVE_CREATEFILEHANDLER */
  74. #ifdef MS_WINDOWS
  75. #include <conio.h>
  76. #define WAIT_FOR_STDIN
  77. static PyObject *
  78. _get_tcl_lib_path()
  79. {
  80. static PyObject *tcl_library_path = NULL;
  81. static int already_checked = 0;
  82. if (already_checked == 0) {
  83. PyObject *prefix;
  84. struct stat stat_buf;
  85. int stat_return_value;
  86. prefix = PyUnicode_FromWideChar(Py_GetPrefix(), -1);
  87. if (prefix == NULL) {
  88. return NULL;
  89. }
  90. /* Check expected location for an installed Python first */
  91. tcl_library_path = PyUnicode_FromString("\\tcl\\tcl" TCL_VERSION);
  92. if (tcl_library_path == NULL) {
  93. return NULL;
  94. }
  95. tcl_library_path = PyUnicode_Concat(prefix, tcl_library_path);
  96. if (tcl_library_path == NULL) {
  97. return NULL;
  98. }
  99. stat_return_value = _Py_stat(tcl_library_path, &stat_buf);
  100. if (stat_return_value == -2) {
  101. return NULL;
  102. }
  103. if (stat_return_value == -1) {
  104. /* install location doesn't exist, reset errno and see if
  105. we're a repository build */
  106. errno = 0;
  107. #ifdef Py_TCLTK_DIR
  108. tcl_library_path = PyUnicode_FromString(
  109. Py_TCLTK_DIR "\\lib\\tcl" TCL_VERSION);
  110. if (tcl_library_path == NULL) {
  111. return NULL;
  112. }
  113. stat_return_value = _Py_stat(tcl_library_path, &stat_buf);
  114. if (stat_return_value == -2) {
  115. return NULL;
  116. }
  117. if (stat_return_value == -1) {
  118. /* tcltkDir for a repository build doesn't exist either,
  119. reset errno and leave Tcl to its own devices */
  120. errno = 0;
  121. tcl_library_path = NULL;
  122. }
  123. #else
  124. tcl_library_path = NULL;
  125. #endif
  126. }
  127. already_checked = 1;
  128. }
  129. return tcl_library_path;
  130. }
  131. #endif /* MS_WINDOWS */
  132. #ifdef WITH_THREAD
  133. /* The threading situation is complicated. Tcl is not thread-safe, except
  134. when configured with --enable-threads.
  135. So we need to use a lock around all uses of Tcl. Previously, the
  136. Python interpreter lock was used for this. However, this causes
  137. problems when other Python threads need to run while Tcl is blocked
  138. waiting for events.
  139. To solve this problem, a separate lock for Tcl is introduced.
  140. Holding it is incompatible with holding Python's interpreter lock.
  141. The following four macros manipulate both locks together.
  142. ENTER_TCL and LEAVE_TCL are brackets, just like
  143. Py_BEGIN_ALLOW_THREADS and Py_END_ALLOW_THREADS. They should be
  144. used whenever a call into Tcl is made that could call an event
  145. handler, or otherwise affect the state of a Tcl interpreter. These
  146. assume that the surrounding code has the Python interpreter lock;
  147. inside the brackets, the Python interpreter lock has been released
  148. and the lock for Tcl has been acquired.
  149. Sometimes, it is necessary to have both the Python lock and the Tcl
  150. lock. (For example, when transferring data from the Tcl
  151. interpreter result to a Python string object.) This can be done by
  152. using different macros to close the ENTER_TCL block: ENTER_OVERLAP
  153. reacquires the Python lock (and restores the thread state) but
  154. doesn't release the Tcl lock; LEAVE_OVERLAP_TCL releases the Tcl
  155. lock.
  156. By contrast, ENTER_PYTHON and LEAVE_PYTHON are used in Tcl event
  157. handlers when the handler needs to use Python. Such event handlers
  158. are entered while the lock for Tcl is held; the event handler
  159. presumably needs to use Python. ENTER_PYTHON releases the lock for
  160. Tcl and acquires the Python interpreter lock, restoring the
  161. appropriate thread state, and LEAVE_PYTHON releases the Python
  162. interpreter lock and re-acquires the lock for Tcl. It is okay for
  163. ENTER_TCL/LEAVE_TCL pairs to be contained inside the code between
  164. ENTER_PYTHON and LEAVE_PYTHON.
  165. These locks expand to several statements and brackets; they should
  166. not be used in branches of if statements and the like.
  167. If Tcl is threaded, this approach won't work anymore. The Tcl
  168. interpreter is only valid in the thread that created it, and all Tk
  169. activity must happen in this thread, also. That means that the
  170. mainloop must be invoked in the thread that created the
  171. interpreter. Invoking commands from other threads is possible;
  172. _tkinter will queue an event for the interpreter thread, which will
  173. then execute the command and pass back the result. If the main
  174. thread is not in the mainloop, and invoking commands causes an
  175. exception; if the main loop is running but not processing events,
  176. the command invocation will block.
  177. In addition, for a threaded Tcl, a single global tcl_tstate won't
  178. be sufficient anymore, since multiple Tcl interpreters may
  179. simultaneously dispatch in different threads. So we use the Tcl TLS
  180. API.
  181. */
  182. static PyThread_type_lock tcl_lock = 0;
  183. #ifdef TCL_THREADS
  184. static Tcl_ThreadDataKey state_key;
  185. typedef PyThreadState *ThreadSpecificData;
  186. #define tcl_tstate \
  187. (*(PyThreadState**)Tcl_GetThreadData(&state_key, sizeof(PyThreadState*)))
  188. #else
  189. static PyThreadState *tcl_tstate = NULL;
  190. #endif
  191. #define ENTER_TCL \
  192. { PyThreadState *tstate = PyThreadState_Get(); Py_BEGIN_ALLOW_THREADS \
  193. if(tcl_lock)PyThread_acquire_lock(tcl_lock, 1); tcl_tstate = tstate;
  194. #define LEAVE_TCL \
  195. tcl_tstate = NULL; \
  196. if(tcl_lock)PyThread_release_lock(tcl_lock); Py_END_ALLOW_THREADS}
  197. #define ENTER_OVERLAP \
  198. Py_END_ALLOW_THREADS
  199. #define LEAVE_OVERLAP_TCL \
  200. tcl_tstate = NULL; if(tcl_lock)PyThread_release_lock(tcl_lock); }
  201. #define ENTER_PYTHON \
  202. { PyThreadState *tstate = tcl_tstate; tcl_tstate = NULL; \
  203. if(tcl_lock) \
  204. PyThread_release_lock(tcl_lock); PyEval_RestoreThread((tstate)); }
  205. #define LEAVE_PYTHON \
  206. { PyThreadState *tstate = PyEval_SaveThread(); \
  207. if(tcl_lock)PyThread_acquire_lock(tcl_lock, 1); tcl_tstate = tstate; }
  208. #define CHECK_TCL_APPARTMENT \
  209. if (((TkappObject *)self)->threaded && \
  210. ((TkappObject *)self)->thread_id != Tcl_GetCurrentThread()) { \
  211. PyErr_SetString(PyExc_RuntimeError, \
  212. "Calling Tcl from different appartment"); \
  213. return 0; \
  214. }
  215. #else
  216. #define ENTER_TCL
  217. #define LEAVE_TCL
  218. #define ENTER_OVERLAP
  219. #define LEAVE_OVERLAP_TCL
  220. #define ENTER_PYTHON
  221. #define LEAVE_PYTHON
  222. #define CHECK_TCL_APPARTMENT
  223. #endif
  224. #ifndef FREECAST
  225. #define FREECAST (char *)
  226. #endif
  227. /**** Tkapp Object Declaration ****/
  228. static PyObject *Tkapp_Type;
  229. typedef struct {
  230. PyObject_HEAD
  231. Tcl_Interp *interp;
  232. int wantobjects;
  233. int threaded; /* True if tcl_platform[threaded] */
  234. Tcl_ThreadId thread_id;
  235. int dispatching;
  236. /* We cannot include tclInt.h, as this is internal.
  237. So we cache interesting types here. */
  238. const Tcl_ObjType *OldBooleanType;
  239. const Tcl_ObjType *BooleanType;
  240. const Tcl_ObjType *ByteArrayType;
  241. const Tcl_ObjType *DoubleType;
  242. const Tcl_ObjType *IntType;
  243. const Tcl_ObjType *WideIntType;
  244. const Tcl_ObjType *BignumType;
  245. const Tcl_ObjType *ListType;
  246. const Tcl_ObjType *ProcBodyType;
  247. const Tcl_ObjType *StringType;
  248. } TkappObject;
  249. #define Tkapp_Interp(v) (((TkappObject *) (v))->interp)
  250. #define Tkapp_Result(v) Tcl_GetStringResult(Tkapp_Interp(v))
  251. #define DEBUG_REFCNT(v) (printf("DEBUG: id=%p, refcnt=%i\n", \
  252. (void *) v, Py_REFCNT(v)))
  253. /**** Error Handling ****/
  254. static PyObject *Tkinter_TclError;
  255. static int quitMainLoop = 0;
  256. static int errorInCmd = 0;
  257. static PyObject *excInCmd;
  258. static PyObject *valInCmd;
  259. static PyObject *trbInCmd;
  260. #ifdef TKINTER_PROTECT_LOADTK
  261. static int tk_load_failed = 0;
  262. #endif
  263. static PyObject *
  264. Tkinter_Error(PyObject *v)
  265. {
  266. PyErr_SetString(Tkinter_TclError, Tkapp_Result(v));
  267. return NULL;
  268. }
  269. /**** Utils ****/
  270. static int Tkinter_busywaitinterval = 20;
  271. #ifdef WITH_THREAD
  272. #ifndef MS_WINDOWS
  273. /* Millisecond sleep() for Unix platforms. */
  274. static void
  275. Sleep(int milli)
  276. {
  277. /* XXX Too bad if you don't have select(). */
  278. struct timeval t;
  279. t.tv_sec = milli/1000;
  280. t.tv_usec = (milli%1000) * 1000;
  281. select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t);
  282. }
  283. #endif /* MS_WINDOWS */
  284. /* Wait up to 1s for the mainloop to come up. */
  285. static int
  286. WaitForMainloop(TkappObject* self)
  287. {
  288. int i;
  289. for (i = 0; i < 10; i++) {
  290. if (self->dispatching)
  291. return 1;
  292. Py_BEGIN_ALLOW_THREADS
  293. Sleep(100);
  294. Py_END_ALLOW_THREADS
  295. }
  296. if (self->dispatching)
  297. return 1;
  298. PyErr_SetString(PyExc_RuntimeError, "main thread is not in main loop");
  299. return 0;
  300. }
  301. #endif /* WITH_THREAD */
  302. #define ARGSZ 64
  303. static PyObject *
  304. unicodeFromTclStringAndSize(const char *s, Py_ssize_t size)
  305. {
  306. PyObject *r = PyUnicode_DecodeUTF8(s, size, NULL);
  307. if (!r && PyErr_ExceptionMatches(PyExc_UnicodeDecodeError)) {
  308. /* Tcl encodes null character as \xc0\x80 */
  309. if (memchr(s, '\xc0', size)) {
  310. char *buf, *q;
  311. const char *e = s + size;
  312. PyErr_Clear();
  313. q = buf = (char *)PyMem_Malloc(size);
  314. if (buf == NULL) {
  315. PyErr_NoMemory();
  316. return NULL;
  317. }
  318. while (s != e) {
  319. if (s + 1 != e && s[0] == '\xc0' && s[1] == '\x80') {
  320. *q++ = '\0';
  321. s += 2;
  322. }
  323. else
  324. *q++ = *s++;
  325. }
  326. s = buf;
  327. size = q - s;
  328. r = PyUnicode_DecodeUTF8(s, size, NULL);
  329. PyMem_Free(buf);
  330. }
  331. }
  332. return r;
  333. }
  334. static PyObject *
  335. unicodeFromTclString(const char *s)
  336. {
  337. return unicodeFromTclStringAndSize(s, strlen(s));
  338. }
  339. static PyObject *
  340. unicodeFromTclObj(Tcl_Obj *value)
  341. {
  342. int len;
  343. char *s = Tcl_GetStringFromObj(value, &len);
  344. return unicodeFromTclStringAndSize(s, len);
  345. }
  346. static PyObject *
  347. Split(const char *list)
  348. {
  349. int argc;
  350. const char **argv;
  351. PyObject *v;
  352. if (list == NULL) {
  353. Py_RETURN_NONE;
  354. }
  355. if (Tcl_SplitList((Tcl_Interp *)NULL, list, &argc, &argv) != TCL_OK) {
  356. /* Not a list.
  357. * Could be a quoted string containing funnies, e.g. {"}.
  358. * Return the string itself.
  359. */
  360. return unicodeFromTclString(list);
  361. }
  362. if (argc == 0)
  363. v = PyUnicode_FromString("");
  364. else if (argc == 1)
  365. v = unicodeFromTclString(argv[0]);
  366. else if ((v = PyTuple_New(argc)) != NULL) {
  367. int i;
  368. PyObject *w;
  369. for (i = 0; i < argc; i++) {
  370. if ((w = Split(argv[i])) == NULL) {
  371. Py_DECREF(v);
  372. v = NULL;
  373. break;
  374. }
  375. PyTuple_SetItem(v, i, w);
  376. }
  377. }
  378. Tcl_Free(FREECAST argv);
  379. return v;
  380. }
  381. /* In some cases, Tcl will still return strings that are supposed to
  382. be lists. SplitObj walks through a nested tuple, finding string
  383. objects that need to be split. */
  384. static PyObject *
  385. SplitObj(PyObject *arg)
  386. {
  387. if (PyTuple_Check(arg)) {
  388. Py_ssize_t i, size;
  389. PyObject *elem, *newelem, *result;
  390. size = PyTuple_Size(arg);
  391. result = NULL;
  392. /* Recursively invoke SplitObj for all tuple items.
  393. If this does not return a new object, no action is
  394. needed. */
  395. for(i = 0; i < size; i++) {
  396. elem = PyTuple_GetItem(arg, i);
  397. newelem = SplitObj(elem);
  398. if (!newelem) {
  399. Py_XDECREF(result);
  400. return NULL;
  401. }
  402. if (!result) {
  403. Py_ssize_t k;
  404. if (newelem == elem) {
  405. Py_DECREF(newelem);
  406. continue;
  407. }
  408. result = PyTuple_New(size);
  409. if (!result)
  410. return NULL;
  411. for(k = 0; k < i; k++) {
  412. elem = PyTuple_GetItem(arg, k);
  413. Py_INCREF(elem);
  414. PyTuple_SetItem(result, k, elem);
  415. }
  416. }
  417. PyTuple_SetItem(result, i, newelem);
  418. }
  419. if (result)
  420. return result;
  421. /* Fall through, returning arg. */
  422. }
  423. else if (PyList_Check(arg)) {
  424. Py_ssize_t i, size;
  425. PyObject *elem, *newelem, *result;
  426. size = PyList_GET_SIZE(arg);
  427. result = PyTuple_New(size);
  428. if (!result)
  429. return NULL;
  430. /* Recursively invoke SplitObj for all list items. */
  431. for(i = 0; i < size; i++) {
  432. elem = PyList_GET_ITEM(arg, i);
  433. newelem = SplitObj(elem);
  434. if (!newelem) {
  435. Py_XDECREF(result);
  436. return NULL;
  437. }
  438. PyTuple_SetItem(result, i, newelem);
  439. }
  440. return result;
  441. }
  442. else if (PyUnicode_Check(arg)) {
  443. int argc;
  444. const char **argv;
  445. char *list = PyUnicode_AsUTF8(arg);
  446. if (list == NULL ||
  447. Tcl_SplitList((Tcl_Interp *)NULL, list, &argc, &argv) != TCL_OK) {
  448. Py_INCREF(arg);
  449. return arg;
  450. }
  451. Tcl_Free(FREECAST argv);
  452. if (argc > 1)
  453. return Split(list);
  454. /* Fall through, returning arg. */
  455. }
  456. else if (PyBytes_Check(arg)) {
  457. int argc;
  458. const char **argv;
  459. char *list = PyBytes_AsString(arg);
  460. if (Tcl_SplitList((Tcl_Interp *)NULL, list, &argc, &argv) != TCL_OK) {
  461. Py_INCREF(arg);
  462. return arg;
  463. }
  464. Tcl_Free(FREECAST argv);
  465. if (argc > 1)
  466. return Split(PyBytes_AsString(arg));
  467. /* Fall through, returning arg. */
  468. }
  469. Py_INCREF(arg);
  470. return arg;
  471. }
  472. /*[clinic input]
  473. module _tkinter
  474. class _tkinter.tkapp "TkappObject *" "&Tkapp_Type_spec"
  475. class _tkinter.Tcl_Obj "PyTclObject *" "&PyTclObject_Type_spec"
  476. class _tkinter.tktimertoken "TkttObject *" "&Tktt_Type_spec"
  477. [clinic start generated code]*/
  478. /*[clinic end generated code: output=da39a3ee5e6b4b0d input=b1ebf15c162ee229]*/
  479. /**** Tkapp Object ****/
  480. #ifndef WITH_APPINIT
  481. int
  482. Tcl_AppInit(Tcl_Interp *interp)
  483. {
  484. const char * _tkinter_skip_tk_init;
  485. if (Tcl_Init(interp) == TCL_ERROR) {
  486. PySys_WriteStderr("Tcl_Init error: %s\n", Tcl_GetStringResult(interp));
  487. return TCL_ERROR;
  488. }
  489. _tkinter_skip_tk_init = Tcl_GetVar(interp,
  490. "_tkinter_skip_tk_init", TCL_GLOBAL_ONLY);
  491. if (_tkinter_skip_tk_init != NULL &&
  492. strcmp(_tkinter_skip_tk_init, "1") == 0) {
  493. return TCL_OK;
  494. }
  495. #ifdef TKINTER_PROTECT_LOADTK
  496. if (tk_load_failed) {
  497. PySys_WriteStderr("Tk_Init error: %s\n", TKINTER_LOADTK_ERRMSG);
  498. return TCL_ERROR;
  499. }
  500. #endif
  501. if (Tk_Init(interp) == TCL_ERROR) {
  502. #ifdef TKINTER_PROTECT_LOADTK
  503. tk_load_failed = 1;
  504. #endif
  505. PySys_WriteStderr("Tk_Init error: %s\n", Tcl_GetStringResult(interp));
  506. return TCL_ERROR;
  507. }
  508. return TCL_OK;
  509. }
  510. #endif /* !WITH_APPINIT */
  511. /* Initialize the Tk application; see the `main' function in
  512. * `tkMain.c'.
  513. */
  514. static void EnableEventHook(void); /* Forward */
  515. static void DisableEventHook(void); /* Forward */
  516. static TkappObject *
  517. Tkapp_New(const char *screenName, const char *className,
  518. int interactive, int wantobjects, int wantTk, int sync,
  519. const char *use)
  520. {
  521. TkappObject *v;
  522. char *argv0;
  523. v = PyObject_New(TkappObject, (PyTypeObject *) Tkapp_Type);
  524. if (v == NULL)
  525. return NULL;
  526. Py_INCREF(Tkapp_Type);
  527. v->interp = Tcl_CreateInterp();
  528. v->wantobjects = wantobjects;
  529. v->threaded = Tcl_GetVar2Ex(v->interp, "tcl_platform", "threaded",
  530. TCL_GLOBAL_ONLY) != NULL;
  531. v->thread_id = Tcl_GetCurrentThread();
  532. v->dispatching = 0;
  533. #ifndef TCL_THREADS
  534. if (v->threaded) {
  535. PyErr_SetString(PyExc_RuntimeError,
  536. "Tcl is threaded but _tkinter is not");
  537. Py_DECREF(v);
  538. return 0;
  539. }
  540. #endif
  541. #ifdef WITH_THREAD
  542. if (v->threaded && tcl_lock) {
  543. /* If Tcl is threaded, we don't need the lock. */
  544. PyThread_free_lock(tcl_lock);
  545. tcl_lock = NULL;
  546. }
  547. #endif
  548. v->OldBooleanType = Tcl_GetObjType("boolean");
  549. v->BooleanType = Tcl_GetObjType("booleanString");
  550. v->ByteArrayType = Tcl_GetObjType("bytearray");
  551. v->DoubleType = Tcl_GetObjType("double");
  552. v->IntType = Tcl_GetObjType("int");
  553. v->WideIntType = Tcl_GetObjType("wideInt");
  554. v->BignumType = Tcl_GetObjType("bignum");
  555. v->ListType = Tcl_GetObjType("list");
  556. v->ProcBodyType = Tcl_GetObjType("procbody");
  557. v->StringType = Tcl_GetObjType("string");
  558. /* Delete the 'exit' command, which can screw things up */
  559. Tcl_DeleteCommand(v->interp, "exit");
  560. if (screenName != NULL)
  561. Tcl_SetVar2(v->interp, "env", "DISPLAY",
  562. screenName, TCL_GLOBAL_ONLY);
  563. if (interactive)
  564. Tcl_SetVar(v->interp, "tcl_interactive", "1", TCL_GLOBAL_ONLY);
  565. else
  566. Tcl_SetVar(v->interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY);
  567. /* This is used to get the application class for Tk 4.1 and up */
  568. argv0 = (char*)PyMem_Malloc(strlen(className) + 1);
  569. if (!argv0) {
  570. PyErr_NoMemory();
  571. Py_DECREF(v);
  572. return NULL;
  573. }
  574. strcpy(argv0, className);
  575. if (Py_ISUPPER(Py_CHARMASK(argv0[0])))
  576. argv0[0] = Py_TOLOWER(Py_CHARMASK(argv0[0]));
  577. Tcl_SetVar(v->interp, "argv0", argv0, TCL_GLOBAL_ONLY);
  578. PyMem_Free(argv0);
  579. if (! wantTk) {
  580. Tcl_SetVar(v->interp,
  581. "_tkinter_skip_tk_init", "1", TCL_GLOBAL_ONLY);
  582. }
  583. #ifdef TKINTER_PROTECT_LOADTK
  584. else if (tk_load_failed) {
  585. Tcl_SetVar(v->interp,
  586. "_tkinter_tk_failed", "1", TCL_GLOBAL_ONLY);
  587. }
  588. #endif
  589. /* some initial arguments need to be in argv */
  590. if (sync || use) {
  591. char *args;
  592. Py_ssize_t len = 0;
  593. if (sync)
  594. len += sizeof "-sync";
  595. if (use)
  596. len += strlen(use) + sizeof "-use "; /* never overflows */
  597. args = (char*)PyMem_Malloc(len);
  598. if (!args) {
  599. PyErr_NoMemory();
  600. Py_DECREF(v);
  601. return NULL;
  602. }
  603. args[0] = '\0';
  604. if (sync)
  605. strcat(args, "-sync");
  606. if (use) {
  607. if (sync)
  608. strcat(args, " ");
  609. strcat(args, "-use ");
  610. strcat(args, use);
  611. }
  612. Tcl_SetVar(v->interp, "argv", args, TCL_GLOBAL_ONLY);
  613. PyMem_Free(args);
  614. }
  615. #ifdef MS_WINDOWS
  616. {
  617. PyObject *str_path;
  618. PyObject *utf8_path;
  619. DWORD ret;
  620. ret = GetEnvironmentVariableW(L"TCL_LIBRARY", NULL, 0);
  621. if (!ret && GetLastError() == ERROR_ENVVAR_NOT_FOUND) {
  622. str_path = _get_tcl_lib_path();
  623. if (str_path == NULL && PyErr_Occurred()) {
  624. return NULL;
  625. }
  626. if (str_path != NULL) {
  627. utf8_path = PyUnicode_AsUTF8String(str_path);
  628. if (utf8_path == NULL) {
  629. return NULL;
  630. }
  631. Tcl_SetVar(v->interp,
  632. "tcl_library",
  633. PyBytes_AsString(utf8_path),
  634. TCL_GLOBAL_ONLY);
  635. Py_DECREF(utf8_path);
  636. }
  637. }
  638. }
  639. #endif
  640. if (Tcl_AppInit(v->interp) != TCL_OK) {
  641. PyObject *result = Tkinter_Error((PyObject *)v);
  642. #ifdef TKINTER_PROTECT_LOADTK
  643. if (wantTk) {
  644. const char *_tkinter_tk_failed;
  645. _tkinter_tk_failed = Tcl_GetVar(v->interp,
  646. "_tkinter_tk_failed", TCL_GLOBAL_ONLY);
  647. if ( _tkinter_tk_failed != NULL &&
  648. strcmp(_tkinter_tk_failed, "1") == 0) {
  649. tk_load_failed = 1;
  650. }
  651. }
  652. #endif
  653. Py_DECREF((PyObject *)v);
  654. return (TkappObject *)result;
  655. }
  656. EnableEventHook();
  657. return v;
  658. }
  659. #ifdef WITH_THREAD
  660. static void
  661. Tkapp_ThreadSend(TkappObject *self, Tcl_Event *ev,
  662. Tcl_Condition *cond, Tcl_Mutex *mutex)
  663. {
  664. Py_BEGIN_ALLOW_THREADS;
  665. Tcl_MutexLock(mutex);
  666. Tcl_ThreadQueueEvent(self->thread_id, ev, TCL_QUEUE_TAIL);
  667. Tcl_ThreadAlert(self->thread_id);
  668. Tcl_ConditionWait(cond, mutex, NULL);
  669. Tcl_MutexUnlock(mutex);
  670. Py_END_ALLOW_THREADS
  671. }
  672. #endif
  673. /** Tcl Eval **/
  674. typedef struct {
  675. PyObject_HEAD
  676. Tcl_Obj *value;
  677. PyObject *string; /* This cannot cause cycles. */
  678. } PyTclObject;
  679. static PyObject *PyTclObject_Type;
  680. #define PyTclObject_Check(v) ((v)->ob_type == (PyTypeObject *) PyTclObject_Type)
  681. static PyObject *
  682. newPyTclObject(Tcl_Obj *arg)
  683. {
  684. PyTclObject *self;
  685. self = PyObject_New(PyTclObject, (PyTypeObject *) PyTclObject_Type);
  686. if (self == NULL)
  687. return NULL;
  688. Py_INCREF(PyTclObject_Type);
  689. Tcl_IncrRefCount(arg);
  690. self->value = arg;
  691. self->string = NULL;
  692. return (PyObject*)self;
  693. }
  694. static void
  695. PyTclObject_dealloc(PyTclObject *self)
  696. {
  697. PyObject *tp = (PyObject *) Py_TYPE(self);
  698. Tcl_DecrRefCount(self->value);
  699. Py_XDECREF(self->string);
  700. PyObject_Del(self);
  701. Py_DECREF(tp);
  702. }
  703. static char*
  704. PyTclObject_TclString(PyObject *self)
  705. {
  706. return Tcl_GetString(((PyTclObject*)self)->value);
  707. }
  708. /* Like _str, but create Unicode if necessary. */
  709. PyDoc_STRVAR(PyTclObject_string__doc__,
  710. "the string representation of this object, either as str or bytes");
  711. static PyObject *
  712. PyTclObject_string(PyTclObject *self, void *ignored)
  713. {
  714. if (!self->string) {
  715. self->string = unicodeFromTclObj(self->value);
  716. if (!self->string)
  717. return NULL;
  718. }
  719. Py_INCREF(self->string);
  720. return self->string;
  721. }
  722. static PyObject *
  723. PyTclObject_str(PyTclObject *self, void *ignored)
  724. {
  725. if (self->string) {
  726. Py_INCREF(self->string);
  727. return self->string;
  728. }
  729. /* XXX Could chache result if it is non-ASCII. */
  730. return unicodeFromTclObj(self->value);
  731. }
  732. static PyObject *
  733. PyTclObject_repr(PyTclObject *self)
  734. {
  735. PyObject *repr, *str = PyTclObject_str(self, NULL);
  736. if (str == NULL)
  737. return NULL;
  738. repr = PyUnicode_FromFormat("<%s object: %R>",
  739. self->value->typePtr->name, str);
  740. Py_DECREF(str);
  741. return repr;
  742. }
  743. #define TEST_COND(cond) ((cond) ? Py_True : Py_False)
  744. static PyObject *
  745. PyTclObject_richcompare(PyObject *self, PyObject *other, int op)
  746. {
  747. int result;
  748. PyObject *v;
  749. /* neither argument should be NULL, unless something's gone wrong */
  750. if (self == NULL || other == NULL) {
  751. PyErr_BadInternalCall();
  752. return NULL;
  753. }
  754. /* both arguments should be instances of PyTclObject */
  755. if (!PyTclObject_Check(self) || !PyTclObject_Check(other)) {
  756. v = Py_NotImplemented;
  757. goto finished;
  758. }
  759. if (self == other)
  760. /* fast path when self and other are identical */
  761. result = 0;
  762. else
  763. result = strcmp(Tcl_GetString(((PyTclObject *)self)->value),
  764. Tcl_GetString(((PyTclObject *)other)->value));
  765. /* Convert return value to a Boolean */
  766. switch (op) {
  767. case Py_EQ:
  768. v = TEST_COND(result == 0);
  769. break;
  770. case Py_NE:
  771. v = TEST_COND(result != 0);
  772. break;
  773. case Py_LE:
  774. v = TEST_COND(result <= 0);
  775. break;
  776. case Py_GE:
  777. v = TEST_COND(result >= 0);
  778. break;
  779. case Py_LT:
  780. v = TEST_COND(result < 0);
  781. break;
  782. case Py_GT:
  783. v = TEST_COND(result > 0);
  784. break;
  785. default:
  786. PyErr_BadArgument();
  787. return NULL;
  788. }
  789. finished:
  790. Py_INCREF(v);
  791. return v;
  792. }
  793. PyDoc_STRVAR(get_typename__doc__, "name of the Tcl type");
  794. static PyObject*
  795. get_typename(PyTclObject* obj, void* ignored)
  796. {
  797. return unicodeFromTclString(obj->value->typePtr->name);
  798. }
  799. static PyGetSetDef PyTclObject_getsetlist[] = {
  800. {"typename", (getter)get_typename, NULL, get_typename__doc__},
  801. {"string", (getter)PyTclObject_string, NULL,
  802. PyTclObject_string__doc__},
  803. {0},
  804. };
  805. static PyType_Slot PyTclObject_Type_slots[] = {
  806. {Py_tp_dealloc, (destructor)PyTclObject_dealloc},
  807. {Py_tp_repr, (reprfunc)PyTclObject_repr},
  808. {Py_tp_str, (reprfunc)PyTclObject_str},
  809. {Py_tp_getattro, PyObject_GenericGetAttr},
  810. {Py_tp_richcompare, PyTclObject_richcompare},
  811. {Py_tp_getset, PyTclObject_getsetlist},
  812. {0, 0}
  813. };
  814. static PyType_Spec PyTclObject_Type_spec = {
  815. "_tkinter.Tcl_Obj",
  816. sizeof(PyTclObject),
  817. 0,
  818. Py_TPFLAGS_DEFAULT,
  819. PyTclObject_Type_slots,
  820. };
  821. #if PY_SIZE_MAX > INT_MAX
  822. #define CHECK_STRING_LENGTH(s) do { \
  823. if (s != NULL && strlen(s) >= INT_MAX) { \
  824. PyErr_SetString(PyExc_OverflowError, "string is too long"); \
  825. return NULL; \
  826. } } while(0)
  827. #else
  828. #define CHECK_STRING_LENGTH(s)
  829. #endif
  830. #ifdef HAVE_LIBTOMMAMTH
  831. static Tcl_Obj*
  832. asBignumObj(PyObject *value)
  833. {
  834. Tcl_Obj *result;
  835. int neg;
  836. PyObject *hexstr;
  837. char *hexchars;
  838. mp_int bigValue;
  839. neg = Py_SIZE(value) < 0;
  840. hexstr = _PyLong_Format(value, 16);
  841. if (hexstr == NULL)
  842. return NULL;
  843. hexchars = PyUnicode_AsUTF8(hexstr);
  844. if (hexchars == NULL) {
  845. Py_DECREF(hexstr);
  846. return NULL;
  847. }
  848. hexchars += neg + 2; /* skip sign and "0x" */
  849. mp_init(&bigValue);
  850. if (mp_read_radix(&bigValue, hexchars, 16) != MP_OKAY) {
  851. mp_clear(&bigValue);
  852. Py_DECREF(hexstr);
  853. PyErr_NoMemory();
  854. return NULL;
  855. }
  856. Py_DECREF(hexstr);
  857. bigValue.sign = neg ? MP_NEG : MP_ZPOS;
  858. result = Tcl_NewBignumObj(&bigValue);
  859. mp_clear(&bigValue);
  860. if (result == NULL) {
  861. PyErr_NoMemory();
  862. return NULL;
  863. }
  864. return result;
  865. }
  866. #endif
  867. static Tcl_Obj*
  868. AsObj(PyObject *value)
  869. {
  870. Tcl_Obj *result;
  871. if (PyBytes_Check(value)) {
  872. if (PyBytes_GET_SIZE(value) >= INT_MAX) {
  873. PyErr_SetString(PyExc_OverflowError, "bytes object is too long");
  874. return NULL;
  875. }
  876. return Tcl_NewByteArrayObj((unsigned char *)PyBytes_AS_STRING(value),
  877. (int)PyBytes_GET_SIZE(value));
  878. }
  879. if (PyBool_Check(value))
  880. return Tcl_NewBooleanObj(PyObject_IsTrue(value));
  881. if (PyLong_CheckExact(value)) {
  882. int overflow;
  883. long longValue;
  884. #ifdef TCL_WIDE_INT_TYPE
  885. Tcl_WideInt wideValue;
  886. #endif
  887. longValue = PyLong_AsLongAndOverflow(value, &overflow);
  888. if (!overflow) {
  889. return Tcl_NewLongObj(longValue);
  890. }
  891. /* If there is an overflow in the long conversion,
  892. fall through to wideInt handling. */
  893. #ifdef TCL_WIDE_INT_TYPE
  894. if (_PyLong_AsByteArray((PyLongObject *)value,
  895. (unsigned char *)(void *)&wideValue,
  896. sizeof(wideValue),
  897. PY_LITTLE_ENDIAN,
  898. /* signed */ 1) == 0) {
  899. return Tcl_NewWideIntObj(wideValue);
  900. }
  901. PyErr_Clear();
  902. #endif
  903. /* If there is an overflow in the wideInt conversion,
  904. fall through to bignum handling. */
  905. #ifdef HAVE_LIBTOMMAMTH
  906. return asBignumObj(value);
  907. #endif
  908. /* If there is no wideInt or bignum support,
  909. fall through to default object handling. */
  910. }
  911. if (PyFloat_Check(value))
  912. return Tcl_NewDoubleObj(PyFloat_AS_DOUBLE(value));
  913. if (PyTuple_Check(value) || PyList_Check(value)) {
  914. Tcl_Obj **argv;
  915. Py_ssize_t size, i;
  916. size = PySequence_Fast_GET_SIZE(value);
  917. if (size == 0)
  918. return Tcl_NewListObj(0, NULL);
  919. if (!CHECK_SIZE(size, sizeof(Tcl_Obj *))) {
  920. PyErr_SetString(PyExc_OverflowError,
  921. PyTuple_Check(value) ? "tuple is too long" :
  922. "list is too long");
  923. return NULL;
  924. }
  925. argv = (Tcl_Obj **) PyMem_Malloc(((size_t)size) * sizeof(Tcl_Obj *));
  926. if (!argv) {
  927. PyErr_NoMemory();
  928. return NULL;
  929. }
  930. for (i = 0; i < size; i++)
  931. argv[i] = AsObj(PySequence_Fast_GET_ITEM(value,i));
  932. result = Tcl_NewListObj((int)size, argv);
  933. PyMem_Free(argv);
  934. return result;
  935. }
  936. if (PyUnicode_Check(value)) {
  937. void *inbuf;
  938. Py_ssize_t size;
  939. int kind;
  940. Tcl_UniChar *outbuf = NULL;
  941. Py_ssize_t i;
  942. size_t allocsize;
  943. if (PyUnicode_READY(value) == -1)
  944. return NULL;
  945. inbuf = PyUnicode_DATA(value);
  946. size = PyUnicode_GET_LENGTH(value);
  947. if (size == 0)
  948. return Tcl_NewUnicodeObj((const void *)"", 0);
  949. if (!CHECK_SIZE(size, sizeof(Tcl_UniChar))) {
  950. PyErr_SetString(PyExc_OverflowError, "string is too long");
  951. return NULL;
  952. }
  953. kind = PyUnicode_KIND(value);
  954. if (kind == sizeof(Tcl_UniChar))
  955. return Tcl_NewUnicodeObj(inbuf, (int)size);
  956. allocsize = ((size_t)size) * sizeof(Tcl_UniChar);
  957. outbuf = (Tcl_UniChar*)PyMem_Malloc(allocsize);
  958. /* Else overflow occurred, and we take the next exit */
  959. if (!outbuf) {
  960. PyErr_NoMemory();
  961. return NULL;
  962. }
  963. for (i = 0; i < size; i++) {
  964. Py_UCS4 ch = PyUnicode_READ(kind, inbuf, i);
  965. /* We cannot test for sizeof(Tcl_UniChar) directly,
  966. so we test for UTF-8 size instead. */
  967. #if TCL_UTF_MAX == 3
  968. if (ch >= 0x10000) {
  969. /* Tcl doesn't do UTF-16, yet. */
  970. PyErr_Format(Tkinter_TclError,
  971. "character U+%x is above the range "
  972. "(U+0000-U+FFFF) allowed by Tcl",
  973. ch);
  974. PyMem_Free(outbuf);
  975. return NULL;
  976. }
  977. #endif
  978. outbuf[i] = ch;
  979. }
  980. result = Tcl_NewUnicodeObj(outbuf, (int)size);
  981. PyMem_Free(outbuf);
  982. return result;
  983. }
  984. if (PyTclObject_Check(value)) {
  985. Tcl_Obj *v = ((PyTclObject*)value)->value;
  986. Tcl_IncrRefCount(v);
  987. return v;
  988. }
  989. {
  990. PyObject *v = PyObject_Str(value);
  991. if (!v)
  992. return 0;
  993. result = AsObj(v);
  994. Py_DECREF(v);
  995. return result;
  996. }
  997. }
  998. static PyObject *
  999. fromBoolean(PyObject* tkapp, Tcl_Obj *value)
  1000. {
  1001. int boolValue;
  1002. if (Tcl_GetBooleanFromObj(Tkapp_Interp(tkapp), value, &boolValue) == TCL_ERROR)
  1003. return Tkinter_Error(tkapp);
  1004. return PyBool_FromLong(boolValue);
  1005. }
  1006. static PyObject*
  1007. fromWideIntObj(PyObject* tkapp, Tcl_Obj *value)
  1008. {
  1009. Tcl_WideInt wideValue;
  1010. if (Tcl_GetWideIntFromObj(Tkapp_Interp(tkapp), value, &wideValue) == TCL_OK) {
  1011. #ifdef HAVE_LONG_LONG
  1012. if (sizeof(wideValue) <= SIZEOF_LONG_LONG)
  1013. return PyLong_FromLongLong(wideValue);
  1014. #endif
  1015. return _PyLong_FromByteArray((unsigned char *)(void *)&wideValue,
  1016. sizeof(wideValue),
  1017. PY_LITTLE_ENDIAN,
  1018. /* signed */ 1);
  1019. }
  1020. return NULL;
  1021. }
  1022. #ifdef HAVE_LIBTOMMAMTH
  1023. static PyObject*
  1024. fromBignumObj(PyObject* tkapp, Tcl_Obj *value)
  1025. {
  1026. mp_int bigValue;
  1027. unsigned long numBytes;
  1028. unsigned char *bytes;
  1029. PyObject *res;
  1030. if (Tcl_GetBignumFromObj(Tkapp_Interp(tkapp), value, &bigValue) != TCL_OK)
  1031. return Tkinter_Error(tkapp);
  1032. numBytes = mp_unsigned_bin_size(&bigValue);
  1033. bytes = PyMem_Malloc(numBytes);
  1034. if (bytes == NULL) {
  1035. mp_clear(&bigValue);
  1036. return PyErr_NoMemory();
  1037. }
  1038. if (mp_to_unsigned_bin_n(&bigValue, bytes,
  1039. &numBytes) != MP_OKAY) {
  1040. mp_clear(&bigValue);
  1041. PyMem_Free(bytes);
  1042. return PyErr_NoMemory();
  1043. }
  1044. res = _PyLong_FromByteArray(bytes, numBytes,
  1045. /* big-endian */ 0,
  1046. /* unsigned */ 0);
  1047. PyMem_Free(bytes);
  1048. if (res != NULL && bigValue.sign == MP_NEG) {
  1049. PyObject *res2 = PyNumber_Negative(res);
  1050. Py_DECREF(res);
  1051. res = res2;
  1052. }
  1053. mp_clear(&bigValue);
  1054. return res;
  1055. }
  1056. #endif
  1057. static PyObject*
  1058. FromObj(PyObject* tkapp, Tcl_Obj *value)
  1059. {
  1060. PyObject *result = NULL;
  1061. TkappObject *app = (TkappObject*)tkapp;
  1062. Tcl_Interp *interp = Tkapp_Interp(tkapp);
  1063. if (value->typePtr == NULL) {
  1064. return unicodeFromTclStringAndSize(value->bytes, value->length);
  1065. }
  1066. if (value->typePtr == app->BooleanType ||
  1067. value->typePtr == app->OldBooleanType) {
  1068. return fromBoolean(tkapp, value);
  1069. }
  1070. if (value->typePtr == app->ByteArrayType) {
  1071. int size;
  1072. char *data = (char*)Tcl_GetByteArrayFromObj(value, &size);
  1073. return PyBytes_FromStringAndSize(data, size);
  1074. }
  1075. if (value->typePtr == app->DoubleType) {
  1076. return PyFloat_FromDouble(value->internalRep.doubleValue);
  1077. }
  1078. if (value->typePtr == app->IntType) {
  1079. long longValue;
  1080. if (Tcl_GetLongFromObj(interp, value, &longValue) == TCL_OK)
  1081. return PyLong_FromLong(longValue);
  1082. /* If there is an error in the long conversion,
  1083. fall through to wideInt handling. */
  1084. }
  1085. if (value->typePtr == app->IntType ||
  1086. value->typePtr == app->WideIntType) {
  1087. result = fromWideIntObj(tkapp, value);
  1088. if (result != NULL || PyErr_Occurred())
  1089. return result;
  1090. Tcl_ResetResult(interp);
  1091. /* If there is an error in the wideInt conversion,
  1092. fall through to bignum handling. */
  1093. }
  1094. #ifdef HAVE_LIBTOMMAMTH
  1095. if (value->typePtr == app->IntType ||
  1096. value->typePtr == app->WideIntType ||
  1097. value->typePtr == app->BignumType) {
  1098. return fromBignumObj(tkapp, value);
  1099. }
  1100. #endif
  1101. if (value->typePtr == app->ListType) {
  1102. int size;
  1103. int i, status;
  1104. PyObject *elem;
  1105. Tcl_Obj *tcl_elem;
  1106. status = Tcl_ListObjLength(interp, value, &size);
  1107. if (status == TCL_ERROR)
  1108. return Tkinter_Error(tkapp);
  1109. result = PyTuple_New(size);
  1110. if (!result)
  1111. return NULL;
  1112. for (i = 0; i < size; i++) {
  1113. status = Tcl_ListObjIndex(interp, value, i, &tcl_elem);
  1114. if (status == TCL_ERROR) {
  1115. Py_DECREF(result);
  1116. return Tkinter_Error(tkapp);
  1117. }
  1118. elem = FromObj(tkapp, tcl_elem);
  1119. if (!elem) {
  1120. Py_DECREF(result);
  1121. return NULL;
  1122. }
  1123. PyTuple_SetItem(result, i, elem);
  1124. }
  1125. return result;
  1126. }
  1127. if (value->typePtr == app->ProcBodyType) {
  1128. /* fall through: return tcl object. */
  1129. }
  1130. if (value->typePtr == app->StringType) {
  1131. return PyUnicode_FromKindAndData(
  1132. sizeof(Tcl_UniChar), Tcl_GetUnicode(value),
  1133. Tcl_GetCharLength(value));
  1134. }
  1135. #if TK_HEX_VERSION >= 0x08050000
  1136. if (app->BooleanType == NULL &&
  1137. strcmp(value->typePtr->name, "booleanString") == 0) {
  1138. /* booleanString type is not registered in Tcl */
  1139. app->BooleanType = value->typePtr;
  1140. return fromBoolean(tkapp, value);
  1141. }
  1142. #endif
  1143. #ifdef HAVE_LIBTOMMAMTH
  1144. if (app->BignumType == NULL &&
  1145. strcmp(value->typePtr->name, "bignum") == 0) {
  1146. /* bignum type is not registered in Tcl */
  1147. app->BignumType = value->typePtr;
  1148. return fromBignumObj(tkapp, value);
  1149. }
  1150. #endif
  1151. return newPyTclObject(value);
  1152. }
  1153. #ifdef WITH_THREAD
  1154. /* This mutex synchronizes inter-thread command calls. */
  1155. TCL_DECLARE_MUTEX(call_mutex)
  1156. typedef struct Tkapp_CallEvent {
  1157. Tcl_Event ev; /* Must be first */
  1158. TkappObject *self;
  1159. PyObject *args;
  1160. int flags;
  1161. PyObject **res;
  1162. PyObject **exc_type, **exc_value, **exc_tb;
  1163. Tcl_Condition *done;
  1164. } Tkapp_CallEvent;
  1165. #endif
  1166. void
  1167. Tkapp_CallDeallocArgs(Tcl_Obj** objv, Tcl_Obj** objStore, int objc)
  1168. {
  1169. int i;
  1170. for (i = 0; i < objc; i++)
  1171. Tcl_DecrRefCount(objv[i]);
  1172. if (objv != objStore)
  1173. PyMem_Free(objv);
  1174. }
  1175. /* Convert Python objects to Tcl objects. This must happen in the
  1176. interpreter thread, which may or may not be the calling thread. */
  1177. static Tcl_Obj**
  1178. Tkapp_CallArgs(PyObject *args, Tcl_Obj** objStore, int *pobjc)
  1179. {
  1180. Tcl_Obj **objv = objStore;
  1181. Py_ssize_t objc = 0, i;
  1182. if (args == NULL)
  1183. /* do nothing */;
  1184. else if (!(PyTuple_Check(args) || PyList_Check(args))) {
  1185. objv[0] = AsObj(args);
  1186. if (objv[0] == 0)
  1187. goto finally;
  1188. objc = 1;
  1189. Tcl_IncrRefCount(objv[0]);
  1190. }
  1191. else {
  1192. objc = PySequence_Fast_GET_SIZE(args);
  1193. if (objc > ARGSZ) {
  1194. if (!CHECK_SIZE(objc, sizeof(Tcl_Obj *))) {
  1195. PyErr_SetString(PyExc_OverflowError,
  1196. PyTuple_Check(args) ? "tuple is too long" :
  1197. "list is too long");
  1198. return NULL;
  1199. }
  1200. objv = (Tcl_Obj **)PyMem_Malloc(((size_t)objc) * sizeof(Tcl_Obj *));
  1201. if (objv == NULL) {
  1202. PyErr_NoMemory();
  1203. objc = 0;
  1204. goto finally;
  1205. }
  1206. }
  1207. for (i = 0; i < objc; i++) {
  1208. PyObject *v = PySequence_Fast_GET_ITEM(args, i);
  1209. if (v == Py_None) {
  1210. objc = i;
  1211. break;
  1212. }
  1213. objv[i] = AsObj(v);
  1214. if (!objv[i]) {
  1215. /* Reset objc, so it attempts to clear
  1216. objects only up to i. */
  1217. objc = i;
  1218. goto finally;
  1219. }
  1220. Tcl_IncrRefCount(objv[i]);
  1221. }
  1222. }
  1223. *pobjc = (int)objc;
  1224. return objv;
  1225. finally:
  1226. Tkapp_CallDeallocArgs(objv, objStore, (int)objc);
  1227. return NULL;
  1228. }
  1229. /* Convert the results of a command call into a Python objects. */
  1230. static PyObject*
  1231. Tkapp_CallResult(TkappObject *self)
  1232. {
  1233. PyObject *res = NULL;
  1234. Tcl_Obj *value = Tcl_GetObjResult(self->interp);
  1235. if(self->wantobjects) {
  1236. /* Not sure whether the IncrRef is necessary, but something
  1237. may overwrite the interpreter result while we are
  1238. converting it. */
  1239. Tcl_IncrRefCount(value);
  1240. res = FromObj((PyObject*)self, value);
  1241. Tcl_DecrRefCount(value);
  1242. } else {
  1243. res = unicodeFromTclObj(value);
  1244. }
  1245. return res;
  1246. }
  1247. #ifdef WITH_THREAD
  1248. /* Tkapp_CallProc is the event procedure that is executed in the context of
  1249. the Tcl interpreter thread. Initially, it holds the Tcl lock, and doesn't
  1250. hold the Python lock. */
  1251. static int
  1252. Tkapp_CallProc(Tkapp_CallEvent *e, int flags)
  1253. {
  1254. Tcl_Obj *objStore[ARGSZ];
  1255. Tcl_Obj **objv;
  1256. int objc;
  1257. int i;
  1258. ENTER_PYTHON
  1259. objv = Tkapp_CallArgs(e->args, objStore, &objc);
  1260. if (!objv) {
  1261. PyErr_Fetch(e->exc_type, e->exc_value, e->exc_tb);
  1262. *(e->res) = NULL;
  1263. }
  1264. LEAVE_PYTHON
  1265. if (!objv)
  1266. goto done;
  1267. i = Tcl_EvalObjv(e->self->interp, objc, objv, e->flags);
  1268. ENTER_PYTHON
  1269. if (i == TCL_ERROR) {
  1270. *(e->res) = NULL;
  1271. *(e->exc_type) = NULL;
  1272. *(e->exc_tb) = NULL;
  1273. *(e->exc_value) = PyObject_CallFunction(
  1274. Tkinter_TclError, "s",
  1275. Tcl_GetStringResult(e->self->interp));
  1276. }
  1277. else {
  1278. *(e->res) = Tkapp_CallResult(e->self);
  1279. }
  1280. LEAVE_PYTHON
  1281. Tkapp_CallDeallocArgs(objv, objStore, objc);
  1282. done:
  1283. /* Wake up calling thread. */
  1284. Tcl_MutexLock(&call_mutex);
  1285. Tcl_ConditionNotify(e->done);
  1286. Tcl_MutexUnlock(&call_mutex);
  1287. return 1;
  1288. }
  1289. #endif
  1290. /* This is the main entry point for calling a Tcl command.
  1291. It supports three cases, with regard to threading:
  1292. 1. Tcl is not threaded: Must have the Tcl lock, then can invoke command in
  1293. the context of the calling thread.
  1294. 2. Tcl is threaded, caller of the command is in the interpreter thread:
  1295. Execute the command in the calling thread. Since the Tcl lock will
  1296. not be used, we can merge that with case 1.
  1297. 3. Tcl is threaded, caller is in a different thread: Must queue an event to
  1298. the interpreter thread. Allocation of Tcl objects needs to occur in the
  1299. interpreter thread, so we ship the PyObject* args to the target thread,
  1300. and perform processing there. */
  1301. static PyObject *
  1302. Tkapp_Call(PyObject *selfptr, PyObject *args)
  1303. {
  1304. Tcl_Obj *objStore[ARGSZ];
  1305. Tcl_Obj **objv = NULL;
  1306. int objc, i;
  1307. PyObject *res = NULL;
  1308. TkappObject *self = (TkappObject*)selfptr;
  1309. int flags = TCL_EVAL_DIRECT | TCL_EVAL_GLOBAL;
  1310. /* If args is a single tuple, replace with contents of tuple */
  1311. if (1 == PyTuple_Size(args)){
  1312. PyObject* item = PyTuple_GetItem(args, 0);
  1313. if (PyTuple_Check(item))
  1314. args = item;
  1315. }
  1316. #ifdef WITH_THREAD
  1317. if (self->threaded && self->thread_id != Tcl_GetCurrentThread()) {
  1318. /* We cannot call the command directly. Instead, we must
  1319. marshal the parameters to the interpreter thread. */
  1320. Tkapp_CallEvent *ev;
  1321. Tcl_Condition cond = NULL;
  1322. PyObject *exc_type, *exc_value, *exc_tb;
  1323. if (!WaitForMainloop(self))
  1324. return NULL;
  1325. ev = (Tkapp_CallEvent*)attemptckalloc(sizeof(Tkapp_CallEvent));
  1326. if (ev == NULL) {
  1327. PyErr_NoMemory();
  1328. return NULL;
  1329. }
  1330. ev->ev.proc = (Tcl_EventProc*)Tkapp_CallProc;
  1331. ev->self = self;
  1332. ev->args = args;
  1333. ev->res = &res;
  1334. ev->exc_type = &exc_type;
  1335. ev->exc_value = &exc_value;
  1336. ev->exc_tb = &exc_tb;
  1337. ev->done = &cond;
  1338. Tkapp_ThreadSend(self, (Tcl_Event*)ev, &cond, &call_mutex);
  1339. if (res == NULL) {
  1340. if (exc_type)
  1341. PyErr_Restore(exc_type, exc_value, exc_tb);
  1342. else
  1343. PyErr_SetObject(Tkinter_TclError, exc_value);
  1344. }
  1345. Tcl_ConditionFinalize(&cond);
  1346. }
  1347. else
  1348. #endif
  1349. {
  1350. objv = Tkapp_CallArgs(args, objStore, &objc);
  1351. if (!objv)
  1352. return NULL;
  1353. ENTER_TCL
  1354. i = Tcl_EvalObjv(self->interp, objc, objv, flags);
  1355. ENTER_OVERLAP
  1356. if (i == TCL_ERROR)
  1357. Tkinter_Error(selfptr);
  1358. else
  1359. res = Tkapp_CallResult(self);
  1360. LEAVE_OVERLAP_TCL
  1361. Tkapp_CallDeallocArgs(objv, objStore, objc);
  1362. }
  1363. return res;
  1364. }
  1365. /*[clinic input]
  1366. _tkinter.tkapp.eval
  1367. script: str
  1368. /
  1369. [clinic start generated code]*/
  1370. static PyObject *
  1371. _tkinter_tkapp_eval_impl(TkappObject *self, const char *script)
  1372. /*[clinic end generated code: output=24b79831f700dea0 input=481484123a455f22]*/
  1373. {
  1374. PyObject *res = NULL;
  1375. int err;
  1376. CHECK_STRING_LENGTH(script);
  1377. CHECK_TCL_APPARTMENT;
  1378. ENTER_TCL
  1379. err = Tcl_Eval(Tkapp_Interp(self), script);
  1380. ENTER_OVERLAP
  1381. if (err == TCL_ERROR)
  1382. res = Tkinter_Error((PyObject *)self);
  1383. else
  1384. res = unicodeFromTclString(Tkapp_Result(self));
  1385. LEAVE_OVERLAP_TCL
  1386. return res;
  1387. }
  1388. /*[clinic input]
  1389. _tkinter.tkapp.evalfile
  1390. fileName: str
  1391. /
  1392. [clinic start generated code]*/
  1393. static PyObject *
  1394. _tkinter_tkapp_evalfile_impl(TkappObject *self, const char *fileName)
  1395. /*[clinic end generated code: output=63be88dcee4f11d3 input=873ab707e5e947e1]*/
  1396. {
  1397. PyObject *res = NULL;
  1398. int err;
  1399. CHECK_STRING_LENGTH(fileName);
  1400. CHECK_TCL_APPARTMENT;
  1401. ENTER_TCL
  1402. err = Tcl_EvalFile(Tkapp_Interp(self), fileName);
  1403. ENTER_OVERLAP
  1404. if (err == TCL_ERROR)
  1405. res = Tkinter_Error((PyObject *)self);
  1406. else
  1407. res = unicodeFromTclString(Tkapp_Result(self));
  1408. LEAVE_OVERLAP_TCL
  1409. return res;
  1410. }
  1411. /*[clinic input]
  1412. _tkinter.tkapp.record
  1413. script: str
  1414. /
  1415. [clinic start generated code]*/
  1416. static PyObject *
  1417. _tkinter_tkapp_record_impl(TkappObject *self, const char *script)
  1418. /*[clinic end generated code: output=0ffe08a0061730df input=c0b0db5a21412cac]*/
  1419. {
  1420. PyObject *res = NULL;
  1421. int err;
  1422. CHECK_STRING_LENGTH(script);
  1423. CHECK_TCL_APPARTMENT;
  1424. ENTER_TCL
  1425. err = Tcl_RecordAndEval(Tkapp_Interp(self), script, TCL_NO_EVAL);
  1426. ENTER_OVERLAP
  1427. if (err == TCL_ERROR)
  1428. res = Tkinter_Error((PyObject *)self);
  1429. else
  1430. res = unicodeFromTclString(Tkapp_Result(self));
  1431. LEAVE_OVERLAP_TCL
  1432. return res;
  1433. }
  1434. /*[clinic input]
  1435. _tkinter.tkapp.adderrinfo
  1436. msg: str
  1437. /
  1438. [clinic start generated code]*/
  1439. static PyObject *
  1440. _tkinter_tkapp_adderrinfo_impl(TkappObject *self, const char *msg)
  1441. /*[clinic end generated code: output=0e222ee2050eb357 input=4971399317d4c136]*/
  1442. {
  1443. CHECK_STRING_LENGTH(msg);
  1444. CHECK_TCL_APPARTMENT;
  1445. ENTER_TCL
  1446. Tcl_AddErrorInfo(Tkapp_Interp(self), msg);
  1447. LEAVE_TCL
  1448. Py_RETURN_NONE;
  1449. }
  1450. /** Tcl Variable **/
  1451. typedef PyObject* (*EventFunc)(PyObject*, PyObject *args, int flags);
  1452. #ifdef WITH_THREAD
  1453. TCL_DECLARE_MUTEX(var_mutex)
  1454. typedef struct VarEvent {
  1455. Tcl_Event ev; /* must be first */
  1456. PyObject *self;
  1457. PyObject *args;
  1458. int flags;
  1459. EventFunc func;
  1460. PyObject **res;
  1461. PyObject **exc_type;
  1462. PyObject **exc_val;
  1463. Tcl_Condition *cond;
  1464. } VarEvent;
  1465. #endif
  1466. /*[python]
  1467. class varname_converter(CConverter):
  1468. type = 'const char *'
  1469. converter = 'varname_converter'
  1470. [python]*/
  1471. /*[python checksum: da39a3ee5e6b4b0d3255bfef95601890afd80709]*/
  1472. static int
  1473. varname_converter(PyObject *in, void *_out)
  1474. {
  1475. char *s;
  1476. char **out = (char**)_out;
  1477. if (PyBytes_Check(in)) {
  1478. if (PyBytes_Size(in) > INT_MAX) {
  1479. PyErr_SetString(PyExc_OverflowError, "bytes object is too long");
  1480. return 0;
  1481. }
  1482. s = PyBytes_AsString(in);
  1483. if (strlen(s) != (size_t)PyBytes_Size(in)) {
  1484. PyErr_SetString(PyExc_ValueError, "embedded null byte");
  1485. return 0;
  1486. }
  1487. *out = s;
  1488. return 1;
  1489. }
  1490. if (PyUnicode_Check(in)) {
  1491. Py_ssize_t size;
  1492. s = PyUnicode_AsUTF8AndSize(in, &size);
  1493. if (s == NULL) {
  1494. return 0;
  1495. }
  1496. if (size > INT_MAX) {
  1497. PyErr_SetString(PyExc_OverflowError, "string is too long");
  1498. return 0;
  1499. }
  1500. if (strlen(s) != (size_t)size) {
  1501. PyErr_SetString(PyExc_ValueError, "embedded null character");
  1502. return 0;
  1503. }
  1504. *out = s;
  1505. return 1;
  1506. }
  1507. if (PyTclObject_Check(in)) {
  1508. *out = PyTclObject_TclString(in);
  1509. return 1;
  1510. }
  1511. PyErr_Format(PyExc_TypeError,
  1512. "must be str, bytes or Tcl_Obj, not %.50s",
  1513. in->ob_type->tp_name);
  1514. return 0;
  1515. }
  1516. #ifdef WITH_THREAD
  1517. static void
  1518. var_perform(VarEvent *ev)
  1519. {
  1520. *(ev->res) = ev->func(ev->self, ev->args, ev->flags);
  1521. if (!*(ev->res)) {
  1522. PyObject *exc, *val, *tb;
  1523. PyErr_Fetch(&exc, &val, &tb);
  1524. PyErr_NormalizeException(&exc, &val, &tb);
  1525. *(ev->exc_type) = exc;
  1526. *(ev->exc_val) = val;
  1527. Py_DECREF(tb);
  1528. }
  1529. }
  1530. static int
  1531. var_proc(VarEvent* ev, int flags)
  1532. {
  1533. ENTER_PYTHON
  1534. var_perform(ev);
  1535. Tcl_MutexLock(&var_mutex);
  1536. Tcl_ConditionNotify(ev->cond);
  1537. Tcl_MutexUnlock(&var_mutex);
  1538. LEAVE_PYTHON
  1539. return 1;
  1540. }
  1541. #endif
  1542. static PyObject*
  1543. var_invoke(EventFunc func, PyObject *selfptr, PyObject *args, int flags)
  1544. {
  1545. #ifdef WITH_THREAD
  1546. TkappObject *self = (TkappObject*)selfptr;
  1547. if (self->threaded && self->thread_id != Tcl_GetCurrentThread()) {
  1548. VarEvent *ev;
  1549. PyObject *res, *exc_type, *exc_val;
  1550. Tcl_Condition cond = NULL;
  1551. /* The current thread is not the interpreter thread. Marshal
  1552. the call to the interpreter thread, then wait for
  1553. completion. */
  1554. if (!WaitForMainloop(self))
  1555. return NULL;
  1556. ev = (VarEvent*)attemptckalloc(sizeof(VarEvent));
  1557. if (ev == NULL) {
  1558. PyErr_NoMemory();
  1559. return NULL;
  1560. }
  1561. ev->self = selfptr;
  1562. ev->args = args;
  1563. ev->flags = flags;
  1564. ev->func = func;
  1565. ev->res = &res;
  1566. ev->exc_type = &exc_type;
  1567. ev->exc_val = &exc_val;
  1568. ev->cond = &cond;
  1569. ev->ev.proc = (Tcl_EventProc*)var_proc;
  1570. Tkapp_ThreadSend(self, (Tcl_Event*)ev, &cond, &var_mutex);
  1571. Tcl_ConditionFinalize(&cond);
  1572. if (!res) {
  1573. PyErr_SetObject(exc_type, exc_val);
  1574. Py_DECREF(exc_type);
  1575. Py_DECREF(exc_val);
  1576. return NULL;
  1577. }
  1578. return res;
  1579. }
  1580. #endif
  1581. /* Tcl is not threaded, or this is the interpreter thread. */
  1582. return func(selfptr, args, flags);
  1583. }
  1584. static PyObject *
  1585. SetVar(PyObject *self, PyObject *args, int flags)
  1586. {
  1587. char *name1, *name2;
  1588. PyObject *newValue;
  1589. PyObject *res = NULL;
  1590. Tcl_Obj *newval, *ok;
  1591. switch (PyTuple_GET_SIZE(args)) {
  1592. case 2:
  1593. if (!PyArg_ParseTuple(args, "O&O:setvar",
  1594. varname_converter, &name1, &newValue))
  1595. return NULL;
  1596. /* XXX Acquire tcl lock??? */
  1597. newval = AsObj(newValue);
  1598. if (newval == NULL)
  1599. return NULL;
  1600. ENTER_TCL
  1601. ok = Tcl_SetVar2Ex(Tkapp_Interp(self), name1, NULL,
  1602. newval, flags);
  1603. ENTER_OVERLAP
  1604. if (!ok)
  1605. Tkinter_Error(self);
  1606. else {
  1607. res = Py_None;
  1608. Py_INCREF(res);
  1609. }
  1610. LEAVE_OVERLAP_TCL
  1611. break;
  1612. case 3:
  1613. if (!PyArg_ParseTuple(args, "ssO:setvar",
  1614. &name1, &name2, &newValue))
  1615. return NULL;
  1616. CHECK_STRING_LENGTH(name1);
  1617. CHECK_STRING_LENGTH(name2);
  1618. /* XXX must hold tcl lock already??? */
  1619. newval = AsObj(newValue);
  1620. ENTER_TCL
  1621. ok = Tcl_SetVar2Ex(Tkapp_Interp(self), name1, name2, newval, flags);
  1622. ENTER_OVERLAP
  1623. if (!ok)
  1624. Tkinter_Error(self);
  1625. else {
  1626. res = Py_None;
  1627. Py_INCREF(res);
  1628. }
  1629. LEAVE_OVERLAP_TCL
  1630. break;
  1631. default:
  1632. PyErr_SetString(PyExc_TypeError, "setvar requires 2 to 3 arguments");
  1633. return NULL;
  1634. }
  1635. return res;
  1636. }
  1637. static PyObject *
  1638. Tkapp_SetVar(PyObject *self, PyObject *args)
  1639. {
  1640. return var_invoke(SetVar, self, args, TCL_LEAVE_ERR_MSG);
  1641. }
  1642. static PyObject *
  1643. Tkapp_GlobalSetVar(PyObject *self, PyObject *args)
  1644. {
  1645. return var_invoke(SetVar, self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY);
  1646. }
  1647. static PyObject *
  1648. GetVar(PyObject *self, PyObject *args, int flags)
  1649. {
  1650. char *name1, *name2=NULL;
  1651. PyObject *res = NULL;
  1652. Tcl_Obj *tres;
  1653. if (!PyArg_ParseTuple(args, "O&|s:getvar",
  1654. varname_converter, &name1, &name2))
  1655. return NULL;
  1656. CHECK_STRING_LENGTH(name2);
  1657. ENTER_TCL
  1658. tres = Tcl_GetVar2Ex(Tkapp_Interp(self), name1, name2, flags);
  1659. ENTER_OVERLAP
  1660. if (tres == NULL) {
  1661. PyErr_SetString(Tkinter_TclError,
  1662. Tcl_GetStringResult(Tkapp_Interp(self)));
  1663. } else {
  1664. if (((TkappObject*)self)->wantobjects) {
  1665. res = FromObj(self, tres);
  1666. }
  1667. else {
  1668. res = unicodeFromTclObj(tres);
  1669. }
  1670. }
  1671. LEAVE_OVERLAP_TCL
  1672. return res;
  1673. }
  1674. static PyObject *
  1675. Tkapp_GetVar(PyObject *self, PyObject *args)
  1676. {
  1677. return var_invoke(GetVar, self, args, TCL_LEAVE_ERR_MSG);
  1678. }
  1679. static PyObject *
  1680. Tkapp_GlobalGetVar(PyObject *self, PyObject *args)
  1681. {
  1682. return var_invoke(GetVar, self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY);
  1683. }
  1684. static PyObject *
  1685. UnsetVar(PyObject *self, PyObject *args, int flags)
  1686. {
  1687. char *name1, *name2=NULL;
  1688. int code;
  1689. PyObject *res = NULL;
  1690. if (!PyArg_ParseTuple(args, "s|s:unsetvar", &name1, &name2))
  1691. return NULL;
  1692. CHECK_STRING_LENGTH(name1);
  1693. CHECK_STRING_LENGTH(name2);
  1694. ENTER_TCL
  1695. code = Tcl_UnsetVar2(Tkapp_Interp(self), name1, name2, flags);
  1696. ENTER_OVERLAP
  1697. if (code == TCL_ERROR)
  1698. res = Tkinter_Error(self);
  1699. else {
  1700. Py_INCREF(Py_None);
  1701. res = Py_None;
  1702. }
  1703. LEAVE_OVERLAP_TCL
  1704. return res;
  1705. }
  1706. static PyObject *
  1707. Tkapp_UnsetVar(PyObject *self, PyObject *args)
  1708. {
  1709. return var_invoke(UnsetVar, self, args, TCL_LEAVE_ERR_MSG);
  1710. }
  1711. static PyObject *
  1712. Tkapp_GlobalUnsetVar(PyObject *self, PyObject *args)
  1713. {
  1714. return var_invoke(UnsetVar, self, args,
  1715. TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY);
  1716. }
  1717. /** Tcl to Python **/
  1718. /*[clinic input]
  1719. _tkinter.tkapp.getint
  1720. arg: object
  1721. /
  1722. [clinic start generated code]*/
  1723. static PyObject *
  1724. _tkinter_tkapp_getint(TkappObject *self, PyObject *arg)
  1725. /*[clinic end generated code: output=88cf293fae307cfe input=034026997c5b91f8]*/
  1726. {
  1727. char *s;
  1728. Tcl_Obj *value;
  1729. PyObject *result;
  1730. if (PyLong_Check(arg)) {
  1731. Py_INCREF(arg);
  1732. return arg;
  1733. }
  1734. if (PyTclObject_Check(arg)) {
  1735. value = ((PyTclObject*)arg)->value;
  1736. Tcl_IncrRefCount(value);
  1737. }
  1738. else {
  1739. if (!PyArg_Parse(arg, "s:getint", &s))
  1740. return NULL;
  1741. CHECK_STRING_LENGTH(s);
  1742. value = Tcl_NewStringObj(s, -1);
  1743. if (value == NULL)
  1744. return Tkinter_Error((PyObject *)self);
  1745. }
  1746. /* Don't use Tcl_GetInt() because it returns ambiguous result for value
  1747. in ranges -2**32..-2**31-1 and 2**31..2**32-1 (on 32-bit platform).
  1748. Prefer bignum because Tcl_GetWideIntFromObj returns ambiguous result for
  1749. value in ranges -2**64..-2**63-1 and 2**63..2**64-1 (on 32-bit platform).
  1750. */
  1751. #ifdef HAVE_LIBTOMMAMTH
  1752. result = fromBignumObj((PyObject *)self, value);
  1753. #else
  1754. result = fromWideIntObj((PyObject *)self, value);
  1755. #endif
  1756. Tcl_DecrRefCount(value);
  1757. if (result != NULL || PyErr_Occurred())
  1758. return result;
  1759. return Tkinter_Error((PyObject *)self);
  1760. }
  1761. /*[clinic input]
  1762. _tkinter.tkapp.getdouble
  1763. arg: object
  1764. /
  1765. [clinic start generated code]*/
  1766. static PyObject *
  1767. _tkinter_tkapp_getdouble(TkappObject *self, PyObject *arg)
  1768. /*[clinic end generated code: output=c52b138bd8b956b9 input=22015729ce9ef7f8]*/
  1769. {
  1770. char *s;
  1771. double v;
  1772. if (PyFloat_Check(arg)) {
  1773. Py_INCREF(arg);
  1774. return arg;
  1775. }
  1776. if (PyNumber_Check(arg)) {
  1777. return PyNumber_Float(arg);
  1778. }
  1779. if (PyTclObject_Check(arg)) {
  1780. if (Tcl_GetDoubleFromObj(Tkapp_Interp(self),
  1781. ((PyTclObject*)arg)->value,
  1782. &v) == TCL_ERROR)
  1783. return Tkinter_Error((PyObject *)self);
  1784. return PyFloat_FromDouble(v);
  1785. }
  1786. if (!PyArg_Parse(arg, "s:getdouble", &s))
  1787. return NULL;
  1788. CHECK_STRING_LENGTH(s);
  1789. if (Tcl_GetDouble(Tkapp_Interp(self), s, &v) == TCL_ERROR)
  1790. return Tkinter_Error((PyObject *)self);
  1791. return PyFloat_FromDouble(v);
  1792. }
  1793. /*[clinic input]
  1794. _tkinter.tkapp.getboolean
  1795. arg: object
  1796. /
  1797. [clinic start generated code]*/
  1798. static PyObject *
  1799. _tkinter_tkapp_getboolean(TkappObject *self, PyObject *arg)
  1800. /*[clinic end generated code: output=726a9ae445821d91 input=7f11248ef8f8776e]*/
  1801. {
  1802. char *s;
  1803. int v;
  1804. if (PyLong_Check(arg)) { /* int or bool */
  1805. return PyBool_FromLong(Py_SIZE(arg) != 0);
  1806. }
  1807. if (PyTclObject_Check(arg)) {
  1808. if (Tcl_GetBooleanFromObj(Tkapp_Interp(self),
  1809. ((PyTclObject*)arg)->value,
  1810. &v) == TCL_ERROR)
  1811. return Tkinter_Error((PyObject *)self);
  1812. return PyBool_FromLong(v);
  1813. }
  1814. if (!PyArg_Parse(arg, "s:getboolean", &s))
  1815. return NULL;
  1816. CHECK_STRING_LENGTH(s);
  1817. if (Tcl_GetBoolean(Tkapp_Interp(self), s, &v) == TCL_ERROR)
  1818. return Tkinter_Error((PyObject *)self);
  1819. return PyBool_FromLong(v);
  1820. }
  1821. /*[clinic input]
  1822. _tkinter.tkapp.exprstring
  1823. s: str
  1824. /
  1825. [clinic start generated code]*/
  1826. static PyObject *
  1827. _tkinter_tkapp_exprstring_impl(TkappObject *self, const char *s)
  1828. /*[clinic end generated code: output=beda323d3ed0abb1 input=fa78f751afb2f21b]*/
  1829. {
  1830. PyObject *res = NULL;
  1831. int retval;
  1832. CHECK_STRING_LENGTH(s);
  1833. CHECK_TCL_APPARTMENT;
  1834. ENTER_TCL
  1835. retval = Tcl_ExprString(Tkapp_Interp(self), s);
  1836. ENTER_OVERLAP
  1837. if (retval == TCL_ERROR)
  1838. res = Tkinter_Error((PyObject *)self);
  1839. else
  1840. res = unicodeFromTclString(Tkapp_Result(self));
  1841. LEAVE_OVERLAP_TCL
  1842. return res;
  1843. }
  1844. /*[clinic input]
  1845. _tkinter.tkapp.exprlong
  1846. s: str
  1847. /
  1848. [clinic start generated code]*/
  1849. static PyObject *
  1850. _tkinter_tkapp_exprlong_impl(TkappObject *self, const char *s)
  1851. /*[clinic end generated code: output=5d6a46b63c6ebcf9 input=11bd7eee0c57b4dc]*/
  1852. {
  1853. PyObject *res = NULL;
  1854. int retval;
  1855. long v;
  1856. CHECK_STRING_LENGTH(s);
  1857. CHECK_TCL_APPARTMENT;
  1858. ENTER_TCL
  1859. retval = Tcl_ExprLong(Tkapp_Interp(self), s, &v);
  1860. ENTER_OVERLAP
  1861. if (retval == TCL_ERROR)
  1862. res = Tkinter_Error((PyObject *)self);
  1863. else
  1864. res = PyLong_FromLong(v);
  1865. LEAVE_OVERLAP_TCL
  1866. return res;
  1867. }
  1868. /*[clinic input]
  1869. _tkinter.tkapp.exprdouble
  1870. s: str
  1871. /
  1872. [clinic start generated code]*/
  1873. static PyObject *
  1874. _tkinter_tkapp_exprdouble_impl(TkappObject *self, const char *s)
  1875. /*[clinic end generated code: output=ff78df1081ea4158 input=ff02bc11798832d5]*/
  1876. {
  1877. PyObject *res = NULL;
  1878. double v;
  1879. int retval;
  1880. CHECK_STRING_LENGTH(s);
  1881. CHECK_TCL_APPARTMENT;
  1882. PyFPE_START_PROTECT("Tkapp_ExprDouble", return 0)
  1883. ENTER_TCL
  1884. retval = Tcl_ExprDouble(Tkapp_Interp(self), s, &v);
  1885. ENTER_OVERLAP
  1886. PyFPE_END_PROTECT(retval)
  1887. if (retval == TCL_ERROR)
  1888. res = Tkinter_Error((PyObject *)self);
  1889. else
  1890. res = PyFloat_FromDouble(v);
  1891. LEAVE_OVERLAP_TCL
  1892. return res;
  1893. }
  1894. /*[clinic input]
  1895. _tkinter.tkapp.exprboolean
  1896. s: str
  1897. /
  1898. [clinic start generated code]*/
  1899. static PyObject *
  1900. _tkinter_tkapp_exprboolean_impl(TkappObject *self, const char *s)
  1901. /*[clinic end generated code: output=8b28038c22887311 input=c8c66022bdb8d5d3]*/
  1902. {
  1903. PyObject *res = NULL;
  1904. int retval;
  1905. int v;
  1906. CHECK_STRING_LENGTH(s);
  1907. CHECK_TCL_APPARTMENT;
  1908. ENTER_TCL
  1909. retval = Tcl_ExprBoolean(Tkapp_Interp(self), s, &v);
  1910. ENTER_OVERLAP
  1911. if (retval == TCL_ERROR)
  1912. res = Tkinter_Error((PyObject *)self);
  1913. else
  1914. res = PyLong_FromLong(v);
  1915. LEAVE_OVERLAP_TCL
  1916. return res;
  1917. }
  1918. /*[clinic input]
  1919. _tkinter.tkapp.splitlist
  1920. arg: object
  1921. /
  1922. [clinic start generated code]*/
  1923. static PyObject *
  1924. _tkinter_tkapp_splitlist(TkappObject *self, PyObject *arg)
  1925. /*[clinic end generated code: output=13b51d34386d36fb input=2b2e13351e3c0b53]*/
  1926. {
  1927. char *list;
  1928. int argc;
  1929. const char **argv;
  1930. PyObject *v;
  1931. int i;
  1932. if (PyTclObject_Check(arg)) {
  1933. int objc;
  1934. Tcl_Obj **objv;
  1935. if (Tcl_ListObjGetElements(Tkapp_Interp(self),
  1936. ((PyTclObject*)arg)->value,
  1937. &objc, &objv) == TCL_ERROR) {
  1938. return Tkinter_Error((PyObject *)self);
  1939. }
  1940. if (!(v = PyTuple_New(objc)))
  1941. return NULL;
  1942. for (i = 0; i < objc; i++) {
  1943. PyObject *s = FromObj((PyObject*)self, objv[i]);
  1944. if (!s || PyTuple_SetItem(v, i, s)) {
  1945. Py_DECREF(v);
  1946. return NULL;
  1947. }
  1948. }
  1949. return v;
  1950. }
  1951. if (PyTuple_Check(arg)) {
  1952. Py_INCREF(arg);
  1953. return arg;
  1954. }
  1955. if (PyList_Check(arg)) {
  1956. return PySequence_Tuple(arg);
  1957. }
  1958. if (!PyArg_Parse(arg, "et:splitlist", "utf-8", &list))
  1959. return NULL;
  1960. CHECK_STRING_LENGTH(list);
  1961. if (Tcl_SplitList(Tkapp_Interp(self), list,
  1962. &argc, &argv) == TCL_ERROR) {
  1963. PyMem_Free(list);
  1964. return Tkinter_Error((PyObject *)self);
  1965. }
  1966. if (!(v = PyTuple_New(argc)))
  1967. goto finally;
  1968. for (i = 0; i < argc; i++) {
  1969. PyObject *s = unicodeFromTclString(argv[i]);
  1970. if (!s || PyTuple_SetItem(v, i, s)) {
  1971. Py_DECREF(v);
  1972. v = NULL;
  1973. goto finally;
  1974. }
  1975. }
  1976. finally:
  1977. ckfree(FREECAST argv);
  1978. PyMem_Free(list);
  1979. return v;
  1980. }
  1981. /*[clinic input]
  1982. _tkinter.tkapp.split
  1983. arg: object
  1984. /
  1985. [clinic start generated code]*/
  1986. static PyObject *
  1987. _tkinter_tkapp_split(TkappObject *self, PyObject *arg)
  1988. /*[clinic end generated code: output=e08ad832363facfd input=a1c78349eacaa140]*/
  1989. {
  1990. PyObject *v;
  1991. char *list;
  1992. if (PyTclObject_Check(arg)) {
  1993. Tcl_Obj *value = ((PyTclObject*)arg)->value;
  1994. int objc;
  1995. Tcl_Obj **objv;
  1996. int i;
  1997. if (Tcl_ListObjGetElements(Tkapp_Interp(self), value,
  1998. &objc, &objv) == TCL_ERROR) {
  1999. return FromObj((PyObject*)self, value);
  2000. }
  2001. if (objc == 0)
  2002. return PyUnicode_FromString("");
  2003. if (objc == 1)
  2004. return FromObj((PyObject*)self, objv[0]);
  2005. if (!(v = PyTuple_New(objc)))
  2006. return NULL;
  2007. for (i = 0; i < objc; i++) {
  2008. PyObject *s = FromObj((PyObject*)self, objv[i]);
  2009. if (!s || PyTuple_SetItem(v, i, s)) {
  2010. Py_DECREF(v);
  2011. return NULL;
  2012. }
  2013. }
  2014. return v;
  2015. }
  2016. if (PyTuple_Check(arg) || PyList_Check(arg))
  2017. return SplitObj(arg);
  2018. if (!PyArg_Parse(arg, "et:split", "utf-8", &list))
  2019. return NULL;
  2020. CHECK_STRING_LENGTH(list);
  2021. v = Split(list);
  2022. PyMem_Free(list);
  2023. return v;
  2024. }
  2025. /** Tcl Command **/
  2026. /* Client data struct */
  2027. typedef struct {
  2028. PyObject *self;
  2029. PyObject *func;
  2030. } PythonCmd_ClientData;
  2031. static int
  2032. PythonCmd_Error(Tcl_Interp *interp)
  2033. {
  2034. errorInCmd = 1;
  2035. PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd);
  2036. LEAVE_PYTHON
  2037. return TCL_ERROR;
  2038. }
  2039. /* This is the Tcl command that acts as a wrapper for Python
  2040. * function or method.
  2041. */
  2042. static int
  2043. PythonCmd(ClientData clientData, Tcl_Interp *interp, int argc, const char *argv[])
  2044. {
  2045. PythonCmd_ClientData *data = (PythonCmd_ClientData *)clientData;
  2046. PyObject *func, *arg, *res;
  2047. int i, rv;
  2048. Tcl_Obj *obj_res;
  2049. ENTER_PYTHON
  2050. /* TBD: no error checking here since we know, via the
  2051. * Tkapp_CreateCommand() that the client data is a two-tuple
  2052. */
  2053. func = data->func;
  2054. /* Create argument list (argv1, ..., argvN) */
  2055. if (!(arg = PyTuple_New(argc - 1)))
  2056. return PythonCmd_Error(interp);
  2057. for (i = 0; i < (argc - 1); i++) {
  2058. PyObject *s = unicodeFromTclString(argv[i + 1]);
  2059. if (!s || PyTuple_SetItem(arg, i, s)) {
  2060. Py_DECREF(arg);
  2061. return PythonCmd_Error(interp);
  2062. }
  2063. }
  2064. res = PyEval_CallObject(func, arg);
  2065. Py_DECREF(arg);
  2066. if (res == NULL)
  2067. return PythonCmd_Error(interp);
  2068. obj_res = AsObj(res);
  2069. if (obj_res == NULL) {
  2070. Py_DECREF(res);
  2071. return PythonCmd_Error(interp);
  2072. }
  2073. else {
  2074. Tcl_SetObjResult(interp, obj_res);
  2075. rv = TCL_OK;
  2076. }
  2077. Py_DECREF(res);
  2078. LEAVE_PYTHON
  2079. return rv;
  2080. }
  2081. static void
  2082. PythonCmdDelete(ClientData clientData)
  2083. {
  2084. PythonCmd_ClientData *data = (PythonCmd_ClientData *)clientData;
  2085. ENTER_PYTHON
  2086. Py_XDECREF(data->self);
  2087. Py_XDECREF(data->func);
  2088. PyMem_DEL(data);
  2089. LEAVE_PYTHON
  2090. }
  2091. #ifdef WITH_THREAD
  2092. TCL_DECLARE_MUTEX(command_mutex)
  2093. typedef struct CommandEvent{
  2094. Tcl_Event ev;
  2095. Tcl_Interp* interp;
  2096. const char *name;
  2097. int create;
  2098. int *status;
  2099. ClientData *data;
  2100. Tcl_Condition *done;
  2101. } CommandEvent;
  2102. static int
  2103. Tkapp_CommandProc(CommandEvent *ev, int flags)
  2104. {
  2105. if (ev->create)
  2106. *ev->status = Tcl_CreateCommand(
  2107. ev->interp, ev->name, PythonCmd,
  2108. ev->data, PythonCmdDelete) == NULL;
  2109. else
  2110. *ev->status = Tcl_DeleteCommand(ev->interp, ev->name);
  2111. Tcl_MutexLock(&command_mutex);
  2112. Tcl_ConditionNotify(ev->done);
  2113. Tcl_MutexUnlock(&command_mutex);
  2114. return 1;
  2115. }
  2116. #endif
  2117. /*[clinic input]
  2118. _tkinter.tkapp.createcommand
  2119. self: self(type="TkappObject *")
  2120. name: str
  2121. func: object
  2122. /
  2123. [clinic start generated code]*/
  2124. static PyObject *
  2125. _tkinter_tkapp_createcommand_impl(TkappObject *self, const char *name,
  2126. PyObject *func)
  2127. /*[clinic end generated code: output=2a1c79a4ee2af410 input=2bc2c046a0914234]*/
  2128. {
  2129. PythonCmd_ClientData *data;
  2130. int err;
  2131. CHECK_STRING_LENGTH(name);
  2132. if (!PyCallable_Check(func)) {
  2133. PyErr_SetString(PyExc_TypeError, "command not callable");
  2134. return NULL;
  2135. }
  2136. #ifdef WITH_THREAD
  2137. if (self->threaded && self->thread_id != Tcl_GetCurrentThread() &&
  2138. !WaitForMainloop(self))
  2139. return NULL;
  2140. #endif
  2141. data = PyMem_NEW(PythonCmd_ClientData, 1);
  2142. if (!data)
  2143. return PyErr_NoMemory();
  2144. Py_INCREF(self);
  2145. Py_INCREF(func);
  2146. data->self = (PyObject *) self;
  2147. data->func = func;
  2148. #ifdef WITH_THREAD
  2149. if (self->threaded && self->thread_id != Tcl_GetCurrentThread()) {
  2150. Tcl_Condition cond = NULL;
  2151. CommandEvent *ev = (CommandEvent*)attemptckalloc(sizeof(CommandEvent));
  2152. if (ev == NULL) {
  2153. PyErr_NoMemory();
  2154. PyMem_DEL(data);
  2155. return NULL;
  2156. }
  2157. ev->ev.proc = (Tcl_EventProc*)Tkapp_CommandProc;
  2158. ev->interp = self->interp;
  2159. ev->create = 1;
  2160. ev->name = name;
  2161. ev->data = (ClientData)data;
  2162. ev->status = &err;
  2163. ev->done = &cond;
  2164. Tkapp_ThreadSend(self, (Tcl_Event*)ev, &cond, &command_mutex);
  2165. Tcl_ConditionFinalize(&cond);
  2166. }
  2167. else
  2168. #endif
  2169. {
  2170. ENTER_TCL
  2171. err = Tcl_CreateCommand(
  2172. Tkapp_Interp(self), name, PythonCmd,
  2173. (ClientData)data, PythonCmdDelete) == NULL;
  2174. LEAVE_TCL
  2175. }
  2176. if (err) {
  2177. PyErr_SetString(Tkinter_TclError, "can't create Tcl command");
  2178. PyMem_DEL(data);
  2179. return NULL;
  2180. }
  2181. Py_RETURN_NONE;
  2182. }
  2183. /*[clinic input]
  2184. _tkinter.tkapp.deletecommand
  2185. self: self(type="TkappObject *")
  2186. name: str
  2187. /
  2188. [clinic start generated code]*/
  2189. static PyObject *
  2190. _tkinter_tkapp_deletecommand_impl(TkappObject *self, const char *name)
  2191. /*[clinic end generated code: output=a67e8cb5845e0d2d input=b6306468f10b219c]*/
  2192. {
  2193. int err;
  2194. CHECK_STRING_LENGTH(name);
  2195. #ifdef WITH_THREAD
  2196. if (self->threaded && self->thread_id != Tcl_GetCurrentThread()) {
  2197. Tcl_Condition cond = NULL;
  2198. CommandEvent *ev;
  2199. ev = (CommandEvent*)attemptckalloc(sizeof(CommandEvent));
  2200. if (ev == NULL) {
  2201. PyErr_NoMemory();
  2202. return NULL;
  2203. }
  2204. ev->ev.proc = (Tcl_EventProc*)Tkapp_CommandProc;
  2205. ev->interp = self->interp;
  2206. ev->create = 0;
  2207. ev->name = name;
  2208. ev->status = &err;
  2209. ev->done = &cond;
  2210. Tkapp_ThreadSend(self, (Tcl_Event*)ev, &cond,
  2211. &command_mutex);
  2212. Tcl_ConditionFinalize(&cond);
  2213. }
  2214. else
  2215. #endif
  2216. {
  2217. ENTER_TCL
  2218. err = Tcl_DeleteCommand(self->interp, name);
  2219. LEAVE_TCL
  2220. }
  2221. if (err == -1) {
  2222. PyErr_SetString(Tkinter_TclError, "can't delete Tcl command");
  2223. return NULL;
  2224. }
  2225. Py_RETURN_NONE;
  2226. }
  2227. #ifdef HAVE_CREATEFILEHANDLER
  2228. /** File Handler **/
  2229. typedef struct _fhcdata {
  2230. PyObject *func;
  2231. PyObject *file;
  2232. int id;
  2233. struct _fhcdata *next;
  2234. } FileHandler_ClientData;
  2235. static FileHandler_ClientData *HeadFHCD;
  2236. static FileHandler_ClientData *
  2237. NewFHCD(PyObject *func, PyObject *file, int id)
  2238. {
  2239. FileHandler_ClientData *p;
  2240. p = PyMem_NEW(FileHandler_ClientData, 1);
  2241. if (p != NULL) {
  2242. Py_XINCREF(func);
  2243. Py_XINCREF(file);
  2244. p->func = func;
  2245. p->file = file;
  2246. p->id = id;
  2247. p->next = HeadFHCD;
  2248. HeadFHCD = p;
  2249. }
  2250. return p;
  2251. }
  2252. static void
  2253. DeleteFHCD(int id)
  2254. {
  2255. FileHandler_ClientData *p, **pp;
  2256. pp = &HeadFHCD;
  2257. while ((p = *pp) != NULL) {
  2258. if (p->id == id) {
  2259. *pp = p->next;
  2260. Py_XDECREF(p->func);
  2261. Py_XDECREF(p->file);
  2262. PyMem_DEL(p);
  2263. }
  2264. else
  2265. pp = &p->next;
  2266. }
  2267. }
  2268. static void
  2269. FileHandler(ClientData clientData, int mask)
  2270. {
  2271. FileHandler_ClientData *data = (FileHandler_ClientData *)clientData;
  2272. PyObject *func, *file, *arg, *res;
  2273. ENTER_PYTHON
  2274. func = data->func;
  2275. file = data->file;
  2276. arg = Py_BuildValue("(Oi)", file, (long) mask);
  2277. res = PyEval_CallObject(func, arg);
  2278. Py_DECREF(arg);
  2279. if (res == NULL) {
  2280. errorInCmd = 1;
  2281. PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd);
  2282. }
  2283. Py_XDECREF(res);
  2284. LEAVE_PYTHON
  2285. }
  2286. /*[clinic input]
  2287. _tkinter.tkapp.createfilehandler
  2288. file: object
  2289. mask: int
  2290. func: object
  2291. /
  2292. [clinic start generated code]*/
  2293. static PyObject *
  2294. _tkinter_tkapp_createfilehandler_impl(TkappObject *self, PyObject *file,
  2295. int mask, PyObject *func)
  2296. /*[clinic end generated code: output=f73ce82de801c353 input=84943a5286e47947]*/
  2297. {
  2298. FileHandler_ClientData *data;
  2299. int tfile;
  2300. CHECK_TCL_APPARTMENT;
  2301. tfile = PyObject_AsFileDescriptor(file);
  2302. if (tfile < 0)
  2303. return NULL;
  2304. if (!PyCallable_Check(func)) {
  2305. PyErr_SetString(PyExc_TypeError, "bad argument list");
  2306. return NULL;
  2307. }
  2308. data = NewFHCD(func, file, tfile);
  2309. if (data == NULL)
  2310. return NULL;
  2311. /* Ought to check for null Tcl_File object... */
  2312. ENTER_TCL
  2313. Tcl_CreateFileHandler(tfile, mask, FileHandler, (ClientData) data);
  2314. LEAVE_TCL
  2315. Py_RETURN_NONE;
  2316. }
  2317. /*[clinic input]
  2318. _tkinter.tkapp.deletefilehandler
  2319. file: object
  2320. /
  2321. [clinic start generated code]*/
  2322. static PyObject *
  2323. _tkinter_tkapp_deletefilehandler(TkappObject *self, PyObject *file)
  2324. /*[clinic end generated code: output=b53cc96ebf9476fd input=abbec19d66312e2a]*/
  2325. {
  2326. int tfile;
  2327. CHECK_TCL_APPARTMENT;
  2328. tfile = PyObject_AsFileDescriptor(file);
  2329. if (tfile < 0)
  2330. return NULL;
  2331. DeleteFHCD(tfile);
  2332. /* Ought to check for null Tcl_File object... */
  2333. ENTER_TCL
  2334. Tcl_DeleteFileHandler(tfile);
  2335. LEAVE_TCL
  2336. Py_RETURN_NONE;
  2337. }
  2338. #endif /* HAVE_CREATEFILEHANDLER */
  2339. /**** Tktt Object (timer token) ****/
  2340. static PyObject *Tktt_Type;
  2341. typedef struct {
  2342. PyObject_HEAD
  2343. Tcl_TimerToken token;
  2344. PyObject *func;
  2345. } TkttObject;
  2346. /*[clinic input]
  2347. _tkinter.tktimertoken.deletetimerhandler
  2348. self: self(type="TkttObject *")
  2349. [clinic start generated code]*/
  2350. static PyObject *
  2351. _tkinter_tktimertoken_deletetimerhandler_impl(TkttObject *self)
  2352. /*[clinic end generated code: output=bd7fe17f328cfa55 input=25ba5dd594e52084]*/
  2353. {
  2354. TkttObject *v = self;
  2355. PyObject *func = v->func;
  2356. if (v->token != NULL) {
  2357. Tcl_DeleteTimerHandler(v->token);
  2358. v->token = NULL;
  2359. }
  2360. if (func != NULL) {
  2361. v->func = NULL;
  2362. Py_DECREF(func);
  2363. Py_DECREF(v); /* See Tktt_New() */
  2364. }
  2365. Py_RETURN_NONE;
  2366. }
  2367. static TkttObject *
  2368. Tktt_New(PyObject *func)
  2369. {
  2370. TkttObject *v;
  2371. v = PyObject_New(TkttObject, (PyTypeObject *) Tktt_Type);
  2372. if (v == NULL)
  2373. return NULL;
  2374. Py_INCREF(Tktt_Type);
  2375. Py_INCREF(func);
  2376. v->token = NULL;
  2377. v->func = func;
  2378. /* Extra reference, deleted when called or when handler is deleted */
  2379. Py_INCREF(v);
  2380. return v;
  2381. }
  2382. static void
  2383. Tktt_Dealloc(PyObject *self)
  2384. {
  2385. TkttObject *v = (TkttObject *)self;
  2386. PyObject *func = v->func;
  2387. PyObject *tp = (PyObject *) Py_TYPE(self);
  2388. Py_XDECREF(func);
  2389. PyObject_Del(self);
  2390. Py_DECREF(tp);
  2391. }
  2392. static PyObject *
  2393. Tktt_Repr(PyObject *self)
  2394. {
  2395. TkttObject *v = (TkttObject *)self;
  2396. return PyUnicode_FromFormat("<tktimertoken at %p%s>",
  2397. v,
  2398. v->func == NULL ? ", handler deleted" : "");
  2399. }
  2400. /** Timer Handler **/
  2401. static void
  2402. TimerHandler(ClientData clientData)
  2403. {
  2404. TkttObject *v = (TkttObject *)clientData;
  2405. PyObject *func = v->func;
  2406. PyObject *res;
  2407. if (func == NULL)
  2408. return;
  2409. v->func = NULL;
  2410. ENTER_PYTHON
  2411. res = PyEval_CallObject(func, NULL);
  2412. Py_DECREF(func);
  2413. Py_DECREF(v); /* See Tktt_New() */
  2414. if (res == NULL) {
  2415. errorInCmd = 1;
  2416. PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd);
  2417. }
  2418. else
  2419. Py_DECREF(res);
  2420. LEAVE_PYTHON
  2421. }
  2422. /*[clinic input]
  2423. _tkinter.tkapp.createtimerhandler
  2424. milliseconds: int
  2425. func: object
  2426. /
  2427. [clinic start generated code]*/
  2428. static PyObject *
  2429. _tkinter_tkapp_createtimerhandler_impl(TkappObject *self, int milliseconds,
  2430. PyObject *func)
  2431. /*[clinic end generated code: output=2da5959b9d031911 input=ba6729f32f0277a5]*/
  2432. {
  2433. TkttObject *v;
  2434. if (!PyCallable_Check(func)) {
  2435. PyErr_SetString(PyExc_TypeError, "bad argument list");
  2436. return NULL;
  2437. }
  2438. CHECK_TCL_APPARTMENT;
  2439. v = Tktt_New(func);
  2440. if (v) {
  2441. v->token = Tcl_CreateTimerHandler(milliseconds, TimerHandler,
  2442. (ClientData)v);
  2443. }
  2444. return (PyObject *) v;
  2445. }
  2446. /** Event Loop **/
  2447. /*[clinic input]
  2448. _tkinter.tkapp.mainloop
  2449. self: self(type="TkappObject *")
  2450. threshold: int = 0
  2451. /
  2452. [clinic start generated code]*/
  2453. static PyObject *
  2454. _tkinter_tkapp_mainloop_impl(TkappObject *self, int threshold)
  2455. /*[clinic end generated code: output=0ba8eabbe57841b0 input=ad57c9c1dd2b9470]*/
  2456. {
  2457. #ifdef WITH_THREAD
  2458. PyThreadState *tstate = PyThreadState_Get();
  2459. #endif
  2460. CHECK_TCL_APPARTMENT;
  2461. self->dispatching = 1;
  2462. quitMainLoop = 0;
  2463. while (Tk_GetNumMainWindows() > threshold &&
  2464. !quitMainLoop &&
  2465. !errorInCmd)
  2466. {
  2467. int result;
  2468. #ifdef WITH_THREAD
  2469. if (self->threaded) {
  2470. /* Allow other Python threads to run. */
  2471. ENTER_TCL
  2472. result = Tcl_DoOneEvent(0);
  2473. LEAVE_TCL
  2474. }
  2475. else {
  2476. Py_BEGIN_ALLOW_THREADS
  2477. if(tcl_lock)PyThread_acquire_lock(tcl_lock, 1);
  2478. tcl_tstate = tstate;
  2479. result = Tcl_DoOneEvent(TCL_DONT_WAIT);
  2480. tcl_tstate = NULL;
  2481. if(tcl_lock)PyThread_release_lock(tcl_lock);
  2482. if (result == 0)
  2483. Sleep(Tkinter_busywaitinterval);
  2484. Py_END_ALLOW_THREADS
  2485. }
  2486. #else
  2487. result = Tcl_DoOneEvent(0);
  2488. #endif
  2489. if (PyErr_CheckSignals() != 0) {
  2490. self->dispatching = 0;
  2491. return NULL;
  2492. }
  2493. if (result < 0)
  2494. break;
  2495. }
  2496. self->dispatching = 0;
  2497. quitMainLoop = 0;
  2498. if (errorInCmd) {
  2499. errorInCmd = 0;
  2500. PyErr_Restore(excInCmd, valInCmd, trbInCmd);
  2501. excInCmd = valInCmd = trbInCmd = NULL;
  2502. return NULL;
  2503. }
  2504. Py_RETURN_NONE;
  2505. }
  2506. /*[clinic input]
  2507. _tkinter.tkapp.dooneevent
  2508. flags: int = 0
  2509. /
  2510. [clinic start generated code]*/
  2511. static PyObject *
  2512. _tkinter_tkapp_dooneevent_impl(TkappObject *self, int flags)
  2513. /*[clinic end generated code: output=27c6b2aa464cac29 input=6542b928e364b793]*/
  2514. {
  2515. int rv;
  2516. ENTER_TCL
  2517. rv = Tcl_DoOneEvent(flags);
  2518. LEAVE_TCL
  2519. return PyLong_FromLong(rv);
  2520. }
  2521. /*[clinic input]
  2522. _tkinter.tkapp.quit
  2523. [clinic start generated code]*/
  2524. static PyObject *
  2525. _tkinter_tkapp_quit_impl(TkappObject *self)
  2526. /*[clinic end generated code: output=7f21eeff481f754f input=e03020dc38aff23c]*/
  2527. {
  2528. quitMainLoop = 1;
  2529. Py_RETURN_NONE;
  2530. }
  2531. /*[clinic input]
  2532. _tkinter.tkapp.interpaddr
  2533. [clinic start generated code]*/
  2534. static PyObject *
  2535. _tkinter_tkapp_interpaddr_impl(TkappObject *self)
  2536. /*[clinic end generated code: output=6caaae3273b3c95a input=2dd32cbddb55a111]*/
  2537. {
  2538. return PyLong_FromVoidPtr(Tkapp_Interp(self));
  2539. }
  2540. /*[clinic input]
  2541. _tkinter.tkapp.loadtk
  2542. [clinic start generated code]*/
  2543. static PyObject *
  2544. _tkinter_tkapp_loadtk_impl(TkappObject *self)
  2545. /*[clinic end generated code: output=e9e10a954ce46d2a input=b5e82afedd6354f0]*/
  2546. {
  2547. Tcl_Interp *interp = Tkapp_Interp(self);
  2548. const char * _tk_exists = NULL;
  2549. int err;
  2550. #ifdef TKINTER_PROTECT_LOADTK
  2551. /* Up to Tk 8.4.13, Tk_Init deadlocks on the second call when the
  2552. * first call failed.
  2553. * To avoid the deadlock, we just refuse the second call through
  2554. * a static variable.
  2555. */
  2556. if (tk_load_failed) {
  2557. PyErr_SetString(Tkinter_TclError, TKINTER_LOADTK_ERRMSG);
  2558. return NULL;
  2559. }
  2560. #endif
  2561. /* We want to guard against calling Tk_Init() multiple times */
  2562. CHECK_TCL_APPARTMENT;
  2563. ENTER_TCL
  2564. err = Tcl_Eval(Tkapp_Interp(self), "info exists tk_version");
  2565. ENTER_OVERLAP
  2566. if (err == TCL_ERROR) {
  2567. /* This sets an exception, but we cannot return right
  2568. away because we need to exit the overlap first. */
  2569. Tkinter_Error((PyObject *)self);
  2570. } else {
  2571. _tk_exists = Tkapp_Result(self);
  2572. }
  2573. LEAVE_OVERLAP_TCL
  2574. if (err == TCL_ERROR) {
  2575. return NULL;
  2576. }
  2577. if (_tk_exists == NULL || strcmp(_tk_exists, "1") != 0) {
  2578. if (Tk_Init(interp) == TCL_ERROR) {
  2579. PyErr_SetString(Tkinter_TclError,
  2580. Tcl_GetStringResult(Tkapp_Interp(self)));
  2581. #ifdef TKINTER_PROTECT_LOADTK
  2582. tk_load_failed = 1;
  2583. #endif
  2584. return NULL;
  2585. }
  2586. }
  2587. Py_RETURN_NONE;
  2588. }
  2589. static PyObject *
  2590. Tkapp_WantObjects(PyObject *self, PyObject *args)
  2591. {
  2592. int wantobjects = -1;
  2593. if (!PyArg_ParseTuple(args, "|i:wantobjects", &wantobjects))
  2594. return NULL;
  2595. if (wantobjects == -1)
  2596. return PyBool_FromLong(((TkappObject*)self)->wantobjects);
  2597. ((TkappObject*)self)->wantobjects = wantobjects;
  2598. Py_RETURN_NONE;
  2599. }
  2600. /*[clinic input]
  2601. _tkinter.tkapp.willdispatch
  2602. self: self(type="TkappObject *")
  2603. [clinic start generated code]*/
  2604. static PyObject *
  2605. _tkinter_tkapp_willdispatch_impl(TkappObject *self)
  2606. /*[clinic end generated code: output=0e3f46d244642155 input=2630699767808970]*/
  2607. {
  2608. self->dispatching = 1;
  2609. Py_RETURN_NONE;
  2610. }
  2611. /**** Tkapp Type Methods ****/
  2612. static void
  2613. Tkapp_Dealloc(PyObject *self)
  2614. {
  2615. PyObject *tp = (PyObject *) Py_TYPE(self);
  2616. /*CHECK_TCL_APPARTMENT;*/
  2617. ENTER_TCL
  2618. Tcl_DeleteInterp(Tkapp_Interp(self));
  2619. LEAVE_TCL
  2620. PyObject_Del(self);
  2621. Py_DECREF(tp);
  2622. DisableEventHook();
  2623. }
  2624. /**** Tkinter Module ****/
  2625. typedef struct {
  2626. PyObject* tuple;
  2627. Py_ssize_t size; /* current size */
  2628. Py_ssize_t maxsize; /* allocated size */
  2629. } FlattenContext;
  2630. static int
  2631. _bump(FlattenContext* context, Py_ssize_t size)
  2632. {
  2633. /* expand tuple to hold (at least) size new items.
  2634. return true if successful, false if an exception was raised */
  2635. Py_ssize_t maxsize = context->maxsize * 2; /* never overflows */
  2636. if (maxsize < context->size + size)
  2637. maxsize = context->size + size; /* never overflows */
  2638. context->maxsize = maxsize;
  2639. return _PyTuple_Resize(&context->tuple, maxsize) >= 0;
  2640. }
  2641. static int
  2642. _flatten1(FlattenContext* context, PyObject* item, int depth)
  2643. {
  2644. /* add tuple or list to argument tuple (recursively) */
  2645. Py_ssize_t i, size;
  2646. if (depth > 1000) {
  2647. PyErr_SetString(PyExc_ValueError,
  2648. "nesting too deep in _flatten");
  2649. return 0;
  2650. } else if (PyTuple_Check(item) || PyList_Check(item)) {
  2651. size = PySequence_Fast_GET_SIZE(item);
  2652. /* preallocate (assume no nesting) */
  2653. if (context->size + size > context->maxsize &&
  2654. !_bump(context, size))
  2655. return 0;
  2656. /* copy items to output tuple */
  2657. for (i = 0; i < size; i++) {
  2658. PyObject *o = PySequence_Fast_GET_ITEM(item, i);
  2659. if (PyList_Check(o) || PyTuple_Check(o)) {
  2660. if (!_flatten1(context, o, depth + 1))
  2661. return 0;
  2662. } else if (o != Py_None) {
  2663. if (context->size + 1 > context->maxsize &&
  2664. !_bump(context, 1))
  2665. return 0;
  2666. Py_INCREF(o);
  2667. PyTuple_SET_ITEM(context->tuple,
  2668. context->size++, o);
  2669. }
  2670. }
  2671. } else {
  2672. PyErr_SetString(PyExc_TypeError, "argument must be sequence");
  2673. return 0;
  2674. }
  2675. return 1;
  2676. }
  2677. /*[clinic input]
  2678. _tkinter._flatten
  2679. item: object
  2680. /
  2681. [clinic start generated code]*/
  2682. static PyObject *
  2683. _tkinter__flatten(PyModuleDef *module, PyObject *item)
  2684. /*[clinic end generated code: output=9505049ec74c3480 input=6b9c12260aa1157f]*/
  2685. {
  2686. FlattenContext context;
  2687. context.maxsize = PySequence_Size(item);
  2688. if (context.maxsize < 0)
  2689. return NULL;
  2690. if (context.maxsize == 0)
  2691. return PyTuple_New(0);
  2692. context.tuple = PyTuple_New(context.maxsize);
  2693. if (!context.tuple)
  2694. return NULL;
  2695. context.size = 0;
  2696. if (!_flatten1(&context, item,0))
  2697. return NULL;
  2698. if (_PyTuple_Resize(&context.tuple, context.size))
  2699. return NULL;
  2700. return context.tuple;
  2701. }
  2702. /*[clinic input]
  2703. _tkinter.create
  2704. screenName: str(accept={str, NoneType}) = NULL
  2705. baseName: str = NULL
  2706. className: str = "Tk"
  2707. interactive: int(c_default="0") = False
  2708. wantobjects: int(c_default="0") = False
  2709. wantTk: int(c_default="1") = True
  2710. if false, then Tk_Init() doesn't get called
  2711. sync: int(c_default="0") = False
  2712. if true, then pass -sync to wish
  2713. use: str(accept={str, NoneType}) = NULL
  2714. if not None, then pass -use to wish
  2715. /
  2716. [clinic start generated code]*/
  2717. static PyObject *
  2718. _tkinter_create_impl(PyModuleDef *module, const char *screenName,
  2719. const char *baseName, const char *className,
  2720. int interactive, int wantobjects, int wantTk, int sync,
  2721. const char *use)
  2722. /*[clinic end generated code: output=b8847800fc3b27eb input=0d522aad1cb0ca0e]*/
  2723. {
  2724. /* XXX baseName is not used anymore;
  2725. * try getting rid of it. */
  2726. CHECK_STRING_LENGTH(screenName);
  2727. CHECK_STRING_LENGTH(baseName);
  2728. CHECK_STRING_LENGTH(className);
  2729. CHECK_STRING_LENGTH(use);
  2730. return (PyObject *) Tkapp_New(screenName, className,
  2731. interactive, wantobjects, wantTk,
  2732. sync, use);
  2733. }
  2734. /*[clinic input]
  2735. _tkinter.setbusywaitinterval
  2736. new_val: int
  2737. /
  2738. Set the busy-wait interval in milliseconds between successive calls to Tcl_DoOneEvent in a threaded Python interpreter.
  2739. It should be set to a divisor of the maximum time between frames in an animation.
  2740. [clinic start generated code]*/
  2741. static PyObject *
  2742. _tkinter_setbusywaitinterval_impl(PyModuleDef *module, int new_val)
  2743. /*[clinic end generated code: output=0b9d7ef7940461ea input=deca1d6f9e6dae47]*/
  2744. {
  2745. if (new_val < 0) {
  2746. PyErr_SetString(PyExc_ValueError,
  2747. "busywaitinterval must be >= 0");
  2748. return NULL;
  2749. }
  2750. Tkinter_busywaitinterval = new_val;
  2751. Py_RETURN_NONE;
  2752. }
  2753. /*[clinic input]
  2754. _tkinter.getbusywaitinterval -> int
  2755. Return the current busy-wait interval between successive calls to Tcl_DoOneEvent in a threaded Python interpreter.
  2756. [clinic start generated code]*/
  2757. static int
  2758. _tkinter_getbusywaitinterval_impl(PyModuleDef *module)
  2759. /*[clinic end generated code: output=9d09eee026e96971 input=a695878d2d576a84]*/
  2760. {
  2761. return Tkinter_busywaitinterval;
  2762. }
  2763. #include "clinic/_tkinter.c.h"
  2764. static PyMethodDef Tktt_methods[] =
  2765. {
  2766. _TKINTER_TKTIMERTOKEN_DELETETIMERHANDLER_METHODDEF
  2767. {NULL, NULL}
  2768. };
  2769. static PyType_Slot Tktt_Type_slots[] = {
  2770. {Py_tp_dealloc, Tktt_Dealloc},
  2771. {Py_tp_repr, Tktt_Repr},
  2772. {Py_tp_methods, Tktt_methods},
  2773. {0, 0}
  2774. };
  2775. static PyType_Spec Tktt_Type_spec = {
  2776. "_tkinter.tktimertoken",
  2777. sizeof(TkttObject),
  2778. 0,
  2779. Py_TPFLAGS_DEFAULT,
  2780. Tktt_Type_slots,
  2781. };
  2782. /**** Tkapp Method List ****/
  2783. static PyMethodDef Tkapp_methods[] =
  2784. {
  2785. _TKINTER_TKAPP_WILLDISPATCH_METHODDEF
  2786. {"wantobjects", Tkapp_WantObjects, METH_VARARGS},
  2787. {"call", Tkapp_Call, METH_VARARGS},
  2788. _TKINTER_TKAPP_EVAL_METHODDEF
  2789. _TKINTER_TKAPP_EVALFILE_METHODDEF
  2790. _TKINTER_TKAPP_RECORD_METHODDEF
  2791. _TKINTER_TKAPP_ADDERRINFO_METHODDEF
  2792. {"setvar", Tkapp_SetVar, METH_VARARGS},
  2793. {"globalsetvar", Tkapp_GlobalSetVar, METH_VARARGS},
  2794. {"getvar", Tkapp_GetVar, METH_VARARGS},
  2795. {"globalgetvar", Tkapp_GlobalGetVar, METH_VARARGS},
  2796. {"unsetvar", Tkapp_UnsetVar, METH_VARARGS},
  2797. {"globalunsetvar", Tkapp_GlobalUnsetVar, METH_VARARGS},
  2798. _TKINTER_TKAPP_GETINT_METHODDEF
  2799. _TKINTER_TKAPP_GETDOUBLE_METHODDEF
  2800. _TKINTER_TKAPP_GETBOOLEAN_METHODDEF
  2801. _TKINTER_TKAPP_EXPRSTRING_METHODDEF
  2802. _TKINTER_TKAPP_EXPRLONG_METHODDEF
  2803. _TKINTER_TKAPP_EXPRDOUBLE_METHODDEF
  2804. _TKINTER_TKAPP_EXPRBOOLEAN_METHODDEF
  2805. _TKINTER_TKAPP_SPLITLIST_METHODDEF
  2806. _TKINTER_TKAPP_SPLIT_METHODDEF
  2807. _TKINTER_TKAPP_CREATECOMMAND_METHODDEF
  2808. _TKINTER_TKAPP_DELETECOMMAND_METHODDEF
  2809. _TKINTER_TKAPP_CREATEFILEHANDLER_METHODDEF
  2810. _TKINTER_TKAPP_DELETEFILEHANDLER_METHODDEF
  2811. _TKINTER_TKAPP_CREATETIMERHANDLER_METHODDEF
  2812. _TKINTER_TKAPP_MAINLOOP_METHODDEF
  2813. _TKINTER_TKAPP_DOONEEVENT_METHODDEF
  2814. _TKINTER_TKAPP_QUIT_METHODDEF
  2815. _TKINTER_TKAPP_INTERPADDR_METHODDEF
  2816. _TKINTER_TKAPP_LOADTK_METHODDEF
  2817. {NULL, NULL}
  2818. };
  2819. static PyType_Slot Tkapp_Type_slots[] = {
  2820. {Py_tp_dealloc, Tkapp_Dealloc},
  2821. {Py_tp_methods, Tkapp_methods},
  2822. {0, 0}
  2823. };
  2824. static PyType_Spec Tkapp_Type_spec = {
  2825. "_tkinter.tkapp",
  2826. sizeof(TkappObject),
  2827. 0,
  2828. Py_TPFLAGS_DEFAULT,
  2829. Tkapp_Type_slots,
  2830. };
  2831. static PyMethodDef moduleMethods[] =
  2832. {
  2833. _TKINTER__FLATTEN_METHODDEF
  2834. _TKINTER_CREATE_METHODDEF
  2835. _TKINTER_SETBUSYWAITINTERVAL_METHODDEF
  2836. _TKINTER_GETBUSYWAITINTERVAL_METHODDEF
  2837. {NULL, NULL}
  2838. };
  2839. #ifdef WAIT_FOR_STDIN
  2840. static int stdin_ready = 0;
  2841. #ifndef MS_WINDOWS
  2842. static void
  2843. MyFileProc(void *clientData, int mask)
  2844. {
  2845. stdin_ready = 1;
  2846. }
  2847. #endif
  2848. #ifdef WITH_THREAD
  2849. static PyThreadState *event_tstate = NULL;
  2850. #endif
  2851. static int
  2852. EventHook(void)
  2853. {
  2854. #ifndef MS_WINDOWS
  2855. int tfile;
  2856. #endif
  2857. #ifdef WITH_THREAD
  2858. PyEval_RestoreThread(event_tstate);
  2859. #endif
  2860. stdin_ready = 0;
  2861. errorInCmd = 0;
  2862. #ifndef MS_WINDOWS
  2863. tfile = fileno(stdin);
  2864. Tcl_CreateFileHandler(tfile, TCL_READABLE, MyFileProc, NULL);
  2865. #endif
  2866. while (!errorInCmd && !stdin_ready) {
  2867. int result;
  2868. #ifdef MS_WINDOWS
  2869. if (_kbhit()) {
  2870. stdin_ready = 1;
  2871. break;
  2872. }
  2873. #endif
  2874. #if defined(WITH_THREAD) || defined(MS_WINDOWS)
  2875. Py_BEGIN_ALLOW_THREADS
  2876. if(tcl_lock)PyThread_acquire_lock(tcl_lock, 1);
  2877. tcl_tstate = event_tstate;
  2878. result = Tcl_DoOneEvent(TCL_DONT_WAIT);
  2879. tcl_tstate = NULL;
  2880. if(tcl_lock)PyThread_release_lock(tcl_lock);
  2881. if (result == 0)
  2882. Sleep(Tkinter_busywaitinterval);
  2883. Py_END_ALLOW_THREADS
  2884. #else
  2885. result = Tcl_DoOneEvent(0);
  2886. #endif
  2887. if (result < 0)
  2888. break;
  2889. }
  2890. #ifndef MS_WINDOWS
  2891. Tcl_DeleteFileHandler(tfile);
  2892. #endif
  2893. if (errorInCmd) {
  2894. errorInCmd = 0;
  2895. PyErr_Restore(excInCmd, valInCmd, trbInCmd);
  2896. excInCmd = valInCmd = trbInCmd = NULL;
  2897. PyErr_Print();
  2898. }
  2899. #ifdef WITH_THREAD
  2900. PyEval_SaveThread();
  2901. #endif
  2902. return 0;
  2903. }
  2904. #endif
  2905. static void
  2906. EnableEventHook(void)
  2907. {
  2908. #ifdef WAIT_FOR_STDIN
  2909. if (PyOS_InputHook == NULL) {
  2910. #ifdef WITH_THREAD
  2911. event_tstate = PyThreadState_Get();
  2912. #endif
  2913. PyOS_InputHook = EventHook;
  2914. }
  2915. #endif
  2916. }
  2917. static void
  2918. DisableEventHook(void)
  2919. {
  2920. #ifdef WAIT_FOR_STDIN
  2921. if (Tk_GetNumMainWindows() == 0 && PyOS_InputHook == EventHook) {
  2922. PyOS_InputHook = NULL;
  2923. }
  2924. #endif
  2925. }
  2926. static struct PyModuleDef _tkintermodule = {
  2927. PyModuleDef_HEAD_INIT,
  2928. "_tkinter",
  2929. NULL,
  2930. -1,
  2931. moduleMethods,
  2932. NULL,
  2933. NULL,
  2934. NULL,
  2935. NULL
  2936. };
  2937. PyMODINIT_FUNC
  2938. PyInit__tkinter(void)
  2939. {
  2940. PyObject *m, *uexe, *cexe, *o;
  2941. #ifdef WITH_THREAD
  2942. tcl_lock = PyThread_allocate_lock();
  2943. if (tcl_lock == NULL)
  2944. return NULL;
  2945. #endif
  2946. m = PyModule_Create(&_tkintermodule);
  2947. if (m == NULL)
  2948. return NULL;
  2949. o = PyErr_NewException("_tkinter.TclError", NULL, NULL);
  2950. if (o == NULL) {
  2951. Py_DECREF(m);
  2952. return NULL;
  2953. }
  2954. Py_INCREF(o);
  2955. if (PyModule_AddObject(m, "TclError", o)) {
  2956. Py_DECREF(o);
  2957. Py_DECREF(m);
  2958. return NULL;
  2959. }
  2960. Tkinter_TclError = o;
  2961. if (PyModule_AddIntConstant(m, "READABLE", TCL_READABLE)) {
  2962. Py_DECREF(m);
  2963. return NULL;
  2964. }
  2965. if (PyModule_AddIntConstant(m, "WRITABLE", TCL_WRITABLE)) {
  2966. Py_DECREF(m);
  2967. return NULL;
  2968. }
  2969. if (PyModule_AddIntConstant(m, "EXCEPTION", TCL_EXCEPTION)) {
  2970. Py_DECREF(m);
  2971. return NULL;
  2972. }
  2973. if (PyModule_AddIntConstant(m, "WINDOW_EVENTS", TCL_WINDOW_EVENTS)) {
  2974. Py_DECREF(m);
  2975. return NULL;
  2976. }
  2977. if (PyModule_AddIntConstant(m, "FILE_EVENTS", TCL_FILE_EVENTS)) {
  2978. Py_DECREF(m);
  2979. return NULL;
  2980. }
  2981. if (PyModule_AddIntConstant(m, "TIMER_EVENTS", TCL_TIMER_EVENTS)) {
  2982. Py_DECREF(m);
  2983. return NULL;
  2984. }
  2985. if (PyModule_AddIntConstant(m, "IDLE_EVENTS", TCL_IDLE_EVENTS)) {
  2986. Py_DECREF(m);
  2987. return NULL;
  2988. }
  2989. if (PyModule_AddIntConstant(m, "ALL_EVENTS", TCL_ALL_EVENTS)) {
  2990. Py_DECREF(m);
  2991. return NULL;
  2992. }
  2993. if (PyModule_AddIntConstant(m, "DONT_WAIT", TCL_DONT_WAIT)) {
  2994. Py_DECREF(m);
  2995. return NULL;
  2996. }
  2997. if (PyModule_AddStringConstant(m, "TK_VERSION", TK_VERSION)) {
  2998. Py_DECREF(m);
  2999. return NULL;
  3000. }
  3001. if (PyModule_AddStringConstant(m, "TCL_VERSION", TCL_VERSION)) {
  3002. Py_DECREF(m);
  3003. return NULL;
  3004. }
  3005. o = PyType_FromSpec(&Tkapp_Type_spec);
  3006. if (o == NULL) {
  3007. Py_DECREF(m);
  3008. return NULL;
  3009. }
  3010. if (PyModule_AddObject(m, "TkappType", o)) {
  3011. Py_DECREF(o);
  3012. Py_DECREF(m);
  3013. return NULL;
  3014. }
  3015. Tkapp_Type = o;
  3016. o = PyType_FromSpec(&Tktt_Type_spec);
  3017. if (o == NULL) {
  3018. Py_DECREF(m);
  3019. return NULL;
  3020. }
  3021. if (PyModule_AddObject(m, "TkttType", o)) {
  3022. Py_DECREF(o);
  3023. Py_DECREF(m);
  3024. return NULL;
  3025. }
  3026. Tktt_Type = o;
  3027. o = PyType_FromSpec(&PyTclObject_Type_spec);
  3028. if (o == NULL) {
  3029. Py_DECREF(m);
  3030. return NULL;
  3031. }
  3032. if (PyModule_AddObject(m, "Tcl_Obj", o)) {
  3033. Py_DECREF(o);
  3034. Py_DECREF(m);
  3035. return NULL;
  3036. }
  3037. PyTclObject_Type = o;
  3038. #ifdef TK_AQUA
  3039. /* Tk_MacOSXSetupTkNotifier must be called before Tcl's subsystems
  3040. * start waking up. Note that Tcl_FindExecutable will do this, this
  3041. * code must be above it! The original warning from
  3042. * tkMacOSXAppInit.c is copied below.
  3043. *
  3044. * NB - You have to swap in the Tk Notifier BEFORE you start up the
  3045. * Tcl interpreter for now. It probably should work to do this
  3046. * in the other order, but for now it doesn't seem to.
  3047. *
  3048. */
  3049. Tk_MacOSXSetupTkNotifier();
  3050. #endif
  3051. /* This helps the dynamic loader; in Unicode aware Tcl versions
  3052. it also helps Tcl find its encodings. */
  3053. uexe = PyUnicode_FromWideChar(Py_GetProgramName(), -1);
  3054. if (uexe) {
  3055. cexe = PyUnicode_EncodeFSDefault(uexe);
  3056. if (cexe) {
  3057. #ifdef MS_WINDOWS
  3058. int set_var = 0;
  3059. PyObject *str_path;
  3060. wchar_t *wcs_path;
  3061. DWORD ret;
  3062. ret = GetEnvironmentVariableW(L"TCL_LIBRARY", NULL, 0);
  3063. if (!ret && GetLastError() == ERROR_ENVVAR_NOT_FOUND) {
  3064. str_path = _get_tcl_lib_path();
  3065. if (str_path == NULL && PyErr_Occurred()) {
  3066. return NULL;
  3067. }
  3068. if (str_path != NULL) {
  3069. wcs_path = PyUnicode_AsWideCharString(str_path, NULL);
  3070. if (wcs_path == NULL) {
  3071. return NULL;
  3072. }
  3073. SetEnvironmentVariableW(L"TCL_LIBRARY", wcs_path);
  3074. set_var = 1;
  3075. }
  3076. }
  3077. Tcl_FindExecutable(PyBytes_AsString(cexe));
  3078. if (set_var) {
  3079. SetEnvironmentVariableW(L"TCL_LIBRARY", NULL);
  3080. PyMem_Free(wcs_path);
  3081. }
  3082. #else
  3083. Tcl_FindExecutable(PyBytes_AsString(cexe));
  3084. #endif /* MS_WINDOWS */
  3085. }
  3086. Py_XDECREF(cexe);
  3087. Py_DECREF(uexe);
  3088. }
  3089. if (PyErr_Occurred()) {
  3090. Py_DECREF(m);
  3091. return NULL;
  3092. }
  3093. #if 0
  3094. /* This was not a good idea; through <Destroy> bindings,
  3095. Tcl_Finalize() may invoke Python code but at that point the
  3096. interpreter and thread state have already been destroyed! */
  3097. Py_AtExit(Tcl_Finalize);
  3098. #endif
  3099. return m;
  3100. }