Skip to content

Commit

Permalink
Resolve review comments to:
Browse files Browse the repository at this point in the history
- Use private types in all public headers so that `stddef.h` isn't required.
- Fix the default value of `RSIZE_MAX`.
- Remove duplicate definition of `set_constraint_handler_s`.

Signed-off-by: Mostafa Salman <[email protected]>
  • Loading branch information
mostafa-salmaan committed Jun 24, 2024
1 parent 0492c2a commit 9114c82
Show file tree
Hide file tree
Showing 36 changed files with 374 additions and 847 deletions.
10 changes: 1 addition & 9 deletions newlib/libc/include/errno.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,10 @@ SUCH DAMAGE.
#ifndef __error_t_defined
typedef int error_t;

#ifdef __STDC_WANT_LIB_EXT1__
#if (__STDC_WANT_LIB_EXT1__ != 0) && (__STDC_WANT_LIB_EXT1__ != 1)
#error Please define __STDC_WANT_LIB_EXT__ as 0 or 1
#endif
#if __STDC_WANT_LIB_EXT1__ == 1
typedef int errno_t;
#endif
#endif

#define __error_t_defined 1
#endif

#include <sys/errno.h>
#include <sys/_types.h>

#endif /* !__ERRNO_H__ */
19 changes: 6 additions & 13 deletions newlib/libc/include/stdint.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,22 +458,15 @@ typedef __uint_least64_t uint_least64_t;
#endif
#endif

#ifdef __STDC_WANT_LIB_EXT1__
#if (__STDC_WANT_LIB_EXT1__ != 0) && (__STDC_WANT_LIB_EXT1__ != 1)
#error Please define __STDC_WANT_LIB_EXT__ as 0 or 1
#endif

#if __STDC_WANT_LIB_EXT1__ == 1
#include <stddef.h>
#ifndef __RSIZE_T
#define __RSIZE_T
typedef size_t rsize_t;
#include <sys/_types.h>

// could be defined by the user
#ifndef RSIZE_MAX
#define RSIZE_MAX SIZE_MAX
#endif

extern rsize_t _set_rsize_max_s(rsize_t);
extern rsize_t _get_rsize_max_s(void);
#define RSIZE_MAX (_get_rsize_max_s())
#endif
typedef __rsize_t rsize_t;
#endif


Expand Down
15 changes: 5 additions & 10 deletions newlib/libc/include/stdlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,26 +384,21 @@ _Noreturn void
#endif /* __ISO_C_VISIBLE >= 2011 */


#ifdef __STDC_WANT_LIB_EXT1__
#if (__STDC_WANT_LIB_EXT1__ != 0) && (__STDC_WANT_LIB_EXT1__ != 1)
#error Please define __STDC_WANT_LIB_EXT__ as 0 or 1
#endif

#if __STDC_WANT_LIB_EXT1__ == 1
#include <errno.h>
#include <sys/_types.h>

typedef __errno_t errno_t;

typedef void (*constraint_handler_t)(
const char *restrict msg, void *restrict ptr, errno_t error);

extern constraint_handler_t * ___pcur_handler(void);
#define cur_handler (*___pcur_handler())
extern constraint_handler_t __cur_handler;

