gh-74481: Add missing debug function docs and constants to msvcrt (GH-109650)

This commit is contained in:
AN Long 2023-09-21 23:44:24 +08:00 committed by GitHub
parent d4cea794a7
commit 869f177b5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 107 additions and 13 deletions

View File

@ -159,3 +159,92 @@ Other Functions
Force the :c:func:`malloc` heap to clean itself up and return unused blocks to
the operating system. On failure, this raises :exc:`OSError`.
.. function:: set_error_mode(mode)
Changes the location where the C runtime writes an error message for an error
that might end the program. *mode* must be one of the :const:`!OUT_\*`
constants listed below or :const:`REPORT_ERRMODE`. Returns the old setting
or -1 if an error occurs. Only available in
:ref:`debug build of Python <debug-build>`.
.. data:: OUT_TO_DEFAULT
Error sink is determined by the app's type. Only available in
:ref:`debug build of Python <debug-build>`.
.. data:: OUT_TO_STDERR
Error sink is a standard error. Only available in
:ref:`debug build of Python <debug-build>`.
.. data:: OUT_TO_MSGBOX
Error sink is a message box. Only available in
:ref:`debug build of Python <debug-build>`.
.. data:: REPORT_ERRMODE
Report the current error mode value. Only available in
:ref:`debug build of Python <debug-build>`.
.. function:: CrtSetReportMode(type, mode)
Specifies the destination or destinations for a specific report type
generated by :c:func:`!_CrtDbgReport` in the MS VC++ runtime. *type* must be
one of the :const:`!CRT_\*` constants listed below. *mode* must be one of the
:const:`!CRTDBG_\*` constants listed below. Only available in
:ref:`debug build of Python <debug-build>`.
.. function:: CrtSetReportFile(type, file)
After you use :func:`CrtSetReportMode` to specify :const:`CRTDBG_MODE_FILE`,
you can specify the file handle to receive the message text. *type* must be
one of the :const:`!CRT_\*` constants listed below. *file* shuld be the file
handle your want specified. Only available in
:ref:`debug build of Python <debug-build>`.
.. data:: CRT_WARN
Warnings, messages, and information that doesn't need immediate attention.
.. data:: CRT_ERROR
Errors, unrecoverable problems, and issues that require immediate attention.
.. data:: CRT_ASSERT
Assertion failures.
.. data:: CRTDBG_MODE_DEBUG
Writes the message to the debugger's output window.
.. data:: CRTDBG_MODE_FILE
Writes the message to a user-supplied file handle. :func:`CrtSetReportFile`
should be called to define the specific file or stream to use as
the destination.
.. data:: CRTDBG_MODE_WNDW
Creates a message box to display the message along with the ``Abort``,
``Retry``, and ``Ignore`` buttons.
.. data:: CRTDBG_REPORT_MODE
Returns current *mode* for the specified *type*.

View File

@ -0,0 +1 @@
Add ``set_error_mode`` related constants in ``msvcrt`` module in Python debug build.

View File

@ -615,6 +615,10 @@ exec_module(PyObject* m)
INSERTPTR(m, "CRTDBG_FILE_STDERR", _CRTDBG_FILE_STDERR);
INSERTPTR(m, "CRTDBG_FILE_STDOUT", _CRTDBG_FILE_STDOUT);
INSERTPTR(m, "CRTDBG_REPORT_FILE", _CRTDBG_REPORT_FILE);
INSERTINT(m, "OUT_TO_DEFAULT", _OUT_TO_DEFAULT);
INSERTINT(m, "OUT_TO_STDERR", _OUT_TO_STDERR);
INSERTINT(m, "OUT_TO_MSGBOX", _OUT_TO_MSGBOX);
INSERTINT(m, "REPORT_ERRMODE", _REPORT_ERRMODE);
#endif
#undef INSERTINT