mirror of
https://github.com/python/cpython
synced 2024-10-14 10:33:27 +00:00
gh-103092: Isolate msvcrt (#103248)
This commit is contained in:
parent
f2b7ecb778
commit
dce2d38cb0
|
@ -0,0 +1 @@
|
||||||
|
Adapt the :mod:`msvcrt` extension module to :pep:`687`.
|
|
@ -564,19 +564,6 @@ static struct PyMethodDef msvcrt_functions[] = {
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static struct PyModuleDef msvcrtmodule = {
|
|
||||||
PyModuleDef_HEAD_INIT,
|
|
||||||
"msvcrt",
|
|
||||||
NULL,
|
|
||||||
-1,
|
|
||||||
msvcrt_functions,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
insertint(PyObject *d, char *name, int value)
|
insertint(PyObject *d, char *name, int value)
|
||||||
{
|
{
|
||||||
|
@ -605,14 +592,10 @@ insertptr(PyObject *d, char *name, void *value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PyMODINIT_FUNC
|
static int
|
||||||
PyInit_msvcrt(void)
|
exec_module(PyObject* m)
|
||||||
{
|
{
|
||||||
int st;
|
int st;
|
||||||
PyObject *m = PyModule_Create(&msvcrtmodule);
|
|
||||||
if (m == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
PyObject *d = PyModule_GetDict(m); // Borrowed ref.
|
PyObject *d = PyModule_GetDict(m); // Borrowed ref.
|
||||||
|
|
||||||
/* constants for the locking() function's mode argument */
|
/* constants for the locking() function's mode argument */
|
||||||
|
@ -645,21 +628,21 @@ PyInit_msvcrt(void)
|
||||||
st = PyModule_AddStringConstant(m, "VC_ASSEMBLY_PUBLICKEYTOKEN",
|
st = PyModule_AddStringConstant(m, "VC_ASSEMBLY_PUBLICKEYTOKEN",
|
||||||
_VC_ASSEMBLY_PUBLICKEYTOKEN);
|
_VC_ASSEMBLY_PUBLICKEYTOKEN);
|
||||||
if (st < 0) {
|
if (st < 0) {
|
||||||
goto error;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef _CRT_ASSEMBLY_VERSION
|
#ifdef _CRT_ASSEMBLY_VERSION
|
||||||
st = PyModule_AddStringConstant(m, "CRT_ASSEMBLY_VERSION",
|
st = PyModule_AddStringConstant(m, "CRT_ASSEMBLY_VERSION",
|
||||||
_CRT_ASSEMBLY_VERSION);
|
_CRT_ASSEMBLY_VERSION);
|
||||||
if (st < 0) {
|
if (st < 0) {
|
||||||
goto error;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef __LIBRARIES_ASSEMBLY_NAME_PREFIX
|
#ifdef __LIBRARIES_ASSEMBLY_NAME_PREFIX
|
||||||
st = PyModule_AddStringConstant(m, "LIBRARIES_ASSEMBLY_NAME_PREFIX",
|
st = PyModule_AddStringConstant(m, "LIBRARIES_ASSEMBLY_NAME_PREFIX",
|
||||||
__LIBRARIES_ASSEMBLY_NAME_PREFIX);
|
__LIBRARIES_ASSEMBLY_NAME_PREFIX);
|
||||||
if (st < 0) {
|
if (st < 0) {
|
||||||
goto error;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -671,20 +654,34 @@ PyInit_msvcrt(void)
|
||||||
_VC_CRT_BUILD_VERSION,
|
_VC_CRT_BUILD_VERSION,
|
||||||
_VC_CRT_RBUILD_VERSION);
|
_VC_CRT_RBUILD_VERSION);
|
||||||
if (version == NULL) {
|
if (version == NULL) {
|
||||||
goto error;
|
return -1;
|
||||||
}
|
}
|
||||||
st = PyModule_AddObjectRef(m, "CRT_ASSEMBLY_VERSION", version);
|
st = PyModule_AddObjectRef(m, "CRT_ASSEMBLY_VERSION", version);
|
||||||
Py_DECREF(version);
|
Py_DECREF(version);
|
||||||
if (st < 0) {
|
if (st < 0) {
|
||||||
goto error;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/* make compiler warning quiet if st is unused */
|
/* make compiler warning quiet if st is unused */
|
||||||
(void)st;
|
(void)st;
|
||||||
|
|
||||||
return m;
|
return 0;
|
||||||
|
}
|
||||||
error:
|
|
||||||
Py_DECREF(m);
|
static PyModuleDef_Slot msvcrt_slots[] = {
|
||||||
return NULL;
|
{Py_mod_exec, exec_module},
|
||||||
|
{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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue