Module Name: src Committed By: riastradh Date: Sun Mar 30 00:07:52 UTC 2025
Modified Files: src/lib/libc/gen: ctype_.c ctype_guard.h tolower_.c toupper_.c Log Message: ctype(3): Simplify definitions of ctype/tolower/toupper tables. Clarify comment while here. No functional change intended. No change to `readelf -a' output on amd64 or aarch64. PR lib/58208: ctype(3) provides poor runtime feedback of abuse To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/lib/libc/gen/ctype_.c cvs rdiff -u -r1.2 -r1.3 src/lib/libc/gen/ctype_guard.h cvs rdiff -u -r1.16 -r1.17 src/lib/libc/gen/tolower_.c \ src/lib/libc/gen/toupper_.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libc/gen/ctype_.c diff -u src/lib/libc/gen/ctype_.c:1.22 src/lib/libc/gen/ctype_.c:1.23 --- src/lib/libc/gen/ctype_.c:1.22 Sat Mar 29 20:57:58 2025 +++ src/lib/libc/gen/ctype_.c Sun Mar 30 00:07:51 2025 @@ -1,4 +1,4 @@ -/* $NetBSD: ctype_.c,v 1.22 2025/03/29 20:57:58 riastradh Exp $ */ +/* $NetBSD: ctype_.c,v 1.23 2025/03/30 00:07:51 riastradh Exp $ */ /* * Copyright (c) 1989 The Regents of the University of California. @@ -39,7 +39,7 @@ #if 0 /*static char *sccsid = "from: @(#)ctype_.c 5.6 (Berkeley) 6/1/90";*/ #else -__RCSID("$NetBSD: ctype_.c,v 1.22 2025/03/29 20:57:58 riastradh Exp $"); +__RCSID("$NetBSD: ctype_.c,v 1.23 2025/03/30 00:07:51 riastradh Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -65,7 +65,6 @@ __RCSID("$NetBSD: ctype_.c,v 1.22 2025/0 #define _B _COMPAT_B #define _N _COMPAT_N -__ctype_table_guarded(_C_compat_bsdctype, _C_compat_bsdctype_guarded); __ctype_table static const unsigned char _C_compat_bsdctype_guarded[_C_COMPAT_BSDCTYPE_GUARD + @@ -88,8 +87,8 @@ const unsigned char _C_compat_bsdctype_g _L, _L, _L, _L, _L, _L, _L, _L, _L, _L, _L, _P, _P, _P, _P, _C }; -__ctype_table_size(_C_compat_bsdctype, _C_compat_bsdctype_guarded, - 1 + _CTYPE_NUM_CHARS, /*sizeof(char)*/1); +__ctype_table_guarded(_C_compat_bsdctype, _C_compat_bsdctype_guarded, + 1 + _CTYPE_NUM_CHARS, /*sizeof(unsigned char)*/1); #undef _C #undef _S @@ -119,7 +118,6 @@ const unsigned char *_ctype_ = &_C_compa #define _U _CTYPE_U #define _X _CTYPE_X -__ctype_table_guarded(_C_ctype_tab_, _C_ctype_tab_guarded_); __ctype_table static const unsigned short _C_ctype_tab_guarded_[_C_CTYPE_TAB_GUARD + 1 + _CTYPE_NUM_CHARS] = { @@ -157,7 +155,7 @@ static const unsigned short _C_ctype_tab _A|_G|_L|_R, _A|_G|_L|_R, _A|_G|_L|_R, _G|_R|_P, _G|_R|_P, _G|_R|_P, _G|_R|_P, _C, }; -__ctype_table_size(_C_ctype_tab_, _C_ctype_tab_guarded_, +__ctype_table_guarded(_C_ctype_tab_, _C_ctype_tab_guarded_, 1 + _CTYPE_NUM_CHARS, __SIZEOF_SHORT__); #undef _A Index: src/lib/libc/gen/ctype_guard.h diff -u src/lib/libc/gen/ctype_guard.h:1.2 src/lib/libc/gen/ctype_guard.h:1.3 --- src/lib/libc/gen/ctype_guard.h:1.2 Sat Mar 29 20:57:58 2025 +++ src/lib/libc/gen/ctype_guard.h Sun Mar 30 00:07:51 2025 @@ -1,4 +1,4 @@ -/* $NetBSD: ctype_guard.h,v 1.2 2025/03/29 20:57:58 riastradh Exp $ */ +/* $NetBSD: ctype_guard.h,v 1.3 2025/03/30 00:07:51 riastradh Exp $ */ /*- * Copyright (c) 2025 The NetBSD Foundation, Inc. @@ -138,11 +138,12 @@ enum { }; # define __ctype_table __aligned(_CTYPE_GUARD_SIZE) -# define __ctype_table_guarded(name, guard) \ +# define __ctype_table_guarded(name, guard, nelem, elemsize) \ __ctype_table_object(name); \ __asm(".global " _C_LABEL_STRING(#name)); \ __asm(_C_LABEL_STRING(#name) " = " _C_LABEL_STRING(#guard) " + " \ - ___STRING(_CTYPE_GUARD_SIZE)) + ___STRING(_CTYPE_GUARD_SIZE)); \ + __ctype_table_size(name, guard, nelem, elemsize) #else /* !_CTYPE_GUARD_PAGE */ @@ -159,9 +160,10 @@ enum { /* Compiler can't see into __strong_alias, so mark it __used. */ # define __ctype_table __used -# define __ctype_table_guarded(name, guard) \ +# define __ctype_table_guarded(name, guard, nelem, elemsize) \ __ctype_table_object(name); \ - __strong_alias(name, guard) + __strong_alias(name, guard); \ + __ctype_table_size(name, guard, nelem, elemsize) #endif /* _CTYPE_GUARD_PAGE */ Index: src/lib/libc/gen/tolower_.c diff -u src/lib/libc/gen/tolower_.c:1.16 src/lib/libc/gen/tolower_.c:1.17 --- src/lib/libc/gen/tolower_.c:1.16 Sat Mar 29 20:57:58 2025 +++ src/lib/libc/gen/tolower_.c Sun Mar 30 00:07:51 2025 @@ -1,4 +1,4 @@ -/* $NetBSD: tolower_.c,v 1.16 2025/03/29 20:57:58 riastradh Exp $ */ +/* $NetBSD: tolower_.c,v 1.17 2025/03/30 00:07:51 riastradh Exp $ */ /* * Written by J.T. Conklin <j...@netbsd.org>. @@ -7,7 +7,7 @@ #include <sys/cdefs.h> #if defined(LIBC_RCS) && !defined(lint) -__RCSID("$NetBSD: tolower_.c,v 1.16 2025/03/29 20:57:58 riastradh Exp $"); +__RCSID("$NetBSD: tolower_.c,v 1.17 2025/03/30 00:07:51 riastradh Exp $"); #endif /* LIBC_RCS and not lint */ #include <sys/ctype_bits.h> @@ -22,7 +22,6 @@ __RCSID("$NetBSD: tolower_.c,v 1.16 2025 #error "EOF != -1" #endif -__ctype_table_guarded(_C_tolower_tab_, _C_tolower_tab_guarded_); __ctype_table static const short _C_tolower_tab_guarded_[_C_TOLOWER_TAB_GUARD + 1 + _CTYPE_NUM_CHARS] = { @@ -60,7 +59,7 @@ static const short _C_tolower_tab_guarde 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff }; -__ctype_table_size(_C_tolower_tab_, _C_tolower_tab_guarded_, +__ctype_table_guarded(_C_tolower_tab_, _C_tolower_tab_guarded_, 1 + _CTYPE_NUM_CHARS, __SIZEOF_SHORT__); #ifdef __BUILD_LEGACY Index: src/lib/libc/gen/toupper_.c diff -u src/lib/libc/gen/toupper_.c:1.16 src/lib/libc/gen/toupper_.c:1.17 --- src/lib/libc/gen/toupper_.c:1.16 Sat Mar 29 20:57:58 2025 +++ src/lib/libc/gen/toupper_.c Sun Mar 30 00:07:51 2025 @@ -1,4 +1,4 @@ -/* $NetBSD: toupper_.c,v 1.16 2025/03/29 20:57:58 riastradh Exp $ */ +/* $NetBSD: toupper_.c,v 1.17 2025/03/30 00:07:51 riastradh Exp $ */ /* * Written by J.T. Conklin <j...@netbsd.org>. @@ -7,7 +7,7 @@ #include <sys/cdefs.h> #if defined(LIBC_RCS) && !defined(lint) -__RCSID("$NetBSD: toupper_.c,v 1.16 2025/03/29 20:57:58 riastradh Exp $"); +__RCSID("$NetBSD: toupper_.c,v 1.17 2025/03/30 00:07:51 riastradh Exp $"); #endif /* LIBC_RCS and not lint */ #include <sys/ctype_bits.h> @@ -22,7 +22,6 @@ __RCSID("$NetBSD: toupper_.c,v 1.16 2025 #error "EOF != -1" #endif -__ctype_table_guarded(_C_toupper_tab_, _C_toupper_tab_guarded_); __ctype_table static const short _C_toupper_tab_guarded_[_C_TOUPPER_TAB_GUARD + 1 + _CTYPE_NUM_CHARS] = { @@ -60,7 +59,7 @@ static const short _C_toupper_tab_guarde 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff }; -__ctype_table_size(_C_toupper_tab_, _C_toupper_tab_guarded_, +__ctype_table_guarded(_C_toupper_tab_, _C_toupper_tab_guarded_, 1 + _CTYPE_NUM_CHARS, __SIZEOF_SHORT__); #ifdef __BUILD_LEGACY