[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: commit: ldap/servers/slapd/back-ldbm attr.c



Pierangelo Masarati writes:
> #if SAFE
> #define PTRCMP(x,y) ((x) - (y))
> #else
> #define PTRCMP(x,y) ((x) > (y) ? 1 : ((x) < (y) ? -1 : 0)

  #define PTRCMP(x,y) ((x) < (y) ? -1 : (x) > (y))

is slightly briefer and might give shorter code.

> #endif
> 
> where SAFE is: ptrdiff_t is:
>   - declared

OK,

>   - large enough to contain +/- the space addressable
>     by our pointers

How do you test that?  Keep malloc()ing until it fails, and compare the
resulting pointers as well as some pointers to static memory?

>   - its cast to int (since AVL cmp funcs return int)
>     doesn't lose the sign bit

How do you test that?  Remember that integers may have padding bits, so
you can't just test sizeof(int) and sizeof(ptrdiff_t).  Do we simply
assume that an implementation is not so crazy as to have the same size
of the two, but padding bits in int and not in ptrdiff_t?

> Of course, we may simply stay with !SAFE;
> we'd basically waste one comparison ...

That has my vote.  Unless profiling shows that these functions are
called frequently enough to take some time, which I doubt.  But if you
wish, go ahead.  For profiling, you might use

int PTRCMP(const void *x, const void *y)
{
    return x < y ? -1 : x > y;
}

-- 
Hallvard