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 650663 - Require explicit copy() method for arrays
Require explicit copy() method for arrays
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Arrays
0.41.x
Other All
: Normal normal
: 0.42
Assigned To: Vala maintainers
Vala maintainers
: 672752 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2011-05-20 12:32 UTC by Luca Bruno
Modified: 2018-03-21 13:28 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Deprecate implicit copy of arrays, use explicit copy method (5.57 KB, patch)
2011-07-30 14:43 UTC, Luca Bruno
none Details | Review
Deprecate implicit copy of arrays, use explicit copy method (5.55 KB, patch)
2016-10-18 14:54 UTC, Rico Tzschichholz
none Details | Review
Add explicit copy method for arrays (5.64 KB, patch)
2016-10-20 11:45 UTC, Rico Tzschichholz
committed Details | Review
codegen: Deprecate implicit copy of arrays, use explicit copy method (905 bytes, patch)
2017-09-03 17:50 UTC, Rico Tzschichholz
none Details | Review
codegen: Deprecate implicit copy of arrays, use explicit copy method (1.07 KB, patch)
2017-09-12 10:08 UTC, Rico Tzschichholz
committed Details | Review

Description Luca Bruno 2011-05-20 12:32:31 UTC
Hello,
compact classes actually need an explicit call to .copy() (if it exists) and recently copying delegates has been deprecated.
I'd like to suggest for coherency to deprecated implicit array copy. I guess most of the time array copy is not wanted from a performance point of view, like in this case:
int[] arr1;
...
int[] arr2 = arr1;

In this case arr1 is copied into arr2, this doesn't work anymore with delegates and compact classes, which are pretty similar to arrays. For this reason I'd like to deprecate this implicit copy in favor of calling a .copy() method on arrays:
int[] arr2 = arr1.copy();
Comment 1 Jürg Billeter 2011-05-20 15:18:57 UTC
Yes, let's do this in the 0.13 cycle.
Comment 2 Luca Bruno 2011-05-25 08:39:48 UTC
Do we have to add ArrayCopyMethod or we can do it like with SignalType?
Comment 3 Luca Bruno 2011-07-30 14:43:32 UTC
Created attachment 192912 [details] [review]
Deprecate implicit copy of arrays, use explicit copy method

Fixes bug 650663.
Comment 4 Luca Bruno 2011-07-30 14:46:14 UTC
Do we want to fix copying arrays for closure/coroutine first for consistency?
Comment 5 Rico Tzschichholz 2016-10-18 14:54:55 UTC
Created attachment 337947 [details] [review]
Deprecate implicit copy of arrays, use explicit copy method

Fixes bug 650663.
Comment 6 Rico Tzschichholz 2016-10-18 14:55:39 UTC
This would be nice to have! The patch still works fine with a minor tweak.
The problem is the return-type of properties were "owned get" == "get" for arrays, so this need to be respected.

public class Foo {
	// do not warn here
	public int[] a { owned get; set; }
	
	// warn here and suggest "owned get"
	public int[] b { get; set; }
	
	// do not warn here
	public unowned int[] c { get; set; }
}

void main () {
	int[] i = { 1, 2, 3, 4 };
	
	// warn here
	var a = i;
}
Comment 7 Rico Tzschichholz 2016-10-20 11:45:36 UTC
Created attachment 338093 [details] [review]
Add explicit copy method for arrays
Comment 8 Rico Tzschichholz 2016-10-23 20:50:46 UTC
Comment on attachment 338093 [details] [review]
Add explicit copy method for arrays

commit d274caac1745465c50cfe14908452e0d024011f1
Author: Luca Bruno <lucabru@src.gnome.org>
Date:   Sat Jul 30 16:41:34 2011 +0200

    Add explicit copy method for arrays
Comment 9 Rico Tzschichholz 2017-03-09 16:08:28 UTC
*** Bug 672752 has been marked as a duplicate of this bug. ***
Comment 10 Rico Tzschichholz 2017-09-03 17:50:06 UTC
Created attachment 359036 [details] [review]
codegen: Deprecate implicit copy of arrays, use explicit copy method
Comment 11 Rico Tzschichholz 2017-09-12 10:08:21 UTC
Created attachment 359597 [details] [review]
codegen: Deprecate implicit copy of arrays, use explicit copy method