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

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

Thread Previous | Thread Next
From:
John Unsworth - CP Meta Support
Date:
September 10, 2013 06:14
Subject:
RE: [perl #119617] PerlEmbed 5.14: sv_setsv(ERRSV, &PL_sv_undef); crashes on Linux
Message ID:
000001ceab1a$29aebd20$7d0c3760$@cp.net
Hi James,

I'm afraid I'm failing miserably with this. I have extracted the calls that our code makes into a windows console application but it crashes on the call to CLEAR_ERRSV(). Everything else seems to work OK if I remove the call. I can see that vTHX->Ierrgv returns zero. I have attached the code and test script. It is built against 5.14 from ActiveState. Let me know what you suggest.

Regards,
John.

Summary of my perl5 (revision 5 version 14 subversion 1) configuration:

  Platform:
    osname=MSWin32, osvers=5.2, archname=MSWin32-x86-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=undef, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cl', ccflags ='-nologo -GF -W3 -MD -Zi -DNDEBUG -O1 -DWIN32 -D_CONSOLE -
DNO_STRICT -DPERL_TEXTMODE_SCRIPTS -DUSE_SITECUSTOMIZE -DPERL_IMPLICIT_CONTEXT -
DPERL_IMPLICIT_SYS -DUSE_PERLIO -D_USE_32BIT_TIME_T',
    optimize='-MD -Zi -DNDEBUG -O1',
    cppflags='-DWIN32'
    ccversion='12.00.8168', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=8
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64', lseeksi
ze=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='link', ldflags ='-nologo -nodefaultlib -debug -opt:ref,icf  -libpath:"C:
\Perl\lib\CORE"  -machine:x86'
    libpth=\lib
    libs=oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib  comdlg32.l
ib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib uuid.lib ws2_32
.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib comctl32.lib msvcrt.
lib
    perllibs=oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib  comdlg
32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib uuid.lib ws
2_32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib comctl32.lib msv
crt.lib
    libc=msvcrt.lib, so=dll, useshrplib=true, libperl=perl514.lib
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug -opt:ref,icf  -
libpath:"C:\Perl\lib\CORE"  -machine:x86'


Characteristics of this binary (from libperl):
  Compile-time options: MULTIPLICITY PERL_DONT_CREATE_GVSV
                        PERL_IMPLICIT_CONTEXT PERL_IMPLICIT_SYS
                        PERL_MALLOC_WRAP PERL_PRESERVE_IVUV PL_OP_SLAB_ALLOC
                        USE_ITHREADS USE_LARGE_FILES USE_PERLIO USE_PERL_ATOF
                        USE_SITECUSTOMIZE
  Locally applied patches:
        ActivePerl Build 1401 [294969]
  Built under MSWin32
  Compiled at Jun 16 2011 18:54:40
  @INC:
    C:/Perl514/site/lib
    C:/Perl514/lib

Regards,
John

-----Original Message-----
From: James E Keenan via RT [mailto:perlbug-followup@perl.org] 
Sent: 06 September 2013 00:22
To: john.unsworth@cp.net
Subject: [perl #119617] PerlEmbed 5.14: sv_setsv(ERRSV, &PL_sv_undef); crashes on Linux

On Thu Sep 05 04:18:28 2013, john.unsworth@cp.net wrote:
> This is a bug report for perl from john.unsworth@cp.net,
> 
> generated with the help of perlbug 1.39 running under perl 5.10.1.
> 
>  
> 
> 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.
> 


Would it be possible for you to attach a file which reproduces this problem either (a) in a file in a pure Perl format; or (b) in a minimal
C++ program calling a small Perl program?

Thank you very much.
Jim Keenan

Thread Previous | Thread Next


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