This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Eliminate the conditionally-compiled fallback functions for htonl etc.
authorNicholas Clark <nick@ccl4.org>
Mon, 6 May 2013 12:40:04 +0000 (14:40 +0200)
committerNicholas Clark <nick@ccl4.org>
Mon, 20 May 2013 19:19:43 +0000 (21:19 +0200)
These are now only being used for mixed-endian platforms which do not
provide their own htnol (etc) functions. Given that the fallbacks have been
buggy since they were added in Perl 3.0, it's safe to conclude that no
mixed-endian platforms were ever using these functions.

It's also unclear why these functions were ever marked as 'A', part of the
API. XS code can't call them directly, as it can't rely on them being
compiled. Unsurprisingly, no code on CPAN references them.

embed.fnc
embed.h
perl.h
proto.h
util.c

index 8b73d6d..70f5889 100644 (file)
--- a/embed.fnc
+++ b/embed.fnc
@@ -888,11 +888,6 @@ Ap |void   |my_setenv      |NULLOK const char* nam|NULLOK const char* val
 Apmb   |I32    |my_stat
 pX     |I32    |my_stat_flags  |NULLOK const U32 flags
 Ap     |char * |my_strftime    |NN const char *fmt|int sec|int min|int hour|int mday|int mon|int year|int wday|int yday|int isdst
-#if defined(MYSWAP)
-ApPR   |short  |my_swap        |short s
-ApPR   |long   |my_htonl       |long l
-ApPR   |long   |my_ntohl       |long l
-#endif
 : Used in pp_ctl.c
 p      |void   |my_unexec
 Apa    |OP*    |newANONLIST    |NULLOK OP* o
diff --git a/embed.h b/embed.h
index 9054358..2cd19f8 100644 (file)
--- a/embed.h
+++ b/embed.h
 #define dump_mstats(a)         Perl_dump_mstats(aTHX_ a)
 #define get_mstats(a,b,c)      Perl_get_mstats(aTHX_ a,b,c)
 #endif
-#if defined(MYSWAP)
-#define my_htonl(a)            Perl_my_htonl(aTHX_ a)
-#define my_ntohl(a)            Perl_my_ntohl(aTHX_ a)
-#define my_swap(a)             Perl_my_swap(aTHX_ a)
-#endif
 #if defined(PERL_GLOBAL_STRUCT)
 #define GetVars()              Perl_GetVars(aTHX)
 #define free_global_struct(a)  Perl_free_global_struct(aTHX_ a)
diff --git a/perl.h b/perl.h
index 7324f44..17e6299 100644 (file)
--- a/perl.h
+++ b/perl.h
@@ -743,15 +743,6 @@ EXTERN_C int syscall(int, ...);
 EXTERN_C int usleep(unsigned int);
 #endif
 
-/* Funky places that do not have socket stuff. */
-#if defined(__LIBCATAMOUNT__)
-#  define MYSWAP
-#endif
-
-#ifdef PERL_MICRO /* Last chance to export Perl_my_swap */
-#  define MYSWAP
-#endif
-
 #ifdef PERL_CORE
 
 /* macros for correct constant construction */
@@ -3573,13 +3564,19 @@ my_swap16(const U16 x) {
 #    define ntohs(x)    my_swap16(x)
 #    define htons(x)    my_swap16(x)
 #  else
-/* Assumed to be mixed endian.  */
-#define MYSWAP
-#define htons my_swap
-#define htonl my_htonl
-#define ntohs my_swap
-#define ntohl my_ntohl
-#endif
+#    error "Unsupported byteorder"
+/* The C pre-processor doesn't let us return the value of BYTEORDER as part of
+   the error message. Please check the value of the macro BYTEORDER, as defined
+   in config.h. The values of BYTEORDER we expect are
+
+           big endian  little endian
+   32 bit       0x4321  0x1234
+   64 bit   0x87654321  0x12345678
+
+   If you have a system with a different byte order, please see
+   pod/perlhack.pod for how to submit a patch to add supporting code.
+*/
+#  endif
 #endif
 
 /*
diff --git a/proto.h b/proto.h
index a1b3e97..5c8f779 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -5345,20 +5345,6 @@ PERL_CALLCONV MEM_SIZE   Perl_malloced_size(void *p)
        assert(p)
 
 #endif
-#if defined(MYSWAP)
-PERL_CALLCONV long     Perl_my_htonl(pTHX_ long l)
-                       __attribute__warn_unused_result__
-                       __attribute__pure__;
-
-PERL_CALLCONV long     Perl_my_ntohl(pTHX_ long l)
-                       __attribute__warn_unused_result__
-                       __attribute__pure__;
-
-PERL_CALLCONV short    Perl_my_swap(pTHX_ short s)
-                       __attribute__warn_unused_result__
-                       __attribute__pure__;
-
-#endif
 #if defined(NO_MATHOMS)
 /* PERL_CALLCONV void  Perl_sv_nounlocking(pTHX_ SV *sv); */
 #endif
diff --git a/util.c b/util.c
index 5a56074..1b98d22 100644 (file)
--- a/util.c
+++ b/util.c
@@ -2160,55 +2160,6 @@ vsprintf(char *dest, const char *pat, void *args)
 
 #endif /* HAS_VPRINTF */
 
-#ifdef MYSWAP
-#if BYTEORDER != 0x4321
-short
-Perl_my_swap(pTHX_ short s)
-{
-#if (BYTEORDER & 1) == 0
-    short result;
-
-    result = ((s & 255) << 8) + ((s >> 8) & 255);
-    return result;
-#else
-    return s;
-#endif
-}
-
-long
-Perl_my_htonl(pTHX_ long l)
-{
-    union {
-       long result;
-       char c[sizeof(long)];
-    } u;
-
-#if BYTEORDER > 0xFFFF
-    u.result = 0; 
-#endif 
-    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.result;
-}
-
-long
-Perl_my_ntohl(pTHX_ long l)
-{
-    union {
-       long l;
-       char c[sizeof(long)];
-    } u;
-
-    u.l = l;
-    return ((u.c[0] & 255) << 24) | ((u.c[1] & 255) << 16)
-       | ((u.c[2] & 255) << 8) | (u.c[3] & 255);
-}
-
-#endif /* BYTEORDER != 0x4321 */
-#endif /* MYSWAP */
-
 /*
  * Little-endian byte order functions - 'v' for 'VAX', or 'reVerse'.
  * If these functions are defined,