Rev 149: Describe referrers as parents. in http://bazaar.launchpad.net/~jameinel/meliae/mem-object-collection

John Arbash Meinel john at arbash-meinel.com
Tue Dec 29 04:13:48 GMT 2009


At http://bazaar.launchpad.net/~jameinel/meliae/mem-object-collection

------------------------------------------------------------
revno: 149
revision-id: john at arbash-meinel.com-20091229041329-it4qa9cdvebo2sad
parent: john at arbash-meinel.com-20091229040713-poo0arn5mixechyz
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: mem-object-collection
timestamp: Mon 2009-12-28 22:13:29 -0600
message:
  Describe referrers as parents.
  
  The main issue is that 'references' and 'referrers' are very similar,
  and both shorten to 'refs'. Instead, use 'references' and 'parents',
  which short to 'ref' and 'par' which are more distinct.
  We should consider switching to 'children' if we are going to call
  things parents...
-------------- next part --------------
=== modified file 'meliae/_loader.pyx'
--- a/meliae/_loader.pyx	2009-12-29 04:07:13 +0000
+++ b/meliae/_loader.pyx	2009-12-29 04:13:29 +0000
@@ -164,7 +164,7 @@
     #       name. As such, I should probably remove the redundancy, as it saves
     #       a pointer
     # PyObject *name
-    RefList *referrer_list
+    RefList *parent_list
     unsigned long total_size
     # This is an uncounted ref to a _MemObjectProxy. _MemObjectProxy also has a
     # refreence to this object, so when it disappears it can set the reference
@@ -189,8 +189,8 @@
     cur.value = NULL
     # Py_XDECREF(cur.name)
     # cur.name = NULL
-    _free_ref_list(cur.referrer_list)
-    cur.referrer_list = NULL
+    _free_ref_list(cur.parent_list)
+    cur.parent_list = NULL
     cur.proxy = NULL
     PyMem_Free(cur)
     return 1
@@ -296,9 +296,9 @@
         if self._obj.ref_list != NULL:
             for i from 0 <= i < self._obj.ref_list.size:
                 _set_default_ptr(cache, &self._obj.ref_list.refs[i])
-        if self._obj.referrer_list != NULL:
-            for i from 0 <= i < self._obj.referrer_list.size:
-                _set_default_ptr(cache, &self._obj.referrer_list.refs[i])
+        if self._obj.parent_list != NULL:
+            for i from 0 <= i < self._obj.parent_list.size:
+                _set_default_ptr(cache, &self._obj.parent_list.refs[i])
 
 
     property ref_list:
@@ -310,24 +310,41 @@
             _free_ref_list(self._obj.ref_list)
             self._obj.ref_list = _list_to_ref_list(value)
 
+    # TODO: deprecated for clarity
     property referrers:
+        def __get__(self):
+            return _ref_list_to_list(self._obj.parent_list)
+
+        def __set__(self, value):
+            _free_ref_list(self._obj.parent_list)
+            self._obj.parent_list = _list_to_ref_list(value)
+
+    property parents:
         """The list of objects that reference this object.
 
         Original set to None, can be computed on demand.
         """
         def __get__(self):
-            return _ref_list_to_list(self._obj.referrer_list)
+            return _ref_list_to_list(self._obj.parent_list)
 
         def __set__(self, value):
-            _free_ref_list(self._obj.referrer_list)
-            self._obj.referrer_list = _list_to_ref_list(value)
+            _free_ref_list(self._obj.parent_list)
+            self._obj.parent_list = _list_to_ref_list(value)
 
+    # TODO: deprecated for clarity
     property num_referrers:
-        """The length of the referrers list."""
-        def __get__(self):
-            if self._obj.referrer_list == NULL:
-                return 0
-            return self._obj.referrer_list.size
+        """The length of the parents list."""
+        def __get__(self):
+            if self._obj.parent_list == NULL:
+                return 0
+            return self._obj.parent_list.size
+
+    property num_parents:
+        """The length of the parents list."""
+        def __get__(self):
+            if self._obj.parent_list == NULL:
+                return 0
+            return self._obj.parent_list.size
 
     def __getitem__(self, offset):
         cdef long off
