1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 03:40:34 +02:00

decruftify scm_sys_protects

* libguile/root.h
* libguile/root.c (scm_sys_protects): It used to be that for some reason
  we'd define a special array of "protected" values. This was a little
  silly, always, but with the BDW GC it's completely unnecessary. Also
  many of these variables were unused, and none of them were good API.
  So remove this array, and either eliminate, make static, or make
  internal the various values.

* libguile/snarf.h: No need to generate calls to scm_permanent_object.

* guile-readline/readline.c (scm_init_readline): No need to call
  scm_permanent_object.

* libguile/array-map.c (ramap, rafe): Remove the dubious nullvect
  optimizations.

* libguile/async.c (scm_init_async): No need to init scm_asyncs, it is
  no more.

* libguile/eval.c (scm_init_eval): No need to init scm_listofnull, it is
  no more.

* libguile/gc.c: Make scm_protects a static var.
  (scm_storage_prehistory): Change the sanity check to use the address
  of protects.
  (scm_init_gc_protect_object): No need to clear the scm_sys_protects,
  as it is no more.

* libguile/keywords.c: Make the keyword obarray a static var.
* libguile/numbers.c: Make flo0 a static var.
* libguile/objprop.c: Make object_whash a static var.
* libguile/properties.c: Make properties_whash a static var.

* libguile/srcprop.h:
* libguile/srcprop.c: Make scm_source_whash a global with internal
  linkage.

* libguile/strings.h:
* libguile/strings.c: Make scm_nullstr a global with internal linkage.

* libguile/vectors.c (scm_init_vectors): No need to init scm_nullvect,
  it's unused.
This commit is contained in:
Andy Wingo 2009-12-05 12:38:32 +01:00
parent 838aa00070
commit e7efe8e793
17 changed files with 57 additions and 78 deletions

View file

@ -557,7 +557,7 @@ scm_init_readline ()
rl_basic_word_break_characters = "\t\n\"'`;()";
rl_readline_name = "Guile";
reentry_barrier_mutex = scm_permanent_object (scm_make_mutex ());
reentry_barrier_mutex = scm_make_mutex ();
scm_init_opts (scm_readline_options,
scm_readline_opts);
#if HAVE_RL_GET_KEYMAP

View file

