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