giscanner: give error when utf8 strings are annotated with length argument
Submitted by Simon Feltman
Link to original bug (#694735)
Description
There have been a number of occasions where APIs either take strings with a length arg or return them. The following example came from bug 694448
/**
- secret_value_get:
- @value: the value
- @length: (out): the length of the secret
- Returns: (array length=length): the secret data */ const gchar * secret_value_get (SecretValue *value, gsize *length)
This creates the following GIR:
<method name="get" c:identifier="secret_value_get">
`<return-value transfer-ownership="none">`
<doc xml:whitespace="preserve">the secret data`</doc>`
<array length="0" zero-terminated="0" c:type="gchar*">
<type name="utf8" c:type="gchar"/>
`</array>`
`</return-value>`
The problem here is language bindings will interpret this as an array of utf8 strings based on the definition of GI_TYPE_TAG_UTF8 being "UTF-8 encoded string". It is unclear if this is a bug in scanner output. If it is not, it would be nice to support a "char" type so we can annotate this as follows:
Returns: (array length=length) (element-type char):
There is currently a way to work around this by specifying an element-type of "uint8" which bindings will special case. But we cannot assume utf8 encoding when this is done.