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

Reference to constant not read-only #1801

Closed
p5pRT opened this issue Apr 7, 2000 · 1 comment
Closed

Reference to constant not read-only #1801

p5pRT opened this issue Apr 7, 2000 · 1 comment

Comments

@p5pRT
Copy link

p5pRT commented Apr 7, 2000

Migrated from rt.perl.org#3060 (status was 'resolved')

Searchable as RT3060$

@p5pRT
Copy link
Author

p5pRT commented Apr 7, 2000

From eblood@xmission.com

Created by eblood@xmission.com

When useithreads is defined the following code does not produce
the 'Modification of a read-only value attempted' error.

  sub C () { 1 }
  $r = \C;
  $$r = 2;

The problem is that constants are put on the pad when useithreads
is defined. When toref() creates a reference to a PADTMP it
creates a copy of the SV. It does not, however, copy the
read-only status of the SV.

The following patch corrects this and adds a test case for it.

Inline Patch
diff -bruN perl.sav/pp.c perl/pp.c
--- perl.sav/pp.c Fri Mar 24 22:24:52 2000
+++ perl/pp.c Fri Apr 07 08:05:42 2000
@@ -510,6 +510,13 @@
  SvTEMP_off(sv);
  (void)SvREFCNT_inc(sv);
     }
+#ifdef USE_ITHREADS
+    else if (SvPADTMP(sv) && SvREADONLY(sv)) {
+ /* Must be a const */
+ sv = newSVsv(sv);
+ SvREADONLY_on(sv);
+    }
+#endif
     else if (SvPADTMP(sv))
  sv = newSVsv(sv);
     else {
diff -bruN perl.sav/t/op/ref.t perl/t/op/ref.t
--- perl.sav/t/op/ref.t Fri Mar 24 22:23:58 2000
+++ perl/t/op/ref.t Fri Apr 07 19:34:38 2000
@@ -1,6 +1,6 @@
 #!./perl

-print "1..56\n";
+print "1..57\n";

 # Test glob operations.

@@ -279,17 +279,33 @@
     print ${\$_} for @a;
 }

+# test if ref to constant is readonly
+
+{
+    eval {
+ sub C () { 1 }
+ my $r = \C;
+ print "# should also generate an error...\n";
+ $$r = 2;
+    };
+    if ($@) {
+ print "# $@";
+ print "ok 54\n" if $@ =~ /^Modification of a read-only/;
+    }
+}
+
 # test global destruction

 package FINALE;

 {
-    $ref3 = bless ["ok 56\n"];  # package destruction
-    my $ref2 = bless ["ok 55\n"]; # lexical destruction
-    local $ref1 = bless ["ok 54\n"]; # dynamic destruction
+    $ref3 = bless ["ok 57\n"];  # package destruction
+    my $ref2 = bless ["ok 56\n"]; # lexical destruction
+    local $ref1 = bless ["ok 55\n"]; # dynamic destruction
     1;     # flush any temp values on stack
 }

 DESTROY {
     print $_[0][0];
 }
+
Perl Info

Flags:
    category=core
    severity=low

Site configuration information for perl v5.6.0:

Configured by Eric at Fri Mar 24 12:36:06 2000.

Summary of my perl5 (revision 5 version 6 subversion 0) configuration:
  Platform:
    osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    usethreads=undef use5005threads=undef useithreads=define
usemultiplicity=define
    useperlio=undef d_sfio=undef uselargefiles=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef usesocks=undef
  Compiler:
    cc='cl', optimize='-O1 -MD -DNDEBUG', gccversion=
    cppflags='-DWIN32'
    ccflags
='-O1 -MD -DNDEBUG -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT  -DPERL_
IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DPERL_MSVCRT_READFIX'
    stdchar='char', d_stdstdio=define, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=4
    alignbytes=8, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='link', ldflags
'-nologo -nodefaultlib -release  -libpath:"D:\apps\perl56\lib\CORE"  -machin
e:x86'
    libpth="g:\apps\msdevstd\lib" "g:\apps\msdevstd\mfc\lib" "%lib%"
"D:\apps\perl56\lib\CORE"
    libs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib  netapi32.lib
uuid.lib wsock32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib
msvcrt.lib
    libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl56.lib
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ',
ddlflags='-dll -nologo -nodefaultlib -release  -libpath:"D:\apps\perl56\lib\
CORE"  -machine:x86'

Locally applied patches:
    ACTIVEPERL_LOCAL_PATCHES_ENTRY


@INC for perl v5.6.0:
    d:\apps\cmt\lib
    D:/apps/perl56/lib
    D:/apps/perl56/site/lib
    .


Environment for perl v5.6.0:
    HOME=d:\home
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)

PATH=d:\apps\perl56\bin;D:\WINNT\system32;D:\WINNT;g:\apps\bor\Delphi5\Proje
cts\Bpl;g:\apps\bor\Delphi5\Bin;d:\apps\perl\bin;d:\apps\cmt\nt;d:\bin\nt;d:
\bin;;g:\apps\bor\delphi3\bin;g:\apps\bor\tasm\bin;g:\apps\bor\bp\bin;d:\app
s\iqtools;g:\apps\msdevstd\bin\;g:\apps\bor\bcc55\bin;;d:\rnd;c:\APPS\PERL\B
IN
    PERLLIB=d:\apps\cmt\lib
    PERL_BADLANG (unset)
    SHELL (unset)




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

No branches or pull requests

1 participant