Commit cb6a544c authored by Tres Seaver's avatar Tres Seaver

Deal with unicode attribute names under Py3k.

parent a20f0a72
...@@ -83,6 +83,8 @@ fatal_1350(cPersistentObject *self, const char *caller, const char *detail) ...@@ -83,6 +83,8 @@ fatal_1350(cPersistentObject *self, const char *caller, const char *detail)
static void ghostify(cPersistentObject*); static void ghostify(cPersistentObject*);
static PyObject * convert_name(PyObject *name);
/* Load the state of the object, unghostifying it. Upon success, return 1. /* Load the state of the object, unghostifying it. Upon success, return 1.
* If an error occurred, re-ghostify the object and return -1. * If an error occurred, re-ghostify the object and return -1.
*/ */
...@@ -349,13 +351,24 @@ pickle_copy_dict(PyObject *state) ...@@ -349,13 +351,24 @@ pickle_copy_dict(PyObject *state)
while (PyDict_Next(state, &pos, &key, &value)) while (PyDict_Next(state, &pos, &key, &value))
{ {
int is_special;
#ifdef PY3K
if (key && PyUnicode_Check(key))
{
PyObject *converted = convert_name(key);
ckey = PyBytes_AS_STRING(converted);
#else
if (key && PyBytes_Check(key)) if (key && PyBytes_Check(key))
{ {
ckey = PyBytes_AS_STRING(key); ckey = PyBytes_AS_STRING(key);
if (*ckey == '_' && #endif
(ckey[1] == 'v' || ckey[1] == 'p') && is_special = (*ckey == '_' &&
ckey[2] == '_') (ckey[1] == 'v' || ckey[1] == 'p') &&
/* skip volatile and persistent */ ckey[2] == '_');
#ifdef PY3K
Py_DECREF(converted);
#endif
if (is_special) /* skip volatile and persistent */
continue; continue;
} }
...@@ -417,17 +430,30 @@ pickle___getstate__(PyObject *self) ...@@ -417,17 +430,30 @@ pickle___getstate__(PyObject *self)
for (i = 0; i < PyList_GET_SIZE(slotnames); i++) for (i = 0; i < PyList_GET_SIZE(slotnames); i++)
{ {
PyObject *name, *value; PyObject *name, *value;
char *cname;
name = PyList_GET_ITEM(slotnames, i); name = PyList_GET_ITEM(slotnames, i);
#ifdef PY3K
if (PyUnicode_Check(name))
{
char *cname;
int is_special;
PyObject *converted = convert_name(name);
cname = PyBytes_AS_STRING(converted);
#else
if (PyBytes_Check(name)) if (PyBytes_Check(name))
{ {
cname = PyBytes_AS_STRING(name); cname = PyBytes_AS_STRING(name);
if (*cname == '_' && #endif
(cname[1] == 'v' || cname[1] == 'p') && is_special = (*cname == '_' &&
cname[2] == '_') (cname[1] == 'v' || cname[1] == 'p') &&
/* skip volatile and persistent */ cname[2] == '_');
#ifdef PY3K
Py_DECREF(converted);
#endif
if (is_special) /* skip volatile and persistent */
{
continue; continue;
}
} }
/* Unclear: Will this go through our getattr hook? */ /* Unclear: Will this go through our getattr hook? */
......
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