After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 561099 - initial work on removing is_pointer
initial work on removing is_pointer
Status: RESOLVED OBSOLETE
Product: gobject-introspection
Classification: Platform
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gobject-introspection Maintainer(s)
gobject-introspection Maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2008-11-16 20:10 UTC by Colin Walters
Modified: 2018-02-08 11:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
remove is_pointer (18.95 KB, patch)
2008-11-16 20:11 UTC, Colin Walters
needs-work Details | Review

Description Colin Walters 2008-11-16 20:10:53 UTC
For reasons outlined in http://bugzilla.gnome.org/show_bug.cgi?id=561087 we should remove the is_pointer flag.
Comment 1 Colin Walters 2008-11-16 20:11:47 UTC
Created attachment 122815 [details] [review]
remove is_pointer

Needs work.  Should rename _ANY to _POINTER per owen's comments, and investigate landing this in the next version after all the other struct/array work is in and tested.
Comment 2 Torsten Schoenfeld 2011-08-20 12:26:39 UTC
Without is_pointer, how do you specify that, say, a struct is to be passed by value?  That is, how do you distinguish these functions?

  void foo_by_value (struct blob x);
  void foo_by_ref (struct blob *x);
Comment 3 Torsten Schoenfeld 2011-08-22 22:08:00 UTC
A different use case for is_pointer, on which I now actually depend in the Perl bindings:

To distinguish between arrays containing non-basic types and arrays containing pointers to non-basic types.  That is, the difference between

  GValue *values = g_new (GValue, n);

and

  GValue **values = g_new (GValue*, n);
  values[i] = g_new (GValue, 1);

Or, in GIR format:

  <array c:type="GValue*">
    <type name="GObject.Value" c:type="GValue"/>
  </array>

versus

  <array c:type="GValue**">
    <type name="GObject.Value" c:type="GValue*"/>
  </array>

In the array conversion code, I check for this with

  need_struct_value_semantics =
    !G_TYPE_TAG_IS_BASIC (param_tag) &&
    !g_type_info_is_pointer (param_info);
Comment 4 Colin Walters 2011-08-30 21:37:10 UTC
(In reply to comment #3)

> To distinguish between arrays containing non-basic types and arrays containing
> pointers to non-basic types.  

I call this "flat" versus "not flat" arrays.

I think the right solution here if we agree that is_pointer() is screwed up and broken is to have well-defined rules for whether we expect the array to be flat or not.

An initial set of rules might be:

*) If the array type is between G_TYPE_TAG_BOOLEAN and G_TYPE_TAG_GTYPE (inclusive), the array is flat
*) If the array type is anything else, it must not be flat
Comment 5 Colin Walters 2011-08-30 21:42:34 UTC
(In reply to comment #4)
> (In reply to comment #3)
> 
> > To distinguish between arrays containing non-basic types and arrays containing
> > pointers to non-basic types.  
> 
> I call this "flat" versus "not flat" arrays.

Note that one big intersecting issue here is if we attempt to support "flat" arrays of non-basic types, how do we know how to free them?  Do we always assume that we can free the entire array with g_free()?
Comment 6 Torsten Schoenfeld 2011-08-31 19:12:49 UTC
(In reply to comment #4)
> I think the right solution here if we agree that is_pointer() is screwed up and
> broken is to have well-defined rules for whether we expect the array to be flat
> or not.

I don't quite understand yet what it is exactly that is wrong with is_pointer().  I always viewed it as answering the question: is there an asterisk after the type in the C declaration?  That seems perfectly well-defined and useful to me.  In which cases does it not do the right thing?

Or is it just the name that you take issue with?  But then, the implementation you suggested for is_reference() wouldn't have the semantics I described, would it?  Because something like GValue sometimes is a reference and sometimes not: the "value" argument in gtk_list_store_set_value() is a reference, the element type of the "values" argument in gtk_list_store_set_valuesv() is not.

> An initial set of rules might be:
> 
> *) If the array type is between G_TYPE_TAG_BOOLEAN and G_TYPE_TAG_GTYPE
> (inclusive), the array is flat
> *) If the array type is anything else, it must not be flat

I think the GValue* example cited above violates these rules.  Specific example: gtk_list_store_set_valuesv.  Signature:

void                gtk_list_store_set_valuesv          (GtkListStore *list_store,
                                                         GtkTreeIter *iter,
                                                         gint *columns,
                                                         GValue *values,
                                                         gint n_values);

As most GValue consumers, it expects a flat GValue array.  GI turns this into this:

          <parameter name="values" transfer-ownership="none">
            <doc xml:whitespace="preserve">an array of GValues</doc>
            <array length="3" zero-terminated="0" c:type="GValue*">
              <type name="GObject.Value" c:type="GValue"/>
            </array>
          </parameter>

And calling is_pointer() on the element type gives false, like I expect.

(In reply to comment #5)
> Note that one big intersecting issue here is if we attempt to support "flat"
> arrays of non-basic types, how do we know how to free them?  Do we always
> assume that we can free the entire array with g_free()?

Yeah, that's an issue.  Should there maybe be an annotation "free-func" for all the cases that involve returning raw allocated memory?  We could require it to take exactly one argument and return nothing.
Comment 7 André Klapper 2015-02-07 17:16:11 UTC
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]
Comment 8 GNOME Infrastructure Team 2018-02-08 11:47:06 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/gobject-introspection/issues/9.