Re: GtkImageView
- From: muppet <scott asofyet org>
- To: gtk2-perl List <gtk-perl-list gnome org>
- Subject: Re: GtkImageView
- Date: Sun, 17 Feb 2008 02:03:24 -0500
On Feb 15, 2008, at 5:47 PM, Jeffrey Ratcliffe wrote:
On 15/02/2008, muppet <scott asofyet org> wrote:
Still another option, more correct but more work, is to register a
GBoxed wrapper for the structure. Then everything will Just Wonk.
OK. I think I have got the GBoxed wrappers working.
Now that you have a GBoxed GType for the struct (that can go upstream
just like the GEnum GTypes), you can also register the functions to
marshal the value to and from perl. See gperl_register_boxed() in
Glib::xsapi.
Torsten recently added to Glib some useful functions for this
purpose,
including gperl_sv_is_hash_ref():
That would be excellent, apart from it being too new to be in any
current distribution.
A primitive replacement that you can use on those older versions would
be
#ifndef gperl_sv_is_hash_ref
#define gperl_sv_is_hash_ref(sv) \
((sv) && SvOK (sv) && SvROK (sv) && SvTYPE (SvRV (sv)) == SVt_PVHV)
#endif
Just put that in the xs file where you want to use it, somewhere
before you call it. (The tests are "is it non-null, a valid scalar, a
reference, and a reference to a hash?")
This doesn't handle magical SVs (which is why Torsten created
gperl_sv_is_defined()), but it's enough to get you by for what you need.
Blessing the hash would help you do even more validation, but is not
strictly necessary. If your user is allowed to supply a plain old
hash of his own making, then requiring a blessed hash will be
breakage, but if the user is supposed to use one of your methods to
create one of these things, then blessing the hash is A Very Good
Idea.
If I wanted to bless the hash, I assume I would have to do it in the
SV *
newSVGdkPixbufDrawOpts
function, and therefore above the MODULE, which is pure C, and
ST(0) = sv_newmortal();
sv_setref_pv(ST(0), "Gtk2::Gdk::Pixbuf::Draw::Opts", (void*)RETVAL);
isn't going to work. How do I do it?
HV * hv;
hv = newHV ();
...
return sv_bless (newRV_noinc ((SV *) hv), gv_stashpv
("Gtk2::Gdk::Pixbuf::Draw::Opts", TRUE));
To check it on the other end,
if (! sv_derived_from (sv, "Gtk2::Gdk::Pixbuf::Draw::Opts"))
croak ("It ain't a drawopts, yo!");
Lastly, I am getting
IImageTool.c: In function 'XS_Gtk2__ImageView__Tool_paint_image':
IImageTool.c:96: warning: initialization makes pointer from integer
without a cast
which is
GdkPixbufDrawOpts * opts = SvGdkPixbufDrawOpts (ST(1));
as SvGdkPixbufDrawOpts is defined as a GdkPixbufDrawOpts * in
DrawCache.xs, I assume it is saying that ST(1) isn't SV *. But I don't
see how to fix it.
I don't have the code building at the moment, but that usually means
you don't have a prototype for SvGdkPixbufDrawOpts() in that file. If
you refer to a function without a prototype or prior declaration, C is
defined to assume it returns an int.
I'll guess that this is in the file from which you removed the static
definition of SvGdkPixbufDrawOpts(). Make sure you're getting the
prototype from a header.
--
elysse: You dance better than some.
me: "Some" what?
elysse: Some asparagus.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]