Skip to content

Commit 6b7b9d0

Browse files
authored
gh-138535: Pass directly state to posix fill_time() (#138693)
Pass directly the module state instead of passing the module to avoid a call to get_posix_state().
1 parent a92aec1 commit 6b7b9d0

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

Modules/posixmodule.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2585,7 +2585,8 @@ _posix_free(void *module)
25852585
}
25862586

25872587
static int
2588-
fill_time(PyObject *module, PyObject *v, int s_index, int f_index, int ns_index, time_t sec, unsigned long nsec)
2588+
fill_time(_posixstate *state, PyObject *v, int s_index, int f_index,
2589+
int ns_index, time_t sec, unsigned long nsec)
25892590
{
25902591
assert(!PyErr_Occurred());
25912592
#define SEC_TO_NS (1000000000LL)
@@ -2628,7 +2629,7 @@ fill_time(PyObject *module, PyObject *v, int s_index, int f_index, int ns_index,
26282629
goto exit;
26292630
}
26302631

2631-
s_in_ns = PyNumber_Multiply(s, get_posix_state(module)->billion);
2632+
s_in_ns = PyNumber_Multiply(s, state->billion);
26322633
if (s_in_ns == NULL) {
26332634
goto exit;
26342635
}
@@ -2686,7 +2687,8 @@ _pystat_fromstructstat(PyObject *module, STRUCT_STAT *st)
26862687
{
26872688
assert(!PyErr_Occurred());
26882689

2689-
PyObject *StatResultType = get_posix_state(module)->StatResultType;
2690+
_posixstate *state = get_posix_state(module);
2691+
PyObject *StatResultType = state->StatResultType;
26902692
PyObject *v = PyStructSequence_New((PyTypeObject *)StatResultType);
26912693
if (v == NULL) {
26922694
return NULL;
@@ -2740,13 +2742,13 @@ _pystat_fromstructstat(PyObject *module, STRUCT_STAT *st)
27402742
#else
27412743
ansec = mnsec = cnsec = 0;
27422744
#endif
2743-
if (fill_time(module, v, 7, 10, 13, st->st_atime, ansec) < 0) {
2745+
if (fill_time(state, v, 7, 10, 13, st->st_atime, ansec) < 0) {
27442746
goto error;
27452747
}
2746-
if (fill_time(module, v, 8, 11, 14, st->st_mtime, mnsec) < 0) {
2748+
if (fill_time(state, v, 8, 11, 14, st->st_mtime, mnsec) < 0) {
27472749
goto error;
27482750
}
2749-
if (fill_time(module, v, 9, 12, 15, st->st_ctime, cnsec) < 0) {
2751+
if (fill_time(state, v, 9, 12, 15, st->st_ctime, cnsec) < 0) {
27502752
goto error;
27512753
}
27522754

@@ -2774,7 +2776,7 @@ _pystat_fromstructstat(PyObject *module, STRUCT_STAT *st)
27742776
SET_ITEM(ST_BIRTHTIME_IDX, PyFloat_FromDouble(bsec + bnsec * 1e-9));
27752777
}
27762778
#elif defined(MS_WINDOWS)
2777-
if (fill_time(module, v, -1, ST_BIRTHTIME_IDX, ST_BIRTHTIME_NS_IDX,
2779+
if (fill_time(state, v, -1, ST_BIRTHTIME_IDX, ST_BIRTHTIME_NS_IDX,
27782780
st->st_birthtime, st->st_birthtime_nsec) < 0) {
27792781
goto error;
27802782
}

0 commit comments

Comments
 (0)