From: Klemens Nanni Subject: Re: kernel: more compile-time initializers To: Miod Vallat , tech@openbsd.org Date: Mon, 02 Nov 2026 19:12:17 +0000 02.11.2026 21:35, Miod Vallat пишет: > In the early years of , there were no compile-time > initializer macros, so there had to be WHATEVER_INIT() calls at runtime. > > The WHATEVER_INITIALIZER macros for compile-time initialization have > been introduced in 1996, but code which was written before had not > necessarily been updated. > > The mostly mechanical diff below uses compile-time initializer for > global variables, allowing a few routines to be removed as a result. Nice, all those - sure read OK to me. Not compile-tested, but I didn't find any mismatch between old and new initialisers. > Index: sys/kern/tty.c > =================================================================== > RCS file: /OpenBSD/src/sys/kern/tty.c,v > diff -u -p -r1.186 tty.c > --- sys/kern/tty.c 19 Aug 2026 22:56:24 -0000 1.186 > +++ sys/kern/tty.c 2 Nov 2026 16:23:17 -0000 > @@ -166,8 +166,8 @@ u_char const char_type[] = { > #define tolower(c) ((c) - 'A' + 'a') > #define toupper(c) ((c) - 'a' + 'A') > > -struct ttylist_head ttylist; /* TAILQ_HEAD */ > -int tty_count; > +struct ttylist_head ttylist = TAILQ_HEAD_INITIALIZER(ttylist); > +int tty_count = 0; > struct rwlock ttylist_lock = RWLOCK_INITIALIZER("ttylist"); > > int64_t tk_cancc, tk_nin, tk_nout, tk_rawcc; > @@ -2327,17 +2327,6 @@ ttysleep_nsec(struct tty *tp, void *chan > if ((error = tsleep_nsec(chan, pri, wmesg, nsecs)) != 0) > return (error); > return (tp->t_gen == gen ? 0 : ERESTART); > -} > - > -/* > - * Initialise the global tty list. > - */ > -void > -tty_init(void) > -{ > - > - TAILQ_INIT(&ttylist); > - tty_count = 0; > } > > /* I'd even omit the few = 0 you added to global int decls, but explicitly initialising them to do the exact same those init functions did is fine, too.