Re: [PATCH v2 03/10] pylibfdt: Add support for the rest of the header functions

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



Hi David,

On 8 June 2018 at 04:27, David Gibson <david@xxxxxxxxxxxxxxxxxxxxx> wrote:
> On Wed, Jun 06, 2018 at 03:37:02PM -0600, Simon Glass wrote:
>> Export all of these through Python.
>>
>> Signed-off-by: Simon Glass <sjg@xxxxxxxxxxxx>
>> ---
>>
>> Changes in v2:
>> - Drop use of check_err() since these functions cannot fail
>> - Update existing header functions to also drop check_err()
>>
>>  pylibfdt/libfdt.i       | 71 +++++++++++++++++++++++++++++++++++++++--
>>  tests/pylibfdt_tests.py |  8 +++++
>>  2 files changed, 76 insertions(+), 3 deletions(-)
>>
>> diff --git a/pylibfdt/libfdt.i b/pylibfdt/libfdt.i
>> index 94c3d00..f33e2ab 100644
>> --- a/pylibfdt/libfdt.i
>> +++ b/pylibfdt/libfdt.i
>> @@ -252,21 +252,86 @@ class Fdt:
>>          """
>>          return check_err(fdt_next_subnode(self._fdt, nodeoffset), quiet)
>>
>> +    def magic(self):
>> +        """Return the magic word from the header
>> +
>> +        Returns:
>> +            Magic word
>> +        """
>> +        # Use a mask to ensure that this does not return a -ve number
>> +        return fdt_magic(self._fdt) & 0xffffffff
>
> You still have the mask here for no clear reason.

Python's numbers are a little strange. If the top bit of a 32-bit
number is set, this means it is a negative number in two-complement
arithmetic, as you know. Python will then use a negative value instead
of positive. To force it to regard the number as unsigned, we must
mask it. This is how I have learned to do it in Python, but maybe
there is a better way?

To see the impact, try removing the mask. You will see that magic()
will return a -ve number, rather than unsigned.

Regards,
Simon
--
To unsubscribe from this list: send the line "unsubscribe devicetree-compiler" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[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