def test_structure(self):
     import _rawffi
     oldnum = _rawffi._num_of_allocated_objects()
     s = _rawffi.Structure([('a', 'i'), ('b', 'i')])()
     assert _rawffi._num_of_allocated_objects() - oldnum == 1
     s.free()
     assert _rawffi._num_of_allocated_objects() - oldnum == 0
 def test_array(self):
     import _rawffi
     oldnum = _rawffi._num_of_allocated_objects()
     a = _rawffi.Array('c')(3)
     assert _rawffi._num_of_allocated_objects() - oldnum == 1
     a.free()
     assert _rawffi._num_of_allocated_objects() - oldnum == 0
 def test_callback(self):
     import _rawffi
     oldnum = _rawffi._num_of_allocated_objects()
     c = _rawffi.CallbackPtr(lambda : 3, [], 'i')
     assert _rawffi._num_of_allocated_objects() - oldnum== 1
     c.free()
     assert _rawffi._num_of_allocated_objects() - oldnum== 0
Esempio n. 4
0
 def test_structure_autofree(self):
     import gc, _rawffi
     S = _rawffi.Structure([('x', 'i')])
     oldnum = _rawffi._num_of_allocated_objects()
     s = S(autofree=True)
     s.x = 3
     s = None
     gc.collect()
     assert oldnum == _rawffi._num_of_allocated_objects()
Esempio n. 5
0
 def setup_class(cls):
     #
     # detect if we're running on PyPy with DO_TRACING not compiled in
     if option.runappdirect:
         try:
             import _rawffi
             _rawffi._num_of_allocated_objects()
         except (ImportError, RuntimeError), e:
             py.test.skip(str(e))
Esempio n. 6
0
    def test_array_autofree(self):
        import gc, _rawffi
        oldnum = _rawffi._num_of_allocated_objects()

        A = _rawffi.Array('c')
        a = A(6, 'xxyxx\x00', autofree=True)
        assert _rawffi.charp2string(a.buffer) == 'xxyxx'
        a = None
        gc.collect()
        assert oldnum == _rawffi._num_of_allocated_objects()
Esempio n. 7
0
 def setup_class(cls):
     #
     # detect if we're running on PyPy with DO_TRACING not compiled in
     if option.runappdirect:
         try:
             import _rawffi
             _rawffi._num_of_allocated_objects()
         except (ImportError, RuntimeError) as e:
             py.test.skip(str(e))
     #
     Tracker.DO_TRACING = True
Esempio n. 8
0
 def test_structure_autofree(self):
     import gc, _rawffi
     gc.collect()
     gc.collect()
     S = _rawffi.Structure([('x', 'i')])
     oldnum = _rawffi._num_of_allocated_objects()
     s = S(autofree=True)
     s.x = 3
     s = None
     gc.collect()
     assert oldnum == _rawffi._num_of_allocated_objects()
Esempio n. 9
0
    def test_array_autofree(self):
        import gc, _rawffi
        gc.collect()
        oldnum = _rawffi._num_of_allocated_objects()

        A = _rawffi.Array('c')
        a = A(6, 'xxyxx\x00', autofree=True)
        assert _rawffi.charp2string(a.buffer) == 'xxyxx'
        a = None
        gc.collect()
        assert oldnum == _rawffi._num_of_allocated_objects()
Esempio n. 10
0
 def test_structure_autofree(self):
     import gc, _rawffi
     gc.collect()
     gc.collect()
     S = _rawffi.Structure([('x', 'i')])
     try:
         oldnum = _rawffi._num_of_allocated_objects()
     except RuntimeError:
         oldnum = '?'
     s = S(autofree=True)
     s.x = 3
     s = None
     gc.collect()
     if oldnum != '?':
         assert oldnum == _rawffi._num_of_allocated_objects()
Esempio n. 11
0
    def test_array_autofree(self):
        import gc, _rawffi
        gc.collect()
        try:
            oldnum = _rawffi._num_of_allocated_objects()
        except RuntimeError:
            oldnum = '?'

        A = _rawffi.Array('c')
        a = A(6, 'xxyxx\x00', autofree=True)
        assert _rawffi.charp2string(a.buffer) == 'xxyxx'
        a = None
        gc.collect()
        if oldnum != '?':
            assert oldnum == _rawffi._num_of_allocated_objects()
Esempio n. 12
0
    def test_array_autofree(self):
        import gc, _rawffi
        gc.collect()
        try:
            oldnum = _rawffi._num_of_allocated_objects()
        except RuntimeError:
            oldnum = '?'

        A = _rawffi.Array('c')
        a = A(6, 'xxyxx\x00', autofree=True)
        assert _rawffi.charp2string(a.buffer) == 'xxyxx'
        a = None
        gc.collect()
        if oldnum != '?':
            assert oldnum == _rawffi._num_of_allocated_objects()
