Re: no more GTK_CHECK_CAST in newly written code?



Hi,

Kang Jeong-Hee <Keizi mail co kr> writes:

> I've found gtktypeutils.h define GTK_CHECK_CAST with comment of
> 	/* glib macro wrappers (compatibility) */.
> is that meaning I'd better not to use SOME_CHECK_CAST, but to use directly G_TYPE_CHECK_INSTANCE_CAST?
> 
> for example, GStreamer do not use GST_CHECK_CAST, refer directly to G_TYPE_...
> """
> #define GST_OBJECT_CAST(obj)            ((GstObject*)(obj))
> #define GST_OBJECT_CLASS_CAST(klass)    ((GstObjectClass*)(klass))
> 
> #ifdef GST_TYPE_PARANOID
> # define GST_OBJECT(obj)                (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_OBJECT, GstObject))
> # define GST_OBJECT_CLASS(klass)        (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_OBJECT, GstObjectClass))
> #else
> # define GST_OBJECT                     GST_OBJECT_CAST
> # define GST_OBJECT_CLASS               GST_OBJECT_CLASS_CAST
> #endif
> """
> 
> that form of definition is new GTK+-2.x stlye?

Some of the macros changed their name since the object system is now
independent from GTK+ and lives in GObject which is part of GLib.
However this looks pretty much GStreamer-specific. Normally you'd
write something like this:

#define GIMP_TYPE_IMAGE            (gimp_image_get_type ())
#define GIMP_IMAGE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_IMAGE, GimpImage))
#define GIMP_IMAGE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_IMAGE, GimpImageClass))
#define GIMP_IS_IMAGE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_IMAGE))
#define GIMP_IS_IMAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_IMAGE))
#define GIMP_IMAGE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_IMAGE, GimpImageClass))


I don't think it makes sense to introduce things like GST_TYPE_PARANOID
to switch expensive type-checking casts on and off since the same effect
can be achieved by using G_DISABLE_CHECKS as provided by Glib.


Salut, Sven



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