Re: [PATCH 02/10] pylibfdt: Add support for fdt_next_node()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



On Wed, May 23, 2018 at 10:03:38PM -0600, Simon Glass wrote:
> This function requires a bit of typemap effort to get the depth parameter
> to work correctly. Add support for it, along with a test.
> 
> Signed-off-by: Simon Glass <sjg@xxxxxxxxxxxx>
> ---
> 
>  pylibfdt/libfdt.i       | 31 +++++++++++++++++++++++++++++++
>  tests/pylibfdt_tests.py | 18 ++++++++++++++++++
>  2 files changed, 49 insertions(+)
> 
> diff --git a/pylibfdt/libfdt.i b/pylibfdt/libfdt.i
> index 17e09d7..dd924b0 100644
> --- a/pylibfdt/libfdt.i
> +++ b/pylibfdt/libfdt.i
> @@ -186,6 +186,23 @@ class Fdt:
>          """
>          return bytearray(self._fdt)
>  
> +    def next_node(self, nodeoffset, depth, quiet=()):
> +        """Find the next subnode
> +
> +        Args:
> +            nodeoffset: Node offset of previous node
> +            depth: On input, the depth of the node at nodeoffset. On output, the
> +               depth of the returned node

On output doesn't really mean anything here, since an immutable
integer object is being passed it.

> +            quiet: Errors to ignore (empty to raise on all errors)
> +
> +        Returns:
> +            The offset of the next node, if any

The docs here don't seem to match the example below.  Doesn't it
actually return an (offset, depth) tuple?

> +
> +        Raises:
> +            FdtException if no more nodes found or other error occurs
> +        """
> +        return check_err(fdt_next_node(self._fdt, nodeoffset, depth), quiet)
> +
>      def first_subnode(self, nodeoffset, quiet=()):
>          """Find the first subnode of a parent node
>  
> @@ -501,6 +518,7 @@ typedef int fdt32_t;
>          fdt = fdt; /* avoid unused variable warning */
>  }
>  
> +/* typemap used for fdt_get_property_by_offset() */
>  %typemap(out) (struct fdt_property *) {
>  	PyObject *buff;
>  
> @@ -523,6 +541,19 @@ typedef int fdt32_t;
>  		$result = Py_BuildValue("s#", $1, *arg4);
>  }
>  
> +/* typemaps used for fdt_next_node() */
> +%typemap(in, numinputs=1) int *depth (int depth) {
> +   depth = (int) PyInt_AsLong($input);
> +   $1 = &depth;
> +}
> +
> +%typemap(argout) int *depth {
> +        PyObject *val = Py_BuildValue("i", *arg$argnum);
> +        resultobj = SWIG_Python_AppendOutput(resultobj, val);
> +}
> +
> +%apply int *depth { int *depth };
> +
>  /* We have both struct fdt_property and a function fdt_property() */
>  %warnfilter(302) fdt_property;
>  
> diff --git a/tests/pylibfdt_tests.py b/tests/pylibfdt_tests.py
> index cfa3784..b4efcea 100644
> --- a/tests/pylibfdt_tests.py
> +++ b/tests/pylibfdt_tests.py
> @@ -221,6 +221,24 @@ class PyLibfdtTests(unittest.TestCase):
>          self.assertEquals(libfdt.strerror(-libfdt.NOTFOUND),
>                            'FDT_ERR_NOTFOUND')
>  
> +    def testNextNodeOffset(self):
> +        """Check that we can walk through nodes"""
> +        node_list = []
> +        node = 0
> +        depth = 0
> +        while depth >= 0:
> +            node_list.append([depth, self.fdt.get_name(node)])
> +            node, depth = self.fdt.next_node(node, depth, (libfdt.BADOFFSET,))
> +        self.assertEquals(node_list, [
> +            [0, ''],
> +            [1, 'subnode@1'],
> +            [2, 'subsubnode'],
> +            [2, 'ss1'],
> +            [1, 'subnode@2'],
> +            [2, 'subsubnode@0'],
> +            [2, 'ss2'],
> +            ])
> +
>      def testFirstNextSubnodeOffset(self):
>          """Check that we can walk through subnodes"""
>          node_list = []

-- 
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


[Index of Archives]     [Device Tree]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux