This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
eliminating SCM_POINTERS_MUNGED
- To: Mikael Djurfeldt <mdj at mdj dot nada dot kth dot se>
- Subject: eliminating SCM_POINTERS_MUNGED
- From: Dirk Herrmann <dirk at ida dot ing dot tu-bs dot de>
- Date: Fri, 24 Mar 2000 17:19:36 +0100 (MET)
- cc: Guile Mailing List <guile at sourceware dot cygnus dot com>
Hi!
I have removed a little bit of sick code from gc.c. The point is, that
whenever SCM2PTR and PTR2SCM are nontrivial, SCM_POINTERS_MUNGED is
defined. However, SCM_POINTERS_MUNGED is used in a way that basically
duplicates the definition of PTR2SCM.
I will explain the patch using the following example. I added the
comments after ////
scm_gc_sweep ()
{
register SCM_CELLPTR ptr;
#ifdef SCM_POINTERS_MUNGED //// i. e. PTR2SCM non trivial
register SCM scmptr;
#else //// else PTR2SCM trivial anyway
#undef scmptr
#define scmptr (SCM)ptr //// but still duplicated (sick)
#endif
register SCM nfreelist;
register scm_freelist_t *freelist;
register long m;
...
seg_size = CELL_DN (scm_heap_table[i].bounds[1], span) - ptr;
for (j = seg_size + span; j -= span; ptr += span)
{
#ifdef SCM_POINTERS_MUNGED //// PTR2SCM non trivial
scmptr = PTR2SCM (ptr);
#endif
switch SCM_TYP7 (scmptr) //// ****
{
case scm_tcs_cons_gloc:
at places that use scmptr, like ***, we use either (SCM)ptr if
SCM_POINTERS_MUNGED is not defined. However, in that case PTR2SCM would
have been defined to do exactly the same thing: just cast to (SCM)
The same 'trick' is used a second time in gc.c.
Thus, the patch below should be safe. If you don't object I will apply it and
then also remove SCM_POINTERS_MUNGED from tags.h
Best regards
Dirk Herrmann
Index: gc.c
===================================================================
RCS file: /cvs/guile/guile/guile-core/libguile/gc.c,v
retrieving revision 1.112
diff -u -r1.112 gc.c
--- gc.c 2000/03/23 13:04:27 1.112
+++ gc.c 2000/03/24 16:17:19
@@ -1587,12 +1587,6 @@
scm_gc_sweep ()
{
register SCM_CELLPTR ptr;
-#ifdef SCM_POINTERS_MUNGED
- register SCM scmptr;
-#else
-#undef scmptr
-#define scmptr (SCM)ptr
-#endif
register SCM nfreelist;
register scm_freelist_t *freelist;
register long m;
@@ -1638,9 +1632,8 @@
seg_size = CELL_DN (scm_heap_table[i].bounds[1], span) - ptr;
for (j = seg_size + span; j -= span; ptr += span)
{
-#ifdef SCM_POINTERS_MUNGED
- scmptr = PTR2SCM (ptr);
-#endif
+ SCM scmptr = PTR2SCM (ptr);
+
switch SCM_TYP7 (scmptr)
{
case scm_tcs_cons_gloc:
@@ -2161,12 +2154,6 @@
init_heap_seg (SCM_CELLPTR seg_org, scm_sizet size, scm_freelist_t *freelist)
{
register SCM_CELLPTR ptr;
-#ifdef SCM_POINTERS_MUNGED
- register SCM scmptr;
-#else
-#undef scmptr
-#define scmptr ptr
-#endif
SCM_CELLPTR seg_end;
int new_seg_index;
int n_new_cells;
@@ -2246,9 +2233,8 @@
while (ptr < seg_end)
{
-#ifdef SCM_POINTERS_MUNGED
- scmptr = PTR2SCM (ptr);
-#endif
+ SCM scmptr = PTR2SCM (ptr);
+
SCM_SETCAR (scmptr, scm_tc_free_cell);
SCM_SETCDR (scmptr, PTR2SCM (ptr + span));
ptr += span;
@@ -2270,9 +2256,8 @@
*/
while (ptr < seg_end)
{
-#ifdef SCM_POINTERS_MUNGED
- scmptr = PTR2SCM (ptr);
-#endif
+ SCM scmptr = PTR2SCM (ptr);
+
SCM_SETCAR (scmptr, (SCM) scm_tc_free_cell);
SCM_SETCDR (scmptr, PTR2SCM (ptr + span));
ptr += span;
@@ -2294,9 +2279,6 @@
fprintf (stderr, "H");
#endif
return size;
-#ifdef scmptr
-#undef scmptr
-#endif
}
#ifndef GUILE_NEW_GC_SCHEME