Skip to content

Commit f18f655

Browse files
committed
ctype: Always allow negative _ctype_ indices
Compilers now provide build-time options controlling whether 'char' means 'signed char' or 'unsigned char'. This means we cannot assume the same mode will be used when building picolibc as when building the application. To avoid having the ABI shift with compiler flags, remove support for the smaller tables and always provide tables which allow for signed char indexing as this provides the safest possible implementation. Signed-off-by: Keith Packard <[email protected]>
1 parent f02d772 commit f18f655

File tree

2 files changed

+4
-37
lines changed

2 files changed

+4
-37
lines changed

newlib/libc/ctype/ctype_.c

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,16 @@
3434
#include "locale_private.h"
3535
#include "../stdlib/local.h"
3636

37-
#if defined(_ALLOW_NEGATIVE_CTYPE_INDEX)
38-
3937
const char _ctype_b[128 + 256] = {
4038
_CTYPE_DATA_128_255,
4139
_CTYPE_DATA_0_127,
4240
_CTYPE_DATA_128_255
4341
};
4442

45-
#else /* !_ALLOW_NEGATIVE_CTYPE_INDEX */
46-
47-
const char _ctype_[1 + 256] = {
48-
0,
49-
_CTYPE_DATA_0_127,
50-
_CTYPE_DATA_128_255
51-
};
52-
53-
#endif /* !_ALLOW_NEGATIVE_CTYPE_INDEX */
54-
5543
#ifdef _MB_EXTENDED_CHARSETS_NON_UNICODE
5644

5745
#include "ctype_extended.h"
5846

59-
#if defined(_ALLOW_NEGATIVE_CTYPE_INDEX)
60-
6147
#define __CTYPE(base) [locale_ ## base - locale_EXTENDED_BASE] = { \
6248
_CTYPE_ ## base ## _128_254, \
6349
0, \
@@ -66,17 +52,6 @@ const char _ctype_[1 + 256] = {
6652
_CTYPE_ ## base ## _255 \
6753
}
6854

69-
#else
70-
71-
#define __CTYPE(base) [locale_ ## base - locale_EXTENDED_BASE] = { \
72-
0, \
73-
_CTYPE_DATA_0_127, \
74-
_CTYPE_ ## base ## _128_254, \
75-
_CTYPE_ ## base ## _255 \
76-
}
77-
78-
#endif
79-
8055
const char __ctype[locale_END - locale_EXTENDED_BASE][_CTYPE_OFFSET + 1 + 256] = {
8156
#ifdef _MB_EXTENDED_CHARSETS_ISO
8257
__CTYPE(ISO_8859_1),

newlib/libc/include/ctype.h

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -218,20 +218,12 @@ __declare_extern_inline(int) toupper_l (int c, locale_t l) { (void) l; return to
218218

219219
#else /* _PICOLIBC_CTYPE_SMALL */
220220

221-
#ifndef __CHAR_UNSIGNED__
222-
#define _ALLOW_NEGATIVE_CTYPE_INDEX
223-
#endif
224-
225-
#if defined(_ALLOW_NEGATIVE_CTYPE_INDEX)
226-
extern const char _ctype_b[];
227221
#define _CTYPE_OFFSET 127
228-
#define _ctype_ (_ctype_b + _CTYPE_OFFSET)
229-
#else
230-
#define _CTYPE_OFFSET 0
231-
extern const char _ctype_[];
232-
#endif
233222

234-
extern const short _ctype_wide[];
223+
extern const char _ctype_b[];
224+
extern const short _ctype_wide[];
225+
226+
#define _ctype_ (_ctype_b + _CTYPE_OFFSET)
235227

236228
#ifndef __cplusplus
237229

0 commit comments

Comments
 (0)