guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/2] Reduce scope of variables


From: KAction
Subject: [PATCH 2/2] Reduce scope of variables
Date: Thu, 10 Apr 2014 09:37:46 +0400

From: Dmitry Bogatov <address@hidden>

Signed-off-by: Dmitry Bogatov <address@hidden>
---
 libguile/array-handle.c |  4 ++--
 libguile/array-map.c    |  8 ++++----
 libguile/backtrace.c    |  4 ++--
 libguile/bytevectors.c  |  3 +--
 libguile/dynl.c         |  3 +--
 libguile/eval.c         |  3 ++-
 libguile/ioext.c        |  8 +++++---
 libguile/numbers.c      |  3 ++-
 libguile/procprop.c     |  3 +--
 libguile/random.c       | 11 +++++------
 libguile/read.c         | 13 +++++--------
 libguile/scmsigs.c      |  2 +-
 libguile/script.c       |  2 +-
 libguile/socket.c       |  2 +-
 libguile/srfi-1.c       |  3 ++-
 libguile/srfi-13.c      | 49 +++++++++++++++++++++++--------------------------
 libguile/stacks.c       |  4 ++--
 libguile/strings.c      |  9 +++++----
 libguile/threads.c      | 10 +++++-----
 19 files changed, 70 insertions(+), 74 deletions(-)

