msys2 / MINGW-packages

Package scripts for MinGW-w64 targets to build under MSYS2.
https://packages.msys2.org
BSD 3-Clause "New" or "Revised" License
2.25k stars 1.21k forks source link

glib2: Gio.content_type_guess() changed its signature #21227

Open lovetox opened 3 months ago

lovetox commented 3 months ago

Description / Steps to reproduce the issue

Since a few weeks something changed and we have problems with the Gio.content* methods.

One was fixed here https://github.com/msys2/MINGW-packages/commit/1b141d52378698968de24b53a6f6e13e9eea31af

But there are new problems now with different methods

With the python bindings we see the following error

Gio.content_type_guess() takes exactly 4 arguments (2 given)

although the python binding docs only specify 2 arguments. See https://lazka.github.io/pgi-docs/#Gio-2.0/functions.html#Gio.content_type_guess

I cross posted a issue on the Glib tracker https://gitlab.gnome.org/GNOME/glib/-/issues/3399 but im actually not sure if it is a glib problem.

@Biswa96 it seems you changed something in the glib package regarding GIR, could this be cause because of that?

Expected behavior

Gio.content_type_guess goes back to its old signature

Actual behavior

Gio.content_type_guess has wrong signature

Verification

Windows Version

unknown

MINGW environments affected

Are you willing to submit a PR?

No response

Biswa96 commented 3 months ago

Could you provide a minimal sample code to reproduce the issue?

Biswa96 commented 3 months ago

Gio.content_type_guess() takes exactly 4 arguments (2 given)

The C function, g_content_type_guess really takes 4 arguments in glib2 version 2.80.3 https://gitlab.gnome.org/GNOME/glib/-/blob/2.80.3/gio/gcontenttype-win32.c#L356

gchar *
g_content_type_guess (const gchar  *filename,
                      const guchar *data,
                      gsize         data_size,
                      gboolean     *result_uncertain)

although the python binding docs only specify 2 arguments.

The python binding returns the last result_uncertain argument in return value. The data_size probably goes into returned string object. Hence, 2 arguments in pygobject.

pwithnall commented 3 months ago

Since a few weeks something changed and we have problems with the Gio.content* methods.

Have you established what changed? Did you update one of your dependencies? Did you rebase a GLib/gobject-introspection/pygobject branch? If things broke at a particular point in time, that sounds very bisectable.

g-willems commented 3 months ago

Hi @pwithnall ,

This is a fallout from https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3636

The implementation of g_content_type_guess is not the same for win32 as for linux (different source files), so the gir parser can't find the properly annotated function, and generates some wild guess from the header's signature.

Here what we have in Gio-2.0.gir on msys2:

    <function name="content_type_guess" c:identifier="g_content_type_guess">
      <source-position filename="gio/gcontenttype.h" line="63"/>
      <return-value transfer-ownership="full">
        <type name="utf8" c:type="gchar*"/>
      </return-value>
      <parameters>
        <parameter name="filename" transfer-ownership="none">
          <type name="utf8" c:type="const gchar*"/>
        </parameter>
        <parameter name="data" transfer-ownership="none">
          <type name="guint8" c:type="const guchar*"/>
        </parameter>
        <parameter name="data_size" transfer-ownership="none">
          <type name="gsize" c:type="gsize"/>
        </parameter>
        <parameter name="result_uncertain" transfer-ownership="none">
          <type name="gboolean" c:type="gboolean*"/>
        </parameter>
      </parameters>
    </function>

For reference, the correct introspection data I have on Linux:

    <function name="content_type_guess" c:identifier="g_content_type_guess">
      <doc xml:space="preserve"
           filename="gio-2.0.c"
           line="14877">Guesses the content type based on example data. If the function is
uncertain, @result_uncertain will be set to %TRUE. Either @filename
or @data may be %NULL, in which case the guess will be based solely
on the other argument.</doc>
      <source-position filename="gcontenttype.h" line="63"/>
      <return-value transfer-ownership="full">
        <doc xml:space="preserve"
             filename="gio-2.0.c"
             line="14890">a string indicating a guessed content type for the
    given data. Free with g_free()</doc>
        <type name="utf8" c:type="gchar*"/>
      </return-value>
      <parameters>
        <parameter name="filename"
                   transfer-ownership="none"
                   nullable="1"
                   allow-none="1">
          <doc xml:space="preserve"
               filename="gio-2.0.c"
               line="14879">a path, or %NULL</doc>
          <type name="filename" c:type="const gchar*"/>
        </parameter>
        <parameter name="data"
                   transfer-ownership="none"
                   nullable="1"
                   allow-none="1">
          <doc xml:space="preserve"
               filename="gio-2.0.c"
               line="14880">a stream of data, or %NULL</doc>
          <array length="2" zero-terminated="0" c:type="const guchar*">
            <type name="guint8" c:type="guchar"/>
          </array>
        </parameter>
        <parameter name="data_size" transfer-ownership="none">
          <doc xml:space="preserve"
               filename="gio-2.0.c"
               line="14881">the size of @data</doc>
          <type name="gsize" c:type="gsize"/>
        </parameter>
        <parameter name="result_uncertain"
                   direction="out"
                   caller-allocates="0"
                   transfer-ownership="full"
                   optional="1"
                   allow-none="1">
          <doc xml:space="preserve"
               filename="gio-2.0.c"
               line="14882">return location for the certainty
    of the result, or %NULL</doc>
          <type name="gboolean" c:type="gboolean*"/>
        </parameter>
      </parameters>
    </function>

So there is definitely an issue on GLib: we need to annotate on win32 side too. Alternatively, we can move the annotations in the shared header gcontenttype.h, to avoid duplicates.

Any preference?

pwithnall commented 3 months ago

Thanks for bisecting and finding the problem! This looks very similar to !4106, but for g_content_type_guess() rather than g_content_type_get_icon().

Let’s follow up on https://gitlab.gnome.org/GNOME/glib/-/issues/3399 since it’s an issue in GLib.