freemyipod r607 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r606‎ | r607 | r608 >
Date:17:23, 13 February 2011
Author:farthen
Status:new
Tags:
Comment:
emCORE tools/misc.py: Implement new remote_pointer object that can contain a pointer to a (remote) location and the data that is stored there.
Modified paths:
  • /emcore/trunk/tools/misc.py (modified) (history)

Diff [purge]

Index: emcore/trunk/tools/misc.py
@@ -120,6 +120,34 @@
121121 self.__dict__ = self
122122
123123
 124+class remote_pointer(dict):
 125+ """
 126+ This points to a (remote) location.
 127+ Otherwise it behaves like a Bunch.
 128+ The second argument must be a Bunch object
 129+ """
 130+ def __init__(self, address, bunch):
 131+ dict.__init__(self, bunch.__dict__)
 132+ self.__dict__ = self
 133+ self._address_ = address
 134+
 135+ def __getstate__(self):
 136+ return self
 137+
 138+ def __setstate__(self, state):
 139+ self.update(state)
 140+ self.__dict__ = self
 141+
 142+ def __str__(self):
 143+ return "<remote_pointer object with address 0x%X>" % (self._address_)
 144+
 145+ def __int__(self):
 146+ return self._address_
 147+
 148+ def __repr__(self):
 149+ return self.__str__()
 150+
 151+
124152 class c_enum(_SimpleCData):
125153 """
126154 Resembles the enum datatype from C with an 8 bit size.
@@ -226,6 +254,19 @@
227255 return string_at(addressof(self), sizeof(self))
228256
229257
 258+def getthread(address, threads):
 259+ """
 260+ Returns the thread at <address> from the list of threads <threads>.
 261+ Returns an empty thread if not found
 262+ """
 263+ for thread in threads:
 264+ if address == thread.addr:
 265+ return thread
 266+ thread = scheduler_thread()._to_bunch()
 267+ thread.name = "[Invalid Thread %08X]" % address
 268+ return thread
 269+
 270+
230271 def gethwname(id):
231272 try:
232273 from libemcoredata import hwtypes