[Checkins] SVN: zope.proxy/branches/regebro-python3/src/zope/proxy/ Some steps forward, and clearing up of what caused that segmentation fault.

Lennart Regebro regebro at gmail.com
Fri Nov 19 17:17:40 EST 2010


Log message for revision 118506:
  Some steps forward, and clearing up of what caused that segmentation fault.
  

Changed:
  U   zope.proxy/branches/regebro-python3/src/zope/proxy/_zope_proxy_proxy.c
  U   zope.proxy/branches/regebro-python3/src/zope/proxy/tests/test_proxy.py

-=-
Modified: zope.proxy/branches/regebro-python3/src/zope/proxy/_zope_proxy_proxy.c
===================================================================
--- zope.proxy/branches/regebro-python3/src/zope/proxy/_zope_proxy_proxy.c	2010-11-19 21:58:24 UTC (rev 118505)
+++ zope.proxy/branches/regebro-python3/src/zope/proxy/_zope_proxy_proxy.c	2010-11-19 22:17:40 UTC (rev 118506)
@@ -203,7 +203,7 @@
     const char *name_as_string;
     int maybe_special_name;
 
-#ifdef Py_USING_UNICODE
+#if PY_MAJOR_VERSION < 3 && defined(Py_USING_UNICODE)
     /* The Unicode to string conversion is done here because the
        existing tp_getattro slots expect a string object as name
        and we wouldn't want to break those. */
@@ -229,8 +229,9 @@
 #if PY_MAJOR_VERSION < 3
     name_as_string = PyString_AS_STRING(name);
 #else
-    name_as_string = PyBytes_AS_STRING(name);
+    name_as_string = PyBytes_AS_STRING(PyUnicode_AsUTF8String(name));
 #endif
+    printf("======\n%s=======\n", name_as_string);
 
     wrapped = Proxy_GET_OBJECT(self);
     if (wrapped == NULL) {
@@ -293,7 +294,7 @@
     const char *name_as_string;
     int res = -1;
 
-#ifdef Py_USING_UNICODE
+#if PY_MAJOR_VERSION < 3 && defined(Py_USING_UNICODE)
     /* The Unicode to string conversion is done here because the
        existing tp_setattro slots expect a string object as name
        and we wouldn't want to break those. */
@@ -308,7 +309,7 @@
 #if PY_MAJOR_VERSION < 3
     if (!PyString_Check(name)){
 #else
-    if (!PyUnicode_Check(name)){
+    if (!PyBytes_Check(name)){
 #endif
         PyErr_SetString(PyExc_TypeError, "attribute name must be string");
         return -1;
@@ -331,7 +332,7 @@
 #if PY_MAJOR_VERSION < 3
     name_as_string = PyString_AS_STRING(name);
 #else
-    name_as_string = PyBytes_AS_STRING(name);
+    name_as_string = PyBytes_AS_STRING(PyUnicode_AsUTF8String(name));
 #endif
 
     wrapped = Proxy_GET_OBJECT(self);

Modified: zope.proxy/branches/regebro-python3/src/zope/proxy/tests/test_proxy.py
===================================================================
--- zope.proxy/branches/regebro-python3/src/zope/proxy/tests/test_proxy.py	2010-11-19 21:58:24 UTC (rev 118505)
+++ zope.proxy/branches/regebro-python3/src/zope/proxy/tests/test_proxy.py	2010-11-19 22:17:40 UTC (rev 118506)
@@ -162,8 +162,9 @@
         self.assert_(w2 <= o2)
 
     def test_proxy_callable(self):
-        w = self.new_proxy({}.get)
-        self.assert_(callable(w))
+        if sys.version < '3': # Gone in Python 3:
+            w = self.new_proxy({}.get)
+            self.assert_(callable(w))
 
     def test_proxy_item_protocol(self):
         w = self.new_proxy({})
@@ -220,8 +221,10 @@
 
     unops = [
         "-x", "+x", "abs(x)", "~x",
-        "int(x)", "long(x)", "float(x)",
+        "int(x)", "float(x)",
         ]
+    if sys.version < '3': # long is gone in Python 3
+        unops.append("long(x)") 
 
     def test_unops(self):
         P = self.new_proxy



More information about the checkins mailing list