Skip to content

Commit d51e050

Browse files
authored
Replace PyDateTime_DATE_GET_TZINFO macro with shim (#77)
1 parent fc23bc2 commit d51e050

3 files changed

Lines changed: 34 additions & 4 deletions

File tree

CHANGELOG.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22
Changelog
33
=========
44

5+
######
6+
1.5.1
7+
######
8+
9+
10+
*********
11+
Bug Fixes
12+
*********
13+
14+
* Replace `PyDateTime_DATE_GET_TZINFO` with Python 3.9 compatible function
15+
16+
517
######
618
1.5.0
719
######

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
static_openssl = parser.getboolean("build_ext", "static_openssl", fallback=False)
5656

57-
version = os.getenv("PYMGCLIENT_OVERRIDE_VERSION", "1.5.0")
57+
version = os.getenv("PYMGCLIENT_OVERRIDE_VERSION", "1.5.1")
5858

5959

6060
def list_all_files_in_dir(path):

src/glue.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@
2222
#include <stdio.h>
2323
#include <string.h>
2424

25+
/**
26+
* TODO(colinbarry) Python 3.9 doesn't support the PyDateTime_DATE_GET_TZINFO
27+
* macro. Until we require Python 3.10, this shim function does exactly the
28+
* same thing whilst keeping 3.9 compatibility.
29+
*/
30+
PyObject* INTERNAL_PyDateTime_DATE_GET_TZINFO(PyObject *obj)
31+
{
32+
PyObject *tzinfo = NULL;
33+
34+
if (PyDateTime_Check(obj)) {
35+
tzinfo = ((PyDateTime_DateTime*)obj)->tzinfo;
36+
} else if (PyTime_Check(obj)) {
37+
tzinfo = ((PyDateTime_Time*)obj)->tzinfo;
38+
}
39+
40+
return tzinfo ? tzinfo : Py_None;
41+
}
42+
2543
void py_datetime_import_init() { PyDateTime_IMPORT; }
2644

2745
PyObject *mg_list_to_py_tuple(const mg_list *list) {
@@ -703,7 +721,7 @@ mg_date_time *py_date_time_to_mg_date_time(PyObject *obj) {
703721
}
704722
int64_t subseconds = subseconds_as_nanoseconds(obj);
705723

706-
PyObject *tzinfo = PyDateTime_DATE_GET_TZINFO(obj);
724+
PyObject *tzinfo = INTERNAL_PyDateTime_DATE_GET_TZINFO(obj);
707725
if (tzinfo == Py_None) {
708726
return NULL;
709727
}
@@ -727,7 +745,7 @@ mg_date_time_zone_id *py_date_time_to_mg_date_time_zone_id(PyObject *obj) {
727745
}
728746
int64_t subseconds = subseconds_as_nanoseconds(obj);
729747

730-
PyObject *tzinfo = PyDateTime_DATE_GET_TZINFO(obj);
748+
PyObject *tzinfo = INTERNAL_PyDateTime_DATE_GET_TZINFO(obj);
731749
if (tzinfo == Py_None) {
732750
return NULL;
733751
}
@@ -818,7 +836,7 @@ mg_value *py_object_to_mg_value(PyObject *object) {
818836
}
819837
ret = mg_value_make_local_time(lt);
820838
} else if (PyDateTime_CheckExact(object)) {
821-
PyObject *tzinfo = PyDateTime_DATE_GET_TZINFO(object);
839+
PyObject *tzinfo = INTERNAL_PyDateTime_DATE_GET_TZINFO(object);
822840
if (tzinfo != Py_None) {
823841
// The `timezone` may either be an offset based `datetime.timezone`, or
824842
// some kind of instance of `tzinfo`. In the case of the former, we

0 commit comments

Comments
 (0)