* [PATCH] Maybe change __size_t definition in <stddef.h>?
@ 2016-04-15 9:45 Sebastian Huber
2016-04-15 10:23 ` Richard Biener
0 siblings, 1 reply; 3+ messages in thread
From: Sebastian Huber @ 2016-04-15 9:45 UTC (permalink / raw)
To: gcc-patches; +Cc: devel, newlib, Sebastian Huber
I work currently on a better FreeBSD compatibility for Newlib. For
RTEMS we use the network, USB, SD/MMC stacks from FreeBSD. It would be
nice to use <sys/types.h>, etc. from Newlib directly to compile FreeBSD
user and kernel space files.
Various FreeBSD source and header files need a typedef __size_t via
<sys/_types.h>. Unfortunately the GCC provided <stddef.h> uses
#if (defined (__FreeBSD__) && (__FreeBSD__ >= 5)) \
|| defined(__DragonFly__) \
|| defined(__FreeBSD_kernel__)
/* __size_t is a typedef on FreeBSD 5, must not trash it. */
#elif defined (__VMS__)
/* __size_t is also a typedef on VMS. */
#else
#define __size_t
#endif
and therefore defines __size_t to nothing on Newlib targets which would
trash a __size_t typedef. There exists no Newlib builtin define which
we could add here. As a workaround I include <stddef.h> before
<sys/_types.h> in <sys/types.h> and undefine __size_t in <sys/_types.h>.
This works fine so far, but breaks if someone includes <stddef.h> after
<sys/_types.h> the first time.
This patch would address this issue, but I do not know which other
issues it generates.
gcc/ChangeLog
2016-04-15 Sebastian Huber <sebastian.huber@embedded-brains.de>
* ginclude/stddef.h (__size_t): Define to __SIZE_TYPE__.
---
gcc/ginclude/stddef.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gcc/ginclude/stddef.h b/gcc/ginclude/stddef.h
index d711530..8c2e22e 100644
--- a/gcc/ginclude/stddef.h
+++ b/gcc/ginclude/stddef.h
@@ -207,7 +207,7 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t;
#elif defined (__VMS__)
/* __size_t is also a typedef on VMS. */
#else
-#define __size_t
+#define __size_t __SIZE_TYPE__
#endif
#ifndef __SIZE_TYPE__
#define __SIZE_TYPE__ long unsigned int
--
1.8.4.5
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Maybe change __size_t definition in <stddef.h>?
2016-04-15 9:45 [PATCH] Maybe change __size_t definition in <stddef.h>? Sebastian Huber
@ 2016-04-15 10:23 ` Richard Biener
2016-04-15 11:01 ` Sebastian Huber
0 siblings, 1 reply; 3+ messages in thread
From: Richard Biener @ 2016-04-15 10:23 UTC (permalink / raw)
To: Sebastian Huber; +Cc: GCC Patches, devel, newlib
On Fri, Apr 15, 2016 at 11:44 AM, Sebastian Huber
<sebastian.huber@embedded-brains.de> wrote:
> I work currently on a better FreeBSD compatibility for Newlib. For
> RTEMS we use the network, USB, SD/MMC stacks from FreeBSD. It would be
> nice to use <sys/types.h>, etc. from Newlib directly to compile FreeBSD
> user and kernel space files.
>
> Various FreeBSD source and header files need a typedef __size_t via
> <sys/_types.h>. Unfortunately the GCC provided <stddef.h> uses
>
> #if (defined (__FreeBSD__) && (__FreeBSD__ >= 5)) \
> || defined(__DragonFly__) \
> || defined(__FreeBSD_kernel__)
> /* __size_t is a typedef on FreeBSD 5, must not trash it. */
> #elif defined (__VMS__)
> /* __size_t is also a typedef on VMS. */
> #else
> #define __size_t
This looks odd - maybe it was meant to be a #undef? OTOH there are
a whole lot of other similar cases there which do not make sense to me...
Richard.
> #endif
>
> and therefore defines __size_t to nothing on Newlib targets which would
> trash a __size_t typedef. There exists no Newlib builtin define which
> we could add here. As a workaround I include <stddef.h> before
> <sys/_types.h> in <sys/types.h> and undefine __size_t in <sys/_types.h>.
>
> This works fine so far, but breaks if someone includes <stddef.h> after
> <sys/_types.h> the first time.
>
> This patch would address this issue, but I do not know which other
> issues it generates.
>
> gcc/ChangeLog
> 2016-04-15 Sebastian Huber <sebastian.huber@embedded-brains.de>
>
> * ginclude/stddef.h (__size_t): Define to __SIZE_TYPE__.
> ---
> gcc/ginclude/stddef.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/gcc/ginclude/stddef.h b/gcc/ginclude/stddef.h
> index d711530..8c2e22e 100644
> --- a/gcc/ginclude/stddef.h
> +++ b/gcc/ginclude/stddef.h
> @@ -207,7 +207,7 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t;
> #elif defined (__VMS__)
> /* __size_t is also a typedef on VMS. */
> #else
> -#define __size_t
> +#define __size_t __SIZE_TYPE__
> #endif
> #ifndef __SIZE_TYPE__
> #define __SIZE_TYPE__ long unsigned int
> --
> 1.8.4.5
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Maybe change __size_t definition in <stddef.h>?
2016-04-15 10:23 ` Richard Biener
@ 2016-04-15 11:01 ` Sebastian Huber
0 siblings, 0 replies; 3+ messages in thread
From: Sebastian Huber @ 2016-04-15 11:01 UTC (permalink / raw)
To: Richard Biener; +Cc: GCC Patches, devel, newlib
On 15/04/16 12:23, Richard Biener wrote:
> On Fri, Apr 15, 2016 at 11:44 AM, Sebastian Huber
> <sebastian.huber@embedded-brains.de> wrote:
>> >I work currently on a better FreeBSD compatibility for Newlib. For
>> >RTEMS we use the network, USB, SD/MMC stacks from FreeBSD. It would be
>> >nice to use <sys/types.h>, etc. from Newlib directly to compile FreeBSD
>> >user and kernel space files.
>> >
>> >Various FreeBSD source and header files need a typedef __size_t via
>> ><sys/_types.h>. Unfortunately the GCC provided <stddef.h> uses
>> >
>> > #if (defined (__FreeBSD__) && (__FreeBSD__ >= 5)) \
>> > || defined(__DragonFly__) \
>> > || defined(__FreeBSD_kernel__)
>> > /* __size_t is a typedef on FreeBSD 5, must not trash it. */
>> > #elif defined (__VMS__)
>> > /* __size_t is also a typedef on VMS. */
>> > #else
>> > #define __size_t
> This looks odd - maybe it was meant to be a #undef? OTOH there are
> a whole lot of other similar cases there which do not make sense to me...
No, in case __size_t is defined, then we don't end up in this spot.
stddef.h tests for various guard defines and if none of them is defined,
then it typedefs size_t and defines all the guard defines to nothing,
except for __size_t on some targets.
--
Sebastian Huber, embedded brains GmbH
Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail : sebastian.huber@embedded-brains.de
PGP : Public key available on request.
Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-04-15 11:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-15 9:45 [PATCH] Maybe change __size_t definition in <stddef.h>? Sebastian Huber
2016-04-15 10:23 ` Richard Biener
2016-04-15 11:01 ` Sebastian Huber
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).