Esempio n. 13
0
 def test_structure_autofree(self):
     import gc, _rawffi
     gc.collect()
     gc.collect()
     S = _rawffi.Structure([('x', 'i')])
     try:
         oldnum = _rawffi._num_of_allocated_objects()
     except RuntimeError:
         oldnum = '?'
     s = S(autofree=True)
     s.x = 3
     s = None
     gc.collect()
     if oldnum != '?':
         assert oldnum == _rawffi._num_of_allocated_objects()
Esempio n. 14
0
    def setup_class(cls):
        if _rawffi:
            import gc

            for _ in range(4):
                gc.collect()
            cls.old_num = _rawffi._num_of_allocated_objects()
Esempio n. 15
0
 def setup_class(cls):
     if _rawffi:
         import gc
         for _ in range(4):
             gc.collect()
         try:
             cls.old_num = _rawffi._num_of_allocated_objects()
         except RuntimeError:
             pass
Esempio n. 16
0
 def setup_class(cls):
     if _rawffi:
         import gc
         for _ in range(4):
             gc.collect()
         try:
             cls.old_num = _rawffi._num_of_allocated_objects()
         except RuntimeError:
             pass
Esempio n. 17
0
 def setup_class(cls):
     try:
         import _rawffi
     except ImportError:
         pass
     else:
         import gc
         for _ in range(4):
             gc.collect()
         cls.old_num = _rawffi._num_of_allocated_objects()
Esempio n. 18
0
 def setup_class(cls):
     try:
         import _rawffi
     except ImportError:
         pass
     else:
         import gc
         for _ in range(4):
             gc.collect()
         cls.old_num = _rawffi._num_of_allocated_objects()
Esempio n. 19
0
 def teardown_class(cls):
     #return
     try:
         import _rawffi
     except ImportError:
         pass
     else:
         import gc
         for _ in range(4):
             gc.collect()
         # there is one reference coming from the byref() above
         assert _rawffi._num_of_allocated_objects() == cls.old_num
Esempio n. 20
0
 def teardown_class(cls):
     #return
     try:
         import _rawffi
     except ImportError:
         pass
     else:
         import gc
         for _ in range(4):
             gc.collect()
         # there is one reference coming from the byref() above
         assert _rawffi._num_of_allocated_objects() == cls.old_num
Esempio n. 21
0
 def teardown_class(cls):
     if sys.pypy_translation_info['translation.gc'] == 'boehm':
         return  # it seems that boehm has problems with __del__, so not
         # everything is freed
     #
     mod = sys.modules[cls.__module__]
     del_funcptr_refs_maybe(mod, 'dll')
     del_funcptr_refs_maybe(mod, 'dll2')
     del_funcptr_refs_maybe(mod, 'lib')
     del_funcptr_refs_maybe(mod, 'testdll')
     del_funcptr_refs_maybe(mod, 'ctdll')
     del_funcptr_refs_maybe(cls, '_dll')
     #
     if hasattr(cls, 'old_num'):
         import gc
         for _ in range(4):
             gc.collect()
         # there is one reference coming from the byref() above
         assert _rawffi._num_of_allocated_objects() == cls.old_num
Esempio n. 22
0
    def teardown_class(cls):
        if sys.pypy_translation_info["translation.gc"] == "boehm":
            return  # it seems that boehm has problems with __del__, so not
            # everything is freed
        #
        mod = sys.modules[cls.__module__]
        del_funcptr_refs_maybe(mod, "dll")
        del_funcptr_refs_maybe(mod, "dll2")
        del_funcptr_refs_maybe(mod, "lib")
        del_funcptr_refs_maybe(mod, "testdll")
        del_funcptr_refs_maybe(mod, "ctdll")
        del_funcptr_refs_maybe(cls, "_dll")
        #
        if hasattr(cls, "old_num"):
            import gc

            for _ in range(4):
                gc.collect()
            # there is one reference coming from the byref() above
            assert _rawffi._num_of_allocated_objects() == cls.old_num
Esempio n. 23
0
 def teardown_class(cls):
     if not hasattr(sys, 'pypy_translation_info'):
         return
     if sys.pypy_translation_info['translation.gc'] == 'boehm':
         return # it seems that boehm has problems with __del__, so not
                # everything is freed
     #
     mod = sys.modules[cls.__module__]
     del_funcptr_refs_maybe(mod, 'dll')
     del_funcptr_refs_maybe(mod, 'dll2')
     del_funcptr_refs_maybe(mod, 'lib')
     del_funcptr_refs_maybe(mod, 'testdll')
     del_funcptr_refs_maybe(mod, 'ctdll')
     del_funcptr_refs_maybe(cls, '_dll')
     #
     if hasattr(cls, 'old_num'):
         import gc
         for _ in range(4):
             gc.collect()
         # there is one reference coming from the byref() above
         assert _rawffi._num_of_allocated_objects() == cls.old_num
Esempio n. 24
0
 def setup_class(cls):
     if _rawffi:
         import gc
         for _ in range(4):
             gc.collect()
         cls.old_num = _rawffi._num_of_allocated_objects()