[CLN-list] [PATCH][cln_1-1] Replace (some of) MAYBE_INLINEs with ISO C++ compliant equivalent

Alexei Sheplyakov varg at theor.jinr.ru
Wed Jan 9 08:40:54 CET 2008


ISO C++ demands (in 7.1.2.4)
"If a function with external linkage is declared inline in one translation
unit, it shall be declared inline in all translation units in which it
appears; no diagnostic is required." MAYBE_INLINE violates this requirement.
Moreover, it's pointless, since the compiler emits those functions anyway.
This causes link errors on non-ELF platforms (such as woe32 and Darwin).
Hence, I decided to replace MAYBE_INLINE with standard compliant (but more
intrusive) code. Only fiew occurences of MAYBE_INLINE have been converted.
However, this happens to be enough to build CLN as a woe32 DLL (after
massive hacking of build scripts).

---
 src/complex/transcendental/cl_C_acosh.cc     |    7 ++++---
 src/complex/transcendental/cl_C_asinh_aux.cc |   11 ++++++-----
 src/complex/transcendental/cl_C_atanh_aux.cc |   10 ++++++----
 src/float/dfloat/misc/cl_DF_signum.cc        |    9 +++++++--
 src/float/ffloat/misc/cl_FF_signum.cc        |   10 ++++++++--
 src/float/lfloat/misc/cl_LF_signum.cc        |    9 +++++++--
 src/float/misc/cl_F_signum.cc                |   16 ++++++++++------
 src/float/sfloat/misc/cl_SF_signum.cc        |    9 +++++++--
 src/integer/misc/cl_I_signum.cc              |    9 +++++++--
 src/integer/ring/cl_I_ring.cc                |    5 ++++-
 src/rational/misc/cl_RA_signum.cc            |   10 ++++++++--
 src/rational/ring/cl_RA_ring.cc              |    5 ++++-
 src/real/conv/cl_F_from_R_def.cc             |    9 +++++++--
 src/real/misc/cl_R_signum.cc                 |   19 ++++++++++++++-----
 14 files changed, 99 insertions(+), 39 deletions(-)

diff --git a/src/complex/transcendental/cl_C_acosh.cc b/src/complex/transcendental/cl_C_acosh.cc
index 8c30669..f92989e 100644
--- a/src/complex/transcendental/cl_C_acosh.cc
+++ b/src/complex/transcendental/cl_C_acosh.cc
@@ -16,8 +16,9 @@
 #include "cl_RA.h"
 #include "cln/float.h"
 
