aboutsummaryrefslogtreecommitdiff
path: root/pypy
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2021-03-30 09:09:54 +0300
committerMatti Picus <matti.picus@gmail.com>2021-03-30 09:09:54 +0300
commit805a4d8918f21c4c9efbdc7e492ada19b69fafe4 (patch)
tree09e1d4c0f9eb1dc398ca4761a55e574dd287cfe3 /pypy
parentfix test (diff)
downloadpypy-805a4d8918f21c4c9efbdc7e492ada19b69fafe4.tar.gz
pypy-805a4d8918f21c4c9efbdc7e492ada19b69fafe4.tar.bz2
pypy-805a4d8918f21c4c9efbdc7e492ada19b69fafe4.zip
move processing setupterm error message to rpython for a nicer message
Diffstat (limited to 'pypy')
-rw-r--r--pypy/module/_minimal_curses/fficurses.py27
-rw-r--r--pypy/module/_minimal_curses/interp_curses.py21
2 files changed, 21 insertions, 27 deletions
diff --git a/pypy/module/_minimal_curses/fficurses.py b/pypy/module/_minimal_curses/fficurses.py
index 2d4b863dca..d8245748a7 100644
--- a/pypy/module/_minimal_curses/fficurses.py
+++ b/pypy/module/_minimal_curses/fficurses.py
@@ -1,7 +1,7 @@
""" The ffi for rpython
"""
-from rpython.rtyper.lltypesystem import rffi
+from rpython.rtyper.lltypesystem import rffi, lltype
from rpython.rtyper.tool import rffi_platform
from rpython.translator.tool.cbuild import ExternalCompilationInfo
@@ -75,7 +75,7 @@ eci = eci.copy_without('includes')
eci = eci.merge(ExternalCompilationInfo(
post_include_bits=[
- "RPY_EXTERN char *rpy_curses_setupterm(char *, int);\n"
+ "RPY_EXTERN int rpy_curses_setupterm(char *, int, int *);\n"
"RPY_EXTERN char *rpy_curses_tigetstr(char *);\n"
"RPY_EXTERN char *rpy_curses_tparm(char *, int, int, int, int,"
" int, int, int, int, int);"
@@ -85,23 +85,6 @@ eci = eci.merge(ExternalCompilationInfo(
%(include_lines)s
RPY_EXTERN
-char *rpy_curses_setupterm(char *term, int fd)
-{
- int errret = -42;
- if (setupterm(term, fd, &errret) == ERR) {
- switch (errret) {
- case 0:
- return "setupterm: could not find terminal";
- case -1:
- return "setupterm: could not find terminfo database";
- default:
- return "setupterm: unknown error";
- }
- }
- return NULL;
-}
-
-RPY_EXTERN
char *rpy_curses_tigetstr(char *capname)
{
char *res = tigetstr(capname);
@@ -120,9 +103,9 @@ char *rpy_curses_tparm(char *str, int x0, int x1, int x2, int x3,
""" % globals()]))
-rpy_curses_setupterm = rffi.llexternal(
- "rpy_curses_setupterm", [rffi.CCHARP, rffi.INT], rffi.CCHARP,
- compilation_info=eci)
+setupterm = rffi.llexternal(
+ "setupterm", [rffi.CCHARP, rffi.INT, rffi.INTP],
+ rffi.INT, compilation_info=eci)
rpy_curses_tigetstr = rffi.llexternal(
"rpy_curses_tigetstr", [rffi.CCHARP], rffi.CCHARP,
diff --git a/pypy/module/_minimal_curses/interp_curses.py b/pypy/module/_minimal_curses/interp_curses.py
index 03db5adb98..3c5a6d44a7 100644
--- a/pypy/module/_minimal_curses/interp_curses.py
+++ b/pypy/module/_minimal_curses/interp_curses.py
@@ -2,6 +2,7 @@ from pypy.interpreter.gateway import unwrap_spec
from pypy.interpreter.error import OperationError
from pypy.module._minimal_curses import fficurses
from rpython.rtyper.lltypesystem import lltype, rffi
+from rpython.rlib.rarithmetic import r_uint, intmask, widen
class ModuleInfo:
@@ -30,16 +31,26 @@ def setupterm(space, w_termname=None, fd=-1):
space.newtext('fileno'))))
if space.is_none(w_termname):
termname = None
+ termname_err = 'None'
else:
termname = space.text_w(w_termname)
+ termname_err = "'%s'" % termname
+ p_errret = lltype.malloc(rffi.INTP.TO, 1, flavor='raw')
with rffi.scoped_str2charp(termname) as ll_term:
_fd = rffi.cast(rffi.INT, _fd)
- ll_errmsg = fficurses.rpy_curses_setupterm(ll_term, _fd)
- if ll_errmsg:
- msg = rffi.charp2str(ll_errmsg)
- if "could not find terminal" in msg:
- msg = "setupterm('%s', %d) failed (err=0): could not find terminal" %(termname, fd)
+ errval = fficurses.setupterm(ll_term, _fd, p_errret)
+
+ if errval == -1:
+ errret = widen(p_errret[0])
+ if errret == 0:
+ msg_ext = 'could not find terminal'
+ elif errret == -1:
+ msg_ext = 'could not find termininfo database'
+ else:
+ msg_ext = 'unknown error'
+ msg = ("setupterm(%s, %d) failed (err=%d): %s" %
+ (termname_err, fd, errret, msg_ext))
raise curses_error(space, msg)
space.fromcache(ModuleInfo).setupterm_called = True