@@ -495,9 +495,11 @@ extern char *ctermid_r(char *);
495
495
#ifdef MS_WINDOWS
496
496
# define INITFUNC PyInit_nt
497
497
# define MODNAME "nt"
498
+ # define MODNAME_OBJ &_Py_ID(nt)
498
499
#else
499
500
# define INITFUNC PyInit_posix
500
501
# define MODNAME "posix"
502
+ # define MODNAME_OBJ &_Py_ID(posix)
501
503
#endif
502
504
503
505
#if defined(__sun )
@@ -974,6 +976,7 @@ typedef struct {
974
976
#if defined(HAVE_SCHED_SETPARAM ) || defined(HAVE_SCHED_SETSCHEDULER ) || defined(POSIX_SPAWN_SETSCHEDULER ) || defined(POSIX_SPAWN_SETSCHEDPARAM )
975
977
PyObject * SchedParamType ;
976
978
#endif
979
+ newfunc statresult_new_orig ;
977
980
PyObject * StatResultType ;
978
981
PyObject * StatVFSResultType ;
979
982
PyObject * TerminalSizeType ;
@@ -2225,14 +2228,25 @@ static PyStructSequence_Desc waitid_result_desc = {
2225
2228
5
2226
2229
};
2227
2230
#endif
2228
- static newfunc structseq_new ;
2229
2231
2230
2232
static PyObject *
2231
2233
statresult_new (PyTypeObject * type , PyObject * args , PyObject * kwds )
2232
2234
{
2233
2235
PyStructSequence * result ;
2234
2236
int i ;
2235
2237
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
+
2236
2250
result = (PyStructSequence * )structseq_new (type , args , kwds );
2237
2251
if (!result )
2238
2252
return NULL ;
@@ -9051,10 +9065,23 @@ build_times_result(PyObject *module, double user, double system,
9051
9065
}
9052
9066
9053
9067
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
9058
9085
9059
9086
/*[clinic input]
9060
9087
os.times
@@ -9089,10 +9116,10 @@ os_times_impl(PyObject *module)
9089
9116
(double )0 ,
9090
9117
(double )0 );
9091
9118
}
9119
+ #elif !defined(_OS_NEED_TICKS_PER_SECOND )
9120
+ # error "missing ticks_per_second"
9092
9121
#else /* MS_WINDOWS */
9093
9122
{
9094
-
9095
-
9096
9123
struct tms t ;
9097
9124
clock_t c ;
9098
9125
errno = 0 ;
@@ -15912,7 +15939,7 @@ posixmodule_exec(PyObject *m)
15912
15939
}
15913
15940
PyModule_AddObject (m , "stat_result" , Py_NewRef (StatResultType ));
15914
15941
state -> StatResultType = StatResultType ;
15915
- structseq_new = ((PyTypeObject * )StatResultType )-> tp_new ;
15942
+ state -> statresult_new_orig = ((PyTypeObject * )StatResultType )-> tp_new ;
15916
15943
((PyTypeObject * )StatResultType )-> tp_new = statresult_new ;
15917
15944
15918
15945
statvfs_result_desc .name = "os.statvfs_result" ; /* see issue #19209 */
@@ -15922,14 +15949,9 @@ posixmodule_exec(PyObject *m)
15922
15949
}
15923
15950
PyModule_AddObject (m , "statvfs_result" , Py_NewRef (StatVFSResultType ));
15924
15951
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 ();
15933
15955
#endif
15934
15956
15935
15957
#if defined(HAVE_SCHED_SETPARAM ) || defined(HAVE_SCHED_SETSCHEDULER ) || defined(POSIX_SPAWN_SETSCHEDULER ) || defined(POSIX_SPAWN_SETSCHEDPARAM )
0 commit comments