sys.grc

Here are the examples of the python api sys.grc taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

149 Examples 7

Example 1

Project: openwrt-mt7620
Source File: test_stringptr.py
View license
    def test__POINTER_c_char(self):
        class X(Structure):
            _fields_ = [("str", POINTER(c_char))]
        x = X()

        # NULL pointer access
        self.assertRaises(ValueError, getattr, x.str, "contents")
        b = c_buffer("Hello, World")
        from sys import getrefcount as grc
        self.assertEqual(grc(b), 2)
        x.str = b
        self.assertEqual(grc(b), 3)

        # POINTER(c_char) and Python string is NOT compatible
        # POINTER(c_char) and c_buffer() is compatible
        for i in range(len(b)):
            self.assertEqual(b[i], x.str[i])

        self.assertRaises(TypeError, setattr, x, "str", "Hello, World")

Example 2

Project: WAPT
Source File: test_message.py
View license
def await_gc(obj, rc):
    """wait for refcount on an object to drop to an expected value
    
    Necessary because of the zero-copy gc thread,
    which can take some time to receive its DECREF message.
    """
    for i in range(50):
        # rc + 2 because of the refs in this function
        if grc(obj) <= rc + 2:
            return
        time.sleep(0.05)

Example 3

Project: pymo
Source File: test_python_api.py
View license
    def test_PyString_FromString(self):
        pythonapi.PyString_FromString.restype = py_object
        pythonapi.PyString_FromString.argtypes = (c_char_p,)

        s = "abc"
        refcnt = grc(s)
        pyob = pythonapi.PyString_FromString(s)
        self.assertEqual(grc(s), refcnt)
        self.assertEqual(s, pyob)
        del pyob
        self.assertEqual(grc(s), refcnt)

Example 4

Project: Veil-Catapult
Source File: test_stringptr.py
View license
    def test__POINTER_c_char(self):
        class X(Structure):
            _fields_ = [("str", POINTER(c_char))]
        x = X()

        # NULL pointer access
        self.assertRaises(ValueError, getattr, x.str, "contents")
        b = c_buffer("Hello, World")
        from sys import getrefcount as grc
        self.assertEqual(grc(b), 2)
        x.str = b
        self.assertEqual(grc(b), 3)

        # POINTER(c_char) and Python string is NOT compatible
        # POINTER(c_char) and c_buffer() is compatible
        for i in range(len(b)):
            self.assertEqual(b[i], x.str[i])

        self.assertRaises(TypeError, setattr, x, "str", "Hello, World")

Example 5

Project: Veil-Catapult
Source File: test_internals.py
View license
    def test_ints(self):
        i = 42000123
        refcnt = grc(i)
        ci = c_int(i)
        self.assertEqual(refcnt, grc(i))
        self.assertEqual(ci._objects, None)

Example 6

Project: openwrt-mt7620
Source File: test_internals.py
View license
    def test_ints(self):
        i = 42000123
        refcnt = grc(i)
        ci = c_int(i)
        self.assertEqual(refcnt, grc(i))
        self.assertEqual(ci._objects, None)

Example 7

Project: TrustRouter
Source File: test_python_api.py
View license
        def test_PyLong_Long(self):
            ref42 = grc(42)
            pythonapi.PyLong_FromLong.restype = py_object
            self.assertEqual(pythonapi.PyLong_FromLong(42), 42)

            self.assertEqual(grc(42), ref42)

            pythonapi.PyLong_AsLong.argtypes = (py_object,)
            pythonapi.PyLong_AsLong.restype = c_long

            res = pythonapi.PyLong_AsLong(42)
            self.assertEqual(grc(res), ref42 + 1)
            del res
            self.assertEqual(grc(42), ref42)

Example 8

Project: pymo
Source File: test_internals.py
View license
    def test_ints(self):
        i = 42000123
        refcnt = grc(i)
        ci = c_int(i)
        self.assertEqual(refcnt, grc(i))
        self.assertEqual(ci._objects, None)

Example 9

Project: openwrt-mt7620
Source File: test_callbacks.py
View license
    def test_pyobject(self):
        o = ()
        from sys import getrefcount as grc
        for o in (), [], object():
            initial = grc(o)
            # This call leaks a reference to 'o'...
            self.check_type(py_object, o)
            before = grc(o)
            # ...but this call doesn't leak any more.  Where is the refcount?
            self.check_type(py_object, o)
            after = grc(o)
            self.assertEqual((after, o), (before, o))

Example 10

Project: pymo
Source File: test_python_api.py
View license
        def test_PyInt_Long(self):
            ref42 = grc(42)
            pythonapi.PyInt_FromLong.restype = py_object
            self.assertEqual(pythonapi.PyInt_FromLong(42), 42)

            self.assertEqual(grc(42), ref42)

            pythonapi.PyInt_AsLong.argtypes = (py_object,)
            pythonapi.PyInt_AsLong.restype = c_long

            res = pythonapi.PyInt_AsLong(42)
            self.assertEqual(grc(res), ref42 + 1)
            del res
            self.assertEqual(grc(42), ref42)

Example 11

Project: TrustRouter
Source File: test_callbacks.py
View license
    def test_pyobject(self):
        o = ()
        from sys import getrefcount as grc
        for o in (), [], object():
            initial = grc(o)
            # This call leaks a reference to 'o'...
            self.check_type(py_object, o)
            before = grc(o)
            # ...but this call doesn't leak any more.  Where is the refcount?
            self.check_type(py_object, o)
            after = grc(o)
            self.assertEqual((after, o), (before, o))

Example 12

Project: pymo
Source File: test_python_api.py
View license
    def test_PyObj_FromPtr(self):
        s = "abc def ghi jkl"
        ref = grc(s)
        # id(python-object) is the address
        pyobj = PyObj_FromPtr(id(s))
        self.assertTrue(s is pyobj)

        self.assertEqual(grc(s), ref + 1)
        del pyobj
        self.assertEqual(grc(s), ref)

Example 13

Project: openwrt-mt7620
Source File: test_python_api.py
View license
    def test_PyString_FromString(self):
        pythonapi.PyString_FromString.restype = py_object
        pythonapi.PyString_FromString.argtypes = (c_char_p,)

        s = "abc"
        refcnt = grc(s)
        pyob = pythonapi.PyString_FromString(s)
        self.assertEqual(grc(s), refcnt)
        self.assertEqual(s, pyob)
        del pyob
        self.assertEqual(grc(s), refcnt)

Example 14

Project: pyzmq
Source File: test_message.py
View license
    @skip_pypy
    def test_above_30(self):
        """Message above 30 bytes are never copied by 0MQ."""
        for i in range(5, 16):  # 32, 64,..., 65536
            s = (2**i)*x
            self.assertEqual(grc(s), 2)
            m = zmq.Frame(s)
            self.assertEqual(grc(s), 4)
            del m
            await_gc(s, 2)
            self.assertEqual(grc(s), 2)
            del s

Example 15

Project: openwrt-mt7620
Source File: test_internals.py
View license
    def test_c_char_p(self):
        s = "Hello, World"
        refcnt = grc(s)
        cs = c_char_p(s)
        self.assertEqual(refcnt + 1, grc(s))
        self.assertSame(cs._objects, s)

Example 16

Project: datafari
Source File: test_internals.py
View license
    def test_ints(self):
        i = 42000123
        refcnt = grc(i)
        ci = c_int(i)
        self.assertEqual(refcnt, grc(i))
        self.assertEqual(ci._objects, None)

Example 17

Project: pymo
Source File: test_stringptr.py
View license
    def test__POINTER_c_char(self):
        class X(Structure):
            _fields_ = [("str", POINTER(c_char))]
        x = X()

        # NULL pointer access
        self.assertRaises(ValueError, getattr, x.str, "contents")
        b = c_buffer("Hello, World")
        from sys import getrefcount as grc
        self.assertEqual(grc(b), 2)
        x.str = b
        self.assertEqual(grc(b), 3)

        # POINTER(c_char) and Python string is NOT compatible
        # POINTER(c_char) and c_buffer() is compatible
        for i in range(len(b)):
            self.assertEqual(b[i], x.str[i])

        self.assertRaises(TypeError, setattr, x, "str", "Hello, World")

Example 18

Project: datafari
Source File: test_python_api.py
View license
    def test_PyInt_Long(self):
        requires("refcount")
        ref42 = grc(42)
        pythonapi.PyInt_FromLong.restype = py_object
        self.assertEqual(pythonapi.PyInt_FromLong(42), 42)

        self.assertEqual(grc(42), ref42)

        pythonapi.PyInt_AsLong.argtypes = (py_object,)
        pythonapi.PyInt_AsLong.restype = c_long

        res = pythonapi.PyInt_AsLong(42)
        self.assertEqual(grc(res), ref42 + 1)
        del res
        self.assertEqual(grc(42), ref42)

Example 19

Project: openwrt-mt7620
Source File: test_python_api.py
View license
    def test_PyObj_FromPtr(self):
        s = "abc def ghi jkl"
        ref = grc(s)
        # id(python-object) is the address
        pyobj = PyObj_FromPtr(id(s))
        self.assertTrue(s is pyobj)

        self.assertEqual(grc(s), ref + 1)
        del pyobj
        self.assertEqual(grc(s), ref)

Example 20

Project: datafari
Source File: test_stringptr.py
View license
    def test__POINTER_c_char(self):
        class X(Structure):
            _fields_ = [("str", POINTER(c_char))]
        x = X()

        # NULL pointer access
        self.assertRaises(ValueError, getattr, x.str, "contents")
        b = c_buffer("Hello, World")
        from sys import getrefcount as grc
        self.assertEqual(grc(b), 2)
        x.str = b
        self.assertEqual(grc(b), 3)

        # POINTER(c_char) and Python string is NOT compatible
        # POINTER(c_char) and c_buffer() is compatible
        for i in range(len(b)):
            self.assertEqual(b[i], x.str[i])

        self.assertRaises(TypeError, setattr, x, "str", "Hello, World")

Example 21

Project: openwrt-mt7620
Source File: test_internals.py
View license
    def test_ints(self):
        i = 42000123
        refcnt = grc(i)
        ci = c_int(i)
        self.assertEqual(refcnt, grc(i))
        self.assertEqual(ci._objects, None)

Example 22

Project: Veil-Catapult
Source File: test_callbacks.py
View license
    def test_pyobject(self):
        o = ()
        from sys import getrefcount as grc
        for o in (), [], object():
            initial = grc(o)
            # This call leaks a reference to 'o'...
            self.check_type(py_object, o)
            before = grc(o)
            # ...but this call doesn't leak any more.  Where is the refcount?
            self.check_type(py_object, o)
            after = grc(o)
            self.assertEqual((after, o), (before, o))

Example 23

Project: openwrt-mt7620
Source File: test_internals.py
View license
    def test_c_char_p(self):
        s = "Hello, World"
        refcnt = grc(s)
        cs = c_char_p(s)
        self.assertEqual(refcnt + 1, grc(s))
        self.assertSame(cs._objects, s)

Example 24

Project: Veil-Catapult
Source File: test_internals.py
View license
    def test_c_char_p(self):
        s = "Hello, World"
        refcnt = grc(s)
        cs = c_char_p(s)
        self.assertEqual(refcnt + 1, grc(s))
        self.assertSame(cs._objects, s)

Example 25

Project: pymo
Source File: test_internals.py
View license
    def test_c_char_p(self):
        s = "Hello, World"
        refcnt = grc(s)
        cs = c_char_p(s)
        self.assertEqual(refcnt + 1, grc(s))
        self.assertSame(cs._objects, s)

Example 26

Project: Veil-Catapult
Source File: test_python_api.py
View license
    def test_PyObj_FromPtr(self):
        s = "abc def ghi jkl"
        ref = grc(s)
        # id(python-object) is the address
        pyobj = PyObj_FromPtr(id(s))
        self.assertTrue(s is pyobj)

        self.assertEqual(grc(s), ref + 1)
        del pyobj
        self.assertEqual(grc(s), ref)

Example 27

Project: Veil-Catapult
Source File: test_python_api.py
View license
    def test_PyString_FromString(self):
        pythonapi.PyString_FromString.restype = py_object
        pythonapi.PyString_FromString.argtypes = (c_char_p,)

        s = "abc"
        refcnt = grc(s)
        pyob = pythonapi.PyString_FromString(s)
        self.assertEqual(grc(s), refcnt)
        self.assertEqual(s, pyob)
        del pyob
        self.assertEqual(grc(s), refcnt)

Example 28

Project: openwrt-mt7620
Source File: test_python_api.py
View license
        def test_PyInt_Long(self):
            ref42 = grc(42)
            pythonapi.PyInt_FromLong.restype = py_object
            self.assertEqual(pythonapi.PyInt_FromLong(42), 42)

            self.assertEqual(grc(42), ref42)

            pythonapi.PyInt_AsLong.argtypes = (py_object,)
            pythonapi.PyInt_AsLong.restype = c_long

            res = pythonapi.PyInt_AsLong(42)
            self.assertEqual(grc(res), ref42 + 1)
            del res
            self.assertEqual(grc(42), ref42)

Example 29

Project: TrustRouter
Source File: test_internals.py
View license
    def test_ints(self):
        i = 42000123
        refcnt = grc(i)
        ci = c_int(i)
        self.assertEqual(refcnt, grc(i))
        self.assertEqual(ci._objects, None)

Example 30

Project: openwrt-mt7620
Source File: test_python_api.py
View license
    def test_PyObj_FromPtr(self):
        s = "abc def ghi jkl"
        ref = grc(s)
        # id(python-object) is the address
        pyobj = PyObj_FromPtr(id(s))
        self.assertTrue(s is pyobj)

        self.assertEqual(grc(s), ref + 1)
        del pyobj
        self.assertEqual(grc(s), ref)

Example 31

Project: pyzmq
Source File: test_message.py
View license
def await_gc(obj, rc):
    """wait for refcount on an object to drop to an expected value
    
    Necessary because of the zero-copy gc thread,
    which can take some time to receive its DECREF message.
    """
    for i in range(50):
        # rc + 2 because of the refs in this function
        if grc(obj) <= rc + 2:
            return
        time.sleep(0.05)

Example 32

Project: TrustRouter
Source File: test_internals.py
View license
    def test_c_char_p(self):
        s = b"Hello, World"
        refcnt = grc(s)
        cs = c_char_p(s)
        self.assertEqual(refcnt + 1, grc(s))
        self.assertSame(cs._objects, s)

Example 33

Project: openwrt-mt7620
Source File: test_callbacks.py
View license
    def test_pyobject(self):
        o = ()
        from sys import getrefcount as grc
        for o in (), [], object():
            initial = grc(o)
            # This call leaks a reference to 'o'...
            self.check_type(py_object, o)
            before = grc(o)
            # ...but this call doesn't leak any more.  Where is the refcount?
            self.check_type(py_object, o)
            after = grc(o)
            self.assertEqual((after, o), (before, o))

Example 34

Project: openwrt-mt7620
Source File: test_stringptr.py
View license
    def test__POINTER_c_char(self):
        class X(Structure):
            _fields_ = [("str", POINTER(c_char))]
        x = X()

        # NULL pointer access
        self.assertRaises(ValueError, getattr, x.str, "contents")
        b = c_buffer("Hello, World")
        from sys import getrefcount as grc
        self.assertEqual(grc(b), 2)
        x.str = b
        self.assertEqual(grc(b), 3)

        # POINTER(c_char) and Python string is NOT compatible
        # POINTER(c_char) and c_buffer() is compatible
        for i in range(len(b)):
            self.assertEqual(b[i], x.str[i])

        self.assertRaises(TypeError, setattr, x, "str", "Hello, World")

Example 35

Project: datafari
Source File: test_callbacks.py
View license
    def test_pyobject(self):
        o = ()
        from sys import getrefcount as grc
        for o in (), [], object():
            initial = grc(o)
            # This call leaks a reference to 'o'...
            self.check_type(py_object, o)
            before = grc(o)
            # ...but this call doesn't leak any more.  Where is the refcount?
            self.check_type(py_object, o)
            after = grc(o)
            self.assertEqual((after, o), (before, o))

Example 36

Project: TrustRouter
Source File: test_python_api.py
View license
    def test_PyString_FromString(self):
        pythonapi.PyBytes_FromString.restype = py_object
        pythonapi.PyBytes_FromString.argtypes = (c_char_p,)

        s = b"abc"
        refcnt = grc(s)
        pyob = pythonapi.PyBytes_FromString(s)
        self.assertEqual(grc(s), refcnt)
        self.assertEqual(s, pyob)
        del pyob
        self.assertEqual(grc(s), refcnt)

Example 37

Project: datafari
Source File: test_internals.py
View license
    def test_c_char_p(self):
        s = "Hello, World"
        refcnt = grc(s)
        cs = c_char_p(s)
        self.assertEqual(refcnt + 1, grc(s))
        self.assertSame(cs._objects, s)

Example 38

Project: openwrt-mt7620
Source File: test_python_api.py
View license
        def test_PyInt_Long(self):
            ref42 = grc(42)
            pythonapi.PyInt_FromLong.restype = py_object
            self.assertEqual(pythonapi.PyInt_FromLong(42), 42)

            self.assertEqual(grc(42), ref42)

            pythonapi.PyInt_AsLong.argtypes = (py_object,)
            pythonapi.PyInt_AsLong.restype = c_long

            res = pythonapi.PyInt_AsLong(42)
            self.assertEqual(grc(res), ref42 + 1)
            del res
            self.assertEqual(grc(42), ref42)

Example 39

Project: datafari
Source File: test_python_api.py
View license
    def test_PyString_FromString(self):
        pythonapi.PyString_FromString.restype = py_object
        pythonapi.PyString_FromString.argtypes = (c_char_p,)

        s = "abc"
        refcnt = grc(s)
        pyob = pythonapi.PyString_FromString(s)
        self.assertEqual(grc(s), refcnt)
        self.assertEqual(s, pyob)
        del pyob
        self.assertEqual(grc(s), refcnt)

Example 40

Project: TrustRouter
Source File: test_python_api.py
View license
    def test_PyObj_FromPtr(self):
        s = "abc def ghi jkl"
        ref = grc(s)
        # id(python-object) is the address
        pyobj = PyObj_FromPtr(id(s))
        self.assertTrue(s is pyobj)

        self.assertEqual(grc(s), ref + 1)
        del pyobj
        self.assertEqual(grc(s), ref)

Example 41

Project: datafari
Source File: test_python_api.py
View license
    def test_PyObj_FromPtr(self):
        s = "abc def ghi jkl"
        ref = grc(s)
        # id(python-object) is the address
        pyobj = PyObj_FromPtr(id(s))
        self.assertIs(s, pyobj)

        self.assertEqual(grc(s), ref + 1)
        del pyobj
        self.assertEqual(grc(s), ref)

Example 42

Project: ironpython3
Source File: test_callbacks.py
View license
    def test_pyobject(self):
        o = ()
        from sys import getrefcount as grc
        for o in (), [], object():
            initial = grc(o)
            # This call leaks a reference to 'o'...
            self.check_type(py_object, o)
            before = grc(o)
            # ...but this call doesn't leak any more.  Where is the refcount?
            self.check_type(py_object, o)
            after = grc(o)
            self.assertEqual((after, o), (before, o))

Example 43

