[PATCH] second take: SPU use a 16 byte fpos_t
Jeff Johnston
jjohnstn@redhat.com
Mon Sep 10 23:57:00 GMT 2007
Thanks Patrick,
Tested fine on mn10300 and x86-linux after I made a change to its copy
of sys/_types.h. Patch checked in. I will add flags for all the other
variables shortly.
-- Jeff J.
Patrick Mansfield wrote:
> On Fri, Sep 07, 2007 at 01:56:02PM -0400, Jeff Johnston wrote:
>
>
>>>> So, this is what I propose:
>>>>
>>>> 1. copy machine/_types.h to machine/_default_types.h
>>>> 2. make machine/_types.h simply include machine/_default_types.h
>>>> 3. have sys/_types.h include machine/_types.h
>>>> 4. have sys/_types.h look for flags before defining _ types. For
>>>> example, #ifndef _OFF_T_DEFINED). You need to add
>>>> _fpos_t and _fpos64_t default defs which weren't there previously
>>>> 5. create an machine/spu/machine/_types.h which defines all of these
>>>> to your liking...also set the flags on so sys/_types.h won't try
>>>> and define them
>>>> 6. remove _fpos_t and _fpos64_t defs from sys/reent.h
>>>>
>>>> This will be clean and allow other platforms to do tweaking as
>>>> desired without cluttering up the common headers.
>>>>
>>>> Comments?
>>>>
>>>>
>>> I'm trying this, but machine/spu/machine/_types.h is not being used - at
>>> least it is not installed, full path is
>>> newlib/libc/include/machine/spu/machine/_types.h.
>>>
>>> Do I need a configuration change too, or did you mean a different path?
>>>
>>> And machine/spu/machine/_types.h would replace (and so has to supply
>>> everything included by) machine/_types.h ?
>>>
>>> -- Patrick Mansfield
>>>
>>>
>> I meant libc/machine/spu/machine/_types.h (i.e. not in the libc/include
>> directory). There is code in Makefile.am that will take header files
>> from libc/machine/xxxx/machine and put them in the include/machine
>> directory. This is how platforms override whatever headers they want to.
>>
>> Regarding the override: The reason I had you create a _default_types.h
>> file is so any machine-specific _types.h could start with #include
>> <machine/_default_types.h> and so there is no need to copy the current
>> file over.
>>
>
> Does this look OK?
>
> I don't know why we have the _fpos_t and _fpos64_t with underscore prefix.
> I left the odd comment about it in place, the: "We need fpos_t for the
> following, but it doesn't have a leading "_", so we use _fpos_t instead."
>
> Updated patch based on Jeff's comments:
>
> fpos_t is 12 bytes for 32 bit ppc glibc, and 16 bytes for 64 bit.
>
> Currently SPU newlib uses 4 bytes for fpos_t. This is always a problem
> with 64 bit ppc, since the fgetpos() assist call writes 8 bytes for the
> offset, and is a potential problem with 32 bit ppc.
>
> So for SPU always use 16 bytes for fpos_t and also the currently unused
> (in SPU) _fpos64_t.
>
> Add new files and setup so we do not have machine/cpu #ifdefs in
> sys/reent.h.
>
> newlib ChangeLog:
>
> 2007-09-07 Patrick Mansfield <patmans@us.ibm.com>
>
> * libc/include/machine/_default_types.h: New file, contains what
> was previously in libc/include/machine/_types.h.
> * libc/include/machine/_types.h: Now only includes
> machine/_default_types.h.
> * libc/include/sys/reent.h: Remove _fpos_t and _fpos64_t.
> * libc/include/sys/_types.h: Move _fpos_t and _fpos64_t to here,
> with conditional declarations.
> * libc/machine/spu/machine/_types.h: New file, add SPU specific
> typedefs for _fpos_t and _fpos64_t.
>
> Index: push-sdk3-patches-quilt-base/newlib/libc/include/sys/reent.h
> ===================================================================
> --- push-sdk3-patches-quilt-base.orig/newlib/libc/include/sys/reent.h
> +++ push-sdk3-patches-quilt-base/newlib/libc/include/sys/reent.h
> @@ -108,18 +108,6 @@ struct __sbuf {
> };
>
> /*
> - * We need fpos_t for the following, but it doesn't have a leading "_",
> - * so we use _fpos_t instead.
> - */
> -
> -typedef long _fpos_t; /* XXX must match off_t in <sys/types.h> */
> - /* (and must be `long' for now) */
> -
> -#ifdef __LARGE64_FILES
> -typedef _off64_t _fpos64_t;
> -#endif
> -
> -/*
> * Stdio state variables.
> *
> * The following always hold:
> Index: push-sdk3-patches-quilt-base/newlib/libc/include/machine/_default_types.h
> ===================================================================
> --- /dev/null
> +++ push-sdk3-patches-quilt-base/newlib/libc/include/machine/_default_types.h
> @@ -0,0 +1,121 @@
> +/*
> + * $Id: _types.h,v 1.2 2005/03/22 18:12:29 cgf Exp $
> + */
> +
> +#ifndef _MACHINE__DEFAULT_TYPES_H
> +#define _MACHINE__DEFAULT_TYPES_H
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +/*
> + * Guess on types by examining *_MIN / *_MAX defines.
> + */
> +#if defined(__GNUC__) && (__GNUC__ >= 3 ) \
> + && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ > 2 )
> +/* GCC >= 3.3.0 has __<val>__ implicitly defined. */
> +#define __EXP(x) __##x##__
> +#else
> +/* Fall back to POSIX versions from <limits.h> */
> +#define __EXP(x) x
> +#include <limits.h>
> +#endif
> +
> +#if __EXP(SCHAR_MAX) == 0x7f
> +typedef signed char __int8_t ;
> +typedef unsigned char __uint8_t ;
> +#define ___int8_t_defined 1
> +#endif
> +
> +#if __EXP(INT_MAX) == 0x7fff
> +typedef signed int __int16_t;
> +typedef unsigned int __uint16_t;
> +#define ___int16_t_defined 1
> +#elif __EXP(SHRT_MAX) == 0x7fff
> +typedef signed short __int16_t;
> +typedef unsigned short __uint16_t;
> +#define ___int16_t_defined 1
> +#elif __EXP(SCHAR_MAX) == 0x7fff
> +typedef signed char __int16_t;
> +typedef unsigned char __uint16_t;
> +#define ___int16_t_defined 1
> +#endif
> +
> +#if ___int16_t_defined
> +typedef __int16_t __int_least16_t;
> +typedef __uint16_t __uint_least16_t;
> +#define ___int_least16_t_defined 1
> +
> +#if !___int8_t_defined
> +typedef __int16_t __int_least8_t;
> +typedef __uint16_t __uint_least8_t;
> +#define ___int_least8_t_defined 1
> +#endif
> +#endif
> +
> +#if __EXP(INT_MAX) == 0x7fffffffL
> +typedef signed int __int32_t;
> +typedef unsigned int __uint32_t;
> +#define ___int32_t_defined 1
> +#elif __EXP(LONG_MAX) == 0x7fffffffL
> +typedef signed long __int32_t;
> +typedef unsigned long __uint32_t;
> +#define ___int32_t_defined 1
> +#elif __EXP(SHRT_MAX) == 0x7fffffffL
> +typedef signed short __int32_t;
> +typedef unsigned short __uint32_t;
> +#define ___int32_t_defined 1
> +#elif __EXP(SCHAR_MAX) == 0x7fffffffL
> +typedef signed char __int32_t;
> +typedef unsigned char __uint32_t;
> +#define ___int32_t_defined 1
> +#endif
> +
> +#if ___int32_t_defined
> +typedef __int32_t __int_least32_t;
> +typedef __uint32_t __uint_least32_t;
> +#define ___int_least32_t_defined 1
> +
> +#if !___int8_t_defined
> +typedef __int32_t __int_least8_t;
> +typedef __uint32_t __uint_least8_t;
> +#define ___int_least8_t_defined 1
> +#endif
> +#if !___int16_t_defined
> +typedef __int32_t __int_least16_t;
> +typedef __uint32_t __uint_least16_t;
> +#define ___int_least16_t_defined 1
> +#endif
> +#endif
> +
> +#if __EXP(LONG_MAX) > 0x7fffffff
> +typedef signed long __int64_t;
> +typedef unsigned long __uint64_t;
> +#define ___int64_t_defined 1
> +
> +/* GCC has __LONG_LONG_MAX__ */
> +#elif defined(__LONG_LONG_MAX__) && (__LONG_LONG_MAX__ > 0x7fffffff)
> +typedef signed long long __int64_t;
> +typedef unsigned long long __uint64_t;
> +#define ___int64_t_defined 1
> +
> +/* POSIX mandates LLONG_MAX in <limits.h> */
> +#elif defined(LLONG_MAX) && (LLONG_MAX > 0x7fffffff)
> +typedef signed long long __int64_t;
> +typedef unsigned long long __uint64_t;
> +#define ___int64_t_defined 1
> +
> +#elif __EXP(INT_MAX) > 0x7fffffff
> +typedef signed int __int64_t;
> +typedef unsigned int __uint64_t;
> +#define ___int64_t_defined 1
> +#endif
> +
> +#undef __EXP
> +
> +#ifdef __cplusplus
> +}
> +#endif
> +
> +#endif /* _MACHINE__DEFAULT_TYPES_H */
> Index: push-sdk3-patches-quilt-base/newlib/libc/include/machine/_types.h
> ===================================================================
> --- push-sdk3-patches-quilt-base.orig/newlib/libc/include/machine/_types.h
> +++ push-sdk3-patches-quilt-base/newlib/libc/include/machine/_types.h
> @@ -4,118 +4,5 @@
>
> #ifndef _MACHINE__TYPES_H
> #define _MACHINE__TYPES_H
> -
> -#ifdef __cplusplus
> -extern "C" {
> -#endif
> -
> -/*
> - * Guess on types by examining *_MIN / *_MAX defines.
> - */
> -#if defined(__GNUC__) && (__GNUC__ >= 3 ) \
> - && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ > 2 )
> -/* GCC >= 3.3.0 has __<val>__ implicitly defined. */
> -#define __EXP(x) __##x##__
> -#else
> -/* Fall back to POSIX versions from <limits.h> */
> -#define __EXP(x) x
> -#include <limits.h>
> -#endif
> -
> -#if __EXP(SCHAR_MAX) == 0x7f
> -typedef signed char __int8_t ;
> -typedef unsigned char __uint8_t ;
> -#define ___int8_t_defined 1
> -#endif
> -
> -#if __EXP(INT_MAX) == 0x7fff
> -typedef signed int __int16_t;
> -typedef unsigned int __uint16_t;
> -#define ___int16_t_defined 1
> -#elif __EXP(SHRT_MAX) == 0x7fff
> -typedef signed short __int16_t;
> -typedef unsigned short __uint16_t;
> -#define ___int16_t_defined 1
> -#elif __EXP(SCHAR_MAX) == 0x7fff
> -typedef signed char __int16_t;
> -typedef unsigned char __uint16_t;
> -#define ___int16_t_defined 1
> +#include <machine/_default_types.h>
> #endif
> -
> -#if ___int16_t_defined
> -typedef __int16_t __int_least16_t;
> -typedef __uint16_t __uint_least16_t;
> -#define ___int_least16_t_defined 1
> -
> -#if !___int8_t_defined
> -typedef __int16_t __int_least8_t;
> -typedef __uint16_t __uint_least8_t;
> -#define ___int_least8_t_defined 1
> -#endif
> -#endif
> -
> -#if __EXP(INT_MAX) == 0x7fffffffL
> -typedef signed int __int32_t;
> -typedef unsigned int __uint32_t;
> -#define ___int32_t_defined 1
> -#elif __EXP(LONG_MAX) == 0x7fffffffL
> -typedef signed long __int32_t;
> -typedef unsigned long __uint32_t;
> -#define ___int32_t_defined 1
> -#elif __EXP(SHRT_MAX) == 0x7fffffffL
> -typedef signed short __int32_t;
> -typedef unsigned short __uint32_t;
> -#define ___int32_t_defined 1
> -#elif __EXP(SCHAR_MAX) == 0x7fffffffL
> -typedef signed char __int32_t;
> -typedef unsigned char __uint32_t;
> -#define ___int32_t_defined 1
> -#endif
> -
> -#if ___int32_t_defined
> -typedef __int32_t __int_least32_t;
> -typedef __uint32_t __uint_least32_t;
> -#define ___int_least32_t_defined 1
> -
> -#if !___int8_t_defined
> -typedef __int32_t __int_least8_t;
> -typedef __uint32_t __uint_least8_t;
> -#define ___int_least8_t_defined 1
> -#endif
> -#if !___int16_t_defined
> -typedef __int32_t __int_least16_t;
> -typedef __uint32_t __uint_least16_t;
> -#define ___int_least16_t_defined 1
> -#endif
> -#endif
> -
> -#if __EXP(LONG_MAX) > 0x7fffffff
> -typedef signed long __int64_t;
> -typedef unsigned long __uint64_t;
> -#define ___int64_t_defined 1
> -
> -/* GCC has __LONG_LONG_MAX__ */
> -#elif defined(__LONG_LONG_MAX__) && (__LONG_LONG_MAX__ > 0x7fffffff)
> -typedef signed long long __int64_t;
> -typedef unsigned long long __uint64_t;
> -#define ___int64_t_defined 1
> -
> -/* POSIX mandates LLONG_MAX in <limits.h> */
> -#elif defined(LLONG_MAX) && (LLONG_MAX > 0x7fffffff)
> -typedef signed long long __int64_t;
> -typedef unsigned long long __uint64_t;
> -#define ___int64_t_defined 1
> -
> -#elif __EXP(INT_MAX) > 0x7fffffff
> -typedef signed int __int64_t;
> -typedef unsigned int __uint64_t;
> -#define ___int64_t_defined 1
> -#endif
> -
> -#undef __EXP
> -
> -#ifdef __cplusplus
> -}
> -#endif
> -
> -#endif /* _MACHINE__TYPES_H */
> Index: push-sdk3-patches-quilt-base/newlib/libc/include/sys/_types.h
> ===================================================================
> --- push-sdk3-patches-quilt-base.orig/newlib/libc/include/sys/_types.h
> +++ push-sdk3-patches-quilt-base/newlib/libc/include/sys/_types.h
> @@ -9,11 +9,27 @@
> #ifndef _SYS__TYPES_H
> #define _SYS__TYPES_H
>
> +#include <machine/_types.h>
> #include <sys/lock.h>
>
> typedef long _off_t;
> __extension__ typedef long long _off64_t;
>
> +/*
> + * We need fpos_t for the following, but it doesn't have a leading "_",
> + * so we use _fpos_t instead.
> + */
> +#ifndef __FPOS_T_DEFINED
> +typedef long _fpos_t; /* XXX must match off_t in <sys/types.h> */
> + /* (and must be `long' for now) */
> +#endif
> +
> +#ifdef __LARGE64_FILES
> +#ifndef __FPOS64_T_DEFINED
> +typedef _off64_t _fpos64_t;
> +#endif
> +#endif
> +
> #if defined(__INT_MAX__) && __INT_MAX__ == 2147483647
> typedef int _ssize_t;
> #else
> Index: push-sdk3-patches-quilt-base/newlib/libc/machine/spu/machine/_types.h
> ===================================================================
> --- /dev/null
> +++ push-sdk3-patches-quilt-base/newlib/libc/machine/spu/machine/_types.h
> @@ -0,0 +1,52 @@
> +/*
> + Copyright 2007
> + International Business Machines Corporation,
> + Sony Computer Entertainment, Incorporated,
> + Toshiba Corporation,
> +
> + All rights reserved.
> +
> + Redistribution and use in source and binary forms, with or without
> + modification, are permitted provided that the following conditions are met:
> +
> + * Redistributions of source code must retain the above copyright notice,
> + this list of conditions and the following disclaimer.
> + * Redistributions in binary form must reproduce the above copyright
> + notice, this list of conditions and the following disclaimer in the
> + documentation and/or other materials provided with the distribution.
> + * Neither the names of the copyright holders nor the names of their
> + contributors may be used to endorse or promote products derived from
> + this software without specific prior written permission.
> +
> + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
> + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
> + TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
> + PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
> + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
> + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
> + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
> + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
> + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
> + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
> + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> +*/
> +
> +#ifndef _MACHINE__TYPES_H
> +#define _MACHINE__TYPES_H
> +
> +#include <machine/_default_types.h>
> +
> +/*
> + * fpos_t large enough for either 32 or 64 bit ppc glibc fpos_t.
> + */
> +#define __FPOS_T_DEFINED
> +typedef struct {
> + char __pos[16];
> +} _fpos_t;
> +
> +#ifdef __LARGE64_FILES
> +#define __FPOS64_T_DEFINED
> +typedef _fpos_t _fpos64_t;
> +#endif
> +
> +#endif /* _MACHINE__TYPES_H */
>
More information about the Newlib
mailing list