gtk/gtk.go
func cast(c *C.GObject) (glib.IObject, error) {
	var (
		className = goString(C.object_get_class_name(c))
		obj       = glib.Take(unsafe.Pointer(c))
	)

	fn, ok := WrapMap[className]
	if !ok {
		return nil, errors.New("unrecognized class name '" + className + "'")
	}

	rf := reflect.ValueOf(fn)
	if rf.Type().Kind() != reflect.Func {
		return nil, errors.New("wraper is not a function")
	}

	v := reflect.ValueOf(obj)
	rv := rf.Call([]reflect.Value{v})

	if len(rv) != 1 {
		return nil, errors.New("wrapper did not return")
	}

	if k := rv[0].Kind(); k != reflect.Ptr {
		return nil, fmt.Errorf("wrong return type %s", k)
	}

	ret, ok := rv[0].Interface().(glib.IObject)
	if !ok {
		return nil, errors.New("did not return an IObject")
	}

	return ret, nil
}
func cast(c *C.GObject) (glib.IObject, error) {
	var (
		className = goString(C.object_get_class_name(c))
		obj       = glib.Take(unsafe.Pointer(c))
	)

	fn, ok := WrapMap[className]
	if !ok {
		return nil, errors.New("unrecognized class name '" + className + "'")
	}

	rf := reflect.ValueOf(fn)
	if rf.Type().Kind() != reflect.Func {
		return nil, errors.New("wraper is not a function")
	}

	v := reflect.ValueOf(obj)
	rv := rf.Call([]reflect.Value{v})

	if len(rv) != 1 {
		return nil, errors.New("wrapper did not return")
	}

	if k := rv[0].Kind(); k != reflect.Ptr {
		return nil, fmt.Errorf("wrong return type %s", k)
	}

	ret, ok := rv[0].Interface().(glib.IObject)
	if !ok {
		return nil, errors.New("did not return an IObject")
	}

	return ret, nil
}
// cast takes a native GObject and casts it to the appropriate Go struct.
//TODO change all wrapFns to return an IObject