Allocate complex numbers in contiguous pointer-less memory.
authorLudovic Courtès <ludo@gnu.org>
Tue, 12 Oct 2010 20:57:08 +0000 (22:57 +0200)
committerLudovic Courtès <ludo@gnu.org>
Tue, 12 Oct 2010 22:06:30 +0000 (00:06 +0200)
* libguile/numbers.h (SCM_COMPLEX_MEM): Remove.
  (SCM_COMPLEX_REAL): Change to just fetch the `real' field of the
  pointed-to `scm_t_complex'.
  (SCM_COMPLEX_IMAG): Likewise.
  (scm_t_complex)[type, pad]: New fields.

* libguile/numbers.c (scm_c_make_rectangular): Allocate the whole
  complex contiguously, with `scm_gc_malloc_pointerless'.

libguile/numbers.c
libguile/numbers.h

index 7de9951..fbc6cc8 100644 (file)
@@ -5723,9 +5723,10 @@ scm_c_make_rectangular (double re, double im)
   else
     {
       SCM z;
-      SCM_NEWSMOB (z, scm_tc16_complex,
-                  scm_gc_malloc_pointerless (sizeof (scm_t_complex),
+
+      z = PTR2SCM (scm_gc_malloc_pointerless (sizeof (scm_t_complex),
                                              "complex"));
+      SCM_SET_CELL_TYPE (z, scm_tc16_complex);
       SCM_COMPLEX_REAL (z) = re;
       SCM_COMPLEX_IMAG (z) = im;
       return z;
index a69f5af..a3701a6 100644 (file)
@@ -128,9 +128,8 @@ typedef scm_t_int32 scm_t_wchar;
 #define SCM_COMPLEXP(x) (!SCM_IMP (x) && SCM_TYP16 (x) == scm_tc16_complex)
 
 #define SCM_REAL_VALUE(x) (((scm_t_double *) SCM2PTR (x))->real)
-#define SCM_COMPLEX_MEM(x) ((scm_t_complex *) SCM_CELL_WORD_1 (x))
-#define SCM_COMPLEX_REAL(x) (SCM_COMPLEX_MEM (x)->real)
-#define SCM_COMPLEX_IMAG(x) (SCM_COMPLEX_MEM (x)->imag)
+#define SCM_COMPLEX_REAL(x) (((scm_t_complex *) SCM2PTR (x))->real)
+#define SCM_COMPLEX_IMAG(x) (((scm_t_complex *) SCM2PTR (x))->imag)
 
 /* Each bignum is just an mpz_t stored in a double cell starting at word 1. */
 #define SCM_I_BIG_MPZ(x) (*((mpz_t *) (SCM_CELL_OBJECT_LOC((x),1))))
@@ -157,6 +156,8 @@ typedef struct scm_t_double
 
 typedef struct scm_t_complex
 {
+  SCM type;
+  SCM pad;
   double real;
   double imag;
 } scm_t_complex;