On Mon, Nov 26, 2012 at 10:37 AM, <
dpx.in...@gmail.com> wrote:
>
> I asked this question on stackoverflow and still didn't get definite answer,
> so I decided to try here. Text below mostly is copied from the stackoverflow
> question.
>
>
> Suppose there is CGo package with a struct defined like this:
>
> package test
> ...
> type Test struct {
> Field *C.C_Test
> }
> ...
>
> Now suppose that from somewhere else I get unsafe.Pointer which I know
> points to C_Test C structure.
>
> Do I understand correctly that there is completely no way to create new
> test.Test instance from the unsafe.Pointer value while being in a package
> other than test?
Other than using the unsafe package to push things through pointers, I
believe that is correct.
> Some background: I need a way to create such structure when I use GtkBuilder
> with go-gtk library.
> Its GtkBuilder.GetObject(name) method returns *GObject pointer which in turn
> contains unsafe.Pointer field which I need to turn somehow into, say,
> gtk.GtkEntry struct. gtk.GtkEntry itself contains implicit field of type
> gtk.GtkWidget which has explicit field of type *C.GtkWidget, so I need to
> convert unsafe.Pointer to *C.GtkWidget, but I cannot, as I have described in
> the simple example above.
If that is a reasonable thing to do, then one would hope that the
go-gtk package would provide a way to do it. I don't know enough
about gtk to know how reasonable it is.
Ian