Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a22d823

Browse files
committed
merge
2 parents 19e020c + 5a2146a commit a22d823

4 files changed

Lines changed: 22 additions & 7 deletions

File tree

Lib/test/datetimetester.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import sys
77
import pickle
8+
import random
89
import unittest
910

1011
from operator import lt, le, gt, ge, eq, ne, truediv, floordiv, mod
@@ -76,8 +77,18 @@ class PicklableFixedOffset(FixedOffset):
7677
def __init__(self, offset=None, name=None, dstoffset=None):
7778
FixedOffset.__init__(self, offset, name, dstoffset)
7879

80+
class _TZInfo(tzinfo):
81+
def utcoffset(self, datetime_module):
82+
return random.random()
83+
7984
class TestTZInfo(unittest.TestCase):
8085

86+
def test_refcnt_crash_bug_22044(self):
87+
tz1 = _TZInfo()
88+
dt1 = datetime(2014, 7, 21, 11, 32, 3, 0, tz1)
89+
with self.assertRaises(TypeError):
90+
dt1.utcoffset()
91+
8192
def test_non_abstractness(self):
8293
# In order to allow subclasses to get pickled, the C implementation
8394
# wasn't able to get away with having __init__ raise

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ Russell Finn
411411
Dan Finnie
412412
Nils Fischbeck
413413
Frederik Fix
414+
Tom Flanagan
414415
Matt Fleming
415416
Hernán Martínez Foffani
416417
Artem Fokin

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ Library
117117
- Issue #16133: The asynchat.async_chat.handle_read() method now ignores
118118
BlockingIOError exceptions.
119119

120+
- Issue #22044: Fixed premature DECREF in call_tzinfo_method.
121+
Patch by Tom Flanagan.
122+
120123
- Issue #19884: readline: Disable the meta modifier key if stdout is not
121124
a terminal to not write the ANSI sequence "\033[1034h" into stdout. This
122125
sequence is used on some terminal (ex: TERM=xterm-256color") to enable

Modules/_datetimemodule.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -897,11 +897,11 @@ call_tzinfo_method(PyObject *tzinfo, char *name, PyObject *tzinfoarg)
897897
}
898898
}
899899
else {
900-
Py_DECREF(offset);
901900
PyErr_Format(PyExc_TypeError,
902901
"tzinfo.%s() must return None or "
903902
"timedelta, not '%.200s'",
904903
name, Py_TYPE(offset)->tp_name);
904+
Py_DECREF(offset);
905905
return NULL;
906906
}
907907

@@ -2153,7 +2153,7 @@ delta_new(PyTypeObject *type, PyObject *args, PyObject *kw)
21532153
* is odd. Note that x is odd when it's last bit is 1. The
21542154
* code below uses bitwise and operation to check the last
21552155
* bit. */
2156-
temp = PyNumber_And(x, one); /* temp <- x & 1 */
2156+
temp = PyNumber_And(x, one); /* temp <- x & 1 */
21572157
if (temp == NULL) {
21582158
Py_DECREF(x);
21592159
goto Done;
@@ -3224,10 +3224,10 @@ timezone_richcompare(PyDateTime_TimeZone *self,
32243224
if (op != Py_EQ && op != Py_NE)
32253225
Py_RETURN_NOTIMPLEMENTED;
32263226
if (Py_TYPE(other) != &PyDateTime_TimeZoneType) {
3227-
if (op == Py_EQ)
3228-
Py_RETURN_FALSE;
3229-
else
3230-
Py_RETURN_TRUE;
3227+
if (op == Py_EQ)
3228+
Py_RETURN_FALSE;
3229+
else
3230+
Py_RETURN_TRUE;
32313231
}
32323232
return delta_richcompare(self->offset, other->offset, op);
32333233
}
@@ -4778,7 +4778,7 @@ datetime_astimezone(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
47784778
static char *keywords[] = {"tz", NULL};
47794779

47804780
if (! PyArg_ParseTupleAndKeywords(args, kw, "|O:astimezone", keywords,
4781-
&tzinfo))
4781+
&tzinfo))
47824782
return NULL;
47834783

47844784
if (check_tzinfo_subclass(tzinfo) == -1)

0 commit comments

Comments
 (0)