diff --git a/libguile/array-handle.c b/libguile/array-handle.c
index 2252ecc..051e667 100644
--- a/libguile/array-handle.c
+++ b/libguile/array-handle.c
@@ -246,12 +246,12 @@ ssize_t
 scm_array_handle_pos (scm_t_array_handle *h, SCM indices)
 {
   scm_t_array_dim *s = scm_array_handle_dims (h);
-  ssize_t pos = 0, i;
+  ssize_t pos = 0;
   size_t k = scm_array_handle_rank (h);
   
   while (k > 0 && scm_is_pair (indices))
     {
-      i = scm_to_signed_integer (SCM_CAR (indices), s->lbnd, s->ubnd);
+      ssize_t i = scm_to_signed_integer (SCM_CAR (indices), s->lbnd, s->ubnd);
       pos += (i - s->lbnd) * s->inc;
       k--;
       s++;
diff --git a/libguile/array-map.c b/libguile/array-map.c
index 2d68f5f..c5221a9 100644
--- a/libguile/array-map.c
+++ b/libguile/array-map.c
@@ -337,7 +337,6 @@ scm_ra_eqp (SCM ra0, SCM ras)
   scm_t_array_dim *ra0_dims;
   size_t n;
   ssize_t inc0;
-  size_t i0 = 0;
   unsigned long i1 = SCM_I_ARRAY_BASE (ra1), i2 = SCM_I_ARRAY_BASE (ra2);
   long inc1 = SCM_I_ARRAY_DIMS (ra1)->inc;
   long inc2 = SCM_I_ARRAY_DIMS (ra1)->inc;
@@ -350,7 +349,8 @@ scm_ra_eqp (SCM ra0, SCM ras)
   inc0 = ra0_dims[0].inc;
 
   {
-    for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2)
+    size_t i0;
+    for (i0 = 0; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2)
       if (scm_is_true (scm_array_handle_ref (&ra0_handle, i0)))
        if (!scm_is_eq (AREF (ra1, i1), AREF (ra2, i2)))
          scm_array_handle_set (&ra0_handle, i0, SCM_BOOL_F);
@@ -369,7 +369,6 @@ ra_compare (SCM ra0, SCM ra1, SCM ra2, int opt)
   scm_t_array_dim *ra0_dims;
   size_t n;
   ssize_t inc0;
-  size_t i0 = 0;
   unsigned long i1 = SCM_I_ARRAY_BASE (ra1), i2 = SCM_I_ARRAY_BASE (ra2);
   long inc1 = SCM_I_ARRAY_DIMS (ra1)->inc;
   long inc2 = SCM_I_ARRAY_DIMS (ra1)->inc;
@@ -382,7 +381,8 @@ ra_compare (SCM ra0, SCM ra1, SCM ra2, int opt)
   inc0 = ra0_dims[0].inc;
 
   {
-    for (; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2)
+    size_t i0;
+    for (i0 = 0; n-- > 0; i0 += inc0, i1 += inc1, i2 += inc2)
       if (scm_is_true (scm_array_handle_ref (&ra0_handle, i0)))
        if (opt ?
            scm_is_true (scm_less_p (AREF (ra1, i1), AREF (ra2, i2))) :
diff --git a/libguile/backtrace.c b/libguile/backtrace.c
index e247aa7..4c7c75b 100644
--- a/libguile/backtrace.c
+++ b/libguile/backtrace.c
@@ -449,7 +449,7 @@ display_backtrace_body (struct display_backtrace_args *a)
 {
   int n_frames, beg, end, n, i, j;
   int nfield, indentation;
-  SCM frame, sport, print_state;
+  SCM sport, print_state;
   SCM last_file;
   scm_print_state *pstate;
 
@@ -515,7 +515,7 @@ display_backtrace_body (struct display_backtrace_args *a)
     end--;
   for (i = beg; i != end; SCM_BACKWARDS_P ? ++i : --i)
     {
-      frame = scm_stack_ref (a->stack, scm_from_int (i));
+      SCM frame = scm_stack_ref (a->stack, scm_from_int (i));
       if (!scm_is_eq (SCM_PACK (SCM_SHOW_FILE_NAME), sym_base))
        display_backtrace_file (frame, &last_file, a->port, pstate);
       display_frame (frame, i, nfield, indentation, sport, a->port, pstate);
diff --git a/libguile/bytevectors.c b/libguile/bytevectors.c
index c7908d7..35b2d9b 100644
--- a/libguile/bytevectors.c
+++ b/libguile/bytevectors.c
@@ -208,7 +208,6 @@ static inline SCM
 make_bytevector (size_t len, scm_t_array_element_type element_type)
 {
   SCM ret;
-  size_t c_len;
 
   if (SCM_UNLIKELY (element_type > SCM_ARRAY_ELEMENT_TYPE_LAST
                     || scm_i_array_element_type_sizes[element_type] < 8
@@ -224,7 +223,7 @@ make_bytevector (size_t len, scm_t_array_element_type 
element_type)
     {
       signed char *contents;
 
-      c_len = len * (scm_i_array_element_type_sizes[element_type] / 8);
+      size_t c_len = len * (scm_i_array_element_type_sizes[element_type] / 8);
 
       contents = scm_gc_malloc_pointerless (SCM_BYTEVECTOR_HEADER_BYTES + 
c_len,
                                            SCM_GC_BYTEVECTOR);
diff --git a/libguile/dynl.c b/libguile/dynl.c
index 79198e6..41c3c03 100644
--- a/libguile/dynl.c
+++ b/libguile/dynl.c
@@ -323,8 +323,6 @@ SCM_DEFINE (scm_dynamic_pointer, "dynamic-pointer", 2, 0, 0,
            "since it will be added automatically when necessary.")
 #define FUNC_NAME s_scm_dynamic_pointer
 {
-  void *val;
-
   SCM_VALIDATE_STRING (1, name);
   SCM_VALIDATE_SMOB (SCM_ARG2, dobj, dynamic_obj);
 
@@ -333,6 +331,7 @@ SCM_DEFINE (scm_dynamic_pointer, "dynamic-pointer", 2, 0, 0,
   else
     {
       char *chars;
+      void *val;
 
       scm_dynwind_begin (0);
       chars = scm_to_locale_string (name);
diff --git a/libguile/eval.c b/libguile/eval.c
index 2488ee2..412d0fa 100644
--- a/libguile/eval.c
+++ b/libguile/eval.c
@@ -854,13 +854,14 @@ prepare_boot_closure_env_for_apply (SCM proc, SCM args,
           /* Parse keyword args. */
           {
             int kw_start_idx = i;
-            SCM walk;
 
             if (scm_is_pair (args) && scm_is_pair (CDR (args)))
               for (; scm_is_pair (args) && scm_is_pair (CDR (args));
                    args = CDR (args))
                 {
                   SCM k = CAR (args), v = CADR (args);
+                 SCM walk;
+
                   if (!scm_is_keyword (k))
                     {
                       if (scm_is_true (rest))
diff --git a/libguile/ioext.c b/libguile/ioext.c
index 94b0f4f..db49da5 100644
--- a/libguile/ioext.c
+++ b/libguile/ioext.c
@@ -74,12 +74,12 @@ SCM_DEFINE (scm_redirect_port, "redirect-port", 2, 0, 0,
            "revealed counts.")
 #define FUNC_NAME s_scm_redirect_port
 {
-  int ans, oldfd, newfd;
+  int oldfd, newfd;
   scm_t_fport *fp;
 
   old = SCM_COERCE_OUTPORT (old);
   new = SCM_COERCE_OUTPORT (new);
-  
+
   SCM_VALIDATE_OPFPORT (1, old);
   SCM_VALIDATE_OPFPORT (2, new);
   oldfd = SCM_FPORT_FDES (old);
@@ -90,6 +90,7 @@ SCM_DEFINE (scm_redirect_port, "redirect-port", 2, 0, 0,
       scm_t_port *pt = SCM_PTAB_ENTRY (new);
       scm_t_port *old_pt = SCM_PTAB_ENTRY (old);
       scm_t_ptob_descriptor *ptob = SCM_PORT_DESCRIPTOR (new);
+      int ans;
 
       /* must flush to old fdes.  */
       if (pt->rw_active == SCM_PORT_WRITE)
@@ -113,7 +114,7 @@ SCM_DEFINE (scm_dup_to_fdes, "dup->fdes", 1, 1, 0,
            "file port or a file descriptor.")
 #define FUNC_NAME s_scm_dup_to_fdes
 {
-  int oldfd, newfd, rv;
+  int oldfd, newfd;
 
   fd_or_port = SCM_COERCE_OUTPORT (fd_or_port);
 
@@ -137,6 +138,7 @@ SCM_DEFINE (scm_dup_to_fdes, "dup->fdes", 1, 1, 0,
       newfd = scm_to_int (fd);
       if (oldfd != newfd)
        {
+         int rv;
          scm_evict_ports (newfd);      /* see scsh manual.  */
          rv = dup2 (oldfd, newfd);
          if (rv == -1)
diff --git a/libguile/numbers.c b/libguile/numbers.c
index f4e8b27..228d693 100644
--- a/libguile/numbers.c
+++ b/libguile/numbers.c
@@ -10265,11 +10265,12 @@ SCM_PRIMITIVE_GENERIC (scm_sqrt, "sqrt", 1, 0, 0,
               else
                 {
                   mpz_t xx;
-                  scm_t_inum root;
 
                   mpz_init_set_ui (xx, x);
                   if (mpz_perfect_square_p (xx))
                     {
+                      scm_t_inum root;
+
                       mpz_sqrt (xx, xx);
                       root = mpz_get_ui (xx);
                       mpz_clear (xx);
diff --git a/libguile/procprop.c b/libguile/procprop.c
index d455360..d9daaba 100644
--- a/libguile/procprop.c
+++ b/libguile/procprop.c
@@ -308,12 +308,11 @@ SCM_DEFINE (scm_procedure_source, "procedure-source", 1, 
0, 0,
            "Return the source of the procedure @var{proc}.")
 #define FUNC_NAME s_scm_procedure_source
 {
-  SCM src;
   SCM_VALIDATE_PROC (1, proc);
 
   do
     {
-      src = scm_procedure_property (proc, scm_sym_source);
+      SCM src = scm_procedure_property (proc, scm_sym_source);
       if (scm_is_true (src))
         return src;
 
diff --git a/libguile/random.c b/libguile/random.c
index 915f17f..cf41a1d 100644
--- a/libguile/random.c
+++ b/libguile/random.c
@@ -108,10 +108,10 @@ scm_i_init_rstate (scm_t_rstate *state, const char *seed, 
int n)
   scm_t_i_rstate *istate = (scm_t_i_rstate*) state;
   scm_t_uint32 w = 0L;
   scm_t_uint32 c = 0L;
-  int i, m;
+  int i;
   for (i = 0; i < n; ++i)
     {
-      m = i % 8;
+      int m = i % 8;
       if (m < 4)
        w += seed[i] << (8 * m);
       else
@@ -503,10 +503,9 @@ SCM_DEFINE (scm_random_normal, "random:normal", 0, 1, 0,
 static void
 vector_scale_x (SCM v, double c)
 {
-  size_t n;
   if (scm_is_vector (v))
     {
-      n = SCM_SIMPLE_VECTOR_LENGTH (v);
+      size_t n = SCM_SIMPLE_VECTOR_LENGTH (v);
       while (n-- > 0)
        SCM_REAL_VALUE (SCM_SIMPLE_VECTOR_REF (v, n)) *= c;
     }
@@ -531,10 +530,10 @@ static double
 vector_sum_squares (SCM v)
 {
   double x, sum = 0.0;
-  size_t n;
+  
   if (scm_is_vector (v))
     {
-      n = SCM_SIMPLE_VECTOR_LENGTH (v);
+      size_t n = SCM_SIMPLE_VECTOR_LENGTH (v);
       while (n-- > 0)
        {
          x = SCM_REAL_VALUE (SCM_SIMPLE_VECTOR_REF (v, n));
diff --git a/libguile/read.c b/libguile/read.c
index bcb40ee..bda33ce 100644
--- a/libguile/read.c
+++ b/libguile/read.c
@@ -975,11 +975,10 @@ try_read_ci_chars (SCM port, const char *expected_chars)
   int num_chars_wanted = strlen (expected_chars);
   int num_chars_read = 0;
   char *chars_read = alloca (num_chars_wanted);
-  int c;
 
   while (num_chars_read < num_chars_wanted)
     {
-      c = scm_getc_unlocked (port);
+      int c = scm_getc_unlocked (port);
       if (c == EOF)
         break;
       else if (c_tolower (c) != expected_chars[num_chars_read])
@@ -1418,12 +1417,11 @@ static SCM
 scm_read_shebang (scm_t_wchar chr, SCM port, scm_t_read_opts *opts)
 {
   char name[READER_DIRECTIVE_NAME_MAX_SIZE + 1];
-  int c;
   int i = 0;
 
   while (i <= READER_DIRECTIVE_NAME_MAX_SIZE)
     {
-      c = scm_getc_unlocked (port);
+      int c = scm_getc_unlocked (port);
       if (c == EOF)
        scm_i_input_error ("skip_block_comment", port,
                           "unterminated `#! ... !#' comment", SCM_EOL);
@@ -2183,7 +2181,6 @@ SCM_DEFINE (scm_file_encoding, "file-encoding", 1, 0, 0,
 #define FUNC_NAME s_scm_file_encoding
 {
   char *enc;
-  SCM s_enc;
 
   SCM_VALIDATE_OPINPORT (SCM_ARG1, port);
 
@@ -2192,7 +2189,7 @@ SCM_DEFINE (scm_file_encoding, "file-encoding", 1, 0, 0,
     return SCM_BOOL_F;
   else
     {
-      s_enc = scm_string_upcase (scm_from_locale_string (enc));
+      SCM s_enc = scm_string_upcase (scm_from_locale_string (enc));
       return s_enc;
     }
 
@@ -2295,7 +2292,7 @@ set_port_curly_infix_p (SCM port, scm_t_read_opts *opts, 
int value)
 static void
 init_read_options (SCM port, scm_t_read_opts *opts)
 {
-  SCM val, scm_read_options;
+  SCM scm_read_options;
   unsigned int read_options, x;
 
   scm_read_options = scm_i_port_property (port, sym_port_read_options);
@@ -2308,7 +2305,7 @@ init_read_options (SCM port, scm_t_read_opts *opts)
   x = READ_OPTION_MASK & (read_options >> READ_OPTION_KEYWORD_STYLE);
   if (x == READ_OPTION_INHERIT)
     {
-      val = SCM_PACK (SCM_KEYWORD_STYLE);
+      SCM val = SCM_PACK (SCM_KEYWORD_STYLE);
       if (scm_is_eq (val, scm_keyword_prefix))
         x = KEYWORD_STYLE_PREFIX;
       else if (scm_is_eq (val, scm_keyword_postfix))
diff --git a/libguile/scmsigs.c b/libguile/scmsigs.c
index d65dcea..8adc46b 100644
--- a/libguile/scmsigs.c
+++ b/libguile/scmsigs.c
@@ -156,7 +156,6 @@ read_signal_pipe_data (void * data)
 static SCM
 signal_delivery_thread (void *data)
 {
-  int sig;
 #if HAVE_PTHREAD_SIGMASK  /* not on mingw, see notes above */
   sigset_t all_sigs;
   sigfillset (&all_sigs);
@@ -171,6 +170,7 @@ signal_delivery_thread (void *data)
   while (1)
     {
       struct signal_pipe_data sigdata;
+      int sig;
 
       scm_without_guile (read_signal_pipe_data, &sigdata);
       
diff --git a/libguile/script.c b/libguile/script.c
index 7b737f7..08d91ab 100644
--- a/libguile/script.c
+++ b/libguile/script.c
@@ -128,7 +128,6 @@ char *
 scm_find_executable (const char *name)
 {
   char tbuf[MAXPATHLEN];
-  int i = 0, c;
   FILE *f;
 
   /* fprintf(stderr, "s_f_e checking access %s ->%d\n", name, access(name, 
X_OK)); fflush(stderr); */
@@ -139,6 +138,7 @@ scm_find_executable (const char *name)
     return 0L;
   if ((fgetc (f) == '#') && (fgetc (f) == '!'))
     {
+      int i = 0, c;
       while (1)
        switch (c = fgetc (f))
          {
diff --git a/libguile/socket.c b/libguile/socket.c
index 0516e52..0659590 100644
--- a/libguile/socket.c
+++ b/libguile/socket.c
@@ -1151,7 +1151,6 @@ scm_to_sockaddr (SCM address, size_t *address_size)
        else
          {
            SCM path;
-           size_t path_len = 0;
 
            path = SCM_SIMPLE_VECTOR_REF (address, 1);
            if (!scm_is_string (path) && !scm_is_false (path))
@@ -1160,6 +1159,7 @@ scm_to_sockaddr (SCM address, size_t *address_size)
            else
              {
                struct sockaddr_un c_unix;
+               size_t path_len = 0;
 
                if (scm_is_false (path))
                  path_len = 0;
diff --git a/libguile/srfi-1.c b/libguile/srfi-1.c
index aaa3efe..9d1049f 100644
--- a/libguile/srfi-1.c
+++ b/libguile/srfi-1.c
@@ -509,7 +509,6 @@ SCM_DEFINE (scm_srfi1_delete_duplicates_x, 
"delete-duplicates!", 1, 1, 0,
            "adjacent elements.")
 #define FUNC_NAME s_scm_srfi1_delete_duplicates_x
 {
-  scm_t_trampoline_2 equal_p;
   SCM  ret, endret, item, l;
 
   /* ret is the return list, constructed from the pairs in lst.  endret is
@@ -520,6 +519,8 @@ SCM_DEFINE (scm_srfi1_delete_duplicates_x, 
"delete-duplicates!", 1, 1, 0,
   ret = lst;
   if (scm_is_pair (lst))
     {
+      scm_t_trampoline_2 equal_p;
+
       if (SCM_UNBNDP (pred))
         equal_p = equal_trampoline;
       else
diff --git a/libguile/srfi-13.c b/libguile/srfi-13.c
index 5c30dfe..7c47005 100644
--- a/libguile/srfi-13.c
+++ b/libguile/srfi-13.c
@@ -220,9 +220,8 @@ SCM_DEFINE (scm_string_tabulate, "string-tabulate", 2, 0, 0,
            "@var{proc} is applied to the indices is not specified.")
 #define FUNC_NAME s_scm_string_tabulate
 {
-  size_t clen, i;
+  size_t clen;
   SCM res;
-  SCM ch;
 
   SCM_ASSERT (scm_is_true (scm_procedure_p (proc)),
               proc, SCM_ARG1, FUNC_NAME);
@@ -235,10 +234,10 @@ SCM_DEFINE (scm_string_tabulate, "string-tabulate", 2, 0, 
0,
        of speed.  */
     scm_t_wchar *buf = scm_malloc (clen * sizeof (scm_t_wchar));
     int wide = 0;
-    i = 0; 
+    size_t i = 0;
     while (i < clen)
       {
-        ch = scm_call_1 (proc, scm_from_size_t (i));
+        SCM ch = scm_call_1 (proc, scm_from_size_t (i));
         if (!SCM_CHARP (ch))
           {
             SCM_MISC_ERROR ("procedure ~S returned non-char", scm_list_1 
(proc));
@@ -331,7 +330,7 @@ SCM_DEFINE (scm_reverse_list_to_string, 
"reverse-list->string", 1, 0, 0,
 #define FUNC_NAME s_scm_reverse_list_to_string
 {
   SCM result;
-  long i = scm_ilength (chrs), j;
+  long i = scm_ilength (chrs);
   char *data;
 
   if (i < 0)
@@ -340,8 +339,9 @@ SCM_DEFINE (scm_reverse_list_to_string, 
"reverse-list->string", 1, 0, 0,
 
   {
     SCM rest;
+    long j = 0;
     rest = chrs;
-    j = 0;
+
     while (j < i && scm_is_pair (rest))
       {
         SCM elt = SCM_CAR (rest);
@@ -531,7 +531,7 @@ SCM_DEFINE (scm_string_copy_x, "string-copy!", 3, 2, 0,
            "string.")
 #define FUNC_NAME s_scm_string_copy_x
 {
-  size_t cstart, cend, ctstart, dummy, len, i;
+  size_t cstart, cend, ctstart, dummy, i;
   SCM sdummy = SCM_UNDEFINED;
 
   MY_VALIDATE_SUBSTRING_SPEC (1, target,
@@ -542,7 +542,7 @@ SCM_DEFINE (scm_string_copy_x, "string-copy!", 3, 2, 0,
                              5, end, cend);
   if (cstart < cend)
     {
-      len = cend - cstart;
+      size_t len = cend - cstart;
       SCM_ASSERT_RANGE (3, s, len <= scm_i_string_length (target) - ctstart);
 
       target = scm_i_string_start_writing (target);
@@ -954,7 +954,6 @@ SCM_DEFINE (scm_substring_fill_x, "string-fill!", 2, 2, 0,
 #define FUNC_NAME s_scm_substring_fill_x
 {
   size_t cstart, cend;
-  size_t k;
 
   /* Older versions of Guile provided the function
      scm_substring_fill_x with the following order of arguments:
@@ -979,6 +978,8 @@ SCM_DEFINE (scm_substring_fill_x, "string-fill!", 2, 2, 0,
 
   if (cstart < cend)
     {
+      size_t k;
+
       str = scm_i_string_start_writing (str);
       for (k = cstart; k < cend; k++)
         scm_i_string_set_x (str, k, SCM_CHAR (chr));
@@ -2007,7 +2008,7 @@ SCM_DEFINE (scm_string_contains, "string-contains", 2, 4, 
0,
 #define FUNC_NAME s_scm_string_contains
 {
   size_t cstart1, cend1, cstart2, cend2;
-  size_t len2, i, j;
+  size_t len2;
 
   MY_VALIDATE_SUBSTRING_SPEC (1, s1,
                              3, start1, cstart1,
@@ -2019,8 +2020,8 @@ SCM_DEFINE (scm_string_contains, "string-contains", 2, 4, 
0,
   if (cend1 - cstart1 >= len2)
     while (cstart1 <= cend1 - len2)
       {
-       i = cstart1;
-       j = cstart2;
+       size_t i = cstart1;
+       size_t j = cstart2;
        while (i < cend1 
               && j < cend2 
               && (scm_i_string_ref (s1, i)
@@ -2056,7 +2057,7 @@ SCM_DEFINE (scm_string_contains_ci, "string-contains-ci", 
2, 4, 0,
 #define FUNC_NAME s_scm_string_contains_ci
 {
   size_t cstart1, cend1, cstart2, cend2;
-  size_t len2, i, j;
+  size_t len2;
 
   MY_VALIDATE_SUBSTRING_SPEC (1, s1,
                              3, start1, cstart1,
@@ -2068,8 +2069,8 @@ SCM_DEFINE (scm_string_contains_ci, "string-contains-ci", 
2, 4, 0,
   if (cend1 - cstart1 >= len2)
     while (cstart1 <= cend1 - len2)
       {
-       i = cstart1;
-       j = cstart2;
+       size_t i = cstart1;
+       size_t j = cstart2;
        while (i < cend1 
               && j < cend2 
               && (uc_tolower (uc_toupper (scm_i_string_ref (s1, i)))
@@ -2096,10 +2097,9 @@ SCM_DEFINE (scm_string_contains_ci, 
"string-contains-ci", 2, 4, 0,
 static SCM
 string_upcase_x (SCM v, size_t start, size_t end)
 {
-  size_t k;
-
   if (start < end)
     {
+      size_t k;
       v = scm_i_string_start_writing (v);
       for (k = start; k < end; ++k)
         scm_i_string_set_x (v, k, uc_toupper (scm_i_string_ref (v, k)));
@@ -2162,10 +2162,10 @@ scm_string_upcase (SCM str)
 static SCM
 string_downcase_x (SCM v, size_t start, size_t end)
 {
-  size_t k;
 
   if (start < end)
     {
+      size_t k;
       v = scm_i_string_start_writing (v);
       for (k = start; k < end; ++k)
         scm_i_string_set_x (v, k, uc_tolower (scm_i_string_ref (v, k)));
@@ -2230,16 +2230,15 @@ scm_string_downcase (SCM str)
 static SCM
 string_titlecase_x (SCM str, size_t start, size_t end)
 {
-  SCM ch;
+  if (start < end)
+    {
   size_t i;
   int in_word = 0;
 
-  if (start < end)
-    {
       str = scm_i_string_start_writing (str);
       for(i = start; i < end;  i++)
         {
-          ch = SCM_MAKE_CHAR (scm_i_string_ref (str, i));
+          SCM ch = SCM_MAKE_CHAR (scm_i_string_ref (str, i));
           if (scm_is_true (scm_char_alphabetic_p (ch)))
             {
               if (!in_word)
@@ -2332,12 +2331,11 @@ string_reverse_x (SCM str, size_t cstart, size_t cend)
       str = scm_i_string_start_writing (str);
       if (cend > 0)
         {
-          SCM tmp;
 
           cend--;
           while (cstart < cend)
             {
-              tmp = SCM_MAKE_CHAR (scm_i_string_ref (str, cstart));
+              SCM tmp = SCM_MAKE_CHAR (scm_i_string_ref (str, cstart));
               scm_i_string_set_x (str, cstart, scm_i_string_ref (str, cend));
               scm_i_string_set_x (str, cend, SCM_CHAR (tmp));
               cstart++;
@@ -2870,7 +2868,6 @@ SCM_DEFINE (scm_string_xcopy_x, "string-xcopy!", 4, 3, 0,
            "cannot copy a string on top of itself.")
 #define FUNC_NAME s_scm_string_xcopy_x
 {
-  size_t p;
   size_t ctstart, cstart, cend;
   int csfrom, csto;
   SCM dummy = SCM_UNDEFINED;
@@ -2889,6 +2886,7 @@ SCM_DEFINE (scm_string_xcopy_x, "string-xcopy!", 4, 3, 0,
     csto = scm_to_int (sto); 
   if (csfrom < csto)
     {
+      size_t p;
       if (cstart == cend)
         SCM_MISC_ERROR ("start and end indices must not be equal", SCM_EOL);
       SCM_ASSERT_RANGE (1, tstart,
@@ -2935,7 +2933,6 @@ SCM_DEFINE (scm_string_replace, "string-replace", 2, 4, 0,
          (scm_list_3 (scm_i_substring (s1, 0, cstart1),
                       scm_i_substring (s2, cstart2, cend2),
                       scm_i_substring (s1, cend1, scm_i_string_length (s1)))));
-  return result;
 }
 #undef FUNC_NAME
 
diff --git a/libguile/stacks.c b/libguile/stacks.c
index 360b35f..90d0c70 100644
--- a/libguile/stacks.c
+++ b/libguile/stacks.c
@@ -246,7 +246,7 @@ SCM_DEFINE (scm_make_stack, "make-stack", 1, 0, 1,
   long n;
   SCM frame;
   SCM stack;
-  SCM inner_cut, outer_cut;
+  SCM outer_cut;
 
   /* Extract a pointer to the innermost frame of whatever object
      scm_make_stack was given.  */
@@ -299,7 +299,7 @@ SCM_DEFINE (scm_make_stack, "make-stack", 1, 0, 1,
   SCM_VALIDATE_REST_ARGUMENT (args);
   while (n > 0 && !scm_is_null (args))
     {
-      inner_cut = SCM_CAR (args);
+      SCM inner_cut = SCM_CAR (args);
       args = SCM_CDR (args);
       if (scm_is_null (args)) 
        {
diff --git a/libguile/strings.c b/libguile/strings.c
index 90dc83a..c291bc9 100644
--- a/libguile/strings.c
+++ b/libguile/strings.c
@@ -1198,7 +1198,6 @@ SCM
 scm_c_make_string (size_t len, SCM chr)
 #define FUNC_NAME NULL
 {
-  size_t p;
   char *contents = NULL;
   SCM res = scm_i_make_string (len, &contents, 0);
 
@@ -1207,6 +1206,8 @@ scm_c_make_string (size_t len, SCM chr)
     memset (contents, 0, len);
   else
     {
+      size_t p;
+
       SCM_VALIDATE_CHAR (0, chr);
       res = scm_i_string_start_writing (res);
       for (p = 0; p < len; p++)
@@ -1427,7 +1428,6 @@ SCM_DEFINE (scm_string_append, "string-append", 0, 0, 1,
 {
   SCM res;
   size_t total = 0;
-  size_t len;
   int wide = 0;
   SCM l, s;
   size_t i;
@@ -1440,6 +1440,8 @@ SCM_DEFINE (scm_string_append, "string-append", 0, 0, 1,
   SCM_VALIDATE_REST_ARGUMENT (args);
   for (l = args; !scm_is_null (l); l = SCM_CDR (l))
     {
+      size_t len;
+
       s = SCM_CAR (l);
       SCM_VALIDATE_STRING (SCM_ARGn, s);
       len = scm_i_string_length (s);
@@ -2185,7 +2187,6 @@ scm_to_stringn (SCM str, size_t *lenp, const char 
*encoding,
 {
   char *buf;
   size_t ilen, len, i;
-  int ret;
   const char *enc;
 
   if (!scm_is_string (str))
@@ -2237,7 +2238,7 @@ scm_to_stringn (SCM str, size_t *lenp, const char 
*encoding,
     enc = "ISO-8859-1";
   if (scm_i_is_narrow_string (str))
     {
-      ret = mem_iconveh (scm_i_string_chars (str), ilen,
+      int ret = mem_iconveh (scm_i_string_chars (str), ilen,
                          "ISO-8859-1", enc,
                          (enum iconv_ilseq_handler) handler, NULL,
                          &buf, &len);
diff --git a/libguile/threads.c b/libguile/threads.c
index dd04f6f..471d463 100644
--- a/libguile/threads.c
+++ b/libguile/threads.c
@@ -307,13 +307,14 @@ block_self (SCM queue, SCM sleep_object, 
scm_i_pthread_mutex_t *mutex,
            const scm_t_timespec *waittime)
 {
   scm_i_thread *t = SCM_I_CURRENT_THREAD;
-  SCM q_handle;
   int err;
 
   if (scm_i_setup_sleep (t, sleep_object, mutex, -1))
     err = EINTR;
   else
     {
+      SCM q_handle;
+
       t->block_asyncs++;
       q_handle = enqueue (queue, t->handle);
       if (waittime == NULL)
@@ -1471,9 +1472,8 @@ fat_mutex_unlock (SCM mutex, SCM cond,
 {
   SCM owner;
   fat_mutex *m = SCM_MUTEX_DATA (mutex);
-  fat_cond *c = NULL;
   scm_i_thread *t = SCM_I_CURRENT_THREAD;
-  int err = 0, ret = 0;
+  int ret = 0;
 
   scm_i_scm_pthread_mutex_lock (&m->lock);
 
@@ -1499,11 +1499,11 @@ fat_mutex_unlock (SCM mutex, SCM cond,
 
   if (! (SCM_UNBNDP (cond)))
     {
-      c = SCM_CONDVAR_DATA (cond);
+      fat_cond *c = SCM_CONDVAR_DATA (cond);
       while (1)
        {
          int brk = 0;
-
+         int err;
          if (m->level > 0)
            m->level--;
          if (m->level == 0)
-- 
Please keep me in CC.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]