summaryrefslogtreecommitdiffstats
path: root/Modules/_datetimemodule.c
diff options
context:
space:
mode:
authorPaul Ganssle <pganssle@users.noreply.github.com>2019-04-27 19:39:40 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2019-04-27 19:39:40 (GMT)
commit4d8c8c0ad6163c24136d3419eb04f310b31f7e64 (patch)
tree445d3de23677da75d5c1d3346a45d799b4874b48 /Modules/_datetimemodule.c
parent5c403b203510549a3f89d138d3265c5cc0cc12af (diff)
downloadcpython-4d8c8c0ad6163c24136d3419eb04f310b31f7e64.zip
cpython-4d8c8c0ad6163c24136d3419eb04f310b31f7e64.tar.gz
cpython-4d8c8c0ad6163c24136d3419eb04f310b31f7e64.tar.bz2
bpo-36025: Fix PyDate_FromTimestamp API (GH-11922)
In the process of converting the date.fromtimestamp function to use argument clinic in GH-8535, the C API for PyDate_FromTimestamp was inadvertently changed to expect a timestamp object rather than an argument tuple. This PR fixes this backwards-incompatible change by adding a new wrapper function for the C API function that unwraps the argument tuple and passes it to the underlying function. This PR also adds tests for both PyDate_FromTimestamp and PyDateTime_FromTimestamp to prevent any further regressions.
Diffstat (limited to 'Modules/_datetimemodule.c')
-rw-r--r--Modules/_datetimemodule.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index c1557b5..b3954c9 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -2921,6 +2921,23 @@ datetime_date_fromtimestamp(PyTypeObject *type, PyObject *timestamp)
return date_fromtimestamp((PyObject *) type, timestamp);
}
+/* bpo-36025: This is a wrapper for API compatibility with the public C API,
+ * which expects a function that takes an *args tuple, whereas the argument
+ * clinic generates code that takes METH_O.
+ */
+static PyObject *
+datetime_date_fromtimestamp_capi(PyObject *cls, PyObject *args)
+{
+ PyObject *timestamp;
+ PyObject *result = NULL;
+
+ if (PyArg_UnpackTuple(args, "fromtimestamp", 1, 1, &timestamp)) {
+ result = date_fromtimestamp(cls, timestamp);
+ }
+
+ return result;
+}
+
/* Return new date from proleptic Gregorian ordinal. Raises ValueError if
* the ordinal is out of range.
*/
@@ -6275,7 +6292,7 @@ static PyDateTime_CAPI CAPI = {
new_delta_ex,
new_timezone,
datetime_fromtimestamp,
- date_fromtimestamp,
+ datetime_date_fromtimestamp_capi,
new_datetime_ex2,
new_time_ex2
};