extern constraint_handler_t set_constraint_handler_s(
constraint_handler_t handler);
extern void ignore_handler_s(
extern void abort_handler_s(
const char *restrict msg, void *restrict ptr, errno_t error);
#endif
#endif


_END_STD_C
Expand Down
15 changes: 3 additions & 12 deletions newlib/libc/include/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,11 @@ size_t strspn (const char *, const char *);
char *strstr (const char *, const char *);


#ifdef __STDC_WANT_LIB_EXT1__
#if (__STDC_WANT_LIB_EXT1__ != 0) && (__STDC_WANT_LIB_EXT1__ != 1)
#error Please define __STDC_WANT_LIB_EXT__ as 0 or 1
#endif

#if __STDC_WANT_LIB_EXT1__ == 1
#include <stddef.h>
#include <errno.h>
#include <sys/_types.h>

#ifndef __RSIZE_T
#define __RSIZE_T
typedef size_t rsize_t;
#endif
typedef __rsize_t rsize_t;
typedef __errno_t errno_t;

extern errno_t memcpy_s(void *__restrict, rsize_t, const void *__restrict, rsize_t);
extern errno_t memset_s(void *, rsize_t, int, rsize_t);
Expand All @@ -105,7 +97,6 @@ extern size_t strnlen_s(const char *, size_t);
extern errno_t strerror_s(char *, rsize_t, errno_t); /* C11 */
extern size_t strerrorlen_s(errno_t);
#endif
#endif

#ifndef _REENT_ONLY
char *strtok (char *__restrict, const char *__restrict);
Expand Down
21 changes: 21 additions & 0 deletions newlib/libc/include/sys/_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,25 @@ typedef unsigned short __nlink_t;
typedef long __suseconds_t; /* microseconds (signed) */
typedef unsigned long __useconds_t; /* microseconds (unsigned) */


#ifdef __STDC_WANT_LIB_EXT1__
#if (__STDC_WANT_LIB_EXT1__ != 0) && (__STDC_WANT_LIB_EXT1__ != 1)
#error Please define __STDC_WANT_LIB_EXT__ as 0 or 1
#endif

#if __STDC_WANT_LIB_EXT1__ == 1

#ifndef __RSIZE_T
#define __RSIZE_T
typedef size_t __rsize_t;
#endif

#ifndef __ERRNO_T
#define __ERRNO_T
typedef int __errno_t;
#endif

#endif
#endif

#endif /* _SYS__TYPES_H */
2 changes: 0 additions & 2 deletions newlib/libc/include/sys/errno.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,6 @@ extern NEWLIB_THREAD_LOCAL_ERRNO int errno;
#endif
#define EWOULDBLOCK EAGAIN /* Operation would block */

#define ELAST 149

#define __ELASTERROR 2000 /* Users can add values starting here */

#ifdef __cplusplus
Expand Down
1 change: 0 additions & 1 deletion newlib/libc/stdlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ picolibc_sources(
pico-onexit.c
pico-cxa-atexit.c
set_constraint_handler_s.c
rsizet.c
)

picolibc_sources_flags("-fno-builtin-malloc;-fno-builtin-free"
Expand Down
55 changes: 0 additions & 55 deletions newlib/libc/stdlib/constraint.c

This file was deleted.

1 change: 0 additions & 1 deletion newlib/libc/stdlib/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ srcs_stdlib = [
'wctomb.c',
'wctomb_r.c',
'set_constraint_handler_s.c',
'rsizet.c',
]

srcs_stdlib_stdio = [
Expand Down
48 changes: 0 additions & 48 deletions newlib/libc/stdlib/rsizet.c

This file was deleted.

11 changes: 7 additions & 4 deletions newlib/libc/stdlib/set_constraint_handler_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,27 @@
#define __STDC_WANT_LIB_EXT1__ 1
#include <stdlib.h>

void ignore_handler_s(const char *restrict msg, void *restrict ptr, errno_t error)
constraint_handler_t __cur_handler = abort_handler_s;

void abort_handler_s(const char *restrict msg, void *restrict ptr, errno_t error)
{
(void) msg;
(void) ptr;
(void) error;
abort();
}

constraint_handler_t set_constraint_handler_s(constraint_handler_t handler)
{
constraint_handler_t h = cur_handler;
constraint_handler_t h = __cur_handler;

if (handler == (constraint_handler_t)NULL)
{
cur_handler = ignore_handler_s; // null restores to default handler
__cur_handler = abort_handler_s; // null restores to default handler
}
else
{
cur_handler = handler;
__cur_handler = handler;
}

return h;
Expand Down
Loading

0 comments on commit 9114c82

Please sign in to comment.