On Wed, May 23, 2018 at 10:03:45PM -0600, Simon Glass wrote: > Add a method to call fdt_set_name(). > > Signed-off-by: Simon Glass <sjg@xxxxxxxxxxxx> Node names are C strings, which can't encode everything that Python strings can (embedded \0 in particular). So you should verify that the Python string will be valid in C before passing it through. > --- > > pylibfdt/libfdt.i | 15 +++++++++++++++ > tests/pylibfdt_tests.py | 7 +++++++ > 2 files changed, 22 insertions(+) > > diff --git a/pylibfdt/libfdt.i b/pylibfdt/libfdt.i > index 5ecddba..cf4ed93 100644 > --- a/pylibfdt/libfdt.i > +++ b/pylibfdt/libfdt.i > @@ -545,6 +545,21 @@ class Fdt: > """ > return check_err(fdt_parent_offset(self._fdt, nodeoffset), quiet) > > + def set_name(self, nodeoffset, name, quiet=()): > + """Set the name of a node > + > + Args: > + nodeoffset: Node offset of node to update > + name: New node name > + > + Returns: > + Error code, or 0 if OK > + > + Raises: > + FdtException if no parent found or other error occurs > + """ > + return check_err(fdt_set_name(self._fdt, nodeoffset, name), quiet) > + > def setprop(self, nodeoffset, prop_name, val, quiet=()): > """Set the value of a property > > diff --git a/tests/pylibfdt_tests.py b/tests/pylibfdt_tests.py > index a6d9430..57eedcb 100644 > --- a/tests/pylibfdt_tests.py > +++ b/tests/pylibfdt_tests.py > @@ -450,6 +450,13 @@ class PyLibfdtTests(unittest.TestCase): > self.assertEquals(TEST_STRING_2, > self.fdt.getprop_obj(node, prop).as_str()) > > + def testSetName(self): > + """Test that we can update a node name""" > + node = self.fdt.path_offset('/subnode@1') > + old_val = self.fdt.get_name(node) > + self.fdt.set_name(node, 'test') > + self.assertEquals('test', self.fdt.get_name(node)) > + > > if __name__ == "__main__": > unittest.main() -- 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