Mercurial > cpython-lru_cache-weakref
annotate PC/msvcrtmodule.c @ 54294:dba767bc3155 legacy-trunk
remove mention of old ctypes version
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sat, 23 May 2009 20:59:09 +0000 |
| parents | ab12d716a7a8 |
| children | 992fd0547ff8 c502ec243458 |
| rev | line source |
|---|---|
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 /********************************************************* |
|
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 |
|
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 msvcrtmodule.c |
|
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 |
|
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 A Python interface to the Microsoft Visual C Runtime |
|
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 Library, providing access to those non-portable, but |
|
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
7 still useful routines. |
|
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 |
|
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 Only ever compiled with an MS compiler, so no attempt |
|
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 has been made to avoid MS language extensions, etc... |
|
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
12 This may only work on NT or 95... |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
13 |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
14 Author: Mark Hammond and Guido van Rossum. |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
15 Maintenance: Guido van Rossum. |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
16 |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
17 ***********************************************************/ |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
18 |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
19 #include "Python.h" |
|
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
20 #include "malloc.h" |
|
15513
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
21 #include <io.h> |
|
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
22 #include <conio.h> |
|
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
23 #include <sys/locking.h> |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
24 |
|
49913
ab12d716a7a8
Merged revisions 67455 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47666
diff
changeset
|
25 #ifdef _MSC_VER |
|
ab12d716a7a8
Merged revisions 67455 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47666
diff
changeset
|
26 #if _MSC_VER >= 1500 |
|
ab12d716a7a8
Merged revisions 67455 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47666
diff
changeset
|
27 #include <crtassem.h> |
|
ab12d716a7a8
Merged revisions 67455 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47666
diff
changeset
|
28 #endif |
|
ab12d716a7a8
Merged revisions 67455 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47666
diff
changeset
|
29 #endif |
|
ab12d716a7a8
Merged revisions 67455 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47666
diff
changeset
|
30 |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
31 // Force the malloc heap to clean itself up, and free unused blocks |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
32 // back to the OS. (According to the docs, only works on NT.) |
|
15513
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
33 static PyObject * |
|
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
34 msvcrt_heapmin(PyObject *self, PyObject *args) |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 { |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
36 if (!PyArg_ParseTuple(args, ":heapmin")) |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
37 return NULL; |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
38 |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
39 if (_heapmin() != 0) |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 return PyErr_SetFromErrno(PyExc_IOError); |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
41 |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
42 Py_INCREF(Py_None); |
|
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
43 return Py_None; |
|
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
44 } |
|
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
45 |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
46 // Perform locking operations on a C runtime file descriptor. |
|
15513
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
47 static PyObject * |
|
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
48 msvcrt_locking(PyObject *self, PyObject *args) |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
49 { |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
50 int fd; |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
51 int mode; |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
52 long nbytes; |
|
8445
024714558620
Release the interpreter lock for calls that may block: _locking(),
Guido van Rossum <guido@python.org>
parents:
6000
diff
changeset
|
53 int err; |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
54 |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
55 if (!PyArg_ParseTuple(args, "iil:locking", &fd, &mode, &nbytes)) |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
56 return NULL; |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
57 |
|
8445
024714558620
Release the interpreter lock for calls that may block: _locking(),
Guido van Rossum <guido@python.org>
parents:
6000
diff
changeset
|
58 Py_BEGIN_ALLOW_THREADS |
|
024714558620
Release the interpreter lock for calls that may block: _locking(),
Guido van Rossum <guido@python.org>
parents:
6000
diff
changeset
|
59 err = _locking(fd, mode, nbytes); |
|
024714558620
Release the interpreter lock for calls that may block: _locking(),
Guido van Rossum <guido@python.org>
parents:
6000
diff
changeset
|
60 Py_END_ALLOW_THREADS |
|
024714558620
Release the interpreter lock for calls that may block: _locking(),
Guido van Rossum <guido@python.org>
parents:
6000
diff
changeset
|
61 if (err != 0) |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
62 return PyErr_SetFromErrno(PyExc_IOError); |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
63 |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
64 Py_INCREF(Py_None); |
|
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
65 return Py_None; |
|
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
66 } |
|
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
67 |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
68 // Set the file translation mode for a C runtime file descriptor. |
|
15513
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
69 static PyObject * |
|
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
70 msvcrt_setmode(PyObject *self, PyObject *args) |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
71 { |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
72 int fd; |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
73 int flags; |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
74 if (!PyArg_ParseTuple(args,"ii:setmode", &fd, &flags)) |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
75 return NULL; |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
76 |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
77 flags = _setmode(fd, flags); |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
78 if (flags == -1) |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
79 return PyErr_SetFromErrno(PyExc_IOError); |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
80 |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
81 return PyInt_FromLong(flags); |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
82 } |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
83 |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
84 // Convert an OS file handle to a C runtime file descriptor. |
|
15513
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
85 static PyObject * |
|
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
86 msvcrt_open_osfhandle(PyObject *self, PyObject *args) |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
87 { |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
88 long handle; |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
89 int flags; |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
90 int fd; |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
91 |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
92 if (!PyArg_ParseTuple(args, "li:open_osfhandle", &handle, &flags)) |
|
8445
024714558620
Release the interpreter lock for calls that may block: _locking(),
Guido van Rossum <guido@python.org>
parents:
6000
diff
changeset
|
93 return NULL; |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
94 |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
95 fd = _open_osfhandle(handle, flags); |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
96 if (fd == -1) |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
97 return PyErr_SetFromErrno(PyExc_IOError); |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
98 |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
99 return PyInt_FromLong(fd); |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
100 } |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
101 |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
102 // Convert a C runtime file descriptor to an OS file handle. |
|
15513
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
103 static PyObject * |
|
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
104 msvcrt_get_osfhandle(PyObject *self, PyObject *args) |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
105 { |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
106 int fd; |
|
19568
b0f5278a2ab4
SF bug [#456252] Python should never stomp on [u]intptr_t.
Tim Peters <tim.peters@gmail.com>
parents:
15513
diff
changeset
|
107 Py_intptr_t handle; |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
108 |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
109 if (!PyArg_ParseTuple(args,"i:get_osfhandle", &fd)) |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
110 return NULL; |
|
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
111 |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
112 handle = _get_osfhandle(fd); |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
113 if (handle == -1) |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
114 return PyErr_SetFromErrno(PyExc_IOError); |
|
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
115 |
|
13233
86c9f691f379
[*** Not tested as I don't have Windows running right now! ***]
Fred Drake <fdrake@acm.org>
parents:
10189
diff
changeset
|
116 /* technically 'handle' is not a pointer, but a integer as |
|
86c9f691f379
[*** Not tested as I don't have Windows running right now! ***]
Fred Drake <fdrake@acm.org>
parents:
10189
diff
changeset
|
117 large as a pointer, Python's *VoidPtr interface is the |
|
86c9f691f379
[*** Not tested as I don't have Windows running right now! ***]
Fred Drake <fdrake@acm.org>
parents:
10189
diff
changeset
|
118 most appropriate here */ |
|
86c9f691f379
[*** Not tested as I don't have Windows running right now! ***]
Fred Drake <fdrake@acm.org>
parents:
10189
diff
changeset
|
119 return PyLong_FromVoidPtr((void*)handle); |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
120 } |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
121 |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
122 /* Console I/O */ |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
123 |
|
15513
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
124 static PyObject * |
|
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
125 msvcrt_kbhit(PyObject *self, PyObject *args) |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
126 { |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
127 int ok; |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
128 |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
129 if (!PyArg_ParseTuple(args, ":kbhit")) |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
130 return NULL; |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
131 |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
132 ok = _kbhit(); |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
133 return PyInt_FromLong(ok); |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
134 } |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
135 |
|
15513
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
136 static PyObject * |
|
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
137 msvcrt_getch(PyObject *self, PyObject *args) |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
138 { |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
139 int ch; |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
140 char s[1]; |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
141 |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
142 if (!PyArg_ParseTuple(args, ":getch")) |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
143 return NULL; |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
144 |
|
8445
024714558620
Release the interpreter lock for calls that may block: _locking(),
Guido van Rossum <guido@python.org>
parents:
6000
diff
changeset
|
145 Py_BEGIN_ALLOW_THREADS |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
146 ch = _getch(); |
|
8445
024714558620
Release the interpreter lock for calls that may block: _locking(),
Guido van Rossum <guido@python.org>
parents:
6000
diff
changeset
|
147 Py_END_ALLOW_THREADS |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
148 s[0] = ch; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
149 return PyString_FromStringAndSize(s, 1); |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
150 } |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
151 |
|
47666
fcfe10f3dc14
Restore support for Microsoft VC6 compiler.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47527
diff
changeset
|
152 #ifdef _WCONIO_DEFINED |
|
15513
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
153 static PyObject * |
|
44250
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
154 msvcrt_getwch(PyObject *self, PyObject *args) |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
155 { |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
156 Py_UNICODE ch; |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
157 Py_UNICODE u[1]; |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
158 |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
159 if (!PyArg_ParseTuple(args, ":getwch")) |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
160 return NULL; |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
161 |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
162 Py_BEGIN_ALLOW_THREADS |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
163 ch = _getwch(); |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
164 Py_END_ALLOW_THREADS |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
165 u[0] = ch; |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
166 return PyUnicode_FromUnicode(u, 1); |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
167 } |
|
47666
fcfe10f3dc14
Restore support for Microsoft VC6 compiler.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47527
diff
changeset
|
168 #endif |
|
44250
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
169 |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
170 static PyObject * |
|
15513
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
171 msvcrt_getche(PyObject *self, PyObject *args) |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
172 { |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
173 int ch; |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
174 char s[1]; |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
175 |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
176 if (!PyArg_ParseTuple(args, ":getche")) |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
177 return NULL; |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
178 |
|
8445
024714558620
Release the interpreter lock for calls that may block: _locking(),
Guido van Rossum <guido@python.org>
parents:
6000
diff
changeset
|
179 Py_BEGIN_ALLOW_THREADS |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
180 ch = _getche(); |
|
8445
024714558620
Release the interpreter lock for calls that may block: _locking(),
Guido van Rossum <guido@python.org>
parents:
6000
diff
changeset
|
181 Py_END_ALLOW_THREADS |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
182 s[0] = ch; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
183 return PyString_FromStringAndSize(s, 1); |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
184 } |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
185 |
|
47666
fcfe10f3dc14
Restore support for Microsoft VC6 compiler.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47527
diff
changeset
|
186 #ifdef _WCONIO_DEFINED |
|
15513
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
187 static PyObject * |
|
44250
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
188 msvcrt_getwche(PyObject *self, PyObject *args) |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
189 { |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
190 Py_UNICODE ch; |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
191 Py_UNICODE s[1]; |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
192 |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
193 if (!PyArg_ParseTuple(args, ":getwche")) |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
194 return NULL; |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
195 |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
196 Py_BEGIN_ALLOW_THREADS |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
197 ch = _getwche(); |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
198 Py_END_ALLOW_THREADS |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
199 s[0] = ch; |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
200 return PyUnicode_FromUnicode(s, 1); |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
201 } |
|
47666
fcfe10f3dc14
Restore support for Microsoft VC6 compiler.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47527
diff
changeset
|
202 #endif |
|
44250
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
203 |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
204 static PyObject * |
|
15513
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
205 msvcrt_putch(PyObject *self, PyObject *args) |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
206 { |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
207 char ch; |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
208 |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
209 if (!PyArg_ParseTuple(args, "c:putch", &ch)) |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
210 return NULL; |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
211 |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
212 _putch(ch); |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
213 Py_INCREF(Py_None); |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
214 return Py_None; |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
215 } |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
216 |
|
47666
fcfe10f3dc14
Restore support for Microsoft VC6 compiler.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47527
diff
changeset
|
217 #ifdef _WCONIO_DEFINED |
|
44250
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
218 static PyObject * |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
219 msvcrt_putwch(PyObject *self, PyObject *args) |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
220 { |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
221 Py_UNICODE *ch; |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
222 int size; |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
223 |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
224 if (!PyArg_ParseTuple(args, "u#:putwch", &ch, &size)) |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
225 return NULL; |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
226 |
|
44251
2028feb94b57
Stupid save all didn't safe it all ...
Christian Heimes <christian@cheimes.de>
parents:
44250
diff
changeset
|
227 if (size == 0) { |
|
44250
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
228 PyErr_SetString(PyExc_ValueError, |
|
44251
2028feb94b57
Stupid save all didn't safe it all ...
Christian Heimes <christian@cheimes.de>
parents:
44250
diff
changeset
|
229 "Expected unicode string of length 1"); |
|
2028feb94b57
Stupid save all didn't safe it all ...
Christian Heimes <christian@cheimes.de>
parents:
44250
diff
changeset
|
230 return NULL; |
|
44250
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
231 } |
|
44251
2028feb94b57
Stupid save all didn't safe it all ...
Christian Heimes <christian@cheimes.de>
parents:
44250
diff
changeset
|
232 _putwch(*ch); |
|
2028feb94b57
Stupid save all didn't safe it all ...
Christian Heimes <christian@cheimes.de>
parents:
44250
diff
changeset
|
233 Py_RETURN_NONE; |
|
2028feb94b57
Stupid save all didn't safe it all ...
Christian Heimes <christian@cheimes.de>
parents:
44250
diff
changeset
|
234 |
|
44250
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
235 } |
|
47666
fcfe10f3dc14
Restore support for Microsoft VC6 compiler.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47527
diff
changeset
|
236 #endif |
|
44250
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
237 |
|
15513
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
238 static PyObject * |
|
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
239 msvcrt_ungetch(PyObject *self, PyObject *args) |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
240 { |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
241 char ch; |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
242 |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
243 if (!PyArg_ParseTuple(args, "c:ungetch", &ch)) |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
244 return NULL; |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
245 |
|
10189
bd30d39797a4
Check for potential error returned by _ungetch().
Guido van Rossum <guido@python.org>
parents:
8445
diff
changeset
|
246 if (_ungetch(ch) == EOF) |
|
bd30d39797a4
Check for potential error returned by _ungetch().
Guido van Rossum <guido@python.org>
parents:
8445
diff
changeset
|
247 return PyErr_SetFromErrno(PyExc_IOError); |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
248 Py_INCREF(Py_None); |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
249 return Py_None; |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
250 } |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
251 |
|
47666
fcfe10f3dc14
Restore support for Microsoft VC6 compiler.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47527
diff
changeset
|
252 #ifdef _WCONIO_DEFINED |
|
44250
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
253 static PyObject * |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
254 msvcrt_ungetwch(PyObject *self, PyObject *args) |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
255 { |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
256 Py_UNICODE ch; |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
257 |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
258 if (!PyArg_ParseTuple(args, "u:ungetwch", &ch)) |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
259 return NULL; |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
260 |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
261 if (_ungetch(ch) == EOF) |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
262 return PyErr_SetFromErrno(PyExc_IOError); |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
263 Py_INCREF(Py_None); |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
264 return Py_None; |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
265 } |
|
47666
fcfe10f3dc14
Restore support for Microsoft VC6 compiler.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47527
diff
changeset
|
266 #endif |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
267 |
|
15513
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
268 static void |
|
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
269 insertint(PyObject *d, char *name, int value) |
|
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
270 { |
|
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
271 PyObject *v = PyInt_FromLong((long) value); |
|
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
272 if (v == NULL) { |
|
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
273 /* Don't bother reporting this error */ |
|
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
274 PyErr_Clear(); |
|
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
275 } |
|
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
276 else { |
|
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
277 PyDict_SetItemString(d, name, v); |
|
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
278 Py_DECREF(v); |
|
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
279 } |
|
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
280 } |
|
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
281 |
|
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
282 |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
283 /* List of functions exported by this module */ |
|
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
284 static struct PyMethodDef msvcrt_functions[] = { |
|
22705
8703d2052339
Use symbolic METH_VARARGS instead of 1 for ml_flags
Neal Norwitz <nnorwitz@gmail.com>
parents:
19568
diff
changeset
|
285 {"heapmin", msvcrt_heapmin, METH_VARARGS}, |
|
8703d2052339
Use symbolic METH_VARARGS instead of 1 for ml_flags
Neal Norwitz <nnorwitz@gmail.com>
parents:
19568
diff
changeset
|
286 {"locking", msvcrt_locking, METH_VARARGS}, |
|
8703d2052339
Use symbolic METH_VARARGS instead of 1 for ml_flags
Neal Norwitz <nnorwitz@gmail.com>
parents:
19568
diff
changeset
|
287 {"setmode", msvcrt_setmode, METH_VARARGS}, |
|
8703d2052339
Use symbolic METH_VARARGS instead of 1 for ml_flags
Neal Norwitz <nnorwitz@gmail.com>
parents:
19568
diff
changeset
|
288 {"open_osfhandle", msvcrt_open_osfhandle, METH_VARARGS}, |
|
8703d2052339
Use symbolic METH_VARARGS instead of 1 for ml_flags
Neal Norwitz <nnorwitz@gmail.com>
parents:
19568
diff
changeset
|
289 {"get_osfhandle", msvcrt_get_osfhandle, METH_VARARGS}, |
|
8703d2052339
Use symbolic METH_VARARGS instead of 1 for ml_flags
Neal Norwitz <nnorwitz@gmail.com>
parents:
19568
diff
changeset
|
290 {"kbhit", msvcrt_kbhit, METH_VARARGS}, |
|
8703d2052339
Use symbolic METH_VARARGS instead of 1 for ml_flags
Neal Norwitz <nnorwitz@gmail.com>
parents:
19568
diff
changeset
|
291 {"getch", msvcrt_getch, METH_VARARGS}, |
|
8703d2052339
Use symbolic METH_VARARGS instead of 1 for ml_flags
Neal Norwitz <nnorwitz@gmail.com>
parents:
19568
diff
changeset
|
292 {"getche", msvcrt_getche, METH_VARARGS}, |
|
8703d2052339
Use symbolic METH_VARARGS instead of 1 for ml_flags
Neal Norwitz <nnorwitz@gmail.com>
parents:
19568
diff
changeset
|
293 {"putch", msvcrt_putch, METH_VARARGS}, |
|
8703d2052339
Use symbolic METH_VARARGS instead of 1 for ml_flags
Neal Norwitz <nnorwitz@gmail.com>
parents:
19568
diff
changeset
|
294 {"ungetch", msvcrt_ungetch, METH_VARARGS}, |
|
47666
fcfe10f3dc14
Restore support for Microsoft VC6 compiler.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47527
diff
changeset
|
295 #ifdef _WCONIO_DEFINED |
|
44250
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
296 {"getwch", msvcrt_getwch, METH_VARARGS}, |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
297 {"getwche", msvcrt_getwche, METH_VARARGS}, |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
298 {"putwch", msvcrt_putwch, METH_VARARGS}, |
|
59e64fa3ad1d
Added wide char api variants of getch and putch to msvcrt module. The wide char methods are required to fix #1578 in py3k. I figured out that they might be useful in 2.6, too.
Christian Heimes <christian@cheimes.de>
parents:
36326
diff
changeset
|
299 {"ungetwch", msvcrt_ungetwch, METH_VARARGS}, |
|
47666
fcfe10f3dc14
Restore support for Microsoft VC6 compiler.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47527
diff
changeset
|
300 #endif |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
301 {NULL, NULL} |
|
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
302 }; |
|
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
303 |
| 32845 | 304 PyMODINIT_FUNC |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
305 initmsvcrt(void) |
|
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
306 { |
|
49913
ab12d716a7a8
Merged revisions 67455 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47666
diff
changeset
|
307 int st; |
|
36326
2e151bc820f7
initmsvcrt(): This no longer compiled on Windows, because
Tim Peters <tim.peters@gmail.com>
parents:
36324
diff
changeset
|
308 PyObject *d; |
|
15513
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
309 PyObject *m = Py_InitModule("msvcrt", msvcrt_functions); |
|
36324
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
32845
diff
changeset
|
310 if (m == NULL) |
|
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
32845
diff
changeset
|
311 return; |
|
36326
2e151bc820f7
initmsvcrt(): This no longer compiled on Windows, because
Tim Peters <tim.peters@gmail.com>
parents:
36324
diff
changeset
|
312 d = PyModule_GetDict(m); |
|
15513
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
313 |
|
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
314 /* constants for the locking() function's mode argument */ |
|
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
315 insertint(d, "LK_LOCK", _LK_LOCK); |
|
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
316 insertint(d, "LK_NBLCK", _LK_NBLCK); |
|
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
317 insertint(d, "LK_NBRLCK", _LK_NBRLCK); |
|
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
318 insertint(d, "LK_RLCK", _LK_RLCK); |
|
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
319 insertint(d, "LK_UNLCK", _LK_UNLCK); |
|
49913
ab12d716a7a8
Merged revisions 67455 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47666
diff
changeset
|
320 |
|
ab12d716a7a8
Merged revisions 67455 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47666
diff
changeset
|
321 /* constants for the crt versions */ |
|
ab12d716a7a8
Merged revisions 67455 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47666
diff
changeset
|
322 #ifdef _VC_ASSEMBLY_PUBLICKEYTOKEN |
|
ab12d716a7a8
Merged revisions 67455 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47666
diff
changeset
|
323 st = PyModule_AddStringConstant(m, "VC_ASSEMBLY_PUBLICKEYTOKEN", |
|
ab12d716a7a8
Merged revisions 67455 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47666
diff
changeset
|
324 _VC_ASSEMBLY_PUBLICKEYTOKEN); |
|
ab12d716a7a8
Merged revisions 67455 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47666
diff
changeset
|
325 if (st < 0)return; |
|
ab12d716a7a8
Merged revisions 67455 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47666
diff
changeset
|
326 #endif |
|
ab12d716a7a8
Merged revisions 67455 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47666
diff
changeset
|
327 #ifdef _CRT_ASSEMBLY_VERSION |
|
ab12d716a7a8
Merged revisions 67455 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47666
diff
changeset
|
328 st = PyModule_AddStringConstant(m, "CRT_ASSEMBLY_VERSION", |
|
ab12d716a7a8
Merged revisions 67455 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47666
diff
changeset
|
329 _CRT_ASSEMBLY_VERSION); |
|
ab12d716a7a8
Merged revisions 67455 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47666
diff
changeset
|
330 if (st < 0)return; |
|
ab12d716a7a8
Merged revisions 67455 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47666
diff
changeset
|
331 #endif |
|
ab12d716a7a8
Merged revisions 67455 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47666
diff
changeset
|
332 #ifdef __LIBRARIES_ASSEMBLY_NAME_PREFIX |
|
ab12d716a7a8
Merged revisions 67455 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47666
diff
changeset
|
333 st = PyModule_AddStringConstant(m, "LIBRARIES_ASSEMBLY_NAME_PREFIX", |
|
ab12d716a7a8
Merged revisions 67455 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47666
diff
changeset
|
334 __LIBRARIES_ASSEMBLY_NAME_PREFIX); |
|
ab12d716a7a8
Merged revisions 67455 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47666
diff
changeset
|
335 if (st < 0)return; |
|
ab12d716a7a8
Merged revisions 67455 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47666
diff
changeset
|
336 #endif |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
337 } |
