Mercurial > cpython-lru_cache-weakref
annotate Modules/_tkinter.c @ 29500:aa84ede1c364 legacy-trunk
Add item about new threading module functions.
| author | Jeremy Hylton <jeremy@alum.mit.edu> |
|---|---|
| date | Mon, 16 Jun 2003 20:38:15 +0000 |
| parents | 1ab9978123be |
| children | a3015bba3999 |
| 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 |
|
4079
a6e62c21b0e3
Add #define MAC_TCL for Mac.
Guido van Rossum <guido@python.org>
parents:
4005
diff
changeset
|
36 #ifdef macintosh |
|
a6e62c21b0e3
Add #define MAC_TCL for Mac.
Guido van Rossum <guido@python.org>
parents:
4005
diff
changeset
|
37 #define MAC_TCL |
|
9203
07dae6fdae79
Renamed thread.h to pythread.h.
Guido van Rossum <guido@python.org>
parents:
9128
diff
changeset
|
38 #endif |
|
07dae6fdae79
Renamed thread.h to pythread.h.
Guido van Rossum <guido@python.org>
parents:
9128
diff
changeset
|
39 |
|
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
|
40 /* 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
|
41 #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
|
42 #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
|
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 |
|
c30f97287602
Wrap doc strings in PyDoc_STRVAR. Fix .string docstring. Provide default
Martin v. Löwis <martin@v.loewis.de>
parents:
27069
diff
changeset
|
45 #ifndef PyMODINIT_FUNC |
| 27084 | 46 #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
|
47 #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
|
48 |
|
28444
2405371be34c
Fake bool API for Python 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
28156
diff
changeset
|
49 #ifndef PyBool_Check |
|
2405371be34c
Fake bool API for Python 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
28156
diff
changeset
|
50 #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
|
51 #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
|
52 #endif |
|
2405371be34c
Fake bool API for Python 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents:
28156
diff
changeset
|
53 |
|
25527
5420969ddd70
Eliminate constness warnings with Tcl 8.4.
Martin v. Löwis <martin@v.loewis.de>
parents:
25525
diff
changeset
|
54 /* 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
|
55 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
|
56 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
|
57 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
|
58 anymore, this should go. */ |
|
5420969ddd70
Eliminate constness warnings with Tcl 8.4.
Martin v. Löwis <martin@v.loewis.de>
parents:
25525
diff
changeset
|
59 #define USE_COMPAT_CONST |
|
5420969ddd70
Eliminate constness warnings with Tcl 8.4.
Martin v. Löwis <martin@v.loewis.de>
parents:
25525
diff
changeset
|
60 |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
61 /* 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
|
62 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
|
63 Tcl are empty. */ |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
64 #define TCL_THREADS |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
65 |
|
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
|
66 #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
|
67 #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
|
68 #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
|
69 #else |
| 1664 | 70 #include <tcl.h> |
| 71 #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
|
72 #endif |
| 1664 | 73 |
|
26989
bcbd94c610e8
Patch #660485: Cygwin _tkinter Tcl/Tk 8.3 patch
Jason Tishler <jason@tishler.net>
parents:
26971
diff
changeset
|
74 /* 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
|
75 #ifndef CONST84_RETURN |
|
b4ca5b9ba933
Silence cast warnings for Tcl 8.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
26814
diff
changeset
|
76 #define CONST84_RETURN |
|
26989
bcbd94c610e8
Patch #660485: Cygwin _tkinter Tcl/Tk 8.3 patch
Jason Tishler <jason@tishler.net>
parents:
26971
diff
changeset
|
77 #undef CONST |
|
26858
b4ca5b9ba933
Silence cast warnings for Tcl 8.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
26814
diff
changeset
|
78 #define CONST |
|
b4ca5b9ba933
Silence cast warnings for Tcl 8.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
26814
diff
changeset
|
79 #endif |
|
b4ca5b9ba933
Silence cast warnings for Tcl 8.3.
Martin v. Löwis <martin@v.loewis.de>
parents:
26814
diff
changeset
|
80 |
|
5913
6b39f8633ca5
Compatibility with Tcl/Tk 8.0b*.
Guido van Rossum <guido@python.org>
parents:
5866
diff
changeset
|
81 #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
|
82 |
|
25525
2e140700fb6c
Drop support for Tk 8.0 and 8.1.
Martin v. Löwis <martin@v.loewis.de>
parents:
24363
diff
changeset
|
83 #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
|
84 #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
|
85 #endif |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
86 |
|
25530
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
87 /* 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
|
88 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
|
89 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
|
90 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
|
91 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
|
92 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
|
93 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
|
94 */ |
|
ca2482012b3c
Support UCS-4 Tcl for UCS-4 Python builds. Fixes #719880.
Martin v. Löwis <martin@v.loewis.de>
parents:
28622
diff
changeset
|
95 #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
|
96 #error "unsupported Tcl configuration" |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
97 #endif |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
98 |
|
12071
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
99 #if defined(macintosh) |
|
6026
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
100 /* Sigh, we have to include this to get at the tcl qd pointer */ |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
101 #include <tkMac.h> |
|
8185
929b7e6e7520
On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents:
8096
diff
changeset
|
102 /* And this one we need to clear the menu bar */ |
|
929b7e6e7520
On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents:
8096
diff
changeset
|
103 #include <Menus.h> |
|
6026
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
104 #endif |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
105 |
|
18637
05cf6b3e63de
File handlers don't work on the mac, so don't pretend they do. I guess this is a 2.1.1 candidate, if it isn't too late for that.
Jack Jansen <jack.jansen@cwi.nl>
parents:
17976
diff
changeset
|
106 #if !(defined(MS_WINDOWS) || defined(__CYGWIN__) || defined(macintosh)) |
|
05cf6b3e63de
File handlers don't work on the mac, so don't pretend they do. I guess this is a 2.1.1 candidate, if it isn't too late for that.
Jack Jansen <jack.jansen@cwi.nl>
parents:
17976
diff
changeset
|
107 /* Mac has it, but it doesn't really work:-( */ |
|
6026
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
108 #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
|
109 #endif |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
110 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
111 #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
|
112 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
113 /* 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
|
114 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
|
115 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
|
116 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
|
117 |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
118 #ifdef MS_WINDOWS |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
119 #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
|
120 #else |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
121 #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
|
122 #endif |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
123 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
124 /* 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
|
125 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
|
126 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
127 #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
|
128 #define WAIT_FOR_STDIN |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
129 #endif |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
130 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
131 #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
|
132 |
|
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
|
133 #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
|
134 #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
|
135 #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
|
136 #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
|
137 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
138 #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
|
139 |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
140 /* 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
|
141 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
|
142 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
|
143 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
|
144 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
|
145 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
146 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
|
147 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
|
148 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
|
149 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
150 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
|
151 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
|
152 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
|
153 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
|
154 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
|
155 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
|
156 |
|
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
|
157 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
|
158 (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
|
159 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
|
160 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
|
161 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
|
162 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
|
163 |
|
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
|
164 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
|
165 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
|
166 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
|
167 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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
173 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
|
174 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
|
175 |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
176 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
|
177 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
|
178 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
|
179 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
|
180 _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
|
181 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
|
182 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
|
183 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
|
184 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
185 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
|
186 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
|
187 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
|
188 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
189 */ |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
190 |
|
9679
877d23bd5bdc
Thanks to Chris Herborth, the thread primitives now have proper Py*
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
191 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
|
192 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
193 #ifdef TCL_THREADS |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
194 static Tcl_ThreadDataKey state_key; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
195 typedef PyThreadState *ThreadSpecificData; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
196 #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
|
197 #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
|
198 static PyThreadState *tcl_tstate = NULL; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
199 #endif |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
200 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
201 #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
|
202 { 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
|
203 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
|
204 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
205 #define LEAVE_TCL \ |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
206 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
|
207 |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
208 #define ENTER_OVERLAP \ |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
209 Py_END_ALLOW_THREADS |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
210 |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
211 #define LEAVE_OVERLAP_TCL \ |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
212 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
|
213 |
|
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
|
214 #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
|
215 { 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
|
216 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
|
217 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
218 #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
|
219 { PyThreadState *tstate = PyEval_SaveThread(); \ |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
220 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
|
221 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
222 #define CHECK_TCL_APPARTMENT \ |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
223 if (((TkappObject *)self)->threaded && \ |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
224 ((TkappObject *)self)->thread_id != Tcl_GetCurrentThread()) { \ |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
225 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
|
226 return 0; \ |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
227 } |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
228 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
229 #else |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
230 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
231 #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
|
232 #define LEAVE_TCL |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
233 #define ENTER_OVERLAP |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
234 #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
|
235 #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
|
236 #define LEAVE_PYTHON |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
237 #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
|
238 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
239 #endif |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
240 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
241 #ifdef macintosh |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
242 |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
243 /* |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
244 ** Additional cruft needed by Tcl/Tk on the Mac. |
|
3973
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
245 ** This is for Tcl 7.5 and Tk 4.1 (patch release 1). |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
246 */ |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
247 |
|
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
|
248 /* ckfree() expects a char* */ |
|
3973
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
249 #define FREECAST (char *) |
|
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
250 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
251 #include <Events.h> /* For EventRecord */ |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
252 |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
253 typedef int (*TclMacConvertEventPtr) (EventRecord *eventPtr); |
|
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
|
254 void Tcl_MacSetEventProc(TclMacConvertEventPtr procPtr); |
|
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
|
255 int TkMacConvertEvent(EventRecord *eventPtr); |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
256 |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23662
diff
changeset
|
257 static int PyMacConvertEvent(EventRecord *eventPtr); |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
258 |
|
8185
929b7e6e7520
On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents:
8096
diff
changeset
|
259 #include <SIOUX.h> |
|
929b7e6e7520
On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents:
8096
diff
changeset
|
260 extern int SIOUXIsAppWindow(WindowPtr); |
|
929b7e6e7520
On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents:
8096
diff
changeset
|
261 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
262 #endif /* macintosh */ |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
263 |
|
3973
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
264 #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
|
265 #define FREECAST (char *) |
|
3973
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
266 #endif |
|
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
267 |
| 1664 | 268 /**** Tkapp Object Declaration ****/ |
| 269 | |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23662
diff
changeset
|
270 static PyTypeObject Tkapp_Type; |
| 1664 | 271 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
272 typedef struct { |
| 4968 | 273 PyObject_HEAD |
| 274 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
|
275 int wantobjects; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
276 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
|
277 Tcl_ThreadId thread_id; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
278 int dispatching; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
279 /* 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
|
280 So we cache interesting types here. */ |
|
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
281 Tcl_ObjType *BooleanType; |
|
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
282 Tcl_ObjType *ByteArrayType; |
|
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
283 Tcl_ObjType *DoubleType; |
|
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
284 Tcl_ObjType *IntType; |
|
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
285 Tcl_ObjType *ListType; |
|
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
286 Tcl_ObjType *ProcBodyType; |
|
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
287 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
|
288 } TkappObject; |
| 1664 | 289 |
| 290 #define Tkapp_Check(v) ((v)->ob_type == &Tkapp_Type) | |
| 291 #define Tkapp_Interp(v) (((TkappObject *) (v))->interp) | |
| 15177 | 292 #define Tkapp_Result(v) Tcl_GetStringResult(Tkapp_Interp(v)) |
| 1664 | 293 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
294 #define DEBUG_REFCNT(v) (printf("DEBUG: id=%p, refcnt=%i\n", \ |
| 4968 | 295 (void *) v, ((PyObject *) v)->ob_refcnt)) |
| 1664 | 296 |
| 4968 | 297 |
| 298 | |
| 1664 | 299 /**** Error Handling ****/ |
| 300 | |
| 301 static PyObject *Tkinter_TclError; | |
| 1713 | 302 static int quitMainLoop = 0; |
| 1664 | 303 static int errorInCmd = 0; |
| 304 static PyObject *excInCmd; | |
| 305 static PyObject *valInCmd; | |
|
2055
cf31eab6ab5a
Another bulky set of minor changes.
Guido van Rossum <guido@python.org>
parents:
2009
diff
changeset
|
306 static PyObject *trbInCmd; |
| 1664 | 307 |
| 4968 | 308 |
| 309 | |
| 1664 | 310 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
311 Tkinter_Error(PyObject *v) |
| 1664 | 312 { |
| 4968 | 313 PyErr_SetString(Tkinter_TclError, Tkapp_Result(v)); |
| 314 return NULL; | |
| 1664 | 315 } |
| 316 | |
| 4968 | 317 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
318 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
319 /**** Utils ****/ |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
320 |
|
29038
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
321 static int Tkinter_busywaitinterval = 20; |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
322 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
323 #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
|
324 #ifndef MS_WINDOWS |
|
8987
3e127bca84e7
Need mytime.h for Sleep().
Guido van Rossum <guido@python.org>
parents:
8828
diff
changeset
|
325 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
326 /* 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
|
327 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
328 static void |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
329 Sleep(int milli) |
| 1664 | 330 { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
331 /* 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
|
332 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
|
333 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
|
334 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
|
335 select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t); |
| 1664 | 336 } |
|
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
|
337 #endif /* MS_WINDOWS */ |
| 4968 | 338 |
|
26814
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
339 /* 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
|
340 |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
341 static int |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
342 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
|
343 { |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
344 int i; |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
345 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
|
346 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
|
347 return 1; |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
348 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
|
349 Sleep(100); |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
350 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
|
351 } |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
352 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
|
353 return 1; |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
354 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
|
355 return 0; |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
356 } |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
357 #endif /* WITH_THREAD */ |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
358 |
| 4968 | 359 |
| 1664 | 360 static char * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
361 AsString(PyObject *value, PyObject *tmp) |
| 1664 | 362 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
363 if (PyString_Check(value)) |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
364 return PyString_AsString(value); |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19033
diff
changeset
|
365 #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
|
366 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
|
367 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
|
368 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
|
369 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
|
370 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
|
371 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
|
372 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
|
373 } |
|
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
|
374 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
|
375 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
|
376 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19033
diff
changeset
|
377 #endif |
| 4968 | 378 else { |
| 379 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
|
380 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
|
381 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
|
382 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
|
383 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
|
384 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
|
385 } |
| 4968 | 386 Py_DECREF(v); |
| 387 return PyString_AsString(v); | |
| 388 } | |
| 1664 | 389 } |
| 390 | |
| 4968 | 391 |
| 392 | |
| 1664 | 393 #define ARGSZ 64 |
| 394 | |
| 395 static char * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
396 Merge(PyObject *args) |
| 1664 | 397 { |
| 4968 | 398 PyObject *tmp = NULL; |
| 399 char *argvStore[ARGSZ]; | |
| 400 char **argv = NULL; | |
| 401 int fvStore[ARGSZ]; | |
| 402 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
|
403 int argc = 0, fvc = 0, i; |
| 4968 | 404 char *res = NULL; |
| 405 | |
| 406 if (!(tmp = PyList_New(0))) | |
| 407 return NULL; | |
| 408 | |
| 409 argv = argvStore; | |
| 410 fv = fvStore; | |
| 411 | |
| 412 if (args == NULL) | |
| 413 argc = 0; | |
| 1664 | 414 |
| 4968 | 415 else if (!PyTuple_Check(args)) { |
| 416 argc = 1; | |
| 417 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
|
418 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
|
419 goto finally; |
| 4968 | 420 } |
| 421 else { | |
| 422 argc = PyTuple_Size(args); | |
| 423 | |
| 424 if (argc > ARGSZ) { | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
425 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
|
426 fv = (int *)ckalloc(argc * sizeof(int)); |
| 4968 | 427 if (argv == NULL || fv == NULL) { |
| 428 PyErr_NoMemory(); | |
| 429 goto finally; | |
| 430 } | |
| 431 } | |
| 1664 | 432 |
| 4968 | 433 for (i = 0; i < argc; i++) { |
| 434 PyObject *v = PyTuple_GetItem(args, i); | |
| 435 if (PyTuple_Check(v)) { | |
| 436 fv[i] = 1; | |
| 437 if (!(argv[i] = Merge(v))) | |
| 438 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
|
439 fvc++; |
| 4968 | 440 } |
| 441 else if (v == Py_None) { | |
| 442 argc = i; | |
| 443 break; | |
| 444 } | |
| 445 else { | |
| 446 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
|
447 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
|
448 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
|
449 fvc++; |
| 4968 | 450 } |
| 451 } | |
| 452 } | |
| 453 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
|
454 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
|
455 PyErr_SetString(Tkinter_TclError, "merge failed"); |
| 1664 | 456 |
| 4968 | 457 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
|
458 for (i = 0; i < fvc; i++) |
| 4968 | 459 if (fv[i]) { |
| 460 ckfree(argv[i]); | |
| 461 } | |
| 462 if (argv != argvStore) | |
| 463 ckfree(FREECAST argv); | |
| 464 if (fv != fvStore) | |
| 465 ckfree(FREECAST fv); | |
| 466 | |
| 467 Py_DECREF(tmp); | |
| 468 return res; | |
| 469 } | |
| 470 | |
| 471 | |
| 472 | |
| 473 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
474 Split(char *list) |
| 4968 | 475 { |
| 476 int argc; | |
| 477 char **argv; | |
| 478 PyObject *v; | |
| 479 | |
| 480 if (list == NULL) { | |
| 481 Py_INCREF(Py_None); | |
| 482 return Py_None; | |
| 1664 | 483 } |
| 484 | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
485 if (Tcl_SplitList((Tcl_Interp *)NULL, list, &argc, &argv) != TCL_OK) { |
| 4968 | 486 /* Not a list. |
| 487 * Could be a quoted string containing funnies, e.g. {"}. | |
| 488 * Return the string itself. | |
| 489 */ | |
| 490 return PyString_FromString(list); | |
| 1664 | 491 } |
| 492 | |
| 4968 | 493 if (argc == 0) |
| 494 v = PyString_FromString(""); | |
| 495 else if (argc == 1) | |
| 496 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
|
497 else if ((v = PyTuple_New(argc)) != NULL) { |
| 4968 | 498 int i; |
| 499 PyObject *w; | |
| 1664 | 500 |
| 4968 | 501 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
|
502 if ((w = Split(argv[i])) == NULL) { |
| 4968 | 503 Py_DECREF(v); |
| 504 v = NULL; | |
| 505 break; | |
| 506 } | |
| 507 PyTuple_SetItem(v, i, w); | |
| 508 } | |
| 509 } | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
510 Tcl_Free(FREECAST argv); |
| 4968 | 511 return v; |
| 1664 | 512 } |
| 513 | |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
514 /* 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
|
515 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
|
516 need to be split. */ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
517 |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
518 PyObject * |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
519 SplitObj(PyObject *arg) |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
520 { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
521 if (PyTuple_Check(arg)) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
522 int i, size; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
523 PyObject *elem, *newelem, *result; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
524 |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
525 size = PyTuple_Size(arg); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
526 result = NULL; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
527 /* 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
|
528 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
|
529 needed. */ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
530 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
|
531 elem = PyTuple_GetItem(arg, i); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
532 newelem = SplitObj(elem); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
533 if (!newelem) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
534 Py_XDECREF(result); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
535 return NULL; |
|
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 if (!result) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
538 int k; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
539 if (newelem == elem) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
540 Py_DECREF(newelem); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
541 continue; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
542 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
543 result = PyTuple_New(size); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
544 if (!result) |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
545 return NULL; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
546 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
|
547 elem = PyTuple_GetItem(arg, k); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
548 Py_INCREF(elem); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
549 PyTuple_SetItem(result, k, elem); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
550 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
551 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
552 PyTuple_SetItem(result, i, newelem); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
553 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
554 if (result) |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
555 return result; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
556 /* Fall through, returning arg. */ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
557 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
558 else if (PyString_Check(arg)) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
559 int argc; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
560 char **argv; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
561 char *list = PyString_AsString(arg); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
562 |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
563 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
|
564 Py_INCREF(arg); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
565 return arg; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
566 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
567 Tcl_Free(FREECAST argv); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
568 if (argc > 1) |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
569 return Split(PyString_AsString(arg)); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
570 /* Fall through, returning arg. */ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
571 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
572 Py_INCREF(arg); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
573 return arg; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
574 } |
| 1664 | 575 |
| 4968 | 576 |
| 1664 | 577 /**** Tkapp Object ****/ |
| 578 | |
| 579 #ifndef WITH_APPINIT | |
| 580 int | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
581 Tcl_AppInit(Tcl_Interp *interp) |
| 1664 | 582 { |
| 4968 | 583 Tk_Window main; |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
584 |
| 4968 | 585 main = Tk_MainWindow(interp); |
| 586 if (Tcl_Init(interp) == TCL_ERROR) { | |
| 15177 | 587 PySys_WriteStderr("Tcl_Init error: %s\n", Tcl_GetStringResult(interp)); |
| 4968 | 588 return TCL_ERROR; |
| 589 } | |
| 590 if (Tk_Init(interp) == TCL_ERROR) { | |
| 15177 | 591 PySys_WriteStderr("Tk_Init error: %s\n", Tcl_GetStringResult(interp)); |
| 4968 | 592 return TCL_ERROR; |
| 593 } | |
| 594 return TCL_OK; | |
| 1664 | 595 } |
| 4968 | 596 #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
|
597 |
| 4968 | 598 |
| 599 | |
| 1664 | 600 |
| 601 /* Initialize the Tk application; see the `main' function in | |
| 4968 | 602 * `tkMain.c'. |
| 603 */ | |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
604 |
|
13690
c09c0171474f
ANSIfy some more forward declarations.
Thomas Wouters <thomas@python.org>
parents:
13651
diff
changeset
|
605 static void EnableEventHook(void); /* Forward */ |
|
c09c0171474f
ANSIfy some more forward declarations.
Thomas Wouters <thomas@python.org>
parents:
13651
diff
changeset
|
606 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
|
607 |
| 1664 | 608 static TkappObject * |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
609 Tkapp_New(char *screenName, char *baseName, char *className, |
|
26428
0103f0b75fe2
Rename want_objects to wantobjects throughout, for consistency.
Martin v. Löwis <martin@v.loewis.de>
parents:
26416
diff
changeset
|
610 int interactive, int wantobjects) |
| 1664 | 611 { |
| 4968 | 612 TkappObject *v; |
| 613 char *argv0; | |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
614 |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12513
diff
changeset
|
615 v = PyObject_New(TkappObject, &Tkapp_Type); |
| 4968 | 616 if (v == NULL) |
| 617 return NULL; | |
| 1664 | 618 |
| 4968 | 619 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
|
620 v->wantobjects = wantobjects; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
621 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
|
622 TCL_GLOBAL_ONLY) != NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
623 v->thread_id = Tcl_GetCurrentThread(); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
624 v->dispatching = 0; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
625 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
626 #ifndef TCL_THREADS |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
627 if (v->threaded) { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
628 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
|
629 Py_DECREF(v); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
630 return 0; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
631 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
632 #endif |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
633 #ifdef WITH_THREAD |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
634 if (v->threaded && tcl_lock) { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
635 /* 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
|
636 PyThread_free_lock(tcl_lock); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
637 tcl_lock = NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
638 } |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
639 #endif |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
640 |
|
26431
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
641 v->BooleanType = Tcl_GetObjType("boolean"); |
|
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
642 v->ByteArrayType = Tcl_GetObjType("bytearray"); |
|
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
643 v->DoubleType = Tcl_GetObjType("double"); |
|
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
644 v->IntType = Tcl_GetObjType("int"); |
|
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
645 v->ListType = Tcl_GetObjType("list"); |
|
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
646 v->ProcBodyType = Tcl_GetObjType("procbody"); |
|
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
647 v->StringType = Tcl_GetObjType("string"); |
|
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
648 |
|
12071
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
649 #if defined(macintosh) |
|
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
650 /* This seems to be needed */ |
|
8185
929b7e6e7520
On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents:
8096
diff
changeset
|
651 ClearMenuBar(); |
|
929b7e6e7520
On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents:
8096
diff
changeset
|
652 TkMacInitMenus(v->interp); |
|
929b7e6e7520
On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents:
8096
diff
changeset
|
653 #endif |
|
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
|
654 |
|
7416
13f29b62a209
Delete the 'exit' command from the Tcl interpreter -- it would allow
Guido van Rossum <guido@python.org>
parents:
7212
diff
changeset
|
655 /* 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
|
656 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
|
657 |
| 4968 | 658 if (screenName != NULL) |
| 659 Tcl_SetVar2(v->interp, "env", "DISPLAY", | |
| 660 screenName, TCL_GLOBAL_ONLY); | |
| 1664 | 661 |
| 4968 | 662 if (interactive) |
| 663 Tcl_SetVar(v->interp, "tcl_interactive", "1", TCL_GLOBAL_ONLY); | |
| 664 else | |
| 665 Tcl_SetVar(v->interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY); | |
| 1664 | 666 |
| 4968 | 667 /* This is used to get the application class for Tk 4.1 and up */ |
| 668 argv0 = (char*)ckalloc(strlen(className) + 1); | |
| 669 if (!argv0) { | |
| 670 PyErr_NoMemory(); | |
| 671 Py_DECREF(v); | |
| 672 return NULL; | |
| 673 } | |
|
3973
3d1e4b76f745
Add optional casts to free() calls. (Jack)
Guido van Rossum <guido@python.org>
parents:
3899
diff
changeset
|
674 |
| 4968 | 675 strcpy(argv0, className); |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
7416
diff
changeset
|
676 if (isupper((int)(argv0[0]))) |
| 4968 | 677 argv0[0] = tolower(argv0[0]); |
| 678 Tcl_SetVar(v->interp, "argv0", argv0, TCL_GLOBAL_ONLY); | |
| 679 ckfree(argv0); | |
| 1664 | 680 |
| 4968 | 681 if (Tcl_AppInit(v->interp) != TCL_OK) |
|
8639
027a1dad1353
Add a cast that a picky SGI compiler found was necessary.
Guido van Rossum <guido@python.org>
parents:
8522
diff
changeset
|
682 return (TkappObject *)Tkinter_Error((PyObject *)v); |
| 4968 | 683 |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
684 EnableEventHook(); |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
685 |
| 4968 | 686 return v; |
| 1664 | 687 } |
| 688 | |
| 4968 | 689 |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
690 static void |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
691 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
|
692 Tcl_Condition *cond, Tcl_Mutex *mutex) |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
693 { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
694 Py_BEGIN_ALLOW_THREADS; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
695 Tcl_MutexLock(mutex); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
696 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
|
697 Tcl_ThreadAlert(self->thread_id); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
698 Tcl_ConditionWait(cond, mutex, NULL); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
699 Tcl_MutexUnlock(mutex); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
700 Py_END_ALLOW_THREADS |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
701 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
702 |
| 4968 | 703 |
| 1664 | 704 /** Tcl Eval **/ |
| 705 | |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
706 typedef struct { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
707 PyObject_HEAD |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
708 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
|
709 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
|
710 } PyTclObject; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
711 |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
712 staticforward PyTypeObject PyTclObject_Type; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
713 #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
|
714 |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
715 static PyObject * |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
716 newPyTclObject(Tcl_Obj *arg) |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
717 { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
718 PyTclObject *self; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
719 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
|
720 if (self == NULL) |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
721 return NULL; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
722 Tcl_IncrRefCount(arg); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
723 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
|
724 self->string = NULL; |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
725 return (PyObject*)self; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
726 } |
|
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 static void |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
729 PyTclObject_dealloc(PyTclObject *self) |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
730 { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
731 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
|
732 Py_XDECREF(self->string); |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
733 PyObject_Del(self); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
734 } |
|
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 static PyObject * |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
737 PyTclObject_str(PyTclObject *self) |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
738 { |
|
27069
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
739 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
|
740 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
|
741 return self->string; |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
742 } |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
743 /* 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
|
744 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
|
745 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
746 |
|
28915
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
747 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
|
748 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
|
749 { |
|
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
750 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
|
751 } |
|
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
752 |
|
27069
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
753 /* 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
|
754 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
|
755 "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
|
756 |
|
27069
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
757 static PyObject * |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
758 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
|
759 { |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
760 char *s; |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
761 int i, len; |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
762 if (!self->string) { |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
763 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
|
764 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
|
765 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
|
766 break; |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
767 #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
|
768 if (i == len) |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
769 /* 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
|
770 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
|
771 else { |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
772 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
|
773 if (!self->string) { |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
774 PyErr_Clear(); |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
775 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
|
776 } |
|
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 #else |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
779 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
|
780 #endif |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
781 if (!self->string) |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
782 return NULL; |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
783 } |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
784 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
|
785 return self->string; |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
786 } |
|
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 #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
|
789 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
|
790 |
|
27069
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
791 static PyObject * |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
792 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
|
793 { |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
794 char *s; |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
795 int len; |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
796 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
|
797 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
|
798 return self->string; |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
799 } |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
800 /* 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
|
801 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
|
802 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
|
803 } |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
804 #endif |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
805 |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
806 static PyObject * |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
807 PyTclObject_repr(PyTclObject *self) |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
808 { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
809 char buf[50]; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
810 PyOS_snprintf(buf, 50, "<%s object at 0x%.8x>", |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
811 self->value->typePtr->name, (int)self->value); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
812 return PyString_FromString(buf); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
813 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
814 |
|
28950
3a9f5f0c512e
Implement tcl object __cmp__.
Martin v. Löwis <martin@v.loewis.de>
parents:
28915
diff
changeset
|
815 static int |
|
3a9f5f0c512e
Implement tcl object __cmp__.
Martin v. Löwis <martin@v.loewis.de>
parents:
28915
diff
changeset
|
816 PyTclObject_cmp(PyTclObject *self, PyTclObject *other) |
|
3a9f5f0c512e
Implement tcl object __cmp__.
Martin v. Löwis <martin@v.loewis.de>
parents:
28915
diff
changeset
|
817 { |
|
3a9f5f0c512e
Implement tcl object __cmp__.
Martin v. Löwis <martin@v.loewis.de>
parents:
28915
diff
changeset
|
818 int res; |
|
3a9f5f0c512e
Implement tcl object __cmp__.
Martin v. Löwis <martin@v.loewis.de>
parents:
28915
diff
changeset
|
819 res = strcmp(Tcl_GetString(self->value), |
|
3a9f5f0c512e
Implement tcl object __cmp__.
Martin v. Löwis <martin@v.loewis.de>
parents:
28915
diff
changeset
|
820 Tcl_GetString(other->value)); |
|
3a9f5f0c512e
Implement tcl object __cmp__.
Martin v. Löwis <martin@v.loewis.de>
parents:
28915
diff
changeset
|
821 if (res < 0) return -1; |
|
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 return 0; |
|
3a9f5f0c512e
Implement tcl object __cmp__.
Martin v. Löwis <martin@v.loewis.de>
parents:
28915
diff
changeset
|
824 } |
|
3a9f5f0c512e
Implement tcl object __cmp__.
Martin v. Löwis <martin@v.loewis.de>
parents:
28915
diff
changeset
|
825 |
|
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
|
826 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
|
827 |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
828 static PyObject* |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
829 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
|
830 { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
831 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
|
832 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
833 |
|
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
|
834 |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
835 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
|
836 {"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
|
837 {"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
|
838 PyTclObject_string__doc__}, |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
839 {0}, |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
840 }; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
841 |
|
27069
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
842 static PyMethodDef PyTclObject_methods[] = { |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
843 {"__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
|
844 PyTclObject_unicode__doc__}, |
|
27069
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
845 {0} |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
846 }; |
|
ef531482bb37
Convert Tcl path objects to strings. Fixes #661357.
Martin v. Löwis <martin@v.loewis.de>
parents:
26989
diff
changeset
|
847 |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
848 statichere PyTypeObject PyTclObject_Type = { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
849 PyObject_HEAD_INIT(NULL) |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
850 0, /*ob_size*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
851 "_tkinter.Tcl_Obj", /*tp_name*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
852 sizeof(PyTclObject), /*tp_basicsize*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
853 0, /*tp_itemsize*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
854 /* methods */ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
855 (destructor)PyTclObject_dealloc, /*tp_dealloc*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
856 0, /*tp_print*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
857 0, /*tp_getattr*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
858 0, /*tp_setattr*/ |
|
28950
3a9f5f0c512e
Implement tcl object __cmp__.
Martin v. Löwis <martin@v.loewis.de>
parents:
28915
diff
changeset
|
859 (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
|
860 (reprfunc)PyTclObject_repr, /*tp_repr*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
861 0, /*tp_as_number*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
862 0, /*tp_as_sequence*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
863 0, /*tp_as_mapping*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
864 0, /*tp_hash*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
865 0, /*tp_call*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
866 (reprfunc)PyTclObject_str, /*tp_str*/ |
|
27104
2443c557cbc3
Patch #661760: Cygwin auto-import module patch
Jason Tishler <jason@tishler.net>
parents:
27084
diff
changeset
|
867 PyObject_GenericGetAttr,/*tp_getattro*/ |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
868 0, /*tp_setattro*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
869 0, /*tp_as_buffer*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
870 Py_TPFLAGS_DEFAULT, /*tp_flags*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
871 0, /*tp_doc*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
872 0, /*tp_traverse*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
873 0, /*tp_clear*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
874 0, /*tp_richcompare*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
875 0, /*tp_weaklistoffset*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
876 0, /*tp_iter*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
877 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
|
878 PyTclObject_methods, /*tp_methods*/ |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
879 0, /*tp_members*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
880 PyTclObject_getsetlist, /*tp_getset*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
881 0, /*tp_base*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
882 0, /*tp_dict*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
883 0, /*tp_descr_get*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
884 0, /*tp_descr_set*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
885 0, /*tp_dictoffset*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
886 0, /*tp_init*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
887 0, /*tp_alloc*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
888 0, /*tp_new*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
889 0, /*tp_free*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
890 0, /*tp_is_gc*/ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
891 }; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
892 |
|
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
|
893 static Tcl_Obj* |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
894 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
|
895 { |
|
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 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
|
897 |
|
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 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
|
899 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
|
900 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
|
901 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
|
902 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
|
903 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
|
904 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
|
905 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
|
906 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
|
907 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
|
908 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
|
909 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
|
910 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
|
911 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
|
912 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
|
913 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
|
914 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
|
915 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
|
916 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
|
917 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
|
918 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19033
diff
changeset
|
919 #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
|
920 else if (PyUnicode_Check(value)) { |
|
25530
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
921 Py_UNICODE *inbuf = PyUnicode_AS_UNICODE(value); |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
922 int size = PyUnicode_GET_SIZE(value); |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
923 /* 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
|
924 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
|
925 #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
|
926 Tcl_UniChar *outbuf; |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
927 int i; |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
928 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
|
929 if (!outbuf) { |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
930 PyErr_NoMemory(); |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
931 return NULL; |
|
12580
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
932 } |
|
25530
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
933 for (i = 0; i < size; i++) { |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
934 if (inbuf[i] >= 0x10000) { |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
935 /* Tcl doesn't do UTF-16, yet. */ |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
936 PyErr_SetString(PyExc_ValueError, |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
937 "unsupported character"); |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
938 ckfree(FREECAST outbuf); |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
939 return NULL; |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
940 } |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
941 outbuf[i] = inbuf[i]; |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
942 } |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
943 result = Tcl_NewUnicodeObj(outbuf, size); |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
944 ckfree(FREECAST outbuf); |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
945 return result; |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
946 #else |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
947 return Tcl_NewUnicodeObj(inbuf, size); |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
948 #endif |
|
70d93b62370b
Support UCS-4 builds.
Martin v. Löwis <martin@v.loewis.de>
parents:
25527
diff
changeset
|
949 |
|
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
|
950 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19033
diff
changeset
|
951 #endif |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
952 else if(PyTclObject_Check(value)) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
953 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
|
954 Tcl_IncrRefCount(v); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
955 return v; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
956 } |
|
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
|
957 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
|
958 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
|
959 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
|
960 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
|
961 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
|
962 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
|
963 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
|
964 } |
|
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 } |
|
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 |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
967 static PyObject* |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
968 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
|
969 { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
970 PyObject *result = NULL; |
|
26431
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
971 TkappObject *app = (TkappObject*)tkapp; |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
972 |
|
26534
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
973 if (value->typePtr == NULL) { |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
974 /* 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
|
975 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
|
976 #ifdef Py_USING_UNICODE |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
977 int i; |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
978 char *s = value->bytes; |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
979 int len = value->length; |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
980 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
|
981 if (value->bytes[i] & 0x80) |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
982 break; |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
983 } |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
984 |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
985 if (i == value->length) |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
986 result = PyString_FromStringAndSize(s, len); |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
987 else { |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
988 /* 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
|
989 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
|
990 if (result == NULL) { |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
991 PyErr_Clear(); |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
992 result = PyString_FromStringAndSize(s, len); |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
993 } |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
994 } |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
995 #else |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
996 res = PyString_FromStringAndSize(value->bytes, value->length); |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
997 #endif |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
998 return result; |
|
ca6fa69711bb
Decode untyped strings from UTF-8.
Martin v. Löwis <martin@v.loewis.de>
parents:
26431
diff
changeset
|
999 } |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1000 |
|
26431
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
1001 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
|
1002 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
|
1003 Py_INCREF(result); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1004 return result; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1005 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1006 |
|
26431
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
1007 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
|
1008 int size; |
|
26572
d755d4292f3f
Remove C++ comment. Silence unsigned char* cast warning.
Martin v. Löwis <martin@v.loewis.de>
parents:
26534
diff
changeset
|
1009 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
|
1010 return PyString_FromStringAndSize(data, size); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1011 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1012 |
|
26431
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
1013 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
|
1014 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
|
1015 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1016 |
|
26431
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
1017 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
|
1018 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
|
1019 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1020 |
|
26431
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
1021 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
|
1022 int size; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1023 int i, status; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1024 PyObject *elem; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1025 Tcl_Obj *tcl_elem; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1026 |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1027 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
|
1028 if (status == TCL_ERROR) |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1029 return Tkinter_Error(tkapp); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1030 result = PyTuple_New(size); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1031 if (!result) |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1032 return NULL; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1033 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
|
1034 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
|
1035 value, i, &tcl_elem); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1036 if (status == TCL_ERROR) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1037 Py_DECREF(result); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1038 return Tkinter_Error(tkapp); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1039 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1040 elem = FromObj(tkapp, tcl_elem); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1041 if (!elem) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1042 Py_DECREF(result); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1043 return NULL; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1044 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1045 PyTuple_SetItem(result, i, elem); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1046 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1047 return result; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1048 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1049 |
|
26431
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
1050 if (value->typePtr == app->ProcBodyType) { |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1051 /* 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
|
1052 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1053 |
|
26431
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
1054 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
|
1055 #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
|
1056 #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
|
1057 PyObject *result; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1058 int size; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1059 Tcl_UniChar *input; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1060 Py_UNICODE *output; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1061 |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1062 size = Tcl_GetCharLength(value); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1063 result = PyUnicode_FromUnicode(NULL, size); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1064 if (!result) |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1065 return NULL; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1066 input = Tcl_GetUnicode(value); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1067 output = PyUnicode_AS_UNICODE(result); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1068 while (size--) |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1069 *output++ = *input++; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1070 return result; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1071 #else |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1072 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
|
1073 Tcl_GetCharLength(value)); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1074 #endif |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1075 #else |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1076 int size; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1077 char *c; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1078 c = Tcl_GetStringFromObj(value, &size); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1079 return PyString_FromStringAndSize(c, size); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1080 #endif |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1081 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1082 |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1083 return newPyTclObject(value); |
|
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 |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1086 /* 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
|
1087 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1088 TCL_DECLARE_MUTEX(call_mutex) |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1089 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1090 typedef struct Tkapp_CallEvent { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1091 Tcl_Event ev; /* Must be first */ |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1092 TkappObject *self; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1093 PyObject *args; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1094 int flags; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1095 PyObject **res; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1096 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
|
1097 Tcl_Condition done; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1098 } Tkapp_CallEvent; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1099 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1100 void |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1101 Tkapp_CallDeallocArgs(Tcl_Obj** objv, Tcl_Obj** objStore, int objc) |
| 1664 | 1102 { |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1103 int i; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1104 for (i = 0; i < objc; i++) |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1105 Tcl_DecrRefCount(objv[i]); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1106 if (objv != objStore) |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1107 ckfree(FREECAST objv); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1108 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1109 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1110 /* 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
|
1111 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
|
1112 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1113 static Tcl_Obj** |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1114 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
|
1115 { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1116 Tcl_Obj **objv = objStore; |
|
26620
cb93d9287b4e
Always initialize objc.
Martin v. Löwis <martin@v.loewis.de>
parents:
26613
diff
changeset
|
1117 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
|
1118 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
|
1119 /* do nothing */; |
|
8200
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
1120 |
|
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
1121 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
|
1122 objv[0] = AsObj(args); |
|
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
1123 if (objv[0] == 0) |
|
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
1124 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
|
1125 objc = 1; |
|
12087
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
1126 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
|
1127 } |
|
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
1128 else { |
|
12087
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
1129 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
|
1130 |
|
12087
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
1131 if (objc > ARGSZ) { |
|
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
1132 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
|
1133 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
|
1134 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
|
1135 objc = 0; |
|
8200
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
1136 goto finally; |
|
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
1137 } |
|
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
1138 } |
| 4968 | 1139 |
|
12087
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
1140 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
|
1141 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
|
1142 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
|
1143 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
|
1144 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
|
1145 } |
|
12087
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
1146 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
|
1147 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
|
1148 /* 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
|
1149 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
|
1150 objc = i; |
|
12087
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
1151 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
|
1152 } |
|
12087
e2db89a98cb2
The Tcl_Obj patch discussed on the patches list.
Guido van Rossum <guido@python.org>
parents:
12071
diff
changeset
|
1153 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
|
1154 } |
|
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
1155 } |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1156 *pobjc = objc; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1157 return objv; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1158 finally: |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1159 Tkapp_CallDeallocArgs(objv, objStore, objc); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1160 return NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1161 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1162 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1163 /* 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
|
1164 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1165 static PyObject* |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1166 Tkapp_CallResult(TkappObject *self) |
|
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 PyObject *res = NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1169 if(self->wantobjects) { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1170 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
|
1171 /* 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
|
1172 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
|
1173 converting it. */ |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1174 Tcl_IncrRefCount(value); |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1175 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
|
1176 Tcl_DecrRefCount(value); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1177 } else { |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1178 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
|
1179 const char *p = s; |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19033
diff
changeset
|
1180 |
|
12580
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
1181 /* 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
|
1182 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
|
1183 #ifdef Py_USING_UNICODE |
|
12580
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
1184 while (*p != '\0') { |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
1185 if (*p & 0x80) |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
1186 break; |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
1187 p++; |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
1188 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19033
diff
changeset
|
1189 |
|
12580
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
1190 if (*p == '\0') |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
1191 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
|
1192 else { |
|
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
1193 /* 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
|
1194 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
|
1195 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
|
1196 if (res == NULL) { |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1197 PyErr_Clear(); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1198 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
|
1199 } |
|
12580
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
1200 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19033
diff
changeset
|
1201 #else |
|
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19033
diff
changeset
|
1202 p = strchr(p, '\0'); |
|
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19033
diff
changeset
|
1203 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
|
1204 #endif |
|
12580
e0a12095fac2
Two changes to improve (I hope) Unicode support.
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
1205 } |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1206 return res; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1207 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1208 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1209 /* 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
|
1210 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
|
1211 hold the Python lock. */ |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1212 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1213 static int |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1214 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
|
1215 { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1216 Tcl_Obj *objStore[ARGSZ]; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1217 Tcl_Obj **objv; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1218 int objc; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1219 int i; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1220 ENTER_PYTHON |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1221 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
|
1222 if (!objv) { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1223 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
|
1224 *(e->res) = NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1225 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1226 LEAVE_PYTHON |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1227 if (!objv) |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1228 goto done; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1229 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
|
1230 ENTER_PYTHON |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1231 if (i == TCL_ERROR) { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1232 *(e->res) = NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1233 *(e->exc_type) = NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1234 *(e->exc_tb) = NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1235 *(e->exc_value) = PyObject_CallFunction( |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1236 Tkinter_TclError, "s", |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1237 Tcl_GetStringResult(e->self->interp)); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1238 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1239 else { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1240 *(e->res) = Tkapp_CallResult(e->self); |
|
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 LEAVE_PYTHON |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1243 done: |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1244 /* Wake up calling thread. */ |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1245 Tcl_MutexLock(&call_mutex); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1246 Tcl_ConditionNotify(&e->done); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1247 Tcl_MutexUnlock(&call_mutex); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1248 return 1; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1249 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1250 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1251 /* 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
|
1252 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
|
1253 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
|
1254 the context of the calling thread. |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1255 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
|
1256 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
|
1257 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
|
1258 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
|
1259 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
|
1260 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
|
1261 and perform processing there. */ |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1262 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1263 static PyObject * |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1264 Tkapp_Call(PyObject *_self, PyObject *args) |
|
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 Tcl_Obj *objStore[ARGSZ]; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1267 Tcl_Obj **objv = NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1268 int objc, i; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1269 PyObject *res = NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1270 TkappObject *self = (TkappObject*)_self; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1271 /* 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
|
1272 int flags = TCL_EVAL_DIRECT; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1273 |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
1274 #ifdef WITH_THREAD |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1275 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
|
1276 /* 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
|
1277 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
|
1278 Tkapp_CallEvent *ev; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1279 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
|
1280 if (!WaitForMainloop(self)) |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1281 return NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1282 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
|
1283 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
|
1284 ev->self = self; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1285 ev->args = args; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1286 ev->res = &res; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1287 ev->exc_type = &exc_type; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1288 ev->exc_value = &exc_value; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1289 ev->exc_tb = &exc_tb; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1290 ev->done = (Tcl_Condition)0; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1291 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1292 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
|
1293 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1294 if (res == NULL) { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1295 if (exc_type) |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1296 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
|
1297 else |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1298 PyErr_SetObject(Tkinter_TclError, exc_value); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1299 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1300 } |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
1301 else |
|
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
1302 #endif |
|
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
1303 { |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1304 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1305 objv = Tkapp_CallArgs(args, objStore, &objc); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1306 if (!objv) |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1307 return NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1308 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1309 ENTER_TCL |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1310 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1311 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
|
1312 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1313 ENTER_OVERLAP |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1314 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1315 if (i == TCL_ERROR) |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1316 Tkinter_Error(_self); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1317 else |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1318 res = Tkapp_CallResult(self); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1319 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1320 LEAVE_OVERLAP_TCL |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1321 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1322 Tkapp_CallDeallocArgs(objv, objStore, objc); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1323 } |
| 4968 | 1324 return res; |
| 1325 } | |
| 1664 | 1326 |
| 4968 | 1327 |
| 1328 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1329 Tkapp_GlobalCall(PyObject *self, PyObject *args) |
| 4968 | 1330 { |
|
8200
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
1331 /* 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
|
1332 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
|
1333 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
|
1334 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
|
1335 scope pointer). */ |
|
482e4ba33c08
Still somewhat experimental speedup. This appears to speed up the
Guido van Rossum <guido@python.org>
parents:
8199
diff
changeset
|
1336 |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1337 char *cmd; |
| 4968 | 1338 PyObject *res = NULL; |
| 1664 | 1339 |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1340 CHECK_TCL_APPARTMENT; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1341 |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1342 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
|
1343 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
|
1344 int err; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1345 ENTER_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1346 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
|
1347 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
|
1348 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
|
1349 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
|
1350 else |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1351 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
|
1352 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
|
1353 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
|
1354 } |
| 4968 | 1355 |
| 1356 return res; | |
| 1664 | 1357 } |
| 1358 | |
| 1359 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1360 Tkapp_Eval(PyObject *self, PyObject *args) |
| 1664 | 1361 { |
| 4968 | 1362 char *script; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1363 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
|
1364 int err; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1365 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1366 if (!PyArg_ParseTuple(args, "s:eval", &script)) |
| 4968 | 1367 return NULL; |
| 1664 | 1368 |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1369 CHECK_TCL_APPARTMENT; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1370 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1371 ENTER_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1372 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
|
1373 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
|
1374 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
|
1375 res = Tkinter_Error(self); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1376 else |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1377 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
|
1378 LEAVE_OVERLAP_TCL |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1379 return res; |
| 1664 | 1380 } |
| 1381 | |
| 1382 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1383 Tkapp_GlobalEval(PyObject *self, PyObject *args) |
| 1664 | 1384 { |
| 4968 | 1385 char *script; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1386 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
|
1387 int err; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1388 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1389 if (!PyArg_ParseTuple(args, "s:globaleval", &script)) |
| 4968 | 1390 return NULL; |
| 1664 | 1391 |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1392 CHECK_TCL_APPARTMENT; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1393 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1394 ENTER_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1395 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
|
1396 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
|
1397 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
|
1398 res = Tkinter_Error(self); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1399 else |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1400 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
|
1401 LEAVE_OVERLAP_TCL |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1402 return res; |
| 1664 | 1403 } |
| 1404 | |
| 1405 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1406 Tkapp_EvalFile(PyObject *self, PyObject *args) |
| 1664 | 1407 { |
| 4968 | 1408 char *fileName; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1409 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
|
1410 int err; |
| 1664 | 1411 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1412 if (!PyArg_ParseTuple(args, "s:evalfile", &fileName)) |
| 4968 | 1413 return NULL; |
| 1664 | 1414 |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1415 CHECK_TCL_APPARTMENT; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1416 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1417 ENTER_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1418 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
|
1419 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
|
1420 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
|
1421 res = Tkinter_Error(self); |
| 1664 | 1422 |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1423 else |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1424 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
|
1425 LEAVE_OVERLAP_TCL |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1426 return res; |
| 1664 | 1427 } |
| 1428 | |
| 1429 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1430 Tkapp_Record(PyObject *self, PyObject *args) |
| 1664 | 1431 { |
| 4968 | 1432 char *script; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1433 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
|
1434 int err; |
| 1664 | 1435 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1436 if (!PyArg_ParseTuple(args, "s", &script)) |
| 4968 | 1437 return NULL; |
| 1664 | 1438 |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1439 CHECK_TCL_APPARTMENT; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1440 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1441 ENTER_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1442 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
|
1443 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
|
1444 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
|
1445 res = Tkinter_Error(self); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1446 else |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1447 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
|
1448 LEAVE_OVERLAP_TCL |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1449 return res; |
| 1664 | 1450 } |
| 1451 | |
| 1452 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1453 Tkapp_AddErrorInfo(PyObject *self, PyObject *args) |
| 1664 | 1454 { |
| 4968 | 1455 char *msg; |
| 1664 | 1456 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1457 if (!PyArg_ParseTuple(args, "s:adderrorinfo", &msg)) |
| 4968 | 1458 return NULL; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1459 CHECK_TCL_APPARTMENT; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1460 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1461 ENTER_TCL |
| 4968 | 1462 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
|
1463 LEAVE_TCL |
| 1664 | 1464 |
| 4968 | 1465 Py_INCREF(Py_None); |
| 1466 return Py_None; | |
| 1664 | 1467 } |
| 1468 | |
| 4968 | 1469 |
| 1470 | |
| 1664 | 1471 /** Tcl Variable **/ |
| 1472 | |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1473 TCL_DECLARE_MUTEX(var_mutex) |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1474 |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1475 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
|
1476 typedef struct VarEvent { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1477 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
|
1478 PyObject *self; |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1479 PyObject *args; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1480 int flags; |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1481 EventFunc func; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1482 PyObject **res; |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1483 PyObject **exc_type; |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1484 PyObject **exc_val; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1485 Tcl_Condition cond; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1486 } VarEvent; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1487 |
|
28915
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
1488 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
|
1489 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
|
1490 { |
|
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
1491 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
|
1492 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
|
1493 *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
|
1494 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
|
1495 } |
|
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
1496 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
|
1497 *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
|
1498 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
|
1499 } |
|
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
1500 /* 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
|
1501 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
|
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 |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1504 void |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1505 var_perform(VarEvent *ev) |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
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 *(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
|
1508 if (!*(ev->res)) { |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1509 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
|
1510 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
|
1511 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
|
1512 *(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
|
1513 *(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
|
1514 Py_DECREF(tb); |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1515 } |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1516 |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1517 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1518 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1519 static int |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1520 var_proc(VarEvent* ev, int flags) |
|
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 ENTER_PYTHON |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1523 var_perform(ev); |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1524 Tcl_MutexLock(&var_mutex); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1525 Tcl_ConditionNotify(&ev->cond); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1526 Tcl_MutexUnlock(&var_mutex); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1527 LEAVE_PYTHON |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1528 return 1; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1529 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1530 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1531 static PyObject* |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1532 var_invoke(EventFunc func, PyObject *_self, PyObject *args, int flags) |
|
26613
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 TkappObject *self = (TkappObject*)_self; |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
1535 #ifdef WITH_THREAD |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1536 if (self->threaded && self->thread_id != Tcl_GetCurrentThread()) { |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1537 TkappObject *self = (TkappObject*)_self; |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1538 VarEvent *ev; |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1539 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
|
1540 |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1541 /* 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
|
1542 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
|
1543 completion. */ |
|
26814
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
1544 if (!WaitForMainloop(self)) |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1545 return NULL; |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1546 |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1547 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
|
1548 |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1549 ev->self = _self; |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1550 ev->args = args; |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1551 ev->flags = flags; |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1552 ev->func = func; |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1553 ev->res = &res; |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1554 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
|
1555 ev->exc_val = &exc_val; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1556 ev->cond = NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1557 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
|
1558 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
|
1559 if (!res) { |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1560 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
|
1561 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
|
1562 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
|
1563 return NULL; |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1564 } |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1565 return res; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1566 } |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1567 #endif |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1568 /* Tcl is not threaded, or this is the interpreter thread. */ |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1569 return func(_self, args, flags); |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1570 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1571 |
| 1664 | 1572 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1573 SetVar(PyObject *self, PyObject *args, int flags) |
| 1664 | 1574 { |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1575 char *name1, *name2; |
| 4968 | 1576 PyObject *newValue; |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1577 PyObject *res = NULL; |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1578 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
|
1579 |
|
28915
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
1580 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
|
1581 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
|
1582 /* 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
|
1583 newval = AsObj(newValue); |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1584 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
|
1585 return NULL; |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1586 ENTER_TCL |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1587 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
|
1588 newval, flags); |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1589 ENTER_OVERLAP |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1590 if (!ok) |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1591 Tkinter_Error(self); |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1592 else { |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1593 res = Py_None; |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1594 Py_INCREF(res); |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1595 } |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1596 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
|
1597 } |
| 4968 | 1598 else { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1599 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
|
1600 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
|
1601 &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
|
1602 /* 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
|
1603 newval = AsObj(newValue); |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1604 ENTER_TCL |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1605 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
|
1606 ENTER_OVERLAP |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1607 if (!ok) |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1608 Tkinter_Error(self); |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1609 else { |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1610 res = Py_None; |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1611 Py_INCREF(res); |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1612 } |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1613 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
|
1614 } |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1615 else { |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1616 return NULL; |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1617 } |
| 4968 | 1618 } |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1619 return res; |
| 1664 | 1620 } |
| 1621 | |
| 1622 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1623 Tkapp_SetVar(PyObject *self, PyObject *args) |
| 1664 | 1624 { |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1625 return var_invoke(SetVar, self, args, TCL_LEAVE_ERR_MSG); |
| 1664 | 1626 } |
| 1627 | |
| 1628 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1629 Tkapp_GlobalSetVar(PyObject *self, PyObject *args) |
| 1664 | 1630 { |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1631 return var_invoke(SetVar, self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY); |
| 1664 | 1632 } |
| 1633 | |
| 4968 | 1634 |
| 1635 | |
| 1664 | 1636 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1637 GetVar(PyObject *self, PyObject *args, int flags) |
| 1664 | 1638 { |
|
25527
5420969ddd70
Eliminate constness warnings with Tcl 8.4.
Martin v. Löwis <martin@v.loewis.de>
parents:
25525
diff
changeset
|
1639 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
|
1640 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
|
1641 Tcl_Obj *tres; |
| 4968 | 1642 |
|
28915
fa0063928518
Convert tcl objects to strings in getvar/setvar. Fixes #730506.
Martin v. Löwis <martin@v.loewis.de>
parents:
28643
diff
changeset
|
1643 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
|
1644 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
|
1645 return NULL; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1646 |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1647 ENTER_TCL |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1648 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
|
1649 ENTER_OVERLAP |
|
29170
f0b67731e545
Only return objects if wantobjects is set in GetVar.
Martin v. Löwis <martin@v.loewis.de>
parents:
29038
diff
changeset
|
1650 if (((TkappObject*)self)->wantobjects) { |
|
f0b67731e545
Only return objects if wantobjects is set in GetVar.
Martin v. Löwis <martin@v.loewis.de>
parents:
29038
diff
changeset
|
1651 res = FromObj(self, tres); |
|
f0b67731e545
Only return objects if wantobjects is set in GetVar.
Martin v. Löwis <martin@v.loewis.de>
parents:
29038
diff
changeset
|
1652 } |
|
f0b67731e545
Only return objects if wantobjects is set in GetVar.
Martin v. Löwis <martin@v.loewis.de>
parents:
29038
diff
changeset
|
1653 else { |
|
f0b67731e545
Only return objects if wantobjects is set in GetVar.
Martin v. Löwis <martin@v.loewis.de>
parents:
29038
diff
changeset
|
1654 res = PyString_FromString(Tcl_GetString(tres)); |
|
f0b67731e545
Only return objects if wantobjects is set in GetVar.
Martin v. Löwis <martin@v.loewis.de>
parents:
29038
diff
changeset
|
1655 } |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1656 LEAVE_OVERLAP_TCL |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1657 return res; |
| 1664 | 1658 } |
| 1659 | |
| 1660 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1661 Tkapp_GetVar(PyObject *self, PyObject *args) |
| 1664 | 1662 { |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1663 return var_invoke(GetVar, self, args, TCL_LEAVE_ERR_MSG); |
| 1664 | 1664 } |
| 1665 | |
| 1666 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1667 Tkapp_GlobalGetVar(PyObject *self, PyObject *args) |
| 1664 | 1668 { |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1669 return var_invoke(GetVar, self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY); |
| 1664 | 1670 } |
| 1671 | |
| 4968 | 1672 |
| 1673 | |
| 1664 | 1674 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1675 UnsetVar(PyObject *self, PyObject *args, int flags) |
| 1664 | 1676 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1677 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
|
1678 int code; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1679 PyObject *res = NULL; |
| 4968 | 1680 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1681 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
|
1682 return NULL; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1683 |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1684 ENTER_TCL |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1685 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
|
1686 ENTER_OVERLAP |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1687 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
|
1688 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
|
1689 else { |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1690 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
|
1691 res = Py_None; |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1692 } |
|
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1693 LEAVE_OVERLAP_TCL |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1694 return res; |
| 1664 | 1695 } |
| 1696 | |
| 1697 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1698 Tkapp_UnsetVar(PyObject *self, PyObject *args) |
| 1664 | 1699 { |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1700 return var_invoke(UnsetVar, self, args, TCL_LEAVE_ERR_MSG); |
| 1664 | 1701 } |
| 1702 | |
| 1703 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1704 Tkapp_GlobalUnsetVar(PyObject *self, PyObject *args) |
| 1664 | 1705 { |
|
28622
6c0004690941
Use object interface for global vars. Fixes #721171.
Martin v. Löwis <martin@v.loewis.de>
parents:
28445
diff
changeset
|
1706 return var_invoke(UnsetVar, self, args, TCL_LEAVE_ERR_MSG | TCL_GLOBAL_ONLY); |
| 1664 | 1707 } |
| 1708 | |
| 4968 | 1709 |
| 1710 | |
| 1664 | 1711 /** Tcl to Python **/ |
| 1712 | |
| 1713 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1714 Tkapp_GetInt(PyObject *self, PyObject *args) |
| 1664 | 1715 { |
| 4968 | 1716 char *s; |
| 1717 int v; | |
| 1664 | 1718 |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1719 if (PyTuple_Size(args) == 1) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1720 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
|
1721 if (PyInt_Check(o)) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1722 Py_INCREF(o); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1723 return o; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1724 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1725 } |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1726 if (!PyArg_ParseTuple(args, "s:getint", &s)) |
| 4968 | 1727 return NULL; |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1728 if (Tcl_GetInt(Tkapp_Interp(self), s, &v) == TCL_ERROR) |
| 4968 | 1729 return Tkinter_Error(self); |
| 1730 return Py_BuildValue("i", v); | |
| 1664 | 1731 } |
| 1732 | |
| 1733 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1734 Tkapp_GetDouble(PyObject *self, PyObject *args) |
| 1664 | 1735 { |
| 4968 | 1736 char *s; |
| 1737 double v; | |
| 1664 | 1738 |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1739 if (PyTuple_Size(args) == 1) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1740 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
|
1741 if (PyFloat_Check(o)) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1742 Py_INCREF(o); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1743 return o; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1744 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1745 } |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1746 if (!PyArg_ParseTuple(args, "s:getdouble", &s)) |
| 4968 | 1747 return NULL; |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1748 if (Tcl_GetDouble(Tkapp_Interp(self), s, &v) == TCL_ERROR) |
| 4968 | 1749 return Tkinter_Error(self); |
| 1750 return Py_BuildValue("d", v); | |
| 1664 | 1751 } |
| 1752 | |
| 1753 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1754 Tkapp_GetBoolean(PyObject *self, PyObject *args) |
| 1664 | 1755 { |
| 4968 | 1756 char *s; |
| 1757 int v; | |
| 1664 | 1758 |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1759 if (PyTuple_Size(args) == 1) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1760 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
|
1761 if (PyInt_Check(o)) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1762 Py_INCREF(o); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1763 return o; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1764 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1765 } |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1766 if (!PyArg_ParseTuple(args, "s:getboolean", &s)) |
| 4968 | 1767 return NULL; |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1768 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
|
1769 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
|
1770 return PyBool_FromLong(v); |
| 1664 | 1771 } |
| 1772 | |
| 1773 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1774 Tkapp_ExprString(PyObject *self, PyObject *args) |
| 1664 | 1775 { |
| 4968 | 1776 char *s; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1777 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
|
1778 int retval; |
| 1664 | 1779 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1780 if (!PyArg_ParseTuple(args, "s:exprstring", &s)) |
| 4968 | 1781 return NULL; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1782 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1783 CHECK_TCL_APPARTMENT; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1784 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1785 ENTER_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1786 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
|
1787 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
|
1788 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
|
1789 res = Tkinter_Error(self); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1790 else |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1791 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
|
1792 LEAVE_OVERLAP_TCL |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1793 return res; |
| 1664 | 1794 } |
| 1795 | |
| 1796 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1797 Tkapp_ExprLong(PyObject *self, PyObject *args) |
| 1664 | 1798 { |
| 4968 | 1799 char *s; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1800 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
|
1801 int retval; |
| 4968 | 1802 long v; |
| 1664 | 1803 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1804 if (!PyArg_ParseTuple(args, "s:exprlong", &s)) |
| 4968 | 1805 return NULL; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1806 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1807 CHECK_TCL_APPARTMENT; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1808 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1809 ENTER_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1810 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
|
1811 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
|
1812 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
|
1813 res = Tkinter_Error(self); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1814 else |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1815 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
|
1816 LEAVE_OVERLAP_TCL |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1817 return res; |
| 1664 | 1818 } |
| 1819 | |
| 1820 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1821 Tkapp_ExprDouble(PyObject *self, PyObject *args) |
| 1664 | 1822 { |
| 4968 | 1823 char *s; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1824 PyObject *res = NULL; |
| 4968 | 1825 double v; |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
4968
diff
changeset
|
1826 int retval; |
| 1664 | 1827 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1828 if (!PyArg_ParseTuple(args, "s:exprdouble", &s)) |
| 4968 | 1829 return NULL; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1830 CHECK_TCL_APPARTMENT; |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
4968
diff
changeset
|
1831 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
|
1832 ENTER_TCL |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
1833 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
|
1834 ENTER_OVERLAP |
|
5197
74c12704a0bd
New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents:
5120
diff
changeset
|
1835 PyFPE_END_PROTECT(retval) |
|
5120
a48f3678f9e1
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
4968
diff
changeset
|
1836 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
|
1837 res = Tkinter_Error(self); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1838 else |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1839 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
|
1840 LEAVE_OVERLAP_TCL |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1841 return res; |
| 1664 | 1842 } |
| 1843 | |
| 1844 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1845 Tkapp_ExprBoolean(PyObject *self, PyObject *args) |
| 1664 | 1846 { |
| 4968 | 1847 char *s; |
|
8500
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1848 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
|
1849 int retval; |
| 4968 | 1850 int v; |
| 1664 | 1851 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
1852 if (!PyArg_ParseTuple(args, "s:exprboolean", &s)) |
| 4968 | 1853 return NULL; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1854 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
|
1855 ENTER_TCL |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1856 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
|
1857 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
|
1858 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
|
1859 res = Tkinter_Error(self); |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1860 else |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1861 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
|
1862 LEAVE_OVERLAP_TCL |
|
92cf7f427723
# (My first checkin from Windows NT using remote CVS!)
Guido van Rossum <guido@python.org>
parents:
8499
diff
changeset
|
1863 return res; |
| 1664 | 1864 } |
| 1865 | |
| 4968 | 1866 |
| 1867 | |
| 1664 | 1868 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1869 Tkapp_SplitList(PyObject *self, PyObject *args) |
| 1664 | 1870 { |
| 4968 | 1871 char *list; |
| 1872 int argc; | |
| 1873 char **argv; | |
| 1874 PyObject *v; | |
| 1875 int i; | |
| 1876 | |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1877 if (PyTuple_Size(args) == 1) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1878 v = PyTuple_GetItem(args, 0); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1879 if (PyTuple_Check(v)) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1880 Py_INCREF(v); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1881 return v; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1882 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1883 } |
|
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
|
1884 if (!PyArg_ParseTuple(args, "et:splitlist", "utf-8", &list)) |
| 4968 | 1885 return NULL; |
| 1886 | |
|
29295
d46459d82a79
Fix SF #745055, Memory leak in _tkinter.c/Tkapp_SplitList()
Neal Norwitz <nnorwitz@gmail.com>
parents:
29170
diff
changeset
|
1887 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
|
1888 &argc, &argv) == TCL_ERROR) { |
|
d46459d82a79
Fix SF #745055, Memory leak in _tkinter.c/Tkapp_SplitList()
Neal Norwitz <nnorwitz@gmail.com>
parents:
29170
diff
changeset
|
1889 PyMem_Free(list); |
| 4968 | 1890 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
|
1891 } |
| 1664 | 1892 |
| 4968 | 1893 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
|
1894 goto finally; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
1895 |
| 4968 | 1896 for (i = 0; i < argc; i++) { |
| 1897 PyObject *s = PyString_FromString(argv[i]); | |
| 1898 if (!s || PyTuple_SetItem(v, i, s)) { | |
| 1899 Py_DECREF(v); | |
| 1900 v = NULL; | |
| 1901 goto finally; | |
| 1902 } | |
| 1903 } | |
| 1664 | 1904 |
| 4968 | 1905 finally: |
| 1906 ckfree(FREECAST argv); | |
|
29295
d46459d82a79
Fix SF #745055, Memory leak in _tkinter.c/Tkapp_SplitList()
Neal Norwitz <nnorwitz@gmail.com>
parents:
29170
diff
changeset
|
1907 PyMem_Free(list); |
| 4968 | 1908 return v; |
| 1664 | 1909 } |
| 1910 | |
| 1911 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1912 Tkapp_Split(PyObject *self, PyObject *args) |
| 1664 | 1913 { |
|
29295
d46459d82a79
Fix SF #745055, Memory leak in _tkinter.c/Tkapp_SplitList()
Neal Norwitz <nnorwitz@gmail.com>
parents:
29170
diff
changeset
|
1914 PyObject *v; |
| 4968 | 1915 char *list; |
| 1664 | 1916 |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1917 if (PyTuple_Size(args) == 1) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1918 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
|
1919 if (PyTuple_Check(o)) { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1920 o = SplitObj(o); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1921 return o; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1922 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
1923 } |
|
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
|
1924 if (!PyArg_ParseTuple(args, "et:split", "utf-8", &list)) |
| 4968 | 1925 return NULL; |
|
29295
d46459d82a79
Fix SF #745055, Memory leak in _tkinter.c/Tkapp_SplitList()
Neal Norwitz <nnorwitz@gmail.com>
parents:
29170
diff
changeset
|
1926 v = Split(list); |
|
d46459d82a79
Fix SF #745055, Memory leak in _tkinter.c/Tkapp_SplitList()
Neal Norwitz <nnorwitz@gmail.com>
parents:
29170
diff
changeset
|
1927 PyMem_Free(list); |
|
d46459d82a79
Fix SF #745055, Memory leak in _tkinter.c/Tkapp_SplitList()
Neal Norwitz <nnorwitz@gmail.com>
parents:
29170
diff
changeset
|
1928 return v; |
| 1664 | 1929 } |
| 1930 | |
| 1931 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1932 Tkapp_Merge(PyObject *self, PyObject *args) |
| 1664 | 1933 { |
| 4968 | 1934 char *s = Merge(args); |
| 1935 PyObject *res = NULL; | |
| 1664 | 1936 |
| 4968 | 1937 if (s) { |
| 1938 res = PyString_FromString(s); | |
| 1939 ckfree(s); | |
| 1940 } | |
| 1941 | |
| 1942 return res; | |
| 1664 | 1943 } |
| 1944 | |
| 4968 | 1945 |
| 1946 | |
| 1664 | 1947 /** Tcl Command **/ |
| 1948 | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1949 /* 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
|
1950 typedef struct { |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1951 PyObject *self; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1952 PyObject *func; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1953 } PythonCmd_ClientData; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1954 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1955 static int |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1956 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
|
1957 { |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1958 errorInCmd = 1; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1959 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
|
1960 LEAVE_PYTHON |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1961 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
|
1962 } |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1963 |
| 1664 | 1964 /* This is the Tcl command that acts as a wrapper for Python |
| 4968 | 1965 * function or method. |
| 1966 */ | |
| 1664 | 1967 static int |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
1968 PythonCmd(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) |
| 1664 | 1969 { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1970 PythonCmd_ClientData *data = (PythonCmd_ClientData *)clientData; |
| 4968 | 1971 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
|
1972 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
|
1973 char *s; |
| 1664 | 1974 |
|
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
|
1975 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
|
1976 |
| 4968 | 1977 /* TBD: no error checking here since we know, via the |
| 1978 * Tkapp_CreateCommand() that the client data is a two-tuple | |
| 1979 */ | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
1980 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
|
1981 func = data->func; |
| 4968 | 1982 |
| 1983 /* Create argument list (argv1, ..., argvN) */ | |
| 1984 if (!(arg = PyTuple_New(argc - 1))) | |
| 1985 return PythonCmd_Error(interp); | |
| 1664 | 1986 |
| 4968 | 1987 for (i = 0; i < (argc - 1); i++) { |
| 1988 PyObject *s = PyString_FromString(argv[i + 1]); | |
| 1989 if (!s || PyTuple_SetItem(arg, i, s)) { | |
| 1990 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
|
1991 return PythonCmd_Error(interp); |
| 4968 | 1992 } |
| 1993 } | |
| 1994 res = PyEval_CallObject(func, arg); | |
| 1995 Py_DECREF(arg); | |
| 1713 | 1996 |
| 4968 | 1997 if (res == NULL) |
| 1998 return PythonCmd_Error(interp); | |
| 1664 | 1999 |
| 4968 | 2000 if (!(tmp = PyList_New(0))) { |
| 2001 Py_DECREF(res); | |
| 2002 return PythonCmd_Error(interp); | |
| 2003 } | |
| 1664 | 2004 |
|
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
|
2005 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
|
2006 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
|
2007 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
|
2008 } |
|
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
|
2009 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
|
2010 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
|
2011 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
|
2012 } |
|
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 |
| 4968 | 2014 Py_DECREF(res); |
| 2015 Py_DECREF(tmp); | |
| 2016 | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2017 LEAVE_PYTHON |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2018 |
|
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
|
2019 return rv; |
| 1664 | 2020 } |
| 2021 | |
| 2022 static void | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2023 PythonCmdDelete(ClientData clientData) |
| 1664 | 2024 { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2025 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
|
2026 |
|
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
|
2027 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
|
2028 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
|
2029 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
|
2030 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
|
2031 LEAVE_PYTHON |
| 1664 | 2032 } |
| 2033 | |
| 4968 | 2034 |
| 2035 | |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2036 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2037 TCL_DECLARE_MUTEX(command_mutex) |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2038 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2039 typedef struct CommandEvent{ |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2040 Tcl_Event ev; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2041 Tcl_Interp* interp; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2042 char *name; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2043 int create; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2044 int *status; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2045 ClientData *data; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2046 Tcl_Condition done; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2047 } CommandEvent; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2048 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2049 static int |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2050 Tkapp_CommandProc(CommandEvent *ev, int flags) |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2051 { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2052 if (ev->create) |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2053 *ev->status = Tcl_CreateCommand( |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2054 ev->interp, ev->name, PythonCmd, |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2055 ev->data, PythonCmdDelete) == NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2056 else |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2057 *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
|
2058 Tcl_MutexLock(&command_mutex); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2059 Tcl_ConditionNotify(&ev->done); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2060 Tcl_MutexUnlock(&command_mutex); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2061 return 1; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2062 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2063 |
| 1664 | 2064 static PyObject * |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2065 Tkapp_CreateCommand(PyObject *_self, PyObject *args) |
| 1664 | 2066 { |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2067 TkappObject *self = (TkappObject*)_self; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2068 PythonCmd_ClientData *data; |
| 4968 | 2069 char *cmdName; |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2070 PyObject *func; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2071 int err; |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2072 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
2073 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
|
2074 return NULL; |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2075 if (!PyCallable_Check(func)) { |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2076 PyErr_SetString(PyExc_TypeError, "command not callable"); |
| 4968 | 2077 return NULL; |
| 2078 } | |
| 1664 | 2079 |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
2080 #ifdef WITH_THREAD |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2081 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
|
2082 !WaitForMainloop(self)) |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2083 return NULL; |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
2084 #endif |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2085 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2086 data = PyMem_NEW(PythonCmd_ClientData, 1); |
| 4968 | 2087 if (!data) |
|
27826
7dffcc498c45
Add more missing PyErr_NoMemory() after failled memory allocs
Neal Norwitz <nnorwitz@gmail.com>
parents:
27341
diff
changeset
|
2088 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
|
2089 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
|
2090 Py_XINCREF(func); |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2091 data->self = _self; |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2092 data->func = func; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2093 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2094 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
|
2095 CommandEvent *ev = (CommandEvent*)ckalloc(sizeof(CommandEvent)); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2096 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
|
2097 ev->interp = self->interp; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2098 ev->create = 1; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2099 ev->name = cmdName; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2100 ev->data = (ClientData)data; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2101 ev->status = &err; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2102 ev->done = NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2103 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
|
2104 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2105 else { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2106 ENTER_TCL |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2107 err = Tcl_CreateCommand( |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2108 Tkapp_Interp(self), cmdName, PythonCmd, |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2109 (ClientData)data, PythonCmdDelete) == NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2110 LEAVE_TCL |
|
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 if (err) { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2113 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
|
2114 PyMem_DEL(data); |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2115 return NULL; |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2116 } |
| 1664 | 2117 |
| 4968 | 2118 Py_INCREF(Py_None); |
| 2119 return Py_None; | |
| 1664 | 2120 } |
| 2121 | |
| 4968 | 2122 |
| 2123 | |
| 1664 | 2124 static PyObject * |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2125 Tkapp_DeleteCommand(PyObject *_self, PyObject *args) |
| 1664 | 2126 { |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2127 TkappObject *self = (TkappObject*)_self; |
| 4968 | 2128 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
|
2129 int err; |
| 1664 | 2130 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
2131 if (!PyArg_ParseTuple(args, "s:deletecommand", &cmdName)) |
| 4968 | 2132 return NULL; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2133 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
|
2134 CommandEvent *ev; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2135 ev = (CommandEvent*)ckalloc(sizeof(CommandEvent)); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2136 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
|
2137 ev->interp = self->interp; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2138 ev->create = 0; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2139 ev->name = cmdName; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2140 ev->status = &err; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2141 ev->done = NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2142 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
|
2143 &command_mutex); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2144 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2145 else { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2146 ENTER_TCL |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2147 err = Tcl_DeleteCommand(self->interp, cmdName); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2148 LEAVE_TCL |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2149 } |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2150 if (err == -1) { |
| 4968 | 2151 PyErr_SetString(Tkinter_TclError, "can't delete Tcl command"); |
| 2152 return NULL; | |
| 2153 } | |
| 2154 Py_INCREF(Py_None); | |
| 2155 return Py_None; | |
| 1664 | 2156 } |
| 2157 | |
| 4968 | 2158 |
| 2159 | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2160 #ifdef HAVE_CREATEFILEHANDLER |
| 1664 | 2161 /** File Handler **/ |
| 2162 | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2163 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
|
2164 PyObject *func; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2165 PyObject *file; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2166 int id; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2167 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
|
2168 } FileHandler_ClientData; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2169 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2170 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
|
2171 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2172 static FileHandler_ClientData * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2173 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
|
2174 { |
|
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 *p; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2176 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
|
2177 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
|
2178 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
|
2179 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
|
2180 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
|
2181 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
|
2182 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
|
2183 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
|
2184 HeadFHCD = p; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2185 } |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2186 return p; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2187 } |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2188 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2189 static void |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2190 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
|
2191 { |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2192 FileHandler_ClientData *p, **pp; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2193 |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2194 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
|
2195 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
|
2196 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
|
2197 *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
|
2198 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
|
2199 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
|
2200 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
|
2201 } |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2202 else |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2203 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
|
2204 } |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2205 } |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2206 |
|
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
|
2207 static void |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2208 FileHandler(ClientData clientData, int mask) |
| 1664 | 2209 { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2210 FileHandler_ClientData *data = (FileHandler_ClientData *)clientData; |
| 4968 | 2211 PyObject *func, *file, *arg, *res; |
| 1664 | 2212 |
|
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
|
2213 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
|
2214 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
|
2215 file = data->file; |
| 1664 | 2216 |
| 4968 | 2217 arg = Py_BuildValue("(Oi)", file, (long) mask); |
| 2218 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
|
2219 Py_DECREF(arg); |
| 4968 | 2220 |
| 2221 if (res == NULL) { | |
| 2222 errorInCmd = 1; | |
| 2223 PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd); | |
| 2224 } | |
| 2225 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
|
2226 LEAVE_PYTHON |
|
1771
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
2227 } |
|
51c2e5a9f39c
* tkintermodule.c (*FileHandler): generalize to arbitrary file ids
Guido van Rossum <guido@python.org>
parents:
1756
diff
changeset
|
2228 |
| 1664 | 2229 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2230 Tkapp_CreateFileHandler(PyObject *self, PyObject *args) |
|
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2231 /* args is (file, mask, func) */ |
| 1664 | 2232 { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2233 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
|
2234 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
|
2235 int mask, tfile; |
| 1664 | 2236 |
|
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
|
2237 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
|
2238 &file, &mask, &func)) |
| 4968 | 2239 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
|
2240 |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
2241 #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
|
2242 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
|
2243 /* 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
|
2244 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
|
2245 "_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
|
2246 "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
|
2247 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
|
2248 } |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
2249 #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
|
2250 |
|
524e5f9f85e6
Don't crash on _tkinter.createfilehandler in non-threaded Tcl;
Martin v. Löwis <martin@v.loewis.de>
parents:
27826
diff
changeset
|
2251 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
|
2252 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
|
2253 } |
|
524e5f9f85e6
Don't crash on _tkinter.createfilehandler in non-threaded Tcl;
Martin v. Löwis <martin@v.loewis.de>
parents:
27826
diff
changeset
|
2254 |
|
13593
df64cc0e84e2
Use PyObject_AsFileDescriptor
Andrew M. Kuchling <amk@amk.ca>
parents:
13576
diff
changeset
|
2255 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
|
2256 if (tfile < 0) |
| 4968 | 2257 return NULL; |
| 2258 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
|
2259 PyErr_SetString(PyExc_TypeError, "bad argument list"); |
| 4968 | 2260 return NULL; |
| 2261 } | |
| 2262 | |
|
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 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
|
2264 if (data == NULL) |
| 4968 | 2265 return NULL; |
| 2266 | |
| 2267 /* 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
|
2268 ENTER_TCL |
| 4968 | 2269 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
|
2270 LEAVE_TCL |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2271 Py_INCREF(Py_None); |
| 4968 | 2272 return Py_None; |
| 1664 | 2273 } |
| 2274 | |
| 2275 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2276 Tkapp_DeleteFileHandler(PyObject *self, PyObject *args) |
| 1664 | 2277 { |
| 4968 | 2278 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
|
2279 int tfile; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2280 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
2281 if (!PyArg_ParseTuple(args, "O:deletefilehandler", &file)) |
| 4968 | 2282 return NULL; |
|
28156
3fe72a994103
Fix SF #692416, don't crash interpreter for _tkinter.deletefilehandler
Neal Norwitz <nnorwitz@gmail.com>
parents:
28142
diff
changeset
|
2283 |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
2284 #ifdef WITH_THREAD |
|
28156
3fe72a994103
Fix SF #692416, don't crash interpreter for _tkinter.deletefilehandler
Neal Norwitz <nnorwitz@gmail.com>
parents:
28142
diff
changeset
|
2285 if (!self && !tcl_lock) { |
|
3fe72a994103
Fix SF #692416, don't crash interpreter for _tkinter.deletefilehandler
Neal Norwitz <nnorwitz@gmail.com>
parents:
28142
diff
changeset
|
2286 /* 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
|
2287 PyErr_SetString(PyExc_RuntimeError, |
|
3fe72a994103
Fix SF #692416, don't crash interpreter for _tkinter.deletefilehandler
Neal Norwitz <nnorwitz@gmail.com>
parents:
28142
diff
changeset
|
2288 "_tkinter.deletefilehandler not supported " |
|
3fe72a994103
Fix SF #692416, don't crash interpreter for _tkinter.deletefilehandler
Neal Norwitz <nnorwitz@gmail.com>
parents:
28142
diff
changeset
|
2289 "for threaded Tcl"); |
|
3fe72a994103
Fix SF #692416, don't crash interpreter for _tkinter.deletefilehandler
Neal Norwitz <nnorwitz@gmail.com>
parents:
28142
diff
changeset
|
2290 return NULL; |
|
3fe72a994103
Fix SF #692416, don't crash interpreter for _tkinter.deletefilehandler
Neal Norwitz <nnorwitz@gmail.com>
parents:
28142
diff
changeset
|
2291 } |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
2292 #endif |
|
28156
3fe72a994103
Fix SF #692416, don't crash interpreter for _tkinter.deletefilehandler
Neal Norwitz <nnorwitz@gmail.com>
parents:
28142
diff
changeset
|
2293 |
|
3fe72a994103
Fix SF #692416, don't crash interpreter for _tkinter.deletefilehandler
Neal Norwitz <nnorwitz@gmail.com>
parents:
28142
diff
changeset
|
2294 if (self) { |
|
3fe72a994103
Fix SF #692416, don't crash interpreter for _tkinter.deletefilehandler
Neal Norwitz <nnorwitz@gmail.com>
parents:
28142
diff
changeset
|
2295 CHECK_TCL_APPARTMENT; |
|
3fe72a994103
Fix SF #692416, don't crash interpreter for _tkinter.deletefilehandler
Neal Norwitz <nnorwitz@gmail.com>
parents:
28142
diff
changeset
|
2296 } |
|
3fe72a994103
Fix SF #692416, don't crash interpreter for _tkinter.deletefilehandler
Neal Norwitz <nnorwitz@gmail.com>
parents:
28142
diff
changeset
|
2297 |
|
13593
df64cc0e84e2
Use PyObject_AsFileDescriptor
Andrew M. Kuchling <amk@amk.ca>
parents:
13576
diff
changeset
|
2298 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
|
2299 if (tfile < 0) |
| 4968 | 2300 return NULL; |
| 2301 | |
|
12071
9750af5e71b0
Patch by Neil Schemenauer to remove support for Tcl/Tk versions before
Guido van Rossum <guido@python.org>
parents:
12063
diff
changeset
|
2302 DeleteFHCD(tfile); |
| 1664 | 2303 |
| 4968 | 2304 /* 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
|
2305 ENTER_TCL |
| 4968 | 2306 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
|
2307 LEAVE_TCL |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2308 Py_INCREF(Py_None); |
| 4968 | 2309 return Py_None; |
| 1664 | 2310 } |
|
6026
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
2311 #endif /* HAVE_CREATEFILEHANDLER */ |
| 1664 | 2312 |
| 4968 | 2313 |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2314 /**** 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
|
2315 |
|
24280
1598a1e473e2
staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
23662
diff
changeset
|
2316 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
|
2317 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2318 typedef struct { |
| 4968 | 2319 PyObject_HEAD |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2320 Tcl_TimerToken token; |
| 4968 | 2321 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
|
2322 } TkttObject; |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2323 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2324 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2325 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
|
2326 { |
| 4968 | 2327 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
|
2328 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
|
2329 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
2330 if (!PyArg_ParseTuple(args, ":deletetimerhandler")) |
| 4968 | 2331 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
|
2332 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
|
2333 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
|
2334 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
|
2335 } |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2336 if (func != NULL) { |
| 4968 | 2337 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
|
2338 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
|
2339 Py_DECREF(v); /* See Tktt_New() */ |
| 4968 | 2340 } |
| 2341 Py_INCREF(Py_None); | |
| 2342 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
|
2343 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2344 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2345 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
|
2346 { |
|
22706
14ebd7610902
Use symbolic METH_VARARGS/METH_OLDARGS instead of 1/0 for ml_flags
Neal Norwitz <nnorwitz@gmail.com>
parents:
21813
diff
changeset
|
2347 {"deletetimerhandler", Tktt_DeleteTimerHandler, METH_VARARGS}, |
| 4968 | 2348 {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
|
2349 }; |
|
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 static TkttObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2352 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
|
2353 { |
| 4968 | 2354 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
|
2355 |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12513
diff
changeset
|
2356 v = PyObject_New(TkttObject, &Tktt_Type); |
| 4968 | 2357 if (v == NULL) |
| 2358 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
|
2359 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2360 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
|
2361 v->token = NULL; |
| 4968 | 2362 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
|
2363 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2364 /* 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
|
2365 Py_INCREF(v); |
| 4968 | 2366 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
|
2367 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2368 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2369 static void |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2370 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
|
2371 { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2372 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
|
2373 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
|
2374 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2375 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
|
2376 |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12513
diff
changeset
|
2377 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
|
2378 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2379 |
|
8312
d67be13da3cc
Trivial little change: timer tokens shouldn't have a Print() function,
Guido van Rossum <guido@python.org>
parents:
8200
diff
changeset
|
2380 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2381 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
|
2382 { |
| 4968 | 2383 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
|
2384 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
|
2385 |
|
21073
304b34023876
sprintf -> PyOS_snprintf in some "obviously safe" cases.
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
2386 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
|
2387 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
|
2388 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
|
2389 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2390 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2391 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2392 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
|
2393 { |
| 4968 | 2394 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
|
2395 } |
|
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 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
|
2398 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2399 PyObject_HEAD_INIT(NULL) |
| 4968 | 2400 0, /*ob_size */ |
| 2401 "tktimertoken", /*tp_name */ | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2402 sizeof(TkttObject), /*tp_basicsize */ |
| 4968 | 2403 0, /*tp_itemsize */ |
| 2404 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
|
2405 0, /*tp_print */ |
| 4968 | 2406 Tktt_GetAttr, /*tp_getattr */ |
| 2407 0, /*tp_setattr */ | |
| 2408 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
|
2409 Tktt_Repr, /*tp_repr */ |
| 4968 | 2410 0, /*tp_as_number */ |
| 2411 0, /*tp_as_sequence */ | |
| 2412 0, /*tp_as_mapping */ | |
| 2413 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
|
2414 }; |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2415 |
| 4968 | 2416 |
| 2417 | |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2418 /** Timer Handler **/ |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2419 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2420 static void |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2421 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
|
2422 { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2423 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
|
2424 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
|
2425 PyObject *res; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2426 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2427 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
|
2428 return; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2429 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2430 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
|
2431 |
|
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
|
2432 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
|
2433 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2434 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
|
2435 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
|
2436 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
|
2437 |
| 4968 | 2438 if (res == NULL) { |
| 2439 errorInCmd = 1; | |
| 2440 PyErr_Fetch(&excInCmd, &valInCmd, &trbInCmd); | |
| 2441 } | |
| 2442 else | |
| 2443 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
|
2444 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2445 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
|
2446 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2447 |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2448 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2449 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
|
2450 { |
| 4968 | 2451 int milliseconds; |
| 2452 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
|
2453 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
|
2454 |
|
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
|
2455 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
|
2456 &milliseconds, &func)) |
| 4968 | 2457 return NULL; |
| 2458 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
|
2459 PyErr_SetString(PyExc_TypeError, "bad argument list"); |
| 4968 | 2460 return NULL; |
| 2461 } | |
|
28142
524e5f9f85e6
Don't crash on _tkinter.createfilehandler in non-threaded Tcl;
Martin v. Löwis <martin@v.loewis.de>
parents:
27826
diff
changeset
|
2462 |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
2463 #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
|
2464 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
|
2465 /* 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
|
2466 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
|
2467 "_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
|
2468 "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
|
2469 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
|
2470 } |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
2471 #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
|
2472 |
|
524e5f9f85e6
Don't crash on _tkinter.createfilehandler in non-threaded Tcl;
Martin v. Löwis <martin@v.loewis.de>
parents:
27826
diff
changeset
|
2473 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
|
2474 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
|
2475 } |
|
524e5f9f85e6
Don't crash on _tkinter.createfilehandler in non-threaded Tcl;
Martin v. Löwis <martin@v.loewis.de>
parents:
27826
diff
changeset
|
2476 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2477 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
|
2478 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
|
2479 (ClientData)v); |
| 4968 | 2480 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2481 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
|
2482 } |
|
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2483 |
| 4968 | 2484 |
| 1664 | 2485 /** Event Loop **/ |
| 2486 | |
| 2487 static PyObject * | |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2488 Tkapp_MainLoop(PyObject *_self, PyObject *args) |
| 1664 | 2489 { |
| 4968 | 2490 int threshold = 0; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2491 TkappObject *self = (TkappObject*)_self; |
|
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
|
2492 #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
|
2493 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
|
2494 #endif |
|
2009
392db1881190
added timer and file callbacks and global mainloop and quit fns
Guido van Rossum <guido@python.org>
parents:
1888
diff
changeset
|
2495 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
2496 if (!PyArg_ParseTuple(args, "|i:mainloop", &threshold)) |
| 4968 | 2497 return NULL; |
| 1664 | 2498 |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
2499 #ifdef WITH_THREAD |
|
27083
d5e09d412b53
Remove appartment check from dooneevent. Fixes #660961.
Martin v. Löwis <martin@v.loewis.de>
parents:
27071
diff
changeset
|
2500 if (!self && !tcl_lock) { |
|
d5e09d412b53
Remove appartment check from dooneevent. Fixes #660961.
Martin v. Löwis <martin@v.loewis.de>
parents:
27071
diff
changeset
|
2501 /* 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
|
2502 PyErr_SetString(PyExc_RuntimeError, |
|
d5e09d412b53
Remove appartment check from dooneevent. Fixes #660961.
Martin v. Löwis <martin@v.loewis.de>
parents:
27071
diff
changeset
|
2503 "_tkinter.mainloop not supported " |
|
d5e09d412b53
Remove appartment check from dooneevent. Fixes #660961.
Martin v. Löwis <martin@v.loewis.de>
parents:
27071
diff
changeset
|
2504 "for threaded Tcl"); |
|
d5e09d412b53
Remove appartment check from dooneevent. Fixes #660961.
Martin v. Löwis <martin@v.loewis.de>
parents:
27071
diff
changeset
|
2505 return NULL; |
|
d5e09d412b53
Remove appartment check from dooneevent. Fixes #660961.
Martin v. Löwis <martin@v.loewis.de>
parents:
27071
diff
changeset
|
2506 } |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
2507 #endif |
|
27083
d5e09d412b53
Remove appartment check from dooneevent. Fixes #660961.
Martin v. Löwis <martin@v.loewis.de>
parents:
27071
diff
changeset
|
2508 |
|
d5e09d412b53
Remove appartment check from dooneevent. Fixes #660961.
Martin v. Löwis <martin@v.loewis.de>
parents:
27071
diff
changeset
|
2509 if (self) { |
|
d5e09d412b53
Remove appartment check from dooneevent. Fixes #660961.
Martin v. Löwis <martin@v.loewis.de>
parents:
27071
diff
changeset
|
2510 CHECK_TCL_APPARTMENT; |
|
d5e09d412b53
Remove appartment check from dooneevent. Fixes #660961.
Martin v. Löwis <martin@v.loewis.de>
parents:
27071
diff
changeset
|
2511 self->dispatching = 1; |
|
d5e09d412b53
Remove appartment check from dooneevent. Fixes #660961.
Martin v. Löwis <martin@v.loewis.de>
parents:
27071
diff
changeset
|
2512 } |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2513 |
| 4968 | 2514 quitMainLoop = 0; |
| 2515 while (Tk_GetNumMainWindows() > threshold && | |
| 2516 !quitMainLoop && | |
| 2517 !errorInCmd) | |
| 1664 | 2518 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2519 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
|
2520 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2521 #ifdef WITH_THREAD |
|
27083
d5e09d412b53
Remove appartment check from dooneevent. Fixes #660961.
Martin v. Löwis <martin@v.loewis.de>
parents:
27071
diff
changeset
|
2522 if (self && self->threaded) { |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2523 /* Allow other Python threads to run. */ |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2524 ENTER_TCL |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2525 result = Tcl_DoOneEvent(0); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2526 LEAVE_TCL |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2527 } |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2528 else { |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2529 Py_BEGIN_ALLOW_THREADS |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2530 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
|
2531 tcl_tstate = tstate; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2532 result = Tcl_DoOneEvent(TCL_DONT_WAIT); |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2533 tcl_tstate = NULL; |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2534 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
|
2535 if (result == 0) |
|
29038
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2536 Sleep(Tkinter_busywaitinterval); |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2537 Py_END_ALLOW_THREADS |
|
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2538 } |
|
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
|
2539 #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
|
2540 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
|
2541 #endif |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2542 |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2543 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
|
2544 if (self) |
|
d5e09d412b53
Remove appartment check from dooneevent. Fixes #660961.
Martin v. Löwis <martin@v.loewis.de>
parents:
27071
diff
changeset
|
2545 self->dispatching = 0; |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2546 return NULL; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2547 } |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2548 if (result < 0) |
|
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2549 break; |
| 1664 | 2550 } |
|
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; |
| 4968 | 2553 quitMainLoop = 0; |
| 1664 | 2554 |
| 4968 | 2555 if (errorInCmd) { |
| 2556 errorInCmd = 0; | |
| 2557 PyErr_Restore(excInCmd, valInCmd, trbInCmd); | |
| 2558 excInCmd = valInCmd = trbInCmd = NULL; | |
| 2559 return NULL; | |
| 2560 } | |
| 2561 Py_INCREF(Py_None); | |
| 2562 return Py_None; | |
| 1664 | 2563 } |
| 2564 | |
| 2565 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2566 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
|
2567 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2568 int flags = 0; |
| 4968 | 2569 int rv; |
|
2121
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
2570 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
2571 if (!PyArg_ParseTuple(args, "|i:dooneevent", &flags)) |
| 4968 | 2572 return NULL; |
| 2573 | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2574 ENTER_TCL |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2575 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
|
2576 LEAVE_TCL |
| 4968 | 2577 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
|
2578 } |
|
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
2579 |
|
86d9e91405c8
added interface to Tk_DoOneEvent (R Lindsay Todd)
Guido van Rossum <guido@python.org>
parents:
2055
diff
changeset
|
2580 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2581 Tkapp_Quit(PyObject *self, PyObject *args) |
| 1664 | 2582 { |
| 2583 | |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
2584 if (!PyArg_ParseTuple(args, ":quit")) |
| 4968 | 2585 return NULL; |
| 2586 | |
| 2587 quitMainLoop = 1; | |
| 2588 Py_INCREF(Py_None); | |
| 2589 return Py_None; | |
| 1664 | 2590 } |
| 2591 | |
|
8199
c31c59f192af
Add a new method of interpreter objects, interpaddr(). This returns
Guido van Rossum <guido@python.org>
parents:
8185
diff
changeset
|
2592 static PyObject * |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2593 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
|
2594 { |
|
c31c59f192af
Add a new method of interpreter objects, interpaddr(). This returns
Guido van Rossum <guido@python.org>
parents:
8185
diff
changeset
|
2595 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
11443
diff
changeset
|
2596 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
|
2597 return NULL; |
|
c31c59f192af
Add a new method of interpreter objects, interpaddr(). This returns
Guido van Rossum <guido@python.org>
parents:
8185
diff
changeset
|
2598 |
|
c31c59f192af
Add a new method of interpreter objects, interpaddr(). This returns
Guido van Rossum <guido@python.org>
parents:
8185
diff
changeset
|
2599 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
|
2600 } |
|
c31c59f192af
Add a new method of interpreter objects, interpaddr(). This returns
Guido van Rossum <guido@python.org>
parents:
8185
diff
changeset
|
2601 |
| 4968 | 2602 |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
2603 static PyObject * |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
2604 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
|
2605 { |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
2606 |
|
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
|
2607 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
|
2608 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
|
2609 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
|
2610 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
|
2611 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
|
2612 ((TkappObject*)self)->wantobjects = wantobjects; |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
2613 |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
2614 Py_INCREF(Py_None); |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
2615 return Py_None; |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
2616 } |
|
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
2617 |
|
26814
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
2618 static PyObject * |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
2619 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
|
2620 { |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
2621 |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
2622 ((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
|
2623 |
|
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
2624 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
|
2625 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
|
2626 } |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
2627 |
| 4968 | 2628 |
| 1664 | 2629 /**** Tkapp Method List ****/ |
| 2630 | |
| 2631 static PyMethodDef Tkapp_methods[] = | |
| 2632 { | |
|
26814
7c8af1979e78
Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents:
26620
diff
changeset
|
2633 {"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
|
2634 {"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
|
2635 {"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
|
2636 {"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
|
2637 {"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
|
2638 {"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
|
2639 {"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
|
2640 {"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
|
2641 {"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
|
2642 {"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
|
2643 {"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
|
2644 {"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
|
2645 {"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
|
2646 {"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
|
2647 {"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
|
2648 {"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
|
2649 {"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
|
2650 {"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
|
2651 {"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
|
2652 {"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
|
2653 {"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
|
2654 {"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
|
2655 {"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
|
2656 {"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
|
2657 {"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
|
2658 {"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
|
2659 {"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
|
2660 #ifdef HAVE_CREATEFILEHANDLER |
|
21757
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2661 {"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
|
2662 {"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
|
2663 #endif |
|
21757
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2664 {"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
|
2665 {"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
|
2666 {"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
|
2667 {"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
|
2668 {"interpaddr", Tkapp_InterpAddr, METH_VARARGS}, |
| 4968 | 2669 {NULL, NULL} |
| 1664 | 2670 }; |
| 2671 | |
| 4968 | 2672 |
| 2673 | |
| 1664 | 2674 /**** Tkapp Type Methods ****/ |
| 2675 | |
| 2676 static void | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2677 Tkapp_Dealloc(PyObject *self) |
| 1664 | 2678 { |
|
26971
4c03a4fad72e
Eliminate C++ comment.
Martin v. Löwis <martin@v.loewis.de>
parents:
26858
diff
changeset
|
2679 /*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
|
2680 ENTER_TCL |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2681 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
|
2682 LEAVE_TCL |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12513
diff
changeset
|
2683 PyObject_Del(self); |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2684 DisableEventHook(); |
| 1664 | 2685 } |
| 2686 | |
| 2687 static PyObject * | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2688 Tkapp_GetAttr(PyObject *self, char *name) |
| 1664 | 2689 { |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2690 return Py_FindMethod(Tkapp_methods, self, name); |
| 1664 | 2691 } |
| 2692 | |
| 2693 static PyTypeObject Tkapp_Type = | |
| 2694 { | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2695 PyObject_HEAD_INIT(NULL) |
| 4968 | 2696 0, /*ob_size */ |
| 2697 "tkapp", /*tp_name */ | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2698 sizeof(TkappObject), /*tp_basicsize */ |
| 4968 | 2699 0, /*tp_itemsize */ |
| 2700 Tkapp_Dealloc, /*tp_dealloc */ | |
| 2701 0, /*tp_print */ | |
| 2702 Tkapp_GetAttr, /*tp_getattr */ | |
| 2703 0, /*tp_setattr */ | |
| 2704 0, /*tp_compare */ | |
| 2705 0, /*tp_repr */ | |
| 2706 0, /*tp_as_number */ | |
| 2707 0, /*tp_as_sequence */ | |
| 2708 0, /*tp_as_mapping */ | |
| 2709 0, /*tp_hash */ | |
| 1664 | 2710 }; |
| 2711 | |
| 4968 | 2712 |
| 2713 | |
| 1664 | 2714 /**** Tkinter Module ****/ |
| 2715 | |
| 12953 | 2716 typedef struct { |
| 2717 PyObject* tuple; | |
| 2718 int size; /* current size */ | |
| 2719 int maxsize; /* allocated size */ | |
| 2720 } FlattenContext; | |
| 2721 | |
| 2722 static int | |
| 2723 _bump(FlattenContext* context, int size) | |
| 2724 { | |
|
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
|
2725 /* 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
|
2726 return true if successful, false if an exception was raised */ |
| 12953 | 2727 |
| 2728 int maxsize = context->maxsize * 2; | |
| 2729 | |
| 2730 if (maxsize < context->size + size) | |
| 2731 maxsize = context->size + size; | |
| 2732 | |
| 2733 context->maxsize = maxsize; | |
| 2734 | |
|
17976
d579a5d8b3fe
Cruft cleanup: Removed the unused last_is_sticky argument from the internal
Tim Peters <tim.peters@gmail.com>
parents:
15356
diff
changeset
|
2735 return _PyTuple_Resize(&context->tuple, maxsize) >= 0; |
| 12953 | 2736 } |
| 2737 | |
| 2738 static int | |
|
12958
3c6641c810db
Patch from Michael Hudson to fix flatten recursive data structures:
Andrew M. Kuchling <amk@amk.ca>
parents:
12953
diff
changeset
|
2739 _flatten1(FlattenContext* context, PyObject* item, int depth) |
| 12953 | 2740 { |
| 2741 /* add tuple or list to argument tuple (recursively) */ | |
| 2742 | |
| 2743 int i, size; | |
| 2744 | |
|
12958
3c6641c810db
Patch from Michael Hudson to fix flatten recursive data structures:
Andrew M. Kuchling <amk@amk.ca>
parents:
12953
diff
changeset
|
2745 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
|
2746 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
|
2747 "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
|
2748 return 0; |
|
3c6641c810db
Patch from Michael Hudson to fix flatten recursive data structures:
Andrew M. Kuchling <amk@amk.ca>
parents:
12953
diff
changeset
|
2749 } else if (PyList_Check(item)) { |
| 12953 | 2750 size = PyList_GET_SIZE(item); |
| 2751 /* 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
|
2752 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
|
2753 !_bump(context, size)) |
| 12953 | 2754 return 0; |
| 2755 /* copy items to output tuple */ | |
| 2756 for (i = 0; i < size; i++) { | |
| 2757 PyObject *o = PyList_GET_ITEM(item, i); | |
| 2758 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
|
2759 if (!_flatten1(context, o, depth + 1)) |
| 12953 | 2760 return 0; |
| 2761 } 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
|
2762 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
|
2763 !_bump(context, 1)) |
| 12953 | 2764 return 0; |
| 2765 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
|
2766 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
|
2767 context->size++, o); |
| 12953 | 2768 } |
| 2769 } | |
| 2770 } else if (PyTuple_Check(item)) { | |
| 2771 /* same, for tuples */ | |
| 2772 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
|
2773 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
|
2774 !_bump(context, size)) |
| 12953 | 2775 return 0; |
| 2776 for (i = 0; i < size; i++) { | |
| 2777 PyObject *o = PyTuple_GET_ITEM(item, i); | |
| 2778 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
|
2779 if (!_flatten1(context, o, depth + 1)) |
| 12953 | 2780 return 0; |
| 2781 } 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
|
2782 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
|
2783 !_bump(context, 1)) |
| 12953 | 2784 return 0; |
| 2785 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
|
2786 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
|
2787 context->size++, o); |
| 12953 | 2788 } |
| 2789 } | |
| 2790 } else { | |
| 2791 PyErr_SetString(PyExc_TypeError, "argument must be sequence"); | |
| 2792 return 0; | |
| 2793 } | |
| 2794 return 1; | |
| 2795 } | |
| 2796 | |
| 2797 static PyObject * | |
| 2798 Tkinter_Flatten(PyObject* self, PyObject* args) | |
| 2799 { | |
| 2800 FlattenContext context; | |
| 2801 PyObject* item; | |
| 2802 | |
| 2803 if (!PyArg_ParseTuple(args, "O:_flatten", &item)) | |
| 2804 return NULL; | |
| 2805 | |
|
13576
61e4c29d53d8
replace PyXXX_Length calls with PyXXX_Size calls
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13503
diff
changeset
|
2806 context.maxsize = PySequence_Size(item); |
| 12953 | 2807 if (context.maxsize <= 0) |
| 2808 return PyTuple_New(0); | |
| 2809 | |
| 2810 context.tuple = PyTuple_New(context.maxsize); | |
| 2811 if (!context.tuple) | |
| 2812 return NULL; | |
| 2813 | |
| 2814 context.size = 0; | |
| 2815 | |
|
12958
3c6641c810db
Patch from Michael Hudson to fix flatten recursive data structures:
Andrew M. Kuchling <amk@amk.ca>
parents:
12953
diff
changeset
|
2816 if (!_flatten1(&context, item,0)) |
| 12953 | 2817 return NULL; |
| 2818 | |
|
17976
d579a5d8b3fe
Cruft cleanup: Removed the unused last_is_sticky argument from the internal
Tim Peters <tim.peters@gmail.com>
parents:
15356
diff
changeset
|
2819 if (_PyTuple_Resize(&context.tuple, context.size)) |
| 12953 | 2820 return NULL; |
| 2821 | |
| 2822 return context.tuple; | |
| 2823 } | |
| 2824 | |
| 1664 | 2825 static PyObject * |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13593
diff
changeset
|
2826 Tkinter_Create(PyObject *self, PyObject *args) |
| 1664 | 2827 { |
| 4968 | 2828 char *screenName = NULL; |
| 2829 char *baseName = NULL; | |
| 2830 char *className = NULL; | |
| 2831 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
|
2832 int wantobjects = 0; |
| 1664 | 2833 |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
2834 baseName = strrchr(Py_GetProgramName(), '/'); |
| 4968 | 2835 if (baseName != NULL) |
| 2836 baseName++; | |
| 2837 else | |
| 2838 baseName = Py_GetProgramName(); | |
| 2839 className = "Tk"; | |
| 1664 | 2840 |
|
26431
ad75efe2f0a6
Avoid including tclInt.h.
Martin v. Löwis <martin@v.loewis.de>
parents:
26428
diff
changeset
|
2841 if (!PyArg_ParseTuple(args, "|zssii:create", |
| 4968 | 2842 &screenName, &baseName, &className, |
|
26428
0103f0b75fe2
Rename want_objects to wantobjects throughout, for consistency.
Martin v. Löwis <martin@v.loewis.de>
parents:
26416
diff
changeset
|
2843 &interactive, &wantobjects)) |
| 4968 | 2844 return NULL; |
| 1664 | 2845 |
| 4968 | 2846 return (PyObject *) Tkapp_New(screenName, baseName, className, |
|
26428
0103f0b75fe2
Rename want_objects to wantobjects throughout, for consistency.
Martin v. Löwis <martin@v.loewis.de>
parents:
26416
diff
changeset
|
2847 interactive, wantobjects); |
| 1664 | 2848 } |
| 2849 | |
|
29038
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2850 static PyObject * |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2851 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
|
2852 { |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2853 int new_val; |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2854 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
|
2855 return NULL; |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2856 if (new_val < 0) { |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2857 PyErr_SetString(PyExc_ValueError, |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2858 "busywaitinterval must be >= 0"); |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2859 return NULL; |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2860 } |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2861 Tkinter_busywaitinterval = new_val; |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2862 Py_INCREF(Py_None); |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2863 return Py_None; |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2864 } |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2865 |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2866 static char setbusywaitinterval_doc[] = |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2867 "setbusywaitinterval(n) -> None\n\ |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2868 \n\ |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2869 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
|
2870 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
|
2871 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
|
2872 frames in an animation."; |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2873 |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2874 static PyObject * |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2875 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
|
2876 { |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2877 return PyInt_FromLong(Tkinter_busywaitinterval); |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2878 } |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2879 |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2880 static char getbusywaitinterval_doc[] = |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2881 "getbusywaitinterval() -> int\n\ |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2882 \n\ |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2883 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
|
2884 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
|
2885 |
| 1664 | 2886 static PyMethodDef moduleMethods[] = |
| 2887 { | |
|
21757
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2888 {"_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
|
2889 {"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
|
2890 #ifdef HAVE_CREATEFILEHANDLER |
|
21757
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2891 {"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
|
2892 {"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
|
2893 #endif |
|
21757
40631ae74b17
Patch #477750: Use METH_ constants in Modules.
Martin v. Löwis <martin@v.loewis.de>
parents:
21322
diff
changeset
|
2894 {"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
|
2895 {"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
|
2896 {"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
|
2897 {"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
|
2898 {"setbusywaitinterval",Tkinter_setbusywaitinterval, METH_VARARGS, |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2899 setbusywaitinterval_doc}, |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2900 {"getbusywaitinterval",(PyCFunction)Tkinter_getbusywaitinterval, |
|
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2901 METH_NOARGS, getbusywaitinterval_doc}, |
| 4968 | 2902 {NULL, NULL} |
| 1664 | 2903 }; |
| 2904 | |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2905 #ifdef WAIT_FOR_STDIN |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2906 |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2907 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
|
2908 |
|
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
|
2909 #ifndef MS_WINDOWS |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2910 static void |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
2911 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
|
2912 { |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2913 stdin_ready = 1; |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2914 } |
|
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
|
2915 #endif |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2916 |
|
28445
3fc5764273d9
Wrap thread stuff in WITH_THREAD. Fixes #704641.
Martin v. Löwis <martin@v.loewis.de>
parents:
28444
diff
changeset
|
2917 #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
|
2918 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
|
2919 #endif |
|
6438
9e46ecf03c3e
Fix EventHook (the trick to make widgets appear when using GNU
Guido van Rossum <guido@python.org>
parents:
6343
diff
changeset
|
2920 |
| 1664 | 2921 static int |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13593
diff
changeset
|
2922 EventHook(void) |
| 1664 | 2923 { |
|
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
|
2924 #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
|
2925 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
|
2926 #endif |
|
9488
b0ca2ca586b1
RajGopal Srinivasan noted that the latest code doesn't work when
Guido van Rossum <guido@python.org>
parents:
9327
diff
changeset
|
2927 #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
|
2928 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
|
2929 #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
|
2930 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
|
2931 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
|
2932 #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
|
2933 tfile = fileno(stdin); |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2934 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
|
2935 #endif |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2936 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
|
2937 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
|
2938 #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
|
2939 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
|
2940 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
|
2941 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
|
2942 } |
|
0447ef8483c8
Fixed the EventHook() code so that it also works on Windows, sort of.
Guido van Rossum <guido@python.org>
parents:
8446
diff
changeset
|
2943 #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
|
2944 #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
|
2945 Py_BEGIN_ALLOW_THREADS |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2946 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
|
2947 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
|
2948 |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2949 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
|
2950 |
|
8918e4f54eca
Patch by Jonathan Giddy (with some cleanup by me) to always use the
Guido van Rossum <guido@python.org>
parents:
9308
diff
changeset
|
2951 tcl_tstate = NULL; |
|
26613
28bc2d3af91d
Support threads-enabled Tcl installations.
Martin v. Löwis <martin@v.loewis.de>
parents:
26572
diff
changeset
|
2952 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
|
2953 if (result == 0) |
|
29038
d3c1a03a5130
Patch #734118: Add {get|set}busywaitinterval.
Martin v. Löwis <martin@v.loewis.de>
parents:
28950
diff
changeset
|
2954 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
|
2955 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
|
2956 #else |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2957 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
|
2958 #endif |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2959 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2960 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
|
2961 break; |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2962 } |
|
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
|
2963 #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
|
2964 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
|
2965 #endif |
| 4968 | 2966 if (errorInCmd) { |
| 2967 errorInCmd = 0; | |
| 2968 PyErr_Restore(excInCmd, valInCmd, trbInCmd); | |
| 2969 excInCmd = valInCmd = trbInCmd = NULL; | |
| 2970 PyErr_Print(); | |
| 2971 } | |
|
9488
b0ca2ca586b1
RajGopal Srinivasan noted that the latest code doesn't work when
Guido van Rossum <guido@python.org>
parents:
9327
diff
changeset
|
2972 #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
|
2973 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
|
2974 #endif |
| 4968 | 2975 return 0; |
| 1664 | 2976 } |
| 2977 | |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2978 #endif |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2979 |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2980 static void |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13593
diff
changeset
|
2981 EnableEventHook(void) |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2982 { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2983 #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
|
2984 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
|
2985 #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
|
2986 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
|
2987 #endif |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2988 PyOS_InputHook = EventHook; |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2989 } |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2990 #endif |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2991 } |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2992 |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2993 static void |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13593
diff
changeset
|
2994 DisableEventHook(void) |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2995 { |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
2996 #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
|
2997 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
|
2998 PyOS_InputHook = NULL; |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
2999 } |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
3000 #endif |
|
8417
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
3001 } |
|
f398419d50f9
Use a different implementation of EventHook(). The new version
Guido van Rossum <guido@python.org>
parents:
8315
diff
changeset
|
3002 |
| 4968 | 3003 |
| 3004 /* all errors will be checked in one fell swoop in init_tkinter() */ | |
| 3005 static void | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
3006 ins_long(PyObject *d, char *name, long val) |
| 4968 | 3007 { |
| 3008 PyObject *v = PyInt_FromLong(val); | |
| 3009 if (v) { | |
| 3010 PyDict_SetItemString(d, name, v); | |
| 3011 Py_DECREF(v); | |
| 3012 } | |
| 3013 } | |
| 3014 static void | |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
3015 ins_string(PyObject *d, char *name, char *val) |
| 4968 | 3016 { |
| 3017 PyObject *v = PyString_FromString(val); | |
| 3018 if (v) { | |
| 3019 PyDict_SetItemString(d, name, v); | |
| 3020 Py_DECREF(v); | |
| 3021 } | |
| 3022 } | |
| 3023 | |
| 3024 | |
|
24363
979ff5d0ae07
Replace DL_IMPORT with PyMODINIT_FUNC and remove "/export:init..." link
Mark Hammond <mhammond@skippinet.com.au>
parents:
24280
diff
changeset
|
3025 PyMODINIT_FUNC |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13593
diff
changeset
|
3026 init_tkinter(void) |
| 1664 | 3027 { |
| 4968 | 3028 PyObject *m, *d; |
| 1664 | 3029 |
| 4968 | 3030 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
|
3031 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
3032 #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
|
3033 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
|
3034 #endif |
|
4091
dc946cab7b9b
Hacks to support being a Windows DLL
Guido van Rossum <guido@python.org>
parents:
4079
diff
changeset
|
3035 |
| 4968 | 3036 m = Py_InitModule("_tkinter", moduleMethods); |
| 1664 | 3037 |
| 4968 | 3038 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
|
3039 Tkinter_TclError = PyErr_NewException("_tkinter.TclError", NULL, NULL); |
| 4968 | 3040 PyDict_SetItemString(d, "TclError", Tkinter_TclError); |
| 3041 | |
|
5914
5155b2c35e15
Functionality enhancement: allow other threads to use Tk commands
Guido van Rossum <guido@python.org>
parents:
5913
diff
changeset
|
3042 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
|
3043 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
|
3044 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
|
3045 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
|
3046 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
|
3047 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
|
3048 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
|
3049 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
|
3050 ins_long(d, "DONT_WAIT", TCL_DONT_WAIT); |
| 4968 | 3051 ins_string(d, "TK_VERSION", TK_VERSION); |
| 3052 ins_string(d, "TCL_VERSION", TCL_VERSION); | |
| 1664 | 3053 |
|
6311
13fbd98d81cc
Export names for the types defined by this module: TkappType and TkttType.
Guido van Rossum <guido@python.org>
parents:
6265
diff
changeset
|
3054 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
|
3055 |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
3056 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
|
3057 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
|
3058 |
|
26416
bd09e3a2d536
Patch #518625: Return objects in Tkinter.
Martin v. Löwis <martin@v.loewis.de>
parents:
25530
diff
changeset
|
3059 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
|
3060 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
|
3061 |
|
1852caba7014
Mods by Tony Lownds (patch 490100, slightly massaged by me) to make Tkinter
Jack Jansen <jack.jansen@cwi.nl>
parents:
21073
diff
changeset
|
3062 #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
|
3063 /* 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
|
3064 * 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
|
3065 * 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
|
3066 * 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
|
3067 * |
|
1852caba7014
Mods by Tony Lownds (patch 490100, slightly massaged by me) to make Tkinter
Jack Jansen <jack.jansen@cwi.nl>
parents:
21073
diff
changeset
|
3068 * 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
|
3069 * 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
|
3070 * 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
|
3071 * |
|
1852caba7014
Mods by Tony Lownds (patch 490100, slightly massaged by me) to make Tkinter
Jack Jansen <jack.jansen@cwi.nl>
parents:
21073
diff
changeset
|
3072 */ |
|
1852caba7014
Mods by Tony Lownds (patch 490100, slightly massaged by me) to make Tkinter
Jack Jansen <jack.jansen@cwi.nl>
parents:
21073
diff
changeset
|
3073 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
|
3074 #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
|
3075 |
|
1852caba7014
Mods by Tony Lownds (patch 490100, slightly massaged by me) to make Tkinter
Jack Jansen <jack.jansen@cwi.nl>
parents:
21073
diff
changeset
|
3076 |
|
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
|
3077 /* 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
|
3078 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
|
3079 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
|
3080 |
| 4968 | 3081 if (PyErr_Occurred()) |
|
7212
b9bbfa169920
Register Tcl_Finalize as a Python exit handler.
Guido van Rossum <guido@python.org>
parents:
6478
diff
changeset
|
3082 return; |
|
b9bbfa169920
Register Tcl_Finalize as a Python exit handler.
Guido van Rossum <guido@python.org>
parents:
6478
diff
changeset
|
3083 |
|
8670
07e47370fcb8
Temporarily get rid of the registration of Tcl_Finalize() as a
Guido van Rossum <guido@python.org>
parents:
8639
diff
changeset
|
3084 #if 0 |
|
07e47370fcb8
Temporarily get rid of the registration of Tcl_Finalize() as a
Guido van Rossum <guido@python.org>
parents:
8639
diff
changeset
|
3085 /* 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
|
3086 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
|
3087 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
|
3088 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
|
3089 #endif |
|
7212
b9bbfa169920
Register Tcl_Finalize as a Python exit handler.
Guido van Rossum <guido@python.org>
parents:
6478
diff
changeset
|
3090 |
|
3240
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
3091 #ifdef macintosh |
|
6026
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
3092 /* |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
3093 ** Part of this code is stolen from MacintoshInit in tkMacAppInit. |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
3094 ** Most of the initializations in that routine (toolbox init calls and |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
3095 ** such) have already been done for us, so we only need these. |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
3096 */ |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
3097 tcl_macQdPtr = &qd; |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
3098 |
|
b5804154af4d
Merge Mac and Windows mods (which mostly affect the same problem -- no
Guido van Rossum <guido@python.org>
parents:
5973
diff
changeset
|
3099 Tcl_MacSetEventProc(PyMacConvertEvent); |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
3100 #if GENERATINGCFM |
| 4968 | 3101 mac_addlibresources(); |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
3102 #endif /* GENERATINGCFM */ |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
3103 #endif /* macintosh */ |
| 1664 | 3104 } |
| 3120 | 3105 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
3106 |
| 4968 | 3107 |
| 3120 | 3108 #ifdef macintosh |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
3109 |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
3110 /* |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
3111 ** Anyone who embeds Tcl/Tk on the Mac must define panic(). |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
3112 */ |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
3113 |
| 3120 | 3114 void |
| 3115 panic(char * format, ...) | |
| 3116 { | |
| 4968 | 3117 va_list varg; |
| 3120 | 3118 |
| 4968 | 3119 va_start(varg, format); |
| 3120 | 3120 |
|
8828
8532141cff4c
Undo a silly effect of a global substitution: the macintosh panic()
Guido van Rossum <guido@python.org>
parents:
8670
diff
changeset
|
3121 vfprintf(stderr, format, varg); |
| 4968 | 3122 (void) fflush(stderr); |
| 3120 | 3123 |
| 4968 | 3124 va_end(varg); |
| 3120 | 3125 |
| 4968 | 3126 Py_FatalError("Tcl/Tk panic"); |
| 3120 | 3127 } |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
3128 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
3129 /* |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
3130 ** Pass events to SIOUX before passing them to Tk. |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
3131 */ |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
3132 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
3133 static int |
|
13421
346df1920873
Removed Py_PROTO, ANSI-fied sources.
Fred Drake <fdrake@acm.org>
parents:
13255
diff
changeset
|
3134 PyMacConvertEvent(EventRecord *eventPtr) |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
3135 { |
|
8185
929b7e6e7520
On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents:
8096
diff
changeset
|
3136 WindowPtr frontwin; |
|
929b7e6e7520
On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents:
8096
diff
changeset
|
3137 /* |
|
8444
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
3138 ** Sioux eats too many events, so we don't pass it everything. We |
|
6f70ca7c84e6
Changes to make it possible to write multi-threaded programs using
Guido van Rossum <guido@python.org>
parents:
8417
diff
changeset
|
3139 ** always pass update events to Sioux, and we only pass other events if |
|
8185
929b7e6e7520
On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents:
8096
diff
changeset
|
3140 ** the Sioux window is frontmost. This means that Tk menus don't work |
|
929b7e6e7520
On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents:
8096
diff
changeset
|
3141 ** in that case, but at least we can scroll the sioux window. |
|
929b7e6e7520
On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents:
8096
diff
changeset
|
3142 ** Note that the SIOUXIsAppWindow() routine we use here is not really |
|
929b7e6e7520
On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents:
8096
diff
changeset
|
3143 ** part of the external interface of Sioux... |
|
929b7e6e7520
On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents:
8096
diff
changeset
|
3144 */ |
|
929b7e6e7520
On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents:
8096
diff
changeset
|
3145 frontwin = FrontWindow(); |
|
929b7e6e7520
On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents:
8096
diff
changeset
|
3146 if ( eventPtr->what == updateEvt || SIOUXIsAppWindow(frontwin) ) { |
|
929b7e6e7520
On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents:
8096
diff
changeset
|
3147 if (SIOUXHandleOneEvent(eventPtr)) |
|
929b7e6e7520
On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents:
8096
diff
changeset
|
3148 return 0; /* Nothing happened to the Tcl event queue */ |
|
929b7e6e7520
On the Mac a call to TkMacInitMenus is needed. Also, we pass
Guido van Rossum <guido@python.org>
parents:
8096
diff
changeset
|
3149 } |
| 4968 | 3150 return TkMacConvertEvent(eventPtr); |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
3151 } |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
3152 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
3153 #if GENERATINGCFM |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
3154 |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
3155 /* |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
3156 ** Additional Mac specific code for dealing with shared libraries. |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
3157 */ |
|
3262
bfb63b45ff0f
Initialize GUSI on the mac.
Jack Jansen <jack.jansen@cwi.nl>
parents:
3240
diff
changeset
|
3158 |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
3159 #include <Resources.h> |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
3160 #include <CodeFragments.h> |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
3161 |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
3162 static int loaded_from_shlib = 0; |
|
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
3163 static FSSpec library_fss; |
| 3120 | 3164 |
|
3240
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
3165 /* |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
3166 ** If this module is dynamically loaded the following routine should |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
3167 ** be the init routine. It takes care of adding the shared library to |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
3168 ** the resource-file chain, so that the tk routines can find their |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
3169 ** resources. |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
3170 */ |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
3171 OSErr pascal |
|
5360
f858038b64c2
Adapt Mac specific code to new universal headers (I think -- this is
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
3172 init_tkinter_shlib(CFragInitBlockPtr data) |
|
3240
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
3173 { |
|
4139
010344b4a616
Call __initialize(), not __sinit() on Mac dynamic loading entry.
Guido van Rossum <guido@python.org>
parents:
4091
diff
changeset
|
3174 __initialize(); |
|
3240
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
3175 if ( data == nil ) return noErr; |
|
5360
f858038b64c2
Adapt Mac specific code to new universal headers (I think -- this is
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
3176 if ( data->fragLocator.where == kDataForkCFragLocator ) { |
|
3240
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
3177 library_fss = *data->fragLocator.u.onDisk.fileSpec; |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
3178 loaded_from_shlib = 1; |
|
5360
f858038b64c2
Adapt Mac specific code to new universal headers (I think -- this is
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
3179 } else if ( data->fragLocator.where == kResourceCFragLocator ) { |
|
3240
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
3180 library_fss = *data->fragLocator.u.inSegs.fileSpec; |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
3181 loaded_from_shlib = 1; |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
3182 } |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
3183 return noErr; |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
3184 } |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
3185 |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
3186 /* |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
3187 ** Insert the library resources into the search path. Put them after |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
3188 ** the resources from the application. Again, we ignore errors. |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
3189 */ |
|
3413
2fe7d489654e
Changes to make it work with Tcl/Tk beta 1.
Guido van Rossum <guido@python.org>
parents:
3386
diff
changeset
|
3190 static |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13593
diff
changeset
|
3191 mac_addlibresources(void) |
|
3240
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
3192 { |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
3193 if ( !loaded_from_shlib ) |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
3194 return; |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
3195 (void)FSpOpenResFile(&library_fss, fsRdPerm); |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
3196 } |
|
f7fd85b32a7d
Fix to load needed resources on a mac
Jack Jansen <jack.jansen@cwi.nl>
parents:
3231
diff
changeset
|
3197 |
|
3414
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
3198 #endif /* GENERATINGCFM */ |
|
098cbd6d196e
Changes needed to build with Tcl/Tk beta 2!
Guido van Rossum <guido@python.org>
parents:
3413
diff
changeset
|
3199 #endif /* macintosh */ |
