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 620170 - GStrv args being interpreted as void*
GStrv args being interpreted as void*
Status: RESOLVED FIXED
Product: gobject-introspection
Classification: Platform
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gobject-introspection Maintainer(s)
gobject-introspection Maintainer(s)
: 616815 619799 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2010-05-31 18:00 UTC by Tomeu Vizoso
Modified: 2015-02-07 17:02 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add a special case for GStrv so it's interpreted as an array of utf8. (5.56 KB, patch)
2010-05-31 18:01 UTC, Tomeu Vizoso
none Details | Review
Fix marshalling of GStrv. (9.05 KB, patch)
2010-06-01 15:41 UTC, Tomeu Vizoso
needs-work Details | Review
Fix marshalling of GStrv. (9.68 KB, patch)
2010-06-01 16:33 UTC, Tomeu Vizoso
needs-work Details | Review
Fix marshalling of GStrv. (10.10 KB, patch)
2010-06-02 15:41 UTC, Tomeu Vizoso
accepted-commit_now Details | Review
Fix marshalling of GStrv. (10.10 KB, patch)
2010-06-02 17:38 UTC, Tomeu Vizoso
none Details | Review

Description Tomeu Vizoso 2010-05-31 18:00:21 UTC
The patch attached special cases GStrv as an array of utf8.

Another alternative is to make the C parser interpret correctly the typedef as gchar** and making sure the GIR parser generates the correct info on the typelib. It may imply adding support for annotations about types.
Comment 1 Tomeu Vizoso 2010-05-31 18:01:15 UTC
Created attachment 162394 [details] [review]
Add a special case for GStrv so it's interpreted as an array of utf8.
Comment 2 Xavier Claessens 2010-05-31 18:27:05 UTC
Tested this patch and it fix segfault when calling a function that has a GStrv in its args. Thanks!

Note that this bug is the same as described in bug #619799 comment #3.
Comment 3 Xavier Claessens 2010-05-31 18:29:29 UTC
Also note that this patch does not fix the case of GStrv inside a struct, I still get that error when running g-ir-compiler:

** WARNING **: field TelepathyGLib.AvatarRequirements.supported_mime_types has void type
Comment 4 Xavier Claessens 2010-05-31 18:34:19 UTC
Looks like we can't pass 'None' for a GStrv arg, is that normal? I get that backtrace:

Traceback (most recent call last):
  • File "test.py", line 13 in <module>
    print get_name();
  • File "test.py", line 9 in get_name
    field = TelepathyGLib.ContactInfoField.new ("n", None, None)
  • File "/usr/local/lib/python2.6/dist-packages/gtk-2.0/gi/types.py", line 54 in constructor
    return info.invoke(cls, *args)
TypeError: argument 2: Must be sequence, not NoneType

