diff: runtime/mercury_grade.h portability fix
Fergus Henderson
fjh at cs.mu.OZ.AU
Sat Sep 5 07:12:34 AEST 1998
runtime/mercury_grade.h:
Fix a portability problem reported by Chris Higgins:
the code was doing token pasting on empty macros.
This is undefined behaviour, according to the C standard.
Index: runtime/mercury_grade.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_grade.h,v
retrieving revision 1.12
diff -u -r1.12 mercury_grade.h
--- mercury_grade.h 1998/07/26 08:38:34 1.12
+++ mercury_grade.h 1998/09/04 20:38:20
@@ -33,12 +33,6 @@
#define MR_PASTE2(p1,p2) MR_PASTE2_2(p1,p2)
#define MR_PASTE2_2(p1,p2) p1##p2
-/* paste 13 macros together */
-#define MR_PASTE13(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12) \
- MR_PASTE13_2(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12)
-#define MR_PASTE13_2(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12) \
- p0##p1##p2##p3##p4##p5##p6##p7##p8##p9##p10##p11##p12
-
/*
** Here we build up the MR_GRADE macro part at a time,
** based on the compilation flags.
@@ -50,44 +44,44 @@
#define MR_GRADE_PART_0 redofr_
#ifdef USE_ASM_LABELS
- #define MR_GRADE_PART_1 asm_
+ #define MR_GRADE_PART_1 MR_PASTE2(MR_GRADE_PART_0, asm_)
#else
- #define MR_GRADE_PART_1
+ #define MR_GRADE_PART_1 MR_GRADE_PART_0
#endif
#ifdef USE_GCC_NONLOCAL_GOTOS
#ifdef USE_GCC_GLOBAL_REGISTERS
- #define MR_GRADE_PART_2 fast
+ #define MR_GRADE_PART_2 MR_PASTE2(MR_GRADE_PART_1, fast)
#else
- #define MR_GRADE_PART_2 jump
+ #define MR_GRADE_PART_2 MR_PASTE2(MR_GRADE_PART_1, jump)
#endif
#else
#ifdef USE_GCC_GLOBAL_REGS
- #define MR_GRADE_PART_2 reg
+ #define MR_GRADE_PART_2 MR_PASTE2(MR_GRADE_PART_1, reg)
#else
- #define MR_GRADE_PART_2 none
+ #define MR_GRADE_PART_2 MR_PASTE2(MR_GRADE_PART_1, none)
#endif
#endif
#ifdef MR_THREAD_SAFE
- #define MR_GRADE_PART_3 _par
+ #define MR_GRADE_PART_3 MR_PASTE2(MR_GRADE_PART_2, _par)
#else
- #define MR_GRADE_PART_3
+ #define MR_GRADE_PART_3 MR_GRADE_PART_2
#endif
#ifdef CONSERVATIVE_GC
- #define MR_GRADE_PART_4 _gc
+ #define MR_GRADE_PART_4 MR_PASTE2(MR_GRADE_PART_3, _gc)
#elif defined(NATIVE_GC)
- #define MR_GRADE_PART_4 _agc
+ #define MR_GRADE_PART_4 MR_PASTE2(MR_GRADE_PART_3, _agc)
#else
- #define MR_GRADE_PART_4
+ #define MR_GRADE_PART_4 MR_GRADE_PART_3
#endif
#ifdef PROFILE_TIME
#ifdef PROFILE_CALLS
#ifdef PROFILE_MEMORY
- #define MR_GRADE_PART_5 _profall
+ #define MR_GRADE_PART_5 MR_PASTE2(MR_GRADE_PART_4, _profall)
#else
- #define MR_GRADE_PART_5 _prof
+ #define MR_GRADE_PART_5 MR_PASTE2(MR_GRADE_PART_4, _prof)
#endif
#else
#ifdef PROFILE_MEMORY
@@ -98,15 +92,15 @@
#error "Invalid combination of profiling options"
#else
/* Currently useless, but... */
- #define MR_GRADE_PART_5 _proftime
+ #define MR_GRADE_PART_5 MR_PASTE2(MR_GRADE_PART_4, _proftime)
#endif
#endif
#else
#ifdef PROFILE_CALLS
#ifdef PROFILE_MEMORY
- #define MR_GRADE_PART_5 _memprof
+ #define MR_GRADE_PART_5 MR_PASTE2(MR_GRADE_PART_4, _memprof)
#else
- #define MR_GRADE_PART_5 _profcalls
+ #define MR_GRADE_PART_5 MR_PASTE2(MR_GRADE_PART_4, _profcalls)
#endif
#else
#ifdef PROFILE_MEMORY
@@ -117,47 +111,49 @@
*/
#error "Invalid combination of profiling options"
#else
- #define MR_GRADE_PART_5
+ #define MR_GRADE_PART_5 MR_GRADE_PART_4
#endif
#endif
#endif
#ifdef MR_USE_TRAIL
- #define MR_GRADE_PART_6 _tr
+ #define MR_GRADE_PART_6 MR_PASTE2(MR_GRADE_PART_5, _tr)
#else
- #define MR_GRADE_PART_6
+ #define MR_GRADE_PART_6 MR_GRADE_PART_5
#endif
#if TAGBITS == 0
- #define MR_GRADE_PART_7 _notags
+ #define MR_GRADE_PART_7 MR_PASTE2(MR_GRADE_PART_6, _notags)
#elif defined(HIGHTAGS)
- #define MR_GRADE_PART_7 MR_PASTE2(_hightags, TAGBITS)
+ #define MR_GRADE_PART_7 MR_PASTE2(MR_GRADE_PART_6, \
+ MR_PASTE2(_hightags, TAGBITS))
#else
- #define MR_GRADE_PART_7 MR_PASTE2(_tags, TAGBITS)
+ #define MR_GRADE_PART_7 MR_PASTE2(MR_GRADE_PART_6, \
+ MR_PASTE2(_tags, TAGBITS))
#endif
#ifdef BOXED_FLOAT
- #define MR_GRADE_PART_8
+ #define MR_GRADE_PART_8 MR_GRADE_PART_7
#else /* "ubf" stands for "unboxed float" */
- #define MR_GRADE_PART_8 _ubf
+ #define MR_GRADE_PART_8 MR_PASTE2(MR_GRADE_PART_7, _ubf)
#endif
#ifdef COMPACT_ARGS
- #define MR_GRADE_PART_9
+ #define MR_GRADE_PART_9 MR_GRADE_PART_8
#else /* "sa" stands for "simple args" */
- #define MR_GRADE_PART_9 _sa
+ #define MR_GRADE_PART_9 MR_PASTE2(MR_GRADE_PART_8, _sa)
#endif
#ifndef MR_DEBUG_NONDET_STACK
- #define MR_GRADE_PART_10
+ #define MR_GRADE_PART_10 MR_GRADE_PART_9
#else
- #define MR_GRADE_PART_10 _debugNDS
+ #define MR_GRADE_PART_10 MR_PASTE2(MR_GRADE_PART_9, _debugNDS)
#endif
#if defined(PIC_REG) && defined(USE_GCC_GLOBAL_REGISTERS) && defined(__i386__)
- #define MR_GRADE_PART_11 _picreg
+ #define MR_GRADE_PART_11 MR_PASTE2(MR_GRADE_PART_10, _picreg)
#else
- #define MR_GRADE_PART_11
+ #define MR_GRADE_PART_11 MR_GRADE_PART_10
#endif
/*
@@ -169,33 +165,19 @@
*/
#if defined(MR_STACK_TRACE)
#if defined(MR_REQUIRE_TRACING)
- #define MR_GRADE_PART_12 _debug
+ #define MR_GRADE_PART_12 MR_PASTE2(MR_GRADE_PART_11, _debug)
#else
- #define MR_GRADE_PART_12 _strce
+ #define MR_GRADE_PART_12 MR_PASTE2(MR_GRADE_PART_11, _strce)
#endif
#else
#if defined(MR_REQUIRE_TRACING)
- #define MR_GRADE_PART_12 _trace
+ #define MR_GRADE_PART_12 MR_PASTE2(MR_GRADE_PART_11, _trace)
#else
- #define MR_GRADE_PART_12
+ #define MR_GRADE_PART_12 MR_GRADE_PART_11
#endif
#endif
-#define MR_GRADE MR_PASTE13( \
- MR_GRADE_PART_0, \
- MR_GRADE_PART_1, \
- MR_GRADE_PART_2, \
- MR_GRADE_PART_3, \
- MR_GRADE_PART_4, \
- MR_GRADE_PART_5, \
- MR_GRADE_PART_6, \
- MR_GRADE_PART_7, \
- MR_GRADE_PART_8, \
- MR_GRADE_PART_9, \
- MR_GRADE_PART_10, \
- MR_GRADE_PART_11, \
- MR_GRADE_PART_12 \
- )
+#define MR_GRADE MR_GRADE_PART_12
#define MR_GRADE_VAR MR_PASTE2(MR_grade_,MR_GRADE)
#define MR_GRADE_STRING MR_STRINGIFY(MR_GRADE)
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
More information about the developers
mailing list