Re: gtype.h broken for 64-bit



On 25 Nov 2001, Havoc Pennington wrote:

> Hi,
> 
> On 64-bit, sizeof(GType) is 8 but sizeof(GTypeFundamentals) is
> 4. So in this code in gobject.c:
> 
>     g_signal_new ("notify",
>                   G_TYPE_FROM_CLASS (class),
>                   G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE |
>                   G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
>                   G_STRUCT_OFFSET (GObjectClass, notify),
>                   NULL, NULL,
>                   g_cclosure_marshal_VOID__PARAM,
>                   G_TYPE_NONE,
>                   1, G_TYPE_PARAM);
> 
> G_TYPE_PARAM goes through the varargs as 4 bytes, then we collect it
> as 8 bytes, and everything blows up.
> 
> One possible patch is to change the enum to a bunch of macros as
> follows:
> 
>  #define G_TYPE_CHAR ((GType) 3 << G_TYPE_FUNDAMENTAL_SHIFT)
> 
> That patch makes testgruntime work for me again on ia64. There is a
> tiny API change here, which is that you no longer need the enum name
> GTypeFundamentals, but I doubt anyone is using it - GLib itself
> doesn't appear to.
> 
> This is showstopper-ish, so please let me know how to fix as soon as
> you can.

ok, thanks for tracking this down. i'm about to comit the following fix:

