Skip to content

Commit

Permalink
config.mak.dev: specify C99 for IBM xlc
Browse files Browse the repository at this point in the history
In 5f46385 (config.mak.dev: specify -std=gnu99 for gcc/clang,
2021-12-08) GCC and Clang were made to use the C99 standard when
compiling, let's do the same for IBM's XLC. Its default is a looser
mode that "accepts implementation-specific language extensions"[1].

The entire codebase compiles with this, except the code being altered
here in wildmatch.c. Since we've permanently forked that upstream
code (the upstream is GPLv3) let's just drop the "typedef" and use
"unsigned char" directly.

This resolves the following warnings on IBM xlc 13.01:

	"wildmatch.c", line 15.23: 1506-334 (S) Identifier uchar has already been defined on line 560 of "/usr/include/sys/types.h".
	"wildmatch.c", line 60.38: 1506-281 (S) Prefix and postfix increment and decrement operators cannot be applied to "illegal type*".
	"wildmatch.c", line 60.46: 1506-281 (S) Prefix and postfix increment and decrement operators cannot be applied to "illegal type*".
	"wildmatch.c", line 73.35: 1506-281 (S) Prefix and postfix increment and decrement operators cannot be applied to "illegal type*".
	"wildmatch.c", line 85.32: 1506-281 (S) Prefix and postfix increment and decrement operators cannot be applied to "illegal type*".
	"wildmatch.c", line 86.57: 1506-068 (S) Operation between types "illegal type*" and "int" is not allowed.
	"wildmatch.c", line 87.43: 1506-281 (S) Prefix and postfix increment and decrement operators cannot be applied to "illegal type*".
	"wildmatch.c", line 91.50: 1506-068 (E) Operation between types "illegal type*" and "illegal type*" is not allowed.
	"wildmatch.c", line 93.39: 1506-019 (S) Expecting an array or a pointer to object type.
	"wildmatch.c", line 93.55: 1506-019 (S) Expecting an array or a pointer to object type.
	"wildmatch.c", line 103.45: 1506-019 (S) Expecting an array or a pointer to object type.
	"wildmatch.c", line 104.54: 1506-068 (S) Operation between types "illegal type*" and "int" is not allowed.
	"wildmatch.c", line 154.49: 1506-281 (S) Prefix and postfix increment and decrement operators cannot be applied to "illegal type*".
	"wildmatch.c", line 164.43: 1506-281 (S) Prefix and postfix increment and decrement operators cannot be applied to "illegal type*".
	"wildmatch.c", line 168.35: 1506-281 (S) Prefix and postfix increment and decrement operators cannot be applied to "illegal type*".
	"wildmatch.c", line 177.43: 1506-281 (S) Prefix and postfix increment and decrement operators cannot be applied to "illegal type*".
	"wildmatch.c", line 185.51: 1506-281 (S) Prefix and postfix increment and decrement operators cannot be applied to "illegal type*".
	"wildmatch.c", line 190.70: 1506-019 (S) Expecting an array or a pointer to object type.
	"wildmatch.c", line 190.78: 1506-019 (S) Expecting an array or a pointer to object type.
	"wildmatch.c", line 191.51: 1506-281 (S) Prefix and postfix increment and decrement operators cannot be applied to "illegal type*".
	"wildmatch.c", line 193.59: 1506-281 (S) Prefix and postfix increment and decrement operators cannot be applied to "illegal type*".
	"wildmatch.c", line 205.59: 1506-019 (S) Expecting an array or a pointer to object type.
	"wildmatch.c", line 208.52: 1506-068 (S) Operation between types "illegal type*" and "int" is not allowed.
	"wildmatch.c", line 208.86: 1506-281 (S) Prefix and postfix increment and decrement operators cannot be applied to "illegal type*".
	"wildmatch.c", line 211.47: 1506-068 (S) Operation between types "illegal type*" and "illegal type*" is not allowed.
	"wildmatch.c", line 212.54: 1506-019 (S) Expecting an array or a pointer to object type.
	"wildmatch.c", line 214.55: 1506-068 (S) Operation between types "illegal type*" and "int" is not allowed.
	"wildmatch.c", line 263.61: 1506-281 (S) Prefix and postfix increment and decrement operators cannot be applied to "illegal type*".
	Makefile:2609: recipe for target 'wildmatch.o' failed