@@ -351,10 +368,10 @@
             refs = ''
         else:
             refs = ' %drefs' % (self._obj.ref_list.size,)
-        if self._obj.referrer_list == NULL:
-            referrers = ''
+        if self._obj.parent_list == NULL:
+            parent_str = ''
         else:
-            referrers = ' %dpar' % (self._obj.referrer_list.size,)
+            parent_str = ' %dpar' % (self._obj.parent_list.size,)
         if self._obj.value == NULL or self._obj.value == Py_None:
             val = ''
         else:
@@ -376,7 +393,7 @@
             total_size_str = ' %.1f%stot' % (total_size, order)
         return '%s(%d %dB%s%s%s%s)' % (
             self.type_str, self.address, self.size,
-            refs, referrers, val, total_size_str)
+            refs, parent_str, val, total_size_str)
 
 
 cdef class MemObjectCollection:
@@ -589,7 +606,7 @@
 
 
     def add(self, address, type_str, size, ref_list=(), length=0,
-            value=None, name=None, referrer_list=(), total_size=0):
+            value=None, name=None, parent_list=(), total_size=0):
         """Add a new MemObject to this collection."""
         cdef _MemObject **slot, *new_entry
         cdef _MemObjectProxy proxy
@@ -634,7 +651,7 @@
         else:
             new_entry.value = <PyObject *>name
         Py_INCREF(new_entry.value)
-        new_entry.referrer_list = _list_to_ref_list(referrer_list)
+        new_entry.parent_list = _list_to_ref_list(parent_list)
         new_entry.total_size = total_size
 
         if self._filled * 3 > (self._table_mask + 1) * 2:

=== modified file 'meliae/tests/test__loader.py'
--- a/meliae/tests/test__loader.py	2009-12-29 04:07:13 +0000
+++ b/meliae/tests/test__loader.py	2009-12-29 04:13:29 +0000
@@ -386,6 +386,21 @@
         mop.total_size = (2**31+1)
         self.assertEqual(2**31+1, mop.total_size)
 
+    def test_parents(self):
+        mop = self.moc.add(1234567, 'type', 256, ref_list=[0, 255])
+        mop0 = self.moc[0]
+        self.assertEqual((), mop0.parents)
+        self.assertEqual(0, mop0.num_parents)
+        mop255 = self.moc[255]
+        self.assertEqual((), mop255.parents)
+        self.assertEqual(0, mop255.num_parents)
+        mop0.parents = [1234567]
+        self.assertEqual(1, mop0.num_parents)
+        self.assertEqual([1234567], mop0.parents)
+        mop255.parents = [1234567]
+        self.assertEqual(1, mop255.num_parents)
+        self.assertEqual([1234567], mop255.parents)
+
     def test_referrers(self):
         mop = self.moc.add(1234567, 'type', 256, ref_list=[0, 255])
         mop0 = self.moc[0]
@@ -411,7 +426,7 @@
         self.assertEqual("module(1236 12B 2refs 'named')", repr(mop))
         mop = self.moc.add(1237, 'module', 12, range(20), name='named')
         self.assertEqual("module(1237 12B 20refs 'named')", repr(mop))
-        mop = self.moc.add(1238, 'foo', 12, [10], referrer_list=[20, 30])
+        mop = self.moc.add(1238, 'foo', 12, [10], parent_list=[20, 30])
         self.assertEqual("foo(1238 12B 1refs 2par)", repr(mop))
         mop = self.moc.add(1239, 'str', 24, value='teststr')
         self.assertEqual("str(1239 24B 'teststr')", repr(mop))



More information about the bazaar-commits mailing list