Skip to content

Commit

Permalink
fix method cache generation when package contains blessed subs
Browse files Browse the repository at this point in the history
When generating the method cache, the code was trying to call ->body on
it if it was an object.  The add_method code had previously been fixed
to only call ->body on meta objects rather than anything blessed.  The
XS code was only checking for objects being making that call.  This was
masked by method cache being kept up to date.

If the method cache is out of date though, this can crash.  The cache
can be intentionally reset, or we may not be able to track its status
properly (perl 5.8 without Class::C3::XS).

Fixes RT#113704
  • Loading branch information
haarg committed Apr 13, 2016
1 parent 3471200 commit 0bb2719
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ for, noteworthy changes.

{{$NEXT}}

[BUG FIXES]

- Fixed method cache regeneration when a class contains a blessed sub
(RT#113704)

[TESTS]

- restore test on perl 5.8.x when Class::C3::XS is not installed (RT#113704)
Expand Down
6 changes: 6 additions & 0 deletions t/cmop/methods.t
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ is( exception {
$Foo->add_method('bork', $bork_blessed);
}, undef, 'can add blessed sub as method');

$Foo->reset_package_cache_flag;

is( exception {
$Foo->has_method('bork');
}, undef, 'regeneration of method cache works after adding blessed sub as method');

# now check all our other items ...

ok( $Foo->has_method('FOO_CONSTANT'),
Expand Down
2 changes: 1 addition & 1 deletion xs/HasMethods.xs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mop_update_method_map(pTHX_ HV *const stash, HV *const map)
continue;
}

if (sv_isobject(method)) {
if (sv_derived_from(method, "Class::MOP::Method")) {
/* $method_object->body() */
body = mop_call0(aTHX_ method, KEY_FOR(body));
}
Expand Down

0 comments on commit 0bb2719

Please sign in to comment.