Skip to content

Commit 1e55b65

Browse files
committed
FEAT: UNPROTECT/words object!
Implements: Oldes/Rebol-issues#1015 Related to: Oldes/Rebol-issues#1014
1 parent 3092806 commit 1e55b65

File tree

2 files changed

+50
-13
lines changed

2 files changed

+50
-13
lines changed

src/core/n-control.c

+13-13
Original file line numberDiff line numberDiff line change
@@ -135,27 +135,27 @@ enum {
135135
***********************************************************************/
136136
{
137137
REBSER *series = VAL_OBJ_FRAME(value);
138-
139-
if (!GET_FLAG(flags, PROT_WORDS)) {
140-
if (IS_MARK_SERIES(series)) return; // avoid loop
141-
if (GET_FLAG(flags, PROT_SET)) {
138+
if (IS_MARK_SERIES(series)) return; // avoid loop
139+
for (value = FRM_WORDS(series)+1; NOT_END(value); value++) {
140+
Protect_Word(value, flags);
141+
}
142+
if (GET_FLAG(flags, PROT_SET)) {
143+
// protecting...
144+
if (!GET_FLAG(flags, PROT_WORDS)) {
142145
PROTECT_SERIES(series);
143-
if (GET_FLAG(flags, PROT_PERMANENTLY)) LOCK_SERIES(series);
146+
if (GET_FLAG(flags, PROT_PERMANENTLY))
147+
LOCK_SERIES(series);
144148
}
145-
else
149+
} else {
150+
// unprotecting...
151+
if(!GET_FLAG(flags, PROT_WORDS)) {
146152
//unprotect series only when not locked (using protect/permanently)
147153
if (!IS_LOCK_SERIES(series))
148154
UNPROTECT_SERIES(series);
155+
}
149156
}
150-
151-
for (value = FRM_WORDS(series)+1; NOT_END(value); value++) {
152-
Protect_Word(value, flags);
153-
}
154-
155157
if (!GET_FLAG(flags, PROT_DEEP)) return;
156-
157158
MARK_SERIES(series); // recursion protection
158-
159159
for (value = FRM_VALUES(series)+1; NOT_END(value); value++) {
160160
Protect_Value(value, flags);
161161
}

src/tests/units/object-test.r3

+37
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,41 @@ Rebol [
103103

104104
===end-group===
105105

106+
107+
===start-group=== "UNPROTECT object!"
108+
;@@ https://github.com/Oldes/Rebol-issues/issues/1015
109+
--test-- "unprotect object"
110+
; To allow adding words to o, and allow modification of words already in o, but not affect their values:
111+
o: unprotect protect/deep o: object [a: 10 b: [20]]
112+
--assert not error? try [extend o 'c 3]
113+
--assert not error? try [append o 'd]
114+
--assert not error? try [o/a: 0]
115+
--assert error? try [append o/b 0]
116+
117+
--test-- "unprotect/words object!"
118+
; To allow modification of words already in o, but not affect their values or the object itself:
119+
o: unprotect/words protect/deep o: object [a: 10 b: [20]]
120+
--assert error? try [extend o 'c 3]
121+
--assert error? try [append o 'd]
122+
--assert not error? try [o/a: 0]
123+
--assert error? try [append o/b 0]
124+
125+
--test-- "unprotect/deep object!"
126+
; To allow adding words to o, and allow modification of words already in o or their values:
127+
o: unprotect/deep protect/deep o: object [a: 10 b: [20]]
128+
--assert not error? try [extend o 'c 3]
129+
--assert not error? try [append o 'd]
130+
--assert not error? try [o/a: 0]
131+
--assert not error? try [append o/b 0]
132+
133+
--test-- "unprotect/words/deep object!"
134+
; To allow modification of words already in o and their contents, but not affect the object itself:
135+
o: unprotect/words/deep protect/deep o: object [a: 10 b: [20]]
136+
--assert error? try [extend o 'c 3]
137+
--assert error? try [append o 'd]
138+
--assert not error? try [o/a: 0]
139+
--assert not error? try [append o/b 0]
140+
141+
===end-group===
142+
106143
~~~end-file~~~

0 commit comments

Comments
 (0)