Subject: Re: OpenFirmware, node numbers, handles etc.
To: Valeriy E.Ushakov <uwe@stderr.spb.ru>
From: Michael Lorenz <macallan@netbsd.org>
List: tech-kern
Date: 11/28/2007 12:17:01
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,

On Nov 28, 2007, at 11:28, Valeriy E. Ushakov wrote:

> On Wed, Nov 28, 2007 at 09:33:38 -0500, Michael Lorenz wrote:
>
>> On Nov 28, 2007, at 01:36, der Mouse wrote:
>>
>>>> is there a good reason why OF handles, node numbers etc. are
>>>> represented as int in our code?  As far as I can tell using a  
>>>> signed
>>>> type here only causes trouble since at least node numbers may well
>>>> have the upper bit set.
>>>
>>> Perhaps I'm missing something, but, what difference does it make if
>>> some of the values happen to be negative?  They're just opaque
>>> handles,
>>> right?
>>
>> People (including myself at times ) keep running into the trap of
>> checking node numbers for >0, which apparently works on some machines
>> ( not macs though ). Since there is no reason for node numbers and
>> handles to be signed as far as I can see I want to make them  
>> unsigned.
>
> OFW standard says that some client interface functions,
> e.g. finddevice or instance-to-package return (cell_t)-1 on error so
> an invalid handle is going to pass your > 0 test for an unsigned type.

As I said, testing for >0 is wrong and usually happens with just  
that, -1 as error, in mind.

> So you are just trading one set of signedness related problems for  
> another.

I want to keep people from thinking of handles as signed at all.  
Don't call it -1, call it 0xffffffff.

> The issue here is not signedness per se (unsigned type is more natural
> (whatever that means) for handles, I guess), it's how you use it.

Exactly.

have fun
Michael
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)

iQEVAwUBR02ijspnzkX8Yg2nAQJCqgf/cIWZng3uXT3kSC3cMcTfNStwWBvh7ZV7
iCUmiJUZ7MVnsar/HPWYH3CM6MbGS8OB2EXb1v1Zc+4ITsJy5TTl3BTGLjrT8A1G
EavAhzGYyzQ4ksuy67TV56rOjaGMjDzOJEYwDJMbnUWBZCaT9ywKzb8wkFS9qwur
Au4vj2nqB9X7IwiwIo8tLMOwv8TvZi4JxzSExOtY96QaO4+sc0Y2gVjQp57x1BeF
p0vLqCUKT+qdEtxh/bptA7r6IB7pOBCUvDsFtqx0IQN2CIi8dwR24a8AahvvCmLp
8PM4NZeEu3w3k2UhJBWlL5vD0VW4u0jGYVesem8Zs7Okp80Uuk3BgQ==
=A/8o
-----END PGP SIGNATURE-----