From f706a58b671131718a85cf7ccd6f40edb52a0cc9 Mon Sep 17 00:00:00 2001 From: Dirk Herrmann Date: Mon, 10 Jul 2000 13:54:03 +0000 Subject: [PATCH] * Make the compiler warn about code like SCM_CELL_WORD (x, n) = y. --- libguile/ChangeLog | 11 +++++++++++ libguile/gc.h | 26 +++++++++++--------------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/libguile/ChangeLog b/libguile/ChangeLog index 9de06a427..c26394e76 100644 --- a/libguile/ChangeLog +++ b/libguile/ChangeLog @@ -1,3 +1,14 @@ +2000-07-10 Dirk Herrmann + + * gc.h (SCM_CELL_WORD, SCM_CELL_OBJECT): Treat the referenced + object as const in order to make the compiler warn about code like + SCM_CELL_WORD (x, n) = y. Instead, SCM_SET_CELL_WORD (x, n, y) + should be used. + + (SCM_CELL_WORD_LOC, SCM_CARLOC, SCM_CDRLOC): Return the address + as an address to a non-const object, since these macros are used + to allow direct write access to objects. + 2000-07-07 Dirk Herrmann * hashtab.c (scm_hash_fn_create_handle_x): Signal an error if the diff --git a/libguile/gc.h b/libguile/gc.h index 431e3ad44..a90d47614 100644 --- a/libguile/gc.h +++ b/libguile/gc.h @@ -92,33 +92,29 @@ typedef scm_cell * SCM_CELLPTR; #define SCM_VALIDATE_CELL(cell, expr) expr #endif -#define SCM_CELL_WORD(x, n) \ - SCM_VALIDATE_CELL ((x), \ - ((scm_bits_t *) SCM2PTR (x)) [n]) +#define SCM_CELL_WORD(x, n) \ + SCM_VALIDATE_CELL ((x), ((const scm_bits_t *) SCM2PTR (x)) [n]) #define SCM_CELL_WORD_0(x) SCM_CELL_WORD (x, 0) #define SCM_CELL_WORD_1(x) SCM_CELL_WORD (x, 1) #define SCM_CELL_WORD_2(x) SCM_CELL_WORD (x, 2) #define SCM_CELL_WORD_3(x) SCM_CELL_WORD (x, 3) -#define SCM_CELL_OBJECT(x, n) \ - SCM_VALIDATE_CELL ((x), \ - SCM_PACK (((scm_bits_t *) SCM2PTR (x)) [n])) +#define SCM_CELL_OBJECT(x, n) \ + SCM_VALIDATE_CELL ((x), SCM_PACK (((const scm_bits_t *) SCM2PTR (x)) [n])) #define SCM_CELL_OBJECT_0(x) SCM_CELL_OBJECT (x, 0) #define SCM_CELL_OBJECT_1(x) SCM_CELL_OBJECT (x, 1) #define SCM_CELL_OBJECT_2(x) SCM_CELL_OBJECT (x, 2) #define SCM_CELL_OBJECT_3(x) SCM_CELL_OBJECT (x, 3) -#define SCM_SET_CELL_WORD(x, n, v) \ - SCM_VALIDATE_CELL ((x), \ - ((scm_bits_t *) SCM2PTR (x)) [n] = (scm_bits_t) (v)) +#define SCM_SET_CELL_WORD(x, n, v) \ + SCM_VALIDATE_CELL ((x), ((scm_bits_t *) SCM2PTR (x)) [n] = (scm_bits_t) (v)) #define SCM_SET_CELL_WORD_0(x, v) SCM_SET_CELL_WORD (x, 0, v) #define SCM_SET_CELL_WORD_1(x, v) SCM_SET_CELL_WORD (x, 1, v) #define SCM_SET_CELL_WORD_2(x, v) SCM_SET_CELL_WORD (x, 2, v) #define SCM_SET_CELL_WORD_3(x, v) SCM_SET_CELL_WORD (x, 3, v) -#define SCM_SET_CELL_OBJECT(x, n, v) \ - SCM_VALIDATE_CELL ((x), \ - ((scm_bits_t *) SCM2PTR (x)) [n] = SCM_UNPACK (v)) +#define SCM_SET_CELL_OBJECT(x, n, v) \ + SCM_VALIDATE_CELL ((x), ((scm_bits_t *) SCM2PTR (x)) [n] = SCM_UNPACK (v)) #define SCM_SET_CELL_OBJECT_0(x, v) SCM_SET_CELL_OBJECT (x, 0, v) #define SCM_SET_CELL_OBJECT_1(x, v) SCM_SET_CELL_OBJECT (x, 1, v) #define SCM_SET_CELL_OBJECT_2(x, v) SCM_SET_CELL_OBJECT (x, 2, v) @@ -136,9 +132,9 @@ typedef scm_cell * SCM_CELLPTR; #define SCM_SETOR_CDR(x, y)\ (SCM_SETCDR ((x), SCM_PACK (SCM_UNPACK (SCM_CDR (x)) | (y)))) -#define SCM_CELL_WORD_LOC(x, n) (&SCM_CELL_WORD (x, n)) -#define SCM_CARLOC(x) ((SCM *) (&(((scm_bits_t *) SCM2PTR (x)) [0]))) -#define SCM_CDRLOC(x) ((SCM *) (&(((scm_bits_t *) SCM2PTR (x)) [1]))) +#define SCM_CELL_WORD_LOC(x, n) ((scm_bits_t *) & SCM_CELL_WORD (x, n)) +#define SCM_CARLOC(x) ((SCM *) SCM_CELL_WORD_LOC ((x), 0)) +#define SCM_CDRLOC(x) ((SCM *) SCM_CELL_WORD_LOC ((x), 1)) /* SCM_PTR_LT and friends define how to compare two SCM_CELLPTRs (which may