[Mono-devel-list] problems with Syscall.syslog

Jonathan Pryor jonpryor at vt.edu
Wed Jun 29 08:13:09 EDT 2005

On Tue, 2005-06-28 at 16:18 +0400, Vorobiev Maksim wrote:
> Good day.
> But it still has a problem in map.c for function int
> Mono_Posix_FromSyslogFacility (int x, int *r).
> It checks for constants via &-mask: search for first occurrence. The
> next code:
> if ((x & Mono_Posix_SyslogFacility_LOG_USRE) ==
> Mono_Posix_SyslogFacility_LOG_USRE)
> #ifdef LOG_USRE
> 		*r |= LOG_USRE;
> #else /* def LOG_USRE */
> 		{errno = EINVAL; return -1;}
> will be TRUE for all constants, which ends with "8"
> (Mono_Posix_SyslogFacility_LOG_DAEMON and so on - "even ones").

Obviously I need to be in less of a hurry. :-)

I also need to read these constants better -- I originally thought that
all the shifting would prevent collisions, and that SyslogFacility was
obviously a [Flags] enum, but the shifts are really to prevent
collisions with SyslogOptions.  I should have read the constants better.

> Here
> should be another way for testing. BTW, why to look throght all possible
> constants? Since these are not flags, where could be only one possible
> value. So, function should return after first found. And IMHO test
> should be performed like this:
> if ((x & Mono_Posix_SyslogFacility_ALL) ==
> Mono_Posix_SyslogFacility_LOG_USRE)
> #ifdef LOG_USRE
> 		{*r = LOG_USRE;return 0;}
> #else /* def LOG_USRE */
> 		{errno = EINVAL; return -1;}
> Where Mono_Posix_SyslogFacility_ALL = Mono_Posix_SyslogFacility_LOG_KERN
> | Mono_Posix_SyslogFacility_LOG_USRE | ....

The `(x & VAL) == VAL' pattern is only required for [Flags] enums.
Normal enums use the pattern `x == VAL' (see the generated code for the
Error and SyslogLevel enums), so the introduction of a _ALL value isn't
necessary, just the removal of [Flags].

Regardless, I've fixed the definition of SyslogFacility, and make-map
now ignores [Obsolete]ed enum values in r46718 and r46719.

 - Jon

More information about the Mono-devel-list mailing list