blob: b1c588b0642ab200becb5f93094e40f7e4657f9d [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
Sylvain74453812017-06-10 06:51:48 +020053 if (!_PyArg_ParseStack(args, nargs, "iil:locking",
54 &fd, &mode, &nbytes)) {
Victor Stinner259f0e42017-01-17 01:35:17 +010055 goto exit;
56 }
Zachary Ware45520892015-05-13 01:22:32 -050057 return_value = msvcrt_locking_impl(module, fd, mode, nbytes);
58
59exit:
60 return return_value;
61}
62
63PyDoc_STRVAR(msvcrt_setmode__doc__,
64"setmode($module, fd, mode, /)\n"
65"--\n"
66"\n"
67"Set the line-end translation mode for the file descriptor fd.\n"
68"\n"
69"To set it to text mode, flags should be os.O_TEXT; for binary, it\n"
70"should be os.O_BINARY.\n"
71"\n"
72"Return value is the previous mode.");
73
74#define MSVCRT_SETMODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +020075 {"setmode", (PyCFunction)(void(*)(void))msvcrt_setmode, METH_FASTCALL, msvcrt_setmode__doc__},
Zachary Ware45520892015-05-13 01:22:32 -050076
77static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030078msvcrt_setmode_impl(PyObject *module, int fd, int flags);
Zachary Ware45520892015-05-13 01:22:32 -050079
80static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +020081msvcrt_setmode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Ware45520892015-05-13 01:22:32 -050082{
83 PyObject *return_value = NULL;
84 int fd;
85 int flags;
86 long _return_value;
87
Sylvain74453812017-06-10 06:51:48 +020088 if (!_PyArg_ParseStack(args, nargs, "ii:setmode",
89 &fd, &flags)) {
Victor Stinner259f0e42017-01-17 01:35:17 +010090 goto exit;
91 }
Zachary Ware45520892015-05-13 01:22:32 -050092 _return_value = msvcrt_setmode_impl(module, fd, flags);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030093 if ((_return_value == -1) && PyErr_Occurred()) {
Zachary Ware45520892015-05-13 01:22:32 -050094 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030095 }
Zachary Ware45520892015-05-13 01:22:32 -050096 return_value = PyLong_FromLong(_return_value);
97
98exit:
99 return return_value;
100}
101
102PyDoc_STRVAR(msvcrt_open_osfhandle__doc__,
103"open_osfhandle($module, handle, flags, /)\n"
104"--\n"
105"\n"
106"Create a C runtime file descriptor from the file handle handle.\n"
107"\n"
108"The flags parameter should be a bitwise OR of os.O_APPEND, os.O_RDONLY,\n"
109"and os.O_TEXT. The returned file descriptor may be used as a parameter\n"
110"to os.fdopen() to create a file object.");
111
112#define MSVCRT_OPEN_OSFHANDLE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200113 {"open_osfhandle", (PyCFunction)(void(*)(void))msvcrt_open_osfhandle, METH_FASTCALL, msvcrt_open_osfhandle__doc__},
Zachary Ware45520892015-05-13 01:22:32 -0500114
115static long
Segev Finer679b5662017-07-27 01:17:57 +0300116msvcrt_open_osfhandle_impl(PyObject *module, void *handle, int flags);
Zachary Ware45520892015-05-13 01:22:32 -0500117
118static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200119msvcrt_open_osfhandle(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Ware45520892015-05-13 01:22:32 -0500120{
121 PyObject *return_value = NULL;
Segev Finer679b5662017-07-27 01:17:57 +0300122 void *handle;
Zachary Ware45520892015-05-13 01:22:32 -0500123 int flags;
124 long _return_value;
125
Segev Finera80e9852017-07-27 06:15:18 +0300126 if (!_PyArg_ParseStack(args, nargs, ""_Py_PARSE_UINTPTR"i:open_osfhandle",
Sylvain74453812017-06-10 06:51:48 +0200127 &handle, &flags)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100128 goto exit;
129 }
Zachary Ware45520892015-05-13 01:22:32 -0500130 _return_value = msvcrt_open_osfhandle_impl(module, handle, flags);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300131 if ((_return_value == -1) && PyErr_Occurred()) {
Zachary Ware45520892015-05-13 01:22:32 -0500132 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300133 }
Zachary Ware45520892015-05-13 01:22:32 -0500134 return_value = PyLong_FromLong(_return_value);
135
136exit:
137 return return_value;
138}
139
140PyDoc_STRVAR(msvcrt_get_osfhandle__doc__,
141"get_osfhandle($module, fd, /)\n"
142"--\n"
143"\n"
144"Return the file handle for the file descriptor fd.\n"
145"\n"
Serhiy Storchaka55fe1ae2017-04-16 10:46:38 +0300146"Raises OSError if fd is not recognized.");
Zachary Ware45520892015-05-13 01:22:32 -0500147
148#define MSVCRT_GET_OSFHANDLE_METHODDEF \
149 {"get_osfhandle", (PyCFunction)msvcrt_get_osfhandle, METH_O, msvcrt_get_osfhandle__doc__},
150
Segev Finer679b5662017-07-27 01:17:57 +0300151static void *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300152msvcrt_get_osfhandle_impl(PyObject *module, int fd);
Zachary Ware45520892015-05-13 01:22:32 -0500153
154static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300155msvcrt_get_osfhandle(PyObject *module, PyObject *arg)
Zachary Ware45520892015-05-13 01:22:32 -0500156{
157 PyObject *return_value = NULL;
158 int fd;
Segev Finer679b5662017-07-27 01:17:57 +0300159 void *_return_value;
Zachary Ware45520892015-05-13 01:22:32 -0500160
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200161 if (PyFloat_Check(arg)) {
162 PyErr_SetString(PyExc_TypeError,
163 "integer argument expected, got float" );
164 goto exit;
165 }
166 fd = _PyLong_AsInt(arg);
167 if (fd == -1 && PyErr_Occurred()) {
Zachary Ware45520892015-05-13 01:22:32 -0500168 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300169 }
Zachary Ware45520892015-05-13 01:22:32 -0500170 _return_value = msvcrt_get_osfhandle_impl(module, fd);
Segev Finer679b5662017-07-27 01:17:57 +0300171 if ((_return_value == NULL || _return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
Zachary Ware45520892015-05-13 01:22:32 -0500172 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300173 }
Segev Finer679b5662017-07-27 01:17:57 +0300174 return_value = PyLong_FromVoidPtr(_return_value);
Zachary Ware45520892015-05-13 01:22:32 -0500175
176exit:
177 return return_value;
178}
179
180PyDoc_STRVAR(msvcrt_kbhit__doc__,
181"kbhit($module, /)\n"
182"--\n"
183"\n"
184"Return true if a keypress is waiting to be read.");
185
186#define MSVCRT_KBHIT_METHODDEF \
187 {"kbhit", (PyCFunction)msvcrt_kbhit, METH_NOARGS, msvcrt_kbhit__doc__},
188
189static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300190msvcrt_kbhit_impl(PyObject *module);
Zachary Ware45520892015-05-13 01:22:32 -0500191
192static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300193msvcrt_kbhit(PyObject *module, PyObject *Py_UNUSED(ignored))
Zachary Ware45520892015-05-13 01:22:32 -0500194{
195 PyObject *return_value = NULL;
196 long _return_value;
197
198 _return_value = msvcrt_kbhit_impl(module);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300199 if ((_return_value == -1) && PyErr_Occurred()) {
Zachary Ware45520892015-05-13 01:22:32 -0500200 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300201 }
Zachary Ware45520892015-05-13 01:22:32 -0500202 return_value = PyLong_FromLong(_return_value);
203
204exit:
205 return return_value;
206}
207
208PyDoc_STRVAR(msvcrt_getch__doc__,
209"getch($module, /)\n"
210"--\n"
211"\n"
212"Read a keypress and return the resulting character as a byte string.\n"
213"\n"
214"Nothing is echoed to the console. This call will block if a keypress is\n"
215"not already available, but will not wait for Enter to be pressed. If the\n"
216"pressed key was a special function key, this will return \'\\000\' or\n"
217"\'\\xe0\'; the next call will return the keycode. The Control-C keypress\n"
218"cannot be read with this function.");
219
220#define MSVCRT_GETCH_METHODDEF \
221 {"getch", (PyCFunction)msvcrt_getch, METH_NOARGS, msvcrt_getch__doc__},
222
223static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300224msvcrt_getch_impl(PyObject *module);
Zachary Ware45520892015-05-13 01:22:32 -0500225
226static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300227msvcrt_getch(PyObject *module, PyObject *Py_UNUSED(ignored))
Zachary Ware45520892015-05-13 01:22:32 -0500228{
229 PyObject *return_value = NULL;
230 char s[1];
231
232 s[0] = msvcrt_getch_impl(module);
233 return_value = PyBytes_FromStringAndSize(s, 1);
234
235 return return_value;
236}
237
Zachary Ware45520892015-05-13 01:22:32 -0500238PyDoc_STRVAR(msvcrt_getwch__doc__,
239"getwch($module, /)\n"
240"--\n"
241"\n"
242"Wide char variant of getch(), returning a Unicode value.");
243
244#define MSVCRT_GETWCH_METHODDEF \
245 {"getwch", (PyCFunction)msvcrt_getwch, METH_NOARGS, msvcrt_getwch__doc__},
246
247static wchar_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300248msvcrt_getwch_impl(PyObject *module);
Zachary Ware45520892015-05-13 01:22:32 -0500249
250static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300251msvcrt_getwch(PyObject *module, PyObject *Py_UNUSED(ignored))
Zachary Ware45520892015-05-13 01:22:32 -0500252{
253 PyObject *return_value = NULL;
254 wchar_t _return_value;
255
256 _return_value = msvcrt_getwch_impl(module);
257 return_value = PyUnicode_FromOrdinal(_return_value);
258
259 return return_value;
260}
261
Zachary Ware45520892015-05-13 01:22:32 -0500262PyDoc_STRVAR(msvcrt_getche__doc__,
263"getche($module, /)\n"
264"--\n"
265"\n"
266"Similar to getch(), but the keypress will be echoed if possible.");
267
268#define MSVCRT_GETCHE_METHODDEF \
269 {"getche", (PyCFunction)msvcrt_getche, METH_NOARGS, msvcrt_getche__doc__},
270
271static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300272msvcrt_getche_impl(PyObject *module);
Zachary Ware45520892015-05-13 01:22:32 -0500273
274static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300275msvcrt_getche(PyObject *module, PyObject *Py_UNUSED(ignored))
Zachary Ware45520892015-05-13 01:22:32 -0500276{
277 PyObject *return_value = NULL;
278 char s[1];
279
280 s[0] = msvcrt_getche_impl(module);
281 return_value = PyBytes_FromStringAndSize(s, 1);
282
283 return return_value;
284}
285
Zachary Ware45520892015-05-13 01:22:32 -0500286PyDoc_STRVAR(msvcrt_getwche__doc__,
287"getwche($module, /)\n"
288"--\n"
289"\n"
290"Wide char variant of getche(), returning a Unicode value.");
291
292#define MSVCRT_GETWCHE_METHODDEF \
293 {"getwche", (PyCFunction)msvcrt_getwche, METH_NOARGS, msvcrt_getwche__doc__},
294
295static wchar_t
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300296msvcrt_getwche_impl(PyObject *module);
Zachary Ware45520892015-05-13 01:22:32 -0500297
298static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300299msvcrt_getwche(PyObject *module, PyObject *Py_UNUSED(ignored))
Zachary Ware45520892015-05-13 01:22:32 -0500300{
301 PyObject *return_value = NULL;
302 wchar_t _return_value;
303
304 _return_value = msvcrt_getwche_impl(module);
305 return_value = PyUnicode_FromOrdinal(_return_value);
306
307 return return_value;
308}
309
Zachary Ware45520892015-05-13 01:22:32 -0500310PyDoc_STRVAR(msvcrt_putch__doc__,
311"putch($module, char, /)\n"
312"--\n"
313"\n"
314"Print the byte string char to the console without buffering.");
315
316#define MSVCRT_PUTCH_METHODDEF \
317 {"putch", (PyCFunction)msvcrt_putch, METH_O, msvcrt_putch__doc__},
318
319static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300320msvcrt_putch_impl(PyObject *module, char char_value);
Zachary Ware45520892015-05-13 01:22:32 -0500321
322static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300323msvcrt_putch(PyObject *module, PyObject *arg)
Zachary Ware45520892015-05-13 01:22:32 -0500324{
325 PyObject *return_value = NULL;
326 char char_value;
327
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200328 if (PyBytes_Check(arg) && PyBytes_GET_SIZE(arg) == 1) {
329 char_value = PyBytes_AS_STRING(arg)[0];
330 }
331 else if (PyByteArray_Check(arg) && PyByteArray_GET_SIZE(arg) == 1) {
332 char_value = PyByteArray_AS_STRING(arg)[0];
333 }
334 else {
335 _PyArg_BadArgument("putch", "a byte string of length 1", arg);
Zachary Ware45520892015-05-13 01:22:32 -0500336 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300337 }
Zachary Ware45520892015-05-13 01:22:32 -0500338 return_value = msvcrt_putch_impl(module, char_value);
339
340exit:
341 return return_value;
342}
343
Zachary Ware45520892015-05-13 01:22:32 -0500344PyDoc_STRVAR(msvcrt_putwch__doc__,
345"putwch($module, unicode_char, /)\n"
346"--\n"
347"\n"
348"Wide char variant of putch(), accepting a Unicode value.");
349
350#define MSVCRT_PUTWCH_METHODDEF \
351 {"putwch", (PyCFunction)msvcrt_putwch, METH_O, msvcrt_putwch__doc__},
352
353static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300354msvcrt_putwch_impl(PyObject *module, int unicode_char);
Zachary Ware45520892015-05-13 01:22:32 -0500355
356static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300357msvcrt_putwch(PyObject *module, PyObject *arg)
Zachary Ware45520892015-05-13 01:22:32 -0500358{
359 PyObject *return_value = NULL;
360 int unicode_char;
361
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200362 if (!PyUnicode_Check(arg)) {
363 _PyArg_BadArgument("putwch", "a unicode character", arg);
Zachary Ware45520892015-05-13 01:22:32 -0500364 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300365 }
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200366 if (PyUnicode_READY(arg)) {
367 goto exit;
368 }
369 if (PyUnicode_GET_LENGTH(arg) != 1) {
370 _PyArg_BadArgument("putwch", "a unicode character", arg);
371 goto exit;
372 }
373 unicode_char = PyUnicode_READ_CHAR(arg, 0);
Zachary Ware45520892015-05-13 01:22:32 -0500374 return_value = msvcrt_putwch_impl(module, unicode_char);
375
376exit:
377 return return_value;
378}
379
Zachary Ware45520892015-05-13 01:22:32 -0500380PyDoc_STRVAR(msvcrt_ungetch__doc__,
381"ungetch($module, char, /)\n"
382"--\n"
383"\n"
384"Opposite of getch.\n"
385"\n"
386"Cause the byte string char to be \"pushed back\" into the\n"
387"console buffer; it will be the next character read by\n"
388"getch() or getche().");
389
390#define MSVCRT_UNGETCH_METHODDEF \
391 {"ungetch", (PyCFunction)msvcrt_ungetch, METH_O, msvcrt_ungetch__doc__},
392
393static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300394msvcrt_ungetch_impl(PyObject *module, char char_value);
Zachary Ware45520892015-05-13 01:22:32 -0500395
396static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300397msvcrt_ungetch(PyObject *module, PyObject *arg)
Zachary Ware45520892015-05-13 01:22:32 -0500398{
399 PyObject *return_value = NULL;
400 char char_value;
401
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200402 if (PyBytes_Check(arg) && PyBytes_GET_SIZE(arg) == 1) {
403 char_value = PyBytes_AS_STRING(arg)[0];
404 }
405 else if (PyByteArray_Check(arg) && PyByteArray_GET_SIZE(arg) == 1) {
406 char_value = PyByteArray_AS_STRING(arg)[0];
407 }
408 else {
409 _PyArg_BadArgument("ungetch", "a byte string of length 1", arg);
Zachary Ware45520892015-05-13 01:22:32 -0500410 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300411 }
Zachary Ware45520892015-05-13 01:22:32 -0500412 return_value = msvcrt_ungetch_impl(module, char_value);
413
414exit:
415 return return_value;
416}
417
Zachary Ware45520892015-05-13 01:22:32 -0500418PyDoc_STRVAR(msvcrt_ungetwch__doc__,
419"ungetwch($module, unicode_char, /)\n"
420"--\n"
421"\n"
422"Wide char variant of ungetch(), accepting a Unicode value.");
423
424#define MSVCRT_UNGETWCH_METHODDEF \
425 {"ungetwch", (PyCFunction)msvcrt_ungetwch, METH_O, msvcrt_ungetwch__doc__},
426
427static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300428msvcrt_ungetwch_impl(PyObject *module, int unicode_char);
Zachary Ware45520892015-05-13 01:22:32 -0500429
430static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300431msvcrt_ungetwch(PyObject *module, PyObject *arg)
Zachary Ware45520892015-05-13 01:22:32 -0500432{
433 PyObject *return_value = NULL;
434 int unicode_char;
435
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200436 if (!PyUnicode_Check(arg)) {
437 _PyArg_BadArgument("ungetwch", "a unicode character", arg);
Zachary Ware45520892015-05-13 01:22:32 -0500438 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300439 }
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200440 if (PyUnicode_READY(arg)) {
441 goto exit;
442 }
443 if (PyUnicode_GET_LENGTH(arg) != 1) {
444 _PyArg_BadArgument("ungetwch", "a unicode character", arg);
445 goto exit;
446 }
447 unicode_char = PyUnicode_READ_CHAR(arg, 0);
Zachary Ware45520892015-05-13 01:22:32 -0500448 return_value = msvcrt_ungetwch_impl(module, unicode_char);
449
450exit:
451 return return_value;
452}
453
Zachary Ware45520892015-05-13 01:22:32 -0500454#if defined(_DEBUG)
455
456PyDoc_STRVAR(msvcrt_CrtSetReportFile__doc__,
457"CrtSetReportFile($module, type, file, /)\n"
458"--\n"
459"\n"
460"Wrapper around _CrtSetReportFile.\n"
461"\n"
462"Only available on Debug builds.");
463
464#define MSVCRT_CRTSETREPORTFILE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200465 {"CrtSetReportFile", (PyCFunction)(void(*)(void))msvcrt_CrtSetReportFile, METH_FASTCALL, msvcrt_CrtSetReportFile__doc__},
Zachary Ware45520892015-05-13 01:22:32 -0500466
Segev Finer679b5662017-07-27 01:17:57 +0300467static void *
468msvcrt_CrtSetReportFile_impl(PyObject *module, int type, void *file);
Zachary Ware45520892015-05-13 01:22:32 -0500469
470static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200471msvcrt_CrtSetReportFile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Ware45520892015-05-13 01:22:32 -0500472{
473 PyObject *return_value = NULL;
474 int type;
Segev Finer679b5662017-07-27 01:17:57 +0300475 void *file;
476 void *_return_value;
Zachary Ware45520892015-05-13 01:22:32 -0500477
Segev Finera80e9852017-07-27 06:15:18 +0300478 if (!_PyArg_ParseStack(args, nargs, "i"_Py_PARSE_UINTPTR":CrtSetReportFile",
Sylvain74453812017-06-10 06:51:48 +0200479 &type, &file)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100480 goto exit;
481 }
Zachary Ware45520892015-05-13 01:22:32 -0500482 _return_value = msvcrt_CrtSetReportFile_impl(module, type, file);
Segev Finer679b5662017-07-27 01:17:57 +0300483 if ((_return_value == NULL || _return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
Zachary Ware45520892015-05-13 01:22:32 -0500484 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300485 }
Segev Finer679b5662017-07-27 01:17:57 +0300486 return_value = PyLong_FromVoidPtr(_return_value);
Zachary Ware45520892015-05-13 01:22:32 -0500487
488exit:
489 return return_value;
490}
491
492#endif /* defined(_DEBUG) */
493
494#if defined(_DEBUG)
495
496PyDoc_STRVAR(msvcrt_CrtSetReportMode__doc__,
497"CrtSetReportMode($module, type, mode, /)\n"
498"--\n"
499"\n"
500"Wrapper around _CrtSetReportMode.\n"
501"\n"
502"Only available on Debug builds.");
503
504#define MSVCRT_CRTSETREPORTMODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200505 {"CrtSetReportMode", (PyCFunction)(void(*)(void))msvcrt_CrtSetReportMode, METH_FASTCALL, msvcrt_CrtSetReportMode__doc__},
Zachary Ware45520892015-05-13 01:22:32 -0500506
507static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300508msvcrt_CrtSetReportMode_impl(PyObject *module, int type, int mode);
Zachary Ware45520892015-05-13 01:22:32 -0500509
510static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200511msvcrt_CrtSetReportMode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Zachary Ware45520892015-05-13 01:22:32 -0500512{
513 PyObject *return_value = NULL;
514 int type;
515 int mode;
516 long _return_value;
517
Sylvain74453812017-06-10 06:51:48 +0200518 if (!_PyArg_ParseStack(args, nargs, "ii:CrtSetReportMode",
519 &type, &mode)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100520 goto exit;
521 }
Zachary Ware45520892015-05-13 01:22:32 -0500522 _return_value = msvcrt_CrtSetReportMode_impl(module, type, mode);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300523 if ((_return_value == -1) && PyErr_Occurred()) {
Zachary Ware45520892015-05-13 01:22:32 -0500524 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300525 }
Zachary Ware45520892015-05-13 01:22:32 -0500526 return_value = PyLong_FromLong(_return_value);
527
528exit:
529 return return_value;
530}
531
532#endif /* defined(_DEBUG) */
533
534#if defined(_DEBUG)
535
536PyDoc_STRVAR(msvcrt_set_error_mode__doc__,
537"set_error_mode($module, mode, /)\n"
538"--\n"
539"\n"
540"Wrapper around _set_error_mode.\n"
541"\n"
542"Only available on Debug builds.");
543
544#define MSVCRT_SET_ERROR_MODE_METHODDEF \
545 {"set_error_mode", (PyCFunction)msvcrt_set_error_mode, METH_O, msvcrt_set_error_mode__doc__},
546
547static long
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300548msvcrt_set_error_mode_impl(PyObject *module, int mode);
Zachary Ware45520892015-05-13 01:22:32 -0500549
550static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300551msvcrt_set_error_mode(PyObject *module, PyObject *arg)
Zachary Ware45520892015-05-13 01:22:32 -0500552{
553 PyObject *return_value = NULL;
554 int mode;
555 long _return_value;
556
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200557 if (PyFloat_Check(arg)) {
558 PyErr_SetString(PyExc_TypeError,
559 "integer argument expected, got float" );
560 goto exit;
561 }
562 mode = _PyLong_AsInt(arg);
563 if (mode == -1 && PyErr_Occurred()) {
Zachary Ware45520892015-05-13 01:22:32 -0500564 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300565 }
Zachary Ware45520892015-05-13 01:22:32 -0500566 _return_value = msvcrt_set_error_mode_impl(module, mode);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300567 if ((_return_value == -1) && PyErr_Occurred()) {
Zachary Ware45520892015-05-13 01:22:32 -0500568 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300569 }
Zachary Ware45520892015-05-13 01:22:32 -0500570 return_value = PyLong_FromLong(_return_value);
571
572exit:
573 return return_value;
574}
575
576#endif /* defined(_DEBUG) */
577
578PyDoc_STRVAR(msvcrt_SetErrorMode__doc__,
579"SetErrorMode($module, mode, /)\n"
580"--\n"
581"\n"
582"Wrapper around SetErrorMode.");
583
584#define MSVCRT_SETERRORMODE_METHODDEF \
585 {"SetErrorMode", (PyCFunction)msvcrt_SetErrorMode, METH_O, msvcrt_SetErrorMode__doc__},
586
587static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300588msvcrt_SetErrorMode_impl(PyObject *module, unsigned int mode);
Zachary Ware45520892015-05-13 01:22:32 -0500589
590static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300591msvcrt_SetErrorMode(PyObject *module, PyObject *arg)
Zachary Ware45520892015-05-13 01:22:32 -0500592{
593 PyObject *return_value = NULL;
594 unsigned int mode;
595
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200596 if (PyFloat_Check(arg)) {
597 PyErr_SetString(PyExc_TypeError,
598 "integer argument expected, got float" );
599 goto exit;
600 }
601 mode = (unsigned int)PyLong_AsUnsignedLongMask(arg);
602 if (mode == (unsigned int)-1 && PyErr_Occurred()) {
Zachary Ware45520892015-05-13 01:22:32 -0500603 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300604 }
Zachary Ware45520892015-05-13 01:22:32 -0500605 return_value = msvcrt_SetErrorMode_impl(module, mode);
606
607exit:
608 return return_value;
609}
610
Zachary Ware45520892015-05-13 01:22:32 -0500611#ifndef MSVCRT_CRTSETREPORTFILE_METHODDEF
612 #define MSVCRT_CRTSETREPORTFILE_METHODDEF
613#endif /* !defined(MSVCRT_CRTSETREPORTFILE_METHODDEF) */
614
615#ifndef MSVCRT_CRTSETREPORTMODE_METHODDEF
616 #define MSVCRT_CRTSETREPORTMODE_METHODDEF
617#endif /* !defined(MSVCRT_CRTSETREPORTMODE_METHODDEF) */
618
619#ifndef MSVCRT_SET_ERROR_MODE_METHODDEF
620 #define MSVCRT_SET_ERROR_MODE_METHODDEF
621#endif /* !defined(MSVCRT_SET_ERROR_MODE_METHODDEF) */
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200622/*[clinic end generated code: output=2530b4ff248563b4 input=a9049054013a1b77]*/