[Zodb-checkins] CVS: Zope/lib/python/ZODB - cPickleCache.c:1.62
Toby Dickenson
tdickenson@geminidataloggers.com
Thu, 18 Apr 2002 05:16:25 -0400
Update of /cvs-repository/Zope/lib/python/ZODB
In directory cvs.zope.org:/tmp/cvs-serv3239
Modified Files:
cPickleCache.c
Log Message:
Extra sanity checks on attributes of persistent objects; enough to fix a broken test case
=== Zope/lib/python/ZODB/cPickleCache.c 1.61 => 1.62 ===
{
int result;
- PyObject *oid, *object_again;
+ PyObject *oid, *object_again, *jar;
cPersistentObject *p;
if (PyExtensionClass_Check(v)) {
@@ -810,8 +810,15 @@
oid = PyObject_GetAttr(v, py__p_oid);
if (oid == NULL)
return -1;
- /* XXX key and oid should both be PyString objects.
- May be helpful to check this. */
+ if (!PyString_Check(oid)) {
+ PyErr_Format(PyExc_TypeError,
+ "Cached object oid must be a string, not a %s",
+ oid->ob_type->tp_name);
+ return -1;
+ }
+ /* we know they are both strings.
+ * now check if they are the same string.
+ */
result = PyObject_Compare(key, oid);
if (PyErr_Occurred()) {
Py_DECREF(oid);
@@ -819,11 +826,20 @@
}
Py_DECREF(oid);
if (result) {
- PyErr_SetString(PyExc_ValueError, "cache key does not match oid");
+ PyErr_SetString(PyExc_ValueError, "Cache key does not match oid");
return -1;
}
- /* XXX check that object has valid _p_jar? */
+ /* useful sanity check, but not strictly an invariant of this class */
+ jar = PyObject_GetAttr(v, py__p_jar);
+ if (jar == NULL)
+ return -1;
+ Py_DECREF(jar);
+ if (jar==Py_None) {
+ PyErr_SetString(PyExc_ValueError,
+ "Cached object jar missing");
+ return -1;
+ }
object_again = object_from_oid(self, key);
if (object_again) {