summaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/PC
diff options
context:
space:
mode:
authorthegeorg <[email protected]>2024-02-19 02:38:52 +0300
committerthegeorg <[email protected]>2024-02-19 02:50:43 +0300
commitd96fa07134c06472bfee6718b5cfd1679196fc99 (patch)
tree31ec344fa9d3ff8dc038692516b6438dfbdb8a2d /contrib/tools/python3/PC
parent452cf9e068aef7110e35e654c5d47eb80111ef89 (diff)
Sync contrib/tools/python3 layout with upstream
* Move src/ subdir contents to the top of the layout * Rename self-written lib -> lib2 to avoid CaseFolding warning from the VCS * Regenerate contrib/libs/python proxy-headers accordingly 4ccc62ac1511abcf0fed14ccade38e984e088f1e
Diffstat (limited to 'contrib/tools/python3/PC')
-rw-r--r--contrib/tools/python3/PC/WinMain.c17
-rw-r--r--contrib/tools/python3/PC/clinic/msvcrtmodule.c.h710
-rw-r--r--contrib/tools/python3/PC/clinic/winreg.c.h1798
-rw-r--r--contrib/tools/python3/PC/clinic/winsound.c.h209
-rw-r--r--contrib/tools/python3/PC/errmap.h140
-rw-r--r--contrib/tools/python3/PC/invalid_parameter_handler.c22
-rw-r--r--contrib/tools/python3/PC/msvcrtmodule.c679
-rw-r--r--contrib/tools/python3/PC/pyconfig.h740
-rw-r--r--contrib/tools/python3/PC/winreg.c2223
-rw-r--r--contrib/tools/python3/PC/winsound.c254
10 files changed, 6792 insertions, 0 deletions
diff --git a/contrib/tools/python3/PC/WinMain.c b/contrib/tools/python3/PC/WinMain.c
new file mode 100644
index 00000000000..07e21ce3e9f
--- /dev/null
+++ b/contrib/tools/python3/PC/WinMain.c
@@ -0,0 +1,17 @@
+/* Minimal main program -- everything is loaded from the library. */
+
+#include "Python.h"
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <stdlib.h> /* __argc, __wargv */
+
+int WINAPI wWinMain(
+ HINSTANCE hInstance, /* handle to current instance */
+ HINSTANCE hPrevInstance, /* handle to previous instance */
+ LPWSTR lpCmdLine, /* pointer to command line */
+ int nCmdShow /* show state of window */
+)
+{
+ return Py_Main(__argc, __wargv);
+}
diff --git a/contrib/tools/python3/PC/clinic/msvcrtmodule.c.h b/contrib/tools/python3/PC/clinic/msvcrtmodule.c.h
new file mode 100644
index 00000000000..b708c6cdde7
--- /dev/null
+++ b/contrib/tools/python3/PC/clinic/msvcrtmodule.c.h
@@ -0,0 +1,710 @@
+/*[clinic input]
+preserve
+[clinic start generated code]*/
+
+#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
+#endif
+
+
+PyDoc_STRVAR(msvcrt_heapmin__doc__,
+"heapmin($module, /)\n"
+"--\n"
+"\n"
+"Minimize the malloc() heap.\n"
+"\n"
+"Force the malloc() heap to clean itself up and return unused blocks\n"
+"to the operating system. On failure, this raises OSError.");
+
+#define MSVCRT_HEAPMIN_METHODDEF \
+ {"heapmin", (PyCFunction)msvcrt_heapmin, METH_NOARGS, msvcrt_heapmin__doc__},
+
+static PyObject *
+msvcrt_heapmin_impl(PyObject *module);
+
+static PyObject *
+msvcrt_heapmin(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+ return msvcrt_heapmin_impl(module);
+}
+
+PyDoc_STRVAR(msvcrt_locking__doc__,
+"locking($module, fd, mode, nbytes, /)\n"
+"--\n"
+"\n"
+"Lock part of a file based on file descriptor fd from the C runtime.\n"
+"\n"
+"Raises OSError on failure. The locked region of the file extends from\n"
+"the current file position for nbytes bytes, and may continue beyond\n"
+"the end of the file. mode must be one of the LK_* constants listed\n"
+"below. Multiple regions in a file may be locked at the same time, but\n"
+"may not overlap. Adjacent regions are not merged; they must be unlocked\n"
+"individually.");
+
+#define MSVCRT_LOCKING_METHODDEF \
+ {"locking", _PyCFunction_CAST(msvcrt_locking), METH_FASTCALL, msvcrt_locking__doc__},
+
+static PyObject *
+msvcrt_locking_impl(PyObject *module, int fd, int mode, long nbytes);
+
+static PyObject *
+msvcrt_locking(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ int fd;
+ int mode;
+ long nbytes;
+
+ if (!_PyArg_CheckPositional("locking", nargs, 3, 3)) {
+ goto exit;
+ }
+ fd = _PyLong_AsInt(args[0]);
+ if (fd == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ mode = _PyLong_AsInt(args[1]);
+ if (mode == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ nbytes = PyLong_AsLong(args[2]);
+ if (nbytes == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ return_value = msvcrt_locking_impl(module, fd, mode, nbytes);
+
+exit:
+ return return_value;
+}
+
+PyDoc_STRVAR(msvcrt_setmode__doc__,
+"setmode($module, fd, mode, /)\n"
+"--\n"
+"\n"
+"Set the line-end translation mode for the file descriptor fd.\n"
+"\n"
+"To set it to text mode, flags should be os.O_TEXT; for binary, it\n"
+"should be os.O_BINARY.\n"
+"\n"
+"Return value is the previous mode.");
+
+#define MSVCRT_SETMODE_METHODDEF \
+ {"setmode", _PyCFunction_CAST(msvcrt_setmode), METH_FASTCALL, msvcrt_setmode__doc__},
+
+static long
+msvcrt_setmode_impl(PyObject *module, int fd, int flags);
+
+static PyObject *
+msvcrt_setmode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ int fd;
+ int flags;
+ long _return_value;
+
+ if (!_PyArg_CheckPositional("setmode", nargs, 2, 2)) {
+ goto exit;
+ }
+ fd = _PyLong_AsInt(args[0]);
+ if (fd == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ flags = _PyLong_AsInt(args[1]);
+ if (flags == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ _return_value = msvcrt_setmode_impl(module, fd, flags);
+ if ((_return_value == -1) && PyErr_Occurred()) {
+ goto exit;
+ }
+ return_value = PyLong_FromLong(_return_value);
+
+exit:
+ return return_value;
+}
+
+PyDoc_STRVAR(msvcrt_open_osfhandle__doc__,
+"open_osfhandle($module, handle, flags, /)\n"
+"--\n"
+"\n"
+"Create a C runtime file descriptor from the file handle handle.\n"
+"\n"
+"The flags parameter should be a bitwise OR of os.O_APPEND, os.O_RDONLY,\n"
+"and os.O_TEXT. The returned file descriptor may be used as a parameter\n"
+"to os.fdopen() to create a file object.");
+
+#define MSVCRT_OPEN_OSFHANDLE_METHODDEF \
+ {"open_osfhandle", _PyCFunction_CAST(msvcrt_open_osfhandle), METH_FASTCALL, msvcrt_open_osfhandle__doc__},
+
+static long
+msvcrt_open_osfhandle_impl(PyObject *module, void *handle, int flags);
+
+static PyObject *
+msvcrt_open_osfhandle(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ void *handle;
+ int flags;
+ long _return_value;
+
+ if (!_PyArg_CheckPositional("open_osfhandle", nargs, 2, 2)) {
+ goto exit;
+ }
+ handle = PyLong_AsVoidPtr(args[0]);
+ if (!handle && PyErr_Occurred()) {
+ goto exit;
+ }
+ flags = _PyLong_AsInt(args[1]);
+ if (flags == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ _return_value = msvcrt_open_osfhandle_impl(module, handle, flags);
+ if ((_return_value == -1) && PyErr_Occurred()) {
+ goto exit;
+ }
+ return_value = PyLong_FromLong(_return_value);
+
+exit:
+ return return_value;
+}
+
+PyDoc_STRVAR(msvcrt_get_osfhandle__doc__,
+"get_osfhandle($module, fd, /)\n"
+"--\n"
+"\n"
+"Return the file handle for the file descriptor fd.\n"
+"\n"
+"Raises OSError if fd is not recognized.");
+
+#define MSVCRT_GET_OSFHANDLE_METHODDEF \
+ {"get_osfhandle", (PyCFunction)msvcrt_get_osfhandle, METH_O, msvcrt_get_osfhandle__doc__},
+
+static void *
+msvcrt_get_osfhandle_impl(PyObject *module, int fd);
+
+static PyObject *
+msvcrt_get_osfhandle(PyObject *module, PyObject *arg)
+{
+ PyObject *return_value = NULL;
+ int fd;
+ void *_return_value;
+
+ fd = _PyLong_AsInt(arg);
+ if (fd == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ _return_value = msvcrt_get_osfhandle_impl(module, fd);
+ if ((_return_value == NULL || _return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
+ goto exit;
+ }
+ return_value = PyLong_FromVoidPtr(_return_value);
+
+exit:
+ return return_value;
+}
+
+PyDoc_STRVAR(msvcrt_kbhit__doc__,
+"kbhit($module, /)\n"
+"--\n"
+"\n"
+"Return true if a keypress is waiting to be read.");
+
+#define MSVCRT_KBHIT_METHODDEF \
+ {"kbhit", (PyCFunction)msvcrt_kbhit, METH_NOARGS, msvcrt_kbhit__doc__},
+
+static long
+msvcrt_kbhit_impl(PyObject *module);
+
+static PyObject *
+msvcrt_kbhit(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+ PyObject *return_value = NULL;
+ long _return_value;
+
+ _return_value = msvcrt_kbhit_impl(module);
+ if ((_return_value == -1) && PyErr_Occurred()) {
+ goto exit;
+ }
+ return_value = PyLong_FromLong(_return_value);
+
+exit:
+ return return_value;
+}
+
+PyDoc_STRVAR(msvcrt_getch__doc__,
+"getch($module, /)\n"
+"--\n"
+"\n"
+"Read a keypress and return the resulting character as a byte string.\n"
+"\n"
+"Nothing is echoed to the console. This call will block if a keypress is\n"
+"not already available, but will not wait for Enter to be pressed. If the\n"
+"pressed key was a special function key, this will return \'\\000\' or\n"
+"\'\\xe0\'; the next call will return the keycode. The Control-C keypress\n"
+"cannot be read with this function.");
+
+#define MSVCRT_GETCH_METHODDEF \
+ {"getch", (PyCFunction)msvcrt_getch, METH_NOARGS, msvcrt_getch__doc__},
+
+static int
+msvcrt_getch_impl(PyObject *module);
+
+static PyObject *
+msvcrt_getch(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+ PyObject *return_value = NULL;
+ char s[1];
+
+ s[0] = msvcrt_getch_impl(module);
+ return_value = PyBytes_FromStringAndSize(s, 1);
+
+ return return_value;
+}
+
+#if defined(MS_WINDOWS_DESKTOP)
+
+PyDoc_STRVAR(msvcrt_getwch__doc__,
+"getwch($module, /)\n"
+"--\n"
+"\n"
+"Wide char variant of getch(), returning a Unicode value.");
+
+#define MSVCRT_GETWCH_METHODDEF \
+ {"getwch", (PyCFunction)msvcrt_getwch, METH_NOARGS, msvcrt_getwch__doc__},
+
+static wchar_t
+msvcrt_getwch_impl(PyObject *module);
+
+static PyObject *
+msvcrt_getwch(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+ PyObject *return_value = NULL;
+ wchar_t _return_value;
+
+ _return_value = msvcrt_getwch_impl(module);
+ return_value = PyUnicode_FromOrdinal(_return_value);
+
+ return return_value;
+}
+
+#endif /* defined(MS_WINDOWS_DESKTOP) */
+
+PyDoc_STRVAR(msvcrt_getche__doc__,
+"getche($module, /)\n"
+"--\n"
+"\n"
+"Similar to getch(), but the keypress will be echoed if possible.");
+
+#define MSVCRT_GETCHE_METHODDEF \
+ {"getche", (PyCFunction)msvcrt_getche, METH_NOARGS, msvcrt_getche__doc__},
+
+static int
+msvcrt_getche_impl(PyObject *module);
+
+static PyObject *
+msvcrt_getche(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+ PyObject *return_value = NULL;
+ char s[1];
+
+ s[0] = msvcrt_getche_impl(module);
+ return_value = PyBytes_FromStringAndSize(s, 1);
+
+ return return_value;
+}
+
+#if defined(MS_WINDOWS_DESKTOP)
+
+PyDoc_STRVAR(msvcrt_getwche__doc__,
+"getwche($module, /)\n"
+"--\n"
+"\n"
+"Wide char variant of getche(), returning a Unicode value.");
+
+#define MSVCRT_GETWCHE_METHODDEF \
+ {"getwche", (PyCFunction)msvcrt_getwche, METH_NOARGS, msvcrt_getwche__doc__},
+
+static wchar_t
+msvcrt_getwche_impl(PyObject *module);
+
+static PyObject *
+msvcrt_getwche(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+ PyObject *return_value = NULL;
+ wchar_t _return_value;
+
+ _return_value = msvcrt_getwche_impl(module);
+ return_value = PyUnicode_FromOrdinal(_return_value);
+
+ return return_value;
+}
+
+#endif /* defined(MS_WINDOWS_DESKTOP) */
+
+PyDoc_STRVAR(msvcrt_putch__doc__,
+"putch($module, char, /)\n"
+"--\n"
+"\n"
+"Print the byte string char to the console without buffering.");
+
+#define MSVCRT_PUTCH_METHODDEF \
+ {"putch", (PyCFunction)msvcrt_putch, METH_O, msvcrt_putch__doc__},
+
+static PyObject *
+msvcrt_putch_impl(PyObject *module, char char_value);
+
+static PyObject *
+msvcrt_putch(PyObject *module, PyObject *arg)
+{
+ PyObject *return_value = NULL;
+ char char_value;
+
+ if (PyBytes_Check(arg) && PyBytes_GET_SIZE(arg) == 1) {
+ char_value = PyBytes_AS_STRING(arg)[0];
+ }
+ else if (PyByteArray_Check(arg) && PyByteArray_GET_SIZE(arg) == 1) {
+ char_value = PyByteArray_AS_STRING(arg)[0];
+ }
+ else {
+ _PyArg_BadArgument("putch", "argument", "a byte string of length 1", arg);
+ goto exit;
+ }
+ return_value = msvcrt_putch_impl(module, char_value);
+
+exit:
+ return return_value;
+}
+
+#if defined(MS_WINDOWS_DESKTOP)
+
+PyDoc_STRVAR(msvcrt_putwch__doc__,
+"putwch($module, unicode_char, /)\n"
+"--\n"
+"\n"
+"Wide char variant of putch(), accepting a Unicode value.");
+
+#define MSVCRT_PUTWCH_METHODDEF \
+ {"putwch", (PyCFunction)msvcrt_putwch, METH_O, msvcrt_putwch__doc__},
+
+static PyObject *
+msvcrt_putwch_impl(PyObject *module, int unicode_char);
+
+static PyObject *
+msvcrt_putwch(PyObject *module, PyObject *arg)
+{
+ PyObject *return_value = NULL;
+ int unicode_char;
+
+ if (!PyUnicode_Check(arg)) {
+ _PyArg_BadArgument("putwch", "argument", "a unicode character", arg);
+ goto exit;
+ }
+ if (PyUnicode_READY(arg)) {
+ goto exit;
+ }
+ if (PyUnicode_GET_LENGTH(arg) != 1) {
+ _PyArg_BadArgument("putwch", "argument", "a unicode character", arg);
+ goto exit;
+ }
+ unicode_char = PyUnicode_READ_CHAR(arg, 0);
+ return_value = msvcrt_putwch_impl(module, unicode_char);
+
+exit:
+ return return_value;
+}
+
+#endif /* defined(MS_WINDOWS_DESKTOP) */
+
+PyDoc_STRVAR(msvcrt_ungetch__doc__,
+"ungetch($module, char, /)\n"
+"--\n"
+"\n"
+"Opposite of getch.\n"
+"\n"
+"Cause the byte string char to be \"pushed back\" into the\n"
+"console buffer; it will be the next character read by\n"
+"getch() or getche().");
+
+#define MSVCRT_UNGETCH_METHODDEF \
+ {"ungetch", (PyCFunction)msvcrt_ungetch, METH_O, msvcrt_ungetch__doc__},
+
+static PyObject *
+msvcrt_ungetch_impl(PyObject *module, char char_value);
+
+static PyObject *
+msvcrt_ungetch(PyObject *module, PyObject *arg)
+{
+ PyObject *return_value = NULL;
+ char char_value;
+
+ if (PyBytes_Check(arg) && PyBytes_GET_SIZE(arg) == 1) {
+ char_value = PyBytes_AS_STRING(arg)[0];
+ }
+ else if (PyByteArray_Check(arg) && PyByteArray_GET_SIZE(arg) == 1) {
+ char_value = PyByteArray_AS_STRING(arg)[0];
+ }
+ else {
+ _PyArg_BadArgument("ungetch", "argument", "a byte string of length 1", arg);
+ goto exit;
+ }
+ return_value = msvcrt_ungetch_impl(module, char_value);
+
+exit:
+ return return_value;
+}
+
+#if defined(MS_WINDOWS_DESKTOP)
+
+PyDoc_STRVAR(msvcrt_ungetwch__doc__,
+"ungetwch($module, unicode_char, /)\n"
+"--\n"
+"\n"
+"Wide char variant of ungetch(), accepting a Unicode value.");
+
+#define MSVCRT_UNGETWCH_METHODDEF \
+ {"ungetwch", (PyCFunction)msvcrt_ungetwch, METH_O, msvcrt_ungetwch__doc__},
+
+static PyObject *
+msvcrt_ungetwch_impl(PyObject *module, int unicode_char);
+
+static PyObject *
+msvcrt_ungetwch(PyObject *module, PyObject *arg)
+{
+ PyObject *return_value = NULL;
+ int unicode_char;
+
+ if (!PyUnicode_Check(arg)) {
+ _PyArg_BadArgument("ungetwch", "argument", "a unicode character", arg);
+ goto exit;
+ }
+ if (PyUnicode_READY(arg)) {
+ goto exit;
+ }
+ if (PyUnicode_GET_LENGTH(arg) != 1) {
+ _PyArg_BadArgument("ungetwch", "argument", "a unicode character", arg);
+ goto exit;
+ }
+ unicode_char = PyUnicode_READ_CHAR(arg, 0);
+ return_value = msvcrt_ungetwch_impl(module, unicode_char);
+
+exit:
+ return return_value;
+}
+
+#endif /* defined(MS_WINDOWS_DESKTOP) */
+
+#if defined(_DEBUG)
+
+PyDoc_STRVAR(msvcrt_CrtSetReportFile__doc__,
+"CrtSetReportFile($module, type, file, /)\n"
+"--\n"
+"\n"
+"Wrapper around _CrtSetReportFile.\n"
+"\n"
+"Only available on Debug builds.");
+
+#define MSVCRT_CRTSETREPORTFILE_METHODDEF \
+ {"CrtSetReportFile", _PyCFunction_CAST(msvcrt_CrtSetReportFile), METH_FASTCALL, msvcrt_CrtSetReportFile__doc__},
+
+static void *
+msvcrt_CrtSetReportFile_impl(PyObject *module, int type, void *file);
+
+static PyObject *
+msvcrt_CrtSetReportFile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ int type;
+ void *file;
+ void *_return_value;
+
+ if (!_PyArg_CheckPositional("CrtSetReportFile", nargs, 2, 2)) {
+ goto exit;
+ }
+ type = _PyLong_AsInt(args[0]);
+ if (type == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ file = PyLong_AsVoidPtr(args[1]);
+ if (!file && PyErr_Occurred()) {
+ goto exit;
+ }
+ _return_value = msvcrt_CrtSetReportFile_impl(module, type, file);
+ if ((_return_value == NULL || _return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) {
+ goto exit;
+ }
+ return_value = PyLong_FromVoidPtr(_return_value);
+
+exit:
+ return return_value;
+}
+
+#endif /* defined(_DEBUG) */
+
+#if defined(_DEBUG)
+
+PyDoc_STRVAR(msvcrt_CrtSetReportMode__doc__,
+"CrtSetReportMode($module, type, mode, /)\n"
+"--\n"
+"\n"
+"Wrapper around _CrtSetReportMode.\n"
+"\n"
+"Only available on Debug builds.");
+
+#define MSVCRT_CRTSETREPORTMODE_METHODDEF \
+ {"CrtSetReportMode", _PyCFunction_CAST(msvcrt_CrtSetReportMode), METH_FASTCALL, msvcrt_CrtSetReportMode__doc__},
+
+static long
+msvcrt_CrtSetReportMode_impl(PyObject *module, int type, int mode);
+
+static PyObject *
+msvcrt_CrtSetReportMode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ int type;
+ int mode;
+ long _return_value;
+
+ if (!_PyArg_CheckPositional("CrtSetReportMode", nargs, 2, 2)) {
+ goto exit;
+ }
+ type = _PyLong_AsInt(args[0]);
+ if (type == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ mode = _PyLong_AsInt(args[1]);
+ if (mode == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ _return_value = msvcrt_CrtSetReportMode_impl(module, type, mode);
+ if ((_return_value == -1) && PyErr_Occurred()) {
+ goto exit;
+ }
+ return_value = PyLong_FromLong(_return_value);
+
+exit:
+ return return_value;
+}
+
+#endif /* defined(_DEBUG) */
+
+#if defined(_DEBUG)
+
+PyDoc_STRVAR(msvcrt_set_error_mode__doc__,
+"set_error_mode($module, mode, /)\n"
+"--\n"
+"\n"
+"Wrapper around _set_error_mode.\n"
+"\n"
+"Only available on Debug builds.");
+
+#define MSVCRT_SET_ERROR_MODE_METHODDEF \
+ {"set_error_mode", (PyCFunction)msvcrt_set_error_mode, METH_O, msvcrt_set_error_mode__doc__},
+
+static long
+msvcrt_set_error_mode_impl(PyObject *module, int mode);
+
+static PyObject *
+msvcrt_set_error_mode(PyObject *module, PyObject *arg)
+{
+ PyObject *return_value = NULL;
+ int mode;
+ long _return_value;
+
+ mode = _PyLong_AsInt(arg);
+ if (mode == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ _return_value = msvcrt_set_error_mode_impl(module, mode);
+ if ((_return_value == -1) && PyErr_Occurred()) {
+ goto exit;
+ }
+ return_value = PyLong_FromLong(_return_value);
+
+exit:
+ return return_value;
+}
+
+#endif /* defined(_DEBUG) */
+
+#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM))
+
+PyDoc_STRVAR(msvcrt_GetErrorMode__doc__,
+"GetErrorMode($module, /)\n"
+"--\n"
+"\n"
+"Wrapper around GetErrorMode.");
+
+#define MSVCRT_GETERRORMODE_METHODDEF \
+ {"GetErrorMode", (PyCFunction)msvcrt_GetErrorMode, METH_NOARGS, msvcrt_GetErrorMode__doc__},
+
+static PyObject *
+msvcrt_GetErrorMode_impl(PyObject *module);
+
+static PyObject *
+msvcrt_GetErrorMode(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+ return msvcrt_GetErrorMode_impl(module);
+}
+
+#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */
+
+PyDoc_STRVAR(msvcrt_SetErrorMode__doc__,
+"SetErrorMode($module, mode, /)\n"
+"--\n"
+"\n"
+"Wrapper around SetErrorMode.");
+
+#define MSVCRT_SETERRORMODE_METHODDEF \
+ {"SetErrorMode", (PyCFunction)msvcrt_SetErrorMode, METH_O, msvcrt_SetErrorMode__doc__},
+
+static PyObject *
+msvcrt_SetErrorMode_impl(PyObject *module, unsigned int mode);
+
+static PyObject *
+msvcrt_SetErrorMode(PyObject *module, PyObject *arg)
+{
+ PyObject *return_value = NULL;
+ unsigned int mode;
+
+ mode = (unsigned int)PyLong_AsUnsignedLongMask(arg);
+ if (mode == (unsigned int)-1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ return_value = msvcrt_SetErrorMode_impl(module, mode);
+
+exit:
+ return return_value;
+}
+
+#ifndef MSVCRT_GETWCH_METHODDEF
+ #define MSVCRT_GETWCH_METHODDEF
+#endif /* !defined(MSVCRT_GETWCH_METHODDEF) */
+
+#ifndef MSVCRT_GETWCHE_METHODDEF
+ #define MSVCRT_GETWCHE_METHODDEF
+#endif /* !defined(MSVCRT_GETWCHE_METHODDEF) */
+
+#ifndef MSVCRT_PUTWCH_METHODDEF
+ #define MSVCRT_PUTWCH_METHODDEF
+#endif /* !defined(MSVCRT_PUTWCH_METHODDEF) */
+
+#ifndef MSVCRT_UNGETWCH_METHODDEF
+ #define MSVCRT_UNGETWCH_METHODDEF
+#endif /* !defined(MSVCRT_UNGETWCH_METHODDEF) */
+
+#ifndef MSVCRT_CRTSETREPORTFILE_METHODDEF
+ #define MSVCRT_CRTSETREPORTFILE_METHODDEF
+#endif /* !defined(MSVCRT_CRTSETREPORTFILE_METHODDEF) */
+
+#ifndef MSVCRT_CRTSETREPORTMODE_METHODDEF
+ #define MSVCRT_CRTSETREPORTMODE_METHODDEF
+#endif /* !defined(MSVCRT_CRTSETREPORTMODE_METHODDEF) */
+
+#ifndef MSVCRT_SET_ERROR_MODE_METHODDEF
+ #define MSVCRT_SET_ERROR_MODE_METHODDEF
+#endif /* !defined(MSVCRT_SET_ERROR_MODE_METHODDEF) */
+
+#ifndef MSVCRT_GETERRORMODE_METHODDEF
+ #define MSVCRT_GETERRORMODE_METHODDEF
+#endif /* !defined(MSVCRT_GETERRORMODE_METHODDEF) */
+/*[clinic end generated code: output=2db6197608a6aab3 input=a9049054013a1b77]*/
diff --git a/contrib/tools/python3/PC/clinic/winreg.c.h b/contrib/tools/python3/PC/clinic/winreg.c.h
new file mode 100644
index 00000000000..4109c85276f
--- /dev/null
+++ b/contrib/tools/python3/PC/clinic/winreg.c.h
@@ -0,0 +1,1798 @@
+/*[clinic input]
+preserve
+[clinic start generated code]*/
+
+#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
+#endif
+
+
+#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES))
+
+PyDoc_STRVAR(winreg_HKEYType_Close__doc__,
+"Close($self, /)\n"
+"--\n"
+"\n"
+"Closes the underlying Windows handle.\n"
+"\n"
+"If the handle is already closed, no error is raised.");
+
+#define WINREG_HKEYTYPE_CLOSE_METHODDEF \
+ {"Close", (PyCFunction)winreg_HKEYType_Close, METH_NOARGS, winreg_HKEYType_Close__doc__},
+
+static PyObject *
+winreg_HKEYType_Close_impl(PyHKEYObject *self);
+
+static PyObject *
+winreg_HKEYType_Close(PyHKEYObject *self, PyObject *Py_UNUSED(ignored))
+{
+ return winreg_HKEYType_Close_impl(self);
+}
+
+#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */
+
+#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES))
+
+PyDoc_STRVAR(winreg_HKEYType_Detach__doc__,
+"Detach($self, /)\n"
+"--\n"
+"\n"
+"Detaches the Windows handle from the handle object.\n"
+"\n"
+"The result is the value of the handle before it is detached. If the\n"
+"handle is already detached, this will return zero.\n"
+"\n"
+"After calling this function, the handle is effectively invalidated,\n"
+"but the handle is not closed. You would call this function when you\n"
+"need the underlying win32 handle to exist beyond the lifetime of the\n"
+"handle object.");
+
+#define WINREG_HKEYTYPE_DETACH_METHODDEF \
+ {"Detach", (PyCFunction)winreg_HKEYType_Detach, METH_NOARGS, winreg_HKEYType_Detach__doc__},
+
+static PyObject *
+winreg_HKEYType_Detach_impl(PyHKEYObject *self);
+
+static PyObject *
+winreg_HKEYType_Detach(PyHKEYObject *self, PyObject *Py_UNUSED(ignored))
+{
+ return winreg_HKEYType_Detach_impl(self);
+}
+
+#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */
+
+#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES))
+
+PyDoc_STRVAR(winreg_HKEYType___enter____doc__,
+"__enter__($self, /)\n"
+"--\n"
+"\n");
+
+#define WINREG_HKEYTYPE___ENTER___METHODDEF \
+ {"__enter__", (PyCFunction)winreg_HKEYType___enter__, METH_NOARGS, winreg_HKEYType___enter____doc__},
+
+static PyHKEYObject *
+winreg_HKEYType___enter___impl(PyHKEYObject *self);
+
+static PyObject *
+winreg_HKEYType___enter__(PyHKEYObject *self, PyObject *Py_UNUSED(ignored))
+{
+ PyObject *return_value = NULL;
+ PyHKEYObject *_return_value;
+
+ _return_value = winreg_HKEYType___enter___impl(self);
+ return_value = (PyObject *)_return_value;
+
+ return return_value;
+}
+
+#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */
+
+#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES))
+
+PyDoc_STRVAR(winreg_HKEYType___exit____doc__,
+"__exit__($self, /, exc_type, exc_value, traceback)\n"
+"--\n"
+"\n");
+
+#define WINREG_HKEYTYPE___EXIT___METHODDEF \
+ {"__exit__", _PyCFunction_CAST(winreg_HKEYType___exit__), METH_FASTCALL|METH_KEYWORDS, winreg_HKEYType___exit____doc__},
+
+static PyObject *
+winreg_HKEYType___exit___impl(PyHKEYObject *self, PyObject *exc_type,
+ PyObject *exc_value, PyObject *traceback);
+
+static PyObject *
+winreg_HKEYType___exit__(PyHKEYObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+{
+ PyObject *return_value = NULL;
+ #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
+
+ #define NUM_KEYWORDS 3
+ static struct {
+ PyGC_Head _this_is_not_used;
+ PyObject_VAR_HEAD
+ PyObject *ob_item[NUM_KEYWORDS];
+ } _kwtuple = {
+ .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
+ .ob_item = { &_Py_ID(exc_type), &_Py_ID(exc_value), &_Py_ID(traceback), },
+ };
+ #undef NUM_KEYWORDS
+ #define KWTUPLE (&_kwtuple.ob_base.ob_base)
+
+ #else // !Py_BUILD_CORE
+ # define KWTUPLE NULL
+ #endif // !Py_BUILD_CORE
+
+ static const char * const _keywords[] = {"exc_type", "exc_value", "traceback", NULL};
+ static _PyArg_Parser _parser = {
+ .keywords = _keywords,
+ .fname = "__exit__",
+ .kwtuple = KWTUPLE,
+ };
+ #undef KWTUPLE
+ PyObject *argsbuf[3];
+ PyObject *exc_type;
+ PyObject *exc_value;
+ PyObject *traceback;
+
+ args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
+ if (!args) {
+ goto exit;
+ }
+ exc_type = args[0];
+ exc_value = args[1];
+ traceback = args[2];
+ return_value = winreg_HKEYType___exit___impl(self, exc_type, exc_value, traceback);
+
+exit:
+ return return_value;
+}
+
+#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */
+
+#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES))
+
+PyDoc_STRVAR(winreg_CloseKey__doc__,
+"CloseKey($module, hkey, /)\n"
+"--\n"
+"\n"
+"Closes a previously opened registry key.\n"
+"\n"
+" hkey\n"
+" A previously opened key.\n"
+"\n"
+"Note that if the key is not closed using this method, it will be\n"
+"closed when the hkey object is destroyed by Python.");
+
+#define WINREG_CLOSEKEY_METHODDEF \
+ {"CloseKey", (PyCFunction)winreg_CloseKey, METH_O, winreg_CloseKey__doc__},
+
+#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */
+
+#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) && (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM))
+
+PyDoc_STRVAR(winreg_ConnectRegistry__doc__,
+"ConnectRegistry($module, computer_name, key, /)\n"
+"--\n"
+"\n"
+"Establishes a connection to the registry on another computer.\n"
+"\n"
+" computer_name\n"
+" The name of the remote computer, of the form r\"\\\\computername\". If\n"
+" None, the local computer is used.\n"
+" key\n"
+" The predefined key to connect to.\n"
+"\n"
+"The return value is the handle of the opened key.\n"
+"If the function fails, an OSError exception is raised.");
+
+#define WINREG_CONNECTREGISTRY_METHODDEF \
+ {"ConnectRegistry", _PyCFunction_CAST(winreg_ConnectRegistry), METH_FASTCALL, winreg_ConnectRegistry__doc__},
+
+static HKEY
+winreg_ConnectRegistry_impl(PyObject *module,
+ const Py_UNICODE *computer_name, HKEY key);
+
+static PyObject *
+winreg_ConnectRegistry(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ const Py_UNICODE *computer_name = NULL;
+ HKEY key;
+ HKEY _return_value;
+
+ if (!_PyArg_CheckPositional("ConnectRegistry", nargs, 2, 2)) {
+ goto exit;
+ }
+ if (args[0] == Py_None) {
+ computer_name = NULL;
+ }
+ else if (PyUnicode_Check(args[0])) {
+ computer_name = PyUnicode_AsWideCharString(args[0], NULL);
+ if (computer_name == NULL) {
+ goto exit;
+ }
+ }
+ else {
+ _PyArg_BadArgument("ConnectRegistry", "argument 1", "str or None", args[0]);
+ goto exit;
+ }
+ if (!clinic_HKEY_converter(_PyModule_GetState(module), args[1], &key)) {
+ goto exit;
+ }
+ _return_value = winreg_ConnectRegistry_impl(module, computer_name, key);
+ if (_return_value == NULL) {
+ goto exit;
+ }
+ return_value = PyHKEY_FromHKEY(_PyModule_GetState(module), _return_value);
+
+exit:
+ /* Cleanup for computer_name */
+ PyMem_Free((void *)computer_name);
+
+ return return_value;
+}
+
+#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) && (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */
+
+#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES))
+
+PyDoc_STRVAR(winreg_CreateKey__doc__,
+"CreateKey($module, key, sub_key, /)\n"
+"--\n"
+"\n"
+"Creates or opens the specified key.\n"
+"\n"
+" key\n"
+" An already open key, or one of the predefined HKEY_* constants.\n"
+" sub_key\n"
+" The name of the key this method opens or creates.\n"
+"\n"
+"If key is one of the predefined keys, sub_key may be None. In that case,\n"
+"the handle returned is the same key handle passed in to the function.\n"
+"\n"
+"If the key already exists, this function opens the existing key.\n"
+"\n"
+"The return value is the handle of the opened key.\n"
+"If the function fails, an OSError exception is raised.");
+
+#define WINREG_CREATEKEY_METHODDEF \
+ {"CreateKey", _PyCFunction_CAST(winreg_CreateKey), METH_FASTCALL, winreg_CreateKey__doc__},
+
+static HKEY
+winreg_CreateKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key);
+
+static PyObject *
+winreg_CreateKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ HKEY key;
+ const Py_UNICODE *sub_key = NULL;
+ HKEY _return_value;
+
+ if (!_PyArg_CheckPositional("CreateKey", nargs, 2, 2)) {
+ goto exit;
+ }
+ if (!clinic_HKEY_converter(_PyModule_GetState(module), args[0], &key)) {
+ goto exit;
+ }
+ if (args[1] == Py_None) {
+ sub_key = NULL;
+ }
+ else if (PyUnicode_Check(args[1])) {
+ sub_key = PyUnicode_AsWideCharString(args[1], NULL);
+ if (sub_key == NULL) {
+ goto exit;
+ }
+ }
+ else {
+ _PyArg_BadArgument("CreateKey", "argument 2", "str or None", args[1]);
+ goto exit;
+ }
+ _return_value = winreg_CreateKey_impl(module, key, sub_key);
+ if (_return_value == NULL) {
+ goto exit;
+ }
+ return_value = PyHKEY_FromHKEY(_PyModule_GetState(module), _return_value);
+
+exit:
+ /* Cleanup for sub_key */
+ PyMem_Free((void *)sub_key);
+
+ return return_value;
+}
+
+#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */
+
+#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES))
+
+PyDoc_STRVAR(winreg_CreateKeyEx__doc__,
+"CreateKeyEx($module, /, key, sub_key, reserved=0,\n"
+" access=winreg.KEY_WRITE)\n"
+"--\n"
+"\n"
+"Creates or opens the specified key.\n"
+"\n"
+" key\n"
+" An already open key, or one of the predefined HKEY_* constants.\n"
+" sub_key\n"
+" The name of the key this method opens or creates.\n"
+" reserved\n"
+" A reserved integer, and must be zero. Default is zero.\n"
+" access\n"
+" An integer that specifies an access mask that describes the\n"
+" desired security access for the key. Default is KEY_WRITE.\n"
+"\n"
+"If key is one of the predefined keys, sub_key may be None. In that case,\n"
+"the handle returned is the same key handle passed in to the function.\n"
+"\n"
+"If the key already exists, this function opens the existing key\n"
+"\n"
+"The return value is the handle of the opened key.\n"
+"If the function fails, an OSError exception is raised.");
+
+#define WINREG_CREATEKEYEX_METHODDEF \
+ {"CreateKeyEx", _PyCFunction_CAST(winreg_CreateKeyEx), METH_FASTCALL|METH_KEYWORDS, winreg_CreateKeyEx__doc__},
+
+static HKEY
+winreg_CreateKeyEx_impl(PyObject *module, HKEY key,
+ const Py_UNICODE *sub_key, int reserved,
+ REGSAM access);
+
+static PyObject *
+winreg_CreateKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+{
+ PyObject *return_value = NULL;
+ #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
+
+ #define NUM_KEYWORDS 4
+ static struct {
+ PyGC_Head _this_is_not_used;
+ PyObject_VAR_HEAD
+ PyObject *ob_item[NUM_KEYWORDS];
+ } _kwtuple = {
+ .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
+ .ob_item = { &_Py_ID(key), &_Py_ID(sub_key), &_Py_ID(reserved), &_Py_ID(access), },
+ };
+ #undef NUM_KEYWORDS
+ #define KWTUPLE (&_kwtuple.ob_base.ob_base)
+
+ #else // !Py_BUILD_CORE
+ # define KWTUPLE NULL
+ #endif // !Py_BUILD_CORE
+
+ static const char * const _keywords[] = {"key", "sub_key", "reserved", "access", NULL};
+ static _PyArg_Parser _parser = {
+ .keywords = _keywords,
+ .fname = "CreateKeyEx",
+ .kwtuple = KWTUPLE,
+ };
+ #undef KWTUPLE
+ PyObject *argsbuf[4];
+ Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
+ HKEY key;
+ const Py_UNICODE *sub_key = NULL;
+ int reserved = 0;
+ REGSAM access = KEY_WRITE;
+ HKEY _return_value;
+
+ args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 4, 0, argsbuf);
+ if (!args) {
+ goto exit;
+ }
+ if (!clinic_HKEY_converter(_PyModule_GetState(module), args[0], &key)) {
+ goto exit;
+ }
+ if (args[1] == Py_None) {
+ sub_key = NULL;
+ }
+ else if (PyUnicode_Check(args[1])) {
+ sub_key = PyUnicode_AsWideCharString(args[1], NULL);
+ if (sub_key == NULL) {
+ goto exit;
+ }
+ }
+ else {
+ _PyArg_BadArgument("CreateKeyEx", "argument 'sub_key'", "str or None", args[1]);
+ goto exit;
+ }
+ if (!noptargs) {
+ goto skip_optional_pos;
+ }
+ if (args[2]) {
+ reserved = _PyLong_AsInt(args[2]);
+ if (reserved == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ if (!--noptargs) {
+ goto skip_optional_pos;
+ }
+ }
+ access = _PyLong_AsInt(args[3]);
+ if (access == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+skip_optional_pos:
+ _return_value = winreg_CreateKeyEx_impl(module, key, sub_key, reserved, access);
+ if (_return_value == NULL) {
+ goto exit;
+ }
+ return_value = PyHKEY_FromHKEY(_PyModule_GetState(module), _return_value);
+
+exit:
+ /* Cleanup for sub_key */
+ PyMem_Free((void *)sub_key);
+
+ return return_value;
+}
+
+#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */
+
+#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES))
+
+PyDoc_STRVAR(winreg_DeleteKey__doc__,
+"DeleteKey($module, key, sub_key, /)\n"
+"--\n"
+"\n"
+"Deletes the specified key.\n"
+"\n"
+" key\n"
+" An already open key, or any one of the predefined HKEY_* constants.\n"
+" sub_key\n"
+" A string that must be the name of a subkey of the key identified by\n"
+" the key parameter. This value must not be None, and the key may not\n"
+" have subkeys.\n"
+"\n"
+"This method can not delete keys with subkeys.\n"
+"\n"
+"If the function succeeds, the entire key, including all of its values,\n"
+"is removed. If the function fails, an OSError exception is raised.");
+
+#define WINREG_DELETEKEY_METHODDEF \
+ {"DeleteKey", _PyCFunction_CAST(winreg_DeleteKey), METH_FASTCALL, winreg_DeleteKey__doc__},
+
+static PyObject *
+winreg_DeleteKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key);
+
+static PyObject *
+winreg_DeleteKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ HKEY key;
+ const Py_UNICODE *sub_key = NULL;
+
+ if (!_PyArg_CheckPositional("DeleteKey", nargs, 2, 2)) {
+ goto exit;
+ }
+ if (!clinic_HKEY_converter(_PyModule_GetState(module), args[0], &key)) {
+ goto exit;
+ }
+ if (!PyUnicode_Check(args[1])) {
+ _PyArg_BadArgument("DeleteKey", "argument 2", "str", args[1]);
+ goto exit;
+ }
+ sub_key = PyUnicode_AsWideCharString(args[1], NULL);
+ if (sub_key == NULL) {
+ goto exit;
+ }
+ return_value = winreg_DeleteKey_impl(module, key, sub_key);
+
+exit:
+ /* Cleanup for sub_key */
+ PyMem_Free((void *)sub_key);
+
+ return return_value;
+}
+
+#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */
+
+#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES))
+
+PyDoc_STRVAR(winreg_DeleteKeyEx__doc__,
+"DeleteKeyEx($module, /, key, sub_key, access=winreg.KEY_WOW64_64KEY,\n"
+" reserved=0)\n"
+"--\n"
+"\n"
+"Deletes the specified key (intended for 64-bit OS).\n"
+"\n"
+" key\n"
+" An already open key, or any one of the predefined HKEY_* constants.\n"
+" sub_key\n"
+" A string that must be the name of a subkey of the key identified by\n"
+" the key parameter. This value must not be None, and the key may not\n"
+" have subkeys.\n"
+" access\n"
+" An integer that specifies an access mask that describes the\n"
+" desired security access for the key. Default is KEY_WOW64_64KEY.\n"
+" reserved\n"
+" A reserved integer, and must be zero. Default is zero.\n"
+"\n"
+"While this function is intended to be used for 64-bit OS, it is also\n"
+" available on 32-bit systems.\n"
+"\n"
+"This method can not delete keys with subkeys.\n"
+"\n"
+"If the function succeeds, the entire key, including all of its values,\n"
+"is removed. If the function fails, an OSError exception is raised.\n"
+"On unsupported Windows versions, NotImplementedError is raised.");
+
+#define WINREG_DELETEKEYEX_METHODDEF \
+ {"DeleteKeyEx", _PyCFunction_CAST(winreg_DeleteKeyEx), METH_FASTCALL|METH_KEYWORDS, winreg_DeleteKeyEx__doc__},
+
+static PyObject *
+winreg_DeleteKeyEx_impl(PyObject *module, HKEY key,
+ const Py_UNICODE *sub_key, REGSAM access,
+ int reserved);
+
+static PyObject *
+winreg_DeleteKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+{
+ PyObject *return_value = NULL;
+ #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
+
+ #define NUM_KEYWORDS 4
+ static struct {
+ PyGC_Head _this_is_not_used;
+ PyObject_VAR_HEAD
+ PyObject *ob_item[NUM_KEYWORDS];
+ } _kwtuple = {
+ .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
+ .ob_item = { &_Py_ID(key), &_Py_ID(sub_key), &_Py_ID(access), &_Py_ID(reserved), },
+ };
+ #undef NUM_KEYWORDS
+ #define KWTUPLE (&_kwtuple.ob_base.ob_base)
+
+ #else // !Py_BUILD_CORE
+ # define KWTUPLE NULL
+ #endif // !Py_BUILD_CORE
+
+ static const char * const _keywords[] = {"key", "sub_key", "access", "reserved", NULL};
+ static _PyArg_Parser _parser = {
+ .keywords = _keywords,
+ .fname = "DeleteKeyEx",
+ .kwtuple = KWTUPLE,
+ };
+ #undef KWTUPLE
+ PyObject *argsbuf[4];
+ Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
+ HKEY key;
+ const Py_UNICODE *sub_key = NULL;
+ REGSAM access = KEY_WOW64_64KEY;
+ int reserved = 0;
+
+ args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 4, 0, argsbuf);
+ if (!args) {
+ goto exit;
+ }
+ if (!clinic_HKEY_converter(_PyModule_GetState(module), args[0], &key)) {
+ goto exit;
+ }
+ if (!PyUnicode_Check(args[1])) {
+ _PyArg_BadArgument("DeleteKeyEx", "argument 'sub_key'", "str", args[1]);
+ goto exit;
+ }
+ sub_key = PyUnicode_AsWideCharString(args[1], NULL);
+ if (sub_key == NULL) {
+ goto exit;
+ }
+ if (!noptargs) {
+ goto skip_optional_pos;
+ }
+ if (args[2]) {
+ access = _PyLong_AsInt(args[2]);
+ if (access == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ if (!--noptargs) {
+ goto skip_optional_pos;
+ }
+ }
+ reserved = _PyLong_AsInt(args[3]);
+ if (reserved == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+skip_optional_pos:
+ return_value = winreg_DeleteKeyEx_impl(module, key, sub_key, access, reserved);
+
+exit:
+ /* Cleanup for sub_key */
+ PyMem_Free((void *)sub_key);
+
+ return return_value;
+}
+
+#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */
+
+#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES))
+
+PyDoc_STRVAR(winreg_DeleteValue__doc__,
+"DeleteValue($module, key, value, /)\n"
+"--\n"
+"\n"
+"Removes a named value from a registry key.\n"
+"\n"
+" key\n"
+" An already open key, or any one of the predefined HKEY_* constants.\n"
+" value\n"
+" A string that identifies the value to remove.");
+
+#define WINREG_DELETEVALUE_METHODDEF \
+ {"DeleteValue", _PyCFunction_CAST(winreg_DeleteValue), METH_FASTCALL, winreg_DeleteValue__doc__},
+
+static PyObject *
+winreg_DeleteValue_impl(PyObject *module, HKEY key, const Py_UNICODE *value);
+
+static PyObject *
+winreg_DeleteValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ HKEY key;
+ const Py_UNICODE *value = NULL;
+
+ if (!_PyArg_CheckPositional("DeleteValue", nargs, 2, 2)) {
+ goto exit;
+ }
+ if (!clinic_HKEY_converter(_PyModule_GetState(module), args[0], &key)) {
+ goto exit;
+ }
+ if (args[1] == Py_None) {
+ value = NULL;
+ }
+ else if (PyUnicode_Check(args[1])) {
+ value = PyUnicode_AsWideCharString(args[1], NULL);
+ if (value == NULL) {
+ goto exit;
+ }
+ }
+ else {
+ _PyArg_BadArgument("DeleteValue", "argument 2", "str or None", args[1]);
+ goto exit;
+ }
+ return_value = winreg_DeleteValue_impl(module, key, value);
+
+exit:
+ /* Cleanup for value */
+ PyMem_Free((void *)value);
+
+ return return_value;
+}
+
+#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */
+
+#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES))
+
+PyDoc_STRVAR(winreg_EnumKey__doc__,
+"EnumKey($module, key, index, /)\n"
+"--\n"
+"\n"
+"Enumerates subkeys of an open registry key.\n"
+"\n"
+" key\n"
+" An already open key, or any one of the predefined HKEY_* constants.\n"
+" index\n"
+" An integer that identifies the index of the key to retrieve.\n"
+"\n"
+"The function retrieves the name of one subkey each time it is called.\n"
+"It is typically called repeatedly until an OSError exception is\n"
+"raised, indicating no more values are available.");
+
+#define WINREG_ENUMKEY_METHODDEF \
+ {"EnumKey", _PyCFunction_CAST(winreg_EnumKey), METH_FASTCALL, winreg_EnumKey__doc__},
+
+static PyObject *
+winreg_EnumKey_impl(PyObject *module, HKEY key, int index);
+
+static PyObject *
+winreg_EnumKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ HKEY key;
+ int index;
+
+ if (!_PyArg_CheckPositional("EnumKey", nargs, 2, 2)) {
+ goto exit;
+ }
+ if (!clinic_HKEY_converter(_PyModule_GetState(module), args[0], &key)) {
+ goto exit;
+ }
+ index = _PyLong_AsInt(args[1]);
+ if (index == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ return_value = winreg_EnumKey_impl(module, key, index);
+
+exit:
+ return return_value;
+}
+
+#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */
+
+#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES))
+
+PyDoc_STRVAR(winreg_EnumValue__doc__,
+"EnumValue($module, key, index, /)\n"
+"--\n"
+"\n"
+"Enumerates values of an open registry key.\n"
+"\n"
+" key\n"
+" An already open key, or any one of the predefined HKEY_* constants.\n"
+" index\n"
+" An integer that identifies the index of the value to retrieve.\n"
+"\n"
+"The function retrieves the name of one subkey each time it is called.\n"
+"It is typically called repeatedly, until an OSError exception\n"
+"is raised, indicating no more values.\n"
+"\n"
+"The result is a tuple of 3 items:\n"
+" value_name\n"
+" A string that identifies the value.\n"
+" value_data\n"
+" An object that holds the value data, and whose type depends\n"
+" on the underlying registry type.\n"
+" data_type\n"
+" An integer that identifies the type of the value data.");
+
+#define WINREG_ENUMVALUE_METHODDEF \
+ {"EnumValue", _PyCFunction_CAST(winreg_EnumValue), METH_FASTCALL, winreg_EnumValue__doc__},
+
+static PyObject *
+winreg_EnumValue_impl(PyObject *module, HKEY key, int index);
+
+static PyObject *
+winreg_EnumValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ HKEY key;
+ int index;
+
+ if (!_PyArg_CheckPositional("EnumValue", nargs, 2, 2)) {
+ goto exit;
+ }
+ if (!clinic_HKEY_converter(_PyModule_GetState(module), args[0], &key)) {
+ goto exit;
+ }
+ index = _PyLong_AsInt(args[1]);
+ if (index == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ return_value = winreg_EnumValue_impl(module, key, index);
+
+exit:
+ return return_value;
+}
+
+#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */
+
+#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES))
+
+PyDoc_STRVAR(winreg_ExpandEnvironmentStrings__doc__,
+"ExpandEnvironmentStrings($module, string, /)\n"
+"--\n"
+"\n"
+"Expand environment vars.");
+
+#define WINREG_EXPANDENVIRONMENTSTRINGS_METHODDEF \
+ {"ExpandEnvironmentStrings", (PyCFunction)winreg_ExpandEnvironmentStrings, METH_O, winreg_ExpandEnvironmentStrings__doc__},
+
+static PyObject *
+winreg_ExpandEnvironmentStrings_impl(PyObject *module,
+ const Py_UNICODE *string);
+
+static PyObject *
+winreg_ExpandEnvironmentStrings(PyObject *module, PyObject *arg)
+{
+ PyObject *return_value = NULL;
+ const Py_UNICODE *string = NULL;
+
+ if (!PyUnicode_Check(arg)) {
+ _PyArg_BadArgument("ExpandEnvironmentStrings", "argument", "str", arg);
+ goto exit;
+ }
+ string = PyUnicode_AsWideCharString(arg, NULL);
+ if (string == NULL) {
+ goto exit;
+ }
+ return_value = winreg_ExpandEnvironmentStrings_impl(module, string);
+
+exit:
+ /* Cleanup for string */
+ PyMem_Free((void *)string);
+
+ return return_value;
+}
+
+#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */
+
+#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) && (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM))
+
+PyDoc_STRVAR(winreg_FlushKey__doc__,
+"FlushKey($module, key, /)\n"
+"--\n"
+"\n"
+"Writes all the attributes of a key to the registry.\n"
+"\n"
+" key\n"
+" An already open key, or any one of the predefined HKEY_* constants.\n"
+"\n"
+"It is not necessary to call FlushKey to change a key. Registry changes\n"
+"are flushed to disk by the registry using its lazy flusher. Registry\n"
+"changes are also flushed to disk at system shutdown. Unlike\n"
+"CloseKey(), the FlushKey() method returns only when all the data has\n"
+"been written to the registry.\n"
+"\n"
+"An application should only call FlushKey() if it requires absolute\n"
+"certainty that registry changes are on disk. If you don\'t know whether\n"
+"a FlushKey() call is required, it probably isn\'t.");
+
+#define WINREG_FLUSHKEY_METHODDEF \
+ {"FlushKey", (PyCFunction)winreg_FlushKey, METH_O, winreg_FlushKey__doc__},
+
+static PyObject *
+winreg_FlushKey_impl(PyObject *module, HKEY key);
+
+static PyObject *
+winreg_FlushKey(PyObject *module, PyObject *arg)
+{
+ PyObject *return_value = NULL;
+ HKEY key;
+
+ if (!clinic_HKEY_converter(_PyModule_GetState(module), arg, &key)) {
+ goto exit;
+ }
+ return_value = winreg_FlushKey_impl(module, key);
+
+exit:
+ return return_value;
+}
+
+#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) && (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */
+
+#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) && (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM))
+
+PyDoc_STRVAR(winreg_LoadKey__doc__,
+"LoadKey($module, key, sub_key, file_name, /)\n"
+"--\n"
+"\n"
+"Insert data into the registry from a file.\n"
+"\n"
+" key\n"
+" An already open key, or any one of the predefined HKEY_* constants.\n"
+" sub_key\n"
+" A string that identifies the sub-key to load.\n"
+" file_name\n"
+" The name of the file to load registry data from. This file must\n"
+" have been created with the SaveKey() function. Under the file\n"
+" allocation table (FAT) file system, the filename may not have an\n"
+" extension.\n"
+"\n"
+"Creates a subkey under the specified key and stores registration\n"
+"information from a specified file into that subkey.\n"
+"\n"
+"A call to LoadKey() fails if the calling process does not have the\n"
+"SE_RESTORE_PRIVILEGE privilege.\n"
+"\n"
+"If key is a handle returned by ConnectRegistry(), then the path\n"
+"specified in fileName is relative to the remote computer.\n"
+"\n"
+"The MSDN docs imply key must be in the HKEY_USER or HKEY_LOCAL_MACHINE\n"
+"tree.");
+
+#define WINREG_LOADKEY_METHODDEF \
+ {"LoadKey", _PyCFunction_CAST(winreg_LoadKey), METH_FASTCALL, winreg_LoadKey__doc__},
+
+static PyObject *
+winreg_LoadKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
+ const Py_UNICODE *file_name);
+
+static PyObject *
+winreg_LoadKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ HKEY key;
+ const Py_UNICODE *sub_key = NULL;
+ const Py_UNICODE *file_name = NULL;
+
+ if (!_PyArg_CheckPositional("LoadKey", nargs, 3, 3)) {
+ goto exit;
+ }
+ if (!clinic_HKEY_converter(_PyModule_GetState(module), args[0], &key)) {
+ goto exit;
+ }
+ if (!PyUnicode_Check(args[1])) {
+ _PyArg_BadArgument("LoadKey", "argument 2", "str", args[1]);
+ goto exit;
+ }
+ sub_key = PyUnicode_AsWideCharString(args[1], NULL);
+ if (sub_key == NULL) {
+ goto exit;
+ }
+ if (!PyUnicode_Check(args[2])) {
+ _PyArg_BadArgument("LoadKey", "argument 3", "str", args[2]);
+ goto exit;
+ }
+ file_name = PyUnicode_AsWideCharString(args[2], NULL);
+ if (file_name == NULL) {
+ goto exit;
+ }
+ return_value = winreg_LoadKey_impl(module, key, sub_key, file_name);
+
+exit:
+ /* Cleanup for sub_key */
+ PyMem_Free((void *)sub_key);
+ /* Cleanup for file_name */
+ PyMem_Free((void *)file_name);
+
+ return return_value;
+}
+
+#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) && (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */
+
+#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES))
+
+PyDoc_STRVAR(winreg_OpenKey__doc__,
+"OpenKey($module, /, key, sub_key, reserved=0, access=winreg.KEY_READ)\n"
+"--\n"
+"\n"
+"Opens the specified key.\n"
+"\n"
+" key\n"
+" An already open key, or any one of the predefined HKEY_* constants.\n"
+" sub_key\n"
+" A string that identifies the sub_key to open.\n"
+" reserved\n"
+" A reserved integer that must be zero. Default is zero.\n"
+" access\n"
+" An integer that specifies an access mask that describes the desired\n"
+" security access for the key. Default is KEY_READ.\n"
+"\n"
+"The result is a new handle to the specified key.\n"
+"If the function fails, an OSError exception is raised.");
+
+#define WINREG_OPENKEY_METHODDEF \
+ {"OpenKey", _PyCFunction_CAST(winreg_OpenKey), METH_FASTCALL|METH_KEYWORDS, winreg_OpenKey__doc__},
+
+static HKEY
+winreg_OpenKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
+ int reserved, REGSAM access);
+
+static PyObject *
+winreg_OpenKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+{
+ PyObject *return_value = NULL;
+ #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
+
+ #define NUM_KEYWORDS 4
+ static struct {
+ PyGC_Head _this_is_not_used;
+ PyObject_VAR_HEAD
+ PyObject *ob_item[NUM_KEYWORDS];
+ } _kwtuple = {
+ .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
+ .ob_item = { &_Py_ID(key), &_Py_ID(sub_key), &_Py_ID(reserved), &_Py_ID(access), },
+ };
+ #undef NUM_KEYWORDS
+ #define KWTUPLE (&_kwtuple.ob_base.ob_base)
+
+ #else // !Py_BUILD_CORE
+ # define KWTUPLE NULL
+ #endif // !Py_BUILD_CORE
+
+ static const char * const _keywords[] = {"key", "sub_key", "reserved", "access", NULL};
+ static _PyArg_Parser _parser = {
+ .keywords = _keywords,
+ .fname = "OpenKey",
+ .kwtuple = KWTUPLE,
+ };
+ #undef KWTUPLE
+ PyObject *argsbuf[4];
+ Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
+ HKEY key;
+ const Py_UNICODE *sub_key = NULL;
+ int reserved = 0;
+ REGSAM access = KEY_READ;
+ HKEY _return_value;
+
+ args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 4, 0, argsbuf);
+ if (!args) {
+ goto exit;
+ }
+ if (!clinic_HKEY_converter(_PyModule_GetState(module), args[0], &key)) {
+ goto exit;
+ }
+ if (args[1] == Py_None) {
+ sub_key = NULL;
+ }
+ else if (PyUnicode_Check(args[1])) {
+ sub_key = PyUnicode_AsWideCharString(args[1], NULL);
+ if (sub_key == NULL) {
+ goto exit;
+ }
+ }
+ else {
+ _PyArg_BadArgument("OpenKey", "argument 'sub_key'", "str or None", args[1]);
+ goto exit;
+ }
+ if (!noptargs) {
+ goto skip_optional_pos;
+ }
+ if (args[2]) {
+ reserved = _PyLong_AsInt(args[2]);
+ if (reserved == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ if (!--noptargs) {
+ goto skip_optional_pos;
+ }
+ }
+ access = _PyLong_AsInt(args[3]);
+ if (access == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+skip_optional_pos:
+ _return_value = winreg_OpenKey_impl(module, key, sub_key, reserved, access);
+ if (_return_value == NULL) {
+ goto exit;
+ }
+ return_value = PyHKEY_FromHKEY(_PyModule_GetState(module), _return_value);
+
+exit:
+ /* Cleanup for sub_key */
+ PyMem_Free((void *)sub_key);
+
+ return return_value;
+}
+
+#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */
+
+#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES))
+
+PyDoc_STRVAR(winreg_OpenKeyEx__doc__,
+"OpenKeyEx($module, /, key, sub_key, reserved=0, access=winreg.KEY_READ)\n"
+"--\n"
+"\n"
+"Opens the specified key.\n"
+"\n"
+" key\n"
+" An already open key, or any one of the predefined HKEY_* constants.\n"
+" sub_key\n"
+" A string that identifies the sub_key to open.\n"
+" reserved\n"
+" A reserved integer that must be zero. Default is zero.\n"
+" access\n"
+" An integer that specifies an access mask that describes the desired\n"
+" security access for the key. Default is KEY_READ.\n"
+"\n"
+"The result is a new handle to the specified key.\n"
+"If the function fails, an OSError exception is raised.");
+
+#define WINREG_OPENKEYEX_METHODDEF \
+ {"OpenKeyEx", _PyCFunction_CAST(winreg_OpenKeyEx), METH_FASTCALL|METH_KEYWORDS, winreg_OpenKeyEx__doc__},
+
+static HKEY
+winreg_OpenKeyEx_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
+ int reserved, REGSAM access);
+
+static PyObject *
+winreg_OpenKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+{
+ PyObject *return_value = NULL;
+ #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
+
+ #define NUM_KEYWORDS 4
+ static struct {
+ PyGC_Head _this_is_not_used;
+ PyObject_VAR_HEAD
+ PyObject *ob_item[NUM_KEYWORDS];
+ } _kwtuple = {
+ .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
+ .ob_item = { &_Py_ID(key), &_Py_ID(sub_key), &_Py_ID(reserved), &_Py_ID(access), },
+ };
+ #undef NUM_KEYWORDS
+ #define KWTUPLE (&_kwtuple.ob_base.ob_base)
+
+ #else // !Py_BUILD_CORE
+ # define KWTUPLE NULL
+ #endif // !Py_BUILD_CORE
+
+ static const char * const _keywords[] = {"key", "sub_key", "reserved", "access", NULL};
+ static _PyArg_Parser _parser = {
+ .keywords = _keywords,
+ .fname = "OpenKeyEx",
+ .kwtuple = KWTUPLE,
+ };
+ #undef KWTUPLE
+ PyObject *argsbuf[4];
+ Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
+ HKEY key;
+ const Py_UNICODE *sub_key = NULL;
+ int reserved = 0;
+ REGSAM access = KEY_READ;
+ HKEY _return_value;
+
+ args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 4, 0, argsbuf);
+ if (!args) {
+ goto exit;
+ }
+ if (!clinic_HKEY_converter(_PyModule_GetState(module), args[0], &key)) {
+ goto exit;
+ }
+ if (args[1] == Py_None) {
+ sub_key = NULL;
+ }
+ else if (PyUnicode_Check(args[1])) {
+ sub_key = PyUnicode_AsWideCharString(args[1], NULL);
+ if (sub_key == NULL) {
+ goto exit;
+ }
+ }
+ else {
+ _PyArg_BadArgument("OpenKeyEx", "argument 'sub_key'", "str or None", args[1]);
+ goto exit;
+ }
+ if (!noptargs) {
+ goto skip_optional_pos;
+ }
+ if (args[2]) {
+ reserved = _PyLong_AsInt(args[2]);
+ if (reserved == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ if (!--noptargs) {
+ goto skip_optional_pos;
+ }
+ }
+ access = _PyLong_AsInt(args[3]);
+ if (access == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+skip_optional_pos:
+ _return_value = winreg_OpenKeyEx_impl(module, key, sub_key, reserved, access);
+ if (_return_value == NULL) {
+ goto exit;
+ }
+ return_value = PyHKEY_FromHKEY(_PyModule_GetState(module), _return_value);
+
+exit:
+ /* Cleanup for sub_key */
+ PyMem_Free((void *)sub_key);
+
+ return return_value;
+}
+
+#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */
+
+#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES))
+
+PyDoc_STRVAR(winreg_QueryInfoKey__doc__,
+"QueryInfoKey($module, key, /)\n"
+"--\n"
+"\n"
+"Returns information about a key.\n"
+"\n"
+" key\n"
+" An already open key, or any one of the predefined HKEY_* constants.\n"
+"\n"
+"The result is a tuple of 3 items:\n"
+"An integer that identifies the number of sub keys this key has.\n"
+"An integer that identifies the number of values this key has.\n"
+"An integer that identifies when the key was last modified (if available)\n"
+"as 100\'s of nanoseconds since Jan 1, 1600.");
+
+#define WINREG_QUERYINFOKEY_METHODDEF \
+ {"QueryInfoKey", (PyCFunction)winreg_QueryInfoKey, METH_O, winreg_QueryInfoKey__doc__},
+
+static PyObject *
+winreg_QueryInfoKey_impl(PyObject *module, HKEY key);
+
+static PyObject *
+winreg_QueryInfoKey(PyObject *module, PyObject *arg)
+{
+ PyObject *return_value = NULL;
+ HKEY key;
+
+ if (!clinic_HKEY_converter(_PyModule_GetState(module), arg, &key)) {
+ goto exit;
+ }
+ return_value = winreg_QueryInfoKey_impl(module, key);
+
+exit:
+ return return_value;
+}
+
+#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */
+
+#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES))
+
+PyDoc_STRVAR(winreg_QueryValue__doc__,
+"QueryValue($module, key, sub_key, /)\n"
+"--\n"
+"\n"
+"Retrieves the unnamed value for a key.\n"
+"\n"
+" key\n"
+" An already open key, or any one of the predefined HKEY_* constants.\n"
+" sub_key\n"
+" A string that holds the name of the subkey with which the value\n"
+" is associated. If this parameter is None or empty, the function\n"
+" retrieves the value set by the SetValue() method for the key\n"
+" identified by key.\n"
+"\n"
+"Values in the registry have name, type, and data components. This method\n"
+"retrieves the data for a key\'s first value that has a NULL name.\n"
+"But since the underlying API call doesn\'t return the type, you\'ll\n"
+"probably be happier using QueryValueEx; this function is just here for\n"
+"completeness.");
+
+#define WINREG_QUERYVALUE_METHODDEF \
+ {"QueryValue", _PyCFunction_CAST(winreg_QueryValue), METH_FASTCALL, winreg_QueryValue__doc__},
+
+static PyObject *
+winreg_QueryValue_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key);
+
+static PyObject *
+winreg_QueryValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ HKEY key;
+ const Py_UNICODE *sub_key = NULL;
+
+ if (!_PyArg_CheckPositional("QueryValue", nargs, 2, 2)) {
+ goto exit;
+ }
+ if (!clinic_HKEY_converter(_PyModule_GetState(module), args[0], &key)) {
+ goto exit;
+ }
+ if (args[1] == Py_None) {
+ sub_key = NULL;
+ }
+ else if (PyUnicode_Check(args[1])) {
+ sub_key = PyUnicode_AsWideCharString(args[1], NULL);
+ if (sub_key == NULL) {
+ goto exit;
+ }
+ }
+ else {
+ _PyArg_BadArgument("QueryValue", "argument 2", "str or None", args[1]);
+ goto exit;
+ }
+ return_value = winreg_QueryValue_impl(module, key, sub_key);
+
+exit:
+ /* Cleanup for sub_key */
+ PyMem_Free((void *)sub_key);
+
+ return return_value;
+}
+
+#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */
+
+#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES))
+
+PyDoc_STRVAR(winreg_QueryValueEx__doc__,
+"QueryValueEx($module, key, name, /)\n"
+"--\n"
+"\n"
+"Retrieves the type and value of a specified sub-key.\n"
+"\n"
+" key\n"
+" An already open key, or any one of the predefined HKEY_* constants.\n"
+" name\n"
+" A string indicating the value to query.\n"
+"\n"
+"Behaves mostly like QueryValue(), but also returns the type of the\n"
+"specified value name associated with the given open registry key.\n"
+"\n"
+"The return value is a tuple of the value and the type_id.");
+
+#define WINREG_QUERYVALUEEX_METHODDEF \
+ {"QueryValueEx", _PyCFunction_CAST(winreg_QueryValueEx), METH_FASTCALL, winreg_QueryValueEx__doc__},
+
+static PyObject *
+winreg_QueryValueEx_impl(PyObject *module, HKEY key, const Py_UNICODE *name);
+
+static PyObject *
+winreg_QueryValueEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ HKEY key;
+ const Py_UNICODE *name = NULL;
+
+ if (!_PyArg_CheckPositional("QueryValueEx", nargs, 2, 2)) {
+ goto exit;
+ }
+ if (!clinic_HKEY_converter(_PyModule_GetState(module), args[0], &key)) {
+ goto exit;
+ }
+ if (args[1] == Py_None) {
+ name = NULL;
+ }
+ else if (PyUnicode_Check(args[1])) {
+ name = PyUnicode_AsWideCharString(args[1], NULL);
+ if (name == NULL) {
+ goto exit;
+ }
+ }
+ else {
+ _PyArg_BadArgument("QueryValueEx", "argument 2", "str or None", args[1]);
+ goto exit;
+ }
+ return_value = winreg_QueryValueEx_impl(module, key, name);
+
+exit:
+ /* Cleanup for name */
+ PyMem_Free((void *)name);
+
+ return return_value;
+}
+
+#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */
+
+#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) && (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM))
+
+PyDoc_STRVAR(winreg_SaveKey__doc__,
+"SaveKey($module, key, file_name, /)\n"
+"--\n"
+"\n"
+"Saves the specified key, and all its subkeys to the specified file.\n"
+"\n"
+" key\n"
+" An already open key, or any one of the predefined HKEY_* constants.\n"
+" file_name\n"
+" The name of the file to save registry data to. This file cannot\n"
+" already exist. If this filename includes an extension, it cannot be\n"
+" used on file allocation table (FAT) file systems by the LoadKey(),\n"
+" ReplaceKey() or RestoreKey() methods.\n"
+"\n"
+"If key represents a key on a remote computer, the path described by\n"
+"file_name is relative to the remote computer.\n"
+"\n"
+"The caller of this method must possess the SeBackupPrivilege\n"
+"security privilege. This function passes NULL for security_attributes\n"
+"to the API.");
+
+#define WINREG_SAVEKEY_METHODDEF \
+ {"SaveKey", _PyCFunction_CAST(winreg_SaveKey), METH_FASTCALL, winreg_SaveKey__doc__},
+
+static PyObject *
+winreg_SaveKey_impl(PyObject *module, HKEY key, const Py_UNICODE *file_name);
+
+static PyObject *
+winreg_SaveKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ HKEY key;
+ const Py_UNICODE *file_name = NULL;
+
+ if (!_PyArg_CheckPositional("SaveKey", nargs, 2, 2)) {
+ goto exit;
+ }
+ if (!clinic_HKEY_converter(_PyModule_GetState(module), args[0], &key)) {
+ goto exit;
+ }
+ if (!PyUnicode_Check(args[1])) {
+ _PyArg_BadArgument("SaveKey", "argument 2", "str", args[1]);
+ goto exit;
+ }
+ file_name = PyUnicode_AsWideCharString(args[1], NULL);
+ if (file_name == NULL) {
+ goto exit;
+ }
+ return_value = winreg_SaveKey_impl(module, key, file_name);
+
+exit:
+ /* Cleanup for file_name */
+ PyMem_Free((void *)file_name);
+
+ return return_value;
+}
+
+#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) && (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */
+
+#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES))
+
+PyDoc_STRVAR(winreg_SetValue__doc__,
+"SetValue($module, key, sub_key, type, value, /)\n"
+"--\n"
+"\n"
+"Associates a value with a specified key.\n"
+"\n"
+" key\n"
+" An already open key, or any one of the predefined HKEY_* constants.\n"
+" sub_key\n"
+" A string that names the subkey with which the value is associated.\n"
+" type\n"
+" An integer that specifies the type of the data. Currently this must\n"
+" be REG_SZ, meaning only strings are supported.\n"
+" value\n"
+" A string that specifies the new value.\n"
+"\n"
+"If the key specified by the sub_key parameter does not exist, the\n"
+"SetValue function creates it.\n"
+"\n"
+"Value lengths are limited by available memory. Long values (more than\n"
+"2048 bytes) should be stored as files with the filenames stored in\n"
+"the configuration registry to help the registry perform efficiently.\n"
+"\n"
+"The key identified by the key parameter must have been opened with\n"
+"KEY_SET_VALUE access.");
+
+#define WINREG_SETVALUE_METHODDEF \
+ {"SetValue", _PyCFunction_CAST(winreg_SetValue), METH_FASTCALL, winreg_SetValue__doc__},
+
+static PyObject *
+winreg_SetValue_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
+ DWORD type, PyObject *value_obj);
+
+static PyObject *
+winreg_SetValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ HKEY key;
+ const Py_UNICODE *sub_key = NULL;
+ DWORD type;
+ PyObject *value_obj;
+
+ if (!_PyArg_CheckPositional("SetValue", nargs, 4, 4)) {
+ goto exit;
+ }
+ if (!clinic_HKEY_converter(_PyModule_GetState(module), args[0], &key)) {
+ goto exit;
+ }
+ if (args[1] == Py_None) {
+ sub_key = NULL;
+ }
+ else if (PyUnicode_Check(args[1])) {
+ sub_key = PyUnicode_AsWideCharString(args[1], NULL);
+ if (sub_key == NULL) {
+ goto exit;
+ }
+ }
+ else {
+ _PyArg_BadArgument("SetValue", "argument 2", "str or None", args[1]);
+ goto exit;
+ }
+ if (!_PyLong_UnsignedLong_Converter(args[2], &type)) {
+ goto exit;
+ }
+ if (!PyUnicode_Check(args[3])) {
+ _PyArg_BadArgument("SetValue", "argument 4", "str", args[3]);
+ goto exit;
+ }
+ if (PyUnicode_READY(args[3]) == -1) {
+ goto exit;
+ }
+ value_obj = args[3];
+ return_value = winreg_SetValue_impl(module, key, sub_key, type, value_obj);
+
+exit:
+ /* Cleanup for sub_key */
+ PyMem_Free((void *)sub_key);
+
+ return return_value;
+}
+
+#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */
+
+#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES))
+
+PyDoc_STRVAR(winreg_SetValueEx__doc__,
+"SetValueEx($module, key, value_name, reserved, type, value, /)\n"
+"--\n"
+"\n"
+"Stores data in the value field of an open registry key.\n"
+"\n"
+" key\n"
+" An already open key, or any one of the predefined HKEY_* constants.\n"
+" value_name\n"
+" A string containing the name of the value to set, or None.\n"
+" reserved\n"
+" Can be anything - zero is always passed to the API.\n"
+" type\n"
+" An integer that specifies the type of the data, one of:\n"
+" REG_BINARY -- Binary data in any form.\n"
+" REG_DWORD -- A 32-bit number.\n"
+" REG_DWORD_LITTLE_ENDIAN -- A 32-bit number in little-endian format. Equivalent to REG_DWORD\n"
+" REG_DWORD_BIG_ENDIAN -- A 32-bit number in big-endian format.\n"
+" REG_EXPAND_SZ -- A null-terminated string that contains unexpanded\n"
+" references to environment variables (for example,\n"
+" %PATH%).\n"
+" REG_LINK -- A Unicode symbolic link.\n"
+" REG_MULTI_SZ -- A sequence of null-terminated strings, terminated\n"
+" by two null characters. Note that Python handles\n"
+" this termination automatically.\n"
+" REG_NONE -- No defined value type.\n"
+" REG_QWORD -- A 64-bit number.\n"
+" REG_QWORD_LITTLE_ENDIAN -- A 64-bit number in little-endian format. Equivalent to REG_QWORD.\n"
+" REG_RESOURCE_LIST -- A device-driver resource list.\n"
+" REG_SZ -- A null-terminated string.\n"
+" value\n"
+" A string that specifies the new value.\n"
+"\n"
+"This method can also set additional value and type information for the\n"
+"specified key. The key identified by the key parameter must have been\n"
+"opened with KEY_SET_VALUE access.\n"
+"\n"
+"To open the key, use the CreateKeyEx() or OpenKeyEx() methods.\n"
+"\n"
+"Value lengths are limited by available memory. Long values (more than\n"
+"2048 bytes) should be stored as files with the filenames stored in\n"
+"the configuration registry to help the registry perform efficiently.");
+
+#define WINREG_SETVALUEEX_METHODDEF \
+ {"SetValueEx", _PyCFunction_CAST(winreg_SetValueEx), METH_FASTCALL, winreg_SetValueEx__doc__},
+
+static PyObject *
+winreg_SetValueEx_impl(PyObject *module, HKEY key,
+ const Py_UNICODE *value_name, PyObject *reserved,
+ DWORD type, PyObject *value);
+
+static PyObject *
+winreg_SetValueEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ HKEY key;
+ const Py_UNICODE *value_name = NULL;
+ PyObject *reserved;
+ DWORD type;
+ PyObject *value;
+
+ if (!_PyArg_CheckPositional("SetValueEx", nargs, 5, 5)) {
+ goto exit;
+ }
+ if (!clinic_HKEY_converter(_PyModule_GetState(module), args[0], &key)) {
+ goto exit;
+ }
+ if (args[1] == Py_None) {
+ value_name = NULL;
+ }
+ else if (PyUnicode_Check(args[1])) {
+ value_name = PyUnicode_AsWideCharString(args[1], NULL);
+ if (value_name == NULL) {
+ goto exit;
+ }
+ }
+ else {
+ _PyArg_BadArgument("SetValueEx", "argument 2", "str or None", args[1]);
+ goto exit;
+ }
+ reserved = args[2];
+ if (!_PyLong_UnsignedLong_Converter(args[3], &type)) {
+ goto exit;
+ }
+ value = args[4];
+ return_value = winreg_SetValueEx_impl(module, key, value_name, reserved, type, value);
+
+exit:
+ /* Cleanup for value_name */
+ PyMem_Free((void *)value_name);
+
+ return return_value;
+}
+
+#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */
+
+#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) && (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM))
+
+PyDoc_STRVAR(winreg_DisableReflectionKey__doc__,
+"DisableReflectionKey($module, key, /)\n"
+"--\n"
+"\n"
+"Disables registry reflection for 32bit processes running on a 64bit OS.\n"
+"\n"
+" key\n"
+" An already open key, or any one of the predefined HKEY_* constants.\n"
+"\n"
+"Will generally raise NotImplementedError if executed on a 32bit OS.\n"
+"\n"
+"If the key is not on the reflection list, the function succeeds but has\n"
+"no effect. Disabling reflection for a key does not affect reflection\n"
+"of any subkeys.");
+
+#define WINREG_DISABLEREFLECTIONKEY_METHODDEF \
+ {"DisableReflectionKey", (PyCFunction)winreg_DisableReflectionKey, METH_O, winreg_DisableReflectionKey__doc__},
+
+static PyObject *
+winreg_DisableReflectionKey_impl(PyObject *module, HKEY key);
+
+static PyObject *
+winreg_DisableReflectionKey(PyObject *module, PyObject *arg)
+{
+ PyObject *return_value = NULL;
+ HKEY key;
+
+ if (!clinic_HKEY_converter(_PyModule_GetState(module), arg, &key)) {
+ goto exit;
+ }
+ return_value = winreg_DisableReflectionKey_impl(module, key);
+
+exit:
+ return return_value;
+}
+
+#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) && (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */
+
+#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) && (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM))
+
+PyDoc_STRVAR(winreg_EnableReflectionKey__doc__,
+"EnableReflectionKey($module, key, /)\n"
+"--\n"
+"\n"
+"Restores registry reflection for the specified disabled key.\n"
+"\n"
+" key\n"
+" An already open key, or any one of the predefined HKEY_* constants.\n"
+"\n"
+"Will generally raise NotImplementedError if executed on a 32bit OS.\n"
+"Restoring reflection for a key does not affect reflection of any\n"
+"subkeys.");
+
+#define WINREG_ENABLEREFLECTIONKEY_METHODDEF \
+ {"EnableReflectionKey", (PyCFunction)winreg_EnableReflectionKey, METH_O, winreg_EnableReflectionKey__doc__},
+
+static PyObject *
+winreg_EnableReflectionKey_impl(PyObject *module, HKEY key);
+
+static PyObject *
+winreg_EnableReflectionKey(PyObject *module, PyObject *arg)
+{
+ PyObject *return_value = NULL;
+ HKEY key;
+
+ if (!clinic_HKEY_converter(_PyModule_GetState(module), arg, &key)) {
+ goto exit;
+ }
+ return_value = winreg_EnableReflectionKey_impl(module, key);
+
+exit:
+ return return_value;
+}
+
+#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) && (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */
+
+#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) && (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM))
+
+PyDoc_STRVAR(winreg_QueryReflectionKey__doc__,
+"QueryReflectionKey($module, key, /)\n"
+"--\n"
+"\n"
+"Returns the reflection state for the specified key as a bool.\n"
+"\n"
+" key\n"
+" An already open key, or any one of the predefined HKEY_* constants.\n"
+"\n"
+"Will generally raise NotImplementedError if executed on a 32bit OS.");
+
+#define WINREG_QUERYREFLECTIONKEY_METHODDEF \
+ {"QueryReflectionKey", (PyCFunction)winreg_QueryReflectionKey, METH_O, winreg_QueryReflectionKey__doc__},
+
+static PyObject *
+winreg_QueryReflectionKey_impl(PyObject *module, HKEY key);
+
+static PyObject *
+winreg_QueryReflectionKey(PyObject *module, PyObject *arg)
+{
+ PyObject *return_value = NULL;
+ HKEY key;
+
+ if (!clinic_HKEY_converter(_PyModule_GetState(module), arg, &key)) {
+ goto exit;
+ }
+ return_value = winreg_QueryReflectionKey_impl(module, key);
+
+exit:
+ return return_value;
+}
+
+#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) && (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */
+
+#ifndef WINREG_HKEYTYPE_CLOSE_METHODDEF
+ #define WINREG_HKEYTYPE_CLOSE_METHODDEF
+#endif /* !defined(WINREG_HKEYTYPE_CLOSE_METHODDEF) */
+
+#ifndef WINREG_HKEYTYPE_DETACH_METHODDEF
+ #define WINREG_HKEYTYPE_DETACH_METHODDEF
+#endif /* !defined(WINREG_HKEYTYPE_DETACH_METHODDEF) */
+
+#ifndef WINREG_HKEYTYPE___ENTER___METHODDEF
+ #define WINREG_HKEYTYPE___ENTER___METHODDEF
+#endif /* !defined(WINREG_HKEYTYPE___ENTER___METHODDEF) */
+
+#ifndef WINREG_HKEYTYPE___EXIT___METHODDEF
+ #define WINREG_HKEYTYPE___EXIT___METHODDEF
+#endif /* !defined(WINREG_HKEYTYPE___EXIT___METHODDEF) */
+
+#ifndef WINREG_CLOSEKEY_METHODDEF
+ #define WINREG_CLOSEKEY_METHODDEF
+#endif /* !defined(WINREG_CLOSEKEY_METHODDEF) */
+
+#ifndef WINREG_CONNECTREGISTRY_METHODDEF
+ #define WINREG_CONNECTREGISTRY_METHODDEF
+#endif /* !defined(WINREG_CONNECTREGISTRY_METHODDEF) */
+
+#ifndef WINREG_CREATEKEY_METHODDEF
+ #define WINREG_CREATEKEY_METHODDEF
+#endif /* !defined(WINREG_CREATEKEY_METHODDEF) */
+
+#ifndef WINREG_CREATEKEYEX_METHODDEF
+ #define WINREG_CREATEKEYEX_METHODDEF
+#endif /* !defined(WINREG_CREATEKEYEX_METHODDEF) */
+
+#ifndef WINREG_DELETEKEY_METHODDEF
+ #define WINREG_DELETEKEY_METHODDEF
+#endif /* !defined(WINREG_DELETEKEY_METHODDEF) */
+
+#ifndef WINREG_DELETEKEYEX_METHODDEF
+ #define WINREG_DELETEKEYEX_METHODDEF
+#endif /* !defined(WINREG_DELETEKEYEX_METHODDEF) */
+
+#ifndef WINREG_DELETEVALUE_METHODDEF
+ #define WINREG_DELETEVALUE_METHODDEF
+#endif /* !defined(WINREG_DELETEVALUE_METHODDEF) */
+
+#ifndef WINREG_ENUMKEY_METHODDEF
+ #define WINREG_ENUMKEY_METHODDEF
+#endif /* !defined(WINREG_ENUMKEY_METHODDEF) */
+
+#ifndef WINREG_ENUMVALUE_METHODDEF
+ #define WINREG_ENUMVALUE_METHODDEF
+#endif /* !defined(WINREG_ENUMVALUE_METHODDEF) */
+
+#ifndef WINREG_EXPANDENVIRONMENTSTRINGS_METHODDEF
+ #define WINREG_EXPANDENVIRONMENTSTRINGS_METHODDEF
+#endif /* !defined(WINREG_EXPANDENVIRONMENTSTRINGS_METHODDEF) */
+
+#ifndef WINREG_FLUSHKEY_METHODDEF
+ #define WINREG_FLUSHKEY_METHODDEF
+#endif /* !defined(WINREG_FLUSHKEY_METHODDEF) */
+
+#ifndef WINREG_LOADKEY_METHODDEF
+ #define WINREG_LOADKEY_METHODDEF
+#endif /* !defined(WINREG_LOADKEY_METHODDEF) */
+
+#ifndef WINREG_OPENKEY_METHODDEF
+ #define WINREG_OPENKEY_METHODDEF
+#endif /* !defined(WINREG_OPENKEY_METHODDEF) */
+
+#ifndef WINREG_OPENKEYEX_METHODDEF
+ #define WINREG_OPENKEYEX_METHODDEF
+#endif /* !defined(WINREG_OPENKEYEX_METHODDEF) */
+
+#ifndef WINREG_QUERYINFOKEY_METHODDEF
+ #define WINREG_QUERYINFOKEY_METHODDEF
+#endif /* !defined(WINREG_QUERYINFOKEY_METHODDEF) */
+
+#ifndef WINREG_QUERYVALUE_METHODDEF
+ #define WINREG_QUERYVALUE_METHODDEF
+#endif /* !defined(WINREG_QUERYVALUE_METHODDEF) */
+
+#ifndef WINREG_QUERYVALUEEX_METHODDEF
+ #define WINREG_QUERYVALUEEX_METHODDEF
+#endif /* !defined(WINREG_QUERYVALUEEX_METHODDEF) */
+
+#ifndef WINREG_SAVEKEY_METHODDEF
+ #define WINREG_SAVEKEY_METHODDEF
+#endif /* !defined(WINREG_SAVEKEY_METHODDEF) */
+
+#ifndef WINREG_SETVALUE_METHODDEF
+ #define WINREG_SETVALUE_METHODDEF
+#endif /* !defined(WINREG_SETVALUE_METHODDEF) */
+
+#ifndef WINREG_SETVALUEEX_METHODDEF
+ #define WINREG_SETVALUEEX_METHODDEF
+#endif /* !defined(WINREG_SETVALUEEX_METHODDEF) */
+
+#ifndef WINREG_DISABLEREFLECTIONKEY_METHODDEF
+ #define WINREG_DISABLEREFLECTIONKEY_METHODDEF
+#endif /* !defined(WINREG_DISABLEREFLECTIONKEY_METHODDEF) */
+
+#ifndef WINREG_ENABLEREFLECTIONKEY_METHODDEF
+ #define WINREG_ENABLEREFLECTIONKEY_METHODDEF
+#endif /* !defined(WINREG_ENABLEREFLECTIONKEY_METHODDEF) */
+
+#ifndef WINREG_QUERYREFLECTIONKEY_METHODDEF
+ #define WINREG_QUERYREFLECTIONKEY_METHODDEF
+#endif /* !defined(WINREG_QUERYREFLECTIONKEY_METHODDEF) */
+/*[clinic end generated code: output=15dc2e6c4d4e2ad5 input=a9049054013a1b77]*/
diff --git a/contrib/tools/python3/PC/clinic/winsound.c.h b/contrib/tools/python3/PC/clinic/winsound.c.h
new file mode 100644
index 00000000000..241d547c267
--- /dev/null
+++ b/contrib/tools/python3/PC/clinic/winsound.c.h
@@ -0,0 +1,209 @@
+/*[clinic input]
+preserve
+[clinic start generated code]*/
+
+#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
+#endif
+
+
+PyDoc_STRVAR(winsound_PlaySound__doc__,
+"PlaySound($module, /, sound, flags)\n"
+"--\n"
+"\n"
+"A wrapper around the Windows PlaySound API.\n"
+"\n"
+" sound\n"
+" The sound to play; a filename, data, or None.\n"
+" flags\n"
+" Flag values, ored together. See module documentation.");
+
+#define WINSOUND_PLAYSOUND_METHODDEF \
+ {"PlaySound", _PyCFunction_CAST(winsound_PlaySound), METH_FASTCALL|METH_KEYWORDS, winsound_PlaySound__doc__},
+
+static PyObject *
+winsound_PlaySound_impl(PyObject *module, PyObject *sound, int flags);
+
+static PyObject *
+winsound_PlaySound(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+{
+ PyObject *return_value = NULL;
+ #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
+
+ #define NUM_KEYWORDS 2
+ static struct {
+ PyGC_Head _this_is_not_used;
+ PyObject_VAR_HEAD
+ PyObject *ob_item[NUM_KEYWORDS];
+ } _kwtuple = {
+ .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
+ .ob_item = { &_Py_ID(sound), &_Py_ID(flags), },
+ };
+ #undef NUM_KEYWORDS
+ #define KWTUPLE (&_kwtuple.ob_base.ob_base)
+
+ #else // !Py_BUILD_CORE
+ # define KWTUPLE NULL
+ #endif // !Py_BUILD_CORE
+
+ static const char * const _keywords[] = {"sound", "flags", NULL};
+ static _PyArg_Parser _parser = {
+ .keywords = _keywords,
+ .fname = "PlaySound",
+ .kwtuple = KWTUPLE,
+ };
+ #undef KWTUPLE
+ PyObject *argsbuf[2];
+ PyObject *sound;
+ int flags;
+
+ args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
+ if (!args) {
+ goto exit;
+ }
+ sound = args[0];
+ flags = _PyLong_AsInt(args[1]);
+ if (flags == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ return_value = winsound_PlaySound_impl(module, sound, flags);
+
+exit:
+ return return_value;
+}
+
+PyDoc_STRVAR(winsound_Beep__doc__,
+"Beep($module, /, frequency, duration)\n"
+"--\n"
+"\n"
+"A wrapper around the Windows Beep API.\n"
+"\n"
+" frequency\n"
+" Frequency of the sound in hertz.\n"
+" Must be in the range 37 through 32,767.\n"
+" duration\n"
+" How long the sound should play, in milliseconds.");
+
+#define WINSOUND_BEEP_METHODDEF \
+ {"Beep", _PyCFunction_CAST(winsound_Beep), METH_FASTCALL|METH_KEYWORDS, winsound_Beep__doc__},
+
+static PyObject *
+winsound_Beep_impl(PyObject *module, int frequency, int duration);
+
+static PyObject *
+winsound_Beep(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+{
+ PyObject *return_value = NULL;
+ #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
+
+ #define NUM_KEYWORDS 2
+ static struct {
+ PyGC_Head _this_is_not_used;
+ PyObject_VAR_HEAD
+ PyObject *ob_item[NUM_KEYWORDS];
+ } _kwtuple = {
+ .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
+ .ob_item = { &_Py_ID(frequency), &_Py_ID(duration), },
+ };
+ #undef NUM_KEYWORDS
+ #define KWTUPLE (&_kwtuple.ob_base.ob_base)
+
+ #else // !Py_BUILD_CORE
+ # define KWTUPLE NULL
+ #endif // !Py_BUILD_CORE
+
+ static const char * const _keywords[] = {"frequency", "duration", NULL};
+ static _PyArg_Parser _parser = {
+ .keywords = _keywords,
+ .fname = "Beep",
+ .kwtuple = KWTUPLE,
+ };
+ #undef KWTUPLE
+ PyObject *argsbuf[2];
+ int frequency;
+ int duration;
+
+ args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
+ if (!args) {
+ goto exit;
+ }
+ frequency = _PyLong_AsInt(args[0]);
+ if (frequency == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ duration = _PyLong_AsInt(args[1]);
+ if (duration == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ return_value = winsound_Beep_impl(module, frequency, duration);
+
+exit:
+ return return_value;
+}
+
+PyDoc_STRVAR(winsound_MessageBeep__doc__,
+"MessageBeep($module, /, type=MB_OK)\n"
+"--\n"
+"\n"
+"Call Windows MessageBeep(x).\n"
+"\n"
+"x defaults to MB_OK.");
+
+#define WINSOUND_MESSAGEBEEP_METHODDEF \
+ {"MessageBeep", _PyCFunction_CAST(winsound_MessageBeep), METH_FASTCALL|METH_KEYWORDS, winsound_MessageBeep__doc__},
+
+static PyObject *
+winsound_MessageBeep_impl(PyObject *module, int type);
+
+static PyObject *
+winsound_MessageBeep(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+{
+ PyObject *return_value = NULL;
+ #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
+
+ #define NUM_KEYWORDS 1
+ static struct {
+ PyGC_Head _this_is_not_used;
+ PyObject_VAR_HEAD
+ PyObject *ob_item[NUM_KEYWORDS];
+ } _kwtuple = {
+ .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
+ .ob_item = { &_Py_ID(type), },
+ };
+ #undef NUM_KEYWORDS
+ #define KWTUPLE (&_kwtuple.ob_base.ob_base)
+
+ #else // !Py_BUILD_CORE
+ # define KWTUPLE NULL
+ #endif // !Py_BUILD_CORE
+
+ static const char * const _keywords[] = {"type", NULL};
+ static _PyArg_Parser _parser = {
+ .keywords = _keywords,
+ .fname = "MessageBeep",
+ .kwtuple = KWTUPLE,
+ };
+ #undef KWTUPLE
+ PyObject *argsbuf[1];
+ Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
+ int type = MB_OK;
+
+ args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
+ if (!args) {
+ goto exit;
+ }
+ if (!noptargs) {
+ goto skip_optional_pos;
+ }
+ type = _PyLong_AsInt(args[0]);
+ if (type == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+skip_optional_pos:
+ return_value = winsound_MessageBeep_impl(module, type);
+
+exit:
+ return return_value;
+}
+/*[clinic end generated code: output=f70b7730127208d8 input=a9049054013a1b77]*/
diff --git a/contrib/tools/python3/PC/errmap.h b/contrib/tools/python3/PC/errmap.h
new file mode 100644
index 00000000000..a7489ab75c6
--- /dev/null
+++ b/contrib/tools/python3/PC/errmap.h
@@ -0,0 +1,140 @@
+int
+winerror_to_errno(int winerror)
+{
+ // Unwrap FACILITY_WIN32 HRESULT errors.
+ if ((winerror & 0xFFFF0000) == 0x80070000) {
+ winerror &= 0x0000FFFF;
+ }
+
+ // Winsock error codes (10000-11999) are errno values.
+ if (winerror >= 10000 && winerror < 12000) {
+ switch (winerror) {
+ case WSAEINTR:
+ case WSAEBADF:
+ case WSAEACCES:
+ case WSAEFAULT:
+ case WSAEINVAL:
+ case WSAEMFILE:
+ // Winsock definitions of errno values. See WinSock2.h
+ return winerror - 10000;
+ default:
+ return winerror;
+ }
+ }
+
+ switch (winerror) {
+ case ERROR_FILE_NOT_FOUND: // 2
+ case ERROR_PATH_NOT_FOUND: // 3
+ case ERROR_INVALID_DRIVE: // 15
+ case ERROR_NO_MORE_FILES: // 18
+ case ERROR_BAD_NETPATH: // 53
+ case ERROR_BAD_NET_NAME: // 67
+ case ERROR_BAD_PATHNAME: // 161
+ case ERROR_FILENAME_EXCED_RANGE: // 206
+ return ENOENT;
+
+ case ERROR_BAD_ENVIRONMENT: // 10
+ return E2BIG;
+
+ case ERROR_BAD_FORMAT: // 11
+ case ERROR_INVALID_STARTING_CODESEG: // 188
+ case ERROR_INVALID_STACKSEG: // 189
+ case ERROR_INVALID_MODULETYPE: // 190
+ case ERROR_INVALID_EXE_SIGNATURE: // 191
+ case ERROR_EXE_MARKED_INVALID: // 192
+ case ERROR_BAD_EXE_FORMAT: // 193
+ case ERROR_ITERATED_DATA_EXCEEDS_64k: // 194
+ case ERROR_INVALID_MINALLOCSIZE: // 195
+ case ERROR_DYNLINK_FROM_INVALID_RING: // 196
+ case ERROR_IOPL_NOT_ENABLED: // 197
+ case ERROR_INVALID_SEGDPL: // 198
+ case ERROR_AUTODATASEG_EXCEEDS_64k: // 199
+ case ERROR_RING2SEG_MUST_BE_MOVABLE: // 200
+ case ERROR_RELOC_CHAIN_XEEDS_SEGLIM: // 201
+ case ERROR_INFLOOP_IN_RELOC_CHAIN: // 202
+ return ENOEXEC;
+
+ case ERROR_INVALID_HANDLE: // 6
+ case ERROR_INVALID_TARGET_HANDLE: // 114
+ case ERROR_DIRECT_ACCESS_HANDLE: // 130
+ return EBADF;
+
+ case ERROR_WAIT_NO_CHILDREN: // 128
+ case ERROR_CHILD_NOT_COMPLETE: // 129
+ return ECHILD;
+
+ case ERROR_NO_PROC_SLOTS: // 89
+ case ERROR_MAX_THRDS_REACHED: // 164
+ case ERROR_NESTING_NOT_ALLOWED: // 215
+ return EAGAIN;
+
+ case ERROR_ARENA_TRASHED: // 7
+ case ERROR_NOT_ENOUGH_MEMORY: // 8
+ case ERROR_INVALID_BLOCK: // 9
+ case ERROR_NOT_ENOUGH_QUOTA: // 1816
+ return ENOMEM;
+
+ case ERROR_ACCESS_DENIED: // 5
+ case ERROR_CURRENT_DIRECTORY: // 16
+ case ERROR_WRITE_PROTECT: // 19
+ case ERROR_BAD_UNIT: // 20
+ case ERROR_NOT_READY: // 21
+ case ERROR_BAD_COMMAND: // 22
+ case ERROR_CRC: // 23
+ case ERROR_BAD_LENGTH: // 24
+ case ERROR_SEEK: // 25
+ case ERROR_NOT_DOS_DISK: // 26
+ case ERROR_SECTOR_NOT_FOUND: // 27
+ case ERROR_OUT_OF_PAPER: // 28
+ case ERROR_WRITE_FAULT: // 29
+ case ERROR_READ_FAULT: // 30
+ case ERROR_GEN_FAILURE: // 31
+ case ERROR_SHARING_VIOLATION: // 32
+ case ERROR_LOCK_VIOLATION: // 33
+ case ERROR_WRONG_DISK: // 34
+ case ERROR_SHARING_BUFFER_EXCEEDED: // 36
+ case ERROR_NETWORK_ACCESS_DENIED: // 65
+ case ERROR_CANNOT_MAKE: // 82
+ case ERROR_FAIL_I24: // 83
+ case ERROR_DRIVE_LOCKED: // 108
+ case ERROR_SEEK_ON_DEVICE: // 132
+ case ERROR_NOT_LOCKED: // 158
+ case ERROR_LOCK_FAILED: // 167
+ case 35: // 35 (undefined)
+ return EACCES;
+
+ case ERROR_FILE_EXISTS: // 80
+ case ERROR_ALREADY_EXISTS: // 183
+ return EEXIST;
+
+ case ERROR_NOT_SAME_DEVICE: // 17
+ return EXDEV;
+
+ case ERROR_DIRECTORY: // 267 (bpo-12802)
+ return ENOTDIR;
+
+ case ERROR_TOO_MANY_OPEN_FILES: // 4
+ return EMFILE;
+
+ case ERROR_DISK_FULL: // 112
+ return ENOSPC;
+
+ case ERROR_BROKEN_PIPE: // 109
+ case ERROR_NO_DATA: // 232 (bpo-13063)
+ return EPIPE;
+
+ case ERROR_DIR_NOT_EMPTY: // 145
+ return ENOTEMPTY;
+
+ case ERROR_NO_UNICODE_TRANSLATION: // 1113
+ return EILSEQ;
+
+ case ERROR_INVALID_FUNCTION: // 1
+ case ERROR_INVALID_ACCESS: // 12
+ case ERROR_INVALID_DATA: // 13
+ case ERROR_INVALID_PARAMETER: // 87
+ case ERROR_NEGATIVE_SEEK: // 131
+ default:
+ return EINVAL;
+ }
+}
diff --git a/contrib/tools/python3/PC/invalid_parameter_handler.c b/contrib/tools/python3/PC/invalid_parameter_handler.c
new file mode 100644
index 00000000000..d634710cbec
--- /dev/null
+++ b/contrib/tools/python3/PC/invalid_parameter_handler.c
@@ -0,0 +1,22 @@
+#ifdef _MSC_VER
+
+#include <stdlib.h>
+
+#if _MSC_VER >= 1900
+/* pyconfig.h uses this function in the _Py_BEGIN/END_SUPPRESS_IPH
+ * macros. It does not need to be defined when building using MSVC
+ * earlier than 14.0 (_MSC_VER == 1900).
+ */
+
+static void __cdecl _silent_invalid_parameter_handler(
+ wchar_t const* expression,
+ wchar_t const* function,
+ wchar_t const* file,
+ unsigned int line,
+ uintptr_t pReserved) { }
+
+_invalid_parameter_handler _Py_silent_invalid_parameter_handler = _silent_invalid_parameter_handler;
+
+#endif
+
+#endif
diff --git a/contrib/tools/python3/PC/msvcrtmodule.c b/contrib/tools/python3/PC/msvcrtmodule.c
new file mode 100644
index 00000000000..53ef26b732f
--- /dev/null
+++ b/contrib/tools/python3/PC/msvcrtmodule.c
@@ -0,0 +1,679 @@
+/*********************************************************
+
+ msvcrtmodule.c
+
+ A Python interface to the Microsoft Visual C Runtime
+ Library, providing access to those non-portable, but
+ still useful routines.
+
+ Only ever compiled with an MS compiler, so no attempt
+ has been made to avoid MS language extensions, etc...
+
+ This may only work on NT or 95...
+
+ Author: Mark Hammond and Guido van Rossum.
+ Maintenance: Guido van Rossum.
+
+***********************************************************/
+
+#include "Python.h"
+#include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH
+#include "malloc.h"
+#include <io.h>
+#include <conio.h>
+#include <sys/locking.h>
+#include <crtdbg.h>
+#include <windows.h>
+
+#ifdef _MSC_VER
+#if _MSC_VER >= 1500 && _MSC_VER < 1600
+#include <crtassem.h>
+#elif _MSC_VER >= 1600
+#include <crtversion.h>
+#endif
+#endif
+
+/*[python input]
+class HANDLE_converter(CConverter):
+ type = 'void *'
+ format_unit = '"_Py_PARSE_UINTPTR"'
+
+ def parse_arg(self, argname, displayname):
+ return """
+ {paramname} = PyLong_AsVoidPtr({argname});
+ if (!{paramname} && PyErr_Occurred()) {{{{
+ goto exit;
+ }}}}
+ """.format(argname=argname, paramname=self.parser_name)
+
+class HANDLE_return_converter(CReturnConverter):
+ type = 'void *'
+
+ def render(self, function, data):
+ self.declare(data)
+ self.err_occurred_if(
+ "_return_value == NULL || _return_value == INVALID_HANDLE_VALUE",
+ data)
+ data.return_conversion.append(
+ 'return_value = PyLong_FromVoidPtr(_return_value);\n')
+
+class byte_char_return_converter(CReturnConverter):
+ type = 'int'
+
+ def render(self, function, data):
+ data.declarations.append('char s[1];')
+ data.return_value = 's[0]'
+ data.return_conversion.append(
+ 'return_value = PyBytes_FromStringAndSize(s, 1);\n')
+
+class wchar_t_return_converter(CReturnConverter):
+ type = 'wchar_t'
+
+ def render(self, function, data):
+ self.declare(data)
+ data.return_conversion.append(
+ 'return_value = PyUnicode_FromOrdinal(_return_value);\n')
+[python start generated code]*/
+/*[python end generated code: output=da39a3ee5e6b4b0d input=1e8e9fa3538ec08f]*/
+
+/*[clinic input]
+module msvcrt
+[clinic start generated code]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=f31a87a783d036cd]*/
+
+#include "clinic/msvcrtmodule.c.h"
+
+/*[clinic input]
+msvcrt.heapmin
+
+Minimize the malloc() heap.
+
+Force the malloc() heap to clean itself up and return unused blocks
+to the operating system. On failure, this raises OSError.
+[clinic start generated code]*/
+
+static PyObject *
+msvcrt_heapmin_impl(PyObject *module)
+/*[clinic end generated code: output=1ba00f344782dc19 input=82e1771d21bde2d8]*/
+{
+ if (_heapmin() != 0)
+ return PyErr_SetFromErrno(PyExc_OSError);
+
+ Py_RETURN_NONE;
+}
+/*[clinic input]
+msvcrt.locking
+
+ fd: int
+ mode: int
+ nbytes: long
+ /
+
+Lock part of a file based on file descriptor fd from the C runtime.
+
+Raises OSError on failure. The locked region of the file extends from
+the current file position for nbytes bytes, and may continue beyond
+the end of the file. mode must be one of the LK_* constants listed
+below. Multiple regions in a file may be locked at the same time, but
+may not overlap. Adjacent regions are not merged; they must be unlocked
+individually.
+[clinic start generated code]*/
+
+static PyObject *
+msvcrt_locking_impl(PyObject *module, int fd, int mode, long nbytes)
+/*[clinic end generated code: output=a4a90deca9785a03 input=e97bd15fc4a04fef]*/
+{
+ int err;
+
+ if (PySys_Audit("msvcrt.locking", "iil", fd, mode, nbytes) < 0) {
+ return NULL;
+ }
+
+ Py_BEGIN_ALLOW_THREADS
+ _Py_BEGIN_SUPPRESS_IPH
+ err = _locking(fd, mode, nbytes);
+ _Py_END_SUPPRESS_IPH
+ Py_END_ALLOW_THREADS
+ if (err != 0)
+ return PyErr_SetFromErrno(PyExc_OSError);
+
+ Py_RETURN_NONE;
+}
+
+/*[clinic input]
+msvcrt.setmode -> long
+
+ fd: int
+ mode as flags: int
+ /
+
+Set the line-end translation mode for the file descriptor fd.
+
+To set it to text mode, flags should be os.O_TEXT; for binary, it
+should be os.O_BINARY.
+
+Return value is the previous mode.
+[clinic start generated code]*/
+
+static long
+msvcrt_setmode_impl(PyObject *module, int fd, int flags)
+/*[clinic end generated code: output=24a9be5ea07ccb9b input=76e7c01f6b137f75]*/
+{
+ _Py_BEGIN_SUPPRESS_IPH
+ flags = _setmode(fd, flags);
+ _Py_END_SUPPRESS_IPH
+ if (flags == -1)
+ PyErr_SetFromErrno(PyExc_OSError);
+
+ return flags;
+}
+
+/*[clinic input]
+msvcrt.open_osfhandle -> long
+
+ handle: HANDLE
+ flags: int
+ /
+
+Create a C runtime file descriptor from the file handle handle.
+
+The flags parameter should be a bitwise OR of os.O_APPEND, os.O_RDONLY,
+and os.O_TEXT. The returned file descriptor may be used as a parameter
+to os.fdopen() to create a file object.
+[clinic start generated code]*/
+
+static long
+msvcrt_open_osfhandle_impl(PyObject *module, void *handle, int flags)
+/*[clinic end generated code: output=b2fb97c4b515e4e6 input=d5db190a307cf4bb]*/
+{
+ if (PySys_Audit("msvcrt.open_osfhandle", "Ki", handle, flags) < 0) {
+ return -1;
+ }
+
+ return _Py_open_osfhandle(handle, flags);
+}
+
+/*[clinic input]
+msvcrt.get_osfhandle -> HANDLE
+
+ fd: int
+ /
+
+Return the file handle for the file descriptor fd.
+
+Raises OSError if fd is not recognized.
+[clinic start generated code]*/
+
+static void *
+msvcrt_get_osfhandle_impl(PyObject *module, int fd)
+/*[clinic end generated code: output=aca01dfe24637374 input=5fcfde9b17136aa2]*/
+{
+ if (PySys_Audit("msvcrt.get_osfhandle", "(i)", fd) < 0) {
+ return NULL;
+ }
+
+ return _Py_get_osfhandle(fd);
+}
+
+/* Console I/O */
+/*[clinic input]
+msvcrt.kbhit -> long
+
+Return true if a keypress is waiting to be read.
+[clinic start generated code]*/
+
+static long
+msvcrt_kbhit_impl(PyObject *module)
+/*[clinic end generated code: output=940dfce6587c1890 input=e70d678a5c2f6acc]*/
+{
+ return _kbhit();
+}
+
+/*[clinic input]
+msvcrt.getch -> byte_char
+
+Read a keypress and return the resulting character as a byte string.
+
+Nothing is echoed to the console. This call will block if a keypress is
+not already available, but will not wait for Enter to be pressed. If the
+pressed key was a special function key, this will return '\000' or
+'\xe0'; the next call will return the keycode. The Control-C keypress
+cannot be read with this function.
+[clinic start generated code]*/
+
+static int
+msvcrt_getch_impl(PyObject *module)
+/*[clinic end generated code: output=a4e51f0565064a7d input=37a40cf0ed0d1153]*/
+{
+ int ch;
+
+ Py_BEGIN_ALLOW_THREADS
+ ch = _getch();
+ Py_END_ALLOW_THREADS
+ return ch;
+}
+
+#ifdef MS_WINDOWS_DESKTOP
+
+/*[clinic input]
+msvcrt.getwch -> wchar_t
+
+Wide char variant of getch(), returning a Unicode value.
+[clinic start generated code]*/
+
+static wchar_t
+msvcrt_getwch_impl(PyObject *module)
+/*[clinic end generated code: output=be9937494e22f007 input=27b3dec8ad823d7c]*/
+{
+ wchar_t ch;
+
+ Py_BEGIN_ALLOW_THREADS
+ ch = _getwch();
+ Py_END_ALLOW_THREADS
+ return ch;
+}
+
+#endif /* MS_WINDOWS_DESKTOP */
+
+/*[clinic input]
+msvcrt.getche -> byte_char
+
+Similar to getch(), but the keypress will be echoed if possible.
+[clinic start generated code]*/
+
+static int
+msvcrt_getche_impl(PyObject *module)
+/*[clinic end generated code: output=d8f7db4fd2990401 input=43311ade9ed4a9c0]*/
+{
+ int ch;
+
+ Py_BEGIN_ALLOW_THREADS
+ ch = _getche();
+ Py_END_ALLOW_THREADS
+ return ch;
+}
+
+#ifdef MS_WINDOWS_DESKTOP
+
+/*[clinic input]
+msvcrt.getwche -> wchar_t
+
+Wide char variant of getche(), returning a Unicode value.
+[clinic start generated code]*/
+
+static wchar_t
+msvcrt_getwche_impl(PyObject *module)
+/*[clinic end generated code: output=d0dae5ba3829d596 input=49337d59d1a591f8]*/
+{
+ wchar_t ch;
+
+ Py_BEGIN_ALLOW_THREADS
+ ch = _getwche();
+ Py_END_ALLOW_THREADS
+ return ch;
+}
+
+#endif /* MS_WINDOWS_DESKTOP */
+
+/*[clinic input]
+msvcrt.putch
+
+ char: char
+ /
+
+Print the byte string char to the console without buffering.
+[clinic start generated code]*/
+
+static PyObject *
+msvcrt_putch_impl(PyObject *module, char char_value)
+/*[clinic end generated code: output=92ec9b81012d8f60 input=ec078dd10cb054d6]*/
+{
+ _Py_BEGIN_SUPPRESS_IPH
+ _putch(char_value);
+ _Py_END_SUPPRESS_IPH
+ Py_RETURN_NONE;
+}
+
+#ifdef MS_WINDOWS_DESKTOP
+
+/*[clinic input]
+msvcrt.putwch
+
+ unicode_char: int(accept={str})
+ /
+
+Wide char variant of putch(), accepting a Unicode value.
+[clinic start generated code]*/
+
+static PyObject *
+msvcrt_putwch_impl(PyObject *module, int unicode_char)
+/*[clinic end generated code: output=a3bd1a8951d28eee input=996ccd0bbcbac4c3]*/
+{
+ _Py_BEGIN_SUPPRESS_IPH
+ _putwch(unicode_char);
+ _Py_END_SUPPRESS_IPH
+ Py_RETURN_NONE;
+
+}
+
+#endif /* MS_WINDOWS_DESKTOP */
+
+/*[clinic input]
+msvcrt.ungetch
+
+ char: char
+ /
+
+Opposite of getch.
+
+Cause the byte string char to be "pushed back" into the
+console buffer; it will be the next character read by
+getch() or getche().
+[clinic start generated code]*/
+
+static PyObject *
+msvcrt_ungetch_impl(PyObject *module, char char_value)
+/*[clinic end generated code: output=c6942a0efa119000 input=22f07ee9001bbf0f]*/
+{
+ int res;
+
+ _Py_BEGIN_SUPPRESS_IPH
+ res = _ungetch(char_value);
+ _Py_END_SUPPRESS_IPH
+
+ if (res == EOF)
+ return PyErr_SetFromErrno(PyExc_OSError);
+ Py_RETURN_NONE;
+}
+
+#ifdef MS_WINDOWS_DESKTOP
+
+/*[clinic input]
+msvcrt.ungetwch
+
+ unicode_char: int(accept={str})
+ /
+
+Wide char variant of ungetch(), accepting a Unicode value.
+[clinic start generated code]*/
+
+static PyObject *
+msvcrt_ungetwch_impl(PyObject *module, int unicode_char)
+/*[clinic end generated code: output=e63af05438b8ba3d input=83ec0492be04d564]*/
+{
+ int res;
+
+ _Py_BEGIN_SUPPRESS_IPH
+ res = _ungetwch(unicode_char);
+ _Py_END_SUPPRESS_IPH
+
+ if (res == WEOF)
+ return PyErr_SetFromErrno(PyExc_OSError);
+ Py_RETURN_NONE;
+}
+
+#endif /* MS_WINDOWS_DESKTOP */
+
+#ifdef _DEBUG
+/*[clinic input]
+msvcrt.CrtSetReportFile -> HANDLE
+
+ type: int
+ file: HANDLE
+ /
+
+Wrapper around _CrtSetReportFile.
+
+Only available on Debug builds.
+[clinic start generated code]*/
+
+static void *
+msvcrt_CrtSetReportFile_impl(PyObject *module, int type, void *file)
+/*[clinic end generated code: output=9393e8c77088bbe9 input=290809b5f19e65b9]*/
+{
+ HANDLE res;
+
+ _Py_BEGIN_SUPPRESS_IPH
+ res = _CrtSetReportFile(type, file);
+ _Py_END_SUPPRESS_IPH
+
+ return res;
+}
+
+/*[clinic input]
+msvcrt.CrtSetReportMode -> long
+
+ type: int
+ mode: int
+ /
+
+Wrapper around _CrtSetReportMode.
+
+Only available on Debug builds.
+[clinic start generated code]*/
+
+static long
+msvcrt_CrtSetReportMode_impl(PyObject *module, int type, int mode)
+/*[clinic end generated code: output=b2863761523de317 input=9319d29b4319426b]*/
+{
+ int res;
+
+ _Py_BEGIN_SUPPRESS_IPH
+ res = _CrtSetReportMode(type, mode);
+ _Py_END_SUPPRESS_IPH
+ if (res == -1)
+ PyErr_SetFromErrno(PyExc_OSError);
+ return res;
+}
+
+/*[clinic input]
+msvcrt.set_error_mode -> long
+
+ mode: int
+ /
+
+Wrapper around _set_error_mode.
+
+Only available on Debug builds.
+[clinic start generated code]*/
+
+static long
+msvcrt_set_error_mode_impl(PyObject *module, int mode)
+/*[clinic end generated code: output=ac4a09040d8ac4e3 input=046fca59c0f20872]*/
+{
+ long res;
+
+ _Py_BEGIN_SUPPRESS_IPH
+ res = _set_error_mode(mode);
+ _Py_END_SUPPRESS_IPH
+
+ return res;
+}
+#endif /* _DEBUG */
+
+#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)
+
+/*[clinic input]
+msvcrt.GetErrorMode
+
+Wrapper around GetErrorMode.
+[clinic start generated code]*/
+
+static PyObject *
+msvcrt_GetErrorMode_impl(PyObject *module)
+/*[clinic end generated code: output=3103fc6145913591 input=5a7fb083b6dd71fd]*/
+{
+ unsigned int res;
+
+ _Py_BEGIN_SUPPRESS_IPH
+ res = GetErrorMode();
+ _Py_END_SUPPRESS_IPH
+
+ return PyLong_FromUnsignedLong(res);
+}
+
+#endif /* MS_WINDOWS_APP || MS_WINDOWS_SYSTEM */
+
+/*[clinic input]
+msvcrt.SetErrorMode
+
+ mode: unsigned_int(bitwise=True)
+ /
+
+Wrapper around SetErrorMode.
+[clinic start generated code]*/
+
+static PyObject *
+msvcrt_SetErrorMode_impl(PyObject *module, unsigned int mode)
+/*[clinic end generated code: output=01d529293f00da8f input=d8b167258d32d907]*/
+{
+ unsigned int res;
+
+ _Py_BEGIN_SUPPRESS_IPH
+ res = SetErrorMode(mode);
+ _Py_END_SUPPRESS_IPH
+
+ return PyLong_FromUnsignedLong(res);
+}
+
+/*[clinic input]
+[clinic start generated code]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=da39a3ee5e6b4b0d]*/
+
+/* List of functions exported by this module */
+static struct PyMethodDef msvcrt_functions[] = {
+ MSVCRT_HEAPMIN_METHODDEF
+ MSVCRT_LOCKING_METHODDEF
+ MSVCRT_SETMODE_METHODDEF
+ MSVCRT_OPEN_OSFHANDLE_METHODDEF
+ MSVCRT_GET_OSFHANDLE_METHODDEF
+ MSVCRT_KBHIT_METHODDEF
+ MSVCRT_GETCH_METHODDEF
+ MSVCRT_GETCHE_METHODDEF
+ MSVCRT_PUTCH_METHODDEF
+ MSVCRT_UNGETCH_METHODDEF
+ MSVCRT_GETERRORMODE_METHODDEF
+ MSVCRT_SETERRORMODE_METHODDEF
+ MSVCRT_CRTSETREPORTFILE_METHODDEF
+ MSVCRT_CRTSETREPORTMODE_METHODDEF
+ MSVCRT_SET_ERROR_MODE_METHODDEF
+ MSVCRT_GETWCH_METHODDEF
+ MSVCRT_GETWCHE_METHODDEF
+ MSVCRT_PUTWCH_METHODDEF
+ MSVCRT_UNGETWCH_METHODDEF
+ {NULL, NULL}
+};
+
+static int
+insertptr(PyObject *mod, char *name, void *value)
+{
+ PyObject *v = PyLong_FromVoidPtr(value);
+ if (v == NULL) {
+ return -1;
+ }
+ int rc = PyModule_AddObjectRef(mod, name, v);
+ Py_DECREF(v);
+ return rc;
+}
+
+#define INSERTINT(MOD, NAME, VAL) do { \
+ if (PyModule_AddIntConstant(MOD, NAME, VAL) < 0) { \
+ return -1; \
+ } \
+} while (0)
+
+#define INSERTPTR(MOD, NAME, PTR) do { \
+ if (insertptr(MOD, NAME, PTR) < 0) { \
+ return -1; \
+ } \
+} while (0)
+
+#define INSERTSTR(MOD, NAME, CONST) do { \
+ if (PyModule_AddStringConstant(MOD, NAME, CONST) < 0) { \
+ return -1; \
+ } \
+} while (0)
+
+static int
+exec_module(PyObject* m)
+{
+ /* constants for the locking() function's mode argument */
+ INSERTINT(m, "LK_LOCK", _LK_LOCK);
+ INSERTINT(m, "LK_NBLCK", _LK_NBLCK);
+ INSERTINT(m, "LK_NBRLCK", _LK_NBRLCK);
+ INSERTINT(m, "LK_RLCK", _LK_RLCK);
+ INSERTINT(m, "LK_UNLCK", _LK_UNLCK);
+#ifdef MS_WINDOWS_DESKTOP
+ INSERTINT(m, "SEM_FAILCRITICALERRORS", SEM_FAILCRITICALERRORS);
+ INSERTINT(m, "SEM_NOALIGNMENTFAULTEXCEPT", SEM_NOALIGNMENTFAULTEXCEPT);
+ INSERTINT(m, "SEM_NOGPFAULTERRORBOX", SEM_NOGPFAULTERRORBOX);
+ INSERTINT(m, "SEM_NOOPENFILEERRORBOX", SEM_NOOPENFILEERRORBOX);
+#endif
+#ifdef _DEBUG
+ INSERTINT(m, "CRT_WARN", _CRT_WARN);
+ INSERTINT(m, "CRT_ERROR", _CRT_ERROR);
+ INSERTINT(m, "CRT_ASSERT", _CRT_ASSERT);
+ INSERTINT(m, "CRTDBG_MODE_DEBUG", _CRTDBG_MODE_DEBUG);
+ INSERTINT(m, "CRTDBG_MODE_FILE", _CRTDBG_MODE_FILE);
+ INSERTINT(m, "CRTDBG_MODE_WNDW", _CRTDBG_MODE_WNDW);
+ INSERTINT(m, "CRTDBG_REPORT_MODE", _CRTDBG_REPORT_MODE);
+ INSERTPTR(m, "CRTDBG_FILE_STDERR", _CRTDBG_FILE_STDERR);
+ INSERTPTR(m, "CRTDBG_FILE_STDOUT", _CRTDBG_FILE_STDOUT);
+ INSERTPTR(m, "CRTDBG_REPORT_FILE", _CRTDBG_REPORT_FILE);
+#endif
+
+#undef INSERTINT
+#undef INSERTPTR
+
+ /* constants for the crt versions */
+#ifdef _VC_ASSEMBLY_PUBLICKEYTOKEN
+ INSERTSTR(m, "VC_ASSEMBLY_PUBLICKEYTOKEN", _VC_ASSEMBLY_PUBLICKEYTOKEN);
+#endif
+#ifdef _CRT_ASSEMBLY_VERSION
+ INSERTSTR(m, "CRT_ASSEMBLY_VERSION", _CRT_ASSEMBLY_VERSION);
+#endif
+#ifdef __LIBRARIES_ASSEMBLY_NAME_PREFIX
+ INSERTSTR(m, "LIBRARIES_ASSEMBLY_NAME_PREFIX",
+ __LIBRARIES_ASSEMBLY_NAME_PREFIX);
+#endif
+
+#undef INSERTSTR
+
+ /* constants for the 2010 crt versions */
+#if defined(_VC_CRT_MAJOR_VERSION) && defined (_VC_CRT_MINOR_VERSION) && defined(_VC_CRT_BUILD_VERSION) && defined(_VC_CRT_RBUILD_VERSION)
+ PyObject *version = PyUnicode_FromFormat("%d.%d.%d.%d",
+ _VC_CRT_MAJOR_VERSION,
+ _VC_CRT_MINOR_VERSION,
+ _VC_CRT_BUILD_VERSION,
+ _VC_CRT_RBUILD_VERSION);
+ if (version == NULL) {
+ return -1;
+ }
+ int st = PyModule_AddObjectRef(m, "CRT_ASSEMBLY_VERSION", version);
+ Py_DECREF(version);
+ if (st < 0) {
+ return -1;
+ }
+#endif
+
+ return 0;
+}
+
+static PyModuleDef_Slot msvcrt_slots[] = {
+ {Py_mod_exec, exec_module},
+ {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+ {0, NULL}
+};
+
+static struct PyModuleDef msvcrtmodule = {
+ .m_base = PyModuleDef_HEAD_INIT,
+ .m_name = "msvcrt",
+ .m_methods = msvcrt_functions,
+ .m_slots = msvcrt_slots,
+};
+
+PyMODINIT_FUNC
+PyInit_msvcrt(void)
+{
+ return PyModuleDef_Init(&msvcrtmodule);
+}
diff --git a/contrib/tools/python3/PC/pyconfig.h b/contrib/tools/python3/PC/pyconfig.h
new file mode 100644
index 00000000000..db9e8a8855d
--- /dev/null
+++ b/contrib/tools/python3/PC/pyconfig.h
@@ -0,0 +1,740 @@
+#ifndef Py_CONFIG_H
+#define Py_CONFIG_H
+
+/* pyconfig.h. NOT Generated automatically by configure.
+
+This is a manually maintained version used for the Watcom,
+Borland and Microsoft Visual C++ compilers. It is a
+standard part of the Python distribution.
+
+WINDOWS DEFINES:
+The code specific to Windows should be wrapped around one of
+the following #defines
+
+MS_WIN64 - Code specific to the MS Win64 API
+MS_WIN32 - Code specific to the MS Win32 (and Win64) API (obsolete, this covers all supported APIs)
+MS_WINDOWS - Code specific to Windows, but all versions.
+Py_ENABLE_SHARED - Code if the Python core is built as a DLL.
+
+Also note that neither "_M_IX86" or "_MSC_VER" should be used for
+any purpose other than "Windows Intel x86 specific" and "Microsoft
+compiler specific". Therefore, these should be very rare.
+
+
+NOTE: The following symbols are deprecated:
+NT, USE_DL_EXPORT, USE_DL_IMPORT, DL_EXPORT, DL_IMPORT
+MS_CORE_DLL.
+
+WIN32 is still required for the locale module.
+
+*/
+
+/* Deprecated USE_DL_EXPORT macro - please use Py_BUILD_CORE */
+#ifdef USE_DL_EXPORT
+# define Py_BUILD_CORE
+#endif /* USE_DL_EXPORT */
+
+/* Visual Studio 2005 introduces deprecation warnings for
+ "insecure" and POSIX functions. The insecure functions should
+ be replaced by *_s versions (according to Microsoft); the
+ POSIX functions by _* versions (which, according to Microsoft,
+ would be ISO C conforming). Neither renaming is feasible, so
+ we just silence the warnings. */
+
+#ifndef _CRT_SECURE_NO_DEPRECATE
+#define _CRT_SECURE_NO_DEPRECATE 1
+#endif
+#ifndef _CRT_NONSTDC_NO_DEPRECATE
+#define _CRT_NONSTDC_NO_DEPRECATE 1
+#endif
+
+#define HAVE_IO_H
+#define HAVE_SYS_UTIME_H
+#define HAVE_TEMPNAM
+#define HAVE_TMPFILE
+#define HAVE_TMPNAM
+#define HAVE_CLOCK
+#define HAVE_STRERROR
+
+#include <io.h>
+
+#define HAVE_STRFTIME
+#define DONT_HAVE_SIG_ALARM
+#define DONT_HAVE_SIG_PAUSE
+#define LONG_BIT 32
+#define WORD_BIT 32
+
+#define MS_WIN32 /* only support win32 and greater. */
+#define MS_WINDOWS
+#define NT_THREADS
+#define WITH_THREAD
+#ifndef NETSCAPE_PI
+#define USE_SOCKET
+#endif
+
+#if defined(Py_BUILD_CORE) || defined(Py_BUILD_CORE_BUILTIN) || defined(Py_BUILD_CORE_MODULE)
+#include <winapifamily.h>
+
+#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
+#define MS_WINDOWS_DESKTOP
+#endif
+#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
+#define MS_WINDOWS_APP
+#endif
+#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_SYSTEM)
+#define MS_WINDOWS_SYSTEM
+#endif
+#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_GAMES)
+#define MS_WINDOWS_GAMES
+#endif
+
+/* Define to 1 if you support windows console io */
+#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)
+#define HAVE_WINDOWS_CONSOLE_IO 1
+#endif
+#endif /* Py_BUILD_CORE || Py_BUILD_CORE_BUILTIN || Py_BUILD_CORE_MODULE */
+
+/* Compiler specific defines */
+
+/* ------------------------------------------------------------------------*/
+/* Microsoft C defines _MSC_VER, as does clang-cl.exe */
+#ifdef _MSC_VER
+
+/* We want COMPILER to expand to a string containing _MSC_VER's *value*.
+ * This is horridly tricky, because the stringization operator only works
+ * on macro arguments, and doesn't evaluate macros passed *as* arguments.
+ */
+#define _Py_PASTE_VERSION(SUFFIX) \
+ ("[MSC v." _Py_STRINGIZE(_MSC_VER) " " SUFFIX "]")
+/* e.g., this produces, after compile-time string catenation,
+ * ("[MSC v.1900 64 bit (Intel)]")
+ *
+ * _Py_STRINGIZE(_MSC_VER) expands to
+ * _Py_STRINGIZE1(_MSC_VER) and this second macro call is scanned
+ * again for macros and so further expands to
+ * _Py_STRINGIZE1(1900) which then expands to
+ * "1900"
+ */
+#define _Py_STRINGIZE(X) _Py_STRINGIZE1(X)
+#define _Py_STRINGIZE1(X) #X
+
+/* MSVC defines _WINxx to differentiate the windows platform types
+
+ Note that for compatibility reasons _WIN32 is defined on Win32
+ *and* on Win64. For the same reasons, in Python, MS_WIN32 is
+ defined on Win32 *and* Win64. Win32 only code must therefore be
+ guarded as follows:
+ #if defined(MS_WIN32) && !defined(MS_WIN64)
+*/
+#ifdef _WIN64
+#define MS_WIN64
+#endif
+
+/* set the COMPILER and support tier
+ *
+ * win_amd64 MSVC (x86_64-pc-windows-msvc): 1
+ * win32 MSVC (i686-pc-windows-msvc): 1
+ * win_arm64 MSVC (aarch64-pc-windows-msvc): 3
+ * other archs and ICC: 0
+ */
+#ifdef MS_WIN64
+#if defined(_M_X64) || defined(_M_AMD64)
+#if defined(__clang__)
+#define COMPILER ("[Clang " __clang_version__ "] 64 bit (AMD64) with MSC v." _Py_STRINGIZE(_MSC_VER) " CRT]")
+#define PY_SUPPORT_TIER 0
+#elif defined(__INTEL_COMPILER)
+#define COMPILER ("[ICC v." _Py_STRINGIZE(__INTEL_COMPILER) " 64 bit (amd64) with MSC v." _Py_STRINGIZE(_MSC_VER) " CRT]")
+#define PY_SUPPORT_TIER 0
+#else
+#define COMPILER _Py_PASTE_VERSION("64 bit (AMD64)")
+#define PY_SUPPORT_TIER 1
+#endif /* __clang__ */
+#define PYD_PLATFORM_TAG "win_amd64"
+#elif defined(_M_ARM64)
+#define COMPILER _Py_PASTE_VERSION("64 bit (ARM64)")
+#define PY_SUPPORT_TIER 3
+#define PYD_PLATFORM_TAG "win_arm64"
+#else
+#define COMPILER _Py_PASTE_VERSION("64 bit (Unknown)")
+#define PY_SUPPORT_TIER 0
+#endif
+#endif /* MS_WIN64 */
+
+/* set the version macros for the windows headers */
+/* Python 3.9+ requires Windows 8 or greater */
+#define Py_WINVER 0x0602 /* _WIN32_WINNT_WIN8 */
+#define Py_NTDDI NTDDI_WIN8
+
+/* We only set these values when building Python - we don't want to force
+ these values on extensions, as that will affect the prototypes and
+ structures exposed in the Windows headers. Even when building Python, we
+ allow a single source file to override this - they may need access to
+ structures etc so it can optionally use new Windows features if it
+ determines at runtime they are available.
+*/
+#if defined(Py_BUILD_CORE) || defined(Py_BUILD_CORE_BUILTIN) || defined(Py_BUILD_CORE_MODULE)
+#ifndef NTDDI_VERSION
+#define NTDDI_VERSION Py_NTDDI
+#endif
+#ifndef WINVER
+#define WINVER Py_WINVER
+#endif
+#ifndef _WIN32_WINNT
+#define _WIN32_WINNT Py_WINVER
+#endif
+#endif
+
+/* _W64 is not defined for VC6 or eVC4 */
+#ifndef _W64
+#define _W64
+#endif
+
+/* Define like size_t, omitting the "unsigned" */
+#ifdef MS_WIN64
+typedef __int64 Py_ssize_t;
+# define PY_SSIZE_T_MAX LLONG_MAX
+#else
+typedef _W64 int Py_ssize_t;
+# define PY_SSIZE_T_MAX INT_MAX
+#endif
+#define HAVE_PY_SSIZE_T 1
+
+#if defined(MS_WIN32) && !defined(MS_WIN64)
+#if defined(_M_IX86)
+#if defined(__clang__)
+#define COMPILER ("[Clang " __clang_version__ "] 32 bit (Intel) with MSC v." _Py_STRINGIZE(_MSC_VER) " CRT]")
+#define PY_SUPPORT_TIER 0
+#elif defined(__INTEL_COMPILER)
+#define COMPILER ("[ICC v." _Py_STRINGIZE(__INTEL_COMPILER) " 32 bit (Intel) with MSC v." _Py_STRINGIZE(_MSC_VER) " CRT]")
+#define PY_SUPPORT_TIER 0
+#else
+#define COMPILER _Py_PASTE_VERSION("32 bit (Intel)")
+#define PY_SUPPORT_TIER 1
+#endif /* __clang__ */
+#define PYD_PLATFORM_TAG "win32"
+#elif defined(_M_ARM)
+#define COMPILER _Py_PASTE_VERSION("32 bit (ARM)")
+#define PYD_PLATFORM_TAG "win_arm32"
+#define PY_SUPPORT_TIER 0
+#else
+#define COMPILER _Py_PASTE_VERSION("32 bit (Unknown)")
+#define PY_SUPPORT_TIER 0
+#endif
+#endif /* MS_WIN32 && !MS_WIN64 */
+
+typedef int pid_t;
+
+/* define some ANSI types that are not defined in earlier Win headers */
+#if _MSC_VER >= 1200
+/* This file only exists in VC 6.0 or higher */
+#include <basetsd.h>
+#endif
+
+#endif /* _MSC_VER */
+
+/* ------------------------------------------------------------------------*/
+/* mingw and mingw-w64 define __MINGW32__ */
+#ifdef __MINGW32__
+
+#ifdef _WIN64
+#define MS_WIN64
+#endif
+
+#endif /* __MINGW32__*/
+
+/* ------------------------------------------------------------------------*/
+/* egcs/gnu-win32 defines __GNUC__ and _WIN32 */
+#if defined(__GNUC__) && defined(_WIN32)
+/* XXX These defines are likely incomplete, but should be easy to fix.
+ They should be complete enough to build extension modules. */
+/* Suggested by Rene Liebscher <[email protected]> to avoid a GCC 2.91.*
+ bug that requires structure imports. More recent versions of the
+ compiler don't exhibit this bug.
+*/
+#if (__GNUC__==2) && (__GNUC_MINOR__<=91)
+#warning "Please use an up-to-date version of gcc! (>2.91 recommended)"
+#endif
+
+#define COMPILER "[gcc]"
+#define PY_LONG_LONG long long
+#define PY_LLONG_MIN LLONG_MIN
+#define PY_LLONG_MAX LLONG_MAX
+#define PY_ULLONG_MAX ULLONG_MAX
+#endif /* GNUC */
+
+/* ------------------------------------------------------------------------*/
+/* lcc-win32 defines __LCC__ */
+#if defined(__LCC__)
+/* XXX These defines are likely incomplete, but should be easy to fix.
+ They should be complete enough to build extension modules. */
+
+#define COMPILER "[lcc-win32]"
+typedef int pid_t;
+/* __declspec() is supported here too - do nothing to get the defaults */
+
+#endif /* LCC */
+
+/* ------------------------------------------------------------------------*/
+/* End of compilers - finish up */
+
+#ifndef NO_STDIO_H
+# include <stdio.h>
+#endif
+
+/* 64 bit ints are usually spelt __int64 unless compiler has overridden */
+#ifndef PY_LONG_LONG
+# define PY_LONG_LONG __int64
+# define PY_LLONG_MAX _I64_MAX
+# define PY_LLONG_MIN _I64_MIN
+# define PY_ULLONG_MAX _UI64_MAX
+#endif
+
+/* For Windows the Python core is in a DLL by default. Test
+Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */
+#if !defined(MS_NO_COREDLL) && !defined(Py_NO_ENABLE_SHARED)
+# define Py_ENABLE_SHARED 1 /* standard symbol for shared library */
+# define MS_COREDLL /* deprecated old symbol */
+#endif /* !MS_NO_COREDLL && ... */
+
+/* All windows compilers that use this header support __declspec */
+#define HAVE_DECLSPEC_DLL
+
+/* For an MSVC DLL, we can nominate the .lib files used by extensions */
+#ifdef MS_COREDLL
+# if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)
+ /* not building the core - must be an ext */
+# if defined(_MSC_VER)
+ /* So MSVC users need not specify the .lib
+ file in their Makefile (other compilers are
+ generally taken care of by distutils.) */
+# if defined(_DEBUG)
+# pragma comment(lib,"python312_d.lib")
+# elif defined(Py_LIMITED_API)
+# pragma comment(lib,"python3.lib")
+# else
+# pragma comment(lib,"python312.lib")
+# endif /* _DEBUG */
+# endif /* _MSC_VER */
+# endif /* Py_BUILD_CORE */
+#endif /* MS_COREDLL */
+
+#ifdef MS_WIN64
+/* maintain "win32" sys.platform for backward compatibility of Python code,
+ the Win64 API should be close enough to the Win32 API to make this
+ preferable */
+# define PLATFORM "win32"
+# define SIZEOF_VOID_P 8
+# define SIZEOF_TIME_T 8
+# define SIZEOF_OFF_T 4
+# define SIZEOF_FPOS_T 8
+# define SIZEOF_HKEY 8
+# define SIZEOF_SIZE_T 8
+# define ALIGNOF_SIZE_T 8
+# define ALIGNOF_MAX_ALIGN_T 8
+/* configure.ac defines HAVE_LARGEFILE_SUPPORT iff
+ sizeof(off_t) > sizeof(long), and sizeof(long long) >= sizeof(off_t).
+ On Win64 the second condition is not true, but if fpos_t replaces off_t
+ then this is true. The uses of HAVE_LARGEFILE_SUPPORT imply that Win64
+ should define this. */
+# define HAVE_LARGEFILE_SUPPORT
+#elif defined(MS_WIN32)
+# define PLATFORM "win32"
+# define HAVE_LARGEFILE_SUPPORT
+# define SIZEOF_VOID_P 4
+# define SIZEOF_OFF_T 4
+# define SIZEOF_FPOS_T 8
+# define SIZEOF_HKEY 4
+# define SIZEOF_SIZE_T 4
+# define ALIGNOF_SIZE_T 4
+ /* MS VS2005 changes time_t to a 64-bit type on all platforms */
+# if defined(_MSC_VER) && _MSC_VER >= 1400
+# define SIZEOF_TIME_T 8
+# else
+# define SIZEOF_TIME_T 4
+# endif
+# define ALIGNOF_MAX_ALIGN_T 8
+#endif
+
+
+#ifdef MS_WIN32
+
+#define SIZEOF_SHORT 2
+#define SIZEOF_INT 4
+#define SIZEOF_LONG 4
+#define ALIGNOF_LONG 4
+#define SIZEOF_LONG_LONG 8
+#define SIZEOF_DOUBLE 8
+#define SIZEOF_FLOAT 4
+
+/* VC 7.1 has them and VC 6.0 does not. VC 6.0 has a version number of 1200.
+ Microsoft eMbedded Visual C++ 4.0 has a version number of 1201 and doesn't
+ define these.
+ If some compiler does not provide them, modify the #if appropriately. */
+#if defined(_MSC_VER)
+#if _MSC_VER > 1300
+#define HAVE_UINTPTR_T 1
+#define HAVE_INTPTR_T 1
+#else
+/* VC6, VS 2002 and eVC4 don't support the C99 LL suffix for 64-bit integer literals */
+#define Py_LL(x) x##I64
+#endif /* _MSC_VER > 1300 */
+#endif /* _MSC_VER */
+
+#endif
+
+/* define signed and unsigned exact-width 32-bit and 64-bit types, used in the
+ implementation of Python integers. */
+#define PY_UINT32_T uint32_t
+#define PY_UINT64_T uint64_t
+#define PY_INT32_T int32_t
+#define PY_INT64_T int64_t
+
+/* Fairly standard from here! */
+
+/* Define if on AIX 3.
+ System headers sometimes define this.
+ We just want to avoid a redefinition error message. */
+#ifndef _ALL_SOURCE
+/* #undef _ALL_SOURCE */
+#endif
+
+/* Define to empty if the keyword does not work. */
+/* #define const */
+
+/* Define to 1 if you have the <conio.h> header file. */
+#define HAVE_CONIO_H 1
+
+/* Define to 1 if you have the <direct.h> header file. */
+#define HAVE_DIRECT_H 1
+
+/* Define to 1 if you have the declaration of `tzname', and to 0 if you don't.
+ */
+#define HAVE_DECL_TZNAME 1
+
+/* Define if you have dirent.h. */
+/* #define DIRENT 1 */
+
+/* Define to the type of elements in the array set by `getgroups'.
+ Usually this is either `int' or `gid_t'. */
+/* #undef GETGROUPS_T */
+
+/* Define to `int' if <sys/types.h> doesn't define. */
+/* #undef gid_t */
+
+/* Define if your struct tm has tm_zone. */
+/* #undef HAVE_TM_ZONE */
+
+/* Define if you don't have tm_zone but do have the external array
+ tzname. */
+#define HAVE_TZNAME
+
+/* Define to `int' if <sys/types.h> doesn't define. */
+/* #undef mode_t */
+
+/* Define if you don't have dirent.h, but have ndir.h. */
+/* #undef NDIR */
+
+/* Define to `long' if <sys/types.h> doesn't define. */
+/* #undef off_t */
+
+/* Define to `int' if <sys/types.h> doesn't define. */
+/* #undef pid_t */
+
+/* Define if the system does not provide POSIX.1 features except
+ with this defined. */
+/* #undef _POSIX_1_SOURCE */
+
+/* Define if you need to in order for stat and other things to work. */
+/* #undef _POSIX_SOURCE */
+
+/* Define as the return type of signal handlers (int or void). */
+#define RETSIGTYPE void
+
+/* Define to `unsigned' if <sys/types.h> doesn't define. */
+/* #undef size_t */
+
+/* Define if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* Define if you don't have dirent.h, but have sys/dir.h. */
+/* #undef SYSDIR */
+
+/* Define if you don't have dirent.h, but have sys/ndir.h. */
+/* #undef SYSNDIR */
+
+/* Define if you can safely include both <sys/time.h> and <time.h>. */
+/* #undef TIME_WITH_SYS_TIME */
+
+/* Define if your <sys/time.h> declares struct tm. */
+/* #define TM_IN_SYS_TIME 1 */
+
+/* Define to `int' if <sys/types.h> doesn't define. */
+/* #undef uid_t */
+
+/* Define if the closedir function returns void instead of int. */
+/* #undef VOID_CLOSEDIR */
+
+/* Define if getpgrp() must be called as getpgrp(0)
+ and (consequently) setpgrp() as setpgrp(0, 0). */
+/* #undef GETPGRP_HAVE_ARGS */
+
+/* Define this if your time.h defines altzone */
+/* #define HAVE_ALTZONE */
+
+/* Define if you have the putenv function. */
+#define HAVE_PUTENV
+
+/* Define if your compiler supports function prototypes */
+#define HAVE_PROTOTYPES
+
+/* Define if you can safely include both <sys/select.h> and <sys/time.h>
+ (which you can't on SCO ODT 3.0). */
+/* #undef SYS_SELECT_WITH_SYS_TIME */
+
+/* Define if you want build the _decimal module using a coroutine-local rather
+ than a thread-local context */
+#define WITH_DECIMAL_CONTEXTVAR 1
+
+/* Define if you want documentation strings in extension modules */
+#define WITH_DOC_STRINGS 1
+
+/* Define if you want to compile in rudimentary thread support */
+/* #undef WITH_THREAD */
+
+/* Define if you want to use the GNU readline library */
+/* #define WITH_READLINE 1 */
+
+/* Use Python's own small-block memory-allocator. */
+#ifndef address_sanitizer_enabled
+#define WITH_PYMALLOC 1
+#endif
+
+/* Define if you want to compile in object freelists optimization */
+#define WITH_FREELISTS 1
+
+/* Define if you have clock. */
+/* #define HAVE_CLOCK */
+
+/* Define when any dynamic module loading is enabled */
+#define HAVE_DYNAMIC_LOADING
+
+/* Define if you have ftime. */
+#define HAVE_FTIME
+
+/* Define if you have getpeername. */
+#define HAVE_GETPEERNAME
+
+/* Define if you have getpgrp. */
+/* #undef HAVE_GETPGRP */
+
+/* Define if you have getpid. */
+#define HAVE_GETPID
+
+/* Define if you have gettimeofday. */
+/* #undef HAVE_GETTIMEOFDAY */
+
+/* Define if you have getwd. */
+/* #undef HAVE_GETWD */
+
+/* Define if you have lstat. */
+/* #undef HAVE_LSTAT */
+
+/* Define if you have the mktime function. */
+#define HAVE_MKTIME
+
+/* Define if you have nice. */
+/* #undef HAVE_NICE */
+
+/* Define if you have readlink. */
+/* #undef HAVE_READLINK */
+
+/* Define if you have setpgid. */
+/* #undef HAVE_SETPGID */
+
+/* Define if you have setpgrp. */
+/* #undef HAVE_SETPGRP */
+
+/* Define if you have setsid. */
+/* #undef HAVE_SETSID */
+
+/* Define if you have setvbuf. */
+#define HAVE_SETVBUF
+
+/* Define if you have siginterrupt. */
+/* #undef HAVE_SIGINTERRUPT */
+
+/* Define to 1 if you have the `shutdown' function. */
+#define HAVE_SHUTDOWN 1
+
+/* Define if you have symlink. */
+/* #undef HAVE_SYMLINK */
+
+/* Define if you have tcgetpgrp. */
+/* #undef HAVE_TCGETPGRP */
+
+/* Define if you have tcsetpgrp. */
+/* #undef HAVE_TCSETPGRP */
+
+/* Define if you have times. */
+/* #undef HAVE_TIMES */
+
+/* Define to 1 if you have the `umask' function. */
+#define HAVE_UMASK 1
+
+/* Define if you have uname. */
+/* #undef HAVE_UNAME */
+
+/* Define if you have waitpid. */
+/* #undef HAVE_WAITPID */
+
+/* Define to 1 if you have the `wcsftime' function. */
+#if defined(_MSC_VER) && _MSC_VER >= 1310
+#define HAVE_WCSFTIME 1
+#endif
+
+/* Define to 1 if you have the `wcscoll' function. */
+#define HAVE_WCSCOLL 1
+
+/* Define to 1 if you have the `wcsxfrm' function. */
+#define HAVE_WCSXFRM 1
+
+/* Define if the zlib library has inflateCopy */
+#define HAVE_ZLIB_COPY 1
+
+/* Define if you have the <dlfcn.h> header file. */
+/* #undef HAVE_DLFCN_H */
+
+/* Define to 1 if you have the <errno.h> header file. */
+#define HAVE_ERRNO_H 1
+
+/* Define if you have the <fcntl.h> header file. */
+#define HAVE_FCNTL_H 1
+
+/* Define to 1 if you have the <process.h> header file. */
+#define HAVE_PROCESS_H 1
+
+/* Define to 1 if you have the <signal.h> header file. */
+#define HAVE_SIGNAL_H 1
+
+/* Define if you have the <stddef.h> header file. */
+#define HAVE_STDDEF_H 1
+
+/* Define if you have the <sys/audioio.h> header file. */
+/* #undef HAVE_SYS_AUDIOIO_H */
+
+/* Define if you have the <sys/param.h> header file. */
+/* #define HAVE_SYS_PARAM_H 1 */
+
+/* Define if you have the <sys/select.h> header file. */
+/* #define HAVE_SYS_SELECT_H 1 */
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define if you have the <sys/time.h> header file. */
+/* #define HAVE_SYS_TIME_H 1 */
+
+/* Define if you have the <sys/times.h> header file. */
+/* #define HAVE_SYS_TIMES_H 1 */
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define if you have the <sys/un.h> header file. */
+/* #define HAVE_SYS_UN_H 1 */
+
+/* Define if you have the <sys/utime.h> header file. */
+/* #define HAVE_SYS_UTIME_H 1 */
+
+/* Define if you have the <sys/utsname.h> header file. */
+/* #define HAVE_SYS_UTSNAME_H 1 */
+
+/* Define if you have the <unistd.h> header file. */
+/* #define HAVE_UNISTD_H 1 */
+
+/* Define if you have the <utime.h> header file. */
+/* #define HAVE_UTIME_H 1 */
+
+/* Define if the compiler provides a wchar.h header file. */
+#define HAVE_WCHAR_H 1
+
+/* The size of `wchar_t', as computed by sizeof. */
+#define SIZEOF_WCHAR_T 2
+
+/* The size of `_Bool', as computed by sizeof. */
+#define SIZEOF__BOOL 1
+
+/* The size of `pid_t', as computed by sizeof. */
+#define SIZEOF_PID_T SIZEOF_INT
+
+/* Define if you have the dl library (-ldl). */
+/* #undef HAVE_LIBDL */
+
+/* Define if you have the mpc library (-lmpc). */
+/* #undef HAVE_LIBMPC */
+
+/* Define if you have the nsl library (-lnsl). */
+#define HAVE_LIBNSL 1
+
+/* Define if you have the seq library (-lseq). */
+/* #undef HAVE_LIBSEQ */
+
+/* Define if you have the socket library (-lsocket). */
+#define HAVE_LIBSOCKET 1
+
+/* Define if you have the sun library (-lsun). */
+/* #undef HAVE_LIBSUN */
+
+/* Define if you have the termcap library (-ltermcap). */
+/* #undef HAVE_LIBTERMCAP */
+
+/* Define if you have the termlib library (-ltermlib). */
+/* #undef HAVE_LIBTERMLIB */
+
+/* Define if you have the thread library (-lthread). */
+/* #undef HAVE_LIBTHREAD */
+
+/* WinSock does not use a bitmask in select, and uses
+ socket handles greater than FD_SETSIZE */
+#define Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE
+
+/* Define if C doubles are 64-bit IEEE 754 binary format, stored with the
+ least significant byte first */
+#define DOUBLE_IS_LITTLE_ENDIAN_IEEE754 1
+
+/* Define to 1 if you have the `erf' function. */
+#define HAVE_ERF 1
+
+/* Define to 1 if you have the `erfc' function. */
+#define HAVE_ERFC 1
+
+// netdb.h functions (provided by winsock.h)
+#define HAVE_GETHOSTNAME 1
+#define HAVE_GETHOSTBYADDR 1
+#define HAVE_GETHOSTBYNAME 1
+#define HAVE_GETPROTOBYNAME 1
+#define HAVE_GETSERVBYNAME 1
+#define HAVE_GETSERVBYPORT 1
+// sys/socket.h functions (provided by winsock.h)
+#define HAVE_INET_PTON 1
+#define HAVE_INET_NTOA 1
+#define HAVE_ACCEPT 1
+#define HAVE_BIND 1
+#define HAVE_CONNECT 1
+#define HAVE_GETSOCKNAME 1
+#define HAVE_LISTEN 1
+#define HAVE_RECVFROM 1
+#define HAVE_SENDTO 1
+#define HAVE_SETSOCKOPT 1
+#define HAVE_SOCKET 1
+
+/* Define to 1 if you have the `dup' function. */
+#define HAVE_DUP 1
+
+/* framework name */
+#define _PYTHONFRAMEWORK ""
+
+/* Define if libssl has X509_VERIFY_PARAM_set1_host and related function */
+#define HAVE_X509_VERIFY_PARAM_SET1_HOST 1
+
+#endif /* !Py_CONFIG_H */
diff --git a/contrib/tools/python3/PC/winreg.c b/contrib/tools/python3/PC/winreg.c
new file mode 100644
index 00000000000..e2d5322f458
--- /dev/null
+++ b/contrib/tools/python3/PC/winreg.c
@@ -0,0 +1,2223 @@
+/*
+ winreg.c
+
+ Windows Registry access module for Python.
+
+ * Simple registry access written by Mark Hammond in win32api
+ module circa 1995.
+ * Bill Tutt expanded the support significantly not long after.
+ * Numerous other people have submitted patches since then.
+ * Ripped from win32api module 03-Feb-2000 by Mark Hammond, and
+ basic Unicode support added.
+
+*/
+
+#define PY_SSIZE_T_CLEAN
+#include "Python.h"
+#include "pycore_object.h" // _PyObject_Init()
+#include "pycore_moduleobject.h"
+#include "structmember.h" // PyMemberDef
+#include <windows.h>
+
+#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)
+
+typedef struct {
+ PyTypeObject *PyHKEY_Type;
+} winreg_state;
+
+/* Forward declares */
+
+static BOOL PyHKEY_AsHKEY(winreg_state *st, PyObject *ob, HKEY *pRes, BOOL bNoneOK);
+static BOOL clinic_HKEY_converter(winreg_state *st, PyObject *ob, void *p);
+static PyObject *PyHKEY_FromHKEY(winreg_state *st, HKEY h);
+static BOOL PyHKEY_Close(winreg_state *st, PyObject *obHandle);
+
+static char errNotAHandle[] = "Object is not a handle";
+
+/* The win32api module reports the function name that failed,
+ but this concept is not in the Python core.
+ Hopefully it will one day, and in the meantime I don't
+ want to lose this info...
+*/
+#define PyErr_SetFromWindowsErrWithFunction(rc, fnname) \
+ PyErr_SetFromWindowsErr(rc)
+
+/* Doc strings */
+PyDoc_STRVAR(module_doc,
+"This module provides access to the Windows registry API.\n"
+"\n"
+"Functions:\n"
+"\n"
+"CloseKey() - Closes a registry key.\n"
+"ConnectRegistry() - Establishes a connection to a predefined registry handle\n"
+" on another computer.\n"
+"CreateKey() - Creates the specified key, or opens it if it already exists.\n"
+"DeleteKey() - Deletes the specified key.\n"
+"DeleteValue() - Removes a named value from the specified registry key.\n"
+"EnumKey() - Enumerates subkeys of the specified open registry key.\n"
+"EnumValue() - Enumerates values of the specified open registry key.\n"
+"ExpandEnvironmentStrings() - Expand the env strings in a REG_EXPAND_SZ\n"
+" string.\n"
+"FlushKey() - Writes all the attributes of the specified key to the registry.\n"
+"LoadKey() - Creates a subkey under HKEY_USER or HKEY_LOCAL_MACHINE and\n"
+" stores registration information from a specified file into that\n"
+" subkey.\n"
+"OpenKey() - Opens the specified key.\n"
+"OpenKeyEx() - Alias of OpenKey().\n"
+"QueryValue() - Retrieves the value associated with the unnamed value for a\n"
+" specified key in the registry.\n"
+"QueryValueEx() - Retrieves the type and data for a specified value name\n"
+" associated with an open registry key.\n"
+"QueryInfoKey() - Returns information about the specified key.\n"
+"SaveKey() - Saves the specified key, and all its subkeys a file.\n"
+"SetValue() - Associates a value with a specified key.\n"
+"SetValueEx() - Stores data in the value field of an open registry key.\n"
+"\n"
+"Special objects:\n"
+"\n"
+"HKEYType -- type object for HKEY objects\n"
+"error -- exception raised for Win32 errors\n"
+"\n"
+"Integer constants:\n"
+"Many constants are defined - see the documentation for each function\n"
+"to see what constants are used, and where.");
+
+
+
+/* PyHKEY docstrings */
+PyDoc_STRVAR(PyHKEY_doc,
+"PyHKEY Object - A Python object, representing a win32 registry key.\n"
+"\n"
+"This object wraps a Windows HKEY object, automatically closing it when\n"
+"the object is destroyed. To guarantee cleanup, you can call either\n"
+"the Close() method on the PyHKEY, or the CloseKey() method.\n"
+"\n"
+"All functions which accept a handle object also accept an integer --\n"
+"however, use of the handle object is encouraged.\n"
+"\n"
+"Functions:\n"
+"Close() - Closes the underlying handle.\n"
+"Detach() - Returns the integer Win32 handle, detaching it from the object\n"
+"\n"
+"Properties:\n"
+"handle - The integer Win32 handle.\n"
+"\n"
+"Operations:\n"
+"__bool__ - Handles with an open object return true, otherwise false.\n"
+"__int__ - Converting a handle to an integer returns the Win32 handle.\n"
+"rich comparison - Handle objects are compared using the handle value.");
+
+
+
+/************************************************************************
+
+ The PyHKEY object definition
+
+************************************************************************/
+typedef struct {
+ PyObject_VAR_HEAD
+ HKEY hkey;
+} PyHKEYObject;
+
+#define PyHKEY_Check(st, op) Py_IS_TYPE(op, st->PyHKEY_Type)
+
+static char *failMsg = "bad operand type";
+
+static PyObject *
+PyHKEY_unaryFailureFunc(PyObject *ob)
+{
+ PyErr_SetString(PyExc_TypeError, failMsg);
+ return NULL;
+}
+static PyObject *
+PyHKEY_binaryFailureFunc(PyObject *ob1, PyObject *ob2)
+{
+ PyErr_SetString(PyExc_TypeError, failMsg);
+ return NULL;
+}
+static PyObject *
+PyHKEY_ternaryFailureFunc(PyObject *ob1, PyObject *ob2, PyObject *ob3)
+{
+ PyErr_SetString(PyExc_TypeError, failMsg);
+ return NULL;
+}
+
+static void
+PyHKEY_deallocFunc(PyObject *ob)
+{
+ /* Can not call PyHKEY_Close, as the ob->tp_type
+ has already been cleared, thus causing the type
+ check to fail!
+ */
+ PyHKEYObject *obkey = (PyHKEYObject *)ob;
+ if (obkey->hkey)
+ RegCloseKey((HKEY)obkey->hkey);
+
+ PyTypeObject *tp = Py_TYPE(ob);
+ PyObject_GC_UnTrack(ob);
+ PyObject_GC_Del(ob);
+ Py_DECREF(tp);
+}
+
+static int
+PyHKEY_traverseFunc(PyHKEYObject *self, visitproc visit, void *arg)
+{
+ Py_VISIT(Py_TYPE(self));
+ return 0;
+}
+
+static int
+PyHKEY_boolFunc(PyObject *ob)
+{
+ return ((PyHKEYObject *)ob)->hkey != 0;
+}
+
+static PyObject *
+PyHKEY_intFunc(PyObject *ob)
+{
+ PyHKEYObject *pyhkey = (PyHKEYObject *)ob;
+ return PyLong_FromVoidPtr(pyhkey->hkey);
+}
+
+static PyObject *
+PyHKEY_strFunc(PyObject *ob)
+{
+ PyHKEYObject *pyhkey = (PyHKEYObject *)ob;
+ return PyUnicode_FromFormat("<PyHKEY:%p>", pyhkey->hkey);
+}
+
+static int
+PyHKEY_compareFunc(PyObject *ob1, PyObject *ob2)
+{
+ PyHKEYObject *pyhkey1 = (PyHKEYObject *)ob1;
+ PyHKEYObject *pyhkey2 = (PyHKEYObject *)ob2;
+ return pyhkey1 == pyhkey2 ? 0 :
+ (pyhkey1 < pyhkey2 ? -1 : 1);
+}
+
+static Py_hash_t
+PyHKEY_hashFunc(PyObject *ob)
+{
+ /* Just use the address.
+ XXX - should we use the handle value?
+ */
+ return _Py_HashPointer(ob);
+}
+
+
+/*[clinic input]
+module winreg
+class winreg.HKEYType "PyHKEYObject *" "&PyHKEY_Type"
+[clinic start generated code]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=4c964eba3bf914d6]*/
+
+/*[python input]
+class REGSAM_converter(int_converter):
+ type = 'REGSAM'
+
+class DWORD_converter(unsigned_long_converter):
+ type = 'DWORD'
+
+class HKEY_converter(CConverter):
+ type = 'HKEY'
+ converter = 'clinic_HKEY_converter'
+
+ def parse_arg(self, argname, displayname):
+ return """
+ if (!{converter}(_PyModule_GetState(module), {argname}, &{paramname})) {{{{
+ goto exit;
+ }}}}
+ """.format(argname=argname, paramname=self.parser_name,
+ converter=self.converter)
+
+class HKEY_return_converter(CReturnConverter):
+ type = 'HKEY'
+
+ def render(self, function, data):
+ self.declare(data)
+ self.err_occurred_if_null_pointer("_return_value", data)
+ data.return_conversion.append(
+ 'return_value = PyHKEY_FromHKEY(_PyModule_GetState(module), _return_value);\n')
+
+# HACK: this only works for PyHKEYObjects, nothing else.
+# Should this be generalized and enshrined in clinic.py,
+# destroy this converter with prejudice.
+class self_return_converter(CReturnConverter):
+ type = 'PyHKEYObject *'
+
+ def render(self, function, data):
+ self.declare(data)
+ data.return_conversion.append(
+ 'return_value = (PyObject *)_return_value;\n')
+[python start generated code]*/
+/*[python end generated code: output=da39a3ee5e6b4b0d input=17e645060c7b8ae1]*/
+
+#include "clinic/winreg.c.h"
+
+/************************************************************************
+
+ The PyHKEY object methods
+
+************************************************************************/
+/*[clinic input]
+winreg.HKEYType.Close
+
+Closes the underlying Windows handle.
+
+If the handle is already closed, no error is raised.
+[clinic start generated code]*/
+
+static PyObject *
+winreg_HKEYType_Close_impl(PyHKEYObject *self)
+/*[clinic end generated code: output=fced3a624fb0c344 input=6786ac75f6b89de6]*/
+{
+ winreg_state *st = _PyType_GetModuleState(Py_TYPE(self));
+ assert(st != NULL);
+ if (!PyHKEY_Close(st, (PyObject *)self)) {
+ return NULL;
+ }
+ Py_RETURN_NONE;
+}
+
+/*[clinic input]
+winreg.HKEYType.Detach
+
+Detaches the Windows handle from the handle object.
+
+The result is the value of the handle before it is detached. If the
+handle is already detached, this will return zero.
+
+After calling this function, the handle is effectively invalidated,
+but the handle is not closed. You would call this function when you
+need the underlying win32 handle to exist beyond the lifetime of the
+handle object.
+[clinic start generated code]*/
+
+static PyObject *
+winreg_HKEYType_Detach_impl(PyHKEYObject *self)
+/*[clinic end generated code: output=dda5a9e1a01ae78f input=dd2cc09e6c6ba833]*/
+{
+ void* ret;
+ if (PySys_Audit("winreg.PyHKEY.Detach", "n", (Py_ssize_t)self->hkey) < 0) {
+ return NULL;
+ }
+ ret = (void*)self->hkey;
+ self->hkey = 0;
+ return PyLong_FromVoidPtr(ret);
+}
+
+/*[clinic input]
+winreg.HKEYType.__enter__ -> self
+[clinic start generated code]*/
+
+static PyHKEYObject *
+winreg_HKEYType___enter___impl(PyHKEYObject *self)
+/*[clinic end generated code: output=52c34986dab28990 input=c40fab1f0690a8e2]*/
+{
+ return (PyHKEYObject*)Py_XNewRef(self);
+}
+
+
+/*[clinic input]
+winreg.HKEYType.__exit__
+
+ exc_type: object
+ exc_value: object
+ traceback: object
+[clinic start generated code]*/
+
+static PyObject *
+winreg_HKEYType___exit___impl(PyHKEYObject *self, PyObject *exc_type,
+ PyObject *exc_value, PyObject *traceback)
+/*[clinic end generated code: output=923ebe7389e6a263 input=fb32489ee92403c7]*/
+{
+ winreg_state *st = _PyType_GetModuleState(Py_TYPE(self));
+ assert(st != NULL);
+ if (!PyHKEY_Close(st, (PyObject *)self)) {
+ return NULL;
+ }
+ Py_RETURN_NONE;
+}
+
+/*[clinic input]
+[clinic start generated code]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=da39a3ee5e6b4b0d]*/
+
+static struct PyMethodDef PyHKEY_methods[] = {
+ WINREG_HKEYTYPE_CLOSE_METHODDEF
+ WINREG_HKEYTYPE_DETACH_METHODDEF
+ WINREG_HKEYTYPE___ENTER___METHODDEF
+ WINREG_HKEYTYPE___EXIT___METHODDEF
+ {NULL}
+};
+
+#define OFF(e) offsetof(PyHKEYObject, e)
+static PyMemberDef PyHKEY_memberlist[] = {
+ {"handle", T_INT, OFF(hkey), READONLY},
+ {NULL} /* Sentinel */
+};
+
+static PyType_Slot pyhkey_type_slots[] = {
+ {Py_tp_dealloc, PyHKEY_deallocFunc},
+ {Py_tp_members, PyHKEY_memberlist},
+ {Py_tp_methods, PyHKEY_methods},
+ {Py_tp_doc, (char *)PyHKEY_doc},
+ {Py_tp_traverse, PyHKEY_traverseFunc},
+ {Py_tp_hash, PyHKEY_hashFunc},
+ {Py_tp_str, PyHKEY_strFunc},
+
+ // Number protocol
+ {Py_nb_add, PyHKEY_binaryFailureFunc},
+ {Py_nb_subtract, PyHKEY_binaryFailureFunc},
+ {Py_nb_multiply, PyHKEY_binaryFailureFunc},
+ {Py_nb_remainder, PyHKEY_binaryFailureFunc},
+ {Py_nb_divmod, PyHKEY_binaryFailureFunc},
+ {Py_nb_power, PyHKEY_ternaryFailureFunc},
+ {Py_nb_negative, PyHKEY_unaryFailureFunc},
+ {Py_nb_positive, PyHKEY_unaryFailureFunc},
+ {Py_nb_absolute, PyHKEY_unaryFailureFunc},
+ {Py_nb_bool, PyHKEY_boolFunc},
+ {Py_nb_invert, PyHKEY_unaryFailureFunc},
+ {Py_nb_lshift, PyHKEY_binaryFailureFunc},
+ {Py_nb_rshift, PyHKEY_binaryFailureFunc},
+ {Py_nb_and, PyHKEY_binaryFailureFunc},
+ {Py_nb_xor, PyHKEY_binaryFailureFunc},
+ {Py_nb_or, PyHKEY_binaryFailureFunc},
+ {Py_nb_int, PyHKEY_intFunc},
+ {Py_nb_float, PyHKEY_unaryFailureFunc},
+ {0, NULL},
+};
+
+static PyType_Spec pyhkey_type_spec = {
+ .name = "winreg.PyHKEY",
+ .basicsize = sizeof(PyHKEYObject),
+ .flags = (Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE |
+ Py_TPFLAGS_DISALLOW_INSTANTIATION),
+ .slots = pyhkey_type_slots,
+};
+
+/************************************************************************
+ The public PyHKEY API (well, not public yet :-)
+************************************************************************/
+PyObject *
+PyHKEY_New(PyObject *m, HKEY hInit)
+{
+ winreg_state *st = _PyModule_GetState(m);
+ PyHKEYObject *key = PyObject_GC_New(PyHKEYObject, st->PyHKEY_Type);
+ if (key == NULL) {
+ return NULL;
+ }
+ key->hkey = hInit;
+ PyObject_GC_Track(key);
+ return (PyObject *)key;
+}
+
+BOOL
+PyHKEY_Close(winreg_state *st, PyObject *ob_handle)
+{
+ LONG rc;
+ HKEY key;
+
+ if (!PyHKEY_AsHKEY(st, ob_handle, &key, TRUE)) {
+ return FALSE;
+ }
+ if (PyHKEY_Check(st, ob_handle)) {
+ ((PyHKEYObject*)ob_handle)->hkey = 0;
+ }
+ rc = key ? RegCloseKey(key) : ERROR_SUCCESS;
+ if (rc != ERROR_SUCCESS)
+ PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey");
+ return rc == ERROR_SUCCESS;
+}
+
+BOOL
+PyHKEY_AsHKEY(winreg_state *st, PyObject *ob, HKEY *pHANDLE, BOOL bNoneOK)
+{
+ if (ob == Py_None) {
+ if (!bNoneOK) {
+ PyErr_SetString(
+ PyExc_TypeError,
+ "None is not a valid HKEY in this context");
+ return FALSE;
+ }
+ *pHANDLE = (HKEY)0;
+ }
+ else if (PyHKEY_Check(st ,ob)) {
+ PyHKEYObject *pH = (PyHKEYObject *)ob;
+ *pHANDLE = pH->hkey;
+ }
+ else if (PyLong_Check(ob)) {
+ /* We also support integers */
+ PyErr_Clear();
+ *pHANDLE = (HKEY)PyLong_AsVoidPtr(ob);
+ if (PyErr_Occurred())
+ return FALSE;
+ }
+ else {
+ PyErr_SetString(
+ PyExc_TypeError,
+ "The object is not a PyHKEY object");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+BOOL
+clinic_HKEY_converter(winreg_state *st, PyObject *ob, void *p)
+{
+ if (!PyHKEY_AsHKEY(st, ob, (HKEY *)p, FALSE)) {
+ return FALSE;
+ }
+ return TRUE;
+}
+
+PyObject *
+PyHKEY_FromHKEY(winreg_state *st, HKEY h)
+{
+ PyHKEYObject *op = (PyHKEYObject *)PyObject_GC_New(PyHKEYObject,
+ st->PyHKEY_Type);
+ if (op == NULL) {
+ return NULL;
+ }
+ op->hkey = h;
+ PyObject_GC_Track(op);
+ return (PyObject *)op;
+}
+
+
+/************************************************************************
+ The module methods
+************************************************************************/
+BOOL
+PyWinObject_CloseHKEY(winreg_state *st, PyObject *obHandle)
+{
+ BOOL ok;
+ if (PyHKEY_Check(st, obHandle)) {
+ ok = PyHKEY_Close(st, obHandle);
+ }
+#if SIZEOF_LONG >= SIZEOF_HKEY
+ else if (PyLong_Check(obHandle)) {
+ long rc = RegCloseKey((HKEY)PyLong_AsLong(obHandle));
+ ok = (rc == ERROR_SUCCESS);
+ if (!ok)
+ PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey");
+ }
+#else
+ else if (PyLong_Check(obHandle)) {
+ long rc = RegCloseKey((HKEY)PyLong_AsVoidPtr(obHandle));
+ ok = (rc == ERROR_SUCCESS);
+ if (!ok)
+ PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey");
+ }
+#endif
+ else {
+ PyErr_SetString(
+ PyExc_TypeError,
+ "A handle must be a HKEY object or an integer");
+ return FALSE;
+ }
+ return ok;
+}
+
+
+/*
+ Private Helper functions for the registry interfaces
+
+** Note that fixupMultiSZ and countString have both had changes
+** made to support "incorrect strings". The registry specification
+** calls for strings to be terminated with 2 null bytes. It seems
+** some commercial packages install strings which don't conform,
+** causing this code to fail - however, "regedit" etc still work
+** with these strings (ie only we don't!).
+*/
+static void
+fixupMultiSZ(wchar_t **str, wchar_t *data, int len)
+{
+ wchar_t *P;
+ int i;
+ wchar_t *Q;
+
+ if (len > 0 && data[len - 1] == '\0') {
+ Q = data + len - 1;
+ }
+ else {
+ Q = data + len;
+ }
+
+ for (P = data, i = 0; P < Q; P++, i++) {
+ str[i] = P;
+ for (; P < Q && *P != '\0'; P++) {
+ ;
+ }
+ }
+}
+
+static int
+countStrings(wchar_t *data, int len)
+{
+ int strings;
+ wchar_t *P, *Q;
+
+ if (len > 0 && data[len - 1] == '\0') {
+ Q = data + len - 1;
+ }
+ else {
+ Q = data + len;
+ }
+
+ for (P = data, strings = 0; P < Q; P++, strings++) {
+ for (; P < Q && *P != '\0'; P++) {
+ ;
+ }
+ }
+ return strings;
+}
+
+/* Convert PyObject into Registry data.
+ Allocates space as needed. */
+static BOOL
+Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
+{
+ Py_ssize_t i,j;
+ switch (typ) {
+ case REG_DWORD:
+ {
+ if (value != Py_None && !PyLong_Check(value)) {
+ return FALSE;
+ }
+ DWORD d;
+ if (value == Py_None) {
+ d = 0;
+ }
+ else if (PyLong_Check(value)) {
+ d = PyLong_AsUnsignedLong(value);
+ if (d == (DWORD)(-1) && PyErr_Occurred()) {
+ return FALSE;
+ }
+ }
+ *retDataBuf = (BYTE *)PyMem_NEW(DWORD, 1);
+ if (*retDataBuf == NULL) {
+ PyErr_NoMemory();
+ return FALSE;
+ }
+ memcpy(*retDataBuf, &d, sizeof(DWORD));
+ *retDataSize = sizeof(DWORD);
+ break;
+ }
+ case REG_QWORD:
+ {
+ if (value != Py_None && !PyLong_Check(value)) {
+ return FALSE;
+ }
+ DWORD64 d;
+ if (value == Py_None) {
+ d = 0;
+ }
+ else if (PyLong_Check(value)) {
+ d = PyLong_AsUnsignedLongLong(value);
+ if (d == (DWORD64)(-1) && PyErr_Occurred()) {
+ return FALSE;
+ }
+ }
+ *retDataBuf = (BYTE *)PyMem_NEW(DWORD64, 1);
+ if (*retDataBuf == NULL) {
+ PyErr_NoMemory();
+ return FALSE;
+ }
+ memcpy(*retDataBuf, &d, sizeof(DWORD64));
+ *retDataSize = sizeof(DWORD64);
+ break;
+ }
+ case REG_SZ:
+ case REG_EXPAND_SZ:
+ {
+ if (value != Py_None) {
+ Py_ssize_t len;
+ if (!PyUnicode_Check(value))
+ return FALSE;
+ *retDataBuf = (BYTE*)PyUnicode_AsWideCharString(value, &len);
+ if (*retDataBuf == NULL)
+ return FALSE;
+ *retDataSize = Py_SAFE_DOWNCAST(
+ (len + 1) * sizeof(wchar_t),
+ Py_ssize_t, DWORD);
+ }
+ else {
+ *retDataBuf = (BYTE *)PyMem_NEW(wchar_t, 1);
+ if (*retDataBuf == NULL) {
+ PyErr_NoMemory();
+ return FALSE;
+ }
+ ((wchar_t *)*retDataBuf)[0] = L'\0';
+ *retDataSize = 1 * sizeof(wchar_t);
+ }
+ break;
+ }
+ case REG_MULTI_SZ:
+ {
+ DWORD size = 0;
+ wchar_t *P;
+
+ if (value == Py_None)
+ i = 0;
+ else {
+ if (!PyList_Check(value))
+ return FALSE;
+ i = PyList_Size(value);
+ }
+ for (j = 0; j < i; j++)
+ {
+ PyObject *t;
+ Py_ssize_t len;
+
+ t = PyList_GET_ITEM(value, j);
+ if (!PyUnicode_Check(t))
+ return FALSE;
+ len = PyUnicode_AsWideChar(t, NULL, 0);
+ if (len < 0)
+ return FALSE;
+ size += Py_SAFE_DOWNCAST(len * sizeof(wchar_t),
+ size_t, DWORD);
+ }
+
+ *retDataSize = size + 2;
+ *retDataBuf = (BYTE *)PyMem_NEW(char,
+ *retDataSize);
+ if (*retDataBuf == NULL){
+ PyErr_NoMemory();
+ return FALSE;
+ }
+ P = (wchar_t *)*retDataBuf;
+
+ for (j = 0; j < i; j++)
+ {
+ PyObject *t;
+ Py_ssize_t len;
+
+ t = PyList_GET_ITEM(value, j);
+ assert(size > 0);
+ len = PyUnicode_AsWideChar(t, P, size);
+ assert(len >= 0);
+ assert((unsigned)len < size);
+ size -= (DWORD)len + 1;
+ P += len + 1;
+ }
+ /* And doubly-terminate the list... */
+ *P = L'\0';
+ break;
+ }
+ case REG_BINARY:
+ /* ALSO handle ALL unknown data types here. Even if we can't
+ support it natively, we should handle the bits. */
+ default:
+ if (value == Py_None) {
+ *retDataSize = 0;
+ *retDataBuf = NULL;
+ }
+ else {
+ Py_buffer view;
+
+ if (!PyObject_CheckBuffer(value)) {
+ PyErr_Format(PyExc_TypeError,
+ "Objects of type '%s' can not "
+ "be used as binary registry values",
+ Py_TYPE(value)->tp_name);
+ return FALSE;
+ }
+
+ if (PyObject_GetBuffer(value, &view, PyBUF_SIMPLE) < 0)
+ return FALSE;
+
+ *retDataBuf = (BYTE *)PyMem_NEW(char, view.len);
+ if (*retDataBuf == NULL){
+ PyBuffer_Release(&view);
+ PyErr_NoMemory();
+ return FALSE;
+ }
+ *retDataSize = Py_SAFE_DOWNCAST(view.len, Py_ssize_t, DWORD);
+ memcpy(*retDataBuf, view.buf, view.len);
+ PyBuffer_Release(&view);
+ }
+ break;
+ }
+ return TRUE;
+}
+
+/* Convert Registry data into PyObject*/
+static PyObject *
+Reg2Py(BYTE *retDataBuf, DWORD retDataSize, DWORD typ)
+{
+ PyObject *obData;
+
+ switch (typ) {
+ case REG_DWORD:
+ if (retDataSize == 0)
+ obData = PyLong_FromUnsignedLong(0);
+ else
+ obData = PyLong_FromUnsignedLong(*(DWORD *)retDataBuf);
+ break;
+ case REG_QWORD:
+ if (retDataSize == 0)
+ obData = PyLong_FromUnsignedLongLong(0);
+ else
+ obData = PyLong_FromUnsignedLongLong(*(DWORD64 *)retDataBuf);
+ break;
+ case REG_SZ:
+ case REG_EXPAND_SZ:
+ {
+ /* REG_SZ should be a NUL terminated string, but only by
+ * convention. The buffer may have been saved without a NUL
+ * or with embedded NULs. To be consistent with reg.exe and
+ * regedit.exe, consume only up to the first NUL. */
+ wchar_t *data = (wchar_t *)retDataBuf;
+ size_t len = wcsnlen(data, retDataSize / sizeof(wchar_t));
+ obData = PyUnicode_FromWideChar(data, len);
+ break;
+ }
+ case REG_MULTI_SZ:
+ if (retDataSize == 0)
+ obData = PyList_New(0);
+ else
+ {
+ int index = 0;
+ wchar_t *data = (wchar_t *)retDataBuf;
+ int len = retDataSize / 2;
+ int s = countStrings(data, len);
+ wchar_t **str = PyMem_New(wchar_t *, s);
+ if (str == NULL)
+ return PyErr_NoMemory();
+
+ fixupMultiSZ(str, data, len);
+ obData = PyList_New(s);
+ if (obData == NULL) {
+ PyMem_Free(str);
+ return NULL;
+ }
+ for (index = 0; index < s; index++)
+ {
+ size_t slen = wcsnlen(str[index], len);
+ PyObject *uni = PyUnicode_FromWideChar(str[index], slen);
+ if (uni == NULL) {
+ Py_DECREF(obData);
+ PyMem_Free(str);
+ return NULL;
+ }
+ PyList_SET_ITEM(obData, index, uni);
+ len -= Py_SAFE_DOWNCAST(slen + 1, size_t, int);
+ }
+ PyMem_Free(str);
+
+ break;
+ }
+ case REG_BINARY:
+ /* ALSO handle ALL unknown data types here. Even if we can't
+ support it natively, we should handle the bits. */
+ default:
+ if (retDataSize == 0) {
+ obData = Py_NewRef(Py_None);
+ }
+ else
+ obData = PyBytes_FromStringAndSize(
+ (char *)retDataBuf, retDataSize);
+ break;
+ }
+ return obData;
+}
+
+/* The Python methods */
+
+/*[clinic input]
+winreg.CloseKey
+
+ hkey: object
+ A previously opened key.
+ /
+
+Closes a previously opened registry key.
+
+Note that if the key is not closed using this method, it will be
+closed when the hkey object is destroyed by Python.
+[clinic start generated code]*/
+
+static PyObject *
+winreg_CloseKey(PyObject *module, PyObject *hkey)
+/*[clinic end generated code: output=a4fa537019a80d15 input=5b1aac65ba5127ad]*/
+{
+ if (!PyHKEY_Close(_PyModule_GetState(module), hkey)) {
+ return NULL;
+ }
+ Py_RETURN_NONE;
+}
+
+#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)
+
+/*[clinic input]
+winreg.ConnectRegistry -> HKEY
+
+ computer_name: Py_UNICODE(accept={str, NoneType})
+ The name of the remote computer, of the form r"\\computername". If
+ None, the local computer is used.
+ key: HKEY
+ The predefined key to connect to.
+ /
+
+Establishes a connection to the registry on another computer.
+
+The return value is the handle of the opened key.
+If the function fails, an OSError exception is raised.
+[clinic start generated code]*/
+
+static HKEY
+winreg_ConnectRegistry_impl(PyObject *module,
+ const Py_UNICODE *computer_name, HKEY key)
+/*[clinic end generated code: output=cd4f70fb9ec901fb input=5f98a891a347e68e]*/
+{
+ HKEY retKey;
+ long rc;
+ if (PySys_Audit("winreg.ConnectRegistry", "un",
+ computer_name, (Py_ssize_t)key) < 0) {
+ return NULL;
+ }
+ Py_BEGIN_ALLOW_THREADS
+ rc = RegConnectRegistryW(computer_name, key, &retKey);
+ Py_END_ALLOW_THREADS
+ if (rc != ERROR_SUCCESS) {
+ PyErr_SetFromWindowsErrWithFunction(rc, "ConnectRegistry");
+ return NULL;
+ }
+ return retKey;
+}
+
+#endif /* MS_WINDOWS_DESKTOP || MS_WINDOWS_SYSTEM */
+
+/*[clinic input]
+winreg.CreateKey -> HKEY
+
+ key: HKEY
+ An already open key, or one of the predefined HKEY_* constants.
+ sub_key: Py_UNICODE(accept={str, NoneType})
+ The name of the key this method opens or creates.
+ /
+
+Creates or opens the specified key.
+
+If key is one of the predefined keys, sub_key may be None. In that case,
+the handle returned is the same key handle passed in to the function.
+
+If the key already exists, this function opens the existing key.
+
+The return value is the handle of the opened key.
+If the function fails, an OSError exception is raised.
+[clinic start generated code]*/
+
+static HKEY
+winreg_CreateKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key)
+/*[clinic end generated code: output=2af13910d56eae26 input=3cdd1622488acea2]*/
+{
+ HKEY retKey;
+ long rc;
+
+ if (PySys_Audit("winreg.CreateKey", "nun",
+ (Py_ssize_t)key, sub_key,
+ (Py_ssize_t)KEY_WRITE) < 0) {
+ return NULL;
+ }
+ rc = RegCreateKeyW(key, sub_key, &retKey);
+ if (rc != ERROR_SUCCESS) {
+ PyErr_SetFromWindowsErrWithFunction(rc, "CreateKey");
+ return NULL;
+ }
+ if (PySys_Audit("winreg.OpenKey/result", "n",
+ (Py_ssize_t)retKey) < 0) {
+ return NULL;
+ }
+ return retKey;
+}
+
+/*[clinic input]
+winreg.CreateKeyEx -> HKEY
+
+ key: HKEY
+ An already open key, or one of the predefined HKEY_* constants.
+ sub_key: Py_UNICODE(accept={str, NoneType})
+ The name of the key this method opens or creates.
+ reserved: int = 0
+ A reserved integer, and must be zero. Default is zero.
+ access: REGSAM(c_default='KEY_WRITE') = winreg.KEY_WRITE
+ An integer that specifies an access mask that describes the
+ desired security access for the key. Default is KEY_WRITE.
+
+Creates or opens the specified key.
+
+If key is one of the predefined keys, sub_key may be None. In that case,
+the handle returned is the same key handle passed in to the function.
+
+If the key already exists, this function opens the existing key
+
+The return value is the handle of the opened key.
+If the function fails, an OSError exception is raised.
+[clinic start generated code]*/
+
+static HKEY
+winreg_CreateKeyEx_impl(PyObject *module, HKEY key,
+ const Py_UNICODE *sub_key, int reserved,
+ REGSAM access)
+/*[clinic end generated code: output=643a70ad6a361a97 input=42c2b03f98406b66]*/
+{
+ HKEY retKey;
+ long rc;
+
+ if (PySys_Audit("winreg.CreateKey", "nun",
+ (Py_ssize_t)key, sub_key,
+ (Py_ssize_t)access) < 0) {
+ return NULL;
+ }
+ rc = RegCreateKeyExW(key, sub_key, reserved, NULL, 0,
+ access, NULL, &retKey, NULL);
+ if (rc != ERROR_SUCCESS) {
+ PyErr_SetFromWindowsErrWithFunction(rc, "CreateKeyEx");
+ return NULL;
+ }
+ if (PySys_Audit("winreg.OpenKey/result", "n",
+ (Py_ssize_t)retKey) < 0) {
+ return NULL;
+ }
+ return retKey;
+}
+
+/*[clinic input]
+winreg.DeleteKey
+ key: HKEY
+ An already open key, or any one of the predefined HKEY_* constants.
+ sub_key: Py_UNICODE
+ A string that must be the name of a subkey of the key identified by
+ the key parameter. This value must not be None, and the key may not
+ have subkeys.
+ /
+
+Deletes the specified key.
+
+This method can not delete keys with subkeys.
+
+If the function succeeds, the entire key, including all of its values,
+is removed. If the function fails, an OSError exception is raised.
+[clinic start generated code]*/
+
+static PyObject *
+winreg_DeleteKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key)
+/*[clinic end generated code: output=d2652a84f70e0862 input=b31d225b935e4211]*/
+{
+ long rc;
+ if (PySys_Audit("winreg.DeleteKey", "nun",
+ (Py_ssize_t)key, sub_key,
+ (Py_ssize_t)0) < 0) {
+ return NULL;
+ }
+ Py_BEGIN_ALLOW_THREADS
+ rc = RegDeleteKeyW(key, sub_key);
+ Py_END_ALLOW_THREADS
+ if (rc != ERROR_SUCCESS)
+ return PyErr_SetFromWindowsErrWithFunction(rc, "RegDeleteKey");
+ Py_RETURN_NONE;
+}
+
+/*[clinic input]
+winreg.DeleteKeyEx
+
+ key: HKEY
+ An already open key, or any one of the predefined HKEY_* constants.
+ sub_key: Py_UNICODE
+ A string that must be the name of a subkey of the key identified by
+ the key parameter. This value must not be None, and the key may not
+ have subkeys.
+ access: REGSAM(c_default='KEY_WOW64_64KEY') = winreg.KEY_WOW64_64KEY
+ An integer that specifies an access mask that describes the
+ desired security access for the key. Default is KEY_WOW64_64KEY.
+ reserved: int = 0
+ A reserved integer, and must be zero. Default is zero.
+
+Deletes the specified key (intended for 64-bit OS).
+
+While this function is intended to be used for 64-bit OS, it is also
+ available on 32-bit systems.
+
+This method can not delete keys with subkeys.
+
+If the function succeeds, the entire key, including all of its values,
+is removed. If the function fails, an OSError exception is raised.
+On unsupported Windows versions, NotImplementedError is raised.
+[clinic start generated code]*/
+
+static PyObject *
+winreg_DeleteKeyEx_impl(PyObject *module, HKEY key,
+ const Py_UNICODE *sub_key, REGSAM access,
+ int reserved)
+/*[clinic end generated code: output=52a1c8b374ebc003 input=a3186db079b3bf85]*/
+{
+ long rc;
+ if (PySys_Audit("winreg.DeleteKey", "nun",
+ (Py_ssize_t)key, sub_key,
+ (Py_ssize_t)access) < 0) {
+ return NULL;
+ }
+ Py_BEGIN_ALLOW_THREADS
+ rc = RegDeleteKeyExW(key, sub_key, access, reserved);
+ Py_END_ALLOW_THREADS
+ if (rc != ERROR_SUCCESS)
+ return PyErr_SetFromWindowsErrWithFunction(rc, "RegDeleteKeyEx");
+ Py_RETURN_NONE;
+}
+
+/*[clinic input]
+winreg.DeleteValue
+
+ key: HKEY
+ An already open key, or any one of the predefined HKEY_* constants.
+ value: Py_UNICODE(accept={str, NoneType})
+ A string that identifies the value to remove.
+ /
+
+Removes a named value from a registry key.
+[clinic start generated code]*/
+
+static PyObject *
+winreg_DeleteValue_impl(PyObject *module, HKEY key, const Py_UNICODE *value)
+/*[clinic end generated code: output=56fa9d21f3a54371 input=a78d3407a4197b21]*/
+{
+ long rc;
+ if (PySys_Audit("winreg.DeleteValue", "nu",
+ (Py_ssize_t)key, value) < 0) {
+ return NULL;
+ }
+ Py_BEGIN_ALLOW_THREADS
+ rc = RegDeleteValueW(key, value);
+ Py_END_ALLOW_THREADS
+ if (rc !=ERROR_SUCCESS)
+ return PyErr_SetFromWindowsErrWithFunction(rc,
+ "RegDeleteValue");
+ Py_RETURN_NONE;
+}
+
+/*[clinic input]
+winreg.EnumKey
+
+ key: HKEY
+ An already open key, or any one of the predefined HKEY_* constants.
+ index: int
+ An integer that identifies the index of the key to retrieve.
+ /
+
+Enumerates subkeys of an open registry key.
+
+The function retrieves the name of one subkey each time it is called.
+It is typically called repeatedly until an OSError exception is
+raised, indicating no more values are available.
+[clinic start generated code]*/
+
+static PyObject *
+winreg_EnumKey_impl(PyObject *module, HKEY key, int index)
+/*[clinic end generated code: output=25a6ec52cd147bc4 input=fad9a7c00ab0e04b]*/
+{
+ long rc;
+ PyObject *retStr;
+
+ if (PySys_Audit("winreg.EnumKey", "ni",
+ (Py_ssize_t)key, index) < 0) {
+ return NULL;
+ }
+ /* The Windows docs claim that the max key name length is 255
+ * characters, plus a terminating nul character. However,
+ * empirical testing demonstrates that it is possible to
+ * create a 256 character key that is missing the terminating
+ * nul. RegEnumKeyEx requires a 257 character buffer to
+ * retrieve such a key name. */
+ wchar_t tmpbuf[257];
+ DWORD len = sizeof(tmpbuf)/sizeof(wchar_t); /* includes NULL terminator */
+
+ Py_BEGIN_ALLOW_THREADS
+ rc = RegEnumKeyExW(key, index, tmpbuf, &len, NULL, NULL, NULL, NULL);
+ Py_END_ALLOW_THREADS
+ if (rc != ERROR_SUCCESS)
+ return PyErr_SetFromWindowsErrWithFunction(rc, "RegEnumKeyEx");
+
+ retStr = PyUnicode_FromWideChar(tmpbuf, len);
+ return retStr; /* can be NULL */
+}
+
+/*[clinic input]
+winreg.EnumValue
+
+ key: HKEY
+ An already open key, or any one of the predefined HKEY_* constants.
+ index: int
+ An integer that identifies the index of the value to retrieve.
+ /
+
+Enumerates values of an open registry key.
+
+The function retrieves the name of one subkey each time it is called.
+It is typically called repeatedly, until an OSError exception
+is raised, indicating no more values.
+
+The result is a tuple of 3 items:
+ value_name
+ A string that identifies the value.
+ value_data
+ An object that holds the value data, and whose type depends
+ on the underlying registry type.
+ data_type
+ An integer that identifies the type of the value data.
+[clinic start generated code]*/
+
+static PyObject *
+winreg_EnumValue_impl(PyObject *module, HKEY key, int index)
+/*[clinic end generated code: output=d363b5a06f8789ac input=4414f47a6fb238b5]*/
+{
+ long rc;
+ wchar_t *retValueBuf;
+ BYTE *tmpBuf;
+ BYTE *retDataBuf;
+ DWORD retValueSize, bufValueSize;
+ DWORD retDataSize, bufDataSize;
+ DWORD typ;
+ PyObject *obData;
+ PyObject *retVal;
+
+ if (PySys_Audit("winreg.EnumValue", "ni",
+ (Py_ssize_t)key, index) < 0) {
+ return NULL;
+ }
+ if ((rc = RegQueryInfoKeyW(key, NULL, NULL, NULL, NULL, NULL, NULL,
+ NULL,
+ &retValueSize, &retDataSize, NULL, NULL))
+ != ERROR_SUCCESS)
+ return PyErr_SetFromWindowsErrWithFunction(rc,
+ "RegQueryInfoKey");
+ ++retValueSize; /* include null terminators */
+ ++retDataSize;
+ bufDataSize = retDataSize;
+ bufValueSize = retValueSize;
+ retValueBuf = PyMem_New(wchar_t, retValueSize);
+ if (retValueBuf == NULL)
+ return PyErr_NoMemory();
+ retDataBuf = (BYTE *)PyMem_Malloc(retDataSize);
+ if (retDataBuf == NULL) {
+ PyMem_Free(retValueBuf);
+ return PyErr_NoMemory();
+ }
+
+ while (1) {
+ Py_BEGIN_ALLOW_THREADS
+ rc = RegEnumValueW(key,
+ index,
+ retValueBuf,
+ &retValueSize,
+ NULL,
+ &typ,
+ (BYTE *)retDataBuf,
+ &retDataSize);
+ Py_END_ALLOW_THREADS
+
+ if (rc != ERROR_MORE_DATA)
+ break;
+
+ bufDataSize *= 2;
+ tmpBuf = (BYTE *)PyMem_Realloc(retDataBuf, bufDataSize);
+ if (tmpBuf == NULL) {
+ PyErr_NoMemory();
+ retVal = NULL;
+ goto fail;
+ }
+ retDataBuf = tmpBuf;
+ retDataSize = bufDataSize;
+ retValueSize = bufValueSize;
+ }
+
+ if (rc != ERROR_SUCCESS) {
+ retVal = PyErr_SetFromWindowsErrWithFunction(rc,
+ "PyRegEnumValue");
+ goto fail;
+ }
+ obData = Reg2Py(retDataBuf, retDataSize, typ);
+ if (obData == NULL) {
+ retVal = NULL;
+ goto fail;
+ }
+ retVal = Py_BuildValue("uOi", retValueBuf, obData, typ);
+ Py_DECREF(obData);
+ fail:
+ PyMem_Free(retValueBuf);
+ PyMem_Free(retDataBuf);
+ return retVal;
+}
+
+/*[clinic input]
+winreg.ExpandEnvironmentStrings
+
+ string: Py_UNICODE
+ /
+
+Expand environment vars.
+[clinic start generated code]*/
+
+static PyObject *
+winreg_ExpandEnvironmentStrings_impl(PyObject *module,
+ const Py_UNICODE *string)
+/*[clinic end generated code: output=8fa4e959747a7312 input=b2a9714d2b751aa6]*/
+{
+ wchar_t *retValue = NULL;
+ DWORD retValueSize;
+ DWORD rc;
+ PyObject *o;
+
+ if (PySys_Audit("winreg.ExpandEnvironmentStrings", "u",
+ string) < 0) {
+ return NULL;
+ }
+
+ retValueSize = ExpandEnvironmentStringsW(string, retValue, 0);
+ if (retValueSize == 0) {
+ return PyErr_SetFromWindowsErrWithFunction(retValueSize,
+ "ExpandEnvironmentStrings");
+ }
+ retValue = PyMem_New(wchar_t, retValueSize);
+ if (retValue == NULL) {
+ return PyErr_NoMemory();
+ }
+
+ rc = ExpandEnvironmentStringsW(string, retValue, retValueSize);
+ if (rc == 0) {
+ PyMem_Free(retValue);
+ return PyErr_SetFromWindowsErrWithFunction(retValueSize,
+ "ExpandEnvironmentStrings");
+ }
+ o = PyUnicode_FromWideChar(retValue, wcslen(retValue));
+ PyMem_Free(retValue);
+ return o;
+}
+
+#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)
+
+/*[clinic input]
+winreg.FlushKey
+
+ key: HKEY
+ An already open key, or any one of the predefined HKEY_* constants.
+ /
+
+Writes all the attributes of a key to the registry.
+
+It is not necessary to call FlushKey to change a key. Registry changes
+are flushed to disk by the registry using its lazy flusher. Registry
+changes are also flushed to disk at system shutdown. Unlike
+CloseKey(), the FlushKey() method returns only when all the data has
+been written to the registry.
+
+An application should only call FlushKey() if it requires absolute
+certainty that registry changes are on disk. If you don't know whether
+a FlushKey() call is required, it probably isn't.
+[clinic start generated code]*/
+
+static PyObject *
+winreg_FlushKey_impl(PyObject *module, HKEY key)
+/*[clinic end generated code: output=e6fc230d4c5dc049 input=f57457c12297d82f]*/
+{
+ long rc;
+ Py_BEGIN_ALLOW_THREADS
+ rc = RegFlushKey(key);
+ Py_END_ALLOW_THREADS
+ if (rc != ERROR_SUCCESS)
+ return PyErr_SetFromWindowsErrWithFunction(rc, "RegFlushKey");
+ Py_RETURN_NONE;
+}
+
+#endif /* MS_WINDOWS_DESKTOP || MS_WINDOWS_SYSTEM */
+
+#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)
+
+/*[clinic input]
+winreg.LoadKey
+
+ key: HKEY
+ An already open key, or any one of the predefined HKEY_* constants.
+ sub_key: Py_UNICODE
+ A string that identifies the sub-key to load.
+ file_name: Py_UNICODE
+ The name of the file to load registry data from. This file must
+ have been created with the SaveKey() function. Under the file
+ allocation table (FAT) file system, the filename may not have an
+ extension.
+ /
+
+Insert data into the registry from a file.
+
+Creates a subkey under the specified key and stores registration
+information from a specified file into that subkey.
+
+A call to LoadKey() fails if the calling process does not have the
+SE_RESTORE_PRIVILEGE privilege.
+
+If key is a handle returned by ConnectRegistry(), then the path
+specified in fileName is relative to the remote computer.
+
+The MSDN docs imply key must be in the HKEY_USER or HKEY_LOCAL_MACHINE
+tree.
+[clinic start generated code]*/
+
+static PyObject *
+winreg_LoadKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
+ const Py_UNICODE *file_name)
+/*[clinic end generated code: output=65f89f2548cb27c7 input=e3b5b45ade311582]*/
+{
+ long rc;
+
+ if (PySys_Audit("winreg.LoadKey", "nuu",
+ (Py_ssize_t)key, sub_key, file_name) < 0) {
+ return NULL;
+ }
+ Py_BEGIN_ALLOW_THREADS
+ rc = RegLoadKeyW(key, sub_key, file_name );
+ Py_END_ALLOW_THREADS
+ if (rc != ERROR_SUCCESS)
+ return PyErr_SetFromWindowsErrWithFunction(rc, "RegLoadKey");
+ Py_RETURN_NONE;
+}
+
+#endif /* MS_WINDOWS_DESKTOP || MS_WINDOWS_SYSTEM */
+
+/*[clinic input]
+winreg.OpenKey -> HKEY
+
+ key: HKEY
+ An already open key, or any one of the predefined HKEY_* constants.
+ sub_key: Py_UNICODE(accept={str, NoneType})
+ A string that identifies the sub_key to open.
+ reserved: int = 0
+ A reserved integer that must be zero. Default is zero.
+ access: REGSAM(c_default='KEY_READ') = winreg.KEY_READ
+ An integer that specifies an access mask that describes the desired
+ security access for the key. Default is KEY_READ.
+
+Opens the specified key.
+
+The result is a new handle to the specified key.
+If the function fails, an OSError exception is raised.
+[clinic start generated code]*/
+
+static HKEY
+winreg_OpenKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
+ int reserved, REGSAM access)
+/*[clinic end generated code: output=8849bff2c30104ad input=098505ac36a9ae28]*/
+{
+ HKEY retKey;
+ long rc;
+
+ if (PySys_Audit("winreg.OpenKey", "nun",
+ (Py_ssize_t)key, sub_key,
+ (Py_ssize_t)access) < 0) {
+ return NULL;
+ }
+ Py_BEGIN_ALLOW_THREADS
+ rc = RegOpenKeyExW(key, sub_key, reserved, access, &retKey);
+ Py_END_ALLOW_THREADS
+ if (rc != ERROR_SUCCESS) {
+ PyErr_SetFromWindowsErrWithFunction(rc, "RegOpenKeyEx");
+ return NULL;
+ }
+ if (PySys_Audit("winreg.OpenKey/result", "n",
+ (Py_ssize_t)retKey) < 0) {
+ return NULL;
+ }
+ return retKey;
+}
+
+/*[clinic input]
+winreg.OpenKeyEx = winreg.OpenKey
+
+Opens the specified key.
+
+The result is a new handle to the specified key.
+If the function fails, an OSError exception is raised.
+[clinic start generated code]*/
+
+static HKEY
+winreg_OpenKeyEx_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
+ int reserved, REGSAM access)
+/*[clinic end generated code: output=81bc2bd684bc77ae input=c6c4972af8622959]*/
+{
+ return winreg_OpenKey_impl(module, key, sub_key, reserved, access);
+}
+
+/*[clinic input]
+winreg.QueryInfoKey
+
+ key: HKEY
+ An already open key, or any one of the predefined HKEY_* constants.
+ /
+
+Returns information about a key.
+
+The result is a tuple of 3 items:
+An integer that identifies the number of sub keys this key has.
+An integer that identifies the number of values this key has.
+An integer that identifies when the key was last modified (if available)
+as 100's of nanoseconds since Jan 1, 1600.
+[clinic start generated code]*/
+
+static PyObject *
+winreg_QueryInfoKey_impl(PyObject *module, HKEY key)
+/*[clinic end generated code: output=dc657b8356a4f438 input=c3593802390cde1f]*/
+{
+ long rc;
+ DWORD nSubKeys, nValues;
+ FILETIME ft;
+ LARGE_INTEGER li;
+ PyObject *l;
+ PyObject *ret;
+
+ if (PySys_Audit("winreg.QueryInfoKey", "n", (Py_ssize_t)key) < 0) {
+ return NULL;
+ }
+ if ((rc = RegQueryInfoKeyW(key, NULL, NULL, 0, &nSubKeys, NULL, NULL,
+ &nValues, NULL, NULL, NULL, &ft))
+ != ERROR_SUCCESS) {
+ return PyErr_SetFromWindowsErrWithFunction(rc, "RegQueryInfoKey");
+ }
+ li.LowPart = ft.dwLowDateTime;
+ li.HighPart = ft.dwHighDateTime;
+ l = PyLong_FromLongLong(li.QuadPart);
+ if (l == NULL) {
+ return NULL;
+ }
+ ret = Py_BuildValue("iiO", nSubKeys, nValues, l);
+ Py_DECREF(l);
+ return ret;
+}
+
+
+/*[clinic input]
+winreg.QueryValue
+
+ key: HKEY
+ An already open key, or any one of the predefined HKEY_* constants.
+ sub_key: Py_UNICODE(accept={str, NoneType})
+ A string that holds the name of the subkey with which the value
+ is associated. If this parameter is None or empty, the function
+ retrieves the value set by the SetValue() method for the key
+ identified by key.
+ /
+
+Retrieves the unnamed value for a key.
+
+Values in the registry have name, type, and data components. This method
+retrieves the data for a key's first value that has a NULL name.
+But since the underlying API call doesn't return the type, you'll
+probably be happier using QueryValueEx; this function is just here for
+completeness.
+[clinic start generated code]*/
+
+static PyObject *
+winreg_QueryValue_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key)
+/*[clinic end generated code: output=c655810ae50c63a9 input=41cafbbf423b21d6]*/
+{
+ LONG rc;
+ HKEY childKey = key;
+ WCHAR buf[256], *pbuf = buf;
+ DWORD size = sizeof(buf);
+ DWORD type;
+ Py_ssize_t length;
+ PyObject *result = NULL;
+
+ if (PySys_Audit("winreg.QueryValue", "nuu",
+ (Py_ssize_t)key, sub_key, NULL) < 0)
+ {
+ return NULL;
+ }
+
+ if (key == HKEY_PERFORMANCE_DATA) {
+ return PyErr_SetFromWindowsErrWithFunction(ERROR_INVALID_HANDLE,
+ "RegQueryValue");
+ }
+
+ if (sub_key && sub_key[0]) {
+ Py_BEGIN_ALLOW_THREADS
+ rc = RegOpenKeyExW(key, sub_key, 0, KEY_QUERY_VALUE, &childKey);
+ Py_END_ALLOW_THREADS
+ if (rc != ERROR_SUCCESS) {
+ return PyErr_SetFromWindowsErrWithFunction(rc, "RegOpenKeyEx");
+ }
+ }
+
+ while (1) {
+ Py_BEGIN_ALLOW_THREADS
+ rc = RegQueryValueExW(childKey, NULL, NULL, &type, (LPBYTE)pbuf,
+ &size);
+ Py_END_ALLOW_THREADS
+ if (rc != ERROR_MORE_DATA) {
+ break;
+ }
+ void *tmp = PyMem_Realloc(pbuf != buf ? pbuf : NULL, size);
+ if (tmp == NULL) {
+ PyErr_NoMemory();
+ goto exit;
+ }
+ pbuf = tmp;
+ }
+
+ if (rc == ERROR_SUCCESS) {
+ if (type != REG_SZ) {
+ PyErr_SetFromWindowsErrWithFunction(ERROR_INVALID_DATA,
+ "RegQueryValue");
+ goto exit;
+ }
+ length = wcsnlen(pbuf, size / sizeof(WCHAR));
+ }
+ else if (rc == ERROR_FILE_NOT_FOUND) {
+ // Return an empty string if there's no default value.
+ length = 0;
+ }
+ else {
+ PyErr_SetFromWindowsErrWithFunction(rc, "RegQueryValueEx");
+ goto exit;
+ }
+
+ result = PyUnicode_FromWideChar(pbuf, length);
+
+exit:
+ if (pbuf != buf) {
+ PyMem_Free(pbuf);
+ }
+ if (childKey != key) {
+ RegCloseKey(childKey);
+ }
+ return result;
+}
+
+
+/*[clinic input]
+winreg.QueryValueEx
+
+ key: HKEY
+ An already open key, or any one of the predefined HKEY_* constants.
+ name: Py_UNICODE(accept={str, NoneType})
+ A string indicating the value to query.
+ /
+
+Retrieves the type and value of a specified sub-key.
+
+Behaves mostly like QueryValue(), but also returns the type of the
+specified value name associated with the given open registry key.
+
+The return value is a tuple of the value and the type_id.
+[clinic start generated code]*/
+
+static PyObject *
+winreg_QueryValueEx_impl(PyObject *module, HKEY key, const Py_UNICODE *name)
+/*[clinic end generated code: output=f1b85b1c3d887ec7 input=cf366cada4836891]*/
+{
+ long rc;
+ BYTE *retBuf, *tmp;
+ DWORD bufSize = 0, retSize;
+ DWORD typ;
+ PyObject *obData;
+ PyObject *result;
+
+ if (PySys_Audit("winreg.QueryValue", "nuu",
+ (Py_ssize_t)key, NULL, name) < 0) {
+ return NULL;
+ }
+ rc = RegQueryValueExW(key, name, NULL, NULL, NULL, &bufSize);
+ if (rc == ERROR_MORE_DATA)
+ bufSize = 256;
+ else if (rc != ERROR_SUCCESS)
+ return PyErr_SetFromWindowsErrWithFunction(rc,
+ "RegQueryValueEx");
+ retBuf = (BYTE *)PyMem_Malloc(bufSize);
+ if (retBuf == NULL)
+ return PyErr_NoMemory();
+
+ while (1) {
+ retSize = bufSize;
+ rc = RegQueryValueExW(key, name, NULL, &typ,
+ (BYTE *)retBuf, &retSize);
+ if (rc != ERROR_MORE_DATA)
+ break;
+
+ bufSize *= 2;
+ tmp = (char *) PyMem_Realloc(retBuf, bufSize);
+ if (tmp == NULL) {
+ PyMem_Free(retBuf);
+ return PyErr_NoMemory();
+ }
+ retBuf = tmp;
+ }
+
+ if (rc != ERROR_SUCCESS) {
+ PyMem_Free(retBuf);
+ return PyErr_SetFromWindowsErrWithFunction(rc,
+ "RegQueryValueEx");
+ }
+ obData = Reg2Py(retBuf, bufSize, typ);
+ PyMem_Free(retBuf);
+ if (obData == NULL)
+ return NULL;
+ result = Py_BuildValue("Oi", obData, typ);
+ Py_DECREF(obData);
+ return result;
+}
+
+#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)
+
+/*[clinic input]
+winreg.SaveKey
+
+ key: HKEY
+ An already open key, or any one of the predefined HKEY_* constants.
+ file_name: Py_UNICODE
+ The name of the file to save registry data to. This file cannot
+ already exist. If this filename includes an extension, it cannot be
+ used on file allocation table (FAT) file systems by the LoadKey(),
+ ReplaceKey() or RestoreKey() methods.
+ /
+
+Saves the specified key, and all its subkeys to the specified file.
+
+If key represents a key on a remote computer, the path described by
+file_name is relative to the remote computer.
+
+The caller of this method must possess the SeBackupPrivilege
+security privilege. This function passes NULL for security_attributes
+to the API.
+[clinic start generated code]*/
+
+static PyObject *
+winreg_SaveKey_impl(PyObject *module, HKEY key, const Py_UNICODE *file_name)
+/*[clinic end generated code: output=ca94b835c88f112b input=da735241f91ac7a2]*/
+{
+ LPSECURITY_ATTRIBUTES pSA = NULL;
+
+ long rc;
+/* One day we may get security into the core?
+ if (!PyWinObject_AsSECURITY_ATTRIBUTES(obSA, &pSA, TRUE))
+ return NULL;
+*/
+ if (PySys_Audit("winreg.SaveKey", "nu",
+ (Py_ssize_t)key, file_name) < 0) {
+ return NULL;
+ }
+ Py_BEGIN_ALLOW_THREADS
+ rc = RegSaveKeyW(key, file_name, pSA );
+ Py_END_ALLOW_THREADS
+ if (rc != ERROR_SUCCESS)
+ return PyErr_SetFromWindowsErrWithFunction(rc, "RegSaveKey");
+ Py_RETURN_NONE;
+}
+
+#endif /* MS_WINDOWS_DESKTOP || MS_WINDOWS_SYSTEM */
+
+/*[clinic input]
+winreg.SetValue
+
+ key: HKEY
+ An already open key, or any one of the predefined HKEY_* constants.
+ sub_key: Py_UNICODE(accept={str, NoneType})
+ A string that names the subkey with which the value is associated.
+ type: DWORD
+ An integer that specifies the type of the data. Currently this must
+ be REG_SZ, meaning only strings are supported.
+ value as value_obj: unicode
+ A string that specifies the new value.
+ /
+
+Associates a value with a specified key.
+
+If the key specified by the sub_key parameter does not exist, the
+SetValue function creates it.
+
+Value lengths are limited by available memory. Long values (more than
+2048 bytes) should be stored as files with the filenames stored in
+the configuration registry to help the registry perform efficiently.
+
+The key identified by the key parameter must have been opened with
+KEY_SET_VALUE access.
+[clinic start generated code]*/
+
+static PyObject *
+winreg_SetValue_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key,
+ DWORD type, PyObject *value_obj)
+/*[clinic end generated code: output=d4773dc9c372311a input=bf088494ae2d24fd]*/
+{
+ LONG rc;
+ HKEY childKey = key;
+ LPWSTR value;
+ Py_ssize_t size;
+ Py_ssize_t length;
+ PyObject *result = NULL;
+
+ if (type != REG_SZ) {
+ PyErr_SetString(PyExc_TypeError, "type must be winreg.REG_SZ");
+ return NULL;
+ }
+
+ value = PyUnicode_AsWideCharString(value_obj, &length);
+ if (value == NULL) {
+ return NULL;
+ }
+
+ size = (length + 1) * sizeof(WCHAR);
+ if ((Py_ssize_t)(DWORD)size != size) {
+ PyErr_SetString(PyExc_OverflowError, "value is too long");
+ goto exit;
+ }
+
+ if (PySys_Audit("winreg.SetValue", "nunu#",
+ (Py_ssize_t)key, sub_key, (Py_ssize_t)type,
+ value, length) < 0)
+ {
+ goto exit;
+ }
+
+ if (key == HKEY_PERFORMANCE_DATA) {
+ PyErr_SetFromWindowsErrWithFunction(ERROR_INVALID_HANDLE,
+ "RegSetValue");
+ goto exit;
+ }
+
+ if (sub_key && sub_key[0]) {
+ Py_BEGIN_ALLOW_THREADS
+ rc = RegCreateKeyExW(key, sub_key, 0, NULL, 0, KEY_SET_VALUE, NULL,
+ &childKey, NULL);
+ Py_END_ALLOW_THREADS
+ if (rc != ERROR_SUCCESS) {
+ PyErr_SetFromWindowsErrWithFunction(rc, "RegCreateKeyEx");
+ goto exit;
+ }
+ }
+
+ Py_BEGIN_ALLOW_THREADS
+ rc = RegSetValueExW(childKey, NULL, 0, REG_SZ, (LPBYTE)value, (DWORD)size);
+ Py_END_ALLOW_THREADS
+ if (rc == ERROR_SUCCESS) {
+ result = Py_NewRef(Py_None);
+ }
+ else {
+ PyErr_SetFromWindowsErrWithFunction(rc, "RegSetValueEx");
+ }
+
+exit:
+ PyMem_Free(value);
+ if (childKey != key) {
+ RegCloseKey(childKey);
+ }
+ return result;
+}
+
+
+/*[clinic input]
+winreg.SetValueEx
+
+ key: HKEY
+ An already open key, or any one of the predefined HKEY_* constants.
+ value_name: Py_UNICODE(accept={str, NoneType})
+ A string containing the name of the value to set, or None.
+ reserved: object
+ Can be anything - zero is always passed to the API.
+ type: DWORD
+ An integer that specifies the type of the data, one of:
+ REG_BINARY -- Binary data in any form.
+ REG_DWORD -- A 32-bit number.
+ REG_DWORD_LITTLE_ENDIAN -- A 32-bit number in little-endian format. Equivalent to REG_DWORD
+ REG_DWORD_BIG_ENDIAN -- A 32-bit number in big-endian format.
+ REG_EXPAND_SZ -- A null-terminated string that contains unexpanded
+ references to environment variables (for example,
+ %PATH%).
+ REG_LINK -- A Unicode symbolic link.
+ REG_MULTI_SZ -- A sequence of null-terminated strings, terminated
+ by two null characters. Note that Python handles
+ this termination automatically.
+ REG_NONE -- No defined value type.
+ REG_QWORD -- A 64-bit number.
+ REG_QWORD_LITTLE_ENDIAN -- A 64-bit number in little-endian format. Equivalent to REG_QWORD.
+ REG_RESOURCE_LIST -- A device-driver resource list.
+ REG_SZ -- A null-terminated string.
+ value: object
+ A string that specifies the new value.
+ /
+
+Stores data in the value field of an open registry key.
+
+This method can also set additional value and type information for the
+specified key. The key identified by the key parameter must have been
+opened with KEY_SET_VALUE access.
+
+To open the key, use the CreateKeyEx() or OpenKeyEx() methods.
+
+Value lengths are limited by available memory. Long values (more than
+2048 bytes) should be stored as files with the filenames stored in
+the configuration registry to help the registry perform efficiently.
+[clinic start generated code]*/
+
+static PyObject *
+winreg_SetValueEx_impl(PyObject *module, HKEY key,
+ const Py_UNICODE *value_name, PyObject *reserved,
+ DWORD type, PyObject *value)
+/*[clinic end generated code: output=811b769a66ae11b7 input=900a9e3990bfb196]*/
+{
+ LONG rc;
+ BYTE *data = NULL;
+ DWORD size;
+ PyObject *result = NULL;
+
+ if (!Py2Reg(value, type, &data, &size))
+ {
+ if (!PyErr_Occurred()) {
+ PyErr_SetString(PyExc_ValueError,
+ "Could not convert the data to the specified type.");
+ }
+ return NULL;
+ }
+ if (PySys_Audit("winreg.SetValue", "nunO",
+ (Py_ssize_t)key, value_name, (Py_ssize_t)type,
+ value) < 0)
+ {
+ goto exit;
+ }
+
+ Py_BEGIN_ALLOW_THREADS
+ rc = RegSetValueExW(key, value_name, 0, type, data, size);
+ Py_END_ALLOW_THREADS
+ if (rc == ERROR_SUCCESS) {
+ result = Py_NewRef(Py_None);
+ }
+ else {
+ PyErr_SetFromWindowsErrWithFunction(rc, "RegSetValueEx");
+ }
+
+exit:
+ PyMem_Free(data);
+ return result;
+}
+
+#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)
+
+/*[clinic input]
+winreg.DisableReflectionKey
+
+ key: HKEY
+ An already open key, or any one of the predefined HKEY_* constants.
+ /
+
+Disables registry reflection for 32bit processes running on a 64bit OS.
+
+Will generally raise NotImplementedError if executed on a 32bit OS.
+
+If the key is not on the reflection list, the function succeeds but has
+no effect. Disabling reflection for a key does not affect reflection
+of any subkeys.
+[clinic start generated code]*/
+
+static PyObject *
+winreg_DisableReflectionKey_impl(PyObject *module, HKEY key)
+/*[clinic end generated code: output=830cce504cc764b4 input=70bece2dee02e073]*/
+{
+ HMODULE hMod;
+ typedef LONG (WINAPI *RDRKFunc)(HKEY);
+ RDRKFunc pfn = NULL;
+ LONG rc;
+
+ if (PySys_Audit("winreg.DisableReflectionKey", "n", (Py_ssize_t)key) < 0) {
+ return NULL;
+ }
+
+ /* Only available on 64bit platforms, so we must load it
+ dynamically.*/
+ Py_BEGIN_ALLOW_THREADS
+ hMod = GetModuleHandleW(L"advapi32.dll");
+ if (hMod)
+ pfn = (RDRKFunc)GetProcAddress(hMod,
+ "RegDisableReflectionKey");
+ Py_END_ALLOW_THREADS
+ if (!pfn) {
+ PyErr_SetString(PyExc_NotImplementedError,
+ "not implemented on this platform");
+ return NULL;
+ }
+ Py_BEGIN_ALLOW_THREADS
+ rc = (*pfn)(key);
+ Py_END_ALLOW_THREADS
+ if (rc != ERROR_SUCCESS)
+ return PyErr_SetFromWindowsErrWithFunction(rc,
+ "RegDisableReflectionKey");
+ Py_RETURN_NONE;
+}
+
+/*[clinic input]
+winreg.EnableReflectionKey
+
+ key: HKEY
+ An already open key, or any one of the predefined HKEY_* constants.
+ /
+
+Restores registry reflection for the specified disabled key.
+
+Will generally raise NotImplementedError if executed on a 32bit OS.
+Restoring reflection for a key does not affect reflection of any
+subkeys.
+[clinic start generated code]*/
+
+static PyObject *
+winreg_EnableReflectionKey_impl(PyObject *module, HKEY key)
+/*[clinic end generated code: output=86fa1385fdd9ce57 input=eeae770c6eb9f559]*/
+{
+ HMODULE hMod;
+ typedef LONG (WINAPI *RERKFunc)(HKEY);
+ RERKFunc pfn = NULL;
+ LONG rc;
+
+ if (PySys_Audit("winreg.EnableReflectionKey", "n", (Py_ssize_t)key) < 0) {
+ return NULL;
+ }
+
+ /* Only available on 64bit platforms, so we must load it
+ dynamically.*/
+ Py_BEGIN_ALLOW_THREADS
+ hMod = GetModuleHandleW(L"advapi32.dll");
+ if (hMod)
+ pfn = (RERKFunc)GetProcAddress(hMod,
+ "RegEnableReflectionKey");
+ Py_END_ALLOW_THREADS
+ if (!pfn) {
+ PyErr_SetString(PyExc_NotImplementedError,
+ "not implemented on this platform");
+ return NULL;
+ }
+ Py_BEGIN_ALLOW_THREADS
+ rc = (*pfn)(key);
+ Py_END_ALLOW_THREADS
+ if (rc != ERROR_SUCCESS)
+ return PyErr_SetFromWindowsErrWithFunction(rc,
+ "RegEnableReflectionKey");
+ Py_RETURN_NONE;
+}
+
+/*[clinic input]
+winreg.QueryReflectionKey
+
+ key: HKEY
+ An already open key, or any one of the predefined HKEY_* constants.
+ /
+
+Returns the reflection state for the specified key as a bool.
+
+Will generally raise NotImplementedError if executed on a 32bit OS.
+[clinic start generated code]*/
+
+static PyObject *
+winreg_QueryReflectionKey_impl(PyObject *module, HKEY key)
+/*[clinic end generated code: output=4e774af288c3ebb9 input=a98fa51d55ade186]*/
+{
+ HMODULE hMod;
+ typedef LONG (WINAPI *RQRKFunc)(HKEY, BOOL *);
+ RQRKFunc pfn = NULL;
+ BOOL result;
+ LONG rc;
+
+ if (PySys_Audit("winreg.QueryReflectionKey", "n", (Py_ssize_t)key) < 0) {
+ return NULL;
+ }
+
+ /* Only available on 64bit platforms, so we must load it
+ dynamically.*/
+ Py_BEGIN_ALLOW_THREADS
+ hMod = GetModuleHandleW(L"advapi32.dll");
+ if (hMod)
+ pfn = (RQRKFunc)GetProcAddress(hMod,
+ "RegQueryReflectionKey");
+ Py_END_ALLOW_THREADS
+ if (!pfn) {
+ PyErr_SetString(PyExc_NotImplementedError,
+ "not implemented on this platform");
+ return NULL;
+ }
+ Py_BEGIN_ALLOW_THREADS
+ rc = (*pfn)(key, &result);
+ Py_END_ALLOW_THREADS
+ if (rc != ERROR_SUCCESS)
+ return PyErr_SetFromWindowsErrWithFunction(rc,
+ "RegQueryReflectionKey");
+ return PyBool_FromLong(result);
+}
+
+#endif /* MS_WINDOWS_DESKTOP || MS_WINDOWS_SYSTEM */
+
+static struct PyMethodDef winreg_methods[] = {
+ WINREG_CLOSEKEY_METHODDEF
+ WINREG_CONNECTREGISTRY_METHODDEF
+ WINREG_CREATEKEY_METHODDEF
+ WINREG_CREATEKEYEX_METHODDEF
+ WINREG_DELETEKEY_METHODDEF
+ WINREG_DELETEKEYEX_METHODDEF
+ WINREG_DELETEVALUE_METHODDEF
+ WINREG_DISABLEREFLECTIONKEY_METHODDEF
+ WINREG_ENABLEREFLECTIONKEY_METHODDEF
+ WINREG_ENUMKEY_METHODDEF
+ WINREG_ENUMVALUE_METHODDEF
+ WINREG_EXPANDENVIRONMENTSTRINGS_METHODDEF
+ WINREG_FLUSHKEY_METHODDEF
+ WINREG_LOADKEY_METHODDEF
+ WINREG_OPENKEY_METHODDEF
+ WINREG_OPENKEYEX_METHODDEF
+ WINREG_QUERYVALUE_METHODDEF
+ WINREG_QUERYVALUEEX_METHODDEF
+ WINREG_QUERYINFOKEY_METHODDEF
+ WINREG_QUERYREFLECTIONKEY_METHODDEF
+ WINREG_SAVEKEY_METHODDEF
+ WINREG_SETVALUE_METHODDEF
+ WINREG_SETVALUEEX_METHODDEF
+ NULL,
+};
+
+#define ADD_INT(VAL) do { \
+ if (PyModule_AddIntConstant(m, #VAL, VAL) < 0) { \
+ return -1; \
+ } \
+} while (0)
+
+static int
+inskey(PyObject *mod, char *name, HKEY key)
+{
+ PyObject *v = PyLong_FromVoidPtr(key);
+ if (v == NULL) {
+ return -1;
+ }
+ int rc = PyModule_AddObjectRef(mod, name, v);
+ Py_DECREF(v);
+ return rc;
+}
+
+#define ADD_KEY(VAL) do { \
+ if (inskey(m, #VAL, VAL) < 0) { \
+ return -1; \
+ } \
+} while (0)
+
+static int
+exec_module(PyObject *m)
+{
+ winreg_state *st = (winreg_state *)_PyModule_GetState(m);
+
+ st->PyHKEY_Type = (PyTypeObject *)
+ PyType_FromModuleAndSpec(m, &pyhkey_type_spec, NULL);
+ if (st->PyHKEY_Type == NULL) {
+ return -1;
+ }
+ if (PyModule_AddObjectRef(m, "HKEYType", (PyObject *)st->PyHKEY_Type) < 0) {
+ return -1;
+ }
+ if (PyModule_AddObjectRef(m, "error", PyExc_OSError) < 0) {
+ return -1;
+ }
+
+ /* Add the relevant constants */
+ ADD_KEY(HKEY_CLASSES_ROOT);
+ ADD_KEY(HKEY_CURRENT_USER);
+ ADD_KEY(HKEY_LOCAL_MACHINE);
+ ADD_KEY(HKEY_USERS);
+ ADD_KEY(HKEY_PERFORMANCE_DATA);
+#ifdef HKEY_CURRENT_CONFIG
+ ADD_KEY(HKEY_CURRENT_CONFIG);
+#endif
+#ifdef HKEY_DYN_DATA
+ ADD_KEY(HKEY_DYN_DATA);
+#endif
+ ADD_INT(KEY_QUERY_VALUE);
+ ADD_INT(KEY_SET_VALUE);
+ ADD_INT(KEY_CREATE_SUB_KEY);
+ ADD_INT(KEY_ENUMERATE_SUB_KEYS);
+ ADD_INT(KEY_NOTIFY);
+ ADD_INT(KEY_CREATE_LINK);
+ ADD_INT(KEY_READ);
+ ADD_INT(KEY_WRITE);
+ ADD_INT(KEY_EXECUTE);
+ ADD_INT(KEY_ALL_ACCESS);
+#ifdef KEY_WOW64_64KEY
+ ADD_INT(KEY_WOW64_64KEY);
+#endif
+#ifdef KEY_WOW64_32KEY
+ ADD_INT(KEY_WOW64_32KEY);
+#endif
+ ADD_INT(REG_OPTION_RESERVED);
+ ADD_INT(REG_OPTION_NON_VOLATILE);
+ ADD_INT(REG_OPTION_VOLATILE);
+ ADD_INT(REG_OPTION_CREATE_LINK);
+ ADD_INT(REG_OPTION_BACKUP_RESTORE);
+ ADD_INT(REG_OPTION_OPEN_LINK);
+ ADD_INT(REG_LEGAL_OPTION);
+ ADD_INT(REG_CREATED_NEW_KEY);
+ ADD_INT(REG_OPENED_EXISTING_KEY);
+ ADD_INT(REG_WHOLE_HIVE_VOLATILE);
+ ADD_INT(REG_REFRESH_HIVE);
+ ADD_INT(REG_NO_LAZY_FLUSH);
+ ADD_INT(REG_NOTIFY_CHANGE_NAME);
+ ADD_INT(REG_NOTIFY_CHANGE_ATTRIBUTES);
+ ADD_INT(REG_NOTIFY_CHANGE_LAST_SET);
+ ADD_INT(REG_NOTIFY_CHANGE_SECURITY);
+ ADD_INT(REG_LEGAL_CHANGE_FILTER);
+ ADD_INT(REG_NONE);
+ ADD_INT(REG_SZ);
+ ADD_INT(REG_EXPAND_SZ);
+ ADD_INT(REG_BINARY);
+ ADD_INT(REG_DWORD);
+ ADD_INT(REG_DWORD_LITTLE_ENDIAN);
+ ADD_INT(REG_DWORD_BIG_ENDIAN);
+ ADD_INT(REG_QWORD);
+ ADD_INT(REG_QWORD_LITTLE_ENDIAN);
+ ADD_INT(REG_LINK);
+ ADD_INT(REG_MULTI_SZ);
+ ADD_INT(REG_RESOURCE_LIST);
+ ADD_INT(REG_FULL_RESOURCE_DESCRIPTOR);
+ ADD_INT(REG_RESOURCE_REQUIREMENTS_LIST);
+
+#undef ADD_INT
+ return 0;
+}
+
+static PyModuleDef_Slot winreg_slots[] = {
+ {Py_mod_exec, exec_module},
+ {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+ {0, NULL}
+};
+
+static int
+winreg_traverse(PyObject *module, visitproc visit, void *arg)
+{
+ winreg_state *state = _PyModule_GetState(module);
+ Py_VISIT(state->PyHKEY_Type);
+ return 0;
+}
+
+static int
+winreg_clear(PyObject *module)
+{
+ winreg_state *state = _PyModule_GetState(module);
+ Py_CLEAR(state->PyHKEY_Type);
+ return 0;
+}
+
+static struct PyModuleDef winregmodule = {
+ .m_base = PyModuleDef_HEAD_INIT,
+ .m_name = "winreg",
+ .m_doc = module_doc,
+ .m_size = sizeof(winreg_state),
+ .m_methods = winreg_methods,
+ .m_slots = winreg_slots,
+ .m_traverse = winreg_traverse,
+ .m_clear = winreg_clear,
+};
+
+PyMODINIT_FUNC PyInit_winreg(void)
+{
+ return PyModuleDef_Init(&winregmodule);
+}
+
+#endif /* MS_WINDOWS_DESKTOP || MS_WINDOWS_SYSTEM || MS_WINDOWS_GAMES */
diff --git a/contrib/tools/python3/PC/winsound.c b/contrib/tools/python3/PC/winsound.c
new file mode 100644
index 00000000000..68a917810f8
--- /dev/null
+++ b/contrib/tools/python3/PC/winsound.c
@@ -0,0 +1,254 @@
+/* Author: Toby Dickenson <[email protected]>
+ *
+ * Copyright (c) 1999 Toby Dickenson
+ *
+ * Permission to use this software in any way is granted without
+ * fee, provided that the copyright notice above appears in all
+ * copies. This software is provided "as is" without any warranty.
+ */
+
+/* Modified by Guido van Rossum */
+/* Beep added by Mark Hammond */
+/* Win9X Beep and platform identification added by Uncle Timmy */
+
+/* Example:
+
+ import winsound
+ import time
+
+ # Play wav file
+ winsound.PlaySound('c:/windows/media/Chord.wav', winsound.SND_FILENAME)
+
+ # Play sound from control panel settings
+ winsound.PlaySound('SystemQuestion', winsound.SND_ALIAS)
+
+ # Play wav file from memory
+ data=open('c:/windows/media/Chimes.wav',"rb").read()
+ winsound.PlaySound(data, winsound.SND_MEMORY)
+
+ # Start playing the first bit of wav file asynchronously
+ winsound.PlaySound('c:/windows/media/Chord.wav',
+ winsound.SND_FILENAME|winsound.SND_ASYNC)
+ # But don't let it go for too long...
+ time.sleep(0.1)
+ # ...Before stopping it
+ winsound.PlaySound(None, 0)
+*/
+
+#include <Python.h>
+#include <windows.h>
+#include <mmsystem.h>
+
+PyDoc_STRVAR(sound_module_doc,
+"PlaySound(sound, flags) - play a sound\n"
+"SND_FILENAME - sound is a wav file name\n"
+"SND_ALIAS - sound is a registry sound association name\n"
+"SND_LOOP - Play the sound repeatedly; must also specify SND_ASYNC\n"
+"SND_MEMORY - sound is a memory image of a wav file\n"
+"SND_PURGE - stop all instances of the specified sound\n"
+"SND_ASYNC - PlaySound returns immediately\n"
+"SND_NODEFAULT - Do not play a default beep if the sound can not be found\n"
+"SND_NOSTOP - Do not interrupt any sounds currently playing\n" // Raising RuntimeError if needed
+"SND_NOWAIT - Return immediately if the sound driver is busy\n" // Without any errors
+"\n"
+"Beep(frequency, duration) - Make a beep through the PC speaker.\n"
+"MessageBeep(type) - Call Windows MessageBeep.");
+
+/*[clinic input]
+module winsound
+[clinic start generated code]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=a18401142d97b8d5]*/
+
+#include "clinic/winsound.c.h"
+
+/*[clinic input]
+winsound.PlaySound
+
+ sound: object
+ The sound to play; a filename, data, or None.
+ flags: int
+ Flag values, ored together. See module documentation.
+
+A wrapper around the Windows PlaySound API.
+[clinic start generated code]*/
+
+static PyObject *
+winsound_PlaySound_impl(PyObject *module, PyObject *sound, int flags)
+/*[clinic end generated code: output=49a0fd16a372ebeb input=c63e1f2d848da2f2]*/
+{
+ int ok;
+ wchar_t *wsound;
+ Py_buffer view = {NULL, NULL};
+
+ if (sound == Py_None) {
+ wsound = NULL;
+ } else if (flags & SND_MEMORY) {
+ if (flags & SND_ASYNC) {
+ /* Sidestep reference counting headache; unfortunately this also
+ prevent SND_LOOP from memory. */
+ PyErr_SetString(PyExc_RuntimeError,
+ "Cannot play asynchronously from memory");
+ return NULL;
+ }
+ if (PyObject_GetBuffer(sound, &view, PyBUF_SIMPLE) < 0) {
+ return NULL;
+ }
+ wsound = (wchar_t *)view.buf;
+ } else if (PyBytes_Check(sound)) {
+ PyErr_Format(PyExc_TypeError,
+ "'sound' must be str, os.PathLike, or None, not '%s'",
+ Py_TYPE(sound)->tp_name);
+ return NULL;
+ } else {
+ PyObject *obj = PyOS_FSPath(sound);
+ // Either <obj> is unicode/bytes/NULL, or a helpful message
+ // has been surfaced to the user about how they gave a non-path.
+ if (obj == NULL) return NULL;
+ if (PyBytes_Check(obj)) {
+ PyErr_Format(PyExc_TypeError,
+ "'sound' must resolve to str, not bytes");
+ Py_DECREF(obj);
+ return NULL;
+ }
+ wsound = PyUnicode_AsWideCharString(obj, NULL);
+ Py_DECREF(obj);
+ if (wsound == NULL) return NULL;
+ }
+
+
+ Py_BEGIN_ALLOW_THREADS
+ ok = PlaySoundW(wsound, NULL, flags);
+ Py_END_ALLOW_THREADS
+ if (view.obj) {
+ PyBuffer_Release(&view);
+ } else if (sound != Py_None) {
+ PyMem_Free(wsound);
+ }
+ if (!ok) {
+ PyErr_SetString(PyExc_RuntimeError, "Failed to play sound");
+ return NULL;
+ }
+ Py_RETURN_NONE;
+}
+
+/*[clinic input]
+winsound.Beep
+
+ frequency: int
+ Frequency of the sound in hertz.
+ Must be in the range 37 through 32,767.
+ duration: int
+ How long the sound should play, in milliseconds.
+
+A wrapper around the Windows Beep API.
+[clinic start generated code]*/
+
+static PyObject *
+winsound_Beep_impl(PyObject *module, int frequency, int duration)
+/*[clinic end generated code: output=f32382e52ee9b2fb input=40e360cfa00a5cf0]*/
+{
+ BOOL ok;
+
+ if (frequency < 37 || frequency > 32767) {
+ PyErr_SetString(PyExc_ValueError,
+ "frequency must be in 37 thru 32767");
+ return NULL;
+ }
+
+ Py_BEGIN_ALLOW_THREADS
+ ok = Beep(frequency, duration);
+ Py_END_ALLOW_THREADS
+ if (!ok) {
+ PyErr_SetString(PyExc_RuntimeError,"Failed to beep");
+ return NULL;
+ }
+
+ Py_RETURN_NONE;
+}
+
+/*[clinic input]
+winsound.MessageBeep
+
+ type: int(c_default="MB_OK") = MB_OK
+
+Call Windows MessageBeep(x).
+
+x defaults to MB_OK.
+[clinic start generated code]*/
+
+static PyObject *
+winsound_MessageBeep_impl(PyObject *module, int type)
+/*[clinic end generated code: output=120875455121121f input=db185f741ae21401]*/
+{
+ BOOL ok;
+
+ Py_BEGIN_ALLOW_THREADS
+ ok = MessageBeep(type);
+ Py_END_ALLOW_THREADS
+
+ if (!ok) {
+ PyErr_SetExcFromWindowsErr(PyExc_RuntimeError, 0);
+ return NULL;
+ }
+
+ Py_RETURN_NONE;
+}
+
+static struct PyMethodDef sound_methods[] =
+{
+ WINSOUND_PLAYSOUND_METHODDEF
+ WINSOUND_BEEP_METHODDEF
+ WINSOUND_MESSAGEBEEP_METHODDEF
+ {NULL, NULL}
+};
+
+#define ADD_DEFINE(CONST) do { \
+ if (PyModule_AddIntConstant(module, #CONST, CONST) < 0) { \
+ return -1; \
+ } \
+} while (0)
+
+static int
+exec_module(PyObject *module)
+{
+ ADD_DEFINE(SND_ASYNC);
+ ADD_DEFINE(SND_NODEFAULT);
+ ADD_DEFINE(SND_NOSTOP);
+ ADD_DEFINE(SND_NOWAIT);
+ ADD_DEFINE(SND_ALIAS);
+ ADD_DEFINE(SND_FILENAME);
+ ADD_DEFINE(SND_MEMORY);
+ ADD_DEFINE(SND_PURGE);
+ ADD_DEFINE(SND_LOOP);
+ ADD_DEFINE(SND_APPLICATION);
+
+ ADD_DEFINE(MB_OK);
+ ADD_DEFINE(MB_ICONASTERISK);
+ ADD_DEFINE(MB_ICONEXCLAMATION);
+ ADD_DEFINE(MB_ICONHAND);
+ ADD_DEFINE(MB_ICONQUESTION);
+
+#undef ADD_DEFINE
+
+ return 0;
+}
+
+static PyModuleDef_Slot sound_slots[] = {
+ {Py_mod_exec, exec_module},
+ {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+ {0, NULL}
+};
+
+static struct PyModuleDef winsoundmodule = {
+ .m_base = PyModuleDef_HEAD_INIT,
+ .m_name = "winsound",
+ .m_doc = sound_module_doc,
+ .m_methods = sound_methods,
+ .m_slots = sound_slots,
+};
+
+PyMODINIT_FUNC
+PyInit_winsound(void)
+{
+ return PyModuleDef_Init(&winsoundmodule);
+}