blob: 180c3e5fc54a7a8e1e1a7fa22cb5c13ea075f4a1 [file] [log] [blame]
Zachary Ware45520892015-05-13 01:22:32 -05001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_STRVAR(msvcrt_heapmin__doc__,
6"heapmin($module, /)\n"
7"--\n"
8"\n"
9"Minimize the malloc() heap.\n"
10"\n"
11"Force the malloc() heap to clean itself up and return unused blocks\n"
12"to the operating system. On failure, this raises OSError.");
13
14#define MSVCRT_HEAPMIN_METHODDEF \
15 {"heapmin", (PyCFunction)msvcrt_heapmin, METH_NOARGS, msvcrt_heapmin__doc__},
16
17static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030018msvcrt_heapmin_impl(PyObject *module);
Zachary Ware45520892015-05-13 01:22:32 -050019
20static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030021msvcrt_heapmin(PyObject *module, PyObject *Py_UNUSED(ignored))
Zachary Ware45520892015-05-13 01:22:32 -050022{
23 return msvcrt_heapmin_impl(module);
24}
25
26PyDoc_STRVAR(msvcrt_locking__doc__,
27"locking($module, fd, mode, nbytes, /)\n"
28"--\n"
29"\n"
30"Lock part of a file based on file descriptor fd from the C runtime.\n"
31"\n"
Serhiy Storchaka55fe1ae2017-04-16 10:46:38 +030032"Raises OSError on failure. The locked region of the file extends from\n"
Zachary Ware45520892015-05-13 01:22:32 -050033"the current file position for nbytes bytes, and may continue beyond\n"
34"the end of the file. mode must be one of the LK_* constants listed\n"
35"below. Multiple regions in a file may be locked at the same time, but\n"
36"may not overlap. Adjacent regions are not merged; they must be unlocked\n"
37"individually.");
38
39#define MSVCRT_LOCKING_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +020040 {"locking", (PyCFunction)(void(*)(void))msvcrt_locking, METH_FASTCALL, msvcrt_locking__doc__},
Zachary Ware45520892015-05-13 01:22:32 -050041
42static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030043msvcrt_locking_impl(PyObject *module, int fd, int mode, long nbytes);
Zachary Ware45520892015-05-13 01:22:32 -050044
45static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +020046msvcrt_locking(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Ware45520892015-05-13 01:22:32 -050047{
48 PyObject *return_value = NULL;
49 int fd;
50 int mode;
51 long nbytes;
52
Serhiy Storchaka4fa95912019-01-11 16:01:14 +020053 if (!_PyArg_CheckPositional("locking", nargs, 3, 3)) {
54 goto exit;
55 }
56 if (PyFloat_Check(args[0])) {
57 PyErr_SetString(PyExc_TypeError,
58 "integer argument expected, got float" );
59 goto exit;
60 }
61 fd = _PyLong_AsInt(args[0]);
62 if (fd == -1 && PyErr_Occurred()) {
63 goto exit;
64 }
65 if (PyFloat_Check(args[1])) {
66 PyErr_SetString(PyExc_TypeError,
67 "integer argument expected, got float" );
68 goto exit;
69 }
70 mode = _PyLong_AsInt(args[1]);
71 if (mode == -1 && PyErr_Occurred()) {
72 goto exit;
73 }
74 if (PyFloat_Check(args[2])) {
75 PyErr_SetString(PyExc_TypeError,
76 "integer argument expected, got float" );
77 goto exit;
78 }
79 nbytes = PyLong_AsLong(args[2]);
80 if (nbytes == -1 && PyErr_Occurred()) {
Victor Stinner259f0e42017-01-17 01:35:17 +010081 goto exit;
82 }
Zachary Ware45520892015-05-13 01:22:32 -050083 return_value = msvcrt_locking_impl(module, fd, mode, nbytes);
84
85exit:
86 return return_value;
87}
88
89PyDoc_STRVAR(msvcrt_setmode__doc__,
90"setmode($module, fd, mode, /)\n"
91"--\n"
92"\n"
93"Set the line-end translation mode for the file descriptor fd.\n"
94"\n"
95"To set it to text mode, flags should be os.O_TEXT; for binary, it\n"
96"should be os.O_BINARY.\n"
97"\n"
98"Return value is the previous mode.");
99
100#define MSVCRT_SETMODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200101 {"setmode", (PyCFunction)(void(*)(void))msvcrt_setmode, METH_FASTCALL, msvcrt_setmode__doc__},
Zachary Ware45520892015-05-13 01:22:32 -0500102
103static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300104msvcrt_setmode_impl(PyObject *module, int fd, int flags);
Zachary Ware45520892015-05-13 01:22:32 -0500105
106static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200107msvcrt_setmode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Ware45520892015-05-13 01:22:32 -0500108{
109 PyObject *return_value = NULL;
110 int fd;
111 int flags;
112 long _return_value;
113
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200114 if (!_PyArg_CheckPositional("setmode", nargs, 2, 2)) {
115 goto exit;
116 }
117 if (PyFloat_Check(args[0])) {
118 PyErr_SetString(PyExc_TypeError,
119 "integer argument expected, got float" );
120 goto exit;
121 }
122 fd = _PyLong_AsInt(args[0]);
123 if (fd == -1 && PyErr_Occurred()) {
124 goto exit;
125 }
126 if (PyFloat_Check(args[1])) {
127 PyErr_SetString(PyExc_TypeError,
128 "integer argument expected, got float" );
129 goto exit;
130 }
131 flags = _PyLong_AsInt(args[1]);
132 if (flags == -1 && PyErr_Occurred()) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100133 goto exit;
134 }
Zachary Ware45520892015-05-13 01:22:32 -0500135 _return_value = msvcrt_setmode_impl(module, fd, flags);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300136 if ((_return_value == -1) && PyErr_Occurred()) {
Zachary Ware45520892015-05-13 01:22:32 -0500137 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300138 }
Zachary Ware45520892015-05-13 01:22:32 -0500139 return_value = PyLong_FromLong(_return_value);
140
141exit:
142 return return_value;
143}
144
145PyDoc_STRVAR(msvcrt_open_osfhandle__doc__,
146"open_osfhandle($module, handle, flags, /)\n"
147"--\n"
148"\n"
149"Create a C runtime file descriptor from the file handle handle.\n"
150"\n"
151"The flags parameter should be a bitwise OR of os.O_APPEND, os.O_RDONLY,\n"
152"and os.O_TEXT. The returned file descriptor may be used as a parameter\n"
153"to os.fdopen() to create a file object.");
154
155#define MSVCRT_OPEN_OSFHANDLE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200156 {"open_osfhandle", (PyCFunction)(void(*)(void))msvcrt_open_osfhandle, METH_FASTCALL, msvcrt_open_osfhandle__doc__},
Zachary Ware45520892015-05-13 01:22:32 -0500157
158static long
Segev Finer679b5662017-07-27 01:17:57 +0300159msvcrt_open_osfhandle_impl(PyObject *module, void *handle, int flags);
Zachary Ware45520892015-05-13 01:22:32 -0500160
161static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200162msvcrt_open_osfhandle(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Ware45520892015-05-13 01:22:32 -0500163{
164 PyObject *return_value = NULL;
Segev Finer679b5662017-07-27 01:17:57 +0300165 void *handle;
Zachary Ware45520892015-05-13 01:22:32 -0500166 int flags;
167 long _return_value;
168
Segev Finera80e9852017-07-27 06:15:18 +0300169 if (!_PyArg_ParseStack(args, nargs, ""_Py_PARSE_UINTPTR"i:open_osfhandle",
Sylvain74453812017-06-10 06:51:48 +0200170 &handle, &flags)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100171 goto exit;
172 }
Zachary Ware45520892015-05-13 01:22:32 -0500173 _return_value = msvcrt_open_osfhandle_impl(module, handle, flags);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300174 if ((_return_value == -1) && PyErr_Occurred()) {
Zachary Ware45520892015-05-13 01:22:32 -0500175 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300176 }
Zachary Ware45520892015-05-13 01:22:32 -0500177 return_value = PyLong_FromLong(_return_value);
178
179exit:
180 return return_value;
181}
182
183PyDoc_STRVAR(msvcrt_get_osfhandle__doc__,
184"get_osfhandle($module, fd, /)\n"
185"--\n"
186"\n"
187"Return the file handle for the file descriptor fd.\n"
188"\n"
Serhiy Storchaka55fe1ae2017-04-16 10:46:38 +0300189"Raises OSError if fd is not recognized.");
Zachary Ware45520892015-05-13 01:22:32 -0500190
191#define MSVCRT_GET_OSFHANDLE_METHODDEF \
192 {"get_osfhandle", (PyCFunction)msvcrt_get_osfhandle, METH_O, msvcrt_get_osfhandle__doc__},
193
Segev Finer679b5662017-07-27 01:17:57 +0300194static void *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300195msvcrt_get_osfhandle_impl(PyObject *module, int fd);
Zachary Ware45520892015-05-13 01:22:32 -0500196
197static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300198msvcrt_get_osfhandle(PyObject *module, PyObject *arg)
Zachary Ware45520892015-05-13 01:22:32 -0500199{
200 PyObject *return_value = NULL;
201 int fd;
Segev Finer679b5662017-07-27 01:17:57 +0300202 void *_return_value;
Zachary Ware45520892015-05-13 01:22:32 -0500203
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200204 if (PyFloat_Check(arg)) {
205 PyErr_SetString(PyExc_TypeError,
206 "integer argument expected, got float" );
207 goto exit;
208 }
209 fd = _PyLong_AsInt(arg);
210 if (fd == -1 && PyErr_Occurred()) {
Zachary Ware45520892015-05-13 01:22:32 -0500211 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300212 }
Zachary Ware45520892015-05-13 01:22:32 -0500213 _return_value = msvcrt_get_osfhandle_impl(module, fd);
Segev Finer679b5662017-07-27 01:17:57 +0300214 if ((_return_value == NULL || _return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
Zachary Ware45520892015-05-13 01:22:32 -0500215 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300216 }
Segev Finer679b5662017-07-27 01:17:57 +0300217 return_value = PyLong_FromVoidPtr(_return_value);
Zachary Ware45520892015-05-13 01:22:32 -0500218
219exit:
220 return return_value;
221}
222
223PyDoc_STRVAR(msvcrt_kbhit__doc__,
224"kbhit($module, /)\n"
225"--\n"
226"\n"
227"Return true if a keypress is waiting to be read.");
228
229#define MSVCRT_KBHIT_METHODDEF \
230 {"kbhit", (PyCFunction)msvcrt_kbhit, METH_NOARGS, msvcrt_kbhit__doc__},
231
232static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300233msvcrt_kbhit_impl(PyObject *module);
Zachary Ware45520892015-05-13 01:22:32 -0500234
235static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300236msvcrt_kbhit(PyObject *module, PyObject *Py_UNUSED(ignored))
Zachary Ware45520892015-05-13 01:22:32 -0500237{
238 PyObject *return_value = NULL;
239 long _return_value;
240
241 _return_value = msvcrt_kbhit_impl(module);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300242 if ((_return_value == -1) && PyErr_Occurred()) {
Zachary Ware45520892015-05-13 01:22:32 -0500243 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300244 }
Zachary Ware45520892015-05-13 01:22:32 -0500245 return_value = PyLong_FromLong(_return_value);
246
247exit:
248 return return_value;
249}
250
251PyDoc_STRVAR(msvcrt_getch__doc__,
252"getch($module, /)\n"
253"--\n"
254"\n"
255"Read a keypress and return the resulting character as a byte string.\n"
256"\n"
257"Nothing is echoed to the console. This call will block if a keypress is\n"
258"not already available, but will not wait for Enter to be pressed. If the\n"
259"pressed key was a special function key, this will return \'\\000\' or\n"
260"\'\\xe0\'; the next call will return the keycode. The Control-C keypress\n"
261"cannot be read with this function.");
262
263#define MSVCRT_GETCH_METHODDEF \
264 {"getch", (PyCFunction)msvcrt_getch, METH_NOARGS, msvcrt_getch__doc__},
265
266static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300267msvcrt_getch_impl(PyObject *module);
Zachary Ware45520892015-05-13 01:22:32 -0500268
269static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300270msvcrt_getch(PyObject *module, PyObject *Py_UNUSED(ignored))
Zachary Ware45520892015-05-13 01:22:32 -0500271{
272 PyObject *return_value = NULL;
273 char s[1];
274
275 s[0] = msvcrt_getch_impl(module);
276 return_value = PyBytes_FromStringAndSize(s, 1);
277
278 return return_value;
279}
280
Zachary Ware45520892015-05-13 01:22:32 -0500281PyDoc_STRVAR(msvcrt_getwch__doc__,
282"getwch($module, /)\n"
283"--\n"
284"\n"
285"Wide char variant of getch(), returning a Unicode value.");
286
287#define MSVCRT_GETWCH_METHODDEF \
288 {"getwch", (PyCFunction)msvcrt_getwch, METH_NOARGS, msvcrt_getwch__doc__},
289
290static wchar_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300291msvcrt_getwch_impl(PyObject *module);
Zachary Ware45520892015-05-13 01:22:32 -0500292
293static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300294msvcrt_getwch(PyObject *module, PyObject *Py_UNUSED(ignored))
Zachary Ware45520892015-05-13 01:22:32 -0500295{
296 PyObject *return_value = NULL;
297 wchar_t _return_value;
298
299 _return_value = msvcrt_getwch_impl(module);
300 return_value = PyUnicode_FromOrdinal(_return_value);
301
302 return return_value;
303}
304
Zachary Ware45520892015-05-13 01:22:32 -0500305PyDoc_STRVAR(msvcrt_getche__doc__,
306"getche($module, /)\n"
307"--\n"
308"\n"
309"Similar to getch(), but the keypress will be echoed if possible.");
310
311#define MSVCRT_GETCHE_METHODDEF \
312 {"getche", (PyCFunction)msvcrt_getche, METH_NOARGS, msvcrt_getche__doc__},
313
314static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300315msvcrt_getche_impl(PyObject *module);
Zachary Ware45520892015-05-13 01:22:32 -0500316
317static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300318msvcrt_getche(PyObject *module, PyObject *Py_UNUSED(ignored))
Zachary Ware45520892015-05-13 01:22:32 -0500319{
320 PyObject *return_value = NULL;
321 char s[1];
322
323 s[0] = msvcrt_getche_impl(module);
324 return_value = PyBytes_FromStringAndSize(s, 1);
325
326 return return_value;
327}
328
Zachary Ware45520892015-05-13 01:22:32 -0500329PyDoc_STRVAR(msvcrt_getwche__doc__,
330"getwche($module, /)\n"
331"--\n"
332"\n"
333"Wide char variant of getche(), returning a Unicode value.");
334
335#define MSVCRT_GETWCHE_METHODDEF \
336 {"getwche", (PyCFunction)msvcrt_getwche, METH_NOARGS, msvcrt_getwche__doc__},
337
338static wchar_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300339msvcrt_getwche_impl(PyObject *module);
Zachary Ware45520892015-05-13 01:22:32 -0500340
341static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300342msvcrt_getwche(PyObject *module, PyObject *Py_UNUSED(ignored))
Zachary Ware45520892015-05-13 01:22:32 -0500343{
344 PyObject *return_value = NULL;
345 wchar_t _return_value;
346
347 _return_value = msvcrt_getwche_impl(module);
348 return_value = PyUnicode_FromOrdinal(_return_value);
349
350 return return_value;
351}
352
Zachary Ware45520892015-05-13 01:22:32 -0500353PyDoc_STRVAR(msvcrt_putch__doc__,
354"putch($module, char, /)\n"
355"--\n"
356"\n"
357"Print the byte string char to the console without buffering.");
358
359#define MSVCRT_PUTCH_METHODDEF \
360 {"putch", (PyCFunction)msvcrt_putch, METH_O, msvcrt_putch__doc__},
361
362static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300363msvcrt_putch_impl(PyObject *module, char char_value);
Zachary Ware45520892015-05-13 01:22:32 -0500364
365static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300366msvcrt_putch(PyObject *module, PyObject *arg)
Zachary Ware45520892015-05-13 01:22:32 -0500367{
368 PyObject *return_value = NULL;
369 char char_value;
370
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200371 if (PyBytes_Check(arg) && PyBytes_GET_SIZE(arg) == 1) {
372 char_value = PyBytes_AS_STRING(arg)[0];
373 }
374 else if (PyByteArray_Check(arg) && PyByteArray_GET_SIZE(arg) == 1) {
375 char_value = PyByteArray_AS_STRING(arg)[0];
376 }
377 else {
Serhiy Storchaka96631dc2019-08-29 18:29:59 +0300378 _PyArg_BadArgument("putch", "argument", "a byte string of length 1", arg);
Zachary Ware45520892015-05-13 01:22:32 -0500379 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300380 }
Zachary Ware45520892015-05-13 01:22:32 -0500381 return_value = msvcrt_putch_impl(module, char_value);
382
383exit:
384 return return_value;
385}
386
Zachary Ware45520892015-05-13 01:22:32 -0500387PyDoc_STRVAR(msvcrt_putwch__doc__,
388"putwch($module, unicode_char, /)\n"
389"--\n"
390"\n"
391"Wide char variant of putch(), accepting a Unicode value.");
392
393#define MSVCRT_PUTWCH_METHODDEF \
394 {"putwch", (PyCFunction)msvcrt_putwch, METH_O, msvcrt_putwch__doc__},
395
396static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300397msvcrt_putwch_impl(PyObject *module, int unicode_char);
Zachary Ware45520892015-05-13 01:22:32 -0500398
399static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300400msvcrt_putwch(PyObject *module, PyObject *arg)
Zachary Ware45520892015-05-13 01:22:32 -0500401{
402 PyObject *return_value = NULL;
403 int unicode_char;
404
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200405 if (!PyUnicode_Check(arg)) {
Serhiy Storchaka96631dc2019-08-29 18:29:59 +0300406 _PyArg_BadArgument("putwch", "argument", "a unicode character", arg);
Zachary Ware45520892015-05-13 01:22:32 -0500407 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300408 }
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200409 if (PyUnicode_READY(arg)) {
410 goto exit;
411 }
412 if (PyUnicode_GET_LENGTH(arg) != 1) {
Serhiy Storchaka96631dc2019-08-29 18:29:59 +0300413 _PyArg_BadArgument("putwch", "argument", "a unicode character", arg);
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200414 goto exit;
415 }
416 unicode_char = PyUnicode_READ_CHAR(arg, 0);
Zachary Ware45520892015-05-13 01:22:32 -0500417 return_value = msvcrt_putwch_impl(module, unicode_char);
418
419exit:
420 return return_value;
421}
422
Zachary Ware45520892015-05-13 01:22:32 -0500423PyDoc_STRVAR(msvcrt_ungetch__doc__,
424"ungetch($module, char, /)\n"
425"--\n"
426"\n"
427"Opposite of getch.\n"
428"\n"
429"Cause the byte string char to be \"pushed back\" into the\n"
430"console buffer; it will be the next character read by\n"
431"getch() or getche().");
432
433#define MSVCRT_UNGETCH_METHODDEF \
434 {"ungetch", (PyCFunction)msvcrt_ungetch, METH_O, msvcrt_ungetch__doc__},
435
436static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300437msvcrt_ungetch_impl(PyObject *module, char char_value);
Zachary Ware45520892015-05-13 01:22:32 -0500438
439static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300440msvcrt_ungetch(PyObject *module, PyObject *arg)
Zachary Ware45520892015-05-13 01:22:32 -0500441{
442 PyObject *return_value = NULL;
443 char char_value;
444
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200445 if (PyBytes_Check(arg) && PyBytes_GET_SIZE(arg) == 1) {
446 char_value = PyBytes_AS_STRING(arg)[0];
447 }
448 else if (PyByteArray_Check(arg) && PyByteArray_GET_SIZE(arg) == 1) {
449 char_value = PyByteArray_AS_STRING(arg)[0];
450 }
451 else {
Serhiy Storchaka96631dc2019-08-29 18:29:59 +0300452 _PyArg_BadArgument("ungetch", "argument", "a byte string of length 1", arg);
Zachary Ware45520892015-05-13 01:22:32 -0500453 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300454 }
Zachary Ware45520892015-05-13 01:22:32 -0500455 return_value = msvcrt_ungetch_impl(module, char_value);
456
457exit:
458 return return_value;
459}
460
Zachary Ware45520892015-05-13 01:22:32 -0500461PyDoc_STRVAR(msvcrt_ungetwch__doc__,
462"ungetwch($module, unicode_char, /)\n"
463"--\n"
464"\n"
465"Wide char variant of ungetch(), accepting a Unicode value.");
466
467#define MSVCRT_UNGETWCH_METHODDEF \
468 {"ungetwch", (PyCFunction)msvcrt_ungetwch, METH_O, msvcrt_ungetwch__doc__},
469
470static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300471msvcrt_ungetwch_impl(PyObject *module, int unicode_char);
Zachary Ware45520892015-05-13 01:22:32 -0500472
473static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300474msvcrt_ungetwch(PyObject *module, PyObject *arg)
Zachary Ware45520892015-05-13 01:22:32 -0500475{
476 PyObject *return_value = NULL;
477 int unicode_char;
478
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200479 if (!PyUnicode_Check(arg)) {
Serhiy Storchaka96631dc2019-08-29 18:29:59 +0300480 _PyArg_BadArgument("ungetwch", "argument", "a unicode character", arg);
Zachary Ware45520892015-05-13 01:22:32 -0500481 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300482 }
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200483 if (PyUnicode_READY(arg)) {
484 goto exit;
485 }
486 if (PyUnicode_GET_LENGTH(arg) != 1) {
Serhiy Storchaka96631dc2019-08-29 18:29:59 +0300487 _PyArg_BadArgument("ungetwch", "argument", "a unicode character", arg);
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200488 goto exit;
489 }
490 unicode_char = PyUnicode_READ_CHAR(arg, 0);
Zachary Ware45520892015-05-13 01:22:32 -0500491 return_value = msvcrt_ungetwch_impl(module, unicode_char);
492
493exit:
494 return return_value;
495}
496
Zachary Ware45520892015-05-13 01:22:32 -0500497#if defined(_DEBUG)
498
499PyDoc_STRVAR(msvcrt_CrtSetReportFile__doc__,
500"CrtSetReportFile($module, type, file, /)\n"
501"--\n"
502"\n"
503"Wrapper around _CrtSetReportFile.\n"
504"\n"
505"Only available on Debug builds.");
506
507#define MSVCRT_CRTSETREPORTFILE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200508 {"CrtSetReportFile", (PyCFunction)(void(*)(void))msvcrt_CrtSetReportFile, METH_FASTCALL, msvcrt_CrtSetReportFile__doc__},
Zachary Ware45520892015-05-13 01:22:32 -0500509
Segev Finer679b5662017-07-27 01:17:57 +0300510static void *
511msvcrt_CrtSetReportFile_impl(PyObject *module, int type, void *file);
Zachary Ware45520892015-05-13 01:22:32 -0500512
513static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200514msvcrt_CrtSetReportFile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Ware45520892015-05-13 01:22:32 -0500515{
516 PyObject *return_value = NULL;
517 int type;
Segev Finer679b5662017-07-27 01:17:57 +0300518 void *file;
519 void *_return_value;
Zachary Ware45520892015-05-13 01:22:32 -0500520
Segev Finera80e9852017-07-27 06:15:18 +0300521 if (!_PyArg_ParseStack(args, nargs, "i"_Py_PARSE_UINTPTR":CrtSetReportFile",
Sylvain74453812017-06-10 06:51:48 +0200522 &type, &file)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100523 goto exit;
524 }
Zachary Ware45520892015-05-13 01:22:32 -0500525 _return_value = msvcrt_CrtSetReportFile_impl(module, type, file);
Segev Finer679b5662017-07-27 01:17:57 +0300526 if ((_return_value == NULL || _return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
Zachary Ware45520892015-05-13 01:22:32 -0500527 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300528 }
Segev Finer679b5662017-07-27 01:17:57 +0300529 return_value = PyLong_FromVoidPtr(_return_value);
Zachary Ware45520892015-05-13 01:22:32 -0500530
531exit:
532 return return_value;
533}
534
535#endif /* defined(_DEBUG) */
536
537#if defined(_DEBUG)
538
539PyDoc_STRVAR(msvcrt_CrtSetReportMode__doc__,
540"CrtSetReportMode($module, type, mode, /)\n"
541"--\n"
542"\n"
543"Wrapper around _CrtSetReportMode.\n"
544"\n"
545"Only available on Debug builds.");
546
547#define MSVCRT_CRTSETREPORTMODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200548 {"CrtSetReportMode", (PyCFunction)(void(*)(void))msvcrt_CrtSetReportMode, METH_FASTCALL, msvcrt_CrtSetReportMode__doc__},
Zachary Ware45520892015-05-13 01:22:32 -0500549
550static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300551msvcrt_CrtSetReportMode_impl(PyObject *module, int type, int mode);
Zachary Ware45520892015-05-13 01:22:32 -0500552
553static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200554msvcrt_CrtSetReportMode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Ware45520892015-05-13 01:22:32 -0500555{
556 PyObject *return_value = NULL;
557 int type;
558 int mode;
559 long _return_value;
560
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200561 if (!_PyArg_CheckPositional("CrtSetReportMode", nargs, 2, 2)) {
562 goto exit;
563 }
564 if (PyFloat_Check(args[0])) {
565 PyErr_SetString(PyExc_TypeError,
566 "integer argument expected, got float" );
567 goto exit;
568 }
569 type = _PyLong_AsInt(args[0]);
570 if (type == -1 && PyErr_Occurred()) {
571 goto exit;
572 }
573 if (PyFloat_Check(args[1])) {
574 PyErr_SetString(PyExc_TypeError,
575 "integer argument expected, got float" );
576 goto exit;
577 }
578 mode = _PyLong_AsInt(args[1]);
579 if (mode == -1 && PyErr_Occurred()) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100580 goto exit;
581 }
Zachary Ware45520892015-05-13 01:22:32 -0500582 _return_value = msvcrt_CrtSetReportMode_impl(module, type, mode);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300583 if ((_return_value == -1) && PyErr_Occurred()) {
Zachary Ware45520892015-05-13 01:22:32 -0500584 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300585 }
Zachary Ware45520892015-05-13 01:22:32 -0500586 return_value = PyLong_FromLong(_return_value);
587
588exit:
589 return return_value;
590}
591
592#endif /* defined(_DEBUG) */
593
594#if defined(_DEBUG)
595
596PyDoc_STRVAR(msvcrt_set_error_mode__doc__,
597"set_error_mode($module, mode, /)\n"
598"--\n"
599"\n"
600"Wrapper around _set_error_mode.\n"
601"\n"
602"Only available on Debug builds.");
603
604#define MSVCRT_SET_ERROR_MODE_METHODDEF \
605 {"set_error_mode", (PyCFunction)msvcrt_set_error_mode, METH_O, msvcrt_set_error_mode__doc__},
606
607static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300608msvcrt_set_error_mode_impl(PyObject *module, int mode);
Zachary Ware45520892015-05-13 01:22:32 -0500609
610static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300611msvcrt_set_error_mode(PyObject *module, PyObject *arg)
Zachary Ware45520892015-05-13 01:22:32 -0500612{
613 PyObject *return_value = NULL;
614 int mode;
615 long _return_value;
616
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200617 if (PyFloat_Check(arg)) {
618 PyErr_SetString(PyExc_TypeError,
619 "integer argument expected, got float" );
620 goto exit;
621 }
622 mode = _PyLong_AsInt(arg);
623 if (mode == -1 && PyErr_Occurred()) {
Zachary Ware45520892015-05-13 01:22:32 -0500624 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300625 }
Zachary Ware45520892015-05-13 01:22:32 -0500626 _return_value = msvcrt_set_error_mode_impl(module, mode);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300627 if ((_return_value == -1) && PyErr_Occurred()) {
Zachary Ware45520892015-05-13 01:22:32 -0500628 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300629 }
Zachary Ware45520892015-05-13 01:22:32 -0500630 return_value = PyLong_FromLong(_return_value);
631
632exit:
633 return return_value;
634}
635
636#endif /* defined(_DEBUG) */
637
638PyDoc_STRVAR(msvcrt_SetErrorMode__doc__,
639"SetErrorMode($module, mode, /)\n"
640"--\n"
641"\n"
642"Wrapper around SetErrorMode.");
643
644#define MSVCRT_SETERRORMODE_METHODDEF \
645 {"SetErrorMode", (PyCFunction)msvcrt_SetErrorMode, METH_O, msvcrt_SetErrorMode__doc__},
646
647static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300648msvcrt_SetErrorMode_impl(PyObject *module, unsigned int mode);
Zachary Ware45520892015-05-13 01:22:32 -0500649
650static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300651msvcrt_SetErrorMode(PyObject *module, PyObject *arg)
Zachary Ware45520892015-05-13 01:22:32 -0500652{
653 PyObject *return_value = NULL;
654 unsigned int mode;
655
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200656 if (PyFloat_Check(arg)) {
657 PyErr_SetString(PyExc_TypeError,
658 "integer argument expected, got float" );
659 goto exit;
660 }
661 mode = (unsigned int)PyLong_AsUnsignedLongMask(arg);
662 if (mode == (unsigned int)-1 && PyErr_Occurred()) {
Zachary Ware45520892015-05-13 01:22:32 -0500663 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300664 }
Zachary Ware45520892015-05-13 01:22:32 -0500665 return_value = msvcrt_SetErrorMode_impl(module, mode);
666
667exit:
668 return return_value;
669}
670
Zachary Ware45520892015-05-13 01:22:32 -0500671#ifndef MSVCRT_CRTSETREPORTFILE_METHODDEF
672 #define MSVCRT_CRTSETREPORTFILE_METHODDEF
673#endif /* !defined(MSVCRT_CRTSETREPORTFILE_METHODDEF) */
674
675#ifndef MSVCRT_CRTSETREPORTMODE_METHODDEF
676 #define MSVCRT_CRTSETREPORTMODE_METHODDEF
677#endif /* !defined(MSVCRT_CRTSETREPORTMODE_METHODDEF) */
678
679#ifndef MSVCRT_SET_ERROR_MODE_METHODDEF
680 #define MSVCRT_SET_ERROR_MODE_METHODDEF
681#endif /* !defined(MSVCRT_SET_ERROR_MODE_METHODDEF) */
Serhiy Storchaka96631dc2019-08-29 18:29:59 +0300682/*[clinic end generated code: output=7cc6ffaf64f268f7 input=a9049054013a1b77]*/