X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=glib%2Fgtypes.h;h=0e73b40b93999063a9649c66f3dd90f0a78be790;hb=4454b815367831a71b1ae00b0182b5b389a78df2;hp=27597b700667b1996f81a8a1bde4c26bdb1b9ec6;hpb=f96f290c6332e5b48cee8407d2f917ae9e6adbed;p=platform%2Fupstream%2Fglib.git diff --git a/glib/gtypes.h b/glib/gtypes.h index 27597b7..0e73b40 100644 --- a/glib/gtypes.h +++ b/glib/gtypes.h @@ -12,22 +12,27 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * License along with this library; if not, see . */ /* * Modified by the GLib Team and others 1997-2000. See the AUTHORS * file for a list of people on the GLib Team. See the ChangeLog * files for a list of changes. These files are distributed with - * GLib at ftp://ftp.gtk.org/pub/gtk/. + * GLib at ftp://ftp.gtk.org/pub/gtk/. */ #ifndef __G_TYPES_H__ #define __G_TYPES_H__ +#if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION) +#error "Only can be included directly." +#endif + #include +#include +#include +#include G_BEGIN_DECLS @@ -52,16 +57,22 @@ typedef unsigned int guint; typedef float gfloat; typedef double gdouble; -/* HAVE_LONG_DOUBLE doesn't work correctly on all platforms. - * Since gldouble isn't used anywhere, just disable it for now */ +/* Define min and max constants for the fixed size numerical types */ +#define G_MININT8 ((gint8) 0x80) +#define G_MAXINT8 ((gint8) 0x7f) +#define G_MAXUINT8 ((guint8) 0xff) + +#define G_MININT16 ((gint16) 0x8000) +#define G_MAXINT16 ((gint16) 0x7fff) +#define G_MAXUINT16 ((guint16) 0xffff) + +#define G_MININT32 ((gint32) 0x80000000) +#define G_MAXINT32 ((gint32) 0x7fffffff) +#define G_MAXUINT32 ((guint32) 0xffffffff) -#if 0 -#ifdef HAVE_LONG_DOUBLE -typedef long double gldouble; -#else /* HAVE_LONG_DOUBLE */ -typedef double gldouble; -#endif /* HAVE_LONG_DOUBLE */ -#endif /* 0 */ +#define G_MININT64 ((gint64) G_GINT64_CONSTANT(0x8000000000000000)) +#define G_MAXINT64 G_GINT64_CONSTANT(0x7fffffffffffffff) +#define G_MAXUINT64 G_GINT64_CONSTANT(0xffffffffffffffffU) typedef void* gpointer; typedef const void *gconstpointer; @@ -80,18 +91,50 @@ typedef guint (*GHashFunc) (gconstpointer key); typedef void (*GHFunc) (gpointer key, gpointer value, gpointer user_data); + +/** + * GFreeFunc: + * @data: a data pointer + * + * Declares a type of function which takes an arbitrary + * data pointer argument and has no return value. It is + * not currently used in GLib or GTK+. + */ typedef void (*GFreeFunc) (gpointer data); +/** + * GTranslateFunc: + * @str: the untranslated string + * @data: user data specified when installing the function, e.g. + * in g_option_group_set_translate_func() + * + * The type of functions which are used to translate user-visible + * strings, for output. + * + * Returns: a translation of the string for the current locale. + * The returned string is owned by GLib and must not be freed. + */ +typedef const gchar * (*GTranslateFunc) (const gchar *str, + gpointer data); + + /* Define some mathematical constants that aren't available * symbolically in some strict ISO C implementations. + * + * Note that the large number of digits used in these definitions + * doesn't imply that GLib or current computers in general would be + * able to handle floating point numbers with an accuracy like this. + * It's mostly an exercise in futility and future proofing. For + * extended precision floating point support, look somewhere else + * than GLib. */ -#define G_E 2.7182818284590452354E0 -#define G_LN2 6.9314718055994530942E-1 -#define G_LN10 2.3025850929940456840E0 -#define G_PI 3.14159265358979323846E0 -#define G_PI_2 1.57079632679489661923E0 -#define G_PI_4 0.78539816339744830962E0 -#define G_SQRT2 1.4142135623730950488E0 +#define G_E 2.7182818284590452353602874713526624977572470937000 +#define G_LN2 0.69314718055994530941723212145817656807550013436026 +#define G_LN10 2.3025850929940456840179914546843642076011014886288 +#define G_PI 3.1415926535897932384626433832795028841971693993751 +#define G_PI_2 1.5707963267948966192313216916397514420985846996876 +#define G_PI_4 0.78539816339744830961566084581987572104929234984378 +#define G_SQRT2 1.4142135623730950488016887242096980785696718753769 /* Portable endian checks and conversions * @@ -106,99 +149,186 @@ typedef void (*GFreeFunc) (gpointer data); /* Basic bit swapping functions */ #define GUINT16_SWAP_LE_BE_CONSTANT(val) ((guint16) ( \ - (((guint16) (val) & (guint16) 0x00ffU) << 8) | \ - (((guint16) (val) & (guint16) 0xff00U) >> 8))) + (guint16) ((guint16) (val) >> 8) | \ + (guint16) ((guint16) (val) << 8))) + #define GUINT32_SWAP_LE_BE_CONSTANT(val) ((guint32) ( \ (((guint32) (val) & (guint32) 0x000000ffU) << 24) | \ (((guint32) (val) & (guint32) 0x0000ff00U) << 8) | \ (((guint32) (val) & (guint32) 0x00ff0000U) >> 8) | \ (((guint32) (val) & (guint32) 0xff000000U) >> 24))) -/* Intel specific stuff for speed - */ -#if defined (__i386__) && defined (__GNUC__) && __GNUC__ >= 2 -# define GUINT16_SWAP_LE_BE_X86(val) \ - (G_GNUC_EXTENSION \ - ({ register guint16 __v; \ - if (__builtin_constant_p (val)) \ - __v = GUINT16_SWAP_LE_BE_CONSTANT (val); \ - else \ - __asm__ __const__ ("rorw $8, %w0" \ - : "=r" (__v) \ - : "0" ((guint16) (val))); \ - __v; })) -# define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_X86 (val)) -# if !defined(__i486__) && !defined(__i586__) \ - && !defined(__pentium__) && !defined(__i686__) && !defined(__pentiumpro__) -# define GUINT32_SWAP_LE_BE_X86(val) \ - (G_GNUC_EXTENSION \ - ({ register guint32 __v; \ - if (__builtin_constant_p (val)) \ - __v = GUINT32_SWAP_LE_BE_CONSTANT (val); \ - else \ - __asm__ __const__ ("rorw $8, %w0\n\t" \ - "rorl $16, %0\n\t" \ - "rorw $8, %w0" \ - : "=r" (__v) \ - : "0" ((guint32) (val))); \ - __v; })) -# else /* 486 and higher has bswap */ -# define GUINT32_SWAP_LE_BE_X86(val) \ - (G_GNUC_EXTENSION \ - ({ register guint32 __v; \ - if (__builtin_constant_p (val)) \ - __v = GUINT32_SWAP_LE_BE_CONSTANT (val); \ - else \ - __asm__ __const__ ("bswap %0" \ - : "=r" (__v) \ - : "0" ((guint32) (val))); \ - __v; })) -# endif /* processor specific 32-bit stuff */ -# define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_X86 (val)) -#else /* !__i386__ */ -# define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_CONSTANT (val)) -# define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_CONSTANT (val)) -#endif /* __i386__ */ - -#ifdef G_HAVE_GINT64 -# define GUINT64_SWAP_LE_BE_CONSTANT(val) ((guint64) ( \ +#define GUINT64_SWAP_LE_BE_CONSTANT(val) ((guint64) ( \ (((guint64) (val) & \ - (guint64) G_GINT64_CONSTANT(0x00000000000000ffU)) << 56) | \ + (guint64) G_GINT64_CONSTANT (0x00000000000000ffU)) << 56) | \ (((guint64) (val) & \ - (guint64) G_GINT64_CONSTANT(0x000000000000ff00U)) << 40) | \ + (guint64) G_GINT64_CONSTANT (0x000000000000ff00U)) << 40) | \ (((guint64) (val) & \ - (guint64) G_GINT64_CONSTANT(0x0000000000ff0000U)) << 24) | \ + (guint64) G_GINT64_CONSTANT (0x0000000000ff0000U)) << 24) | \ (((guint64) (val) & \ - (guint64) G_GINT64_CONSTANT(0x00000000ff000000U)) << 8) | \ + (guint64) G_GINT64_CONSTANT (0x00000000ff000000U)) << 8) | \ (((guint64) (val) & \ - (guint64) G_GINT64_CONSTANT(0x000000ff00000000U)) >> 8) | \ + (guint64) G_GINT64_CONSTANT (0x000000ff00000000U)) >> 8) | \ (((guint64) (val) & \ - (guint64) G_GINT64_CONSTANT(0x0000ff0000000000U)) >> 24) | \ + (guint64) G_GINT64_CONSTANT (0x0000ff0000000000U)) >> 24) | \ (((guint64) (val) & \ - (guint64) G_GINT64_CONSTANT(0x00ff000000000000U)) >> 40) | \ + (guint64) G_GINT64_CONSTANT (0x00ff000000000000U)) >> 40) | \ (((guint64) (val) & \ - (guint64) G_GINT64_CONSTANT(0xff00000000000000U)) >> 56))) -# if defined (__i386__) && defined (__GNUC__) && __GNUC__ >= 2 -# define GUINT64_SWAP_LE_BE_X86(val) \ - (__extension__ \ - ({ union { guint64 __ll; \ - guint32 __l[2]; } __r; \ - if (__builtin_constant_p (val)) \ - __r.__ll = GUINT64_SWAP_LE_BE_CONSTANT (val); \ + (guint64) G_GINT64_CONSTANT (0xff00000000000000U)) >> 56))) + +/* Arch specific stuff for speed + */ +#if defined (__GNUC__) && (__GNUC__ >= 2) && defined (__OPTIMIZE__) + +# if __GNUC__ >= 4 && defined (__GNUC_MINOR__) && __GNUC_MINOR__ >= 3 +# define GUINT32_SWAP_LE_BE(val) ((guint32) __builtin_bswap32 ((gint32) (val))) +# define GUINT64_SWAP_LE_BE(val) ((guint64) __builtin_bswap64 ((gint64) (val))) +# endif + +# if defined (__i386__) +# define GUINT16_SWAP_LE_BE_IA32(val) \ + (G_GNUC_EXTENSION \ + ({ guint16 __v, __x = ((guint16) (val)); \ + if (__builtin_constant_p (__x)) \ + __v = GUINT16_SWAP_LE_BE_CONSTANT (__x); \ + else \ + __asm__ ("rorw $8, %w0" \ + : "=r" (__v) \ + : "0" (__x) \ + : "cc"); \ + __v; })) +# if !defined (__i486__) && !defined (__i586__) \ + && !defined (__pentium__) && !defined (__i686__) \ + && !defined (__pentiumpro__) && !defined (__pentium4__) +# define GUINT32_SWAP_LE_BE_IA32(val) \ + (G_GNUC_EXTENSION \ + ({ guint32 __v, __x = ((guint32) (val)); \ + if (__builtin_constant_p (__x)) \ + __v = GUINT32_SWAP_LE_BE_CONSTANT (__x); \ + else \ + __asm__ ("rorw $8, %w0\n\t" \ + "rorl $16, %0\n\t" \ + "rorw $8, %w0" \ + : "=r" (__v) \ + : "0" (__x) \ + : "cc"); \ + __v; })) +# else /* 486 and higher has bswap */ +# define GUINT32_SWAP_LE_BE_IA32(val) \ + (G_GNUC_EXTENSION \ + ({ guint32 __v, __x = ((guint32) (val)); \ + if (__builtin_constant_p (__x)) \ + __v = GUINT32_SWAP_LE_BE_CONSTANT (__x); \ + else \ + __asm__ ("bswap %0" \ + : "=r" (__v) \ + : "0" (__x)); \ + __v; })) +# endif /* processor specific 32-bit stuff */ +# define GUINT64_SWAP_LE_BE_IA32(val) \ + (G_GNUC_EXTENSION \ + ({ union { guint64 __ll; \ + guint32 __l[2]; } __w, __r; \ + __w.__ll = ((guint64) (val)); \ + if (__builtin_constant_p (__w.__ll)) \ + __r.__ll = GUINT64_SWAP_LE_BE_CONSTANT (__w.__ll); \ + else \ + { \ + __r.__l[0] = GUINT32_SWAP_LE_BE (__w.__l[1]); \ + __r.__l[1] = GUINT32_SWAP_LE_BE (__w.__l[0]); \ + } \ + __r.__ll; })) + /* Possibly just use the constant version and let gcc figure it out? */ +# define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_IA32 (val)) +# ifndef GUINT32_SWAP_LE_BE +# define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_IA32 (val)) +# endif +# ifndef GUINT64_SWAP_LE_BE +# define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_IA32 (val)) +# endif +# elif defined (__ia64__) +# define GUINT16_SWAP_LE_BE_IA64(val) \ + (G_GNUC_EXTENSION \ + ({ guint16 __v, __x = ((guint16) (val)); \ + if (__builtin_constant_p (__x)) \ + __v = GUINT16_SWAP_LE_BE_CONSTANT (__x); \ + else \ + __asm__ __volatile__ ("shl %0 = %1, 48 ;;" \ + "mux1 %0 = %0, @rev ;;" \ + : "=r" (__v) \ + : "r" (__x)); \ + __v; })) +# define GUINT32_SWAP_LE_BE_IA64(val) \ + (G_GNUC_EXTENSION \ + ({ guint32 __v, __x = ((guint32) (val)); \ + if (__builtin_constant_p (__x)) \ + __v = GUINT32_SWAP_LE_BE_CONSTANT (__x); \ else \ - { \ - union { guint64 __ll; \ - guint32 __l[2]; } __w; \ - __w.__ll = ((guint64) val); \ - __r.__l[0] = GUINT32_SWAP_LE_BE (__w.__l[1]); \ - __r.__l[1] = GUINT32_SWAP_LE_BE (__w.__l[0]); \ - } \ - __r.__ll; })) -# define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_X86 (val)) -# else /* !__i386__ */ -# define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_CONSTANT(val)) + __asm__ __volatile__ ("shl %0 = %1, 32 ;;" \ + "mux1 %0 = %0, @rev ;;" \ + : "=r" (__v) \ + : "r" (__x)); \ + __v; })) +# define GUINT64_SWAP_LE_BE_IA64(val) \ + (G_GNUC_EXTENSION \ + ({ guint64 __v, __x = ((guint64) (val)); \ + if (__builtin_constant_p (__x)) \ + __v = GUINT64_SWAP_LE_BE_CONSTANT (__x); \ + else \ + __asm__ __volatile__ ("mux1 %0 = %1, @rev ;;" \ + : "=r" (__v) \ + : "r" (__x)); \ + __v; })) +# define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_IA64 (val)) +# ifndef GUINT32_SWAP_LE_BE +# define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_IA64 (val)) +# endif +# ifndef GUINT64_SWAP_LE_BE +# define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_IA64 (val)) +# endif +# elif defined (__x86_64__) +# define GUINT32_SWAP_LE_BE_X86_64(val) \ + (G_GNUC_EXTENSION \ + ({ guint32 __v, __x = ((guint32) (val)); \ + if (__builtin_constant_p (__x)) \ + __v = GUINT32_SWAP_LE_BE_CONSTANT (__x); \ + else \ + __asm__ ("bswapl %0" \ + : "=r" (__v) \ + : "0" (__x)); \ + __v; })) +# define GUINT64_SWAP_LE_BE_X86_64(val) \ + (G_GNUC_EXTENSION \ + ({ guint64 __v, __x = ((guint64) (val)); \ + if (__builtin_constant_p (__x)) \ + __v = GUINT64_SWAP_LE_BE_CONSTANT (__x); \ + else \ + __asm__ ("bswapq %0" \ + : "=r" (__v) \ + : "0" (__x)); \ + __v; })) + /* gcc seems to figure out optimal code for this on its own */ +# define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_CONSTANT (val)) +# ifndef GUINT32_SWAP_LE_BE +# define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_X86_64 (val)) +# endif +# ifndef GUINT64_SWAP_LE_BE +# define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_X86_64 (val)) +# endif +# else /* generic gcc */ +# define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_CONSTANT (val)) +# ifndef GUINT32_SWAP_LE_BE +# define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_CONSTANT (val)) +# endif +# ifndef GUINT64_SWAP_LE_BE +# define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_CONSTANT (val)) +# endif # endif -#endif +#else /* generic */ +# define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_CONSTANT (val)) +# define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_CONSTANT (val)) +# define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_CONSTANT (val)) +#endif /* generic */ #define GUINT16_SWAP_LE_PDP(val) ((guint16) (val)) #define GUINT16_SWAP_BE_PDP(val) (GUINT16_SWAP_LE_BE (val)) @@ -221,12 +351,10 @@ typedef void (*GFreeFunc) (gpointer data); #define GINT32_FROM_BE(val) (GINT32_TO_BE (val)) #define GUINT32_FROM_BE(val) (GUINT32_TO_BE (val)) -#ifdef G_HAVE_GINT64 #define GINT64_FROM_LE(val) (GINT64_TO_LE (val)) #define GUINT64_FROM_LE(val) (GUINT64_TO_LE (val)) #define GINT64_FROM_BE(val) (GINT64_TO_BE (val)) #define GUINT64_FROM_BE(val) (GUINT64_TO_BE (val)) -#endif #define GLONG_FROM_LE(val) (GLONG_TO_LE (val)) #define GULONG_FROM_LE(val) (GULONG_TO_LE (val)) @@ -238,6 +366,11 @@ typedef void (*GFreeFunc) (gpointer data); #define GINT_FROM_BE(val) (GINT_TO_BE (val)) #define GUINT_FROM_BE(val) (GUINT_TO_BE (val)) +#define GSIZE_FROM_LE(val) (GSIZE_TO_LE (val)) +#define GSSIZE_FROM_LE(val) (GSSIZE_TO_LE (val)) +#define GSIZE_FROM_BE(val) (GSIZE_TO_BE (val)) +#define GSSIZE_FROM_BE(val) (GSSIZE_TO_BE (val)) + /* Portable versions of host-network order stuff */ @@ -267,7 +400,7 @@ typedef union _GDoubleIEEE754 GDoubleIEEE754; typedef union _GFloatIEEE754 GFloatIEEE754; #define G_IEEE754_FLOAT_BIAS (127) #define G_IEEE754_DOUBLE_BIAS (1023) -/* multiply with base2 exponent to get base10 exponent (nomal numbers) */ +/* multiply with base2 exponent to get base10 exponent (normal numbers) */ #define G_LOG_2_BASE_10 (0.30102999566398119521) #if G_BYTE_ORDER == G_LITTLE_ENDIAN union _GFloatIEEE754 @@ -324,7 +457,7 @@ struct _GTimeVal G_END_DECLS /* We prefix variable declarations so they can - * properly get exported in windows dlls. + * properly get exported in Windows DLLs. */ #ifndef GLIB_VAR # ifdef G_PLATFORM_WIN32 @@ -342,9 +475,8 @@ G_END_DECLS # endif /* !GLIB_COMPILATION */ # endif /* !GLIB_STATIC_COMPILATION */ # else /* !G_PLATFORM_WIN32 */ -# define GLIB_VAR extern +# define GLIB_VAR _GLIB_EXTERN # endif /* !G_PLATFORM_WIN32 */ #endif /* GLIB_VAR */ #endif /* __G_TYPES_H__ */ -