Page MenuHomeFreeBSD

Stop using non ctype.h versions of toupper()
AbandonedPublic

Authored by sbruno on May 6 2018, 4:25 PM.
Tags
None
Referenced Files
Unknown Object (File)
Jan 2 2024, 8:52 PM
Unknown Object (File)
Dec 31 2023, 9:20 PM
Unknown Object (File)
Nov 4 2023, 2:32 AM
Unknown Object (File)
Sep 4 2023, 1:49 AM
Unknown Object (File)
Jul 24 2023, 12:33 AM
Unknown Object (File)
Jun 21 2023, 10:16 PM
Unknown Object (File)
May 20 2023, 3:08 PM
Unknown Object (File)
May 3 2023, 9:43 AM
Subscribers

Details

Reviewers
allanjude
imp
Summary

There is already some variation in our version of the zfs lualibs that is specific to illumos. This change will shutup warnings about redefining toupper() and friends and use our standard definitions for these macros in ctype.h

https://github.com/illumos/illumos-gate/blob/master/usr/src/uts/common/fs/zfs/lua/lbaselib.c#L18

https://github.com/illumos/illumos-gate/blob/master/usr/src/uts/common/fs/zfs/lua/lstrlib.c#L32

Silences warnings such as:

cc -target x86_64-unknown-freebsd12.0 --sysroot=/var/tmp/home/sbruno/bsd/fbsd_head/amd64.amd64/tmp -B/var/tmp/home/sbruno/bsd/fbsd_head/amd64.amd64/tmp/usr/bin -fpic -DPIC  -O2 -pipe -I/home/sbruno/bsd/fbsd_head/sys/cddl/compat/opensolaris -I/home/sbruno/bsd/fbsd_head/cddl/compat/opensolaris/include -I/home/sbruno/bsd/fbsd_head/cddl/compat/opensolaris/lib/libumem -I/home/sbruno/bsd/fbsd_head/cddl/contrib/opensolaris/lib/libzpool/common -I/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/sys -I/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs -I/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua -I/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/common/zfs -I/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common -I/home/sbruno/bsd/fbsd_head/cddl/contrib/opensolaris/head -I/home/sbruno/bsd/fbsd_head/cddl/contrib/opensolaris/lib/libnvpair -I/home/sbruno/bsd/fbsd_head/cddl/contrib/opensolaris/lib/libcmdutils -DWANTS_MUTEX_OWNED -I/home/sbruno/bsd/fbsd_head/lib/libpthread/thread -I/home/sbruno/bsd/fbsd_head/lib/libpthread/sys -I/home/sbruno/bsd/fbsd_head/lib/libthr/arch/amd64/include -g -DDEBUG=1   -DNEED_SOLARIS_BOOLEAN -g -MD  -MF.depend.lstrlib.pico -MTlstrlib.pico -std=iso9899:1999 -fstack-protector-strong -Wno-pointer-sign -Wno-unknown-pragmas -Wno-empty-body -Wno-string-plus-int -Wno-unused-const-variable -Wno-tautological-compare -Wno-unused-value -Wno-parentheses-equality -Wno-unused-function -Wno-enum-conversion -Wno-unused-local-typedef -Wno-address-of-packed-member -Wno-switch -Wno-switch-enum -Wno-knr-promoted-parameter -Wno-parentheses  -Qunused-arguments  -c /home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lstrlib.c -o lstrlib.pico
/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lstrlib.c:115:12: warning: implicitly declaring library function 'tolower' with type 'int (int)' [-Wimplicit-function-declaration]
    p[i] = tolower(uchar(s[i]));
           ^
/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lstrlib.c:115:12: note: include the header <ctype.h> or explicitly provide a declaration for 'tolower'
/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lstrlib.c:128:12: warning: implicitly declaring library function 'toupper' with type 'int (int)' [-Wimplicit-function-declaration]
    p[i] = toupper(uchar(s[i]));
           ^
/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lstrlib.c:128:12: note: include the header <ctype.h> or explicitly provide a declaration for 'toupper'
/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lstrlib.c:298:22: warning: implicitly declaring library function 'isalpha' with type 'int (int)' [-Wimplicit-function-declaration]
    case 'a' : res = isalpha(c); break;
                     ^
/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lstrlib.c:298:22: note: include the header <ctype.h> or explicitly provide a declaration for 'isalpha'
/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lstrlib.c:300:22: warning: implicitly declaring library function 'isdigit' with type 'int (int)' [-Wimplicit-function-declaration]
    case 'd' : res = isdigit(c); break;
                     ^
/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lstrlib.c:300:22: note: include the header <ctype.h> or explicitly provide a declaration for 'isdigit'
/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lstrlib.c:302:22: warning: implicitly declaring library function 'islower' with type 'int (int)' [-Wimplicit-function-declaration]
    case 'l' : res = islower(c); break;
                     ^
/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lstrlib.c:302:22: note: include the header <ctype.h> or explicitly provide a declaration for 'islower'
/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lstrlib.c:304:22: warning: implicitly declaring library function 'isspace' with type 'int (int)' [-Wimplicit-function-declaration]
    case 's' : res = isspace(c); break;
                     ^
/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lstrlib.c:304:22: note: include the header <ctype.h> or explicitly provide a declaration for 'isspace'
/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lstrlib.c:305:22: warning: implicitly declaring library function 'isupper' with type 'int (int)' [-Wimplicit-function-declaration]
    case 'u' : res = isupper(c); break;
                     ^
/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lstrlib.c:305:22: note: include the header <ctype.h> or explicitly provide a declaration for 'isupper'
/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lstrlib.c:307:22: warning: implicitly declaring library function 'isxdigit' with type 'int (int)' [-Wimplicit-function-declaration]
    case 'x' : res = isxdigit(c); break;
                     ^
