Commit 3bc05b0e authored by Jim Fulton's avatar Jim Fulton

Added a missing type error to void crashes under unlikely situations.

parent dee3bca2
......@@ -474,23 +474,23 @@ pickle___setstate__(PyObject *self, PyObject *state)
PyObject **dict;
dict = _PyObject_GetDictPtr(self);
if (dict)
if (!dict)
{
if (!*dict)
{
*dict = PyDict_New();
if (!*dict)
return NULL;
}
PyErr_SetString(PyExc_TypeError,
"this object has no instance dictionary");
return NULL;
}
if (*dict)
if (!*dict)
{
PyDict_Clear(*dict);
if (PyDict_Update(*dict, state) < 0)
*dict = PyDict_New();
if (!*dict)
return NULL;
}
else if (pickle_setattrs_from_dict(self, state) < 0)
PyDict_Clear(*dict);
if (PyDict_Update(*dict, state) < 0)
return NULL;
}
......
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# Copyright (c) Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# 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.
#
##############################################################################
import unittest
from zope.testing import doctest
from persistent import Persistent
......@@ -20,5 +21,23 @@ class P(Persistent):
def inc(self):
self.x += 1
def cpersistent_setstate_pointer_sanity():
"""
>>> Persistent().__setstate__({})
Traceback (most recent call last):
...
TypeError: this object has no instance dictionary
>>> class C(Persistent): __slots__ = 'x', 'y'
>>> C().__setstate__(({}, {}))
Traceback (most recent call last):
...
TypeError: this object has no instance dictionary
"""
def test_suite():
return doctest.DocFileSuite("persistent.txt", globs={"P": P})
return unittest.TestSuite((
doctest.DocFileSuite("persistent.txt", globs={"P": P}),
doctest.DocTestSuite(),
))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment