2024-11-04 Paul Eggert <eggert@cs.ucla.edu>
+ stdlib: make MB_CUR_MAX usable from extern inline
+ * lib/stdlib.c: New file.
+ * modules/stdlib (Files, lib_SOURCES): Add it.
+ (Depends-on): Add extern-inline.
+ * lib/stdlib.in.h: Use _GL_INLINE_HEADER_BEGIN, _GL_INLINE_HEADER_END.
+ (_GL_STDLIB_INLINE): New macro.
+ (gl_MB_CUR_MAX): Make it _GL_STDLIB_INLINE not static inline,
+ so that it can be called from extern inline functions.
+ Redo implementation to help GCC better optimize common expressions
+ like (MB_CUR_MAX == 1).
+
realloc-posix: set CHERI bounds
* lib/ialloc.h, lib/xmalloc.c [__CHERI_PURE_CAPABILITY__]:
Do nothing special, as realloc and reallocarray
/* This file uses _Noreturn, _GL_ATTRIBUTE_DEALLOC, _GL_ATTRIBUTE_MALLOC,
_GL_ATTRIBUTE_NODISCARD, _GL_ATTRIBUTE_NOTHROW, _GL_ATTRIBUTE_PURE,
- GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */
+ _GL_INLINE_HEADER_BEGIN, GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */
#if !_GL_CONFIG_H_INCLUDED
#error "Please include config.h first."
#endif
# include <string>
#endif
+_GL_INLINE_HEADER_BEGIN
+#ifndef _GL_STDLIB_INLINE
+# define _GL_STDLIB_INLINE _GL_INLINE
+#endif
+
/* _GL_ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers
that can be freed by passing them as the Ith argument to the
function F. */
/* Return maximum number of bytes of a multibyte character. */
#if @REPLACE_MB_CUR_MAX@
# if !GNULIB_defined_MB_CUR_MAX
-static inline
-int gl_MB_CUR_MAX (void)
+_GL_STDLIB_INLINE int
+gl_MB_CUR_MAX (void)
{
/* Turn the value 3 to the value 4, as needed for the UTF-8 encoding. */
- return MB_CUR_MAX + (MB_CUR_MAX == 3);
+ int gl_mb_cur_max = MB_CUR_MAX;
+ return gl_mb_cur_max == 3 ? 4 : gl_mb_cur_max;
}
# undef MB_CUR_MAX
# define MB_CUR_MAX gl_MB_CUR_MAX ()
#endif
+_GL_INLINE_HEADER_END
+
#endif /* _@GUARD_PREFIX@_STDLIB_H */
#endif /* _@GUARD_PREFIX@_STDLIB_H */
#endif
A GNU-like <stdlib.h>.
Files:
+lib/stdlib.c
lib/stdlib.in.h
m4/stdlib_h.m4
m4/locale-en.m4
Depends-on:
gen-header
+extern-inline
include_next
snippet/arg-nonnull
snippet/c++defs
Makefile.am:
BUILT_SOURCES += stdlib.h
+lib_SOURCES += stdlib.c
-# We need the following in order to create <stdlib.h> when the system
-# doesn't have one that works with the given compiler.
stdlib.h: stdlib.in.h $(top_builddir)/config.status $(CXXDEFS_H) \
$(_NORETURN_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
@NMD@ $(AM_V_GEN)$(MKDIR_P) '%reldir%'