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 629705 - Handle wide ranging enum values better
Handle wide ranging enum values better
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gjs-maint
gjs-maint
Depends on: 629704
Blocks:
 
 
Reported: 2010-09-14 20:03 UTC by Owen Taylor
Modified: 2011-01-13 01:15 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Handle wide ranging enum values better (16.39 KB, patch)
2010-09-14 20:03 UTC, Owen Taylor
committed Details | Review

Description Owen Taylor 2010-09-14 20:03:40 UTC
Enums were being converted to and from jsval using JSVAL_TO_INT
and INT_TO_JSVAL. The latter is just wrong - INT_TO_JSVAL produces
junk results if called on an integer outside the range of
-0x40000000 - 0x3fffffff.

Just fixing that still leaves a problem - if we get 0x80000000 as
a flags value, and we treat it as (int)0x80000000 then we pass it
to another function that is using 'guint' for flags instead of the
enum type, we'll throw because the value is out of range.

So, this change goes a further and (by depending on gobject-introspection
changes in 629704) correctly maps all signed and unsigned 32 bit
constants onto the correct numeric value.

A new utility function gjs_value_to_int64() is added to convert from
jsval to gint64, since we are using int64 as an intermediate type for
holding enum values.
Comment 1 Owen Taylor 2010-09-14 20:03:42 UTC
Created attachment 170284 [details] [review]
Handle wide ranging enum values better
Comment 2 Colin Walters 2010-11-17 20:30:00 UTC
Review of attachment 170284 [details] [review]:

Two minor comments.

::: gi/arg.c
@@ +52,2 @@
     /* check all bits are defined for flags.. not necessarily desired */
     tmpval = value;

Include a cast now to avoid a compiler warning?

::: test/js/testEverythingBasic.js
@@ +352,3 @@
    assertEquals('Enum parameter', 'value1', e);
+   e = Everything.test_unsigned_enum_param(Everything.TestEnumUnsigned.VALUE2);
+   log(e);

You told me not to add log() to the test suite earlier, so... =)
Comment 3 Owen Taylor 2011-01-13 01:14:26 UTC
(In reply to comment #2)
> Review of attachment 170284 [details] [review]:
> 
> Two minor comments.
> 
> ::: gi/arg.c
> @@ +52,2 @@
>      /* check all bits are defined for flags.. not necessarily desired */
>      tmpval = value;
> 
> Include a cast now to avoid a compiler warning?

I don't get a warning, but sure, doesn't hurt.

> ::: test/js/testEverythingBasic.js
> @@ +352,3 @@
>     assertEquals('Enum parameter', 'value1', e);
> +   e =
> Everything.test_unsigned_enum_param(Everything.TestEnumUnsigned.VALUE2);
> +   log(e);
> 
> You told me not to add log() to the test suite earlier, so... =)

Yeah, left-over
Comment 4 Owen Taylor 2011-01-13 01:15:24 UTC
Attachment 170284 [details] pushed as 259ede1 - Handle wide ranging enum values better