From ae137ef75a77f539f501c1d718f9effa710621e8 Mon Sep 17 00:00:00 2001
From: Mark Florisson <markflorisson88@gmail.com>
Date: Mon, 24 Jan 2011 23:06:52 +0100
Subject: [PATCH] Debugger: Python 3 compatibility testsuite

---
 Cython/Debugger/Tests/test_libcython_in_gdb.py | 5 ++++-
 Cython/Debugger/Tests/test_libpython_in_gdb.py | 6 +++---
 Cython/Debugger/libpython.py                   | 2 +-
 3 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/Cython/Debugger/Tests/test_libcython_in_gdb.py b/Cython/Debugger/Tests/test_libcython_in_gdb.py
index 79de18581..6003be089 100644
--- a/Cython/Debugger/Tests/test_libcython_in_gdb.py
+++ b/Cython/Debugger/Tests/test_libcython_in_gdb.py
@@ -232,7 +232,10 @@ class TestStep(DebugStepperTestCase):
         self.assertEqual(curframe.name(), 'PyEval_EvalFrameEx')
 
         pyframe = libpython.Frame(curframe).get_pyop()
-        self.assertEqual(str(pyframe.co_name), 'join')
+        # With Python 3 inferiors, pyframe.co_name will return a PyUnicodePtr,
+        # be compatible
+        frame_name = pyframe.co_name.proxyval(set())
+        self.assertEqual(frame_name, 'join')
         assert re.match(r'\d+    def join\(', result), result
 
 
diff --git a/Cython/Debugger/Tests/test_libpython_in_gdb.py b/Cython/Debugger/Tests/test_libpython_in_gdb.py
index 5e0407d9e..e45adb22f 100644
--- a/Cython/Debugger/Tests/test_libpython_in_gdb.py
+++ b/Cython/Debugger/Tests/test_libpython_in_gdb.py
@@ -52,14 +52,14 @@ class TestPrettyPrinters(test_libcython_in_gdb.DebugTestCase):
 
     def alloc_bytestring(self, string, gdbvar=None):
         if inferior_python_version < (3, 0):
-            funcname = 'PyString_FromString'
+            funcname = 'PyString_FromStringAndSize'
         else:
-            funcname = 'PyBytes_FromString'
+            funcname = 'PyBytes_FromStringAndSize'
 
         assert '"' not in string
 
         # ensure double quotes
-        code = '(PyObject *) %s("%s")' % (funcname, string)
+        code = '(PyObject *) %s("%s", %d)' % (funcname, string, len(string))
         return self.pyobject_fromcode(code, gdbvar=gdbvar)
 
     def alloc_unicodestring(self, string, gdbvar=None):
diff --git a/Cython/Debugger/libpython.py b/Cython/Debugger/libpython.py
index 769ecd066..78534a490 100644
--- a/Cython/Debugger/libpython.py
+++ b/Cython/Debugger/libpython.py
@@ -2281,7 +2281,7 @@ class PythonCodeExecutor(object):
         except RuntimeError:
             # Python 3
             PyString_FromStringAndSize = ('PyUnicode%s_FromStringAndSize' %
-                                               (get_inferior_unicode_postfix,))
+                                               (get_inferior_unicode_postfix(),))
 
         try:
             result = gdb.parse_and_eval(
-- 
2.30.9