develooper Front page | perl.perl5.porters | Postings from January 2018

[perl #132768] OP_ENTERSUB is not called for constructor of tiedobject

Thread Next
From:
KES
Date:
January 25, 2018 18:00
Subject:
[perl #132768] OP_ENTERSUB is not called for constructor of tiedobject
Message ID:
rt-4.0.24-15198-1516903229-1365.132768-75-0@perl.org
# New Ticket Created by  KES 
# Please include the string:  [perl #132768]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=132768 >


To: perlbug@perl.org
From: kes-kes@yandex.ru
Subject: OP_ENTERSUB is not called for constructor of tied object
Message-Id: <5.24.0_23043_1516902196@work>
Reply-To: kes-kes@yandex.ru
Cc: kes-kes@yandex.ru


This is a bug report for perl from kes-kes@yandex.ru,
generated with the help of perlbug 1.40 running under perl 5.24.0.


-----------------------------------------------------------------
[Please describe your issue here]

TLDR;
When we tie scalar to 'MyObj' class the MyObj::TIESCALAR is called
but OP_ENTERSUB is not executed before that. 
But still we can see OP_LEAVESUB for it


How to reproduce:
$cat script.pl
package Obj;
sub DESTROY {
    print "DESTROY\n";
}

sub new{ bless {} };
package MyTie;

our $test;

sub TIESCALAR {
    bless {}, 'MyTie::Scalar';
}

package MyTie::Scalar;

package main;

sub MyTie::Scalar::FETCH {
    local $MyTie::test = Obj->new;
    print "FETCHed\n";
    return 7;
}


my $x;
tie $x, 'MyTie';
{
    local $MyTie::test = 3;
    print $x;

    print "TEST: $MyTie::test\n";
}


$cat script.xs
#define PERL_NO_GET_CONTEXT
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

#include "ppport.h"

int
My_runops2(pTHX){
    SV* id =  get_sv("DB::runops_id", GV_ADD|GV_ADDMULTI);
    save_item( id );
    sv_inc_nomg( id );
    int idv = SvIV( id );

    printf( "Run OP start(%d)\n", idv );

    SV *tv =  newSVpvs( "MyTie::Scalar" );

    OP *o; CV *cv; SV *pkg;
    while( PL_op ) {
        o =  PL_op;

        SV* intv =  get_sv("DB::intv", 0);
        printf( "OP Type: %d -- %s intv:%d\n", o->op_type, OP_DESC( o ), SvTRUE( intv ) );

        switch( o->op_type ) {
        case OP_ENTERSUB:;
            PL_op = o =  CALL_FPTR(o->op_ppaddr)(aTHX);

            cv =  find_runcv(0);
            pkg = newSVpv( HvNAME( GvSTASH(CvGV(cv)) ), 0 );
            printf( "ENTER: %s::%s\n", SvPV_nolen( pkg ), GvNAME( CvGV(cv) ) );

            // sv_dump( cv );
            break;
        case OP_LEAVESUB:;

            cv =  find_runcv(0);
            pkg = newSVpv( HvNAME( GvSTASH(CvGV(cv)) ), 0 );
            printf( "LEAVE: %s::%s\n", SvPV_nolen( pkg ), GvNAME( CvGV(cv) ) );


            // sv_dump( cv );
            break;
        }


        PL_op = CALL_FPTR(o->op_ppaddr)(aTHX);
    }

    printf( "Run OP finish (%d)\n", idv );

    PERL_ASYNC_CHECK();
    TAINT_NOT;
    return 0;
}

MODULE = Module                    PACKAGE = Module
BOOT:
    get_sv("DB::intv",   GV_ADD|GV_ADDMULTI);

    PL_runops =  My_runops2;

$perl -MModule script.pl
Run OP start(1)
OP Type: 0 -- null operation intv:0
OP Type: 5 -- constant item intv:0
OP Type: 68 -- string intv:0
Run OP finish (1)
Run OP start(1)
OP Type: 0 -- null operation intv:0
OP Type: 5 -- constant item intv:0
OP Type: 68 -- string intv:0
Run OP finish (1)
Run OP start(1)
OP Type: 196 -- block entry intv:0
OP Type: 193 -- next statement intv:0
OP Type: 9 -- private variable intv:0
OP Type: 193 -- next statement intv:0
OP Type: 3 -- pushmark intv:0
OP Type: 9 -- private variable intv:0
OP Type: 5 -- constant item intv:0
OP Type: 226 -- tie intv:0

/*** here TIESCALAR is called but there is no OP_ENTERSUB for it ***/
Run OP start(2)
OP Type: 193 -- next statement intv:0
OP Type: 3 -- pushmark intv:0
OP Type: 161 -- anonymous hash ({}) intv:0
OP Type: 5 -- constant item intv:0
OP Type: 23 -- bless intv:0
OP Type: 186 -- subroutine exit intv:0
LEAVE: MyTie::TIESCALAR
Run OP finish (2)

/*** Actually next is not relevant, but provided for completeness ***/

OP Type: 193 -- next statement intv:0
OP Type: 201 -- loop entry intv:0
OP Type: 193 -- next statement intv:0
OP Type: 5 -- constant item intv:0
OP Type: 6 -- scalar variable intv:0
OP Type: 37 -- scalar assignment intv:0
OP Type: 193 -- next statement intv:0
OP Type: 3 -- pushmark intv:0
OP Type: 9 -- private variable intv:0
OP Type: 238 -- print intv:0
Run OP start(2)
OP Type: 210 -- method with known name intv:0
OP Type: 185 -- subroutine entry intv:0
ENTER: MyTie::Scalar::FETCH
OP Type: 3 -- pushmark intv:0
OP Type: 5 -- constant item intv:0
OP Type: 210 -- method with known name intv:0
OP Type: 185 -- subroutine entry intv:0
ENTER: Obj::new
OP Type: 3 -- pushmark intv:0
OP Type: 161 -- anonymous hash ({}) intv:0
OP Type: 23 -- bless intv:0
OP Type: 186 -- subroutine exit intv:0
LEAVE: Obj::new
OP Type: 6 -- scalar variable intv:0
OP Type: 37 -- scalar assignment intv:0
OP Type: 193 -- next statement intv:0
OP Type: 3 -- pushmark intv:0
OP Type: 5 -- constant item intv:0
OP Type: 238 -- print intv:0
FETCHed
OP Type: 193 -- next statement intv:0
OP Type: 5 -- constant item intv:0
OP Type: 186 -- subroutine exit intv:0
LEAVE: MyTie::Scalar::FETCH
Run OP start(3)
OP Type: 193 -- next statement intv:0
OP Type: 3 -- pushmark intv:0
OP Type: 5 -- constant item intv:0
OP Type: 238 -- print intv:0
DESTROY
OP Type: 186 -- subroutine exit intv:0
LEAVE: Obj::DESTROY
Run OP finish (3)
Run OP finish (2)
OP Type: 193 -- next statement intv:0
OP Type: 3 -- pushmark intv:0
OP Type: 5 -- constant item intv:0
OP Type: 6 -- scalar variable intv:0
OP Type: 67 -- concatenation (.) or string intv:0
OP Type: 5 -- constant item intv:0
OP Type: 67 -- concatenation (.) or string intv:0
OP Type: 238 -- print intv:0
7TEST: 3
OP Type: 202 -- loop exit intv:0
OP Type: 197 -- block exit intv:0
Run OP finish (1)


[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=low
---
Site configuration information for perl 5.24.0:

Configured by kes at Wed Oct 19 14:07:47 EEST 2016.

Summary of my perl5 (revision 5 version 24 subversion 0) configuration:
   
  Platform:
    osname=linux, osvers=4.4.0-43-generic, archname=x86_64-linux
    uname='linux work 4.4.0-43-generic #63-ubuntu smp wed oct 12 13:48:03 utc 2016 x86_64 x86_64 x86_64 gnulinux '
    config_args='-de -Dprefix=/home/kes/perl5/perlbrew/perls/perl-5.24.0 -Aeval:scriptdir=/home/kes/perl5/perlbrew/perls/perl-5.24.0/bin'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
    ccversion='', gccversion='5.4.0 20160609', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678, doublekind=3
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16, longdblkind=3
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -fstack-protector-strong -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib/gcc/x86_64-linux-gnu/5/include-fixed /usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib /lib64 /usr/lib64
    libs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.23.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.23'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector-strong'

Locally applied patches:
    Devel::PatchPerl 1.38

---
@INC for perl 5.24.0:
    /home/kes/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0/x86_64-linux
    /home/kes/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0
    /home/kes/perl5/perlbrew/perls/perl-5.24.0/lib/5.24.0/x86_64-linux
    /home/kes/perl5/perlbrew/perls/perl-5.24.0/lib/5.24.0
    .

---
Environment for perl 5.24.0:
    HOME=/home/kes
    LANG=en_US.UTF-8
    LANGUAGE=en
    LC_ADDRESS=uk_UA.UTF-8
    LC_IDENTIFICATION=uk_UA.UTF-8
    LC_MEASUREMENT=uk_UA.UTF-8
    LC_MESSAGES=en_US.UTF-8
    LC_MONETARY=uk_UA.UTF-8
    LC_NAME=uk_UA.UTF-8
    LC_NUMERIC=uk_UA.UTF-8
    LC_PAPER=uk_UA.UTF-8
    LC_TELEPHONE=uk_UA.UTF-8
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/kes/perl5/perlbrew/bin:/home/kes/perl5/perlbrew/perls/perl-5.24.0/bin:/home/kes/bin:/home/kes/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
    PERLBREW=command perlbrew
    PERLBREW_BASHRC_VERSION=0.78
    PERLBREW_HOME=/home/kes/.perlbrew
    PERLBREW_MANPATH=/home/kes/perl5/perlbrew/perls/perl-5.24.0/man
    PERLBREW_PATH=/home/kes/perl5/perlbrew/bin:/home/kes/perl5/perlbrew/perls/perl-5.24.0/bin
    PERLBREW_PERL=perl-5.24.0
    PERLBREW_ROOT=/home/kes/perl5/perlbrew
    PERLBREW_VERSION=0.78
    PERL_BADLANG (unset)
    SHELL=/bin/bash


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