[Zodb-checkins] SVN: ZODB/branches/fdrake-optional-64bits/ use
64-bit ints based on a compilation flag;
Fred L. Drake, Jr.
fdrake at gmail.com
Fri Apr 21 11:17:23 EDT 2006
Log message for revision 67222:
use 64-bit ints based on a compilation flag;
define ZODB_64BIT_INTS to get 64-bit ints for all "I" parts
Changed:
U ZODB/branches/fdrake-optional-64bits/src/BTrees/BTreeModuleTemplate.c
U ZODB/branches/fdrake-optional-64bits/src/BTrees/SetOpTemplate.c
U ZODB/branches/fdrake-optional-64bits/src/BTrees/intkeymacros.h
U ZODB/branches/fdrake-optional-64bits/src/BTrees/intvaluemacros.h
U ZODB/branches/fdrake-optional-64bits/src/BTrees/sorters.c
U ZODB/branches/fdrake-optional-64bits/src/BTrees/tests/testBTrees.py
U ZODB/branches/fdrake-optional-64bits/test.py
-=-
Modified: ZODB/branches/fdrake-optional-64bits/src/BTrees/BTreeModuleTemplate.c
===================================================================
--- ZODB/branches/fdrake-optional-64bits/src/BTrees/BTreeModuleTemplate.c 2006-04-21 14:51:34 UTC (rev 67221)
+++ ZODB/branches/fdrake-optional-64bits/src/BTrees/BTreeModuleTemplate.c 2006-04-21 15:17:22 UTC (rev 67222)
@@ -527,4 +527,11 @@
if (PyDict_SetItemString(d, MOD_NAME_PREFIX "TreeIterator",
(PyObject *)&BTreeIter_Type) < 0)
return;
+#if defined(ZODB_64BIT_INTS) && defined(NEED_LONG_LONG_SUPPORT)
+ if (PyDict_SetItemString(d, "using64bits", Py_True) < 0)
+ return;
+#else
+ if (PyDict_SetItemString(d, "using64bits", Py_False) < 0)
+ return;
+#endif
}
Modified: ZODB/branches/fdrake-optional-64bits/src/BTrees/SetOpTemplate.c
===================================================================
--- ZODB/branches/fdrake-optional-64bits/src/BTrees/SetOpTemplate.c 2006-04-21 14:51:34 UTC (rev 67221)
+++ ZODB/branches/fdrake-optional-64bits/src/BTrees/SetOpTemplate.c 2006-04-21 15:17:22 UTC (rev 67222)
@@ -543,7 +543,7 @@
*/
if (result->len > 0) {
size_t newlen; /* number of elements in final result set */
- newlen = sort_int8_nodups(result->keys, (size_t)result->len);
+ newlen = sort_int_nodups(result->keys, (size_t)result->len);
result->len = (int)newlen;
}
return (PyObject *)result;
Modified: ZODB/branches/fdrake-optional-64bits/src/BTrees/intkeymacros.h
===================================================================
--- ZODB/branches/fdrake-optional-64bits/src/BTrees/intkeymacros.h 2006-04-21 14:51:34 UTC (rev 67221)
+++ ZODB/branches/fdrake-optional-64bits/src/BTrees/intkeymacros.h 2006-04-21 15:17:22 UTC (rev 67222)
@@ -1,15 +1,11 @@
#define KEYMACROS_H "$Id$\n"
+#ifdef ZODB_64BIT_INTS
+/* PY_LONG_LONG as key */
#define NEED_LONG_LONG_SUPPORT
-
#define KEY_TYPE PY_LONG_LONG
-#undef KEY_TYPE_IS_PYOBJECT
#define KEY_CHECK longlong_check
-#define TEST_KEY_SET_OR(V, K, T) if ( ( (V) = (((K) < (T)) ? -1 : (((K) > (T)) ? 1: 0)) ) , 0 )
-#define DECREF_KEY(KEY)
-#define INCREF_KEY(k)
-#define COPY_KEY(KEY, E) (KEY=(E))
#define COPY_KEY_TO_OBJECT(O, K) O=longlong_as_object(K)
#define COPY_KEY_FROM_ARG(TARGET, ARG, STATUS) \
if (PyInt_Check(ARG)) TARGET=PyInt_AS_LONG(ARG); else \
@@ -20,4 +16,20 @@
else { \
PyErr_SetString(PyExc_TypeError, "expected integer key"); \
(STATUS)=0; (TARGET)=0; }
+#else
+/* C int as key */
+#define KEY_TYPE int
+#define KEY_CHECK PyInt_Check
+#define COPY_KEY_TO_OBJECT(O, K) O=PyInt_FromLong(K)
+#define COPY_KEY_FROM_ARG(TARGET, ARG, STATUS) \
+ if (PyInt_Check(ARG)) TARGET=PyInt_AS_LONG(ARG); else { \
+ PyErr_SetString(PyExc_TypeError, "expected integer key"); \
+ (STATUS)=0; (TARGET)=0; }
+#endif
+
+#undef KEY_TYPE_IS_PYOBJECT
+#define TEST_KEY_SET_OR(V, K, T) if ( ( (V) = (((K) < (T)) ? -1 : (((K) > (T)) ? 1: 0)) ) , 0 )
+#define DECREF_KEY(KEY)
+#define INCREF_KEY(k)
+#define COPY_KEY(KEY, E) (KEY=(E))
#define MULTI_INT_UNION 1
Modified: ZODB/branches/fdrake-optional-64bits/src/BTrees/intvaluemacros.h
===================================================================
--- ZODB/branches/fdrake-optional-64bits/src/BTrees/intvaluemacros.h 2006-04-21 14:51:34 UTC (rev 67221)
+++ ZODB/branches/fdrake-optional-64bits/src/BTrees/intvaluemacros.h 2006-04-21 15:17:22 UTC (rev 67222)
@@ -1,17 +1,10 @@
#define VALUEMACROS_H "$Id$\n"
+#ifdef ZODB_64BIT_INTS
#define NEED_LONG_LONG_SUPPORT
-
#define VALUE_TYPE PY_LONG_LONG
-#undef VALUE_TYPE_IS_PYOBJECT
-#define TEST_VALUE(K, T) (((K) < (T)) ? -1 : (((K) > (T)) ? 1: 0))
-#define VALUE_SAME(VALUE, TARGET) ( (VALUE) == (TARGET) )
-#define DECLARE_VALUE(NAME) VALUE_TYPE NAME
#define VALUE_PARSE "L"
-#define DECREF_VALUE(k)
-#define INCREF_VALUE(k)
-#define COPY_VALUE(V, E) (V=(E))
#define COPY_VALUE_TO_OBJECT(O, K) O=longlong_as_object(K)
#define COPY_VALUE_FROM_ARG(TARGET, ARG, STATUS) \
if (PyInt_Check(ARG)) TARGET=PyInt_AS_LONG(ARG); else \
@@ -22,7 +15,24 @@
else { \
PyErr_SetString(PyExc_TypeError, "expected integer key"); \
(STATUS)=0; (TARGET)=0; }
+#else
+#define VALUE_TYPE int
+#define VALUE_PARSE "i"
+#define COPY_VALUE_TO_OBJECT(O, K) O=PyInt_FromLong(K)
+#define COPY_VALUE_FROM_ARG(TARGET, ARG, STATUS) \
+ if (PyInt_Check(ARG)) TARGET=PyInt_AsLong(ARG); else { \
+ PyErr_SetString(PyExc_TypeError, "expected integer value"); \
+ (STATUS)=0; (TARGET)=0; }
+#endif
+#undef VALUE_TYPE_IS_PYOBJECT
+#define TEST_VALUE(K, T) (((K) < (T)) ? -1 : (((K) > (T)) ? 1: 0))
+#define VALUE_SAME(VALUE, TARGET) ( (VALUE) == (TARGET) )
+#define DECLARE_VALUE(NAME) VALUE_TYPE NAME
+#define DECREF_VALUE(k)
+#define INCREF_VALUE(k)
+#define COPY_VALUE(V, E) (V=(E))
+
#define NORMALIZE_VALUE(V, MIN) ((MIN) > 0) ? ((V)/=(MIN)) : 0
#define MERGE_DEFAULT 1
Modified: ZODB/branches/fdrake-optional-64bits/src/BTrees/sorters.c
===================================================================
--- ZODB/branches/fdrake-optional-64bits/src/BTrees/sorters.c 2006-04-21 14:51:34 UTC (rev 67221)
+++ ZODB/branches/fdrake-optional-64bits/src/BTrees/sorters.c 2006-04-21 15:17:22 UTC (rev 67222)
@@ -8,29 +8,30 @@
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
- FOR A PARTICULAR PURPOSE
+ FOR A PARTICULAR PURPOSE.
****************************************************************************/
/* Revision information: $Id$ */
/* The only routine here intended to be used outside the file is
- size_t sort_int8_nodups(int *p, size_t n)
+ size_t sort_int_nodups(int *p, size_t n)
Sort the array of n ints pointed at by p, in place, and also remove
duplicates. Return the number of unique elements remaining, which occupy
a contiguous and monotonically increasing slice of the array starting at p.
- Example: If the input array is [3, 1, 2, 3, 1, 5, 2], sort_int8_nodups
+ Example: If the input array is [3, 1, 2, 3, 1, 5, 2], sort_int_nodups
returns 4, and the first 4 elements of the array are changed to
[1, 2, 3, 5]. The content of the remaining array positions is not defined.
Notes:
- + This is specific to 8-byte signed ints, with endianness natural to the
- platform.
+ + This is specific to n-byte signed ints, with endianness natural to the
+ platform. `n` is determined based on ZODB_64BIT_INTS.
- + 8*n bytes of available heap memory are required for best speed.
+ + 4*n bytes of available heap memory are required for best speed
+ (8*n when ZODB_64BIT_INTS is defined).
*/
#include <stdlib.h>
@@ -45,7 +46,7 @@
the radix sort has to know everything about the type's internal
representation.
*/
-typedef PY_LONG_LONG element_type;
+typedef KEY_TYPE element_type;
/* The radixsort is faster than the quicksort for large arrays, but radixsort
has high fixed overhead, making it a poor choice for small arrays. The
@@ -72,25 +73,33 @@
swaps are done internally, the final result may come back in 'in' or 'work';
and that pointer is returned.
- radixsort_int8 is specific to signed 8-byte ints, with natural machine
- endianness.
+ radixsort_int is specific to signed n-byte ints, with natural machine
+ endianness. `n` is determined based on ZODB_64BIT_INTS.
*/
static element_type*
-radixsort_int8(element_type *in, element_type *work, size_t n)
+radixsort_int(element_type *in, element_type *work, size_t n)
{
/* count[i][j] is the number of input elements that have byte value j
in byte position i, where byte position 0 is the LSB. Note that
holding i fixed, the sum of count[i][j] over all j in range(256)
is n.
*/
+#ifdef ZODB_64BIT_INTS
size_t count[8][256];
+#else
+ size_t count[4][256];
+#endif
size_t i;
int offset, offsetinc;
/* Which byte position are we working on now? 0=LSB, 1, 2, ... */
int bytenum;
+#ifdef ZODB_64BIT_INTS
assert(sizeof(element_type) == 8);
+#else
+ assert(sizeof(element_type) == 4);
+#endif
assert(in);
assert(work);
@@ -102,10 +111,12 @@
++count[1][(x >> 8) & 0xff];
++count[2][(x >> 16) & 0xff];
++count[3][(x >> 24) & 0xff];
+#ifdef ZODB_64BIT_INTS
++count[4][(x >> 32) & 0xff];
++count[5][(x >> 40) & 0xff];
++count[6][(x >> 48) & 0xff];
++count[7][(x >> 56) & 0xff];
+#endif
}
/* For p an element_type* cast to char*, offset is how much farther we
@@ -502,12 +513,12 @@
/* Sort p and remove duplicates, as fast as we can. */
static size_t
-sort_int8_nodups(PY_LONG_LONG *p, size_t n)
+sort_int_nodups(KEY_TYPE *p, size_t n)
{
size_t nunique;
element_type *work;
- assert(sizeof(PY_LONG_LONG) == sizeof(element_type));
+ assert(sizeof(KEY_TYPE) == sizeof(element_type));
assert(p);
/* Use quicksort if the array is small, OR if malloc can't find
@@ -518,7 +529,7 @@
work = (element_type *)malloc(n * sizeof(element_type));
if (work) {
- element_type *out = radixsort_int8(p, work, n);
+ element_type *out = radixsort_int(p, work, n);
nunique = uniq(p, out, n);
free(work);
}
Modified: ZODB/branches/fdrake-optional-64bits/src/BTrees/tests/testBTrees.py
===================================================================
--- ZODB/branches/fdrake-optional-64bits/src/BTrees/tests/testBTrees.py 2006-04-21 14:51:34 UTC (rev 67221)
+++ ZODB/branches/fdrake-optional-64bits/src/BTrees/tests/testBTrees.py 2006-04-21 15:17:22 UTC (rev 67222)
@@ -20,6 +20,7 @@
from BTrees.IFBTree import IFBTree, IFBucket, IFSet, IFTreeSet
from BTrees.OIBTree import OIBTree, OIBucket, OISet, OITreeSet
+from BTrees.IIBTree import using64bits
from BTrees.check import check
import transaction
@@ -1241,6 +1242,17 @@
self._set_value, k1, LARGEST_NEGATIVE_65_BITS)
+if not using64bits:
+ # We're not using 64-bit ints in this build, so we don't expect
+ # the long-integer tests to pass.
+
+ class TestLongIntKeys:
+ pass
+
+ class TestLongIntValues:
+ pass
+
+
# tests of various type errors
class TypeTest(TestCase):
Modified: ZODB/branches/fdrake-optional-64bits/test.py
===================================================================
--- ZODB/branches/fdrake-optional-64bits/test.py 2006-04-21 14:51:34 UTC (rev 67221)
+++ ZODB/branches/fdrake-optional-64bits/test.py 2006-04-21 15:17:22 UTC (rev 67222)
@@ -60,6 +60,7 @@
defaults = [
"--path", path,
+ "-m", "!^zope[.]",
]
testrunner.run(defaults)
More information about the Zodb-checkins
mailing list