Skip to content

Commit 3dc33d1

Browse files
committed
Revert 57722. Move error dialog APIs to msvcrt instead,
add -n option to regrtest, and use it on the buildbot.
1 parent 39cf04b commit 3dc33d1

4 files changed

Lines changed: 97 additions & 23 deletions

File tree

‎Lib/test/regrtest.py‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
-L: runleaks -- run the leaks(1) command just before exit
2929
-R: huntrleaks -- search for reference leaks (needs debug build, v. slow)
3030
-M: memlimit -- run very large memory-consuming tests
31+
-n: nowindows -- suppress error message boxes on Windows
3132
3233
If non-option arguments are present, they are names for tests to run,
3334
unless -x is given, in which case they are names for tests not to run.
@@ -210,13 +211,13 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False,
210211

211212
test_support.record_original_stdout(sys.stdout)
212213
try:
213-
opts, args = getopt.getopt(sys.argv[1:], 'dhvgqxsS:rf:lu:t:TD:NLR:wM:',
214+
opts, args = getopt.getopt(sys.argv[1:], 'dhvgqxsS:rf:lu:t:TD:NLR:wM:n',
214215
['help', 'verbose', 'quiet', 'generate',
215216
'exclude', 'single', 'random', 'fromfile',
216217
'findleaks', 'use=', 'threshold=', 'trace',
217218
'coverdir=', 'nocoverdir', 'runleaks',
218219
'huntrleaks=', 'verbose2', 'memlimit=',
219-
'debug', 'start='
220+
'debug', 'start=', "nowindows"
220221
])
221222
except getopt.error as msg:
222223
usage(msg)
@@ -296,6 +297,21 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False,
296297
use_resources.remove(r)
297298
elif r not in use_resources:
298299
use_resources.append(r)
300+
elif o in ('-n', '--nowindows'):
301+
import msvcrt
302+
msvcrt.SetErrorMode(msvcrt.SEM_FAILCRITICALERRORS|
303+
msvcrt.SEM_NOALIGNMENTFAULTEXCEPT|
304+
msvcrt.SEM_NOGPFAULTERRORBOX|
305+
msvcrt.SEM_NOOPENFILEERRORBOX)
306+
try:
307+
msvcrt.CrtSetReportMode
308+
except AttributeError:
309+
# release build
310+
pass
311+
else:
312+
for m in [msvcrt.CRT_WARN, msvcrt.CRT_ERROR, msvcrt.CRT_ASSERT]:
313+
msvcrt.CrtSetReportMode(m, msvcrt.CRTDBG_MODE_FILE)
314+
msvcrt.CrtSetReportFile(m, msvcrt.CRTDBG_FILE_STDERR)
299315
if generate and verbose:
300316
usage("-g and -v don't go together!")
301317
if single and fromfile:

‎Modules/main.c‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -328,25 +328,6 @@ Py_Main(int argc, char **argv)
328328
(p = Py_GETENV("PYTHONUNBUFFERED")) && *p != '\0')
329329
unbuffered = 1;
330330

331-
#ifdef MS_WINDOWS
332-
if ((p = Py_GETENV("PYTHONNOERRORWINDOW")) && *p != '\0') {
333-
/* Disable all error windows created by the sytem
334-
or the CRT. */
335-
#if defined(_DEBUG) && defined(_MSC_VER)
336-
int types[] = {_CRT_WARN, _CRT_ERROR, _CRT_ASSERT};
337-
int i;
338-
for (i = 0; i < sizeof(types)/sizeof(types[0]); i++) {
339-
_CrtSetReportFile(types[i], _CRTDBG_FILE_STDERR);
340-
_CrtSetReportMode(types[i], _CRTDBG_MODE_FILE);
341-
}
342-
_set_error_mode(_OUT_TO_STDERR);
343-
#endif
344-
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT |
345-
SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
346-
}
347-
#endif
348-
349-
350331
if (command == NULL && module == NULL && _PyOS_optind < argc &&
351332
strcmp(argv[_PyOS_optind], "-") != 0)
352333
{

‎PC/msvcrtmodule.c‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <io.h>
2222
#include <conio.h>
2323
#include <sys/locking.h>
24+
#include <crtdbg.h>
25+
#include <windows.h>
2426

2527
// Force the malloc heap to clean itself up, and free unused blocks
2628
// back to the OS. (According to the docs, only works on NT.)
@@ -201,6 +203,60 @@ insertint(PyObject *d, char *name, int value)
201203
}
202204
}
203205

