Re: GType <=> gpointer



On Tue, Feb 03, 2004 at 12:03:24AM -0500, muppet wrote:
> 
> Here's a little something i stumbled across while debugging a really 
> bizarre gtk2-perl crash on alpha processors.
> 
> 	type = (GType) GPOINTER_TO_UINT
> 			(g_hash_table_lookup (types_by_package, package));
> 
> that code results in an invalid GType on alpha.  that's because:
> 
> 	#define GPOINTER_TO_UINT(p)	((guint) (gulong) (p))
> 
> and
> 
> 	sizeof (GType) == sizeof (gulong)
> 	sizeof (guint) != sizeof (GType)
> 
> thus, the GPOINTER_TO_UINT filter has the effect of stripping the upper 
> 4 bytes off of the GType value, resulting in an invalid GType which 
> later causes Very Bad Things to happen.
> 
> glib seems to jump through some hoops to ensure that a GType is the 
> same size as the platform's pointer (actually, the size of size_t on 
> that platform), but doesn't bother with the relationship to int/uint.
> 
> 
> is it more correct to do
> 
> 	type = (GType) pointer
> 
> than to use the GPOINTER_TO_UINT macro?  should there be a 
> GPOINTER_TO_GTYPE/GTYPE_TO_GPOINTER pair?
> 
> 
> interestingly, the GPOINTER_TO_UINT casts were necessary to get 
> gtk2-perl working correctly on x86_64, and seem to have no ill effect 
> on mips.

Uhm, those casts aren't really correct on x86_64 either (though it will
work in most cases). type = (GType) pointer should work just fine. How
did you come to the conclusion it was required?

-Yosh



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