[Python-checkins] cpython: Closes #15973: fix a segmentation fault when comparing timezone objects.
georg.brandl
python-checkins at python.org
Mon Sep 24 07:47:07 CEST 2012
http://hg.python.org/cpython/rev/ec77f8fb9958
changeset: 79119:ec77f8fb9958
user: Georg Brandl <georg at python.org>
date: Sat Sep 22 09:23:12 2012 +0200
summary:
Closes #15973: fix a segmentation fault when comparing timezone objects.
files:
Lib/datetime.py | 2 ++
Lib/test/datetimetester.py | 2 ++
Misc/NEWS | 3 +++
Modules/_datetimemodule.c | 6 ++++++
4 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/Lib/datetime.py b/Lib/datetime.py
--- a/Lib/datetime.py
+++ b/Lib/datetime.py
@@ -1854,6 +1854,8 @@
return (self._offset, self._name)
def __eq__(self, other):
+ if type(other) != timezone:
+ return False
return self._offset == other._offset
def __hash__(self):
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -235,6 +235,8 @@
self.assertEqual(timezone(-5 * HOUR), timezone(-5 * HOUR, 'EST'))
with self.assertRaises(TypeError): timezone(ZERO) < timezone(ZERO)
self.assertIn(timezone(ZERO), {timezone(ZERO)})
+ self.assertTrue(timezone(ZERO) != None)
+ self.assertFalse(timezone(ZERO) == None)
def test_aware_datetime(self):
# test that timezone instances can be used by datetime
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -31,6 +31,9 @@
Extension Modules
-----------------
+- Issue #15973: Fix a segmentation fault when comparing datetime timezone
+ objects.
+
- Issue #15977: Fix memory leak in Modules/_ssl.c when the function
_set_npn_protocols() is called multiple times, thanks to Daniel Sommermann.
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -3215,6 +3215,12 @@
{
if (op != Py_EQ && op != Py_NE)
Py_RETURN_NOTIMPLEMENTED;
+ if (Py_TYPE(other) != &PyDateTime_TimeZoneType) {
+ if (op == Py_EQ)
+ Py_RETURN_FALSE;
+ else
+ Py_RETURN_TRUE;
+ }
return delta_richcompare(self->offset, other->offset, op);
}
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list