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

catch modification of read-only arguments #392

Closed
p6rt opened this issue Nov 6, 2008 · 7 comments
Closed

catch modification of read-only arguments #392

p6rt opened this issue Nov 6, 2008 · 7 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Nov 6, 2008

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

Searchable as RT60380$

@p6rt
Copy link
Author

p6rt commented Nov 6, 2008

From @moritz

Rakudo r32373​:

$ ./perl6 -e 'sub f($x) {$x++}; my $y = 2; f($y); say "still here"'
still here

that should die, because subroutine arguments are read-only by default.
A test for that is in t/spec/S06-traits/misc.t.

Note that assignment already dies as it should​:

$ ./perl6 -e 'sub f($x) {$x = 3}; my $y = 2; f($y); say "still here"'
Cannot assign to readonly variable
...

(there's now also a test for that in the same file).

Moritz

--
Moritz Lenz
http://perlgeek.de/ | http://perl-6.de/ | http://sudokugarden.de/

@p6rt
Copy link
Author

p6rt commented Nov 8, 2008

From @bacek

Hello,

there is attached patch to factor check readonly status to separate
function. Unfortunately I can't add call to '!CHECK_READONLY'
into (prefix|postfix)(++|--) because I'm waiting to resolve #​59596 :)

--
Bacek

@p6rt
Copy link
Author

p6rt commented Nov 8, 2008

From @bacek

check_readonly.patch
diff --git a/languages/perl6/src/builtins/assign.pir b/languages/perl6/src/builtins/assign.pir
index 2dd9b57..2c70f45 100644
--- a/languages/perl6/src/builtins/assign.pir
+++ b/languages/perl6/src/builtins/assign.pir
@@ -33,12 +33,9 @@ src/builtins/inplace.pir - Inplace assignments
     unless $I0 goto have_source
     source = source.'Scalar'()
   have_source:
-    .local pmc ro, type
-    getprop ro, 'readonly', cont
-    if null ro goto ro_ok
-    unless ro goto ro_ok
-    'die'('Cannot assign to readonly variable.')
+    '!CHECK_READONLY'(cont)
   ro_ok:
+    .local pmc type
     $I0 = defined source
     unless $I0 goto do_assign
     getprop type, 'type', cont
@@ -69,6 +66,7 @@ src/builtins/inplace.pir - Inplace assignments
 .sub 'infix:~='
     .param pmc a
     .param pmc b
+    '!CHECK_READONLY'(a)
     concat a, b
     .return (a)
 .end
@@ -77,6 +75,7 @@ src/builtins/inplace.pir - Inplace assignments
 .sub 'infix:+='
     .param pmc a
     .param pmc b
+    '!CHECK_READONLY'(a)
     a += b
     .return (a)
 .end
@@ -85,6 +84,7 @@ src/builtins/inplace.pir - Inplace assignments
 .sub 'infix:-='
     .param pmc a
     .param pmc b
+    '!CHECK_READONLY'(a)
     a -= b
     .return (a)
 .end
@@ -93,6 +93,7 @@ src/builtins/inplace.pir - Inplace assignments
 .sub 'infix:*='
     .param pmc a
     .param pmc b
+    '!CHECK_READONLY'(a)
     a *= b
     .return (a)
 .end
@@ -101,6 +102,7 @@ src/builtins/inplace.pir - Inplace assignments
 .sub 'infix:/='
     .param pmc a
     .param pmc b
+    '!CHECK_READONLY'(a)
     a /= b
     .return (a)
 .end
@@ -109,6 +111,7 @@ src/builtins/inplace.pir - Inplace assignments
 .sub 'infix:%='
     .param pmc a
     .param pmc b
+    '!CHECK_READONLY'(a)
     a %= b
     .return (a)
 .end
@@ -117,6 +120,7 @@ src/builtins/inplace.pir - Inplace assignments
 .sub 'infix:x='
     .param pmc a
     .param pmc b
+    '!CHECK_READONLY'(a)
     repeat a, b
     .return (a)
 .end
@@ -126,6 +130,7 @@ src/builtins/inplace.pir - Inplace assignments
 .sub 'infix:**='
     .param pmc a
     .param pmc b
+    '!CHECK_READONLY'(a)
     pow $P0, a, b
     'infix:='(a, $P0)
     .return (a)
@@ -138,6 +143,7 @@ src/builtins/inplace.pir - Inplace assignments
 .sub 'infix:+<='
     .param pmc a
     .param pmc b
+    '!CHECK_READONLY'(a)
     a <<= b
     .return (a)
 .end
@@ -146,6 +152,7 @@ src/builtins/inplace.pir - Inplace assignments
 .sub 'infix:+>='
     .param pmc a
     .param pmc b
+    '!CHECK_READONLY'(a)
     a >>= b
     .return (a)
 .end
@@ -154,6 +161,7 @@ src/builtins/inplace.pir - Inplace assignments
 .sub 'infix:+&='
     .param pmc a
     .param pmc b
+    '!CHECK_READONLY'(a)
     band a, b
     .return (a)
 .end
@@ -162,6 +170,7 @@ src/builtins/inplace.pir - Inplace assignments
 .sub 'infix:+|='
     .param pmc a
     .param pmc b
+    '!CHECK_READONLY'(a)
     bor a, b
     .return (a)
 .end
@@ -170,6 +179,7 @@ src/builtins/inplace.pir - Inplace assignments
 .sub 'infix:+^='
     .param pmc a
     .param pmc b
+    '!CHECK_READONLY'(a)
     bxor a, b
     .return (a)
 .end
@@ -178,6 +188,7 @@ src/builtins/inplace.pir - Inplace assignments
 .sub 'infix:~&='
     .param pmc a
     .param pmc b
+    '!CHECK_READONLY'(a)
     a = bands a, b
     .return (a)
 .end
@@ -186,6 +197,7 @@ src/builtins/inplace.pir - Inplace assignments
 .sub 'infix:~|='
     .param pmc a
     .param pmc b
+    '!CHECK_READONLY'(a)
     bors a, b
     .return (a)
 .end
@@ -194,6 +206,7 @@ src/builtins/inplace.pir - Inplace assignments
 .sub 'infix:~^='
     .param pmc a
     .param pmc b
+    '!CHECK_READONLY'(a)
     bxors a, b
     .return (a)
 .end
@@ -202,6 +215,7 @@ src/builtins/inplace.pir - Inplace assignments
 .sub 'infix:?&='
     .param pmc a
     .param pmc b
+    '!CHECK_READONLY'(a)
     band a, b
     $I0 = istrue a
     a = $I0
@@ -212,6 +226,7 @@ src/builtins/inplace.pir - Inplace assignments
 .sub 'infix:?|='
     .param pmc a
     .param pmc b
+    '!CHECK_READONLY'(a)
     bor a, b
     $I0 = istrue a
     a = $I0
@@ -222,12 +237,23 @@ src/builtins/inplace.pir - Inplace assignments
 .sub 'infix:?^='
     .param pmc a
     .param pmc b
+    '!CHECK_READONLY'(a)
     bxor a, b
     $I0 = istrue a
     a = $I0
     .return (a)
 .end
 
+.sub '!CHECK_READONLY'
+    .param pmc arg
+    .local pmc ro
+    getprop ro, 'readonly', arg
+    if null ro goto done
+    unless ro goto done
+    'die'('Cannot assign to readonly variable.')
+  done:
+    .return ()
+.end
 
 =back
 

@p6rt
Copy link
Author

p6rt commented Nov 8, 2008

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Nov 26, 2008

From @jnthn

On Sat Nov 08 04​:58​:36 2008, bacek wrote​:

there is attached patch to factor check readonly status to separate
function. Unfortunately I can't add call to '!CHECK_READONLY'
into (prefix|postfix)(++|--) because I'm waiting to resolve #​59596 :)

Thanks for the patch. However, it's not really the way to go on these.
The op= cases are meta-operators, and should be equivalent to

infix​:<=>($target, infix​:{$op}($target, $arg))

In the (nearer) future I think we'll generate these from the op table
rather than maintaining them all by hand, but in the end the grammar
rules will parse them just as meta-operators and we can emit code like
the above directly. Then the check will fall out of the infix​:<=>.

Thanks,

Jonathan

@p6rt
Copy link
Author

p6rt commented Feb 11, 2009

From @jnthn

On Thu Nov 06 10​:37​:55 2008, moritz@​casella.verplant.org wrote​:

Rakudo r32373​:

$ ./perl6 -e 'sub f($x) {$x++}; my $y = 2; f($y); say "still here"'
still here

that should die, because subroutine arguments are read-only by default.
A test for that is in t/spec/S06-traits/misc.t.

Fixed in git 45cf376 and that test is un-fudged.

Thanks,

Jonathan

@p6rt
Copy link
Author

p6rt commented Feb 11, 2009

@jnthn - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Feb 11, 2009
@p6rt p6rt added the Todo label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant