Type Errors in GObject-Bindings generated by haskell-gi

I tried generating GObject-Bindings with haskell-gi for the wireplumber library, the generated code fails to typecheck, because the bindings slightly off.

The type errors are not especially hard ones. I am unsure about how to proceed, because it is the generated code that failed and I am working for my first time with haskell-gi.

/home/vego/Git/haskell-gi/bindings/WirePlumber/GI/Wp/Structs/Iterator.hs:353:44: error: [GHC-83865]
    • Couldn't match type ‘GValue’ with ‘Ptr GValue’
      Expected: Ptr (Ptr GValue)
        Actual: Ptr GValue
    • In the third argument of ‘wp_iterator_fold’, namely ‘ret''’
      In a stmt of a 'do' block:
        result <- wp_iterator_fold self' func' ret'' data_
      In the second argument of ‘($)’, namely
        ‘do self' <- unsafeManagedPtrGetPtr self
            func' <- Wp.Callbacks.mk_IteratorFoldFunc
                       (Wp.Callbacks.wrap_IteratorFoldFunc Nothing func)
            ret' <- disownGValue ret
            ret'' <- callocBytes 24 :: IO (Ptr GValue)
            ....’
    |
353 |     result <- wp_iterator_fold self' func' ret'' data_
    |                                            ^^^^^

Inspecting the error I found that the coressponding function was translated this way:

foreign import ccall "wp_iterator_fold" wp_iterator_fold :: 
    Ptr Iterator ->                         -- self : TInterface (Name {namespace = "Wp", name = "Iterator"})
    FunPtr Wp.Callbacks.C_IteratorFoldFunc -> -- func : TInterface (Name {namespace = "Wp", name = "IteratorFoldFunc"})
    Ptr (Ptr GValue) ->                     -- ret : TGValue
    Ptr () ->                               -- data : TBasicType TPtr
    IO CInt

Where ret is translated as Ptr Ptr GValue, but the xml documents the argument this way:

          <parameter name="ret"
                     direction="inout"
                     caller-allocates="0"
                     transfer-ownership="full">
            <doc xml:space="preserve"
                 filename="docs/wp-gtkdoc.h"
                 line="1917">the accumulator data</doc>
            <type name="GObject.Value" c:type="GValue*"/>
          </parameter>

Which is only a single value, as far as I can tell.

Is this an error in haskell-gi, because of the direction of the parameter? (inout)
Are these kind of errors common, can I fix them by hand without further problems?

Thank you for any comments!

I tried generating bindings for the WirePlumber library, this is what I tried so far:

  1. Clone haskell-gi
    git clone https://github.com/haskell-gi/haskell-gi.git
  2. Make sure the libraries I need are available, for me these were: gobject-introspection-devel.x86_64, wireplumber-devel.x86_64
  3. Create a new directory bindings/WirePlumber and fill out the files for the build info tool.
pkg.info
{
    "name": "gi-WirePlumber",
    "version": "0.5.8",
    "description": "Bindings for WirePlumber, autogenerated by haskell-gi.",
    "synopsis": "WirePlumber bindings",
    "author": "My name here",
    "girName": "Wp",
    "girVersion": "0.5",
    "girOverrides": "Wp.overrides",
    "baseVersion": "base >= 4.17.2.1",
    "distributionPackages": {
        "fedora": [
            "wireplumber-devel"
        ]
    },
    "giDepends": [
        "gi-glib",
        "gi-gobject",
        "gi-gio"
    ],
    "pkgconfigDepends": "wireplumber-0.5"
}
Changelog.md
### 0.5.8

Initial commit.

I did not paste Wp.overrides here because it is quite lengthy, you can generate it using xsltproc ../Nullable.xslt /usr/share/gir-1.0/Wp-0.5.gir >> Wp.overrides

  1. Generate the repository using stack run genBuildInfo WirePlumber/ from the directory above
  2. Enter the repository again, run stack build after finding a stackage snapshot that contains all the packages (I tried nightly-2025-04-03 and lts-23-17)
  3. Observe Error Messages without any further interaction

Did I miss a step which made this build fail? Are there any resources which could help me troubleshoot the generated code?

Hi @VegOwOtenks, welcome.

To me, this reads like a bug in haskell-gi. The 3rd argument to wp_iterator_fold should obviously be just Ptr GValue, not Ptr (Ptr GValue).

You might get better luck asking the project itself, in https://github.com/haskell-gi/haskell-gi/issues. A pretty similar issue was reported there before: Couldn't match type ‘GValue’ with ‘Ptr GValue’ · Issue #65 · haskell-gi/haskell-gi · GitHub — but I didn’t understand how it was resolved exactly. Perhaps asking again is the best way.

Knowing a little bit about GTK APIs instabi fluidity, I’d warn against hand-patching the generated output. That’ll cost you a bunch of maintenance in the long run. Still, it may be useful to try briefly, as a temporary scaffold, just to see if/what issues you’ll encounter next; but for permanent solution, do seek a fix in haskell-gi so that it produces correct output.

1 Like

Thank you for the hint about opening a new Issue, I did just that, hopefully I will be able to resolve it together with the maintainers. :]

1 Like