Skip to content

Commit 6f05f25

Browse files
committed
Address review comments
1 parent a92719d commit 6f05f25

File tree

1 file changed

+38
-48
lines changed

1 file changed

+38
-48
lines changed

Modules/posixmodule.c

Lines changed: 38 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2591,74 +2591,64 @@ fill_time(PyObject *module, PyObject *v, int s_index, int f_index, int ns_index,
25912591
#define S_TO_NS (1000000000LL)
25922592
assert(nsec < S_TO_NS);
25932593

2594+
if (s_index >= 0) {
2595+
PyObject *s = _PyLong_FromTime_t(sec);
2596+
if (!s) {
2597+
return -1;
2598+
}
2599+
PyStructSequence_SET_ITEM(v, s_index, s);
2600+
}
2601+
25942602
if (f_index >= 0) {
2595-
PyObject *float_s = PyFloat_FromDouble(sec + 1e-9*nsec);
2603+
PyObject *float_s = PyFloat_FromDouble(sec + 1e-9 * nsec);
25962604
if (!float_s) {
25972605
return -1;
25982606
}
25992607
PyStructSequence_SET_ITEM(v, f_index, float_s);
26002608
}
26012609

2602-
/* 1677-09-21 00:12:44 to 2262-04-11 23:47:15 UTC inclusive */
2603-
if ((LLONG_MIN / S_TO_NS) <= sec && sec <= (LONG_MAX / S_TO_NS - 1)) {
2604-
if (s_index >= 0) {
2605-
PyObject *s = _PyLong_FromTime_t(sec);
2606-
if (!s) {
2607-
return -1;
2608-
}
2609-
PyStructSequence_SET_ITEM(v, s_index, s);
2610-
}
2611-
2612-
if (ns_index >= 0) {
2610+
int res = -1;
2611+
if (ns_index >= 0) {
2612+
/* 1677-09-21 00:12:44 to 2262-04-11 23:47:15 UTC inclusive */
2613+
if ((LLONG_MIN / S_TO_NS) <= sec && sec <= (LONG_MAX / S_TO_NS - 1)) {
26132614
PyObject *ns_total = PyLong_FromLongLong(sec * S_TO_NS + nsec);
26142615
if (!ns_total) {
26152616
return -1;
26162617
}
26172618
PyStructSequence_SET_ITEM(v, ns_index, ns_total);
2619+
res = 0;
26182620
}
2621+
else {
2622+
PyObject *s_in_ns = NULL;
2623+
PyObject *ns_total = NULL;
2624+
PyObject *s = _PyLong_FromTime_t(sec);
2625+
PyObject *ns_fractional = PyLong_FromUnsignedLong(nsec);
2626+
if (!(s && ns_fractional)) {
2627+
goto exit;
2628+
}
26192629

2620-
assert(!PyErr_Occurred());
2621-
return 0;
2622-
}
2623-
#undef S_TO_NS
2624-
2625-
int res = -1;
2626-
PyObject *s_in_ns = NULL;
2627-
PyObject *ns_total = NULL;
2628-
PyObject *s = _PyLong_FromTime_t(sec);
2629-
PyObject *ns_fractional = PyLong_FromUnsignedLong(nsec);
2630-
if (!(s && ns_fractional)) {
2631-
goto exit;
2632-
}
2633-
2634-
s_in_ns = PyNumber_Multiply(s, get_posix_state(module)->billion);
2635-
if (!s_in_ns) {
2636-
goto exit;
2637-
}
2630+
s_in_ns = PyNumber_Multiply(s, get_posix_state(module)->billion);
2631+
if (!s_in_ns) {
2632+
goto exit;
2633+
}
26382634

2639-
ns_total = PyNumber_Add(s_in_ns, ns_fractional);
2640-
if (!ns_total) {
2641-
goto exit;
2642-
}
2635+
ns_total = PyNumber_Add(s_in_ns, ns_fractional);
2636+
if (!ns_total) {
2637+
goto exit;
2638+
}
2639+
PyStructSequence_SET_ITEM(v, ns_index, ns_total);
2640+
res = 0;
26432641

2644-
if (s_index >= 0) {
2645-
PyStructSequence_SET_ITEM(v, s_index, s);
2646-
s = NULL;
2647-
}
2648-
if (ns_index >= 0) {
2649-
PyStructSequence_SET_ITEM(v, ns_index, ns_total);
2650-
ns_total = NULL;
2642+
exit:
2643+
Py_XDECREF(s);
2644+
Py_XDECREF(ns_fractional);
2645+
Py_XDECREF(s_in_ns);
2646+
}
26512647
}
26522648

26532649
assert(!PyErr_Occurred());
2654-
res = 0;
2655-
2656-
exit:
2657-
Py_XDECREF(s);
2658-
Py_XDECREF(ns_fractional);
2659-
Py_XDECREF(s_in_ns);
2660-
Py_XDECREF(ns_total);
26612650
return res;
2651+
#undef S_TO_NS
26622652
}
26632653

26642654
#ifdef MS_WINDOWS

0 commit comments

Comments
 (0)