diff --git a/Tests/test_core_resources.py b/Tests/test_core_resources.py index 30bea3e80..11f26d38e 100644 --- a/Tests/test_core_resources.py +++ b/Tests/test_core_resources.py @@ -129,14 +129,15 @@ class TestCoreMemory(PillowTestCase): Image.core.set_block_size(4096) Image.new('RGB', (256, 256)) Image.new('RGB', (256, 256)) - Image.core.clear_cache() + # Keep 16 blocks in cache + Image.core.clear_cache(16) stats = Image.core.get_stats() self.assertGreaterEqual(stats['new_count'], 2) self.assertGreaterEqual(stats['allocated_blocks'], 64) self.assertGreaterEqual(stats['reused_blocks'], 64) - self.assertGreaterEqual(stats['freed_blocks'], 64) - self.assertEqual(stats['blocks_cached'], 0) + self.assertGreaterEqual(stats['freed_blocks'], 48) + self.assertEqual(stats['blocks_cached'], 16) def test_large_images(self): Image.core.reset_stats() diff --git a/_imaging.c b/_imaging.c index be612c1b7..b7d1ec09b 100644 --- a/_imaging.c +++ b/_imaging.c @@ -3466,10 +3466,12 @@ _set_blocks_max(PyObject* self, PyObject* args) static PyObject* _clear_cache(PyObject* self, PyObject* args) { - if (!PyArg_ParseTuple(args, ":clear_cache")) + int i = 0; + + if (!PyArg_ParseTuple(args, "|i:clear_cache", &i)) return NULL; - ImagingMemoryClearCache(&ImagingDefaultArena, 0); + ImagingMemoryClearCache(&ImagingDefaultArena, i); Py_INCREF(Py_None); return Py_None;