Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Include/unicodeobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -2309,6 +2309,10 @@ PyAPI_FUNC(Py_UNICODE*) PyUnicode_AsUnicodeCopy(
PyAPI_FUNC(int) _PyUnicode_CheckConsistency(
PyObject *op,
int check_content);
#elif !defined(NDEBUG)
/* For asserts that call _PyUnicode_CheckConsistency(), which would
* otherwise be a problem when building with asserts but without Py_DEBUG. */
#define _PyUnicode_CheckConsistency(op, check_content) PyUnicode_Check(op)
#endif

#ifndef Py_LIMITED_API
Expand Down
5 changes: 5 additions & 0 deletions Lib/test/datetimetester.py
Original file line number Diff line number Diff line change
Expand Up @@ -4313,6 +4313,11 @@ def test_replace(self):
dt = dt.replace(fold=1, tzinfo=Eastern)
self.assertEqual(t.replace(tzinfo=None).fold, 1)
self.assertEqual(dt.replace(tzinfo=None).fold, 1)
# Out of bounds.
with self.assertRaises(ValueError):
t.replace(fold=2)
with self.assertRaises(ValueError):
dt.replace(fold=2)
# Check that fold is a keyword-only argument
with self.assertRaises(TypeError):
t.replace(1, 1, 1, None, 1)
Expand Down
5 changes: 5 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ What's New in Python 3.6.2 release candidate 1?
Core and Builtins
-----------------

- bpo-29949: Fix memory usage regression of set and frozenset object.

- bpo-29935: Fixed error messages in the index() method of tuple, list and deque
when pass indices of wrong type.

Expand All @@ -30,6 +32,9 @@ Core and Builtins
Library
-------

- bpo-29953: Fixed memory leaks in the replace() method of datetime and time
objects when pass out of bound fold argument.

- bpo-29942: Fix a crash in itertools.chain.from_iterable when encountering
long runs of empty iterables.

Expand Down
21 changes: 10 additions & 11 deletions Modules/_datetimemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3926,16 +3926,16 @@ time_replace(PyDateTime_Time *self, PyObject *args, PyObject *kw)
time_kws,
&hh, &mm, &ss, &us, &tzinfo, &fold))
return NULL;
if (fold != 0 && fold != 1) {
PyErr_SetString(PyExc_ValueError,
"fold must be either 0 or 1");
return NULL;
}
tuple = Py_BuildValue("iiiiO", hh, mm, ss, us, tzinfo);
if (tuple == NULL)
return NULL;
clone = time_new(Py_TYPE(self), tuple, NULL);
if (clone != NULL) {
if (fold != 0 && fold != 1) {
PyErr_SetString(PyExc_ValueError,
"fold must be either 0 or 1");
return NULL;
}
TIME_SET_FOLD(clone, fold);
}
Py_DECREF(tuple);
Expand Down Expand Up @@ -5019,17 +5019,16 @@ datetime_replace(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
&y, &m, &d, &hh, &mm, &ss, &us,
&tzinfo, &fold))
return NULL;
if (fold != 0 && fold != 1) {
PyErr_SetString(PyExc_ValueError,
"fold must be either 0 or 1");
return NULL;
}
tuple = Py_BuildValue("iiiiiiiO", y, m, d, hh, mm, ss, us, tzinfo);
if (tuple == NULL)
return NULL;
clone = datetime_new(Py_TYPE(self), tuple, NULL);

if (clone != NULL) {
if (fold != 0 && fold != 1) {
PyErr_SetString(PyExc_ValueError,
"fold must be either 0 or 1");
return NULL;
}
DATE_SET_FOLD(clone, fold);
}
Py_DECREF(tuple);
Expand Down
2 changes: 1 addition & 1 deletion Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ static PyObject *empty_values[1] = { NULL };
/* #define DEBUG_PYDICT */


#ifdef Py_DEBUG
#ifndef NDEBUG
static int
_PyDict_CheckConsistency(PyDictObject *mp)
{
Expand Down
2 changes: 1 addition & 1 deletion Objects/obmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,7 @@ _PyObject_Alloc(int use_calloc, void *ctx, size_t nelem, size_t elsize)

_Py_AllocatedBlocks++;

assert(nelem <= PY_SSIZE_T_MAX / elsize);
assert(elsize == 0 || nelem <= PY_SSIZE_T_MAX / elsize);
nbytes = nelem * elsize;

#ifdef WITH_VALGRIND
Expand Down
11 changes: 5 additions & 6 deletions Objects/setobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ set_add_entry(PySetObject *so, PyObject *key, Py_hash_t hash)
entry->hash = hash;
if ((size_t)so->fill*3 < mask*2)
return 0;
return set_table_resize(so, so->used);
return set_table_resize(so, so->used>50000 ? so->used*2 : so->used*4);

found_active:
Py_DECREF(key);
Expand Down Expand Up @@ -304,7 +304,6 @@ set_table_resize(PySetObject *so, Py_ssize_t minused)
setentry small_copy[PySet_MINSIZE];

assert(minused >= 0);
minused = (minused > 50000) ? minused * 2 : minused * 4;

/* Find the smallest table size > minused. */
/* XXX speed-up with intrinsics */
Expand Down Expand Up @@ -646,8 +645,8 @@ set_merge(PySetObject *so, PyObject *otherset)
* that there will be no (or few) overlapping keys.
*/
if ((so->fill + other->used)*3 >= so->mask*2) {
if (set_table_resize(so, so->used + other->used) != 0)
return -1;
if (set_table_resize(so, (so->used + other->used)*2) != 0)
return -1;
}
so_entry = so->table;
other_entry = other->table;
Expand Down Expand Up @@ -990,7 +989,7 @@ set_update_internal(PySetObject *so, PyObject *other)
if (dictsize < 0)
return -1;
if ((so->fill + dictsize)*3 >= so->mask*2) {
if (set_table_resize(so, so->used + dictsize) != 0)
if (set_table_resize(so, (so->used + dictsize)*2) != 0)
return -1;
}
while (_PyDict_Next(other, &pos, &key, &value, &hash)) {
Expand Down Expand Up @@ -1511,7 +1510,7 @@ set_difference_update_internal(PySetObject *so, PyObject *other)
/* If more than 1/4th are dummies, then resize them away. */
if ((size_t)(so->fill - so->used) <= (size_t)so->mask / 4)
return 0;
return set_table_resize(so, so->used);
return set_table_resize(so, so->used>50000 ? so->used*2 : so->used*4);
}

static PyObject *
Expand Down