On Thu, Aug 31, 2017 at 04:41:59AM -0600, Simon Glass wrote: > When calling libfdt functions which are not supported by the Fdt class it > is necessary to get direct access to the device tree data. At present this > requries using the internal _fdt member. Add a new method to provide > public access to this. > > Signed-off-by: Simon Glass <sjg@xxxxxxxxxxxx> Sorry I've taken so long to look at this. I don't think this actually has much value. You're directly returning _fdt, which is a mutable object. Anything bad you can do to the object by accessing _fdt directly you can do just as badly via this method. Which makes this an abstraction that doesn't abstract, and an interface that doesn't actually protect anything, even notionally. If you want things from outside to be able to access the raw blob, I suggest you just remove the underscore and make .fdt an advertised, accessible attribute of the object. > --- > > Changes in v2: > - Change from get_fdt() to as_bytearray() > > pylibfdt/libfdt.i | 11 +++++++++++ > tests/pylibfdt_tests.py | 5 +++-- > 2 files changed, 14 insertions(+), 2 deletions(-) > > diff --git a/pylibfdt/libfdt.i b/pylibfdt/libfdt.i > index 415820d..f8e3a2c 100644 > --- a/pylibfdt/libfdt.i > +++ b/pylibfdt/libfdt.i > @@ -174,6 +174,17 @@ class Fdt: > self._fdt = bytearray(data) > check_err(fdt_check_header(self._fdt)); > > + def as_bytearray(self): > + """Get the device tree contents as a bytearray > + > + This can be passed directly to libfdt functions that access a > + const void * for the device tree. > + > + Returns: > + bytearray containing the device tree > + """ > + return self._fdt > + > def subnode_offset(self, parentoffset, name, quiet=()): > """Get the offset of a named subnode > > diff --git a/tests/pylibfdt_tests.py b/tests/pylibfdt_tests.py > index 95d911a..0ec0f38 100644 > --- a/tests/pylibfdt_tests.py > +++ b/tests/pylibfdt_tests.py > @@ -297,9 +297,10 @@ class PyLibfdtTests(unittest.TestCase): > > def testIntegers(self): > """Check that integers can be passed and returned""" > - self.assertEquals(0, libfdt.fdt_get_phandle(self.fdt._fdt, 0)) > + self.assertEquals(0, libfdt.fdt_get_phandle(self.fdt.as_bytearray(), 0)) > node2 = self.fdt.path_offset('/subnode@2') > - self.assertEquals(0x2000, libfdt.fdt_get_phandle(self.fdt._fdt, node2)) > + self.assertEquals( > + 0x2000, libfdt.fdt_get_phandle(self.fdt.as_bytearray(), node2)) > > def testGetPhandle(self): > """Test for the get_phandle() method""" -- David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Attachment:
signature.asc
Description: PGP signature