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 686263 - Add array length annotations for add_from_string
Add array length annotations for add_from_string
Status: RESOLVED WONTFIX
Product: gtk+
Classification: Platform
Component: Class: GtkBuilder
unspecified
Other Linux
: Normal normal
: ---
Assigned To: GtkBuilder maintainers
GtkBuilder maintainers
Depends on:
Blocks: 686264
 
 
Reported: 2012-10-17 04:55 UTC by Simon Feltman
Modified: 2013-02-27 09:34 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Simon Feltman 2012-10-17 04:55:44 UTC
Both gtk_builder_add_from_string and gtk_builder_add_objects_from_string support char buffers along with length arguments. Neither of the methods bind the length argument to the buffer through annotations. pygobject takes care of passing array lengths for python programs based on the (array length=) annotation. In the case of these methods, there is an explicit override for these methods which are unnecessary if simple annotations are added.
Comment 1 Martin Pitt 2013-02-27 08:41:12 UTC
It's not actually that trivial. From an introspection client's perspective the API is self-contradictory: Right now "buffer" is annotated (by default) to be of type "utf8" which is by definition null-terminated. We can also say that it's an arbitrary length byte array with

 * @buffer: (array length=length) (element-type guint8): the string to parse

This would be an API break though, as now you'd have to pass byte arrays instead of strings into the function (I tested this with pygobject's test suite, and that annotation does work).

A mere

 * @buffer: (array length=length): the string to parse

is wrong, as this comes out as

          <parameter name="buffer" transfer-ownership="none">
            <doc xml:whitespace="preserve">the string to parse</doc>
            <array length="1" zero-terminated="0" c:type="gchar*">
              <type name="utf8" c:type="gchar"/>
            </array>
          </parameter>

I. e. it will be interpreted as an array of strings.

I really don't want to break the API here. I'd be interested in the rationale of the length argument -- is it really a use case to have zero bytes in GtkBuilder strings?

I suggest that in e. g. pygobject (bug 686264) we just keep the override or, if the length argument actually has some value, expose it to the outside as a keyword argument and otherwise default to -1.
Comment 2 Simon Feltman 2013-02-27 09:34:24 UTC
I assume the length arg is used as a potential optimization. Strings passed to this may end up being fairly large and avoiding an strlen might not be a bad idea in cases where the caller already knows it.

In any case, even if a utf8 string with length hint gave acceptable gi output, you are right in that it would break API. And even if we react to it in PyGObject other introspection binding clients could break.