Mercurial > cpython-lru_cache-weakref
annotate Modules/_tkinter.c @ 38664:7619216bbc19 2.4
Bug #1502728: Correctly link against librt library on HP-UX.
(backport from rev. 46743)
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Thu, 08 Jun 2006 12:54:16 +0000 |
| parents | 129ab846a71f |
| children | 6fb46e87d5f9 |
| rev | line source |
|---|---|
| 3703 | 1 /*********************************************************** |
| 2 Copyright (C) 1994 Steen Lumholt. | |
| 3 | |
| 4 All Rights Reserved | |
| 5 | |
| 6 ******************************************************************/ | |
| 7 | |
| 8 /* _tkinter.c -- Interface to libtk.a and libtcl.a. */ | |
| 1664 | 9 |
|
4005
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
10 /* TCL/TK VERSION INFO: |
|
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
11 |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
12 Only Tcl/Tk 8.2 and later are supported. Older versions are not |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
13 supported. (Use Python 2.2 if you cannot upgrade your Tcl/Tk |
|
12071
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
14 libraries.) |
|
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
15 */ |
|
4005
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
16 |
|
12071
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
17 /* XXX Further speed-up ideas, involving Tcl 8.0 features: |
|
8200
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
18 |
|
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
19 - Register a new Tcl type, "Python callable", which can be called more |
|
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
20 efficiently and passed to Tcl_EvalObj() directly (if this is possible). |
|
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
21 |
|
4005
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
22 */ |
|
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
23 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
24 |
| 3120 | 25 #include "Python.h" |
|
3973
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
26 #include <ctype.h> |
| 3120 | 27 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
28 #ifdef WITH_THREAD |
|
9203
07dae6fdae79
Renamed thread.h to pythread.h.
Guido van Rossum <guido@python.org>
parents:
9128
diff
changeset
|
29 #include "pythread.h" |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
30 #endif |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
31 |
|
8446
59dfa9eb7c07
On Windows, need #include <windows.h>; and it's MS_WINDOWS, not MS_WIN32.
Guido van Rossum <guido@python.org>
parents:
8444
diff
changeset
|
32 #ifdef MS_WINDOWS |
|
59dfa9eb7c07
On Windows, need #include <windows.h>; and it's MS_WINDOWS, not MS_WIN32.
Guido van Rossum <guido@python.org>
parents:
8444
diff
changeset
|
33 #include <windows.h> |
|
59dfa9eb7c07
On Windows, need #include <windows.h>; and it's MS_WINDOWS, not MS_WIN32.
Guido van Rossum <guido@python.org>
parents:
8444
diff
changeset
|
34 #endif |
|
59dfa9eb7c07
On Windows, need #include <windows.h>; and it's MS_WINDOWS, not MS_WIN32.
Guido van Rossum <guido@python.org>
parents:
8444
diff
changeset
|
35 |
|
27071
c30f97287602
Wrap doc strings in PyDoc_STRVAR. Fix .string docstring. Provide default
Martin v. Löwis <martin@v.loewis.de>
parents:
27069
diff
changeset
|
36 /* Allow using this code in Python 2.[12] */ |
|
c30f97287602
Wrap doc strings in PyDoc_STRVAR. Fix .string docstring. Provide default
Martin v. Löwis <martin@v.loewis.de>
parents:
27069
diff
changeset
|
37 #ifndef PyDoc_STRVAR |
|
27333
f4c694a01425
Avoid usage of PyDoc_STR in 2.2 compatibility code.
Martin v. Löwis <martin@v.loewis.de>
parents:
27104
diff
changeset
|
38 #define PyDoc_STRVAR(name,str) static char name[] = str |
|
27071
c30f97287602
Wrap doc strings in PyDoc_STRVAR. Fix .string docstring. Provide default
Martin v. Löwis <martin@v.loewis.de>
parents:
27069
diff
changeset
|
39 #endif |
|
c30f97287602
Wrap doc strings in PyDoc_STRVAR. Fix .string docstring. Provide default
Martin v. Löwis <martin@v.loewis.de>
parents:
27069
diff
changeset
|
40 |
|
c30f97287602
Wrap doc strings in PyDoc_STRVAR. Fix .string docstring. Provide default
Martin v. Löwis <martin@v.loewis.de>
parents:
27069
diff
changeset
|
41 #ifndef PyMODINIT_FUNC |
| 27084 | 42 #define PyMODINIT_FUNC void |
|
27071
c30f97287602
Wrap doc strings in PyDoc_STRVAR. Fix .string docstring. Provide default
Martin v. Löwis <martin@v.loewis.de>
parents:
27069
diff
changeset
|
43 #endif |
|
c30f97287602
Wrap doc strings in PyDoc_STRVAR. Fix .string docstring. Provide default
Martin v. Löwis <martin@v.loewis.de>
parents:
27069
diff
changeset
|
44 |
|
28444
2405371be34c
Fake bool API for Python 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
28156
diff
changeset
|
45 #ifndef PyBool_Check |
|
2405371be34c
Fake bool API for Python 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
28156
diff
changeset
|
46 #define PyBool_Check(o) 0 |
|
2405371be34c
Fake bool API for Python 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
28156
diff
changeset
|
47 #define PyBool_FromLong PyInt_FromLong |
|
2405371be34c
Fake bool API for Python 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
28156
diff
changeset
|
48 #endif |
|
2405371be34c
Fake bool API for Python 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
28156
diff
changeset
|
49 |
|
25527
5420969ddd70
Eliminate constness warnings with Tcl 8.4.
Martin v. Löwis <martin@v.loewis.de>
parents:
25525
diff
changeset
|
50 /* Starting with Tcl 8.4, many APIs offer const-correctness. Unfortunately, |
|
5420969ddd70
Eliminate constness warnings with Tcl 8.4.
Martin v. Löwis <martin@v.loewis.de>
parents:
25525
diff
changeset
|
51 making _tkinter correct for this API means to break earlier |
|
5420969ddd70
Eliminate constness warnings with Tcl 8.4.
Martin v. Löwis <martin@v.loewis.de>
parents:
25525
diff
changeset
|
52 versions. USE_COMPAT_CONST allows to make _tkinter work with both 8.4 and |
|
5420969ddd70
Eliminate constness warnings with Tcl 8.4.
Martin v. Löwis <martin@v.loewis.de>
parents:
25525
diff
changeset
|
53 earlier versions. Once Tcl releases before 8.4 don't need to be supported |
|
5420969ddd70
Eliminate constness warnings with Tcl 8.4.
Martin v. Löwis <martin@v.loewis.de>
parents:
25525
diff
changeset
|
54 anymore, this should go. */ |
|
5420969ddd70
Eliminate constness warnings with Tcl 8.4.
Martin v. Löwis <martin@v.loewis.de>
parents:
25525
diff
changeset
|
55 #define USE_COMPAT_CONST |
|
5420969ddd70
Eliminate constness warnings with Tcl 8.4.
Martin v. Löwis <martin@v.loewis.de>
parents:
25525
diff
changeset
|
56 |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
57 /* If Tcl is compiled for threads, we must also define TCL_THREAD. We define |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
58 it always; if Tcl is not threaded, the thread functions in |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
59 Tcl are empty. */ |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
60 #define TCL_THREADS |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
61 |
|
21322
1852caba7014
Mods by Tony Lownds (patch 490100, slightly massaged by me) to make Tkinter
Jack Jansen <jack.jansen@cwi.nl>
parents:
21073
diff
changeset
|
62 #ifdef TK_FRAMEWORK |
|
1852caba7014
Mods by Tony Lownds (patch 490100, slightly massaged by me) to make Tkinter
Jack Jansen <jack.jansen@cwi.nl>
parents:
21073
diff
changeset
|
63 #include <Tcl/tcl.h> |
|
1852caba7014
Mods by Tony Lownds (patch 490100, slightly massaged by me) to make Tkinter
Jack Jansen <jack.jansen@cwi.nl>
parents:
21073
diff
changeset
|
64 #include <Tk/tk.h> |
|
1852caba7014
Mods by Tony Lownds (patch 490100, slightly massaged by me) to make Tkinter
Jack Jansen <jack.jansen@cwi.nl>
parents:
21073
diff
changeset
|
65 #else |
| 1664 | 66 #include <tcl.h> |
| 67 #include <tk.h> | |
|
21322
1852caba7014
Mods by Tony Lownds (patch 490100, slightly massaged by me) to make Tkinter
Jack Jansen <jack.jansen@cwi.nl>
parents:
21073
diff
changeset
|
68 #endif |
| 1664 | 69 |
|
26989
bcbd94c610e8
Patch #660485: Cygwin _tkinter Tcl/Tk 8.3 patch
Jason Tishler <jason@tishler.net>
parents:
26971
diff
changeset
|
70 /* For Tcl 8.2 and 8.3, CONST* is not defined (except on Cygwin). */ |
|
26858
b4ca5b9ba933
Silence cast warnings for Tcl 8.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
26814
diff
changeset
|
71 #ifndef CONST84_RETURN |
|
b4ca5b9ba933
Silence cast warnings for Tcl 8.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
26814
diff
changeset
|
72 #define CONST84_RETURN |
|
26989
bcbd94c610e8
Patch #660485: Cygwin _tkinter Tcl/Tk 8.3 patch
Jason Tishler <jason@tishler.net>
parents:
26971
diff
changeset
|
73 #undef CONST |
|
26858
b4ca5b9ba933
Silence cast warnings for Tcl 8.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
26814
diff
changeset
|
74 #define CONST |
|
b4ca5b9ba933
Silence cast warnings for Tcl 8.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
26814
diff
changeset
|
75 #endif |
|
b4ca5b9ba933
Silence cast warnings for Tcl 8.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
26814
diff
changeset
|
76 |
|
5913
6b39f8633ca5
Compatibility with Tcl/Tk 8.0b*.
Guido van Rossum <guido@python.org>
parents:
5866
diff
changeset
|
77 #define TKMAJORMINOR (TK_MAJOR_VERSION*1000 + TK_MINOR_VERSION) |
|
6b39f8633ca5
Compatibility with Tcl/Tk 8.0b*.
Guido van Rossum <guido@python.org>
parents:
5866
diff
changeset
|
78 |
|
25525
2e140700fb6c
Drop support for Tk 8.0 and 8.1.
Martin v. Löwis <martin@v.loewis.de>
parents:
24363
diff
changeset
|
79 #if TKMAJORMINOR < 8002 |
|
2e140700fb6c
Drop support for Tk 8.0 and 8.1.
Martin v. Löwis <martin@v.loewis.de>
parents:
24363
diff
changeset
|
80 #error "Tk older than 8.2 not supported" |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
81 #endif |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
82 |
|
25530
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
83 /* Unicode conversion assumes that Tcl_UniChar is two bytes. |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
84 We cannot test this directly, so we test UTF-8 size instead, |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
85 expecting that TCL_UTF_MAX is changed if Tcl ever supports |
|
28643
ca2482012b3c
Support UCS-4 Tcl for UCS-4 Python builds. Fixes #719880.
Martin v. Löwis <martin@v.loewis.de>
parents:
28622
diff
changeset
|
86 either UTF-16 or UCS-4. |
|
ca2482012b3c
Support UCS-4 Tcl for UCS-4 Python builds. Fixes #719880.
Martin v. Löwis <martin@v.loewis.de>
parents:
28622
diff
changeset
|
87 Redhat 8 sets TCL_UTF_MAX to 6, and uses wchar_t for |
|
ca2482012b3c
Support UCS-4 Tcl for UCS-4 Python builds. Fixes #719880.
Martin v. Löwis <martin@v.loewis.de>
parents:
28622
diff
changeset
|
88 Tcl_Unichar. This is also ok as long as Python uses UCS-4, |
|
ca2482012b3c
Support UCS-4 Tcl for UCS-4 Python builds. Fixes #719880.
Martin v. Löwis <martin@v.loewis.de>
parents:
28622
diff
changeset
|
89 as well. |
|
ca2482012b3c
Support UCS-4 Tcl for UCS-4 Python builds. Fixes #719880.
Martin v. Löwis <martin@v.loewis.de>
parents:
28622
diff
changeset
|
90 */ |
|
ca2482012b3c
Support UCS-4 Tcl for UCS-4 Python builds. Fixes #719880.
Martin v. Löwis <martin@v.loewis.de>
parents:
28622
diff
changeset
|
91 #if TCL_UTF_MAX != 3 && !(defined(Py_UNICODE_WIDE) && TCL_UTF_MAX==6) |
|
25530
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
92 #error "unsupported Tcl configuration" |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
93 #endif |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
94 |
|
30979
86fdf8fe7f17
Getting rid of all the code inside #ifdef macintosh too.
Jack Jansen <jack.jansen@cwi.nl>
parents:
30638
diff
changeset
|
95 #if !(defined(MS_WINDOWS) || defined(__CYGWIN__)) |
|
6026
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
96 #define HAVE_CREATEFILEHANDLER |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
97 #endif |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
98 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
99 #ifdef HAVE_CREATEFILEHANDLER |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
100 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
101 /* Tcl_CreateFileHandler() changed several times; these macros deal with the |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
102 messiness. In Tcl 8.0 and later, it is not available on Windows (and on |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
103 Unix, only because Jack added it back); when available on Windows, it only |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
104 applies to sockets. */ |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
105 |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
106 #ifdef MS_WINDOWS |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
107 #define FHANDLETYPE TCL_WIN_SOCKET |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
108 #else |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
109 #define FHANDLETYPE TCL_UNIX_FD |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
110 #endif |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
111 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
112 /* If Tcl can wait for a Unix file descriptor, define the EventHook() routine |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
113 which uses this to handle Tcl events while the user is typing commands. */ |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
114 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
115 #if FHANDLETYPE == TCL_UNIX_FD |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
116 #define WAIT_FOR_STDIN |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
117 #endif |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
118 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
119 #endif /* HAVE_CREATEFILEHANDLER */ |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
120 |
|
8499
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
121 #ifdef MS_WINDOWS |
|
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
122 #include <conio.h> |
|
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
123 #define WAIT_FOR_STDIN |
|
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
124 #endif |
|
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
125 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
126 #ifdef WITH_THREAD |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
127 |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
128 /* The threading situation is complicated. Tcl is not thread-safe, except |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
129 when configured with --enable-threads. |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
130 So we need to use a lock around all uses of Tcl. Previously, the Python |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
131 interpreter lock was used for this. However, this causes problems when |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
132 other Python threads need to run while Tcl is blocked waiting for events. |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
133 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
134 To solve this problem, a separate lock for Tcl is introduced. Holding it |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
135 is incompatible with holding Python's interpreter lock. The following four |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
136 macros manipulate both locks together. |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
137 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
138 ENTER_TCL and LEAVE_TCL are brackets, just like Py_BEGIN_ALLOW_THREADS and |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
139 Py_END_ALLOW_THREADS. They should be used whenever a call into Tcl is made |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
140 that could call an event handler, or otherwise affect the state of a Tcl |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
141 interpreter. These assume that the surrounding code has the Python |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
142 interpreter lock; inside the brackets, the Python interpreter lock has been |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
143 released and the lock for Tcl has been acquired. |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
144 |
|
8504
de11a88ac498
# Note: a previous checkin message was lost because I can now use CVS
Guido van Rossum <guido@python.org>
parents:
8500
diff
changeset
|
145 Sometimes, it is necessary to have both the Python lock and the Tcl lock. |
|
de11a88ac498
# Note: a previous checkin message was lost because I can now use CVS
Guido van Rossum <guido@python.org>
parents:
8500
diff
changeset
|
146 (For example, when transferring data from the Tcl interpreter result to a |
|
de11a88ac498
# Note: a previous checkin message was lost because I can now use CVS
Guido van Rossum <guido@python.org>
parents:
8500
diff
changeset
|
147 Python string object.) This can be done by using different macros to close |
|
de11a88ac498
# Note: a previous checkin message was lost because I can now use CVS
Guido van Rossum <guido@python.org>
parents:
8500
diff
changeset
|
148 the ENTER_TCL block: ENTER_OVERLAP reacquires the Python lock (and restores |
|
de11a88ac498
# Note: a previous checkin message was lost because I can now use CVS
Guido van Rossum <guido@python.org>
parents:
8500
diff
changeset
|
149 the thread state) but doesn't release the Tcl lock; LEAVE_OVERLAP_TCL |
|
de11a88ac498
# Note: a previous checkin message was lost because I can now use CVS
Guido van Rossum <guido@python.org>
parents:
8500
diff
changeset
|
150 releases the Tcl lock. |
|
de11a88ac498
# Note: a previous checkin message was lost because I can now use CVS
Guido van Rossum <guido@python.org>
parents:
8500
diff
changeset
|
151 |
|
9319
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
152 By contrast, ENTER_PYTHON and LEAVE_PYTHON are used in Tcl event |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
153 handlers when the handler needs to use Python. Such event handlers are |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
154 entered while the lock for Tcl is held; the event handler presumably needs |
|
9319
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
155 to use Python. ENTER_PYTHON releases the lock for Tcl and acquires |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
156 the Python interpreter lock, restoring the appropriate thread state, and |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
157 LEAVE_PYTHON releases the Python interpreter lock and re-acquires the lock |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
158 for Tcl. It is okay for ENTER_TCL/LEAVE_TCL pairs to be contained inside |
|
9319
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
159 the code between ENTER_PYTHON and LEAVE_PYTHON. |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
160 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
161 These locks expand to several statements and brackets; they should not be |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
162 used in branches of if statements and the like. |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
163 |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
164 If Tcl is threaded, this approach won't work anymore. The Tcl interpreter is |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
165 only valid in the thread that created it, and all Tk activity must happen in this |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
166 thread, also. That means that the mainloop must be invoked in the thread that |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
167 created the interpreter. Invoking commands from other threads is possible; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
168 _tkinter will queue an event for the interpreter thread, which will then |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
169 execute the command and pass back the result. If the main thread is not in the |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
170 mainloop, and invoking commands causes an exception; if the main loop is running |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
171 but not processing events, the command invocation will block. |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
172 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
173 In addition, for a threaded Tcl, a single global tcl_tstate won't be sufficient |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
174 anymore, since multiple Tcl interpreters may simultaneously dispatch in different |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
175 threads. So we use the Tcl TLS API. |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
176 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
177 */ |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
178 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
179 static PyThread_type_lock tcl_lock = 0; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
180 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
181 #ifdef TCL_THREADS |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
182 static Tcl_ThreadDataKey state_key; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
183 typedef PyThreadState *ThreadSpecificData; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
184 #define tcl_tstate (*(PyThreadState**)Tcl_GetThreadData(&state_key, sizeof(PyThreadState*))) |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
185 #else |
|
9319
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
186 static PyThreadState *tcl_tstate = NULL; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
187 #endif |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
188 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
189 #define ENTER_TCL \ |
|
9319
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
190 { PyThreadState *tstate = PyThreadState_Get(); Py_BEGIN_ALLOW_THREADS \ |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
191 if(tcl_lock)PyThread_acquire_lock(tcl_lock, 1); tcl_tstate = tstate; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
192 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
193 #define LEAVE_TCL \ |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
194 tcl_tstate = NULL; if(tcl_lock)PyThread_release_lock(tcl_lock); Py_END_ALLOW_THREADS} |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
195 |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
196 #define ENTER_OVERLAP \ |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
197 Py_END_ALLOW_THREADS |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
198 |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
199 #define LEAVE_OVERLAP_TCL \ |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
200 tcl_tstate = NULL; if(tcl_lock)PyThread_release_lock(tcl_lock); } |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
201 |
|
9319
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
202 #define ENTER_PYTHON \ |
|
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
203 { PyThreadState *tstate = tcl_tstate; tcl_tstate = NULL; \ |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
204 if(tcl_lock)PyThread_release_lock(tcl_lock); PyEval_RestoreThread((tstate)); } |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
205 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
206 #define LEAVE_PYTHON \ |
|
9319
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
207 { PyThreadState *tstate = PyEval_SaveThread(); \ |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
208 if(tcl_lock)PyThread_acquire_lock(tcl_lock, 1); tcl_tstate = tstate; } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
209 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
210 #define CHECK_TCL_APPARTMENT \ |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
211 if (((TkappObject *)self)->threaded && \ |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
212 ((TkappObject *)self)->thread_id != Tcl_GetCurrentThread()) { \ |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
213 PyErr_SetString(PyExc_RuntimeError, "Calling Tcl from different appartment"); \ |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
214 return 0; \ |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
215 } |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
216 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
217 #else |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
218 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
219 #define ENTER_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
220 #define LEAVE_TCL |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
221 #define ENTER_OVERLAP |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
222 #define LEAVE_OVERLAP_TCL |
|
9319
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
223 #define ENTER_PYTHON |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
224 #define LEAVE_PYTHON |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
225 #define CHECK_TCL_APPARTMENT |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
226 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
227 #endif |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
228 |
|
3973
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
229 #ifndef FREECAST |
|
4005
7495322427c7
Changes for Windows NT -- this time it works, with Tcl4.1p1 (p1!!!) etc.
Guido van Rossum <guido@python.org>
parents:
3973
diff
changeset
|
230 #define FREECAST (char *) |
|
3973
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
231 #endif |
|
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
232 |
| 1664 | 233 /**** Tkapp Object Declaration ****/ |
| 234 | |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23662
diff
changeset
|
235 static PyTypeObject Tkapp_Type; |
| 1664 | 236 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
237 typedef struct { |
| 4968 | 238 PyObject_HEAD |
| 239 Tcl_Interp *interp; | |
|
26428
0103f0b75fe2
Rename want_objects to wantobjects throughout, for consistency.
Martin v. Löwis <martin@v.loewis.de>
parents:
26416
diff
changeset
|
240 int wantobjects; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
241 int threaded; /* True if tcl_platform[threaded] */ |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
242 Tcl_ThreadId thread_id; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
243 int dispatching; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
244 /* We cannot include tclInt.h, as this is internal. |
|
26431
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
245 So we cache interesting types here. */ |
|
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
246 Tcl_ObjType *BooleanType; |
|
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
247 Tcl_ObjType *ByteArrayType; |
|
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
248 Tcl_ObjType *DoubleType; |
|
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
249 Tcl_ObjType *IntType; |
|
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
250 Tcl_ObjType *ListType; |
|
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
251 Tcl_ObjType *ProcBodyType; |
|
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
252 Tcl_ObjType *StringType; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
253 } TkappObject; |
| 1664 | 254 |
| 255 #define Tkapp_Check(v) ((v)->ob_type == &Tkapp_Type) | |
| 256 #define Tkapp_Interp(v) (((TkappObject *) (v))->interp) | |
| 15177 | 257 #define Tkapp_Result(v) Tcl_GetStringResult(Tkapp_Interp(v)) |
| 1664 | 258 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
259 #define DEBUG_REFCNT(v) (printf("DEBUG: id=%p, refcnt=%i\n", \ |
| 4968 | 260 (void *) v, ((PyObject *) v)->ob_refcnt)) |
| 1664 | 261 |
| 4968 | 262 |
| 263 | |
| 1664 | 264 /**** Error Handling ****/ |
| 265 | |
| 266 static PyObject *Tkinter_TclError; | |
| 1713 | 267 static int quitMainLoop = 0; |
| 1664 | 268 static int errorInCmd = 0; |
| 269 static PyObject *excInCmd; | |
| 270 static PyObject *valInCmd; | |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
2009
diff
changeset
|
271 static PyObject *trbInCmd; |
| 1664 | 272 |
| 4968 | 273 |
| 274 | |
| 1664 | 275 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
276 Tkinter_Error(PyObject *v) |
| 1664 | 277 { |
| 4968 | 278 PyErr_SetString(Tkinter_TclError, Tkapp_Result(v)); |
| 279 return NULL; | |
| 1664 | 280 } |
| 281 | |
| 4968 | 282 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
283 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
284 /**** Utils ****/ |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
285 |
|
29038
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
286 static int Tkinter_busywaitinterval = 20; |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
287 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
288 #ifdef WITH_THREAD |
|
8446
59dfa9eb7c07
On Windows, need #include <windows.h>; and it's MS_WINDOWS, not MS_WIN32.
Guido van Rossum <guido@python.org>
parents:
8444
diff
changeset
|
289 #ifndef MS_WINDOWS |
|
8987
3e127bca84e7
Need mytime.h for Sleep().
Guido van Rossum <guido@python.org>
parents:
8828
diff
changeset
|
290 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
291 /* Millisecond sleep() for Unix platforms. */ |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
292 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
293 static void |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
294 Sleep(int milli) |
| 1664 | 295 { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
296 /* XXX Too bad if you don't have select(). */ |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
297 struct timeval t; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
298 t.tv_sec = milli/1000; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
299 t.tv_usec = (milli%1000) * 1000; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
300 select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t); |
| 1664 | 301 } |
|
8446
59dfa9eb7c07
On Windows, need #include <windows.h>; and it's MS_WINDOWS, not MS_WIN32.
Guido van Rossum <guido@python.org>
parents:
8444
diff
changeset
|
302 #endif /* MS_WINDOWS */ |
| 4968 | 303 |
|
26814
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
304 /* Wait up to 1s for the mainloop to come up. */ |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
305 |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
306 static int |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
307 WaitForMainloop(TkappObject* self) |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
308 { |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
309 int i; |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
310 for (i = 0; i < 10; i++) { |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
311 if (self->dispatching) |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
312 return 1; |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
313 Py_BEGIN_ALLOW_THREADS |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
314 Sleep(100); |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
315 Py_END_ALLOW_THREADS |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
316 } |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
317 if (self->dispatching) |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
318 return 1; |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
319 PyErr_SetString(PyExc_RuntimeError, "main thread is not in main loop"); |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
320 return 0; |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
321 } |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
322 #endif /* WITH_THREAD */ |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
323 |
| 4968 | 324 |
| 1664 | 325 static char * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
326 AsString(PyObject *value, PyObject *tmp) |
| 1664 | 327 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
328 if (PyString_Check(value)) |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
329 return PyString_AsString(value); |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19033
diff
changeset
|
330 #ifdef Py_USING_UNICODE |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
331 else if (PyUnicode_Check(value)) { |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
332 PyObject *v = PyUnicode_AsUTF8String(value); |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
333 if (v == NULL) |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
334 return NULL; |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
335 if (PyList_Append(tmp, v) != 0) { |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
336 Py_DECREF(v); |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
337 return NULL; |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
338 } |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
339 Py_DECREF(v); |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
340 return PyString_AsString(v); |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
341 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19033
diff
changeset
|
342 #endif |
| 4968 | 343 else { |
| 344 PyObject *v = PyObject_Str(value); | |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
345 if (v == NULL) |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
346 return NULL; |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
347 if (PyList_Append(tmp, v) != 0) { |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
348 Py_DECREF(v); |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
349 return NULL; |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
350 } |
| 4968 | 351 Py_DECREF(v); |
| 352 return PyString_AsString(v); | |
| 353 } | |
| 1664 | 354 } |
| 355 | |
| 4968 | 356 |
| 357 | |
| 1664 | 358 #define ARGSZ 64 |
| 359 | |
| 360 static char * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
361 Merge(PyObject *args) |
| 1664 | 362 { |
| 4968 | 363 PyObject *tmp = NULL; |
| 364 char *argvStore[ARGSZ]; | |
| 365 char **argv = NULL; | |
| 366 int fvStore[ARGSZ]; | |
| 367 int *fv = NULL; | |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
368 int argc = 0, fvc = 0, i; |
| 4968 | 369 char *res = NULL; |
| 370 | |
| 371 if (!(tmp = PyList_New(0))) | |
| 372 return NULL; | |
| 373 | |
| 374 argv = argvStore; | |
| 375 fv = fvStore; | |
| 376 | |
| 377 if (args == NULL) | |
| 378 argc = 0; | |
| 1664 | 379 |
| 4968 | 380 else if (!PyTuple_Check(args)) { |
| 381 argc = 1; | |
| 382 fv[0] = 0; | |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
383 if (!(argv[0] = AsString(args, tmp))) |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
384 goto finally; |
| 4968 | 385 } |
| 386 else { | |
| 387 argc = PyTuple_Size(args); | |
| 388 | |
| 389 if (argc > ARGSZ) { | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
390 argv = (char **)ckalloc(argc * sizeof(char *)); |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
391 fv = (int *)ckalloc(argc * sizeof(int)); |
| 4968 | 392 if (argv == NULL || fv == NULL) { |
| 393 PyErr_NoMemory(); | |
| 394 goto finally; | |
| 395 } | |
| 396 } | |
| 1664 | 397 |
| 4968 | 398 for (i = 0; i < argc; i++) { |
| 399 PyObject *v = PyTuple_GetItem(args, i); | |
| 400 if (PyTuple_Check(v)) { | |
| 401 fv[i] = 1; | |
| 402 if (!(argv[i] = Merge(v))) | |
| 403 goto finally; | |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
404 fvc++; |
| 4968 | 405 } |
| 406 else if (v == Py_None) { | |
| 407 argc = i; | |
| 408 break; | |
| 409 } | |
| 410 else { | |
| 411 fv[i] = 0; | |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
412 if (!(argv[i] = AsString(v, tmp))) |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
413 goto finally; |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
414 fvc++; |
| 4968 | 415 } |
| 416 } | |
| 417 } | |
| 418 res = Tcl_Merge(argc, argv); | |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
419 if (res == NULL) |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
420 PyErr_SetString(Tkinter_TclError, "merge failed"); |
| 1664 | 421 |
| 4968 | 422 finally: |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
423 for (i = 0; i < fvc; i++) |
| 4968 | 424 if (fv[i]) { |
| 425 ckfree(argv[i]); | |
| 426 } | |
| 427 if (argv != argvStore) | |
| 428 ckfree(FREECAST argv); | |
| 429 if (fv != fvStore) | |
| 430 ckfree(FREECAST fv); | |
| 431 | |
| 432 Py_DECREF(tmp); | |
| 433 return res; | |
| 434 } | |
| 435 | |
| 436 | |
| 437 | |
| 438 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
439 Split(char *list) |
| 4968 | 440 { |
| 441 int argc; | |
| 442 char **argv; | |
| 443 PyObject *v; | |
| 444 | |
| 445 if (list == NULL) { | |
| 446 Py_INCREF(Py_None); | |
| 447 return Py_None; | |
| 1664 | 448 } |
| 449 | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
450 if (Tcl_SplitList((Tcl_Interp *)NULL, list, &argc, &argv) != TCL_OK) { |
| 4968 | 451 /* Not a list. |
| 452 * Could be a quoted string containing funnies, e.g. {"}. | |
| 453 * Return the string itself. | |
| 454 */ | |
| 455 return PyString_FromString(list); | |
| 1664 | 456 } |
| 457 | |
| 4968 | 458 if (argc == 0) |
| 459 v = PyString_FromString(""); | |
| 460 else if (argc == 1) | |
| 461 v = PyString_FromString(argv[0]); | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
462 else if ((v = PyTuple_New(argc)) != NULL) { |
| 4968 | 463 int i; |
| 464 PyObject *w; | |
| 1664 | 465 |
| 4968 | 466 for (i = 0; i < argc; i++) { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
467 if ((w = Split(argv[i])) == NULL) { |
| 4968 | 468 Py_DECREF(v); |
| 469 v = NULL; | |
| 470 break; | |
| 471 } | |
| 472 PyTuple_SetItem(v, i, w); | |
| 473 } | |
| 474 } | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
475 Tcl_Free(FREECAST argv); |
| 4968 | 476 return v; |
| 1664 | 477 } |
| 478 | |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
479 /* In some cases, Tcl will still return strings that are supposed to be |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
480 lists. SplitObj walks through a nested tuple, finding string objects that |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
481 need to be split. */ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
482 |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
483 PyObject * |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
484 SplitObj(PyObject *arg) |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
485 { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
486 if (PyTuple_Check(arg)) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
487 int i, size; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
488 PyObject *elem, *newelem, *result; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
489 |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
490 size = PyTuple_Size(arg); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
491 result = NULL; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
492 /* Recursively invoke SplitObj for all tuple items. |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
493 If this does not return a new object, no action is |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
494 needed. */ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
495 for(i = 0; i < size; i++) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
496 elem = PyTuple_GetItem(arg, i); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
497 newelem = SplitObj(elem); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
498 if (!newelem) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
499 Py_XDECREF(result); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
500 return NULL; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
501 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
502 if (!result) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
503 int k; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
504 if (newelem == elem) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
505 Py_DECREF(newelem); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
506 continue; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
507 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
508 result = PyTuple_New(size); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
509 if (!result) |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
510 return NULL; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
511 for(k = 0; k < i; k++) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
512 elem = PyTuple_GetItem(arg, k); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
513 Py_INCREF(elem); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
514 PyTuple_SetItem(result, k, elem); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
515 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
516 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
517 PyTuple_SetItem(result, i, newelem); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
518 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
519 if (result) |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
520 return result; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
521 /* Fall through, returning arg. */ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
522 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
523 else if (PyString_Check(arg)) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
524 int argc; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
525 char **argv; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
526 char *list = PyString_AsString(arg); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
527 |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
528 if (Tcl_SplitList((Tcl_Interp *)NULL, list, &argc, &argv) != TCL_OK) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
529 Py_INCREF(arg); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
530 return arg; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
531 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
532 Tcl_Free(FREECAST argv); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
533 if (argc > 1) |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
534 return Split(PyString_AsString(arg)); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
535 /* Fall through, returning arg. */ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
536 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
537 Py_INCREF(arg); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
538 return arg; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
539 } |
| 1664 | 540 |
| 4968 | 541 |
| 1664 | 542 /**** Tkapp Object ****/ |
| 543 | |
| 544 #ifndef WITH_APPINIT | |
| 545 int | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
546 Tcl_AppInit(Tcl_Interp *interp) |
| 1664 | 547 { |
| 4968 | 548 Tk_Window main; |
|
31547
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
549 const char * _tkinter_skip_tk_init; |
|
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
550 |
| 4968 | 551 if (Tcl_Init(interp) == TCL_ERROR) { |
| 15177 | 552 PySys_WriteStderr("Tcl_Init error: %s\n", Tcl_GetStringResult(interp)); |
| 4968 | 553 return TCL_ERROR; |
| 554 } | |
|
31547
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
555 _tkinter_skip_tk_init = Tcl_GetVar(interp, "_tkinter_skip_tk_init", TCL_GLOBAL_ONLY); |
|
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
556 if (_tkinter_skip_tk_init == NULL || strcmp(_tkinter_skip_tk_init, "1") != 0) { |
|
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
557 main = Tk_MainWindow(interp); |
|
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
558 if (Tk_Init(interp) == TCL_ERROR) { |
|
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
559 PySys_WriteStderr("Tk_Init error: %s\n", Tcl_GetStringResult(interp)); |
|
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
560 return TCL_ERROR; |
|
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
561 } |
| 4968 | 562 } |
| 563 return TCL_OK; | |
| 1664 | 564 } |
| 4968 | 565 #endif /* !WITH_APPINIT */ |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
566 |
| 4968 | 567 |
| 568 | |
| 1664 | 569 |
| 570 /* Initialize the Tk application; see the `main' function in | |
| 4968 | 571 * `tkMain.c'. |
| 572 */ | |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
573 |
|
13690
c09c0171474f
ANSIfy some more forward declarations.
Thomas Wouters <thomas@python.org>
parents:
13651
diff
changeset
|
574 static void EnableEventHook(void); /* Forward */ |
|
c09c0171474f
ANSIfy some more forward declarations.
Thomas Wouters <thomas@python.org>
parents:
13651
diff
changeset
|
575 static void DisableEventHook(void); /* Forward */ |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
576 |
| 1664 | 577 static TkappObject * |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
578 Tkapp_New(char *screenName, char *baseName, char *className, |
|
32942
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
579 int interactive, int wantobjects, int wantTk, int sync, char *use) |
| 1664 | 580 { |
| 4968 | 581 TkappObject *v; |
| 582 char *argv0; | |
|
32945
fbb5428ebf41
Tkapp_New(): Rewrite in C so it compiles again.
Tim Peters <tim.peters@gmail.com>
parents:
32942
diff
changeset
|
583 |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12513
diff
changeset
|
584 v = PyObject_New(TkappObject, &Tkapp_Type); |
| 4968 | 585 if (v == NULL) |
| 586 return NULL; | |
| 1664 | 587 |
| 4968 | 588 v->interp = Tcl_CreateInterp(); |
|
26428
0103f0b75fe2
Rename want_objects to wantobjects throughout, for consistency.
Martin v. Löwis <martin@v.loewis.de>
parents:
26416
diff
changeset
|
589 v->wantobjects = wantobjects; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
590 v->threaded = Tcl_GetVar2Ex(v->interp, "tcl_platform", "threaded", |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
591 TCL_GLOBAL_ONLY) != NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
592 v->thread_id = Tcl_GetCurrentThread(); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
593 v->dispatching = 0; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
594 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
595 #ifndef TCL_THREADS |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
596 if (v->threaded) { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
597 PyErr_SetString(PyExc_RuntimeError, "Tcl is threaded but _tkinter is not"); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
598 Py_DECREF(v); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
599 return 0; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
600 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
601 #endif |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
602 #ifdef WITH_THREAD |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
603 if (v->threaded && tcl_lock) { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
604 /* If Tcl is threaded, we don't need the lock. */ |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
605 PyThread_free_lock(tcl_lock); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
606 tcl_lock = NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
607 } |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
608 #endif |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
609 |
|
26431
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
610 v->BooleanType = Tcl_GetObjType("boolean"); |
|
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
611 v->ByteArrayType = Tcl_GetObjType("bytearray"); |
|
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
612 v->DoubleType = Tcl_GetObjType("double"); |
|
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
613 v->IntType = Tcl_GetObjType("int"); |
|
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
614 v->ListType = Tcl_GetObjType("list"); |
|
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
615 v->ProcBodyType = Tcl_GetObjType("procbody"); |
|
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
616 v->StringType = Tcl_GetObjType("string"); |
|
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
617 |
|
7416
13f29b62a209
Delete the 'exit' command from the Tcl interpreter -- it would allow
Guido van Rossum <guido@python.org>
parents:
7212
diff
changeset
|
618 /* Delete the 'exit' command, which can screw things up */ |
|
13f29b62a209
Delete the 'exit' command from the Tcl interpreter -- it would allow
Guido van Rossum <guido@python.org>
parents:
7212
diff
changeset
|
619 Tcl_DeleteCommand(v->interp, "exit"); |
|
13f29b62a209
Delete the 'exit' command from the Tcl interpreter -- it would allow
Guido van Rossum <guido@python.org>
parents:
7212
diff
changeset
|
620 |
| 4968 | 621 if (screenName != NULL) |
| 622 Tcl_SetVar2(v->interp, "env", "DISPLAY", | |
| 623 screenName, TCL_GLOBAL_ONLY); | |
| 1664 | 624 |
| 4968 | 625 if (interactive) |
| 626 Tcl_SetVar(v->interp, "tcl_interactive", "1", TCL_GLOBAL_ONLY); | |
| 627 else | |
| 628 Tcl_SetVar(v->interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY); | |
| 1664 | 629 |
| 4968 | 630 /* This is used to get the application class for Tk 4.1 and up */ |
| 631 argv0 = (char*)ckalloc(strlen(className) + 1); | |
| 632 if (!argv0) { | |
| 633 PyErr_NoMemory(); | |
| 634 Py_DECREF(v); | |
| 635 return NULL; | |
| 636 } | |
|
3973
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
637 |
| 4968 | 638 strcpy(argv0, className); |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
7416
diff
changeset
|
639 if (isupper((int)(argv0[0]))) |
| 4968 | 640 argv0[0] = tolower(argv0[0]); |
| 641 Tcl_SetVar(v->interp, "argv0", argv0, TCL_GLOBAL_ONLY); | |
| 642 ckfree(argv0); | |
| 1664 | 643 |
|
31547
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
644 if (! wantTk) { |
|
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
645 Tcl_SetVar(v->interp, "_tkinter_skip_tk_init", "1", TCL_GLOBAL_ONLY); |
|
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
646 } |
|
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
647 |
|
32942
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
648 /* some initial arguments need to be in argv */ |
|
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
649 if (sync || use) { |
|
32945
fbb5428ebf41
Tkapp_New(): Rewrite in C so it compiles again.
Tim Peters <tim.peters@gmail.com>
parents:
32942
diff
changeset
|
650 char *args; |
|
32942
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
651 int len = 0; |
|
32945
fbb5428ebf41
Tkapp_New(): Rewrite in C so it compiles again.
Tim Peters <tim.peters@gmail.com>
parents:
32942
diff
changeset
|
652 |
|
32942
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
653 if (sync) |
|
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
654 len += sizeof "-sync"; |
|
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
655 if (use) |
|
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
656 len += strlen(use) + sizeof "-use "; |
|
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
657 |
|
32945
fbb5428ebf41
Tkapp_New(): Rewrite in C so it compiles again.
Tim Peters <tim.peters@gmail.com>
parents:
32942
diff
changeset
|
658 args = (char*)ckalloc(len); |
|
32942
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
659 if (!args) { |
|
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
660 PyErr_NoMemory(); |
|
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
661 Py_DECREF(v); |
|
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
662 return NULL; |
|
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
663 } |
|
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
664 |
|
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
665 args[0] = '\0'; |
|
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
666 if (sync) |
|
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
667 strcat(args, "-sync"); |
|
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
668 if (use) { |
|
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
669 if (sync) |
|
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
670 strcat(args, " "); |
|
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
671 strcat(args, "-use "); |
|
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
672 strcat(args, use); |
|
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
673 } |
|
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
674 |
|
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
675 Tcl_SetVar(v->interp, "argv", args, TCL_GLOBAL_ONLY); |
|
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
676 ckfree(args); |
|
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
677 } |
|
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
678 |
|
36872
b16e504413c3
Backport trunk's r42888 (thomas.wouters):
Thomas Wouters <thomas@python.org>
parents:
34707
diff
changeset
|
679 if (Tcl_AppInit(v->interp) != TCL_OK) { |
|
b16e504413c3
Backport trunk's r42888 (thomas.wouters):
Thomas Wouters <thomas@python.org>
parents:
34707
diff
changeset
|
680 PyObject *result = Tkinter_Error((PyObject *)v); |
|
b16e504413c3
Backport trunk's r42888 (thomas.wouters):
Thomas Wouters <thomas@python.org>
parents:
34707
diff
changeset
|
681 Py_DECREF((PyObject *)v); |
|
b16e504413c3
Backport trunk's r42888 (thomas.wouters):
Thomas Wouters <thomas@python.org>
parents:
34707
diff
changeset
|
682 return (TkappObject *)result; |
|
b16e504413c3
Backport trunk's r42888 (thomas.wouters):
Thomas Wouters <thomas@python.org>
parents:
34707
diff
changeset
|
683 } |
| 4968 | 684 |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
685 EnableEventHook(); |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
686 |
| 4968 | 687 return v; |
| 1664 | 688 } |
| 689 | |
| 4968 | 690 |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
691 static void |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
692 Tkapp_ThreadSend(TkappObject *self, Tcl_Event *ev, |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
693 Tcl_Condition *cond, Tcl_Mutex *mutex) |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
694 { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
695 Py_BEGIN_ALLOW_THREADS; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
696 Tcl_MutexLock(mutex); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
697 Tcl_ThreadQueueEvent(self->thread_id, ev, TCL_QUEUE_TAIL); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
698 Tcl_ThreadAlert(self->thread_id); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
699 Tcl_ConditionWait(cond, mutex, NULL); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
700 Tcl_MutexUnlock(mutex); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
701 Py_END_ALLOW_THREADS |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
702 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
703 |
| 4968 | 704 |
| 1664 | 705 /** Tcl Eval **/ |
| 706 | |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
707 typedef struct { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
708 PyObject_HEAD |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
709 Tcl_Obj *value; |
|
27069
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
710 PyObject *string; /* This cannot cause cycles. */ |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
711 } PyTclObject; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
712 |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
713 staticforward PyTypeObject PyTclObject_Type; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
714 #define PyTclObject_Check(v) ((v)->ob_type == &PyTclObject_Type) |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
715 |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
716 static PyObject * |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
717 newPyTclObject(Tcl_Obj *arg) |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
718 { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
719 PyTclObject *self; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
720 self = PyObject_New(PyTclObject, &PyTclObject_Type); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
721 if (self == NULL) |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
722 return NULL; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
723 Tcl_IncrRefCount(arg); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
724 self->value = arg; |
|
27069
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
725 self->string = NULL; |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
726 return (PyObject*)self; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
727 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
728 |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
729 static void |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
730 PyTclObject_dealloc(PyTclObject *self) |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
731 { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
732 Tcl_DecrRefCount(self->value); |
|
27069
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
733 Py_XDECREF(self->string); |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
734 PyObject_Del(self); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
735 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
736 |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
737 static PyObject * |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
738 PyTclObject_str(PyTclObject *self) |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
739 { |
|
27069
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
740 if (self->string && PyString_Check(self->string)) { |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
741 Py_INCREF(self->string); |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
742 return self->string; |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
743 } |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
744 /* XXX Could cache value if it is an ASCII string. */ |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
745 return PyString_FromString(Tcl_GetString(self->value)); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
746 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
747 |
|
28915
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
748 static char* |
|
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
749 PyTclObject_TclString(PyObject *self) |
|
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
750 { |
|
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
751 return Tcl_GetString(((PyTclObject*)self)->value); |
|
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
752 } |
|
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
753 |
|
27069
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
754 /* Like _str, but create Unicode if necessary. */ |
|
27071
c30f97287602
Wrap doc strings in PyDoc_STRVAR. Fix .string docstring. Provide default
Martin v. Löwis <martin@v.loewis.de>
parents:
27069
diff
changeset
|
755 PyDoc_STRVAR(PyTclObject_string__doc__, |
|
c30f97287602
Wrap doc strings in PyDoc_STRVAR. Fix .string docstring. Provide default
Martin v. Löwis <martin@v.loewis.de>
parents:
27069
diff
changeset
|
756 "the string representation of this object, either as string or Unicode"); |
|
c30f97287602
Wrap doc strings in PyDoc_STRVAR. Fix .string docstring. Provide default
Martin v. Löwis <martin@v.loewis.de>
parents:
27069
diff
changeset
|
757 |
|
27069
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
758 static PyObject * |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
759 PyTclObject_string(PyTclObject *self, void *ignored) |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
760 { |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
761 char *s; |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
762 int i, len; |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
763 if (!self->string) { |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
764 s = Tcl_GetStringFromObj(self->value, &len); |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
765 for (i = 0; i < len; i++) |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
766 if (s[i] & 0x80) |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
767 break; |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
768 #ifdef Py_USING_UNICODE |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
769 if (i == len) |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
770 /* It is an ASCII string. */ |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
771 self->string = PyString_FromStringAndSize(s, len); |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
772 else { |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
773 self->string = PyUnicode_DecodeUTF8(s, len, "strict"); |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
774 if (!self->string) { |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
775 PyErr_Clear(); |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
776 self->string = PyString_FromStringAndSize(s, len); |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
777 } |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
778 } |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
779 #else |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
780 self->string = PyString_FromStringAndSize(s, len); |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
781 #endif |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
782 if (!self->string) |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
783 return NULL; |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
784 } |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
785 Py_INCREF(self->string); |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
786 return self->string; |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
787 } |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
788 |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
789 #ifdef Py_USING_UNICODE |
|
27071
c30f97287602
Wrap doc strings in PyDoc_STRVAR. Fix .string docstring. Provide default
Martin v. Löwis <martin@v.loewis.de>
parents:
27069
diff
changeset
|
790 PyDoc_STRVAR(PyTclObject_unicode__doc__, "convert argument to unicode"); |
|
c30f97287602
Wrap doc strings in PyDoc_STRVAR. Fix .string docstring. Provide default
Martin v. Löwis <martin@v.loewis.de>
parents:
27069
diff
changeset
|
791 |
|
27069
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
792 static PyObject * |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
793 PyTclObject_unicode(PyTclObject *self, void *ignored) |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
794 { |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
795 char *s; |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
796 int len; |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
797 if (self->string && PyUnicode_Check(self->string)) { |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
798 Py_INCREF(self->string); |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
799 return self->string; |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
800 } |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
801 /* XXX Could chache result if it is non-ASCII. */ |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
802 s = Tcl_GetStringFromObj(self->value, &len); |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
803 return PyUnicode_DecodeUTF8(s, len, "strict"); |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
804 } |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
805 #endif |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
806 |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
807 static PyObject * |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
808 PyTclObject_repr(PyTclObject *self) |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
809 { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
810 char buf[50]; |
|
33986
49b6e966e57f
Patch #1050475: Fix various x86_64 build issues
Martin v. Löwis <martin@v.loewis.de>
parents:
32945
diff
changeset
|
811 PyOS_snprintf(buf, 50, "<%s object at %p>", |
|
49b6e966e57f
Patch #1050475: Fix various x86_64 build issues
Martin v. Löwis <martin@v.loewis.de>
parents:
32945
diff
changeset
|
812 self->value->typePtr->name, self->value); |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
813 return PyString_FromString(buf); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
814 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
815 |
|
28950
3a9f5f0c512e
Implement tcl object __cmp__.
Martin v. Löwis <martin@v.loewis.de>
parents:
28915
diff
changeset
|
816 static int |
|
3a9f5f0c512e
Implement tcl object __cmp__.
Martin v. Löwis <martin@v.loewis.de>
parents:
28915
diff
changeset
|
817 PyTclObject_cmp(PyTclObject *self, PyTclObject *other) |
|
3a9f5f0c512e
Implement tcl object __cmp__.
Martin v. Löwis <martin@v.loewis.de>
parents:
28915
diff
changeset
|
818 { |
|
3a9f5f0c512e
Implement tcl object __cmp__.
Martin v. Löwis <martin@v.loewis.de>
parents:
28915
diff
changeset
|
819 int res; |
|
3a9f5f0c512e
Implement tcl object __cmp__.
Martin v. Löwis <martin@v.loewis.de>
parents:
28915
diff
changeset
|
820 res = strcmp(Tcl_GetString(self->value), |
|
3a9f5f0c512e
Implement tcl object __cmp__.
Martin v. Löwis <martin@v.loewis.de>
parents:
28915
diff
changeset
|
821 Tcl_GetString(other->value)); |
|
3a9f5f0c512e
Implement tcl object __cmp__.
Martin v. Löwis <martin@v.loewis.de>
parents:
28915
diff
changeset
|
822 if (res < 0) return -1; |
|
3a9f5f0c512e
Implement tcl object __cmp__.
Martin v. Löwis <martin@v.loewis.de>
parents:
28915
diff
changeset
|
823 if (res > 0) return 1; |
|
3a9f5f0c512e
Implement tcl object __cmp__.
Martin v. Löwis <martin@v.loewis.de>
parents:
28915
diff
changeset
|
824 return 0; |
|
3a9f5f0c512e
Implement tcl object __cmp__.
Martin v. Löwis <martin@v.loewis.de>
parents:
28915
diff
changeset
|
825 } |
|
3a9f5f0c512e
Implement tcl object __cmp__.
Martin v. Löwis <martin@v.loewis.de>
parents:
28915
diff
changeset
|
826 |
|
27071
c30f97287602
Wrap doc strings in PyDoc_STRVAR. Fix .string docstring. Provide default
Martin v. Löwis <martin@v.loewis.de>
parents:
27069
diff
changeset
|
827 PyDoc_STRVAR(get_typename__doc__, "name of the Tcl type"); |
|
c30f97287602
Wrap doc strings in PyDoc_STRVAR. Fix .string docstring. Provide default
Martin v. Löwis <martin@v.loewis.de>
parents:
27069
diff
changeset
|
828 |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
829 static PyObject* |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
830 get_typename(PyTclObject* obj, void* ignored) |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
831 { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
832 return PyString_FromString(obj->value->typePtr->name); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
833 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
834 |
|
27071
c30f97287602
Wrap doc strings in PyDoc_STRVAR. Fix .string docstring. Provide default
Martin v. Löwis <martin@v.loewis.de>
parents:
27069
diff
changeset
|
835 |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
836 static PyGetSetDef PyTclObject_getsetlist[] = { |
|
27071
c30f97287602
Wrap doc strings in PyDoc_STRVAR. Fix .string docstring. Provide default
Martin v. Löwis <martin@v.loewis.de>
parents:
27069
diff
changeset
|
837 {"typename", (getter)get_typename, NULL, get_typename__doc__}, |
|
c30f97287602
Wrap doc strings in PyDoc_STRVAR. Fix .string docstring. Provide default
Martin v. Löwis <martin@v.loewis.de>
parents:
27069
diff
changeset
|
838 {"string", (getter)PyTclObject_string, NULL, |
|
c30f97287602
Wrap doc strings in PyDoc_STRVAR. Fix .string docstring. Provide default
Martin v. Löwis <martin@v.loewis.de>
parents:
27069
diff
changeset
|
839 PyTclObject_string__doc__}, |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
840 {0}, |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
841 }; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
842 |
|
27069
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
843 static PyMethodDef PyTclObject_methods[] = { |
|
34707
0d44d9071e97
Build with --disable-unicode again. Fixes #1158607.
Martin v. Löwis <martin@v.loewis.de>
parents:
33986
diff
changeset
|
844 #ifdef Py_USING_UNICODE |
|
27069
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
845 {"__unicode__", (PyCFunction)PyTclObject_unicode, METH_NOARGS, |
|
27071
c30f97287602
Wrap doc strings in PyDoc_STRVAR. Fix .string docstring. Provide default
Martin v. Löwis <martin@v.loewis.de>
parents:
27069
diff
changeset
|
846 PyTclObject_unicode__doc__}, |
|
34707
0d44d9071e97
Build with --disable-unicode again. Fixes #1158607.
Martin v. Löwis <martin@v.loewis.de>
parents:
33986
diff
changeset
|
847 #endif |
|
27069
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
848 {0} |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
849 }; |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
850 |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
851 statichere PyTypeObject PyTclObject_Type = { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
852 PyObject_HEAD_INIT(NULL) |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
853 0, /*ob_size*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
854 "_tkinter.Tcl_Obj", /*tp_name*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
855 sizeof(PyTclObject), /*tp_basicsize*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
856 0, /*tp_itemsize*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
857 /* methods */ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
858 (destructor)PyTclObject_dealloc, /*tp_dealloc*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
859 0, /*tp_print*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
860 0, /*tp_getattr*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
861 0, /*tp_setattr*/ |
|
28950
3a9f5f0c512e
Implement tcl object __cmp__.
Martin v. Löwis <martin@v.loewis.de>
parents:
28915
diff
changeset
|
862 (cmpfunc)PyTclObject_cmp, /*tp_compare*/ |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
863 (reprfunc)PyTclObject_repr, /*tp_repr*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
864 0, /*tp_as_number*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
865 0, /*tp_as_sequence*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
866 0, /*tp_as_mapping*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
867 0, /*tp_hash*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
868 0, /*tp_call*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
869 (reprfunc)PyTclObject_str, /*tp_str*/ |
|
27104
2443c557cbc3
Patch #661760: Cygwin auto-import module patch
Jason Tishler <jason@tishler.net>
parents:
27084
diff
changeset
|
870 PyObject_GenericGetAttr,/*tp_getattro*/ |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
871 0, /*tp_setattro*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
872 0, /*tp_as_buffer*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
873 Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
874 0, /*tp_doc*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
875 0, /*tp_traverse*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
876 0, /*tp_clear*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
877 0, /*tp_richcompare*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
878 0, /*tp_weaklistoffset*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
879 0, /*tp_iter*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
880 0, /*tp_iternext*/ |
|
27069
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
881 PyTclObject_methods, /*tp_methods*/ |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
882 0, /*tp_members*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
883 PyTclObject_getsetlist, /*tp_getset*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
884 0, /*tp_base*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
885 0, /*tp_dict*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
886 0, /*tp_descr_get*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
887 0, /*tp_descr_set*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
888 0, /*tp_dictoffset*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
889 0, /*tp_init*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
890 0, /*tp_alloc*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
891 0, /*tp_new*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
892 0, /*tp_free*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
893 0, /*tp_is_gc*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
894 }; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
895 |
|
12141
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
896 static Tcl_Obj* |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
897 AsObj(PyObject *value) |
|
12141
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
898 { |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
899 Tcl_Obj *result; |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
900 |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
901 if (PyString_Check(value)) |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
902 return Tcl_NewStringObj(PyString_AS_STRING(value), |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
903 PyString_GET_SIZE(value)); |
|
27341
ba63d717c75f
Convert booleans to integers in IntVar.set. Fixes #671741.
Martin v. Löwis <martin@v.loewis.de>
parents:
27333
diff
changeset
|
904 else if (PyBool_Check(value)) |
|
ba63d717c75f
Convert booleans to integers in IntVar.set. Fixes #671741.
Martin v. Löwis <martin@v.loewis.de>
parents:
27333
diff
changeset
|
905 return Tcl_NewBooleanObj(PyObject_IsTrue(value)); |
|
12141
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
906 else if (PyInt_Check(value)) |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
907 return Tcl_NewLongObj(PyInt_AS_LONG(value)); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
908 else if (PyFloat_Check(value)) |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
909 return Tcl_NewDoubleObj(PyFloat_AS_DOUBLE(value)); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
910 else if (PyTuple_Check(value)) { |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
911 Tcl_Obj **argv = (Tcl_Obj**) |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
912 ckalloc(PyTuple_Size(value)*sizeof(Tcl_Obj*)); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
913 int i; |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
914 if(!argv) |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
915 return 0; |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
916 for(i=0;i<PyTuple_Size(value);i++) |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
917 argv[i] = AsObj(PyTuple_GetItem(value,i)); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
918 result = Tcl_NewListObj(PyTuple_Size(value), argv); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
919 ckfree(FREECAST argv); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
920 return result; |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
921 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19033
diff
changeset
|
922 #ifdef Py_USING_UNICODE |
|
12141
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
923 else if (PyUnicode_Check(value)) { |
|
25530
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
924 Py_UNICODE *inbuf = PyUnicode_AS_UNICODE(value); |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
925 int size = PyUnicode_GET_SIZE(value); |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
926 /* This #ifdef assumes that Tcl uses UCS-2. |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
927 See TCL_UTF_MAX test above. */ |
|
28643
ca2482012b3c
Support UCS-4 Tcl for UCS-4 Python builds. Fixes #719880.
Martin v. Löwis <martin@v.loewis.de>
parents:
28622
diff
changeset
|
928 #if defined(Py_UNICODE_WIDE) && TCL_UTF_MAX == 3 |
|
25530
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
929 Tcl_UniChar *outbuf; |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
930 int i; |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
931 outbuf = (Tcl_UniChar*)ckalloc(size * sizeof(Tcl_UniChar)); |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
932 if (!outbuf) { |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
933 PyErr_NoMemory(); |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
934 return NULL; |
|
12580
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
935 } |
|
25530
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
936 for (i = 0; i < size; i++) { |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
937 if (inbuf[i] >= 0x10000) { |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
938 /* Tcl doesn't do UTF-16, yet. */ |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
939 PyErr_SetString(PyExc_ValueError, |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
940 "unsupported character"); |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
941 ckfree(FREECAST outbuf); |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
942 return NULL; |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
943 } |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
944 outbuf[i] = inbuf[i]; |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
945 } |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
946 result = Tcl_NewUnicodeObj(outbuf, size); |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
947 ckfree(FREECAST outbuf); |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
948 return result; |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
949 #else |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
950 return Tcl_NewUnicodeObj(inbuf, size); |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
951 #endif |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
952 |
|
12141
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
953 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19033
diff
changeset
|
954 #endif |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
955 else if(PyTclObject_Check(value)) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
956 Tcl_Obj *v = ((PyTclObject*)value)->value; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
957 Tcl_IncrRefCount(v); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
958 return v; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
959 } |
|
12141
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
960 else { |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
961 PyObject *v = PyObject_Str(value); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
962 if (!v) |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
963 return 0; |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
964 result = AsObj(v); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
965 Py_DECREF(v); |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
966 return result; |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
967 } |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
968 } |
|
4a3fd2c1372f
Don't use the object call interface in Tk 8.0 -- the EvalObj* API
Guido van Rossum <guido@python.org>
parents:
12087
diff
changeset
|
969 |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
970 static PyObject* |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
971 FromObj(PyObject* tkapp, Tcl_Obj *value) |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
972 { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
973 PyObject *result = NULL; |
|
26431
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
974 TkappObject *app = (TkappObject*)tkapp; |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
975 |
|
26534
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
976 if (value->typePtr == NULL) { |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
977 /* If the result contains any bytes with the top bit set, |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
978 it's UTF-8 and we should decode it to Unicode */ |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
979 #ifdef Py_USING_UNICODE |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
980 int i; |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
981 char *s = value->bytes; |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
982 int len = value->length; |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
983 for (i = 0; i < len; i++) { |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
984 if (value->bytes[i] & 0x80) |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
985 break; |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
986 } |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
987 |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
988 if (i == value->length) |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
989 result = PyString_FromStringAndSize(s, len); |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
990 else { |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
991 /* Convert UTF-8 to Unicode string */ |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
992 result = PyUnicode_DecodeUTF8(s, len, "strict"); |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
993 if (result == NULL) { |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
994 PyErr_Clear(); |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
995 result = PyString_FromStringAndSize(s, len); |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
996 } |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
997 } |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
998 #else |
|
34707
0d44d9071e97
Build with --disable-unicode again. Fixes #1158607.
Martin v. Löwis <martin@v.loewis.de>
parents:
33986
diff
changeset
|
999 result = PyString_FromStringAndSize(value->bytes, value->length); |
|
26534
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
1000 #endif |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
1001 return result; |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
1002 } |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1003 |
|
26431
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
1004 if (value->typePtr == app->BooleanType) { |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1005 result = value->internalRep.longValue ? Py_True : Py_False; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1006 Py_INCREF(result); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1007 return result; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1008 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1009 |
|
26431
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
1010 if (value->typePtr == app->ByteArrayType) { |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1011 int size; |
|
26572
d755d4292f3f
Remove C++ comment. Silence unsigned char* cast warning.
Martin v. Löwis <martin@v.loewis.de>
parents:
26534
diff
changeset
|
1012 char *data = (char*)Tcl_GetByteArrayFromObj(value, &size); |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1013 return PyString_FromStringAndSize(data, size); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1014 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1015 |
|
26431
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
1016 if (value->typePtr == app->DoubleType) { |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1017 return PyFloat_FromDouble(value->internalRep.doubleValue); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1018 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1019 |
|
26431
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
1020 if (value->typePtr == app->IntType) { |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1021 return PyInt_FromLong(value->internalRep.longValue); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1022 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1023 |
|
26431
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
1024 if (value->typePtr == app->ListType) { |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1025 int size; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1026 int i, status; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1027 PyObject *elem; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1028 Tcl_Obj *tcl_elem; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1029 |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1030 status = Tcl_ListObjLength(Tkapp_Interp(tkapp), value, &size); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1031 if (status == TCL_ERROR) |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1032 return Tkinter_Error(tkapp); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1033 result = PyTuple_New(size); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1034 if (!result) |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1035 return NULL; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1036 for (i = 0; i < size; i++) { |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1037 status = Tcl_ListObjIndex(Tkapp_Interp(tkapp), |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1038 value, i, &tcl_elem); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1039 if (status == TCL_ERROR) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1040 Py_DECREF(result); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1041 return Tkinter_Error(tkapp); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1042 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1043 elem = FromObj(tkapp, tcl_elem); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1044 if (!elem) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1045 Py_DECREF(result); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1046 return NULL; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1047 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1048 PyTuple_SetItem(result, i, elem); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1049 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1050 return result; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1051 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1052 |
|
26431
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
1053 if (value->typePtr == app->ProcBodyType) { |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1054 /* fall through: return tcl object. */ |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1055 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1056 |
|
26431
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
1057 if (value->typePtr == app->StringType) { |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1058 #ifdef Py_USING_UNICODE |
|
28643
ca2482012b3c
Support UCS-4 Tcl for UCS-4 Python builds. Fixes #719880.
Martin v. Löwis <martin@v.loewis.de>
parents:
28622
diff
changeset
|
1059 #if defined(Py_UNICODE_WIDE) && TCL_UTF_MAX==3 |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1060 PyObject *result; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1061 int size; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1062 Tcl_UniChar *input; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1063 Py_UNICODE *output; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1064 |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1065 size = Tcl_GetCharLength(value); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1066 result = PyUnicode_FromUnicode(NULL, size); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1067 if (!result) |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1068 return NULL; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1069 input = Tcl_GetUnicode(value); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1070 output = PyUnicode_AS_UNICODE(result); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1071 while (size--) |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1072 *output++ = *input++; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1073 return result; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1074 #else |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1075 return PyUnicode_FromUnicode(Tcl_GetUnicode(value), |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1076 Tcl_GetCharLength(value)); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1077 #endif |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1078 #else |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1079 int size; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1080 char *c; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1081 c = Tcl_GetStringFromObj(value, &size); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1082 return PyString_FromStringAndSize(c, size); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1083 #endif |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1084 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1085 |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1086 return newPyTclObject(value); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1087 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1088 |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1089 /* This mutex synchronizes inter-thread command calls. */ |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1090 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1091 TCL_DECLARE_MUTEX(call_mutex) |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1092 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1093 typedef struct Tkapp_CallEvent { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1094 Tcl_Event ev; /* Must be first */ |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1095 TkappObject *self; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1096 PyObject *args; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1097 int flags; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1098 PyObject **res; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1099 PyObject **exc_type, **exc_value, **exc_tb; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1100 Tcl_Condition done; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1101 } Tkapp_CallEvent; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1102 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1103 void |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1104 Tkapp_CallDeallocArgs(Tcl_Obj** objv, Tcl_Obj** objStore, int objc) |
| 1664 | 1105 { |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1106 int i; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1107 for (i = 0; i < objc; i++) |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1108 Tcl_DecrRefCount(objv[i]); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1109 if (objv != objStore) |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1110 ckfree(FREECAST objv); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1111 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1112 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1113 /* Convert Python objects to Tcl objects. This must happen in the |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1114 interpreter thread, which may or may not be the calling thread. */ |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1115 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1116 static Tcl_Obj** |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1117 Tkapp_CallArgs(PyObject *args, Tcl_Obj** objStore, int *pobjc) |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1118 { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1119 Tcl_Obj **objv = objStore; |
|
26620
cb93d9287b4e
Always initialize objc.
Martin v. Löwis <martin@v.loewis.de>
parents:
26613
diff
changeset
|
1120 int objc = 0, i; |
|
8200
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
1121 if (args == NULL) |
|
15356
6e70baa487ed
Do not release unallocated Tcl objects. Closes #117278 and #117167.
Martin v. Löwis <martin@v.loewis.de>
parents:
15177
diff
changeset
|
1122 /* do nothing */; |
|
8200
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
1123 |
|
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
1124 else if (!PyTuple_Check(args)) { |
|
12087
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
1125 objv[0] = AsObj(args); |
|
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
1126 if (objv[0] == 0) |
|
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
1127 goto finally; |
|
15356
6e70baa487ed
Do not release unallocated Tcl objects. Closes #117278 and #117167.
Martin v. Löwis <martin@v.loewis.de>
parents:
15177
diff
changeset
|
1128 objc = 1; |
|
12087
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
1129 Tcl_IncrRefCount(objv[0]); |
|
8200
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
1130 } |
|
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
1131 else { |
|
12087
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
1132 objc = PyTuple_Size(args); |
|
8200
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
1133 |
|
12087
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
1134 if (objc > ARGSZ) { |
|
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
1135 objv = (Tcl_Obj **)ckalloc(objc * sizeof(char *)); |
|
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
1136 if (objv == NULL) { |
|
8200
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
1137 PyErr_NoMemory(); |
|
15356
6e70baa487ed
Do not release unallocated Tcl objects. Closes #117278 and #117167.
Martin v. Löwis <martin@v.loewis.de>
parents:
15177
diff
changeset
|
1138 objc = 0; |
|
8200
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
1139 goto finally; |
|
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
1140 } |
|
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
1141 } |
| 4968 | 1142 |
|
12087
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
1143 for (i = 0; i < objc; i++) { |
|
8200
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
1144 PyObject *v = PyTuple_GetItem(args, i); |
|
12162
98b09c40d97c
Add back an obscure "feature" to the Obj version of Tkapp_Call(): a
Guido van Rossum <guido@python.org>
parents:
12141
diff
changeset
|
1145 if (v == Py_None) { |
|
98b09c40d97c
Add back an obscure "feature" to the Obj version of Tkapp_Call(): a
Guido van Rossum <guido@python.org>
parents:
12141
diff
changeset
|
1146 objc = i; |
|
98b09c40d97c
Add back an obscure "feature" to the Obj version of Tkapp_Call(): a
Guido van Rossum <guido@python.org>
parents:
12141
diff
changeset
|
1147 break; |
|
98b09c40d97c
Add back an obscure "feature" to the Obj version of Tkapp_Call(): a
Guido van Rossum <guido@python.org>
parents:
12141
diff
changeset
|
1148 } |
|
12087
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
1149 objv[i] = AsObj(v); |
|
15356
6e70baa487ed
Do not release unallocated Tcl objects. Closes #117278 and #117167.
Martin v. Löwis <martin@v.loewis.de>
parents:
15177
diff
changeset
|
1150 if (!objv[i]) { |
|
6e70baa487ed
Do not release unallocated Tcl objects. Closes #117278 and #117167.
Martin v. Löwis <martin@v.loewis.de>
parents:
15177
diff
changeset
|
1151 /* Reset objc, so it attempts to clear |
|
6e70baa487ed
Do not release unallocated Tcl objects. Closes #117278 and #117167.
Martin v. Löwis <martin@v.loewis.de>
parents:
15177
diff
changeset
|
1152 objects only up to i. */ |
|
6e70baa487ed
Do not release unallocated Tcl objects. Closes #117278 and #117167.
Martin v. Löwis <martin@v.loewis.de>
parents:
15177
diff
changeset
|
1153 objc = i; |
|
12087
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
1154 goto finally; |
|
15356
6e70baa487ed
Do not release unallocated Tcl objects. Closes #117278 and #117167.
Martin v. Löwis <martin@v.loewis.de>
parents:
15177
diff
changeset
|
1155 } |
|
12087
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
1156 Tcl_IncrRefCount(objv[i]); |
|
8200
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
1157 } |
|
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
1158 } |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1159 *pobjc = objc; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1160 return objv; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1161 finally: |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1162 Tkapp_CallDeallocArgs(objv, objStore, objc); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1163 return NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1164 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1165 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1166 /* Convert the results of a command call into a Python objects. */ |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1167 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1168 static PyObject* |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1169 Tkapp_CallResult(TkappObject *self) |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1170 { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1171 PyObject *res = NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1172 if(self->wantobjects) { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1173 Tcl_Obj *value = Tcl_GetObjResult(self->interp); |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1174 /* Not sure whether the IncrRef is necessary, but something |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1175 may overwrite the interpreter result while we are |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1176 converting it. */ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1177 Tcl_IncrRefCount(value); |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1178 res = FromObj((PyObject*)self, value); |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1179 Tcl_DecrRefCount(value); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1180 } else { |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1181 const char *s = Tcl_GetStringResult(self->interp); |
|
25527
5420969ddd70
Eliminate constness warnings with Tcl 8.4.
Martin v. Löwis <martin@v.loewis.de>
parents:
25525
diff
changeset
|
1182 const char *p = s; |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19033
diff
changeset
|
1183 |
|
12580
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
1184 /* If the result contains any bytes with the top bit set, |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
1185 it's UTF-8 and we should decode it to Unicode */ |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19033
diff
changeset
|
1186 #ifdef Py_USING_UNICODE |
|
12580
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
1187 while (*p != '\0') { |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
1188 if (*p & 0x80) |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
1189 break; |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
1190 p++; |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
1191 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19033
diff
changeset
|
1192 |
|
12580
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
1193 if (*p == '\0') |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
1194 res = PyString_FromStringAndSize(s, (int)(p-s)); |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
1195 else { |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
1196 /* Convert UTF-8 to Unicode string */ |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
1197 p = strchr(p, '\0'); |
|
12583
db9458c2b631
When the UTF-8 conversion to Unicode fails, return an 8-bit string
Guido van Rossum <guido@python.org>
parents:
12580
diff
changeset
|
1198 res = PyUnicode_DecodeUTF8(s, (int)(p-s), "strict"); |
|
db9458c2b631
When the UTF-8 conversion to Unicode fails, return an 8-bit string
Guido van Rossum <guido@python.org>
parents:
12580
diff
changeset
|
1199 if (res == NULL) { |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1200 PyErr_Clear(); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1201 res = PyString_FromStringAndSize(s, (int)(p-s)); |
|
12583
db9458c2b631
When the UTF-8 conversion to Unicode fails, return an 8-bit string
Guido van Rossum <guido@python.org>
parents:
12580
diff
changeset
|
1202 } |
|
12580
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
1203 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19033
diff
changeset
|
1204 #else |
|
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19033
diff
changeset
|
1205 p = strchr(p, '\0'); |
|
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19033
diff
changeset
|
1206 res = PyString_FromStringAndSize(s, (int)(p-s)); |
|
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19033
diff
changeset
|
1207 #endif |
|
12580
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
1208 } |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1209 return res; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1210 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1211 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1212 /* Tkapp_CallProc is the event procedure that is executed in the context of |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1213 the Tcl interpreter thread. Initially, it holds the Tcl lock, and doesn't |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1214 hold the Python lock. */ |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1215 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1216 static int |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1217 Tkapp_CallProc(Tkapp_CallEvent *e, int flags) |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1218 { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1219 Tcl_Obj *objStore[ARGSZ]; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1220 Tcl_Obj **objv; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1221 int objc; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1222 int i; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1223 ENTER_PYTHON |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1224 objv = Tkapp_CallArgs(e->args, objStore, &objc); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1225 if (!objv) { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1226 PyErr_Fetch(e->exc_type, e->exc_value, e->exc_tb); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1227 *(e->res) = NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1228 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1229 LEAVE_PYTHON |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1230 if (!objv) |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1231 goto done; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1232 i = Tcl_EvalObjv(e->self->interp, objc, objv, e->flags); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1233 ENTER_PYTHON |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1234 if (i == TCL_ERROR) { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1235 *(e->res) = NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1236 *(e->exc_type) = NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1237 *(e->exc_tb) = NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1238 *(e->exc_value) = PyObject_CallFunction( |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1239 Tkinter_TclError, "s", |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1240 Tcl_GetStringResult(e->self->interp)); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1241 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1242 else { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1243 *(e->res) = Tkapp_CallResult(e->self); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1244 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1245 LEAVE_PYTHON |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1246 done: |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1247 /* Wake up calling thread. */ |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1248 Tcl_MutexLock(&call_mutex); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1249 Tcl_ConditionNotify(&e->done); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1250 Tcl_MutexUnlock(&call_mutex); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1251 return 1; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1252 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1253 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1254 /* This is the main entry point for calling a Tcl command. |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1255 It supports three cases, with regard to threading: |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1256 1. Tcl is not threaded: Must have the Tcl lock, then can invoke command in |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1257 the context of the calling thread. |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1258 2. Tcl is threaded, caller of the command is in the interpreter thread: |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1259 Execute the command in the calling thread. Since the Tcl lock will |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1260 not be used, we can merge that with case 1. |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1261 3. Tcl is threaded, caller is in a different thread: Must queue an event to |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1262 the interpreter thread. Allocation of Tcl objects needs to occur in the |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1263 interpreter thread, so we ship the PyObject* args to the target thread, |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1264 and perform processing there. */ |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1265 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1266 static PyObject * |
|
38559
129ab846a71f
[Bug #1497414] _self is a reserved word in the WATCOM 10.6 C compiler.
Andrew M. Kuchling <amk@amk.ca>
parents:
38067
diff
changeset
|
1267 Tkapp_Call(PyObject *selfptr, PyObject *args) |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1268 { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1269 Tcl_Obj *objStore[ARGSZ]; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1270 Tcl_Obj **objv = NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1271 int objc, i; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1272 PyObject *res = NULL; |
|
38559
129ab846a71f
[Bug #1497414] _self is a reserved word in the WATCOM 10.6 C compiler.
Andrew M. Kuchling <amk@amk.ca>
parents:
38067
diff
changeset
|
1273 TkappObject *self = (TkappObject*)selfptr; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1274 /* Could add TCL_EVAL_GLOBAL if wrapped by GlobalCall... */ |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1275 int flags = TCL_EVAL_DIRECT; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1276 |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
1277 #ifdef WITH_THREAD |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1278 if (self->threaded && self->thread_id != Tcl_GetCurrentThread()) { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1279 /* We cannot call the command directly. Instead, we must |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1280 marshal the parameters to the interpreter thread. */ |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1281 Tkapp_CallEvent *ev; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1282 PyObject *exc_type, *exc_value, *exc_tb; |
|
26814
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
1283 if (!WaitForMainloop(self)) |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1284 return NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1285 ev = (Tkapp_CallEvent*)ckalloc(sizeof(Tkapp_CallEvent)); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1286 ev->ev.proc = (Tcl_EventProc*)Tkapp_CallProc; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1287 ev->self = self; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1288 ev->args = args; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1289 ev->res = &res; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1290 ev->exc_type = &exc_type; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1291 ev->exc_value = &exc_value; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1292 ev->exc_tb = &exc_tb; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1293 ev->done = (Tcl_Condition)0; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1294 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1295 Tkapp_ThreadSend(self, (Tcl_Event*)ev, &ev->done, &call_mutex); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1296 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1297 if (res == NULL) { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1298 if (exc_type) |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1299 PyErr_Restore(exc_type, exc_value, exc_tb); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1300 else |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1301 PyErr_SetObject(Tkinter_TclError, exc_value); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1302 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1303 } |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
1304 else |
|
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
1305 #endif |
|
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
1306 { |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1307 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1308 objv = Tkapp_CallArgs(args, objStore, &objc); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1309 if (!objv) |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1310 return NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1311 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1312 ENTER_TCL |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1313 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1314 i = Tcl_EvalObjv(self->interp, objc, objv, flags); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1315 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1316 ENTER_OVERLAP |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1317 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1318 if (i == TCL_ERROR) |
|
38559
129ab846a71f
[Bug #1497414] _self is a reserved word in the WATCOM 10.6 C compiler.
Andrew M. Kuchling <amk@amk.ca>
parents:
38067
diff
changeset
|
1319 Tkinter_Error(selfptr); |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1320 else |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1321 res = Tkapp_CallResult(self); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1322 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1323 LEAVE_OVERLAP_TCL |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1324 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1325 Tkapp_CallDeallocArgs(objv, objStore, objc); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1326 } |
| 4968 | 1327 return res; |
| 1328 } | |
| 1664 | 1329 |
| 4968 | 1330 |
| 1331 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1332 Tkapp_GlobalCall(PyObject *self, PyObject *args) |
| 4968 | 1333 { |
|
8200
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
1334 /* Could do the same here as for Tkapp_Call(), but this is not used |
|
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
1335 much, so I can't be bothered. Unfortunately Tcl doesn't export a |
|
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
1336 way for the user to do what all its Global* variants do (save and |
|
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
1337 reset the scope pointer, call the local version, restore the saved |
|
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
1338 scope pointer). */ |
|
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
1339 |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1340 char *cmd; |
| 4968 | 1341 PyObject *res = NULL; |
| 1664 | 1342 |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1343 CHECK_TCL_APPARTMENT; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1344 |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1345 cmd = Merge(args); |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1346 if (cmd) { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1347 int err; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1348 ENTER_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1349 err = Tcl_GlobalEval(Tkapp_Interp(self), cmd); |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1350 ENTER_OVERLAP |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1351 if (err == TCL_ERROR) |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1352 res = Tkinter_Error(self); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1353 else |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1354 res = PyString_FromString(Tkapp_Result(self)); |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1355 LEAVE_OVERLAP_TCL |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1356 ckfree(cmd); |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1357 } |
| 4968 | 1358 |
| 1359 return res; | |
| 1664 | 1360 } |
| 1361 | |
| 1362 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1363 Tkapp_Eval(PyObject *self, PyObject *args) |
| 1664 | 1364 { |
| 4968 | 1365 char *script; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1366 PyObject *res = NULL; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1367 int err; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1368 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1369 if (!PyArg_ParseTuple(args, "s:eval", &script)) |
| 4968 | 1370 return NULL; |
| 1664 | 1371 |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1372 CHECK_TCL_APPARTMENT; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1373 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1374 ENTER_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1375 err = Tcl_Eval(Tkapp_Interp(self), script); |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1376 ENTER_OVERLAP |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1377 if (err == TCL_ERROR) |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1378 res = Tkinter_Error(self); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1379 else |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1380 res = PyString_FromString(Tkapp_Result(self)); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1381 LEAVE_OVERLAP_TCL |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1382 return res; |
| 1664 | 1383 } |
| 1384 | |
| 1385 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1386 Tkapp_GlobalEval(PyObject *self, PyObject *args) |
| 1664 | 1387 { |
| 4968 | 1388 char *script; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1389 PyObject *res = NULL; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1390 int err; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1391 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1392 if (!PyArg_ParseTuple(args, "s:globaleval", &script)) |
| 4968 | 1393 return NULL; |
| 1664 | 1394 |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1395 CHECK_TCL_APPARTMENT; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1396 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1397 ENTER_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1398 err = Tcl_GlobalEval(Tkapp_Interp(self), script); |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1399 ENTER_OVERLAP |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1400 if (err == TCL_ERROR) |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1401 res = Tkinter_Error(self); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1402 else |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1403 res = PyString_FromString(Tkapp_Result(self)); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1404 LEAVE_OVERLAP_TCL |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1405 return res; |
| 1664 | 1406 } |
| 1407 | |
| 1408 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1409 Tkapp_EvalFile(PyObject *self, PyObject *args) |
| 1664 | 1410 { |
| 4968 | 1411 char *fileName; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1412 PyObject *res = NULL; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1413 int err; |
| 1664 | 1414 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1415 if (!PyArg_ParseTuple(args, "s:evalfile", &fileName)) |
| 4968 | 1416 return NULL; |
| 1664 | 1417 |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1418 CHECK_TCL_APPARTMENT; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1419 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1420 ENTER_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1421 err = Tcl_EvalFile(Tkapp_Interp(self), fileName); |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1422 ENTER_OVERLAP |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1423 if (err == TCL_ERROR) |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1424 res = Tkinter_Error(self); |
| 1664 | 1425 |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1426 else |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1427 res = PyString_FromString(Tkapp_Result(self)); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1428 LEAVE_OVERLAP_TCL |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1429 return res; |
| 1664 | 1430 } |
| 1431 | |
| 1432 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1433 Tkapp_Record(PyObject *self, PyObject *args) |
| 1664 | 1434 { |
| 4968 | 1435 char *script; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1436 PyObject *res = NULL; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1437 int err; |
| 1664 | 1438 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1439 if (!PyArg_ParseTuple(args, "s", &script)) |
| 4968 | 1440 return NULL; |
| 1664 | 1441 |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1442 CHECK_TCL_APPARTMENT; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1443 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1444 ENTER_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1445 err = Tcl_RecordAndEval(Tkapp_Interp(self), script, TCL_NO_EVAL); |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1446 ENTER_OVERLAP |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1447 if (err == TCL_ERROR) |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1448 res = Tkinter_Error(self); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1449 else |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1450 res = PyString_FromString(Tkapp_Result(self)); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1451 LEAVE_OVERLAP_TCL |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1452 return res; |
| 1664 | 1453 } |
| 1454 | |
| 1455 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1456 Tkapp_AddErrorInfo(PyObject *self, PyObject *args) |
| 1664 | 1457 { |
| 4968 | 1458 char *msg; |
| 1664 | 1459 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1460 if (!PyArg_ParseTuple(args, "s:adderrorinfo", &msg)) |
| 4968 | 1461 return NULL; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1462 CHECK_TCL_APPARTMENT; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1463 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1464 ENTER_TCL |
| 4968 | 1465 Tcl_AddErrorInfo(Tkapp_Interp(self), msg); |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1466 LEAVE_TCL |
| 1664 | 1467 |
| 4968 | 1468 Py_INCREF(Py_None); |
| 1469 return Py_None; | |
| 1664 | 1470 } |
| 1471 | |
| 4968 | 1472 |
| 1473 | |
| 1664 | 1474 /** Tcl Variable **/ |
| 1475 | |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1476 TCL_DECLARE_MUTEX(var_mutex) |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1477 |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1478 typedef PyObject* (*EventFunc)(PyObject*, PyObject *args, int flags); |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1479 typedef struct VarEvent { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1480 Tcl_Event ev; /* must be first */ |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1481 PyObject *self; |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1482 PyObject *args; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1483 int flags; |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1484 EventFunc func; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1485 PyObject **res; |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1486 PyObject **exc_type; |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1487 PyObject **exc_val; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1488 Tcl_Condition cond; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1489 } VarEvent; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1490 |
|
28915
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
1491 static int |
|
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
1492 varname_converter(PyObject *in, void *_out) |
|
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
1493 { |
|
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
1494 char **out = (char**)_out; |
|
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
1495 if (PyString_Check(in)) { |
|
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
1496 *out = PyString_AsString(in); |
|
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
1497 return 1; |
|
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
1498 } |
|
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
1499 if (PyTclObject_Check(in)) { |
|
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
1500 *out = PyTclObject_TclString(in); |
|
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
1501 return 1; |
|
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
1502 } |
|
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
1503 /* XXX: Should give diagnostics. */ |
|
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
1504 return 0; |
|
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
1505 } |
|
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
1506 |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1507 void |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1508 var_perform(VarEvent *ev) |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1509 { |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1510 *(ev->res) = ev->func(ev->self, ev->args, ev->flags); |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1511 if (!*(ev->res)) { |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1512 PyObject *exc, *val, *tb; |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1513 PyErr_Fetch(&exc, &val, &tb); |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1514 PyErr_NormalizeException(&exc, &val, &tb); |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1515 *(ev->exc_type) = exc; |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1516 *(ev->exc_val) = val; |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1517 Py_DECREF(tb); |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1518 } |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1519 |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1520 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1521 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1522 static int |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1523 var_proc(VarEvent* ev, int flags) |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1524 { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1525 ENTER_PYTHON |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1526 var_perform(ev); |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1527 Tcl_MutexLock(&var_mutex); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1528 Tcl_ConditionNotify(&ev->cond); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1529 Tcl_MutexUnlock(&var_mutex); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1530 LEAVE_PYTHON |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1531 return 1; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1532 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1533 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1534 static PyObject* |
|
38559
129ab846a71f
[Bug #1497414] _self is a reserved word in the WATCOM 10.6 C compiler.
Andrew M. Kuchling <amk@amk.ca>
parents:
38067
diff
changeset
|
1535 var_invoke(EventFunc func, PyObject *selfptr, PyObject *args, int flags) |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1536 { |
|
38559
129ab846a71f
[Bug #1497414] _self is a reserved word in the WATCOM 10.6 C compiler.
Andrew M. Kuchling <amk@amk.ca>
parents:
38067
diff
changeset
|
1537 TkappObject *self = (TkappObject*)selfptr; |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
1538 #ifdef WITH_THREAD |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1539 if (self->threaded && self->thread_id != Tcl_GetCurrentThread()) { |
|
38559
129ab846a71f
[Bug #1497414] _self is a reserved word in the WATCOM 10.6 C compiler.
Andrew M. Kuchling <amk@amk.ca>
parents:
38067
diff
changeset
|
1540 TkappObject *self = (TkappObject*)selfptr; |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1541 VarEvent *ev; |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1542 PyObject *res, *exc_type, *exc_val; |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1543 |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1544 /* The current thread is not the interpreter thread. Marshal |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1545 the call to the interpreter thread, then wait for |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1546 completion. */ |
|
26814
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
1547 if (!WaitForMainloop(self)) |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1548 return NULL; |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1549 |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1550 ev = (VarEvent*)ckalloc(sizeof(VarEvent)); |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1551 |
|
38559
129ab846a71f
[Bug #1497414] _self is a reserved word in the WATCOM 10.6 C compiler.
Andrew M. Kuchling <amk@amk.ca>
parents:
38067
diff
changeset
|
1552 ev->self = selfptr; |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1553 ev->args = args; |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1554 ev->flags = flags; |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1555 ev->func = func; |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1556 ev->res = &res; |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1557 ev->exc_type = &exc_type; |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1558 ev->exc_val = &exc_val; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1559 ev->cond = NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1560 ev->ev.proc = (Tcl_EventProc*)var_proc; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1561 Tkapp_ThreadSend(self, (Tcl_Event*)ev, &ev->cond, &var_mutex); |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1562 if (!res) { |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1563 PyErr_SetObject(exc_type, exc_val); |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1564 Py_DECREF(exc_type); |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1565 Py_DECREF(exc_val); |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1566 return NULL; |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1567 } |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1568 return res; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1569 } |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1570 #endif |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1571 /* Tcl is not threaded, or this is the interpreter thread. */ |
|
38559
129ab846a71f
[Bug #1497414] _self is a reserved word in the WATCOM 10.6 C compiler.
Andrew M. Kuchling <amk@amk.ca>
parents:
38067
diff
changeset
|
1572 return func(selfptr, args, flags); |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1573 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1574 |
| 1664 | 1575 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1576 SetVar(PyObject *self, PyObject *args, int flags) |
| 1664 | 1577 { |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1578 char *name1, *name2; |
| 4968 | 1579 PyObject *newValue; |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1580 PyObject *res = NULL; |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1581 Tcl_Obj *newval, *ok; |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1582 |
|
28915
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
1583 if (PyArg_ParseTuple(args, "O&O:setvar", |
|
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
1584 varname_converter, &name1, &newValue)) { |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1585 /* XXX Acquire tcl lock??? */ |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1586 newval = AsObj(newValue); |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1587 if (newval == NULL) |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1588 return NULL; |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1589 ENTER_TCL |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1590 ok = Tcl_SetVar2Ex(Tkapp_Interp(self), name1, NULL, |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1591 newval, flags); |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1592 ENTER_OVERLAP |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1593 if (!ok) |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1594 Tkinter_Error(self); |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1595 else { |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1596 res = Py_None; |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1597 Py_INCREF(res); |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1598 } |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1599 LEAVE_OVERLAP_TCL |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1600 } |
| 4968 | 1601 else { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1602 PyErr_Clear(); |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1603 if (PyArg_ParseTuple(args, "ssO:setvar", |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1604 &name1, &name2, &newValue)) { |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1605 /* XXX must hold tcl lock already??? */ |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1606 newval = AsObj(newValue); |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1607 ENTER_TCL |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1608 ok = Tcl_SetVar2Ex(Tkapp_Interp(self), name1, name2, newval, flags); |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1609 ENTER_OVERLAP |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1610 if (!ok) |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1611 Tkinter_Error(self); |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1612 else { |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1613 res = Py_None; |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1614 Py_INCREF(res); |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1615 } |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1616 LEAVE_OVERLAP_TCL |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1617 } |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1618 else { |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1619 return NULL; |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1620 } |
| 4968 | 1621 } |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1622 return res; |
| 1664 | 1623 } |
| 1624 | |
| 1625 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1626 Tkapp_SetVar(PyObject *self, PyObject *args) |
| 1664 | 1627 { |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1628 return var_invoke(SetVar, self, args, TCL_LEAVE_ERR_MSG); |
| 1664 | 1629 } |
| 1630 | |
| 1631 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1632 Tkapp_GlobalSetVar(PyObject *self, PyObject *args) |
| 1664 | 1633 { |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1634 return var_invoke(SetVar, self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY); |
| 1664 | 1635 } |
| 1636 | |
| 4968 | 1637 |
| 1638 | |
| 1664 | 1639 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1640 GetVar(PyObject *self, PyObject *args, int flags) |
| 1664 | 1641 { |
|
25527
5420969ddd70
Eliminate constness warnings with Tcl 8.4.
Martin v. Löwis <martin@v.loewis.de>
parents:
25525
diff
changeset
|
1642 char *name1, *name2=NULL; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1643 PyObject *res = NULL; |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1644 Tcl_Obj *tres; |
| 4968 | 1645 |
|
28915
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
1646 if (!PyArg_ParseTuple(args, "O&|s:getvar", |
|
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
1647 varname_converter, &name1, &name2)) |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1648 return NULL; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1649 |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1650 ENTER_TCL |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1651 tres = Tcl_GetVar2Ex(Tkapp_Interp(self), name1, name2, flags); |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1652 ENTER_OVERLAP |
|
30638
39e635da2326
Check for TclError when reading variables. Fixes #807314.
Martin v. Löwis <martin@v.loewis.de>
parents:
29472
diff
changeset
|
1653 if (tres == NULL) { |
|
39e635da2326
Check for TclError when reading variables. Fixes #807314.
Martin v. Löwis <martin@v.loewis.de>
parents:
29472
diff
changeset
|
1654 PyErr_SetString(Tkinter_TclError, Tcl_GetStringResult(Tkapp_Interp(self))); |
|
39e635da2326
Check for TclError when reading variables. Fixes #807314.
Martin v. Löwis <martin@v.loewis.de>
parents:
29472
diff
changeset
|
1655 } else { |
|
39e635da2326
Check for TclError when reading variables. Fixes #807314.
Martin v. Löwis <martin@v.loewis.de>
parents:
29472
diff
changeset
|
1656 if (((TkappObject*)self)->wantobjects) { |
|
39e635da2326
Check for TclError when reading variables. Fixes #807314.
Martin v. Löwis <martin@v.loewis.de>
parents:
29472
diff
changeset
|
1657 res = FromObj(self, tres); |
|
39e635da2326
Check for TclError when reading variables. Fixes #807314.
Martin v. Löwis <martin@v.loewis.de>
parents:
29472
diff
changeset
|
1658 } |
|
39e635da2326
Check for TclError when reading variables. Fixes #807314.
Martin v. Löwis <martin@v.loewis.de>
parents:
29472
diff
changeset
|
1659 else { |
|
39e635da2326
Check for TclError when reading variables. Fixes #807314.
Martin v. Löwis <martin@v.loewis.de>
parents:
29472
diff
changeset
|
1660 res = PyString_FromString(Tcl_GetString(tres)); |
|
39e635da2326
Check for TclError when reading variables. Fixes #807314.
Martin v. Löwis <martin@v.loewis.de>
parents:
29472
diff
changeset
|
1661 } |
|
29170
f0b67731e545
Only return objects if wantobjects is set in GetVar.
Martin v. Löwis <martin@v.loewis.de>
parents:
29038
diff
changeset
|
1662 } |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1663 LEAVE_OVERLAP_TCL |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1664 return res; |
| 1664 | 1665 } |
| 1666 | |
| 1667 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1668 Tkapp_GetVar(PyObject *self, PyObject *args) |
| 1664 | 1669 { |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1670 return var_invoke(GetVar, self, args, TCL_LEAVE_ERR_MSG); |
| 1664 | 1671 } |
| 1672 | |
| 1673 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1674 Tkapp_GlobalGetVar(PyObject *self, PyObject *args) |
| 1664 | 1675 { |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1676 return var_invoke(GetVar, self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY); |
| 1664 | 1677 } |
| 1678 | |
| 4968 | 1679 |
| 1680 | |
| 1664 | 1681 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1682 UnsetVar(PyObject *self, PyObject *args, int flags) |
| 1664 | 1683 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1684 char *name1, *name2=NULL; |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1685 int code; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1686 PyObject *res = NULL; |
| 4968 | 1687 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1688 if (!PyArg_ParseTuple(args, "s|s:unsetvar", &name1, &name2)) |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1689 return NULL; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1690 |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1691 ENTER_TCL |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1692 code = Tcl_UnsetVar2(Tkapp_Interp(self), name1, name2, flags); |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1693 ENTER_OVERLAP |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1694 if (code == TCL_ERROR) |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1695 res = Tkinter_Error(self); |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1696 else { |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1697 Py_INCREF(Py_None); |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1698 res = Py_None; |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1699 } |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1700 LEAVE_OVERLAP_TCL |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1701 return res; |
| 1664 | 1702 } |
| 1703 | |
| 1704 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1705 Tkapp_UnsetVar(PyObject *self, PyObject *args) |
| 1664 | 1706 { |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1707 return var_invoke(UnsetVar, self, args, TCL_LEAVE_ERR_MSG); |
| 1664 | 1708 } |
| 1709 | |
| 1710 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1711 Tkapp_GlobalUnsetVar(PyObject *self, PyObject *args) |
| 1664 | 1712 { |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1713 return var_invoke(UnsetVar, self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY); |
| 1664 | 1714 } |
| 1715 | |
| 4968 | 1716 |
| 1717 | |
| 1664 | 1718 /** Tcl to Python **/ |
| 1719 | |
| 1720 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1721 Tkapp_GetInt(PyObject *self, PyObject *args) |
| 1664 | 1722 { |
| 4968 | 1723 char *s; |
| 1724 int v; | |
| 1664 | 1725 |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1726 if (PyTuple_Size(args) == 1) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1727 PyObject* o = PyTuple_GetItem(args, 0); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1728 if (PyInt_Check(o)) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1729 Py_INCREF(o); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1730 return o; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1731 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1732 } |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1733 if (!PyArg_ParseTuple(args, "s:getint", &s)) |
| 4968 | 1734 return NULL; |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1735 if (Tcl_GetInt(Tkapp_Interp(self), s, &v) == TCL_ERROR) |
| 4968 | 1736 return Tkinter_Error(self); |
| 1737 return Py_BuildValue("i", v); | |
| 1664 | 1738 } |
| 1739 | |
| 1740 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1741 Tkapp_GetDouble(PyObject *self, PyObject *args) |
| 1664 | 1742 { |
| 4968 | 1743 char *s; |
| 1744 double v; | |
| 1664 | 1745 |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1746 if (PyTuple_Size(args) == 1) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1747 PyObject *o = PyTuple_GetItem(args, 0); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1748 if (PyFloat_Check(o)) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1749 Py_INCREF(o); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1750 return o; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1751 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1752 } |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1753 if (!PyArg_ParseTuple(args, "s:getdouble", &s)) |
| 4968 | 1754 return NULL; |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1755 if (Tcl_GetDouble(Tkapp_Interp(self), s, &v) == TCL_ERROR) |
| 4968 | 1756 return Tkinter_Error(self); |
| 1757 return Py_BuildValue("d", v); | |
| 1664 | 1758 } |
| 1759 | |
| 1760 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1761 Tkapp_GetBoolean(PyObject *self, PyObject *args) |
| 1664 | 1762 { |
| 4968 | 1763 char *s; |
| 1764 int v; | |
| 1664 | 1765 |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1766 if (PyTuple_Size(args) == 1) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1767 PyObject *o = PyTuple_GetItem(args, 0); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1768 if (PyInt_Check(o)) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1769 Py_INCREF(o); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1770 return o; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1771 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1772 } |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1773 if (!PyArg_ParseTuple(args, "s:getboolean", &s)) |
| 4968 | 1774 return NULL; |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1775 if (Tcl_GetBoolean(Tkapp_Interp(self), s, &v) == TCL_ERROR) |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1776 return Tkinter_Error(self); |
|
27341
ba63d717c75f
Convert booleans to integers in IntVar.set. Fixes #671741.
Martin v. Löwis <martin@v.loewis.de>
parents:
27333
diff
changeset
|
1777 return PyBool_FromLong(v); |
| 1664 | 1778 } |
| 1779 | |
| 1780 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1781 Tkapp_ExprString(PyObject *self, PyObject *args) |
| 1664 | 1782 { |
| 4968 | 1783 char *s; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1784 PyObject *res = NULL; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1785 int retval; |
| 1664 | 1786 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1787 if (!PyArg_ParseTuple(args, "s:exprstring", &s)) |
| 4968 | 1788 return NULL; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1789 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1790 CHECK_TCL_APPARTMENT; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1791 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1792 ENTER_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1793 retval = Tcl_ExprString(Tkapp_Interp(self), s); |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1794 ENTER_OVERLAP |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1795 if (retval == TCL_ERROR) |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1796 res = Tkinter_Error(self); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1797 else |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1798 res = Py_BuildValue("s", Tkapp_Result(self)); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1799 LEAVE_OVERLAP_TCL |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1800 return res; |
| 1664 | 1801 } |
| 1802 | |
| 1803 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1804 Tkapp_ExprLong(PyObject *self, PyObject *args) |
| 1664 | 1805 { |
| 4968 | 1806 char *s; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1807 PyObject *res = NULL; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1808 int retval; |
| 4968 | 1809 long v; |
| 1664 | 1810 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1811 if (!PyArg_ParseTuple(args, "s:exprlong", &s)) |
| 4968 | 1812 return NULL; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1813 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1814 CHECK_TCL_APPARTMENT; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1815 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1816 ENTER_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1817 retval = Tcl_ExprLong(Tkapp_Interp(self), s, &v); |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1818 ENTER_OVERLAP |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1819 if (retval == TCL_ERROR) |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1820 res = Tkinter_Error(self); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1821 else |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1822 res = Py_BuildValue("l", v); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1823 LEAVE_OVERLAP_TCL |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1824 return res; |
| 1664 | 1825 } |
| 1826 | |
| 1827 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1828 Tkapp_ExprDouble(PyObject *self, PyObject *args) |
| 1664 | 1829 { |
| 4968 | 1830 char *s; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1831 PyObject *res = NULL; |
| 4968 | 1832 double v; |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
4968
diff
changeset
|
1833 int retval; |
| 1664 | 1834 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1835 if (!PyArg_ParseTuple(args, "s:exprdouble", &s)) |
| 4968 | 1836 return NULL; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1837 CHECK_TCL_APPARTMENT; |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
4968
diff
changeset
|
1838 PyFPE_START_PROTECT("Tkapp_ExprDouble", return 0) |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1839 ENTER_TCL |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1840 retval = Tcl_ExprDouble(Tkapp_Interp(self), s, &v); |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1841 ENTER_OVERLAP |
|
5197
74c12704a0bd
New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents:
5120
diff
changeset
|
1842 PyFPE_END_PROTECT(retval) |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
4968
diff
changeset
|
1843 if (retval == TCL_ERROR) |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1844 res = Tkinter_Error(self); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1845 else |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1846 res = Py_BuildValue("d", v); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1847 LEAVE_OVERLAP_TCL |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1848 return res; |
| 1664 | 1849 } |
| 1850 | |
| 1851 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1852 Tkapp_ExprBoolean(PyObject *self, PyObject *args) |
| 1664 | 1853 { |
| 4968 | 1854 char *s; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1855 PyObject *res = NULL; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1856 int retval; |
| 4968 | 1857 int v; |
| 1664 | 1858 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1859 if (!PyArg_ParseTuple(args, "s:exprboolean", &s)) |
| 4968 | 1860 return NULL; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1861 CHECK_TCL_APPARTMENT; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1862 ENTER_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1863 retval = Tcl_ExprBoolean(Tkapp_Interp(self), s, &v); |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1864 ENTER_OVERLAP |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1865 if (retval == TCL_ERROR) |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1866 res = Tkinter_Error(self); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1867 else |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1868 res = Py_BuildValue("i", v); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1869 LEAVE_OVERLAP_TCL |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1870 return res; |
| 1664 | 1871 } |
| 1872 | |
| 4968 | 1873 |
| 1874 | |
| 1664 | 1875 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1876 Tkapp_SplitList(PyObject *self, PyObject *args) |
| 1664 | 1877 { |
| 4968 | 1878 char *list; |
| 1879 int argc; | |
| 1880 char **argv; | |
| 1881 PyObject *v; | |
| 1882 int i; | |
| 1883 | |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1884 if (PyTuple_Size(args) == 1) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1885 v = PyTuple_GetItem(args, 0); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1886 if (PyTuple_Check(v)) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1887 Py_INCREF(v); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1888 return v; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1889 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1890 } |
|
21813
f3b0e3cb340b
Encode Unicode arguments to split/splitlist as UTF-8. Fixes #507962.
Martin v. Löwis <martin@v.loewis.de>
parents:
21757
diff
changeset
|
1891 if (!PyArg_ParseTuple(args, "et:splitlist", "utf-8", &list)) |
| 4968 | 1892 return NULL; |
| 1893 | |
|
29295
d46459d82a79
Fix SF #745055, Memory leak in _tkinter.c/Tkapp_SplitList()
Neal Norwitz <nnorwitz@gmail.com>
parents:
29170
diff
changeset
|
1894 if (Tcl_SplitList(Tkapp_Interp(self), list, |
|
d46459d82a79
Fix SF #745055, Memory leak in _tkinter.c/Tkapp_SplitList()
Neal Norwitz <nnorwitz@gmail.com>
parents:
29170
diff
changeset
|
1895 &argc, &argv) == TCL_ERROR) { |
|
d46459d82a79
Fix SF #745055, Memory leak in _tkinter.c/Tkapp_SplitList()
Neal Norwitz <nnorwitz@gmail.com>
parents:
29170
diff
changeset
|
1896 PyMem_Free(list); |
| 4968 | 1897 return Tkinter_Error(self); |
|
29295
d46459d82a79
Fix SF #745055, Memory leak in _tkinter.c/Tkapp_SplitList()
Neal Norwitz <nnorwitz@gmail.com>
parents:
29170
diff
changeset
|
1898 } |
| 1664 | 1899 |
| 4968 | 1900 if (!(v = PyTuple_New(argc))) |
|
29295
d46459d82a79
Fix SF #745055, Memory leak in _tkinter.c/Tkapp_SplitList()
Neal Norwitz <nnorwitz@gmail.com>
parents:
29170
diff
changeset
|
1901 goto finally; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1902 |
| 4968 | 1903 for (i = 0; i < argc; i++) { |
| 1904 PyObject *s = PyString_FromString(argv[i]); | |
| 1905 if (!s || PyTuple_SetItem(v, i, s)) { | |
| 1906 Py_DECREF(v); | |
| 1907 v = NULL; | |
| 1908 goto finally; | |
| 1909 } | |
| 1910 } | |
| 1664 | 1911 |
| 4968 | 1912 finally: |
| 1913 ckfree(FREECAST argv); | |
|
29295
d46459d82a79
Fix SF #745055, Memory leak in _tkinter.c/Tkapp_SplitList()
Neal Norwitz <nnorwitz@gmail.com>
parents:
29170
diff
changeset
|
1914 PyMem_Free(list); |
| 4968 | 1915 return v; |
| 1664 | 1916 } |
| 1917 | |
| 1918 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1919 Tkapp_Split(PyObject *self, PyObject *args) |
| 1664 | 1920 { |
|
29295
d46459d82a79
Fix SF #745055, Memory leak in _tkinter.c/Tkapp_SplitList()
Neal Norwitz <nnorwitz@gmail.com>
parents:
29170
diff
changeset
|
1921 PyObject *v; |
| 4968 | 1922 char *list; |
| 1664 | 1923 |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1924 if (PyTuple_Size(args) == 1) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1925 PyObject* o = PyTuple_GetItem(args, 0); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1926 if (PyTuple_Check(o)) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1927 o = SplitObj(o); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1928 return o; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1929 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1930 } |
|
21813
f3b0e3cb340b
Encode Unicode arguments to split/splitlist as UTF-8. Fixes #507962.
Martin v. Löwis <martin@v.loewis.de>
parents:
21757
diff
changeset
|
1931 if (!PyArg_ParseTuple(args, "et:split", "utf-8", &list)) |
| 4968 | 1932 return NULL; |
|
29295
d46459d82a79
Fix SF #745055, Memory leak in _tkinter.c/Tkapp_SplitList()
Neal Norwitz <nnorwitz@gmail.com>
parents:
29170
diff
changeset
|
1933 v = Split(list); |
|
d46459d82a79
Fix SF #745055, Memory leak in _tkinter.c/Tkapp_SplitList()
Neal Norwitz <nnorwitz@gmail.com>
parents:
29170
diff
changeset
|
1934 PyMem_Free(list); |
|
d46459d82a79
Fix SF #745055, Memory leak in _tkinter.c/Tkapp_SplitList()
Neal Norwitz <nnorwitz@gmail.com>
parents:
29170
diff
changeset
|
1935 return v; |
| 1664 | 1936 } |
| 1937 | |
| 1938 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1939 Tkapp_Merge(PyObject *self, PyObject *args) |
| 1664 | 1940 { |
| 4968 | 1941 char *s = Merge(args); |
| 1942 PyObject *res = NULL; | |
| 1664 | 1943 |
| 4968 | 1944 if (s) { |
| 1945 res = PyString_FromString(s); | |
| 1946 ckfree(s); | |
| 1947 } | |
| 1948 | |
| 1949 return res; | |
| 1664 | 1950 } |
| 1951 | |
| 4968 | 1952 |
| 1953 | |
| 1664 | 1954 /** Tcl Command **/ |
| 1955 | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1956 /* Client data struct */ |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1957 typedef struct { |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1958 PyObject *self; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1959 PyObject *func; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1960 } PythonCmd_ClientData; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1961 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1962 static int |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1963 PythonCmd_Error(Tcl_Interp *interp) |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1964 { |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1965 errorInCmd = 1; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1966 PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1967 LEAVE_PYTHON |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1968 return TCL_ERROR; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1969 } |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1970 |
| 1664 | 1971 /* This is the Tcl command that acts as a wrapper for Python |
| 4968 | 1972 * function or method. |
| 1973 */ | |
| 1664 | 1974 static int |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1975 PythonCmd(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) |
| 1664 | 1976 { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1977 PythonCmd_ClientData *data = (PythonCmd_ClientData *)clientData; |
| 4968 | 1978 PyObject *self, *func, *arg, *res, *tmp; |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1979 int i, rv; |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
1980 char *s; |
| 1664 | 1981 |
|
9319
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
1982 ENTER_PYTHON |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1983 |
| 4968 | 1984 /* TBD: no error checking here since we know, via the |
| 1985 * Tkapp_CreateCommand() that the client data is a two-tuple | |
| 1986 */ | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1987 self = data->self; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1988 func = data->func; |
| 4968 | 1989 |
| 1990 /* Create argument list (argv1, ..., argvN) */ | |
| 1991 if (!(arg = PyTuple_New(argc - 1))) | |
| 1992 return PythonCmd_Error(interp); | |
| 1664 | 1993 |
| 4968 | 1994 for (i = 0; i < (argc - 1); i++) { |
| 1995 PyObject *s = PyString_FromString(argv[i + 1]); | |
| 1996 if (!s || PyTuple_SetItem(arg, i, s)) { | |
| 1997 Py_DECREF(arg); | |
|
8522
4e4fd954dda0
There was an error check in a loop in PythonCmd which called
Guido van Rossum <guido@python.org>
parents:
8504
diff
changeset
|
1998 return PythonCmd_Error(interp); |
| 4968 | 1999 } |
| 2000 } | |
| 2001 res = PyEval_CallObject(func, arg); | |
| 2002 Py_DECREF(arg); | |
| 1713 | 2003 |
| 4968 | 2004 if (res == NULL) |
| 2005 return PythonCmd_Error(interp); | |
| 1664 | 2006 |
| 4968 | 2007 if (!(tmp = PyList_New(0))) { |
| 2008 Py_DECREF(res); | |
| 2009 return PythonCmd_Error(interp); | |
| 2010 } | |
| 1664 | 2011 |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
2012 s = AsString(res, tmp); |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
2013 if (s == NULL) { |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
2014 rv = PythonCmd_Error(interp); |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
2015 } |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
2016 else { |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
2017 Tcl_SetResult(Tkapp_Interp(self), s, TCL_VOLATILE); |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
2018 rv = TCL_OK; |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
2019 } |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
2020 |
| 4968 | 2021 Py_DECREF(res); |
| 2022 Py_DECREF(tmp); | |
| 2023 | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2024 LEAVE_PYTHON |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2025 |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
2026 return rv; |
| 1664 | 2027 } |
| 2028 | |
| 2029 static void | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2030 PythonCmdDelete(ClientData clientData) |
| 1664 | 2031 { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2032 PythonCmd_ClientData *data = (PythonCmd_ClientData *)clientData; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2033 |
|
9319
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
2034 ENTER_PYTHON |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2035 Py_XDECREF(data->self); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2036 Py_XDECREF(data->func); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2037 PyMem_DEL(data); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2038 LEAVE_PYTHON |
| 1664 | 2039 } |
| 2040 | |
| 4968 | 2041 |
| 2042 | |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2043 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2044 TCL_DECLARE_MUTEX(command_mutex) |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2045 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2046 typedef struct CommandEvent{ |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2047 Tcl_Event ev; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2048 Tcl_Interp* interp; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2049 char *name; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2050 int create; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2051 int *status; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2052 ClientData *data; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2053 Tcl_Condition done; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2054 } CommandEvent; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2055 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2056 static int |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2057 Tkapp_CommandProc(CommandEvent *ev, int flags) |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2058 { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2059 if (ev->create) |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2060 *ev->status = Tcl_CreateCommand( |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2061 ev->interp, ev->name, PythonCmd, |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2062 ev->data, PythonCmdDelete) == NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2063 else |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2064 *ev->status = Tcl_DeleteCommand(ev->interp, ev->name); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2065 Tcl_MutexLock(&command_mutex); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2066 Tcl_ConditionNotify(&ev->done); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2067 Tcl_MutexUnlock(&command_mutex); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2068 return 1; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2069 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2070 |
| 1664 | 2071 static PyObject * |
|
38559
129ab846a71f
[Bug #1497414] _self is a reserved word in the WATCOM 10.6 C compiler.
Andrew M. Kuchling <amk@amk.ca>
parents:
38067
diff
changeset
|
2072 Tkapp_CreateCommand(PyObject *selfptr, PyObject *args) |
| 1664 | 2073 { |
|
38559
129ab846a71f
[Bug #1497414] _self is a reserved word in the WATCOM 10.6 C compiler.
Andrew M. Kuchling <amk@amk.ca>
parents:
38067
diff
changeset
|
2074 TkappObject *self = (TkappObject*)selfptr; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2075 PythonCmd_ClientData *data; |
| 4968 | 2076 char *cmdName; |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2077 PyObject *func; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2078 int err; |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2079 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
2080 if (!PyArg_ParseTuple(args, "sO:createcommand", &cmdName, &func)) |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2081 return NULL; |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2082 if (!PyCallable_Check(func)) { |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2083 PyErr_SetString(PyExc_TypeError, "command not callable"); |
| 4968 | 2084 return NULL; |
| 2085 } | |
| 1664 | 2086 |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
2087 #ifdef WITH_THREAD |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2088 if (self->threaded && self->thread_id != Tcl_GetCurrentThread() && |
|
26814
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
2089 !WaitForMainloop(self)) |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2090 return NULL; |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
2091 #endif |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2092 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2093 data = PyMem_NEW(PythonCmd_ClientData, 1); |
| 4968 | 2094 if (!data) |
|
27826
7dffcc498c45
Add more missing PyErr_NoMemory() after failled memory allocs
Neal Norwitz <nnorwitz@gmail.com>
parents:
27341
diff
changeset
|
2095 return PyErr_NoMemory(); |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2096 Py_XINCREF(self); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2097 Py_XINCREF(func); |
|
38559
129ab846a71f
[Bug #1497414] _self is a reserved word in the WATCOM 10.6 C compiler.
Andrew M. Kuchling <amk@amk.ca>
parents:
38067
diff
changeset
|
2098 data->self = selfptr; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2099 data->func = func; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2100 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2101 if (self->threaded && self->thread_id != Tcl_GetCurrentThread()) { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2102 CommandEvent *ev = (CommandEvent*)ckalloc(sizeof(CommandEvent)); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2103 ev->ev.proc = (Tcl_EventProc*)Tkapp_CommandProc; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2104 ev->interp = self->interp; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2105 ev->create = 1; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2106 ev->name = cmdName; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2107 ev->data = (ClientData)data; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2108 ev->status = &err; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2109 ev->done = NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2110 Tkapp_ThreadSend(self, (Tcl_Event*)ev, &ev->done, &command_mutex); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2111 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2112 else { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2113 ENTER_TCL |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2114 err = Tcl_CreateCommand( |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2115 Tkapp_Interp(self), cmdName, PythonCmd, |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2116 (ClientData)data, PythonCmdDelete) == NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2117 LEAVE_TCL |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2118 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2119 if (err) { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2120 PyErr_SetString(Tkinter_TclError, "can't create Tcl command"); |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2121 PyMem_DEL(data); |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2122 return NULL; |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2123 } |
| 1664 | 2124 |
| 4968 | 2125 Py_INCREF(Py_None); |
| 2126 return Py_None; | |
| 1664 | 2127 } |
| 2128 | |
| 4968 | 2129 |
| 2130 | |
| 1664 | 2131 static PyObject * |
|
38559
129ab846a71f
[Bug #1497414] _self is a reserved word in the WATCOM 10.6 C compiler.
Andrew M. Kuchling <amk@amk.ca>
parents:
38067
diff
changeset
|
2132 Tkapp_DeleteCommand(PyObject *selfptr, PyObject *args) |
| 1664 | 2133 { |
|
38559
129ab846a71f
[Bug #1497414] _self is a reserved word in the WATCOM 10.6 C compiler.
Andrew M. Kuchling <amk@amk.ca>
parents:
38067
diff
changeset
|
2134 TkappObject *self = (TkappObject*)selfptr; |
| 4968 | 2135 char *cmdName; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2136 int err; |
| 1664 | 2137 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
2138 if (!PyArg_ParseTuple(args, "s:deletecommand", &cmdName)) |
| 4968 | 2139 return NULL; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2140 if (self->threaded && self->thread_id != Tcl_GetCurrentThread()) { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2141 CommandEvent *ev; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2142 ev = (CommandEvent*)ckalloc(sizeof(CommandEvent)); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2143 ev->ev.proc = (Tcl_EventProc*)Tkapp_CommandProc; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2144 ev->interp = self->interp; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2145 ev->create = 0; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2146 ev->name = cmdName; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2147 ev->status = &err; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2148 ev->done = NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2149 Tkapp_ThreadSend(self, (Tcl_Event*)ev, &ev->done, |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2150 &command_mutex); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2151 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2152 else { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2153 ENTER_TCL |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2154 err = Tcl_DeleteCommand(self->interp, cmdName); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2155 LEAVE_TCL |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2156 } |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2157 if (err == -1) { |
| 4968 | 2158 PyErr_SetString(Tkinter_TclError, "can't delete Tcl command"); |
| 2159 return NULL; | |
| 2160 } | |
| 2161 Py_INCREF(Py_None); | |
| 2162 return Py_None; | |
| 1664 | 2163 } |
| 2164 | |
| 4968 | 2165 |
| 2166 | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2167 #ifdef HAVE_CREATEFILEHANDLER |
| 1664 | 2168 /** File Handler **/ |
| 2169 | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2170 typedef struct _fhcdata { |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2171 PyObject *func; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2172 PyObject *file; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2173 int id; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2174 struct _fhcdata *next; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2175 } FileHandler_ClientData; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2176 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2177 static FileHandler_ClientData *HeadFHCD; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2178 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2179 static FileHandler_ClientData * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2180 NewFHCD(PyObject *func, PyObject *file, int id) |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2181 { |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2182 FileHandler_ClientData *p; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2183 p = PyMem_NEW(FileHandler_ClientData, 1); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2184 if (p != NULL) { |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2185 Py_XINCREF(func); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2186 Py_XINCREF(file); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2187 p->func = func; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2188 p->file = file; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2189 p->id = id; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2190 p->next = HeadFHCD; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2191 HeadFHCD = p; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2192 } |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2193 return p; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2194 } |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2195 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2196 static void |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2197 DeleteFHCD(int id) |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2198 { |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2199 FileHandler_ClientData *p, **pp; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2200 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2201 pp = &HeadFHCD; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2202 while ((p = *pp) != NULL) { |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2203 if (p->id == id) { |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2204 *pp = p->next; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2205 Py_XDECREF(p->func); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2206 Py_XDECREF(p->file); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2207 PyMem_DEL(p); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2208 } |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2209 else |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2210 pp = &p->next; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2211 } |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2212 } |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2213 |
|
2123
fd5ab7e828fc
cosmetic changes so these modules will work with the strict new naming scheme
Guido van Rossum <guido@python.org>
parents:
2121
diff
changeset
|
2214 static void |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2215 FileHandler(ClientData clientData, int mask) |
| 1664 | 2216 { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2217 FileHandler_ClientData *data = (FileHandler_ClientData *)clientData; |
| 4968 | 2218 PyObject *func, *file, *arg, *res; |
| 1664 | 2219 |
|
9319
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
2220 ENTER_PYTHON |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2221 func = data->func; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2222 file = data->file; |
| 1664 | 2223 |
| 4968 | 2224 arg = Py_BuildValue("(Oi)", file, (long) mask); |
| 2225 res = PyEval_CallObject(func, arg); | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2226 Py_DECREF(arg); |
| 4968 | 2227 |
| 2228 if (res == NULL) { | |
| 2229 errorInCmd = 1; | |
| 2230 PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd); | |
| 2231 } | |
| 2232 Py_XDECREF(res); | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2233 LEAVE_PYTHON |
|
1771
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
2234 } |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
2235 |
| 1664 | 2236 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2237 Tkapp_CreateFileHandler(PyObject *self, PyObject *args) |
|
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2238 /* args is (file, mask, func) */ |
| 1664 | 2239 { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2240 FileHandler_ClientData *data; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2241 PyObject *file, *func; |
|
12071
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
2242 int mask, tfile; |
| 1664 | 2243 |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
2244 if (!PyArg_ParseTuple(args, "OiO:createfilehandler", |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
2245 &file, &mask, &func)) |
| 4968 | 2246 return NULL; |
|
28142
524e5f9f85e6
Don't crash on _tkinter.createfilehandler in non-threaded Tcl;
Martin v. Löwis <martin@v.loewis.de>
parents:
27826
diff
changeset
|
2247 |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
2248 #ifdef WITH_THREAD |
|
28142
524e5f9f85e6
Don't crash on _tkinter.createfilehandler in non-threaded Tcl;
Martin v. Löwis <martin@v.loewis.de>
parents:
27826
diff
changeset
|
2249 if (!self && !tcl_lock) { |
|
524e5f9f85e6
Don't crash on _tkinter.createfilehandler in non-threaded Tcl;
Martin v. Löwis <martin@v.loewis.de>
parents:
27826
diff
changeset
|
2250 /* We don't have the Tcl lock since Tcl is threaded. */ |
|
524e5f9f85e6
Don't crash on _tkinter.createfilehandler in non-threaded Tcl;
Martin v. Löwis <martin@v.loewis.de>
parents:
27826
diff
changeset
|
2251 PyErr_SetString(PyExc_RuntimeError, |
|
524e5f9f85e6
Don't crash on _tkinter.createfilehandler in non-threaded Tcl;
Martin v. Löwis <martin@v.loewis.de>
parents:
27826
diff
changeset
|
2252 "_tkinter.createfilehandler not supported " |
|
524e5f9f85e6
Don't crash on _tkinter.createfilehandler in non-threaded Tcl;
Martin v. Löwis <martin@v.loewis.de>
parents:
27826
diff
changeset
|
2253 "for threaded Tcl"); |
|
524e5f9f85e6
Don't crash on _tkinter.createfilehandler in non-threaded Tcl;
Martin v. Löwis <martin@v.loewis.de>
parents:
27826
diff
changeset
|
2254 return NULL; |
|
524e5f9f85e6
Don't crash on _tkinter.createfilehandler in non-threaded Tcl;
Martin v. Löwis <martin@v.loewis.de>
parents:
27826
diff
changeset
|
2255 } |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
2256 #endif |
|
28142
524e5f9f85e6
Don't crash on _tkinter.createfilehandler in non-threaded Tcl;
Martin v. Löwis <martin@v.loewis.de>
parents:
27826
diff
changeset
|
2257 |
|
524e5f9f85e6
Don't crash on _tkinter.createfilehandler in non-threaded Tcl;
Martin v. Löwis <martin@v.loewis.de>
parents:
27826
diff
changeset
|
2258 if (self) { |
|
524e5f9f85e6
Don't crash on _tkinter.createfilehandler in non-threaded Tcl;
Martin v. Löwis <martin@v.loewis.de>
parents:
27826
diff
changeset
|
2259 CHECK_TCL_APPARTMENT; |
|
524e5f9f85e6
Don't crash on _tkinter.createfilehandler in non-threaded Tcl;
Martin v. Löwis <martin@v.loewis.de>
parents:
27826
diff
changeset
|
2260 } |
|
524e5f9f85e6
Don't crash on _tkinter.createfilehandler in non-threaded Tcl;
Martin v. Löwis <martin@v.loewis.de>
parents:
27826
diff
changeset
|
2261 |
|
13593
df64cc0e84e2
Use PyObject_AsFileDescriptor
Andrew M. Kuchling <amk@amk.ca>
parents:
13576
diff
changeset
|
2262 tfile = PyObject_AsFileDescriptor(file); |
|
12071
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
2263 if (tfile < 0) |
| 4968 | 2264 return NULL; |
| 2265 if (!PyCallable_Check(func)) { | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2266 PyErr_SetString(PyExc_TypeError, "bad argument list"); |
| 4968 | 2267 return NULL; |
| 2268 } | |
| 2269 | |
|
12071
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
2270 data = NewFHCD(func, file, tfile); |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2271 if (data == NULL) |
| 4968 | 2272 return NULL; |
| 2273 | |
| 2274 /* Ought to check for null Tcl_File object... */ | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2275 ENTER_TCL |
| 4968 | 2276 Tcl_CreateFileHandler(tfile, mask, FileHandler, (ClientData) data); |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2277 LEAVE_TCL |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2278 Py_INCREF(Py_None); |
| 4968 | 2279 return Py_None; |
| 1664 | 2280 } |
| 2281 | |
| 2282 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2283 Tkapp_DeleteFileHandler(PyObject *self, PyObject *args) |
| 1664 | 2284 { |
| 4968 | 2285 PyObject *file; |
|
12071
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
2286 int tfile; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2287 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
2288 if (!PyArg_ParseTuple(args, "O:deletefilehandler", &file)) |
| 4968 | 2289 return NULL; |
|
28156
3fe72a994103
Fix SF #692416, don't crash interpreter for _tkinter.deletefilehandler
Neal Norwitz <nnorwitz@gmail.com>
parents:
28142
diff
changeset
|
2290 |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
2291 #ifdef WITH_THREAD |
|
28156
3fe72a994103
Fix SF #692416, don't crash interpreter for _tkinter.deletefilehandler
Neal Norwitz <nnorwitz@gmail.com>
parents:
28142
diff
changeset
|
2292 if (!self && !tcl_lock) { |
|
3fe72a994103
Fix SF #692416, don't crash interpreter for _tkinter.deletefilehandler
Neal Norwitz <nnorwitz@gmail.com>
parents:
28142
diff
changeset
|
2293 /* We don't have the Tcl lock since Tcl is threaded. */ |
|
3fe72a994103
Fix SF #692416, don't crash interpreter for _tkinter.deletefilehandler
Neal Norwitz <nnorwitz@gmail.com>
parents:
28142
diff
changeset
|
2294 PyErr_SetString(PyExc_RuntimeError, |
|
3fe72a994103
Fix SF #692416, don't crash interpreter for _tkinter.deletefilehandler
Neal Norwitz <nnorwitz@gmail.com>
parents:
28142
diff
changeset
|
2295 "_tkinter.deletefilehandler not supported " |
|
3fe72a994103
Fix SF #692416, don't crash interpreter for _tkinter.deletefilehandler
Neal Norwitz <nnorwitz@gmail.com>
parents:
28142
diff
changeset
|
2296 "for threaded Tcl"); |
|
3fe72a994103
Fix SF #692416, don't crash interpreter for _tkinter.deletefilehandler
Neal Norwitz <nnorwitz@gmail.com>
parents:
28142
diff
changeset
|
2297 return NULL; |
|
3fe72a994103
Fix SF #692416, don't crash interpreter for _tkinter.deletefilehandler
Neal Norwitz <nnorwitz@gmail.com>
parents:
28142
diff
changeset
|
2298 } |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
2299 #endif |
|
28156
3fe72a994103
Fix SF #692416, don't crash interpreter for _tkinter.deletefilehandler
Neal Norwitz <nnorwitz@gmail.com>
parents:
28142
diff
changeset
|
2300 |
|
3fe72a994103
Fix SF #692416, don't crash interpreter for _tkinter.deletefilehandler
Neal Norwitz <nnorwitz@gmail.com>
parents:
28142
diff
changeset
|
2301 if (self) { |
|
3fe72a994103
Fix SF #692416, don't crash interpreter for _tkinter.deletefilehandler
Neal Norwitz <nnorwitz@gmail.com>
parents:
28142
diff
changeset
|
2302 CHECK_TCL_APPARTMENT; |
|
3fe72a994103
Fix SF #692416, don't crash interpreter for _tkinter.deletefilehandler
Neal Norwitz <nnorwitz@gmail.com>
parents:
28142
diff
changeset
|
2303 } |
|
3fe72a994103
Fix SF #692416, don't crash interpreter for _tkinter.deletefilehandler
Neal Norwitz <nnorwitz@gmail.com>
parents:
28142
diff
changeset
|
2304 |
|
13593
df64cc0e84e2
Use PyObject_AsFileDescriptor
Andrew M. Kuchling <amk@amk.ca>
parents:
13576
diff
changeset
|
2305 tfile = PyObject_AsFileDescriptor(file); |
|
12071
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
2306 if (tfile < 0) |
| 4968 | 2307 return NULL; |
| 2308 | |
|
12071
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
2309 DeleteFHCD(tfile); |
| 1664 | 2310 |
| 4968 | 2311 /* Ought to check for null Tcl_File object... */ |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2312 ENTER_TCL |
| 4968 | 2313 Tcl_DeleteFileHandler(tfile); |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2314 LEAVE_TCL |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2315 Py_INCREF(Py_None); |
| 4968 | 2316 return Py_None; |
| 1664 | 2317 } |
|
6026
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
2318 #endif /* HAVE_CREATEFILEHANDLER */ |
| 1664 | 2319 |
| 4968 | 2320 |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2321 /**** Tktt Object (timer token) ****/ |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2322 |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23662
diff
changeset
|
2323 static PyTypeObject Tktt_Type; |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2324 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2325 typedef struct { |
| 4968 | 2326 PyObject_HEAD |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2327 Tcl_TimerToken token; |
| 4968 | 2328 PyObject *func; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2329 } TkttObject; |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2330 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2331 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2332 Tktt_DeleteTimerHandler(PyObject *self, PyObject *args) |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2333 { |
| 4968 | 2334 TkttObject *v = (TkttObject *)self; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2335 PyObject *func = v->func; |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2336 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
2337 if (!PyArg_ParseTuple(args, ":deletetimerhandler")) |
| 4968 | 2338 return NULL; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2339 if (v->token != NULL) { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2340 Tcl_DeleteTimerHandler(v->token); |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2341 v->token = NULL; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2342 } |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2343 if (func != NULL) { |
| 4968 | 2344 v->func = NULL; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2345 Py_DECREF(func); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2346 Py_DECREF(v); /* See Tktt_New() */ |
| 4968 | 2347 } |
| 2348 Py_INCREF(Py_None); | |
| 2349 return Py_None; | |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2350 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2351 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2352 static PyMethodDef Tktt_methods[] = |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2353 { |
|
22706
14ebd7610902
Use symbolic METH_VARARGS/METH_OLDARGS instead of 1/0 for ml_flags
Neal Norwitz <nnorwitz@gmail.com>
parents:
21813
diff
changeset
|
2354 {"deletetimerhandler", Tktt_DeleteTimerHandler, METH_VARARGS}, |
| 4968 | 2355 {NULL, NULL} |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2356 }; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2357 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2358 static TkttObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2359 Tktt_New(PyObject *func) |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2360 { |
| 4968 | 2361 TkttObject *v; |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2362 |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12513
diff
changeset
|
2363 v = PyObject_New(TkttObject, &Tktt_Type); |
| 4968 | 2364 if (v == NULL) |
| 2365 return NULL; | |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2366 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2367 Py_INCREF(func); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2368 v->token = NULL; |
| 4968 | 2369 v->func = func; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2370 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2371 /* Extra reference, deleted when called or when handler is deleted */ |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2372 Py_INCREF(v); |
| 4968 | 2373 return v; |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2374 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2375 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2376 static void |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2377 Tktt_Dealloc(PyObject *self) |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2378 { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2379 TkttObject *v = (TkttObject *)self; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2380 PyObject *func = v->func; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2381 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2382 Py_XDECREF(func); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2383 |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12513
diff
changeset
|
2384 PyObject_Del(self); |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2385 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2386 |
|
8312
d67be13da3cc
Trivial little change: timer tokens shouldn't have a Print() function,
Guido van Rossum <guido@python.org>
parents:
8200
diff
changeset
|
2387 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2388 Tktt_Repr(PyObject *self) |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2389 { |
| 4968 | 2390 TkttObject *v = (TkttObject *)self; |
|
8312
d67be13da3cc
Trivial little change: timer tokens shouldn't have a Print() function,
Guido van Rossum <guido@python.org>
parents:
8200
diff
changeset
|
2391 char buf[100]; |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2392 |
|
21073
304b34023876
sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
2393 PyOS_snprintf(buf, sizeof(buf), "<tktimertoken at %p%s>", v, |
|
21322
1852caba7014
Mods by Tony Lownds (patch 490100, slightly massaged by me) to make Tkinter
Jack Jansen <jack.jansen@cwi.nl>
parents:
21073
diff
changeset
|
2394 v->func == NULL ? ", handler deleted" : ""); |
|
8312
d67be13da3cc
Trivial little change: timer tokens shouldn't have a Print() function,
Guido van Rossum <guido@python.org>
parents:
8200
diff
changeset
|
2395 return PyString_FromString(buf); |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2396 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2397 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2398 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2399 Tktt_GetAttr(PyObject *self, char *name) |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2400 { |
| 4968 | 2401 return Py_FindMethod(Tktt_methods, self, name); |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2402 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2403 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2404 static PyTypeObject Tktt_Type = |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2405 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2406 PyObject_HEAD_INIT(NULL) |
| 4968 | 2407 0, /*ob_size */ |
| 2408 "tktimertoken", /*tp_name */ | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2409 sizeof(TkttObject), /*tp_basicsize */ |
| 4968 | 2410 0, /*tp_itemsize */ |
| 2411 Tktt_Dealloc, /*tp_dealloc */ | |
|
8312
d67be13da3cc
Trivial little change: timer tokens shouldn't have a Print() function,
Guido van Rossum <guido@python.org>
parents:
8200
diff
changeset
|
2412 0, /*tp_print */ |
| 4968 | 2413 Tktt_GetAttr, /*tp_getattr */ |
| 2414 0, /*tp_setattr */ | |
| 2415 0, /*tp_compare */ | |
|
8312
d67be13da3cc
Trivial little change: timer tokens shouldn't have a Print() function,
Guido van Rossum <guido@python.org>
parents:
8200
diff
changeset
|
2416 Tktt_Repr, /*tp_repr */ |
| 4968 | 2417 0, /*tp_as_number */ |
| 2418 0, /*tp_as_sequence */ | |
| 2419 0, /*tp_as_mapping */ | |
| 2420 0, /*tp_hash */ | |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2421 }; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2422 |
| 4968 | 2423 |
| 2424 | |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2425 /** Timer Handler **/ |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2426 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2427 static void |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2428 TimerHandler(ClientData clientData) |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2429 { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2430 TkttObject *v = (TkttObject *)clientData; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2431 PyObject *func = v->func; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2432 PyObject *res; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2433 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2434 if (func == NULL) |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2435 return; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2436 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2437 v->func = NULL; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2438 |
|
9319
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
2439 ENTER_PYTHON |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2440 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2441 res = PyEval_CallObject(func, NULL); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2442 Py_DECREF(func); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2443 Py_DECREF(v); /* See Tktt_New() */ |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2444 |
| 4968 | 2445 if (res == NULL) { |
| 2446 errorInCmd = 1; | |
| 2447 PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd); | |
| 2448 } | |
| 2449 else | |
| 2450 Py_DECREF(res); | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2451 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2452 LEAVE_PYTHON |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2453 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2454 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2455 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2456 Tkapp_CreateTimerHandler(PyObject *self, PyObject *args) |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2457 { |
| 4968 | 2458 int milliseconds; |
| 2459 PyObject *func; | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2460 TkttObject *v; |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2461 |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
2462 if (!PyArg_ParseTuple(args, "iO:createtimerhandler", |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
2463 &milliseconds, &func)) |
| 4968 | 2464 return NULL; |
| 2465 if (!PyCallable_Check(func)) { | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2466 PyErr_SetString(PyExc_TypeError, "bad argument list"); |
| 4968 | 2467 return NULL; |
| 2468 } | |
|
28142
524e5f9f85e6
Don't crash on _tkinter.createfilehandler in non-threaded Tcl;
Martin v. Löwis <martin@v.loewis.de>
parents:
27826
diff
changeset
|
2469 |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
2470 #ifdef WITH_THREAD |
|
28142
524e5f9f85e6
Don't crash on _tkinter.createfilehandler in non-threaded Tcl;
Martin v. Löwis <martin@v.loewis.de>
parents:
27826
diff
changeset
|
2471 if (!self && !tcl_lock) { |
|
524e5f9f85e6
Don't crash on _tkinter.createfilehandler in non-threaded Tcl;
Martin v. Löwis <martin@v.loewis.de>
parents:
27826
diff
changeset
|
2472 /* We don't have the Tcl lock since Tcl is threaded. */ |
|
524e5f9f85e6
Don't crash on _tkinter.createfilehandler in non-threaded Tcl;
Martin v. Löwis <martin@v.loewis.de>
parents:
27826
diff
changeset
|
2473 PyErr_SetString(PyExc_RuntimeError, |
|
524e5f9f85e6
Don't crash on _tkinter.createfilehandler in non-threaded Tcl;
Martin v. Löwis <martin@v.loewis.de>
parents:
27826
diff
changeset
|
2474 "_tkinter.createtimerhandler not supported " |
|
524e5f9f85e6
Don't crash on _tkinter.createfilehandler in non-threaded Tcl;
Martin v. Löwis <martin@v.loewis.de>
parents:
27826
diff
changeset
|
2475 "for threaded Tcl"); |
|
524e5f9f85e6
Don't crash on _tkinter.createfilehandler in non-threaded Tcl;
Martin v. Löwis <martin@v.loewis.de>
parents:
27826
diff
changeset
|
2476 return NULL; |
|
524e5f9f85e6
Don't crash on _tkinter.createfilehandler in non-threaded Tcl;
Martin v. Löwis <martin@v.loewis.de>
parents:
27826
diff
changeset
|
2477 } |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
2478 #endif |
|
28142
524e5f9f85e6
Don't crash on _tkinter.createfilehandler in non-threaded Tcl;
Martin v. Löwis <martin@v.loewis.de>
parents:
27826
diff
changeset
|
2479 |
|
524e5f9f85e6
Don't crash on _tkinter.createfilehandler in non-threaded Tcl;
Martin v. Löwis <martin@v.loewis.de>
parents:
27826
diff
changeset
|
2480 if (self) { |
|
524e5f9f85e6
Don't crash on _tkinter.createfilehandler in non-threaded Tcl;
Martin v. Löwis <martin@v.loewis.de>
parents:
27826
diff
changeset
|
2481 CHECK_TCL_APPARTMENT; |
|
524e5f9f85e6
Don't crash on _tkinter.createfilehandler in non-threaded Tcl;
Martin v. Löwis <martin@v.loewis.de>
parents:
27826
diff
changeset
|
2482 } |
|
524e5f9f85e6
Don't crash on _tkinter.createfilehandler in non-threaded Tcl;
Martin v. Löwis <martin@v.loewis.de>
parents:
27826
diff
changeset
|
2483 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2484 v = Tktt_New(func); |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2485 v->token = Tcl_CreateTimerHandler(milliseconds, TimerHandler, |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2486 (ClientData)v); |
| 4968 | 2487 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2488 return (PyObject *) v; |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2489 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2490 |
| 4968 | 2491 |
| 1664 | 2492 /** Event Loop **/ |
| 2493 | |
| 2494 static PyObject * | |
|
38559
129ab846a71f
[Bug #1497414] _self is a reserved word in the WATCOM 10.6 C compiler.
Andrew M. Kuchling <amk@amk.ca>
parents:
38067
diff
changeset
|
2495 Tkapp_MainLoop(PyObject *selfptr, PyObject *args) |
| 1664 | 2496 { |
| 4968 | 2497 int threshold = 0; |
|
38559
129ab846a71f
[Bug #1497414] _self is a reserved word in the WATCOM 10.6 C compiler.
Andrew M. Kuchling <amk@amk.ca>
parents:
38067
diff
changeset
|
2498 TkappObject *self = (TkappObject*)selfptr; |
|
9319
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
2499 #ifdef WITH_THREAD |
|
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
2500 PyThreadState *tstate = PyThreadState_Get(); |
|
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
2501 #endif |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2502 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
2503 if (!PyArg_ParseTuple(args, "|i:mainloop", &threshold)) |
| 4968 | 2504 return NULL; |
| 1664 | 2505 |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
2506 #ifdef WITH_THREAD |
|
27083
d5e09d412b53
Remove appartment check from dooneevent. Fixes #660961.
Martin v. Löwis <martin@v.loewis.de>
parents:
27071
diff
changeset
|
2507 if (!self && !tcl_lock) { |
|
d5e09d412b53
Remove appartment check from dooneevent. Fixes #660961.
Martin v. Löwis <martin@v.loewis.de>
parents:
27071
diff
changeset
|
2508 /* We don't have the Tcl lock since Tcl is threaded. */ |
|
d5e09d412b53
Remove appartment check from dooneevent. Fixes #660961.
Martin v. Löwis <martin@v.loewis.de>
parents:
27071
diff
changeset
|
2509 PyErr_SetString(PyExc_RuntimeError, |
|
d5e09d412b53
Remove appartment check from dooneevent. Fixes #660961.
Martin v. Löwis <martin@v.loewis.de>
parents:
27071
diff
changeset
|
2510 "_tkinter.mainloop not supported " |
|
d5e09d412b53
Remove appartment check from dooneevent. Fixes #660961.
Martin v. Löwis <martin@v.loewis.de>
parents:
27071
diff
changeset
|
2511 "for threaded Tcl"); |
|
d5e09d412b53
Remove appartment check from dooneevent. Fixes #660961.
Martin v. Löwis <martin@v.loewis.de>
parents:
27071
diff
changeset
|
2512 return NULL; |
|
d5e09d412b53
Remove appartment check from dooneevent. Fixes #660961.
Martin v. Löwis <martin@v.loewis.de>
parents:
27071
diff
changeset
|
2513 } |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
2514 #endif |
|
27083
d5e09d412b53
Remove appartment check from dooneevent. Fixes #660961.
Martin v. Löwis <martin@v.loewis.de>
parents:
27071
diff
changeset
|
2515 |
|
d5e09d412b53
Remove appartment check from dooneevent. Fixes #660961.
Martin v. Löwis <martin@v.loewis.de>
parents:
27071
diff
changeset
|
2516 if (self) { |
|
d5e09d412b53
Remove appartment check from dooneevent. Fixes #660961.
Martin v. Löwis <martin@v.loewis.de>
parents:
27071
diff
changeset
|
2517 CHECK_TCL_APPARTMENT; |
|
d5e09d412b53
Remove appartment check from dooneevent. Fixes #660961.
Martin v. Löwis <martin@v.loewis.de>
parents:
27071
diff
changeset
|
2518 self->dispatching = 1; |
|
d5e09d412b53
Remove appartment check from dooneevent. Fixes #660961.
Martin v. Löwis <martin@v.loewis.de>
parents:
27071
diff
changeset
|
2519 } |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2520 |
| 4968 | 2521 quitMainLoop = 0; |
| 2522 while (Tk_GetNumMainWindows() > threshold && | |
| 2523 !quitMainLoop && | |
| 2524 !errorInCmd) | |
| 1664 | 2525 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2526 int result; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2527 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2528 #ifdef WITH_THREAD |
|
27083
d5e09d412b53
Remove appartment check from dooneevent. Fixes #660961.
Martin v. Löwis <martin@v.loewis.de>
parents:
27071
diff
changeset
|
2529 if (self && self->threaded) { |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2530 /* Allow other Python threads to run. */ |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2531 ENTER_TCL |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2532 result = Tcl_DoOneEvent(0); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2533 LEAVE_TCL |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2534 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2535 else { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2536 Py_BEGIN_ALLOW_THREADS |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2537 if(tcl_lock)PyThread_acquire_lock(tcl_lock, 1); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2538 tcl_tstate = tstate; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2539 result = Tcl_DoOneEvent(TCL_DONT_WAIT); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2540 tcl_tstate = NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2541 if(tcl_lock)PyThread_release_lock(tcl_lock); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2542 if (result == 0) |
|
29038
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2543 Sleep(Tkinter_busywaitinterval); |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2544 Py_END_ALLOW_THREADS |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2545 } |
|
6106
36b3b337c566
Alas, the thread support for Tk didn't work. Withdraw it, until I
Guido van Rossum <guido@python.org>
parents:
6093
diff
changeset
|
2546 #else |
|
36b3b337c566
Alas, the thread support for Tk didn't work. Withdraw it, until I
Guido van Rossum <guido@python.org>
parents:
6093
diff
changeset
|
2547 result = Tcl_DoOneEvent(0); |
|
36b3b337c566
Alas, the thread support for Tk didn't work. Withdraw it, until I
Guido van Rossum <guido@python.org>
parents:
6093
diff
changeset
|
2548 #endif |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2549 |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2550 if (PyErr_CheckSignals() != 0) { |
|
27083
d5e09d412b53
Remove appartment check from dooneevent. Fixes #660961.
Martin v. Löwis <martin@v.loewis.de>
parents:
27071
diff
changeset
|
2551 if (self) |
|
d5e09d412b53
Remove appartment check from dooneevent. Fixes #660961.
Martin v. Löwis <martin@v.loewis.de>
parents:
27071
diff
changeset
|
2552 self->dispatching = 0; |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2553 return NULL; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2554 } |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2555 if (result < 0) |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2556 break; |
| 1664 | 2557 } |
|
27083
d5e09d412b53
Remove appartment check from dooneevent. Fixes #660961.
Martin v. Löwis <martin@v.loewis.de>
parents:
27071
diff
changeset
|
2558 if (self) |
|
d5e09d412b53
Remove appartment check from dooneevent. Fixes #660961.
Martin v. Löwis <martin@v.loewis.de>
parents:
27071
diff
changeset
|
2559 self->dispatching = 0; |
| 4968 | 2560 quitMainLoop = 0; |
| 1664 | 2561 |
| 4968 | 2562 if (errorInCmd) { |
| 2563 errorInCmd = 0; | |
| 2564 PyErr_Restore(excInCmd, valInCmd, trbInCmd); | |
| 2565 excInCmd = valInCmd = trbInCmd = NULL; | |
| 2566 return NULL; | |
| 2567 } | |
| 2568 Py_INCREF(Py_None); | |
| 2569 return Py_None; | |
| 1664 | 2570 } |
| 2571 | |
| 2572 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2573 Tkapp_DoOneEvent(PyObject *self, PyObject *args) |
|
2121
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
2574 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2575 int flags = 0; |
| 4968 | 2576 int rv; |
|
2121
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
2577 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
2578 if (!PyArg_ParseTuple(args, "|i:dooneevent", &flags)) |
| 4968 | 2579 return NULL; |
| 2580 | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2581 ENTER_TCL |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2582 rv = Tcl_DoOneEvent(flags); |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2583 LEAVE_TCL |
| 4968 | 2584 return Py_BuildValue("i", rv); |
|
2121
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
2585 } |
|
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
2586 |
|
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
2587 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2588 Tkapp_Quit(PyObject *self, PyObject *args) |
| 1664 | 2589 { |
| 2590 | |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
2591 if (!PyArg_ParseTuple(args, ":quit")) |
| 4968 | 2592 return NULL; |
| 2593 | |
| 2594 quitMainLoop = 1; | |
| 2595 Py_INCREF(Py_None); | |
| 2596 return Py_None; | |
| 1664 | 2597 } |
| 2598 | |
|
8199
c31c59f192af
Add a new method of interpreter objects, interpaddr(). This returns
Guido van Rossum <guido@python.org>
parents:
8185
diff
changeset
|
2599 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2600 Tkapp_InterpAddr(PyObject *self, PyObject *args) |
|
8199
c31c59f192af
Add a new method of interpreter objects, interpaddr(). This returns
Guido van Rossum <guido@python.org>
parents:
8185
diff
changeset
|
2601 { |
|
c31c59f192af
Add a new method of interpreter objects, interpaddr(). This returns
Guido van Rossum <guido@python.org>
parents:
8185
diff
changeset
|
2602 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
2603 if (!PyArg_ParseTuple(args, ":interpaddr")) |
|
8199
c31c59f192af
Add a new method of interpreter objects, interpaddr(). This returns
Guido van Rossum <guido@python.org>
parents:
8185
diff
changeset
|
2604 return NULL; |
|
c31c59f192af
Add a new method of interpreter objects, interpaddr(). This returns
Guido van Rossum <guido@python.org>
parents:
8185
diff
changeset
|
2605 |
|
c31c59f192af
Add a new method of interpreter objects, interpaddr(). This returns
Guido van Rossum <guido@python.org>
parents:
8185
diff
changeset
|
2606 return PyInt_FromLong((long)Tkapp_Interp(self)); |
|
c31c59f192af
Add a new method of interpreter objects, interpaddr(). This returns
Guido van Rossum <guido@python.org>
parents:
8185
diff
changeset
|
2607 } |
|
c31c59f192af
Add a new method of interpreter objects, interpaddr(). This returns
Guido van Rossum <guido@python.org>
parents:
8185
diff
changeset
|
2608 |
|
31547
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
2609 static PyObject * |
|
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
2610 Tkapp_TkInit(PyObject *self, PyObject *args) |
|
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
2611 { |
|
38067
efeebc8770e5
Work around deadlock risk.
Martin v. Löwis <martin@v.loewis.de>
parents:
36872
diff
changeset
|
2612 static int has_failed; |
|
31547
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
2613 Tcl_Interp *interp = Tkapp_Interp(self); |
|
31549
3da6c2adad34
Remove gcc warning from using "main". Use METH_NOARGS instead of METH_VARARGS
Neal Norwitz <nnorwitz@gmail.com>
parents:
31547
diff
changeset
|
2614 Tk_Window main_window; |
|
31547
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
2615 const char * _tk_exists = NULL; |
|
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
2616 int err; |
|
31549
3da6c2adad34
Remove gcc warning from using "main". Use METH_NOARGS instead of METH_VARARGS
Neal Norwitz <nnorwitz@gmail.com>
parents:
31547
diff
changeset
|
2617 main_window = Tk_MainWindow(interp); |
|
31547
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
2618 |
|
38067
efeebc8770e5
Work around deadlock risk.
Martin v. Löwis <martin@v.loewis.de>
parents:
36872
diff
changeset
|
2619 /* In all current versions of Tk (including 8.4.13), Tk_Init |
|
efeebc8770e5
Work around deadlock risk.
Martin v. Löwis <martin@v.loewis.de>
parents:
36872
diff
changeset
|
2620 deadlocks on the second call when the first call failed. |
|
efeebc8770e5
Work around deadlock risk.
Martin v. Löwis <martin@v.loewis.de>
parents:
36872
diff
changeset
|
2621 To avoid the deadlock, we just refuse the second call through |
|
efeebc8770e5
Work around deadlock risk.
Martin v. Löwis <martin@v.loewis.de>
parents:
36872
diff
changeset
|
2622 a static variable. */ |
|
efeebc8770e5
Work around deadlock risk.
Martin v. Löwis <martin@v.loewis.de>
parents:
36872
diff
changeset
|
2623 if (has_failed) { |
|
efeebc8770e5
Work around deadlock risk.
Martin v. Löwis <martin@v.loewis.de>
parents:
36872
diff
changeset
|
2624 PyErr_SetString(Tkinter_TclError, |
|
efeebc8770e5
Work around deadlock risk.
Martin v. Löwis <martin@v.loewis.de>
parents:
36872
diff
changeset
|
2625 "Calling Tk_Init again after a previous call failed might deadlock"); |
|
efeebc8770e5
Work around deadlock risk.
Martin v. Löwis <martin@v.loewis.de>
parents:
36872
diff
changeset
|
2626 return NULL; |
|
efeebc8770e5
Work around deadlock risk.
Martin v. Löwis <martin@v.loewis.de>
parents:
36872
diff
changeset
|
2627 } |
|
efeebc8770e5
Work around deadlock risk.
Martin v. Löwis <martin@v.loewis.de>
parents:
36872
diff
changeset
|
2628 |
|
31547
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
2629 /* We want to guard against calling Tk_Init() multiple times */ |
|
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
2630 CHECK_TCL_APPARTMENT; |
|
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
2631 ENTER_TCL |
|
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
2632 err = Tcl_Eval(Tkapp_Interp(self), "info exists tk_version"); |
|
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
2633 ENTER_OVERLAP |
|
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
2634 if (err == TCL_ERROR) { |
|
38067
efeebc8770e5
Work around deadlock risk.
Martin v. Löwis <martin@v.loewis.de>
parents:
36872
diff
changeset
|
2635 /* This sets an exception, but we cannot return right |
|
efeebc8770e5
Work around deadlock risk.
Martin v. Löwis <martin@v.loewis.de>
parents:
36872
diff
changeset
|
2636 away because we need to exit the overlap first. */ |
|
efeebc8770e5
Work around deadlock risk.
Martin v. Löwis <martin@v.loewis.de>
parents:
36872
diff
changeset
|
2637 Tkinter_Error(self); |
|
31547
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
2638 } else { |
|
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
2639 _tk_exists = Tkapp_Result(self); |
|
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
2640 } |
|
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
2641 LEAVE_OVERLAP_TCL |
|
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
2642 if (err == TCL_ERROR) { |
|
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
2643 return NULL; |
|
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
2644 } |
|
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
2645 if (_tk_exists == NULL || strcmp(_tk_exists, "1") != 0) { |
|
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
2646 if (Tk_Init(interp) == TCL_ERROR) { |
|
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
2647 PyErr_SetString(Tkinter_TclError, Tcl_GetStringResult(Tkapp_Interp(self))); |
|
38067
efeebc8770e5
Work around deadlock risk.
Martin v. Löwis <martin@v.loewis.de>
parents:
36872
diff
changeset
|
2648 has_failed = 1; |
|
31547
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
2649 return NULL; |
|
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
2650 } |
|
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
2651 } |
|
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
2652 Py_INCREF(Py_None); |
|
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
2653 return Py_None; |
|
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
2654 } |
| 4968 | 2655 |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
2656 static PyObject * |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
2657 Tkapp_WantObjects(PyObject *self, PyObject *args) |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
2658 { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
2659 |
|
29472
1ab9978123be
Properly deal with tuples in Open._fixresult. Fixes bug reported in
Martin v. Löwis <martin@v.loewis.de>
parents:
29295
diff
changeset
|
2660 int wantobjects = -1; |
|
1ab9978123be
Properly deal with tuples in Open._fixresult. Fixes bug reported in
Martin v. Löwis <martin@v.loewis.de>
parents:
29295
diff
changeset
|
2661 if (!PyArg_ParseTuple(args, "|i:wantobjects", &wantobjects)) |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
2662 return NULL; |
|
29472
1ab9978123be
Properly deal with tuples in Open._fixresult. Fixes bug reported in
Martin v. Löwis <martin@v.loewis.de>
parents:
29295
diff
changeset
|
2663 if (wantobjects == -1) |
|
1ab9978123be
Properly deal with tuples in Open._fixresult. Fixes bug reported in
Martin v. Löwis <martin@v.loewis.de>
parents:
29295
diff
changeset
|
2664 return PyBool_FromLong(((TkappObject*)self)->wantobjects); |
|
26428
0103f0b75fe2
Rename want_objects to wantobjects throughout, for consistency.
Martin v. Löwis <martin@v.loewis.de>
parents:
26416
diff
changeset
|
2665 ((TkappObject*)self)->wantobjects = wantobjects; |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
2666 |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
2667 Py_INCREF(Py_None); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
2668 return Py_None; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
2669 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
2670 |
|
26814
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
2671 static PyObject * |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
2672 Tkapp_WillDispatch(PyObject *self, PyObject *args) |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
2673 { |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
2674 |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
2675 ((TkappObject*)self)->dispatching = 1; |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
2676 |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
2677 Py_INCREF(Py_None); |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
2678 return Py_None; |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
2679 } |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
2680 |
| 4968 | 2681 |
| 1664 | 2682 /**** Tkapp Method List ****/ |
| 2683 | |
| 2684 static PyMethodDef Tkapp_methods[] = | |
| 2685 { | |
|
26814
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
2686 {"willdispatch", Tkapp_WillDispatch, METH_NOARGS}, |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
2687 {"wantobjects", Tkapp_WantObjects, METH_VARARGS}, |
|
21757
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2688 {"call", Tkapp_Call, METH_OLDARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2689 {"globalcall", Tkapp_GlobalCall, METH_OLDARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2690 {"eval", Tkapp_Eval, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2691 {"globaleval", Tkapp_GlobalEval, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2692 {"evalfile", Tkapp_EvalFile, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2693 {"record", Tkapp_Record, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2694 {"adderrorinfo", Tkapp_AddErrorInfo, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2695 {"setvar", Tkapp_SetVar, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2696 {"globalsetvar", Tkapp_GlobalSetVar, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2697 {"getvar", Tkapp_GetVar, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2698 {"globalgetvar", Tkapp_GlobalGetVar, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2699 {"unsetvar", Tkapp_UnsetVar, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2700 {"globalunsetvar", Tkapp_GlobalUnsetVar, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2701 {"getint", Tkapp_GetInt, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2702 {"getdouble", Tkapp_GetDouble, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2703 {"getboolean", Tkapp_GetBoolean, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2704 {"exprstring", Tkapp_ExprString, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2705 {"exprlong", Tkapp_ExprLong, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2706 {"exprdouble", Tkapp_ExprDouble, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2707 {"exprboolean", Tkapp_ExprBoolean, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2708 {"splitlist", Tkapp_SplitList, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2709 {"split", Tkapp_Split, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2710 {"merge", Tkapp_Merge, METH_OLDARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2711 {"createcommand", Tkapp_CreateCommand, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2712 {"deletecommand", Tkapp_DeleteCommand, METH_VARARGS}, |
|
6026
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
2713 #ifdef HAVE_CREATEFILEHANDLER |
|
21757
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2714 {"createfilehandler", Tkapp_CreateFileHandler, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2715 {"deletefilehandler", Tkapp_DeleteFileHandler, METH_VARARGS}, |
|
5954
d3835a6a18c9
Rather unsatisfactory temporary hack to get it to run
Guido van Rossum <guido@python.org>
parents:
5947
diff
changeset
|
2716 #endif |
|
21757
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2717 {"createtimerhandler", Tkapp_CreateTimerHandler, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2718 {"mainloop", Tkapp_MainLoop, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2719 {"dooneevent", Tkapp_DoOneEvent, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2720 {"quit", Tkapp_Quit, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2721 {"interpaddr", Tkapp_InterpAddr, METH_VARARGS}, |
|
31549
3da6c2adad34
Remove gcc warning from using "main". Use METH_NOARGS instead of METH_VARARGS
Neal Norwitz <nnorwitz@gmail.com>
parents:
31547
diff
changeset
|
2722 {"loadtk", Tkapp_TkInit, METH_NOARGS}, |
| 4968 | 2723 {NULL, NULL} |
| 1664 | 2724 }; |
| 2725 | |
| 4968 | 2726 |
| 2727 | |
| 1664 | 2728 /**** Tkapp Type Methods ****/ |
| 2729 | |
| 2730 static void | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2731 Tkapp_Dealloc(PyObject *self) |
| 1664 | 2732 { |
|
26971
4c03a4fad72e
Eliminate C++ comment.
Martin v. Löwis <martin@v.loewis.de>
parents:
26858
diff
changeset
|
2733 /*CHECK_TCL_APPARTMENT;*/ |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2734 ENTER_TCL |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2735 Tcl_DeleteInterp(Tkapp_Interp(self)); |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2736 LEAVE_TCL |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12513
diff
changeset
|
2737 PyObject_Del(self); |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2738 DisableEventHook(); |
| 1664 | 2739 } |
| 2740 | |
| 2741 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2742 Tkapp_GetAttr(PyObject *self, char *name) |
| 1664 | 2743 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2744 return Py_FindMethod(Tkapp_methods, self, name); |
| 1664 | 2745 } |
| 2746 | |
| 2747 static PyTypeObject Tkapp_Type = | |
| 2748 { | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2749 PyObject_HEAD_INIT(NULL) |
| 4968 | 2750 0, /*ob_size */ |
| 2751 "tkapp", /*tp_name */ | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2752 sizeof(TkappObject), /*tp_basicsize */ |
| 4968 | 2753 0, /*tp_itemsize */ |
| 2754 Tkapp_Dealloc, /*tp_dealloc */ | |
| 2755 0, /*tp_print */ | |
| 2756 Tkapp_GetAttr, /*tp_getattr */ | |
| 2757 0, /*tp_setattr */ | |
| 2758 0, /*tp_compare */ | |
| 2759 0, /*tp_repr */ | |
| 2760 0, /*tp_as_number */ | |
| 2761 0, /*tp_as_sequence */ | |
| 2762 0, /*tp_as_mapping */ | |
| 2763 0, /*tp_hash */ | |
| 1664 | 2764 }; |
| 2765 | |
| 4968 | 2766 |
| 2767 | |
| 1664 | 2768 /**** Tkinter Module ****/ |
| 2769 | |
| 12953 | 2770 typedef struct { |
| 2771 PyObject* tuple; | |
| 2772 int size; /* current size */ | |
| 2773 int maxsize; /* allocated size */ | |
| 2774 } FlattenContext; | |
| 2775 | |
| 2776 static int | |
| 2777 _bump(FlattenContext* context, int size) | |
| 2778 { | |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
2779 /* expand tuple to hold (at least) size new items. |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
2780 return true if successful, false if an exception was raised */ |
| 12953 | 2781 |
| 2782 int maxsize = context->maxsize * 2; | |
| 2783 | |
| 2784 if (maxsize < context->size + size) | |
| 2785 maxsize = context->size + size; | |
| 2786 | |
| 2787 context->maxsize = maxsize; | |
| 2788 | |
|
17976
d579a5d8b3fe
Cruft cleanup: Removed the unused last_is_sticky argument from the internal
Tim Peters <tim.peters@gmail.com>
parents:
15356
diff
changeset
|
2789 return _PyTuple_Resize(&context->tuple, maxsize) >= 0; |
| 12953 | 2790 } |
| 2791 | |
| 2792 static int | |
|
12958
3c6641c810db
Patch from Michael Hudson to fix flatten recursive data structures:
Andrew M. Kuchling <amk@amk.ca>
parents:
12953
diff
changeset
|
2793 _flatten1(FlattenContext* context, PyObject* item, int depth) |
| 12953 | 2794 { |
| 2795 /* add tuple or list to argument tuple (recursively) */ | |
| 2796 | |
| 2797 int i, size; | |
| 2798 | |
|
12958
3c6641c810db
Patch from Michael Hudson to fix flatten recursive data structures:
Andrew M. Kuchling <amk@amk.ca>
parents:
12953
diff
changeset
|
2799 if (depth > 1000) { |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
2800 PyErr_SetString(PyExc_ValueError, |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
2801 "nesting too deep in _flatten"); |
|
12958
3c6641c810db
Patch from Michael Hudson to fix flatten recursive data structures:
Andrew M. Kuchling <amk@amk.ca>
parents:
12953
diff
changeset
|
2802 return 0; |
|
3c6641c810db
Patch from Michael Hudson to fix flatten recursive data structures:
Andrew M. Kuchling <amk@amk.ca>
parents:
12953
diff
changeset
|
2803 } else if (PyList_Check(item)) { |
| 12953 | 2804 size = PyList_GET_SIZE(item); |
| 2805 /* preallocate (assume no nesting) */ | |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
2806 if (context->size + size > context->maxsize && |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
2807 !_bump(context, size)) |
| 12953 | 2808 return 0; |
| 2809 /* copy items to output tuple */ | |
| 2810 for (i = 0; i < size; i++) { | |
| 2811 PyObject *o = PyList_GET_ITEM(item, i); | |
| 2812 if (PyList_Check(o) || PyTuple_Check(o)) { | |
|
12958
3c6641c810db
Patch from Michael Hudson to fix flatten recursive data structures:
Andrew M. Kuchling <amk@amk.ca>
parents:
12953
diff
changeset
|
2813 if (!_flatten1(context, o, depth + 1)) |
| 12953 | 2814 return 0; |
| 2815 } else if (o != Py_None) { | |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
2816 if (context->size + 1 > context->maxsize && |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
2817 !_bump(context, 1)) |
| 12953 | 2818 return 0; |
| 2819 Py_INCREF(o); | |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
2820 PyTuple_SET_ITEM(context->tuple, |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
2821 context->size++, o); |
| 12953 | 2822 } |
| 2823 } | |
| 2824 } else if (PyTuple_Check(item)) { | |
| 2825 /* same, for tuples */ | |
| 2826 size = PyTuple_GET_SIZE(item); | |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
2827 if (context->size + size > context->maxsize && |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
2828 !_bump(context, size)) |
| 12953 | 2829 return 0; |
| 2830 for (i = 0; i < size; i++) { | |
| 2831 PyObject *o = PyTuple_GET_ITEM(item, i); | |
| 2832 if (PyList_Check(o) || PyTuple_Check(o)) { | |
|
12958
3c6641c810db
Patch from Michael Hudson to fix flatten recursive data structures:
Andrew M. Kuchling <amk@amk.ca>
parents:
12953
diff
changeset
|
2833 if (!_flatten1(context, o, depth + 1)) |
| 12953 | 2834 return 0; |
| 2835 } else if (o != Py_None) { | |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
2836 if (context->size + 1 > context->maxsize && |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
2837 !_bump(context, 1)) |
| 12953 | 2838 return 0; |
| 2839 Py_INCREF(o); | |
|
15053
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
2840 PyTuple_SET_ITEM(context->tuple, |
|
be4fc8b6e1cb
[ Bug #113803 ] [2.0b1 NT4.0] printing non asci char causes idle to abort
Guido van Rossum <guido@python.org>
parents:
15036
diff
changeset
|
2841 context->size++, o); |
| 12953 | 2842 } |
| 2843 } | |
| 2844 } else { | |
| 2845 PyErr_SetString(PyExc_TypeError, "argument must be sequence"); | |
| 2846 return 0; | |
| 2847 } | |
| 2848 return 1; | |
| 2849 } | |
| 2850 | |
| 2851 static PyObject * | |
| 2852 Tkinter_Flatten(PyObject* self, PyObject* args) | |
| 2853 { | |
| 2854 FlattenContext context; | |
| 2855 PyObject* item; | |
| 2856 | |
| 2857 if (!PyArg_ParseTuple(args, "O:_flatten", &item)) | |
| 2858 return NULL; | |
| 2859 | |
|
13576
61e4c29d53d8
replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13503
diff
changeset
|
2860 context.maxsize = PySequence_Size(item); |
| 12953 | 2861 if (context.maxsize <= 0) |
| 2862 return PyTuple_New(0); | |
| 2863 | |
| 2864 context.tuple = PyTuple_New(context.maxsize); | |
| 2865 if (!context.tuple) | |
| 2866 return NULL; | |
| 2867 | |
| 2868 context.size = 0; | |
| 2869 | |
|
12958
3c6641c810db
Patch from Michael Hudson to fix flatten recursive data structures:
Andrew M. Kuchling <amk@amk.ca>
parents:
12953
diff
changeset
|
2870 if (!_flatten1(&context, item,0)) |
| 12953 | 2871 return NULL; |
| 2872 | |
|
17976
d579a5d8b3fe
Cruft cleanup: Removed the unused last_is_sticky argument from the internal
Tim Peters <tim.peters@gmail.com>
parents:
15356
diff
changeset
|
2873 if (_PyTuple_Resize(&context.tuple, context.size)) |
| 12953 | 2874 return NULL; |
| 2875 | |
| 2876 return context.tuple; | |
| 2877 } | |
| 2878 | |
| 1664 | 2879 static PyObject * |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13593
diff
changeset
|
2880 Tkinter_Create(PyObject *self, PyObject *args) |
| 1664 | 2881 { |
| 4968 | 2882 char *screenName = NULL; |
| 2883 char *baseName = NULL; | |
| 2884 char *className = NULL; | |
| 2885 int interactive = 0; | |
|
26428
0103f0b75fe2
Rename want_objects to wantobjects throughout, for consistency.
Martin v. Löwis <martin@v.loewis.de>
parents:
26416
diff
changeset
|
2886 int wantobjects = 0; |
|
31547
470f95ad6750
Implementation of patch 869468
David Ascher <david.ascher@gmail.com>
parents:
30979
diff
changeset
|
2887 int wantTk = 1; /* If false, then Tk_Init() doesn't get called */ |
|
32942
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
2888 int sync = 0; /* pass -sync to wish */ |
|
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
2889 char *use = NULL; /* pass -use to wish */ |
| 1664 | 2890 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2891 baseName = strrchr(Py_GetProgramName(), '/'); |
| 4968 | 2892 if (baseName != NULL) |
| 2893 baseName++; | |
| 2894 else | |
| 2895 baseName = Py_GetProgramName(); | |
| 2896 className = "Tk"; | |
| 1664 | 2897 |
|
32942
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
2898 if (!PyArg_ParseTuple(args, "|zssiiiiz:create", |
| 4968 | 2899 &screenName, &baseName, &className, |
|
32942
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
2900 &interactive, &wantobjects, &wantTk, |
|
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
2901 &sync, &use)) |
| 4968 | 2902 return NULL; |
| 1664 | 2903 |
| 4968 | 2904 return (PyObject *) Tkapp_New(screenName, baseName, className, |
|
32942
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
2905 interactive, wantobjects, wantTk, |
|
63df4cb492a1
Patch #986929: Add support for wish -sync and -use options.
Martin v. Löwis <martin@v.loewis.de>
parents:
31549
diff
changeset
|
2906 sync, use); |
| 1664 | 2907 } |
| 2908 | |
|
29038
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2909 static PyObject * |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2910 Tkinter_setbusywaitinterval(PyObject *self, PyObject *args) |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2911 { |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2912 int new_val; |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2913 if (!PyArg_ParseTuple(args, "i:setbusywaitinterval", &new_val)) |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2914 return NULL; |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2915 if (new_val < 0) { |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2916 PyErr_SetString(PyExc_ValueError, |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2917 "busywaitinterval must be >= 0"); |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2918 return NULL; |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2919 } |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2920 Tkinter_busywaitinterval = new_val; |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2921 Py_INCREF(Py_None); |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2922 return Py_None; |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2923 } |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2924 |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2925 static char setbusywaitinterval_doc[] = |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2926 "setbusywaitinterval(n) -> None\n\ |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2927 \n\ |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2928 Set the busy-wait interval in milliseconds between successive\n\ |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2929 calls to Tcl_DoOneEvent in a threaded Python interpreter.\n\ |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2930 It should be set to a divisor of the maximum time between\n\ |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2931 frames in an animation."; |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2932 |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2933 static PyObject * |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2934 Tkinter_getbusywaitinterval(PyObject *self, PyObject *args) |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2935 { |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2936 return PyInt_FromLong(Tkinter_busywaitinterval); |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2937 } |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2938 |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2939 static char getbusywaitinterval_doc[] = |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2940 "getbusywaitinterval() -> int\n\ |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2941 \n\ |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2942 Return the current busy-wait interval between successive\n\ |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2943 calls to Tcl_DoOneEvent in a threaded Python interpreter."; |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2944 |
| 1664 | 2945 static PyMethodDef moduleMethods[] = |
| 2946 { | |
|
21757
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2947 {"_flatten", Tkinter_Flatten, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2948 {"create", Tkinter_Create, METH_VARARGS}, |
|
6026
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
2949 #ifdef HAVE_CREATEFILEHANDLER |
|
21757
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2950 {"createfilehandler", Tkapp_CreateFileHandler, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2951 {"deletefilehandler", Tkapp_DeleteFileHandler, METH_VARARGS}, |
|
5954
d3835a6a18c9
Rather unsatisfactory temporary hack to get it to run
Guido van Rossum <guido@python.org>
parents:
5947
diff
changeset
|
2952 #endif |
|
21757
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2953 {"createtimerhandler", Tkapp_CreateTimerHandler, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2954 {"mainloop", Tkapp_MainLoop, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2955 {"dooneevent", Tkapp_DoOneEvent, METH_VARARGS}, |
|
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2956 {"quit", Tkapp_Quit, METH_VARARGS}, |
|
29038
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2957 {"setbusywaitinterval",Tkinter_setbusywaitinterval, METH_VARARGS, |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2958 setbusywaitinterval_doc}, |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2959 {"getbusywaitinterval",(PyCFunction)Tkinter_getbusywaitinterval, |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2960 METH_NOARGS, getbusywaitinterval_doc}, |
| 4968 | 2961 {NULL, NULL} |
| 1664 | 2962 }; |
| 2963 | |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2964 #ifdef WAIT_FOR_STDIN |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2965 |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2966 static int stdin_ready = 0; |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2967 |
|
8499
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
2968 #ifndef MS_WINDOWS |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2969 static void |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2970 MyFileProc(void *clientData, int mask) |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2971 { |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2972 stdin_ready = 1; |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2973 } |
|
8499
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
2974 #endif |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2975 |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
2976 #ifdef WITH_THREAD |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2977 static PyThreadState *event_tstate = NULL; |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
2978 #endif |
|
6438
9e46ecf03c3e
Fix EventHook (the trick to make widgets appear when using GNU
Guido van Rossum <guido@python.org>
parents:
6343
diff
changeset
|
2979 |
| 1664 | 2980 static int |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13593
diff
changeset
|
2981 EventHook(void) |
| 1664 | 2982 { |
|
8499
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
2983 #ifndef MS_WINDOWS |
|
12071
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
2984 int tfile; |
|
8499
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
2985 #endif |
|
9488
b0ca2ca586b1
RajGopal Srinivasan noted that the latest code doesn't work when
Guido van Rossum <guido@python.org>
parents:
9327
diff
changeset
|
2986 #ifdef WITH_THREAD |
|
8499
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
2987 PyEval_RestoreThread(event_tstate); |
|
9488
b0ca2ca586b1
RajGopal Srinivasan noted that the latest code doesn't work when
Guido van Rossum <guido@python.org>
parents:
9327
diff
changeset
|
2988 #endif |
|
8499
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
2989 stdin_ready = 0; |
|
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
2990 errorInCmd = 0; |
|
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
2991 #ifndef MS_WINDOWS |
|
12071
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
2992 tfile = fileno(stdin); |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2993 Tcl_CreateFileHandler(tfile, TCL_READABLE, MyFileProc, NULL); |
|
8499
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
2994 #endif |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2995 while (!errorInCmd && !stdin_ready) { |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2996 int result; |
|
8499
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
2997 #ifdef MS_WINDOWS |
|
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
2998 if (_kbhit()) { |
|
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
2999 stdin_ready = 1; |
|
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
3000 break; |
|
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
3001 } |
|
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
3002 #endif |
|
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
3003 #if defined(WITH_THREAD) || defined(MS_WINDOWS) |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
3004 Py_BEGIN_ALLOW_THREADS |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
3005 if(tcl_lock)PyThread_acquire_lock(tcl_lock, 1); |
|
9327
c91e4d87f694
Looks like I didn't test this interactively. The EventHook() code was
Guido van Rossum <guido@python.org>
parents:
9319
diff
changeset
|
3006 tcl_tstate = event_tstate; |
|
9319
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
3007 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
3008 result = Tcl_DoOneEvent(TCL_DONT_WAIT); |
|
9319
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
3009 |
|
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
3010 tcl_tstate = NULL; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
3011 if(tcl_lock)PyThread_release_lock(tcl_lock); |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
3012 if (result == 0) |
|
29038
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
3013 Sleep(Tkinter_busywaitinterval); |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
3014 Py_END_ALLOW_THREADS |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
3015 #else |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
3016 result = Tcl_DoOneEvent(0); |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
3017 #endif |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
3018 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
3019 if (result < 0) |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
3020 break; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
3021 } |
|
8499
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
3022 #ifndef MS_WINDOWS |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
3023 Tcl_DeleteFileHandler(tfile); |
|
8499
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
3024 #endif |
| 4968 | 3025 if (errorInCmd) { |
| 3026 errorInCmd = 0; | |
| 3027 PyErr_Restore(excInCmd, valInCmd, trbInCmd); | |
| 3028 excInCmd = valInCmd = trbInCmd = NULL; | |
| 3029 PyErr_Print(); | |
| 3030 } | |
|
9488
b0ca2ca586b1
RajGopal Srinivasan noted that the latest code doesn't work when
Guido van Rossum <guido@python.org>
parents:
9327
diff
changeset
|
3031 #ifdef WITH_THREAD |
|
8499
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
3032 PyEval_SaveThread(); |
|
9488
b0ca2ca586b1
RajGopal Srinivasan noted that the latest code doesn't work when
Guido van Rossum <guido@python.org>
parents:
9327
diff
changeset
|
3033 #endif |
| 4968 | 3034 return 0; |
| 1664 | 3035 } |
| 3036 | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
3037 #endif |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
3038 |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
3039 static void |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13593
diff
changeset
|
3040 EnableEventHook(void) |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
3041 { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
3042 #ifdef WAIT_FOR_STDIN |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
3043 if (PyOS_InputHook == NULL) { |
|
9488
b0ca2ca586b1
RajGopal Srinivasan noted that the latest code doesn't work when
Guido van Rossum <guido@python.org>
parents:
9327
diff
changeset
|
3044 #ifdef WITH_THREAD |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
3045 event_tstate = PyThreadState_Get(); |
|
9488
b0ca2ca586b1
RajGopal Srinivasan noted that the latest code doesn't work when
Guido van Rossum <guido@python.org>
parents:
9327
diff
changeset
|
3046 #endif |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
3047 PyOS_InputHook = EventHook; |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
3048 } |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
3049 #endif |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
3050 } |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
3051 |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
3052 static void |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13593
diff
changeset
|
3053 DisableEventHook(void) |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
3054 { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
3055 #ifdef WAIT_FOR_STDIN |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
3056 if (Tk_GetNumMainWindows() == 0 && PyOS_InputHook == EventHook) { |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
3057 PyOS_InputHook = NULL; |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
3058 } |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
3059 #endif |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
3060 } |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
3061 |
| 4968 | 3062 |
| 3063 /* all errors will be checked in one fell swoop in init_tkinter() */ | |
| 3064 static void | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
3065 ins_long(PyObject *d, char *name, long val) |
| 4968 | 3066 { |
| 3067 PyObject *v = PyInt_FromLong(val); | |
| 3068 if (v) { | |
| 3069 PyDict_SetItemString(d, name, v); | |
| 3070 Py_DECREF(v); | |
| 3071 } | |
| 3072 } | |
| 3073 static void | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
3074 ins_string(PyObject *d, char *name, char *val) |
| 4968 | 3075 { |
| 3076 PyObject *v = PyString_FromString(val); | |
| 3077 if (v) { | |
| 3078 PyDict_SetItemString(d, name, v); | |
| 3079 Py_DECREF(v); | |
| 3080 } | |
| 3081 } | |
| 3082 | |
| 3083 | |
|
24363
979ff5d0ae07
Replace DL_IMPORT with PyMODINIT_FUNC and remove "/export:init..." link
Mark Hammond <mhammond@skippinet.com.au>
parents:
24280
diff
changeset
|
3084 PyMODINIT_FUNC |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13593
diff
changeset
|
3085 init_tkinter(void) |
| 1664 | 3086 { |
| 4968 | 3087 PyObject *m, *d; |
| 1664 | 3088 |
| 4968 | 3089 Tkapp_Type.ob_type = &PyType_Type; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
3090 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
3091 #ifdef WITH_THREAD |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
3092 tcl_lock = PyThread_allocate_lock(); |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
3093 #endif |
|
4091
dc946cab7b9b
Hacks to support being a Windows DLL
Guido van Rossum <guido@python.org>
parents:
4079
diff
changeset
|
3094 |
| 4968 | 3095 m = Py_InitModule("_tkinter", moduleMethods); |
| 1664 | 3096 |
| 4968 | 3097 d = PyModule_GetDict(m); |
|
23662
27e2120cb476
Fix SF bug #557436, TclError is a str should be an Exception
Neal Norwitz <nnorwitz@gmail.com>
parents:
22706
diff
changeset
|
3098 Tkinter_TclError = PyErr_NewException("_tkinter.TclError", NULL, NULL); |
| 4968 | 3099 PyDict_SetItemString(d, "TclError", Tkinter_TclError); |
| 3100 | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
3101 ins_long(d, "READABLE", TCL_READABLE); |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
3102 ins_long(d, "WRITABLE", TCL_WRITABLE); |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
3103 ins_long(d, "EXCEPTION", TCL_EXCEPTION); |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
3104 ins_long(d, "WINDOW_EVENTS", TCL_WINDOW_EVENTS); |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
3105 ins_long(d, "FILE_EVENTS", TCL_FILE_EVENTS); |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
3106 ins_long(d, "TIMER_EVENTS", TCL_TIMER_EVENTS); |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
3107 ins_long(d, "IDLE_EVENTS", TCL_IDLE_EVENTS); |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
3108 ins_long(d, "ALL_EVENTS", TCL_ALL_EVENTS); |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
3109 ins_long(d, "DONT_WAIT", TCL_DONT_WAIT); |
| 4968 | 3110 ins_string(d, "TK_VERSION", TK_VERSION); |
| 3111 ins_string(d, "TCL_VERSION", TCL_VERSION); | |
| 1664 | 3112 |
|
6311
13fbd98d81cc
Export names for the types defined by this module: TkappType and TkttType.
Guido van Rossum <guido@python.org>
parents:
6265
diff
changeset
|
3113 PyDict_SetItemString(d, "TkappType", (PyObject *)&Tkapp_Type); |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
3114 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
3115 Tktt_Type.ob_type = &PyType_Type; |
|
6311
13fbd98d81cc
Export names for the types defined by this module: TkappType and TkttType.
Guido van Rossum <guido@python.org>
parents:
6265
diff
changeset
|
3116 PyDict_SetItemString(d, "TkttType", (PyObject *)&Tktt_Type); |
|
13fbd98d81cc
Export names for the types defined by this module: TkappType and TkttType.
Guido van Rossum <guido@python.org>
parents:
6265
diff
changeset
|
3117 |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
3118 PyTclObject_Type.ob_type = &PyType_Type; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
3119 PyDict_SetItemString(d, "Tcl_Obj", (PyObject *)&PyTclObject_Type); |
|
21322
1852caba7014
Mods by Tony Lownds (patch 490100, slightly massaged by me) to make Tkinter
Jack Jansen <jack.jansen@cwi.nl>
parents:
21073
diff
changeset
|
3120 |
|
1852caba7014
Mods by Tony Lownds (patch 490100, slightly massaged by me) to make Tkinter
Jack Jansen <jack.jansen@cwi.nl>
parents:
21073
diff
changeset
|
3121 #ifdef TK_AQUA |
|
1852caba7014
Mods by Tony Lownds (patch 490100, slightly massaged by me) to make Tkinter
Jack Jansen <jack.jansen@cwi.nl>
parents:
21073
diff
changeset
|
3122 /* Tk_MacOSXSetupTkNotifier must be called before Tcl's subsystems |
|
1852caba7014
Mods by Tony Lownds (patch 490100, slightly massaged by me) to make Tkinter
Jack Jansen <jack.jansen@cwi.nl>
parents:
21073
diff
changeset
|
3123 * start waking up. Note that Tcl_FindExecutable will do this, this |
|
1852caba7014
Mods by Tony Lownds (patch 490100, slightly massaged by me) to make Tkinter
Jack Jansen <jack.jansen@cwi.nl>
parents:
21073
diff
changeset
|
3124 * code must be above it! The original warning from |
|
1852caba7014
Mods by Tony Lownds (patch 490100, slightly massaged by me) to make Tkinter
Jack Jansen <jack.jansen@cwi.nl>
parents:
21073
diff
changeset
|
3125 * tkMacOSXAppInit.c is copied below. |
|
1852caba7014
Mods by Tony Lownds (patch 490100, slightly massaged by me) to make Tkinter
Jack Jansen <jack.jansen@cwi.nl>
parents:
21073
diff
changeset
|
3126 * |
|
1852caba7014
Mods by Tony Lownds (patch 490100, slightly massaged by me) to make Tkinter
Jack Jansen <jack.jansen@cwi.nl>
parents:
21073
diff
changeset
|
3127 * NB - You have to swap in the Tk Notifier BEFORE you start up the |
|
1852caba7014
Mods by Tony Lownds (patch 490100, slightly massaged by me) to make Tkinter
Jack Jansen <jack.jansen@cwi.nl>
parents:
21073
diff
changeset
|
3128 * Tcl interpreter for now. It probably should work to do this |
|
1852caba7014
Mods by Tony Lownds (patch 490100, slightly massaged by me) to make Tkinter
Jack Jansen <jack.jansen@cwi.nl>
parents:
21073
diff
changeset
|
3129 * in the other order, but for now it doesn't seem to. |
|
1852caba7014
Mods by Tony Lownds (patch 490100, slightly massaged by me) to make Tkinter
Jack Jansen <jack.jansen@cwi.nl>
parents:
21073
diff
changeset
|
3130 * |
|
1852caba7014
Mods by Tony Lownds (patch 490100, slightly massaged by me) to make Tkinter
Jack Jansen <jack.jansen@cwi.nl>
parents:
21073
diff
changeset
|
3131 */ |
|
1852caba7014
Mods by Tony Lownds (patch 490100, slightly massaged by me) to make Tkinter
Jack Jansen <jack.jansen@cwi.nl>
parents:
21073
diff
changeset
|
3132 Tk_MacOSXSetupTkNotifier(); |
|
1852caba7014
Mods by Tony Lownds (patch 490100, slightly massaged by me) to make Tkinter
Jack Jansen <jack.jansen@cwi.nl>
parents:
21073
diff
changeset
|
3133 #endif |
|
1852caba7014
Mods by Tony Lownds (patch 490100, slightly massaged by me) to make Tkinter
Jack Jansen <jack.jansen@cwi.nl>
parents:
21073
diff
changeset
|
3134 |
|
1852caba7014
Mods by Tony Lownds (patch 490100, slightly massaged by me) to make Tkinter
Jack Jansen <jack.jansen@cwi.nl>
parents:
21073
diff
changeset
|
3135 |
|
12063
ca8880cf3674
Add a call to Tcl_FindExecutable(). This was inspired by a patch by
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
3136 /* This helps the dynamic loader; in Unicode aware Tcl versions |
|
ca8880cf3674
Add a call to Tcl_FindExecutable(). This was inspired by a patch by
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
3137 it also helps Tcl find its encodings. */ |
|
ca8880cf3674
Add a call to Tcl_FindExecutable(). This was inspired by a patch by
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
3138 Tcl_FindExecutable(Py_GetProgramName()); |
|
ca8880cf3674
Add a call to Tcl_FindExecutable(). This was inspired by a patch by
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
3139 |
| 4968 | 3140 if (PyErr_Occurred()) |
|
7212
b9bbfa169920
Register Tcl_Finalize as a Python exit handler.
Guido van Rossum <guido@python.org>
parents:
6478
diff
changeset
|
3141 return; |
|
b9bbfa169920
Register Tcl_Finalize as a Python exit handler.
Guido van Rossum <guido@python.org>
parents:
6478
diff
changeset
|
3142 |
|
8670
07e47370fcb8
Temporarily get rid of the registration of Tcl_Finalize() as a
Guido van Rossum <guido@python.org>
parents:
8639
diff
changeset
|
3143 #if 0 |
|
07e47370fcb8
Temporarily get rid of the registration of Tcl_Finalize() as a
Guido van Rossum <guido@python.org>
parents:
8639
diff
changeset
|
3144 /* This was not a good idea; through <Destroy> bindings, |
|
07e47370fcb8
Temporarily get rid of the registration of Tcl_Finalize() as a
Guido van Rossum <guido@python.org>
parents:
8639
diff
changeset
|
3145 Tcl_Finalize() may invoke Python code but at that point the |
|
07e47370fcb8
Temporarily get rid of the registration of Tcl_Finalize() as a
Guido van Rossum <guido@python.org>
parents:
8639
diff
changeset
|
3146 interpreter and thread state have already been destroyed! */ |
|
7212
b9bbfa169920
Register Tcl_Finalize as a Python exit handler.
Guido van Rossum <guido@python.org>
parents:
6478
diff
changeset
|
3147 Py_AtExit(Tcl_Finalize); |
|
8096
8c1f161c6c8c
Add #ifdefs so Tcl_Finalize isn't referenced when it's not defined.
Guido van Rossum <guido@python.org>
parents:
7982
diff
changeset
|
3148 #endif |
|
7212
b9bbfa169920
Register Tcl_Finalize as a Python exit handler.
Guido van Rossum <guido@python.org>
parents:
6478
diff
changeset
|
3149 |
| 1664 | 3150 } |
