g_value_peek_pointer weirdness
- From: Sheldon Simms <wsxyz6294 yahoo com>
- To: gtk-devel-list gnome org
- Subject: g_value_peek_pointer weirdness
- Date: Mon, 15 Dec 2003 23:46:53 -0800 (PST)
I'm reading code from glib 2.3.1
In gvalue.c there are the following two functions:
158 gboolean
159 g_value_fits_pointer (const GValue *value)
160 {
161 GTypeValueTable *value_table;
162
163 g_return_val_if_fail (G_IS_VALUE (value),
FALSE);
164
165 value_table = g_type_value_table_peek
(G_VALUE_TYPE (value));
166
167 return value_table->value_peek_pointer != NULL;
168 }
169
170 gpointer
171 g_value_peek_pointer (const GValue *value)
172 {
173 GTypeValueTable *value_table;
174
175 g_return_val_if_fail (G_IS_VALUE (value), NULL);
176
177 value_table = g_type_value_table_peek
(G_VALUE_TYPE (value));
178 if (!value_table->value_peek_pointer)
179 g_return_val_if_fail (g_value_fits_pointer
(value) == TRUE, NULL);
180
181 return value_table->value_peek_pointer (value);
182 }
It seems to me that lines 178 and 179 are wrong. If
there is no function
value_peek_pointer for this value type, then how does
it help anything if
g_value_fits_pointer() were to return TRUE?
value_peek_pointer would still
be a null pointer and cause a crash at line 181.
Of course, I know that value_peek_pointer would still
be a null pointer
primarily because I can see the implementation of
g_value_fits_pointer().
However, even if I didn't know the implementation of
g_value_fits_pointer(),
it is not reasonable to assume that
g_value_fits_pointer() would fill
value_peek_pointer with a valid pointer. Why would a
predicate do that?
And how would it know what function's address should
go there? It doesn't
have any more information than g_value_peek_pointer()
does.
Since I do know know the implementation of
g_value_fits_pointer(), however,
I know that everything will be ok; because when
value_peek_pointer is a null
pointer, g_value_fits_pointer() always return FALSE,
and cause
g_value_peek_pointer() to return NULL. But in that
case, why not just do
this:
178 if (!value_table->value_peek_pointer)
179 return NULL;
180
181 return value_table->value_peek_pointer (value);
-Sheldon
__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]