chicken-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-hackers] [PATCH] cast char to unsigned when creating character


From: Felix
Subject: [Chicken-hackers] [PATCH] cast char to unsigned when creating character value
Date: Tue, 21 Feb 2012 11:30:56 +0100 (CET)

The attached patch casts the argument to C_uword in C_make_character,
as suggested by Joerg Wittenberger and Alan Post to avoid default
char-signedness issues. Whether this is a genuine problem is not clear
to me, but not doing so results in code (at least in gcc) that triggers
a warning in valgrind on 64-bit systems due to uninitialized memory,
caused by irrational optimization efforts done by contemporary C
compilers.


cheers,
felix

>From 89143cd64f90e9bd8241b455139de48a77fa2d8b Mon Sep 17 00:00:00 2001
From: felix <address@hidden>
Date: Fri, 13 Jan 2012 18:47:48 +0100
Subject: [PATCH] Ensure character is extended to full word-length. This doesn't 
make
 much of a difference semantically, but avoids a warning with
 valgrind(1) on 64-bit platforms: gcc stores a character argument using
 a 32-bit "mov" instruction into the stackframe, keeping the upper half
 uninitialized.

The argument value of "C_make_character" is cast to "C_uword", which
was once suggested by Joerg Wittenberger and Alan Post to ensure that
the default sign of characters (which may be different, depending on
the compiler and platform) does not influence any character
operations.
---
 chicken.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/chicken.h b/chicken.h
index fdf4b72..58d7533 100644
--- a/chicken.h
+++ b/chicken.h
@@ -955,7 +955,7 @@ extern double trunc(double);
 #define C_demand_2(n)              (((C_word *)C_fromspace_top + (n)) < 
(C_word *)C_fromspace_limit)
 #define C_fix(n)                   (((C_word)(n) << C_FIXNUM_SHIFT) | 
C_FIXNUM_BIT)
 #define C_unfix(x)                 ((x) >> C_FIXNUM_SHIFT)
-#define C_make_character(c)        ((((c) & C_CHAR_BIT_MASK) << C_CHAR_SHIFT) 
| C_CHARACTER_BITS)
+#define C_make_character(c)        (((((C_uword)(c)) & C_CHAR_BIT_MASK) << 
C_CHAR_SHIFT) | C_CHARACTER_BITS)
 #define C_character_code(x)        (((C_word)(x) >> C_CHAR_SHIFT) & 
C_CHAR_BIT_MASK)
 #define C_flonum_magnitude(x)      (*((double *)(((C_SCHEME_BLOCK 
*)(x))->data)))
 #define C_c_string(x)              ((C_char *)(((C_SCHEME_BLOCK *)(x))->data))
-- 
1.6.0.4


reply via email to

[Prev in Thread] Current Thread [Next in Thread]