Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

constant pragma doesn't warn on redefinition of a list constant #20742

Closed
djerius opened this issue Jan 26, 2023 · 1 comment · Fixed by #20761
Closed

constant pragma doesn't warn on redefinition of a list constant #20742

djerius opened this issue Jan 26, 2023 · 1 comment · Fixed by #20761

Comments

@djerius
Copy link

djerius commented Jan 26, 2023

Module: constant

Description

Redefining a list constant does not produce a warning.

Steps to Reproduce

This redefinition of a scalar constant warns:

$ perl -Mconstant=Scalar,1  -Mconstant=Scalar,4 -E 'say join ", ", Scalar'
Constant subroutine main::Scalar redefined at .../5.36.0/lib/perl5/5.36.0/constant.pm line 171.
4

But this redefinition of a list one doesn't:

$ perl -Mconstant=List,1,2,3  -Mconstant=List,4,5,6 -E 'say join ", ", List'
4, 5, 6

Expected behavior

I expected to see a warning when redefining the list constant.

Perl configuration

Summary of my perl5 (revision 5 version 36 subversion 0) configuration:
   
  Platform:
    osname=linux
    osvers=5.10.0-14-amd64
    archname=x86_64-linux
    uname='linux leafhopper 5.10.0-14-amd64 #1 smp debian 5.10.113-1 (2022-04-29) x86_64 gnulinux '
    config_args='-Dprefix=/home/dj/.plenv/versions/5.36.0 -de -Dversiononly -A'eval:scriptdir=/home/dj/.plenv/versions/5.36.0/bin''
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=undef
    usemultiplicity=undef
    use64bitint=define
    use64bitall=define
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
  Compiler:
    cc='cc'
    ccflags ='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2'
    optimize='-O2'
    cppflags='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
    ccversion=''
    gccversion='10.2.1 20210110'
    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/x86_64-linux-gnu /usr/lib /usr/lib64
    libs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.31.so
    so=so
    useshrplib=false
    libperl=libperl.a
    gnulibc_version='2.31'
  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'


Characteristics of this binary (from libperl): 
  Compile-time options:
    HAS_TIMES
    PERLIO_LAYERS
    PERL_COPY_ON_WRITE
    PERL_DONT_CREATE_GVSV
    PERL_MALLOC_WRAP
    PERL_OP_PARENT
    PERL_PRESERVE_IVUV
    USE_64_BIT_ALL
    USE_64_BIT_INT
    USE_LARGE_FILES
    USE_LOCALE
    USE_LOCALE_COLLATE
    USE_LOCALE_CTYPE
    USE_LOCALE_NUMERIC
    USE_LOCALE_TIME
    USE_PERLIO
    USE_PERL_ATOF
  Built under linux
  Compiled at May 31 2022 10:50:24
  %ENV:
    PERL_CPANM_OPT="--cascade-search --mirror-only  --mirror /home/dj/Work/darkpan --mirror http://www.cpan.org"
    PERL_CPAN_MIRROR_TINY_BASE="/home/dj/Work/darkpan"
  @INC:
    /home/dj/.plenv/versions/5.36.0/lib/perl5/site_perl/5.36.0/x86_64-linux
    /home/dj/.plenv/versions/5.36.0/lib/perl5/site_perl/5.36.0
    /home/dj/.plenv/versions/5.36.0/lib/perl5/5.36.0/x86_64-linux
    /home/dj/.plenv/versions/5.36.0/lib/perl5/5.36.0



@tonycoz
Copy link
Contributor

tonycoz commented Feb 1, 2023

I've reproduced this and I see the cause.

While reviewing the code I found a related problem:

tony@venus:.../docs/perl5$ ~/perl/v5.36.0-dbg-san/bin/perl -Mconstant=x,1,2 -e 'sub x() { 1 }'
perl: sv.c:2820: char *Perl_sv_2pv_flags(SV *const, STRLEN *const, const U32): Assertion `SvTYPE(sv) != SVt_PVAV && SvTYPE(sv) != SVt_PVHV && SvTYPE(sv) != SVt_PVFM' failed.
Aborted

Both that and the reported issue are core bugs rather than bugs in constant.pm

tonycoz added a commit to tonycoz/perl5 that referenced this issue Feb 1, 2023
The code in report_redefined_cv() would check whether the old
constant and the new constant were the same SV to avoid warning on
duplicate imports of the same constant.  Since both gv_setref()
and report_redefined_cv() used cv_const_sv() to fetch the constant
SV, which returns NULL for an AV based constant sub, the check
for the equivalent SV would compare NULL to NULL and
report_redefined_cv() would return early.

Additional checks were required further down to prevent sv_cmp()
being called on AVs.

The check for simple SV's allow redefinition of constant subs if the
new value string compares the same as the old value.  The AV check
does not try to allow that.

Fixed Perl#20742
tonycoz added a commit that referenced this issue Feb 8, 2023
The code in report_redefined_cv() would check whether the old
constant and the new constant were the same SV to avoid warning on
duplicate imports of the same constant.  Since both gv_setref()
and report_redefined_cv() used cv_const_sv() to fetch the constant
SV, which returns NULL for an AV based constant sub, the check
for the equivalent SV would compare NULL to NULL and
report_redefined_cv() would return early.

Additional checks were required further down to prevent sv_cmp()
being called on AVs.

The check for simple SV's allow redefinition of constant subs if the
new value string compares the same as the old value.  The AV check
does not try to allow that.

Fixed #20742
pjacklam pushed a commit to pjacklam/perl5 that referenced this issue May 20, 2023
The code in report_redefined_cv() would check whether the old
constant and the new constant were the same SV to avoid warning on
duplicate imports of the same constant.  Since both gv_setref()
and report_redefined_cv() used cv_const_sv() to fetch the constant
SV, which returns NULL for an AV based constant sub, the check
for the equivalent SV would compare NULL to NULL and
report_redefined_cv() would return early.

Additional checks were required further down to prevent sv_cmp()
being called on AVs.

The check for simple SV's allow redefinition of constant subs if the
new value string compares the same as the old value.  The AV check
does not try to allow that.

Fixed Perl#20742
pjacklam pushed a commit to pjacklam/perl5 that referenced this issue May 20, 2023
The code in report_redefined_cv() would check whether the old
constant and the new constant were the same SV to avoid warning on
duplicate imports of the same constant.  Since both gv_setref()
and report_redefined_cv() used cv_const_sv() to fetch the constant
SV, which returns NULL for an AV based constant sub, the check
for the equivalent SV would compare NULL to NULL and
report_redefined_cv() would return early.

Additional checks were required further down to prevent sv_cmp()
being called on AVs.

The check for simple SV's allow redefinition of constant subs if the
new value string compares the same as the old value.  The AV check
does not try to allow that.

Fixed Perl#20742
khwilliamson pushed a commit to khwilliamson/perl5 that referenced this issue Jul 10, 2023
The code in report_redefined_cv() would check whether the old
constant and the new constant were the same SV to avoid warning on
duplicate imports of the same constant.  Since both gv_setref()
and report_redefined_cv() used cv_const_sv() to fetch the constant
SV, which returns NULL for an AV based constant sub, the check
for the equivalent SV would compare NULL to NULL and
report_redefined_cv() would return early.

Additional checks were required further down to prevent sv_cmp()
being called on AVs.

The check for simple SV's allow redefinition of constant subs if the
new value string compares the same as the old value.  The AV check
does not try to allow that.

Fixed Perl#20742
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants