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 539969 - Generated code contains errors when using HashMap and SequenceIter
Generated code contains errors when using HashMap and SequenceIter
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Code Generator
0.3.x
Other All
: High major
: ---
Assigned To: Jürg Billeter
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2008-06-24 15:12 UTC by Sebastian Pölsterl
Modified: 2008-09-26 19:38 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Test case (417 bytes, text/plain)
2008-06-24 15:12 UTC, Sebastian Pölsterl
  Details
maybe fix? (726 bytes, patch)
2008-07-15 07:04 UTC, Jared Moore
reviewed Details | Review
More extensive test case (1.63 KB, text/plain)
2008-07-15 21:27 UTC, Sebastian Pölsterl
  Details

Description Sebastian Pölsterl 2008-06-24 15:12:03 UTC
$ valac --pkg gee-1.0 -o test test.vala
test.c: In function 'test_constructor':
test.c:146: error: expected expression before ')' token
error: cc exited with status 256
Compilation failed: 1 error(s), 0 warning(s)
Comment 1 Sebastian Pölsterl 2008-06-24 15:12:25 UTC
Created attachment 113337 [details]
Test case
Comment 2 Sebastian Pölsterl 2008-06-24 15:38:35 UTC
Similar error when using SList<SequenceIter<K>>
Comment 3 Jürg Billeter 2008-07-02 17:41:35 UTC
Confirming.
Comment 4 Jared Moore 2008-07-15 06:38:23 UTC
Reduced test case:

[Compact]
[CCode (ref_function = "", unref_function = "")]
class Foo { }

class Bar<X> { }

void main () {
	var e = new Bar<Foo> ();
}



Removing the CCode attribute from Foo makes vala complain about copying and suggests changing to 'new Bar<weak Foo>'. Adding the 'weak' results in correct C code regardless of whether the CCode attribute or not.

I don't really understand how the generics code works, but the above testing indicates to me that the test case should result in a vala error complaining about the lack of ref and unref functions.

Jürg/Raffaele, does this sound correct?

Sebastian, is it possible to make your code work with 'weak SequenceIter<K>' ?
Comment 5 Jared Moore 2008-07-15 07:04:45 UTC
Created attachment 114578 [details] [review]
maybe fix?

Attached patch makes vala produce an error for this test case.

Also, SequenceIter seems to be the only class in all the Vala bindings with ref_function = "", so maybe that is also incorrect?

$ grep "ref_function *= *\"\"" vapi/*.vapi
Comment 6 Sebastian Pölsterl 2008-07-15 21:27:43 UTC
Created attachment 114628 [details]
More extensive test case

I applied your patch. The code compiles and works for me.
However, I still get a warning:
warning: passing argument 3 of 'g_sequence_insert_sorted' from incompatible pointer type

I attached a more extensive test case.
Comment 7 Jared Moore 2008-07-16 02:35:42 UTC
Ok, cool. The problem there is that the generated function

static gint _number_compare_gcompare_data_func (void* a, void* b, gpointer self) {
	return number_compare (a, b);
}

should have 'const void *' in order to be a GCompareDataFunc. But that is fairly harmless. There are already a few bugs filed about not using 'const' in generated methods, I'm not sure if this problem is a dupe of one of those or a different issue.

Comment 8 Jürg Billeter 2008-09-26 19:36:55 UTC
The ref_function = "" and all the weak SequenceIter were a workaround to avoid memory management for these instances. I'll commit a change to bind SequenceIter as a value-type, which should fix the issue.
Comment 9 Jürg Billeter 2008-09-26 19:38:16 UTC
2008-09-26  Jürg Billeter  <j@bitron.ch>

	* vapi/glib-2.0.vapi:

	Fix GSequenceIter binding, it should be treated as a value-type,
	fixes bug 539969

Fixed in r1784.