Mercurial > cpython-lru_cache-weakref
annotate PC/msvcrtmodule.c @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | b36cb4602e21 |
| children |
| 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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
3 msvcrtmodule.c |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
5 A Python interface to the Microsoft Visual C Runtime |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
6 Library, providing access to those non-portable, but |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
7 still useful routines. |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
9 Only ever compiled with an MS compiler, so no attempt |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
10 has been made to avoid MS language extensions, etc... |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
12 This may only work on NT or 95... |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
13 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
14 Author: Mark Hammond and Guido van Rossum. |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
15 Maintenance: Guido van Rossum. |
|
6000
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 |
|
58941
992fd0547ff8
Merged revisions 78213,78215 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
49913
diff
changeset
|
26 #if _MSC_VER >= 1500 && _MSC_VER < 1600 |
|
49913
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 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
36 if (!PyArg_ParseTuple(args, ":heapmin")) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
39 if (_heapmin() != 0) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
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 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
42 Py_INCREF(Py_None); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
43 return Py_None; |
|
5953
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 |
|
57990
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
46 PyDoc_STRVAR(heapmin_doc, |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
47 "heapmin() -> None\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
48 \n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
49 Force the malloc() heap to clean itself up and return unused blocks\n\ |
|
58013
db62977c5713
We only support Windows NT derivatives now.
Georg Brandl <georg@python.org>
parents:
57990
diff
changeset
|
50 to the operating system. On failure, this raises IOError."); |
|
57990
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
51 |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
52 // 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
|
53 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
|
54 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
|
55 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
56 int fd; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
57 int mode; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
58 long nbytes; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
59 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
|
60 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
61 if (!PyArg_ParseTuple(args, "iil:locking", &fd, &mode, &nbytes)) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
62 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
|
63 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
64 Py_BEGIN_ALLOW_THREADS |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
65 err = _locking(fd, mode, nbytes); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
66 Py_END_ALLOW_THREADS |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
67 if (err != 0) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
68 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
|
69 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
70 Py_INCREF(Py_None); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
71 return Py_None; |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
72 } |
|
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
73 |
|
57990
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
74 PyDoc_STRVAR(locking_doc, |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
75 "locking(fd, mode, nbytes) -> None\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
76 \n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
77 Lock part of a file based on file descriptor fd from the C runtime.\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
78 Raises IOError on failure. The locked region of the file extends from\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
79 the current file position for nbytes bytes, and may continue beyond\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
80 the end of the file. mode must be one of the LK_* constants listed\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
81 below. Multiple regions in a file may be locked at the same time, but\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
82 may not overlap. Adjacent regions are not merged; they must be unlocked\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
83 individually."); |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
84 |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
85 // 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
|
86 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
|
87 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
|
88 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
89 int fd; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
90 int flags; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
91 if (!PyArg_ParseTuple(args,"ii:setmode", &fd, &flags)) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
92 return NULL; |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
93 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
94 flags = _setmode(fd, flags); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
95 if (flags == -1) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
96 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
|
97 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
98 return PyInt_FromLong(flags); |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
99 } |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
100 |
|
57990
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
101 PyDoc_STRVAR(setmode_doc, |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
102 "setmode(fd, mode) -> Previous mode\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
103 \n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
104 Set the line-end translation mode for the file descriptor fd. To set\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
105 it to text mode, flags should be os.O_TEXT; for binary, it should be\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
106 os.O_BINARY."); |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
107 |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
108 // 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
|
109 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
|
110 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
|
111 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
112 long handle; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
113 int flags; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
114 int fd; |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
115 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
116 if (!PyArg_ParseTuple(args, "li:open_osfhandle", &handle, &flags)) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
117 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
|
118 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
119 fd = _open_osfhandle(handle, flags); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
120 if (fd == -1) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
121 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
|
122 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
123 return PyInt_FromLong(fd); |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
124 } |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
125 |
|
57990
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
126 PyDoc_STRVAR(open_osfhandle_doc, |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
127 "open_osfhandle(handle, flags) -> file descriptor\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
128 \n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
129 Create a C runtime file descriptor from the file handle handle. The\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
130 flags parameter should be a bitwise OR of os.O_APPEND, os.O_RDONLY,\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
131 and os.O_TEXT. The returned file descriptor may be used as a parameter\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
132 to os.fdopen() to create a file object."); |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
133 |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
134 // 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
|
135 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
|
136 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
|
137 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
138 int fd; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
139 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
|
140 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
141 if (!PyArg_ParseTuple(args,"i:get_osfhandle", &fd)) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
142 return NULL; |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
143 |
|
64446
98083f876455
Merged revisions 84506 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
144 if (!_PyVerify_fd(fd)) |
|
98083f876455
Merged revisions 84506 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
145 return PyErr_SetFromErrno(PyExc_IOError); |
|
98083f876455
Merged revisions 84506 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
61463
diff
changeset
|
146 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
147 handle = _get_osfhandle(fd); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
148 if (handle == -1) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
149 return PyErr_SetFromErrno(PyExc_IOError); |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
150 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
151 /* technically 'handle' is not a pointer, but a integer as |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
152 large as a pointer, Python's *VoidPtr interface is the |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
153 most appropriate here */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
154 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
|
155 } |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
156 |
|
57990
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
157 PyDoc_STRVAR(get_osfhandle_doc, |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
158 "get_osfhandle(fd) -> file handle\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
159 \n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
160 Return the file handle for the file descriptor fd. Raises IOError\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
161 if fd is not recognized."); |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
162 |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
163 /* 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
|
164 |
|
15513
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
165 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
|
166 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
|
167 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
168 int ok; |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
169 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
170 if (!PyArg_ParseTuple(args, ":kbhit")) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
171 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
|
172 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
173 ok = _kbhit(); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
174 return PyInt_FromLong(ok); |
|
6000
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 |
|
57990
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
177 PyDoc_STRVAR(kbhit_doc, |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
178 "kbhit() -> bool\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
179 \n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
180 Return true if a keypress is waiting to be read."); |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
181 |
|
15513
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
182 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
|
183 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
|
184 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
185 int ch; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
186 char 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
|
187 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
188 if (!PyArg_ParseTuple(args, ":getch")) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
189 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
|
190 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
191 Py_BEGIN_ALLOW_THREADS |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
192 ch = _getch(); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
193 Py_END_ALLOW_THREADS |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
194 s[0] = ch; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
195 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
|
196 } |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
197 |
|
57990
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
198 PyDoc_STRVAR(getch_doc, |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
199 "getch() -> key character\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
200 \n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
201 Read a keypress and return the resulting character. Nothing is echoed to\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
202 the console. This call will block if a keypress is not already\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
203 available, but will not wait for Enter to be pressed. If the pressed key\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
204 was a special function key, this will return '\\000' or '\\xe0'; the next\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
205 call will return the keycode. The Control-C keypress cannot be read with\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
206 this function."); |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
207 |
|
47666
fcfe10f3dc14
Restore support for Microsoft VC6 compiler.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47527
diff
changeset
|
208 #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
|
209 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
|
210 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
|
211 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
212 Py_UNICODE ch; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
213 Py_UNICODE u[1]; |
|
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
|
214 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
215 if (!PyArg_ParseTuple(args, ":getwch")) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
216 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
|
217 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
218 Py_BEGIN_ALLOW_THREADS |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
219 ch = _getwch(); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
220 Py_END_ALLOW_THREADS |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
221 u[0] = ch; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
222 return PyUnicode_FromUnicode(u, 1); |
|
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
|
223 } |
|
57990
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
224 |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
225 PyDoc_STRVAR(getwch_doc, |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
226 "getwch() -> Unicode key character\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
227 \n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
228 Wide char variant of getch(), returning a Unicode value."); |
|
47666
fcfe10f3dc14
Restore support for Microsoft VC6 compiler.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47527
diff
changeset
|
229 #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
|
230 |
|
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 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
|
232 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
|
233 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
234 int ch; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
235 char 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
|
236 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
237 if (!PyArg_ParseTuple(args, ":getche")) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
238 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
|
239 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
240 Py_BEGIN_ALLOW_THREADS |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
241 ch = _getche(); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
242 Py_END_ALLOW_THREADS |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
243 s[0] = ch; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
244 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
|
245 } |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
246 |
|
57990
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
247 PyDoc_STRVAR(getche_doc, |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
248 "getche() -> key character\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
249 \n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
250 Similar to getch(), but the keypress will be echoed if it represents\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
251 a printable character."); |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
252 |
|
47666
fcfe10f3dc14
Restore support for Microsoft VC6 compiler.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47527
diff
changeset
|
253 #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
|
254 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
|
255 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
|
256 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
257 Py_UNICODE ch; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
258 Py_UNICODE s[1]; |
|
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
|
259 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
260 if (!PyArg_ParseTuple(args, ":getwche")) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
261 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
|
262 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
263 Py_BEGIN_ALLOW_THREADS |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
264 ch = _getwche(); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
265 Py_END_ALLOW_THREADS |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
266 s[0] = ch; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
267 return PyUnicode_FromUnicode(s, 1); |
|
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
|
268 } |
|
57990
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
269 |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
270 PyDoc_STRVAR(getwche_doc, |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
271 "getwche() -> Unicode key character\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
272 \n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
273 Wide char variant of getche(), returning a Unicode value."); |
|
47666
fcfe10f3dc14
Restore support for Microsoft VC6 compiler.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47527
diff
changeset
|
274 #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
|
275 |
|
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
|
276 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
|
277 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
|
278 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
279 char ch; |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
280 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
281 if (!PyArg_ParseTuple(args, "c:putch", &ch)) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
282 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
|
283 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
284 _putch(ch); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
285 Py_INCREF(Py_None); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
286 return Py_None; |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
287 } |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
288 |
|
57990
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
289 PyDoc_STRVAR(putch_doc, |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
290 "putch(char) -> None\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
291 \n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
292 Print the character char to the console without buffering."); |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
293 |
|
47666
fcfe10f3dc14
Restore support for Microsoft VC6 compiler.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47527
diff
changeset
|
294 #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
|
295 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
|
296 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
|
297 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
298 Py_UNICODE *ch; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
299 int size; |
|
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
|
300 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
301 if (!PyArg_ParseTuple(args, "u#:putwch", &ch, &size)) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
302 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
|
303 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
304 if (size == 0) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
305 PyErr_SetString(PyExc_ValueError, |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
306 "Expected unicode string of length 1"); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
307 return NULL; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
308 } |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
309 _putwch(*ch); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
310 Py_RETURN_NONE; |
|
44251
2028feb94b57
Stupid save all didn't safe it all ...
Christian Heimes <christian@cheimes.de>
parents:
44250
diff
changeset
|
311 |
|
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
|
312 } |
|
57990
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
313 |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
314 PyDoc_STRVAR(putwch_doc, |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
315 "putwch(unicode_char) -> None\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
316 \n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
317 Wide char variant of putch(), accepting a Unicode value."); |
|
47666
fcfe10f3dc14
Restore support for Microsoft VC6 compiler.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47527
diff
changeset
|
318 #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
|
319 |
|
15513
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
320 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
|
321 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
|
322 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
323 char ch; |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
324 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
325 if (!PyArg_ParseTuple(args, "c:ungetch", &ch)) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
326 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
|
327 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
328 if (_ungetch(ch) == EOF) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
329 return PyErr_SetFromErrno(PyExc_IOError); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
330 Py_INCREF(Py_None); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
331 return Py_None; |
|
6000
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
332 } |
|
d520d5d01115
Made it real. Changed locking() to work with file descriptors instead
Guido van Rossum <guido@python.org>
parents:
5953
diff
changeset
|
333 |
|
57990
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
334 PyDoc_STRVAR(ungetch_doc, |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
335 "ungetch(char) -> None\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
336 \n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
337 Cause the character char to be \"pushed back\" into the console buffer;\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
338 it will be the next character read by getch() or getche()."); |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
339 |
|
47666
fcfe10f3dc14
Restore support for Microsoft VC6 compiler.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47527
diff
changeset
|
340 #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
|
341 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
|
342 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
|
343 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
344 Py_UNICODE ch; |
|
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
|
345 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
346 if (!PyArg_ParseTuple(args, "u:ungetwch", &ch)) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
347 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
|
348 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
349 if (_ungetch(ch) == EOF) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
350 return PyErr_SetFromErrno(PyExc_IOError); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
351 Py_INCREF(Py_None); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
352 return Py_None; |
|
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
|
353 } |
|
57990
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
354 |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
355 PyDoc_STRVAR(ungetwch_doc, |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
356 "ungetwch(unicode_char) -> None\n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
357 \n\ |
|
c502ec243458
#7579: Add docstrings to the msvcrt module
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49913
diff
changeset
|
358 Wide char variant of ungetch(), accepting a Unicode value."); |
|
47666
fcfe10f3dc14
Restore support for Microsoft VC6 compiler.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47527
diff
changeset
|
359 #endif |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
360 |
|
15513
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
361 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
|
362 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
|
363 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
364 PyObject *v = PyInt_FromLong((long) value); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
365 if (v == NULL) { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
366 /* Don't bother reporting this error */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
367 PyErr_Clear(); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
368 } |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
369 else { |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
370 PyDict_SetItemString(d, name, v); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
371 Py_DECREF(v); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
372 } |
|
15513
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
373 } |
|
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
374 |
|
efc96aab71c2
Partial fix for SF bug 122780 (msvcrt.locking constants aren't defined).
Tim Peters <tim.peters@gmail.com>
parents:
13233
diff
changeset
|
375 |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
376 /* 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
|
377 static struct PyMethodDef msvcrt_functions[] = { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
58930
diff
changeset
|
378 {"heapmin", msvcrt_heapmin, METH_VARARGS, heapmin_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
58930
diff
changeset
|
379 {"locking", msvcrt_locking, METH_VARARGS, locking_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
58930
diff
changeset
|
380 {"setmode", msvcrt_setmode, METH_VARARGS, setmode_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
58930
diff
changeset
|
381 {"open_osfhandle", msvcrt_open_osfhandle, METH_VARARGS, open_osfhandle_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
58930
diff
changeset
|
382 {"get_osfhandle", msvcrt_get_osfhandle, METH_VARARGS, get_osfhandle_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
58930
diff
changeset
|
383 {"kbhit", msvcrt_kbhit, METH_VARARGS, kbhit_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
58930
diff
changeset
|
384 {"getch", msvcrt_getch, METH_VARARGS, getch_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
58930
diff
changeset
|
385 {"getche", msvcrt_getche, METH_VARARGS, getche_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
58930
diff
changeset
|
386 {"putch", msvcrt_putch, METH_VARARGS, putch_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
58930
diff
changeset
|
387 {"ungetch", msvcrt_ungetch, METH_VARARGS, ungetch_doc}, |
|
47666
fcfe10f3dc14
Restore support for Microsoft VC6 compiler.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47527
diff
changeset
|
388 #ifdef _WCONIO_DEFINED |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
58930
diff
changeset
|
389 {"getwch", msvcrt_getwch, METH_VARARGS, getwch_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
58930
diff
changeset
|
390 {"getwche", msvcrt_getwche, METH_VARARGS, getwche_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
58930
diff
changeset
|
391 {"putwch", msvcrt_putwch, METH_VARARGS, putwch_doc}, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
58930
diff
changeset
|
392 {"ungetwch", msvcrt_ungetwch, METH_VARARGS, ungetwch_doc}, |
|
47666
fcfe10f3dc14
Restore support for Microsoft VC6 compiler.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47527
diff
changeset
|
393 #endif |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
394 {NULL, NULL} |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
395 }; |
|
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
396 |
| 32845 | 397 PyMODINIT_FUNC |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
398 initmsvcrt(void) |
|
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
399 { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
400 int st; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
401 PyObject *d; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
402 PyObject *m = Py_InitModule("msvcrt", msvcrt_functions); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
403 if (m == NULL) |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
404 return; |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
405 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
|
406 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
407 /* constants for the locking() function's mode argument */ |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
408 insertint(d, "LK_LOCK", _LK_LOCK); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
409 insertint(d, "LK_NBLCK", _LK_NBLCK); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
410 insertint(d, "LK_NBRLCK", _LK_NBRLCK); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
411 insertint(d, "LK_RLCK", _LK_RLCK); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
412 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
|
413 |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
414 /* constants for the crt versions */ |
|
49913
ab12d716a7a8
Merged revisions 67455 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47666
diff
changeset
|
415 #ifdef _VC_ASSEMBLY_PUBLICKEYTOKEN |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
416 st = PyModule_AddStringConstant(m, "VC_ASSEMBLY_PUBLICKEYTOKEN", |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
417 _VC_ASSEMBLY_PUBLICKEYTOKEN); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
418 if (st < 0)return; |
|
49913
ab12d716a7a8
Merged revisions 67455 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47666
diff
changeset
|
419 #endif |
|
ab12d716a7a8
Merged revisions 67455 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47666
diff
changeset
|
420 #ifdef _CRT_ASSEMBLY_VERSION |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
421 st = PyModule_AddStringConstant(m, "CRT_ASSEMBLY_VERSION", |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
422 _CRT_ASSEMBLY_VERSION); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
423 if (st < 0)return; |
|
49913
ab12d716a7a8
Merged revisions 67455 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47666
diff
changeset
|
424 #endif |
|
ab12d716a7a8
Merged revisions 67455 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47666
diff
changeset
|
425 #ifdef __LIBRARIES_ASSEMBLY_NAME_PREFIX |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
426 st = PyModule_AddStringConstant(m, "LIBRARIES_ASSEMBLY_NAME_PREFIX", |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
427 __LIBRARIES_ASSEMBLY_NAME_PREFIX); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58941
diff
changeset
|
428 if (st < 0)return; |
|
49913
ab12d716a7a8
Merged revisions 67455 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
47666
diff
changeset
|
429 #endif |
|
5953
1a99695a41cc
Got the new structure working with MSVC 4.2.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
430 } |