/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lstrlib.c:307:22: note: include the header <ctype.h> or explicitly provide a declaration for 'isxdigit'
cc -target x86_64-unknown-freebsd12.0 --sysroot=/var/tmp/home/sbruno/bsd/fbsd_head/amd64.amd64/tmp -B/var/tmp/home/sbruno/bsd/fbsd_head/amd64.amd64/tmp/usr/bin -fpic -DPIC  -O2 -pipe -I/home/sbruno/bsd/fbsd_head/sys/cddl/compat/opensolaris -I/home/sbruno/bsd/fbsd_head/cddl/compat/opensolaris/include -I/home/sbruno/bsd/fbsd_head/cddl/compat/opensolaris/lib/libumem -I/home/sbruno/bsd/fbsd_head/cddl/contrib/opensolaris/lib/libzpool/common -I/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/sys -I/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs -I/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua -I/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/common/zfs -I/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common -I/home/sbruno/bsd/fbsd_head/cddl/contrib/opensolaris/head -I/home/sbruno/bsd/fbsd_head/cddl/contrib/opensolaris/lib/libnvpair -I/home/sbruno/bsd/fbsd_head/cddl/contrib/opensolaris/lib/libcmdutils -DWANTS_MUTEX_OWNED -I/home/sbruno/bsd/fbsd_head/lib/libpthread/thread -I/home/sbruno/bsd/fbsd_head/lib/libpthread/sys -I/home/sbruno/bsd/fbsd_head/lib/libthr/arch/amd64/include -g -DDEBUG=1   -DNEED_SOLARIS_BOOLEAN -g -MD  -MF.depend.lbaselib.pico -MTlbaselib.pico -std=iso9899:1999 -fstack-protector-strong -Wno-pointer-sign -Wno-unknown-pragmas -Wno-empty-body -Wno-string-plus-int -Wno-unused-const-variable -Wno-tautological-compare -Wno-unused-value -Wno-parentheses-equality -Wno-unused-function -Wno-enum-conversion -Wno-unused-local-typedef -Wno-address-of-packed-member -Wno-switch -Wno-switch-enum -Wno-knr-promoted-parameter -Wno-parentheses  -Qunused-arguments  -c /home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lbaselib.c -o lbaselib.pico
/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lbaselib.c:56:9: warning: implicitly declaring library function 'isalpha' with type 'int (int)' [-Wimplicit-function-declaration]
    if (isalnum((unsigned char)*s)) {
        ^
/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lbaselib.c:23:21: note: expanded from macro 'isalnum'
#define isalnum(C)      (isalpha(C) || isdigit(C))
                         ^
/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lbaselib.c:56:9: note: include the header <ctype.h> or explicitly provide a declaration for 'isalpha'
/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lbaselib.c:23:21: note: expanded from macro 'isalnum'
#define isalnum(C)      (isalpha(C) || isdigit(C))
                         ^
/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lbaselib.c:56:9: warning: implicitly declaring library function 'isdigit' with type 'int (int)' [-Wimplicit-function-declaration]
    if (isalnum((unsigned char)*s)) {
        ^
/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lbaselib.c:23:35: note: expanded from macro 'isalnum'
#define isalnum(C)      (isalpha(C) || isdigit(C))
                                       ^
/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lbaselib.c:56:9: note: include the header <ctype.h> or explicitly provide a declaration for 'isdigit'
/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lbaselib.c:23:35: note: expanded from macro 'isalnum'
#define isalnum(C)      (isalpha(C) || isdigit(C))
                                       ^
/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lbaselib.c:60:26: warning: implicitly declaring library function 'toupper' with type 'int (int)' [-Wimplicit-function-declaration]
                       : toupper((unsigned char)*s) - 'A' + 10;
                         ^
/home/sbruno/bsd/fbsd_head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lbaselib.c:60:26: note: include the header <ctype.h> or explicitly provide a declaration for 'toupper'
3 warnings generated.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
No Lint Coverage
Unit
No Test Coverage
Build Status
Buildable 16451
Build 16370: arc lint + arc unit

Event Timeline

sbruno edited the summary of this revision. (Show Details)
imp requested changes to this revision.May 6 2018, 5:35 PM

So why isn't sys/ctypes.h enough? you're introducing a dependency on userland inside files that look like they are used by the kernel.

sys/cddl/contrib/opensolaris/uts/common/fs/zfs/lua/lbaselib.c
23–25

replace these three lines with #else

This revision now requires changes to proceed.May 6 2018, 5:35 PM
In D15326#322966, @imp wrote:

So why isn't sys/ctypes.h enough? you're introducing a dependency on userland inside files that look like they are used by the kernel.

Ugh. This didn't occur to me as this was part of the buildworld stage. How about I add a "#ifndef _KERNEL #includ <ctype.h>" type thing. sys/ctype.h doesn't have all of the same ctype macros that are in /usr/include/ctype.h ... so that might be a problem.

In D15326#322966, @imp wrote:

So why isn't sys/ctypes.h enough? you're introducing a dependency on userland inside files that look like they are used by the kernel.

Ugh. This didn't occur to me as this was part of the buildworld stage. How about I add a "#ifndef _KERNEL #includ <ctype.h>" type thing. sys/ctype.h doesn't have all of the same ctype macros that are in /usr/include/ctype.h ... so that might be a problem.

why doesn't sys/ctype.h work? We should fix that problem...

In D15326#323223, @imp wrote:
In D15326#322966, @imp wrote:

So why isn't sys/ctypes.h enough? you're introducing a dependency on userland inside files that look like they are used by the kernel.

Ugh. This didn't occur to me as this was part of the buildworld stage. How about I add a "#ifndef _KERNEL #includ <ctype.h>" type thing. sys/ctype.h doesn't have all of the same ctype macros that are in /usr/include/ctype.h ... so that might be a problem.

why doesn't sys/ctype.h work? We should fix that problem...

Unless I'm super confused here, this is part of buildworld ... so _KERNEL isn't defined, therefore the include does nothing?

In D15326#323223, @imp wrote:
In D15326#322966, @imp wrote:

So why isn't sys/ctypes.h enough? you're introducing a dependency on userland inside files that look like they are used by the kernel.

Ugh. This didn't occur to me as this was part of the buildworld stage. How about I add a "#ifndef _KERNEL #includ <ctype.h>" type thing. sys/ctype.h doesn't have all of the same ctype macros that are in /usr/include/ctype.h ... so that might be a problem.

why doesn't sys/ctype.h work? We should fix that problem...

Unless I'm super confused here, this is part of buildworld ... so _KERNEL isn't defined, therefore the include does nothing?

OK. I see the issue... normally we have a sys/foo.h we use in the kernel when foo.h would otherwise be used. Including it is supposed to basically always work. sys/ctype.h seems to pre-date that design pattern.... I'm thinking that the right fix is to remove the #ifdef _KERNEL from there entirely. It's only used in the kernel right now, and that would fix the code sharing case that's at issue here.

We may be able to remove the 'patched' bit as well and get closer to upstream at the same time...