Questioning non-NULL boxed types



hi all,

currently we have the behaviour:

GValue value = { 0, };
gpointer boxed;

g_value_init (&value, {G|GDK|GTK}_TYPE_<boxedtype>);
g_value_set_boxed (&value, NULL); /* this line could be omitted */
boxed = g_value_get_boxed (value);

with boxed == NULL, for nearly all boxed types, except for the boxed types
G_TYPE_GSTRING and G_TYPE_VALUE_ARRAY. for GString and GValueArray, boxed
will contain either a GString with 0 length or a GValueArray with 0 elements.

this is achived by the default value initializers of G_TYPE_GSTRING and
G_TYPE_VALUE_ARRAY automatically supplying default 0-length structures.

the idea behind this is to allow value types to be created that will never
be NULL, but always be defined in some default 0-setup, e.g. for LBs that
would want to map GString onto strings or GValueArray onto arrays and
didn't allow for "undefined" or "NULL" values thereof.

this behaviour was implemented for GString and GValueArray mostly as a test
case for value initializers. i'm now questioning whether we want to keep
that behaviour, the drawbacks/pros i see are:

- not allowing NULL is slightly inefficient in setups like:
  g_value_init (&value, G_TYPE_GSTRING);
  g_value_set_boxed (&value, my_gstring);
  since an intermediate 0-length GString is created at g_value_init() time
- for languages that suppot NULL strings/arrays etc, this behaviour implies
  information loss, since a NULL GString != 0length GString, same for
  GValueArray
+ LBs that can't handle NULL strings or arrays don't need to put additional
  logic into their glue code
+ LBs that can't handle NULL strings or arrays don't loose information over
  the C API if NULL is not a representable string/array in GValue

of course this all assumes that there are LBs out there that have problems
representing NULL strings/arrays, so reports thereof would help in making
the final decision over this, e.g. perl wouldn't be an issue as it could
map things as:

my $mystring = "n-length string";
my $mystring = ""; # 0-length string
undef $mystring;   # NULL-string

i'm not so sure about arrays (i'm pretty perl illiterate ;)

so comments, especially from LB authors, are apprechiated.

(also note that our fundamental type for strings, i.e. G_TYPE_STRING, _does_
allow for NULL and "" strings)

---
ciaoTJ





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