From fe4a34d20d8342106a46fc2b842a892c17a11920 Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Fri, 22 Sep 2017 10:25:38 +0200 Subject: Deprecate make-struct * libguile/struct.c: Replace uses of scm_make_struct with scm_make_struct_no_tail or scm_c_make_struct. (scm_make_struct_no_tail): Move this function to C instead of Scheme to be able to deprecate scm_make_struct. * libguile/struct.h (scm_make_struct_no_tail): New public declaration. * libguile/deprecated.h: * libguile/deprecated.c (scm_make_struct): Deprecate. * libguile/print.c: * libguile/procs.c: * libguile/stacks.c: Replace uses of scm_make_struct with scm_make_struct_no_tail. * test-suite/tests/coverage.test: * test-suite/tests/structs.test: Use make-struct/no-tail instead of make-struct. * NEWS: Add entry. --- libguile/struct.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'libguile/struct.c') diff --git a/libguile/struct.c b/libguile/struct.c index 51c0f111d..78099ac45 100644 --- a/libguile/struct.c +++ b/libguile/struct.c @@ -1,5 +1,5 @@ -/* Copyright (C) 1996,1997,1998,1999,2000,2001, 2003, 2004, 2006, 2007, - * 2008, 2009, 2010, 2011, 2012, 2013, 2015 Free Software Foundation, Inc. +/* Copyright (C) 1996-2001, 2003-2004, 2006-2013, 2015, + * 2017 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -553,13 +553,10 @@ SCM_DEFINE (scm_allocate_struct, "allocate-struct", 2, 0, 0, } #undef FUNC_NAME -SCM_DEFINE (scm_make_struct, "make-struct", 2, 0, 1, - (SCM vtable, SCM tail_array_size, SCM init), +SCM_DEFINE (scm_make_struct_no_tail, "make-struct/no-tail", 1, 0, 1, + (SCM vtable, SCM init), "Create a new structure.\n\n" "@var{vtable} must be a vtable structure (@pxref{Vtables}).\n\n" - "@var{tail_array_size} must be a non-negative integer. If the layout\n" - "specification indicated by @var{vtable} includes a tail-array,\n" - "this is the number of elements allocated to that array.\n\n" "The @var{init1}, @dots{} are optional arguments describing how\n" "successive fields of the structure should be initialized. Only fields\n" "with protection 'r' or 'w' can be initialized, except for fields of\n" @@ -569,7 +566,7 @@ SCM_DEFINE (scm_make_struct, "make-struct", 2, 0, 1, "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.") -#define FUNC_NAME s_scm_make_struct +#define FUNC_NAME s_scm_make_struct_no_tail { size_t i, n_init; long ilen; @@ -592,7 +589,7 @@ SCM_DEFINE (scm_make_struct, "make-struct", 2, 0, 1, for (i = 0; i < n_init; i++, init = SCM_CDR (init)) v[i] = SCM_UNPACK (SCM_CAR (init)); - return scm_c_make_structv (vtable, scm_to_size_t (tail_array_size), n_init, v); + return scm_c_make_structv (vtable, 0, n_init, v); } #undef FUNC_NAME @@ -638,9 +635,9 @@ SCM_DEFINE (scm_make_vtable, "make-vtable", 1, 1, 0, if (SCM_UNBNDP (printer)) printer = SCM_BOOL_F; - return scm_make_struct (scm_standard_vtable_vtable, SCM_INUM0, - scm_list_2 (scm_make_struct_layout (fields), - printer)); + return scm_c_make_struct (scm_standard_vtable_vtable, 0, 2, + SCM_UNPACK (scm_make_struct_layout (fields)), + SCM_UNPACK (printer)); } #undef FUNC_NAME @@ -1002,8 +999,8 @@ scm_init_struct () scm_define (name, scm_standard_vtable_vtable); scm_applicable_struct_vtable_vtable = - scm_make_struct (scm_standard_vtable_vtable, SCM_INUM0, - scm_list_1 (scm_make_struct_layout (required_vtable_fields))); + scm_c_make_struct (scm_standard_vtable_vtable, 0, 1, + SCM_UNPACK (scm_make_struct_layout (required_vtable_fields))); name = scm_from_utf8_symbol (""); SCM_SET_VTABLE_FLAGS (scm_applicable_struct_vtable_vtable, SCM_VTABLE_FLAG_APPLICABLE_VTABLE); @@ -1011,8 +1008,8 @@ scm_init_struct () scm_define (name, scm_applicable_struct_vtable_vtable); scm_applicable_struct_with_setter_vtable_vtable = - scm_make_struct (scm_standard_vtable_vtable, SCM_INUM0, - scm_list_1 (scm_make_struct_layout (required_vtable_fields))); + scm_c_make_struct (scm_standard_vtable_vtable, 0, 1, + SCM_UNPACK (scm_make_struct_layout (required_vtable_fields))); name = scm_from_utf8_symbol (""); scm_set_struct_vtable_name_x (scm_applicable_struct_with_setter_vtable_vtable, name); SCM_SET_VTABLE_FLAGS (scm_applicable_struct_with_setter_vtable_vtable, -- cgit v1.2.3 From 9ac0544efff1ce5c9e5a4dcf6477cf2794d11ef0 Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Fri, 22 Sep 2017 10:32:36 +0200 Subject: Remove unused code in struct.c * libguile/struct.c (scm_make_struct_layout, scm_struct-ref) (scm_struct_set_x): Remove commented-out support for signed and double raw fields. --- libguile/struct.c | 34 ---------------------------------- 1 file changed, 34 deletions(-) (limited to 'libguile/struct.c') diff --git a/libguile/struct.c b/libguile/struct.c index 78099ac45..08451e741 100644 --- a/libguile/struct.c +++ b/libguile/struct.c @@ -100,10 +100,6 @@ SCM_DEFINE (scm_make_struct_layout, "make-struct-layout", 1, 0, 0, { case 'u': case 'p': -#if 0 - case 'i': - case 'd': -#endif case 's': break; default: @@ -134,16 +130,6 @@ SCM_DEFINE (scm_make_struct_layout, "make-struct-layout", 1, 0, 0, SCM_MISC_ERROR ("unrecognized ref specification: ~S", scm_list_1 (SCM_MAKE_CHAR (c))); } -#if 0 - if (scm_i_string_ref (fields, x, 'd')) - { - if (!scm_i_string_ref (fields, x+2, '-')) - SCM_MISC_ERROR ("missing dash field at position ~A", - scm_list_1 (scm_from_int (x / 2))); - x += 2; - goto recheck_ref; - } -#endif } new_sym = scm_string_to_symbol (fields); } @@ -758,16 +744,6 @@ SCM_DEFINE (scm_struct_ref, "struct-ref", 2, 0, 0, answer = scm_from_ulong (data[p]); break; -#if 0 - case 'i': - answer = scm_from_long (data[p]); - break; - - case 'd': - answer = scm_make_real (*((double *)&(data[p]))); - break; -#endif - case 's': case 'p': answer = SCM_PACK (data[p]); @@ -841,16 +817,6 @@ SCM_DEFINE (scm_struct_set_x, "struct-set!", 3, 0, 0, data[p] = SCM_NUM2ULONG (3, val); break; -#if 0 - case 'i': - data[p] = SCM_NUM2LONG (3, val); - break; - - case 'd': - *((double *)&(data[p])) = scm_num2dbl (val, (char *)SCM_ARG3); - break; -#endif - case 'p': data[p] = SCM_UNPACK (val); break; -- cgit v1.2.3 From 04f48e94b573eaede0751110c583293cc34cd8f9 Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Fri, 22 Sep 2017 11:23:00 +0200 Subject: Deprecate struct "self" slots * libguile/print.h (SCM_PRINT_STATE_LAYOUT): Use a normal slot instead of a self slot. * libguile/print.c (make_print_state): Initialize "handle" slot manually. * libguile/struct.c (issue_deprecation_warning_for_self_slots): New helper, called when making vtables to issue deprecation warnings for "self" slots. Avoids warning for the "self" slot that's part of the fixed vtable slots. (scm_i_struct_inherit_vtable_magic): Call issue_deprecation_warning_for_self_slots. * doc/ref/api-data.texi (Vtables, Structure Basics): Remove references to self slots. * NEWS: Add entry. --- NEWS | 12 +++++++++++- doc/ref/api-data.texi | 16 ++++------------ libguile/print.c | 1 + libguile/print.h | 4 ++-- libguile/struct.c | 20 ++++++++++++++++++++ 5 files changed, 38 insertions(+), 15 deletions(-) (limited to 'libguile/struct.c') diff --git a/NEWS b/NEWS index f13f40a86..78e3b30c3 100644 --- a/NEWS +++ b/NEWS @@ -26,7 +26,7 @@ If you don't care whether the URI is a relative-ref or not, use In the future `uri?' will return a true value only for URIs that specify a scheme. -** Tail arrays deprecated +** Struct tail arrays deprecated Guile's structures used to have a facility whereby each instance of a vtable can contain a variable-length tail array of values. The length @@ -57,6 +57,16 @@ will be removed from Guile 3.0. Likewise, `make-struct' / `scm_make_struct_no_tail'. Perhaps one day we will be able to reclaim the `make-struct' name! +** Struct "self" slots deprecated + +It used to be that you could make a structure vtable that had "self" +slots. Instances of that vtable would have those slots initialized to +the instance itself. This can be useful in C code where you might have +a pointer to the data array, and want to get the `SCM' handle for the +structure. However this was a little used complication without any use +in Scheme code. To replace it, just use "p" slots and initialize the +slot values manually on initialization. + * Bug fixes ** Enable GNU Readline 7.0's support for "bracketed paste". diff --git a/doc/ref/api-data.texi b/doc/ref/api-data.texi index 7e36f7446..faddc3f65 100644 --- a/doc/ref/api-data.texi +++ b/doc/ref/api-data.texi @@ -8785,13 +8785,6 @@ Scheme level it's read and written as an unsigned integer. ``u'' stands for ``uninterpreted'' (it's not treated as a Scheme value), or ``unprotected'' (it's not marked during GC), or ``unsigned long'' (its size), or all of these things. - -@item -@code{s} -- a self-reference. Such a field holds the @code{SCM} value -of the structure itself (a circular reference). This can be useful in -C code where you might have a pointer to the data array, and want to -get the Scheme @code{SCM} handle for the structure. In Scheme code it -has no use. @end itemize The second letter for each field is a permission code, @@ -8857,11 +8850,10 @@ used to have a @code{make-struct} that took an additional argument; while we deprecate that old interface, @code{make-struct/no-tail} is the new name for this functionality. -Type @code{s} self-reference fields and permission @code{o} opaque -fields are ignored for the @var{init} arguments, ie.@: an argument is -not consumed by such a field. An @code{s} is always set to the -structure itself and an @code{o} is always set to @code{#f} or 0 (with -the intention that C code will do something to it later). +Fields with permission @code{o} opaque fields are ignored for the +@var{init} arguments, ie.@: an argument is not consumed by such a field. +An @code{o} slot is always set to @code{#f} or 0 (with the intention +that C code will do something to it later). For example, diff --git a/libguile/print.c b/libguile/print.c index 4d57a877d..24c532f29 100644 --- a/libguile/print.c +++ b/libguile/print.c @@ -196,6 +196,7 @@ make_print_state (void) { SCM print_state = scm_make_struct_no_tail (scm_print_state_vtable, SCM_EOL); scm_print_state *pstate = SCM_PRINT_STATE (print_state); + pstate->handle = print_state; pstate->ref_vect = scm_c_make_vector (PSTATE_SIZE, SCM_UNDEFINED); pstate->ceiling = SCM_SIMPLE_VECTOR_LENGTH (pstate->ref_vect); pstate->highlight_objects = SCM_EOL; diff --git a/libguile/print.h b/libguile/print.h index 14318c031..11f533c79 100644 --- a/libguile/print.h +++ b/libguile/print.h @@ -4,7 +4,7 @@ #define SCM_PRINT_H /* Copyright (C) 1995, 1996, 1998, 2000, 2001, 2003, 2004, 2006, 2008, - * 2010, 2012 Free Software Foundation, Inc. + * 2010, 2012, 2017 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -53,7 +53,7 @@ do { \ #define SCM_COERCE_OUTPORT(p) \ (SCM_PORT_WITH_PS_P (p) ? SCM_PORT_WITH_PS_PORT (p) : p) -#define SCM_PRINT_STATE_LAYOUT "sruwuwuwuwuwpwuwuwurprpw" +#define SCM_PRINT_STATE_LAYOUT "pruwuwuwuwuwpwuwuwurprpw" typedef struct scm_print_state { SCM handle; /* Struct handle */ int revealed; /* Has the state escaped to Scheme? */ diff --git a/libguile/struct.c b/libguile/struct.c index 08451e741..3ebe89064 100644 --- a/libguile/struct.c +++ b/libguile/struct.c @@ -30,6 +30,7 @@ #include "libguile/_scm.h" #include "libguile/async.h" #include "libguile/chars.h" +#include "libguile/deprecation.h" #include "libguile/eval.h" #include "libguile/alist.h" #include "libguile/hashtab.h" @@ -229,6 +230,23 @@ scm_is_valid_vtable_layout (SCM layout) return 1; } +static void +issue_deprecation_warning_for_self_slots (SCM vtable) +{ + SCM olayout; + size_t idx, first_user_slot = 0; + + olayout = scm_symbol_to_string (SCM_VTABLE_LAYOUT (vtable)); + if (SCM_VTABLE_FLAG_IS_SET (vtable, SCM_VTABLE_FLAG_VTABLE)) + first_user_slot = scm_vtable_offset_user; + + for (idx = first_user_slot * 2; idx < scm_c_string_length (olayout); idx += 2) + if (scm_is_eq (scm_c_string_ref (olayout, idx), SCM_MAKE_CHAR ('s'))) + scm_c_issue_deprecation_warning + ("Vtables with \"self\" slots are deprecated. Initialize these " + "fields manually."); +} + /* Have OBJ, a newly created vtable, inherit flags from VTABLE. VTABLE is a vtable-vtable and OBJ is an instance of VTABLE. */ void @@ -288,6 +306,8 @@ scm_i_struct_inherit_vtable_magic (SCM vtable, SCM obj) SCM_SET_VTABLE_FLAGS (obj, SCM_VTABLE_FLAG_APPLICABLE); } + issue_deprecation_warning_for_self_slots (obj); + SCM_SET_VTABLE_FLAGS (obj, SCM_VTABLE_FLAG_VALIDATED); } #undef FUNC_NAME -- cgit v1.2.3 From c7c7588f2416624319be2a037056ba8bb1c054e7 Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Fri, 22 Sep 2017 11:38:41 +0200 Subject: Fix up make-struct-layout and make-struct/no-tail docstrings * libguile/struct.c (scm_make_struct_layout, scm_make_struct_no_tail): Fix up docstrings for self and tail deprecation. --- libguile/struct.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'libguile/struct.c') diff --git a/libguile/struct.c b/libguile/struct.c index 3ebe89064..5c03f4fb0 100644 --- a/libguile/struct.c +++ b/libguile/struct.c @@ -69,16 +69,14 @@ SCM_DEFINE (scm_make_struct_layout, "make-struct-layout", 1, 0, 0, "@var{fields} must be a string made up of pairs of characters\n" "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, and 's' for\n" - "a field that points to the structure itself. Allowed protections\n" + "GC-protected Scheme data, 'u' for unprotected binary data. \n" + "Allowed protections\n" "are 'w' for mutable fields, 'h' for hidden fields, 'r' for read-only\n" "fields, and 'o' for opaque 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" - "@code{make-struct}, especially for derived vtables.\n\n" - "The last field protection specification may be capitalized to indicate\n" - "that the field is a tail-array.") + "@code{make-struct}, especially for derived vtables.") #define FUNC_NAME s_scm_make_struct_layout { SCM new_sym; @@ -564,11 +562,10 @@ SCM_DEFINE (scm_make_struct_no_tail, "make-struct/no-tail", 1, 0, 1, "Create a new structure.\n\n" "@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. Only fields\n" - "with protection 'r' or 'w' can be initialized, except for fields of\n" - "type 's', which are automatically initialized to point to the new\n" - "structure itself. Fields with protection 'o' can not be initialized by\n" - "Scheme programs.\n\n" + "successive fields of the structure should be initialized.\n" + "Only fields with protection 'r' or 'w' can be initialized.\n" + "Fields with protection 'o' can not be initialized by Scheme\n" + "programs.\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.") -- cgit v1.2.3