Skip to content

Commit a848eaa

Browse files
committed
pythongh-103092: isolate msvcrt
1 parent 810d365 commit a848eaa

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Adapt :mod:`!msvcrt` to :pep:`687`.

PC/msvcrtmodule.c

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -564,19 +564,6 @@ static struct PyMethodDef msvcrt_functions[] = {
564564
{NULL, NULL}
565565
};
566566

567-
568-
static struct PyModuleDef msvcrtmodule = {
569-
PyModuleDef_HEAD_INIT,
570-
"msvcrt",
571-
NULL,
572-
-1,
573-
msvcrt_functions,
574-
NULL,
575-
NULL,
576-
NULL,
577-
NULL
578-
};
579-
580567
static void
581568
insertint(PyObject *d, char *name, int value)
582569
{
@@ -605,14 +592,11 @@ insertptr(PyObject *d, char *name, void *value)
605592
}
606593
}
607594

608-
PyMODINIT_FUNC
609-
PyInit_msvcrt(void)
595+
static int
596+
exec_module(PyObject* m)
610597
{
611598
int st;
612599
PyObject *d, *version;
613-
PyObject *m = PyModule_Create(&msvcrtmodule);
614-
if (m == NULL)
615-
return NULL;
616600
d = PyModule_GetDict(m);
617601

618602
/* constants for the locking() function's mode argument */
@@ -664,10 +648,34 @@ PyInit_msvcrt(void)
664648
_VC_CRT_BUILD_VERSION,
665649
_VC_CRT_RBUILD_VERSION);
666650
st = PyModule_AddObject(m, "CRT_ASSEMBLY_VERSION", version);
667-
if (st < 0) return NULL;
651+
if (st < 0) return -1;
668652
#endif
669653
/* make compiler warning quiet if st is unused */
670654
(void)st;
671655

672-
return m;
656+
return 0;
657+
658+
}
659+
660+
static PyModuleDef_Slot msvcrt_slots[] = {
661+
{Py_mod_exec, exec_module},
662+
{0, NULL}
663+
};
664+
665+
static struct PyModuleDef msvcrtmodule = {
666+
PyModuleDef_HEAD_INIT,
667+
"msvcrt",
668+
NULL,
669+
0,
670+
msvcrt_functions,
671+
msvcrt_slots,
672+
NULL,
673+
NULL,
674+
NULL
675+
};
676+
677+
PyMODINIT_FUNC
678+
PyInit_msvcrt(void)
679+
{
680+
return PyModuleDef_Init(&msvcrtmodule);
673681
}

0 commit comments

Comments
 (0)