{"thread":{"id":"63775","subject":"[PATCH] sane-ctype: fix compiler error on Amazon Linux 2","startedAt":"2025-07-10T07:56:56Z","lastAt":"2025-07-10T07:56:56Z","messageCount":1,"participants":["Patrick Steinhardt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"521737","messageId":"20250710-pks-ctype-v1-1-c668b308d628@pks.im","threadId":"63775","inReplyTo":null,"subject":"[PATCH] sane-ctype: fix compiler error on Amazon Linux 2","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-07-10T07:56:35Z","receivedAt":"2025-07-10T07:56:56Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Compiling Git fails on Amazon Linux 2 when using GCC 7.3.1 with the\nfollowing compiler error:\n\n    In file included from compat/posix.h:449:0,\n                     from git-compat-util.h:26,\n                     from daemon.c:3:\n    compat/../sane-ctype.h:29:60: error: expected expression before ']' token\n     #define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)\n                                                                ^\n    compat/../sane-ctype.h:29:72: error: expected ')' before '!=' token\n     #define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)\n                                                                            ^\n    compat/../sane-ctype.h:29:60: error: expected expression before ']' token\n     #define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)\n                                                                ^\n    ... lots of similar lines ...\n\n    compat/../sane-ctype.h:45:50: error: expected declaration specifiers or '...' before numeric constant\n     #define toupper(x) sane_case((unsigned char)(x), 0)\n                                                      ^\n    /usr/include/ctype.h:142:12: error: expected identifier or '(' before 'int'\n     extern int isascii (int __c) __THROW;\n                ^\n    compat/../sane-ctype.h:30:26: error: expected ')' before '&' token\n     #define isascii(x) (((x) & ~0x7f) == 0)\n                              ^\n    compat/../sane-ctype.h:30:35: error: expected ')' before '==' token\n     #define isascii(x) (((x) & ~0x7f) == 0)\n                                       ^\n    In file included from /usr/include/features.h:423:0,\n                     from /usr/include/unistd.h:25,\n                     from compat/posix.h:90,\n                     from git-compat-util.h:26,\n                     from daemon.c:3:\n    compat/../sane-ctype.h:44:30: error: expected declaration specifiers or '...' before '(' token\n     #define tolower(x) sane_case((unsigned char)(x), 0x20)\n                                  ^\n    compat/../sane-ctype.h:44:50: error: expected declaration specifiers or '...' before numeric constant\n     #define tolower(x) sane_case((unsigned char)(x), 0x20)\n                                                      ^\n    compat/../sane-ctype.h:45:30: error: expected declaration specifiers or '...' before '(' token\n     #define toupper(x) sane_case((unsigned char)(x), 0)\n                                  ^\n    compat/../sane-ctype.h:45:50: error: expected declaration specifiers or '...' before numeric constant\n     #define toupper(x) sane_case((unsigned char)(x), 0)\n                                                      ^\n\nThis error bisect back to 75a044f748 (git-compat-util.h: split out\nPOSIX-emulating bits, 2025-02-18), where lots of bits got split out of\n\"git-compat-util.h\" into a new \"compat/posix.h\" header.\n\nThe compiler error isn't immediately obvious, doubly so because the\nactual errors are ~3x as long as the above snippet. But what happens\nhere is that we transitively include <ctype.h> after we have included\nour own \"sane-ctype.h\" header. Consequently, the function declarations\nthat exist in <ctype.h> for isascii(3p) et al will be mangled by our\nmacros of the same type. The result is of course completely broken.\n\nIt's unclear why this issue only happens on Amazon Linux 2. My guess is\nthat it's either specific to the compiler version or specific to the\nglibc v\n"}]}