# HG changeset patch # User Paul Boddie # Date 1636065869 -3600 # Node ID 1e7ccc84119f6b71d82aaf2d697627364b8b711f # Parent 50706c4011d47d7d3cf9181e43168fabe82d1075# Parent 16ecb996eb96c54f414d3201ae2a20b250655917 Merged changes from the default branch. diff -r 50706c4011d4 -r 1e7ccc84119f generator.py --- a/generator.py Tue Nov 02 00:05:23 2021 +0100 +++ b/generator.py Thu Nov 04 23:44:29 2021 +0100 @@ -1066,7 +1066,7 @@ # Special internal size member. elif attrname == "__size__": - structure.append("__INTVALUE(%d)" % attr) + structure.append("{.sizevalue=%d}" % attr) continue # Special internal key member. diff -r 50706c4011d4 -r 1e7ccc84119f lib/__builtins__/str.py --- a/lib/__builtins__/str.py Tue Nov 02 00:05:23 2021 +0100 +++ b/lib/__builtins__/str.py Thu Nov 04 23:44:29 2021 +0100 @@ -24,7 +24,7 @@ from __builtins__.types import check_int from native import isinstance as _isinstance, \ str_add, str_lt, str_gt, str_eq, str_ord, \ - str_substr + str_size, str_substr WHITESPACE = (" ", "\f", "\n", "\r", "\t") @@ -54,7 +54,7 @@ else: self.__data__ = None self.__key__ = None - self.__size__ = 0 + self.__size__ = None # Internal methods. @@ -158,7 +158,7 @@ "Return the number of bytes in this string." - return self.__size__ + return str_size(self.__size__) # General type methods. @@ -166,7 +166,7 @@ "Return whether the string provides any data." - return self.__size__.__bool__() + return str_size(self.__size__).__bool__() def __contains__(self, value): diff -r 50706c4011d4 -r 1e7ccc84119f lib/native/__init__.py --- a/lib/native/__init__.py Tue Nov 02 00:05:23 2021 +0100 +++ b/lib/native/__init__.py Thu Nov 04 23:44:29 2021 +0100 @@ -3,7 +3,7 @@ """ Native library functions. -Copyright (C) 2011, 2015, 2016, 2017, 2018 Paul Boddie +Copyright (C) 2011, 2015-2018, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -51,7 +51,7 @@ from native.program import get_using from native.str import str_add, str_chr, str_eq, str_gt, str_lt, \ - str_ord, str_substr + str_ord, str_size, str_substr from native.system import exit, get_argv, get_path diff -r 50706c4011d4 -r 1e7ccc84119f lib/native/str.py --- a/lib/native/str.py Tue Nov 02 00:05:23 2021 +0100 +++ b/lib/native/str.py Thu Nov 04 23:44:29 2021 +0100 @@ -8,7 +8,7 @@ non-core exceptions used by the native functions because they need to be identified as being needed by the program. -Copyright (C) 2011, 2015, 2016, 2017 Paul Boddie +Copyright (C) 2011, 2015, 2016, 2017, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -32,6 +32,7 @@ def str_gt(data, other_data): return True or False def str_lt(data, other_data): return True or False def str_ord(data): return 0 +def str_size(size): return 0 def str_substr(data, start, end, step): return "" # vim: tabstop=4 expandtab shiftwidth=4 diff -r 50706c4011d4 -r 1e7ccc84119f templates/native/buffer.c --- a/templates/native/buffer.c Tue Nov 02 00:05:23 2021 +0100 +++ b/templates/native/buffer.c Thu Nov 04 23:44:29 2021 +0100 @@ -36,7 +36,7 @@ /* Calculate the size of the string. */ for (i = 0; i < data->size; i++) - size += __TOINT(__load_via_object(__VALUE(data->attrs[i]), __size__)); + size += __load_via_object(__VALUE(data->attrs[i]), __size__).sizevalue; /* Reserve space for a new string. */ s = (char *) __ALLOCATE(size + 1, sizeof(char)); @@ -45,7 +45,7 @@ for (i = 0, j = 0; i < data->size; i++) { o = __load_via_object(__VALUE(data->attrs[i]), __data__); - n = __TOINT(__load_via_object(__VALUE(data->attrs[i]), __size__)); + n = __load_via_object(__VALUE(data->attrs[i]), __size__).sizevalue; memcpy(s + j, o.strvalue, n); /* does not null terminate but final byte should be zero */ j += n; } diff -r 50706c4011d4 -r 1e7ccc84119f templates/native/common.c --- a/templates/native/common.c Tue Nov 02 00:05:23 2021 +0100 +++ b/templates/native/common.c Thu Nov 04 23:44:29 2021 +0100 @@ -31,7 +31,7 @@ /* Create a new string and mutate the __data__, __size__ and __key__ attributes. */ __attr attr = __NEWINSTANCE(__builtins___str_str); __store_via_object(__VALUE(attr), __data__, (__attr) {.strvalue=s}); - __store_via_object(__VALUE(attr), __size__, __INTVALUE(size)); + __store_via_object(__VALUE(attr), __size__, (__attr) {.sizevalue=size}); __store_via_object(__VALUE(attr), __key__, __NULL); return attr; } diff -r 50706c4011d4 -r 1e7ccc84119f templates/native/io.c --- a/templates/native/io.c Tue Nov 02 00:05:23 2021 +0100 +++ b/templates/native/io.c Thu Nov 04 23:44:29 2021 +0100 @@ -150,7 +150,7 @@ /* str.__data__ interpreted as string */ char *s = __load_via_object(__VALUE(str), __data__).strvalue; /* str.__size__ interpreted as int */ - size_t to_write = __TOINT(__load_via_object(__VALUE(str), __size__)); + size_t to_write = __load_via_object(__VALUE(str), __size__).sizevalue; size_t have_written = fwrite(s, sizeof(char), to_write, f); int error; @@ -207,7 +207,7 @@ /* str.__data__ interpreted as string */ char *s = __load_via_object(__VALUE(str), __data__).strvalue; /* str.__size__ interpreted as int */ - size_t size = __TOINT(__load_via_object(__VALUE(str), __size__)); + size_t size = __load_via_object(__VALUE(str), __size__).sizevalue; ssize_t have_written; errno = 0; diff -r 50706c4011d4 -r 1e7ccc84119f templates/native/str.c --- a/templates/native/str.c Tue Nov 02 00:05:23 2021 +0100 +++ b/templates/native/str.c Thu Nov 04 23:44:29 2021 +0100 @@ -33,8 +33,8 @@ /* _data, other interpreted as string.__data__ */ char *s = _data.strvalue; char *o = other.strvalue; - /* _size, othersize interpreted as int */ - __int ss = __TOINT(_size), os = __TOINT(othersize); + /* _size, othersize interpreted as size */ + __int ss = _size.sizevalue, os = othersize.sizevalue; __int n = ss + os; char *r = (char *) __ALLOCATE(n + 1, sizeof(char)); @@ -93,6 +93,11 @@ return __new_int((__int) s[0]); } +__attr __fn_native_str_str_size(__attr __self, __attr _size) +{ + return __new_int(_size.sizevalue); +} + __attr __fn_native_str_str_substr(__attr __self, __attr _data, __attr start, __attr end, __attr step) { /* _data interpreted as string.__data__ */ diff -r 50706c4011d4 -r 1e7ccc84119f templates/native/str.h --- a/templates/native/str.h Tue Nov 02 00:05:23 2021 +0100 +++ b/templates/native/str.h Thu Nov 04 23:44:29 2021 +0100 @@ -1,6 +1,6 @@ /* Native functions for string operations. -Copyright (C) 2016, 2017 Paul Boddie +Copyright (C) 2016, 2017, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -27,6 +27,7 @@ __attr __fn_native_str_str_gt(__attr __self, __attr _data, __attr other); __attr __fn_native_str_str_eq(__attr __self, __attr _data, __attr other); __attr __fn_native_str_str_ord(__attr __self, __attr _data); +__attr __fn_native_str_str_size(__attr __self); __attr __fn_native_str_str_substr(__attr __self, __attr _data, __attr start, __attr end, __attr step); /* Module initialisation. */ diff -r 50706c4011d4 -r 1e7ccc84119f templates/native/unicode.c --- a/templates/native/unicode.c Tue Nov 02 00:05:23 2021 +0100 +++ b/templates/native/unicode.c Thu Nov 04 23:44:29 2021 +0100 @@ -73,8 +73,8 @@ { /* _data interpreted as string.__data__ */ char *s = _data.strvalue; - /* _size interpreted as int */ - __int size = __TOINT(_size); + /* _size interpreted as size */ + __int size = _size.sizevalue; __int i, c = 0; for (i = 0; i < size; i++) @@ -89,8 +89,8 @@ { /* _data interpreted as string.__data__ */ char *s = _data.strvalue; - /* _size interpreted as int */ - __int size = __TOINT(_size); + /* _size interpreted as size */ + __int size = _size.sizevalue; __int i, c = 0, v; for (i = 0; i < size; i++) @@ -123,8 +123,8 @@ { /* _data interpreted as string.__data__ */ char *s = _data.strvalue, *sub; - /* _size interpreted as int */ - __int ss = __TOINT(_size); + /* _size interpreted as size */ + __int ss = _size.sizevalue; /* start interpreted as int */ __int istart = __TOINT(start); /* end interpreted as int */ diff -r 50706c4011d4 -r 1e7ccc84119f templates/types.h --- a/templates/types.h Tue Nov 02 00:05:23 2021 +0100 +++ b/templates/types.h Thu Nov 04 23:44:29 2021 +0100 @@ -1,7 +1,6 @@ /* Runtime types. -Copyright (C) 2015, 2016, 2017, 2018, 2019, - 2021 Paul Boddie +Copyright (C) 2015-2019, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -72,8 +71,7 @@ typedef union __attr __attr; typedef __obj * __ref; -/* Introduce an integer type that should not exceed the size of the pointer - type. */ +/* Introduce an integer type that is interoperable with the size type. */ typedef ssize_t __int; @@ -97,6 +95,7 @@ char * strvalue; /* string value */ __fragment * seqvalue; /* sequence data */ void * datavalue; /* object-specific data */ + __int sizevalue; /* object-specific size */ } __attr; typedef struct __obj