devicetree-compiler.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
To: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
Cc: Devicetree Compiler
	<devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	Benjamin Bimmermann <b.bimmermann-LWAfsSFWpa4@public.gmane.org>,
	Ulrich Langenbach
	<ulrich.langenbach-srmvecZYGfHobmly5n/iKBvVK+yQ3ZXh@public.gmane.org>
Subject: Re: [PATCH v5 1/5] Add an initial Python library for libfdt
Date: Wed, 22 Feb 2017 12:15:07 +1100	[thread overview]
Message-ID: <20170222011507.GE12577@umbus.fritz.box> (raw)
In-Reply-To: <CAPnjgZ2hWsfm7PoNReLt7cAk=OiZBzwERFQnb-utF4fWMuUXgw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 5821 bytes --]

On Tue, Feb 21, 2017 at 11:07:58AM -0700, Simon Glass wrote:
> Hi David,
> 
> On 19 February 2017 at 20:37, David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org> wrote:
> > On Thu, Feb 16, 2017 at 09:48:22PM -0700, Simon Glass wrote:
> >> Hi David,
> >>
> >> On 14 February 2017 at 22:29, David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6iEOx6SR5NKn@public.gmane.orgu> wrote:
> >> > On Tue, Feb 14, 2017 at 08:51:56PM -0700, Simon Glass wrote:
> >> >> Add Python bindings for a bare-bones set of libfdt functions. These allow
> >> >> navigating the tree and reading node names and properties.
> >> >>
> >> >> Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
> >> >> ---
> >> >>
> >> >> Changes in v5:
> >> >> - Use a 'quiet' parameter instead of quiet versions of functions
> >> >> - Add a Property object to hold a property's name and value
> >> >> - Drop the data() and string() functions which are not needed now
> >> >> - Rename pylibfdt_copy_data() tp pylibfdt_copy_value()
> >> >> - Change order of libfdt.h inclusion to avoid #ifdef around libfdt macros
> >> >> - Drop fdt_offset_ptr() and fdt_getprop_namelen() from the swig interface
> >> >> - Use $(SWIG) to call swig from the Makefile
> >> >> - Review function comments
> >> >>
> >> >> Changes in v4:
> >> >> - Make the library less pythonic to avoid a shaky illusion
> >> >> - Drop classes for Node and Prop, along with associated methods
> >> >> - Include libfdt.h instead of repeating it
> >> >> - Add support for fdt_getprop()
> >> >> - Bring in all libfdt functions (but Python support is missing for many)
> >> >> - Add full comments for Python methods
> >> >>
> >> >> Changes in v3:
> >> >> - Make the library more pythonic
> >> >> - Add classes for Node and Prop along with methods
> >> >> - Add an exception class
> >> >> - Use Python to generate exeptions instead of SWIG
> >> >>
> >> >> Changes in v2:
> >> >> - Add exceptions when functions return an error
> >> >> - Correct Python naming to following PEP8
> >> >> - Use a class to encapsulate the various methods
> >> >> - Include fdt.h instead of redefining struct fdt_property
> >> >> - Use bytearray to avoid the SWIG warning 454
> >> >> - Add comments
> >> >>
> >> >>  Makefile                   |   1 +
> >> >>  pylibfdt/.gitignore        |   3 +
> >> >>  pylibfdt/Makefile.pylibfdt |  18 ++
> >> >>  pylibfdt/libfdt.swig       | 465 +++++++++++++++++++++++++++++++++++++++++++++
> >> >>  pylibfdt/setup.py          |  34 ++++
> >> >>  5 files changed, 521 insertions(+)
> >> >>  create mode 100644 pylibfdt/.gitignore
> >> >>  create mode 100644 pylibfdt/Makefile.pylibfdt
> >> >>  create mode 100644 pylibfdt/libfdt.swig
> >> >>  create mode 100644 pylibfdt/setup.py
> >> >>
> >>
> >> [..]
> >>
> >> >> +def check_err_null(val, quiet=[]):
> >> >> +    """Raise an error if the return value is NULL
> >> >> +
> >> >> +    This is used to check for a NULL return value from certain libfdt C
> >> >> +    functions
> >> >> +
> >> >> +    Args:
> >> >> +        val: Return value from a libfdt function
> >> >> +        quiet: Errors to ignore (empty to raise on all errors)
> >> >> +
> >> >> +    Returns:
> >> >> +        val if val is a list, None if not
> >> >> +
> >> >> +    Raises
> >> >> +        FdtException if val indicates an error was reported and the error
> >> >> +        is not in @quiet.
> >> >> +    """
> >> >> +    # Normally a tuple is returned which contains the data and its length.
> >> >
> >> > Is it a tuple returned..?
> >> >
> >> >> +    # If we get just an integer error code, it means the function failed.
> >> >> +    if not isinstance(val, list):
> >> >
> >> > ..or a list?  Seems like either the comment or the code must be
> >> > incorrect here.
> >>
> >> OK.
> >>
> >> >
> >> > Come to that, what is it tells swig to map fdt_propery_by_offset() and
> >> > the like to the pair of values?  How does it know how to detect the
> >> > error cases?
> >> >
> >> > From the usage, I take it that in the success case val[0] is a string
> >> > or bytearray containing the relevant chunk of data.  Remind me what
> >> > the second value is?
> >>
> >> It's the length, or error number. The final arg to
> >> fdt_get_property_by_offset() is int *len.
> >
> > Ok.  Why is it sometimes a tuple and sometimes a bare error value
> > then?  I would have expect it to always return a 2-tuple, the first
> > being the return value (maybe NULL/None) and the second being the
> > len/err value returned by reference.
> >
> > I guess that's a swig question rather than  question for you, though.
> 
> Well it's just the way that it seems to work. I think it makes some
> sense in that we don't want to return a NULL pointer into Python. But
> I agree it is a bit odd and it took me a while to get used to it.

