bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: htonl: New module.


From: Bruno Haible
Subject: Re: htonl: New module.
Date: Sun, 11 Aug 2024 16:24:45 +0200

Collin Funk wrote:
> Doing a separate for each seems excessive.

I agree. If a package needs one of these functions, the odds are high that
it needs some of the other three functions as well.

The second patch, with the tests, is fine.

However, the first patch is not sufficient:

1) The portability problem that it solves is that the functions are missing
   on HP-UX 11 and on old Android. HP-UX is dead, but old Android is relevant
   for Emacs.

   On all other POSIX-like platforms, REPLACE_HTONL is never set to 1, because
   the test 'if arpa/inet.h defines htonl, htons, ntohl, ntohs' always succeeds.
   All platforms that I could test have these functions, and inspection of the
   header files shows that the functions are defined as functions everywhere,
   except that some platforms define them as macros when they are the identity
   function (i.e. on big-endian platforms):

       $ grep 'define[  ]htonl' */usr/include/arpa/inet.h
       aix-4.3.2/usr/include/arpa/inet.h:#define htonl(hostlong)  (hostlong)
       aix-5.1.0/usr/include/arpa/inet.h:#define htonl(hostlong)  (hostlong)
       aix-5.2.0/usr/include/arpa/inet.h:#define htonl(hostlong)  (hostlong)
       aix-5.3.0a/usr/include/arpa/inet.h:#define htonl(hostlong)  (hostlong)
       aix-5.3.0/usr/include/arpa/inet.h:#define htonl(hostlong)  (hostlong)
       aix-6.1.0/usr/include/arpa/inet.h:#define htonl(hostlong)  (hostlong)
       aix-7.1.0/usr/include/arpa/inet.h:#define htonl(hostlong)  (hostlong)
       aix-7.2.0/usr/include/arpa/inet.h:#define htonl(hostlong)  (hostlong)
       aix-7.3.1/usr/include/arpa/inet.h:#define htonl(hostlong)  (hostlong)
       freebsd-11.0/usr/include/arpa/inet.h:#define    htonl(x)        
__htonl(x)
       freebsd-12.0/usr/include/arpa/inet.h:#define    htonl(x)        
__htonl(x)
       freebsd-13.0/usr/include/arpa/inet.h:#define    htonl(x)        
__htonl(x)
       freebsd-14.0/usr/include/arpa/inet.h:#define    htonl(x)        
__htonl(x)
       freebsd-5.2.1/usr/include/arpa/inet.h:#define   htonl(x)        
__htonl(x)
       freebsd-6.0/usr/include/arpa/inet.h:#define     htonl(x)        
__htonl(x)
       freebsd-6.4/usr/include/arpa/inet.h:#define     htonl(x)        
__htonl(x)
       hpux-10.20/usr/include/arpa/inet.h:#define htonl(x)        (x)
       hpux-11.00/usr/include/arpa/inet.h:#define htonl(x)        (x)
       hpux-11.11/usr/include/arpa/inet.h:#define htonl(x)        (x)
       hpux-11.23-ia64/usr/include/arpa/inet.h:#define htonl(x)        (x)
       hpux-11.23/usr/include/arpa/inet.h:#define htonl(x)        (x)
       hpux-11.31/usr/include/arpa/inet.h:#define htonl(x)        (x)
       openbsd-6.0/usr/include/arpa/inet.h:#define htonl(x)    __htobe32(x)
       openbsd-6.7/usr/include/arpa/inet.h:#define htonl(x)    __htobe32(x)
       openbsd-7.5/usr/include/arpa/inet.h:#define htonl(x)    __htobe32(x)

   For a function, the float-argument test and the evaluates-arg-only-once
   test naturally succeed.

   I believe the situation is good here because these 4 functions have been
   heavily used over the last 30 years, and problems like evaluates-arg-
   several-times would have been noticed and fixed many years ago already.

2) It does not solve the portability problem that it advertises to solve
   in the documentation.

   The doc change claims to solve the problem on native Windows. But a testdir
   of module 'htonl' produces a link error there. (See attached log1, log2, 
log3.)
   The error message indicates that the declarations in <winsock2.h> were in
   effect (that declare the functions, with a dllimport; via <sys/socket.h>),
   but the test program was not linked with -lws2_32. Cf.
   
<https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-htonl>

In order to fix the native Windows problem, the module description should
have a 'Link:' section that references a variable (named $(HTONL_LIB) by
convention) that expands to -lws2_32 on native Windows systems.

Bruno

Attachment: log1
Description: Text document

Attachment: log2
Description: Text document

Attachment: log3
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]