diff options
-rw-r--r-- | ChangeLog | 18 | ||||
-rw-r--r-- | HACKING | 57 | ||||
-rwxr-xr-x | configure | 26 | ||||
-rw-r--r-- | lib.h | 5 |
4 files changed, 60 insertions, 46 deletions
@@ -1,5 +1,23 @@ 2015-01-12 Kaz Kylheku <kaz@kylheku.com> + Fix for LLVM wchar_t literals not being four byte + aligned, affecting OS X port. + + * configure: Detect a SIZEOF_WCHAR_T when detecting integer + type that will hold a pointer. In the lit_align test, + if we are on Apple Mac OSX, use a lit_align of 2, + so the logic kicks in for padding literals and handling + misalignment. + + * lib.h (litptr): Add a case for LIT_ALIGN < 4 and + SIZEOF_WCHAR_T == 4. In this case we do the arithmetic + on the pointer using short *, and then convert to + wchar_t. + + * HACKING: New section 2.4.3 about new wchar_t hack. + +2015-01-12 Kaz Kylheku <kaz@kylheku.com> + * signal.h (sig_save_enable, sig_save_disable): Use do;while(0) trick instead of local typedef to cause terminating semicolon to be required. @@ -1,8 +1,3 @@ - Txr Internals Guide - Kaz Kylheku <kaz@kylheku.com> - -CONTENTS: - SECTION LINE 0. Overview 47 @@ -22,26 +17,27 @@ SECTION LINE 2.3 The COBJ type 288 2.4 Strings 305 2.4.1 Encapsulated C Strings 320 -2.4.2 Representation Hacks for 2 Byte wchar_t 364 - -3. Garbage Collection 423 -3.1 Root Pointers 441 -3.2 GC-safe Code 464 -3.2.1 Rule One: Full Initialization 490 -3.2.2 Rule Two: Make it Reachable 519 -3.3 Weak Reference Support 654 -3.4 Finalization 697 -3.5 Generational GC 721 -3.5.2 Representation of Generations 730 -3.5.3 Basic Algorithm 766 -3.5.4 Handling Backpointers 801 -3.5.5 Generational GC and Finalization 879 - -4. Debugging 908 -4.2. Debugging the Yacc-generated Parser 1039 -4.3. Debugging GC Issues 1052 -4.4 Object Breakpoint 1075 -4.5 Valgrind: Your Friend 1094 +2.4.2 Representation Hacks for 2-byte wchar_t 364 +2.4.3 Representation hacks for 4-byte wchar_t that is 2-byte aligned 422 + +3. Garbage Collection 432 +3.1 Root Pointers 450 +3.2 GC-safe Code 473 +3.2.1 Rule One: Full Initialization 499 +3.2.2 Rule Two: Make it Reachable 528 +3.3 Weak Reference Support 663 +3.4 Finalization 706 +3.5 Generational GC 730 +3.5.2 Representation of Generations 739 +3.5.3 Basic Algorithm 775 +3.5.4 Handling Backpointers 810 +3.5.5 Generational GC and Finalization 888 + +4. Debugging 917 +4.2. Debugging the Yacc-generated Parser 1048 +4.3. Debugging GC Issues 1061 +4.4 Object Breakpoint 1084 +4.5 Valgrind: Your Friend 1103 0. Overview @@ -361,7 +357,7 @@ string. Note that it is okay if garbage objects contain auto_str values, which refer to strings that no longer exist, because the garbage collector will recognize these pointers by their type tag and not use them. -2.4.2 Representation Hacks for 2 Byte wchar_t +2.4.2 Representation Hacks for 2-byte wchar_t On some systems (notably Cygwin), the wide character type wchar_t is only two bytes wide, and the alignment of string literals and arrays is two @@ -419,6 +415,15 @@ The wref macro hides the displacement of the first character: On a platform where this hack isn't needed, these w* macros are no-ops. +2.4.3 Representation hacks for 4-byte wchar_t that is 2-byte aligned + +On the LLVM compiler on OS X, I ran into the issue that although wchar_t +is four byte aligned, the compiler neglects to make wide string literals +four byte aligned. Cases occur of misaligned literals. + +The solution is to borrow some of the logic that is used for handling +two-byte wchar_t. The data is similarly padded, and an adjustment calculation +takes place similarly to recover the pointer. 3. Garbage Collection @@ -1083,6 +1083,7 @@ read_syms() if [ -z "$intptr" ] ; then cat > conftest.c <<! +#include <stddef.h> #include "config.h" #ifdef HAVE_SUPERLONG_T char SIZEOF_SUPERLONG_T[sizeof (superlong_t)]; @@ -1094,6 +1095,7 @@ char SIZEOF_PTR[sizeof (char *)]; char SIZEOF_LONG[sizeof (long)]; char SIZEOF_INT[sizeof (int)]; char SIZEOF_SHORT[sizeof (short)]; +char SIZEOF_WCHAR_T[sizeof (wchar_t)]; char DUMMY; ! if ! conftest_syms ; then @@ -1176,30 +1178,16 @@ fi printf "Conservatively guessing the alignment of wide literals ... " if [ -z "$lit_align" ] ; then - cat > conftest.c <<! -#include <wchar.h> -char SIZEOF_WCHAR_T[sizeof (wchar_t)]; -char DUMMY; -! - if ! conftest_syms ; then - printf "failed\n\n" - - printf "Errors from compilation: \n\n" - cat conftest.err - exit 1 - fi - - SIZEOF_WCHAR_T=0 - deferred_offset= - - read_syms - if [ $SIZEOF_WCHAR_T -eq 0 ] ; then printf "failed\n" exit 1 fi - lit_align=$SIZEOF_WCHAR_T + if [ -n "$need_darwin_c_source" ] ; then + lit_align=2 + else + lit_align=$SIZEOF_WCHAR_T + fi fi printf "%d\n" "$lit_align" @@ -327,9 +327,12 @@ INLINE val static_str(const wchli_t *str) INLINE wchar_t *litptr(val obj) { -#if LIT_ALIGN < 4 +#if LIT_ALIGN < 4 && SIZEOF_WCHAR_T < 4 wchar_t *ret = coerce(wchar_t *, (coerce(cnum, obj) & ~TAG_MASK)); return (*ret == 0) ? ret + 1 : ret; +#elif LIT_ALIGN < 4 && SIZEOF_WCHAR_T == 4 + short *ret = coerce(short *, (coerce(cnum, obj) & ~TAG_MASK)); + return coerce(wchar_t *, (*ret == 0) ? ret + 1 : ret); #else return coerce(wchar_t *, coerce(cnum, obj) & ~TAG_MASK); #endif |