1

I've solved the prev question partially.

Right now I'm able to register GObject subtype via bindings-gobject (see hpase) I can implement SourceCompletionProvider using c'g_type_add_interface_static function (but didn't tried yet).

The only issue is to convert Ptr (), returned by c'g_object_newv, to gtk2hs data type SourceCompletionProvider. How can I do it? Any hints?

SourceCompletionProvider is defined like:

newtype SourceCompletionProvider = SourceCompletionProvider (ForeignPtr (SourceCompletionProvider))

What does this definition means? Why it is recursive? Provider is a ForeignPtr to provider -- looks strange for me.

Thanks.

Solution:

makeNewGObject mkGObject $ castPtr <$> c'g_object_newv myObType 0 nullPtr
Community
  • 1
  • 1
Yuras
  • 13,856
  • 1
  • 45
  • 58

1 Answers1

1

The outer SourceCompletionProvider is required since this is a newtype, and the inner SourceCompletionProvider is just a marker to distinguish this foreign pointer from pointers to other types. If you look at the definition of Ptr a, it's data Ptr a = Ptr Addr# - a is a phantom type that doesn't appear on the right-hand side, so the definition is not actually recursive.

You can convert a Ptr () to ForeignPtr () using newForeignPtr_ and then cast it to ForeignPtr SourceCompletionProvider with castForeignPtr.

edit: After looking at this a bit more, I think that to make this work you'll need to first convert your Ptr to GObject with the method outlined above and then use unsafeCastGObject. Not tested, though.

Mikhail Glushenkov
  • 14,928
  • 3
  • 52
  • 65
  • Hmm... I think I need to add finalizer, right? I can use `p'g_object_unref` as a finalizer, is it enough? – Yuras Sep 20 '12 at 10:50
  • From what I can tell after looking at the [C interface documentation](http://developer.gnome.org/gobject/stable/gobject-The-Base-Object-Type.html#g-object-unref), you're right. – Mikhail Glushenkov Sep 20 '12 at 10:59