1.1 --- a/generator.py Mon Feb 13 17:54:29 2017 +0100
1.2 +++ b/generator.py Mon Feb 13 21:26:38 2017 +0100
1.3 @@ -505,6 +505,11 @@
1.4 else:
1.5 attrs["__key__"] = None
1.6
1.7 + # Initialise the size, if a string.
1.8 +
1.9 + if attrs.has_key("__size__"):
1.10 + attrs["__size__"] = len(data)
1.11 +
1.12 # Define Unicode constant encoding details.
1.13
1.14 if cls == self.unicode_type:
1.15 @@ -912,6 +917,12 @@
1.16 encode_literal_constant_value(attr)))
1.17 continue
1.18
1.19 + # Special internal size member.
1.20 +
1.21 + elif attrname == "__size__":
1.22 + structure.append("{.intvalue=%d}" % attr)
1.23 + continue
1.24 +
1.25 # Special internal key member.
1.26
1.27 elif attrname == "__key__":
2.1 --- a/lib/__builtins__/str.py Mon Feb 13 17:54:29 2017 +0100
2.2 +++ b/lib/__builtins__/str.py Mon Feb 13 21:26:38 2017 +0100
2.3 @@ -22,8 +22,8 @@
2.4 from __builtins__.operator import _negate
2.5 from __builtins__.sequence import hashable, itemaccess
2.6 from __builtins__.types import check_int
2.7 -from native import str_add, str_lt, str_gt, str_eq, str_len, str_ord, \
2.8 - str_nonempty, str_substr
2.9 +from native import int_new, str_add, str_lt, str_gt, str_eq, str_ord, \
2.10 + str_substr
2.11
2.12 WHITESPACE = (" ", "\f", "\n", "\r", "\t")
2.13
2.14 @@ -39,26 +39,25 @@
2.15 # literals or converted using routines defined for other types, no form
2.16 # of actual initialisation is performed here.
2.17
2.18 + # Note the __key__ member. This is also initialised statically. Where
2.19 + # a string is the same as an attribute name, the __key__ member contains
2.20 + # attribute position and code details.
2.21 +
2.22 # NOTE: Cannot perform "other and other.__data__ or None" since the
2.23 # NOTE: __data__ attribute is not a normal attribute.
2.24
2.25 if other:
2.26 self.__data__ = other.__data__
2.27 + self.__key__ = other.__key__
2.28 + self.__size__ = other.__size__
2.29 else:
2.30 self.__data__ = None
2.31 -
2.32 - # Note the __key__ member. This is also initialised statically. Where
2.33 - # a string is the same as an attribute name, the __key__ member contains
2.34 - # attribute position and code details.
2.35 -
2.36 - if other:
2.37 - self.__key__ = other.__key__
2.38 - else:
2.39 self.__key__ = None
2.40 + self.__size__ = None
2.41
2.42 # Internal methods.
2.43
2.44 - def _binary_op(self, op, other):
2.45 + def _binary_op(self, op, other, sizes=False):
2.46
2.47 "Perform 'op' on this object and 'other' if appropriate."
2.48
2.49 @@ -69,10 +68,12 @@
2.50
2.51 # Otherwise, perform the operation on the operands' data.
2.52
2.53 + elif sizes:
2.54 + return op(self.__data__, other.__data__, self.__size__, other.__size__)
2.55 else:
2.56 return op(self.__data__, other.__data__)
2.57
2.58 - def _binary_op_rev(self, op, other):
2.59 + def _binary_op_rev(self, op, other, sizes=False):
2.60
2.61 "Perform 'op' on 'other' and this object if appropriate."
2.62
2.63 @@ -83,6 +84,8 @@
2.64
2.65 # Otherwise, perform the operation on the operands' data.
2.66
2.67 + elif sizes:
2.68 + return op(other.__data__, self.__data__, other.__size__, self.__size__)
2.69 else:
2.70 return op(other.__data__, self.__data__)
2.71
2.72 @@ -154,7 +157,7 @@
2.73
2.74 "Return the number of bytes in this string."
2.75
2.76 - return str_len(self.__data__)
2.77 + return int_new(self.__size__)
2.78
2.79 # General type methods.
2.80
2.81 @@ -162,7 +165,7 @@
2.82
2.83 "Return whether the string provides any data."
2.84
2.85 - return str_nonempty(self.__data__)
2.86 + return int_new(self.__size__).__bool__()
2.87
2.88 def __contains__(self, value):
2.89
2.90 @@ -196,7 +199,7 @@
2.91
2.92 "Return a string combining this string with 'other'."
2.93
2.94 - return self._binary_op(str_add, other)
2.95 + return self._binary_op(str_add, other, True)
2.96
2.97 __add__ = __iadd__
2.98
2.99 @@ -204,7 +207,7 @@
2.100
2.101 "Return a string combining this string with 'other'."
2.102
2.103 - return self._binary_op_rev(str_add, other)
2.104 + return self._binary_op_rev(str_add, other, True)
2.105
2.106 def __mod__(self, other): pass
2.107 def __rmod__(self, other): pass
3.1 --- a/lib/__builtins__/unicode.py Mon Feb 13 17:54:29 2017 +0100
3.2 +++ b/lib/__builtins__/unicode.py Mon Feb 13 21:26:38 2017 +0100
3.3 @@ -133,7 +133,7 @@
3.4 "Return the length of this string in characters."
3.5
3.6 if self.length is None:
3.7 - self.length = unicode_len(self.__data__)
3.8 + self.length = unicode_len(self.__data__, self.__size__)
3.9
3.10 return self.length
3.11
3.12 @@ -142,7 +142,7 @@
3.13 "Return the value of the string, if only a single character."
3.14
3.15 if self.__len__() == 1:
3.16 - return unicode_ord(self.__data__)
3.17 + return unicode_ord(self.__data__, self.__size__)
3.18 else:
3.19 raise ValueError, self
3.20
3.21 @@ -204,7 +204,7 @@
3.22 "Return the item at the normalised (positive) 'index'."
3.23
3.24 self._check_index(index)
3.25 - return utf8string(unicode_substr(self.__data__, index, index + 1, 1), self.encoding)
3.26 + return utf8string(unicode_substr(self.__data__, self.__size__, index, index + 1, 1), self.encoding)
3.27
3.28 def __get_multiple_items__(self, start, end, step):
3.29
4.1 --- a/lib/native/__init__.py Mon Feb 13 17:54:29 2017 +0100
4.2 +++ b/lib/native/__init__.py Mon Feb 13 21:26:38 2017 +0100
4.3 @@ -23,7 +23,8 @@
4.4
4.5 from native.identity import is_, is_not
4.6
4.7 -from native.int import int_add, int_div, int_mod, int_mul, int_neg, int_pow, \
4.8 +from native.int import int_new, \
4.9 + int_add, int_div, int_mod, int_mul, int_neg, int_pow, \
4.10 int_sub, int_and, int_not, int_or, int_xor, int_lt, \
4.11 int_gt, int_eq, int_ne, int_str
4.12
4.13 @@ -42,8 +43,8 @@
4.14
4.15 from native.program import get_using
4.16
4.17 -from native.str import str_add, str_chr, str_eq, str_gt, str_lt, str_len, \
4.18 - str_nonempty, str_ord, str_substr
4.19 +from native.str import str_add, str_chr, str_eq, str_gt, str_lt, \
4.20 + str_ord, str_substr
4.21
4.22 from native.system import exit, get_argv, get_path
4.23
5.1 --- a/lib/native/int.py Mon Feb 13 17:54:29 2017 +0100
5.2 +++ b/lib/native/int.py Mon Feb 13 21:26:38 2017 +0100
5.3 @@ -8,7 +8,7 @@
5.4 non-core exceptions used by the native functions because they need to be
5.5 identified as being needed by the program.
5.6
5.7 -Copyright (C) 2011, 2015, 2016 Paul Boddie <paul@boddie.org.uk>
5.8 +Copyright (C) 2011, 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
5.9
5.10 This program is free software; you can redistribute it and/or modify it under
5.11 the terms of the GNU General Public License as published by the Free Software
5.12 @@ -24,6 +24,8 @@
5.13 this program. If not, see <http://www.gnu.org/licenses/>.
5.14 """
5.15
5.16 +def int_new(data): pass
5.17 +
5.18 def int_add(self, other): pass
5.19 def int_div(self, other): pass
5.20 def int_mod(self, other): pass
6.1 --- a/lib/native/str.py Mon Feb 13 17:54:29 2017 +0100
6.2 +++ b/lib/native/str.py Mon Feb 13 21:26:38 2017 +0100
6.3 @@ -26,13 +26,11 @@
6.4
6.5 # String operations.
6.6
6.7 -def str_add(data, other_data): pass
6.8 +def str_add(data, other_data, size, other_size): pass
6.9 def str_chr(data): pass
6.10 def str_eq(data, other_data): pass
6.11 def str_gt(data, other_data): pass
6.12 def str_lt(data, other_data): pass
6.13 -def str_len(data): pass
6.14 -def str_nonempty(data): pass
6.15 def str_ord(data): pass
6.16 def str_substr(data, start, end, step): pass
6.17
7.1 --- a/lib/native/unicode.py Mon Feb 13 17:54:29 2017 +0100
7.2 +++ b/lib/native/unicode.py Mon Feb 13 21:26:38 2017 +0100
7.3 @@ -26,8 +26,8 @@
7.4
7.5 # Unicode string operations.
7.6
7.7 -def unicode_len(data): pass
7.8 -def unicode_ord(data): pass
7.9 -def unicode_substr(data, start, end, step): pass
7.10 +def unicode_len(data, size): pass
7.11 +def unicode_ord(data, size): pass
7.12 +def unicode_substr(data, size, start, end, step): pass
7.13
7.14 # vim: tabstop=4 expandtab shiftwidth=4
8.1 --- a/templates/native/buffer.c Mon Feb 13 17:54:29 2017 +0100
8.2 +++ b/templates/native/buffer.c Mon Feb 13 21:26:38 2017 +0100
8.3 @@ -37,7 +37,7 @@
8.4
8.5 /* Calculate the size of the string. */
8.6 for (i = 0; i < data->size; i++)
8.7 - size += strlen(__load_via_object(data->attrs[i].value, __pos___data__).strvalue);
8.8 + size += __load_via_object(data->attrs[i].value, __pos___size__).intvalue;
8.9
8.10 /* Reserve space for a new string. */
8.11 s = (char *) __ALLOCATE(size + 1, sizeof(char));
8.12 @@ -46,13 +46,13 @@
8.13 for (i = 0, j = 0; i < data->size; i++)
8.14 {
8.15 o = __load_via_object(data->attrs[i].value, __pos___data__);
8.16 - n = strlen(o.strvalue);
8.17 + n = __load_via_object(data->attrs[i].value, __pos___size__).intvalue;
8.18 memcpy(s + j, o.strvalue, n); /* does not null terminate but final byte should be zero */
8.19 j += n;
8.20 }
8.21
8.22 /* Return a new string. */
8.23 - return __new_str(s);
8.24 + return __new_str(s, size);
8.25 }
8.26
8.27 /* Module initialisation. */
9.1 --- a/templates/native/common.c Mon Feb 13 17:54:29 2017 +0100
9.2 +++ b/templates/native/common.c Mon Feb 13 21:26:38 2017 +0100
9.3 @@ -34,11 +34,12 @@
9.4 return attr;
9.5 }
9.6
9.7 -__attr __new_str(char *s)
9.8 +__attr __new_str(char *s, int size)
9.9 {
9.10 - /* Create a new string and mutate the __data__ and __key__ attributes. */
9.11 + /* Create a new string and mutate the __data__, __size__ and __key__ attributes. */
9.12 __attr attr = __NEWINSTANCE(__builtins___str_string);
9.13 attr.value->attrs[__pos___data__].strvalue = s;
9.14 + attr.value->attrs[__pos___size__].intvalue = size;
9.15 attr.value->attrs[__pos___key__] = __NULL;
9.16 return attr;
9.17 }
10.1 --- a/templates/native/common.h Mon Feb 13 17:54:29 2017 +0100
10.2 +++ b/templates/native/common.h Mon Feb 13 21:26:38 2017 +0100
10.3 @@ -24,7 +24,7 @@
10.4 /* Utility functions. */
10.5
10.6 __attr __new_int(int i);
10.7 -__attr __new_str(char *s);
10.8 +__attr __new_str(char *s, int size);
10.9 __attr __new_list(__fragment *f);
10.10 __fragment *__fragment_append(__fragment *data, __attr * const value);
10.11
11.1 --- a/templates/native/iconv.c Mon Feb 13 17:54:29 2017 +0100
11.2 +++ b/templates/native/iconv.c Mon Feb 13 21:26:38 2017 +0100
11.3 @@ -99,9 +99,9 @@
11.4 /* Incomplete sequence: raise the string in an OSError instead. */
11.5
11.6 if (errno == EINVAL)
11.7 - __raise_incomplete_sequence_error(__new_int(errno), __new_str(resultbuf));
11.8 + __raise_incomplete_sequence_error(__new_int(errno), __new_str(resultbuf, outbytestotal));
11.9
11.10 - return __new_str(resultbuf);
11.11 + return __new_str(resultbuf, outbytestotal);
11.12 }
11.13
11.14 /* Invalid sequence. */
11.15 @@ -110,7 +110,7 @@
11.16 {
11.17 resultbuf = __ALLOCATE(inbytesleft + 1, sizeof(char));
11.18 memcpy(resultbuf, inbuf, inbytesleft);
11.19 - __raise_invalid_sequence_error(__new_int(errno), __new_str(resultbuf));
11.20 + __raise_invalid_sequence_error(__new_int(errno), __new_str(resultbuf, inbytesleft));
11.21 }
11.22
11.23 /* General failure. */
12.1 --- a/templates/native/int.c Mon Feb 13 17:54:29 2017 +0100
12.2 +++ b/templates/native/int.c Mon Feb 13 21:26:38 2017 +0100
12.3 @@ -18,8 +18,9 @@
12.4
12.5 #include <limits.h> /* INT_MAX, INT_MIN */
12.6 #include <math.h> /* ceil, log10, pow */
12.7 -#include <stdio.h> /* fdopen, snprintf, strlen */
12.8 +#include <stdio.h> /* fdopen, snprintf */
12.9 #include <errno.h> /* errno */
12.10 +#include <string.h> /* strlen */
12.11 #include "native/common.h"
12.12 #include "types.h"
12.13 #include "exceptions.h"
12.14 @@ -31,6 +32,13 @@
12.15
12.16 /* Integer operations. */
12.17
12.18 +__attr __fn_native_int_int_new(__attr __args[])
12.19 +{
12.20 + __attr * const _data = &__args[1];
12.21 +
12.22 + return __new_int(_data->intvalue);
12.23 +}
12.24 +
12.25 __attr __fn_native_int_int_add(__attr __args[])
12.26 {
12.27 __attr * const _data = &__args[1];
12.28 @@ -268,7 +276,7 @@
12.29 snprintf(s, n, "%d", i);
12.30
12.31 /* Return a new string. */
12.32 - return __new_str(s);
12.33 + return __new_str(s, strlen(s));
12.34 }
12.35
12.36 /* Module initialisation. */
13.1 --- a/templates/native/int.h Mon Feb 13 17:54:29 2017 +0100
13.2 +++ b/templates/native/int.h Mon Feb 13 21:26:38 2017 +0100
13.3 @@ -1,6 +1,6 @@
13.4 /* Native functions for integer operations.
13.5
13.6 -Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
13.7 +Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
13.8
13.9 This program is free software; you can redistribute it and/or modify it under
13.10 the terms of the GNU General Public License as published by the Free Software
13.11 @@ -23,6 +23,8 @@
13.12
13.13 /* Integer operations. */
13.14
13.15 +__attr __fn_native_int_int_new(__attr __args[]);
13.16 +
13.17 __attr __fn_native_int_int_add(__attr __args[]);
13.18 __attr __fn_native_int_int_div(__attr __args[]);
13.19 __attr __fn_native_int_int_mod(__attr __args[]);
14.1 --- a/templates/native/io.c Mon Feb 13 17:54:29 2017 +0100
14.2 +++ b/templates/native/io.c Mon Feb 13 21:26:38 2017 +0100
14.3 @@ -148,7 +148,7 @@
14.4
14.5 s = __ALLOCATE(have_read + 1, sizeof(char));
14.6 memcpy(s, (char *) buf, have_read); /* does not null terminate but final byte should be zero */
14.7 - return __new_str(s);
14.8 + return __new_str(s, have_read);
14.9 }
14.10
14.11 __attr __fn_native_io_fwrite(__attr __args[])
14.12 @@ -158,9 +158,9 @@
14.13 /* fp interpreted as FILE reference */
14.14 FILE *f = (FILE *) fp->datavalue;
14.15 /* str.__data__ interpreted as string */
14.16 - __attr sa = __load_via_object(str->value, __pos___data__);
14.17 - char *s = sa.strvalue;
14.18 - size_t to_write = strlen(sa.strvalue);
14.19 + char *s = __load_via_object(str->value, __pos___data__).strvalue;
14.20 + /* str.__size__ interpreted as int */
14.21 + int to_write = __load_via_object(str->value, __pos___size__).intvalue;
14.22 size_t have_written = fwrite(s, sizeof(char), to_write, f);
14.23 int error;
14.24
14.25 @@ -210,7 +210,7 @@
14.26
14.27 s = __ALLOCATE(have_read + 1, 1);
14.28 memcpy(s, (char *) buf, have_read); /* does not null terminate but final byte should be zero */
14.29 - return __new_str(s);
14.30 + return __new_str(s, have_read);
14.31 }
14.32
14.33 __attr __fn_native_io_write(__attr __args[])
14.34 @@ -220,12 +220,13 @@
14.35 /* fd.__data__ interpreted as int */
14.36 int i = __load_via_object(fd->value, __pos___data__).intvalue;
14.37 /* str.__data__ interpreted as string */
14.38 - __attr sa = __load_via_object(str->value, __pos___data__);
14.39 - char *s = sa.strvalue;
14.40 + char *s = __load_via_object(str->value, __pos___data__).strvalue;
14.41 + /* str.__size__ interpreted as int */
14.42 + int size = __load_via_object(str->value, __pos___size__).intvalue;
14.43 ssize_t have_written;
14.44
14.45 errno = 0;
14.46 - have_written = write(i, s, sizeof(char) * strlen(sa.strvalue));
14.47 + have_written = write(i, s, sizeof(char) * size);
14.48
14.49 if (have_written == -1)
14.50 __raise_io_error(__new_int(errno));
15.1 --- a/templates/native/locale.c Mon Feb 13 17:54:29 2017 +0100
15.2 +++ b/templates/native/locale.c Mon Feb 13 21:26:38 2017 +0100
15.3 @@ -46,7 +46,7 @@
15.4 out = __ALLOCATE(length + 1, sizeof(char));
15.5 strncpy(out, result, length);
15.6
15.7 - return __new_str(result);
15.8 + return __new_str(result, length);
15.9 }
15.10
15.11 __attr __fn_native_locale_setlocale(__attr __args[])
15.12 @@ -69,7 +69,7 @@
15.13 out = __ALLOCATE(length + 1, sizeof(char));
15.14 strncpy(out, result, length);
15.15
15.16 - return __new_str(result);
15.17 + return __new_str(result, length);
15.18 }
15.19
15.20 /* Module initialisation. */
16.1 --- a/templates/native/str.c Mon Feb 13 17:54:29 2017 +0100
16.2 +++ b/templates/native/str.c Mon Feb 13 21:26:38 2017 +0100
16.3 @@ -32,10 +32,12 @@
16.4 {
16.5 __attr * const _data = &__args[1];
16.6 __attr * const other = &__args[2];
16.7 + __attr * const _size = &__args[3];
16.8 + __attr * const othersize = &__args[4];
16.9 /* _data, other interpreted as string */
16.10 char *s = _data->strvalue;
16.11 char *o = other->strvalue;
16.12 - size_t ss = strlen(_data->strvalue), os = strlen(other->strvalue);
16.13 + int ss = _size->intvalue, os = othersize->intvalue;
16.14 int n = ss + os;
16.15 char *r = (char *) __ALLOCATE(n + 1, sizeof(char));
16.16
16.17 @@ -43,7 +45,7 @@
16.18 memcpy(r + ss, o, os);
16.19
16.20 /* Return a new string. */
16.21 - return __new_str(r);
16.22 + return __new_str(r, n);
16.23 }
16.24
16.25 __attr __fn_native_str_str_chr(__attr __args[])
16.26 @@ -54,7 +56,7 @@
16.27 char *s = (char *) __ALLOCATE(2, sizeof(char));
16.28
16.29 s[0] = (char) n;
16.30 - return __new_str(s);
16.31 + return __new_str(s, 1);
16.32 }
16.33
16.34 __attr __fn_native_str_str_lt(__attr __args[])
16.35 @@ -93,21 +95,6 @@
16.36 return strcmp(s, o) == 0 ? __builtins___boolean_True : __builtins___boolean_False;
16.37 }
16.38
16.39 -__attr __fn_native_str_str_len(__attr __args[])
16.40 -{
16.41 - __attr * const _data = &__args[1];
16.42 -
16.43 - /* Return the new integer. */
16.44 - return __new_int(strlen(_data->strvalue));
16.45 -}
16.46 -
16.47 -__attr __fn_native_str_str_nonempty(__attr __args[])
16.48 -{
16.49 - __attr * const _data = &__args[1];
16.50 -
16.51 - return _data->strvalue[0] ? __builtins___boolean_True : __builtins___boolean_False;
16.52 -}
16.53 -
16.54 __attr __fn_native_str_str_ord(__attr __args[])
16.55 {
16.56 __attr * const _data = &__args[1];
16.57 @@ -147,7 +134,7 @@
16.58 for (from = istart, to = 0; from > iend; from += istep, to++)
16.59 sub[to] = s[from];
16.60
16.61 - return __new_str(sub);
16.62 + return __new_str(sub, resultsize);
16.63 }
16.64
16.65 /* Module initialisation. */
17.1 --- a/templates/native/str.h Mon Feb 13 17:54:29 2017 +0100
17.2 +++ b/templates/native/str.h Mon Feb 13 21:26:38 2017 +0100
17.3 @@ -26,8 +26,6 @@
17.4 __attr __fn_native_str_str_lt(__attr __args[]);
17.5 __attr __fn_native_str_str_gt(__attr __args[]);
17.6 __attr __fn_native_str_str_eq(__attr __args[]);
17.7 -__attr __fn_native_str_str_len(__attr __args[]);
17.8 -__attr __fn_native_str_str_nonempty(__attr __args[]);
17.9 __attr __fn_native_str_str_ord(__attr __args[]);
17.10 __attr __fn_native_str_str_substr(__attr __args[]);
17.11
18.1 --- a/templates/native/unicode.c Mon Feb 13 17:54:29 2017 +0100
18.2 +++ b/templates/native/unicode.c Mon Feb 13 21:26:38 2017 +0100
18.3 @@ -72,11 +72,14 @@
18.4 __attr __fn_native_unicode_unicode_len(__attr __args[])
18.5 {
18.6 __attr * const _data = &__args[1];
18.7 + __attr * const _size = &__args[2];
18.8 /* _data interpreted as string */
18.9 char *s = _data->strvalue;
18.10 + /* _size interpreted as int */
18.11 + int size = _size->intvalue;
18.12 unsigned int i, c = 0;
18.13
18.14 - for (i = 0; s[i] != 0; i++)
18.15 + for (i = 0; i < size; i++)
18.16 if (boundary(s[i]))
18.17 c++;
18.18
18.19 @@ -87,11 +90,14 @@
18.20 __attr __fn_native_unicode_unicode_ord(__attr __args[])
18.21 {
18.22 __attr * const _data = &__args[1];
18.23 + __attr * const _size = &__args[2];
18.24 /* _data interpreted as string */
18.25 char *s = _data->strvalue;
18.26 + /* _size interpreted as int */
18.27 + int size = _size->intvalue;
18.28 unsigned int i, c = 0, v;
18.29
18.30 - for (i = 0; s[i] != 0; i++)
18.31 + for (i = 0; i < size; i++)
18.32 {
18.33 /* Evaluate the current character as a boundary. */
18.34
18.35 @@ -120,11 +126,14 @@
18.36 __attr __fn_native_unicode_unicode_substr(__attr __args[])
18.37 {
18.38 __attr * const _data = &__args[1];
18.39 - __attr * const start = &__args[2];
18.40 - __attr * const end = &__args[3];
18.41 - __attr * const step = &__args[4];
18.42 + __attr * const _size = &__args[2];
18.43 + __attr * const start = &__args[3];
18.44 + __attr * const end = &__args[4];
18.45 + __attr * const step = &__args[5];
18.46 /* _data interpreted as string */
18.47 char *s = _data->strvalue, *sub;
18.48 + /* _size interpreted as int */
18.49 + int ss = _size->intvalue;
18.50 /* start.__data__ interpreted as int */
18.51 int istart = __load_via_object(start->value, __pos___data__).intvalue;
18.52 /* end.__data__ interpreted as int */
18.53 @@ -137,7 +146,7 @@
18.54 unsigned int indexes[nchar];
18.55
18.56 unsigned int c, d, i, to, from, lastbyte = 0;
18.57 - size_t resultsize = 0, ss = strlen(_data->strvalue);
18.58 + int resultsize = 0;
18.59
18.60 /* Find the indexes of the characters. */
18.61 if (istep > 0)
18.62 @@ -190,7 +199,7 @@
18.63 } while (!boundary(s[from]));
18.64 }
18.65
18.66 - return __new_str(sub);
18.67 + return __new_str(sub, resultsize);
18.68 }
18.69
18.70 /* Module initialisation. */