[ZODB-Dev] persistence errors with python2.5 64 bit linux

Jim Fulton jim at zope.com
Tue Oct 16 08:33:18 EDT 2007


Interesting.  I'm amazed that this wasn't caught by any of the  
extensive ZODB tests.

Would you mind submitting this as a bug report: https://launchpad.net/ 
zodb/+filebug

Jim

On Oct 16, 2007, at 6:14 AM, Shane Evans wrote:

> Hi,
>
> I was looking at zodb for the first time and noticed a problem  
> where persistent objects would be read and not have all their  
> attributes.  A simple test case it attached (persistent_error.py).   
> It prints "not set" when I run it.
>
> After a little poking it seems the error is with the use of int  
> instead of Py_ssize_t. The attached patch fixed my problem - I  
> thought I'd send it around in case it was of use to others. I  
> noticed a few other places where int is also used in this context,  
> it's probably worth changing everywhere and adding the appropriate  
> "#if PY_VERSION_HEX" incantation.
>
> Cheers,
>
> Shane
>
>
> from ZODB import FileStorage, DB
> from persistent import Persistent
> import transaction
>
> import logging
> console = logging.StreamHandler()
> console.setLevel(logging.DEBUG)
> logging.getLogger('').addHandler(console)
>
> testfile = 'test.fs'
>
> storage = FileStorage.FileStorage(testfile)
> db = DB(storage)
> conn = db.open()
> dbroot = conn.root()
>
> class TestPersistent(Persistent):
>     pass
>
> t = TestPersistent()
> t.foo = 'bar'
> dbroot['test'] = t
>
> transaction.commit()
> conn.close()
> db.close()
> storage.close()
>
> storage = FileStorage.FileStorage(testfile, read_only=True)
> db = DB(storage)
> conn = db.open()
> dbroot = conn.root()
>
> t = dbroot['test']
> if t:
>     # I would expect this to print 'bar'
>     msg = getattr(t, 'foo', 'not set')
>     print msg
> else:
>     print "t not in database"
> diff -burN ZODB3-3.7.2/src/persistent/cPersistence.c  
> ZODB3-3.7.2_patch/src/persistent/cPersistence.c
> --- ZODB3-3.7.2/src/persistent/cPersistence.c	2007-06-17  
> 05:13:28.000000000 +0900
> +++ ZODB3-3.7.2_patch/src/persistent/cPersistence.c	2007-10-16  
> 17:45:18.000000000 +0900
> @@ -300,7 +300,7 @@
>  {
>      PyObject *copy, *key, *value;
>      char *ckey;
> -    int pos = 0;
> +    Py_ssize_t pos = 0;
>
>      copy = PyDict_New();
>      if (!copy)
> @@ -414,7 +414,7 @@
>  pickle_setattrs_from_dict(PyObject *self, PyObject *dict)
>  {
>      PyObject *key, *value;
> -    int pos = 0;
> +    Py_ssize_t pos = 0;
>
>      if (!PyDict_Check(dict)) {
>  	PyErr_SetString(PyExc_TypeError, "Expected dictionary");
> diff -burN ZODB3-3.7.2/src/persistent/cPickleCache.c  
> ZODB3-3.7.2_patch/src/persistent/cPickleCache.c
> --- ZODB3-3.7.2/src/persistent/cPickleCache.c	2007-06-17  
> 05:13:28.000000000 +0900
> +++ ZODB3-3.7.2_patch/src/persistent/cPickleCache.c	2007-10-16  
> 17:44:36.000000000 +0900
> @@ -378,7 +378,7 @@
>  cc_invalidate(ccobject *self, PyObject *inv)
>  {
>    PyObject *key, *v;
> -  int i = 0;
> +  Py_ssize_t i = 0;
>
>    if (PyDict_Check(inv))
>      {
> @@ -448,7 +448,7 @@
>  cc_klass_items(ccobject *self)
>  {
>      PyObject *l,*k,*v;
> -    int p = 0;
> +    Py_ssize_t p = 0;
>
>      l = PyList_New(0);
>      if (l == NULL)
> @@ -477,7 +477,7 @@
>  cc_debug_info(ccobject *self)
>  {
>      PyObject *l,*k,*v;
> -    int p = 0;
> +    Py_ssize_t p = 0;
>
>      l = PyList_New(0);
>      if (l == NULL)
> @@ -707,7 +707,7 @@
>  static int
>  cc_clear(ccobject *self)
>  {
> -    int pos = 0;
> +    Py_ssize_t pos = 0;
>      PyObject *k, *v;
>      /* Clearing the cache is delicate.
>
> _______________________________________________
> For more information about ZODB, see the ZODB Wiki:
> http://www.zope.org/Wikis/ZODB/
>
> ZODB-Dev mailing list  -  ZODB-Dev at zope.org
> http://mail.zope.org/mailman/listinfo/zodb-dev

--
Jim Fulton
Zope Corporation




More information about the ZODB-Dev mailing list