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.

3646 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
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
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
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
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 MS_WINDOWS
  19. #include <windows.h>
  20. #endif
  21. #define CHECK_SIZE(size, elemsize) \
  22. ((size_t)(size) <= Py_MIN((size_t)INT_MAX, UINT_MAX / (size_t)(elemsize)))
  23. /* If Tcl is compiled for threads, we must also define TCL_THREAD. We define
  24. it always; if Tcl is not threaded, the thread functions in
  25. Tcl are empty. */
  26. #define TCL_THREADS
  27. #ifdef TK_FRAMEWORK
  28. #include <Tcl/tcl.h>
  29. #include <Tk/tk.h>
  30. #else
  31. #include <tcl.h>
  32. #include <tk.h>
  33. #endif
  34. #include "tkinter.h"
  35. #if TK_HEX_VERSION < 0x08040200
  36. #error "Tk older than 8.4 not supported"
  37. #endif
  38. #if TK_HEX_VERSION >= 0x08050208 && TK_HEX_VERSION < 0x08060000 || \
  39. TK_HEX_VERSION >= 0x08060200
  40. #define HAVE_LIBTOMMATH
  41. #include <tclTomMath.h>
  42. #endif
  43. #if !(defined(MS_WINDOWS) || defined(__CYGWIN__))
  44. #define HAVE_CREATEFILEHANDLER
  45. #endif
  46. #ifdef HAVE_CREATEFILEHANDLER
  47. /* This bit is to ensure that TCL_UNIX_FD is defined and doesn't interfere
  48. with the proper calculation of FHANDLETYPE == TCL_UNIX_FD below. */
  49. #ifndef TCL_UNIX_FD
  50. # ifdef TCL_WIN_SOCKET
  51. # define TCL_UNIX_FD (! TCL_WIN_SOCKET)
  52. # else
  53. # define TCL_UNIX_FD 1
  54. # endif
  55. #endif
  56. /* Tcl_CreateFileHandler() changed several times; these macros deal with the
  57. messiness. In Tcl 8.0 and later, it is not available on Windows (and on
  58. Unix, only because Jack added it back); when available on Windows, it only
  59. applies to sockets. */
  60. #ifdef MS_WINDOWS
  61. #define FHANDLETYPE TCL_WIN_SOCKET
  62. #else
  63. #define FHANDLETYPE TCL_UNIX_FD
  64. #endif
  65. /* If Tcl can wait for a Unix file descriptor, define the EventHook() routine
  66. which uses this to handle Tcl events while the user is typing commands. */
  67. #if FHANDLETYPE == TCL_UNIX_FD
  68. #define WAIT_FOR_STDIN
  69. #endif
  70. #endif /* HAVE_CREATEFILEHANDLER */
  71. /* Use OS native encoding for converting between Python strings and
  72. Tcl objects.
  73. On Windows use UTF-16 (or UTF-32 for 32-bit Tcl_UniChar) with the
  74. "surrogatepass" error handler for converting to/from Tcl Unicode objects.
  75. On Linux use UTF-8 with the "surrogateescape" error handler for converting
  76. to/from Tcl String objects. */
  77. #ifdef MS_WINDOWS
  78. #define USE_TCL_UNICODE 1
  79. #else
  80. #define USE_TCL_UNICODE 0
  81. #endif
  82. #if PY_LITTLE_ENDIAN
  83. #define NATIVE_BYTEORDER -1
  84. #else
  85. #define NATIVE_BYTEORDER 1
  86. #endif
  87. #ifdef MS_WINDOWS
  88. #include <conio.h>
  89. #define WAIT_FOR_STDIN
  90. static PyObject *
  91. _get_tcl_lib_path()
  92. {
  93. static PyObject *tcl_library_path = NULL;
  94. static int already_checked = 0;
  95. if (already_checked == 0) {
  96. PyObject *prefix;
  97. struct stat stat_buf;
  98. int stat_return_value;
  99. prefix = PyUnicode_FromWideChar(Py_GetPrefix(), -1);
  100. if (prefix == NULL) {
  101. return NULL;
  102. }
  103. /* Check expected location for an installed Python first */
  104. tcl_library_path = PyUnicode_FromString("\\tcl\\tcl" TCL_VERSION);
  105. if (tcl_library_path == NULL) {
  106. return NULL;
  107. }
  108. tcl_library_path = PyUnicode_Concat(prefix, tcl_library_path);
  109. if (tcl_library_path == NULL) {
  110. return NULL;
  111. }
  112. stat_return_value = _Py_stat(tcl_library_path, &stat_buf);
  113. if (stat_return_value == -2) {
  114. return NULL;
  115. }
  116. if (stat_return_value == -1) {
  117. /* install location doesn't exist, reset errno and see if
  118. we're a repository build */
  119. errno = 0;
  120. #ifdef Py_TCLTK_DIR
  121. tcl_library_path = PyUnicode_FromString(
  122. Py_TCLTK_DIR "\\lib\\tcl" TCL_VERSION);
  123. if (tcl_library_path == NULL) {
  124. return NULL;
  125. }
  126. stat_return_value = _Py_stat(tcl_library_path, &stat_buf);
  127. if (stat_return_value == -2) {
  128. return NULL;
  129. }
  130. if (stat_return_value == -1) {
  131. /* tcltkDir for a repository build doesn't exist either,
  132. reset errno and leave Tcl to its own devices */
  133. errno = 0;
  134. tcl_library_path = NULL;
  135. }
  136. #else
  137. tcl_library_path = NULL;
  138. #endif
  139. }
  140. already_checked = 1;
  141. }
  142. return tcl_library_path;
  143. }
  144. #endif /* MS_WINDOWS */
  145. /* The threading situation is complicated. Tcl is not thread-safe, except
  146. when configured with --enable-threads.
  147. So we need to use a lock around all uses of Tcl. Previously, the
  148. Python interpreter lock was used for this. However, this causes
  149. problems when other Python threads need to run while Tcl is blocked
  150. waiting for events.
  151. To solve this problem, a separate lock for Tcl is introduced.
  152. Holding it is incompatible with holding Python's interpreter lock.
  153. The following four macros manipulate both locks together.
  154. ENTER_TCL and LEAVE_TCL are brackets, just like
  155. Py_BEGIN_ALLOW_THREADS and Py_END_ALLOW_THREADS. They should be
  156. used whenever a call into Tcl is made that could call an event
  157. handler, or otherwise affect the state of a Tcl interpreter. These
  158. assume that the surrounding code has the Python interpreter lock;
  159. inside the brackets, the Python interpreter lock has been released
  160. and the lock for Tcl has been acquired.
  161. Sometimes, it is necessary to have both the Python lock and the Tcl
  162. lock. (For example, when transferring data from the Tcl
  163. interpreter result to a Python string object.) This can be done by
  164. using different macros to close the ENTER_TCL block: ENTER_OVERLAP
  165. reacquires the Python lock (and restores the thread state) but
  166. doesn't release the Tcl lock; LEAVE_OVERLAP_TCL releases the Tcl
  167. lock.
  168. By contrast, ENTER_PYTHON and LEAVE_PYTHON are used in Tcl event
  169. handlers when the handler needs to use Python. Such event handlers
  170. are entered while the lock for Tcl is held; the event handler
  171. presumably needs to use Python. ENTER_PYTHON releases the lock for
  172. Tcl and acquires the Python interpreter lock, restoring the
  173. appropriate thread state, and LEAVE_PYTHON releases the Python
  174. interpreter lock and re-acquires the lock for Tcl. It is okay for
  175. ENTER_TCL/LEAVE_TCL pairs to be contained inside the code between
  176. ENTER_PYTHON and LEAVE_PYTHON.
  177. These locks expand to several statements and brackets; they should
  178. not be used in branches of if statements and the like.
  179. If Tcl is threaded, this approach won't work anymore. The Tcl
  180. interpreter is only valid in the thread that created it, and all Tk
  181. activity must happen in this thread, also. That means that the
  182. mainloop must be invoked in the thread that created the
  183. interpreter. Invoking commands from other threads is possible;
  184. _tkinter will queue an event for the interpreter thread, which will
  185. then execute the command and pass back the result. If the main
  186. thread is not in the mainloop, and invoking commands causes an
  187. exception; if the main loop is running but not processing events,
  188. the command invocation will block.
  189. In addition, for a threaded Tcl, a single global tcl_tstate won't
  190. be sufficient anymore, since multiple Tcl interpreters may
  191. simultaneously dispatch in different threads. So we use the Tcl TLS
  192. API.
  193. */
  194. static PyThread_type_lock tcl_lock = 0;
  195. #ifdef TCL_THREADS
  196. static Tcl_ThreadDataKey state_key;
  197. typedef PyThreadState *ThreadSpecificData;
  198. #define tcl_tstate \
  199. (*(PyThreadState**)Tcl_GetThreadData(&state_key, sizeof(PyThreadState*)))
  200. #else
  201. static PyThreadState *tcl_tstate = NULL;
  202. #endif
  203. #define ENTER_TCL \
  204. { PyThreadState *tstate = PyThreadState_Get(); Py_BEGIN_ALLOW_THREADS \
  205. if(tcl_lock)PyThread_acquire_lock(tcl_lock, 1); tcl_tstate = tstate;
  206. #define LEAVE_TCL \
  207. tcl_tstate = NULL; \
  208. if(tcl_lock)PyThread_release_lock(tcl_lock); Py_END_ALLOW_THREADS}
  209. #define ENTER_OVERLAP \
  210. Py_END_ALLOW_THREADS
  211. #define LEAVE_OVERLAP_TCL \
  212. tcl_tstate = NULL; if(tcl_lock)PyThread_release_lock(tcl_lock); }
  213. #define ENTER_PYTHON \
  214. { PyThreadState *tstate = tcl_tstate; tcl_tstate = NULL; \
  215. if(tcl_lock) \
  216. PyThread_release_lock(tcl_lock); PyEval_RestoreThread((tstate)); }
  217. #define LEAVE_PYTHON \
  218. { PyThreadState *tstate = PyEval_SaveThread(); \
  219. if(tcl_lock)PyThread_acquire_lock(tcl_lock, 1); tcl_tstate = tstate; }
  220. #define CHECK_TCL_APPARTMENT \
  221. if (((TkappObject *)self)->threaded && \
  222. ((TkappObject *)self)->thread_id != Tcl_GetCurrentThread()) { \
  223. PyErr_SetString(PyExc_RuntimeError, \
  224. "Calling Tcl from different apartment"); \
  225. return 0; \
  226. }
  227. #ifndef FREECAST
  228. #define FREECAST (char *)
  229. #endif
  230. /**** Tkapp Object Declaration ****/
  231. static PyObject *Tkapp_Type;
  232. typedef struct {
  233. PyObject_HEAD
  234. Tcl_Interp *interp;
  235. int wantobjects;
  236. int threaded; /* True if tcl_platform[threaded] */
  237. Tcl_ThreadId thread_id;
  238. int dispatching;
  239. /* We cannot include tclInt.h, as this is internal.
  240. So we cache interesting types here. */
  241. const Tcl_ObjType *OldBooleanType;
  242. const Tcl_ObjType *BooleanType;
  243. const Tcl_ObjType *ByteArrayType;
  244. const Tcl_ObjType *DoubleType;
  245. const Tcl_ObjType *IntType;
  246. const Tcl_ObjType *WideIntType;
  247. const Tcl_ObjType *BignumType;
  248. const Tcl_ObjType *ListType;
  249. const Tcl_ObjType *ProcBodyType;
  250. const Tcl_ObjType *StringType;
  251. } TkappObject;
  252. #define Tkapp_Interp(v) (((TkappObject *) (v))->interp)
  253. #define DEBUG_REFCNT(v) (printf("DEBUG: id=%p, refcnt=%i\n", \
  254. (void *) v, Py_REFCNT(v)))
  255. /**** Error Handling ****/
  256. static PyObject *Tkinter_TclError;
  257. static int quitMainLoop = 0;
  258. static int errorInCmd = 0;
  259. static PyObject *excInCmd;
  260. static PyObject *valInCmd;
  261. static PyObject *trbInCmd;
  262. #ifdef TKINTER_PROTECT_LOADTK
  263. static int tk_load_failed = 0;
  264. #endif
  265. static PyObject *Tkapp_UnicodeResult(TkappObject *);
  266. static PyObject *
  267. Tkinter_Error(TkappObject *self)
  268. {
  269. PyObject *res = Tkapp_UnicodeResult(self);
  270. if (res != NULL) {
  271. PyErr_SetObject(Tkinter_TclError, res);
  272. Py_DECREF(res);
  273. }
  274. return NULL;
  275. }
  276. /**** Utils ****/
  277. static int Tkinter_busywaitinterval = 20;
  278. #ifndef MS_WINDOWS
  279. /* Millisecond sleep() for Unix platforms. */
  280. static void
  281. Sleep(int milli)
  282. {
  283. /* XXX Too bad if you don't have select(). */
  284. struct timeval t;
  285. t.tv_sec = milli/1000;
  286. t.tv_usec = (milli%1000) * 1000;
  287. select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t);
  288. }
  289. #endif /* MS_WINDOWS */
  290. /* Wait up to 1s for the mainloop to come up. */
  291. static int
  292. WaitForMainloop(TkappObject* self)
  293. {
  294. int i;
  295. for (i = 0; i < 10; i++) {
  296. if (self->dispatching)
  297. return 1;
  298. Py_BEGIN_ALLOW_THREADS
  299. Sleep(100);
  300. Py_END_ALLOW_THREADS
  301. }
  302. if (self->dispatching)
  303. return 1;
  304. PyErr_SetString(PyExc_RuntimeError, "main thread is not in main loop");
  305. return 0;
  306. }
  307. #define ARGSZ 64
  308. static PyObject *
  309. unicodeFromTclStringAndSize(const char *s, Py_ssize_t size)
  310. {
  311. PyObject *r = PyUnicode_DecodeUTF8(s, size, NULL);
  312. if (r != NULL || !PyErr_ExceptionMatches(PyExc_UnicodeDecodeError)) {
  313. return r;
  314. }
  315. char *buf = NULL;
  316. PyErr_Clear();
  317. /* Tcl encodes null character as \xc0\x80.
  318. https://en.wikipedia.org/wiki/UTF-8#Modified_UTF-8 */
  319. if (memchr(s, '\xc0', size)) {
  320. char *q;
  321. const char *e = s + size;
  322. q = buf = (char *)PyMem_Malloc(size);
  323. if (buf == NULL) {
  324. PyErr_NoMemory();
  325. return NULL;
  326. }
  327. while (s != e) {
  328. if (s + 1 != e && s[0] == '\xc0' && s[1] == '\x80') {
  329. *q++ = '\0';
  330. s += 2;
  331. }
  332. else
  333. *q++ = *s++;
  334. }
  335. s = buf;
  336. size = q - s;
  337. }
  338. r = PyUnicode_DecodeUTF8(s, size, "surrogateescape");
  339. if (buf != NULL) {
  340. PyMem_Free(buf);
  341. }
  342. if (r == NULL || PyUnicode_KIND(r) == PyUnicode_1BYTE_KIND) {
  343. return r;
  344. }
  345. /* In CESU-8 non-BMP characters are represented as a surrogate pair,
  346. like in UTF-16, and then each surrogate code point is encoded in UTF-8.
  347. https://en.wikipedia.org/wiki/CESU-8 */
  348. Py_ssize_t len = PyUnicode_GET_LENGTH(r);
  349. Py_ssize_t i, j;
  350. /* All encoded surrogate characters start with \xED. */
  351. i = PyUnicode_FindChar(r, 0xdcED, 0, len, 1);
  352. if (i == -2) {
  353. Py_DECREF(r);
  354. return NULL;
  355. }
  356. if (i == -1) {
  357. return r;
  358. }
  359. Py_UCS4 *u = PyUnicode_AsUCS4Copy(r);
  360. Py_DECREF(r);
  361. if (u == NULL) {
  362. return NULL;
  363. }
  364. Py_UCS4 ch;
  365. for (j = i; i < len; i++, u[j++] = ch) {
  366. Py_UCS4 ch1, ch2, ch3, high, low;
  367. /* Low surrogates U+D800 - U+DBFF are encoded as
  368. \xED\xA0\x80 - \xED\xAF\xBF. */
  369. ch1 = ch = u[i];
  370. if (ch1 != 0xdcED) continue;
  371. ch2 = u[i + 1];
  372. if (!(0xdcA0 <= ch2 && ch2 <= 0xdcAF)) continue;
  373. ch3 = u[i + 2];
  374. if (!(0xdc80 <= ch3 && ch3 <= 0xdcBF)) continue;
  375. high = 0xD000 | ((ch2 & 0x3F) << 6) | (ch3 & 0x3F);
  376. assert(Py_UNICODE_IS_HIGH_SURROGATE(high));
  377. /* High surrogates U+DC00 - U+DFFF are encoded as
  378. \xED\xB0\x80 - \xED\xBF\xBF. */
  379. ch1 = u[i + 3];
  380. if (ch1 != 0xdcED) continue;
  381. ch2 = u[i + 4];
  382. if (!(0xdcB0 <= ch2 && ch2 <= 0xdcBF)) continue;
  383. ch3 = u[i + 5];
  384. if (!(0xdc80 <= ch3 && ch3 <= 0xdcBF)) continue;
  385. low = 0xD000 | ((ch2 & 0x3F) << 6) | (ch3 & 0x3F);
  386. assert(Py_UNICODE_IS_HIGH_SURROGATE(high));
  387. ch = Py_UNICODE_JOIN_SURROGATES(high, low);
  388. i += 5;
  389. }
  390. r = PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND, u, j);
  391. PyMem_Free(u);
  392. return r;
  393. }
  394. static PyObject *
  395. unicodeFromTclString(const char *s)
  396. {
  397. return unicodeFromTclStringAndSize(s, strlen(s));
  398. }
  399. static PyObject *
  400. unicodeFromTclObj(Tcl_Obj *value)
  401. {
  402. int len;
  403. #if USE_TCL_UNICODE
  404. int byteorder = NATIVE_BYTEORDER;
  405. const Tcl_UniChar *u = Tcl_GetUnicodeFromObj(value, &len);
  406. if (sizeof(Tcl_UniChar) == 2)
  407. return PyUnicode_DecodeUTF16((const char *)u, len * 2,
  408. "surrogatepass", &byteorder);
  409. else if (sizeof(Tcl_UniChar) == 4)
  410. return PyUnicode_DecodeUTF32((const char *)u, len * 4,
  411. "surrogatepass", &byteorder);
  412. else
  413. Py_UNREACHABLE();
  414. #else
  415. const char *s = Tcl_GetStringFromObj(value, &len);
  416. return unicodeFromTclStringAndSize(s, len);
  417. #endif
  418. }
  419. static PyObject *
  420. Split(const char *list)
  421. {
  422. int argc;
  423. const char **argv;
  424. PyObject *v;
  425. if (list == NULL) {
  426. Py_RETURN_NONE;
  427. }
  428. if (Tcl_SplitList((Tcl_Interp *)NULL, list, &argc, &argv) != TCL_OK) {
  429. /* Not a list.
  430. * Could be a quoted string containing funnies, e.g. {"}.
  431. * Return the string itself.
  432. */
  433. return unicodeFromTclString(list);
  434. }
  435. if (argc == 0)
  436. v = PyUnicode_FromString("");
  437. else if (argc == 1)
  438. v = unicodeFromTclString(argv[0]);
  439. else if ((v = PyTuple_New(argc)) != NULL) {
  440. int i;
  441. PyObject *w;
  442. for (i = 0; i < argc; i++) {
  443. if ((w = Split(argv[i])) == NULL) {
  444. Py_DECREF(v);
  445. v = NULL;
  446. break;
  447. }
  448. PyTuple_SET_ITEM(v, i, w);
  449. }
  450. }
  451. Tcl_Free(FREECAST argv);
  452. return v;
  453. }
  454. /* In some cases, Tcl will still return strings that are supposed to
  455. be lists. SplitObj walks through a nested tuple, finding string
  456. objects that need to be split. */
  457. static PyObject *
  458. SplitObj(PyObject *arg)
  459. {
  460. if (PyTuple_Check(arg)) {
  461. Py_ssize_t i, size;
  462. PyObject *elem, *newelem, *result;
  463. size = PyTuple_GET_SIZE(arg);
  464. result = NULL;
  465. /* Recursively invoke SplitObj for all tuple items.
  466. If this does not return a new object, no action is
  467. needed. */
  468. for(i = 0; i < size; i++) {
  469. elem = PyTuple_GET_ITEM(arg, i);
  470. newelem = SplitObj(elem);
  471. if (!newelem) {
  472. Py_XDECREF(result);
  473. return NULL;
  474. }
  475. if (!result) {
  476. Py_ssize_t k;
  477. if (newelem == elem) {
  478. Py_DECREF(newelem);
  479. continue;
  480. }
  481. result = PyTuple_New(size);
  482. if (!result)
  483. return NULL;
  484. for(k = 0; k < i; k++) {
  485. elem = PyTuple_GET_ITEM(arg, k);
  486. Py_INCREF(elem);
  487. PyTuple_SET_ITEM(result, k, elem);
  488. }
  489. }
  490. PyTuple_SET_ITEM(result, i, newelem);
  491. }
  492. if (result)
  493. return result;
  494. /* Fall through, returning arg. */
  495. }
  496. else if (PyList_Check(arg)) {
  497. Py_ssize_t i, size;
  498. PyObject *elem, *newelem, *result;
  499. size = PyList_GET_SIZE(arg);
  500. result = PyTuple_New(size);
  501. if (!result)
  502. return NULL;
  503. /* Recursively invoke SplitObj for all list items. */
  504. for(i = 0; i < size; i++) {
  505. elem = PyList_GET_ITEM(arg, i);
  506. newelem = SplitObj(elem);
  507. if (!newelem) {
  508. Py_XDECREF(result);
  509. return NULL;
  510. }
  511. PyTuple_SET_ITEM(result, i, newelem);
  512. }
  513. return result;
  514. }
  515. else if (PyUnicode_Check(arg)) {
  516. int argc;
  517. const char **argv;
  518. const char *list = PyUnicode_AsUTF8(arg);
  519. if (list == NULL ||
  520. Tcl_SplitList((Tcl_Interp *)NULL, list, &argc, &argv) != TCL_OK) {
  521. Py_INCREF(arg);
  522. return arg;
  523. }
  524. Tcl_Free(FREECAST argv);
  525. if (argc > 1)
  526. return Split(list);
  527. /* Fall through, returning arg. */
  528. }
  529. else if (PyBytes_Check(arg)) {
  530. int argc;
  531. const char **argv;
  532. const char *list = PyBytes_AS_STRING(arg);
  533. if (Tcl_SplitList((Tcl_Interp *)NULL, (char *)list, &argc, &argv) != TCL_OK) {
  534. Py_INCREF(arg);
  535. return arg;
  536. }
  537. Tcl_Free(FREECAST argv);
  538. if (argc > 1)
  539. return Split(PyBytes_AS_STRING(arg));
  540. /* Fall through, returning arg. */
  541. }
  542. Py_INCREF(arg);
  543. return arg;
  544. }
  545. /*[clinic input]
  546. module _tkinter
  547. class _tkinter.tkapp "TkappObject *" "&Tkapp_Type_spec"
  548. class _tkinter.Tcl_Obj "PyTclObject *" "&PyTclObject_Type_spec"
  549. class _tkinter.tktimertoken "TkttObject *" "&Tktt_Type_spec"
  550. [clinic start generated code]*/
  551. /*[clinic end generated code: output=da39a3ee5e6b4b0d input=b1ebf15c162ee229]*/
  552. /**** Tkapp Object ****/
  553. #ifndef WITH_APPINIT
  554. int
  555. Tcl_AppInit(Tcl_Interp *interp)
  556. {
  557. const char * _tkinter_skip_tk_init;
  558. if (Tcl_Init(interp) == TCL_ERROR) {
  559. PySys_WriteStderr("Tcl_Init error: %s\n", Tcl_GetStringResult(interp));
  560. return TCL_ERROR;
  561. }
  562. _tkinter_skip_tk_init = Tcl_GetVar(interp,
  563. "_tkinter_skip_tk_init", TCL_GLOBAL_ONLY);
  564. if (_tkinter_skip_tk_init != NULL &&
  565. strcmp(_tkinter_skip_tk_init, "1") == 0) {
  566. return TCL_OK;
  567. }
  568. #ifdef TKINTER_PROTECT_LOADTK
  569. if (tk_load_failed) {
  570. PySys_WriteStderr("Tk_Init error: %s\n", TKINTER_LOADTK_ERRMSG);
  571. return TCL_ERROR;
  572. }
  573. #endif
  574. if (Tk_Init(interp) == TCL_ERROR) {
  575. #ifdef TKINTER_PROTECT_LOADTK
  576. tk_load_failed = 1;
  577. #endif
  578. PySys_WriteStderr("Tk_Init error: %s\n", Tcl_GetStringResult(interp));
  579. return TCL_ERROR;
  580. }
  581. return TCL_OK;
  582. }
  583. #endif /* !WITH_APPINIT */
  584. /* Initialize the Tk application; see the `main' function in
  585. * `tkMain.c'.
  586. */
  587. static void EnableEventHook(void); /* Forward */
  588. static void DisableEventHook(void); /* Forward */
  589. static TkappObject *
  590. Tkapp_New(const char *screenName, const char *className,
  591. int interactive, int wantobjects, int wantTk, int sync,
  592. const char *use)
  593. {
  594. TkappObject *v;
  595. char *argv0;
  596. v = PyObject_New(TkappObject, (PyTypeObject *) Tkapp_Type);
  597. if (v == NULL)
  598. return NULL;
  599. v->interp = Tcl_CreateInterp();
  600. v->wantobjects = wantobjects;
  601. v->threaded = Tcl_GetVar2Ex(v->interp, "tcl_platform", "threaded",
  602. TCL_GLOBAL_ONLY) != NULL;
  603. v->thread_id = Tcl_GetCurrentThread();
  604. v->dispatching = 0;
  605. #ifndef TCL_THREADS
  606. if (v->threaded) {
  607. PyErr_SetString(PyExc_RuntimeError,
  608. "Tcl is threaded but _tkinter is not");
  609. Py_DECREF(v);
  610. return 0;
  611. }
  612. #endif
  613. if (v->threaded && tcl_lock) {
  614. /* If Tcl is threaded, we don't need the lock. */
  615. PyThread_free_lock(tcl_lock);
  616. tcl_lock = NULL;
  617. }
  618. v->OldBooleanType = Tcl_GetObjType("boolean");
  619. v->BooleanType = Tcl_GetObjType("booleanString");
  620. v->ByteArrayType = Tcl_GetObjType("bytearray");
  621. v->DoubleType = Tcl_GetObjType("double");
  622. v->IntType = Tcl_GetObjType("int");
  623. v->WideIntType = Tcl_GetObjType("wideInt");
  624. v->BignumType = Tcl_GetObjType("bignum");
  625. v->ListType = Tcl_GetObjType("list");
  626. v->ProcBodyType = Tcl_GetObjType("procbody");
  627. v->StringType = Tcl_GetObjType("string");
  628. /* Delete the 'exit' command, which can screw things up */
  629. Tcl_DeleteCommand(v->interp, "exit");
  630. if (screenName != NULL)
  631. Tcl_SetVar2(v->interp, "env", "DISPLAY",
  632. screenName, TCL_GLOBAL_ONLY);
  633. if (interactive)
  634. Tcl_SetVar(v->interp, "tcl_interactive", "1", TCL_GLOBAL_ONLY);
  635. else
  636. Tcl_SetVar(v->interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY);
  637. /* This is used to get the application class for Tk 4.1 and up */
  638. argv0 = (char*)PyMem_Malloc(strlen(className) + 1);
  639. if (!argv0) {
  640. PyErr_NoMemory();
  641. Py_DECREF(v);
  642. return NULL;
  643. }
  644. strcpy(argv0, className);
  645. if (Py_ISUPPER(argv0[0]))
  646. argv0[0] = Py_TOLOWER(argv0[0]);
  647. Tcl_SetVar(v->interp, "argv0", argv0, TCL_GLOBAL_ONLY);
  648. PyMem_Free(argv0);
  649. if (! wantTk) {
  650. Tcl_SetVar(v->interp,
  651. "_tkinter_skip_tk_init", "1", TCL_GLOBAL_ONLY);
  652. }
  653. #ifdef TKINTER_PROTECT_LOADTK
  654. else if (tk_load_failed) {
  655. Tcl_SetVar(v->interp,
  656. "_tkinter_tk_failed", "1", TCL_GLOBAL_ONLY);
  657. }
  658. #endif
  659. /* some initial arguments need to be in argv */
  660. if (sync || use) {
  661. char *args;
  662. Py_ssize_t len = 0;
  663. if (sync)
  664. len += sizeof "-sync";
  665. if (use)
  666. len += strlen(use) + sizeof "-use "; /* never overflows */
  667. args = (char*)PyMem_Malloc(len);
  668. if (!args) {
  669. PyErr_NoMemory();
  670. Py_DECREF(v);
  671. return NULL;
  672. }
  673. args[0] = '\0';
  674. if (sync)
  675. strcat(args, "-sync");
  676. if (use) {
  677. if (sync)
  678. strcat(args, " ");
  679. strcat(args, "-use ");
  680. strcat(args, use);
  681. }
  682. Tcl_SetVar(v->interp, "argv", args, TCL_GLOBAL_ONLY);
  683. PyMem_Free(args);
  684. }
  685. #ifdef MS_WINDOWS
  686. {
  687. PyObject *str_path;
  688. PyObject *utf8_path;
  689. DWORD ret;
  690. ret = GetEnvironmentVariableW(L"TCL_LIBRARY", NULL, 0);
  691. if (!ret && GetLastError() == ERROR_ENVVAR_NOT_FOUND) {
  692. str_path = _get_tcl_lib_path();
  693. if (str_path == NULL && PyErr_Occurred()) {
  694. return NULL;
  695. }
  696. if (str_path != NULL) {
  697. utf8_path = PyUnicode_AsUTF8String(str_path);
  698. if (utf8_path == NULL) {
  699. return NULL;
  700. }
  701. Tcl_SetVar(v->interp,
  702. "tcl_library",
  703. PyBytes_AS_STRING(utf8_path),
  704. TCL_GLOBAL_ONLY);
  705. Py_DECREF(utf8_path);
  706. }
  707. }
  708. }
  709. #endif
  710. if (Tcl_AppInit(v->interp) != TCL_OK) {
  711. PyObject *result = Tkinter_Error(v);
  712. #ifdef TKINTER_PROTECT_LOADTK
  713. if (wantTk) {
  714. const char *_tkinter_tk_failed;
  715. _tkinter_tk_failed = Tcl_GetVar(v->interp,
  716. "_tkinter_tk_failed", TCL_GLOBAL_ONLY);
  717. if ( _tkinter_tk_failed != NULL &&
  718. strcmp(_tkinter_tk_failed, "1") == 0) {
  719. tk_load_failed = 1;
  720. }
  721. }
  722. #endif
  723. Py_DECREF((PyObject *)v);
  724. return (TkappObject *)result;
  725. }
  726. EnableEventHook();
  727. return v;
  728. }
  729. static void
  730. Tkapp_ThreadSend(TkappObject *self, Tcl_Event *ev,
  731. Tcl_Condition *cond, Tcl_Mutex *mutex)
  732. {
  733. Py_BEGIN_ALLOW_THREADS;
  734. Tcl_MutexLock(mutex);
  735. Tcl_ThreadQueueEvent(self->thread_id, ev, TCL_QUEUE_TAIL);
  736. Tcl_ThreadAlert(self->thread_id);
  737. Tcl_ConditionWait(cond, mutex, NULL);
  738. Tcl_MutexUnlock(mutex);
  739. Py_END_ALLOW_THREADS
  740. }
  741. /** Tcl Eval **/
  742. typedef struct {
  743. PyObject_HEAD
  744. Tcl_Obj *value;
  745. PyObject *string; /* This cannot cause cycles. */
  746. } PyTclObject;
  747. static PyObject *PyTclObject_Type;
  748. #define PyTclObject_Check(v) Py_IS_TYPE(v, (PyTypeObject *) PyTclObject_Type)
  749. static PyObject *
  750. newPyTclObject(Tcl_Obj *arg)
  751. {
  752. PyTclObject *self;
  753. self = PyObject_New(PyTclObject, (PyTypeObject *) PyTclObject_Type);
  754. if (self == NULL)
  755. return NULL;
  756. Tcl_IncrRefCount(arg);
  757. self->value = arg;
  758. self->string = NULL;
  759. return (PyObject*)self;
  760. }
  761. static void
  762. PyTclObject_dealloc(PyTclObject *self)
  763. {
  764. PyObject *tp = (PyObject *) Py_TYPE(self);
  765. Tcl_DecrRefCount(self->value);
  766. Py_XDECREF(self->string);
  767. PyObject_Free(self);
  768. Py_DECREF(tp);
  769. }
  770. /* Like _str, but create Unicode if necessary. */
  771. PyDoc_STRVAR(PyTclObject_string__doc__,
  772. "the string representation of this object, either as str or bytes");
  773. static PyObject *
  774. PyTclObject_string(PyTclObject *self, void *ignored)
  775. {
  776. if (!self->string) {
  777. self->string = unicodeFromTclObj(self->value);
  778. if (!self->string)
  779. return NULL;
  780. }
  781. Py_INCREF(self->string);
  782. return self->string;
  783. }
  784. static PyObject *
  785. PyTclObject_str(PyTclObject *self)
  786. {
  787. if (self->string) {
  788. Py_INCREF(self->string);
  789. return self->string;
  790. }
  791. /* XXX Could chache result if it is non-ASCII. */
  792. return unicodeFromTclObj(self->value);
  793. }
  794. static PyObject *
  795. PyTclObject_repr(PyTclObject *self)
  796. {
  797. PyObject *repr, *str = PyTclObject_str(self);
  798. if (str == NULL)
  799. return NULL;
  800. repr = PyUnicode_FromFormat("<%s object: %R>",
  801. self->value->typePtr->name, str);
  802. Py_DECREF(str);
  803. return repr;
  804. }
  805. static PyObject *
  806. PyTclObject_richcompare(PyObject *self, PyObject *other, int op)
  807. {
  808. int result;
  809. /* neither argument should be NULL, unless something's gone wrong */
  810. if (self == NULL || other == NULL) {
  811. PyErr_BadInternalCall();
  812. return NULL;
  813. }
  814. /* both arguments should be instances of PyTclObject */
  815. if (!PyTclObject_Check(self) || !PyTclObject_Check(other)) {
  816. Py_RETURN_NOTIMPLEMENTED;
  817. }
  818. if (self == other)
  819. /* fast path when self and other are identical */
  820. result = 0;
  821. else
  822. result = strcmp(Tcl_GetString(((PyTclObject *)self)->value),
  823. Tcl_GetString(((PyTclObject *)other)->value));
  824. Py_RETURN_RICHCOMPARE(result, 0, op);
  825. }
  826. PyDoc_STRVAR(get_typename__doc__, "name of the Tcl type");
  827. static PyObject*
  828. get_typename(PyTclObject* obj, void* ignored)
  829. {
  830. return unicodeFromTclString(obj->value->typePtr->name);
  831. }
  832. static PyGetSetDef PyTclObject_getsetlist[] = {
  833. {"typename", (getter)get_typename, NULL, get_typename__doc__},
  834. {"string", (getter)PyTclObject_string, NULL,
  835. PyTclObject_string__doc__},
  836. {0},
  837. };
  838. static PyType_Slot PyTclObject_Type_slots[] = {
  839. {Py_tp_dealloc, (destructor)PyTclObject_dealloc},
  840. {Py_tp_repr, (reprfunc)PyTclObject_repr},
  841. {Py_tp_str, (reprfunc)PyTclObject_str},
  842. {Py_tp_getattro, PyObject_GenericGetAttr},
  843. {Py_tp_richcompare, PyTclObject_richcompare},
  844. {Py_tp_getset, PyTclObject_getsetlist},
  845. {0, 0}
  846. };
  847. static PyType_Spec PyTclObject_Type_spec = {
  848. "_tkinter.Tcl_Obj",
  849. sizeof(PyTclObject),
  850. 0,
  851. Py_TPFLAGS_DEFAULT,
  852. PyTclObject_Type_slots,
  853. };
  854. #if SIZE_MAX > INT_MAX
  855. #define CHECK_STRING_LENGTH(s) do { \
  856. if (s != NULL && strlen(s) >= INT_MAX) { \
  857. PyErr_SetString(PyExc_OverflowError, "string is too long"); \
  858. return NULL; \
  859. } } while(0)
  860. #else
  861. #define CHECK_STRING_LENGTH(s)
  862. #endif
  863. #ifdef HAVE_LIBTOMMATH
  864. static Tcl_Obj*
  865. asBignumObj(PyObject *value)
  866. {
  867. Tcl_Obj *result;
  868. int neg;
  869. PyObject *hexstr;
  870. const char *hexchars;
  871. mp_int bigValue;
  872. neg = Py_SIZE(value) < 0;
  873. hexstr = _PyLong_Format(value, 16);
  874. if (hexstr == NULL)
  875. return NULL;
  876. hexchars = PyUnicode_AsUTF8(hexstr);
  877. if (hexchars == NULL) {
  878. Py_DECREF(hexstr);
  879. return NULL;
  880. }
  881. hexchars += neg + 2; /* skip sign and "0x" */
  882. mp_init(&bigValue);
  883. if (mp_read_radix(&bigValue, hexchars, 16) != MP_OKAY) {
  884. mp_clear(&bigValue);
  885. Py_DECREF(hexstr);
  886. PyErr_NoMemory();
  887. return NULL;
  888. }
  889. Py_DECREF(hexstr);
  890. bigValue.sign = neg ? MP_NEG : MP_ZPOS;
  891. result = Tcl_NewBignumObj(&bigValue);
  892. mp_clear(&bigValue);
  893. if (result == NULL) {
  894. PyErr_NoMemory();
  895. return NULL;
  896. }
  897. return result;
  898. }
  899. #endif
  900. static Tcl_Obj*
  901. AsObj(PyObject *value)
  902. {
  903. Tcl_Obj *result;
  904. if (PyBytes_Check(value)) {
  905. if (PyBytes_GET_SIZE(value) >= INT_MAX) {
  906. PyErr_SetString(PyExc_OverflowError, "bytes object is too long");
  907. return NULL;
  908. }
  909. return Tcl_NewByteArrayObj((unsigned char *)PyBytes_AS_STRING(value),
  910. (int)PyBytes_GET_SIZE(value));
  911. }
  912. if (PyBool_Check(value))
  913. return Tcl_NewBooleanObj(PyObject_IsTrue(value));
  914. if (PyLong_CheckExact(value)) {
  915. int overflow;
  916. long longValue;
  917. #ifdef TCL_WIDE_INT_TYPE
  918. Tcl_WideInt wideValue;
  919. #endif
  920. longValue = PyLong_AsLongAndOverflow(value, &overflow);
  921. if (!overflow) {
  922. return Tcl_NewLongObj(longValue);
  923. }
  924. /* If there is an overflow in the long conversion,
  925. fall through to wideInt handling. */
  926. #ifdef TCL_WIDE_INT_TYPE
  927. if (_PyLong_AsByteArray((PyLongObject *)value,
  928. (unsigned char *)(void *)&wideValue,
  929. sizeof(wideValue),
  930. PY_LITTLE_ENDIAN,
  931. /* signed */ 1) == 0) {
  932. return Tcl_NewWideIntObj(wideValue);
  933. }
  934. PyErr_Clear();
  935. #endif
  936. /* If there is an overflow in the wideInt conversion,
  937. fall through to bignum handling. */
  938. #ifdef HAVE_LIBTOMMATH
  939. return asBignumObj(value);
  940. #endif
  941. /* If there is no wideInt or bignum support,
  942. fall through to default object handling. */
  943. }
  944. if (PyFloat_Check(value))
  945. return Tcl_NewDoubleObj(PyFloat_AS_DOUBLE(value));
  946. if (PyTuple_Check(value) || PyList_Check(value)) {
  947. Tcl_Obj **argv;
  948. Py_ssize_t size, i;
  949. size = PySequence_Fast_GET_SIZE(value);
  950. if (size == 0)
  951. return Tcl_NewListObj(0, NULL);
  952. if (!CHECK_SIZE(size, sizeof(Tcl_Obj *))) {
  953. PyErr_SetString(PyExc_OverflowError,
  954. PyTuple_Check(value) ? "tuple is too long" :
  955. "list is too long");
  956. return NULL;
  957. }
  958. argv = (Tcl_Obj **) PyMem_Malloc(((size_t)size) * sizeof(Tcl_Obj *));
  959. if (!argv) {
  960. PyErr_NoMemory();
  961. return NULL;
  962. }
  963. for (i = 0; i < size; i++)
  964. argv[i] = AsObj(PySequence_Fast_GET_ITEM(value,i));
  965. result = Tcl_NewListObj((int)size, argv);
  966. PyMem_Free(argv);
  967. return result;
  968. }
  969. if (PyUnicode_Check(value)) {
  970. if (PyUnicode_READY(value) == -1)
  971. return NULL;
  972. Py_ssize_t size = PyUnicode_GET_LENGTH(value);
  973. if (size == 0) {
  974. return Tcl_NewStringObj("", 0);
  975. }
  976. if (!CHECK_SIZE(size, sizeof(Tcl_UniChar))) {
  977. PyErr_SetString(PyExc_OverflowError, "string is too long");
  978. return NULL;
  979. }
  980. if (PyUnicode_IS_ASCII(value)) {
  981. return Tcl_NewStringObj((const char *)PyUnicode_DATA(value),
  982. (int)size);
  983. }
  984. PyObject *encoded;
  985. #if USE_TCL_UNICODE
  986. if (sizeof(Tcl_UniChar) == 2)
  987. encoded = _PyUnicode_EncodeUTF16(value,
  988. "surrogatepass", NATIVE_BYTEORDER);
  989. else if (sizeof(Tcl_UniChar) == 4)
  990. encoded = _PyUnicode_EncodeUTF32(value,
  991. "surrogatepass", NATIVE_BYTEORDER);
  992. else
  993. Py_UNREACHABLE();
  994. #else
  995. encoded = _PyUnicode_AsUTF8String(value, "surrogateescape");
  996. #endif
  997. if (!encoded) {
  998. return NULL;
  999. }
  1000. size = PyBytes_GET_SIZE(encoded);
  1001. if (size > INT_MAX) {
  1002. Py_DECREF(encoded);
  1003. PyErr_SetString(PyExc_OverflowError, "string is too long");
  1004. return NULL;
  1005. }
  1006. #if USE_TCL_UNICODE
  1007. result = Tcl_NewUnicodeObj((const Tcl_UniChar *)PyBytes_AS_STRING(encoded),
  1008. (int)(size / sizeof(Tcl_UniChar)));
  1009. #else
  1010. result = Tcl_NewStringObj(PyBytes_AS_STRING(encoded), (int)size);
  1011. #endif
  1012. Py_DECREF(encoded);
  1013. return result;
  1014. }
  1015. if (PyTclObject_Check(value)) {
  1016. return ((PyTclObject*)value)->value;
  1017. }
  1018. {
  1019. PyObject *v = PyObject_Str(value);
  1020. if (!v)
  1021. return 0;
  1022. result = AsObj(v);
  1023. Py_DECREF(v);
  1024. return result;
  1025. }
  1026. }
  1027. static PyObject *
  1028. fromBoolean(TkappObject *tkapp, Tcl_Obj *value)
  1029. {
  1030. int boolValue;
  1031. if (Tcl_GetBooleanFromObj(Tkapp_Interp(tkapp), value, &boolValue) == TCL_ERROR)
  1032. return Tkinter_Error(tkapp);
  1033. return PyBool_FromLong(boolValue);
  1034. }
  1035. static PyObject*
  1036. fromWideIntObj(TkappObject *tkapp, Tcl_Obj *value)
  1037. {
  1038. Tcl_WideInt wideValue;
  1039. if (Tcl_GetWideIntFromObj(Tkapp_Interp(tkapp), value, &wideValue) == TCL_OK) {
  1040. if (sizeof(wideValue) <= SIZEOF_LONG_LONG)
  1041. return PyLong_FromLongLong(wideValue);
  1042. return _PyLong_FromByteArray((unsigned char *)(void *)&wideValue,
  1043. sizeof(wideValue),
  1044. PY_LITTLE_ENDIAN,
  1045. /* signed */ 1);
  1046. }
  1047. return NULL;
  1048. }
  1049. #ifdef HAVE_LIBTOMMATH
  1050. static PyObject*
  1051. fromBignumObj(TkappObject *tkapp, Tcl_Obj *value)
  1052. {
  1053. mp_int bigValue;
  1054. unsigned long numBytes;
  1055. unsigned char *bytes;
  1056. PyObject *res;
  1057. if (Tcl_GetBignumFromObj(Tkapp_Interp(tkapp), value, &bigValue) != TCL_OK)
  1058. return Tkinter_Error(tkapp);
  1059. numBytes = mp_unsigned_bin_size(&bigValue);
  1060. bytes = PyMem_Malloc(numBytes);
  1061. if (bytes == NULL) {
  1062. mp_clear(&bigValue);
  1063. return PyErr_NoMemory();
  1064. }
  1065. if (mp_to_unsigned_bin_n(&bigValue, bytes,
  1066. &numBytes) != MP_OKAY) {
  1067. mp_clear(&bigValue);
  1068. PyMem_Free(bytes);
  1069. return PyErr_NoMemory();
  1070. }
  1071. res = _PyLong_FromByteArray(bytes, numBytes,
  1072. /* big-endian */ 0,
  1073. /* unsigned */ 0);
  1074. PyMem_Free(bytes);
  1075. if (res != NULL && bigValue.sign == MP_NEG) {
  1076. PyObject *res2 = PyNumber_Negative(res);
  1077. Py_DECREF(res);
  1078. res = res2;
  1079. }
  1080. mp_clear(&bigValue);
  1081. return res;
  1082. }
  1083. #endif
  1084. static PyObject*
  1085. FromObj(TkappObject *tkapp, Tcl_Obj *value)
  1086. {
  1087. PyObject *result = NULL;
  1088. Tcl_Interp *interp = Tkapp_Interp(tkapp);
  1089. if (value->typePtr == NULL) {
  1090. return unicodeFromTclObj(value);
  1091. }
  1092. if (value->typePtr == tkapp->BooleanType ||
  1093. value->typePtr == tkapp->OldBooleanType) {
  1094. return fromBoolean(tkapp, value);
  1095. }
  1096. if (value->typePtr == tkapp->ByteArrayType) {
  1097. int size;
  1098. char *data = (char*)Tcl_GetByteArrayFromObj(value, &size);
  1099. return PyBytes_FromStringAndSize(data, size);
  1100. }
  1101. if (value->typePtr == tkapp->DoubleType) {
  1102. return PyFloat_FromDouble(value->internalRep.doubleValue);
  1103. }
  1104. if (value->typePtr == tkapp->IntType) {
  1105. long longValue;
  1106. if (Tcl_GetLongFromObj(interp, value, &longValue) == TCL_OK)
  1107. return PyLong_FromLong(longValue);
  1108. /* If there is an error in the long conversion,
  1109. fall through to wideInt handling. */
  1110. }
  1111. if (value->typePtr == tkapp->IntType ||
  1112. value->typePtr == tkapp->WideIntType) {
  1113. result = fromWideIntObj(tkapp, value);
  1114. if (result != NULL || PyErr_Occurred())
  1115. return result;
  1116. Tcl_ResetResult(interp);
  1117. /* If there is an error in the wideInt conversion,
  1118. fall through to bignum handling. */
  1119. }
  1120. #ifdef HAVE_LIBTOMMATH
  1121. if (value->typePtr == tkapp->IntType ||
  1122. value->typePtr == tkapp->WideIntType ||
  1123. value->typePtr == tkapp->BignumType) {
  1124. return fromBignumObj(tkapp, value);
  1125. }
  1126. #endif
  1127. if (value->typePtr == tkapp->ListType) {
  1128. int size;
  1129. int i, status;
  1130. PyObject *elem;
  1131. Tcl_Obj *tcl_elem;
  1132. status = Tcl_ListObjLength(interp, value, &size);
  1133. if (status == TCL_ERROR)
  1134. return Tkinter_Error(tkapp);
  1135. result = PyTuple_New(size);
  1136. if (!result)
  1137. return NULL;
  1138. for (i = 0; i < size; i++) {
  1139. status = Tcl_ListObjIndex(interp, value, i, &tcl_elem);
  1140. if (status == TCL_ERROR) {
  1141. Py_DECREF(result);
  1142. return Tkinter_Error(tkapp);
  1143. }
  1144. elem = FromObj(tkapp, tcl_elem);
  1145. if (!elem) {
  1146. Py_DECREF(result);
  1147. return NULL;
  1148. }
  1149. PyTuple_SET_ITEM(result, i, elem);
  1150. }
  1151. return result;
  1152. }
  1153. if (value->typePtr == tkapp->ProcBodyType) {
  1154. /* fall through: return tcl object. */
  1155. }
  1156. if (value->typePtr == tkapp->StringType) {
  1157. return unicodeFromTclObj(value);
  1158. }
  1159. #if TK_HEX_VERSION >= 0x08050000
  1160. if (tkapp->BooleanType == NULL &&
  1161. strcmp(value->typePtr->name, "booleanString") == 0) {
  1162. /* booleanString type is not registered in Tcl */
  1163. tkapp->BooleanType = value->typePtr;
  1164. return fromBoolean(tkapp, value);
  1165. }
  1166. #endif
  1167. #ifdef HAVE_LIBTOMMATH
  1168. if (tkapp->BignumType == NULL &&
  1169. strcmp(value->typePtr->name, "bignum") == 0) {
  1170. /* bignum type is not registered in Tcl */
  1171. tkapp->BignumType = value->typePtr;
  1172. return fromBignumObj(tkapp, value);
  1173. }
  1174. #endif
  1175. return newPyTclObject(value);
  1176. }
  1177. /* This mutex synchronizes inter-thread command calls. */
  1178. TCL_DECLARE_MUTEX(call_mutex)
  1179. typedef struct Tkapp_CallEvent {
  1180. Tcl_Event ev; /* Must be first */
  1181. TkappObject *self;
  1182. PyObject *args;
  1183. int flags;
  1184. PyObject **res;
  1185. PyObject **exc_type, **exc_value, **exc_tb;
  1186. Tcl_Condition *done;
  1187. } Tkapp_CallEvent;
  1188. void
  1189. Tkapp_CallDeallocArgs(Tcl_Obj** objv, Tcl_Obj** objStore, int objc)
  1190. {
  1191. int i;
  1192. for (i = 0; i < objc; i++)
  1193. Tcl_DecrRefCount(objv[i]);
  1194. if (objv != objStore)
  1195. PyMem_Free(objv);
  1196. }
  1197. /* Convert Python objects to Tcl objects. This must happen in the
  1198. interpreter thread, which may or may not be the calling thread. */
  1199. static Tcl_Obj**
  1200. Tkapp_CallArgs(PyObject *args, Tcl_Obj** objStore, int *pobjc)
  1201. {
  1202. Tcl_Obj **objv = objStore;
  1203. Py_ssize_t objc = 0, i;
  1204. if (args == NULL)
  1205. /* do nothing */;
  1206. else if (!(PyTuple_Check(args) || PyList_Check(args))) {
  1207. objv[0] = AsObj(args);
  1208. if (objv[0] == NULL)
  1209. goto finally;
  1210. objc = 1;
  1211. Tcl_IncrRefCount(objv[0]);
  1212. }
  1213. else {
  1214. objc = PySequence_Fast_GET_SIZE(args);
  1215. if (objc > ARGSZ) {
  1216. if (!CHECK_SIZE(objc, sizeof(Tcl_Obj *))) {
  1217. PyErr_SetString(PyExc_OverflowError,
  1218. PyTuple_Check(args) ? "tuple is too long" :
  1219. "list is too long");
  1220. return NULL;
  1221. }
  1222. objv = (Tcl_Obj **)PyMem_Malloc(((size_t)objc) * sizeof(Tcl_Obj *));
  1223. if (objv == NULL) {
  1224. PyErr_NoMemory();
  1225. objc = 0;
  1226. goto finally;
  1227. }
  1228. }
  1229. for (i = 0; i < objc; i++) {
  1230. PyObject *v = PySequence_Fast_GET_ITEM(args, i);
  1231. if (v == Py_None) {
  1232. objc = i;
  1233. break;
  1234. }
  1235. objv[i] = AsObj(v);
  1236. if (!objv[i]) {
  1237. /* Reset objc, so it attempts to clear
  1238. objects only up to i. */
  1239. objc = i;
  1240. goto finally;
  1241. }
  1242. Tcl_IncrRefCount(objv[i]);
  1243. }
  1244. }
  1245. *pobjc = (int)objc;
  1246. return objv;
  1247. finally:
  1248. Tkapp_CallDeallocArgs(objv, objStore, (int)objc);
  1249. return NULL;
  1250. }
  1251. /* Convert the results of a command call into a Python string. */
  1252. static PyObject *
  1253. Tkapp_UnicodeResult(TkappObject *self)
  1254. {
  1255. return unicodeFromTclObj(Tcl_GetObjResult(self->interp));
  1256. }
  1257. /* Convert the results of a command call into a Python objects. */
  1258. static PyObject *
  1259. Tkapp_ObjectResult(TkappObject *self)
  1260. {
  1261. PyObject *res = NULL;
  1262. Tcl_Obj *value = Tcl_GetObjResult(self->interp);
  1263. if (self->wantobjects) {
  1264. /* Not sure whether the IncrRef is necessary, but something
  1265. may overwrite the interpreter result while we are
  1266. converting it. */
  1267. Tcl_IncrRefCount(value);
  1268. res = FromObj(self, value);
  1269. Tcl_DecrRefCount(value);
  1270. } else {
  1271. res = unicodeFromTclObj(value);
  1272. }
  1273. return res;
  1274. }
  1275. /* Tkapp_CallProc is the event procedure that is executed in the context of
  1276. the Tcl interpreter thread. Initially, it holds the Tcl lock, and doesn't
  1277. hold the Python lock. */
  1278. static int
  1279. Tkapp_CallProc(Tkapp_CallEvent *e, int flags)
  1280. {
  1281. Tcl_Obj *objStore[ARGSZ];
  1282. Tcl_Obj **objv;
  1283. int objc;
  1284. int i;
  1285. ENTER_PYTHON
  1286. objv = Tkapp_CallArgs(e->args, objStore, &objc);
  1287. if (!objv) {
  1288. PyErr_Fetch(e->exc_type, e->exc_value, e->exc_tb);
  1289. *(e->res) = NULL;
  1290. }
  1291. LEAVE_PYTHON
  1292. if (!objv)
  1293. goto done;
  1294. i = Tcl_EvalObjv(e->self->interp, objc, objv, e->flags);
  1295. ENTER_PYTHON
  1296. if (i == TCL_ERROR) {
  1297. *(e->res) = Tkinter_Error(e->self);
  1298. }
  1299. else {
  1300. *(e->res) = Tkapp_ObjectResult(e->self);
  1301. }
  1302. if (*(e->res) == NULL) {
  1303. PyErr_Fetch(e->exc_type, e->exc_value, e->exc_tb);
  1304. }
  1305. LEAVE_PYTHON
  1306. Tkapp_CallDeallocArgs(objv, objStore, objc);
  1307. done:
  1308. /* Wake up calling thread. */
  1309. Tcl_MutexLock(&call_mutex);
  1310. Tcl_ConditionNotify(e->done);
  1311. Tcl_MutexUnlock(&call_mutex);
  1312. return 1;
  1313. }
  1314. /* This is the main entry point for calling a Tcl command.
  1315. It supports three cases, with regard to threading:
  1316. 1. Tcl is not threaded: Must have the Tcl lock, then can invoke command in
  1317. the context of the calling thread.
  1318. 2. Tcl is threaded, caller of the command is in the interpreter thread:
  1319. Execute the command in the calling thread. Since the Tcl lock will
  1320. not be used, we can merge that with case 1.
  1321. 3. Tcl is threaded, caller is in a different thread: Must queue an event to
  1322. the interpreter thread. Allocation of Tcl objects needs to occur in the
  1323. interpreter thread, so we ship the PyObject* args to the target thread,
  1324. and perform processing there. */
  1325. static PyObject *
  1326. Tkapp_Call(PyObject *selfptr, PyObject *args)
  1327. {
  1328. Tcl_Obj *objStore[ARGSZ];
  1329. Tcl_Obj **objv = NULL;
  1330. int objc, i;
  1331. PyObject *res = NULL;
  1332. TkappObject *self = (TkappObject*)selfptr;
  1333. int flags = TCL_EVAL_DIRECT | TCL_EVAL_GLOBAL;
  1334. /* If args is a single tuple, replace with contents of tuple */
  1335. if (PyTuple_GET_SIZE(args) == 1) {
  1336. PyObject *item = PyTuple_GET_ITEM(args, 0);
  1337. if (PyTuple_Check(item))
  1338. args = item;
  1339. }
  1340. if (self->threaded && self->thread_id != Tcl_GetCurrentThread()) {
  1341. /* We cannot call the command directly. Instead, we must
  1342. marshal the parameters to the interpreter thread. */
  1343. Tkapp_CallEvent *ev;
  1344. Tcl_Condition cond = NULL;
  1345. PyObject *exc_type, *exc_value, *exc_tb;
  1346. if (!WaitForMainloop(self))
  1347. return NULL;
  1348. ev = (Tkapp_CallEvent*)attemptckalloc(sizeof(Tkapp_CallEvent));
  1349. if (ev == NULL) {
  1350. PyErr_NoMemory();
  1351. return NULL;
  1352. }
  1353. ev->ev.proc = (Tcl_EventProc*)Tkapp_CallProc;
  1354. ev->self = self;
  1355. ev->args = args;
  1356. ev->res = &res;
  1357. ev->exc_type = &exc_type;
  1358. ev->exc_value = &exc_value;
  1359. ev->exc_tb = &exc_tb;
  1360. ev->done = &cond;
  1361. Tkapp_ThreadSend(self, (Tcl_Event*)ev, &cond, &call_mutex);
  1362. if (res == NULL) {
  1363. if (exc_type)
  1364. PyErr_Restore(exc_type, exc_value, exc_tb);
  1365. else
  1366. PyErr_SetObject(Tkinter_TclError, exc_value);
  1367. }
  1368. Tcl_ConditionFinalize(&cond);
  1369. }
  1370. else
  1371. {
  1372. objv = Tkapp_CallArgs(args, objStore, &objc);
  1373. if (!objv)
  1374. return NULL;
  1375. ENTER_TCL
  1376. i = Tcl_EvalObjv(self->interp, objc, objv, flags);
  1377. ENTER_OVERLAP
  1378. if (i == TCL_ERROR)
  1379. Tkinter_Error(self);
  1380. else
  1381. res = Tkapp_ObjectResult(self);
  1382. LEAVE_OVERLAP_TCL
  1383. Tkapp_CallDeallocArgs(objv, objStore, objc);
  1384. }
  1385. return res;
  1386. }
  1387. /*[clinic input]
  1388. _tkinter.tkapp.eval
  1389. script: str
  1390. /
  1391. [clinic start generated code]*/
  1392. static PyObject *
  1393. _tkinter_tkapp_eval_impl(TkappObject *self, const char *script)
  1394. /*[clinic end generated code: output=24b79831f700dea0 input=481484123a455f22]*/
  1395. {
  1396. PyObject *res = NULL;
  1397. int err;
  1398. CHECK_STRING_LENGTH(script);
  1399. CHECK_TCL_APPARTMENT;
  1400. ENTER_TCL
  1401. err = Tcl_Eval(Tkapp_Interp(self), script);
  1402. ENTER_OVERLAP
  1403. if (err == TCL_ERROR)
  1404. res = Tkinter_Error(self);
  1405. else
  1406. res = Tkapp_UnicodeResult(self);
  1407. LEAVE_OVERLAP_TCL
  1408. return res;
  1409. }
  1410. /*[clinic input]
  1411. _tkinter.tkapp.evalfile
  1412. fileName: str
  1413. /
  1414. [clinic start generated code]*/
  1415. static PyObject *
  1416. _tkinter_tkapp_evalfile_impl(TkappObject *self, const char *fileName)
  1417. /*[clinic end generated code: output=63be88dcee4f11d3 input=873ab707e5e947e1]*/
  1418. {
  1419. PyObject *res = NULL;
  1420. int err;
  1421. CHECK_STRING_LENGTH(fileName);
  1422. CHECK_TCL_APPARTMENT;
  1423. ENTER_TCL
  1424. err = Tcl_EvalFile(Tkapp_Interp(self), fileName);
  1425. ENTER_OVERLAP
  1426. if (err == TCL_ERROR)
  1427. res = Tkinter_Error(self);
  1428. else
  1429. res = Tkapp_UnicodeResult(self);
  1430. LEAVE_OVERLAP_TCL
  1431. return res;
  1432. }
  1433. /*[clinic input]
  1434. _tkinter.tkapp.record
  1435. script: str
  1436. /
  1437. [clinic start generated code]*/
  1438. static PyObject *
  1439. _tkinter_tkapp_record_impl(TkappObject *self, const char *script)
  1440. /*[clinic end generated code: output=0ffe08a0061730df input=c0b0db5a21412cac]*/
  1441. {
  1442. PyObject *res = NULL;
  1443. int err;
  1444. CHECK_STRING_LENGTH(script);
  1445. CHECK_TCL_APPARTMENT;
  1446. ENTER_TCL
  1447. err = Tcl_RecordAndEval(Tkapp_Interp(self), script, TCL_NO_EVAL);
  1448. ENTER_OVERLAP
  1449. if (err == TCL_ERROR)
  1450. res = Tkinter_Error(self);
  1451. else
  1452. res = Tkapp_UnicodeResult(self);
  1453. LEAVE_OVERLAP_TCL
  1454. return res;
  1455. }
  1456. /*[clinic input]
  1457. _tkinter.tkapp.adderrorinfo
  1458. msg: str
  1459. /
  1460. [clinic start generated code]*/
  1461. static PyObject *
  1462. _tkinter_tkapp_adderrorinfo_impl(TkappObject *self, const char *msg)
  1463. /*[clinic end generated code: output=52162eaca2ee53cb input=f4b37aec7c7e8c77]*/
  1464. {
  1465. CHECK_STRING_LENGTH(msg);
  1466. CHECK_TCL_APPARTMENT;
  1467. ENTER_TCL
  1468. Tcl_AddErrorInfo(Tkapp_Interp(self), msg);
  1469. LEAVE_TCL
  1470. Py_RETURN_NONE;
  1471. }
  1472. /** Tcl Variable **/
  1473. typedef PyObject* (*EventFunc)(TkappObject *, PyObject *, int);
  1474. TCL_DECLARE_MUTEX(var_mutex)
  1475. typedef struct VarEvent {
  1476. Tcl_Event ev; /* must be first */
  1477. TkappObject *self;
  1478. PyObject *args;
  1479. int flags;
  1480. EventFunc func;
  1481. PyObject **res;
  1482. PyObject **exc_type;
  1483. PyObject **exc_val;
  1484. Tcl_Condition *cond;
  1485. } VarEvent;
  1486. /*[python]
  1487. class varname_converter(CConverter):
  1488. type = 'const char *'
  1489. converter = 'varname_converter'
  1490. [python]*/
  1491. /*[python checksum: da39a3ee5e6b4b0d3255bfef95601890afd80709]*/
  1492. static int
  1493. varname_converter(PyObject *in, void *_out)
  1494. {
  1495. const char *s;
  1496. const char **out = (const char**)_out;
  1497. if (PyBytes_Check(in)) {
  1498. if (PyBytes_GET_SIZE(in) > INT_MAX) {
  1499. PyErr_SetString(PyExc_OverflowError, "bytes object is too long");
  1500. return 0;
  1501. }
  1502. s = PyBytes_AS_STRING(in);
  1503. if (strlen(s) != (size_t)PyBytes_GET_SIZE(in)) {
  1504. PyErr_SetString(PyExc_ValueError, "embedded null byte");
  1505. return 0;
  1506. }
  1507. *out = s;
  1508. return 1;
  1509. }
  1510. if (PyUnicode_Check(in)) {
  1511. Py_ssize_t size;
  1512. s = PyUnicode_AsUTF8AndSize(in, &size);
  1513. if (s == NULL) {
  1514. return 0;
  1515. }
  1516. if (size > INT_MAX) {
  1517. PyErr_SetString(PyExc_OverflowError, "string is too long");
  1518. return 0;
  1519. }
  1520. if (strlen(s) != (size_t)size) {
  1521. PyErr_SetString(PyExc_ValueError, "embedded null character");
  1522. return 0;
  1523. }
  1524. *out = s;
  1525. return 1;
  1526. }
  1527. if (PyTclObject_Check(in)) {
  1528. *out = Tcl_GetString(((PyTclObject *)in)->value);
  1529. return 1;
  1530. }
  1531. PyErr_Format(PyExc_TypeError,
  1532. "must be str, bytes or Tcl_Obj, not %.50s",
  1533. Py_TYPE(in)->tp_name);
  1534. return 0;
  1535. }
  1536. static void
  1537. var_perform(VarEvent *ev)
  1538. {
  1539. *(ev->res) = ev->func(ev->self, ev->args, ev->flags);
  1540. if (!*(ev->res)) {
  1541. PyObject *exc, *val, *tb;
  1542. PyErr_Fetch(&exc, &val, &tb);
  1543. PyErr_NormalizeException(&exc, &val, &tb);
  1544. *(ev->exc_type) = exc;
  1545. *(ev->exc_val) = val;
  1546. Py_XDECREF(tb);
  1547. }
  1548. }
  1549. static int
  1550. var_proc(VarEvent* ev, int flags)
  1551. {
  1552. ENTER_PYTHON
  1553. var_perform(ev);
  1554. Tcl_MutexLock(&var_mutex);
  1555. Tcl_ConditionNotify(ev->cond);
  1556. Tcl_MutexUnlock(&var_mutex);
  1557. LEAVE_PYTHON
  1558. return 1;
  1559. }
  1560. static PyObject*
  1561. var_invoke(EventFunc func, PyObject *selfptr, PyObject *args, int flags)
  1562. {
  1563. TkappObject *self = (TkappObject*)selfptr;
  1564. if (self->threaded && self->thread_id != Tcl_GetCurrentThread()) {
  1565. VarEvent *ev;
  1566. PyObject *res, *exc_type, *exc_val;
  1567. Tcl_Condition cond = NULL;
  1568. /* The current thread is not the interpreter thread. Marshal
  1569. the call to the interpreter thread, then wait for
  1570. completion. */
  1571. if (!WaitForMainloop(self))
  1572. return NULL;
  1573. ev = (VarEvent*)attemptckalloc(sizeof(VarEvent));
  1574. if (ev == NULL) {
  1575. PyErr_NoMemory();
  1576. return NULL;
  1577. }
  1578. ev->self = self;
  1579. ev->args = args;
  1580. ev->flags = flags;
  1581. ev->func = func;
  1582. ev->res = &res;
  1583. ev->exc_type = &exc_type;
  1584. ev->exc_val = &exc_val;
  1585. ev->cond = &cond;
  1586. ev->ev.proc = (Tcl_EventProc*)var_proc;
  1587. Tkapp_ThreadSend(self, (Tcl_Event*)ev, &cond, &var_mutex);
  1588. Tcl_ConditionFinalize(&cond);
  1589. if (!res) {
  1590. PyErr_SetObject(exc_type, exc_val);
  1591. Py_DECREF(exc_type);
  1592. Py_DECREF(exc_val);
  1593. return NULL;
  1594. }
  1595. return res;
  1596. }
  1597. /* Tcl is not threaded, or this is the interpreter thread. */
  1598. return func(self, args, flags);
  1599. }
  1600. static PyObject *
  1601. SetVar(TkappObject *self, PyObject *args, int flags)
  1602. {
  1603. const char *name1, *name2;
  1604. PyObject *newValue;
  1605. PyObject *res = NULL;
  1606. Tcl_Obj *newval, *ok;
  1607. switch (PyTuple_GET_SIZE(args)) {
  1608. case 2:
  1609. if (!PyArg_ParseTuple(args, "O&O:setvar",
  1610. varname_converter, &name1, &newValue))
  1611. return NULL;
  1612. /* XXX Acquire tcl lock??? */
  1613. newval = AsObj(newValue);
  1614. if (newval == NULL)
  1615. return NULL;
  1616. ENTER_TCL
  1617. ok = Tcl_SetVar2Ex(Tkapp_Interp(self), name1, NULL,
  1618. newval, flags);
  1619. ENTER_OVERLAP
  1620. if (!ok)
  1621. Tkinter_Error(self);
  1622. else {
  1623. res = Py_None;
  1624. Py_INCREF(res);
  1625. }
  1626. LEAVE_OVERLAP_TCL
  1627. break;
  1628. case 3:
  1629. if (!PyArg_ParseTuple(args, "ssO:setvar",
  1630. &name1, &name2, &newValue))
  1631. return NULL;
  1632. CHECK_STRING_LENGTH(name1);
  1633. CHECK_STRING_LENGTH(name2);
  1634. /* XXX must hold tcl lock already??? */
  1635. newval = AsObj(newValue);
  1636. ENTER_TCL
  1637. ok = Tcl_SetVar2Ex(Tkapp_Interp(self), name1, name2, newval, flags);
  1638. ENTER_OVERLAP
  1639. if (!ok)
  1640. Tkinter_Error(self);
  1641. else {
  1642. res = Py_None;
  1643. Py_INCREF(res);
  1644. }
  1645. LEAVE_OVERLAP_TCL
  1646. break;
  1647. default:
  1648. PyErr_SetString(PyExc_TypeError, "setvar requires 2 to 3 arguments");
  1649. return NULL;
  1650. }
  1651. return res;
  1652. }
  1653. static PyObject *
  1654. Tkapp_SetVar(PyObject *self, PyObject *args)
  1655. {
  1656. return var_invoke(SetVar, self, args, TCL_LEAVE_ERR_MSG);
  1657. }
  1658. static PyObject *
  1659. Tkapp_GlobalSetVar(PyObject *self, PyObject *args)
  1660. {
  1661. return var_invoke(SetVar, self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY);
  1662. }
  1663. static PyObject *
  1664. GetVar(TkappObject *self, PyObject *args, int flags)
  1665. {
  1666. const char *name1, *name2=NULL;
  1667. PyObject *res = NULL;
  1668. Tcl_Obj *tres;
  1669. if (!PyArg_ParseTuple(args, "O&|s:getvar",
  1670. varname_converter, &name1, &name2))
  1671. return NULL;
  1672. CHECK_STRING_LENGTH(name2);
  1673. ENTER_TCL
  1674. tres = Tcl_GetVar2Ex(Tkapp_Interp(self), name1, name2, flags);
  1675. ENTER_OVERLAP
  1676. if (tres == NULL) {
  1677. Tkinter_Error(self);
  1678. } else {
  1679. if (self->wantobjects) {
  1680. res = FromObj(self, tres);
  1681. }
  1682. else {
  1683. res = unicodeFromTclObj(tres);
  1684. }
  1685. }
  1686. LEAVE_OVERLAP_TCL
  1687. return res;
  1688. }
  1689. static PyObject *
  1690. Tkapp_GetVar(PyObject *self, PyObject *args)
  1691. {
  1692. return var_invoke(GetVar, self, args, TCL_LEAVE_ERR_MSG);
  1693. }
  1694. static PyObject *
  1695. Tkapp_GlobalGetVar(PyObject *self, PyObject *args)
  1696. {
  1697. return var_invoke(GetVar, self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY);
  1698. }
  1699. static PyObject *
  1700. UnsetVar(TkappObject *self, PyObject *args, int flags)
  1701. {
  1702. char *name1, *name2=NULL;
  1703. int code;
  1704. PyObject *res = NULL;
  1705. if (!PyArg_ParseTuple(args, "s|s:unsetvar", &name1, &name2))
  1706. return NULL;
  1707. CHECK_STRING_LENGTH(name1);
  1708. CHECK_STRING_LENGTH(name2);
  1709. ENTER_TCL
  1710. code = Tcl_UnsetVar2(Tkapp_Interp(self), name1, name2, flags);
  1711. ENTER_OVERLAP
  1712. if (code == TCL_ERROR)
  1713. res = Tkinter_Error(self);
  1714. else {
  1715. Py_INCREF(Py_None);
  1716. res = Py_None;
  1717. }
  1718. LEAVE_OVERLAP_TCL
  1719. return res;
  1720. }
  1721. static PyObject *
  1722. Tkapp_UnsetVar(PyObject *self, PyObject *args)
  1723. {
  1724. return var_invoke(UnsetVar, self, args, TCL_LEAVE_ERR_MSG);
  1725. }
  1726. static PyObject *
  1727. Tkapp_GlobalUnsetVar(PyObject *self, PyObject *args)
  1728. {
  1729. return var_invoke(UnsetVar, self, args,
  1730. TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY);
  1731. }
  1732. /** Tcl to Python **/
  1733. /*[clinic input]
  1734. _tkinter.tkapp.getint
  1735. arg: object
  1736. /
  1737. [clinic start generated code]*/
  1738. static PyObject *
  1739. _tkinter_tkapp_getint(TkappObject *self, PyObject *arg)
  1740. /*[clinic end generated code: output=88cf293fae307cfe input=034026997c5b91f8]*/
  1741. {
  1742. char *s;
  1743. Tcl_Obj *value;
  1744. PyObject *result;
  1745. if (PyLong_Check(arg)) {
  1746. Py_INCREF(arg);
  1747. return arg;
  1748. }
  1749. if (PyTclObject_Check(arg)) {
  1750. value = ((PyTclObject*)arg)->value;
  1751. Tcl_IncrRefCount(value);
  1752. }
  1753. else {
  1754. if (!PyArg_Parse(arg, "s:getint", &s))
  1755. return NULL;
  1756. CHECK_STRING_LENGTH(s);
  1757. value = Tcl_NewStringObj(s, -1);
  1758. if (value == NULL)
  1759. return Tkinter_Error(self);
  1760. }
  1761. /* Don't use Tcl_GetInt() because it returns ambiguous result for value
  1762. in ranges -2**32..-2**31-1 and 2**31..2**32-1 (on 32-bit platform).
  1763. Prefer bignum because Tcl_GetWideIntFromObj returns ambiguous result for
  1764. value in ranges -2**64..-2**63-1 and 2**63..2**64-1 (on 32-bit platform).
  1765. */
  1766. #ifdef HAVE_LIBTOMMATH
  1767. result = fromBignumObj(self, value);
  1768. #else
  1769. result = fromWideIntObj(self, value);
  1770. #endif
  1771. Tcl_DecrRefCount(value);
  1772. if (result != NULL || PyErr_Occurred())
  1773. return result;
  1774. return Tkinter_Error(self);
  1775. }
  1776. /*[clinic input]
  1777. _tkinter.tkapp.getdouble
  1778. arg: object
  1779. /
  1780. [clinic start generated code]*/
  1781. static PyObject *
  1782. _tkinter_tkapp_getdouble(TkappObject *self, PyObject *arg)
  1783. /*[clinic end generated code: output=c52b138bd8b956b9 input=22015729ce9ef7f8]*/
  1784. {
  1785. char *s;
  1786. double v;
  1787. if (PyFloat_Check(arg)) {
  1788. Py_INCREF(arg);
  1789. return arg;
  1790. }
  1791. if (PyNumber_Check(arg)) {
  1792. return PyNumber_Float(arg);
  1793. }
  1794. if (PyTclObject_Check(arg)) {
  1795. if (Tcl_GetDoubleFromObj(Tkapp_Interp(self),
  1796. ((PyTclObject*)arg)->value,
  1797. &v) == TCL_ERROR)
  1798. return Tkinter_Error(self);
  1799. return PyFloat_FromDouble(v);
  1800. }
  1801. if (!PyArg_Parse(arg, "s:getdouble", &s))
  1802. return NULL;
  1803. CHECK_STRING_LENGTH(s);
  1804. if (Tcl_GetDouble(Tkapp_Interp(self), s, &v) == TCL_ERROR)
  1805. return Tkinter_Error(self);
  1806. return PyFloat_FromDouble(v);
  1807. }
  1808. /*[clinic input]
  1809. _tkinter.tkapp.getboolean
  1810. arg: object
  1811. /
  1812. [clinic start generated code]*/
  1813. static PyObject *
  1814. _tkinter_tkapp_getboolean(TkappObject *self, PyObject *arg)
  1815. /*[clinic end generated code: output=726a9ae445821d91 input=7f11248ef8f8776e]*/
  1816. {
  1817. char *s;
  1818. int v;
  1819. if (PyLong_Check(arg)) { /* int or bool */
  1820. return PyBool_FromLong(Py_SIZE(arg) != 0);
  1821. }
  1822. if (PyTclObject_Check(arg)) {
  1823. if (Tcl_GetBooleanFromObj(Tkapp_Interp(self),
  1824. ((PyTclObject*)arg)->value,
  1825. &v) == TCL_ERROR)
  1826. return Tkinter_Error(self);
  1827. return PyBool_FromLong(v);
  1828. }
  1829. if (!PyArg_Parse(arg, "s:getboolean", &s))
  1830. return NULL;
  1831. CHECK_STRING_LENGTH(s);
  1832. if (Tcl_GetBoolean(Tkapp_Interp(self), s, &v) == TCL_ERROR)
  1833. return Tkinter_Error(self);
  1834. return PyBool_FromLong(v);
  1835. }
  1836. /*[clinic input]
  1837. _tkinter.tkapp.exprstring
  1838. s: str
  1839. /
  1840. [clinic start generated code]*/
  1841. static PyObject *
  1842. _tkinter_tkapp_exprstring_impl(TkappObject *self, const char *s)
  1843. /*[clinic end generated code: output=beda323d3ed0abb1 input=fa78f751afb2f21b]*/
  1844. {
  1845. PyObject *res = NULL;
  1846. int retval;
  1847. CHECK_STRING_LENGTH(s);
  1848. CHECK_TCL_APPARTMENT;
  1849. ENTER_TCL
  1850. retval = Tcl_ExprString(Tkapp_Interp(self), s);
  1851. ENTER_OVERLAP
  1852. if (retval == TCL_ERROR)
  1853. res = Tkinter_Error(self);
  1854. else
  1855. res = Tkapp_UnicodeResult(self);
  1856. LEAVE_OVERLAP_TCL
  1857. return res;
  1858. }
  1859. /*[clinic input]
  1860. _tkinter.tkapp.exprlong
  1861. s: str
  1862. /
  1863. [clinic start generated code]*/
  1864. static PyObject *
  1865. _tkinter_tkapp_exprlong_impl(TkappObject *self, const char *s)
  1866. /*[clinic end generated code: output=5d6a46b63c6ebcf9 input=11bd7eee0c57b4dc]*/
  1867. {
  1868. PyObject *res = NULL;
  1869. int retval;
  1870. long v;
  1871. CHECK_STRING_LENGTH(s);
  1872. CHECK_TCL_APPARTMENT;
  1873. ENTER_TCL
  1874. retval = Tcl_ExprLong(Tkapp_Interp(self), s, &v);
  1875. ENTER_OVERLAP
  1876. if (retval == TCL_ERROR)
  1877. res = Tkinter_Error(self);
  1878. else
  1879. res = PyLong_FromLong(v);
  1880. LEAVE_OVERLAP_TCL
  1881. return res;
  1882. }
  1883. /*[clinic input]
  1884. _tkinter.tkapp.exprdouble
  1885. s: str
  1886. /
  1887. [clinic start generated code]*/
  1888. static PyObject *
  1889. _tkinter_tkapp_exprdouble_impl(TkappObject *self, const char *s)
  1890. /*[clinic end generated code: output=ff78df1081ea4158 input=ff02bc11798832d5]*/
  1891. {
  1892. PyObject *res = NULL;
  1893. double v;
  1894. int retval;
  1895. CHECK_STRING_LENGTH(s);
  1896. CHECK_TCL_APPARTMENT;
  1897. ENTER_TCL
  1898. retval = Tcl_ExprDouble(Tkapp_Interp(self), s, &v);
  1899. ENTER_OVERLAP
  1900. if (retval == TCL_ERROR)
  1901. res = Tkinter_Error(self);
  1902. else
  1903. res = PyFloat_FromDouble(v);
  1904. LEAVE_OVERLAP_TCL
  1905. return res;
  1906. }
  1907. /*[clinic input]
  1908. _tkinter.tkapp.exprboolean
  1909. s: str
  1910. /
  1911. [clinic start generated code]*/
  1912. static PyObject *
  1913. _tkinter_tkapp_exprboolean_impl(TkappObject *self, const char *s)
  1914. /*[clinic end generated code: output=8b28038c22887311 input=c8c66022bdb8d5d3]*/
  1915. {
  1916. PyObject *res = NULL;
  1917. int retval;
  1918. int v;
  1919. CHECK_STRING_LENGTH(s);
  1920. CHECK_TCL_APPARTMENT;
  1921. ENTER_TCL
  1922. retval = Tcl_ExprBoolean(Tkapp_Interp(self), s, &v);
  1923. ENTER_OVERLAP
  1924. if (retval == TCL_ERROR)
  1925. res = Tkinter_Error(self);
  1926. else
  1927. res = PyLong_FromLong(v);
  1928. LEAVE_OVERLAP_TCL
  1929. return res;
  1930. }
  1931. /*[clinic input]
  1932. _tkinter.tkapp.splitlist
  1933. arg: object
  1934. /
  1935. [clinic start generated code]*/
  1936. static PyObject *
  1937. _tkinter_tkapp_splitlist(TkappObject *self, PyObject *arg)
  1938. /*[clinic end generated code: output=13b51d34386d36fb input=2b2e13351e3c0b53]*/
  1939. {
  1940. char *list;
  1941. int argc;
  1942. const char **argv;
  1943. PyObject *v;
  1944. int i;
  1945. if (PyTclObject_Check(arg)) {
  1946. int objc;
  1947. Tcl_Obj **objv;
  1948. if (Tcl_ListObjGetElements(Tkapp_Interp(self),
  1949. ((PyTclObject*)arg)->value,
  1950. &objc, &objv) == TCL_ERROR) {
  1951. return Tkinter_Error(self);
  1952. }
  1953. if (!(v = PyTuple_New(objc)))
  1954. return NULL;
  1955. for (i = 0; i < objc; i++) {
  1956. PyObject *s = FromObj(self, objv[i]);
  1957. if (!s) {
  1958. Py_DECREF(v);
  1959. return NULL;
  1960. }
  1961. PyTuple_SET_ITEM(v, i, s);
  1962. }
  1963. return v;
  1964. }
  1965. if (PyTuple_Check(arg)) {
  1966. Py_INCREF(arg);
  1967. return arg;
  1968. }
  1969. if (PyList_Check(arg)) {
  1970. return PySequence_Tuple(arg);
  1971. }
  1972. if (!PyArg_Parse(arg, "et:splitlist", "utf-8", &list))
  1973. return NULL;
  1974. if (strlen(list) >= INT_MAX) {
  1975. PyErr_SetString(PyExc_OverflowError, "string is too long");
  1976. PyMem_Free(list);
  1977. return NULL;
  1978. }
  1979. if (Tcl_SplitList(Tkapp_Interp(self), list,
  1980. &argc, &argv) == TCL_ERROR) {
  1981. PyMem_Free(list);
  1982. return Tkinter_Error(self);
  1983. }
  1984. if (!(v = PyTuple_New(argc)))
  1985. goto finally;
  1986. for (i = 0; i < argc; i++) {
  1987. PyObject *s = unicodeFromTclString(argv[i]);
  1988. if (!s) {
  1989. Py_DECREF(v);
  1990. v = NULL;
  1991. goto finally;
  1992. }
  1993. PyTuple_SET_ITEM(v, i, s);
  1994. }
  1995. finally:
  1996. ckfree(FREECAST argv);
  1997. PyMem_Free(list);
  1998. return v;
  1999. }
  2000. /*[clinic input]
  2001. _tkinter.tkapp.split
  2002. arg: object
  2003. /
  2004. [clinic start generated code]*/
  2005. static PyObject *
  2006. _tkinter_tkapp_split(TkappObject *self, PyObject *arg)
  2007. /*[clinic end generated code: output=e08ad832363facfd input=a1c78349eacaa140]*/
  2008. {
  2009. PyObject *v;
  2010. char *list;
  2011. if (PyErr_WarnEx(PyExc_DeprecationWarning,
  2012. "split() is deprecated; consider using splitlist() instead", 1))
  2013. {
  2014. return NULL;
  2015. }
  2016. if (PyTclObject_Check(arg)) {
  2017. Tcl_Obj *value = ((PyTclObject*)arg)->value;
  2018. int objc;
  2019. Tcl_Obj **objv;
  2020. int i;
  2021. if (Tcl_ListObjGetElements(Tkapp_Interp(self), value,
  2022. &objc, &objv) == TCL_ERROR) {
  2023. return FromObj(self, value);
  2024. }
  2025. if (objc == 0)
  2026. return PyUnicode_FromString("");
  2027. if (objc == 1)
  2028. return FromObj(self, objv[0]);
  2029. if (!(v = PyTuple_New(objc)))
  2030. return NULL;
  2031. for (i = 0; i < objc; i++) {
  2032. PyObject *s = FromObj(self, objv[i]);
  2033. if (!s) {
  2034. Py_DECREF(v);
  2035. return NULL;
  2036. }
  2037. PyTuple_SET_ITEM(v, i, s);
  2038. }
  2039. return v;
  2040. }
  2041. if (PyTuple_Check(arg) || PyList_Check(arg))
  2042. return SplitObj(arg);
  2043. if (!PyArg_Parse(arg, "et:split", "utf-8", &list))
  2044. return NULL;
  2045. if (strlen(list) >= INT_MAX) {
  2046. PyErr_SetString(PyExc_OverflowError, "string is too long");
  2047. PyMem_Free(list);
  2048. return NULL;
  2049. }
  2050. v = Split(list);
  2051. PyMem_Free(list);
  2052. return v;
  2053. }
  2054. /** Tcl Command **/
  2055. /* Client data struct */
  2056. typedef struct {
  2057. PyObject *self;
  2058. PyObject *func;
  2059. } PythonCmd_ClientData;
  2060. static int
  2061. PythonCmd_Error(Tcl_Interp *interp)
  2062. {
  2063. errorInCmd = 1;
  2064. PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd);
  2065. LEAVE_PYTHON
  2066. return TCL_ERROR;
  2067. }
  2068. /* This is the Tcl command that acts as a wrapper for Python
  2069. * function or method.
  2070. */
  2071. static int
  2072. PythonCmd(ClientData clientData, Tcl_Interp *interp,
  2073. int objc, Tcl_Obj *const objv[])
  2074. {
  2075. PythonCmd_ClientData *data = (PythonCmd_ClientData *)clientData;
  2076. PyObject *args, *res;
  2077. int i;
  2078. Tcl_Obj *obj_res;
  2079. ENTER_PYTHON
  2080. /* Create argument tuple (objv1, ..., objvN) */
  2081. if (!(args = PyTuple_New(objc - 1)))
  2082. return PythonCmd_Error(interp);
  2083. for (i = 0; i < (objc - 1); i++) {
  2084. PyObject *s = unicodeFromTclObj(objv[i + 1]);
  2085. if (!s) {
  2086. Py_DECREF(args);
  2087. return PythonCmd_Error(interp);
  2088. }
  2089. PyTuple_SET_ITEM(args, i, s);
  2090. }
  2091. res = PyObject_Call(data->func, args, NULL);
  2092. Py_DECREF(args);
  2093. if (res == NULL)
  2094. return PythonCmd_Error(interp);
  2095. obj_res = AsObj(res);
  2096. if (obj_res == NULL) {
  2097. Py_DECREF(res);
  2098. return PythonCmd_Error(interp);
  2099. }
  2100. Tcl_SetObjResult(interp, obj_res);
  2101. Py_DECREF(res);
  2102. LEAVE_PYTHON
  2103. return TCL_OK;
  2104. }
  2105. static void
  2106. PythonCmdDelete(ClientData clientData)
  2107. {
  2108. PythonCmd_ClientData *data = (PythonCmd_ClientData *)clientData;
  2109. ENTER_PYTHON
  2110. Py_XDECREF(data->self);
  2111. Py_XDECREF(data->func);
  2112. PyMem_Free(data);
  2113. LEAVE_PYTHON
  2114. }
  2115. TCL_DECLARE_MUTEX(command_mutex)
  2116. typedef struct CommandEvent{
  2117. Tcl_Event ev;
  2118. Tcl_Interp* interp;
  2119. const char *name;
  2120. int create;
  2121. int *status;
  2122. ClientData *data;
  2123. Tcl_Condition *done;
  2124. } CommandEvent;
  2125. static int
  2126. Tkapp_CommandProc(CommandEvent *ev, int flags)
  2127. {
  2128. if (ev->create)
  2129. *ev->status = Tcl_CreateObjCommand(
  2130. ev->interp, ev->name, PythonCmd,
  2131. ev->data, PythonCmdDelete) == NULL;
  2132. else
  2133. *ev->status = Tcl_DeleteCommand(ev->interp, ev->name);
  2134. Tcl_MutexLock(&command_mutex);
  2135. Tcl_ConditionNotify(ev->done);
  2136. Tcl_MutexUnlock(&command_mutex);
  2137. return 1;
  2138. }
  2139. /*[clinic input]
  2140. _tkinter.tkapp.createcommand
  2141. name: str
  2142. func: object
  2143. /
  2144. [clinic start generated code]*/
  2145. static PyObject *
  2146. _tkinter_tkapp_createcommand_impl(TkappObject *self, const char *name,
  2147. PyObject *func)
  2148. /*[clinic end generated code: output=2a1c79a4ee2af410 input=255785cb70edc6a0]*/
  2149. {
  2150. PythonCmd_ClientData *data;
  2151. int err;
  2152. CHECK_STRING_LENGTH(name);
  2153. if (!PyCallable_Check(func)) {
  2154. PyErr_SetString(PyExc_TypeError, "command not callable");
  2155. return NULL;
  2156. }
  2157. if (self->threaded && self->thread_id != Tcl_GetCurrentThread() &&
  2158. !WaitForMainloop(self))
  2159. return NULL;
  2160. data = PyMem_NEW(PythonCmd_ClientData, 1);
  2161. if (!data)
  2162. return PyErr_NoMemory();
  2163. Py_INCREF(self);
  2164. Py_INCREF(func);
  2165. data->self = (PyObject *) self;
  2166. data->func = func;
  2167. if (self->threaded && self->thread_id != Tcl_GetCurrentThread()) {
  2168. Tcl_Condition cond = NULL;
  2169. CommandEvent *ev = (CommandEvent*)attemptckalloc(sizeof(CommandEvent));
  2170. if (ev == NULL) {
  2171. PyErr_NoMemory();
  2172. PyMem_Free(data);
  2173. return NULL;
  2174. }
  2175. ev->ev.proc = (Tcl_EventProc*)Tkapp_CommandProc;
  2176. ev->interp = self->interp;
  2177. ev->create = 1;
  2178. ev->name = name;
  2179. ev->data = (ClientData)data;
  2180. ev->status = &err;
  2181. ev->done = &cond;
  2182. Tkapp_ThreadSend(self, (Tcl_Event*)ev, &cond, &command_mutex);
  2183. Tcl_ConditionFinalize(&cond);
  2184. }
  2185. else
  2186. {
  2187. ENTER_TCL
  2188. err = Tcl_CreateObjCommand(
  2189. Tkapp_Interp(self), name, PythonCmd,
  2190. (ClientData)data, PythonCmdDelete) == NULL;
  2191. LEAVE_TCL
  2192. }
  2193. if (err) {
  2194. PyErr_SetString(Tkinter_TclError, "can't create Tcl command");
  2195. PyMem_Free(data);
  2196. return NULL;
  2197. }
  2198. Py_RETURN_NONE;
  2199. }
  2200. /*[clinic input]
  2201. _tkinter.tkapp.deletecommand
  2202. name: str
  2203. /
  2204. [clinic start generated code]*/
  2205. static PyObject *
  2206. _tkinter_tkapp_deletecommand_impl(TkappObject *self, const char *name)
  2207. /*[clinic end generated code: output=a67e8cb5845e0d2d input=53e9952eae1f85f5]*/
  2208. {
  2209. int err;
  2210. CHECK_STRING_LENGTH(name);
  2211. if (self->threaded && self->thread_id != Tcl_GetCurrentThread()) {
  2212. Tcl_Condition cond = NULL;
  2213. CommandEvent *ev;
  2214. ev = (CommandEvent*)attemptckalloc(sizeof(CommandEvent));
  2215. if (ev == NULL) {
  2216. PyErr_NoMemory();
  2217. return NULL;
  2218. }
  2219. ev->ev.proc = (Tcl_EventProc*)Tkapp_CommandProc;
  2220. ev->interp = self->interp;
  2221. ev->create = 0;
  2222. ev->name = name;
  2223. ev->status = &err;
  2224. ev->done = &cond;
  2225. Tkapp_ThreadSend(self, (Tcl_Event*)ev, &cond,
  2226. &command_mutex);
  2227. Tcl_ConditionFinalize(&cond);
  2228. }
  2229. else
  2230. {
  2231. ENTER_TCL
  2232. err = Tcl_DeleteCommand(self->interp, name);
  2233. LEAVE_TCL
  2234. }
  2235. if (err == -1) {
  2236. PyErr_SetString(Tkinter_TclError, "can't delete Tcl command");
  2237. return NULL;
  2238. }
  2239. Py_RETURN_NONE;
  2240. }
  2241. #ifdef HAVE_CREATEFILEHANDLER
  2242. /** File Handler **/
  2243. typedef struct _fhcdata {
  2244. PyObject *func;
  2245. PyObject *file;
  2246. int id;
  2247. struct _fhcdata *next;
  2248. } FileHandler_ClientData;
  2249. static FileHandler_ClientData *HeadFHCD;
  2250. static FileHandler_ClientData *
  2251. NewFHCD(PyObject *func, PyObject *file, int id)
  2252. {
  2253. FileHandler_ClientData *p;
  2254. p = PyMem_NEW(FileHandler_ClientData, 1);
  2255. if (p != NULL) {
  2256. Py_XINCREF(func);
  2257. Py_XINCREF(file);
  2258. p->func = func;
  2259. p->file = file;
  2260. p->id = id;
  2261. p->next = HeadFHCD;
  2262. HeadFHCD = p;
  2263. }
  2264. return p;
  2265. }
  2266. static void
  2267. DeleteFHCD(int id)
  2268. {
  2269. FileHandler_ClientData *p, **pp;
  2270. pp = &HeadFHCD;
  2271. while ((p = *pp) != NULL) {
  2272. if (p->id == id) {
  2273. *pp = p->next;
  2274. Py_XDECREF(p->func);
  2275. Py_XDECREF(p->file);
  2276. PyMem_Free(p);
  2277. }
  2278. else
  2279. pp = &p->next;
  2280. }
  2281. }
  2282. static void
  2283. FileHandler(ClientData clientData, int mask)
  2284. {
  2285. FileHandler_ClientData *data = (FileHandler_ClientData *)clientData;
  2286. PyObject *func, *file, *res;
  2287. ENTER_PYTHON
  2288. func = data->func;
  2289. file = data->file;
  2290. res = PyObject_CallFunction(func, "Oi", file, mask);
  2291. if (res == NULL) {
  2292. errorInCmd = 1;
  2293. PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd);
  2294. }
  2295. Py_XDECREF(res);
  2296. LEAVE_PYTHON
  2297. }
  2298. /*[clinic input]
  2299. _tkinter.tkapp.createfilehandler
  2300. file: object
  2301. mask: int
  2302. func: object
  2303. /
  2304. [clinic start generated code]*/
  2305. static PyObject *
  2306. _tkinter_tkapp_createfilehandler_impl(TkappObject *self, PyObject *file,
  2307. int mask, PyObject *func)
  2308. /*[clinic end generated code: output=f73ce82de801c353 input=84943a5286e47947]*/
  2309. {
  2310. FileHandler_ClientData *data;
  2311. int tfile;
  2312. CHECK_TCL_APPARTMENT;
  2313. tfile = PyObject_AsFileDescriptor(file);
  2314. if (tfile < 0)
  2315. return NULL;
  2316. if (!PyCallable_Check(func)) {
  2317. PyErr_SetString(PyExc_TypeError, "bad argument list");
  2318. return NULL;
  2319. }
  2320. data = NewFHCD(func, file, tfile);
  2321. if (data == NULL)
  2322. return NULL;
  2323. /* Ought to check for null Tcl_File object... */
  2324. ENTER_TCL
  2325. Tcl_CreateFileHandler(tfile, mask, FileHandler, (ClientData) data);
  2326. LEAVE_TCL
  2327. Py_RETURN_NONE;
  2328. }
  2329. /*[clinic input]
  2330. _tkinter.tkapp.deletefilehandler
  2331. file: object
  2332. /
  2333. [clinic start generated code]*/
  2334. static PyObject *
  2335. _tkinter_tkapp_deletefilehandler(TkappObject *self, PyObject *file)
  2336. /*[clinic end generated code: output=b53cc96ebf9476fd input=abbec19d66312e2a]*/
  2337. {
  2338. int tfile;
  2339. CHECK_TCL_APPARTMENT;
  2340. tfile = PyObject_AsFileDescriptor(file);
  2341. if (tfile < 0)
  2342. return NULL;
  2343. DeleteFHCD(tfile);
  2344. /* Ought to check for null Tcl_File object... */
  2345. ENTER_TCL
  2346. Tcl_DeleteFileHandler(tfile);
  2347. LEAVE_TCL
  2348. Py_RETURN_NONE;
  2349. }
  2350. #endif /* HAVE_CREATEFILEHANDLER */
  2351. /**** Tktt Object (timer token) ****/
  2352. static PyObject *Tktt_Type;
  2353. typedef struct {
  2354. PyObject_HEAD
  2355. Tcl_TimerToken token;
  2356. PyObject *func;
  2357. } TkttObject;
  2358. /*[clinic input]
  2359. _tkinter.tktimertoken.deletetimerhandler
  2360. [clinic start generated code]*/
  2361. static PyObject *
  2362. _tkinter_tktimertoken_deletetimerhandler_impl(TkttObject *self)
  2363. /*[clinic end generated code: output=bd7fe17f328cfa55 input=40bd070ff85f5cf3]*/
  2364. {
  2365. TkttObject *v = self;
  2366. PyObject *func = v->func;
  2367. if (v->token != NULL) {
  2368. Tcl_DeleteTimerHandler(v->token);
  2369. v->token = NULL;
  2370. }
  2371. if (func != NULL) {
  2372. v->func = NULL;
  2373. Py_DECREF(func);
  2374. Py_DECREF(v); /* See Tktt_New() */
  2375. }
  2376. Py_RETURN_NONE;
  2377. }
  2378. static TkttObject *
  2379. Tktt_New(PyObject *func)
  2380. {
  2381. TkttObject *v;
  2382. v = PyObject_New(TkttObject, (PyTypeObject *) Tktt_Type);
  2383. if (v == NULL)
  2384. return NULL;
  2385. Py_INCREF(func);
  2386. v->token = NULL;
  2387. v->func = func;
  2388. /* Extra reference, deleted when called or when handler is deleted */
  2389. Py_INCREF(v);
  2390. return v;
  2391. }
  2392. static void
  2393. Tktt_Dealloc(PyObject *self)
  2394. {
  2395. TkttObject *v = (TkttObject *)self;
  2396. PyObject *func = v->func;
  2397. PyObject *tp = (PyObject *) Py_TYPE(self);
  2398. Py_XDECREF(func);
  2399. PyObject_Free(self);
  2400. Py_DECREF(tp);
  2401. }
  2402. static PyObject *
  2403. Tktt_Repr(PyObject *self)
  2404. {
  2405. TkttObject *v = (TkttObject *)self;
  2406. return PyUnicode_FromFormat("<tktimertoken at %p%s>",
  2407. v,
  2408. v->func == NULL ? ", handler deleted" : "");
  2409. }
  2410. /** Timer Handler **/
  2411. static void
  2412. TimerHandler(ClientData clientData)
  2413. {
  2414. TkttObject *v = (TkttObject *)clientData;
  2415. PyObject *func = v->func;
  2416. PyObject *res;
  2417. if (func == NULL)
  2418. return;
  2419. v->func = NULL;
  2420. ENTER_PYTHON
  2421. res = PyObject_CallNoArgs(func);
  2422. Py_DECREF(func);
  2423. Py_DECREF(v); /* See Tktt_New() */
  2424. if (res == NULL) {
  2425. errorInCmd = 1;
  2426. PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd);
  2427. }
  2428. else
  2429. Py_DECREF(res);
  2430. LEAVE_PYTHON
  2431. }
  2432. /*[clinic input]
  2433. _tkinter.tkapp.createtimerhandler
  2434. milliseconds: int
  2435. func: object
  2436. /
  2437. [clinic start generated code]*/
  2438. static PyObject *
  2439. _tkinter_tkapp_createtimerhandler_impl(TkappObject *self, int milliseconds,
  2440. PyObject *func)
  2441. /*[clinic end generated code: output=2da5959b9d031911 input=ba6729f32f0277a5]*/
  2442. {
  2443. TkttObject *v;
  2444. if (!PyCallable_Check(func)) {
  2445. PyErr_SetString(PyExc_TypeError, "bad argument list");
  2446. return NULL;
  2447. }
  2448. CHECK_TCL_APPARTMENT;
  2449. v = Tktt_New(func);
  2450. if (v) {
  2451. v->token = Tcl_CreateTimerHandler(milliseconds, TimerHandler,
  2452. (ClientData)v);
  2453. }
  2454. return (PyObject *) v;
  2455. }
  2456. /** Event Loop **/
  2457. /*[clinic input]
  2458. _tkinter.tkapp.mainloop
  2459. threshold: int = 0
  2460. /
  2461. [clinic start generated code]*/
  2462. static PyObject *
  2463. _tkinter_tkapp_mainloop_impl(TkappObject *self, int threshold)
  2464. /*[clinic end generated code: output=0ba8eabbe57841b0 input=036bcdcf03d5eca0]*/
  2465. {
  2466. PyThreadState *tstate = PyThreadState_Get();
  2467. CHECK_TCL_APPARTMENT;
  2468. self->dispatching = 1;
  2469. quitMainLoop = 0;
  2470. while (Tk_GetNumMainWindows() > threshold &&
  2471. !quitMainLoop &&
  2472. !errorInCmd)
  2473. {
  2474. int result;
  2475. if (self->threaded) {
  2476. /* Allow other Python threads to run. */
  2477. ENTER_TCL
  2478. result = Tcl_DoOneEvent(0);
  2479. LEAVE_TCL
  2480. }
  2481. else {
  2482. Py_BEGIN_ALLOW_THREADS
  2483. if(tcl_lock)PyThread_acquire_lock(tcl_lock, 1);
  2484. tcl_tstate = tstate;
  2485. result = Tcl_DoOneEvent(TCL_DONT_WAIT);
  2486. tcl_tstate = NULL;
  2487. if(tcl_lock)PyThread_release_lock(tcl_lock);
  2488. if (result == 0)
  2489. Sleep(Tkinter_busywaitinterval);
  2490. Py_END_ALLOW_THREADS
  2491. }
  2492. if (PyErr_CheckSignals() != 0) {
  2493. self->dispatching = 0;
  2494. return NULL;
  2495. }
  2496. if (result < 0)
  2497. break;
  2498. }
  2499. self->dispatching = 0;
  2500. quitMainLoop = 0;
  2501. if (errorInCmd) {
  2502. errorInCmd = 0;
  2503. PyErr_Restore(excInCmd, valInCmd, trbInCmd);
  2504. excInCmd = valInCmd = trbInCmd = NULL;
  2505. return NULL;
  2506. }
  2507. Py_RETURN_NONE;
  2508. }
  2509. /*[clinic input]
  2510. _tkinter.tkapp.dooneevent
  2511. flags: int = 0
  2512. /
  2513. [clinic start generated code]*/
  2514. static PyObject *
  2515. _tkinter_tkapp_dooneevent_impl(TkappObject *self, int flags)
  2516. /*[clinic end generated code: output=27c6b2aa464cac29 input=6542b928e364b793]*/
  2517. {
  2518. int rv;
  2519. ENTER_TCL
  2520. rv = Tcl_DoOneEvent(flags);
  2521. LEAVE_TCL
  2522. return PyLong_FromLong(rv);
  2523. }
  2524. /*[clinic input]
  2525. _tkinter.tkapp.quit
  2526. [clinic start generated code]*/
  2527. static PyObject *
  2528. _tkinter_tkapp_quit_impl(TkappObject *self)
  2529. /*[clinic end generated code: output=7f21eeff481f754f input=e03020dc38aff23c]*/
  2530. {
  2531. quitMainLoop = 1;
  2532. Py_RETURN_NONE;
  2533. }
  2534. /*[clinic input]
  2535. _tkinter.tkapp.interpaddr
  2536. [clinic start generated code]*/
  2537. static PyObject *
  2538. _tkinter_tkapp_interpaddr_impl(TkappObject *self)
  2539. /*[clinic end generated code: output=6caaae3273b3c95a input=2dd32cbddb55a111]*/
  2540. {
  2541. return PyLong_FromVoidPtr(Tkapp_Interp(self));
  2542. }
  2543. /*[clinic input]
  2544. _tkinter.tkapp.loadtk
  2545. [clinic start generated code]*/
  2546. static PyObject *
  2547. _tkinter_tkapp_loadtk_impl(TkappObject *self)
  2548. /*[clinic end generated code: output=e9e10a954ce46d2a input=b5e82afedd6354f0]*/
  2549. {
  2550. Tcl_Interp *interp = Tkapp_Interp(self);
  2551. const char * _tk_exists = NULL;
  2552. int err;
  2553. #ifdef TKINTER_PROTECT_LOADTK
  2554. /* Up to Tk 8.4.13, Tk_Init deadlocks on the second call when the
  2555. * first call failed.
  2556. * To avoid the deadlock, we just refuse the second call through
  2557. * a static variable.
  2558. */
  2559. if (tk_load_failed) {
  2560. PyErr_SetString(Tkinter_TclError, TKINTER_LOADTK_ERRMSG);
  2561. return NULL;
  2562. }
  2563. #endif
  2564. /* We want to guard against calling Tk_Init() multiple times */
  2565. CHECK_TCL_APPARTMENT;
  2566. ENTER_TCL
  2567. err = Tcl_Eval(Tkapp_Interp(self), "info exists tk_version");
  2568. ENTER_OVERLAP
  2569. if (err == TCL_ERROR) {
  2570. /* This sets an exception, but we cannot return right
  2571. away because we need to exit the overlap first. */
  2572. Tkinter_Error(self);
  2573. } else {
  2574. _tk_exists = Tcl_GetStringResult(Tkapp_Interp(self));
  2575. }
  2576. LEAVE_OVERLAP_TCL
  2577. if (err == TCL_ERROR) {
  2578. return NULL;
  2579. }
  2580. if (_tk_exists == NULL || strcmp(_tk_exists, "1") != 0) {
  2581. if (Tk_Init(interp) == TCL_ERROR) {
  2582. Tkinter_Error(self);
  2583. #ifdef TKINTER_PROTECT_LOADTK
  2584. tk_load_failed = 1;
  2585. #endif
  2586. return NULL;
  2587. }
  2588. }
  2589. Py_RETURN_NONE;
  2590. }
  2591. static PyObject *
  2592. Tkapp_WantObjects(PyObject *self, PyObject *args)
  2593. {
  2594. int wantobjects = -1;
  2595. if (!PyArg_ParseTuple(args, "|i:wantobjects", &wantobjects))
  2596. return NULL;
  2597. if (wantobjects == -1)
  2598. return PyBool_FromLong(((TkappObject*)self)->wantobjects);
  2599. ((TkappObject*)self)->wantobjects = wantobjects;
  2600. Py_RETURN_NONE;
  2601. }
  2602. /*[clinic input]
  2603. _tkinter.tkapp.willdispatch
  2604. [clinic start generated code]*/
  2605. static PyObject *
  2606. _tkinter_tkapp_willdispatch_impl(TkappObject *self)
  2607. /*[clinic end generated code: output=0e3f46d244642155 input=d88f5970843d6dab]*/
  2608. {
  2609. self->dispatching = 1;
  2610. Py_RETURN_NONE;
  2611. }
  2612. /**** Tkapp Type Methods ****/
  2613. static void
  2614. Tkapp_Dealloc(PyObject *self)
  2615. {
  2616. PyObject *tp = (PyObject *) Py_TYPE(self);
  2617. /*CHECK_TCL_APPARTMENT;*/
  2618. ENTER_TCL
  2619. Tcl_DeleteInterp(Tkapp_Interp(self));
  2620. LEAVE_TCL
  2621. PyObject_Free(self);
  2622. Py_DECREF(tp);
  2623. DisableEventHook();
  2624. }
  2625. /**** Tkinter Module ****/
  2626. typedef struct {
  2627. PyObject* tuple;
  2628. Py_ssize_t size; /* current size */
  2629. Py_ssize_t maxsize; /* allocated size */
  2630. } FlattenContext;
  2631. static int
  2632. _bump(FlattenContext* context, Py_ssize_t size)
  2633. {
  2634. /* expand tuple to hold (at least) size new items.
  2635. return true if successful, false if an exception was raised */
  2636. Py_ssize_t maxsize = context->maxsize * 2; /* never overflows */
  2637. if (maxsize < context->size + size)
  2638. maxsize = context->size + size; /* never overflows */
  2639. context->maxsize = maxsize;
  2640. return _PyTuple_Resize(&context->tuple, maxsize) >= 0;
  2641. }
  2642. static int
  2643. _flatten1(FlattenContext* context, PyObject* item, int depth)
  2644. {
  2645. /* add tuple or list to argument tuple (recursively) */
  2646. Py_ssize_t i, size;
  2647. if (depth > 1000) {
  2648. PyErr_SetString(PyExc_ValueError,
  2649. "nesting too deep in _flatten");
  2650. return 0;
  2651. } else if (PyTuple_Check(item) || PyList_Check(item)) {
  2652. size = PySequence_Fast_GET_SIZE(item);
  2653. /* preallocate (assume no nesting) */
  2654. if (context->size + size > context->maxsize &&
  2655. !_bump(context, size))
  2656. return 0;
  2657. /* copy items to output tuple */
  2658. for (i = 0; i < size; i++) {
  2659. PyObject *o = PySequence_Fast_GET_ITEM(item, i);
  2660. if (PyList_Check(o) || PyTuple_Check(o)) {
  2661. if (!_flatten1(context, o, depth + 1))
  2662. return 0;
  2663. } else if (o != Py_None) {
  2664. if (context->size + 1 > context->maxsize &&
  2665. !_bump(context, 1))
  2666. return 0;
  2667. Py_INCREF(o);
  2668. PyTuple_SET_ITEM(context->tuple,
  2669. context->size++, o);
  2670. }
  2671. }
  2672. } else {
  2673. PyErr_SetString(PyExc_TypeError, "argument must be sequence");
  2674. return 0;
  2675. }
  2676. return 1;
  2677. }
  2678. /*[clinic input]
  2679. _tkinter._flatten
  2680. item: object
  2681. /
  2682. [clinic start generated code]*/
  2683. static PyObject *
  2684. _tkinter__flatten(PyObject *module, PyObject *item)
  2685. /*[clinic end generated code: output=cad02a3f97f29862 input=6b9c12260aa1157f]*/
  2686. {
  2687. FlattenContext context;
  2688. context.maxsize = PySequence_Size(item);
  2689. if (context.maxsize < 0)
  2690. return NULL;
  2691. if (context.maxsize == 0)
  2692. return PyTuple_New(0);
  2693. context.tuple = PyTuple_New(context.maxsize);
  2694. if (!context.tuple)
  2695. return NULL;
  2696. context.size = 0;
  2697. if (!_flatten1(&context, item,0))
  2698. return NULL;
  2699. if (_PyTuple_Resize(&context.tuple, context.size))
  2700. return NULL;
  2701. return context.tuple;
  2702. }
  2703. /*[clinic input]
  2704. _tkinter.create
  2705. screenName: str(accept={str, NoneType}) = None
  2706. baseName: str = ""
  2707. className: str = "Tk"
  2708. interactive: bool(accept={int}) = False
  2709. wantobjects: bool(accept={int}) = False
  2710. wantTk: bool(accept={int}) = True
  2711. if false, then Tk_Init() doesn't get called
  2712. sync: bool(accept={int}) = False
  2713. if true, then pass -sync to wish
  2714. use: str(accept={str, NoneType}) = None
  2715. if not None, then pass -use to wish
  2716. /
  2717. [clinic start generated code]*/
  2718. static PyObject *
  2719. _tkinter_create_impl(PyObject *module, const char *screenName,
  2720. const char *baseName, const char *className,
  2721. int interactive, int wantobjects, int wantTk, int sync,
  2722. const char *use)
  2723. /*[clinic end generated code: output=e3315607648e6bb4 input=da9b17ee7358d862]*/
  2724. {
  2725. /* XXX baseName is not used anymore;
  2726. * try getting rid of it. */
  2727. CHECK_STRING_LENGTH(screenName);
  2728. CHECK_STRING_LENGTH(baseName);
  2729. CHECK_STRING_LENGTH(className);
  2730. CHECK_STRING_LENGTH(use);
  2731. return (PyObject *) Tkapp_New(screenName, className,
  2732. interactive, wantobjects, wantTk,
  2733. sync, use);
  2734. }
  2735. /*[clinic input]
  2736. _tkinter.setbusywaitinterval
  2737. new_val: int
  2738. /
  2739. Set the busy-wait interval in milliseconds between successive calls to Tcl_DoOneEvent in a threaded Python interpreter.
  2740. It should be set to a divisor of the maximum time between frames in an animation.
  2741. [clinic start generated code]*/
  2742. static PyObject *
  2743. _tkinter_setbusywaitinterval_impl(PyObject *module, int new_val)
  2744. /*[clinic end generated code: output=42bf7757dc2d0ab6 input=deca1d6f9e6dae47]*/
  2745. {
  2746. if (new_val < 0) {
  2747. PyErr_SetString(PyExc_ValueError,
  2748. "busywaitinterval must be >= 0");
  2749. return NULL;
  2750. }
  2751. Tkinter_busywaitinterval = new_val;
  2752. Py_RETURN_NONE;
  2753. }
  2754. /*[clinic input]
  2755. _tkinter.getbusywaitinterval -> int
  2756. Return the current busy-wait interval between successive calls to Tcl_DoOneEvent in a threaded Python interpreter.
  2757. [clinic start generated code]*/
  2758. static int
  2759. _tkinter_getbusywaitinterval_impl(PyObject *module)
  2760. /*[clinic end generated code: output=23b72d552001f5c7 input=a695878d2d576a84]*/
  2761. {
  2762. return Tkinter_busywaitinterval;
  2763. }
  2764. #include "clinic/_tkinter.c.h"
  2765. static PyMethodDef Tktt_methods[] =
  2766. {
  2767. _TKINTER_TKTIMERTOKEN_DELETETIMERHANDLER_METHODDEF
  2768. {NULL, NULL}
  2769. };
  2770. static PyType_Slot Tktt_Type_slots[] = {
  2771. {Py_tp_dealloc, Tktt_Dealloc},
  2772. {Py_tp_repr, Tktt_Repr},
  2773. {Py_tp_methods, Tktt_methods},
  2774. {0, 0}
  2775. };
  2776. static PyType_Spec Tktt_Type_spec = {
  2777. "_tkinter.tktimertoken",
  2778. sizeof(TkttObject),
  2779. 0,
  2780. Py_TPFLAGS_DEFAULT,
  2781. Tktt_Type_slots,
  2782. };
  2783. /**** Tkapp Method List ****/
  2784. static PyMethodDef Tkapp_methods[] =
  2785. {
  2786. _TKINTER_TKAPP_WILLDISPATCH_METHODDEF
  2787. {"wantobjects", Tkapp_WantObjects, METH_VARARGS},
  2788. {"call", Tkapp_Call, METH_VARARGS},
  2789. _TKINTER_TKAPP_EVAL_METHODDEF
  2790. _TKINTER_TKAPP_EVALFILE_METHODDEF
  2791. _TKINTER_TKAPP_RECORD_METHODDEF
  2792. _TKINTER_TKAPP_ADDERRORINFO_METHODDEF
  2793. {"setvar", Tkapp_SetVar, METH_VARARGS},
  2794. {"globalsetvar", Tkapp_GlobalSetVar, METH_VARARGS},
  2795. {"getvar", Tkapp_GetVar, METH_VARARGS},
  2796. {"globalgetvar", Tkapp_GlobalGetVar, METH_VARARGS},
  2797. {"unsetvar", Tkapp_UnsetVar, METH_VARARGS},
  2798. {"globalunsetvar", Tkapp_GlobalUnsetVar, METH_VARARGS},
  2799. _TKINTER_TKAPP_GETINT_METHODDEF
  2800. _TKINTER_TKAPP_GETDOUBLE_METHODDEF
  2801. _TKINTER_TKAPP_GETBOOLEAN_METHODDEF
  2802. _TKINTER_TKAPP_EXPRSTRING_METHODDEF
  2803. _TKINTER_TKAPP_EXPRLONG_METHODDEF
  2804. _TKINTER_TKAPP_EXPRDOUBLE_METHODDEF
  2805. _TKINTER_TKAPP_EXPRBOOLEAN_METHODDEF
  2806. _TKINTER_TKAPP_SPLITLIST_METHODDEF
  2807. _TKINTER_TKAPP_SPLIT_METHODDEF
  2808. _TKINTER_TKAPP_CREATECOMMAND_METHODDEF
  2809. _TKINTER_TKAPP_DELETECOMMAND_METHODDEF
  2810. _TKINTER_TKAPP_CREATEFILEHANDLER_METHODDEF
  2811. _TKINTER_TKAPP_DELETEFILEHANDLER_METHODDEF
  2812. _TKINTER_TKAPP_CREATETIMERHANDLER_METHODDEF
  2813. _TKINTER_TKAPP_MAINLOOP_METHODDEF
  2814. _TKINTER_TKAPP_DOONEEVENT_METHODDEF
  2815. _TKINTER_TKAPP_QUIT_METHODDEF
  2816. _TKINTER_TKAPP_INTERPADDR_METHODDEF
  2817. _TKINTER_TKAPP_LOADTK_METHODDEF
  2818. {NULL, NULL}
  2819. };
  2820. static PyType_Slot Tkapp_Type_slots[] = {
  2821. {Py_tp_dealloc, Tkapp_Dealloc},
  2822. {Py_tp_methods, Tkapp_methods},
  2823. {0, 0}
  2824. };
  2825. static PyType_Spec Tkapp_Type_spec = {
  2826. "_tkinter.tkapp",
  2827. sizeof(TkappObject),
  2828. 0,
  2829. Py_TPFLAGS_DEFAULT,
  2830. Tkapp_Type_slots,
  2831. };
  2832. static PyMethodDef moduleMethods[] =
  2833. {
  2834. _TKINTER__FLATTEN_METHODDEF
  2835. _TKINTER_CREATE_METHODDEF
  2836. _TKINTER_SETBUSYWAITINTERVAL_METHODDEF
  2837. _TKINTER_GETBUSYWAITINTERVAL_METHODDEF
  2838. {NULL, NULL}
  2839. };
  2840. #ifdef WAIT_FOR_STDIN
  2841. static int stdin_ready = 0;
  2842. #ifndef MS_WINDOWS
  2843. static void
  2844. MyFileProc(void *clientData, int mask)
  2845. {
  2846. stdin_ready = 1;
  2847. }
  2848. #endif
  2849. static PyThreadState *event_tstate = NULL;
  2850. static int
  2851. EventHook(void)
  2852. {
  2853. #ifndef MS_WINDOWS
  2854. int tfile;
  2855. #endif
  2856. PyEval_RestoreThread(event_tstate);
  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. Py_BEGIN_ALLOW_THREADS
  2872. if(tcl_lock)PyThread_acquire_lock(tcl_lock, 1);
  2873. tcl_tstate = event_tstate;
  2874. result = Tcl_DoOneEvent(TCL_DONT_WAIT);
  2875. tcl_tstate = NULL;
  2876. if(tcl_lock)PyThread_release_lock(tcl_lock);
  2877. if (result == 0)
  2878. Sleep(Tkinter_busywaitinterval);
  2879. Py_END_ALLOW_THREADS
  2880. if (result < 0)
  2881. break;
  2882. }
  2883. #ifndef MS_WINDOWS
  2884. Tcl_DeleteFileHandler(tfile);
  2885. #endif
  2886. if (errorInCmd) {
  2887. errorInCmd = 0;
  2888. PyErr_Restore(excInCmd, valInCmd, trbInCmd);
  2889. excInCmd = valInCmd = trbInCmd = NULL;
  2890. PyErr_Print();
  2891. }
  2892. PyEval_SaveThread();
  2893. return 0;
  2894. }
  2895. #endif
  2896. static void
  2897. EnableEventHook(void)
  2898. {
  2899. #ifdef WAIT_FOR_STDIN
  2900. if (PyOS_InputHook == NULL) {
  2901. event_tstate = PyThreadState_Get();
  2902. PyOS_InputHook = EventHook;
  2903. }
  2904. #endif
  2905. }
  2906. static void
  2907. DisableEventHook(void)
  2908. {
  2909. #ifdef WAIT_FOR_STDIN
  2910. if (Tk_GetNumMainWindows() == 0 && PyOS_InputHook == EventHook) {
  2911. PyOS_InputHook = NULL;
  2912. }
  2913. #endif
  2914. }
  2915. static struct PyModuleDef _tkintermodule = {
  2916. PyModuleDef_HEAD_INIT,
  2917. "_tkinter",
  2918. NULL,
  2919. -1,
  2920. moduleMethods,
  2921. NULL,
  2922. NULL,
  2923. NULL,
  2924. NULL
  2925. };
  2926. PyMODINIT_FUNC
  2927. PyInit__tkinter(void)
  2928. {
  2929. PyObject *m, *uexe, *cexe, *o;
  2930. tcl_lock = PyThread_allocate_lock();
  2931. if (tcl_lock == NULL)
  2932. return NULL;
  2933. m = PyModule_Create(&_tkintermodule);
  2934. if (m == NULL)
  2935. return NULL;
  2936. o = PyErr_NewException("_tkinter.TclError", NULL, NULL);
  2937. if (o == NULL) {
  2938. Py_DECREF(m);
  2939. return NULL;
  2940. }
  2941. Py_INCREF(o);
  2942. if (PyModule_AddObject(m, "TclError", o)) {
  2943. Py_DECREF(o);
  2944. Py_DECREF(m);
  2945. return NULL;
  2946. }
  2947. Tkinter_TclError = o;
  2948. if (PyModule_AddIntConstant(m, "READABLE", TCL_READABLE)) {
  2949. Py_DECREF(m);
  2950. return NULL;
  2951. }
  2952. if (PyModule_AddIntConstant(m, "WRITABLE", TCL_WRITABLE)) {
  2953. Py_DECREF(m);
  2954. return NULL;
  2955. }
  2956. if (PyModule_AddIntConstant(m, "EXCEPTION", TCL_EXCEPTION)) {
  2957. Py_DECREF(m);
  2958. return NULL;
  2959. }
  2960. if (PyModule_AddIntConstant(m, "WINDOW_EVENTS", TCL_WINDOW_EVENTS)) {
  2961. Py_DECREF(m);
  2962. return NULL;
  2963. }
  2964. if (PyModule_AddIntConstant(m, "FILE_EVENTS", TCL_FILE_EVENTS)) {
  2965. Py_DECREF(m);
  2966. return NULL;
  2967. }
  2968. if (PyModule_AddIntConstant(m, "TIMER_EVENTS", TCL_TIMER_EVENTS)) {
  2969. Py_DECREF(m);
  2970. return NULL;
  2971. }
  2972. if (PyModule_AddIntConstant(m, "IDLE_EVENTS", TCL_IDLE_EVENTS)) {
  2973. Py_DECREF(m);
  2974. return NULL;
  2975. }
  2976. if (PyModule_AddIntConstant(m, "ALL_EVENTS", TCL_ALL_EVENTS)) {
  2977. Py_DECREF(m);
  2978. return NULL;
  2979. }
  2980. if (PyModule_AddIntConstant(m, "DONT_WAIT", TCL_DONT_WAIT)) {
  2981. Py_DECREF(m);
  2982. return NULL;
  2983. }
  2984. if (PyModule_AddStringConstant(m, "TK_VERSION", TK_VERSION)) {
  2985. Py_DECREF(m);
  2986. return NULL;
  2987. }
  2988. if (PyModule_AddStringConstant(m, "TCL_VERSION", TCL_VERSION)) {
  2989. Py_DECREF(m);
  2990. return NULL;
  2991. }
  2992. o = PyType_FromSpec(&Tkapp_Type_spec);
  2993. if (o == NULL) {
  2994. Py_DECREF(m);
  2995. return NULL;
  2996. }
  2997. ((PyTypeObject *)o)->tp_new = NULL;
  2998. if (PyModule_AddObject(m, "TkappType", o)) {
  2999. Py_DECREF(o);
  3000. Py_DECREF(m);
  3001. return NULL;
  3002. }
  3003. Tkapp_Type = o;
  3004. o = PyType_FromSpec(&Tktt_Type_spec);
  3005. if (o == NULL) {
  3006. Py_DECREF(m);
  3007. return NULL;
  3008. }
  3009. ((PyTypeObject *)o)->tp_new = NULL;
  3010. if (PyModule_AddObject(m, "TkttType", o)) {
  3011. Py_DECREF(o);
  3012. Py_DECREF(m);
  3013. return NULL;
  3014. }
  3015. Tktt_Type = o;
  3016. o = PyType_FromSpec(&PyTclObject_Type_spec);
  3017. if (o == NULL) {
  3018. Py_DECREF(m);
  3019. return NULL;
  3020. }
  3021. ((PyTypeObject *)o)->tp_new = NULL;
  3022. if (PyModule_AddObject(m, "Tcl_Obj", o)) {
  3023. Py_DECREF(o);
  3024. Py_DECREF(m);
  3025. return NULL;
  3026. }
  3027. PyTclObject_Type = o;
  3028. #ifdef TK_AQUA
  3029. /* Tk_MacOSXSetupTkNotifier must be called before Tcl's subsystems
  3030. * start waking up. Note that Tcl_FindExecutable will do this, this
  3031. * code must be above it! The original warning from
  3032. * tkMacOSXAppInit.c is copied below.
  3033. *
  3034. * NB - You have to swap in the Tk Notifier BEFORE you start up the
  3035. * Tcl interpreter for now. It probably should work to do this
  3036. * in the other order, but for now it doesn't seem to.
  3037. *
  3038. */
  3039. Tk_MacOSXSetupTkNotifier();
  3040. #endif
  3041. /* This helps the dynamic loader; in Unicode aware Tcl versions
  3042. it also helps Tcl find its encodings. */
  3043. uexe = PyUnicode_FromWideChar(Py_GetProgramName(), -1);
  3044. if (uexe) {
  3045. cexe = PyUnicode_EncodeFSDefault(uexe);
  3046. if (cexe) {
  3047. #ifdef MS_WINDOWS
  3048. int set_var = 0;
  3049. PyObject *str_path;
  3050. wchar_t *wcs_path;
  3051. DWORD ret;
  3052. ret = GetEnvironmentVariableW(L"TCL_LIBRARY", NULL, 0);
  3053. if (!ret && GetLastError() == ERROR_ENVVAR_NOT_FOUND) {
  3054. str_path = _get_tcl_lib_path();
  3055. if (str_path == NULL && PyErr_Occurred()) {
  3056. Py_DECREF(m);
  3057. return NULL;
  3058. }
  3059. if (str_path != NULL) {
  3060. wcs_path = PyUnicode_AsWideCharString(str_path, NULL);
  3061. if (wcs_path == NULL) {
  3062. Py_DECREF(m);
  3063. return NULL;
  3064. }
  3065. SetEnvironmentVariableW(L"TCL_LIBRARY", wcs_path);
  3066. set_var = 1;
  3067. }
  3068. }
  3069. Tcl_FindExecutable(PyBytes_AS_STRING(cexe));
  3070. if (set_var) {
  3071. SetEnvironmentVariableW(L"TCL_LIBRARY", NULL);
  3072. PyMem_Free(wcs_path);
  3073. }
  3074. #else
  3075. Tcl_FindExecutable(PyBytes_AS_STRING(cexe));
  3076. #endif /* MS_WINDOWS */
  3077. }
  3078. Py_XDECREF(cexe);
  3079. Py_DECREF(uexe);
  3080. }
  3081. if (PyErr_Occurred()) {
  3082. Py_DECREF(m);
  3083. return NULL;
  3084. }
  3085. #if 0
  3086. /* This was not a good idea; through <Destroy> bindings,
  3087. Tcl_Finalize() may invoke Python code but at that point the
  3088. interpreter and thread state have already been destroyed! */
  3089. Py_AtExit(Tcl_Finalize);
  3090. #endif
  3091. return m;
  3092. }