python-wxPython/0004-Fix-time_t-ETG-typedef-extend-DateTime.FromTimeT-tes.patch

56 lines
2.5 KiB
Diff

From 70ecc1afcdd59bbd3b700d000e8f92740d218245 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Br=C3=BCns?= <stefan.bruens@rwth-aachen.de>
Date: Tue, 28 Jun 2022 18:32:32 +0200
Subject: [PATCH 4/4] Fix time_t ETG typedef, extend DateTime.FromTimeT tests
Before c78823549bac ("Ensure time_t is treated as a 64-bit value by SIP")
the typedef used "long" instead of wxInt64, which caused issues on Win64,
as long is 32bit there (LLP64). On the other hand, wxInt64 is wrong on
32 bit Linux (e.g. armv7, i586), and thus the code crashes.
As SIP_SSIZE_T is 64 bit for both LLP64 (Windows) and LP64 (Linux), but
32 bit on 32bit archs, it matches time_t better (though, according to the
C standard, it could even be a double).
---
etg/defs.py | 2 +-
unittests/test_wxdatetime.py | 8 +++++++-
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/etg/defs.py b/etg/defs.py
index 4445cf93..ceb9e2ef 100644
--- a/etg/defs.py
+++ b/etg/defs.py
@@ -73,7 +73,7 @@ def run():
td = module.find('wxUIntPtr')
module.insertItemAfter(td, etgtools.TypedefDef(type='wchar_t', name='wxUChar'))
module.insertItemAfter(td, etgtools.TypedefDef(type='wchar_t', name='wxChar'))
- module.insertItemAfter(td, etgtools.TypedefDef(type='wxInt64', name='time_t'))
+ module.insertItemAfter(td, etgtools.TypedefDef(type='long', name='time_t'))
module.insertItemAfter(td, etgtools.TypedefDef(type='long long', name='wxFileOffset'))
module.insertItemAfter(td, etgtools.TypedefDef(type='SIP_SSIZE_T', name='ssize_t'))
module.insertItemAfter(td, etgtools.TypedefDef(type='unsigned char', name='byte', pyInt=True))
diff --git a/unittests/test_wxdatetime.py b/unittests/test_wxdatetime.py
index 62e7d141..2f620045 100644
--- a/unittests/test_wxdatetime.py
+++ b/unittests/test_wxdatetime.py
@@ -25,9 +25,15 @@ class datetime_Tests(wtc.WidgetTestCase):
def test_datetime2(self):
d1 = wx.DateTime.FromHMS(8, 15, 45, 123)
d2 = wx.DateTime.FromJDN(12345.67)
- d3 = wx.DateTime.FromTimeT(int(time.time()))
d4 = wx.DateTime.FromDMY(1, wx.DateTime.Mar, 2012, 8, 15, 45, 123)
+ def test_datetimeTimeT(self):
+ d1 = wx.DateTime.FromTimeT(0)
+ self.assertEqual(d1.year, 1970)
+ d2 = wx.DateTime.FromTimeT(1643756400) # 2022-02-02
+ self.assertEqual(d2.year, 2022)
+ d3 = wx.DateTime.FromTimeT(int(time.time()))
+
def test_datetime3(self):
d1 = wx.DateTime.Today()
d2 = wx.DateTime.Now()
--
2.36.1