@ -645,11 +645,7 @@ ramap (SCM ra0, SCM proc, SCM ras)
unsigned long k, i1 = SCM_I_ARRAY_BASE (ra1);
long inc1 = SCM_I_ARRAY_DIMS (ra1)->inc;
ra1 = SCM_I_ARRAY_V (ra1);
ras = SCM_CDR (ras);
if (scm_is_null(ras))
ras = scm_nullvect;
else
ras = scm_vector (ras);
ras = scm_vector (SCM_CDR (ras));
for (; i <= n; i++, i1 += inc1)
{
@ -706,11 +702,8 @@ rafe (SCM ra0, SCM proc, SCM ras)
unsigned long k, i1 = SCM_I_ARRAY_BASE (ra1);
long inc1 = SCM_I_ARRAY_DIMS (ra1)->inc;
ra1 = SCM_I_ARRAY_V (ra1);
ras = SCM_CDR (ras);
if (scm_is_null(ras))
ras = scm_nullvect;
else
ras = scm_vector (ras);
ras = scm_vector (SCM_CDR (ras));
for (; i <= n; i++, i0 += inc0, i1 += inc1)
{
args = SCM_EOL;

View file

@ -501,7 +501,6 @@ scm_async_tick (void)
void
scm_init_async ()
{
scm_asyncs = SCM_EOL;
tc16_async = scm_make_smob_type ("async", 0);
#include "libguile/async.x"

View file

@ -923,8 +923,6 @@ scm_init_eval ()
scm_init_opts (scm_eval_options_interface,
scm_eval_opts);
scm_listofnull = scm_list_1 (SCM_EOL);
f_apply = scm_c_define_gsubr ("apply", 2, 0, 1, scm_apply);
scm_tc16_boot_closure = scm_make_smob_type ("boot-closure", 0);

View file

@ -90,6 +90,9 @@ int scm_debug_cells_gc_interval = 0;
*/
int scm_i_cell_validation_already_running ;
static SCM protects;
#if (SCM_DEBUG_CELL_ACCESSES == 1)
@ -505,7 +508,7 @@ scm_gc_protect_object (SCM obj)
critsec/mutex inconsistency here. */
SCM_CRITICAL_SECTION_START;
handle = scm_hashq_create_handle_x (scm_protects, obj, scm_from_int (0));
handle = scm_hashq_create_handle_x (protects, obj, scm_from_int (0));
SCM_SETCDR (handle, scm_sum (SCM_CDR (handle), scm_from_int (1)));
protected_obj_count ++;
@ -535,7 +538,7 @@ scm_gc_unprotect_object (SCM obj)
abort ();
}
handle = scm_hashq_get_handle (scm_protects, obj);
handle = scm_hashq_get_handle (protects, obj);
if (scm_is_false (handle))
{
@ -546,7 +549,7 @@ scm_gc_unprotect_object (SCM obj)
{
SCM count = scm_difference (SCM_CDR (handle), scm_from_int (1));
if (scm_is_eq (count, scm_from_int (0)))
scm_hashq_remove_x (scm_protects, obj);
scm_hashq_remove_x (protects, obj);
else
SCM_SETCDR (handle, count);
}
@ -634,7 +637,7 @@ scm_storage_prehistory ()
/* GC_REGISTER_DISPLACEMENT (scm_tc3_unused); */
/* Sanity check. */
if (!GC_is_visible (scm_sys_protects))
if (!GC_is_visible (&protects))
abort ();
scm_c_hook_init (&scm_before_gc_c_hook, 0, SCM_C_HOOK_NORMAL);
@ -649,11 +652,7 @@ scm_i_pthread_mutex_t scm_i_gc_admin_mutex = SCM_I_PTHREAD_MUTEX_INITIALIZER;
void
scm_init_gc_protect_object ()
{
size_t j;
j = SCM_NUM_PROTECTS;
while (j)
scm_sys_protects[--j] = SCM_BOOL_F;
protects = scm_c_make_hash_table (31);
#if 0
/* We can't have a cleanup handler since we have no thread to run it
@ -668,8 +667,6 @@ scm_init_gc_protect_object ()
#endif
#endif
scm_protects = scm_c_make_hash_table (31);
}

View file

@ -1,4 +1,4 @@
/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2003, 2004, 2006, 2008 Free Software Foundation, Inc.
/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2003, 2004, 2006, 2008, 2009 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
@ -37,6 +37,8 @@
static SCM keyword_obarray;
scm_t_bits scm_tc16_keyword;
#define KEYWORDP(X) (SCM_SMOB_PREDICATE (scm_tc16_keyword, (X)))
@ -71,11 +73,11 @@ SCM_DEFINE (scm_symbol_to_keyword, "symbol->keyword", 1, 0, 0,
SCM_CRITICAL_SECTION_START;
/* njrev: NEWSMOB and hashq_set_x can raise errors */
keyword = scm_hashq_ref (scm_keyword_obarray, symbol, SCM_BOOL_F);
keyword = scm_hashq_ref (keyword_obarray, symbol, SCM_BOOL_F);
if (scm_is_false (keyword))
{
SCM_NEWSMOB (keyword, scm_tc16_keyword, SCM_UNPACK (symbol));
scm_hashq_set_x (scm_keyword_obarray, symbol, keyword);
scm_hashq_set_x (keyword_obarray, symbol, keyword);
}
SCM_CRITICAL_SECTION_END;
return keyword;
@ -117,7 +119,7 @@ scm_init_keywords ()
scm_tc16_keyword = scm_make_smob_type ("keyword", 0);
scm_set_smob_print (scm_tc16_keyword, keyword_print);
scm_keyword_obarray = scm_c_make_hash_table (0);
keyword_obarray = scm_c_make_hash_table (0);
#include "libguile/keywords.x"
}

View file

@ -98,6 +98,8 @@
/* the macro above will not work as is with fractions */
static SCM flo0;
#define SCM_SWAP(x, y) do { SCM __t = x; x = y; y = __t; } while (0)
/* FLOBUFLEN is the maximum number of characters neccessary for the
@ -5828,7 +5830,7 @@ scm_imag_part (SCM z)
else if (SCM_BIGP (z))
return SCM_INUM0;
else if (SCM_REALP (z))
return scm_flo0;
return flo0;
else if (SCM_COMPLEXP (z))
return scm_from_double (SCM_COMPLEX_IMAG (z));
else if (SCM_FRACTIONP (z))
@ -5923,13 +5925,13 @@ SCM
scm_angle (SCM z)
{
/* atan(0,-1) is pi and it'd be possible to have that as a constant like
scm_flo0 to save allocating a new flonum with scm_from_double each time.
flo0 to save allocating a new flonum with scm_from_double each time.
But if atan2 follows the floating point rounding mode, then the value
is not a constant. Maybe it'd be close enough though. */
if (SCM_I_INUMP (z))
{
if (SCM_I_INUM (z) >= 0)
return scm_flo0;
return flo0;
else
return scm_from_double (atan2 (0.0, -1.0));
}
@ -5940,12 +5942,12 @@ scm_angle (SCM z)
if (sgn < 0)
return scm_from_double (atan2 (0.0, -1.0));
else
return scm_flo0;
return flo0;
}
else if (SCM_REALP (z))
{
if (SCM_REAL_VALUE (z) >= 0)
return scm_flo0;
return flo0;
else
return scm_from_double (atan2 (0.0, -1.0));
}
@ -5954,7 +5956,7 @@ scm_angle (SCM z)
else if (SCM_FRACTIONP (z))
{
if (scm_is_false (scm_negative_p (SCM_FRACTION_NUMERATOR (z))))
return scm_flo0;
return flo0;
else return scm_from_double (atan2 (0.0, -1.0));
}
else
@ -6594,7 +6596,7 @@ scm_init_numbers ()
scm_add_feature ("complex");
scm_add_feature ("inexact");
scm_flo0 = scm_from_double (0.0);
flo0 = scm_from_double (0.0);
/* determine floating point precision */
for (i=2; i <= SCM_MAX_DBL_RADIX; ++i)

View file

@ -1,4 +1,4 @@
/* Copyright (C) 1995,1996, 2000, 2001, 2003, 2006, 2008 Free Software Foundation, Inc.
/* Copyright (C) 1995,1996, 2000, 2001, 2003, 2006, 2008, 2009 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
@ -35,12 +35,14 @@
/* {Object Properties}
*/
static SCM object_whash;
SCM_DEFINE (scm_object_properties, "object-properties", 1, 0, 0,
(SCM obj),
"Return @var{obj}'s property list.")
#define FUNC_NAME s_scm_object_properties
{
return scm_hashq_ref (scm_object_whash, obj, SCM_EOL);
return scm_hashq_ref (object_whash, obj, SCM_EOL);
}
#undef FUNC_NAME
@ -50,7 +52,7 @@ SCM_DEFINE (scm_set_object_properties_x, "set-object-properties!", 2, 0, 0,
"Set @var{obj}'s property list to @var{alist}.")
#define FUNC_NAME s_scm_set_object_properties_x
{
SCM handle = scm_hashq_create_handle_x (scm_object_whash, obj, alist);
SCM handle = scm_hashq_create_handle_x (object_whash, obj, alist);
SCM_SETCDR (handle, alist);
return alist;
}
@ -75,7 +77,7 @@ SCM_DEFINE (scm_set_object_property_x, "set-object-property!", 3, 0, 0,
{
SCM h;
SCM assoc;
h = scm_hashq_create_handle_x (scm_object_whash, obj, SCM_EOL);
h = scm_hashq_create_handle_x (object_whash, obj, SCM_EOL);
SCM_CRITICAL_SECTION_START;
assoc = scm_assq (key, SCM_CDR (h));
if (SCM_NIMP (assoc))
@ -94,7 +96,7 @@ SCM_DEFINE (scm_set_object_property_x, "set-object-property!", 3, 0, 0,
void
scm_init_objprop ()
{
scm_object_whash = scm_make_weak_key_hash_table (SCM_UNDEFINED);
object_whash = scm_make_weak_key_hash_table (SCM_UNDEFINED);
#include "libguile/objprop.x"
}

View file

@ -1,4 +1,4 @@
/* Copyright (C) 1995,1996,2000,2001, 2003, 2006, 2008 Free Software Foundation, Inc.
/* Copyright (C) 1995,1996,2000,2001, 2003, 2006, 2008, 2009 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
@ -36,6 +36,8 @@
/* {Properties}
*/
static SCM properties_whash;
SCM_DEFINE (scm_primitive_make_property, "primitive-make-property", 1, 0, 0,
(SCM not_found_proc),
"Create a @dfn{property token} that can be used with\n"
@ -67,7 +69,7 @@ SCM_DEFINE (scm_primitive_property_ref, "primitive-property-ref", 2, 0, 0,
SCM_VALIDATE_CONS (SCM_ARG1, prop);
h = scm_hashq_get_handle (scm_properties_whash, obj);
h = scm_hashq_get_handle (properties_whash, obj);
if (scm_is_true (h))
{
SCM assoc = scm_assq (prop, SCM_CDR (h));
@ -81,7 +83,7 @@ SCM_DEFINE (scm_primitive_property_ref, "primitive-property-ref", 2, 0, 0,
{
SCM val = scm_call_2 (SCM_CAR (prop), prop, obj);
if (scm_is_false (h))
h = scm_hashq_create_handle_x (scm_properties_whash, obj, SCM_EOL);
h = scm_hashq_create_handle_x (properties_whash, obj, SCM_EOL);
SCM_SETCDR (h, scm_acons (prop, val, SCM_CDR (h)));
return val;
}
@ -96,7 +98,7 @@ SCM_DEFINE (scm_primitive_property_set_x, "primitive-property-set!", 3, 0, 0,
{
SCM h, assoc;
SCM_VALIDATE_CONS (SCM_ARG1, prop);
h = scm_hashq_create_handle_x (scm_properties_whash, obj, SCM_EOL);
h = scm_hashq_create_handle_x (properties_whash, obj, SCM_EOL);
assoc = scm_assq (prop, SCM_CDR (h));
if (SCM_NIMP (assoc))
SCM_SETCDR (assoc, val);
@ -117,7 +119,7 @@ SCM_DEFINE (scm_primitive_property_del_x, "primitive-property-del!", 2, 0, 0,
{
SCM h;
SCM_VALIDATE_CONS (SCM_ARG1, prop);
h = scm_hashq_get_handle (scm_properties_whash, obj);
h = scm_hashq_get_handle (properties_whash, obj);
if (scm_is_true (h))
SCM_SETCDR (h, scm_assq_remove_x (SCM_CDR (h), prop));
return SCM_UNSPECIFIED;
@ -128,7 +130,7 @@ SCM_DEFINE (scm_primitive_property_del_x, "primitive-property-del!", 2, 0, 0,
void
scm_init_properties ()
{
scm_properties_whash = scm_make_weak_key_hash_table (SCM_UNDEFINED);
properties_whash = scm_make_weak_key_hash_table (SCM_UNDEFINED);
#include "libguile/properties.x"
}

View file

@ -1,4 +1,4 @@
/* Copyright (C) 1995,1996,1997,1998,1999,2000, 2001, 2002, 2006, 2008 Free Software Foundation, Inc.
/* Copyright (C) 1995,1996,1997,1998,1999,2000, 2001, 2002, 2006, 2008, 2009 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
@ -38,10 +38,6 @@
#include "libguile/root.h"
SCM scm_sys_protects[SCM_NUM_PROTECTS];
/* {call-with-dynamic-root}
*
* Suspending the current thread to evaluate a thunk on the

View file

@ -29,22 +29,6 @@
#define scm_flo0 scm_sys_protects[0]
#define scm_listofnull scm_sys_protects[1]
#define scm_nullvect scm_sys_protects[2]
#define scm_nullstr scm_sys_protects[3]
#define scm_keyword_obarray scm_sys_protects[4]
#define scm_object_whash scm_sys_protects[5]
#define scm_asyncs scm_sys_protects[6]
#define scm_protects scm_sys_protects[7]
#define scm_properties_whash scm_sys_protects[8]
#define scm_source_whash scm_sys_protects[9]
#define SCM_NUM_PROTECTS 10
SCM_API SCM scm_sys_protects[];
SCM_API SCM scm_internal_cwdr (scm_t_catch_body body,
void *body_data,
scm_t_catch_handler handler,

View file

@ -237,37 +237,37 @@ SCM_SNARF_INIT( \
# define SCM_SYMBOL(c_name, scheme_name) \
SCM_SNARF_HERE(static SCM c_name) \
SCM_SNARF_INIT(c_name = scm_permanent_object (scm_from_locale_symbol (scheme_name)))
SCM_SNARF_INIT(c_name = scm_from_locale_symbol (scheme_name))
# define SCM_GLOBAL_SYMBOL(c_name, scheme_name) \
SCM_SNARF_HERE(SCM c_name) \
SCM_SNARF_INIT(c_name = scm_permanent_object (scm_from_locale_symbol (scheme_name)))
SCM_SNARF_INIT(c_name = scm_from_locale_symbol (scheme_name))
#endif /* !SCM_SUPPORT_STATIC_ALLOCATION */
#define SCM_KEYWORD(c_name, scheme_name) \
SCM_SNARF_HERE(static SCM c_name) \
SCM_SNARF_INIT(c_name = scm_permanent_object (scm_from_locale_keyword (scheme_name)))
SCM_SNARF_INIT(c_name = scm_from_locale_keyword (scheme_name))
#define SCM_GLOBAL_KEYWORD(c_name, scheme_name) \
SCM_SNARF_HERE(SCM c_name) \
SCM_SNARF_INIT(c_name = scm_permanent_object (scm_from_locale_keyword (scheme_name)))
SCM_SNARF_INIT(c_name = scm_from_locale_keyword (scheme_name))
#define SCM_VARIABLE(c_name, scheme_name) \
SCM_SNARF_HERE(static SCM c_name) \
SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, SCM_BOOL_F));)
SCM_SNARF_INIT(c_name = scm_c_define (scheme_name, SCM_BOOL_F);)
#define SCM_GLOBAL_VARIABLE(c_name, scheme_name) \
SCM_SNARF_HERE(SCM c_name) \
SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, SCM_BOOL_F));)
SCM_SNARF_INIT(c_name = scm_c_define (scheme_name, SCM_BOOL_F);)
#define SCM_VARIABLE_INIT(c_name, scheme_name, init_val) \
SCM_SNARF_HERE(static SCM c_name) \
SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, init_val));)
SCM_SNARF_INIT(c_name = scm_c_define (scheme_name, init_val);)
#define SCM_GLOBAL_VARIABLE_INIT(c_name, scheme_name, init_val) \
SCM_SNARF_HERE(SCM c_name) \
SCM_SNARF_INIT(c_name = scm_permanent_object (scm_c_define (scheme_name, init_val));)
SCM_SNARF_INIT(c_name = scm_c_define (scheme_name, init_val);)
#define SCM_MUTEX(c_name) \
SCM_SNARF_HERE(static scm_t_mutex c_name) \

View file

@ -59,6 +59,7 @@ SCM_GLOBAL_SYMBOL (scm_sym_copy, "copy");
SCM_GLOBAL_SYMBOL (scm_sym_line, "line");
SCM_GLOBAL_SYMBOL (scm_sym_column, "column");
SCM_GLOBAL_SYMBOL (scm_sym_breakpoint, "breakpoint");
SCM scm_source_whash;

View file

@ -57,6 +57,7 @@ do { \
#define SCM_SOURCE_PROPERTY_FLAG_BREAK 1
SCM_API scm_t_bits scm_tc16_srcprops;
SCM_INTERNAL SCM scm_source_whash;
SCM_API SCM scm_sym_filename;
SCM_API SCM scm_sym_copy;

View file

@ -253,6 +253,8 @@ scm_i_pthread_mutex_t stringbuf_write_mutex = SCM_I_PTHREAD_MUTEX_INITIALIZER;
#define IS_SH_STRING(str) (SCM_CELL_TYPE(str)==SH_STRING_TAG)
SCM scm_nullstr;
/* Create a scheme string with space for LEN 8-bit Latin-1-encoded
characters. CHARSP, if not NULL, will be set to location of the
char array. */

View file

@ -98,6 +98,8 @@ typedef enum
SCM_FAILED_CONVERSION_ESCAPE_SEQUENCE = SCM_ICONVEH_ESCAPE_SEQUENCE
} scm_t_string_failed_conversion_handler;
SCM_INTERNAL SCM scm_nullstr;
SCM_API SCM scm_string_p (SCM x);
SCM_API SCM scm_string (SCM chrs);
SCM_API SCM scm_make_string (SCM k, SCM chr);

View file

@ -637,8 +637,6 @@ SCM_VECTOR_IMPLEMENTATION (SCM_ARRAY_ELEMENT_TYPE_SCM, scm_make_vector);
void
scm_init_vectors ()
{
scm_nullvect = scm_c_make_vector (0, SCM_UNDEFINED);
#include "libguile/vectors.x"
}