Re: Moving to pointer-sized GType?
- From: Tim Janik <timj gtk org>
- To: Owen Taylor <otaylor redhat com>
- Cc: Gtk+ Developers <gtk-devel-list gnome org>, Dan Winship <danw ximian com>, Alex Larsson <alexl redhat com>, Hacking Gnomes <gnome-hackers gnome org>, GNOME MList <gnome-list gnome org>
- Subject: Re: Moving to pointer-sized GType?
- Date: Tue, 18 Sep 2001 18:33:11 +0200 (CEST)
On 18 Sep 2001, Owen Taylor wrote:
> Tim Janik <timj gtk org> writes:
> > - g_type_name(rand()) _must_ continue to work, as that's the recommended
> > way to figure whether a type id is at all valid (it just returns NULL
> > silently, for invalid type ids). so for this, we'll have to do an extra
> > lock and keep track of valid pointers to figure invalid things passed in.
>
> This is no more of a valid operation than:
>
> gtk_widget_show ((GtkWidget *)rand());
nope, since gtk_widegt_show() is not recommended to figure whether a
widget pointer is a valid pointer ;)
> The only reason why I can think of wanting to this to not segfault
> is for 'invalid cast from (Unknown) to GtkWidget' style warnings,
> but we will get a segfault there anyways before we go to
> print the name, and we currently get a segfault quickly after
> such warnings in most cases.
>
> g_type_name() may be semi-performance critical in usages like
> language bindings, and I'd rather not make it a crawlingly slow
> to try and avoid segfaults on invalid arguments.
>
> If you _really_ are worried about this, what I would suggest
> is putting a magic value at the start of GTypeNode structures
> which should allow you to catch invalid values with high
> probability.
that is not good enough, we can already segfault when dereferencing
such a thing, and basically needs a function that returns
is_registered_type_id(num). that's e.g. for things like figuring whether
a certain type has already been registered when you're about to register
a fixed type id, or for g_return_if_fail() in functions that take
type ids.
> (Remember, we don't have 100% certainty currently, since a random
> value can accidentally be a valid type.)
g_type_name(id)!=NULL is a 100% correct check to figure whether id is
an already registered type id, and is actually recommended as such
curently.
>
> Regards,
> Owen
>
---
ciaoTJ
_______________________________________________
gnome-hackers mailing list
gnome-hackers gnome org
http://mail.gnome.org/mailman/listinfo/gnome-hackers
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]