-#undef MAYBE_INLINE
-#define MAYBE_INLINE inline
+#define INLINE static inline
+#define INLINE_DECL(fcn) inline_ ## fcn
+#define REALLY_INLINE __attribute__((always_inline))
 #include "cl_F_from_R_def.cc"
 
 namespace cln {
@@ -78,7 +79,7 @@ const cl_N acosh (const cl_N& z)
 		}
 		if (x < cl_I(-1)) {
 			// x < -1
-			var cl_F xf = cl_float(x);
+			var cl_F xf = inline_cl_float(x);
 			var cl_F& x = xf;
 			// x Float <= -1
 			// log(sqrt(x^2-1)-x), ein Float >=0, Imaginдrteil pi
diff --git a/src/complex/transcendental/cl_C_asinh_aux.cc b/src/complex/transcendental/cl_C_asinh_aux.cc
index 572c722..9d772c6 100644
--- a/src/complex/transcendental/cl_C_asinh_aux.cc
+++ b/src/complex/transcendental/cl_C_asinh_aux.cc
@@ -16,8 +16,9 @@
 #include "cl_RA.h"
 #include "cln/float.h"
 
-#undef MAYBE_INLINE
-#define MAYBE_INLINE inline
+#define INLINE static inline
+#define INLINE_DECL(fcn) inline_ ## fcn
+#define REALLY_INLINE __attribute__((always_inline))
 #include "cl_F_from_R_def.cc"
 
 namespace cln {
@@ -89,7 +90,7 @@ const cl_C_R asinh (const cl_R& x, const cl_R& y)
 					return cl_C_R(0,scale_float(pi(),-1));
 				if (eq(y,-1)) // x=0, y=-1 -> v = -pi/2
 					return cl_C_R(0,-scale_float(pi(),-1));
-				yf = cl_float(y); // y in Float umwandeln
+				yf = inline_cl_float(y); // y in Float umwandeln
 			} else {
 				DeclareType(cl_RT,y);
 				// y Ratio
@@ -99,7 +100,7 @@ const cl_C_R asinh (const cl_R& x, const cl_R& y)
 					if (eq(numerator(y),-1)) // x=0, y=-1/2 -> v = -pi/6
 						return cl_C_R(0,-(pi()/6));
 				}
-				yf = cl_float(y); // y in Float umwandeln
+				yf = inline_cl_float(y); // y in Float umwandeln
 			}
 		} else {
 			DeclareType(cl_F,y);
@@ -135,7 +136,7 @@ const cl_C_R asinh (const cl_R& x, const cl_R& y)
 	}
 	if (eq(y,0)) {
 		// y=0
-		var cl_F xf = cl_float(x); // x in Float umwandeln
+		var cl_F xf = inline_cl_float(x); // x in Float umwandeln
 		var cl_F& x = xf;
 		// x Float
 		if (zerop(x))
diff --git a/src/complex/transcendental/cl_C_atanh_aux.cc b/src/complex/transcendental/cl_C_atanh_aux.cc
index 42cae75..90d5205 100644
--- a/src/complex/transcendental/cl_C_atanh_aux.cc
+++ b/src/complex/transcendental/cl_C_atanh_aux.cc
@@ -14,14 +14,16 @@
 #include "cl_F_tran.h"
 #include "cl_R.h"
 
-#undef MAYBE_INLINE
-#define MAYBE_INLINE inline
+#define INLINE static inline
+#define INLINE_DECL(fcn) inline_ ## fcn
+#define REALLY_INLINE __attribute__((always_inline))
 #include "cl_F_from_R_def.cc"
 
 namespace cln {
 
 // Hilfsfunktion fьr atanh und atan: u+iv := artanh(x+iy). Liefert cl_C_R(u,v).
 
+const cl_C_R atanh (const cl_R& x, const cl_R& y) __attribute__((flatten));
 const cl_C_R atanh (const cl_R& x, const cl_R& y)
 {
 // Methode:
@@ -56,7 +58,7 @@ const cl_C_R atanh (const cl_R& x, const cl_R& y)
 		// x=0 -> u=0, v=atan(X=1,Y=y) (Fall y=0 ist inbegriffen)
 		return cl_C_R(0, atan(1,y));
 	if (eq(y,0)) {
-		var cl_F xf = cl_float(x); // (float x)
+		var cl_F xf = inline_cl_float(x); // (float x)
 		var cl_F& x = xf;
 		// x Float
 		if (zerop(x))
@@ -92,7 +94,7 @@ const cl_C_R atanh (const cl_R& x, const cl_R& y)
 	var cl_F yf;
 	if (rationalp(x)) {
 		DeclareType(cl_RA,x);
-		yf = cl_float(y);
+		yf = inline_cl_float(y);
 		xf = cl_float(x,yf);
 	} else {
 		DeclareType(cl_F,x);
diff --git a/src/float/dfloat/misc/cl_DF_signum.cc b/src/float/dfloat/misc/cl_DF_signum.cc
index 3101a93..524ad8f 100644
--- a/src/float/dfloat/misc/cl_DF_signum.cc
+++ b/src/float/dfloat/misc/cl_DF_signum.cc
@@ -15,11 +15,16 @@
 #define MAYBE_INLINE inline
 #include "cl_DF_minusp.cc"
 #include "cl_DF_zerop.cc"
+#ifndef INLINE2
+#define INLINE2
+#define REALLY_INLINE2
+#define INLINE2_DECL(name) name
+#endif
 
 namespace cln {
 
-MAYBE_INLINE2
-const cl_DF signum (const cl_DF& x)
+INLINE2 const cl_DF INLINE2_DECL(signum) (const cl_DF& x) REALLY_INLINE2;
+INLINE2 const cl_DF INLINE2_DECL(signum) (const cl_DF& x)
 {
 	if (minusp(x)) { return cl_DF_minus1; } // x<0 -> -1.0
 	elif (zerop(x)) { return cl_DF_0; } // x=0 -> 0.0
diff --git a/src/float/ffloat/misc/cl_FF_signum.cc b/src/float/ffloat/misc/cl_FF_signum.cc
index 69cb60e..6816012 100644
--- a/src/float/ffloat/misc/cl_FF_signum.cc
+++ b/src/float/ffloat/misc/cl_FF_signum.cc
@@ -16,10 +16,16 @@
 #include "cl_FF_minusp.cc"
 #include "cl_FF_zerop.cc"
 
+#ifndef INLINE2
+#define INLINE2
+#define REALLY_INLINE2
+#define INLINE2_DECL(name) name
+#endif
+
 namespace cln {
 
-MAYBE_INLINE2
-const cl_FF signum (const cl_FF& x)
+INLINE2 const cl_FF INLINE2_DECL(signum) (const cl_FF& x) REALLY_INLINE2;
+INLINE2 const cl_FF INLINE2_DECL(signum) (const cl_FF& x)
 {
 	if (minusp(x)) { return cl_FF_minus1; } // x<0 -> -1.0
 	elif (zerop(x)) { return cl_FF_0; } // x=0 -> 0.0
diff --git a/src/float/lfloat/misc/cl_LF_signum.cc b/src/float/lfloat/misc/cl_LF_signum.cc
index eae4705..a0d31b1 100644
--- a/src/float/lfloat/misc/cl_LF_signum.cc
+++ b/src/float/lfloat/misc/cl_LF_signum.cc
@@ -16,11 +16,16 @@
 #define MAYBE_INLINE inline
 #include "cl_LF_minusp.cc"
 #include "cl_LF_zerop.cc"
+#ifndef INLINE2
+#define INLINE2
+#define REALLY_INLINE2
+#define INLINE2_DECL(name) name
+#endif
 
 namespace cln {
 
-MAYBE_INLINE2
-const cl_LF signum (const cl_LF& x)
+INLINE2 const cl_LF INLINE2_DECL(signum) (const cl_LF& x) REALLY_INLINE2;
+INLINE2 const cl_LF INLINE2_DECL(signum) (const cl_LF& x)
 {
 	if (zerop(x)) { return x; } // x=0 -> 0.0
 	else // je nach Vorzeichen von x
diff --git a/src/float/misc/cl_F_signum.cc b/src/float/misc/cl_F_signum.cc
index 0b51f9e..08ba0b6 100644
--- a/src/float/misc/cl_F_signum.cc
+++ b/src/float/misc/cl_F_signum.cc
@@ -11,8 +11,12 @@
 
 #include "cl_F.h"
 
-#undef MAYBE_INLINE2
-#define MAYBE_INLINE2 inline
+#undef INLINE2
+#undef INLINE2_DECL
+#undef REALLY_INLINE2
+#define INLINE2 static inline
+#define INLINE2_DECL(name) inline_ ## name
+#define REALLY_INLINE2 __attribute__((always_inline))
 #include "cl_SF_signum.cc"
 #include "cl_FF_signum.cc"
 #include "cl_DF_signum.cc"
@@ -23,10 +27,10 @@ namespace cln {
 const cl_F signum (const cl_F& x)
 {
 	floatcase(x
-	,	return signum(x);
-	,	return signum(x);
-	,	return signum(x);
-	,	return signum(x);
+	,	return inline_signum(x);
+	,	return inline_signum(x);
+	,	return inline_signum(x);
+	,	return inline_signum(x);
 	);
 }
 
diff --git a/src/float/sfloat/misc/cl_SF_signum.cc b/src/float/sfloat/misc/cl_SF_signum.cc
index b1239da..1374727 100644
--- a/src/float/sfloat/misc/cl_SF_signum.cc
+++ b/src/float/sfloat/misc/cl_SF_signum.cc
@@ -15,11 +15,16 @@
 #define MAYBE_INLINE inline
 #include "cl_SF_minusp.cc"
 #include "cl_SF_zerop.cc"
+#ifndef INLINE2
+#define INLINE2
+#define REALLY_INLINE2
+#define INLINE2_DECL(name) name
+#endif
 
 namespace cln {
 
-MAYBE_INLINE2
-const cl_SF signum (const cl_SF& x)
+INLINE2 const cl_SF INLINE2_DECL(signum) (const cl_SF& x) REALLY_INLINE2;
+INLINE2 const cl_SF INLINE2_DECL(signum) (const cl_SF& x)
 {
 	if (minusp(x)) { return SF_minus1; } // x<0 -> -1.0
 	elif (zerop(x)) { return SF_0; } // x=0 -> 0.0
diff --git a/src/integer/misc/cl_I_signum.cc b/src/integer/misc/cl_I_signum.cc
index bbd236a..7a8a8c9 100644
--- a/src/integer/misc/cl_I_signum.cc
+++ b/src/integer/misc/cl_I_signum.cc
@@ -10,11 +10,16 @@
 // Implementation.
 
 #include "cl_I.h"
+#ifndef INLINE
+#define INLINE
+#define REALLY_INLINE
+#define INLINE_DECL(name) name
+#endif
 
 namespace cln {
 
-MAYBE_INLINE
-const cl_I signum (const cl_I& x)
+INLINE const cl_I INLINE_DECL(signum) (const cl_I& x) REALLY_INLINE;
+INLINE const cl_I INLINE_DECL(signum) (const cl_I& x)
 {
 	if (minusp(x)) { return -1; } // x<0 -> -1
 	elif (zerop(x)) { return 0; } // x=0 -> 0
diff --git a/src/integer/ring/cl_I_ring.cc b/src/integer/ring/cl_I_ring.cc
index 0f4e6d7..c8538ef 100644
--- a/src/integer/ring/cl_I_ring.cc
+++ b/src/integer/ring/cl_I_ring.cc
@@ -13,7 +13,9 @@ CL_PROVIDE(cl_I_ring)
 
 #include "cln/integer.h"
 #include "cln/integer_io.h"
+#define zerop inline_zerop
 #include "cl_I.h"
+#undef zerop
 
 namespace cln {
 
@@ -34,10 +36,11 @@ static const _cl_ring_element I_zero (cl_heap_ring* R)
 	return _cl_ring_element(R, (cl_I)0);
 }
 
+static cl_boolean I_zerop (cl_heap_ring* R, const _cl_ring_element& x) __attribute__((flatten));
 static cl_boolean I_zerop (cl_heap_ring* R, const _cl_ring_element& x)
 {
 	unused R;
-	return zerop(The(cl_I)(x));
+	return inline_zerop(The(cl_I)(x));
 }
 
 static const _cl_ring_element I_plus (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
diff --git a/src/rational/misc/cl_RA_signum.cc b/src/rational/misc/cl_RA_signum.cc
index 40f5380..fc80077 100644
--- a/src/rational/misc/cl_RA_signum.cc
+++ b/src/rational/misc/cl_RA_signum.cc
@@ -11,11 +11,17 @@
 
 #include "cl_RA.h"
 #include "cl_I.h"
+#ifndef INLINE
+#define INLINE
+#define REALLY_INLINE
+#define INLINE_DECL(name) name
+#endif
+
 
 namespace cln {
 
-MAYBE_INLINE
-const cl_RA signum (const cl_RA& x)
+INLINE const cl_RA INLINE_DECL(signum) (const cl_RA& x) REALLY_INLINE;
+INLINE const cl_RA INLINE_DECL(signum) (const cl_RA& x)
 {
 	if (minusp(x)) { return -1; } // x<0 -> -1
 	elif (zerop(x)) { return 0; } // x=0 -> 0
diff --git a/src/rational/ring/cl_RA_ring.cc b/src/rational/ring/cl_RA_ring.cc
index a6aef66..420c87d 100644
--- a/src/rational/ring/cl_RA_ring.cc
+++ b/src/rational/ring/cl_RA_ring.cc
@@ -13,7 +13,9 @@ CL_PROVIDE(cl_RA_ring)
 
 #include "cln/rational.h"
 #include "cln/rational_io.h"
+#define zerop inline_zerop
 #include "cl_RA.h"
+#undef zerop
 
 namespace cln {
 
@@ -34,10 +36,11 @@ static const _cl_ring_element RA_zero (cl_heap_ring* R)
 	return _cl_ring_element(R, (cl_RA)0);
 }
 
+static cl_boolean RA_zerop (cl_heap_ring* R, const _cl_ring_element& x) __attribute__((flatten));
 static cl_boolean RA_zerop (cl_heap_ring* R, const _cl_ring_element& x)
 {
 	unused R;
-	return zerop(The(cl_RA)(x));
+	return inline_zerop(The(cl_RA)(x));
 }
 
 static const _cl_ring_element RA_plus (cl_heap_ring* R, const _cl_ring_element& x, const _cl_ring_element& y)
diff --git a/src/real/conv/cl_F_from_R_def.cc b/src/real/conv/cl_F_from_R_def.cc
index 3c8e852..01d1082 100644
--- a/src/real/conv/cl_F_from_R_def.cc
+++ b/src/real/conv/cl_F_from_R_def.cc
@@ -10,11 +10,16 @@
 // Implementation.
 
 #include "cl_R.h"
+#ifndef INLINE
+#define INLINE
+#define INLINE_DECL(decl) decl
+#define REALLY_INLINE
+#endif
 
 namespace cln {
 
-MAYBE_INLINE
-const cl_F cl_float (const cl_R& x)
+INLINE const cl_F INLINE_DECL(cl_float) (const cl_R& x) REALLY_INLINE;
+INLINE const cl_F INLINE_DECL(cl_float) (const cl_R& x)
 {
 	if (rationalp(x)) {
 		DeclareType(cl_RA,x);
diff --git a/src/real/misc/cl_R_signum.cc b/src/real/misc/cl_R_signum.cc
index f151d6c..b225639 100644
--- a/src/real/misc/cl_R_signum.cc
+++ b/src/real/misc/cl_R_signum.cc
@@ -11,12 +11,20 @@
 
 #include "cl_R.h"
 
-#undef MAYBE_INLINE
-#define MAYBE_INLINE inline
+#undef INLINE
+#undef REALLY_INLINE
+#undef INLINE_DECL
+#define INLINE static inline
+#define REALLY_INLINE __attribute__((always_inline))
+#define INLINE_DECL(name) inline_ ## name
 #include "cl_I_signum.cc"
 #include "cl_RA_signum.cc"
-#undef MAYBE_INLINE2
-#define MAYBE_INLINE2 inline
+#undef INLINE2
+#undef INLINE2_DECL
+#undef REALLY_INLINE2
+#define INLINE2 static inline
+#define INLINE2_DECL(name) inline_ ## name
+#define REALLY_INLINE2 __attribute__((always_inline))
 #include "cl_SF_signum.cc"
 #include "cl_FF_signum.cc"
 #include "cl_DF_signum.cc"
@@ -24,7 +32,8 @@
 
 namespace cln {
 
+const cl_R signum (const cl_R& x) __attribute__((flatten));
 const cl_R signum (const cl_R& x)
-GEN_R_OP1_7(x, signum, return)
+GEN_R_OP1_7(x, inline_signum, return)
 
 }  // namespace cln
-- 
1.5.3.7

Best regards,
	Alexei

-- 
All science is either physics or stamp collecting.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 827 bytes
Desc: Digital signature
Url : http://www.cebix.net/pipermail/cln-list/attachments/20080109/2942dc2e/attachment.pgp


More information about the CLN-list mailing list