Sophie

Sophie

distrib > Fedora > 16 > i386 > by-pkgid > d661b8115276f128072a3ff16f0671be > files > 2

python-guppy-0.1.9-4.fc16.src.rpm

From 928398014a407c5728af44b57c4d9fe9994376f4 Mon Sep 17 00:00:00 2001
From: Sverker Nilsson <sn@sncs.se>
Date: Sun, 14 Feb 2010 11:24:42 +0000
Subject: [PATCH 1/2] Work with big endian archs

git-svn-id: https://guppy-pe.svn.sourceforge.net/svnroot/guppy-pe/trunk/guppy@83 a2a17790-8729-0410-921b-93eeb8b3d4a2

In latest patch to src/sets/bitset.c (mutbitset_iop_PyLongObject) changed typo of pos from int to NyBit to handle very large objects in 64-bits mode

git-svn-id: https://guppy-pe.svn.sourceforge.net/svnroot/guppy-pe/trunk/guppy@84 a2a17790-8729-0410-921b-93eeb8b3d4a2
---
 ChangeLog         |   11 +++++++++++
 src/sets/bitset.c |   16 ++++++++++++++--
 src/sets/bitset.h |   26 ++++++++++++++++++++++++++
 3 files changed, 51 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 55aecfd..bbc851c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2010-02-14  Sverker Nilsson  <sverker@sverker-laptop>
+	* src/sets/bitset.c (mutbitset_iop_PyLongObject): 
+	In the latest change where a loop over pos was added, changed type
+	from int to NyBit.
+	
+	* src/sets/bitset.h: Checks endianness and defines macros to
+	handle it.
+	* src/sets/bitset.c (immbitset_long): 
+	* src/sets/bitset.c (mutbitset_iop_PyLongObject): 
+	Changes to work with big endian.
+
 2009-06-23  Sverker Nilsson  <sverker@sverker-laptop>
 
 	* specs/index.gsl: download mentions today's date
diff --git a/src/sets/bitset.c b/src/sets/bitset.c
index 41dbdd5..2a9d6c0 100644
--- a/src/sets/bitset.c
+++ b/src/sets/bitset.c
@@ -2050,6 +2050,15 @@ mutbitset_iop_PyLongObject(NyMutBitSetObject *ms, int op, PyObject *v)
 			1, /* little_endian */
 			0  /* is_signed */);
     if (r == -1) goto Err1;
+#if NyBits_IS_BIG_ENDIAN
+    {
+	NyBit pos;
+	for (pos = 0; pos < num_poses; pos++) {
+	    buf[pos] = NyBits_BSWAP(buf[pos]);
+	}
+    }
+#endif
+
     r = mutbitset_iop_bits(ms, op, 0, buf, num_poses);
     if (!r && cpl)
       r = mutbitset_iop_complement(ms);
@@ -3126,7 +3135,10 @@ immbitset_long(NyImmBitSetObject *v)
     }
     for (pos = 0; pos < num_poses; pos++) {
 	if (pos == f->pos) {
-	    bits = f->bits;		/* xxx may want to byte-swap here */
+	    bits = f->bits;
+#if NyBits_IS_BIG_ENDIAN
+	    bits = NyBits_BSWAP(bits);
+#endif
 	    f++;
 	} else {
 	    bits = NyBits_EMPTY;
@@ -3135,7 +3147,7 @@ immbitset_long(NyImmBitSetObject *v)
     }
     r = _PyLong_FromByteArray((unsigned char *)buf,		/* bytes */
 			      num_poses * sizeof(NyBits),	/* n = number of bytes*/
-			      1,	/* Always little endian here (xxx?) */
+			      1,	/* Always little endian here */
 			      0);	/* not is_signed, never here */
     PyMem_Del(buf);
     return r;
diff --git a/src/sets/bitset.h b/src/sets/bitset.h
index 7fe3e82..cc05f47 100644
--- a/src/sets/bitset.h
+++ b/src/sets/bitset.h
@@ -32,6 +32,32 @@ typedef unsigned long NyBits;
 #endif
 
 
+/* Assume __BYTE_ORDER is defined on all big-endian archs and that they
+   have byteswap.h. Little-endian archs don't include byteswap.h, so
+   it should still work with eg MSC.
+*/
+
+#ifdef __BYTE_ORDER
+#if __BYTE_ORDER==__BIG_ENDIAN
+
+#define NyBits_IS_BIG_ENDIAN 1
+
+#include "byteswap.h"
+
+#if (NyBits_N==64)
+#define NyBits_BSWAP(x) bswap_64(x)
+#elif (NyBits_N==32)
+#define NyBits_BSWAP(x) bswap_32(x)
+#else
+#error "Unsupported NyBits_N"
+#endif
+
+#endif
+#endif
+
+
+
+
 typedef Py_intptr_t NyBit;
 
 /* Largest positive value of type NyBit. */
-- 
1.7.4