GNOME Bugzilla – Bug 774669
Generic array conversion produces incorrect array with enumerations and flags
Last modified: 2016-12-30 07:07:15 UTC
Created attachment 340231 [details] [review] Fix converting enumerations and flags to arrays The generic array conversions fail to special-case enumerations and flags type, which most of the time results in incorrect arrays. It is the same underlying issue as https://bugzilla.gnome.org/show_bug.cgi?id=597737 This issue breaks real apps in hard-to-understand ways, see for example https://bugzilla.gnome.org/show_bug.cgi?id=774653 Attached patch adds special handling for those so they are (generally) correctly handled. Below is the patch's description: --- Fix converting enumerations and flags to arrays Enumerations and flags are classed types for Vala, not integers, so they don't fall in the `typeof(G) == typeof(int)` kind of tests. This leads to using the generic code in which Vala assumes pointer-sized elements, which is often not true for enumerations and flags. Add special case for those to use the `int` converters for enumerations and flags. This is most generally correct, but not always: the compiler will likely chose a larger type for a specific enumeration if one of its value is larger than `int`. It would be tempting to use the enumeration's class minimum and maximum values to determine the appropriate type, but unfortunately the API for this uses int itself, so doesn't help.
Overall this seems ok, although the added test-case fails (on 64bit).
(In reply to Rico Tzschichholz from comment #1) > although the added test-case fails (on 64bit). Does it? It works good here, although I apparently have to run `make` before `make check` (or `make check` twice) to get the tests use the new version of the library. But on all subsequent runs it succeeds just fine, so I guess it's a build system dependency issue.
OK, the testsuite isn't using the just built library but the installed one and therefore obviously fails for that reason. So the test succeeds now.
Review of attachment 340231 [details] [review]: Looks good.
Attachment 340231 [details] pushed as 72671f6 - Fix converting enumerations and flags to arrays
*** Bug 776536 has been marked as a duplicate of this bug. ***