develooper Front page | perl.perl5.porters | Postings from September 2013

[perl #119617] PerlEmbed 5.14: sv_setsv(ERRSV, &PL_sv_undef); crashes on Linux

Thread Previous
From:
Tony Cook via RT
Date:
September 10, 2013 01:46
Subject:
[perl #119617] PerlEmbed 5.14: sv_setsv(ERRSV, &PL_sv_undef); crashes on Linux
Message ID:
rt-3.6.HEAD-1873-1378777568-1554.119617-15-0@perl.org
On Thu Sep 05 04:18:28 2013, john.unsworth@cp.net wrote:
> The C++ application calling Perl worked correctly up to Perl 5.10. However
> when I upgraded to 5.14 it cores on Linux; it continues to work OK on
> Windows.
> 
>  
> 
> This is reported just before the core:
> 
>  
> 
> Bizarre copy of UNKNOWN.
> 
> Segmentation fault (core dumped)
> 
>  
> 
> By adding trace lines I found that the call to sv_setsv(ERRSV,
> &PL_sv_undef); was causing the crash
> 
>  
> 
> I looked into the header files and found a macro CLEAR_ERROR. At 5.10 this
> is defined as:
> 
>  
> 
> #define ERRSV GvSV(PL_errgv) 
> 
> #define CLEAR_ERRSV() STMT_START { sv_setpvn(ERRSV,"",0); if
> (SvMAGICAL(ERRSV)) { mg_free(ERRSV); } SvPOK_only(ERRSV); } STMT_END
> 
>  
> 
> However at 5.14 it is:
> 
>  
> 
> #define ERRSV GvSVn(PL_errgv)
> 
> #define CLEAR_ERRSV() STMT_START {                          \
> 
>     if (!GvSV(PL_errgv)) {                                  \
> 
>       sv_setpvs(GvSV(gv_add_by_type(PL_errgv, SVt_PV)), "");            \
> 
>     } else if (SvREADONLY(GvSV(PL_errgv))) {                      \
> 
>       SvREFCNT_dec(GvSV(PL_errgv));                         \
> 
>       GvSV(PL_errgv) = newSVpvs("");                              \
> 
>     } else {                                                \
> 
>       SV *const errsv = GvSV(PL_errgv);                     \
> 
>       sv_setpvs(errsv, "");                                 \
> 
>       if (SvMAGICAL(errsv)) {                               \
> 
>           mg_free(errsv);                                   \
> 
>       }                                               \
> 
>       SvPOK_only(errsv);                                    \
> 
>     }                                                 \
> 
>     } STMT_END
> 
>  
> 
> So it seems that the implementation of ERRSV has changed in that at
5.14 it
> is not initially defined, hence I assume that sv_setsv(ERRSV,
&PL_sv_undef);
> was trying to set an undefined variable and thus causing the error. The
> correct fix seems to be to change this to CLEAR_ERRSV(). Shouldn't this be
> mentioned in the embed documentation? There is no mention at all of how to
> reset the error variable.

Why do you need to clear ERRSV?

It should be cleared by eval_sv() or call_sv() on success (unless you
use G_KEEPERR).

While I think documenting CLEAR_ERRSV() is useful, I'm not sure where
you'd need to use it outside the core.

The example code Jim asked for would be useful.

Tony

---
via perlbug:  queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=119617

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About