@@ -564,19 +564,6 @@ static struct PyMethodDef msvcrt_functions[] = {
564
564
{NULL , NULL }
565
565
};
566
566
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
-
580
567
static void
581
568
insertint (PyObject * d , char * name , int value )
582
569
{
@@ -605,14 +592,10 @@ insertptr(PyObject *d, char *name, void *value)
605
592
}
606
593
}
607
594
608
- PyMODINIT_FUNC
609
- PyInit_msvcrt ( void )
595
+ static int
596
+ exec_module ( PyObject * m )
610
597
{
611
598
int st ;
612
- PyObject * m = PyModule_Create (& msvcrtmodule );
613
- if (m == NULL ) {
614
- return NULL ;
615
- }
616
599
PyObject * d = PyModule_GetDict (m ); // Borrowed ref.
617
600
618
601
/* constants for the locking() function's mode argument */
@@ -645,21 +628,21 @@ PyInit_msvcrt(void)
645
628
st = PyModule_AddStringConstant (m , "VC_ASSEMBLY_PUBLICKEYTOKEN" ,
646
629
_VC_ASSEMBLY_PUBLICKEYTOKEN );
647
630
if (st < 0 ) {
648
- goto error ;
631
+ return -1 ;
649
632
}
650
633
#endif
651
634
#ifdef _CRT_ASSEMBLY_VERSION
652
635
st = PyModule_AddStringConstant (m , "CRT_ASSEMBLY_VERSION" ,
653
636
_CRT_ASSEMBLY_VERSION );
654
637
if (st < 0 ) {
655
- goto error ;
638
+ return -1 ;
656
639
}
657
640
#endif
658
641
#ifdef __LIBRARIES_ASSEMBLY_NAME_PREFIX
659
642
st = PyModule_AddStringConstant (m , "LIBRARIES_ASSEMBLY_NAME_PREFIX" ,
660
643
__LIBRARIES_ASSEMBLY_NAME_PREFIX );
661
644
if (st < 0 ) {
662
- goto error ;
645
+ return -1 ;
663
646
}
664
647
#endif
665
648
@@ -671,20 +654,34 @@ PyInit_msvcrt(void)
671
654
_VC_CRT_BUILD_VERSION ,
672
655
_VC_CRT_RBUILD_VERSION );
673
656
if (version == NULL ) {
674
- goto error ;
657
+ return -1 ;
675
658
}
676
659
st = PyModule_AddObjectRef (m , "CRT_ASSEMBLY_VERSION" , version );
677
660
Py_DECREF (version );
678
661
if (st < 0 ) {
679
- goto error ;
662
+ return -1 ;
680
663
}
681
664
#endif
682
665
/* make compiler warning quiet if st is unused */
683
666
(void )st ;
684
667
685
- return m ;
668
+ return 0 ;
669
+ }
670
+
671
+ static PyModuleDef_Slot msvcrt_slots [] = {
672
+ {Py_mod_exec , exec_module },
673
+ {0 , NULL }
674
+ };
686
675
687
- error :
688
- Py_DECREF (m );
689
- return NULL ;
676
+ static struct PyModuleDef msvcrtmodule = {
677
+ .m_base = PyModuleDef_HEAD_INIT ,
678
+ .m_name = "msvcrt" ,
679
+ .m_methods = msvcrt_functions ,
680
+ .m_slots = msvcrt_slots ,
681
+ };
682
+
683
+ PyMODINIT_FUNC
684
+ PyInit_msvcrt (void )
685
+ {
686
+ return PyModuleDef_Init (& msvcrtmodule );
690
687
}
0 commit comments