guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] GNU Guile branch, master, updated. release_1-9-3-14-gf5a


From: Andy Wingo
Subject: [Guile-commits] GNU Guile branch, master, updated. release_1-9-3-14-gf5a51ca
Date: Fri, 18 Sep 2009 14:27:06 +0000

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=f5a51caec1bf1900b269da6e07fe466199372970

The branch, master has been updated
       via  f5a51caec1bf1900b269da6e07fe466199372970 (commit)
       via  c5923112fed7b92ff5f1eeea03c74117b2f75490 (commit)
      from  c543e41eb4e1437d3f994b6b8d54540b33145aa7 (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 f5a51caec1bf1900b269da6e07fe466199372970
Author: Andy Wingo <address@hidden>
Date:   Thu Sep 17 13:52:09 2009 +0200

    fix bitvectors after the array handle refactoring
    
    * libguile/uniform.h (scm_array_handle_uniform_element_bit_size): New
      public accessor.
    
    * libguile/uniform.c (scm_array_handle_uniform_element_size): Better
      errors in non-byte-aligned arrays.
      (scm_uniform_vector_element_type, scm_uniform_vector_element_size)
      (scm_c_uniform_vector_ref, scm_c_uniform_vector_set_x):
      (scm_uniform_vector_to_list): Don't require byte-aligned access.
    
    * libguile/bytevectors.c (scm_uniform_array_to_bytevector):
    * libguile/arrays.c (scm_from_contiguous_typed_array):  Fix for
      uniform arrays whose element size is not a multiple of the byte size.

commit c5923112fed7b92ff5f1eeea03c74117b2f75490
Author: Andy Wingo <address@hidden>
Date:   Thu Sep 17 12:24:28 2009 +0200

    fix thinko in api-memory.texi

-----------------------------------------------------------------------

Summary of changes:
 doc/ref/api-memory.texi |    2 +-
 libguile/arrays.c       |   24 +++++++++++++------
 libguile/bytevectors.c  |   21 +++++++++++------
 libguile/uniform.c      |   56 +++++++++++++++++++++-------------------------
 libguile/uniform.h      |    4 ++-
 5 files changed, 60 insertions(+), 47 deletions(-)

diff --git a/doc/ref/api-memory.texi b/doc/ref/api-memory.texi
index 2bf7f10..15cef64 100644
--- a/doc/ref/api-memory.texi
+++ b/doc/ref/api-memory.texi
@@ -113,7 +113,7 @@ functions for dynamic memory allocation that are integrated 
into the
 garbage collector and the error reporting system.
 
 Memory blocks that are associated with Scheme objects (for example a
-smob) should be allocated and freed with @code{scm_gc_malloc} or
+smob) should be allocated with @code{scm_gc_malloc} or
 @code{scm_gc_malloc_pointerless}.  These two functions will either
 return a valid pointer or signal an error.  Memory blocks allocated this
 way can be freed with @code{scm_gc_free}; however, this is not strictly
diff --git a/libguile/arrays.c b/libguile/arrays.c
index 2be9ec3..62ce83e 100644
--- a/libguile/arrays.c
+++ b/libguile/arrays.c
@@ -211,7 +211,7 @@ scm_from_contiguous_typed_array (SCM type, SCM bounds, 
const void *bytes,
   scm_t_array_dim *s;
   SCM ra;
   scm_t_array_handle h;
-  void *base;
+  void *elts;
   size_t sz;
   
   ra = scm_i_shap2ra (bounds);
@@ -230,16 +230,24 @@ scm_from_contiguous_typed_array (SCM type, SCM bounds, 
const void *bytes,
 
 
   scm_array_get_handle (ra, &h);
-  base = scm_array_handle_uniform_writable_elements (&h);
-  sz = scm_array_handle_uniform_element_size (&h);
+  elts = h.writable_elements;
+  sz = scm_array_handle_uniform_element_bit_size (&h);
   scm_array_handle_release (&h);
 
-  if (byte_len % sz)
-    SCM_MISC_ERROR ("byte length not a multiple of the unit size", SCM_EOL);
-  if (byte_len / sz != rlen)
-    SCM_MISC_ERROR ("byte length and dimensions do not match", SCM_EOL);
+  if (sz >= 8 && ((sz % 8) == 0))
+    {
+      if (byte_len % (sz / 8))
+        SCM_MISC_ERROR ("byte length not a multiple of the unit size", 
SCM_EOL);
+      if (byte_len / (sz / 8) != rlen)
+        SCM_MISC_ERROR ("byte length and dimensions do not match", SCM_EOL);
+    }
+  else
+    {
+      if (rlen * (sz / 8) + rlen * (sz % 8) / 8 != byte_len)
+        SCM_MISC_ERROR ("byte length and dimensions do not match", SCM_EOL);
+    }
 
-  memcpy (base, bytes, byte_len);
+  memcpy (elts, bytes, byte_len);
 
   if (1 == SCM_I_ARRAY_NDIM (ra) && 0 == SCM_I_ARRAY_BASE (ra))
     if (s->ubnd < s->lbnd || (0 == s->lbnd && 1 == s->inc))
diff --git a/libguile/bytevectors.c b/libguile/bytevectors.c
index 4246f01..a3233ea 100644
--- a/libguile/bytevectors.c
+++ b/libguile/bytevectors.c
@@ -22,6 +22,7 @@
 #endif
 
 #include <alloca.h>
+#include <assert.h>
 
 #include <gmp.h>
 
@@ -587,23 +588,29 @@ SCM_DEFINE (scm_uniform_array_to_bytevector, 
"uniform-array->bytevector",
 #define FUNC_NAME s_scm_uniform_array_to_bytevector
 {
   SCM contents, ret;
-  size_t len;
+  size_t len, sz, byte_len;
   scm_t_array_handle h;
-  const void *base;
-  size_t sz;
+  const void *elts;
   
   contents = scm_array_contents (array, SCM_BOOL_T);
   if (scm_is_false (contents))
     scm_wrong_type_arg_msg (FUNC_NAME, 0, array, "uniform contiguous array");
 
   scm_array_get_handle (contents, &h);
+  assert (h.base == 0);
 
-  base = scm_array_handle_uniform_elements (&h);
+  elts = h.elements;
   len = h.dims->inc * (h.dims->ubnd - h.dims->lbnd + 1);
-  sz = scm_array_handle_uniform_element_size (&h);
+  sz = scm_array_handle_uniform_element_bit_size (&h);
+  if (sz >= 8 && ((sz % 8) == 0))
+    byte_len = len * (sz / 8);
+  else
+    /* uf. tricky, and i'm not sure i'm avoiding overflow. */
+    byte_len = len * (sz / 8)
+      + (((len * (sz % 8)) - 1) / 8) + 1;
 
-  ret = make_bytevector (len * sz, SCM_ARRAY_ELEMENT_TYPE_VU8);
-  memcpy (SCM_BYTEVECTOR_CONTENTS (ret), base, len * sz);
+  ret = make_bytevector (byte_len, SCM_ARRAY_ELEMENT_TYPE_VU8);
+  memcpy (SCM_BYTEVECTOR_CONTENTS (ret), elts, byte_len);
 
   scm_array_handle_release (&h);
 
diff --git a/libguile/uniform.c b/libguile/uniform.c
index 28125da..6bab856 100644
--- a/libguile/uniform.c
+++ b/libguile/uniform.c
@@ -44,13 +44,24 @@ const size_t 
scm_i_array_element_type_sizes[SCM_ARRAY_ELEMENT_TYPE_LAST + 1] = {
   64, 128
 };
 
-/* FIXME: return bit size instead of byte size? */
 size_t
 scm_array_handle_uniform_element_size (scm_t_array_handle *h)
 {
   size_t ret = scm_i_array_element_type_sizes[h->element_type];
   if (ret && ret % 8 == 0)
     return ret / 8;
+  else if (ret)
+    scm_wrong_type_arg_msg (NULL, 0, h->array, "byte-aligned uniform array");
+  else
+    scm_wrong_type_arg_msg (NULL, 0, h->array, "uniform array");
+}
+
+size_t
+scm_array_handle_uniform_element_bit_size (scm_t_array_handle *h)
+{
+  size_t ret = scm_i_array_element_type_sizes[h->element_type];
+  if (ret)
+    return ret;
   else
     scm_wrong_type_arg_msg (NULL, 0, h->array, "uniform array");
 }
@@ -110,14 +121,15 @@ SCM_DEFINE (scm_uniform_vector_p, "uniform-vector?", 1, 
0, 0,
 
 SCM_DEFINE (scm_uniform_vector_element_type, "uniform-vector-element-type", 1, 
0, 0,
            (SCM v),
-           "Return the number of elements in the uniform vector, @var{v}.")
+           "Return the type of the elements in the uniform vector, @var{v}.")
 #define FUNC_NAME s_scm_uniform_vector_element_type
 {
   scm_t_array_handle h;
-  size_t len;
-  ssize_t inc;
   SCM ret;
-  scm_uniform_vector_elements (v, &h, &len, &inc);
+  
+  if (!scm_is_uniform_vector (v))
+    scm_wrong_type_arg_msg (FUNC_NAME, SCM_ARG1, v, "uniform vector");
+  scm_array_get_handle (v, &h);
   ret = scm_array_handle_element_type (&h);
   scm_array_handle_release (&h);
   return ret;
@@ -144,15 +156,9 @@ SCM_DEFINE (scm_uniform_vector_element_size, 
"uniform-vector-element-size", 1, 0
 SCM
 scm_c_uniform_vector_ref (SCM v, size_t idx)
 {
-  SCM ret;
-  scm_t_array_handle h;
-  size_t len;
-  ssize_t inc;
-  
-  scm_uniform_vector_elements (v, &h, &len, &inc);
-  ret = scm_array_handle_ref (&h, idx*inc);
-  scm_array_handle_release (&h);
-  return ret;
+  if (!scm_is_uniform_vector (v))
+    scm_wrong_type_arg_msg (NULL, 0, v, "uniform vector");
+  return scm_c_generalized_vector_ref (v, idx);
 }
 
 SCM_DEFINE (scm_uniform_vector_ref, "uniform-vector-ref", 2, 0, 0,
@@ -168,13 +174,9 @@ SCM_DEFINE (scm_uniform_vector_ref, "uniform-vector-ref", 
2, 0, 0,
 void
 scm_c_uniform_vector_set_x (SCM v, size_t idx, SCM val)
 {
-  scm_t_array_handle h;
-  size_t len;
-  ssize_t inc;
-  
-  scm_uniform_vector_elements (v, &h, &len, &inc);
-  scm_array_handle_set (&h, idx*inc, val);
-  scm_array_handle_release (&h);
+  if (!scm_is_uniform_vector (v))
+    scm_wrong_type_arg_msg (NULL, 0, v, "uniform vector");
+  scm_c_generalized_vector_set_x (v, idx, val);
 }
 
 SCM_DEFINE (scm_uniform_vector_set_x, "uniform-vector-set!", 3, 0, 0,
@@ -193,15 +195,9 @@ SCM_DEFINE (scm_uniform_vector_to_list, 
"uniform-vector->list", 1, 0, 0,
            "Convert the uniform numeric vector @var{uvec} to a list.")
 #define FUNC_NAME s_scm_uniform_vector_to_list
 {
-  SCM ret;
-  scm_t_array_handle h;
-  size_t len;
-  ssize_t inc;
-  
-  scm_uniform_vector_elements (uvec, &h, &len, &inc);
-  ret = scm_generalized_vector_to_list (uvec);
-  scm_array_handle_release (&h);
-  return ret;
+  if (!scm_is_uniform_vector (uvec))
+    scm_wrong_type_arg_msg (FUNC_NAME, SCM_ARG1, uvec, "uniform vector");
+  return scm_generalized_vector_to_list (uvec);
 }
 #undef FUNC_NAME
 
diff --git a/libguile/uniform.h b/libguile/uniform.h
index b1f3965..f0d5915 100644
--- a/libguile/uniform.h
+++ b/libguile/uniform.h
@@ -36,8 +36,10 @@ SCM_INTERNAL const size_t scm_i_array_element_type_sizes[];
 #define SCM_ARRAY_ELEMENT_TYPE_IS_UNBOXED(t)    \
   (scm_i_array_element_type_sizes[(t)] != 0)
 
-/* returns type size in bits */
+/* type size in bytes */
 SCM_API size_t scm_array_handle_uniform_element_size (scm_t_array_handle *h);
+/* type size in bits */
+SCM_API size_t scm_array_handle_uniform_element_bit_size (scm_t_array_handle 
*h);
 
 SCM_API const void *scm_array_handle_uniform_elements (scm_t_array_handle *h);
 SCM_API void *scm_array_handle_uniform_writable_elements (scm_t_array_handle 
*h);


hooks/post-receive
-- 
GNU Guile




reply via email to

[Prev in Thread] Current Thread [Next in Thread]