From: Gurusamy Sarathy <gsar@cpan.org>
Date: Sat, 22 Nov 1997 07:24:01 +0000 (+0000)
Subject: [win32] Generic change in win32 branch: don't just turn on CRIPPLED_CC
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a80f87c48e630b044cd5371d547b0f38e4476ec0;p=p5sagit%2Fp5-mst-13.2.git

[win32] Generic change in win32 branch: don't just turn on CRIPPLED_CC
when USE_THREADS.  GCC for instance, can do without macros that use
globals.  Instead, selectively re#define only those macros
that use globals to their functional equivalents.  Tests 100% on
Solaris/gcc (after `chmod +x t/op/nothread.t t/lib/thread.t` (hint,hint)).

p4raw-id: //depot/win32/perl@276
---

diff --git a/perl.h b/perl.h
index d895441..b4e8865 100644
--- a/perl.h
+++ b/perl.h
@@ -42,12 +42,6 @@
 #  define EXTERN_C
 #endif
 
-#if defined(USE_THREADS) /* && !defined(PERL_CORE) && !defined(PERLDLL) */
-#ifndef CRIPPLED_CC
-#define CRIPPLED_CC
-#endif
-#endif
-
 #ifdef OP_IN_REGISTER
 #  ifdef __GNUC__
 #    define stringify_immed(s) #s
diff --git a/sv.h b/sv.h
index fcf9297..42a6a1b 100644
--- a/sv.h
+++ b/sv.h
@@ -492,8 +492,6 @@ struct xpvio {
 
 #define SvTAINT(sv)	  STMT_START{ if(tainted){SvTAINTED_on(sv);} }STMT_END
 
-#ifdef CRIPPLED_CC
-
 #define SvPV_force(sv, lp) sv_pvn_force(sv, &lp)
 #define SvPV(sv, lp) sv_pvn(sv, &lp)
 #define SvIVx(sv) sv_iv(sv)
@@ -508,7 +506,8 @@ struct xpvio {
 #define SvUV(sv) SvIVx(sv)
 #define SvTRUE(sv) SvTRUEx(sv)
 
-#else /* !CRIPPLED_CC */
+#ifndef CRIPPLED_CC
+/* redefine some things to more efficient inlined versions */
 
 #undef SvIV
 #define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv))
@@ -528,15 +527,26 @@ struct xpvio {
     ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \
      ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force(sv, &lp))
 
-#undef SvTRUE
-#define SvTRUE(sv) (						\
+#ifdef __GNUC__
+#  undef SvIVx
+#  undef SvUVx
+#  undef SvNVx
+#  undef SvPVx
+#  undef SvTRUE
+#  undef SvTRUEx
+#  define SvIVx(sv) ({SV *nsv = (SV*)(sv); SvIV(nsv); })
+#  define SvUVx(sv) ({SV *nsv = (SV*)(sv); SvUV(nsv); })
+#  define SvNVx(sv) ({SV *nsv = (SV*)(sv); SvNV(nsv); })
+#  define SvPVx(sv, lp) ({SV *nsv = (sv); SvPV(nsv, lp); })
+#  define SvTRUE(sv) (						\
     !sv								\
     ? 0								\
     :    SvPOK(sv)						\
-	?   ((Xpv = (XPV*)SvANY(sv)) &&				\
-	     (*Xpv->xpv_pv > '0' ||				\
-	      Xpv->xpv_cur > 1 ||				\
-	      (Xpv->xpv_cur && *Xpv->xpv_pv != '0'))		\
+	?   (({XPV *nxpv = (XPV*)SvANY(sv);			\
+	     nxpv &&						\
+	     (*nxpv->xpv_pv > '0' ||				\
+	      nxpv->xpv_cur > 1 ||				\
+	      (nxpv->xpv_cur && *nxpv->xpv_pv != '0')); })	\
 	     ? 1						\
 	     : 0)						\
 	:							\
@@ -545,22 +555,42 @@ struct xpvio {
 	    :   SvNOK(sv)					\
 		? SvNVX(sv) != 0.0				\
 		: sv_2bool(sv) )
-
-#ifdef __GNUC__
-#  define SvIVx(sv) ({SV *nsv = (SV*)(sv); SvIV(nsv); })
-#  define SvUVx(sv) ({SV *nsv = (SV*)(sv); SvUV(nsv); })
-#  define SvNVx(sv) ({SV *nsv = (SV*)(sv); SvNV(nsv); })
-#  define SvPVx(sv, lp) ({SV *nsv = (sv); SvPV(nsv, lp); })
-#else
+#  define SvTRUEx(sv) ({SV *nsv = (sv); SvTRUE(nsv); })
+#else /* __GNUC__ */
+#ifndef USE_THREADS
+/* These inlined macros use globals, which will require a thread
+ * declaration in user code, so we avoid them under threads */
+
+#  undef SvIVx
+#  undef SvUVx
+#  undef SvNVx
+#  undef SvPVx
+#  undef SvTRUE
+#  undef SvTRUEx
 #  define SvIVx(sv) ((Sv = (sv)), SvIV(Sv))
 #  define SvUVx(sv) ((Sv = (sv)), SvUV(Sv))
 #  define SvNVx(sv) ((Sv = (sv)), SvNV(Sv))
 #  define SvPVx(sv, lp) ((Sv = (sv)), SvPV(Sv, lp))
-#endif /* __GNUC__ */
-
-#define SvTRUEx(sv) ((Sv = (sv)), SvTRUE(Sv))
-
-#endif /* CRIPPLED_CC */
+#  define SvTRUE(sv) (						\
+    !sv								\
+    ? 0								\
+    :    SvPOK(sv)						\
+	?   ((Xpv = (XPV*)SvANY(sv)) &&				\
+	     (*Xpv->xpv_pv > '0' ||				\
+	      Xpv->xpv_cur > 1 ||				\
+	      (Xpv->xpv_cur && *Xpv->xpv_pv != '0'))		\
+	     ? 1						\
+	     : 0)						\
+	:							\
+	    SvIOK(sv)						\
+	    ? SvIVX(sv) != 0					\
+	    :   SvNOK(sv)					\
+		? SvNVX(sv) != 0.0				\
+		: sv_2bool(sv) )
+#  define SvTRUEx(sv) ((Sv = (sv)), SvTRUE(Sv))
+#endif /* !USE_THREADS */
+#endif /* !__GNU__ */
+#endif /* !CRIPPLED_CC */
 
 #define newRV_inc(sv)	newRV(sv)
 #ifdef __GNUC__