Rev 135: Use the term 'child_list' when referring to the MemObject. in http://bazaar.launchpad.net/~meliae-dev/meliae/trunk
John Arbash Meinel
john at arbash-meinel.com
Fri Jan 8 22:51:45 GMT 2010
At http://bazaar.launchpad.net/~meliae-dev/meliae/trunk
------------------------------------------------------------
revno: 135
revision-id: john at arbash-meinel.com-20100108225133-yb2mzjetrfrwsrtv
parent: john at arbash-meinel.com-20100108224128-u6fl61uuakvoebzc
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: trunk
timestamp: Fri 2010-01-08 16:51:33 -0600
message:
Use the term 'child_list' when referring to the MemObject.
Add .c and .p helpers to make it eaiser to navigate the object graph.
-------------- next part --------------
=== modified file 'meliae/_loader.pyx'
--- a/meliae/_loader.pyx 2010-01-08 22:41:28 +0000
+++ b/meliae/_loader.pyx 2010-01-08 22:51:33 +0000
@@ -165,7 +165,7 @@
PyObject *type_str
# Consider making this unsigned long
long size
- RefList *children
+ RefList *child_list
# Removed for now, since it hasn't proven useful
# int length
PyObject *value
@@ -196,7 +196,7 @@
new_entry.type_str = <PyObject *>type_str
Py_INCREF(new_entry.type_str)
new_entry.size = size
- new_entry.children = _list_to_ref_list(children)
+ new_entry.child_list = _list_to_ref_list(children)
# TODO: Was found wanting and removed
# if length is None:
# new_entry.length = -1
@@ -226,8 +226,8 @@
cur.address = NULL
Py_XDECREF(cur.type_str)
cur.type_str = NULL
- _free_ref_list(cur.children)
- cur.children = NULL
+ _free_ref_list(cur.child_list)
+ cur.child_list = NULL
Py_XDECREF(cur.value)
cur.value = NULL
# Py_XDECREF(cur.name)
@@ -370,9 +370,9 @@
self._obj.total_size = value
def __len__(self):
- if self._obj.children == NULL:
+ if self._obj.child_list == NULL:
return 0
- return self._obj.children.size
+ return self._obj.child_list.size
property num_refs:
def __get__(self):
@@ -384,9 +384,9 @@
cdef long i
_set_default_ptr(cache, &self._obj.address)
_set_default_ptr(cache, &self._obj.type_str)
- if self._obj.children != NULL:
- for i from 0 <= i < self._obj.children.size:
- _set_default_ptr(cache, &self._obj.children.refs[i])
+ if self._obj.child_list != NULL:
+ for i from 0 <= i < self._obj.child_list.size:
+ _set_default_ptr(cache, &self._obj.child_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])
@@ -395,11 +395,11 @@
property children:
"""The list of objects referenced by this object."""
def __get__(self):
- return _ref_list_to_list(self._obj.children)
+ return _ref_list_to_list(self._obj.child_list)
def __set__(self, value):
- _free_ref_list(self._obj.children)
- self._obj.children = _list_to_ref_list(value)
+ _free_ref_list(self._obj.child_list)
+ self._obj.child_list = _list_to_ref_list(value)
property ref_list:
"""The list of objects referenced by this object.
@@ -462,13 +462,13 @@
def __getitem__(self, offset):
cdef long off
- if self._obj.children == NULL:
+ if self._obj.child_list == NULL:
raise IndexError('%s has no references' % (self,))
off = offset
- if off >= self._obj.children.size:
+ if off >= self._obj.child_list.size:
raise IndexError('%s has only %d (not %d) references'
- % (self, self._obj.children.size, offset))
- address = <object>self._obj.children.refs[off]
+ % (self, self._obj.child_list.size, offset))
+ address = <object>self._obj.child_list.refs[off]
try:
return self.collection[address]
except KeyError:
@@ -476,11 +476,43 @@
# 'no-such-object' proxy would be nicer than returning nothing
raise
+ property c:
+ """The list of children objects as objects (not references)."""
+ def __get__(self):
+ cdef long pos
+
+ result = []
+ if self._obj.child_list == NULL:
+ return result
+ for pos from 0 <= pos < self._obj.child_list.size:
+ address = <object>self._obj.child_list.refs[pos]
+ obj = self.collection[address]
+ result.append(obj)
+ return result
+
+ property p:
+ """The list of parent objects as objects (not references)."""
+ def __get__(self):
+ cdef long pos
+
+ result = []
+ if self._obj.parent_list == NULL:
+ return result
+ for pos from 0 <= pos < self._obj.parent_list.size:
+ address = <object>self._obj.parent_list.refs[pos]
+ try:
+ obj = self.collection[address]
+ except KeyError:
+ # We should probably create an "unknown object" type
+ raise
+ result.append(obj)
+ return result
+
def __repr__(self):
- if self._obj.children == NULL:
+ if self._obj.child_list == NULL:
refs = ''
else:
- refs = ' %drefs' % (self._obj.children.size,)
+ refs = ' %drefs' % (self._obj.child_list.size,)
if self._obj.parent_list == NULL:
parent_str = ''
else:
=== modified file 'meliae/tests/test__loader.py'
--- a/meliae/tests/test__loader.py 2010-01-08 22:41:28 +0000
+++ b/meliae/tests/test__loader.py 2010-01-08 22:51:33 +0000
@@ -284,6 +284,15 @@
self.assertEqual([87654321, 23456], mop.children)
self.assertEqual(2, len(mop))
+ def test_c(self):
+ mop = self.moc.add(1234567, 'type', 256, children=[0, 255])
+ mop0 = self.moc[0]
+ self.assertEqual([], mop0.c)
+ c = mop.c
+ self.assertEqual(2, len(c))
+ self.assertEqual(0, c[0].address)
+ self.assertEqual(255, c[1].address)
+
def test_ref_list(self):
# Deprecated
logged = []
@@ -348,6 +357,15 @@
self.assertEqual(1, mop255.num_parents)
self.assertEqual([1234567], mop255.parents)
+ def test_p(self):
+ mop = self.moc.add(1234567, 'type', 256, children=[0, 255])
+ mop0 = self.moc[0]
+ self.assertEqual([], mop0.p)
+ mop0.parents = [1234567]
+ p = mop0.p
+ self.assertEqual(1, len(p))
+ self.assertEqual(mop, p[0])
+
def test_referrers(self):
mop = self.moc.add(1234567, 'type', 256, children=[0, 255])
# Referrers is deprecated
More information about the bazaar-commits
mailing list