1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 03:30:27 +02:00
Conflicts:
	libguile/vectors.c
	test-suite/tests/weaks.test
This commit is contained in:
Andy Wingo 2014-02-07 15:36:06 +01:00
commit 9db57a19e1
3 changed files with 30 additions and 38 deletions

View file

@ -1,5 +1,5 @@
/* Copyright (C) 1995,1996,1998,1999,2000,2001, 2006, 2008, 2009, 2010, /* 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 * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License * modify it under the terms of the GNU Lesser General Public License
@ -35,7 +35,6 @@
#include "libguile/strings.h" #include "libguile/strings.h"
#include "libguile/srfi-13.h" #include "libguile/srfi-13.h"
#include "libguile/dynwind.h" #include "libguile/dynwind.h"
#include "libguile/deprecation.h"
#include "libguile/bdw-gc.h" #include "libguile/bdw-gc.h"
@ -112,7 +111,7 @@ SCM_GPROC (s_vector_length, "vector-length", 1, 0, 0, scm_vector_length, g_vecto
SCM SCM
scm_vector_length (SCM v) scm_vector_length (SCM v)
{ {
if (SCM_I_IS_VECTOR (v)) if (SCM_I_IS_NONWEAK_VECTOR (v))
return scm_from_size_t (SCM_I_VECTOR_LENGTH (v)); return scm_from_size_t (SCM_I_VECTOR_LENGTH (v));
else if (SCM_I_ARRAYP (v) && SCM_I_ARRAY_NDIM (v) == 1) else if (SCM_I_ARRAYP (v) && SCM_I_ARRAY_NDIM (v) == 1)
{ {
@ -126,7 +125,7 @@ scm_vector_length (SCM v)
size_t size_t
scm_c_vector_length (SCM v) 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); return SCM_I_VECTOR_LENGTH (v);
else else
return scm_to_size_t (scm_vector_length (v)); return scm_to_size_t (scm_vector_length (v));
@ -208,8 +207,6 @@ scm_c_vector_ref (SCM v, size_t k)
scm_out_of_range (NULL, scm_from_size_t (k)); scm_out_of_range (NULL, scm_from_size_t (k));
return SCM_SIMPLE_VECTOR_REF (v, k); return SCM_SIMPLE_VECTOR_REF (v, k);
} }
else if (SCM_I_WVECTP (v))
return scm_c_weak_vector_ref (v, k);
else if (SCM_I_ARRAYP (v) && SCM_I_ARRAY_NDIM (v) == 1) else if (SCM_I_ARRAYP (v) && SCM_I_ARRAY_NDIM (v) == 1)
{ {
scm_t_array_dim *dim = SCM_I_ARRAY_DIMS (v); scm_t_array_dim *dim = SCM_I_ARRAY_DIMS (v);
@ -221,8 +218,6 @@ scm_c_vector_ref (SCM v, size_t k)
if (SCM_I_IS_NONWEAK_VECTOR (vv)) if (SCM_I_IS_NONWEAK_VECTOR (vv))
return SCM_SIMPLE_VECTOR_REF (vv, k); return SCM_SIMPLE_VECTOR_REF (vv, k);
else if (SCM_I_WVECTP (vv))
return scm_c_weak_vector_ref (vv, k);
else else
scm_wrong_type_arg_msg (NULL, 0, v, "non-uniform vector"); scm_wrong_type_arg_msg (NULL, 0, v, "non-uniform vector");
} }
@ -262,8 +257,6 @@ scm_c_vector_set_x (SCM v, size_t k, SCM obj)
scm_out_of_range (NULL, scm_from_size_t (k)); scm_out_of_range (NULL, scm_from_size_t (k));
SCM_SIMPLE_VECTOR_SET (v, k, obj); SCM_SIMPLE_VECTOR_SET (v, k, obj);
} }
else if (SCM_I_WVECTP (v))
scm_c_weak_vector_set_x (v, k, obj);
else if (SCM_I_ARRAYP (v) && SCM_I_ARRAY_NDIM (v) == 1) else if (SCM_I_ARRAYP (v) && SCM_I_ARRAY_NDIM (v) == 1)
{ {
scm_t_array_dim *dim = SCM_I_ARRAY_DIMS (v); scm_t_array_dim *dim = SCM_I_ARRAY_DIMS (v);
@ -275,8 +268,6 @@ scm_c_vector_set_x (SCM v, size_t k, SCM obj)
if (SCM_I_IS_NONWEAK_VECTOR (vv)) if (SCM_I_IS_NONWEAK_VECTOR (vv))
SCM_SIMPLE_VECTOR_SET (vv, k, obj); SCM_SIMPLE_VECTOR_SET (vv, k, obj);
else if (SCM_I_WVECTP (vv))
scm_c_weak_vector_set_x (vv, k, obj);
else else
scm_wrong_type_arg_msg (NULL, 0, v, "non-uniform vector"); scm_wrong_type_arg_msg (NULL, 0, v, "non-uniform vector");
} }

View file

@ -1,7 +1,7 @@
;;;; guardians.test --- test suite for Guile Guardians -*- scheme -*- ;;;; guardians.test --- test suite for Guile Guardians -*- scheme -*-
;;;; Jim Blandy <jimb@red-bean.com> --- July 1999 ;;;; Jim Blandy <jimb@red-bean.com> --- 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 ;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public ;;;; modify it under the terms of the GNU Lesser General Public
@ -209,7 +209,7 @@
(gc) (gc)
(let ((p (cons #f #f))) (let ((p (cons #f #f)))
(g p) (g p)
(vector-set! v 0 p) (weak-vector-set! v 0 p)
(set! p #f)) ;; clear refs left on the stack (set! p #f)) ;; clear refs left on the stack
(if (not (eq? (g) #f)) (if (not (eq? (g) #f))
(throw 'unresolved) (throw 'unresolved)
@ -225,7 +225,7 @@
(gc) (gc)
(let ((p (cons #f #f))) (let ((p (cons #f #f)))
(g p) (g p)
(vector-set! v 0 p) (weak-vector-set! v 0 p)
(set! p #f)) ;; clear refs left on the stack (set! p #f)) ;; clear refs left on the stack
(begin (begin
(gc) (gc)
@ -233,7 +233,7 @@
(throw 'unresolved) (throw 'unresolved)
(begin (begin
(gc) (gc)
(or (not (vector-ref v 0)) (or (not (weak-vector-ref v 0))
(throw 'unresolved)))))))) (throw 'unresolved))))))))
(with-test-prefix "guarding weak containers" (with-test-prefix "guarding weak containers"
@ -243,11 +243,11 @@
(v (weak-vector #f))) (v (weak-vector #f)))
;; Note: We don't pass `(cons #f #f)' as an argument to `weak-vector' ;; 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. ;; 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) (g v)
(gc) (gc)
(if (equal? (vector-ref v 0) (cons #f #f)) (if (equal? (weak-vector-ref v 0) (cons #f #f))
(throw 'unresolved) (throw 'unresolved)
#t)))) #t))))

View file

@ -1,5 +1,6 @@
;;;; weaks.test --- tests guile's weaks -*- scheme -*- ;;;; weaks.test --- tests guile's weaks -*- scheme -*-
;;;; Copyright (C) 1999, 2001, 2003, 2006, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. ;;;; Copyright (C) 1999, 2001, 2003, 2006, 2009, 2010, 2011, 2012, 2014
;;;; Free Software Foundation, Inc.
;;;; ;;;;
;;;; This library is free software; you can redistribute it and/or ;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public ;;;; modify it under the terms of the GNU Lesser General Public
@ -57,13 +58,13 @@
(pass-if "create" (pass-if "create"
(let* ((lst '(a b c d e f g)) (let* ((lst '(a b c d e f g))
(wv (list->weak-vector lst))) (wv (list->weak-vector lst)))
(and (eq? (vector-ref wv 0) 'a) (and (eq? (weak-vector-ref wv 0) 'a)
(eq? (vector-ref wv 1) 'b) (eq? (weak-vector-ref wv 1) 'b)
(eq? (vector-ref wv 2) 'c) (eq? (weak-vector-ref wv 2) 'c)
(eq? (vector-ref wv 3) 'd) (eq? (weak-vector-ref wv 3) 'd)
(eq? (vector-ref wv 4) 'e) (eq? (weak-vector-ref wv 4) 'e)
(eq? (vector-ref wv 5) 'f) (eq? (weak-vector-ref wv 5) 'f)
(eq? (vector-ref wv 6) 'g)))) (eq? (weak-vector-ref wv 6) 'g))))
(pass-if-exception "bad-args" (pass-if-exception "bad-args"
exception:wrong-type-arg exception:wrong-type-arg
(list->weak-vector 32))) (list->weak-vector 32)))
@ -99,11 +100,11 @@
(define global-weak (make-weak-vector 10 #f)) (define global-weak (make-weak-vector 10 #f))
(begin (begin
(vector-set! global-weak 0 (string-copy "string")) (weak-vector-set! global-weak 0 (string-copy "string"))
(vector-set! global-weak 1 (string-copy "beans")) (weak-vector-set! global-weak 1 (string-copy "beans"))
(vector-set! global-weak 2 (string-copy "to")) (weak-vector-set! global-weak 2 (string-copy "to"))
(vector-set! global-weak 3 (string-copy "utah")) (weak-vector-set! global-weak 3 (string-copy "utah"))
(vector-set! global-weak 4 (string-copy "yum yum")) (weak-vector-set! global-weak 4 (string-copy "yum yum"))
(gc)) (gc))
;;; Normal weak vectors ;;; Normal weak vectors
@ -113,17 +114,17 @@
"weak-vector" "weak-vector"
(pass-if "lives" (pass-if "lives"
(begin (begin
(vector-set! x 0 bar) (weak-vector-set! x 0 bar)
(gc) (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" (pass-if "dies"
(begin (begin
(gc) (gc)
(or (and (not (vector-ref global-weak 0)) (or (and (not (weak-vector-ref global-weak 0))
(not (vector-ref global-weak 1)) (not (weak-vector-ref global-weak 1))
(not (vector-ref global-weak 2)) (not (weak-vector-ref global-weak 2))
(not (vector-ref global-weak 3)) (not (weak-vector-ref global-weak 3))
(not (vector-ref global-weak 4))) (not (weak-vector-ref global-weak 4)))
(throw 'unresolved)))))) (throw 'unresolved))))))