From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kevin Ryde Newsgroups: gmane.lisp.guile.devel Subject: scm_from_ipv6 Date: Mon, 23 Aug 2004 10:59:45 +1000 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <877jrqr7ni.fsf@zip.com.au> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1093222840 2264 80.91.224.253 (23 Aug 2004 01:00:40 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 23 Aug 2004 01:00:40 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Aug 23 03:00:35 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1Bz3CN-0004u2-00 for ; Mon, 23 Aug 2004 03:00:35 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1Bz3Go-0007ux-7Q for guile-devel@m.gmane.org; Sun, 22 Aug 2004 21:05:10 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1Bz3GZ-0007ur-Nt for guile-devel@gnu.org; Sun, 22 Aug 2004 21:04:55 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1Bz3GX-0007tI-RU for guile-devel@gnu.org; Sun, 22 Aug 2004 21:04:55 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1Bz3GX-0007t7-Nw for guile-devel@gnu.org; Sun, 22 Aug 2004 21:04:53 -0400 Original-Received: from [61.8.0.85] (helo=mailout2.pacific.net.au) by monty-python.gnu.org with esmtp (Exim 4.34) id 1Bz3Bo-0006wH-DH for guile-devel@gnu.org; Sun, 22 Aug 2004 21:00:00 -0400 Original-Received: from mailproxy2.pacific.net.au (mailproxy2.pacific.net.au [61.8.0.87]) by mailout2.pacific.net.au (8.12.3/8.12.3/Debian-6.6) with ESMTP id i7N0xxje030400 for ; Mon, 23 Aug 2004 10:59:59 +1000 Original-Received: from localhost (ppp2B76.dyn.pacific.net.au [61.8.43.118]) by mailproxy2.pacific.net.au (8.12.3/8.12.3/Debian-6.6) with ESMTP id i7N0xw78013407 for ; Mon, 23 Aug 2004 10:59:58 +1000 Original-Received: from gg by localhost with local (Exim 3.36 #1 (Debian)) id 1Bz3Ba-0000IL-00; Mon, 23 Aug 2004 10:59:46 +1000 Original-To: guile-devel@gnu.org Mail-Copies-To: never User-Agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3 (gnu/linux) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:4012 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:4012 --=-=-= A simplification, * socket.c (scm_from_ipv6): Just use mpz_import. Don't bother trying to fit scm_from_ulong_long, since that uses mpz_import anyway. Don't bother trying to fit scm_from_ulong, not really worth the trouble if addresses are more than 4 bytes usually. --=-=-= Content-Disposition: inline; filename=socket.c.ipv6.diff --- socket.c.~1.107.~ 2004-08-20 11:00:38.000000000 +1000 +++ socket.c 2004-08-22 13:31:48.000000000 +1000 @@ -278,55 +278,7 @@ static SCM scm_from_ipv6 (const scm_t_uint8 *src) { - int i = 0; - const scm_t_uint8 *ptr = src; - int num_zero_bytes = 0; - scm_t_uint8 addr[16]; - - /* count leading zeros (since we know it's bigendian, they'll be first) */ - while (i < 16) - { - if (*ptr) break; - num_zero_bytes++; - i++; - } - - if (SCM_SIZEOF_UNSIGNED_LONG_LONG != 0) /* compiler should optimize this */ - { - if ((16 - num_zero_bytes) <= sizeof (unsigned long long)) - { - /* it fits */ - unsigned long long x; - - FLIPCPY_NET_HOST_128(addr, src); -#ifdef WORDS_BIGENDIAN - memcpy (&x, addr + (16 - sizeof (x)), sizeof (x)); -#else - memcpy (&x, addr, sizeof (x)); -#endif - return scm_from_ulong_long (x); - } - } - else - { - if ((16 - num_zero_bytes) <= sizeof (unsigned long)) - { - /* this is just so that we use INUM where possible. */ - unsigned long x; - - FLIPCPY_NET_HOST_128(addr, src); -#ifdef WORDS_BIGENDIAN - memcpy (&x, addr + (16 - sizeof (x)), sizeof (x)); -#else - memcpy (&x, addr, sizeof (x)); -#endif - return scm_from_ulong (x); - } - } - /* otherwise get the big hammer */ - { SCM result = scm_i_mkbig (); - mpz_import (SCM_I_BIG_MPZ (result), 1, /* chunk */ 1, /* big-endian chunk ordering */ @@ -335,7 +287,6 @@ 0, /* "nails" -- leading unused bits per chunk */ src); return scm_i_normbig (result); - } } /* convert a host ordered SCM integer to a 128 bit IPv6 address in --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://lists.gnu.org/mailman/listinfo/guile-devel --=-=-=--