Skip to content

Commit

Permalink
FEAT: UNPROTECT/words object!
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Apr 2, 2020
1 parent 3092806 commit 1e55b65
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/core/n-control.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,27 +135,27 @@ enum {
***********************************************************************/
{
REBSER *series = VAL_OBJ_FRAME(value);

if (!GET_FLAG(flags, PROT_WORDS)) {
if (IS_MARK_SERIES(series)) return; // avoid loop
if (GET_FLAG(flags, PROT_SET)) {
if (IS_MARK_SERIES(series)) return; // avoid loop
for (value = FRM_WORDS(series)+1; NOT_END(value); value++) {
Protect_Word(value, flags);
}
if (GET_FLAG(flags, PROT_SET)) {
// protecting...
if (!GET_FLAG(flags, PROT_WORDS)) {
PROTECT_SERIES(series);
if (GET_FLAG(flags, PROT_PERMANENTLY)) LOCK_SERIES(series);
if (GET_FLAG(flags, PROT_PERMANENTLY))
LOCK_SERIES(series);
}
else
} else {
// unprotecting...
if(!GET_FLAG(flags, PROT_WORDS)) {
//unprotect series only when not locked (using protect/permanently)
if (!IS_LOCK_SERIES(series))
UNPROTECT_SERIES(series);
}
}

for (value = FRM_WORDS(series)+1; NOT_END(value); value++) {
Protect_Word(value, flags);
}

if (!GET_FLAG(flags, PROT_DEEP)) return;

MARK_SERIES(series); // recursion protection

for (value = FRM_VALUES(series)+1; NOT_END(value); value++) {
Protect_Value(value, flags);
}
Expand Down
37 changes: 37 additions & 0 deletions src/tests/units/object-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,41 @@ Rebol [

===end-group===


===start-group=== "UNPROTECT object!"
;@@ https://github.com/Oldes/Rebol-issues/issues/1015
--test-- "unprotect object"
; To allow adding words to o, and allow modification of words already in o, but not affect their values:
o: unprotect protect/deep o: object [a: 10 b: [20]]
--assert not error? try [extend o 'c 3]
--assert not error? try [append o 'd]
--assert not error? try [o/a: 0]
--assert error? try [append o/b 0]

--test-- "unprotect/words object!"
; To allow modification of words already in o, but not affect their values or the object itself:
o: unprotect/words protect/deep o: object [a: 10 b: [20]]
--assert error? try [extend o 'c 3]
--assert error? try [append o 'd]
--assert not error? try [o/a: 0]
--assert error? try [append o/b 0]

--test-- "unprotect/deep object!"
; To allow adding words to o, and allow modification of words already in o or their values:
o: unprotect/deep protect/deep o: object [a: 10 b: [20]]
--assert not error? try [extend o 'c 3]
--assert not error? try [append o 'd]
--assert not error? try [o/a: 0]
--assert not error? try [append o/b 0]

--test-- "unprotect/words/deep object!"
; To allow modification of words already in o and their contents, but not affect the object itself:
o: unprotect/words/deep protect/deep o: object [a: 10 b: [20]]
--assert error? try [extend o 'c 3]
--assert error? try [append o 'd]
--assert not error? try [o/a: 0]
--assert not error? try [append o/b 0]

===end-group===

~~~end-file~~~

0 comments on commit 1e55b65

Please sign in to comment.