@@ -495,9 +495,11 @@ extern char *ctermid_r(char *);
495495#ifdef MS_WINDOWS
496496# define INITFUNC PyInit_nt
497497# define MODNAME "nt"
498+ # define MODNAME_OBJ &_Py_ID(nt)
498499#else
499500# define INITFUNC PyInit_posix
500501# define MODNAME "posix"
502+ # define MODNAME_OBJ &_Py_ID(posix)
501503#endif
502504
503505#if defined(__sun )
@@ -974,6 +976,7 @@ typedef struct {
974976#if defined(HAVE_SCHED_SETPARAM ) || defined(HAVE_SCHED_SETSCHEDULER ) || defined(POSIX_SPAWN_SETSCHEDULER ) || defined(POSIX_SPAWN_SETSCHEDPARAM )
975977 PyObject * SchedParamType ;
976978#endif
979+ newfunc statresult_new_orig ;
977980 PyObject * StatResultType ;
978981 PyObject * StatVFSResultType ;
979982 PyObject * TerminalSizeType ;
@@ -2225,14 +2228,25 @@ static PyStructSequence_Desc waitid_result_desc = {
22252228 5
22262229};
22272230#endif
2228- static newfunc structseq_new ;
22292231
22302232static PyObject *
22312233statresult_new (PyTypeObject * type , PyObject * args , PyObject * kwds )
22322234{
22332235 PyStructSequence * result ;
22342236 int i ;
22352237
2238+ // ht_module doesn't get set in PyStructSequence_NewType(),
2239+ // so we can't use PyType_GetModule().
2240+ PyObject * mod = PyImport_GetModule (MODNAME_OBJ );
2241+ if (mod == NULL ) {
2242+ return NULL ;
2243+ }
2244+ _posixstate * state = get_posix_state (mod );
2245+ if (state == NULL ) {
2246+ return NULL ;
2247+ }
2248+ #define structseq_new state->statresult_new_orig
2249+
22362250 result = (PyStructSequence * )structseq_new (type , args , kwds );
22372251 if (!result )
22382252 return NULL ;
@@ -9051,10 +9065,23 @@ build_times_result(PyObject *module, double user, double system,
90519065}
90529066
90539067
9054- #ifndef MS_WINDOWS
9055- #define NEED_TICKS_PER_SECOND
9056- static long ticks_per_second = -1 ;
9057- #endif /* MS_WINDOWS */
9068+ #ifdef _OS_NEED_TICKS_PER_SECOND
9069+ #define ticks_per_second _PyRuntime.os.ticks_per_second
9070+ static void
9071+ ticks_per_second_init (void )
9072+ {
9073+ if (ticks_per_second != -1 ) {
9074+ return ;
9075+ }
9076+ # if defined(HAVE_SYSCONF ) && defined(_SC_CLK_TCK )
9077+ ticks_per_second = sysconf (_SC_CLK_TCK );
9078+ # elif defined(HZ )
9079+ ticks_per_second = HZ ;
9080+ # else
9081+ ticks_per_second = 60 ; /* magic fallback value; may be bogus */
9082+ # endif
9083+ }
9084+ #endif
90589085
90599086/*[clinic input]
90609087os.times
@@ -9089,10 +9116,10 @@ os_times_impl(PyObject *module)
90899116 (double )0 ,
90909117 (double )0 );
90919118}
9119+ #elif !defined(_OS_NEED_TICKS_PER_SECOND )
9120+ # error "missing ticks_per_second"
90929121#else /* MS_WINDOWS */
90939122{
9094-
9095-
90969123 struct tms t ;
90979124 clock_t c ;
90989125 errno = 0 ;
@@ -15912,7 +15939,7 @@ posixmodule_exec(PyObject *m)
1591215939 }
1591315940 PyModule_AddObject (m , "stat_result" , Py_NewRef (StatResultType ));
1591415941 state -> StatResultType = StatResultType ;
15915- structseq_new = ((PyTypeObject * )StatResultType )-> tp_new ;
15942+ state -> statresult_new_orig = ((PyTypeObject * )StatResultType )-> tp_new ;
1591615943 ((PyTypeObject * )StatResultType )-> tp_new = statresult_new ;
1591715944
1591815945 statvfs_result_desc .name = "os.statvfs_result" ; /* see issue #19209 */
@@ -15922,14 +15949,9 @@ posixmodule_exec(PyObject *m)
1592215949 }
1592315950 PyModule_AddObject (m , "statvfs_result" , Py_NewRef (StatVFSResultType ));
1592415951 state -> StatVFSResultType = StatVFSResultType ;
15925- #ifdef NEED_TICKS_PER_SECOND
15926- # if defined(HAVE_SYSCONF ) && defined(_SC_CLK_TCK )
15927- ticks_per_second = sysconf (_SC_CLK_TCK );
15928- # elif defined(HZ )
15929- ticks_per_second = HZ ;
15930- # else
15931- ticks_per_second = 60 ; /* magic fallback value; may be bogus */
15932- # endif
15952+
15953+ #ifdef _OS_NEED_TICKS_PER_SECOND
15954+ ticks_per_second_init ();
1593315955#endif
1593415956
1593515957#if defined(HAVE_SCHED_SETPARAM ) || defined(HAVE_SCHED_SETSCHEDULER ) || defined(POSIX_SPAWN_SETSCHEDULER ) || defined(POSIX_SPAWN_SETSCHEDPARAM )
0 commit comments