unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Kevin Ryde <user42@zip.com.au>
Subject: scm_from_ipv6
Date: Mon, 23 Aug 2004 10:59:45 +1000	[thread overview]
Message-ID: <877jrqr7ni.fsf@zip.com.au> (raw)

[-- Attachment #1: Type: text/plain, Size: 302 bytes --]

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.


[-- Attachment #2: socket.c.ipv6.diff --]
[-- Type: text/plain, Size: 1808 bytes --]

--- 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

[-- Attachment #3: Type: text/plain, Size: 143 bytes --]

_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel

             reply	other threads:[~2004-08-23  0:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-23  0:59 Kevin Ryde [this message]
2004-08-23 10:27 ` scm_from_ipv6 Marius Vollmer
2004-08-23 12:25   ` mpz_import (was: scm_from_ipv6) Andreas Vögele
2004-08-23 13:19     ` mpz_import Marius Vollmer
2004-08-29 15:33       ` mpz_import Andreas Vögele
2004-08-31  7:47         ` mpz_import Andreas Vögele
2004-09-20 23:21           ` mpz_import Marius Vollmer
2004-09-21  0:28         ` mpz_import Marius Vollmer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877jrqr7ni.fsf@zip.com.au \
    --to=user42@zip.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).