Passing '[]' works though.
Comment 5 Tomeu Vizoso 2010-06-01 08:25:05 UTC
(In reply to comment #4)
> Looks like we can't pass 'None' for a GStrv arg, is that normal?

Yes, unless the arg is annotated with (allow-none).
Comment 6 Johan (not receiving bugmail) Dahlin 2010-06-01 15:02:40 UTC
(In reply to comment #5)
> (In reply to comment #4)
> > Looks like we can't pass 'None' for a GStrv arg, is that normal?
> 
> Yes, unless the arg is annotated with (allow-none).

An empty list should always be accepted though, but that's up to each LB to implement.
Comment 7 Tomeu Vizoso 2010-06-01 15:41:40 UTC
Created attachment 162469 [details] [review]
Fix marshalling of GStrv.

* gir/gimarshallingtests.[hc]: Add a test for GStrv in function args and
as struct fields.

* girepository/giroffsets.c: Correctly compute the size of structs with
  array fields

* girepository/girparser.c: Set is_pointer to FALSE for arrays with
  fixed size inside structs.

* giscanner/glibtransformer.py: Special case GStrv as arrays of utf8.
Comment 8 Tomeu Vizoso 2010-06-01 15:42:30 UTC
*** Bug 616815 has been marked as a duplicate of this bug. ***
Comment 9 Johan (not receiving bugmail) Dahlin 2010-06-01 15:58:08 UTC
Comment on attachment 162469 [details] [review]
Fix marshalling of GStrv.

>diff --git a/giscanner/glibtransformer.py b/giscanner/glibtransformer.py

>+        elif ptype.name == "GObject.Strv":
>+            return Array(None, ptype.ctype, 'utf8')

According to:
http://library.gnome.org/devel/gobject/unstable/gobject-Boxed-Types.html#G-TYPE-STRV:CAPS

G_TYPE_STRV: The GType for a boxed type holding a NULL-terminated array of strings.

In other words, a GStrv should default to being zero-terminated.

We should have a default transfer annotation as well, either container or full.

The rest looks good.
Comment 10 Johan (not receiving bugmail) Dahlin 2010-06-01 15:59:46 UTC
(In reply to comment #9)
[..] 
> We should have a default transfer annotation as well, either container or full.

Should probably mimic the default GObject transfer annotation and our policy that  functions without annotations should rather be "crashing" than "leaking", since otherwise it'll be much harder to track down wrong annotations. In other words, "full" should be the default transfer for GStrv.
Comment 11 Xavier Claessens 2010-06-01 16:28:04 UTC
*** Bug 619799 has been marked as a duplicate of this bug. ***
Comment 12 Tomeu Vizoso 2010-06-01 16:33:41 UTC
Created attachment 162472 [details] [review]
Fix marshalling of GStrv.

* gir/gimarshallingtests.[hc]: Add a test for GStrv in function args and
as struct fields.

* girepository/giroffsets.c: Correctly compute the size of structs with
  array fields

* girepository/girparser.c: Set is_pointer to FALSE for arrays with
  fixed size inside structs.

* giscanner/glibtransformer.py: Special case GStrv as arrays of utf8.
Comment 13 Johan (not receiving bugmail) Dahlin 2010-06-01 16:42:23 UTC
Comment on attachment 162472 [details] [review]
Fix marshalling of GStrv.

+            elif isinstance(node.type, Array):
+                return PARAM_TRANSFER_FULL

Let's be conservative instead and avoid potentially breaking current APIs.
This should also apply only for return values. I can't see the zero-terminated=true part of the patch.

To clarify myself:

* GObject.Strv should set zero-terminated=True (do this in glibtransfer.py where you're creating the Array)
* return values of GObject.Strv should set transfer=full, unsure if this needs to be done in annotationparser.py or if it can be in glibtransfer.py.
Comment 14 Tomeu Vizoso 2010-06-02 15:41:43 UTC
Created attachment 162550 [details] [review]
Fix marshalling of GStrv.

* gir/gimarshallingtests.[hc]: Add a test for GStrv in function args and
as struct fields.

* girepository/giroffsets.c: Correctly compute the size of structs with
  array fields

* girepository/girparser.c: Set is_pointer to FALSE for arrays with
  fixed size that are inside structs.

* giscanner/glibtransformer.py: Special case GStrv as arrays of utf8.

* giscanner/annotationparser.py: Make full transfer the default for
arrays of char* returned by functions.
Comment 15 Tomeu Vizoso 2010-06-02 15:51:12 UTC
(In reply to comment #13)
> (From update of attachment 162472 [details] [review])
> +            elif isinstance(node.type, Array):
> +                return PARAM_TRANSFER_FULL
> 
> Let's be conservative instead and avoid potentially breaking current APIs.
> This should also apply only for return values. I can't see the
> zero-terminated=true part of the patch.
> 
> To clarify myself:
> 
> * GObject.Strv should set zero-terminated=True (do this in glibtransfer.py
> where you're creating the Array)

But all Arrays are zero-terminated by default:

http://git.gnome.org/browse/gobject-introspection/tree/giscanner/ast.py#n306
http://git.gnome.org/browse/gobject-introspection/tree/giscanner/girwriter.py#n245

> * return values of GObject.Strv should set transfer=full, unsure if this needs
> to be done in annotationparser.py or if it can be in glibtransfer.py.

Done
Comment 16 Johan (not receiving bugmail) Dahlin 2010-06-02 16:58:46 UTC
Review of attachment 162550 [details] [review]:

Looks good, thanks for solving that.

::: giscanner/annotationparser.py
@@ +935,3 @@
                 return PARAM_TRANSFER_NONE
         elif isinstance(node, Return):
+            if isinstance(node.type, Array) and \

No need for \ if you put () around the whole if statement.
Comment 17 Tomeu Vizoso 2010-06-02 17:38:36 UTC
Created attachment 162565 [details] [review]
Fix marshalling of GStrv.

* gir/gimarshallingtests.[hc]: Add a test for GStrv in function args and
as struct fields.

* girepository/giroffsets.c: Correctly compute the size of structs with
  array fields

* girepository/girparser.c: Set is_pointer to FALSE for arrays with
  fixed size that are inside structs.

* giscanner/glibtransformer.py: Special case GStrv as arrays of utf8.

* giscanner/annotationparser.py: Make full transfer the default for
arrays of char* returned by functions.
Comment 18 André Klapper 2015-02-07 17:02:33 UTC
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]