This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Provide vtohl, vtohs, htovl and htovs no-op macros on little endian systems.
authorNicholas Clark <nick@ccl4.org>
Sat, 4 May 2013 19:30:27 +0000 (21:30 +0200)
committerNicholas Clark <nick@ccl4.org>
Mon, 20 May 2013 19:19:42 +0000 (21:19 +0200)
This means that there are always macros or functions for vtohl, vtohs,
htovl and htovs available, so eliminate HAS_VTOHL etc, and unconditionally
compile the code that it was protecting. grep.cpan.me shows that no code on
CPAN uses any of these macros.

(Technically the 4 are not quite no-ops, as they truncate their values to
32 or 16 bits, to be consistent with the implementations for platforms which
need re-ordering.)

perl.h
pp_pack.c
util.c

diff --git a/perl.h b/perl.h
index a0feae2..df905d0 100644 (file)
--- a/perl.h
+++ b/perl.h
@@ -3562,12 +3562,14 @@ struct ptr_tbl {
  * -DWS
  */
 #if BYTEORDER == 0x1234 || BYTEORDER == 0x12345678
-/* Little endian system, so vtohl, vtohs, htovl and htovs are all no-ops.  */
+/* Little endian system, so vtohl, vtohs, htovl and htovs do not need to
+   re-order their values. However, to behave identically to the alternative
+   implementations, they should truncate to the correct size.  */
+#  define vtohl(x)      ((x)&0xFFFFFFFF)
+#  define vtohs(x)      ((x)&0xFFFF)
+#  define htovl(x)      vtohl(x)
+#  define htovs(x)      vtohs(x)
 #else
-# define HAS_VTOHL
-# define HAS_VTOHS
-# define HAS_HTOVL
-# define HAS_HTOVS
 # if BYTEORDER == 0x4321 || BYTEORDER == 0x87654321
 #  define vtohl(x)     ((((x)&0xFF)<<24)       \
                        +(((x)>>24)&0xFF)       \
index e9969d5..b47df9b 100644 (file)
--- a/pp_pack.c
+++ b/pp_pack.c
@@ -1480,10 +1480,8 @@ S_unpack_rec(pTHX_ tempsym_t* symptr, const char *s, const char *strbeg, const c
                if (datumtype == 'n')
                    au16 = PerlSock_ntohs(au16);
 #endif
-#ifdef HAS_VTOHS
                if (datumtype == 'v')
                    au16 = vtohs(au16);
-#endif
                if (!checksum)
                    mPUSHu(au16);
                else if (checksum > bits_in_uv)
@@ -1504,10 +1502,8 @@ S_unpack_rec(pTHX_ tempsym_t* symptr, const char *s, const char *strbeg, const c
                if (datumtype == ('n' | TYPE_IS_SHRIEKING))
                    ai16 = (I16) PerlSock_ntohs((U16) ai16);
 # endif /* HAS_NTOHS */
-# ifdef HAS_VTOHS
                if (datumtype == ('v' | TYPE_IS_SHRIEKING))
                    ai16 = (I16) vtohs((U16) ai16);
-# endif /* HAS_VTOHS */
                if (!checksum)
                    mPUSHi(ai16);
                else if (checksum > bits_in_uv)
@@ -1653,10 +1649,8 @@ S_unpack_rec(pTHX_ tempsym_t* symptr, const char *s, const char *strbeg, const c
                if (datumtype == 'N')
                    au32 = PerlSock_ntohl(au32);
 #endif
-#ifdef HAS_VTOHL
                if (datumtype == 'V')
                    au32 = vtohl(au32);
-#endif
                if (!checksum)
                    mPUSHu(au32);
                else if (checksum > bits_in_uv)
@@ -1677,10 +1671,8 @@ S_unpack_rec(pTHX_ tempsym_t* symptr, const char *s, const char *strbeg, const c
                if (datumtype == ('N' | TYPE_IS_SHRIEKING))
                    ai32 = (I32)PerlSock_ntohl((U32)ai32);
 #endif
-#ifdef HAS_VTOHL
                if (datumtype == ('V' | TYPE_IS_SHRIEKING))
                    ai32 = (I32)vtohl((U32)ai32);
-#endif
                if (!checksum)
                    mPUSHi(ai32);
                else if (checksum > bits_in_uv)
@@ -2883,9 +2875,7 @@ S_pack_rec(pTHX_ SV *cat, tempsym_t* symptr, SV **beglist, SV **endlist )
                I16 ai16;
                fromstr = NEXTFROM;
                ai16 = (I16)SvIV(fromstr);
-#ifdef HAS_HTOVS
                ai16 = htovs(ai16);
-#endif
                PUSH16(utf8, cur, &ai16);
            }
            break;
@@ -3092,9 +3082,7 @@ S_pack_rec(pTHX_ SV *cat, tempsym_t* symptr, SV **beglist, SV **endlist )
                U32 au32;
                fromstr = NEXTFROM;
                au32 = SvUV(fromstr);
-#ifdef HAS_HTOVL
                au32 = htovl(au32);
-#endif
                PUSH32(utf8, cur, &au32);
            }
            break;
diff --git a/util.c b/util.c
index 14d9f2c..2c3465e 100644 (file)
--- a/util.c
+++ b/util.c
@@ -2334,16 +2334,16 @@ Perl_my_ntohl(pTHX_ long l)
         }
 
 
-#if defined(HAS_HTOVS) && !defined(htovs)
+#if !defined(htovs)
 HTOLE(htovs,short)
 #endif
-#if defined(HAS_HTOVL) && !defined(htovl)
+#if !defined(htovl)
 HTOLE(htovl,long)
 #endif
-#if defined(HAS_VTOHS) && !defined(vtohs)
+#if !defined(vtohs)
 LETOH(vtohs,short)
 #endif
-#if defined(HAS_VTOHL) && !defined(vtohl)
+#if !defined(vtohl)
 LETOH(vtohl,long)
 #endif