Commits

Armin Rigo committed 2b1c8d8 Merge

Merged in squeaky/pypy/curses_fixes (pull request #174)

Fix some bugs regarding not dereferencing cffi pointers

Comments (0)

Files changed (3)

lib_pypy/_curses.py

     r, g, b = ffi.new("short *"), ffi.new("short *"), ffi.new("short *")
     if lib.color_content(color, r, g, b) == lib.ERR:
         raise error("Argument 1 was out of range. Check value of COLORS.")
-    return (r, g, b)
+    return (r[0], g[0], b[0])
 
 
 def color_pair(n):
         term = ffi.NULL
     err = ffi.new("int *")
     if lib.setupterm(term, fd, err) == lib.ERR:
+        err = err[0]
         if err == 0:
             raise error("setupterm: could not find terminal")
         elif err == -1:

pypy/doc/whatsnew-head.rst

 .. branch: fast-slowpath
 Added an abstraction for functions with a fast and slow path in the JIT. This
 speeds up list.append() and list.pop().
+
+.. branch: curses_fixes

pypy/module/test_lib_pypy/test_curses.py

+from lib_pypy import _curses
+
+import pytest
+
+lib = _curses.lib
+
+
+def test_color_content(monkeypatch):
+    def lib_color_content(color, r, g, b):
+        r[0], g[0], b[0] = 42, 43, 44
+        return lib.OK
+
+    monkeypatch.setattr(_curses, '_ensure_initialised_color', lambda: None)
+    monkeypatch.setattr(lib, 'color_content', lib_color_content)
+
+    assert _curses.color_content(None) == (42, 43, 44)
+
+
+def test_setupterm(monkeypatch):
+    def make_setupterm(err_no):
+        def lib_setupterm(term, fd, err):
+            err[0] = err_no
+
+            return lib.ERR
+
+        return lib_setupterm
+
+    monkeypatch.setattr(_curses, '_initialised_setupterm', False)
+    monkeypatch.setattr(lib, 'setupterm', make_setupterm(0))
+
+    with pytest.raises(Exception) as exc_info:
+        _curses.setupterm()
+
+    assert "could not find terminal" in exc_info.value.args[0]
+
+    monkeypatch.setattr(lib, 'setupterm', make_setupterm(-1))
+
+    with pytest.raises(Exception) as exc_info:
+        _curses.setupterm()
+
+    assert "could not find terminfo database" in exc_info.value.args[0]
+
+    monkeypatch.setattr(lib, 'setupterm', make_setupterm(42))
+
+    with pytest.raises(Exception) as exc_info:
+        _curses.setupterm()
+
+    assert "unknown error" in exc_info.value.args[0]