Beispiel #1
0
func goError(err *C.GError) error {
	if err != nil {
		defer C.g_error_free(err)
		return errors.New(C.GoString((*C.char)(err.message)))
	}
	return nil
}
Beispiel #2
0
// RunJavaScript runs script asynchronously in the context of the current page
// in the WebView. Upon completion, resultCallback will be called with the
// result of evaluating the script, or with an error encountered during
// execution. To get the stack trace and other error logs, use the
// ::console-message signal.
//
// See also: webkit_web_view_run_javascript at
// http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#webkit-web-view-run-javascript
func (v *WebView) RunJavaScript(script string, resultCallback func(result *gojs.Value, err error)) {
	var cCallback C.GAsyncReadyCallback
	var userData C.gpointer
	var err error
	if resultCallback != nil {
		callback := func(result *C.GAsyncResult) {
			var jserr *C.GError
			jsResult := C.webkit_web_view_run_javascript_finish(v.webView, result, &jserr)
			if jsResult == nil {
				defer C.g_error_free(jserr)
				msg := C.GoString((*C.char)(jserr.message))
				resultCallback(nil, errors.New(msg))
				return
			}
			ctxRaw := gojs.RawGlobalContext(unsafe.Pointer(C.webkit_javascript_result_get_global_context(jsResult)))
			jsValRaw := gojs.RawValue(unsafe.Pointer(C.webkit_javascript_result_get_value(jsResult)))
			ctx := (*gojs.Context)(gojs.NewGlobalContextFrom(ctxRaw))
			jsVal := ctx.NewValueFrom(jsValRaw)
			resultCallback(jsVal, nil)
		}
		cCallback, userData, err = newGAsyncReadyCallback(callback)
		if err != nil {
			panic(err)
		}
	}
	cScript := C.CString(script)
	defer C.free(unsafe.Pointer(cScript))
	C.webkit_web_view_run_javascript(v.webView, (*C.gchar)(cScript), nil, cCallback, userData)
}
Beispiel #3
0
// Close is a wrapper around gdk_pixbuf_loader_close().  An error is
// returned instead of a bool like the native C function to support the
// io.Closer interface.
func (v *PixbufLoader) Close() error {
	var err *C.GError

	if ok := gobool(C.gdk_pixbuf_loader_close(v.native(), &err)); !ok {
		defer C.g_error_free(err)
		return errors.New(C.GoString((*C.char)(err.message)))
	}
	return nil
}
Beispiel #4
0
// ParseWarning() is a wrapper around gst_message_parse_warning().
func (v *Message) ParseWarning() (err error, debug string) {
	var e *C.GError
	var d *C.gchar
	C.gst_message_parse_warning(v.native(), &e, &d)
	eMessage := C.GoString((*C.char)(e.message))
	defer C.g_error_free(e)
	debug = C.GoString((*C.char)(d))
	defer C.g_free((C.gpointer)(d))
	return errors.New(eMessage), debug
}
Beispiel #5
0
// SetIconFromFile is a wrapper around gtk_window_set_icon_from_file().
func (v *Window) SetIconFromFile(file string) error {
	cstr := C.CString(file)
	defer C.free(unsafe.Pointer(cstr))
	var err *C.GError = nil
	res := C.gtk_window_set_icon_from_file(v.native(), (*C.gchar)(cstr), &err)
	if res == 0 {
		defer C.g_error_free(err)
		return errors.New(C.GoString((*C.char)(err.message)))
	}
	return nil
}
Beispiel #6
0
func PixbufSaveToStreamFinish(async_result *C.GAsyncResult) (_go__return__ bool, _error_ error) {
	var _cgo_error_ *C.GError
	var _return_ C.gboolean
	_return_ = C._gdk_pixbuf_save_to_stream_finish(async_result, unsafe.Pointer(&_cgo_error_))
	if _cgo_error_ != nil {
		_error_ = &Error{C.GoString((*C.char)(unsafe.Pointer(_cgo_error_.message)))}
		defer C.g_error_free(_cgo_error_)
	}
	_go__return__ = _return_ == (C.gboolean)(C.TRUE)
	return
}
Beispiel #7
0
func PixbufNewFromStream(stream *C.GInputStream, cancellable *C.GCancellable) (_go__return__ Pixbuf, _error_ error) {
	var _cgo_error_ *C.GError
	var _return_ *C.GdkPixbuf
	_return_ = C._gdk_pixbuf_new_from_stream(stream, cancellable, unsafe.Pointer(&_cgo_error_))
	if _cgo_error_ != nil {
		_error_ = &Error{C.GoString((*C.char)(unsafe.Pointer(_cgo_error_.message)))}
		defer C.g_error_free(_cgo_error_)
	}
	_go__return__ = ToPixbuf(unsafe.Pointer(_return_))
	return
}
Beispiel #8
0
func (_self_ *PixbufLoader) Close() (_go__return__ bool, _error_ error) {
	var _cgo_error_ *C.GError
	var _return_ C.gboolean
	_return_ = C._gdk_pixbuf_loader_close((*C.GdkPixbufLoader)(_self_._value_), unsafe.Pointer(&_cgo_error_))
	if _cgo_error_ != nil {
		_error_ = &Error{C.GoString((*C.char)(unsafe.Pointer(_cgo_error_.message)))}
		defer C.g_error_free(_cgo_error_)
	}
	_go__return__ = _return_ == (C.gboolean)(C.TRUE)
	return
}
Beispiel #9
0
func PixbufNewFromStreamFinish(async_result *C.GAsyncResult) (_go__return__ Pixbuf, _error_ error) {
	var _cgo_error_ *C.GError
	var _return_ *C.GdkPixbuf
	_return_ = C._gdk_pixbuf_new_from_stream_finish(async_result, unsafe.Pointer(&_cgo_error_))
	if _cgo_error_ != nil {
		_error_ = &Error{C.GoString((*C.char)(unsafe.Pointer(_cgo_error_.message)))}
		defer C.g_error_free(_cgo_error_)
	}
	_go__return__ = ToPixbuf(unsafe.Pointer(_return_))
	return
}
Beispiel #10
0
func NewElementFromUri(t C.GstURIType, uri, name string) (*C.GstElement, error) {
	var err *C.GError
	element := C.gst_element_make_from_uri(t, toGStr(uri), toGStr(name), &err)
	if element == nil {
		defer C.g_error_free(err)
		return nil, errors.New(fmt.Sprintf("%s", err.message))
	}
	runtime.SetFinalizer(element, func(e *C.GstElement) {
		C.gst_object_unref(asGPtr(element))
	})
	return element, nil
}
Beispiel #11
0
// GetSnapshotCustom runs asynchronously, taking a snapshot of the WebView.
// Upon completion, resultCallback will be called with a copy of the underlying
// bitmap backing store for the frame, or with an error encountered during
// execution.
//
// See also: webkit_web_view_get_snapshot at
// http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#webkit-web-view-get-snapshot
func (v *WebView) GetSnapshotCustom(region SnapshotRegion, options SnapshotOptions, resultCallback func(result *image.RGBA, err error)) {
	var cCallback C.GAsyncReadyCallback
	var userData C.gpointer
	var err error
	if resultCallback != nil {
		callback := func(result *C.GAsyncResult) {
			var snapErr *C.GError
			snapResult := C.webkit_web_view_get_snapshot_finish(v.webView, result, &snapErr)
			if snapResult == nil {
				defer C.g_error_free(snapErr)
				msg := C.GoString((*C.char)(snapErr.message))
				resultCallback(nil, errors.New(msg))
				return
			}
			defer C.cairo_surface_destroy(snapResult)

			if C.cairo_surface_get_type(snapResult) != cairoSurfaceTypeImage ||
				C.cairo_image_surface_get_format(snapResult) != cairoImageSurfaceFormatARGB32 {
				panic("Snapshot in unexpected format")
			}

			w := int(C.cairo_image_surface_get_width(snapResult))
			h := int(C.cairo_image_surface_get_height(snapResult))
			stride := int(C.cairo_image_surface_get_stride(snapResult))
			C.cairo_surface_flush(snapResult)
			data := unsafe.Pointer(C.cairo_image_surface_get_data(snapResult))

			//(miha) fix endianes depended byte order, and copy to go slice at the same time.
			data_fixed := make([]byte, stride*h)
			C.gowk2_cairo_endian_depended_ARGB32_to_RGBA((*C.uchar)(data), (*C.uchar)(&data_fixed[0]), C.uint(stride*h))
			rgba := &image.RGBA{data_fixed, stride, image.Rect(0, 0, w, h)}

			// slower but doesn't use Go pointers inside C. See https://github.com/golang/go/issues/8310 !!!!!!!
			//C.gowk2_cairo_endian_depended_ARGB32_to_RGBA((*C.uchar)(data), C.uint(stride*h))
			//rgba := &image.RGBA{C.GoBytes(data, C.int(stride*h)), stride, image.Rect(0, 0, w, h)}

			resultCallback(rgba, nil)
		}
		cCallback, userData, err = newGAsyncReadyCallback(callback)
		if err != nil {
			panic(err)
		}
	}

	C.webkit_web_view_get_snapshot(v.webView,
		(C.WebKitSnapshotRegion)(region),
		(C.WebKitSnapshotOptions)(options),
		nil,
		cCallback,
		userData)
}
Beispiel #12
0
// SavePNG is a wrapper around gdk_pixbuf_save().
// Compression is a number between 0...9
func (v *Pixbuf) SavePNG(path string, compression int) error {
	cpath := C.CString(path)
	ccompression := C.CString(strconv.Itoa(compression))
	defer C.free(unsafe.Pointer(cpath))
	defer C.free(unsafe.Pointer(ccompression))

	var err *C.GError
	c := C._gdk_pixbuf_save_png(v.native(), cpath, &err, ccompression)
	if !gobool(c) {
		defer C.g_error_free(err)
		return errors.New(C.GoString((*C.char)(err.message)))
	}
	return nil
}
Beispiel #13
0
// SaveJPEG is a wrapper around gdk_pixbuf_save().
// Quality is a number between 0...100
func (v *Pixbuf) SaveJPEG(path string, quality int) error {
	cpath := C.CString(path)
	cquality := C.CString(strconv.Itoa(quality))
	defer C.free(unsafe.Pointer(cpath))
	defer C.free(unsafe.Pointer(cquality))

	var err *C.GError
	c := C._gdk_pixbuf_save_jpeg(v.native(), cpath, &err, cquality)
	if !gobool(c) {
		defer C.g_error_free(err)
		return errors.New(C.GoString((*C.char)(err.message)))
	}
	return nil
}
Beispiel #14
0
// PixbufNewFromFileAtScale() is a wrapper around gdk_pixbuf_new_from_file_at_scale().
func PixbufNewFromFileAtScale(fileName string, width, height int, preserveAspectRatio bool) (*Pixbuf, error) {
	var cerr *C.GError
	cstr := C.CString(fileName)
	defer C.free(unsafe.Pointer(cstr))
	c := C.gdk_pixbuf_new_from_file_at_scale(cstr, C.int(width), C.int(height), gbool(preserveAspectRatio), &cerr)
	if c == nil {
		defer C.g_error_free(cerr)
		return nil, errors.New(C.GoString((*C.char)(C.error_get_message(cerr))))
	}
	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
	p := wrapPixbuf(obj)
	runtime.SetFinalizer(obj, (*glib.Object).Unref)
	return p, nil
}
Beispiel #15
0
// PixbufNewFromFile() is a wrapper around gdk_pixbuf_new_from_file().
func PixbufNewFromFile(fileName string) (*Pixbuf, error) {
	var cerr *C.GError
	cstr := C.CString(fileName)
	defer C.free(unsafe.Pointer(cstr))
	c := C.gdk_pixbuf_new_from_file(cstr, &cerr)
	if c == nil {
		defer C.g_error_free(cerr)
		return nil, errors.New(C.GoString((*C.char)(C.error_get_message(cerr))))
	}
	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
	p := wrapPixbuf(obj)
	runtime.SetFinalizer(obj, (*glib.Object).Unref)
	return p, nil
}
Beispiel #16
0
// Delete removes credentials from the store.
func (h Secretservice) Delete(serverURL string) error {
	if serverURL == "" {
		return errors.New("missing server url")
	}
	server := C.CString(serverURL)
	defer C.free(unsafe.Pointer(server))

	if err := C.delete(server); err != nil {
		defer C.g_error_free(err)
		errMsg := (*C.char)(unsafe.Pointer(err.message))
		return errors.New(C.GoString(errMsg))
	}
	return nil
}
Beispiel #17
0
func PixbufNewFromResource(resource_path string) (_go__return__ Pixbuf, _error_ error) {
	var _cgo_error_ *C.GError
	var _return_ *C.GdkPixbuf
	_cstring_resource_path_ := C.CString(resource_path)
	_cgo_resource_path_ := (*C.char)(unsafe.Pointer(_cstring_resource_path_))
	defer C.free(unsafe.Pointer(_cstring_resource_path_))
	_return_ = C._gdk_pixbuf_new_from_resource(_cgo_resource_path_, unsafe.Pointer(&_cgo_error_))
	if _cgo_error_ != nil {
		_error_ = &Error{C.GoString((*C.char)(unsafe.Pointer(_cgo_error_.message)))}
		defer C.g_error_free(_cgo_error_)
	}
	_go__return__ = ToPixbuf(unsafe.Pointer(_return_))
	return
}
Beispiel #18
0
// PixbufNewFromFile is a wrapper around gdk_pixbuf_new_from_file().
func PixbufNewFromFile(filename string) (*Pixbuf, error) {
	cstr := C.CString(filename)
	defer C.free(unsafe.Pointer(cstr))
	var err *C.GError
	res := C.gdk_pixbuf_new_from_file((*C.char)(cstr), &err)
	if res == nil {
		defer C.g_error_free(err)
		return nil, errors.New(C.GoString((*C.char)(err.message)))
	}
	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(res))}
	p := &Pixbuf{obj}
	runtime.SetFinalizer(obj, (*glib.Object).Unref)
	return p, nil
}
Beispiel #19
0
func PixbufNewFromFileAtSize(filename string, width C.int, height C.int) (_go__return__ Pixbuf, _error_ error) {
	var _cgo_error_ *C.GError
	var _return_ *C.GdkPixbuf
	_cstring_filename_ := C.CString(filename)
	_cgo_filename_ := (*C.char)(unsafe.Pointer(_cstring_filename_))
	defer C.free(unsafe.Pointer(_cstring_filename_))
	_return_ = C._gdk_pixbuf_new_from_file_at_size(_cgo_filename_, width, height, unsafe.Pointer(&_cgo_error_))
	if _cgo_error_ != nil {
		_error_ = &Error{C.GoString((*C.char)(unsafe.Pointer(_cgo_error_.message)))}
		defer C.g_error_free(_cgo_error_)
	}
	_go__return__ = ToPixbuf(unsafe.Pointer(_return_))
	return
}
Beispiel #20
0
func PixbufLoaderNewWithType(image_type string) (_go__return__ PixbufLoader, _error_ error) {
	var _cgo_error_ *C.GError
	var _return_ *C.GdkPixbufLoader
	_cstring_image_type_ := C.CString(image_type)
	_cgo_image_type_ := (*C.char)(unsafe.Pointer(_cstring_image_type_))
	defer C.free(unsafe.Pointer(_cstring_image_type_))
	_return_ = C._gdk_pixbuf_loader_new_with_type(_cgo_image_type_, unsafe.Pointer(&_cgo_error_))
	if _cgo_error_ != nil {
		_error_ = &Error{C.GoString((*C.char)(unsafe.Pointer(_cgo_error_.message)))}
		defer C.g_error_free(_cgo_error_)
	}
	_go__return__ = ToPixbufLoader(unsafe.Pointer(_return_))
	return
}
Beispiel #21
0
func (m *Message) ParseError() (err *glib.Error, debug string) {
	var d *C.gchar
	var e, ret_e *C.GError

	C.gst_message_parse_error(m.g(), &e, &d)
	defer C.g_error_free(e)
	defer C.free(unsafe.Pointer(d))

	debug = C.GoString((*C.char)(d))
	ret_e = new(C.GError)
	*ret_e = *e
	err = (*glib.Error)(unsafe.Pointer(ret_e))
	return
}
Beispiel #22
0
func PixbufAnimationNewFromFile(filename string) (_go__return__ PixbufAnimation, _error_ error) {
	var _cgo_error_ *C.GError
	var _return_ *C.GdkPixbufAnimation
	_cstring_filename_ := C.CString(filename)
	_cgo_filename_ := (*C.char)(unsafe.Pointer(_cstring_filename_))
	defer C.free(unsafe.Pointer(_cstring_filename_))
	_return_ = C._gdk_pixbuf_animation_new_from_file(_cgo_filename_, unsafe.Pointer(&_cgo_error_))
	if _cgo_error_ != nil {
		_error_ = &Error{C.GoString((*C.char)(unsafe.Pointer(_cgo_error_.message)))}
		defer C.g_error_free(_cgo_error_)
	}
	_go__return__ = ToPixbufAnimation(unsafe.Pointer(_return_))
	return
}
Beispiel #23
0
// PixbufNewFromFileAtSize is a wrapper around gdk_pixbuf_new_from_file_at_size().
func PixbufNewFromFileAtSize(filename string, width, height int) (*Pixbuf, error) {
	cstr := C.CString(filename)
	defer C.free(unsafe.Pointer(cstr))
	var err *C.GError = nil
	res := C.gdk_pixbuf_new_from_file_at_size(cstr, C.int(width), C.int(height), &err)
	if err != nil {
		defer C.g_error_free(err)
		return nil, errors.New(C.GoString((*C.char)(err.message)))
	}
	if res == nil {
		return nil, nilPtrErr
	}
	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(res))}
	p := &Pixbuf{obj}
	runtime.SetFinalizer(obj, (*glib.Object).Unref)
	return p, nil
}
Beispiel #24
0
func PixbufNewFromStreamAtScale(stream *C.GInputStream, width int, height int, preserve_aspect_ratio bool, cancellable *C.GCancellable) (_go__return__ Pixbuf, _error_ error) {
	var _cgo_error_ *C.GError
	var _return_ *C.GdkPixbuf
	_cgo_width_ := (C.gint)(width)
	_cgo_height_ := (C.gint)(height)
	_cgo_preserve_aspect_ratio_ := (C.gboolean)(C.FALSE)
	if preserve_aspect_ratio {
		_cgo_preserve_aspect_ratio_ = (C.gboolean)(C.TRUE)
	}
	_return_ = C._gdk_pixbuf_new_from_stream_at_scale(stream, _cgo_width_, _cgo_height_, _cgo_preserve_aspect_ratio_, cancellable, unsafe.Pointer(&_cgo_error_))
	if _cgo_error_ != nil {
		_error_ = &Error{C.GoString((*C.char)(unsafe.Pointer(_cgo_error_.message)))}
		defer C.g_error_free(_cgo_error_)
	}
	_go__return__ = ToPixbuf(unsafe.Pointer(_return_))
	return
}
Beispiel #25
0
// Add adds new credentials to the keychain.
func (h Secretservice) Add(creds *credentials.Credentials) error {
	if creds == nil {
		return errors.New("missing credentials")
	}
	server := C.CString(creds.ServerURL)
	defer C.free(unsafe.Pointer(server))
	username := C.CString(creds.Username)
	defer C.free(unsafe.Pointer(username))
	secret := C.CString(creds.Secret)
	defer C.free(unsafe.Pointer(secret))

	if err := C.add(server, username, secret); err != nil {
		defer C.g_error_free(err)
		errMsg := (*C.char)(unsafe.Pointer(err.message))
		return errors.New(C.GoString(errMsg))
	}
	return nil
}
Beispiel #26
0
func PixbufNewFromResourceAtScale(resource_path string, width C.int, height C.int, preserve_aspect_ratio bool) (_go__return__ Pixbuf, _error_ error) {
	var _cgo_error_ *C.GError
	var _return_ *C.GdkPixbuf
	_cstring_resource_path_ := C.CString(resource_path)
	_cgo_resource_path_ := (*C.char)(unsafe.Pointer(_cstring_resource_path_))
	defer C.free(unsafe.Pointer(_cstring_resource_path_))
	_cgo_preserve_aspect_ratio_ := (C.gboolean)(C.FALSE)
	if preserve_aspect_ratio {
		_cgo_preserve_aspect_ratio_ = (C.gboolean)(C.TRUE)
	}
	_return_ = C._gdk_pixbuf_new_from_resource_at_scale(_cgo_resource_path_, width, height, _cgo_preserve_aspect_ratio_, unsafe.Pointer(&_cgo_error_))
	if _cgo_error_ != nil {
		_error_ = &Error{C.GoString((*C.char)(unsafe.Pointer(_cgo_error_.message)))}
		defer C.g_error_free(_cgo_error_)
	}
	_go__return__ = ToPixbuf(unsafe.Pointer(_return_))
	return
}
Beispiel #27
0
func gErrorToGoError(gerr *C.GError) error {
	if gerr == nil {
		return errors.New("Poppler/GLib: unknown error")
	}

	defer C.g_error_free(gerr)

	message := C.GoString((*C.char)(gerr.message))
	if message == "No error" {
		// Work around inconsistent error message when named file doesn't exist.
		quarkString := C.GoString((*C.char)(C.g_quark_to_string(gerr.domain)))
		if "g-file-error-quark" == quarkString {
			return fmt.Errorf("Poppler/GLib: file error, code %d", gerr.code)
		}
		return fmt.Errorf("Poppler/GLib: unknown error, domain %d, code %d", gerr.domain, gerr.code)
	}

	return fmt.Errorf("Poppler/GLib: %s", C.GoString((*C.char)(gerr.message)))
}
Beispiel #28
0
// Write() is a wrapper around gdk_pixbuf_loader_write().
func (v *PixbufLoader) Write(data []byte) (n int, err error) {
	// n is set to 0 on error, and set to len(data) otherwise.
	// This is a tiny hacky to satisfy io.Writer and io.WriteCloser,
	// which would allow access to all io and ioutil goodies,
	// and play along nice with go environment.

	if len(data) == 0 {
		return 0, nil
	}

	var cerr *C.GError
	ok := gobool(C.gdk_pixbuf_loader_write(v.Native(), (*C.guchar)(unsafe.Pointer(&data[0])), C.gsize(len(data)), &cerr))
	if !ok {
		defer C.g_error_free(cerr)
		return 0, errors.New(C.GoString((*C.char)(C.error_get_message(cerr))))
	}

	return len(data), nil
}
Beispiel #29
0
func PixbufNewFromInline(data_length int, data []byte, copy_pixels bool) (_go__return__ Pixbuf, _error_ error) {
	var _cgo_error_ *C.GError
	var _return_ *C.GdkPixbuf
	_cgo_data_length_ := (C.gint)(data_length)
	_cgo_copy_pixels_ := (C.gboolean)(C.FALSE)
	if copy_pixels {
		_cgo_copy_pixels_ = (C.gboolean)(C.TRUE)
	}
	_cstring_data_ := C.CString(string(data))
	defer C.free(unsafe.Pointer(_cstring_data_))
	_cgo_data_ := (*C.guint8)(unsafe.Pointer(_cstring_data_))
	_return_ = C._gdk_pixbuf_new_from_inline(_cgo_data_length_, _cgo_data_, _cgo_copy_pixels_, unsafe.Pointer(&_cgo_error_))
	if _cgo_error_ != nil {
		_error_ = &Error{C.GoString((*C.char)(unsafe.Pointer(_cgo_error_.message)))}
		defer C.g_error_free(_cgo_error_)
	}
	_go__return__ = ToPixbuf(unsafe.Pointer(_return_))
	return
}
Beispiel #30
0
// Similar to gst_parse_launch, but makes a bin instead of a pipeline
func ParseBinFromDescription(desc string) (*Bin, error) {
	en := (*C.gchar)(C.CString(desc))
	defer C.free(unsafe.Pointer(en))

	ghost_unlinked_pads := C.gboolean(1) // probably should be true? http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/gstreamer-GstParse.html#gst-parse-bin-from-description
	var Cerr *C.GError
	p := glib.Pointer(C.gst_parse_bin_from_description(en, ghost_unlinked_pads, &Cerr))
	if Cerr != nil {
		errStr := (*glib.Error)(unsafe.Pointer(Cerr)).Error()
		C.g_error_free(Cerr)
		return nil, errors.New(errStr)
	}
	if p == nil {
		return nil, nil
	}
	b := new(Bin)
	b.SetPtr(p)

	return b, nil
}