summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libguile/gh.h2
-rw-r--r--libguile/gh_data.c56
2 files changed, 19 insertions, 39 deletions
diff --git a/libguile/gh.h b/libguile/gh.h
index dfc892f17..c9558d3db 100644
--- a/libguile/gh.h
+++ b/libguile/gh.h
@@ -81,7 +81,7 @@ SCM_API SCM gh_double2scm(double x);
SCM_API SCM gh_char2scm(char c);
SCM_API SCM gh_str2scm(const char *s, size_t len);
SCM_API SCM gh_str02scm(const char *s);
-SCM_API void gh_set_substr(char *src, SCM dst, long start, size_t len);
+SCM_API void gh_set_substr(const char *src, SCM dst, long start, size_t len);
SCM_API SCM gh_symbol2scm(const char *symbol_str);
SCM_API SCM gh_ints2scm(const int *d, long n);
diff --git a/libguile/gh_data.c b/libguile/gh_data.c
index 7f41b206d..1b87ad25f 100644
--- a/libguile/gh_data.c
+++ b/libguile/gh_data.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2004 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 as published by the Free Software Foundation; either
@@ -61,12 +61,12 @@ gh_char2scm (char c)
SCM
gh_str2scm (const char *s, size_t len)
{
- return scm_mem2string (s, len);
+ return scm_from_locale_stringn (s, len);
}
SCM
gh_str02scm (const char *s)
{
- return scm_makfrom0str (s);
+ return scm_from_locale_string (s);
}
/* Copy LEN characters at SRC into the *existing* Scheme string DST,
starting at START. START is an index into DST; zero means the
@@ -75,18 +75,19 @@ gh_str02scm (const char *s)
If START + LEN is off the end of DST, signal an out-of-range
error. */
void
-gh_set_substr (char *src, SCM dst, long start, size_t len)
+gh_set_substr (const char *src, SCM dst, long start, size_t len)
{
char *dst_ptr;
size_t dst_len;
- SCM_ASSERT (SCM_I_STRINGP (dst), dst, SCM_ARG3, "gh_set_substr");
+ SCM_ASSERT (scm_is_string (dst), dst, SCM_ARG3, "gh_set_substr");
- dst_ptr = SCM_I_STRING_CHARS (dst);
- dst_len = SCM_I_STRING_LENGTH (dst);
+ dst_len = scm_i_string_length (dst);
SCM_ASSERT (start + len <= dst_len, dst, SCM_ARG4, "gh_set_substr");
-
+
+ dst_ptr = scm_i_string_writable_chars (dst);
memmove (dst_ptr + start, src, len);
+ scm_i_string_stop_writing ();
scm_remember_upto_here_1 (dst);
}
@@ -94,7 +95,7 @@ gh_set_substr (char *src, SCM dst, long start, size_t len)
SCM
gh_symbol2scm (const char *symbol_str)
{
- return scm_str2symbol(symbol_str);
+ return scm_from_locale_symbol(symbol_str);
}
SCM
@@ -259,12 +260,12 @@ gh_scm2chars (SCM obj, char *m)
break;
#endif
case scm_tc7_string:
- n = SCM_I_STRING_LENGTH (obj);
+ n = scm_i_string_length (obj);
if (m == 0)
m = (char *) malloc (n * sizeof (char));
if (m == NULL)
return NULL;
- memcpy (m, SCM_I_STRING_CHARS (obj), n * sizeof (char));
+ memcpy (m, scm_i_string_chars (obj), n * sizeof (char));
break;
default:
scm_wrong_type_arg (0, 0, obj);
@@ -525,7 +526,7 @@ gh_scm2newstr (SCM str, size_t *lenp)
ret_str = scm_to_locale_string (str);
if (lenp)
- *lenp = SCM_I_STRING_LENGTH (str);
+ *lenp = scm_i_string_length (str);
return ret_str;
}
@@ -540,11 +541,11 @@ void
gh_get_substr (SCM src, char *dst, long start, size_t len)
{
size_t src_len, effective_length;
- SCM_ASSERT (SCM_I_STRINGP (src), src, SCM_ARG3, "gh_get_substr");
+ SCM_ASSERT (scm_is_string (src), src, SCM_ARG3, "gh_get_substr");
- src_len = SCM_I_STRING_LENGTH (src);
+ src_len = scm_i_string_length (src);
effective_length = (len < src_len) ? len : src_len;
- memcpy (dst + start, SCM_I_STRING_CHARS (src), effective_length * sizeof (char));
+ memcpy (dst + start, scm_i_string_chars (src), effective_length * sizeof (char));
/* FIXME: must signal an error if len > src_len */
scm_remember_upto_here_1 (src);
}
@@ -561,28 +562,7 @@ gh_get_substr (SCM src, char *dst, long start, size_t len)
char *
gh_symbol2newstr (SCM sym, size_t *lenp)
{
- char *ret_str;
- size_t len;
-
- SCM_ASSERT (SCM_SYMBOLP (sym), sym, SCM_ARG3, "gh_scm2newsymbol");
-
- len = SCM_SYMBOL_LENGTH (sym);
-
- ret_str = (char *) malloc ((len + 1) * sizeof (char));
- if (ret_str == NULL)
- return NULL;
- /* so we copy sym to ret_str, which is what we will allocate */
- memcpy (ret_str, SCM_SYMBOL_CHARS (sym), len);
- scm_remember_upto_here_1 (sym);
- /* now make sure we null-terminate it */
- ret_str[len] = '\0';
-
- if (lenp != NULL)
- {
- *lenp = len;
- }
-
- return ret_str;
+ return gh_scm2newstr (scm_symbol_to_string (sym), lenp);
}
@@ -665,7 +645,7 @@ gh_module_lookup (SCM module, const char *sname)
SCM_VALIDATE_MODULE (SCM_ARG1, module);
- sym = scm_str2symbol (sname);
+ sym = scm_from_locale_symbol (sname);
var = scm_sym2var (sym, scm_module_lookup_closure (module), SCM_BOOL_F);
if (var != SCM_BOOL_F)
return SCM_VARIABLE_REF (var);