Table of Contents
1. wcheck
Tests whether an object’s access attribute permits writing to its value.
1.2. Stack Effects
| Level | Object |
|---|---|
0 |
Composite object |
| Level | Object |
|---|---|
0 |
|
1.3. Description
wcheck tests whether the operand’s access attribute permits its value to be written (modified) by PostScript operators.
Returns:
* true if access is unlimited
* false if access is readonly, executeonly, or noaccess
1.5. Examples
Writable objects
[1 2 3] wcheck % true (unlimited access)
3 dict wcheck % true (can add entries)
(text) wcheck % true (can modify)
Non-writable objects
[1 2 3] readonly wcheck % false
{ code } wcheck % false (procedures readonly by default)
Packed arrays
1 2 3 3 packedarray wcheck % false (always readonly)
File objects
(file.ps) (w) file wcheck % true (write mode)
(file.ps) (r) file wcheck % false (read mode)
1.6. Common Use Cases
1.6.1. Safe Modification
/safe-put {
3 copy pop exch pop % array array index
wcheck {
put
} {
pop pop pop
/invalidaccess cvx exec
} ifelse
} def
1.7. Common Pitfalls
Packed Arrays Always Read-Only - Packed arrays created with packedarray always return false for wcheck.
|
1 2 3 3 packedarray wcheck % false
| Readonly is Permanent - Once an object is made readonly, it cannot be made writable again. |
[1 2 3] readonly
% No way to restore unlimited access
Check Before Modifying - Use wcheck before operations like put or putinterval on untrusted objects.
|
1.8. Error Conditions
| Error | Condition |
|---|---|
[ |
No operand on stack |
[ |
Operand not array, dict, file, or string |
1.9. Access Attribute Hierarchy
| Attribute | Set By | Can Write? |
|---|---|---|
Unlimited |
(default for most objects) |
Yes |
Readonly |
|
No |
Executeonly |
|
No |
Noaccess |
|
No |
1.10. Implementation Notes
-
Fast operation (checks access bits)
-
Does not modify the object
-
Packed arrays inherently readonly
-
Simple objects (numbers, booleans) have no access attribute