Skip to content

Commit

Permalink
pythongh-103092: isolate msvcrt
Browse files Browse the repository at this point in the history
  • Loading branch information
aisk committed Apr 4, 2023
1 parent 810d365 commit a848eaa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adapt :mod:`!msvcrt` to :pep:`687`.
48 changes: 28 additions & 20 deletions PC/msvcrtmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,19 +564,6 @@ static struct PyMethodDef msvcrt_functions[] = {
{NULL, NULL}
};


static struct PyModuleDef msvcrtmodule = {
PyModuleDef_HEAD_INIT,
"msvcrt",
NULL,
-1,
msvcrt_functions,
NULL,
NULL,
NULL,
NULL
};

static void
insertint(PyObject *d, char *name, int value)
{
Expand Down Expand Up @@ -605,14 +592,11 @@ insertptr(PyObject *d, char *name, void *value)
}
}

PyMODINIT_FUNC
PyInit_msvcrt(void)
static int
exec_module(PyObject* m)
{
int st;
PyObject *d, *version;
PyObject *m = PyModule_Create(&msvcrtmodule);
if (m == NULL)
return NULL;
d = PyModule_GetDict(m);

/* constants for the locking() function's mode argument */
Expand Down Expand Up @@ -664,10 +648,34 @@ PyInit_msvcrt(void)
_VC_CRT_BUILD_VERSION,
_VC_CRT_RBUILD_VERSION);
st = PyModule_AddObject(m, "CRT_ASSEMBLY_VERSION", version);
if (st < 0) return NULL;
if (st < 0) return -1;
#endif
/* make compiler warning quiet if st is unused */
(void)st;

return m;
return 0;

}

static PyModuleDef_Slot msvcrt_slots[] = {
{Py_mod_exec, exec_module},
{0, NULL}
};

static struct PyModuleDef msvcrtmodule = {
PyModuleDef_HEAD_INIT,
"msvcrt",
NULL,
0,
msvcrt_functions,
msvcrt_slots,
NULL,
NULL,
NULL
};

PyMODINIT_FUNC
PyInit_msvcrt(void)
{
return PyModuleDef_Init(&msvcrtmodule);
}

0 comments on commit a848eaa

Please sign in to comment.