This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "GNU Guile".
http://git.savannah.gnu.org/cgit/guile.git/commit/?id=9b5da400dde6e6bc8fd0e318e7ca1feffa5870db The branch, stable-2.0 has been updated via 9b5da400dde6e6bc8fd0e318e7ca1feffa5870db (commit) via 1e3fd6a0c81bb3e9900a93a9d1923cc788de0f99 (commit) from 40a723a92236fe4e58feb89057b4182b1fc76810 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 9b5da400dde6e6bc8fd0e318e7ca1feffa5870db Author: Andy Wingo <[email protected]> Date: Fri Feb 7 12:42:44 2014 +0100 Deprecate vector-ref, vector-length, vector-set! on weak vectors * libguile/vectors.c (scm_vector_length, scm_c_vector_length): (scm_c_vector_ref, scm_c_vector_set_x): Deprecate the use of these procedures on weak vectors. * test-suite/tests/guardians.test: * test-suite/tests/weaks.test: Adapt test suites. commit 1e3fd6a0c81bb3e9900a93a9d1923cc788de0f99 Author: Andy Wingo <[email protected]> Date: Fri Feb 7 12:25:05 2014 +0100 Add weak-vector-length, weak-vector-ref, weak-vector-set! * libguile/weaks.c (scm_is_weak_vector, scm_c_weak_vector_length): (scm_c_weak_vector_ref, scm_c_weak_vector_set_x): New interfaces for dealing with weak vectors from C. (scm_weak_vector_length, scm_weak_vector_ref, scm_weak_vector_set_x): New Scheme interfaces to weak vectors; to be used instead of vector-length, vector-ref, etc. * module/ice-9/weak-vector.scm: Export the new interfaces. * doc/ref/api-memory.texi (Weak vectors): Document them. ----------------------------------------------------------------------- Summary of changes: doc/ref/api-memory.texi | 13 +++++- libguile/vectors.c | 50 +++++++++++++------- libguile/weaks.c | 99 ++++++++++++++++++++++++++++++++++++++- libguile/weaks.h | 12 ++++- module/ice-9/weak-vector.scm | 3 +- test-suite/tests/guardians.test | 12 ++-- test-suite/tests/weaks.test | 40 ++++++++-------- 7 files changed, 181 insertions(+), 48 deletions(-) diff --git a/doc/ref/api-memory.texi b/doc/ref/api-memory.texi index ff202e0..8d0c8fe 100644 --- a/doc/ref/api-memory.texi +++ b/doc/ref/api-memory.texi @@ -1,6 +1,6 @@ @c -*-texinfo-*- @c This is part of the GNU Guile Reference Manual. -@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2009, 2010, 2012 +@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2009, 2010, 2012, 2014 @c Free Software Foundation, Inc. @c See the file guile.texi for copying conditions. @@ -413,6 +413,17 @@ Return @code{#t} if @var{obj} is a weak vector. Note that all weak hashes are also weak vectors. @end deffn +@deffn {Scheme Procedure} weak-vector-ref wvect k +@deffnx {C Function} scm_weak_vector_ref (wvect, k) +Return the @var{k}th element of the weak vector @var{wvect}, or +@code{#f} if that element has been collected. +@end deffn + +@deffn {Scheme Procedure} weak-vector-set! wvect k elt +@deffnx {C Function} scm_weak_vector_set_x (wvect, k, elt) +Set the @var{k}th element of the weak vector @var{wvect} to @var{elt}. +@end deffn + @node Guardians @subsection Guardians diff --git a/libguile/vectors.c b/libguile/vectors.c index b386deb..35a9ede 100644 --- a/libguile/vectors.c +++ b/libguile/vectors.c @@ -1,5 +1,5 @@ /* Copyright (C) 1995,1996,1998,1999,2000,2001, 2006, 2008, 2009, 2010, - * 2011, 2012 Free Software Foundation, Inc. + * 2011, 2012, 2014 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 @@ -117,7 +117,13 @@ SCM scm_vector_length (SCM v) { if (SCM_I_IS_VECTOR (v)) - return scm_from_size_t (SCM_I_VECTOR_LENGTH (v)); + { + if (SCM_I_WVECTP (v)) + scm_c_issue_deprecation_warning + ("Using vector-length on weak vectors is deprecated. " + "Use weak-vector-length from (ice-9 weak-vectors) instead."); + return scm_from_size_t (SCM_I_VECTOR_LENGTH (v)); + } else if (SCM_I_ARRAYP (v) && SCM_I_ARRAY_NDIM (v) == 1) { scm_t_array_dim *dim = SCM_I_ARRAY_DIMS (v); @@ -130,7 +136,7 @@ scm_vector_length (SCM v) size_t scm_c_vector_length (SCM v) { - if (SCM_I_IS_VECTOR (v)) + if (SCM_I_IS_NONWEAK_VECTOR (v)) return SCM_I_VECTOR_LENGTH (v); else return scm_to_size_t (scm_vector_length (v)); @@ -206,7 +212,7 @@ scm_vector_ref (SCM v, SCM k) SCM scm_c_vector_ref (SCM v, size_t k) { - if (SCM_I_IS_VECTOR (v)) + if (SCM_I_IS_NONWEAK_VECTOR (v)) { register SCM elt; @@ -214,12 +220,15 @@ scm_c_vector_ref (SCM v, size_t k) scm_out_of_range (NULL, scm_from_size_t (k)); elt = (SCM_I_VECTOR_ELTS(v))[k]; - if (SCM_UNPACK (elt) == 0 && SCM_I_WVECTP (v)) - /* ELT was a weak pointer and got nullified by the GC. */ - return SCM_BOOL_F; - return elt; } + else if (SCM_I_WVECTP (v)) + { + scm_c_issue_deprecation_warning + ("Using vector-ref on weak vectors is deprecated. " + "Instead, use weak-vector-ref from (ice-9 weak-vectors)."); + return scm_c_weak_vector_ref (v, k); + } else if (SCM_I_ARRAYP (v) && SCM_I_ARRAY_NDIM (v) == 1) { scm_t_array_dim *dim = SCM_I_ARRAY_DIMS (v); @@ -234,8 +243,12 @@ scm_c_vector_ref (SCM v, size_t k) elt = (SCM_I_VECTOR_ELTS (vv))[k]; if (SCM_UNPACK (elt) == 0 && (SCM_I_WVECTP (vv))) - /* ELT was a weak pointer and got nullified by the GC. */ - return SCM_BOOL_F; + { + scm_c_issue_deprecation_warning + ("Weak arrays are deprecated. Use weak vectors instead."); + /* ELT was a weak pointer and got nullified by the GC. */ + return SCM_BOOL_F; + } return elt; } @@ -270,17 +283,18 @@ scm_vector_set_x (SCM v, SCM k, SCM obj) void scm_c_vector_set_x (SCM v, size_t k, SCM obj) { - if (SCM_I_IS_VECTOR (v)) + if (SCM_I_IS_NONWEAK_VECTOR (v)) { if (k >= SCM_I_VECTOR_LENGTH (v)) scm_out_of_range (NULL, scm_from_size_t (k)); (SCM_I_VECTOR_WELTS(v))[k] = obj; - if (SCM_I_WVECTP (v)) - { - /* Make it a weak pointer. */ - SCM *link = & SCM_I_VECTOR_WELTS (v)[k]; - SCM_I_REGISTER_DISAPPEARING_LINK ((void **) link, SCM2PTR (obj)); - } + } + else if (SCM_I_WVECTP (v)) + { + scm_c_issue_deprecation_warning + ("Using vector-set! on weak vectors is deprecated. " + "Instead, use weak-vector-set! from (ice-9 weak-vectors)."); + scm_c_weak_vector_set_x (v, k, obj); } else if (SCM_I_ARRAYP (v) && SCM_I_ARRAY_NDIM (v) == 1) { @@ -298,6 +312,8 @@ scm_c_vector_set_x (SCM v, size_t k, SCM obj) /* Make it a weak pointer. */ SCM *link = & SCM_I_VECTOR_WELTS (vv)[k]; SCM_I_REGISTER_DISAPPEARING_LINK ((void **) link, SCM2PTR (obj)); + scm_c_issue_deprecation_warning + ("Weak arrays are deprecated. Use weak vectors instead."); } } else diff --git a/libguile/weaks.c b/libguile/weaks.c index 79ae1fe..b590998 100644 --- a/libguile/weaks.c +++ b/libguile/weaks.c @@ -1,5 +1,5 @@ /* Copyright (C) 1995, 1996, 1998, 2000, 2001, 2003, 2006, 2008, 2009, 2010, - * 2011, 2012 Free Software Foundation, Inc. + * 2011, 2012, 2014 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 @@ -122,6 +122,10 @@ scm_doubly_weak_pair (SCM car, SCM cdr) */ +#define SCM_VALIDATE_WEAK_VECTOR(pos, var) \ + SCM_I_MAKE_VALIDATE_MSG2 (pos, var, SCM_I_WVECTP, "weak vector") + + SCM_DEFINE (scm_make_weak_vector, "make-weak-vector", 1, 1, 0, (SCM size, SCM fill), "Return a weak vector with @var{size} elements. If the optional\n" @@ -157,10 +161,101 @@ SCM_DEFINE (scm_weak_vector_p, "weak-vector?", 1, 0, 0, "weak hashes are also weak vectors.") #define FUNC_NAME s_scm_weak_vector_p { - return scm_from_bool (SCM_I_WVECTP (obj) && !SCM_IS_WHVEC (obj)); + return scm_from_bool (scm_is_weak_vector (obj)); } #undef FUNC_NAME + +int +scm_is_weak_vector (SCM obj) +{ + return SCM_I_WVECTP (obj) && !SCM_IS_WHVEC (obj); +} + + +SCM_DEFINE (scm_weak_vector_length, "weak-vector-length", 1, 0, 0, + (SCM wvect), + "Returns the number of elements in @var{wvect} as an exact integer.") +#define FUNC_NAME s_scm_weak_vector_length +{ + return scm_from_size_t (scm_c_weak_vector_length (wvect)); +} +#undef FUNC_NAME + + +size_t +scm_c_weak_vector_length (SCM wvect) +#define FUNC_NAME s_scm_weak_vector_length +{ + SCM_VALIDATE_WEAK_VECTOR (1, wvect); + return SCM_I_VECTOR_LENGTH (wvect); +} +#undef FUNC_NAME + + +SCM_DEFINE (scm_weak_vector_ref, "weak-vector-ref", 2, 0, 0, + (SCM wvect, SCM k), + "Like @code{vector-ref}, but for weak vectors.") +#define FUNC_NAME s_scm_weak_vector_ref +{ + return scm_c_weak_vector_ref (wvect, scm_to_size_t (k)); +} +#undef FUNC_NAME + + +SCM +scm_c_weak_vector_ref (SCM wvect, size_t k) +#define FUNC_NAME s_scm_weak_vector_ref +{ + SCM elt; + + SCM_VALIDATE_WEAK_VECTOR (1, wvect); + + if (k >= SCM_I_VECTOR_LENGTH (wvect)) + scm_out_of_range (NULL, scm_from_size_t (k)); + elt = (SCM_I_VECTOR_ELTS(wvect))[k]; + + if (SCM_UNPACK (elt) == 0) + /* ELT was a weak pointer and got nullified by the GC. */ + return SCM_BOOL_F; + + return elt; +} +#undef FUNC_NAME + + +SCM_DEFINE (scm_weak_vector_set_x, "weak-vector-set!", 3, 0, 0, + (SCM wvect, SCM k, SCM elt), + "Like @code{vector-set!}, but for weak vectors.") +#define FUNC_NAME s_scm_weak_vector_set_x +{ + scm_c_weak_vector_set_x (wvect, scm_to_size_t (k), elt); + + return SCM_UNSPECIFIED; +} +#undef FUNC_NAME + + +void +scm_c_weak_vector_set_x (SCM wvect, size_t k, SCM elt) +#define FUNC_NAME s_scm_weak_vector_set_x +{ + SCM *loc; + + SCM_VALIDATE_WEAK_VECTOR (1, wvect); + + if (k >= SCM_I_VECTOR_LENGTH (wvect)) + scm_out_of_range (NULL, scm_from_size_t (k)); + + loc = & SCM_I_VECTOR_WELTS (wvect)[k]; + *loc = elt; + + /* Make it a weak pointer. */ + SCM_I_REGISTER_DISAPPEARING_LINK ((void **) loc, SCM2PTR (elt)); +} +#undef FUNC_NAME + + /* Weak alist vectors, i.e., vectors of alists. diff --git a/libguile/weaks.h b/libguile/weaks.h index fc16f8b..be2c686 100644 --- a/libguile/weaks.h +++ b/libguile/weaks.h @@ -3,7 +3,7 @@ #ifndef SCM_WEAKS_H #define SCM_WEAKS_H -/* Copyright (C) 1995,1996,2000,2001, 2003, 2006, 2008, 2009, 2011 Free Software Foundation, Inc. +/* Copyright (C) 1995,1996,2000,2001, 2003, 2006, 2008, 2009, 2011, 2014 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 @@ -76,6 +76,16 @@ SCM_INTERNAL SCM scm_doubly_weak_pair (SCM car, SCM cdr); SCM_API SCM scm_make_weak_vector (SCM k, SCM fill); SCM_API SCM scm_weak_vector (SCM l); SCM_API SCM scm_weak_vector_p (SCM x); +SCM_API SCM scm_weak_vector_length (SCM v); +SCM_API SCM scm_weak_vector_ref (SCM v, SCM k); +SCM_API SCM scm_weak_vector_set_x (SCM v, SCM k, SCM x); + +SCM_API SCM scm_c_make_weak_vector (size_t k, SCM fill); +SCM_API int scm_is_weak_vector (SCM obj); +SCM_API size_t scm_c_weak_vector_length (SCM vec); +SCM_API SCM scm_c_weak_vector_ref (SCM v, size_t k); +SCM_API void scm_c_weak_vector_set_x (SCM v, size_t k, SCM x); + SCM_API SCM scm_make_weak_key_alist_vector (SCM k); SCM_API SCM scm_make_weak_value_alist_vector (SCM k); SCM_API SCM scm_make_doubly_weak_alist_vector (SCM k); diff --git a/module/ice-9/weak-vector.scm b/module/ice-9/weak-vector.scm index 09e2e0a..aedde1e 100644 --- a/module/ice-9/weak-vector.scm +++ b/module/ice-9/weak-vector.scm @@ -1,6 +1,6 @@ ;;; installed-scm-file -;;;; Copyright (C) 2003, 2006 Free Software Foundation, Inc. +;;;; Copyright (C) 2003, 2006, 2014 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 @@ -20,6 +20,7 @@ (define-module (ice-9 weak-vector) :export (make-weak-vector list->weak-vector weak-vector weak-vector? + weak-vector-length weak-vector-ref weak-vector-set! make-weak-key-alist-vector make-weak-value-alist-vector make-doubly-weak-alist-vector diff --git a/test-suite/tests/guardians.test b/test-suite/tests/guardians.test index 470de45..fc4c9d8 100644 --- a/test-suite/tests/guardians.test +++ b/test-suite/tests/guardians.test @@ -1,7 +1,7 @@ ;;;; guardians.test --- test suite for Guile Guardians -*- scheme -*- ;;;; Jim Blandy <[email protected]> --- July 1999 ;;;; -;;;; Copyright (C) 1999, 2001, 2006 Free Software Foundation, Inc. +;;;; Copyright (C) 1999, 2001, 2006, 2014 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 @@ -209,7 +209,7 @@ (gc) (let ((p (cons #f #f))) (g p) - (vector-set! v 0 p) + (weak-vector-set! v 0 p) (set! p #f)) ;; clear refs left on the stack (if (not (eq? (g) #f)) (throw 'unresolved) @@ -225,7 +225,7 @@ (gc) (let ((p (cons #f #f))) (g p) - (vector-set! v 0 p) + (weak-vector-set! v 0 p) (set! p #f)) ;; clear refs left on the stack (begin (gc) @@ -233,7 +233,7 @@ (throw 'unresolved) (begin (gc) - (or (not (vector-ref v 0)) + (or (not (weak-vector-ref v 0)) (throw 'unresolved)))))))) (with-test-prefix "guarding weak containers" @@ -243,11 +243,11 @@ (v (weak-vector #f))) ;; Note: We don't pass `(cons #f #f)' as an argument to `weak-vector' ;; otherwise references to it are likely to be left on the stack. - (vector-set! v 0 (cons #f #f)) + (weak-vector-set! v 0 (cons #f #f)) (g v) (gc) - (if (equal? (vector-ref v 0) (cons #f #f)) + (if (equal? (weak-vector-ref v 0) (cons #f #f)) (throw 'unresolved) #t)))) diff --git a/test-suite/tests/weaks.test b/test-suite/tests/weaks.test index d0f6c5e..b0f36d8 100644 --- a/test-suite/tests/weaks.test +++ b/test-suite/tests/weaks.test @@ -1,5 +1,5 @@ ;;;; weaks.test --- tests guile's weaks -*- scheme -*- -;;;; Copyright (C) 1999, 2001, 2003, 2006, 2009, 2010, 2011 Free Software Foundation, Inc. +;;;; Copyright (C) 1999, 2001, 2003, 2006, 2009, 2010, 2011, 2014 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 @@ -57,13 +57,13 @@ (pass-if "create" (let* ((lst '(a b c d e f g)) (wv (list->weak-vector lst))) - (and (eq? (vector-ref wv 0) 'a) - (eq? (vector-ref wv 1) 'b) - (eq? (vector-ref wv 2) 'c) - (eq? (vector-ref wv 3) 'd) - (eq? (vector-ref wv 4) 'e) - (eq? (vector-ref wv 5) 'f) - (eq? (vector-ref wv 6) 'g)))) + (and (eq? (weak-vector-ref wv 0) 'a) + (eq? (weak-vector-ref wv 1) 'b) + (eq? (weak-vector-ref wv 2) 'c) + (eq? (weak-vector-ref wv 3) 'd) + (eq? (weak-vector-ref wv 4) 'e) + (eq? (weak-vector-ref wv 5) 'f) + (eq? (weak-vector-ref wv 6) 'g)))) (pass-if-exception "bad-args" exception:wrong-type-arg (list->weak-vector 32))) @@ -99,11 +99,11 @@ (define global-weak (make-weak-vector 10 #f)) (begin - (vector-set! global-weak 0 (string-copy "string")) - (vector-set! global-weak 1 (string-copy "beans")) - (vector-set! global-weak 2 (string-copy "to")) - (vector-set! global-weak 3 (string-copy "utah")) - (vector-set! global-weak 4 (string-copy "yum yum")) + (weak-vector-set! global-weak 0 (string-copy "string")) + (weak-vector-set! global-weak 1 (string-copy "beans")) + (weak-vector-set! global-weak 2 (string-copy "to")) + (weak-vector-set! global-weak 3 (string-copy "utah")) + (weak-vector-set! global-weak 4 (string-copy "yum yum")) (gc)) ;;; Normal weak vectors @@ -113,17 +113,17 @@ "weak-vector" (pass-if "lives" (begin - (vector-set! x 0 bar) + (weak-vector-set! x 0 bar) (gc) - (and (vector-ref x 0) (eq? bar (vector-ref x 0))))) + (and (weak-vector-ref x 0) (eq? bar (weak-vector-ref x 0))))) (pass-if "dies" (begin (gc) - (or (and (not (vector-ref global-weak 0)) - (not (vector-ref global-weak 1)) - (not (vector-ref global-weak 2)) - (not (vector-ref global-weak 3)) - (not (vector-ref global-weak 4))) + (or (and (not (weak-vector-ref global-weak 0)) + (not (weak-vector-ref global-weak 1)) + (not (weak-vector-ref global-weak 2)) + (not (weak-vector-ref global-weak 3)) + (not (weak-vector-ref global-weak 4))) (throw 'unresolved)))))) hooks/post-receive -- GNU Guile
