1 | n/a | /********************************************************* |
---|
2 | n/a | |
---|
3 | n/a | msvcrtmodule.c |
---|
4 | n/a | |
---|
5 | n/a | A Python interface to the Microsoft Visual C Runtime |
---|
6 | n/a | Library, providing access to those non-portable, but |
---|
7 | n/a | still useful routines. |
---|
8 | n/a | |
---|
9 | n/a | Only ever compiled with an MS compiler, so no attempt |
---|
10 | n/a | has been made to avoid MS language extensions, etc... |
---|
11 | n/a | |
---|
12 | n/a | This may only work on NT or 95... |
---|
13 | n/a | |
---|
14 | n/a | Author: Mark Hammond and Guido van Rossum. |
---|
15 | n/a | Maintenance: Guido van Rossum. |
---|
16 | n/a | |
---|
17 | n/a | ***********************************************************/ |
---|
18 | n/a | |
---|
19 | n/a | #include "Python.h" |
---|
20 | n/a | #include "malloc.h" |
---|
21 | n/a | #include <io.h> |
---|
22 | n/a | #include <conio.h> |
---|
23 | n/a | #include <sys/locking.h> |
---|
24 | n/a | #include <crtdbg.h> |
---|
25 | n/a | #include <windows.h> |
---|
26 | n/a | |
---|
27 | n/a | #ifdef _MSC_VER |
---|
28 | n/a | #if _MSC_VER >= 1500 && _MSC_VER < 1600 |
---|
29 | n/a | #include <crtassem.h> |
---|
30 | n/a | #elif _MSC_VER >= 1600 |
---|
31 | n/a | #include <crtversion.h> |
---|
32 | n/a | #endif |
---|
33 | n/a | #endif |
---|
34 | n/a | |
---|
35 | n/a | /*[python input] |
---|
36 | n/a | class intptr_t_converter(CConverter): |
---|
37 | n/a | type = 'intptr_t' |
---|
38 | n/a | format_unit = '"_Py_PARSE_INTPTR"' |
---|
39 | n/a | |
---|
40 | n/a | class handle_return_converter(long_return_converter): |
---|
41 | n/a | type = 'intptr_t' |
---|
42 | n/a | cast = '(void *)' |
---|
43 | n/a | conversion_fn = 'PyLong_FromVoidPtr' |
---|
44 | n/a | |
---|
45 | n/a | class byte_char_return_converter(CReturnConverter): |
---|
46 | n/a | type = 'int' |
---|
47 | n/a | |
---|
48 | n/a | def render(self, function, data): |
---|
49 | n/a | data.declarations.append('char s[1];') |
---|
50 | n/a | data.return_value = 's[0]' |
---|
51 | n/a | data.return_conversion.append( |
---|
52 | n/a | 'return_value = PyBytes_FromStringAndSize(s, 1);\n') |
---|
53 | n/a | |
---|
54 | n/a | class wchar_t_return_converter(CReturnConverter): |
---|
55 | n/a | type = 'wchar_t' |
---|
56 | n/a | |
---|
57 | n/a | def render(self, function, data): |
---|
58 | n/a | self.declare(data) |
---|
59 | n/a | data.return_conversion.append( |
---|
60 | n/a | 'return_value = PyUnicode_FromOrdinal(_return_value);\n') |
---|
61 | n/a | [python start generated code]*/ |
---|
62 | n/a | /*[python end generated code: output=da39a3ee5e6b4b0d input=b59f1663dba11997]*/ |
---|
63 | n/a | |
---|
64 | n/a | /*[clinic input] |
---|
65 | n/a | module msvcrt |
---|
66 | n/a | [clinic start generated code]*/ |
---|
67 | n/a | /*[clinic end generated code: output=da39a3ee5e6b4b0d input=f31a87a783d036cd]*/ |
---|
68 | n/a | |
---|
69 | n/a | #include "clinic/msvcrtmodule.c.h" |
---|
70 | n/a | |
---|
71 | n/a | /*[clinic input] |
---|
72 | n/a | msvcrt.heapmin |
---|
73 | n/a | |
---|
74 | n/a | Minimize the malloc() heap. |
---|
75 | n/a | |
---|
76 | n/a | Force the malloc() heap to clean itself up and return unused blocks |
---|
77 | n/a | to the operating system. On failure, this raises OSError. |
---|
78 | n/a | [clinic start generated code]*/ |
---|
79 | n/a | |
---|
80 | n/a | static PyObject * |
---|
81 | n/a | msvcrt_heapmin_impl(PyObject *module) |
---|
82 | n/a | /*[clinic end generated code: output=1ba00f344782dc19 input=82e1771d21bde2d8]*/ |
---|
83 | n/a | { |
---|
84 | n/a | if (_heapmin() != 0) |
---|
85 | n/a | return PyErr_SetFromErrno(PyExc_IOError); |
---|
86 | n/a | |
---|
87 | n/a | Py_RETURN_NONE; |
---|
88 | n/a | } |
---|
89 | n/a | /*[clinic input] |
---|
90 | n/a | msvcrt.locking |
---|
91 | n/a | |
---|
92 | n/a | fd: int |
---|
93 | n/a | mode: int |
---|
94 | n/a | nbytes: long |
---|
95 | n/a | / |
---|
96 | n/a | |
---|
97 | n/a | Lock part of a file based on file descriptor fd from the C runtime. |
---|
98 | n/a | |
---|
99 | n/a | Raises IOError on failure. The locked region of the file extends from |
---|
100 | n/a | the current file position for nbytes bytes, and may continue beyond |
---|
101 | n/a | the end of the file. mode must be one of the LK_* constants listed |
---|
102 | n/a | below. Multiple regions in a file may be locked at the same time, but |
---|
103 | n/a | may not overlap. Adjacent regions are not merged; they must be unlocked |
---|
104 | n/a | individually. |
---|
105 | n/a | [clinic start generated code]*/ |
---|
106 | n/a | |
---|
107 | n/a | static PyObject * |
---|
108 | n/a | msvcrt_locking_impl(PyObject *module, int fd, int mode, long nbytes) |
---|
109 | n/a | /*[clinic end generated code: output=a4a90deca9785a03 input=d9f13f0f6a713ba7]*/ |
---|
110 | n/a | { |
---|
111 | n/a | int err; |
---|
112 | n/a | |
---|
113 | n/a | Py_BEGIN_ALLOW_THREADS |
---|
114 | n/a | _Py_BEGIN_SUPPRESS_IPH |
---|
115 | n/a | err = _locking(fd, mode, nbytes); |
---|
116 | n/a | _Py_END_SUPPRESS_IPH |
---|
117 | n/a | Py_END_ALLOW_THREADS |
---|
118 | n/a | if (err != 0) |
---|
119 | n/a | return PyErr_SetFromErrno(PyExc_IOError); |
---|
120 | n/a | |
---|
121 | n/a | Py_RETURN_NONE; |
---|
122 | n/a | } |
---|
123 | n/a | |
---|
124 | n/a | /*[clinic input] |
---|
125 | n/a | msvcrt.setmode -> long |
---|
126 | n/a | |
---|
127 | n/a | fd: int |
---|
128 | n/a | mode as flags: int |
---|
129 | n/a | / |
---|
130 | n/a | |
---|
131 | n/a | Set the line-end translation mode for the file descriptor fd. |
---|
132 | n/a | |
---|
133 | n/a | To set it to text mode, flags should be os.O_TEXT; for binary, it |
---|
134 | n/a | should be os.O_BINARY. |
---|
135 | n/a | |
---|
136 | n/a | Return value is the previous mode. |
---|
137 | n/a | [clinic start generated code]*/ |
---|
138 | n/a | |
---|
139 | n/a | static long |
---|
140 | n/a | msvcrt_setmode_impl(PyObject *module, int fd, int flags) |
---|
141 | n/a | /*[clinic end generated code: output=24a9be5ea07ccb9b input=76e7c01f6b137f75]*/ |
---|
142 | n/a | { |
---|
143 | n/a | _Py_BEGIN_SUPPRESS_IPH |
---|
144 | n/a | flags = _setmode(fd, flags); |
---|
145 | n/a | _Py_END_SUPPRESS_IPH |
---|
146 | n/a | if (flags == -1) |
---|
147 | n/a | PyErr_SetFromErrno(PyExc_IOError); |
---|
148 | n/a | |
---|
149 | n/a | return flags; |
---|
150 | n/a | } |
---|
151 | n/a | |
---|
152 | n/a | /*[clinic input] |
---|
153 | n/a | msvcrt.open_osfhandle -> long |
---|
154 | n/a | |
---|
155 | n/a | handle: intptr_t |
---|
156 | n/a | flags: int |
---|
157 | n/a | / |
---|
158 | n/a | |
---|
159 | n/a | Create a C runtime file descriptor from the file handle handle. |
---|
160 | n/a | |
---|
161 | n/a | The flags parameter should be a bitwise OR of os.O_APPEND, os.O_RDONLY, |
---|
162 | n/a | and os.O_TEXT. The returned file descriptor may be used as a parameter |
---|
163 | n/a | to os.fdopen() to create a file object. |
---|
164 | n/a | [clinic start generated code]*/ |
---|
165 | n/a | |
---|
166 | n/a | static long |
---|
167 | n/a | msvcrt_open_osfhandle_impl(PyObject *module, intptr_t handle, int flags) |
---|
168 | n/a | /*[clinic end generated code: output=cede871bf939d6e3 input=cb2108bbea84514e]*/ |
---|
169 | n/a | { |
---|
170 | n/a | int fd; |
---|
171 | n/a | |
---|
172 | n/a | _Py_BEGIN_SUPPRESS_IPH |
---|
173 | n/a | fd = _open_osfhandle(handle, flags); |
---|
174 | n/a | _Py_END_SUPPRESS_IPH |
---|
175 | n/a | if (fd == -1) |
---|
176 | n/a | PyErr_SetFromErrno(PyExc_IOError); |
---|
177 | n/a | |
---|
178 | n/a | return fd; |
---|
179 | n/a | } |
---|
180 | n/a | |
---|
181 | n/a | /*[clinic input] |
---|
182 | n/a | msvcrt.get_osfhandle -> handle |
---|
183 | n/a | |
---|
184 | n/a | fd: int |
---|
185 | n/a | / |
---|
186 | n/a | |
---|
187 | n/a | Return the file handle for the file descriptor fd. |
---|
188 | n/a | |
---|
189 | n/a | Raises IOError if fd is not recognized. |
---|
190 | n/a | [clinic start generated code]*/ |
---|
191 | n/a | |
---|
192 | n/a | static intptr_t |
---|
193 | n/a | msvcrt_get_osfhandle_impl(PyObject *module, int fd) |
---|
194 | n/a | /*[clinic end generated code: output=7ce761dd0de2b503 input=c7d18d02c8017ec1]*/ |
---|
195 | n/a | { |
---|
196 | n/a | intptr_t handle = -1; |
---|
197 | n/a | |
---|
198 | n/a | _Py_BEGIN_SUPPRESS_IPH |
---|
199 | n/a | handle = _get_osfhandle(fd); |
---|
200 | n/a | _Py_END_SUPPRESS_IPH |
---|
201 | n/a | if (handle == -1) |
---|
202 | n/a | PyErr_SetFromErrno(PyExc_IOError); |
---|
203 | n/a | |
---|
204 | n/a | return handle; |
---|
205 | n/a | } |
---|
206 | n/a | |
---|
207 | n/a | /* Console I/O */ |
---|
208 | n/a | /*[clinic input] |
---|
209 | n/a | msvcrt.kbhit -> long |
---|
210 | n/a | |
---|
211 | n/a | Return true if a keypress is waiting to be read. |
---|
212 | n/a | [clinic start generated code]*/ |
---|
213 | n/a | |
---|
214 | n/a | static long |
---|
215 | n/a | msvcrt_kbhit_impl(PyObject *module) |
---|
216 | n/a | /*[clinic end generated code: output=940dfce6587c1890 input=e70d678a5c2f6acc]*/ |
---|
217 | n/a | { |
---|
218 | n/a | return _kbhit(); |
---|
219 | n/a | } |
---|
220 | n/a | |
---|
221 | n/a | /*[clinic input] |
---|
222 | n/a | msvcrt.getch -> byte_char |
---|
223 | n/a | |
---|
224 | n/a | Read a keypress and return the resulting character as a byte string. |
---|
225 | n/a | |
---|
226 | n/a | Nothing is echoed to the console. This call will block if a keypress is |
---|
227 | n/a | not already available, but will not wait for Enter to be pressed. If the |
---|
228 | n/a | pressed key was a special function key, this will return '\000' or |
---|
229 | n/a | '\xe0'; the next call will return the keycode. The Control-C keypress |
---|
230 | n/a | cannot be read with this function. |
---|
231 | n/a | [clinic start generated code]*/ |
---|
232 | n/a | |
---|
233 | n/a | static int |
---|
234 | n/a | msvcrt_getch_impl(PyObject *module) |
---|
235 | n/a | /*[clinic end generated code: output=a4e51f0565064a7d input=37a40cf0ed0d1153]*/ |
---|
236 | n/a | { |
---|
237 | n/a | int ch; |
---|
238 | n/a | |
---|
239 | n/a | Py_BEGIN_ALLOW_THREADS |
---|
240 | n/a | ch = _getch(); |
---|
241 | n/a | Py_END_ALLOW_THREADS |
---|
242 | n/a | return ch; |
---|
243 | n/a | } |
---|
244 | n/a | |
---|
245 | n/a | /*[clinic input] |
---|
246 | n/a | msvcrt.getwch -> wchar_t |
---|
247 | n/a | |
---|
248 | n/a | Wide char variant of getch(), returning a Unicode value. |
---|
249 | n/a | [clinic start generated code]*/ |
---|
250 | n/a | |
---|
251 | n/a | static wchar_t |
---|
252 | n/a | msvcrt_getwch_impl(PyObject *module) |
---|
253 | n/a | /*[clinic end generated code: output=be9937494e22f007 input=27b3dec8ad823d7c]*/ |
---|
254 | n/a | { |
---|
255 | n/a | wchar_t ch; |
---|
256 | n/a | |
---|
257 | n/a | Py_BEGIN_ALLOW_THREADS |
---|
258 | n/a | ch = _getwch(); |
---|
259 | n/a | Py_END_ALLOW_THREADS |
---|
260 | n/a | return ch; |
---|
261 | n/a | } |
---|
262 | n/a | |
---|
263 | n/a | /*[clinic input] |
---|
264 | n/a | msvcrt.getche -> byte_char |
---|
265 | n/a | |
---|
266 | n/a | Similar to getch(), but the keypress will be echoed if possible. |
---|
267 | n/a | [clinic start generated code]*/ |
---|
268 | n/a | |
---|
269 | n/a | static int |
---|
270 | n/a | msvcrt_getche_impl(PyObject *module) |
---|
271 | n/a | /*[clinic end generated code: output=d8f7db4fd2990401 input=43311ade9ed4a9c0]*/ |
---|
272 | n/a | { |
---|
273 | n/a | int ch; |
---|
274 | n/a | |
---|
275 | n/a | Py_BEGIN_ALLOW_THREADS |
---|
276 | n/a | ch = _getche(); |
---|
277 | n/a | Py_END_ALLOW_THREADS |
---|
278 | n/a | return ch; |
---|
279 | n/a | } |
---|
280 | n/a | |
---|
281 | n/a | /*[clinic input] |
---|
282 | n/a | msvcrt.getwche -> wchar_t |
---|
283 | n/a | |
---|
284 | n/a | Wide char variant of getche(), returning a Unicode value. |
---|
285 | n/a | [clinic start generated code]*/ |
---|
286 | n/a | |
---|
287 | n/a | static wchar_t |
---|
288 | n/a | msvcrt_getwche_impl(PyObject *module) |
---|
289 | n/a | /*[clinic end generated code: output=d0dae5ba3829d596 input=49337d59d1a591f8]*/ |
---|
290 | n/a | { |
---|
291 | n/a | wchar_t ch; |
---|
292 | n/a | |
---|
293 | n/a | Py_BEGIN_ALLOW_THREADS |
---|
294 | n/a | ch = _getwche(); |
---|
295 | n/a | Py_END_ALLOW_THREADS |
---|
296 | n/a | return ch; |
---|
297 | n/a | } |
---|
298 | n/a | |
---|
299 | n/a | /*[clinic input] |
---|
300 | n/a | msvcrt.putch |
---|
301 | n/a | |
---|
302 | n/a | char: char |
---|
303 | n/a | / |
---|
304 | n/a | |
---|
305 | n/a | Print the byte string char to the console without buffering. |
---|
306 | n/a | [clinic start generated code]*/ |
---|
307 | n/a | |
---|
308 | n/a | static PyObject * |
---|
309 | n/a | msvcrt_putch_impl(PyObject *module, char char_value) |
---|
310 | n/a | /*[clinic end generated code: output=92ec9b81012d8f60 input=ec078dd10cb054d6]*/ |
---|
311 | n/a | { |
---|
312 | n/a | _Py_BEGIN_SUPPRESS_IPH |
---|
313 | n/a | _putch(char_value); |
---|
314 | n/a | _Py_END_SUPPRESS_IPH |
---|
315 | n/a | Py_RETURN_NONE; |
---|
316 | n/a | } |
---|
317 | n/a | |
---|
318 | n/a | /*[clinic input] |
---|
319 | n/a | msvcrt.putwch |
---|
320 | n/a | |
---|
321 | n/a | unicode_char: int(accept={str}) |
---|
322 | n/a | / |
---|
323 | n/a | |
---|
324 | n/a | Wide char variant of putch(), accepting a Unicode value. |
---|
325 | n/a | [clinic start generated code]*/ |
---|
326 | n/a | |
---|
327 | n/a | static PyObject * |
---|
328 | n/a | msvcrt_putwch_impl(PyObject *module, int unicode_char) |
---|
329 | n/a | /*[clinic end generated code: output=a3bd1a8951d28eee input=996ccd0bbcbac4c3]*/ |
---|
330 | n/a | { |
---|
331 | n/a | _Py_BEGIN_SUPPRESS_IPH |
---|
332 | n/a | _putwch(unicode_char); |
---|
333 | n/a | _Py_END_SUPPRESS_IPH |
---|
334 | n/a | Py_RETURN_NONE; |
---|
335 | n/a | |
---|
336 | n/a | } |
---|
337 | n/a | |
---|
338 | n/a | /*[clinic input] |
---|
339 | n/a | msvcrt.ungetch |
---|
340 | n/a | |
---|
341 | n/a | char: char |
---|
342 | n/a | / |
---|
343 | n/a | |
---|
344 | n/a | Opposite of getch. |
---|
345 | n/a | |
---|
346 | n/a | Cause the byte string char to be "pushed back" into the |
---|
347 | n/a | console buffer; it will be the next character read by |
---|
348 | n/a | getch() or getche(). |
---|
349 | n/a | [clinic start generated code]*/ |
---|
350 | n/a | |
---|
351 | n/a | static PyObject * |
---|
352 | n/a | msvcrt_ungetch_impl(PyObject *module, char char_value) |
---|
353 | n/a | /*[clinic end generated code: output=c6942a0efa119000 input=22f07ee9001bbf0f]*/ |
---|
354 | n/a | { |
---|
355 | n/a | int res; |
---|
356 | n/a | |
---|
357 | n/a | _Py_BEGIN_SUPPRESS_IPH |
---|
358 | n/a | res = _ungetch(char_value); |
---|
359 | n/a | _Py_END_SUPPRESS_IPH |
---|
360 | n/a | |
---|
361 | n/a | if (res == EOF) |
---|
362 | n/a | return PyErr_SetFromErrno(PyExc_IOError); |
---|
363 | n/a | Py_RETURN_NONE; |
---|
364 | n/a | } |
---|
365 | n/a | |
---|
366 | n/a | /*[clinic input] |
---|
367 | n/a | msvcrt.ungetwch |
---|
368 | n/a | |
---|
369 | n/a | unicode_char: int(accept={str}) |
---|
370 | n/a | / |
---|
371 | n/a | |
---|
372 | n/a | Wide char variant of ungetch(), accepting a Unicode value. |
---|
373 | n/a | [clinic start generated code]*/ |
---|
374 | n/a | |
---|
375 | n/a | static PyObject * |
---|
376 | n/a | msvcrt_ungetwch_impl(PyObject *module, int unicode_char) |
---|
377 | n/a | /*[clinic end generated code: output=e63af05438b8ba3d input=83ec0492be04d564]*/ |
---|
378 | n/a | { |
---|
379 | n/a | int res; |
---|
380 | n/a | |
---|
381 | n/a | _Py_BEGIN_SUPPRESS_IPH |
---|
382 | n/a | res = _ungetwch(unicode_char); |
---|
383 | n/a | _Py_END_SUPPRESS_IPH |
---|
384 | n/a | |
---|
385 | n/a | if (res == WEOF) |
---|
386 | n/a | return PyErr_SetFromErrno(PyExc_IOError); |
---|
387 | n/a | Py_RETURN_NONE; |
---|
388 | n/a | } |
---|
389 | n/a | |
---|
390 | n/a | #ifdef _DEBUG |
---|
391 | n/a | /*[clinic input] |
---|
392 | n/a | msvcrt.CrtSetReportFile -> long |
---|
393 | n/a | |
---|
394 | n/a | type: int |
---|
395 | n/a | file: int |
---|
396 | n/a | / |
---|
397 | n/a | |
---|
398 | n/a | Wrapper around _CrtSetReportFile. |
---|
399 | n/a | |
---|
400 | n/a | Only available on Debug builds. |
---|
401 | n/a | [clinic start generated code]*/ |
---|
402 | n/a | |
---|
403 | n/a | static long |
---|
404 | n/a | msvcrt_CrtSetReportFile_impl(PyObject *module, int type, int file) |
---|
405 | n/a | /*[clinic end generated code: output=df291c7fe032eb68 input=bb8f721a604fcc45]*/ |
---|
406 | n/a | { |
---|
407 | n/a | long res; |
---|
408 | n/a | |
---|
409 | n/a | _Py_BEGIN_SUPPRESS_IPH |
---|
410 | n/a | res = (long)_CrtSetReportFile(type, (_HFILE)file); |
---|
411 | n/a | _Py_END_SUPPRESS_IPH |
---|
412 | n/a | |
---|
413 | n/a | return res; |
---|
414 | n/a | } |
---|
415 | n/a | |
---|
416 | n/a | /*[clinic input] |
---|
417 | n/a | msvcrt.CrtSetReportMode -> long |
---|
418 | n/a | |
---|
419 | n/a | type: int |
---|
420 | n/a | mode: int |
---|
421 | n/a | / |
---|
422 | n/a | |
---|
423 | n/a | Wrapper around _CrtSetReportMode. |
---|
424 | n/a | |
---|
425 | n/a | Only available on Debug builds. |
---|
426 | n/a | [clinic start generated code]*/ |
---|
427 | n/a | |
---|
428 | n/a | static long |
---|
429 | n/a | msvcrt_CrtSetReportMode_impl(PyObject *module, int type, int mode) |
---|
430 | n/a | /*[clinic end generated code: output=b2863761523de317 input=9319d29b4319426b]*/ |
---|
431 | n/a | { |
---|
432 | n/a | int res; |
---|
433 | n/a | |
---|
434 | n/a | _Py_BEGIN_SUPPRESS_IPH |
---|
435 | n/a | res = _CrtSetReportMode(type, mode); |
---|
436 | n/a | _Py_END_SUPPRESS_IPH |
---|
437 | n/a | if (res == -1) |
---|
438 | n/a | PyErr_SetFromErrno(PyExc_IOError); |
---|
439 | n/a | return res; |
---|
440 | n/a | } |
---|
441 | n/a | |
---|
442 | n/a | /*[clinic input] |
---|
443 | n/a | msvcrt.set_error_mode -> long |
---|
444 | n/a | |
---|
445 | n/a | mode: int |
---|
446 | n/a | / |
---|
447 | n/a | |
---|
448 | n/a | Wrapper around _set_error_mode. |
---|
449 | n/a | |
---|
450 | n/a | Only available on Debug builds. |
---|
451 | n/a | [clinic start generated code]*/ |
---|
452 | n/a | |
---|
453 | n/a | static long |
---|
454 | n/a | msvcrt_set_error_mode_impl(PyObject *module, int mode) |
---|
455 | n/a | /*[clinic end generated code: output=ac4a09040d8ac4e3 input=046fca59c0f20872]*/ |
---|
456 | n/a | { |
---|
457 | n/a | long res; |
---|
458 | n/a | |
---|
459 | n/a | _Py_BEGIN_SUPPRESS_IPH |
---|
460 | n/a | res = _set_error_mode(mode); |
---|
461 | n/a | _Py_END_SUPPRESS_IPH |
---|
462 | n/a | |
---|
463 | n/a | return res; |
---|
464 | n/a | } |
---|
465 | n/a | #endif /* _DEBUG */ |
---|
466 | n/a | |
---|
467 | n/a | /*[clinic input] |
---|
468 | n/a | msvcrt.SetErrorMode |
---|
469 | n/a | |
---|
470 | n/a | mode: unsigned_int(bitwise=True) |
---|
471 | n/a | / |
---|
472 | n/a | |
---|
473 | n/a | Wrapper around SetErrorMode. |
---|
474 | n/a | [clinic start generated code]*/ |
---|
475 | n/a | |
---|
476 | n/a | static PyObject * |
---|
477 | n/a | msvcrt_SetErrorMode_impl(PyObject *module, unsigned int mode) |
---|
478 | n/a | /*[clinic end generated code: output=01d529293f00da8f input=d8b167258d32d907]*/ |
---|
479 | n/a | { |
---|
480 | n/a | unsigned int res; |
---|
481 | n/a | |
---|
482 | n/a | _Py_BEGIN_SUPPRESS_IPH |
---|
483 | n/a | res = SetErrorMode(mode); |
---|
484 | n/a | _Py_END_SUPPRESS_IPH |
---|
485 | n/a | |
---|
486 | n/a | return PyLong_FromUnsignedLong(res); |
---|
487 | n/a | } |
---|
488 | n/a | |
---|
489 | n/a | /*[clinic input] |
---|
490 | n/a | [clinic start generated code]*/ |
---|
491 | n/a | /*[clinic end generated code: output=da39a3ee5e6b4b0d input=da39a3ee5e6b4b0d]*/ |
---|
492 | n/a | |
---|
493 | n/a | /* List of functions exported by this module */ |
---|
494 | n/a | static struct PyMethodDef msvcrt_functions[] = { |
---|
495 | n/a | MSVCRT_HEAPMIN_METHODDEF |
---|
496 | n/a | MSVCRT_LOCKING_METHODDEF |
---|
497 | n/a | MSVCRT_SETMODE_METHODDEF |
---|
498 | n/a | MSVCRT_OPEN_OSFHANDLE_METHODDEF |
---|
499 | n/a | MSVCRT_GET_OSFHANDLE_METHODDEF |
---|
500 | n/a | MSVCRT_KBHIT_METHODDEF |
---|
501 | n/a | MSVCRT_GETCH_METHODDEF |
---|
502 | n/a | MSVCRT_GETCHE_METHODDEF |
---|
503 | n/a | MSVCRT_PUTCH_METHODDEF |
---|
504 | n/a | MSVCRT_UNGETCH_METHODDEF |
---|
505 | n/a | MSVCRT_SETERRORMODE_METHODDEF |
---|
506 | n/a | MSVCRT_CRTSETREPORTFILE_METHODDEF |
---|
507 | n/a | MSVCRT_CRTSETREPORTMODE_METHODDEF |
---|
508 | n/a | MSVCRT_SET_ERROR_MODE_METHODDEF |
---|
509 | n/a | MSVCRT_GETWCH_METHODDEF |
---|
510 | n/a | MSVCRT_GETWCHE_METHODDEF |
---|
511 | n/a | MSVCRT_PUTWCH_METHODDEF |
---|
512 | n/a | MSVCRT_UNGETWCH_METHODDEF |
---|
513 | n/a | {NULL, NULL} |
---|
514 | n/a | }; |
---|
515 | n/a | |
---|
516 | n/a | |
---|
517 | n/a | static struct PyModuleDef msvcrtmodule = { |
---|
518 | n/a | PyModuleDef_HEAD_INIT, |
---|
519 | n/a | "msvcrt", |
---|
520 | n/a | NULL, |
---|
521 | n/a | -1, |
---|
522 | n/a | msvcrt_functions, |
---|
523 | n/a | NULL, |
---|
524 | n/a | NULL, |
---|
525 | n/a | NULL, |
---|
526 | n/a | NULL |
---|
527 | n/a | }; |
---|
528 | n/a | |
---|
529 | n/a | static void |
---|
530 | n/a | insertint(PyObject *d, char *name, int value) |
---|
531 | n/a | { |
---|
532 | n/a | PyObject *v = PyLong_FromLong((long) value); |
---|
533 | n/a | if (v == NULL) { |
---|
534 | n/a | /* Don't bother reporting this error */ |
---|
535 | n/a | PyErr_Clear(); |
---|
536 | n/a | } |
---|
537 | n/a | else { |
---|
538 | n/a | PyDict_SetItemString(d, name, v); |
---|
539 | n/a | Py_DECREF(v); |
---|
540 | n/a | } |
---|
541 | n/a | } |
---|
542 | n/a | |
---|
543 | n/a | PyMODINIT_FUNC |
---|
544 | n/a | PyInit_msvcrt(void) |
---|
545 | n/a | { |
---|
546 | n/a | int st; |
---|
547 | n/a | PyObject *d, *version; |
---|
548 | n/a | PyObject *m = PyModule_Create(&msvcrtmodule); |
---|
549 | n/a | if (m == NULL) |
---|
550 | n/a | return NULL; |
---|
551 | n/a | d = PyModule_GetDict(m); |
---|
552 | n/a | |
---|
553 | n/a | /* constants for the locking() function's mode argument */ |
---|
554 | n/a | insertint(d, "LK_LOCK", _LK_LOCK); |
---|
555 | n/a | insertint(d, "LK_NBLCK", _LK_NBLCK); |
---|
556 | n/a | insertint(d, "LK_NBRLCK", _LK_NBRLCK); |
---|
557 | n/a | insertint(d, "LK_RLCK", _LK_RLCK); |
---|
558 | n/a | insertint(d, "LK_UNLCK", _LK_UNLCK); |
---|
559 | n/a | insertint(d, "SEM_FAILCRITICALERRORS", SEM_FAILCRITICALERRORS); |
---|
560 | n/a | insertint(d, "SEM_NOALIGNMENTFAULTEXCEPT", SEM_NOALIGNMENTFAULTEXCEPT); |
---|
561 | n/a | insertint(d, "SEM_NOGPFAULTERRORBOX", SEM_NOGPFAULTERRORBOX); |
---|
562 | n/a | insertint(d, "SEM_NOOPENFILEERRORBOX", SEM_NOOPENFILEERRORBOX); |
---|
563 | n/a | #ifdef _DEBUG |
---|
564 | n/a | insertint(d, "CRT_WARN", _CRT_WARN); |
---|
565 | n/a | insertint(d, "CRT_ERROR", _CRT_ERROR); |
---|
566 | n/a | insertint(d, "CRT_ASSERT", _CRT_ASSERT); |
---|
567 | n/a | insertint(d, "CRTDBG_MODE_DEBUG", _CRTDBG_MODE_DEBUG); |
---|
568 | n/a | insertint(d, "CRTDBG_MODE_FILE", _CRTDBG_MODE_FILE); |
---|
569 | n/a | insertint(d, "CRTDBG_MODE_WNDW", _CRTDBG_MODE_WNDW); |
---|
570 | n/a | insertint(d, "CRTDBG_REPORT_MODE", _CRTDBG_REPORT_MODE); |
---|
571 | n/a | insertint(d, "CRTDBG_FILE_STDERR", (int)_CRTDBG_FILE_STDERR); |
---|
572 | n/a | insertint(d, "CRTDBG_FILE_STDOUT", (int)_CRTDBG_FILE_STDOUT); |
---|
573 | n/a | insertint(d, "CRTDBG_REPORT_FILE", (int)_CRTDBG_REPORT_FILE); |
---|
574 | n/a | #endif |
---|
575 | n/a | |
---|
576 | n/a | /* constants for the crt versions */ |
---|
577 | n/a | #ifdef _VC_ASSEMBLY_PUBLICKEYTOKEN |
---|
578 | n/a | st = PyModule_AddStringConstant(m, "VC_ASSEMBLY_PUBLICKEYTOKEN", |
---|
579 | n/a | _VC_ASSEMBLY_PUBLICKEYTOKEN); |
---|
580 | n/a | if (st < 0) return NULL; |
---|
581 | n/a | #endif |
---|
582 | n/a | #ifdef _CRT_ASSEMBLY_VERSION |
---|
583 | n/a | st = PyModule_AddStringConstant(m, "CRT_ASSEMBLY_VERSION", |
---|
584 | n/a | _CRT_ASSEMBLY_VERSION); |
---|
585 | n/a | if (st < 0) return NULL; |
---|
586 | n/a | #endif |
---|
587 | n/a | #ifdef __LIBRARIES_ASSEMBLY_NAME_PREFIX |
---|
588 | n/a | st = PyModule_AddStringConstant(m, "LIBRARIES_ASSEMBLY_NAME_PREFIX", |
---|
589 | n/a | __LIBRARIES_ASSEMBLY_NAME_PREFIX); |
---|
590 | n/a | if (st < 0) return NULL; |
---|
591 | n/a | #endif |
---|
592 | n/a | |
---|
593 | n/a | /* constants for the 2010 crt versions */ |
---|
594 | n/a | #if defined(_VC_CRT_MAJOR_VERSION) && defined (_VC_CRT_MINOR_VERSION) && defined(_VC_CRT_BUILD_VERSION) && defined(_VC_CRT_RBUILD_VERSION) |
---|
595 | n/a | version = PyUnicode_FromFormat("%d.%d.%d.%d", _VC_CRT_MAJOR_VERSION, |
---|
596 | n/a | _VC_CRT_MINOR_VERSION, |
---|
597 | n/a | _VC_CRT_BUILD_VERSION, |
---|
598 | n/a | _VC_CRT_RBUILD_VERSION); |
---|
599 | n/a | st = PyModule_AddObject(m, "CRT_ASSEMBLY_VERSION", version); |
---|
600 | n/a | if (st < 0) return NULL; |
---|
601 | n/a | #endif |
---|
602 | n/a | /* make compiler warning quiet if st is unused */ |
---|
603 | n/a | (void)st; |
---|
604 | n/a | |
---|
605 | n/a | return m; |
---|
606 | n/a | } |
---|