How can I use "out caller-allocates" in GJS?

136 views Asked by At

I am trying to retrieve a contact photo via GData.ContactsContact.get_photo() which has this signature:

get_photo(
    GDataContactsContact *self,
    GDataContactsService *service,
    gsize *length,                    (out caller-allocates)
    gchar **content_type,             (out caller-allocates)
    GCancellable *cancellable,
    GError *error
)

However, if I simply declare variable as a "caller-allocate" for this (eg.let length;) or instantiate a new G_TYPE for length the result is always:

Gjs-Message: JS ERROR: Unsupported type guint64 for (out caller-allocates)

I could only find a few old examples of similar problems that all refer to annotation errors:

it seems the method is improperly annotated. It should be (out caller-allocates) (array length=length).

Is this an introspection bug I can workaround and/or file a bug for or am I misunderstanding "out caller-allocates" usage in Javascript?

1

There are 1 answers

0
ptomato On BEST ANSWER

You may be able to work around it by using another function, but it seems this function is not annotated properly either. The length argument should be annotated as the length of the return value. Please file a bug report at https://bugzilla.gnome.org for GData.

The way it should work is that out arguments (even ones that are marked caller-allocates for C code) are not passed in; that all happens under the hood. And, length arguments are only used internally in order to set up the array that they refer to. So the expected way to call the function would be:

let [photoBytes, contentType] = contact.get_photo(service, cancellable);