[Checkins] SVN: BTrees/branches/py3k/ Fix longlong keys edge-cases keys across supported Pythons.
Tres Seaver
cvs-admin at zope.org
Mon Dec 17 16:35:59 UTC 2012
Log message for revision 128687:
Fix longlong keys edge-cases keys across supported Pythons.
Changed:
_U BTrees/branches/py3k/
U BTrees/branches/py3k/BTrees/BTreeModuleTemplate.c
U BTrees/branches/py3k/BTrees/intkeymacros.h
-=-
Modified: BTrees/branches/py3k/BTrees/BTreeModuleTemplate.c
===================================================================
--- BTrees/branches/py3k/BTrees/BTreeModuleTemplate.c 2012-12-17 00:26:40 UTC (rev 128686)
+++ BTrees/branches/py3k/BTrees/BTreeModuleTemplate.c 2012-12-17 16:35:58 UTC (rev 128687)
@@ -110,6 +110,48 @@
#endif
+#ifdef NEED_LONG_LONG_KEYS
+static int
+longlong_convert(PyObject *ob, PY_LONG_LONG *value)
+{
+#ifndef PY3K
+ if (PyInt_Check(ob))
+ {
+ (*value) = (PY_LONG_LONG)PyInt_AS_LONG(ob);
+ return 1;
+ }
+#endif
+
+ if (!PyLong_Check(ob))
+ {
+ PyErr_SetString(PyExc_TypeError, "expected integer key");
+ return 0;
+ }
+ else
+ {
+ PY_LONG_LONG val;
+#if PY_VERSION_HEX < 0x02070000
+ /* check magnitude */
+ val = PyLong_AsLongLong(ob);
+
+ if (val == -1 && PyErr_Occurred())
+ goto overflow;
+#else
+ int overflow;
+ val = PyLong_AsLongLongAndOverflow(ob, &overflow);
+ if (overflow)
+ goto overflow;
+#endif
+ (*value) = val;
+ return 1;
+ }
+overflow:
+ PyErr_SetString(PyExc_ValueError, "long integer out of range");
+ return 0;
+}
+#endif
+
+
/* Various kinds of BTree and Bucket structs are instances of
* "sized containers", and have a common initial layout:
* The stuff needed for all Python objects, or all Persistent objects.
Modified: BTrees/branches/py3k/BTrees/intkeymacros.h
===================================================================
--- BTrees/branches/py3k/BTrees/intkeymacros.h 2012-12-17 00:26:40 UTC (rev 128686)
+++ BTrees/branches/py3k/BTrees/intkeymacros.h 2012-12-17 16:35:58 UTC (rev 128687)
@@ -4,18 +4,15 @@
#ifdef ZODB_64BIT_INTS
/* PY_LONG_LONG as key */
#define NEED_LONG_LONG_SUPPORT
+#define NEED_LONG_LONG_KEYS
#define KEY_TYPE PY_LONG_LONG
#define KEY_CHECK longlong_check
#define COPY_KEY_TO_OBJECT(O, K) O=longlong_as_object(K)
#define COPY_KEY_FROM_ARG(TARGET, ARG, STATUS) \
- if (INT_CHECK(ARG)) TARGET=INT_AS_LONG(ARG); else \
- if (longlong_check(ARG)) TARGET=PyLong_AsLongLong(ARG); else \
- if (PyLong_Check(ARG)) { \
- PyErr_SetString(PyExc_ValueError, "long integer out of range"); \
- (STATUS)=0; (TARGET)=0; } \
- else { \
- PyErr_SetString(PyExc_TypeError, "expected integer key"); \
- (STATUS)=0; (TARGET)=0; }
+ if (!longlong_convert((ARG), &TARGET)) \
+ { \
+ (STATUS)=0; (TARGET)=0; \
+ }
#else
/* C int as key */
#define KEY_TYPE int
More information about the checkins
mailing list