From b9b88351ea2c4b43a6f90938554dc5693b17e328 Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Sat, 8 Feb 2014 14:27:49 +0100 Subject: [PATCH] Deprecate htons, htonl, ntohs, ntohl * libguile/sockets.h: * libguile/sockets.c: * libguile/deprecated.h: * libguile/deprecated.c (scm_htons, scm_htonl, scm_ntohs, scm_ntohl): Deprecate. Bytevectors adequately subsume their functionality. * doc/ref/posix.texi: * test-suite/tests/00-socket.test: Update. --- doc/ref/posix.texi | 51 +------------------------- libguile/deprecated.c | 65 ++++++++++++++++++++++++++++++++- libguile/deprecated.h | 9 ++++- libguile/socket.c | 46 +---------------------- libguile/socket.h | 6 +-- test-suite/tests/00-socket.test | 44 +--------------------- 6 files changed, 76 insertions(+), 145 deletions(-) diff --git a/doc/ref/posix.texi b/doc/ref/posix.texi index 56f5c78fc..7ca2fb01b 100644 --- a/doc/ref/posix.texi +++ b/doc/ref/posix.texi @@ -1,7 +1,7 @@ @c -*-texinfo-*- @c This is part of the GNU Guile Reference Manual. @c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2006, 2007, -@c 2008, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc. +@c 2008, 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc. @c See the file guile.texi for copying conditions. @node POSIX @@ -3392,55 +3392,6 @@ file descriptor: any unflushed buffered port data is ignored. @end deffn -The following functions can be used to convert short and long integers -between ``host'' and ``network'' order. Although the procedures above do -this automatically for addresses, the conversion will still need to -be done when sending or receiving encoded integer data from the network. - -@deffn {Scheme Procedure} htons value -@deffnx {C Function} scm_htons (value) -Convert a 16 bit quantity from host to network byte ordering. -@var{value} is packed into 2 bytes, which are then converted -and returned as a new integer. -@end deffn - -@deffn {Scheme Procedure} ntohs value -@deffnx {C Function} scm_ntohs (value) -Convert a 16 bit quantity from network to host byte ordering. -@var{value} is packed into 2 bytes, which are then converted -and returned as a new integer. -@end deffn - -@deffn {Scheme Procedure} htonl value -@deffnx {C Function} scm_htonl (value) -Convert a 32 bit quantity from host to network byte ordering. -@var{value} is packed into 4 bytes, which are then converted -and returned as a new integer. -@end deffn - -@deffn {Scheme Procedure} ntohl value -@deffnx {C Function} scm_ntohl (value) -Convert a 32 bit quantity from network to host byte ordering. -@var{value} is packed into 4 bytes, which are then converted -and returned as a new integer. -@end deffn - -These procedures are inconvenient to use at present, but consider: - -@example -(define write-network-long - (lambda (value port) - (let ((v (make-uniform-vector 1 1 0))) - (uniform-vector-set! v 0 (htonl value)) - (uniform-vector-write v port)))) - -(define read-network-long - (lambda (port) - (let ((v (make-uniform-vector 1 1 0))) - (uniform-vector-read! v port) - (ntohl (uniform-vector-ref v 0))))) -@end example - @node Internet Socket Examples @subsubsection Network Socket Examples diff --git a/libguile/deprecated.c b/libguile/deprecated.c index dee9ac3a4..7ff7b73ba 100644 --- a/libguile/deprecated.c +++ b/libguile/deprecated.c @@ -2,7 +2,7 @@ deprecate something, move it here when that is feasible. */ -/* Copyright (C) 2003, 2004, 2006, 2008, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc. +/* Copyright (C) 2003, 2004, 2006, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -2952,6 +2952,69 @@ SCM_DEFINE (scm_gc_live_object_stats, "gc-live-object-stats", 0, 0, 0, +SCM_DEFINE (scm_htons, "htons", 1, 0, 0, + (SCM value), + "Convert a 16 bit quantity from host to network byte ordering.\n" + "@var{value} is packed into 2 bytes, which are then converted\n" + "and returned as a new integer.") +#define FUNC_NAME s_scm_htons +{ + scm_c_issue_deprecation_warning + ("htons is deprecated. Use bytevector-u16-set! and bytevector-u16-ref " + "with big endianness."); + + return scm_from_ushort (htons (scm_to_ushort (value))); +} +#undef FUNC_NAME + +SCM_DEFINE (scm_ntohs, "ntohs", 1, 0, 0, + (SCM value), + "Convert a 16 bit quantity from network to host byte ordering.\n" + "@var{value} is packed into 2 bytes, which are then converted\n" + "and returned as a new integer.") +#define FUNC_NAME s_scm_ntohs +{ + scm_c_issue_deprecation_warning + ("ntohs is deprecated. Use bytevector-u16-set! and bytevector-u16-ref " + "with big endianness."); + + return scm_from_ushort (ntohs (scm_to_ushort (value))); +} +#undef FUNC_NAME + +SCM_DEFINE (scm_htonl, "htonl", 1, 0, 0, + (SCM value), + "Convert a 32 bit quantity from host to network byte ordering.\n" + "@var{value} is packed into 4 bytes, which are then converted\n" + "and returned as a new integer.") +#define FUNC_NAME s_scm_htonl +{ + scm_c_issue_deprecation_warning + ("htonl is deprecated. Use bytevector-u32-set! and bytevector-u32-ref " + "with big endianness."); + + return scm_from_ulong (htonl (scm_to_uint32 (value))); +} +#undef FUNC_NAME + +SCM_DEFINE (scm_ntohl, "ntohl", 1, 0, 0, + (SCM value), + "Convert a 32 bit quantity from network to host byte ordering.\n" + "@var{value} is packed into 4 bytes, which are then converted\n" + "and returned as a new integer.") +#define FUNC_NAME s_scm_ntohl +{ + scm_c_issue_deprecation_warning + ("ntohl is deprecated. Use bytevector-u32-set! and bytevector-u32-ref " + "with big endianness."); + + return scm_from_ulong (ntohl (scm_to_uint32 (value))); +} +#undef FUNC_NAME + + + + void scm_i_init_deprecated () { diff --git a/libguile/deprecated.h b/libguile/deprecated.h index cfbea6bbb..5f95f2711 100644 --- a/libguile/deprecated.h +++ b/libguile/deprecated.h @@ -5,7 +5,7 @@ #ifndef SCM_DEPRECATED_H #define SCM_DEPRECATED_H -/* Copyright (C) 2003,2004, 2005, 2006, 2007, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc. +/* Copyright (C) 2003,2004, 2005, 2006, 2007, 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -865,6 +865,13 @@ SCM_DEPRECATED SCM scm_gc_live_object_stats (void); +SCM_DEPRECATED SCM scm_htons (SCM in); +SCM_DEPRECATED SCM scm_ntohs (SCM in); +SCM_DEPRECATED SCM scm_htonl (SCM in); +SCM_DEPRECATED SCM scm_ntohl (SCM in); + + + void scm_i_init_deprecated (void); #endif diff --git a/libguile/socket.c b/libguile/socket.c index a0fb1a9f0..09f4831cd 100644 --- a/libguile/socket.c +++ b/libguile/socket.c @@ -1,5 +1,5 @@ /* Copyright (C) 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005, - * 2006, 2007, 2009, 2011, 2012, 2013 Free Software Foundation, Inc. + * 2006, 2007, 2009, 2011, 2012, 2013, 2014 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -92,50 +92,6 @@ typedef union -SCM_DEFINE (scm_htons, "htons", 1, 0, 0, - (SCM value), - "Convert a 16 bit quantity from host to network byte ordering.\n" - "@var{value} is packed into 2 bytes, which are then converted\n" - "and returned as a new integer.") -#define FUNC_NAME s_scm_htons -{ - return scm_from_ushort (htons (scm_to_ushort (value))); -} -#undef FUNC_NAME - -SCM_DEFINE (scm_ntohs, "ntohs", 1, 0, 0, - (SCM value), - "Convert a 16 bit quantity from network to host byte ordering.\n" - "@var{value} is packed into 2 bytes, which are then converted\n" - "and returned as a new integer.") -#define FUNC_NAME s_scm_ntohs -{ - return scm_from_ushort (ntohs (scm_to_ushort (value))); -} -#undef FUNC_NAME - -SCM_DEFINE (scm_htonl, "htonl", 1, 0, 0, - (SCM value), - "Convert a 32 bit quantity from host to network byte ordering.\n" - "@var{value} is packed into 4 bytes, which are then converted\n" - "and returned as a new integer.") -#define FUNC_NAME s_scm_htonl -{ - return scm_from_ulong (htonl (scm_to_uint32 (value))); -} -#undef FUNC_NAME - -SCM_DEFINE (scm_ntohl, "ntohl", 1, 0, 0, - (SCM value), - "Convert a 32 bit quantity from network to host byte ordering.\n" - "@var{value} is packed into 4 bytes, which are then converted\n" - "and returned as a new integer.") -#define FUNC_NAME s_scm_ntohl -{ - return scm_from_ulong (ntohl (scm_to_uint32 (value))); -} -#undef FUNC_NAME - #ifdef HAVE_INET_NETOF SCM_DEFINE (scm_inet_netof, "inet-netof", 1, 0, 0, (SCM address), diff --git a/libguile/socket.h b/libguile/socket.h index fcddd780d..a211867c6 100644 --- a/libguile/socket.h +++ b/libguile/socket.h @@ -3,7 +3,7 @@ #ifndef SCM_SOCKET_H #define SCM_SOCKET_H -/* Copyright (C) 1995,1996,1997,2000,2001, 2004, 2005, 2006, 2008 Free Software Foundation, Inc. +/* Copyright (C) 1995,1996,1997,2000,2001, 2004, 2005, 2006, 2008, 2014 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -27,10 +27,6 @@ -SCM_API SCM scm_htons (SCM in); -SCM_API SCM scm_ntohs (SCM in); -SCM_API SCM scm_htonl (SCM in); -SCM_API SCM scm_ntohl (SCM in); SCM_API SCM scm_inet_aton (SCM address); SCM_API SCM scm_inet_ntoa (SCM inetid); SCM_API SCM scm_inet_netof (SCM address); diff --git a/test-suite/tests/00-socket.test b/test-suite/tests/00-socket.test index 5093575c0..309c35825 100644 --- a/test-suite/tests/00-socket.test +++ b/test-suite/tests/00-socket.test @@ -1,7 +1,7 @@ ;;;; socket.test --- test socket functions -*- scheme -*- ;;;; ;;;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, -;;;; 2011, 2013 Free Software Foundation, Inc. +;;;; 2011, 2013, 2014 Free Software Foundation, Inc. ;;;; ;;;; This library is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU Lesser General Public @@ -24,27 +24,6 @@ -;;; -;;; htonl -;;; - -(if (defined? 'htonl) - (with-test-prefix "htonl" - - (pass-if "0" (eqv? 0 (htonl 0))) - - (pass-if-exception "-1" exception:out-of-range - (htonl -1)) - - ;; prior to guile 1.6.9 and 1.8.1, systems with 64-bit longs didn't detect - ;; an overflow for values 2^32 <= x < 2^63 - (pass-if-exception "2^32" exception:out-of-range - (htonl (ash 1 32))) - - (pass-if-exception "2^1024" exception:out-of-range - (htonl (ash 1 1024))))) - - ;;; ;;; inet-ntop ;;; @@ -151,27 +130,6 @@ (and (= (sockaddr:fam sa) AF_UNIX) (string=? (sockaddr:path sa) "/tmp/unix-socket")))))) -;;; -;;; ntohl -;;; - -(if (defined? 'ntohl) - (with-test-prefix "ntohl" - - (pass-if "0" (eqv? 0 (ntohl 0))) - - (pass-if-exception "-1" exception:out-of-range - (ntohl -1)) - - ;; prior to guile 1.6.9 and 1.8.1, systems with 64-bit longs didn't detect - ;; an overflow for values 2^32 <= x < 2^63 - (pass-if-exception "2^32" exception:out-of-range - (ntohl (ash 1 32))) - - (pass-if-exception "2^1024" exception:out-of-range - (ntohl (ash 1 1024))))) - - ;;; ;;; AF_UNIX sockets and `make-socket-address' -- 2.20.1