metaperl has asked for the wisdom of the Perl Monks concerning the following question:

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);

Replies are listed 'Best First'.
Re: XS Mentor Requested - debugging the Glib test suite
by syphilis (Archbishop) on Aug 06, 2011 at 00:10 UTC
    `dmake test` reports numerous errors

    I use this patch to GType.xs - and all Glib-1.224 tests pass for me on my Windows builds of perl (including both 32-bit and 64-bit perl-5.10.0).

    I don't recall where I found that patch, though I'm quite sure I can't take the credit for it.

    Cheers,
    Rob
      I downloaded patch for Windows and successfully applied the patch. then `perl Makefile.PL`, `dmake` and `dmake test`. But I will got my same errors:
      C:\Users\thequietcenter\prg\Glib-1.224>dmake test C:\strawberry\perl\bin\perl.exe "-MExtUtils::Command::MM" "-e" "test_h +arness(0, 'blib\lib', 'blib\arch')" t/*.t t/1.t ...................... ok t/2.t ...................... ok t/3.t ...................... ok t/4.t ...................... ok t/5.t ...................... ok t/6.t ...................... ok t/64bit.t .................. ok t/7.t ...................... ok t/8.t ...................... ok t/9.t ...................... ok t/a.t ...................... ok t/b.t ...................... ok t/c.t ...................... ok t/d.t ...................... ok 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' # Failed test 'clamp 70 down to be in range' # at t/e.t line 235. # got: undef # expected: '50' # Failed test 'clamp -70 down to be in range' # at t/e.t line 238. # got: undef # expected: '20' # Looks like you failed 4 tests of 243. t/e.t ...................... Dubious, test returned 4 (wstat 1024, 0x4 +00) Failed 4/243 subtests t/f.t ...................... ok t/filename.t ............... ok t/g.t ...................... 1/33 # Failed test at t/g.t line 155. # got: undef # expected: 'C:\Users\thequietcenter\prg\Glib-1.224\tmp.ini' # Looks like you failed 1 test of 33. t/g.t ...................... Dubious, test returned 1 (wstat 256, 0x10 +0) Failed 1/33 subtests t/h.t ...................... ok t/lazy_loader.t ............ ok t/make_helper.t ............ ok t/options.t ................ ok t/signal_emission_hooks.t .. ok t/signal_marshal.t ......... ok t/signal_query.t ........... ok t/tied_definedness.t ....... ok Test Summary Report ------------------- t/e.t (Wstat: 1024 Tests: 243 Failed: 4) Failed tests: 234, 236, 238, 240 Non-zero exit status: 4 t/g.t (Wstat: 256 Tests: 33 Failed: 1) Failed test: 32 Non-zero exit status: 1 Files=26, Tests=828, 7 wallclock secs ( 0.36 usr + 0.13 sys = 0.48 +CPU) Result: FAIL Failed 2/26 test programs. 5/828 subtests failed. dmake: Error code 255, while making 'test_dynamic' C:\Users\thequietcenter\prg\Glib-1.224>




      The mantra of every experienced web application developer is the same: thou shalt separate business logic from display. Ironically, almost all template engines allow violation of this separation principle, which is the very impetus for HTML template engine development.

      -- Terence Parr, "Enforcing Strict Model View Separation in Template Engines"