guile-devel
[Top][All Lists]
Advanced

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

Re: Exposing `scm_i_mem2number ()'


From: Ludovic Courtès
Subject: Re: Exposing `scm_i_mem2number ()'
Date: Thu, 16 Feb 2006 14:35:36 +0100
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux)

Hello,

Marius Vollmer <address@hidden> writes:

> I'd make it the number of octets, to remain in sync with
> scm_from_locale_stringn, etc.

Right.  Below is a patch that does this.

> But, what about scm_string_to_number (scm_from_locale_string (...))?
> Isn't that good enough?

Using the C variant, you can save the creation and bookkeeping of two
Scheme objects[*].  Since we do have the C variant anyway, I think it's
better to expose it if doing so does not preclude future changes in the
implementation.

Thanks,
Ludovic.

[*] On that topic, see also:
    http://lists.gnu.org/archive/html/guile-devel/2005-12/msg00093.html .


libguile/

2006-02-16  Ludovic Courtès  <address@hidden>

        * numbers.c (scm_i_mem2number): Renamed to
        `scm_c_locale_string_to_number ()'.
        Updated callers.
    
        * numbers.h: Updated function declaration.

        * print.c: Updated callers.

        * read.c: Likewise.


doc/ref/

2006-02-16  Ludovic Courtès  <address@hidden>

        * api-data.texi (Conversion): Documented
        `scm_c_locale_string_to_number ()'.


--- orig/doc/ref/api-data.texi
+++ mod/doc/ref/api-data.texi
@@ -1031,6 +1031,12 @@
 @code{string->number} returns @code{#f}.
 @end deffn
 
address@hidden {C Function} scm_c_locale_string_to_number (string, len, radix)
+Like @code{scm_string_to_number ()}, return a number (a Scheme object)
+whose representation is expressed by the given C string @var{string}
+of size @var{len} octets (@var{string} does not need to be
+null-terminated).  @var{radix} must be of type @code{unsigned int}.
address@hidden deffn
 
 @node Complex
 @subsubsection Complex Number Operations


--- orig/libguile/numbers.c
+++ mod/libguile/numbers.c
@@ -2937,7 +2937,8 @@
 enum t_radix {NO_RADIX=0, DUAL=2, OCT=8, DEC=10, HEX=16};
 
 SCM
-scm_i_mem2number (const char* mem, size_t len, unsigned int default_radix)
+scm_c_locale_string_to_number (const char* mem, size_t len,
+                              unsigned int default_radix)
 {
   unsigned int idx = 0;
   unsigned int radix = NO_RADIX;
@@ -3043,9 +3044,9 @@
   else
     base = scm_to_unsigned_integer (radix, 2, INT_MAX);
 
-  answer = scm_i_mem2number (scm_i_string_chars (string),
-                            scm_i_string_length (string),
-                            base);
+  answer = scm_c_locale_string_to_number (scm_i_string_chars (string),
+                                         scm_i_string_length (string),
+                                         base);
   scm_remember_upto_here_1 (string);
   return answer;
 }


--- orig/libguile/numbers.h
+++ mod/libguile/numbers.h
@@ -215,7 +215,8 @@
 SCM_API int scm_print_real (SCM sexp, SCM port, scm_print_state *pstate);
 SCM_API int scm_print_complex (SCM sexp, SCM port, scm_print_state *pstate);
 SCM_API int scm_bigprint (SCM exp, SCM port, scm_print_state *pstate);
-SCM_API SCM scm_i_mem2number (const char *mem, size_t len, unsigned int radix);
+SCM_API SCM scm_c_locale_string_to_number (const char *mem, size_t len,
+                                          unsigned int radix);
 SCM_API SCM scm_string_to_number (SCM str, SCM radix);
 SCM_API SCM scm_bigequal (SCM x, SCM y);
 SCM_API SCM scm_real_equalp (SCM x, SCM y);


--- orig/libguile/print.c
+++ mod/libguile/print.c
@@ -327,7 +327,7 @@
   if (len == 0 || str[0] == '\'' || str[0] == '`' || str[0] == ','
       || quote_keywordish_symbol (str, len)
       || (str[0] == '.' && len == 1)
-      || scm_is_true (scm_i_mem2number(str, len, 10)))
+      || scm_is_true (scm_c_locale_string_to_number (str, len, 10)))
     {
       scm_lfwrite ("#{", 2, port);
       weird = 1;


--- orig/libguile/read.c
+++ mod/libguile/read.c
@@ -506,7 +506,8 @@
               * does only consist of octal digits.  Finally, it should be
               * checked whether the resulting fixnum is in the range of
               * characters.  */
-             p = scm_i_mem2number (scm_i_string_chars (*tok_buf), j, 8);
+             p = scm_c_locale_string_to_number (scm_i_string_chars (*tok_buf),
+                                                j, 8);
              if (SCM_I_INUMP (p))
                return SCM_MAKE_CHAR (SCM_I_INUM (p));
            }
@@ -644,7 +645,7 @@
        /* Shortcut:  Detected symbol '+ or '- */
        goto tok;
 
-      p = scm_i_mem2number (scm_i_string_chars (*tok_buf), j, 10);
+      p = scm_c_locale_string_to_number (scm_i_string_chars (*tok_buf), j, 10);
       if (scm_is_true (p))
        return p;
       if (c == '#')







reply via email to

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