1. https://www.ibm.com/docs/sv/xl-c-and-cpp-aix/13.1.2?topic=descriptions-qlanglvl

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
  • Loading branch information
avar committed Nov 1, 2022
1 parent 3737679 commit 079f555
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
4 changes: 4 additions & 0 deletions config.mak.dev
Expand Up @@ -36,6 +36,10 @@ endif
ifneq ($(uname_S),FreeBSD)
ifdef PROBE_COMPILER_NEEDS_std-eq-gnu99
DEVELOPER_CFLAGS += -std=gnu99
else
ifdef COMPILER_name_IS_xlc
DEVELOPER_CFLAGS += -qlanglvl=stdc99
endif
endif
else
# FreeBSD cannot limit to C99 because its system headers unconditionally
Expand Down
1 change: 1 addition & 0 deletions config.mak.uname
Expand Up @@ -316,6 +316,7 @@ ifeq ($(uname_S),NetBSD)
PROCFS_EXECUTABLE_PATH = /proc/curproc/exe
endif
ifeq ($(uname_S),AIX)
NO_INITGROUPS = YesPlease
DEFAULT_PAGER = more
NO_STRCASESTR = YesPlease
NO_MEMMEM = YesPlease
Expand Down
24 changes: 13 additions & 11 deletions wildmatch.c
Expand Up @@ -12,8 +12,6 @@
#include "cache.h"
#include "wildmatch.h"

typedef unsigned char uchar;

/* What character marks an inverted character class? */
#define NEGATE_CLASS '!'
#define NEGATE_CLASS2 '^'
Expand Down Expand Up @@ -52,14 +50,15 @@ typedef unsigned char uchar;
#define ISXDIGIT(c) (ISASCII(c) && isxdigit(c))

/* Match pattern "p" against "text" */
static int dowild(const uchar *p, const uchar *text, unsigned int flags)
static int dowild(const unsigned char *p, const unsigned char *text,
unsigned int flags)
{
uchar p_ch;
const uchar *pattern = p;
unsigned char p_ch;
const unsigned char *pattern = p;

for ( ; (p_ch = *p) != '\0'; text++, p++) {
int matched, match_slash, negated;
uchar t_ch, prev_ch;
unsigned char t_ch, prev_ch;
if ((t_ch = *text) == '\0' && p_ch != '*')
return WM_ABORT_ALL;
if ((flags & WM_CASEFOLD) && ISUPPER(t_ch))
Expand All @@ -83,7 +82,7 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags)
continue;
case '*':
if (*++p == '*') {
const uchar *prev_p = p - 2;
const unsigned char *prev_p = p - 2;
while (*++p == '*') {}
if (!(flags & WM_PATHNAME))
/* without WM_PATHNAME, '*' == '**' */
Expand Down Expand Up @@ -126,7 +125,7 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags)
const char *slash = strchr((char*)text, '/');
if (!slash)
return WM_NOMATCH;
text = (const uchar*)slash;
text = (const unsigned char*)slash;
/* the slash is consumed by the top-level for loop */
break;
}
Expand Down Expand Up @@ -197,13 +196,13 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags)
if (t_ch <= p_ch && t_ch >= prev_ch)
matched = 1;
else if ((flags & WM_CASEFOLD) && ISLOWER(t_ch)) {
uchar t_ch_upper = toupper(t_ch);
unsigned char t_ch_upper = toupper(t_ch);
if (t_ch_upper <= p_ch && t_ch_upper >= prev_ch)
matched = 1;
}
p_ch = 0; /* This makes "prev_ch" get set to 0. */
} else if (p_ch == '[' && p[1] == ':') {
const uchar *s;
const unsigned char *s;
int i;
for (s = p += 2; (p_ch = *p) && p_ch != ']'; p++) {} /*SHARED ITERATOR*/
if (!p_ch)
Expand Down Expand Up @@ -274,5 +273,8 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags)
/* Match the "pattern" against the "text" string. */
int wildmatch(const char *pattern, const char *text, unsigned int flags)
{
return dowild((const uchar*)pattern, (const uchar*)text, flags);
const unsigned char *upattern = (const unsigned char*)pattern;
const unsigned char *utext = (const unsigned char*)text;

return dowild(upattern, utext, flags);
}

0 comments on commit 079f555

Please sign in to comment.