diff options
author | Marius Vollmer <mvo@zagadka.de> | 2005-01-02 20:06:08 +0000 |
---|---|---|
committer | Marius Vollmer <mvo@zagadka.de> | 2005-01-02 20:06:08 +0000 |
commit | 6e708ef2b1897c3ea4d5ac47720974078d50e9e4 (patch) | |
tree | 3dde367b768213b4693cc586b2adf23074f15667 /libguile/weaks.c | |
parent | 9c6e33c62acc203792053b6d5a579bdc22827eec (diff) | |
download | guile-6e708ef2b1897c3ea4d5ac47720974078d50e9e4.tar.gz |
* weaks.c: Use new vector elements API or simple vector
API, as appropriate.
* srfi-4.h, srfi-4.c, srfi-4.i.c (scm_array_handle_uniform_elements,
scm_array_handle_uniform_writable_elements,
scm_uniform_vector_elements, scm_uniform_vector_writable_elements):
(scm_<foo>vector_elements, scm_<foo>vector_writable_elements): Use
scm_t_array_handle, deliver length and increment.
(scm_array_handle_<foo>_elements,
scm_array_handle_<foo>_writable_elements): New.
* unif.h, unif.c (scm_t_array_handle, scm_array_get_handle,
scm_array_handle_rank, scm_array_handle_dims, scm_array_handle_ref
scm_array_handle_set, scm_array_handle_elements
scm_array_handle_writable_elements, scm_vector_get_handle): New.
(scm_make_uve, scm_array_prototype, scm_list_to_uniform_array,
scm_dimensions_to_uniform_array): Deprecated for real. (scm_array_p,
scm_i_array_p): Use latter for SCM_DEFINE since snarfing wont allow a
mismatch between C and Scheme arglists. (scm_make_shared_array,
scm_enclose_array): Correctly use scm_c_generalized_vector_length
instead of scm_uniform_vector_length.
* weaks.h, weaks.c: Use new internal weak vector API from
vectors.h.
* Makefile.am (libguile_la_SOURCES, DOT_X_FILES, DOT_DOC_FILES,
EXTRA_libguile_la_SOURCES): Changed ramap.c and unif.c from being
'extra' to being regular sources.
(noinst_HEADERS): Added quicksort.i.c.
* quicksort.i.c: New file.
* vectors.h, vector.c (SCM_VECTORP, SCM_VECTOR_LENGTH, SCM_VELTS,
SCM_WRITABLE_VELTS, SCM_VECTOR_REF, SCM_VECTOR_SET): Deprecated and
reimplemented. Replaced all uses with scm_vector_elements,
scm_vector_writable_elements, or SCM_SIMPLE_VECTOR_*, as appropriate.
(scm_is_simple_vector, SCM_SIMPLE_VECTOR_LENGTH,
SCM_SIMPLE_VECTOR_REF, SCM_SIMPLE_VECTOR_SET, SCM_SIMPLE_VECTOR_LOC):
New. (SCM_VECTOR_BASE, SCM_SET_VECTOR_BASE, SCM_VECTOR_MAX_LENGTH,
SCM_MAKE_VECTOR_TAG, SCM_SET_VECTOR_LENGTH, SCM_VELTS_AS_STACKITEMS,
SCM_SETVELTS, SCM_GC_WRITABLE_VELTS): Removed. (scm_vector_copy):
New. (scm_vector_elements, scm_vector_writable_elements): Use
scm_t_array_handle, deliver length and increment. Moved to
unif.h. Changed all uses. (scm_vector_release_elements,
scm_vector_release_writable_elements,
(scm_frame_vector_release_elements,
scm_frame_vector_release_writable_elements): Removed.
(SCM_I_IS_VECTOR, SCM_I_VECTOR_ELTS, SCM_I_VECTOR_WELTS,
SCM_I_VECTOR_LENGTH, scm_i_vector_free): New internal API.
(SCM_I_WVECTP SCM_I_WVECT_LENGTH SCM_I_WVECT_VELTS
SCM_I_WVECT_GC_WVELTS SCM_I_WVECT_TYPE SCM_I_WVECT_GC_CHAIN
SCM_I_SET_WVECT_GC_CHAIN, scm_i_allocate_weak_vector): New, for weak
vectors.
Diffstat (limited to 'libguile/weaks.c')
-rw-r--r-- | libguile/weaks.c | 90 |
1 files changed, 22 insertions, 68 deletions
diff --git a/libguile/weaks.c b/libguile/weaks.c index 250a4cf7d..6eeebcada 100644 --- a/libguile/weaks.c +++ b/libguile/weaks.c @@ -66,49 +66,6 @@ */ -/* Allocate memory for a weak vector on behalf of the caller. The allocated - * vector will be of the given weak vector subtype. It will contain size - * elements which are initialized with the 'fill' object, or, if 'fill' is - * undefined, with an unspecified object. - */ -SCM -scm_i_allocate_weak_vector (scm_t_bits type, SCM size, SCM fill, const char* caller) -#define FUNC_NAME caller -{ - size_t c_size; - SCM v; - - c_size = scm_to_unsigned_integer (size, 0, SCM_VECTOR_MAX_LENGTH); - - if (c_size > 0) - { - scm_t_bits *base; - size_t j; - - if (SCM_UNBNDP (fill)) - fill = SCM_UNSPECIFIED; - - base = scm_gc_malloc (c_size * sizeof (scm_t_bits), "weak vector"); - for (j = 0; j != c_size; ++j) - base[j] = SCM_UNPACK (fill); - v = scm_double_cell (SCM_MAKE_VECTOR_TAG (c_size, scm_tc7_wvect), - (scm_t_bits) base, - type, - SCM_UNPACK (SCM_EOL)); - scm_remember_upto_here_1 (fill); - } - else - { - v = scm_double_cell (SCM_MAKE_VECTOR_TAG (0, scm_tc7_wvect), - (scm_t_bits) NULL, - type, - SCM_UNPACK (SCM_EOL)); - } - - return v; -} -#undef FUNC_NAME - 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" @@ -117,7 +74,7 @@ SCM_DEFINE (scm_make_weak_vector, "make-weak-vector", 1, 1, 0, "empty list.") #define FUNC_NAME s_scm_make_weak_vector { - return scm_i_allocate_weak_vector (0, size, fill, FUNC_NAME); + return scm_i_allocate_weak_vector (0, size, fill); } #undef FUNC_NAME @@ -133,24 +90,21 @@ SCM_DEFINE (scm_weak_vector, "weak-vector", 0, 0, 1, "the same way @code{list->vector} would.") #define FUNC_NAME s_scm_weak_vector { - SCM res; - SCM *data; + scm_t_array_handle handle; + SCM res, *data; long i; - /* Dirk:FIXME:: In case of multiple threads, the list might get corrupted - while the vector is being created. */ i = scm_ilength (l); SCM_ASSERT (i >= 0, l, SCM_ARG1, FUNC_NAME); + res = scm_make_weak_vector (scm_from_int (i), SCM_UNSPECIFIED); + data = scm_vector_writable_elements (res, &handle, NULL, NULL); - /* - no alloc, so this loop is safe. - */ - data = SCM_WRITABLE_VELTS (res); - while (!SCM_NULL_OR_NIL_P (l)) + while (scm_is_pair (l) && i > 0) { *data++ = SCM_CAR (l); l = SCM_CDR (l); + i--; } return res; @@ -164,7 +118,7 @@ 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_WVECTP (obj) && !SCM_IS_WHVEC (obj)); + return scm_from_bool (SCM_I_WVECTP (obj) && !SCM_IS_WHVEC (obj)); } #undef FUNC_NAME @@ -183,7 +137,7 @@ SCM_DEFINE (scm_make_weak_key_alist_vector, "make-weak-key-alist-vector", 0, 1, #define FUNC_NAME s_scm_make_weak_key_alist_vector { return scm_i_allocate_weak_vector - (1, SCM_UNBNDP (size) ? scm_from_int (31) : size, SCM_EOL, FUNC_NAME); + (1, SCM_UNBNDP (size) ? scm_from_int (31) : size, SCM_EOL); } #undef FUNC_NAME @@ -195,7 +149,7 @@ SCM_DEFINE (scm_make_weak_value_alist_vector, "make-weak-value-alist-vector", 0, #define FUNC_NAME s_scm_make_weak_value_alist_vector { return scm_i_allocate_weak_vector - (2, SCM_UNBNDP (size) ? scm_from_int (31) : size, SCM_EOL, FUNC_NAME); + (2, SCM_UNBNDP (size) ? scm_from_int (31) : size, SCM_EOL); } #undef FUNC_NAME @@ -207,7 +161,7 @@ SCM_DEFINE (scm_make_doubly_weak_alist_vector, "make-doubly-weak-alist-vector", #define FUNC_NAME s_scm_make_doubly_weak_alist_vector { return scm_i_allocate_weak_vector - (3, SCM_UNBNDP (size) ? scm_from_int (31) : size, SCM_EOL, FUNC_NAME); + (3, SCM_UNBNDP (size) ? scm_from_int (31) : size, SCM_EOL); } #undef FUNC_NAME @@ -221,7 +175,7 @@ SCM_DEFINE (scm_weak_key_alist_vector_p, "weak-key-alist-vector?", 1, 0, 0, "nor a weak value hash table.") #define FUNC_NAME s_scm_weak_key_alist_vector_p { - return scm_from_bool (SCM_WVECTP (obj) && SCM_IS_WHVEC (obj)); + return scm_from_bool (SCM_I_WVECTP (obj) && SCM_IS_WHVEC (obj)); } #undef FUNC_NAME @@ -231,7 +185,7 @@ SCM_DEFINE (scm_weak_value_alist_vector_p, "weak-value-alist-vector?", 1, 0, 0, "Return @code{#t} if @var{obj} is a weak value hash table.") #define FUNC_NAME s_scm_weak_value_alist_vector_p { - return scm_from_bool (SCM_WVECTP (obj) && SCM_IS_WHVEC_V (obj)); + return scm_from_bool (SCM_I_WVECTP (obj) && SCM_IS_WHVEC_V (obj)); } #undef FUNC_NAME @@ -241,7 +195,7 @@ SCM_DEFINE (scm_doubly_weak_alist_vector_p, "doubly-weak-alist-vector?", 1, 0, 0 "Return @code{#t} if @var{obj} is a doubly weak hash table.") #define FUNC_NAME s_scm_doubly_weak_alist_vector_p { - return scm_from_bool (SCM_WVECTP (obj) && SCM_IS_WHVEC_B (obj)); + return scm_from_bool (SCM_I_WVECTP (obj) && SCM_IS_WHVEC_B (obj)); } #undef FUNC_NAME @@ -264,7 +218,7 @@ scm_mark_weak_vector_spines (void *dummy1 SCM_UNUSED, { SCM w; - for (w = scm_weak_vectors; !scm_is_null (w); w = SCM_WVECT_GC_CHAIN (w)) + for (w = scm_weak_vectors; !scm_is_null (w); w = SCM_I_WVECT_GC_CHAIN (w)) { if (SCM_IS_WHVEC_ANY (w)) { @@ -274,8 +228,8 @@ scm_mark_weak_vector_spines (void *dummy1 SCM_UNUSED, long n; obj = w; - ptr = SCM_VELTS (w); - n = SCM_VECTOR_LENGTH (w); + ptr = SCM_I_WVECT_GC_WVELTS (w); + n = SCM_I_WVECT_LENGTH (w); for (j = 0; j < n; ++j) { SCM alist; @@ -304,14 +258,14 @@ scm_scan_weak_vectors (void *dummy1 SCM_UNUSED, void *dummy3 SCM_UNUSED) { SCM *ptr, w; - for (w = scm_weak_vectors; !scm_is_null (w); w = SCM_WVECT_GC_CHAIN (w)) + for (w = scm_weak_vectors; !scm_is_null (w); w = SCM_I_WVECT_GC_CHAIN (w)) { if (!SCM_IS_WHVEC_ANY (w)) { register long j, n; - ptr = SCM_GC_WRITABLE_VELTS (w); - n = SCM_VECTOR_LENGTH (w); + ptr = SCM_I_WVECT_GC_WVELTS (w); + n = SCM_I_WVECT_LENGTH (w); for (j = 0; j < n; ++j) if (UNMARKED_CELL_P (ptr[j])) ptr[j] = SCM_BOOL_F; @@ -321,12 +275,12 @@ scm_scan_weak_vectors (void *dummy1 SCM_UNUSED, else if (!SCM_WVECT_NOSCAN_P (w)) { SCM obj = w; - register long n = SCM_VECTOR_LENGTH (w); + register long n = SCM_I_WVECT_LENGTH (w); register long j; int weak_keys = SCM_IS_WHVEC (obj) || SCM_IS_WHVEC_B (obj); int weak_values = SCM_IS_WHVEC_V (obj) || SCM_IS_WHVEC_B (obj); - ptr = SCM_GC_WRITABLE_VELTS (w); + ptr = SCM_I_WVECT_GC_WVELTS (w); for (j = 0; j < n; ++j) { |