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 679362 - gi: Fix issues with functions that modify their input parameter, like g_mkdtemp
gi: Fix issues with functions that modify their input parameter, like g_mkdtemp
Status: RESOLVED WONTFIX
Product: pygobject
Classification: Bindings
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2012-07-04 01:03 UTC by Jasper St. Pierre (not reading bugmail)
Modified: 2012-07-16 00:09 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gi: Fix issues with functions that modify their input parameter, like g_mkdtemp (1.76 KB, patch)
2012-07-04 01:03 UTC, Jasper St. Pierre (not reading bugmail)
needs-work Details | Review
gimarshallingtests: Add a g_mkdtemp lookalike (1.53 KB, patch)
2012-07-04 01:04 UTC, Jasper St. Pierre (not reading bugmail)
none Details | Review

Description Jasper St. Pierre (not reading bugmail) 2012-07-04 01:03:10 UTC
See patch.
Comment 1 Jasper St. Pierre (not reading bugmail) 2012-07-04 01:03:12 UTC
Created attachment 217978 [details] [review]
gi: Fix issues with functions that modify their input parameter, like g_mkdtemp

We cannot free functions that consume an argument they take, which
is true for (transfer full) arguments.
Comment 2 Jasper St. Pierre (not reading bugmail) 2012-07-04 01:04:32 UTC
Created attachment 217979 [details] [review]
gimarshallingtests: Add a g_mkdtemp lookalike

the gimarshallingtests side of things
Comment 3 Martin Pitt 2012-07-11 06:18:12 UTC
Confirming:

$ jhbuild run python3 -c 'from gi.repository import GLib; a="foo.XXXXXX"; print("result:", GLib.mkdtemp(a)); print("a:", a)'
Traceback (most recent call last):
  • File "<string>", line 1 in <module>
  • File "gi/types.py", line 47 in function
    return info.invoke(*args, **kwargs)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb2 in position 1: invalid start byte

This is because g_mkdtemp() and _full()'s annotation of tmpl

        <parameter name="tmpl" transfer-ownership="none">
          <doc xml:whitespace="preserve">template directory name</doc>
          <type name="filename" c:type="gchar*"/>
        </parameter>

which is (transfer none) does not match the return value, which is (transfer full):

     <return-value transfer-ownership="full">
        <doc xml:whitespace="preserve">A pointer to @tmpl, which has been modified to hold the directory name.  In case of errors, %NULL is returned and %errno will be set.</doc>
        <type name="utf8" c:type="gchar*"/>
      </return-value>

tmpl is also slightly confusing because it actually behaves like (inout).

If I annotatate the argument with (inout), regardless of transfer none or full, the call stops segfaulting, but neither creates a temporary dir nor returns the answer:

$ jhbuild run python3 -c 'from gi.repository import GLib; a="foo.XXXXXX"; print("result:", GLib.mkdtemp(a)); print("a:", a)'
result: (None, 'foo.XXXXXX')
a: foo.XXXXXX


But even with your patch applied, I still get the same crash, because in current g_mkdtemp(), the transfer mode of the argument is really "none". Your g-i test case annotates it as "full", but that's neither "like g_mkdtemp" nor true because g_mkdtemp() does not allocate the returned value, but simply uses the existing string. So "none" is actually correct here. But it does not matter much, if I annotate both tmpl and return value as "full" it behaves exactly the same: no crash, but no directory created and the return value is still "XXXXXX".

I'm afraid we do not currently have a good way to annotate "modifies this parameter", but it seems to me that (inout) (transfer none) would be pretty close to reality?
Comment 4 Martin Pitt 2012-07-11 06:18:50 UTC
Comment on attachment 217978 [details] [review]
gi: Fix issues with functions that modify their input parameter, like g_mkdtemp

This does not actually fix g_mkdtemp().
Comment 5 Jasper St. Pierre (not reading bugmail) 2012-07-11 06:48:12 UTC
Applying the patch in this bug makes it work fine:

https://bugzilla.gnome.org/show_bug.cgi?id=679351

But the patch was rejected, for sane reasons, especially because we have good functions, like g_dir_make_tmp
Comment 6 Martin Pitt 2012-07-11 07:02:45 UTC
(In reply to comment #5)
> Applying the patch in this bug makes it work fine:
> 
> https://bugzilla.gnome.org/show_bug.cgi?id=679351

Ah, that's essentially what I tried as well. But the concern in this bug still stands: there is no way to annotate an API that modifies its input char* argument without being (transfer full).