From 46d53380a2266a4a407d72b77d68b9663bfa5f37 Mon Sep 17 00:00:00 2001 From: Dirk Herrmann Date: Fri, 19 May 2000 15:46:32 +0000 Subject: [PATCH] * Added SCM_DEBUG_CELL_ACCESSES debug option. --- libguile/ChangeLog | 13 +++++++++++++ libguile/__scm.h | 9 +++++++++ libguile/gc.h | 19 +++++++++++++++---- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/libguile/ChangeLog b/libguile/ChangeLog index c1686f626..1be7bb80d 100644 --- a/libguile/ChangeLog +++ b/libguile/ChangeLog @@ -1,3 +1,16 @@ +2000-05-19 Dirk Herrmann + + * __scm.h (SCM_DEBUG_CELL_ACCESSES), gc.h (SCM_): Added as a new + debug option to verify all accesses to cells actually access + objects on the heap. + + * gc.h (SCM_VALIDATE_CELL): Added. Only performs validation if + SCM_DEBUG_CELL_ACCESSES is set to 1. + + (SCM_CELL_WORD, SCM_CELL_OBJECT, SCM_SET_CELL_WORD, + SCM_SET_CELL_OBJECT): Use SCM_VALIDATE_CELL to check every cell + that is accessed. + 2000-05-19 Dirk Herrmann * gh_data.c (gh_scm2chars, gh_scm2shorts, gh_scm2longs, diff --git a/libguile/__scm.h b/libguile/__scm.h index fc0f5ab89..455257f51 100644 --- a/libguile/__scm.h +++ b/libguile/__scm.h @@ -160,6 +160,15 @@ #define SCM_DEBUG 0 #endif +/* If SCM_DEBUG_CELL_ACCESSES is set to 1, cell accesses will perform + * exhaustive parameter checking: It will be verified that cell parameters + * actually point to a valid heap cell. Note: If this option is enabled, + * guile will run about ten times slower than normally. + */ +#ifndef SCM_DEBUG_CELL_ACCESSES +#define SCM_DEBUG_CELL_ACCESSES SCM_DEBUG +#endif + /* If SCM_DEBUG_DEPRECATED is set to 1, deprecated code is not compiled. This * can be used by developers to get rid of references to deprecated code. */ diff --git a/libguile/gc.h b/libguile/gc.h index ee5c54157..cb41d484d 100644 --- a/libguile/gc.h +++ b/libguile/gc.h @@ -85,25 +85,36 @@ typedef scm_cell * SCM_CELLPTR; /* Low level cell data accessing macros: */ -#define SCM_CELL_WORD(x, n) (((scm_bits_t *) SCM2PTR (x)) [n]) +#define SCM_VALIDATE_CELL(x) \ + (SCM_DEBUG_CELL_ACCESSES ? (!scm_cellp (x) ? abort () : 1) : 1) + +#define SCM_CELL_WORD(x, n) \ + ((SCM_VALIDATE_CELL (x)), \ + (((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_PACK (((scm_bits_t *) SCM2PTR (x)) [n])) +#define SCM_CELL_OBJECT(x, n) \ + ((SCM_VALIDATE_CELL (x)), \ + (SCM_PACK (((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_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_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)