[PATCH] lib/tevent: remove spectacularly complicated manual subtraction

tridge at samba.org tridge at samba.org
Wed Aug 26 20:07:46 MDT 2009


Hi Rusty,

 > To be completely honest, I don't quite know whether to laugh or cry at
 > this one:

:-)

 >  static uint32_t sig_count(struct sigcounter s)
 >  {
 > -	if (s.count >= s.seen) {
 > -		return s.count - s.seen;
 > -	}
 > -	return 1 + (0xFFFFFFFF & ~(s.seen - s.count));
 > +	return s.count - s.seen;
 >  }

In Samba we have historically not assumed that uint32_t is exactly 32
bits, instead we have assumed it is at least 32 bits. The reason is
that we have in the past had a host in the build farm where the
compiler did not have a 32 bit integer (it had an 8 bit integer, then
the next size up was a 64 bit integer). That host (a Cray Unicos
machine) led to some pretty weird code.

Still, you are right that the above code is grossly silly.  It could
be:

  return 0xFFFFFFFF & (s.count - s.seen);

although these days I noticed we now refuse to compile on systems like
that Unicos one that don't have a 32 bit type, as we have this in
lib/replace:

if test $ac_cv_sizeof_int -eq 4 ; then
AC_CHECK_TYPE(int32_t, int)
AC_CHECK_TYPE(uint32_t, unsigned int)
elif test $ac_cv_size_long -eq 4 ; then
AC_CHECK_TYPE(int32_t, long)
AC_CHECK_TYPE(uint32_t, unsigned long)
else
AC_MSG_ERROR([LIBREPLACE no 32-bit type found])
fi

so in fact your patch would be fine with current lib/replace :-)

Cheers, Tridge


More information about the samba-technical mailing list