206+
#ifdef _DEBUG
207+
208+
static PyObject*
209+
msvcrt_setreportfile(PyObject *self, PyObject *args)
210+
{
211+
int type, file;
212+
_HFILE res;
213+
214+
if (!PyArg_ParseTuple(args, "ii", &type, &file))
215+
return NULL;
216+
res = _CrtSetReportFile(type, (_HFILE)file);
217+
return PyInt_FromLong((long)res);
218+
Py_INCREF(Py_None);
219+
return Py_None;
220+
}
221+
222+
static PyObject*
223+
msvcrt_setreportmode(PyObject *self, PyObject *args)
224+
{
225+
int type, mode;
226+
int res;
227+
228+
if (!PyArg_ParseTuple(args, "ii", &type, &mode))
229+
return NULL;
230+
res = _CrtSetReportMode(type, mode);
231+
if (res == -1)
232+
return PyErr_SetFromErrno(PyExc_IOError);
233+
return PyLong_FromLong(res);
234+
}
235+
236+
static PyObject*
237+
msvcrt_seterrormode(PyObject *self, PyObject *args)
238+
{
239+
int mode, res;
240+
241+
if (!PyArg_ParseTuple(args, "i", &mode))
242+
return NULL;
243+
res = _set_error_mode(mode);
244+
return PyLong_FromLong(res);
245+
}
246+
247+
#endif
248+
249+
static PyObject*
250+
seterrormode(PyObject *self, PyObject *args)
251+
{
252+
unsigned int mode, res;
253+
254+
if (!PyArg_ParseTuple(args, "I", &mode))
255+
return NULL;
256+
res = SetErrorMode(mode);
257+
return PyLong_FromUnsignedLong(res);
258+
}
259+
204260

205261
/* List of functions exported by this module */
206262
static struct PyMethodDef msvcrt_functions[] = {
@@ -214,6 +270,12 @@ static struct PyMethodDef msvcrt_functions[] = {
214270
{"getche", msvcrt_getche, METH_VARARGS},
215271
{"putch", msvcrt_putch, METH_VARARGS},
216272
{"ungetch", msvcrt_ungetch, METH_VARARGS},
273+
{"SetErrorMode", seterrormode, METH_VARARGS},
274+
#ifdef _DEBUG
275+
{"CrtSetReportFile", msvcrt_setreportfile, METH_VARARGS},
276+
{"CrtSetReportMode", msvcrt_setreportmode, METH_VARARGS},
277+
{"set_error_mode", msvcrt_seterrormode, METH_VARARGS},
278+
#endif
217279
{NULL, NULL}
218280
};
219281

@@ -232,4 +294,20 @@ initmsvcrt(void)
232294
insertint(d, "LK_NBRLCK", _LK_NBRLCK);
233295
insertint(d, "LK_RLCK", _LK_RLCK);
234296
insertint(d, "LK_UNLCK", _LK_UNLCK);
297+
insertint(d, "SEM_FAILCRITICALERRORS", SEM_FAILCRITICALERRORS);
298+
insertint(d, "SEM_NOALIGNMENTFAULTEXCEPT", SEM_NOALIGNMENTFAULTEXCEPT);
299+
insertint(d, "SEM_NOGPFAULTERRORBOX", SEM_NOGPFAULTERRORBOX);
300+
insertint(d, "SEM_NOOPENFILEERRORBOX", SEM_NOOPENFILEERRORBOX);
301+
#ifdef _DEBUG
302+
insertint(d, "CRT_WARN", _CRT_WARN);
303+
insertint(d, "CRT_ERROR", _CRT_ERROR);
304+
insertint(d, "CRT_ASSERT", _CRT_ASSERT);
305+
insertint(d, "CRTDBG_MODE_DEBUG", _CRTDBG_MODE_DEBUG);
306+
insertint(d, "CRTDBG_MODE_FILE", _CRTDBG_MODE_FILE);
307+
insertint(d, "CRTDBG_MODE_WNDW", _CRTDBG_MODE_WNDW);
308+
insertint(d, "CRTDBG_REPORT_MODE", _CRTDBG_REPORT_MODE);
309+
insertint(d, "CRTDBG_FILE_STDERR", (int)_CRTDBG_FILE_STDERR);
310+
insertint(d, "CRTDBG_FILE_STDOUT", (int)_CRTDBG_FILE_STDOUT);
311+
insertint(d, "CRTDBG_REPORT_FILE", (int)_CRTDBG_REPORT_FILE);
312+
#endif
235313
}

‎Tools/buildbot/test.bat‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
@rem Used by the buildbot "test" step.
22
cd PCbuild
3-
set PYTHONNOERRORWINDOW=1
4-
call rt.bat -d -q -uall -rw
3+
call rt.bat -d -q -uall -rw -n

0 commit comments

Comments
 (0)