No shared-library name available in fontconfig-2.0.gir and freetype2-2.0.gir

I have just discovered that fontconfig-2.0.gir and freetype2-2.0.gir provide no library name, but at the same time provide at least one function. That could generate problems when the user would try to call that function.

Most GIR files provide the shared-library name like

$ head  -30 /usr/share/gir-1.0/Gtk-3.0.gir 
<?xml version="1.0"?>
<!-- This file was automatically generated from C sources - DO NOT EDIT!
To affect the contents of this file, edit the original C definitions,
and/or use gtk-doc annotations.  -->
<repository version="1.2"
  <include name="Atk" version="1.0"/>
  <include name="Gdk" version="3.0"/>
  <include name="xlib" version="2.0"/>
  <package name="gtk+-3.0"/>
  <c:include name="gtk/gtk-a11y.h"/>
  <c:include name="gtk/gtk.h"/>
  <c:include name="gtk/gtkx.h"/>
  <namespace name="Gtk"
    <alias name="Allocation" c:type="GtkAllocation">
      <doc xml:space="preserve"
           line="70">A #GtkAllocation-struct of a widget represents region
which has been allocated to the widget by its parent. It is a subregion
of its parents allocation. See
[GtkWidget’s geometry management section][geometry-management] for
more information.</doc>
      <source-position filename="gtk+-3.24.20/gtk/gtkwidget.h" line="83"/>
      <type name="Gdk.Rectangle" c:type="GdkRectangle"/>


$ cat /usr/share/gir-1.0/fontconfig-2.0.gir 
<?xml version="1.0"?>
<repository version="1.2"
  <namespace name="fontconfig" version="2.0"
    <record name="Pattern" c:type="FcPattern"/>
    <record name="CharSet" c:type="FcCharSet"/>
    <function name="init" c:identifier="FcInit">
      <return-value transfer-ownership="none">
        <type name="none" c:type="void"/>

$ cat /usr/share/gir-1.0/freetype2-2.0.gir 
<?xml version="1.0"?>
<repository version="1.2"
  <namespace name="freetype2" version="2.0"
    <record name="Bitmap" c:type="FT_Bitmap"/>
    <record name="Face" c:type="FT_Face"/>
    <record name="Library" c:type="FT_Library"/>
    <alias name="Int32" c:type="FT_Int32">
      <type name="int32"/>
    <function name="library_version" c:identifier="FT_Library_Version">
      <return-value transfer-ownership="none">
        <type name="none" c:type="void"/>

I think the fix is to generate no functions at all if the shared-library name is not present.

These two GIR files are handwritten, are are only meant to be used when generating other introspection data in order to resolve types exposed by those libraries. They are not meant to be used to load and use fontconfig/freetype2 symbols directly.

Both fontconfig and freetype2 are not GObject-based libraries, and thus fall outside the scope of GObject-introspection. In order to use them in languages other than C you will need to have native language bindings.

Yes, my generated files are indeed tiny, like

$ cat .nimble/pkgs/gintro-0.7.8/gintro/fontconfig.nim 
# dependencies:
# immediate dependencies:
# libraries:

const Lib = ""
{.pragma: libprag, cdecl, dynlib: Lib.}

  Pattern00* {.pure.} = object
  Pattern* = ref object
    impl*: ptr Pattern00
    ignoreFinalizer*: bool

  CharSet00* {.pure.} = object
  CharSet* = ref object
    impl*: ptr CharSet00
    ignoreFinalizer*: bool

proc init*() {.
    importc: "FcInit", libprag.}

That file provides two data types, Pattern and CharSet. That is fine, I assume that the two datatypes are needed by other libs. But the provided init() function is not of much use and would not work at all, as Lib = “” indicates that we have no library name available. The init() function does not hurt as long a user does not try to call it – better I filter that function out.

No, when I say “generating other introspection data” I literally mean the GIR file for other libraries, like Pango’s GIR file.

The freetype2 and fontconfig GIR files are like the cairo.gir file: only there to satisfy the requirement of GIR files like GTK’s. They are not meant to be used by language bindings to access the underlying library API.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.