[Zodb-checkins] CVS: ZODB3/BDBStorage - _helper.c:1.4.18.2

Tim Peters tim.one at comcast.net
Tue Jul 15 12:54:48 EDT 2003


Update of /cvs-repository/ZODB3/BDBStorage
In directory cvs.zope.org:/tmp/cvs-serv8980/BDBStorage

Modified Files:
      Tag: zodb33-devel-branch
	_helper.c 
Log Message:
helper_incr():  Backported a non-leaking version from ZODB4 (this version
leaked two longs per call).  Documented what the heck this function does.
Noted that what it does may not match what it intended to do in overflow
endcases (I don't know the intent -- I'll ask Barry when he gets back).


=== ZODB3/BDBStorage/_helper.c 1.4.18.1 => 1.4.18.2 ===
--- ZODB3/BDBStorage/_helper.c:1.4.18.1	Tue Jul 15 11:38:20 2003
+++ ZODB3/BDBStorage/_helper.c	Tue Jul 15 11:54:42 2003
@@ -23,10 +23,17 @@
 #error "Must be using at least Python 2.2"
 #endif
 
+/* Increment an 8-byte unsigned integer (represented as an 8-byte raw string),
+ * by a Python integer.
+ * The arguments are an 8-byte Python string, and a Python int or long.
+ * The result is an 8-byte Python string, representing their sum.
+ * XXX It's unclear what this intends to do if the sum overflows an 8-byte
+ * XXX signed integer.  _PyLong_AsByteArray should raise OverflowError then.
+ */
 static PyObject*
 helper_incr(PyObject* self, PyObject* args)
 {
-    PyObject *pylong, *incr, *sum;
+    PyObject *pylong = NULL, *incr, *sum = NULL, *result = NULL;
     char *s, x[8];
     int len, res;
 
@@ -48,15 +55,19 @@
 
     sum = PyNumber_Add(pylong, incr);
     if (!sum)
-        return NULL;
+	goto err;
 
     res = _PyLong_AsByteArray((PyLongObject*)sum, x, 8,
                               0 /* big endian */,
                               0 /* unsigned */);
     if (res < 0)
-        return NULL;
+	goto err;
 
-    return PyString_FromStringAndSize(x, 8);
+    result = PyString_FromStringAndSize(x, 8);
+ err:
+    Py_XDECREF(pylong);
+    Py_XDECREF(sum);
+    return result;
 }
 
 




More information about the Zodb-checkins mailing list