Fix bit-fields for VC [was RE: [perl #50386] GIMME_V broken with 5.10.0/GCC and XS?]
Jan Dubois [Fri, 1 Feb 2008 13:40:41 +0000 (05:40 -0800)]
From: "Jan Dubois" <jand@activestate.com>
Message-ID: <02ee01c8651b$17ef72f0$47ce58d0$@com>

p4raw-id: //depot/perl@33292

op.h
perl.h
regexp.h
sv.h
win32/makefile.mk
win32/win32.h

diff --git a/op.h b/op.h
index 5c18900..b35e9da 100644 (file)
--- a/op.h
+++ b/op.h
     OP*                (CPERLscope(*op_ppaddr))(pTHX);         \
     MADPROP_IN_BASEOP                  \
     PADOFFSET  op_targ;                \
-    unsigned   op_type:9;              \
-    unsigned   op_opt:1;               \
-    unsigned   op_latefree:1;          \
-    unsigned   op_latefreed:1;         \
-    unsigned   op_attached:1;          \
-    unsigned   op_spare:3;             \
+    PERL_BITFIELD16 op_type:9;         \
+    PERL_BITFIELD16 op_opt:1;          \
+    PERL_BITFIELD16 op_latefree:1;     \
+    PERL_BITFIELD16 op_latefreed:1;    \
+    PERL_BITFIELD16 op_attached:1;     \
+    PERL_BITFIELD16 op_spare:3;                \
     U8         op_flags;               \
     U8         op_private;
 #endif
diff --git a/perl.h b/perl.h
index 35bc28a..16b0c7c 100644 (file)
--- a/perl.h
+++ b/perl.h
@@ -3328,6 +3328,17 @@ struct nexttoken {
 };
 #endif
 
+/* macros to define bit-fields in structs. */
+#ifndef PERL_BITFIELD8
+#  define PERL_BITFIELD8 unsigned
+#endif
+#ifndef PERL_BITFIELD16
+#  define PERL_BITFIELD16 unsigned
+#endif
+#ifndef PERL_BITFIELD32
+#  define PERL_BITFIELD32 unsigned
+#endif
+
 #include "sv.h"
 #include "regexp.h"
 #include "util.h"
index f2366ca..156e60b 100644 (file)
--- a/regexp.h
+++ b/regexp.h
@@ -97,9 +97,9 @@ typedef struct regexp_paren_pair {
        I32 sublen;     /* Length of string pointed by subbeg */        \
        /* Information about the match that isn't often used */         \
        /* offset from wrapped to the start of precomp */               \
-       unsigned pre_prefix:4;                                          \
+       PERL_BITFIELD32 pre_prefix:4;                                   \
        /* number of eval groups in the pattern - for security checks */\
-       unsigned seen_evals:28
+       PERL_BITFIELD32 seen_evals:28
 
 typedef struct regexp {
        _XPV_HEAD;
diff --git a/sv.h b/sv.h
index 29a689d..fc67ed9 100644 (file)
--- a/sv.h
+++ b/sv.h
@@ -117,10 +117,10 @@ struct STRUCT_SV {                /* struct sv { */
     _SV_HEAD(void*);
     _SV_HEAD_UNION;
 #ifdef DEBUG_LEAKING_SCALARS
-    unsigned   sv_debug_optype:9;      /* the type of OP that allocated us */
-    unsigned   sv_debug_inpad:1;       /* was allocated in a pad for an OP */
-    unsigned   sv_debug_cloned:1;      /* was cloned for an ithread */
-    unsigned   sv_debug_line:16;       /* the line where we were allocated */
+    PERL_BITFIELD32 sv_debug_optype:9; /* the type of OP that allocated us */
+    PERL_BITFIELD32 sv_debug_inpad:1;  /* was allocated in a pad for an OP */
+    PERL_BITFIELD32 sv_debug_cloned:1; /* was cloned for an ithread */
+    PERL_BITFIELD32 sv_debug_line:16;  /* the line where we were allocated */
     char *     sv_debug_file;          /* the file where we were allocated */
 #endif
 };
index 3f145b8..5a0e020 100644 (file)
@@ -522,7 +522,7 @@ LIBOUT_FLAG =
 
 # NOTE: we assume that GCC uses MSVCRT.DLL
 # See comments about PERL_MSVCRT_READFIX in the "cl" compiler section below.
-BUILDOPT       += -fno-strict-aliasing -DPERL_MSVCRT_READFIX
+BUILDOPT       += -fno-strict-aliasing -mms-bitfields -DPERL_MSVCRT_READFIX
 
 .ELSE
 
index 224c657..7bfeb15 100644 (file)
@@ -170,6 +170,14 @@ struct utsname {
 
 /* Compiler-specific stuff. */
 
+#if defined(_MSC_VER) || defined(__MINGW32__)
+/* VC uses non-standard way to determine the size and alignment if bit-fields */
+/* MinGW will compiler with -mms-bitfields, so should use the same types */
+#  define PERL_BITFIELD8  unsigned char
+#  define PERL_BITFIELD16 unsigned short
+#  define PERL_BITFIELD32 unsigned int
+#endif
+
 #ifdef __BORLANDC__            /* Borland C++ */
 
 #if (__BORLANDC__ <= 0x520)