Re: SET, CLR, ISSET in types.h for _KERNEL builds



On Wed, 28 Jun 2006, Poul-Henning Kamp wrote:

In message <20060628094221.GA50978@xxxxxxxxxxxxxxxx>, Yar Tikhiy writes:
On Tue, Jun 27, 2006 at 01:58:17PM -0600, M. Warner Losh wrote:

NetBSD recently added SET, CLR, ISSET to sys/types.h (only if _KERNEL
is defined).

I see no types here.

As one of the people who have worked with the original /bin/sh source
code, I have a slight alergic reaction to attempts to paste over
the implementation language with macros like these.

Setting a bit in 'C' is spelled
variable |= bit;
not
SET(variable, bit);

Only slightly?

In FreeBSD, these mistakes were only in kern/tty.c and in some usb
files obtained from NetBSD and related to tty.c. In tty.c, they appear
to be just to avoid adding a USL copyright. (tty.c was obfuscated
between FreeBSD-1 and FreeBSD-2 by globally substituting "variable |=
BIT" by "SET(variable, BIT)", etc.) I noticed that NetBSD started
using these macros elsewhere many years ago. However, their use was
still relatively limited in NetBSD a year ago (in kern, they were only
in kern-fork.c (1), kern_subr.c (2), kern_systrace.c (many), sys_process.c
(a few), tty.c (many), tty_pty.c (many), vfs_bio.c (many) and vfs_lookup.c
(1); 211 lines altogether vs 1565 lines matching ' & ' and 27 lines
matching the style bug '[A-Za-z]&[A-Za-z]'). It must have been in
tty_pty.c that I noticed them many years ago.

Higher order macros like roundup(), ispow2() are fine with me,
because they implement something on top of the language and make
the source code more compact and thus faster to read.

But all of the three proposed macros take up more space than
the native language they obfuscate, what is the sense in that ?

They might be to hide the implementation of a set of flags as a bitmap,
but they don't even do that.

Another problem with these macros is that a bitmap is more useful than
a set of flags, but a much larger and uglier set of macros would be
needed to give enough operations on bitmaps, and code that has been
blindly translated from an integer-bitmap operation still assumes that
the implementation is an integer-bitmap. E.g., in tty.c:

%%%
/*
* delayed suspend (^Y)
*/
if (CCEQ(cc[VDSUSP], c) &&
ISSET(lflag, IEXTEN | ISIG) == (IEXTEN | ISIG)) {
%%%

Bruce
_______________________________________________
freebsd-arch@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-arch
To unsubscribe, send any mail to "freebsd-arch-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • Re: macro for shorter array syntax
    ... How is OCaml on adding readmacros, which Lisp can do easily. ... I would not ask that of a parsed language. ... We're confident that using macros is useful to us, ... debate has legitimate points on both sides. ...
    (comp.lang.lisp)
  • Re: The War On HLA
    ... If you're assuming that macros' only purpose is for "in-line" functions, ... languages demonstrate the ability of using macros to extend the language. ... I would ask why you're using Delphi in the first place. ... programming language (i.e., you can assign them to variables, ...
    (alt.lang.asm)
  • Re: LSE64 in standard Forth
    ... The cost of an additional add verses the cost of: ... language and the benefits and pitfalls of that language. ... LSE64 forces a lot more naming of things than Standard Forth, a thing I consider positive, but some in the group have criticized. ... The problem I have with macros is one well known in the C community: while a macro names a concept, it does not automatically provide a clean interface. ...
    (comp.lang.forth)
  • Re: Hey, what is all this off topic posting?
    ... >>> that's all you're using macros for, I can see why you don't much like ASM. ... > PL/I language constructs though. ... >> write the macros using some arcane assembler to do that on a new ...
    (sci.electronics.design)
  • Re: Python syntax in Lisp and Scheme
    ... >>expressive power because you believe it will be misused. ... people programming languages, both on the job and as a University ... that, Macros are just one. ... number of lines of code per year regardless of the language they write ...
    (comp.lang.python)