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 683596 - 64 bit integer not properly converted from gvalue
64 bit integer not properly converted from gvalue
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: general
Git master
Other Linux
: Normal normal
: ---
Assigned To: Martin Pitt
Python bindings maintainers
Need Review
Depends on:
Blocks: 682886
 
 
Reported: 2012-09-07 21:24 UTC by Nicolas Dufresne (ndufresne)
Modified: 2012-09-12 04:51 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
argument: Fix 64bit integer convertion from gvalue (1.35 KB, patch)
2012-09-07 21:24 UTC, Nicolas Dufresne (ndufresne)
committed Details | Review
regress: Add utility to test signals with int64 and uint64 params (6.29 KB, patch)
2012-09-11 20:10 UTC, Nicolas Dufresne (ndufresne)
committed Details | Review
test: Add test for signal with int64 and uint64 parameters (1.35 KB, patch)
2012-09-11 20:11 UTC, Nicolas Dufresne (ndufresne)
rejected Details | Review

Description Nicolas Dufresne (ndufresne) 2012-09-07 21:24:10 UTC
Created attachment 223792 [details] [review]
argument: Fix 64bit integer convertion from gvalue

The 64 bit integers are not retreive properly from GValues, as a result, an assert and 0 being returned. You'll find attached a patch that fixes this issue.
Comment 1 Paolo Borelli 2012-09-08 09:06:40 UTC
we will need a unit test for this (if needed add the C part to gobject-introspection)
Comment 2 Nicolas Dufresne (ndufresne) 2012-09-09 13:11:42 UTC
Sure, I'm just sharing my findings here. In gobject-instrospection, this aspect seems covered by the tests. I also came across this test, which I'm not sure it right on 32bit machines.

pygi-argument.c:58
      case GI_TYPE_TAG_INT64:
          *gssize_out = arg_in->v_int64;
          return TRUE;
      case GI_TYPE_TAG_UINT64:
          *gssize_out = arg_in->v_uint64;
          return TRUE;
Comment 3 Martin Pitt 2012-09-10 14:33:12 UTC
Thanks for this. The patch looks fine, but I'd really like to capture this in a test case.

At least GValue int64 already works fine with the current PyGObject as normal method arguments, both in and out. I just committed test API for that to gobject-introspection:

  http://git.gnome.org/browse/gobject-introspection/commit/?id=9a472fb76c8d603b439562accf0593bb63d86215

and tests to pygobject that make sure that these work:

  http://git.gnome.org/browse/pygobject/commit/?id=822d9e07a95f706a40f64335765293542787da90

_pygi_argument_from_g_value() is only used for unmarshalling signal arguments, so I'll add a test for that.
Comment 4 Martin Pitt 2012-09-11 07:50:20 UTC
I'm afraid I still can't reproduce this error. Can you please attach or link to a piece of code which does not work?

- int64 GValue input arguments and return values for methods work:
  http://git.gnome.org/browse/pygobject/commit/?id=822d9e07

- int64 input arguments and return values for signals work:
  http://git.gnome.org/browse/pygobject/commit/?id=15046b5a

- int64 GValue return values for signals work:
  http://git.gnome.org/browse/pygobject/commit/?id=fddb01b

- int64 GValue input arguments for signals work if you construct them explicitly:
  http://git.gnome.org/browse/pygobject/commit/?id=4559247553b

- int64 GValue signal arguments do not work if you only specify a bare constant, but there the problem is the other direction (marshalling from Python to C), and it's not 100% clear that this should be fixed. See previous patch; I captured this in bug 683775.

Thanks in advance!
Comment 5 Nicolas Dufresne (ndufresne) 2012-09-11 14:29:49 UTC
(In reply to comment #4)
> - int64 GValue signal arguments do not work if you only specify a bare
> constant, but there the problem is the other direction (marshalling from Python
> to C), and it's not 100% clear that this should be fixed. See previous patch; I
> captured this in bug 683775.

I'm a bit unclear of what you mean by "it's not 100% clear that this should be fixed". From reading the code, it's quite clear that calling g_value_get_uint() on a gvalue that holds a GUINT64 will never work. Are you saying you have a patch that completly remove that code ?

For you interest, the situation is gst-editing-services that emit from C the snapping signal. This signal has a GstClockTime (guint64) as parameter. This code is being triggered when the signal is being relayed to Python. Unfortuatly, this is the oppsite of what you just described, which might explain why you don't reproduce it. Taking that code out and running a test like the following clearly show the code is wrong.

>GValue v = {0}
>g_value_init (&v, G_TYPE_UINT64);
>g_value_set_uint64 (&v, 1);
>g_assert (g_value_get_uint (&v) == 1);

returns:

>(process:24520): GLib-GObject-CRITICAL **: g_value_get_uint: assertion `G_VALUE_HOLDS_UINT (value)' >failed
>**
>ERROR:test.c:12:main: assertion failed: (g_value_get_uint (&v) == 1)
>Aborted

This is exactly what that code is doing.
Comment 6 Martin Pitt 2012-09-11 14:51:48 UTC
(In reply to comment #5)
> (In reply to comment #4)
> > - int64 GValue signal arguments do not work if you only specify a bare
> > constant, but there the problem is the other direction (marshalling from Python
> > to C), and it's not 100% clear that this should be fixed. See previous patch; I
> > captured this in bug 683775.
> 
> I'm a bit unclear of what you mean by "it's not 100% clear that this should be
> fixed".

Oh, *this* bug (683596) should certainly be fixed. I meant, it's not clear whether bug 683775 is really a bug or not.

> From reading the code, it's quite clear that calling g_value_get_uint()
> on a gvalue that holds a GUINT64 will never work. Are you saying you have a
> patch that completly remove that code ?

No, I just have trouble finding a reproducer which actually triggers that faulty code. It's obviously wrong.

> For you interest, the situation is gst-editing-services that emit from C the
> snapping signal. This signal has a GstClockTime (guint64) as parameter. This
> code is being triggered when the signal is being relayed to Python.
> Unfortuatly, this is the oppsite of what you just described, which might
> explain why you don't reproduce it.

Right, I see. Thanks!
Comment 7 Nicolas Dufresne (ndufresne) 2012-09-11 20:10:11 UTC
Created attachment 224047 [details] [review]
regress: Add utility to test signals with int64 and uint64 params

Changes required to gobject-introspection Regress module to test int64 signal parameters. I've based my work on the skeleton that Martin wrote today.
Comment 8 Nicolas Dufresne (ndufresne) 2012-09-11 20:11:19 UTC
Created attachment 224049 [details] [review]
test: Add test for signal with int64 and uint64 parameters

This test covers the bug being fixed in this patch.
Comment 9 Martin Pitt 2012-09-12 04:19:24 UTC
Comment on attachment 224049 [details] [review]
test: Add test for signal with int64 and uint64 parameters

This is the wrong patch, it's the actual bug fix again, not the test. But I had it mostly written yesterday anyway, so thanks!
Comment 10 Martin Pitt 2012-09-12 04:47:40 UTC
Comment on attachment 224047 [details] [review]
regress: Add utility to test signals with int64 and uint64 params

Committed the g-i test with some cleanup (fixing the expected output and dropping reference to the nonexisting regress_test_obj_emit_sig_with_int64_no_return).

Thanks!
Comment 11 Martin Pitt 2012-09-12 04:49:53 UTC
Comment on attachment 223792 [details] [review]
argument: Fix 64bit integer convertion from gvalue

Committed the fix with test cases.

http://git.gnome.org/browse/pygobject/commit/?id=4e4c87e3868948743e0446abe2ba0cf5626374c4

Thanks!