Project: WAPT
Source File: test_message.py
View license
    @skip_pypy
    def test_above_30(self):
        """Message above 30 bytes are never copied by 0MQ."""
        for i in range(5, 16):  # 32, 64,..., 65536
            s = (2**i)*x
            self.assertEqual(grc(s), 2)
            m = zmq.Frame(s)
            self.assertEqual(grc(s), 4)
            del m
            await_gc(s, 2)
            self.assertEqual(grc(s), 2)
            del s

Example 44

Project: TrustRouter
Source File: test_stringptr.py
View license
    def test__POINTER_c_char(self):
        class X(Structure):
            _fields_ = [("str", POINTER(c_char))]
        x = X()

        # NULL pointer access
        self.assertRaises(ValueError, getattr, x.str, "contents")
        b = c_buffer(b"Hello, World")
        from sys import getrefcount as grc
        self.assertEqual(grc(b), 2)
        x.str = b
        self.assertEqual(grc(b), 3)

        # POINTER(c_char) and Python string is NOT compatible
        # POINTER(c_char) and c_buffer() is compatible
        for i in range(len(b)):
            self.assertEqual(b[i], x.str[i])

        self.assertRaises(TypeError, setattr, x, "str", "Hello, World")

Example 45

Project: ironpython3
Source File: test_internals.py
View license
    def test_c_char_p(self):
        s = b"Hello, World"
        refcnt = grc(s)
        cs = c_char_p(s)
        self.assertEqual(refcnt + 1, grc(s))
        self.assertSame(cs._objects, s)

Example 46

Project: ironpython3
Source File: test_internals.py
View license
    def test_ints(self):
        i = 42000123
        refcnt = grc(i)
        ci = c_int(i)
        self.assertEqual(refcnt, grc(i))
        self.assertEqual(ci._objects, None)

Example 47

Project: openwrt-mt7620
Source File: test_python_api.py
View license
    def test_PyString_FromString(self):
        pythonapi.PyString_FromString.restype = py_object
        pythonapi.PyString_FromString.argtypes = (c_char_p,)

        s = "abc"
        refcnt = grc(s)
        pyob = pythonapi.PyString_FromString(s)
        self.assertEqual(grc(s), refcnt)
        self.assertEqual(s, pyob)
        del pyob
        self.assertEqual(grc(s), refcnt)

Example 48

Project: pymo
Source File: test_callbacks.py
View license
    def test_pyobject(self):
        o = ()
        from sys import getrefcount as grc
        for o in (), [], object():
            initial = grc(o)
            # This call leaks a reference to 'o'...
            self.check_type(py_object, o)
            before = grc(o)
            # ...but this call doesn't leak any more.  Where is the refcount?
            self.check_type(py_object, o)
            after = grc(o)
            self.assertEqual((after, o), (before, o))

Example 49

Project: ctypeslib
Source File: test_pythonhdr.py
View license
    def test_PyObject(self):
        self.failUnlessRaises(NotImplementedError, PyObject, None)

        class PyFloatObject(PyObject):
            _fields_ = [("ob_fval", c_double)]
        self.failUnlessEqual(sizeof(PyFloatObject), float.__basicsize__,
                             "Alignment, float changed"
                             "or Py_TRACE_REFs not seen.")
        d = 100.0
        rcdt = grc(float)
        try:
            fo = PyFloatObject.from_address(id(d))
            self.failUnlessEqual(grc(float), rcdt)
            e = fo.ob_fval
        finally:
            del fo
        self.failUnlessEqual(d, e)
        del e
        self.failUnlessEqual(grc(float), rcdt)

Example 50

Project: Veil-Catapult
Source File: test_python_api.py
View license
        def test_PyInt_Long(self):
            ref42 = grc(42)
            pythonapi.PyInt_FromLong.restype = py_object
            self.assertEqual(pythonapi.PyInt_FromLong(42), 42)

            self.assertEqual(grc(42), ref42)

            pythonapi.PyInt_AsLong.argtypes = (py_object,)
            pythonapi.PyInt_AsLong.restype = c_long

            res = pythonapi.PyInt_AsLong(42)
            self.assertEqual(grc(res), ref42 + 1)
            del res
            self.assertEqual(grc(42), ref42)