diff options
author | Andy Wingo <wingo@pobox.com> | 2017-09-23 15:16:04 +0200 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2017-09-23 15:33:02 +0200 |
commit | 5870188eb4b6c4246569a1aaaf358bc8a9e6a65d (patch) | |
tree | 239d2b31275520a409576073b67a8cd952a87fc8 /libguile/struct.c | |
parent | 0f14a9e59826c1c304d1f50c741e91d99760ff43 (diff) | |
download | guile-5870188eb4b6c4246569a1aaaf358bc8a9e6a65d.tar.gz |
Replace "pr" struct fields with "pw" fields
* libguile/struct.h (SCM_VTABLE_BASE_LAYOUT): Layout is a "pr" field.
* module/ice-9/boot-9.scm (record-type-vtable): Record vtable fields are
writable.
(<parameter>): "pw" fields.
* module/oop/goops.scm (<class>, %compute-layout): <read-only> fields
are "pw" underneath.
* module/rnrs/records/procedural.scm (record-type-vtable)
(record-constructor-vtable, make-record-type-descriptor): Use "pw"
fields in vtables.
* module/srfi/srfi-35.scm (%condition-type-vtable)
(struct-layout-for-condition): "pw" fields in vtables.
* test-suite/tests/goops.test:
* test-suite/tests/structs.test: Use "pw" fields only.
* benchmark-suite/benchmarks/structs.bm: Update for make-struct/no-tail,
to use pw fields, and also to remove useless tests that the compiler
would optimize away.
* doc/ref/api-data.texi (Vtables): Add a note about the now-vestigial
permissions character and update documentation.
(Structure Basics, Meta-Vtables): Update examples.
* libguile/hash.c (scm_i_struct_hash): Remove code that would handle
opaque/self fields.
* libguile/print.h (SCM_PRINT_STATE_LAYOUT): Use "pw" fields.
* libguile/struct.c (scm_struct_init): Simplify check for hidden
fields.
* libguile/values.c (scm_init_values): Field is "pw".
Diffstat (limited to 'libguile/struct.c')
-rw-r--r-- | libguile/struct.c | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/libguile/struct.c b/libguile/struct.c index 4ee5a81ba..eb2bfbb56 100644 --- a/libguile/struct.c +++ b/libguile/struct.c @@ -67,9 +67,8 @@ SCM_DEFINE (scm_make_struct_layout, "make-struct-layout", 1, 0, 0, "strung together. The first character of each pair describes a field\n" "type, the second a field protection. Allowed types are 'p' for\n" "GC-protected Scheme data, 'u' for unprotected binary data. \n" - "Allowed protections\n" - "are 'w' for mutable fields, 'h' for hidden fields, and\n" - "'r' for read-only fields.\n\n" + "Allowed protections are 'w' for normal fields or 'h' for \n" + "hidden fields.\n\n" "Hidden fields are writable, but they will not consume an initializer arg\n" "passed to @code{make-struct}. They are useful to add slots to a struct\n" "in a way that preserves backward-compatibility with existing calls to\n" @@ -188,7 +187,12 @@ scm_is_valid_vtable_layout (SCM layout) { case 'w': case 'h': + break; case 'r': + scm_c_issue_deprecation_warning + ("Read-only struct fields are deprecated. Implement access " + "control at a higher level instead, as structs no longer " + "enforce field permissions."); break; default: return 0; @@ -293,7 +297,7 @@ scm_struct_init (SCM handle, SCM layout, size_t n_inits, scm_t_bits *inits) switch (scm_i_symbol_ref (layout, i)) { case 'u': - if ((prot != 'r' && prot != 'w') || inits_idx == n_inits) + if (prot == 'h' || inits_idx == n_inits) *mem = 0; else { @@ -303,7 +307,7 @@ scm_struct_init (SCM handle, SCM layout, size_t n_inits, scm_t_bits *inits) break; case 'p': - if ((prot != 'r' && prot != 'w') || inits_idx == n_inits) + if (prot == 'h' || inits_idx == n_inits) *mem = SCM_UNPACK (SCM_BOOL_F); else { @@ -470,9 +474,8 @@ SCM_DEFINE (scm_make_struct_no_tail, "make-struct/no-tail", 1, 0, 1, "@var{vtable} must be a vtable structure (@pxref{Vtables}).\n\n" "The @var{init1}, @dots{} are optional arguments describing how\n" "successive fields of the structure should be initialized.\n" - "Only fields with protection 'r' or 'w' can be initialized.\n" - "Hidden fields (those with protection 'h') have to be manually\n" - "set.\n\n" + "Note that hidden fields (those with protection 'h') have to be\n" + "manually set.\n\n" "If fewer optional arguments than initializable fields are supplied,\n" "fields of type 'p' get default value #f while fields of type 'u' are\n" "initialized to 0.") @@ -677,14 +680,10 @@ SCM_DEFINE (scm_struct_set_x, "struct-set!", 3, 0, 0, else { SCM layout; - scm_t_wchar field_type, protection; + scm_t_wchar field_type; layout = SCM_STRUCT_LAYOUT (handle); field_type = scm_i_symbol_ref (layout, p * 2); - protection = scm_i_symbol_ref (layout, p * 2 + 1); - - if (protection == 'r') - SCM_MISC_ERROR ("set! denied for field ~A", scm_list_1 (pos)); if (field_type == 'p') SCM_STRUCT_SLOT_SET (handle, p, val); |