Three patches for 0.9.14
NIIBE Yutaka <[email protected]> Thu, 04 Apr 2024 12:09:36 +0900
| Newsgroups | gmane.lisp.scheme.gauche |
|---|---|
| Message-ID | <[email protected]> |
Hello, Thanks to Jens Thiele, Gauche is now again available in Debian (0.9.14-5). For building other architectures, I needed to apply following two patches. (1) Alignment for ScmExtendedPairDescriptor Some architectures (like armel/armhf/hppa/powerpc), with current GCC 13.2, the alignment for the variables is 4, instead of 8 (which the code assumed). So, I added required alignment manually. FYI, the specific error I saw was: "../../src/gosh" -ftest "../../lib/tools/precomp" -e -P -o util--match ../../libsrc/util/match.scm "list.c", line 827 (Scm__GetExtendedPairDescriptor): Assertion failed: (z->hiddenTag&0x7) == 0x7 https://buildd.debian.org/status/fetch.php?pkg=gauche&arch=armel&ver=0.9.14-2&stamp=1711974777&raw=0 (2) Signed integer addtion overflow is not portable According to "C, A Reference Mmanual", in 7.2.2 Overflow and Other Arithmetic Exceptions, signed integer overflow is undefined. For some architectures (like armel/armhf/hppa), with current GCC 13.2, signed integer overflow causes a problem in uniform vector implementation. So, I changed the computation with unsigned integer addition. FYI, the specific error I saw was: make[3]: Entering directory '/<<PKGBUILDDIR>>/ext/uvector' GAUCHE_TEST_RECORD_FILE="../../test.record" "../../src/gosh" -ftest -I"." -I. "./test.scm" > test.log Testing uniform vector and array ... failed. 3 discrepancies found: test s32vector-dot(#s32(32767 32767 32767 32767 32767), #s32(32767 32767 32767 32767 32767)): expects 5368381445 => got 1073414149 test s32vector-dot(#s32(32767 32767 32767 32767 32767), (32767 32767 32767 32767 32767)): expects 5368381445 => got 1073414149 test s32vector-dot(#s32(32767 32767 32767 32767 32767), #(32767 32767 32767 32767 32767)): expects 5368381445 => got 1073414149 m https://buildd.debian.org/status/fetch.php?pkg=gauche&arch=armel&ver=0.9.14-3&stamp=1712107656&raw=0 I don't think those patches are good enough to merge. Rather, those are basically for building Debian packages. For (1), I'm afraid it is GCC specific. I don't know portable way to specify the alignment. For (2), while it works, having the specific type "long" for SADDOV would not be good or would not look clean (when it will be used for other types than "long"). Still it works to point out the issues, and to be a starting point for real good fixes, hopefully. And I think that this fix is worth to apply. (3) ESCAPE_BUF_MAX constant should be 12 FYI, the specific error I saw was: string.c: In function ‘string_putc’: string.c:1507:57: warning: ‘;’ directive output may be truncated writing 1 byte into a region of size between 0 and 3 [-Wformat-truncation=] 1507 | snprintf(buf, ESCAPE_BUF_MAX, "\\x%x;", (u_int)ch); | ^ In file included from /usr/include/stdio.h:906, from gauche.h:67, from string.c:35: In function ‘snprintf’, inlined from ‘string_putc’ at string.c:1507:21: /usr/include/arm-linux-gnueabi/bits/stdio2.h:54:10: note: ‘__builtin___snprintf_chk’ output between 9 and 12 bytes into a destination of size 10 54 | return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 55 | __glibc_objsize (__s), __fmt, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 56 | __va_arg_pack ()); | ~~~~~~~~~~~~~~~~~ -- _______________________________________________ Gauche-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/gauche-devel
50_extended_pair_alignment.patch
(text/x-diff, 833 B)
diff --git a/src/list.c b/src/list.c
index 8933462..4cb535f 100644
--- a/src/list.c
+++ b/src/list.c
@@ -807,7 +807,7 @@ static ScmObj make_extended_pair(ScmExtendedPairDescriptor *desc,
Windows. To avoid complication, we initialize the klass field in
_Init() routine.
*/
-static ScmExtendedPairDescriptor mpair_desc = {
+static ScmExtendedPairDescriptor mpair_desc __attribute__ ((aligned (8))) = {
NULL, /* will be SCM_CLASS_PAIR */
0,
NULL,
@@ -912,7 +912,7 @@ int Scm_ImmutablePairP(ScmObj obj)
return d->flags & SCM_PAIR_IMMUTABLE;
}
-static ScmExtendedPairDescriptor ipair_desc = {
+static ScmExtendedPairDescriptor ipair_desc __attribute__ ((aligned (8))) = {
NULL, /* will be SCM_CLASS_PAIR. see above. */
SCM_PAIR_IMMUTABLE,
NULL,
51_signed_overflow.patch
(text/x-diff, 571 B)
diff --git a/src/gauche/priv/arith.h b/src/gauche/priv/arith.h
index bcb9d17..5d02bb5 100644
--- a/src/gauche/priv/arith.h
+++ b/src/gauche/priv/arith.h
@@ -116,7 +116,7 @@
/* Portable version */
#define SADDOV(r, v, x, y) \
do { \
- (r) = (x) + (y); \
+ (r) = (long)((unsigned long)(x) + (unsigned long)(y)); \
if ((x) >= 0) { \
if ((y) >= 0 && (r) < 0) (v) = 1; \
else (v) = 0; \
gauche-escape-buf-max-fix.diff
(text/x-diff, 501 B)
diff --git a/src/string.c b/src/string.c
index fd71543..17b3af4 100644
--- a/src/string.c
+++ b/src/string.c
@@ -1474,7 +1474,7 @@ char **Scm_ListToCStringArray(ScmObj lis, int errp, void *(*alloc)(size_t))
/* ch is single byte if bytemode is true */
static inline void string_putc(ScmChar ch, ScmPort *port, int bytemode)
{
- const int ESCAPE_BUF_MAX = 10;
+ const int ESCAPE_BUF_MAX = 12;
char buf[ESCAPE_BUF_MAX];
switch (ch) {
case '\\': SCM_PUTZ("\\\\", -1, port); break;