1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 11:40:18 +02:00

Allocate complex numbers in contiguous pointer-less memory.

* 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'.
This commit is contained in:
Ludovic Courtès 2010-10-12 22:57:08 +02:00
parent 978c52d108
commit 03604fcf50
2 changed files with 7 additions and 5 deletions

View 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;

View 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;