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 749636 - Missing support for platform-specific macros
Missing support for platform-specific macros
Status: RESOLVED OBSOLETE
Product: gobject-introspection
Classification: Platform
Component: general
2.42.x
Other Linux
: Normal normal
: ---
Assigned To: gobject-introspection Maintainer(s)
gobject-introspection Maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2015-05-20 14:28 UTC by Matěj Cepl
Modified: 2018-02-08 12:35 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Matěj Cepl 2015-05-20 14:28:41 UTC
For some weird reasons simple macros seem to be completely broken via GObject-introspection. This simple script (and the equivalent in ipython)

#!/usr/bin/gjs                                                                  
const GLib = imports.gi.GLib;                                                   
                                                                                
print("The dir sep is - ", GLib.DIR_SEPARATOR_S);                               
print("The search path sep is - ", GLib.SEARCHPATH_SEPARATOR_S);                

gives very weird results:

matej@mitmanek: ~$ gjs test_sep.js 
The dir sep is -  \
The search path sep is -  ;
matej@mitmanek: ~$ uname -a
Linux mitmanek 3.10.0-251.el7.rhel72drm5.x86_64 #1 SMP Wed May 13 17:31:13 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux
matej@mitmanek: ~$ rpm -q glib2
glib2-2.42.2-2.el7.kalev0.x86_64
matej@mitmanek: ~$
Comment 1 Matěj Cepl 2015-05-20 14:29:43 UTC
I forgot
gobject-introspection-1.42.0-1.el7.x86_64
Comment 2 Mathieu Bridon 2015-05-20 14:31:54 UTC
I can reproduce with these:

glib2-2.44.1-1.fc22.x86_64
gobject-introspection-1.44.0-1.fc22.x86_64
python3-gobject-3.16.1-1.fc22.x86_64
pygobject3-3.16.1-1.fc22.x86_64
Comment 3 Emmanuele Bassi (:ebassi) 2015-05-20 15:18:16 UTC
Strictly speaking, using the GLib macros in a language binding is not a great plan — also because the introspection scanner does not support complex macros in the first place.

G_DIR_SEPARATOR_S and G_SEARCHPATH_SEPARATOR_S are defined in terms of G_OS_WIN32, with the Windows macros defined first; this is confusing the introspection scanner, since it has to do a pass before macros are expanded, but it will ignore the #ifdef G_OS_WIN32 and add the first symbol and value unconditionally. Once the scanner reaches the second definition, it'll append it to the list of symbols.

In theory, the scanner should allow for constants to appear multiple times, but it's not implemented:

giscanner/transformer.py:_append_new_node()

        # Special case constants here; we allow duplication to sort-of
        # handle #ifdef.  But this introduces an arch-dependency in the .gir
        # file.  So far this has only come up scanning glib - in theory, other
        # modules will just depend on that.
        if isinstance(original, ast.Constant) and isinstance(node, ast.Constant):
            pass
Comment 4 Emmanuele Bassi (:ebassi) 2015-05-20 15:21:35 UTC
It's worth noting that the code has been the same since 2010, and that the GIR already contains arch-dependent bits. The missing implementation means that any constant that already exists in the AST gets dropped on the floor, which is what causes the Windows-specific values to appear in the GIR and, thus, in the typelib.
Comment 5 Emmanuele Bassi (:ebassi) 2015-05-20 15:29:15 UTC
There are two plausible solutions for this problem:

 1. Since we don't support cross-compilation, we could check the current platform and push platform specific data into the AST by way of the GLib conditionals; this means that we standardise on G_OS_WIN32 for Windows and G_OS_UNIX for any Unix-like system. These are public API of GLib, so it wouldn't be terrible.

 2. If we want to at least try and not make the cross-compilation situation worse, we need to add conditionals to the XML, e.g.

  <if-condition-set key="platform" value="win32">
    <constant name="DIR_SEPARATOR_S" value="\">
      <doc>…</doc>
      <type name="utf8" c:type="gchar*"/>
    </constant>
  </if-condition-set>
  <if-condition-set key="platform" value="unix">
    <constant name="DIR_SEPARATOR_S" value="/">
      <doc>…</doc>
      <type name="utf8" c:type="gchar*"/>
    </constant>
  </if-condition-set>

The g-ir-compiler would then use the existing platform to decide which value to compile into the typelib file.
Comment 6 Matěj Cepl 2015-05-20 16:03:20 UTC
Filed also as https://bugzilla.redhat.com/show_bug.cgi?id=1223490
Comment 7 Mikhail Zabaluev 2015-10-06 14:36:02 UTC
It would be great if there was simply an annotation to mark platform-specific constants (and maybe types, but constants is where the most pain is), so that the binding generators are aware that the definitions vary per platform and manual overrides are needed.
Comment 8 Mikhail Zabaluev 2015-10-27 04:38:23 UTC
(In reply to Mikhail Zabaluev from comment #7)
> It would be great if there was simply an annotation to mark
> platform-specific constants (and maybe types, but constants is where the
> most pain is), so that the binding generators are aware that the definitions
> vary per platform and manual overrides are needed.

Filed away as bug #757165.
Comment 9 Mikhail Zabaluev 2015-10-29 10:31:43 UTC
Another possible approach is to add a g-ir-scanner option for listing platform-specific source files, so that any symbols defined in those files would be flagged as platform-specific. This requires that on the source side, all platform-specific definitions are confined to dedicated header or source files. Unfortunately, this is not completely so even in glib; see bug #757284 and bug #757294.
Comment 10 GNOME Infrastructure Team 2018-02-08 12:35:09 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/gobject-introspection/issues/132.