diff options
-rw-r--r-- | NEWS | 10 | ||||
-rw-r--r-- | RELEASE | 1 | ||||
-rw-r--r-- | libguile/ChangeLog | 20 | ||||
-rw-r--r-- | libguile/eval.c | 2 | ||||
-rw-r--r-- | libguile/gc.c | 47 | ||||
-rw-r--r-- | libguile/gc.h | 5 | ||||
-rw-r--r-- | libguile/gh_data.c | 10 | ||||
-rw-r--r-- | libguile/print.c | 2 |
8 files changed, 84 insertions, 13 deletions
@@ -276,6 +276,16 @@ behaviour is undefined - it may even crash or loop endlessly. Further, for the case that the object is not found in the list, scm_c_memq returns #f which is similar to scm_memq, but different from scm_sloppy_memq's behaviour. +** New functions: scm_remember_upto_here_1, scm_remember_upto_here_2, +scm_remember_upto_here + +These functions replace the function scm_remember. + +** Deprecated function: scm_remember + +Use one of the new functions scm_remember_upto_here_1, +scm_remember_upto_here_2 or scm_remember_upto_here instead. + ** New global variable scm_gc_running_p introduced. Use this variable to find out if garbage collection is being executed. Up to @@ -41,6 +41,7 @@ In release 1.6: eval.c: scm_eval2, scm_eval_3 load.c: scm_read_and_eval_x smob.c: scm_make_smob_type_mfpe, scm_set_smob_mfpe + gc.c: scm_remember - remove deprecated procedures: boot-9.scm:eval-in-module - remove deprecated macros: SCM_OUTOFRANGE, SCM_NALLOC, SCM_HUP_SIGNAL, diff --git a/libguile/ChangeLog b/libguile/ChangeLog index 1c940a079..5961def8e 100644 --- a/libguile/ChangeLog +++ b/libguile/ChangeLog @@ -1,5 +1,17 @@ 2000-12-28 Dirk Herrmann <D.Herrmann@tu-bs.de> + * eval.c (check_map_args), gh_data.c (gh_set_substr, + gh_scm2newstr, gh_get_substr, gh_symbol2newstr), print.c + (scm_iprin1): Use scm_remember_upto_here_1 instead of + scm_remember. + + * gc.[ch] (scm_remember_upto_here_1, scm_remember_upto_here_2, + scm_remember_upto_here): New functions. + + (scm_remember): Deprecated. + +2000-12-28 Dirk Herrmann <D.Herrmann@tu-bs.de> + * continuations.c (scm_make_continuation): Make variable cont volatile to let the compiler know that it won't be clobbered by longjmp. (It wouldn't be anyway, but for some reason the compiler @@ -7,15 +19,15 @@ 2000-12-28 Dirk Herrmann <D.Herrmann@tu-bs.de> - This patch re-introduces the unused member "documentation" of + This patch re-introduces the unused member "properties" of struct scm_subr_entry as requested by Mikael Djurfeldt. - * procs.h (scm_subr_entry): Re-introduced member "documentation". + * procs.h (scm_subr_entry): Re-introduced member "properties". - (SCM_SUBR_DOC): Un-deprecated. + (SCM_SUBR_PROPS): Un-deprecated. * procs.c (scm_make_subr_opt, scm_mark_subr_table): Struct - scm_subr_entry has a member "documentation" again. + scm_subr_entry has a member "properties" again. 2000-12-28 Michael Livshin <mlivshin@bigfoot.com> diff --git a/libguile/eval.c b/libguile/eval.c index 57943e6c4..b7cf5be11 100644 --- a/libguile/eval.c +++ b/libguile/eval.c @@ -3550,7 +3550,7 @@ check_map_args (SCM argv, scm_out_of_range (who, ve[i]); } - scm_remember (&argv); + scm_remember_upto_here_1 (argv); } diff --git a/libguile/gc.c b/libguile/gc.c index b1095d135..d6767651d 100644 --- a/libguile/gc.c +++ b/libguile/gc.c @@ -2316,12 +2316,59 @@ SCM_DEFINE (scm_unhash_name, "unhash-name", 1, 0, 0, */ +/* + * If within a function you need to protect one or more scheme objects from + * garbage collection, pass them as parameters to one of the + * scm_remember_upto_here* functions below. These functions don't do + * anything, but since the compiler does not know that they are actually + * no-ops, it will generate code that calls these functions with the given + * parameters. Therefore, you can be sure that the compiler will keep those + * scheme values alive (on the stack or in a register) up to the point where + * scm_remember_upto_here* is called. In other words, place the call to + * scm_remember_upt_here* _behind_ the last code in your function, that + * depends on the scheme object to exist. + * + * Example: We want to make sure, that the string object str does not get + * garbage collected during the execution of 'some_function', because + * otherwise the characters belonging to str would be freed and + * 'some_function' might access freed memory. To make sure that the compiler + * keeps str alive on the stack or in a register such that it is visible to + * the conservative gc we add the call to scm_remember_upto_here_1 _after_ the + * call to 'some_function'. Note that this would not be necessary if str was + * used anyway after the call to 'some_function'. + * char *chars = SCM_STRING_CHARS (str); + * some_function (chars); + * scm_remember_upto_here_1 (str); // str will be alive up to this point. + */ + +void +scm_remember_upto_here_1 (SCM obj) +{ + /* Empty. Protects a single object from garbage collection. */ +} + +void +scm_remember_upto_here_2 (SCM obj1, SCM obj2) +{ + /* Empty. Protects two objects from garbage collection. */ +} + +void +scm_remember_upto_here (SCM obj, ...) +{ + /* Empty. Protects any number of objects from garbage collection. */ +} + + +#if (SCM_DEBUG_DEPRECATED == 0) + void scm_remember (SCM *ptr) { /* empty */ } +#endif /* SCM_DEBUG_DEPRECATED == 0 */ /* These crazy functions prevent garbage collection diff --git a/libguile/gc.h b/libguile/gc.h index c0c8ce70b..893c262e7 100644 --- a/libguile/gc.h +++ b/libguile/gc.h @@ -349,7 +349,9 @@ extern void * scm_must_realloc (void *where, extern void scm_done_malloc (long size); extern void scm_done_free (long size); extern void scm_must_free (void *obj); -extern void scm_remember (SCM * ptr); +extern void scm_remember_upto_here_1 (SCM obj); +extern void scm_remember_upto_here_2 (SCM obj1, SCM obj2); +extern void scm_remember_upto_here (SCM obj1, ...); extern SCM scm_return_first (SCM elt, ...); extern int scm_return_first_int (int x, ...); extern SCM scm_permanent_object (SCM obj); @@ -370,6 +372,7 @@ extern void scm_init_gc (void); #define SCM_CLRGC8MARK(x) SCM_CLRGCMARK (x) #define SCM_GCTYP16(x) SCM_TYP16 (x) #define SCM_GCCDR(x) SCM_CDR (x) +extern void scm_remember (SCM * ptr); #endif /* SCM_DEBUG_DEPRECATED == 0 */ diff --git a/libguile/gh_data.c b/libguile/gh_data.c index f7e74e5af..33c615251 100644 --- a/libguile/gh_data.c +++ b/libguile/gh_data.c @@ -122,7 +122,7 @@ gh_set_substr (char *src, SCM dst, int start, int len) effective_length = ((unsigned) len < dst_len) ? len : dst_len; memmove (dst_ptr + start, src, effective_length); - scm_remember (&dst); + scm_remember_upto_here_1 (dst); } /* Return the symbol named SYMBOL_STR. */ @@ -543,8 +543,7 @@ gh_scm2newstr (SCM str, int *lenp) "gh_scm2newstr"); /* so we copy tmp_str to ret_str, which is what we will allocate */ memcpy (ret_str, SCM_STRING_CHARS (str), len); - /* from now on we don't mind if str gets GC collected. */ - scm_remember (&str); + scm_remember_upto_here_1 (str); /* now make sure we null-terminate it */ ret_str[len] = '\0'; @@ -575,7 +574,7 @@ gh_get_substr (SCM src, char *dst, int start, int len) effective_length = (len < src_len) ? len : src_len; memcpy (dst + start, SCM_STRING_CHARS (src), effective_length * sizeof (char)); /* FIXME: must signal an error if len > src_len */ - scm_remember (&src); + scm_remember_upto_here_1 (src); } @@ -600,8 +599,7 @@ gh_symbol2newstr (SCM sym, int *lenp) "gh_symbol2newstr"); /* so we copy sym to ret_str, which is what we will allocate */ memcpy (ret_str, SCM_SYMBOL_CHARS (sym), len); - /* from now on we don't mind if sym gets GC collected. */ - scm_remember (&sym); + scm_remember_upto_here_1 (sym); /* now make sure we null-terminate it */ ret_str[len] = '\0'; diff --git a/libguile/print.c b/libguile/print.c index a07d61fe6..0dc7b82ff 100644 --- a/libguile/print.c +++ b/libguile/print.c @@ -578,7 +578,7 @@ taloop: } if (pos < end) scm_lfwrite (str + pos, end - pos, port); - scm_remember (&exp); + scm_remember_upto_here_1 (exp); if (weird) scm_lfwrite ("}#", 2, port); break; |