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.

3653 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_SET_ITEM(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_GET_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_GET_ITEM(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_GET_ITEM(arg, k);
  413. Py_INCREF(elem);
  414. PyTuple_SET_ITEM(result, k, elem);
  415. }
  416. }
  417. PyTuple_SET_ITEM(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_SET_ITEM(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_AS_STRING(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_AS_STRING(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_AS_STRING(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 const 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 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. if (sizeof(wideValue) <= SIZEOF_LONG_LONG)
  1012. return PyLong_FromLongLong(wideValue);
  1013. return _PyLong_FromByteArray((unsigned char *)(void *)&wideValue,
  1014. sizeof(wideValue),
  1015. PY_LITTLE_ENDIAN,
  1016. /* signed */ 1);
  1017. }
  1018. return NULL;
  1019. }
  1020. #ifdef HAVE_LIBTOMMAMTH
  1021. static PyObject*
  1022. fromBignumObj(PyObject* tkapp, Tcl_Obj *value)
  1023. {
  1024. mp_int bigValue;
  1025. unsigned long numBytes;
  1026. unsigned char *bytes;
  1027. PyObject *res;
  1028. if (Tcl_GetBignumFromObj(Tkapp_Interp(tkapp), value, &bigValue) != TCL_OK)
  1029. return Tkinter_Error(tkapp);
  1030. numBytes = mp_unsigned_bin_size(&bigValue);
  1031. bytes = PyMem_Malloc(numBytes);
  1032. if (bytes == NULL) {
  1033. mp_clear(&bigValue);
  1034. return PyErr_NoMemory();
  1035. }
  1036. if (mp_to_unsigned_bin_n(&bigValue, bytes,
  1037. &numBytes) != MP_OKAY) {
  1038. mp_clear(&bigValue);
  1039. PyMem_Free(bytes);
  1040. return PyErr_NoMemory();
  1041. }
  1042. res = _PyLong_FromByteArray(bytes, numBytes,
  1043. /* big-endian */ 0,
  1044. /* unsigned */ 0);
  1045. PyMem_Free(bytes);
  1046. if (res != NULL && bigValue.sign == MP_NEG) {
  1047. PyObject *res2 = PyNumber_Negative(res);
  1048. Py_DECREF(res);
  1049. res = res2;
  1050. }
  1051. mp_clear(&bigValue);
  1052. return res;
  1053. }
  1054. #endif
  1055. static PyObject*
  1056. FromObj(PyObject* tkapp, Tcl_Obj *value)
  1057. {
  1058. PyObject *result = NULL;
  1059. TkappObject *app = (TkappObject*)tkapp;
  1060. Tcl_Interp *interp = Tkapp_Interp(tkapp);
  1061. if (value->typePtr == NULL) {
  1062. return unicodeFromTclStringAndSize(value->bytes, value->length);
  1063. }
  1064. if (value->typePtr == app->BooleanType ||
  1065. value->typePtr == app->OldBooleanType) {
  1066. return fromBoolean(tkapp, value);
  1067. }
  1068. if (value->typePtr == app->ByteArrayType) {
  1069. int size;
  1070. char *data = (char*)Tcl_GetByteArrayFromObj(value, &size);
  1071. return PyBytes_FromStringAndSize(data, size);
  1072. }
  1073. if (value->typePtr == app->DoubleType) {
  1074. return PyFloat_FromDouble(value->internalRep.doubleValue);
  1075. }
  1076. if (value->typePtr == app->IntType) {
  1077. long longValue;
  1078. if (Tcl_GetLongFromObj(interp, value, &longValue) == TCL_OK)
  1079. return PyLong_FromLong(longValue);
  1080. /* If there is an error in the long conversion,
  1081. fall through to wideInt handling. */
  1082. }
  1083. if (value->typePtr == app->IntType ||
  1084. value->typePtr == app->WideIntType) {
  1085. result = fromWideIntObj(tkapp, value);
  1086. if (result != NULL || PyErr_Occurred())
  1087. return result;
  1088. Tcl_ResetResult(interp);
  1089. /* If there is an error in the wideInt conversion,
  1090. fall through to bignum handling. */
  1091. }
  1092. #ifdef HAVE_LIBTOMMAMTH
  1093. if (value->typePtr == app->IntType ||
  1094. value->typePtr == app->WideIntType ||
  1095. value->typePtr == app->BignumType) {
  1096. return fromBignumObj(tkapp, value);
  1097. }
  1098. #endif
  1099. if (value->typePtr == app->ListType) {
  1100. int size;
  1101. int i, status;
  1102. PyObject *elem;
  1103. Tcl_Obj *tcl_elem;
  1104. status = Tcl_ListObjLength(interp, value, &size);
  1105. if (status == TCL_ERROR)
  1106. return Tkinter_Error(tkapp);
  1107. result = PyTuple_New(size);
  1108. if (!result)
  1109. return NULL;
  1110. for (i = 0; i < size; i++) {
  1111. status = Tcl_ListObjIndex(interp, value, i, &tcl_elem);
  1112. if (status == TCL_ERROR) {
  1113. Py_DECREF(result);
  1114. return Tkinter_Error(tkapp);
  1115. }
  1116. elem = FromObj(tkapp, tcl_elem);
  1117. if (!elem) {
  1118. Py_DECREF(result);
  1119. return NULL;
  1120. }
  1121. PyTuple_SET_ITEM(result, i, elem);
  1122. }
  1123. return result;
  1124. }
  1125. if (value->typePtr == app->ProcBodyType) {
  1126. /* fall through: return tcl object. */
  1127. }
  1128. if (value->typePtr == app->StringType) {
  1129. return PyUnicode_FromKindAndData(
  1130. sizeof(Tcl_UniChar), Tcl_GetUnicode(value),
  1131. Tcl_GetCharLength(value));
  1132. }
  1133. #if TK_HEX_VERSION >= 0x08050000
  1134. if (app->BooleanType == NULL &&
  1135. strcmp(value->typePtr->name, "booleanString") == 0) {
  1136. /* booleanString type is not registered in Tcl */
  1137. app->BooleanType = value->typePtr;
  1138. return fromBoolean(tkapp, value);
  1139. }
  1140. #endif
  1141. #ifdef HAVE_LIBTOMMAMTH
  1142. if (app->BignumType == NULL &&
  1143. strcmp(value->typePtr->name, "bignum") == 0) {
  1144. /* bignum type is not registered in Tcl */
  1145. app->BignumType = value->typePtr;
  1146. return fromBignumObj(tkapp, value);
  1147. }
  1148. #endif
  1149. return newPyTclObject(value);
  1150. }
  1151. #ifdef WITH_THREAD
  1152. /* This mutex synchronizes inter-thread command calls. */
  1153. TCL_DECLARE_MUTEX(call_mutex)
  1154. typedef struct Tkapp_CallEvent {
  1155. Tcl_Event ev; /* Must be first */
  1156. TkappObject *self;
  1157. PyObject *args;
  1158. int flags;
  1159. PyObject **res;
  1160. PyObject **exc_type, **exc_value, **exc_tb;
  1161. Tcl_Condition *done;
  1162. } Tkapp_CallEvent;
  1163. #endif
  1164. void
  1165. Tkapp_CallDeallocArgs(Tcl_Obj** objv, Tcl_Obj** objStore, int objc)
  1166. {
  1167. int i;
  1168. for (i = 0; i < objc; i++)
  1169. Tcl_DecrRefCount(objv[i]);
  1170. if (objv != objStore)
  1171. PyMem_Free(objv);
  1172. }
  1173. /* Convert Python objects to Tcl objects. This must happen in the
  1174. interpreter thread, which may or may not be the calling thread. */
  1175. static Tcl_Obj**
  1176. Tkapp_CallArgs(PyObject *args, Tcl_Obj** objStore, int *pobjc)
  1177. {
  1178. Tcl_Obj **objv = objStore;
  1179. Py_ssize_t objc = 0, i;
  1180. if (args == NULL)
  1181. /* do nothing */;
  1182. else if (!(PyTuple_Check(args) || PyList_Check(args))) {
  1183. objv[0] = AsObj(args);
  1184. if (objv[0] == 0)
  1185. goto finally;
  1186. objc = 1;
  1187. Tcl_IncrRefCount(objv[0]);
  1188. }
  1189. else {
  1190. objc = PySequence_Fast_GET_SIZE(args);
  1191. if (objc > ARGSZ) {
  1192. if (!CHECK_SIZE(objc, sizeof(Tcl_Obj *))) {
  1193. PyErr_SetString(PyExc_OverflowError,
  1194. PyTuple_Check(args) ? "tuple is too long" :
  1195. "list is too long");
  1196. return NULL;
  1197. }
  1198. objv = (Tcl_Obj **)PyMem_Malloc(((size_t)objc) * sizeof(Tcl_Obj *));
  1199. if (objv == NULL) {
  1200. PyErr_NoMemory();
  1201. objc = 0;
  1202. goto finally;
  1203. }
  1204. }
  1205. for (i = 0; i < objc; i++) {
  1206. PyObject *v = PySequence_Fast_GET_ITEM(args, i);
  1207. if (v == Py_None) {
  1208. objc = i;
  1209. break;
  1210. }
  1211. objv[i] = AsObj(v);
  1212. if (!objv[i]) {
  1213. /* Reset objc, so it attempts to clear
  1214. objects only up to i. */
  1215. objc = i;
  1216. goto finally;
  1217. }
  1218. Tcl_IncrRefCount(objv[i]);
  1219. }
  1220. }
  1221. *pobjc = (int)objc;
  1222. return objv;
  1223. finally:
  1224. Tkapp_CallDeallocArgs(objv, objStore, (int)objc);
  1225. return NULL;
  1226. }
  1227. /* Convert the results of a command call into a Python objects. */
  1228. static PyObject*
  1229. Tkapp_CallResult(TkappObject *self)
  1230. {
  1231. PyObject *res = NULL;
  1232. Tcl_Obj *value = Tcl_GetObjResult(self->interp);
  1233. if(self->wantobjects) {
  1234. /* Not sure whether the IncrRef is necessary, but something
  1235. may overwrite the interpreter result while we are
  1236. converting it. */
  1237. Tcl_IncrRefCount(value);
  1238. res = FromObj((PyObject*)self, value);
  1239. Tcl_DecrRefCount(value);
  1240. } else {
  1241. res = unicodeFromTclObj(value);
  1242. }
  1243. return res;
  1244. }
  1245. #ifdef WITH_THREAD
  1246. /* Tkapp_CallProc is the event procedure that is executed in the context of
  1247. the Tcl interpreter thread. Initially, it holds the Tcl lock, and doesn't
  1248. hold the Python lock. */
  1249. static int
  1250. Tkapp_CallProc(Tkapp_CallEvent *e, int flags)
  1251. {
  1252. Tcl_Obj *objStore[ARGSZ];
  1253. Tcl_Obj **objv;
  1254. int objc;
  1255. int i;
  1256. ENTER_PYTHON
  1257. objv = Tkapp_CallArgs(e->args, objStore, &objc);
  1258. if (!objv) {
  1259. PyErr_Fetch(e->exc_type, e->exc_value, e->exc_tb);
  1260. *(e->res) = NULL;
  1261. }
  1262. LEAVE_PYTHON
  1263. if (!objv)
  1264. goto done;
  1265. i = Tcl_EvalObjv(e->self->interp, objc, objv, e->flags);
  1266. ENTER_PYTHON
  1267. if (i == TCL_ERROR) {
  1268. *(e->res) = NULL;
  1269. *(e->exc_type) = NULL;
  1270. *(e->exc_tb) = NULL;
  1271. *(e->exc_value) = PyObject_CallFunction(
  1272. Tkinter_TclError, "s",
  1273. Tcl_GetStringResult(e->self->interp));
  1274. }
  1275. else {
  1276. *(e->res) = Tkapp_CallResult(e->self);
  1277. }
  1278. LEAVE_PYTHON
  1279. Tkapp_CallDeallocArgs(objv, objStore, objc);
  1280. done:
  1281. /* Wake up calling thread. */
  1282. Tcl_MutexLock(&call_mutex);
  1283. Tcl_ConditionNotify(e->done);
  1284. Tcl_MutexUnlock(&call_mutex);
  1285. return 1;
  1286. }
  1287. #endif
  1288. /* This is the main entry point for calling a Tcl command.
  1289. It supports three cases, with regard to threading:
  1290. 1. Tcl is not threaded: Must have the Tcl lock, then can invoke command in
  1291. the context of the calling thread.
  1292. 2. Tcl is threaded, caller of the command is in the interpreter thread:
  1293. Execute the command in the calling thread. Since the Tcl lock will
  1294. not be used, we can merge that with case 1.
  1295. 3. Tcl is threaded, caller is in a different thread: Must queue an event to
  1296. the interpreter thread. Allocation of Tcl objects needs to occur in the
  1297. interpreter thread, so we ship the PyObject* args to the target thread,
  1298. and perform processing there. */
  1299. static PyObject *
  1300. Tkapp_Call(PyObject *selfptr, PyObject *args)
  1301. {
  1302. Tcl_Obj *objStore[ARGSZ];
  1303. Tcl_Obj **objv = NULL;
  1304. int objc, i;
  1305. PyObject *res = NULL;
  1306. TkappObject *self = (TkappObject*)selfptr;
  1307. int flags = TCL_EVAL_DIRECT | TCL_EVAL_GLOBAL;
  1308. /* If args is a single tuple, replace with contents of tuple */
  1309. if (PyTuple_GET_SIZE(args) == 1) {
  1310. PyObject *item = PyTuple_GET_ITEM(args, 0);
  1311. if (PyTuple_Check(item))
  1312. args = item;
  1313. }
  1314. #ifdef WITH_THREAD
  1315. if (self->threaded && self->thread_id != Tcl_GetCurrentThread()) {
  1316. /* We cannot call the command directly. Instead, we must
  1317. marshal the parameters to the interpreter thread. */
  1318. Tkapp_CallEvent *ev;
  1319. Tcl_Condition cond = NULL;
  1320. PyObject *exc_type, *exc_value, *exc_tb;
  1321. if (!WaitForMainloop(self))
  1322. return NULL;
  1323. ev = (Tkapp_CallEvent*)attemptckalloc(sizeof(Tkapp_CallEvent));
  1324. if (ev == NULL) {
  1325. PyErr_NoMemory();
  1326. return NULL;
  1327. }
  1328. ev->ev.proc = (Tcl_EventProc*)Tkapp_CallProc;
  1329. ev->self = self;
  1330. ev->args = args;
  1331. ev->res = &res;
  1332. ev->exc_type = &exc_type;
  1333. ev->exc_value = &exc_value;
  1334. ev->exc_tb = &exc_tb;
  1335. ev->done = &cond;
  1336. Tkapp_ThreadSend(self, (Tcl_Event*)ev, &cond, &call_mutex);
  1337. if (res == NULL) {
  1338. if (exc_type)
  1339. PyErr_Restore(exc_type, exc_value, exc_tb);
  1340. else
  1341. PyErr_SetObject(Tkinter_TclError, exc_value);
  1342. }
  1343. Tcl_ConditionFinalize(&cond);
  1344. }
  1345. else
  1346. #endif
  1347. {
  1348. objv = Tkapp_CallArgs(args, objStore, &objc);
  1349. if (!objv)
  1350. return NULL;
  1351. ENTER_TCL
  1352. i = Tcl_EvalObjv(self->interp, objc, objv, flags);
  1353. ENTER_OVERLAP
  1354. if (i == TCL_ERROR)
  1355. Tkinter_Error(selfptr);
  1356. else
  1357. res = Tkapp_CallResult(self);
  1358. LEAVE_OVERLAP_TCL
  1359. Tkapp_CallDeallocArgs(objv, objStore, objc);
  1360. }
  1361. return res;
  1362. }
  1363. /*[clinic input]
  1364. _tkinter.tkapp.eval
  1365. script: str
  1366. /
  1367. [clinic start generated code]*/
  1368. static PyObject *
  1369. _tkinter_tkapp_eval_impl(TkappObject *self, const char *script)
  1370. /*[clinic end generated code: output=24b79831f700dea0 input=481484123a455f22]*/
  1371. {
  1372. PyObject *res = NULL;
  1373. int err;
  1374. CHECK_STRING_LENGTH(script);
  1375. CHECK_TCL_APPARTMENT;
  1376. ENTER_TCL
  1377. err = Tcl_Eval(Tkapp_Interp(self), script);
  1378. ENTER_OVERLAP
  1379. if (err == TCL_ERROR)
  1380. res = Tkinter_Error((PyObject *)self);
  1381. else
  1382. res = unicodeFromTclString(Tkapp_Result(self));
  1383. LEAVE_OVERLAP_TCL
  1384. return res;
  1385. }
  1386. /*[clinic input]
  1387. _tkinter.tkapp.evalfile
  1388. fileName: str
  1389. /
  1390. [clinic start generated code]*/
  1391. static PyObject *
  1392. _tkinter_tkapp_evalfile_impl(TkappObject *self, const char *fileName)
  1393. /*[clinic end generated code: output=63be88dcee4f11d3 input=873ab707e5e947e1]*/
  1394. {
  1395. PyObject *res = NULL;
  1396. int err;
  1397. CHECK_STRING_LENGTH(fileName);
  1398. CHECK_TCL_APPARTMENT;
  1399. ENTER_TCL
  1400. err = Tcl_EvalFile(Tkapp_Interp(self), fileName);
  1401. ENTER_OVERLAP
  1402. if (err == TCL_ERROR)
  1403. res = Tkinter_Error((PyObject *)self);
  1404. else
  1405. res = unicodeFromTclString(Tkapp_Result(self));
  1406. LEAVE_OVERLAP_TCL
  1407. return res;
  1408. }
  1409. /*[clinic input]
  1410. _tkinter.tkapp.record
  1411. script: str
  1412. /
  1413. [clinic start generated code]*/
  1414. static PyObject *
  1415. _tkinter_tkapp_record_impl(TkappObject *self, const char *script)
  1416. /*[clinic end generated code: output=0ffe08a0061730df input=c0b0db5a21412cac]*/
  1417. {
  1418. PyObject *res = NULL;
  1419. int err;
  1420. CHECK_STRING_LENGTH(script);
  1421. CHECK_TCL_APPARTMENT;
  1422. ENTER_TCL
  1423. err = Tcl_RecordAndEval(Tkapp_Interp(self), script, TCL_NO_EVAL);
  1424. ENTER_OVERLAP
  1425. if (err == TCL_ERROR)
  1426. res = Tkinter_Error((PyObject *)self);
  1427. else
  1428. res = unicodeFromTclString(Tkapp_Result(self));
  1429. LEAVE_OVERLAP_TCL
  1430. return res;
  1431. }
  1432. /*[clinic input]
  1433. _tkinter.tkapp.adderrinfo
  1434. msg: str
  1435. /
  1436. [clinic start generated code]*/
  1437. static PyObject *
  1438. _tkinter_tkapp_adderrinfo_impl(TkappObject *self, const char *msg)
  1439. /*[clinic end generated code: output=0e222ee2050eb357 input=4971399317d4c136]*/
  1440. {
  1441. CHECK_STRING_LENGTH(msg);
  1442. CHECK_TCL_APPARTMENT;
  1443. ENTER_TCL
  1444. Tcl_AddErrorInfo(Tkapp_Interp(self), msg);
  1445. LEAVE_TCL
  1446. Py_RETURN_NONE;
  1447. }
  1448. /** Tcl Variable **/
  1449. typedef PyObject* (*EventFunc)(PyObject*, PyObject *args, int flags);
  1450. #ifdef WITH_THREAD
  1451. TCL_DECLARE_MUTEX(var_mutex)
  1452. typedef struct VarEvent {
  1453. Tcl_Event ev; /* must be first */
  1454. PyObject *self;
  1455. PyObject *args;
  1456. int flags;
  1457. EventFunc func;
  1458. PyObject **res;
  1459. PyObject **exc_type;
  1460. PyObject **exc_val;
  1461. Tcl_Condition *cond;
  1462. } VarEvent;
  1463. #endif
  1464. /*[python]
  1465. class varname_converter(CConverter):
  1466. type = 'const char *'
  1467. converter = 'varname_converter'
  1468. [python]*/
  1469. /*[python checksum: da39a3ee5e6b4b0d3255bfef95601890afd80709]*/
  1470. static int
  1471. varname_converter(PyObject *in, void *_out)
  1472. {
  1473. char *s;
  1474. const char **out = (const char**)_out;
  1475. if (PyBytes_Check(in)) {
  1476. if (PyBytes_GET_SIZE(in) > INT_MAX) {
  1477. PyErr_SetString(PyExc_OverflowError, "bytes object is too long");
  1478. return 0;
  1479. }
  1480. s = PyBytes_AS_STRING(in);
  1481. if (strlen(s) != (size_t)PyBytes_GET_SIZE(in)) {
  1482. PyErr_SetString(PyExc_ValueError, "embedded null byte");
  1483. return 0;
  1484. }
  1485. *out = s;
  1486. return 1;
  1487. }
  1488. if (PyUnicode_Check(in)) {
  1489. Py_ssize_t size;
  1490. s = PyUnicode_AsUTF8AndSize(in, &size);
  1491. if (s == NULL) {
  1492. return 0;
  1493. }
  1494. if (size > INT_MAX) {
  1495. PyErr_SetString(PyExc_OverflowError, "string is too long");
  1496. return 0;
  1497. }
  1498. if (strlen(s) != (size_t)size) {
  1499. PyErr_SetString(PyExc_ValueError, "embedded null character");
  1500. return 0;
  1501. }
  1502. *out = s;
  1503. return 1;
  1504. }
  1505. if (PyTclObject_Check(in)) {
  1506. *out = PyTclObject_TclString(in);
  1507. return 1;
  1508. }
  1509. PyErr_Format(PyExc_TypeError,
  1510. "must be str, bytes or Tcl_Obj, not %.50s",
  1511. in->ob_type->tp_name);
  1512. return 0;
  1513. }
  1514. #ifdef WITH_THREAD
  1515. static void
  1516. var_perform(VarEvent *ev)
  1517. {
  1518. *(ev->res) = ev->func(ev->self, ev->args, ev->flags);
  1519. if (!*(ev->res)) {
  1520. PyObject *exc, *val, *tb;
  1521. PyErr_Fetch(&exc, &val, &tb);
  1522. PyErr_NormalizeException(&exc, &val, &tb);
  1523. *(ev->exc_type) = exc;
  1524. *(ev->exc_val) = val;
  1525. Py_DECREF(tb);
  1526. }
  1527. }
  1528. static int
  1529. var_proc(VarEvent* ev, int flags)
  1530. {
  1531. ENTER_PYTHON
  1532. var_perform(ev);
  1533. Tcl_MutexLock(&var_mutex);
  1534. Tcl_ConditionNotify(ev->cond);
  1535. Tcl_MutexUnlock(&var_mutex);
  1536. LEAVE_PYTHON
  1537. return 1;
  1538. }
  1539. #endif
  1540. static PyObject*
  1541. var_invoke(EventFunc func, PyObject *selfptr, PyObject *args, int flags)
  1542. {
  1543. #ifdef WITH_THREAD
  1544. TkappObject *self = (TkappObject*)selfptr;
  1545. if (self->threaded && self->thread_id != Tcl_GetCurrentThread()) {
  1546. VarEvent *ev;
  1547. PyObject *res, *exc_type, *exc_val;
  1548. Tcl_Condition cond = NULL;
  1549. /* The current thread is not the interpreter thread. Marshal
  1550. the call to the interpreter thread, then wait for
  1551. completion. */
  1552. if (!WaitForMainloop(self))
  1553. return NULL;
  1554. ev = (VarEvent*)attemptckalloc(sizeof(VarEvent));
  1555. if (ev == NULL) {
  1556. PyErr_NoMemory();
  1557. return NULL;
  1558. }
  1559. ev->self = selfptr;
  1560. ev->args = args;
  1561. ev->flags = flags;
  1562. ev->func = func;
  1563. ev->res = &res;
  1564. ev->exc_type = &exc_type;
  1565. ev->exc_val = &exc_val;
  1566. ev->cond = &cond;
  1567. ev->ev.proc = (Tcl_EventProc*)var_proc;
  1568. Tkapp_ThreadSend(self, (Tcl_Event*)ev, &cond, &var_mutex);
  1569. Tcl_ConditionFinalize(&cond);
  1570. if (!res) {
  1571. PyErr_SetObject(exc_type, exc_val);
  1572. Py_DECREF(exc_type);
  1573. Py_DECREF(exc_val);
  1574. return NULL;
  1575. }
  1576. return res;
  1577. }
  1578. #endif
  1579. /* Tcl is not threaded, or this is the interpreter thread. */
  1580. return func(selfptr, args, flags);
  1581. }
  1582. static PyObject *
  1583. SetVar(PyObject *self, PyObject *args, int flags)
  1584. {
  1585. const char *name1, *name2;
  1586. PyObject *newValue;
  1587. PyObject *res = NULL;
  1588. Tcl_Obj *newval, *ok;
  1589. switch (PyTuple_GET_SIZE(args)) {
  1590. case 2:
  1591. if (!PyArg_ParseTuple(args, "O&O:setvar",
  1592. varname_converter, &name1, &newValue))
  1593. return NULL;
  1594. /* XXX Acquire tcl lock??? */
  1595. newval = AsObj(newValue);
  1596. if (newval == NULL)
  1597. return NULL;
  1598. ENTER_TCL
  1599. ok = Tcl_SetVar2Ex(Tkapp_Interp(self), name1, NULL,
  1600. newval, flags);
  1601. ENTER_OVERLAP
  1602. if (!ok)
  1603. Tkinter_Error(self);
  1604. else {
  1605. res = Py_None;
  1606. Py_INCREF(res);
  1607. }
  1608. LEAVE_OVERLAP_TCL
  1609. break;
  1610. case 3:
  1611. if (!PyArg_ParseTuple(args, "ssO:setvar",
  1612. &name1, &name2, &newValue))
  1613. return NULL;
  1614. CHECK_STRING_LENGTH(name1);
  1615. CHECK_STRING_LENGTH(name2);
  1616. /* XXX must hold tcl lock already??? */
  1617. newval = AsObj(newValue);
  1618. ENTER_TCL
  1619. ok = Tcl_SetVar2Ex(Tkapp_Interp(self), name1, name2, newval, flags);
  1620. ENTER_OVERLAP
  1621. if (!ok)
  1622. Tkinter_Error(self);
  1623. else {
  1624. res = Py_None;
  1625. Py_INCREF(res);
  1626. }
  1627. LEAVE_OVERLAP_TCL
  1628. break;
  1629. default:
  1630. PyErr_SetString(PyExc_TypeError, "setvar requires 2 to 3 arguments");
  1631. return NULL;
  1632. }
  1633. return res;
  1634. }
  1635. static PyObject *
  1636. Tkapp_SetVar(PyObject *self, PyObject *args)
  1637. {
  1638. return var_invoke(SetVar, self, args, TCL_LEAVE_ERR_MSG);
  1639. }
  1640. static PyObject *
  1641. Tkapp_GlobalSetVar(PyObject *self, PyObject *args)
  1642. {
  1643. return var_invoke(SetVar, self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY);
  1644. }
  1645. static PyObject *
  1646. GetVar(PyObject *self, PyObject *args, int flags)
  1647. {
  1648. const char *name1, *name2=NULL;
  1649. PyObject *res = NULL;
  1650. Tcl_Obj *tres;
  1651. if (!PyArg_ParseTuple(args, "O&|s:getvar",
  1652. varname_converter, &name1, &name2))
  1653. return NULL;
  1654. CHECK_STRING_LENGTH(name2);
  1655. ENTER_TCL
  1656. tres = Tcl_GetVar2Ex(Tkapp_Interp(self), name1, name2, flags);
  1657. ENTER_OVERLAP
  1658. if (tres == NULL) {
  1659. PyErr_SetString(Tkinter_TclError,
  1660. Tcl_GetStringResult(Tkapp_Interp(self)));
  1661. } else {
  1662. if (((TkappObject*)self)->wantobjects) {
  1663. res = FromObj(self, tres);
  1664. }
  1665. else {
  1666. res = unicodeFromTclObj(tres);
  1667. }
  1668. }
  1669. LEAVE_OVERLAP_TCL
  1670. return res;
  1671. }
  1672. static PyObject *
  1673. Tkapp_GetVar(PyObject *self, PyObject *args)
  1674. {
  1675. return var_invoke(GetVar, self, args, TCL_LEAVE_ERR_MSG);
  1676. }
  1677. static PyObject *
  1678. Tkapp_GlobalGetVar(PyObject *self, PyObject *args)
  1679. {
  1680. return var_invoke(GetVar, self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY);
  1681. }
  1682. static PyObject *
  1683. UnsetVar(PyObject *self, PyObject *args, int flags)
  1684. {
  1685. char *name1, *name2=NULL;
  1686. int code;
  1687. PyObject *res = NULL;
  1688. if (!PyArg_ParseTuple(args, "s|s:unsetvar", &name1, &name2))
  1689. return NULL;
  1690. CHECK_STRING_LENGTH(name1);
  1691. CHECK_STRING_LENGTH(name2);
  1692. ENTER_TCL
  1693. code = Tcl_UnsetVar2(Tkapp_Interp(self), name1, name2, flags);
  1694. ENTER_OVERLAP
  1695. if (code == TCL_ERROR)
  1696. res = Tkinter_Error(self);
  1697. else {
  1698. Py_INCREF(Py_None);
  1699. res = Py_None;
  1700. }
  1701. LEAVE_OVERLAP_TCL
  1702. return res;
  1703. }
  1704. static PyObject *
  1705. Tkapp_UnsetVar(PyObject *self, PyObject *args)
  1706. {
  1707. return var_invoke(UnsetVar, self, args, TCL_LEAVE_ERR_MSG);
  1708. }
  1709. static PyObject *
  1710. Tkapp_GlobalUnsetVar(PyObject *self, PyObject *args)
  1711. {
  1712. return var_invoke(UnsetVar, self, args,
  1713. TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY);
  1714. }
  1715. /** Tcl to Python **/
  1716. /*[clinic input]
  1717. _tkinter.tkapp.getint
  1718. arg: object
  1719. /
  1720. [clinic start generated code]*/
  1721. static PyObject *
  1722. _tkinter_tkapp_getint(TkappObject *self, PyObject *arg)
  1723. /*[clinic end generated code: output=88cf293fae307cfe input=034026997c5b91f8]*/
  1724. {
  1725. char *s;
  1726. Tcl_Obj *value;
  1727. PyObject *result;
  1728. if (PyLong_Check(arg)) {
  1729. Py_INCREF(arg);
  1730. return arg;
  1731. }
  1732. if (PyTclObject_Check(arg)) {
  1733. value = ((PyTclObject*)arg)->value;
  1734. Tcl_IncrRefCount(value);
  1735. }
  1736. else {
  1737. if (!PyArg_Parse(arg, "s:getint", &s))
  1738. return NULL;
  1739. CHECK_STRING_LENGTH(s);
  1740. value = Tcl_NewStringObj(s, -1);
  1741. if (value == NULL)
  1742. return Tkinter_Error((PyObject *)self);
  1743. }
  1744. /* Don't use Tcl_GetInt() because it returns ambiguous result for value
  1745. in ranges -2**32..-2**31-1 and 2**31..2**32-1 (on 32-bit platform).
  1746. Prefer bignum because Tcl_GetWideIntFromObj returns ambiguous result for
  1747. value in ranges -2**64..-2**63-1 and 2**63..2**64-1 (on 32-bit platform).
  1748. */
  1749. #ifdef HAVE_LIBTOMMAMTH
  1750. result = fromBignumObj((PyObject *)self, value);
  1751. #else
  1752. result = fromWideIntObj((PyObject *)self, value);
  1753. #endif
  1754. Tcl_DecrRefCount(value);
  1755. if (result != NULL || PyErr_Occurred())
  1756. return result;
  1757. return Tkinter_Error((PyObject *)self);
  1758. }
  1759. /*[clinic input]
  1760. _tkinter.tkapp.getdouble
  1761. arg: object
  1762. /
  1763. [clinic start generated code]*/
  1764. static PyObject *
  1765. _tkinter_tkapp_getdouble(TkappObject *self, PyObject *arg)
  1766. /*[clinic end generated code: output=c52b138bd8b956b9 input=22015729ce9ef7f8]*/
  1767. {
  1768. char *s;
  1769. double v;
  1770. if (PyFloat_Check(arg)) {
  1771. Py_INCREF(arg);
  1772. return arg;
  1773. }
  1774. if (PyNumber_Check(arg)) {
  1775. return PyNumber_Float(arg);
  1776. }
  1777. if (PyTclObject_Check(arg)) {
  1778. if (Tcl_GetDoubleFromObj(Tkapp_Interp(self),
  1779. ((PyTclObject*)arg)->value,
  1780. &v) == TCL_ERROR)
  1781. return Tkinter_Error((PyObject *)self);
  1782. return PyFloat_FromDouble(v);
  1783. }
  1784. if (!PyArg_Parse(arg, "s:getdouble", &s))
  1785. return NULL;
  1786. CHECK_STRING_LENGTH(s);
  1787. if (Tcl_GetDouble(Tkapp_Interp(self), s, &v) == TCL_ERROR)
  1788. return Tkinter_Error((PyObject *)self);
  1789. return PyFloat_FromDouble(v);
  1790. }
  1791. /*[clinic input]
  1792. _tkinter.tkapp.getboolean
  1793. arg: object
  1794. /
  1795. [clinic start generated code]*/
  1796. static PyObject *
  1797. _tkinter_tkapp_getboolean(TkappObject *self, PyObject *arg)
  1798. /*[clinic end generated code: output=726a9ae445821d91 input=7f11248ef8f8776e]*/
  1799. {
  1800. char *s;
  1801. int v;
  1802. if (PyLong_Check(arg)) { /* int or bool */
  1803. return PyBool_FromLong(Py_SIZE(arg) != 0);
  1804. }
  1805. if (PyTclObject_Check(arg)) {
  1806. if (Tcl_GetBooleanFromObj(Tkapp_Interp(self),
  1807. ((PyTclObject*)arg)->value,
  1808. &v) == TCL_ERROR)
  1809. return Tkinter_Error((PyObject *)self);
  1810. return PyBool_FromLong(v);
  1811. }
  1812. if (!PyArg_Parse(arg, "s:getboolean", &s))
  1813. return NULL;
  1814. CHECK_STRING_LENGTH(s);
  1815. if (Tcl_GetBoolean(Tkapp_Interp(self), s, &v) == TCL_ERROR)
  1816. return Tkinter_Error((PyObject *)self);
  1817. return PyBool_FromLong(v);
  1818. }
  1819. /*[clinic input]
  1820. _tkinter.tkapp.exprstring
  1821. s: str
  1822. /
  1823. [clinic start generated code]*/
  1824. static PyObject *
  1825. _tkinter_tkapp_exprstring_impl(TkappObject *self, const char *s)
  1826. /*[clinic end generated code: output=beda323d3ed0abb1 input=fa78f751afb2f21b]*/
  1827. {
  1828. PyObject *res = NULL;
  1829. int retval;
  1830. CHECK_STRING_LENGTH(s);
  1831. CHECK_TCL_APPARTMENT;
  1832. ENTER_TCL
  1833. retval = Tcl_ExprString(Tkapp_Interp(self), s);
  1834. ENTER_OVERLAP
  1835. if (retval == TCL_ERROR)
  1836. res = Tkinter_Error((PyObject *)self);
  1837. else
  1838. res = unicodeFromTclString(Tkapp_Result(self));
  1839. LEAVE_OVERLAP_TCL
  1840. return res;
  1841. }
  1842. /*[clinic input]
  1843. _tkinter.tkapp.exprlong
  1844. s: str
  1845. /
  1846. [clinic start generated code]*/
  1847. static PyObject *
  1848. _tkinter_tkapp_exprlong_impl(TkappObject *self, const char *s)
  1849. /*[clinic end generated code: output=5d6a46b63c6ebcf9 input=11bd7eee0c57b4dc]*/
  1850. {
  1851. PyObject *res = NULL;
  1852. int retval;
  1853. long v;
  1854. CHECK_STRING_LENGTH(s);
  1855. CHECK_TCL_APPARTMENT;
  1856. ENTER_TCL
  1857. retval = Tcl_ExprLong(Tkapp_Interp(self), s, &v);
  1858. ENTER_OVERLAP
  1859. if (retval == TCL_ERROR)
  1860. res = Tkinter_Error((PyObject *)self);
  1861. else
  1862. res = PyLong_FromLong(v);
  1863. LEAVE_OVERLAP_TCL
  1864. return res;
  1865. }
  1866. /*[clinic input]
  1867. _tkinter.tkapp.exprdouble
  1868. s: str
  1869. /
  1870. [clinic start generated code]*/
  1871. static PyObject *
  1872. _tkinter_tkapp_exprdouble_impl(TkappObject *self, const char *s)
  1873. /*[clinic end generated code: output=ff78df1081ea4158 input=ff02bc11798832d5]*/
  1874. {
  1875. PyObject *res = NULL;
  1876. double v;
  1877. int retval;
  1878. CHECK_STRING_LENGTH(s);
  1879. CHECK_TCL_APPARTMENT;
  1880. PyFPE_START_PROTECT("Tkapp_ExprDouble", return 0)
  1881. ENTER_TCL
  1882. retval = Tcl_ExprDouble(Tkapp_Interp(self), s, &v);
  1883. ENTER_OVERLAP
  1884. PyFPE_END_PROTECT(retval)
  1885. if (retval == TCL_ERROR)
  1886. res = Tkinter_Error((PyObject *)self);
  1887. else
  1888. res = PyFloat_FromDouble(v);
  1889. LEAVE_OVERLAP_TCL
  1890. return res;
  1891. }
  1892. /*[clinic input]
  1893. _tkinter.tkapp.exprboolean
  1894. s: str
  1895. /
  1896. [clinic start generated code]*/
  1897. static PyObject *
  1898. _tkinter_tkapp_exprboolean_impl(TkappObject *self, const char *s)
  1899. /*[clinic end generated code: output=8b28038c22887311 input=c8c66022bdb8d5d3]*/
  1900. {
  1901. PyObject *res = NULL;
  1902. int retval;
  1903. int v;
  1904. CHECK_STRING_LENGTH(s);
  1905. CHECK_TCL_APPARTMENT;
  1906. ENTER_TCL
  1907. retval = Tcl_ExprBoolean(Tkapp_Interp(self), s, &v);
  1908. ENTER_OVERLAP
  1909. if (retval == TCL_ERROR)
  1910. res = Tkinter_Error((PyObject *)self);
  1911. else
  1912. res = PyLong_FromLong(v);
  1913. LEAVE_OVERLAP_TCL
  1914. return res;
  1915. }
  1916. /*[clinic input]
  1917. _tkinter.tkapp.splitlist
  1918. arg: object
  1919. /
  1920. [clinic start generated code]*/
  1921. static PyObject *
  1922. _tkinter_tkapp_splitlist(TkappObject *self, PyObject *arg)
  1923. /*[clinic end generated code: output=13b51d34386d36fb input=2b2e13351e3c0b53]*/
  1924. {
  1925. char *list;
  1926. int argc;
  1927. const char **argv;
  1928. PyObject *v;
  1929. int i;
  1930. if (PyTclObject_Check(arg)) {
  1931. int objc;
  1932. Tcl_Obj **objv;
  1933. if (Tcl_ListObjGetElements(Tkapp_Interp(self),
  1934. ((PyTclObject*)arg)->value,
  1935. &objc, &objv) == TCL_ERROR) {
  1936. return Tkinter_Error((PyObject *)self);
  1937. }
  1938. if (!(v = PyTuple_New(objc)))
  1939. return NULL;
  1940. for (i = 0; i < objc; i++) {
  1941. PyObject *s = FromObj((PyObject*)self, objv[i]);
  1942. if (!s) {
  1943. Py_DECREF(v);
  1944. return NULL;
  1945. }
  1946. PyTuple_SET_ITEM(v, i, s);
  1947. }
  1948. return v;
  1949. }
  1950. if (PyTuple_Check(arg)) {
  1951. Py_INCREF(arg);
  1952. return arg;
  1953. }
  1954. if (PyList_Check(arg)) {
  1955. return PySequence_Tuple(arg);
  1956. }
  1957. if (!PyArg_Parse(arg, "et:splitlist", "utf-8", &list))
  1958. return NULL;
  1959. CHECK_STRING_LENGTH(list);
  1960. if (Tcl_SplitList(Tkapp_Interp(self), list,
  1961. &argc, &argv) == TCL_ERROR) {
  1962. PyMem_Free(list);
  1963. return Tkinter_Error((PyObject *)self);
  1964. }
  1965. if (!(v = PyTuple_New(argc)))
  1966. goto finally;
  1967. for (i = 0; i < argc; i++) {
  1968. PyObject *s = unicodeFromTclString(argv[i]);
  1969. if (!s) {
  1970. Py_DECREF(v);
  1971. v = NULL;
  1972. goto finally;
  1973. }
  1974. PyTuple_SET_ITEM(v, i, s);
  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) {
  2010. Py_DECREF(v);
  2011. return NULL;
  2012. }
  2013. PyTuple_SET_ITEM(v, i, s);
  2014. }
  2015. return v;
  2016. }
  2017. if (PyTuple_Check(arg) || PyList_Check(arg))
  2018. return SplitObj(arg);
  2019. if (!PyArg_Parse(arg, "et:split", "utf-8", &list))
  2020. return NULL;
  2021. CHECK_STRING_LENGTH(list);
  2022. v = Split(list);
  2023. PyMem_Free(list);
  2024. return v;
  2025. }
  2026. /** Tcl Command **/
  2027. /* Client data struct */
  2028. typedef struct {
  2029. PyObject *self;
  2030. PyObject *func;
  2031. } PythonCmd_ClientData;
  2032. static int
  2033. PythonCmd_Error(Tcl_Interp *interp)
  2034. {
  2035. errorInCmd = 1;
  2036. PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd);
  2037. LEAVE_PYTHON
  2038. return TCL_ERROR;
  2039. }
  2040. /* This is the Tcl command that acts as a wrapper for Python
  2041. * function or method.
  2042. */
  2043. static int
  2044. PythonCmd(ClientData clientData, Tcl_Interp *interp, int argc, const char *argv[])
  2045. {
  2046. PythonCmd_ClientData *data = (PythonCmd_ClientData *)clientData;
  2047. PyObject *func, *arg, *res;
  2048. int i, rv;
  2049. Tcl_Obj *obj_res;
  2050. ENTER_PYTHON
  2051. /* TBD: no error checking here since we know, via the
  2052. * Tkapp_CreateCommand() that the client data is a two-tuple
  2053. */
  2054. func = data->func;
  2055. /* Create argument list (argv1, ..., argvN) */
  2056. if (!(arg = PyTuple_New(argc - 1)))
  2057. return PythonCmd_Error(interp);
  2058. for (i = 0; i < (argc - 1); i++) {
  2059. PyObject *s = unicodeFromTclString(argv[i + 1]);
  2060. if (!s) {
  2061. Py_DECREF(arg);
  2062. return PythonCmd_Error(interp);
  2063. }
  2064. PyTuple_SET_ITEM(arg, i, s);
  2065. }
  2066. res = PyEval_CallObject(func, arg);
  2067. Py_DECREF(arg);
  2068. if (res == NULL)
  2069. return PythonCmd_Error(interp);
  2070. obj_res = AsObj(res);
  2071. if (obj_res == NULL) {
  2072. Py_DECREF(res);
  2073. return PythonCmd_Error(interp);
  2074. }
  2075. else {
  2076. Tcl_SetObjResult(interp, obj_res);
  2077. rv = TCL_OK;
  2078. }
  2079. Py_DECREF(res);
  2080. LEAVE_PYTHON
  2081. return rv;
  2082. }
  2083. static void
  2084. PythonCmdDelete(ClientData clientData)
  2085. {
  2086. PythonCmd_ClientData *data = (PythonCmd_ClientData *)clientData;
  2087. ENTER_PYTHON
  2088. Py_XDECREF(data->self);
  2089. Py_XDECREF(data->func);
  2090. PyMem_DEL(data);
  2091. LEAVE_PYTHON
  2092. }
  2093. #ifdef WITH_THREAD
  2094. TCL_DECLARE_MUTEX(command_mutex)
  2095. typedef struct CommandEvent{
  2096. Tcl_Event ev;
  2097. Tcl_Interp* interp;
  2098. const char *name;
  2099. int create;
  2100. int *status;
  2101. ClientData *data;
  2102. Tcl_Condition *done;
  2103. } CommandEvent;
  2104. static int
  2105. Tkapp_CommandProc(CommandEvent *ev, int flags)
  2106. {
  2107. if (ev->create)
  2108. *ev->status = Tcl_CreateCommand(
  2109. ev->interp, ev->name, PythonCmd,
  2110. ev->data, PythonCmdDelete) == NULL;
  2111. else
  2112. *ev->status = Tcl_DeleteCommand(ev->interp, ev->name);
  2113. Tcl_MutexLock(&command_mutex);
  2114. Tcl_ConditionNotify(ev->done);
  2115. Tcl_MutexUnlock(&command_mutex);
  2116. return 1;
  2117. }
  2118. #endif
  2119. /*[clinic input]
  2120. _tkinter.tkapp.createcommand
  2121. name: str
  2122. func: object
  2123. /
  2124. [clinic start generated code]*/
  2125. static PyObject *
  2126. _tkinter_tkapp_createcommand_impl(TkappObject *self, const char *name,
  2127. PyObject *func)
  2128. /*[clinic end generated code: output=2a1c79a4ee2af410 input=255785cb70edc6a0]*/
  2129. {
  2130. PythonCmd_ClientData *data;
  2131. int err;
  2132. CHECK_STRING_LENGTH(name);
  2133. if (!PyCallable_Check(func)) {
  2134. PyErr_SetString(PyExc_TypeError, "command not callable");
  2135. return NULL;
  2136. }
  2137. #ifdef WITH_THREAD
  2138. if (self->threaded && self->thread_id != Tcl_GetCurrentThread() &&
  2139. !WaitForMainloop(self))
  2140. return NULL;
  2141. #endif
  2142. data = PyMem_NEW(PythonCmd_ClientData, 1);
  2143. if (!data)
  2144. return PyErr_NoMemory();
  2145. Py_INCREF(self);
  2146. Py_INCREF(func);
  2147. data->self = (PyObject *) self;
  2148. data->func = func;
  2149. #ifdef WITH_THREAD
  2150. if (self->threaded && self->thread_id != Tcl_GetCurrentThread()) {
  2151. Tcl_Condition cond = NULL;
  2152. CommandEvent *ev = (CommandEvent*)attemptckalloc(sizeof(CommandEvent));
  2153. if (ev == NULL) {
  2154. PyErr_NoMemory();
  2155. PyMem_DEL(data);
  2156. return NULL;
  2157. }
  2158. ev->ev.proc = (Tcl_EventProc*)Tkapp_CommandProc;
  2159. ev->interp = self->interp;
  2160. ev->create = 1;
  2161. ev->name = name;
  2162. ev->data = (ClientData)data;
  2163. ev->status = &err;
  2164. ev->done = &cond;
  2165. Tkapp_ThreadSend(self, (Tcl_Event*)ev, &cond, &command_mutex);
  2166. Tcl_ConditionFinalize(&cond);
  2167. }
  2168. else
  2169. #endif
  2170. {
  2171. ENTER_TCL
  2172. err = Tcl_CreateCommand(
  2173. Tkapp_Interp(self), name, PythonCmd,
  2174. (ClientData)data, PythonCmdDelete) == NULL;
  2175. LEAVE_TCL
  2176. }
  2177. if (err) {
  2178. PyErr_SetString(Tkinter_TclError, "can't create Tcl command");
  2179. PyMem_DEL(data);
  2180. return NULL;
  2181. }
  2182. Py_RETURN_NONE;
  2183. }
  2184. /*[clinic input]
  2185. _tkinter.tkapp.deletecommand
  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=53e9952eae1f85f5]*/
  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. [clinic start generated code]*/
  2349. static PyObject *
  2350. _tkinter_tktimertoken_deletetimerhandler_impl(TkttObject *self)
  2351. /*[clinic end generated code: output=bd7fe17f328cfa55 input=40bd070ff85f5cf3]*/
  2352. {
  2353. TkttObject *v = self;
  2354. PyObject *func = v->func;
  2355. if (v->token != NULL) {
  2356. Tcl_DeleteTimerHandler(v->token);
  2357. v->token = NULL;
  2358. }
  2359. if (func != NULL) {
  2360. v->func = NULL;
  2361. Py_DECREF(func);
  2362. Py_DECREF(v); /* See Tktt_New() */
  2363. }
  2364. Py_RETURN_NONE;
  2365. }
  2366. static TkttObject *
  2367. Tktt_New(PyObject *func)
  2368. {
  2369. TkttObject *v;
  2370. v = PyObject_New(TkttObject, (PyTypeObject *) Tktt_Type);
  2371. if (v == NULL)
  2372. return NULL;
  2373. Py_INCREF(Tktt_Type);
  2374. Py_INCREF(func);
  2375. v->token = NULL;
  2376. v->func = func;
  2377. /* Extra reference, deleted when called or when handler is deleted */
  2378. Py_INCREF(v);
  2379. return v;
  2380. }
  2381. static void
  2382. Tktt_Dealloc(PyObject *self)
  2383. {
  2384. TkttObject *v = (TkttObject *)self;
  2385. PyObject *func = v->func;
  2386. PyObject *tp = (PyObject *) Py_TYPE(self);
  2387. Py_XDECREF(func);
  2388. PyObject_Del(self);
  2389. Py_DECREF(tp);
  2390. }
  2391. static PyObject *
  2392. Tktt_Repr(PyObject *self)
  2393. {
  2394. TkttObject *v = (TkttObject *)self;
  2395. return PyUnicode_FromFormat("<tktimertoken at %p%s>",
  2396. v,
  2397. v->func == NULL ? ", handler deleted" : "");
  2398. }
  2399. /** Timer Handler **/
  2400. static void
  2401. TimerHandler(ClientData clientData)
  2402. {
  2403. TkttObject *v = (TkttObject *)clientData;
  2404. PyObject *func = v->func;
  2405. PyObject *res;
  2406. if (func == NULL)
  2407. return;
  2408. v->func = NULL;
  2409. ENTER_PYTHON
  2410. res = PyEval_CallObject(func, NULL);
  2411. Py_DECREF(func);
  2412. Py_DECREF(v); /* See Tktt_New() */
  2413. if (res == NULL) {
  2414. errorInCmd = 1;
  2415. PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd);
  2416. }
  2417. else
  2418. Py_DECREF(res);
  2419. LEAVE_PYTHON
  2420. }
  2421. /*[clinic input]
  2422. _tkinter.tkapp.createtimerhandler
  2423. milliseconds: int
  2424. func: object
  2425. /
  2426. [clinic start generated code]*/
  2427. static PyObject *
  2428. _tkinter_tkapp_createtimerhandler_impl(TkappObject *self, int milliseconds,
  2429. PyObject *func)
  2430. /*[clinic end generated code: output=2da5959b9d031911 input=ba6729f32f0277a5]*/
  2431. {
  2432. TkttObject *v;
  2433. if (!PyCallable_Check(func)) {
  2434. PyErr_SetString(PyExc_TypeError, "bad argument list");
  2435. return NULL;
  2436. }
  2437. CHECK_TCL_APPARTMENT;
  2438. v = Tktt_New(func);
  2439. if (v) {
  2440. v->token = Tcl_CreateTimerHandler(milliseconds, TimerHandler,
  2441. (ClientData)v);
  2442. }
  2443. return (PyObject *) v;
  2444. }
  2445. /** Event Loop **/
  2446. /*[clinic input]
  2447. _tkinter.tkapp.mainloop
  2448. threshold: int = 0
  2449. /
  2450. [clinic start generated code]*/
  2451. static PyObject *
  2452. _tkinter_tkapp_mainloop_impl(TkappObject *self, int threshold)
  2453. /*[clinic end generated code: output=0ba8eabbe57841b0 input=036bcdcf03d5eca0]*/
  2454. {
  2455. #ifdef WITH_THREAD
  2456. PyThreadState *tstate = PyThreadState_Get();
  2457. #endif
  2458. CHECK_TCL_APPARTMENT;
  2459. self->dispatching = 1;
  2460. quitMainLoop = 0;
  2461. while (Tk_GetNumMainWindows() > threshold &&
  2462. !quitMainLoop &&
  2463. !errorInCmd)
  2464. {
  2465. int result;
  2466. #ifdef WITH_THREAD
  2467. if (self->threaded) {
  2468. /* Allow other Python threads to run. */
  2469. ENTER_TCL
  2470. result = Tcl_DoOneEvent(0);
  2471. LEAVE_TCL
  2472. }
  2473. else {
  2474. Py_BEGIN_ALLOW_THREADS
  2475. if(tcl_lock)PyThread_acquire_lock(tcl_lock, 1);
  2476. tcl_tstate = tstate;
  2477. result = Tcl_DoOneEvent(TCL_DONT_WAIT);
  2478. tcl_tstate = NULL;
  2479. if(tcl_lock)PyThread_release_lock(tcl_lock);
  2480. if (result == 0)
  2481. Sleep(Tkinter_busywaitinterval);
  2482. Py_END_ALLOW_THREADS
  2483. }
  2484. #else
  2485. result = Tcl_DoOneEvent(0);
  2486. #endif
  2487. if (PyErr_CheckSignals() != 0) {
  2488. self->dispatching = 0;
  2489. return NULL;
  2490. }
  2491. if (result < 0)
  2492. break;
  2493. }
  2494. self->dispatching = 0;
  2495. quitMainLoop = 0;
  2496. if (errorInCmd) {
  2497. errorInCmd = 0;
  2498. PyErr_Restore(excInCmd, valInCmd, trbInCmd);
  2499. excInCmd = valInCmd = trbInCmd = NULL;
  2500. return NULL;
  2501. }
  2502. Py_RETURN_NONE;
  2503. }
  2504. /*[clinic input]
  2505. _tkinter.tkapp.dooneevent
  2506. flags: int = 0
  2507. /
  2508. [clinic start generated code]*/
  2509. static PyObject *
  2510. _tkinter_tkapp_dooneevent_impl(TkappObject *self, int flags)
  2511. /*[clinic end generated code: output=27c6b2aa464cac29 input=6542b928e364b793]*/
  2512. {
  2513. int rv;
  2514. ENTER_TCL
  2515. rv = Tcl_DoOneEvent(flags);
  2516. LEAVE_TCL
  2517. return PyLong_FromLong(rv);
  2518. }
  2519. /*[clinic input]
  2520. _tkinter.tkapp.quit
  2521. [clinic start generated code]*/
  2522. static PyObject *
  2523. _tkinter_tkapp_quit_impl(TkappObject *self)
  2524. /*[clinic end generated code: output=7f21eeff481f754f input=e03020dc38aff23c]*/
  2525. {
  2526. quitMainLoop = 1;
  2527. Py_RETURN_NONE;
  2528. }
  2529. /*[clinic input]
  2530. _tkinter.tkapp.interpaddr
  2531. [clinic start generated code]*/
  2532. static PyObject *
  2533. _tkinter_tkapp_interpaddr_impl(TkappObject *self)
  2534. /*[clinic end generated code: output=6caaae3273b3c95a input=2dd32cbddb55a111]*/
  2535. {
  2536. return PyLong_FromVoidPtr(Tkapp_Interp(self));
  2537. }
  2538. /*[clinic input]
  2539. _tkinter.tkapp.loadtk
  2540. [clinic start generated code]*/
  2541. static PyObject *
  2542. _tkinter_tkapp_loadtk_impl(TkappObject *self)
  2543. /*[clinic end generated code: output=e9e10a954ce46d2a input=b5e82afedd6354f0]*/
  2544. {
  2545. Tcl_Interp *interp = Tkapp_Interp(self);
  2546. const char * _tk_exists = NULL;
  2547. int err;
  2548. #ifdef TKINTER_PROTECT_LOADTK
  2549. /* Up to Tk 8.4.13, Tk_Init deadlocks on the second call when the
  2550. * first call failed.
  2551. * To avoid the deadlock, we just refuse the second call through
  2552. * a static variable.
  2553. */
  2554. if (tk_load_failed) {
  2555. PyErr_SetString(Tkinter_TclError, TKINTER_LOADTK_ERRMSG);
  2556. return NULL;
  2557. }
  2558. #endif
  2559. /* We want to guard against calling Tk_Init() multiple times */
  2560. CHECK_TCL_APPARTMENT;
  2561. ENTER_TCL
  2562. err = Tcl_Eval(Tkapp_Interp(self), "info exists tk_version");
  2563. ENTER_OVERLAP
  2564. if (err == TCL_ERROR) {
  2565. /* This sets an exception, but we cannot return right
  2566. away because we need to exit the overlap first. */
  2567. Tkinter_Error((PyObject *)self);
  2568. } else {
  2569. _tk_exists = Tkapp_Result(self);
  2570. }
  2571. LEAVE_OVERLAP_TCL
  2572. if (err == TCL_ERROR) {
  2573. return NULL;
  2574. }
  2575. if (_tk_exists == NULL || strcmp(_tk_exists, "1") != 0) {
  2576. if (Tk_Init(interp) == TCL_ERROR) {
  2577. PyErr_SetString(Tkinter_TclError,
  2578. Tcl_GetStringResult(Tkapp_Interp(self)));
  2579. #ifdef TKINTER_PROTECT_LOADTK
  2580. tk_load_failed = 1;
  2581. #endif
  2582. return NULL;
  2583. }
  2584. }
  2585. Py_RETURN_NONE;
  2586. }
  2587. static PyObject *
  2588. Tkapp_WantObjects(PyObject *self, PyObject *args)
  2589. {
  2590. int wantobjects = -1;
  2591. if (!PyArg_ParseTuple(args, "|i:wantobjects", &wantobjects))
  2592. return NULL;
  2593. if (wantobjects == -1)
  2594. return PyBool_FromLong(((TkappObject*)self)->wantobjects);
  2595. ((TkappObject*)self)->wantobjects = wantobjects;
  2596. Py_RETURN_NONE;
  2597. }
  2598. /*[clinic input]
  2599. _tkinter.tkapp.willdispatch
  2600. [clinic start generated code]*/
  2601. static PyObject *
  2602. _tkinter_tkapp_willdispatch_impl(TkappObject *self)
  2603. /*[clinic end generated code: output=0e3f46d244642155 input=d88f5970843d6dab]*/
  2604. {
  2605. self->dispatching = 1;
  2606. Py_RETURN_NONE;
  2607. }
  2608. /**** Tkapp Type Methods ****/
  2609. static void
  2610. Tkapp_Dealloc(PyObject *self)
  2611. {
  2612. PyObject *tp = (PyObject *) Py_TYPE(self);
  2613. /*CHECK_TCL_APPARTMENT;*/
  2614. ENTER_TCL
  2615. Tcl_DeleteInterp(Tkapp_Interp(self));
  2616. LEAVE_TCL
  2617. PyObject_Del(self);
  2618. Py_DECREF(tp);
  2619. DisableEventHook();
  2620. }
  2621. /**** Tkinter Module ****/
  2622. typedef struct {
  2623. PyObject* tuple;
  2624. Py_ssize_t size; /* current size */
  2625. Py_ssize_t maxsize; /* allocated size */
  2626. } FlattenContext;
  2627. static int
  2628. _bump(FlattenContext* context, Py_ssize_t size)
  2629. {
  2630. /* expand tuple to hold (at least) size new items.
  2631. return true if successful, false if an exception was raised */
  2632. Py_ssize_t maxsize = context->maxsize * 2; /* never overflows */
  2633. if (maxsize < context->size + size)
  2634. maxsize = context->size + size; /* never overflows */
  2635. context->maxsize = maxsize;
  2636. return _PyTuple_Resize(&context->tuple, maxsize) >= 0;
  2637. }
  2638. static int
  2639. _flatten1(FlattenContext* context, PyObject* item, int depth)
  2640. {
  2641. /* add tuple or list to argument tuple (recursively) */
  2642. Py_ssize_t i, size;
  2643. if (depth > 1000) {
  2644. PyErr_SetString(PyExc_ValueError,
  2645. "nesting too deep in _flatten");
  2646. return 0;
  2647. } else if (PyTuple_Check(item) || PyList_Check(item)) {
  2648. size = PySequence_Fast_GET_SIZE(item);
  2649. /* preallocate (assume no nesting) */
  2650. if (context->size + size > context->maxsize &&
  2651. !_bump(context, size))
  2652. return 0;
  2653. /* copy items to output tuple */
  2654. for (i = 0; i < size; i++) {
  2655. PyObject *o = PySequence_Fast_GET_ITEM(item, i);
  2656. if (PyList_Check(o) || PyTuple_Check(o)) {
  2657. if (!_flatten1(context, o, depth + 1))
  2658. return 0;
  2659. } else if (o != Py_None) {
  2660. if (context->size + 1 > context->maxsize &&
  2661. !_bump(context, 1))
  2662. return 0;
  2663. Py_INCREF(o);
  2664. PyTuple_SET_ITEM(context->tuple,
  2665. context->size++, o);
  2666. }
  2667. }
  2668. } else {
  2669. PyErr_SetString(PyExc_TypeError, "argument must be sequence");
  2670. return 0;
  2671. }
  2672. return 1;
  2673. }
  2674. /*[clinic input]
  2675. _tkinter._flatten
  2676. item: object
  2677. /
  2678. [clinic start generated code]*/
  2679. static PyObject *
  2680. _tkinter__flatten(PyObject *module, PyObject *item)
  2681. /*[clinic end generated code: output=cad02a3f97f29862 input=6b9c12260aa1157f]*/
  2682. {
  2683. FlattenContext context;
  2684. context.maxsize = PySequence_Size(item);
  2685. if (context.maxsize < 0)
  2686. return NULL;
  2687. if (context.maxsize == 0)
  2688. return PyTuple_New(0);
  2689. context.tuple = PyTuple_New(context.maxsize);
  2690. if (!context.tuple)
  2691. return NULL;
  2692. context.size = 0;
  2693. if (!_flatten1(&context, item,0))
  2694. return NULL;
  2695. if (_PyTuple_Resize(&context.tuple, context.size))
  2696. return NULL;
  2697. return context.tuple;
  2698. }
  2699. /*[clinic input]
  2700. _tkinter.create
  2701. screenName: str(accept={str, NoneType}) = NULL
  2702. baseName: str = NULL
  2703. className: str = "Tk"
  2704. interactive: int(c_default="0") = False
  2705. wantobjects: int(c_default="0") = False
  2706. wantTk: int(c_default="1") = True
  2707. if false, then Tk_Init() doesn't get called
  2708. sync: int(c_default="0") = False
  2709. if true, then pass -sync to wish
  2710. use: str(accept={str, NoneType}) = NULL
  2711. if not None, then pass -use to wish
  2712. /
  2713. [clinic start generated code]*/
  2714. static PyObject *
  2715. _tkinter_create_impl(PyObject *module, const char *screenName,
  2716. const char *baseName, const char *className,
  2717. int interactive, int wantobjects, int wantTk, int sync,
  2718. const char *use)
  2719. /*[clinic end generated code: output=e3315607648e6bb4 input=0d522aad1cb0ca0e]*/
  2720. {
  2721. /* XXX baseName is not used anymore;
  2722. * try getting rid of it. */
  2723. CHECK_STRING_LENGTH(screenName);
  2724. CHECK_STRING_LENGTH(baseName);
  2725. CHECK_STRING_LENGTH(className);
  2726. CHECK_STRING_LENGTH(use);
  2727. return (PyObject *) Tkapp_New(screenName, className,
  2728. interactive, wantobjects, wantTk,
  2729. sync, use);
  2730. }
  2731. /*[clinic input]
  2732. _tkinter.setbusywaitinterval
  2733. new_val: int
  2734. /
  2735. Set the busy-wait interval in milliseconds between successive calls to Tcl_DoOneEvent in a threaded Python interpreter.
  2736. It should be set to a divisor of the maximum time between frames in an animation.
  2737. [clinic start generated code]*/
  2738. static PyObject *
  2739. _tkinter_setbusywaitinterval_impl(PyObject *module, int new_val)
  2740. /*[clinic end generated code: output=42bf7757dc2d0ab6 input=deca1d6f9e6dae47]*/
  2741. {
  2742. if (new_val < 0) {
  2743. PyErr_SetString(PyExc_ValueError,
  2744. "busywaitinterval must be >= 0");
  2745. return NULL;
  2746. }
  2747. Tkinter_busywaitinterval = new_val;
  2748. Py_RETURN_NONE;
  2749. }
  2750. /*[clinic input]
  2751. _tkinter.getbusywaitinterval -> int
  2752. Return the current busy-wait interval between successive calls to Tcl_DoOneEvent in a threaded Python interpreter.
  2753. [clinic start generated code]*/
  2754. static int
  2755. _tkinter_getbusywaitinterval_impl(PyObject *module)
  2756. /*[clinic end generated code: output=23b72d552001f5c7 input=a695878d2d576a84]*/
  2757. {
  2758. return Tkinter_busywaitinterval;
  2759. }
  2760. #include "clinic/_tkinter.c.h"
  2761. static PyMethodDef Tktt_methods[] =
  2762. {
  2763. _TKINTER_TKTIMERTOKEN_DELETETIMERHANDLER_METHODDEF
  2764. {NULL, NULL}
  2765. };
  2766. static PyType_Slot Tktt_Type_slots[] = {
  2767. {Py_tp_dealloc, Tktt_Dealloc},
  2768. {Py_tp_repr, Tktt_Repr},
  2769. {Py_tp_methods, Tktt_methods},
  2770. {0, 0}
  2771. };
  2772. static PyType_Spec Tktt_Type_spec = {
  2773. "_tkinter.tktimertoken",
  2774. sizeof(TkttObject),
  2775. 0,
  2776. Py_TPFLAGS_DEFAULT,
  2777. Tktt_Type_slots,
  2778. };
  2779. /**** Tkapp Method List ****/
  2780. static PyMethodDef Tkapp_methods[] =
  2781. {
  2782. _TKINTER_TKAPP_WILLDISPATCH_METHODDEF
  2783. {"wantobjects", Tkapp_WantObjects, METH_VARARGS},
  2784. {"call", Tkapp_Call, METH_VARARGS},
  2785. _TKINTER_TKAPP_EVAL_METHODDEF
  2786. _TKINTER_TKAPP_EVALFILE_METHODDEF
  2787. _TKINTER_TKAPP_RECORD_METHODDEF
  2788. _TKINTER_TKAPP_ADDERRINFO_METHODDEF
  2789. {"setvar", Tkapp_SetVar, METH_VARARGS},
  2790. {"globalsetvar", Tkapp_GlobalSetVar, METH_VARARGS},
  2791. {"getvar", Tkapp_GetVar, METH_VARARGS},
  2792. {"globalgetvar", Tkapp_GlobalGetVar, METH_VARARGS},
  2793. {"unsetvar", Tkapp_UnsetVar, METH_VARARGS},
  2794. {"globalunsetvar", Tkapp_GlobalUnsetVar, METH_VARARGS},
  2795. _TKINTER_TKAPP_GETINT_METHODDEF
  2796. _TKINTER_TKAPP_GETDOUBLE_METHODDEF
  2797. _TKINTER_TKAPP_GETBOOLEAN_METHODDEF
  2798. _TKINTER_TKAPP_EXPRSTRING_METHODDEF
  2799. _TKINTER_TKAPP_EXPRLONG_METHODDEF
  2800. _TKINTER_TKAPP_EXPRDOUBLE_METHODDEF
  2801. _TKINTER_TKAPP_EXPRBOOLEAN_METHODDEF
  2802. _TKINTER_TKAPP_SPLITLIST_METHODDEF
  2803. _TKINTER_TKAPP_SPLIT_METHODDEF
  2804. _TKINTER_TKAPP_CREATECOMMAND_METHODDEF
  2805. _TKINTER_TKAPP_DELETECOMMAND_METHODDEF
  2806. _TKINTER_TKAPP_CREATEFILEHANDLER_METHODDEF
  2807. _TKINTER_TKAPP_DELETEFILEHANDLER_METHODDEF
  2808. _TKINTER_TKAPP_CREATETIMERHANDLER_METHODDEF
  2809. _TKINTER_TKAPP_MAINLOOP_METHODDEF
  2810. _TKINTER_TKAPP_DOONEEVENT_METHODDEF
  2811. _TKINTER_TKAPP_QUIT_METHODDEF
  2812. _TKINTER_TKAPP_INTERPADDR_METHODDEF
  2813. _TKINTER_TKAPP_LOADTK_METHODDEF
  2814. {NULL, NULL}
  2815. };
  2816. static PyType_Slot Tkapp_Type_slots[] = {
  2817. {Py_tp_dealloc, Tkapp_Dealloc},
  2818. {Py_tp_methods, Tkapp_methods},
  2819. {0, 0}
  2820. };
  2821. static PyType_Spec Tkapp_Type_spec = {
  2822. "_tkinter.tkapp",
  2823. sizeof(TkappObject),
  2824. 0,
  2825. Py_TPFLAGS_DEFAULT,
  2826. Tkapp_Type_slots,
  2827. };
  2828. static PyMethodDef moduleMethods[] =
  2829. {
  2830. _TKINTER__FLATTEN_METHODDEF
  2831. _TKINTER_CREATE_METHODDEF
  2832. _TKINTER_SETBUSYWAITINTERVAL_METHODDEF
  2833. _TKINTER_GETBUSYWAITINTERVAL_METHODDEF
  2834. {NULL, NULL}
  2835. };
  2836. #ifdef WAIT_FOR_STDIN
  2837. static int stdin_ready = 0;
  2838. #ifndef MS_WINDOWS
  2839. static void
  2840. MyFileProc(void *clientData, int mask)
  2841. {
  2842. stdin_ready = 1;
  2843. }
  2844. #endif
  2845. #ifdef WITH_THREAD
  2846. static PyThreadState *event_tstate = NULL;
  2847. #endif
  2848. static int
  2849. EventHook(void)
  2850. {
  2851. #ifndef MS_WINDOWS
  2852. int tfile;
  2853. #endif
  2854. #ifdef WITH_THREAD
  2855. PyEval_RestoreThread(event_tstate);
  2856. #endif
  2857. stdin_ready = 0;
  2858. errorInCmd = 0;
  2859. #ifndef MS_WINDOWS
  2860. tfile = fileno(stdin);
  2861. Tcl_CreateFileHandler(tfile, TCL_READABLE, MyFileProc, NULL);
  2862. #endif
  2863. while (!errorInCmd && !stdin_ready) {
  2864. int result;
  2865. #ifdef MS_WINDOWS
  2866. if (_kbhit()) {
  2867. stdin_ready = 1;
  2868. break;
  2869. }
  2870. #endif
  2871. #if defined(WITH_THREAD) || defined(MS_WINDOWS)
  2872. Py_BEGIN_ALLOW_THREADS
  2873. if(tcl_lock)PyThread_acquire_lock(tcl_lock, 1);
  2874. tcl_tstate = event_tstate;
  2875. result = Tcl_DoOneEvent(TCL_DONT_WAIT);
  2876. tcl_tstate = NULL;
  2877. if(tcl_lock)PyThread_release_lock(tcl_lock);
  2878. if (result == 0)
  2879. Sleep(Tkinter_busywaitinterval);
  2880. Py_END_ALLOW_THREADS
  2881. #else
  2882. result = Tcl_DoOneEvent(0);
  2883. #endif
  2884. if (result < 0)
  2885. break;
  2886. }
  2887. #ifndef MS_WINDOWS
  2888. Tcl_DeleteFileHandler(tfile);
  2889. #endif
  2890. if (errorInCmd) {
  2891. errorInCmd = 0;
  2892. PyErr_Restore(excInCmd, valInCmd, trbInCmd);
  2893. excInCmd = valInCmd = trbInCmd = NULL;
  2894. PyErr_Print();
  2895. }
  2896. #ifdef WITH_THREAD
  2897. PyEval_SaveThread();
  2898. #endif
  2899. return 0;
  2900. }
  2901. #endif
  2902. static void
  2903. EnableEventHook(void)
  2904. {
  2905. #ifdef WAIT_FOR_STDIN
  2906. if (PyOS_InputHook == NULL) {
  2907. #ifdef WITH_THREAD
  2908. event_tstate = PyThreadState_Get();
  2909. #endif
  2910. PyOS_InputHook = EventHook;
  2911. }
  2912. #endif
  2913. }
  2914. static void
  2915. DisableEventHook(void)
  2916. {
  2917. #ifdef WAIT_FOR_STDIN
  2918. if (Tk_GetNumMainWindows() == 0 && PyOS_InputHook == EventHook) {
  2919. PyOS_InputHook = NULL;
  2920. }
  2921. #endif
  2922. }
  2923. static struct PyModuleDef _tkintermodule = {
  2924. PyModuleDef_HEAD_INIT,
  2925. "_tkinter",
  2926. NULL,
  2927. -1,
  2928. moduleMethods,
  2929. NULL,
  2930. NULL,
  2931. NULL,
  2932. NULL
  2933. };
  2934. PyMODINIT_FUNC
  2935. PyInit__tkinter(void)
  2936. {
  2937. PyObject *m, *uexe, *cexe, *o;
  2938. #ifdef WITH_THREAD
  2939. tcl_lock = PyThread_allocate_lock();
  2940. if (tcl_lock == NULL)
  2941. return NULL;
  2942. #endif
  2943. m = PyModule_Create(&_tkintermodule);
  2944. if (m == NULL)
  2945. return NULL;
  2946. o = PyErr_NewException("_tkinter.TclError", NULL, NULL);
  2947. if (o == NULL) {
  2948. Py_DECREF(m);
  2949. return NULL;
  2950. }
  2951. Py_INCREF(o);
  2952. if (PyModule_AddObject(m, "TclError", o)) {
  2953. Py_DECREF(o);
  2954. Py_DECREF(m);
  2955. return NULL;
  2956. }
  2957. Tkinter_TclError = o;
  2958. if (PyModule_AddIntConstant(m, "READABLE", TCL_READABLE)) {
  2959. Py_DECREF(m);
  2960. return NULL;
  2961. }
  2962. if (PyModule_AddIntConstant(m, "WRITABLE", TCL_WRITABLE)) {
  2963. Py_DECREF(m);
  2964. return NULL;
  2965. }
  2966. if (PyModule_AddIntConstant(m, "EXCEPTION", TCL_EXCEPTION)) {
  2967. Py_DECREF(m);
  2968. return NULL;
  2969. }
  2970. if (PyModule_AddIntConstant(m, "WINDOW_EVENTS", TCL_WINDOW_EVENTS)) {
  2971. Py_DECREF(m);
  2972. return NULL;
  2973. }
  2974. if (PyModule_AddIntConstant(m, "FILE_EVENTS", TCL_FILE_EVENTS)) {
  2975. Py_DECREF(m);
  2976. return NULL;
  2977. }
  2978. if (PyModule_AddIntConstant(m, "TIMER_EVENTS", TCL_TIMER_EVENTS)) {
  2979. Py_DECREF(m);
  2980. return NULL;
  2981. }
  2982. if (PyModule_AddIntConstant(m, "IDLE_EVENTS", TCL_IDLE_EVENTS)) {
  2983. Py_DECREF(m);
  2984. return NULL;
  2985. }
  2986. if (PyModule_AddIntConstant(m, "ALL_EVENTS", TCL_ALL_EVENTS)) {
  2987. Py_DECREF(m);
  2988. return NULL;
  2989. }
  2990. if (PyModule_AddIntConstant(m, "DONT_WAIT", TCL_DONT_WAIT)) {
  2991. Py_DECREF(m);
  2992. return NULL;
  2993. }
  2994. if (PyModule_AddStringConstant(m, "TK_VERSION", TK_VERSION)) {
  2995. Py_DECREF(m);
  2996. return NULL;
  2997. }
  2998. if (PyModule_AddStringConstant(m, "TCL_VERSION", TCL_VERSION)) {
  2999. Py_DECREF(m);
  3000. return NULL;
  3001. }
  3002. o = PyType_FromSpec(&Tkapp_Type_spec);
  3003. if (o == NULL) {
  3004. Py_DECREF(m);
  3005. return NULL;
  3006. }
  3007. ((PyTypeObject *)o)->tp_new = NULL;
  3008. if (PyModule_AddObject(m, "TkappType", o)) {
  3009. Py_DECREF(o);
  3010. Py_DECREF(m);
  3011. return NULL;
  3012. }
  3013. Tkapp_Type = o;
  3014. o = PyType_FromSpec(&Tktt_Type_spec);
  3015. if (o == NULL) {
  3016. Py_DECREF(m);
  3017. return NULL;
  3018. }
  3019. ((PyTypeObject *)o)->tp_new = NULL;
  3020. if (PyModule_AddObject(m, "TkttType", o)) {
  3021. Py_DECREF(o);
  3022. Py_DECREF(m);
  3023. return NULL;
  3024. }
  3025. Tktt_Type = o;
  3026. o = PyType_FromSpec(&PyTclObject_Type_spec);
  3027. if (o == NULL) {
  3028. Py_DECREF(m);
  3029. return NULL;
  3030. }
  3031. ((PyTypeObject *)o)->tp_new = NULL;
  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_AS_STRING(cexe));
  3078. if (set_var) {
  3079. SetEnvironmentVariableW(L"TCL_LIBRARY", NULL);
  3080. PyMem_Free(wcs_path);
  3081. }
  3082. #else
  3083. Tcl_FindExecutable(PyBytes_AS_STRING(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. }