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 531918 - pair<T1,T2>
pair<T1,T2>
Status: RESOLVED OBSOLETE
Product: libgee
Classification: Platform
Component: general
git master
Other All
: Low enhancement
: ---
Assigned To: libgee-maint
libgee-maint
: 589801 (view as bug list)
Depends on: 527770
Blocks:
 
 
Reported: 2008-05-07 09:39 UTC by Marc-Andre Lureau
Modified: 2019-03-20 10:35 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Marc-Andre Lureau 2008-05-07 09:39:50 UTC
I wish libgee/vala could have such a nice and useful type.

Thanks!
Comment 1 Marc-Andre Lureau 2008-05-07 09:57:46 UTC
	public class Pair<T1,T2> {
		public T1 first;
		public T2 second;

		public Pair (T1# first, T2# second) {
			this.first = #first;
			this.second = #second;
		}
	}



produces:
OhmPair* ohm_pair_new (gpointer first, gpointer second) {
	OhmPair* self;
	gpointer _tmp1;
	gpointer _tmp0;
	gpointer _tmp3;
	gpointer _tmp2;
	self = g_slice_new0 (OhmPair);
	_tmp1 = NULL;
	_tmp0 = NULL;
	self->first = (_tmp1 = (_tmp0 = first, first = NULL, _tmp0), NULL, _tmp1);
	_tmp3 = NULL;
	_tmp2 = NULL;
	self->second = (_tmp3 = (_tmp2 = second, second = NULL, _tmp2), NULL, _tmp3);
	return self;
}
void ohm_pair_free (OhmPair* self) {
	NULL;
	NULL;
	g_slice_free (OhmPair, self);
}

Why first/second are not free'd?
Comment 2 Marc-Andre Lureau 2008-05-07 12:21:58 UTC
I would like it to be a struct, unfortunately:

I cannot use "this" in ctor, and the .vapi file does not have the template/generic arguments
Comment 3 Vlad Grecescu 2008-05-07 17:08:30 UTC
(In reply to comment #1)
>         public class Pair<T1,T2> {
>                 public T1 first;
>                 public T2 second;
> 
>                 public Pair (T1# first, T2# second) {
>                         this.first = #first;
>                         this.second = #second;
>                 }
>         }
> 
> produces:
> OhmPair* ohm_pair_new (gpointer first, gpointer second) {
>     ...
> }
> 
> Why first/second are not free'd?
> 

Just a guess, but type parameters being considered any gpointer, one cannot assume they are GObjects.

More probable, ownership transfer on T1 and T2 shouldn't be possible, IMO.
Comment 4 Jürg Billeter 2008-05-25 16:05:04 UTC
Maybe we should better directly support tuples in Vala but not sure yet.
Comment 5 Michael 'Mickey' Lauer 2009-10-07 14:32:23 UTC
Please see also #597693
Comment 6 Jürg Billeter 2010-03-23 07:06:51 UTC
Moving this to libgee as we can't really add types in the compiler. For tuples, see bug 597693.
Comment 7 Marc-Andre Lureau 2010-03-29 22:55:06 UTC
public class Pair<T1,T2> {
        public T1 first;
        public T2 second;

        public Pair (T1 first, T2 second) {
                this.first = first;
                this.second = second;
        }
}

Seems to work well enough nowadays (no need for ownership transfer).
Comment 8 Michael 'Mickey' Lauer 2010-05-05 12:08:56 UTC
Can we apply that? What about triplets and quadruples?
Comment 9 Maciej (Matthew) Piechotka 2010-07-14 09:37:16 UTC
*** Bug 589801 has been marked as a duplicate of this bug. ***
Comment 10 GNOME Infrastructure Team 2019-03-20 10:35:56 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/libgee/issues/2.