> +Sun Nov 25 22:33:32 2001  Tim Janik  <timj gtk org>
> +
> +	* gtype.h: removed enum GTypeFundamentals. use macros
> +	to provide the constant fundamental type IDs, so they
> +	all return numbers of type GType, and not int.
> +	sizeof(GTypeFundamentals) < sizeof(GType) problem reported
> +	and fix sugegsted by Havoc.
> +
> 
> diff -u -u -p -r1.40 gtype.h
> --- gtype.h	2001/11/22 18:55:05	1.40
> +++ gtype.h	2001/11/25 21:37:55
> @@ -31,47 +31,44 @@ G_BEGIN_DECLS
>   */
>  #define G_TYPE_FUNDAMENTAL(type)	(g_type_fundamental (type))
>  #define	G_TYPE_FUNDAMENTAL_MAX		(255 << G_TYPE_FUNDAMENTAL_SHIFT)
> -#define	G_TYPE_FUNDAMENTAL_SHIFT	(2)
> +
> +/* Constant fundamental types,
> + * introduced by g_type_init().
> + */
> +#define G_TYPE_INVALID			G_TYPE_MAKE_FUNDAMENTAL (0)
> +#define G_TYPE_NONE			G_TYPE_MAKE_FUNDAMENTAL (1)
> +#define G_TYPE_INTERFACE		G_TYPE_MAKE_FUNDAMENTAL (2)
> +#define G_TYPE_CHAR			G_TYPE_MAKE_FUNDAMENTAL (3)
> +#define G_TYPE_UCHAR			G_TYPE_MAKE_FUNDAMENTAL (4)
> +#define G_TYPE_BOOLEAN			G_TYPE_MAKE_FUNDAMENTAL (5)
> +#define G_TYPE_INT			G_TYPE_MAKE_FUNDAMENTAL (6)
> +#define G_TYPE_UINT			G_TYPE_MAKE_FUNDAMENTAL (7)
> +#define G_TYPE_LONG			G_TYPE_MAKE_FUNDAMENTAL (8)
> +#define G_TYPE_ULONG			G_TYPE_MAKE_FUNDAMENTAL (9)
> +#define G_TYPE_INT64			G_TYPE_MAKE_FUNDAMENTAL (10)
> +#define G_TYPE_UINT64			G_TYPE_MAKE_FUNDAMENTAL (11)
> +#define G_TYPE_ENUM			G_TYPE_MAKE_FUNDAMENTAL (12)
> +#define G_TYPE_FLAGS			G_TYPE_MAKE_FUNDAMENTAL (13)
> +#define G_TYPE_FLOAT			G_TYPE_MAKE_FUNDAMENTAL (14)
> +#define G_TYPE_DOUBLE			G_TYPE_MAKE_FUNDAMENTAL (15)
> +#define G_TYPE_STRING			G_TYPE_MAKE_FUNDAMENTAL (16)
> +#define G_TYPE_POINTER			G_TYPE_MAKE_FUNDAMENTAL (17)
> +#define G_TYPE_BOXED			G_TYPE_MAKE_FUNDAMENTAL (18)
> +#define G_TYPE_PARAM			G_TYPE_MAKE_FUNDAMENTAL (19)
> +#define G_TYPE_OBJECT			G_TYPE_MAKE_FUNDAMENTAL (20)
>  
>  
> -/* Constant fundamental types
> +/* Reserved fundamental type numbers to create new fundamental
> + * type IDs with G_TYPE_MAKE_FUNDAMENTAL().
> + * Send email to gtk-devel-list redhat com for reservations.
>   */
> -typedef enum    /*< skip >*/
> -{
> -  /* standard types, introduced by g_type_init() */
> -  G_TYPE_INVALID		=  0 << G_TYPE_FUNDAMENTAL_SHIFT,
> -  G_TYPE_NONE			=  1 << G_TYPE_FUNDAMENTAL_SHIFT,
> -  G_TYPE_INTERFACE		=  2 << G_TYPE_FUNDAMENTAL_SHIFT,
> -  
> -  /* GLib type IDs */
> -  G_TYPE_CHAR			=  3 << G_TYPE_FUNDAMENTAL_SHIFT,
> -  G_TYPE_UCHAR			=  4 << G_TYPE_FUNDAMENTAL_SHIFT,
> -  G_TYPE_BOOLEAN		=  5 << G_TYPE_FUNDAMENTAL_SHIFT,
> -  G_TYPE_INT			=  6 << G_TYPE_FUNDAMENTAL_SHIFT,
> -  G_TYPE_UINT			=  7 << G_TYPE_FUNDAMENTAL_SHIFT,
> -  G_TYPE_LONG			=  8 << G_TYPE_FUNDAMENTAL_SHIFT,
> -  G_TYPE_ULONG			=  9 << G_TYPE_FUNDAMENTAL_SHIFT,
> -  G_TYPE_INT64			= 10 << G_TYPE_FUNDAMENTAL_SHIFT,
> -  G_TYPE_UINT64			= 11 << G_TYPE_FUNDAMENTAL_SHIFT,
> -  G_TYPE_ENUM			= 12 << G_TYPE_FUNDAMENTAL_SHIFT,
> -  G_TYPE_FLAGS			= 13 << G_TYPE_FUNDAMENTAL_SHIFT,
> -  G_TYPE_FLOAT			= 14 << G_TYPE_FUNDAMENTAL_SHIFT,
> -  G_TYPE_DOUBLE			= 15 << G_TYPE_FUNDAMENTAL_SHIFT,
> -  G_TYPE_STRING			= 16 << G_TYPE_FUNDAMENTAL_SHIFT,
> -  G_TYPE_POINTER		= 17 << G_TYPE_FUNDAMENTAL_SHIFT,
> -  G_TYPE_BOXED			= 18 << G_TYPE_FUNDAMENTAL_SHIFT,
> -  G_TYPE_PARAM			= 19 << G_TYPE_FUNDAMENTAL_SHIFT,
> -  G_TYPE_OBJECT			= 20 << G_TYPE_FUNDAMENTAL_SHIFT,
> -  
> -  /* reserved fundamental type ids,
> -   * mail gtk-devel-list redhat com for reservations
> -   */
> -  G_TYPE_RESERVED_GLIB_FIRST	= 21 << G_TYPE_FUNDAMENTAL_SHIFT,
> -  G_TYPE_RESERVED_GLIB_LAST	= 31 << G_TYPE_FUNDAMENTAL_SHIFT,
> -  G_TYPE_RESERVED_BSE_FIRST	= 32 << G_TYPE_FUNDAMENTAL_SHIFT,
> -  G_TYPE_RESERVED_BSE_LAST	= 48 << G_TYPE_FUNDAMENTAL_SHIFT,
> -  G_TYPE_RESERVED_USER_FIRST	= 49 << G_TYPE_FUNDAMENTAL_SHIFT
> -} GTypeFundamentals;
> +#define	G_TYPE_FUNDAMENTAL_SHIFT	(2)
> +#define	G_TYPE_MAKE_FUNDAMENTAL(x)	((GType) ((x) << G_TYPE_FUNDAMENTAL_SHIFT))
> +#define G_TYPE_RESERVED_GLIB_FIRST	(21)
> +#define G_TYPE_RESERVED_GLIB_LAST	(31)
> +#define G_TYPE_RESERVED_BSE_FIRST	(32)
> +#define G_TYPE_RESERVED_BSE_LAST	(48)
> +#define G_TYPE_RESERVED_USER_FIRST	(49)
>  
>  
>  /* Type Checking Macros


which does pretty much what you suggested, but also introduces
G_TYPE_MAKE_FUNDAMENTAL() for people to use, if they create
new fundamental types (so we don't run into the same problem
in third-party code).
Cc:-ing gnome-2-0, because of API change involved, but this should
really only affect code which introduces reserved fundamental types,
and that's currently just BSE.

> 
> Havoc
> 

---
ciaoTJ




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]