at master 3.0 kB view raw
1diff --git a/src/picologging/compat.hxx b/src/picologging/compat.hxx 2index d3356da..be7a1fc 100644 3--- a/src/picologging/compat.hxx 4+++ b/src/picologging/compat.hxx 5@@ -88,4 +88,12 @@ static inline PyObject* _Py_XNewRef(PyObject *obj) 6 } 7 #endif 8 9+// For Python 3.13 and above, PyTime_t is now part of the public API 10+#if PY_VERSION_HEX >= 0x030d0000 11+#define _PyTime_t PyTime_t 12+#define _PyTime_AsSecondsDouble PyTime_AsSecondsDouble 13+#define _PyTime_AsMilliseconds PyTime_AsMilliseconds 14+#define _PyTime_ROUND_CEILING PyTime_ROUND_CEILING 15+#endif 16+ 17 #endif // COMPAT_H 18\ No newline at end of file 19 20From fe313d8b3dcf0115e1be781e03b20673d3f51c3f Mon Sep 17 00:00:00 2001 21From: Anthony Shaw <anthony.p.shaw@gmail.com> 22Date: Sat, 14 Sep 2024 17:33:25 +1000 23Subject: [PATCH 2/2] Patch other changed APIs for pytime 24 25--- 26 pyproject.toml | 2 +- 27 src/picologging/compat.hxx | 2 -- 28 src/picologging/logrecord.cxx | 13 +++++++++++++ 29 3 files changed, 14 insertions(+), 3 deletions(-) 30 31diff --git a/pyproject.toml b/pyproject.toml 32index 33abe66..27628c9 100644 33--- a/pyproject.toml 34+++ b/pyproject.toml 35@@ -1,7 +1,7 @@ 36 [build-system] 37 requires = [ 38 "setuptools>=65.4.1", 39- "scikit-build>=0.17.0", 40+ "scikit-build>=0.18.0", 41 "cmake>=3.18", 42 "ninja", 43 ] 44diff --git a/src/picologging/compat.hxx b/src/picologging/compat.hxx 45index be7a1fc..7c6970d 100644 46--- a/src/picologging/compat.hxx 47+++ b/src/picologging/compat.hxx 48@@ -92,8 +92,6 @@ static inline PyObject* _Py_XNewRef(PyObject *obj) 49 #if PY_VERSION_HEX >= 0x030d0000 50 #define _PyTime_t PyTime_t 51 #define _PyTime_AsSecondsDouble PyTime_AsSecondsDouble 52-#define _PyTime_AsMilliseconds PyTime_AsMilliseconds 53-#define _PyTime_ROUND_CEILING PyTime_ROUND_CEILING 54 #endif 55 56 #endif // COMPAT_H 57\ No newline at end of file 58diff --git a/src/picologging/logrecord.cxx b/src/picologging/logrecord.cxx 59index cec68c9..9f5cf86 100644 60--- a/src/picologging/logrecord.cxx 61+++ b/src/picologging/logrecord.cxx 62@@ -16,11 +16,19 @@ _PyFloat_FromPyTime(_PyTime_t t) 63 64 _PyTime_t current_time() 65 { 66+#if PY_VERSION_HEX >= 0x030d0000 67+ _PyTime_t t; 68+ if (PyTime_Time(&t) < 0) { 69+ return -1; 70+ } 71+ return t; 72+#else 73 _PyTime_t t; 74 if (_PyTime_GetSystemClockWithInfo(&t, NULL) < 0) { 75 return -1; 76 } 77 return t; 78+#endif 79 } 80 81 PyObject* LogRecord_new(PyTypeObject* type, PyObject *initargs, PyObject *kwds) 82@@ -162,7 +170,12 @@ LogRecord* LogRecord_create(LogRecord* self, PyObject* name, PyObject* msg, PyOb 83 } 84 85 self->created = _PyTime_AsSecondsDouble(ctime); 86+// msecs conversion isn't in 3.13 API 87+#if PY_VERSION_HEX < 0x030d0000 88 self->msecs = _PyTime_AsMilliseconds(ctime, _PyTime_ROUND_CEILING); 89+#else 90+ self->msecs = 0; 91+#endif 92 self->relativeCreated = _PyFloat_FromPyTime((ctime - startTime) * 1000); 93 self->thread = PyThread_get_thread_ident(); // Only supported in Python 3.7+, if big demand for 3.6 patch this out for the old API. 94 // TODO #2 : See if there is a performant way to get the thread name.