Cannot Curl.SList.append multiple headers

Hello,

It seems impossible to append/set more than one header in Curl.SList header list.

string session_token = "...";
string range = "...";

var headers = Curl.SList.append (null, "X-Foo-Bar-Auth: " + session_token);
headers = Curl.SList.append (headers, range);

Compilation yields error:

error: duplicating `SList’ instance, use unowned variable or explicitly invoke copy method

headers = Curl.SList.append (headers, range);

And with vala 0.56, I cannot pass the variable as (unowned).

For information, i use vala-extra-vapis/libcurl.vapi where SList is:

public class SList {
                 [CCode (cname = “curl_slist_append”)]
                 public static SList append (owned SList? p1, string p2);
                 [CCode (cname = “curl_slist_free_all”)]
                 public void free_all ();
         }

It seems that the bindings for curl are wrong. You shouldn’t be using a linked list like that.

The “wrong” way to fix this is to use an owned cast

headers = Curl.SList.append ((owned) headers, range);

This should fix the ownership error, but still looks wrong from a Vala perspective.

The right way to do it would look like:

Curl.Slist headers = null;

headers.append(...);
headers.append(...);

but this requires fixing the vapi to mark the method as [ReturnsModifiedPointer ()] (and not static as it currently seems to be)

Thank you very much for the explanation.

In the mean time, I modified locally the libcurl.vapi file so that i can do:

var headers = Curl.SList.append (null, "foo: bar");
headers = Curl.SList.append (headers, "bar: baz");
...
headers.free_all (); /* manually, so not vala'ish */

the modified class vapi is:

        [CCode (cheader_filename = "curl/curl.h", cname = "struct curl_slist", free_function = "")]
        [Compact]
        public class SList {
                [CCode (cname = "curl_slist_append")]
                public static SList append (SList? p1, string p2);
                [CCode (cname = "curl_slist_free_all")]
                public void free_all ();
        }

But then, memory management must be done manually.