]> granicus.if.org Git - python/commitdiff
Closes #15973: fix a segmentation fault when comparing timezone objects.
authorGeorg Brandl <georg@python.org>
Sat, 22 Sep 2012 07:23:12 +0000 (09:23 +0200)
committerGeorg Brandl <georg@python.org>
Sat, 22 Sep 2012 07:23:12 +0000 (09:23 +0200)
Lib/datetime.py
Lib/test/datetimetester.py
Misc/NEWS
Modules/_datetimemodule.c

index a15c6b091901e4c7b5098ac5fea62d2d357305df..f506e9ab22f9311628746f3eda3dcc8a9e9ac5ad 100644 (file)
@@ -1854,6 +1854,8 @@ class timezone(tzinfo):
         return (self._offset, self._name)
 
     def __eq__(self, other):
+        if type(other) != timezone:
+            return False
         return self._offset == other._offset
 
     def __hash__(self):
index a417170d3f9df2906a67ace68accca8f27a8ecc6..931ef6fc03d4554fe8a2523b5f36fc029c75b867 100644 (file)
@@ -235,6 +235,8 @@ class TestTimeZone(unittest.TestCase):
         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
index 882d274789af36d8bdb888d56e053138872854ce..f82da60112bd06774bf57e8ffda205dfa925c4d9 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -31,6 +31,9 @@ Library
 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.
 
index 6df5c03b97337a832c068c5be240ad026c6477f6..01c85d1cd32e3d80a0cea943e5dd28e04d6cf2ba 100644 (file)
@@ -3215,6 +3215,12 @@ timezone_richcompare(PyDateTime_TimeZone *self,
 {
     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);
 }