Subject: Re: getdirentries(2): argument doesn't match
To: None <itojun@iijlab.net>
From: Andrew Brown <atatat@atatdot.net>
List: tech-kern
Date: 10/03/2002 01:28:01
>>>	it seems that signedness of getdirentries(2) does not meet up with
>>>	document.  does it make sense?  found by checking openbsd commit log.
>>istm that by using a u_int instead of an int (they are both always the
>>same size, right?) you can eliminate the two tests you have to add if
>>you make it an int.
>>less code to debug, audit, etc...
>
>	in some portion system call argument type matches documentation (int),
>	and checks are made using typecast to u_int (by typecasting negative
>	number check is omitted).

right.  there's less code this way (both lines of c and bytes of
assembly).

>	in some portion system call argument type differs from documentation
>	(u_int), and checks are omitted for negative numbers.

but...since the size of an int is always the same as the size of a
u_int, the api/abi isn't affected by the internal handling of the
argument, and the kernel gets to contain less code

>	in some portion system call argument type matches documentation,
>	and explicit checks are made - if (x < 0 || x >= MAX) return EINVAL;

that's almost a waste.  it's certainly more c code, but the "x < 0"
seems to get optimized out of the object code at -O1 or above.  the
only impact there is in terms of stuff we (and the compiler) have to
look at.  not the processor.

>	i want to see some consistency.

i'm guessing that more people are interested in efficiency when you're
looking at this tiny scale.

-- 
|-----< "CODE WARRIOR" >-----|
codewarrior@daemon.org             * "ah!  i see you have the internet
twofsonet@graffiti.com (Andrew Brown)                that goes *ping*!"
werdna@squooshy.com       * "information is power -- share the wealth."