I suppose so.  Although None seems a pretty obvious way to translate
the NULL as well.

> Here is the generated code. I'm not sure what SWIG_IsTmpObj() does exactly...
> 
>   result = (struct fdt_property *)fdt_get_property_by_offset((void
> const *)arg1,arg2,arg3);
>   resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result),
> SWIGTYPE_p_fdt_property, 0 |  0 );
>   if (SWIG_IsTmpObj(res3)) {
>     resultobj = SWIG_Python_AppendOutput(resultobj, SWIG_From_int((*arg3)));
>   } else {
>     int new_flags = SWIG_IsNewObj(res3) ? (SWIG_POINTER_OWN |  0 ) :  0 ;
>     resultobj = SWIG_Python_AppendOutput(resultobj,
> SWIG_NewPointerObj((void*)(arg3), SWIGTYPE_p_int, new_flags));
>   }

Thanks for the info.

-- 
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 #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  parent reply	other threads:[~2017-02-22  1:15 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-15  3:51 [PATCH v5 0/5] Introduce Python bindings for libfdt Simon Glass
     [not found] ` <20170215035200.29934-1-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2017-02-15  3:51   ` [PATCH v5 1/5] Add an initial Python library " Simon Glass
     [not found]     ` <20170215035200.29934-2-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2017-02-15  5:29       ` David Gibson
     [not found]         ` <20170215052942.GI12369-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2017-02-17  4:48           ` Simon Glass
     [not found]             ` <CAPnjgZ2SK-WRkeZwzjh+gA_zB0GiNFyVyer4zA_k9LUdXRV94Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-02-20  3:37               ` David Gibson
     [not found]                 ` <20170220033726.GN12644-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2017-02-21 18:07                   ` Simon Glass
     [not found]                     ` <CAPnjgZ2hWsfm7PoNReLt7cAk=OiZBzwERFQnb-utF4fWMuUXgw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-02-22  1:15                       ` David Gibson [this message]
2017-02-15  5:47       ` David Gibson
2017-02-15  3:51   ` [PATCH v5 2/5] Add tests for pylibfdt Simon Glass
     [not found]     ` <20170215035200.29934-3-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2017-02-15  5:44       ` David Gibson
     [not found]         ` <20170215054423.GJ12369-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2017-02-17  4:48           ` Simon Glass
     [not found]             ` <CAPnjgZ3wEUUEx6-XiKJ5kns-tA9HdKonXULdBYcXAkyEbHaztg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-02-20  3:42               ` David Gibson
2017-02-21 18:08                 ` Simon Glass
     [not found]                   ` <CAPnjgZ3CSwq7mG+fVdOjx2BSKZF1hK2UY4t6OCy_qYYAC-p42A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-02-22  2:11                     ` David Gibson
     [not found]                       ` <20170222021142.GF12577-K0bRW+63XPQe6aEkudXLsA@public.gmane.org>
2017-02-22  4:33                         ` Simon Glass
     [not found]                           ` <CAPnjgZ2v=oQTnYFEwucuCsUN1tQGx3zQfpHBZ1gRzpyZW8_g-g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-02-22  6:19                             ` David Gibson
2017-02-15  5:51       ` David Gibson
2017-02-15  3:51   ` [PATCH v5 3/5] Mention pylibfdt in the documentation Simon Glass
     [not found]     ` <20170215035200.29934-4-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2017-02-15  5:53       ` David Gibson
2017-02-15  3:51   ` [PATCH v5 4/5] Adjust libfdt.h to work with swig Simon Glass
2017-02-15  3:52   ` [PATCH v5 5/5] Build pylibfdt as part of the normal build process Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170222011507.GE12577@umbus.fritz.box \
    --to=david-xt8fgy+axnrb3ne2bgzf6laj5h9x9tb+@public.gmane.org \
    --cc=b.bimmermann-LWAfsSFWpa4@public.gmane.org \
    --cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
    --cc=ulrich.langenbach-srmvecZYGfHobmly5n/iKBvVK+yQ3ZXh@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).