[Checkins] SVN: persistent/trunk/ Deal with unicode attribute names under Py3k.

Tres Seaver cvs-admin at zope.org
Fri Dec 14 01:51:26 UTC 2012


Log message for revision 128644:
  Deal with unicode attribute names under Py3k.

Changed:
  _U  persistent/trunk/
  U   persistent/trunk/persistent/cPersistence.c

-=-
Modified: persistent/trunk/persistent/cPersistence.c
===================================================================
--- persistent/trunk/persistent/cPersistence.c	2012-12-14 01:51:26 UTC (rev 128643)
+++ persistent/trunk/persistent/cPersistence.c	2012-12-14 01:51:26 UTC (rev 128644)
@@ -83,6 +83,8 @@
 
 static void ghostify(cPersistentObject*);
 
+static PyObject * convert_name(PyObject *name);
+
 /* Load the state of the object, unghostifying it.  Upon success, return 1.
  * If an error occurred, re-ghostify the object and return -1.
  */
@@ -349,13 +351,24 @@
 
     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))
         {
             ckey = PyBytes_AS_STRING(key);
-            if (*ckey == '_' &&
-                (ckey[1] == 'v' || ckey[1] == 'p') &&
-                ckey[2] == '_')
-                /* skip volatile and persistent */
+#endif
+            is_special = (*ckey == '_' &&
+                          (ckey[1] == 'v' || ckey[1] == 'p') &&
+                           ckey[2] == '_');
+#ifdef PY3K
+            Py_DECREF(converted);
+#endif
+            if (is_special) /* skip volatile and persistent */
                 continue;
         }
 
@@ -417,17 +430,30 @@
         for (i = 0; i < PyList_GET_SIZE(slotnames); i++)
         {
             PyObject *name, *value;
-            char *cname;
 
             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))
             {
                 cname = PyBytes_AS_STRING(name);
-                if (*cname == '_' &&
-                    (cname[1] == 'v' || cname[1] == 'p') &&
-                    cname[2] == '_')
-                    /* skip volatile and persistent */
+#endif
+                is_special = (*cname == '_' &&
+                              (cname[1] == 'v' || cname[1] == 'p') &&
+                               cname[2] == '_');
+#ifdef PY3K
+                Py_DECREF(converted);
+#endif
+                if (is_special) /* skip volatile and persistent */
+                {
                     continue;
+                }
             }
 
             /* Unclear:  Will this go through our getattr hook? */



More information about the checkins mailing list