I'm new to XS and figure that fixing a bug in the Glib distribution might be a good way to get started. The latest stable release of Glib is 1.224. On 32-bit Strawberry Perl 5.10 `dmake test` reports numerous errors. I want to fix two:
t/e.t ...................... 1/243 # Failed test at t/e.t line 229. # got: '1' # expected: '2' # Failed test 'value 30 value unchanged' # at t/e.t line 231. # got: undef # expected: '30'
Here is the relevant part of e.t:
# # value_validate() and value_cmp() # { my $p = Glib::ParamSpec->int ('name','nick','blurb', 20, 50, 25, G_PARAM_READWRITE); ok (! scalar ($p->value_validate('30')), "value 30 valid"); my @a = $p->value_validate('30'); is (@a, 2); ok (! $a[0], "value 30 bool no modify (array context)"); is ($a[1], 30, "value 30 value unchanged");
And here is a link to the full source of e.t

phase 1: constructor call

The first thing that happens is a constructor calls of some sort:
my $p = Glib::ParamSpec->int ('name','nick','blurb', 20, 50, 25, G_PARAM_READWRITE);
And I cant find a `Glib::ParamSpec` class anywhere. I'm guess that in someway this line in GParamSpec.xs:
gperl_register_param_spec (G_TYPE_PARAM_INT, "Glib::Param::Int");
makes the  ->int() available as a constructor but I'm not sure.

calling value_validate

next, there is a call to a method value_validate, which is supposed to return 2 elements in array context. But for some reason on my distro it only returns one? And why is the 2nd value of the array undef instead of 30? Source code for value_validate follows:
MODULE = Glib::ParamSpec PACKAGE = Glib::ParamSpec PREFIX = g_pa +ram_ =for apidoc =signature bool = $paramspec->value_validate ($value) =signature (bool, newval) = $paramspec->value_validate ($value) In scalar context return true if $value must be modified to be valid for $paramspec, or false if it's valid already. In array context return also a new value which is $value made valid. $value must be the right type for $paramspec (with usual stringizing, numizing, etc). C<value_validate> checks the further restrictions such as minimum and maximum for a numeric type or allowed characters in a string. The "made valid" return is then for instance clamped to the min/max, or offending chars replaced by a substitutor. =cut void g_param_value_validate (GParamSpec * pspec, SV *value) PREINIT: GValue v = { 0, }; GType type; int modify, retcount=1; CODE: type = G_PARAM_SPEC_VALUE_TYPE (pspec); g_value_init (&v, type); gperl_value_from_sv (&v, value); modify = g_param_value_validate (pspec, &v); ST(0) = sv_2mortal (boolSV (modify)); if (GIMME_V == G_ARRAY) { /* If unmodified then can leave ST(1) "value" alone. If modified then expect that g_param_value_validate() will have made a new block of memory owned by the GValue and whi +ch will be freed at the g_value_unset(). For that reason ask _gperl_sv_from_value_internal() to "copy_boxed" to grab before it's freed. If g_param_value_validate() says modified but doesn't in fact modify but just leaves the GValue pointing into the input ST(1) "value" then we might prefer not to copy (but instead leave ST(1) as the return). Believe that shouldn't happen, ie. a value_validate vfunc shouldn't modify the input but rather if modifying something then it will put in new memory. Or alternately if it doesn't modify anything then it shouldn't say modified. (The Glib ref manual circa 2.27 doesn't have much guidance on this.) */ retcount = 2; if (modify) ST(1) = sv_2mortal (_gperl_sv_from_value_internal(&v,TRUE)); } g_value_unset (&v); XSRETURN(retcount);

In reply to XS Mentor Requested - debugging the Glib test suite by metaperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.