Content-Length: 4989 | pFad | http://github.com/python/cpython/pull/111296.patch

thub.com From f7e89dfa2246e769474b03a8f87b2e4f68bd9868 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Wed, 25 Oct 2023 08:42:46 +0300 Subject: [PATCH 1/3] gh-111295: Fix timemodule.c not checking for errors when initializing --- ...-10-25-08-42-05.gh-issue-111295.H2K4lf.rst | 1 + Modules/timemodule.c | 28 ++++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2023-10-25-08-42-05.gh-issue-111295.H2K4lf.rst diff --git a/Misc/NEWS.d/next/Library/2023-10-25-08-42-05.gh-issue-111295.H2K4lf.rst b/Misc/NEWS.d/next/Library/2023-10-25-08-42-05.gh-issue-111295.H2K4lf.rst new file mode 100644 index 00000000000000..28b85ec3eadab7 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-10-25-08-42-05.gh-issue-111295.H2K4lf.rst @@ -0,0 +1 @@ +Fix :mod:`time` not checking for errors when initializing. diff --git a/Modules/timemodule.c b/Modules/timemodule.c index 6a872a285d289b..e0366bef54f135 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -1740,6 +1740,13 @@ get_gmtoff(time_t t, struct tm *p) static int init_timezone(PyObject *m) { +#define ADD_INT(NAME, VALUE) \ + do { \ + if (PyModule_AddIntConstant(m, NAME, VALUE) < 0) { \ + return -1; \ + } \ + } while (0) + assert(!PyErr_Occurred()); /* This code moved from PyInit_time wholesale to allow calling it from @@ -1763,13 +1770,13 @@ init_timezone(PyObject *m) #if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) tzset(); #endif - PyModule_AddIntConstant(m, "timezone", _Py_timezone); + ADD_INT("timezone", _Py_timezone); #ifdef HAVE_ALTZONE - PyModule_AddIntConstant(m, "altzone", altzone); + ADD_INT("altzone", altzone); #else - PyModule_AddIntConstant(m, "altzone", _Py_timezone-3600); + ADD_INT("altzone", _Py_timezone-3600); #endif - PyModule_AddIntConstant(m, "daylight", _Py_daylight); + ADD_INT("daylight", _Py_daylight); #ifdef MS_WINDOWS TIME_ZONE_INFORMATION tzinfo = {0}; GetTimeZoneInformation(&tzinfo); @@ -1828,20 +1835,21 @@ init_timezone(PyObject *m) PyObject *tzname_obj; if (janzone < julyzone) { /* DST is reversed in the southern hemisphere */ - PyModule_AddIntConstant(m, "timezone", julyzone); - PyModule_AddIntConstant(m, "altzone", janzone); - PyModule_AddIntConstant(m, "daylight", janzone != julyzone); + ADD_INT("timezone", julyzone); + ADD_INT("altzone", janzone); + ADD_INT("daylight", janzone != julyzone); tzname_obj = Py_BuildValue("(zz)", julyname, janname); } else { - PyModule_AddIntConstant(m, "timezone", janzone); - PyModule_AddIntConstant(m, "altzone", julyzone); - PyModule_AddIntConstant(m, "daylight", janzone != julyzone); + ADD_INT("timezone", janzone); + ADD_INT("altzone", julyzone); + ADD_INT("daylight", janzone != julyzone); tzname_obj = Py_BuildValue("(zz)", janname, julyname); } if (PyModule_Add(m, "tzname", tzname_obj) < 0) { return -1; } #endif // !HAVE_DECL_TZNAME +#undef ADD_INT if (PyErr_Occurred()) { return -1; From 97b914816c8129e2830397455d3a79e7a54ca581 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Wed, 25 Oct 2023 08:45:27 +0200 Subject: [PATCH 2/3] Style nit Less lines, less clutter, less indent. --- Modules/timemodule.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Modules/timemodule.c b/Modules/timemodule.c index e0366bef54f135..ec221b1540616a 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -1740,12 +1740,11 @@ get_gmtoff(time_t t, struct tm *p) static int init_timezone(PyObject *m) { -#define ADD_INT(NAME, VALUE) \ - do { \ - if (PyModule_AddIntConstant(m, NAME, VALUE) < 0) { \ - return -1; \ - } \ - } while (0) +#define ADD_INT(NAME, VALUE) do { \ + if (PyModule_AddIntConstant(m, NAME, VALUE) < 0) { \ + return -1; \ + } \ +while (0) assert(!PyErr_Occurred()); From 874dfc25cd0d436145e4cc700e87ddf176a6e193 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Wed, 25 Oct 2023 08:49:41 +0200 Subject: [PATCH 3/3] Missing } --- Modules/timemodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/timemodule.c b/Modules/timemodule.c index ec221b1540616a..bf48c89f343948 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -1744,7 +1744,7 @@ init_timezone(PyObject *m) if (PyModule_AddIntConstant(m, NAME, VALUE) < 0) { \ return -1; \ } \ -while (0) +} while (0) assert(!PyErr_Occurred());








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/python/cpython/pull/111296.patch

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy