Task = getattr(tasks, '_CTask', None)
Future = getattr(futures, '_CFuture', None)
+ @support.refcount_test
+ def test_refleaks_in_task___init__(self):
+ gettotalrefcount = support.get_attribute(sys, 'gettotalrefcount')
+ @asyncio.coroutine
+ def coro():
+ pass
+ task = self.new_task(self.loop, coro())
+ self.loop.run_until_complete(task)
+ refs_before = gettotalrefcount()
+ for i in range(100):
+ task.__init__(coro(), loop=self.loop)
+ self.loop.run_until_complete(task)
+ self.assertAlmostEqual(gettotalrefcount() - refs_before, 0, delta=10)
+
@unittest.skipUnless(hasattr(futures, '_CFuture') and
hasattr(tasks, '_CTask'),
import threading
from test.support import unlink
import _compression
+import sys
# Skip tests if the bz2 module doesn't exist.
# Previously, a second call could crash due to internal inconsistency
self.assertRaises(Exception, bzd.decompress, self.BAD_DATA * 30)
+ @support.refcount_test
+ def test_refleaks_in___init__(self):
+ gettotalrefcount = support.get_attribute(sys, 'gettotalrefcount')
+ bzd = BZ2Decompressor()
+ refs_before = gettotalrefcount()
+ for i in range(100):
+ bzd.__init__()
+ self.assertAlmostEqual(gettotalrefcount() - refs_before, 0, delta=10)
+
+
class CompressDecompressTest(BaseTest):
def testCompress(self):
data = bz2.compress(self.TEXT)
del cm.x
self.assertNotHasAttr(cm, "x")
+ @support.refcount_test
+ def test_refleaks_in_classmethod___init__(self):
+ gettotalrefcount = support.get_attribute(sys, 'gettotalrefcount')
+ cm = classmethod(None)
+ refs_before = gettotalrefcount()
+ for i in range(100):
+ cm.__init__(None)
+ self.assertAlmostEqual(gettotalrefcount() - refs_before, 0, delta=10)
+
@support.impl_detail("the module 'xxsubtype' is internal")
def test_classmethods_in_c(self):
# Testing C-based class methods...
del sm.x
self.assertNotHasAttr(sm, "x")
+ @support.refcount_test
+ def test_refleaks_in_staticmethod___init__(self):
+ gettotalrefcount = support.get_attribute(sys, 'gettotalrefcount')
+ sm = staticmethod(None)
+ refs_before = gettotalrefcount()
+ for i in range(100):
+ sm.__init__(None)
+ self.assertAlmostEqual(gettotalrefcount() - refs_before, 0, delta=10)
+
@support.impl_detail("the module 'xxsubtype' is internal")
def test_staticmethods_in_c(self):
# Testing C-based static methods...
constructors = self.constructors_to_test.values()
return itertools.chain.from_iterable(constructors)
+ @support.refcount_test
+ def test_refleaks_in_hash___init__(self):
+ gettotalrefcount = support.get_attribute(sys, 'gettotalrefcount')
+ sha1_hash = c_hashlib.new('sha1')
+ refs_before = gettotalrefcount()
+ for i in range(100):
+ sha1_hash.__init__('sha1')
+ self.assertAlmostEqual(gettotalrefcount() - refs_before, 0, delta=10)
+
def test_hash_array(self):
a = array.array("b", range(10))
for cons in self.hash_constructors:
import pathlib
import pickle
import random
+import sys
+from test import support
import unittest
from test.support import (
with self.assertRaises(TypeError):
pickle.dumps(LZMADecompressor(), proto)
+ @support.refcount_test
+ def test_refleaks_in_decompressor___init__(self):
+ gettotalrefcount = support.get_attribute(sys, 'gettotalrefcount')
+ lzd = LZMADecompressor()
+ refs_before = gettotalrefcount()
+ for i in range(100):
+ lzd.__init__()
+ self.assertAlmostEqual(gettotalrefcount() - refs_before, 0, delta=10)
+
class CompressDecompressFunctionTestCase(unittest.TestCase):
import sys
import unittest
+from test import support
class PropertyBase(Exception):
pass
sub.__class__.spam.__doc__ = 'Spam'
self.assertEqual(sub.__class__.spam.__doc__, 'Spam')
+ @support.refcount_test
+ def test_refleaks_in___init__(self):
+ gettotalrefcount = support.get_attribute(sys, 'gettotalrefcount')
+ fake_prop = property('fget', 'fset', 'fdel', 'doc')
+ refs_before = gettotalrefcount()
+ for i in range(100):
+ fake_prop.__init__('fget', 'fset', 'fdel', 'doc')
+ self.assertAlmostEqual(gettotalrefcount() - refs_before, 0, delta=10)
+
+
# Issue 5890: subclasses of property do not preserve method __doc__ strings
class PropertySub(property):
"""This is a subclass of property"""
--- /dev/null
+Fixed refleaks of ``__init__()`` methods in various modules.
+(Contributed by Oren Milman)
return 0;
}
+
static int
future_init(FutureObj *fut, PyObject *loop)
{
int is_true;
_Py_IDENTIFIER(get_debug);
+ // Same to FutureObj_clear() but not clearing fut->dict
+ Py_CLEAR(fut->fut_loop);
+ Py_CLEAR(fut->fut_callback0);
+ Py_CLEAR(fut->fut_context0);
+ Py_CLEAR(fut->fut_callbacks);
+ Py_CLEAR(fut->fut_result);
+ Py_CLEAR(fut->fut_exception);
+ Py_CLEAR(fut->fut_source_tb);
+
+ fut->fut_state = STATE_PENDING;
+ fut->fut_log_tb = 0;
+ fut->fut_blocking = 0;
+
if (loop == Py_None) {
loop = get_event_loop();
if (loop == NULL) {
else {
Py_INCREF(loop);
}
- Py_XSETREF(fut->fut_loop, loop);
+ fut->fut_loop = loop;
res = _PyObject_CallMethodId(fut->fut_loop, &PyId_get_debug, NULL);
if (res == NULL) {
return -1;
}
if (is_true) {
- Py_XSETREF(fut->fut_source_tb, _PyObject_CallNoArg(traceback_extract_stack));
+ fut->fut_source_tb = _PyObject_CallNoArg(traceback_extract_stack);
if (fut->fut_source_tb == NULL) {
return -1;
}
}
- fut->fut_callback0 = NULL;
- fut->fut_context0 = NULL;
- fut->fut_callbacks = NULL;
-
return 0;
}
return -1;
}
- self->task_context = PyContext_CopyCurrent();
+ Py_XSETREF(self->task_context, PyContext_CopyCurrent());
if (self->task_context == NULL) {
return -1;
}
- self->task_fut_waiter = NULL;
+ Py_CLEAR(self->task_fut_waiter);
self->task_must_cancel = 0;
self->task_log_destroy_pending = 1;
Py_INCREF(coro);
- self->task_coro = coro;
+ Py_XSETREF(self->task_coro, coro);
if (task_call_step_soon(self, NULL)) {
return -1;
self->bzs_avail_in_real = 0;
self->input_buffer = NULL;
self->input_buffer_size = 0;
- self->unused_data = PyBytes_FromStringAndSize(NULL, 0);
+ Py_XSETREF(self->unused_data, PyBytes_FromStringAndSize(NULL, 0));
if (self->unused_data == NULL)
goto error;
return -1;
}
- self->name = name_obj;
- Py_INCREF(self->name);
+ Py_INCREF(name_obj);
+ Py_XSETREF(self->name, name_obj);
if (data_obj) {
if (view.len >= HASHLIB_GIL_MINSIZE) {
self->needs_input = 1;
self->input_buffer = NULL;
self->input_buffer_size = 0;
- self->unused_data = PyBytes_FromStringAndSize(NULL, 0);
+ Py_XSETREF(self->unused_data, PyBytes_FromStringAndSize(NULL, 0));
if (self->unused_data == NULL)
goto error;
Py_XINCREF(fdel);
Py_XINCREF(doc);
- self->prop_get = fget;
- self->prop_set = fset;
- self->prop_del = fdel;
- self->prop_doc = doc;
+ Py_XSETREF(self->prop_get, fget);
+ Py_XSETREF(self->prop_set, fset);
+ Py_XSETREF(self->prop_del, fdel);
+ Py_XSETREF(self->prop_doc, doc);
self->getter_doc = 0;
/* if no docstring given and the getter has one, use that one */
if (!PyArg_UnpackTuple(args, "classmethod", 1, 1, &callable))
return -1;
Py_INCREF(callable);
- cm->cm_callable = callable;
+ Py_XSETREF(cm->cm_callable, callable);
return 0;
}
if (!PyArg_UnpackTuple(args, "staticmethod", 1, 1, &callable))
return -1;
Py_INCREF(callable);
- sm->sm_callable = callable;
+ Py_XSETREF(sm->sm_callable, callable);
return 0;
}