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

bless \( my $x = undef ); fails under Perl 5.37.4.

Thread Next
From:
harryfmudd
Date:
September 22, 2022 17:13
Subject:
bless \( my $x = undef ); fails under Perl 5.37.4.
Message ID:
511521431.656907.1663866778257@connect.xfinity.com
This is a bug report for perl from wyant@cpan.org,
generated with the help of perlbug 1.43 running under perl 5.37.4.

-----------------------------------------------------------------
<!--[Please describe your issue here]-->

**Description**

I had some code that blessed a reference to a scalar that was
initialized to undef. This throws a fatal error under Perl 5.37.4,
though it worked under previous releases. A one-liner reproducing the
problem is below, together with results under a selection of Perl
versions.

NOTE that the failing code takes a reference to the statement that
creates and initializes the variable.

**Steps to Reproduce**

$ perl -E '$| = 1; print "$^V: "; say bless \( my $x = undef );'
v5.36.0: main=SCALAR(0x7fa549025778)
v5.37.3: main=SCALAR(0x7fa3bb826008)
v5.37.4: Modification of a read-only value attempted at -e line 1.

I actually first noticed this in a CPAN testers run against blead, and
was able to reproduce it under 6a011f13d7690dbe2e03ad7500756c983bcb1834.

**Expected behavior**

The error goes away if you create and initialize the variable in a
separate statement:

$ perl -E '$| = 1; print "$^V: "; my $x = undef; say bless \$x;'
v5.36.0: main=SCALAR(0x7fb03c825778)
v5.37.3: main=SCALAR(0x7f822a026008)
v5.37.4: main=SCALAR(0x7fa28a825820)

I would have expected 5.37.4 to produce this behavior with the original
code.

<!--[Please do not change anything below this line]-->
<!------------------------------------------------------------------- -->

---
**Flags**
- category=core
- severity=low
---
**Perl configuration**
```
Site configuration information for perl 5.37.4:
Configured by tom at Wed Sep 21 10:56:12 EDT 2022.
Summary of my perl5 (revision 5 version 37 subversion 4) configuration:

Platform:
osname=darwin
osvers=21.6.0
archname=darwin-2level
uname='darwin samwise.local 21.6.0 darwin kernel version 21.6.0: mon aug 22 20:17:10 pdt 2022; root:xnu-8020.140.49~2release_x86_64 x86_64 '
config_args='-Dprefix=/trw/local/perl/5.37.4 -Dcf_email=wyant@cpan.org -Uinstallusrbinperl -e -d -Dusedevel -Uversiononly'
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 ='-fno-common -DPERL_DARWIN -mmacosx-version-min=12.6 -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -I/opt/local/include'
optimize='-O3'
cppflags='-fno-common -DPERL_DARWIN -mmacosx-version-min=12.6 -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -I/opt/local/include'
ccversion=''
gccversion='Apple LLVM 14.0.0 (clang-1400.0.29.102)'
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 =' -mmacosx-version-min=12.6 -fstack-protector-strong -L/usr/local/lib -L/opt/local/lib'
libpth=/usr/local/lib /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/14.0.0/lib /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib /opt/local/lib /usr/lib
libs=-lgdbm
perllibs=
libc=
so=dylib
useshrplib=false
libperl=libperl.a
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_dlopen.xs
dlext=bundle
d_dlsymun=undef
ccdlflags=' '
cccdlflags=' '
lddlflags=' -mmacosx-version-min=12.6 -bundle -undefined dynamic_lookup -L/usr/local/lib -L/opt/local/lib -fstack-protector-strong'

---
@INC for perl 5.37.4:
/trw/local/perl/5.37.4/lib/site_perl/5.37.4/darwin-2level
/trw/local/perl/5.37.4/lib/site_perl/5.37.4
/trw/local/perl/5.37.4/lib/5.37.4/darwin-2level
/trw/local/perl/5.37.4/lib/5.37.4
---
Environment for perl 5.37.4:
DYLD_LIBRARY_PATH (unset)
HOME=/Users/tom
LANG=en_US.UTF-8
LANGUAGE (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=/Users/Shared/trw/local/perl/5.37.4/bin:/Volumes/LaCie/trw/local/lynx/2.8.8-with-ssl/bin:/Volumes/LaCie/trw/local/simh/3.9-0/bin:/Users/tom/bin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Apple/usr/bin
PERL_BADLANG (unset)
SHELL=/bin/zsh
```

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