Stop "sv_2mortal(&PL_sv_yes)" and "(void)sv_newmortal()" in ParseXS
authorDaniel Dragan <bulk88@hotmail.com>
Sat, 25 May 2013 16:06:27 +0000 (18:06 +0200)
committerSteffen Mueller <smueller@cpan.org>
Tue, 25 Jun 2013 06:00:26 +0000 (08:00 +0200)
commitfc5771079abcc2fce5ac42d93197705063548366
treeb18134e56f5bace3ab8b6b38ae95ed6c8832eca6
parent9219b11479eb6fd9204645473f445cc7bc2b0167
Stop "sv_2mortal(&PL_sv_yes)" and "(void)sv_newmortal()" in ParseXS

This problem was brought up in #115796.  Both of those lines of code that
ParseXS put out when dealing with T_BOOL were unnecessary, and caused a
some inefficiencies (extra calls). Since typemaps can have complicated
evaluation and include Perl code, see commit    9712754a3e, it is best to
eval the typemap entry first, then regexp it to see what it looks like,
not regexp the unevaled entry possibly containing Perl. In case a typemap
entry is maintaining state inside ParseXS (venturing into the undocumented
and unsupported), (I've never seen it done) don't eval it twice if it can
be avoided. Someone might want to change the typemap entry to multiple
eval in the future, but don't introduce it now if it can be avoided.

Using T_BOOL by name to see an immortal is a bad idea, since any XS module
can reuse the typemap entry, so best to regexp for something that looks
like it would return an immortal, "= &PL_sv_* ;" or "= boolSV(". In the
future someone might want to introduce a macro that does nothing, except
gives a signal to ParseXS that an expression returns an immortal or an
already mortaled SV, to suppress the sv_2mortal call.

The tests in 001-basic.t might break in the future with changes to ParseXS
or the Perl API, but I assume they will be fixed at that point in time.

Note: This patch was amended by the committer to apply cleanly to a
newer version of ExtUtils::ParseXS and to include all necessary test
changes.
dist/ExtUtils-ParseXS/Changes
dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm
dist/ExtUtils-ParseXS/t/001-basic.t
dist/ExtUtils-ParseXS/t/XSTest.xs
dist/ExtUtils-ParseXS/t/typemap