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 761360 - Delegate returning array does not return array length
Delegate returning array does not return array length
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Delegates
0.30.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2016-01-31 14:21 UTC by Phillip Wood
Modified: 2016-10-05 06:50 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Test case showing the problem (520 bytes, text/x-vala)
2016-01-31 14:21 UTC, Phillip Wood
  Details
Test case (566 bytes, text/x-vala)
2016-01-31 14:40 UTC, Phillip Wood
  Details
Fix array length of array returned by lambda (2.29 KB, patch)
2016-10-02 10:47 UTC, Simon Werbeck
committed Details | Review

Description Phillip Wood 2016-01-31 14:21:53 UTC
Created attachment 320124 [details]
Test case showing the problem

I've got a function that returns a delegate that returns an array. When the delegate is invoked the length of the returned array isn't set.

Consider the following where I want to pass a number of different function types F1, F2 to something that takes a Func

private delegate double[] Func (double[] xs);
private delegate double F1 (double x);
private delegate double F2 (double x, double y);
private delegate double[] Marshal_f1 (F1 f, double[] xs);
private delegate double[] Marshal_f2 (F2 f, double[] xs);

private Func wrap_f (F f)
{
    Func g = (xs) => {
        var z = f (xs[0]);
        double[] ret = { z };
        return ret;
    };

    return g;
}

The C code created for g above does not set the array length

static gdouble* ___lambda4__func (gdouble* xs, int xs_length1, int* result_length1, gpointer self) {
	gdouble* result;
	result = __lambda4_ (self, xs, xs_length1);
	return result;
}

If I use a marshaller instead then the length is returned. I've attached a simple testcase to illustrate the problem.
Comment 1 Phillip Wood 2016-01-31 14:40:20 UTC
Created attachment 320127 [details]
Test case

Sorry I over simplified the other test case and it didn't compile, this one correctly demonstrates the problem.
Comment 2 Simon Werbeck 2016-10-02 10:47:05 UTC
Created attachment 336756 [details] [review]
Fix array length of array returned by lambda
Comment 3 Rico Tzschichholz 2016-10-05 06:50:33 UTC
commit 566ff81b821775c6e178c8c90bcac95d08436c91
Author: Simon Werbeck <simon.werbeck@gmail.com>
Date:   Fri Feb 26 00:28:11 2016 +0100

    codegen: Fix array length of array returned by lambda
    
    This ensures that the right default values are used for missing ccode
    attributes.