Commit a4e60822 authored by Erick's avatar Erick

Changed the internal representation of strings to support multibytes strings

No real support for now
parent 6d197cc6
......@@ -21,7 +21,7 @@
*
* Author: Erick Gallesio [eg@unice.fr]
* Creation date: 28-Dec-1999 22:58 (eg)
* Last file update: 1-May-2011 22:29 (eg)
* Last file update: 5-May-2011 17:56 (eg)
*/
......@@ -1154,18 +1154,20 @@ int STk_init_socket(void);
*/
struct string_obj {
stk_header header;
int size;
char chars[1]; /* will be sized to a different value when allocated */
int space; /* allocated size */
int size; /* # of bytes used */
int length; /* "external" length of the string */
char *chars;
};
#define STRING_SPACE(p) (((struct string_obj *) (p))->space)
#define STRING_SIZE(p) (((struct string_obj *) (p))->size)
#define STRING_LENGTH(p) (((struct string_obj *) (p))->length)
#define STRING_CHARS(p) (((struct string_obj *) (p))->chars)
#define STRINGP(p) (BOXED_TYPE_EQ((p), tc_string))
#define STRING_CONST (1 << 0)
#define BOX_CSTRING(s) STk_makestring(strlen(s), (s))
SCM STk_makestring(int len, char *init);
SCM STk_Cstring2string(char *str); /* Embed a C string in Scheme world */
......
......@@ -22,7 +22,7 @@
*
* Author: Erick Gallesio [eg@unice.fr]
* Creation date: ??????
* Last file update: 5-May-2011 15:55 (eg)
* Last file update: 5-May-2011 18:00 (eg)
*/
#include <ctype.h>
......@@ -133,8 +133,9 @@ SCM STk_makestring(int len, char *init)
{
register SCM z;
NEWCELL_ATOMIC(z, string, sizeof(struct string_obj) + len);
STRING_SIZE(z) = len;
NEWCELL(z, string);
STRING_CHARS(z) = STk_must_malloc_atomic(len + 1);
STRING_SPACE(z) = STRING_SIZE(z) = STRING_LENGTH(z) = len;
if (init) memcpy(STRING_CHARS(z), init, (size_t) len);
STRING_CHARS(z)[len] = '\0'; /* so that STRING_CHARS is compatible with C */
......@@ -147,8 +148,9 @@ SCM STk_Cstring2string(char *str) /* Embed a C string in Scheme world */
SCM z;
size_t len = strlen(str);
NEWCELL_ATOMIC(z, string, sizeof(struct string_obj) + len);
STRING_SIZE(z) = len;
NEWCELL(z, string);
STRING_CHARS(z) = STk_must_malloc_atomic(len + 1);
STRING_SPACE(z) = STRING_SIZE(z) = STRING_LENGTH(z) = len;
strcpy(STRING_CHARS(z), str);
return z;
......@@ -159,8 +161,9 @@ SCM STk_chars2string(char *str, size_t len)
{
SCM z;
NEWCELL_ATOMIC(z, string, sizeof(struct string_obj) + len);
STRING_SIZE(z) = len;
NEWCELL(z, string);
STRING_CHARS(z) = STk_must_malloc_atomic(len + 1);
STRING_SPACE(z) = STRING_SIZE(z) = STRING_LENGTH(z) = len;
memcpy(STRING_CHARS(z), str, len);
STRING_CHARS(z)[len] = '\0'; /* so that STRING_CHARS is compatible with C */
return z;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment