summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2013-05-06 13:28:20 +0200
committerNicholas Clark <nick@ccl4.org>2013-05-20 21:19:43 +0200
commit66bb80e4324617840aa70c8af410bf76eedcbea1 (patch)
tree9de9bad8eb78b538c87758e7c0290a43777cf04d
parent36bb5e1d607385b423cc4360bce20f3043900790 (diff)
downloadperl-66bb80e4324617840aa70c8af410bf76eedcbea1.tar.gz
Remove buggy loop-based byte swapping code.
The irony is that the union-based code special-cased for little endian systems actually works everywhere, even on mixed-endian systems.
-rw-r--r--pod/perldiag.pod5
-rw-r--r--util.c38
2 files changed, 3 insertions, 40 deletions
diff --git a/pod/perldiag.pod b/pod/perldiag.pod
index 2dc5514b54..ec4812c1a5 100644
--- a/pod/perldiag.pod
+++ b/pod/perldiag.pod
@@ -5411,11 +5411,6 @@ problems when being input or output, which is likely where this message
came from. If you really really know what you are doing you can turn
off this warning by C<no warnings 'surrogate';>.
-=item Unknown BYTEORDER
-
-(F) There are no byte-swapping functions for a machine with this byte
-order.
-
=item Unknown charname '%s'
(F) The name you used inside C<\N{}> is unknown to Perl. Check the
diff --git a/util.c b/util.c
index 2c3465e25e..5a5607458c 100644
--- a/util.c
+++ b/util.c
@@ -2183,8 +2183,7 @@ Perl_my_htonl(pTHX_ long l)
char c[sizeof(long)];
} u;
-#if BYTEORDER == 0x1234 || BYTEORDER == 0x12345678
-#if BYTEORDER == 0x12345678
+#if BYTEORDER > 0xFFFF
u.result = 0;
#endif
u.c[0] = (l >> 24) & 255;
@@ -2192,19 +2191,6 @@ Perl_my_htonl(pTHX_ long l)
u.c[2] = (l >> 8) & 255;
u.c[3] = l & 255;
return u.result;
-#else
-#if ((BYTEORDER - 0x1111) & 0x444) || !(BYTEORDER & 0xf)
- Perl_croak(aTHX_ "Unknown BYTEORDER\n");
-#else
- I32 o;
- I32 s;
-
- for (o = BYTEORDER - 0x1111, s = 0; s < (sizeof(long)*8); o >>= 4, s += 8) {
- u.c[o & 0xf] = (l >> s) & 255;
- }
- return u.result;
-#endif
-#endif
}
long
@@ -2215,27 +2201,9 @@ Perl_my_ntohl(pTHX_ long l)
char c[sizeof(long)];
} u;
-#if BYTEORDER == 0x1234
- u.c[0] = (l >> 24) & 255;
- u.c[1] = (l >> 16) & 255;
- u.c[2] = (l >> 8) & 255;
- u.c[3] = l & 255;
- return u.l;
-#else
-#if ((BYTEORDER - 0x1111) & 0x444) || !(BYTEORDER & 0xf)
- Perl_croak(aTHX_ "Unknown BYTEORDER\n");
-#else
- I32 o;
- I32 s;
-
u.l = l;
- l = 0;
- for (o = BYTEORDER - 0x1111, s = 0; s < (sizeof(long)*8); o >>= 4, s += 8) {
- l |= (u.c[o & 0xf] & 255) << s;
- }
- return l;
-#endif
-#endif
+ return ((u.c[0] & 255) << 24) | ((u.c[1] & 255) << 16)
+ | ((u.c[2] & 255) << 8) | (u.c[3] & 255);
}
#endif /* BYTEORDER != 0x4321 */