Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

curses addch broken on Python3.3a1 #58431

Closed
NicholasCole mannequin opened this issue Mar 7, 2012 · 19 comments
Closed

curses addch broken on Python3.3a1 #58431

NicholasCole mannequin opened this issue Mar 7, 2012 · 19 comments
Labels
release-blocker stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@NicholasCole
Copy link
Mannequin

NicholasCole mannequin commented Mar 7, 2012

BPO 14223
Nosy @birkenfeld, @jcea, @cben, @pitrou, @vstinner, @ned-deily, @bitdancer

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2012-09-08.05:53:42.950>
created_at = <Date 2012-03-07.20:44:53.571>
labels = ['type-bug', 'library', 'release-blocker']
title = 'curses addch broken on Python3.3a1'
updated_at = <Date 2012-09-09.20:12:34.075>
user = 'https://bugs.python.org/NicholasCole'

bugs.python.org fields:

activity = <Date 2012-09-09.20:12:34.075>
actor = 'vstinner'
assignee = 'none'
closed = True
closed_date = <Date 2012-09-08.05:53:42.950>
closer = 'georg.brandl'
components = ['Library (Lib)']
creation = <Date 2012-03-07.20:44:53.571>
creator = 'Nicholas.Cole'
dependencies = []
files = []
hgrepos = []
issue_num = 14223
keywords = []
message_count = 19.0
messages = ['155118', '155125', '155142', '155143', '169579', '169580', '169628', '169630', '169631', '169752', '169756', '169759', '169764', '169765', '169781', '170032', '170083', '170118', '170132']
nosy_count = 12.0
nosy_names = ['georg.brandl', 'jcea', 'cben', 'pitrou', 'vstinner', 'gpolo', 'ned.deily', 'r.david.murray', 'inigoserna', 'phep', 'python-dev', 'Nicholas.Cole']
pr_nums = []
priority = 'release blocker'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue14223'
versions = ['Python 3.3']

@NicholasCole
Copy link
Mannequin Author

NicholasCole mannequin commented Mar 7, 2012

The following code works on Python versions prior to 3.3a1:

import curses

def test_screen(screen):
    screen.addch(5,5, curses.ACS_HLINE)
    screen.refresh()

curses.wrapper(test_screen)

On python3.3, the program produces the following traceback:

Traceback (most recent call last):
  File "/tmp/p.py", line 7, in <module>
    curses.wrapper(test_screen)
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/curses/__init__.py", line 94, in wrapper
    return func(stdscr, *args, **kwds)
  File "/tmp/p.py", line 4, in test_screen
    screen.addch(5,5, curses.ACS_HLINE)
OverflowError: byte doesn't fit in chtype

@NicholasCole NicholasCole mannequin added the stdlib Python modules in the Lib dir label Mar 7, 2012
@bitdancer
Copy link
Member

Marking as release blocker since this is a regression. Added people from the other curses issue as being likely to be interested in this one.

@bitdancer bitdancer added release-blocker type-bug An unexpected behavior, bug, or error labels Mar 7, 2012
@python-dev
Copy link
Mannequin

python-dev mannequin commented Mar 8, 2012

New changeset 861a5f3e7453 by Victor Stinner in branch 'default':
Close bpo-14223: curses.addch() is no more limited to the range 0-255 when the
http://hg.python.org/cpython/rev/861a5f3e7453

@python-dev python-dev mannequin closed this as completed Mar 8, 2012
@vstinner
Copy link
Member

vstinner commented Mar 8, 2012

I introduced the arbitrary limit when I added support of the curses Unicode API (libncursesw). The limit is useless if libncursesw is used, whereas it blocks legal "characters" like KEY_xxx constants. So I just removed the check and it should not be ok.

The real issue is that Python curses is not linked to libncursesw on Mac OS X!

@NicholasCole
Copy link
Mannequin Author

NicholasCole mannequin commented Aug 31, 2012

I'm reopening this bug because I've noticed that in Python3.3rc1, although trying to print curses.ACS_HLINE and other such characters no long cause an Exception, only blank characters are printed to the screen.

Tested with both Terminal.App and xterm running under XQuartz.

Here is some minimal test code, that will print a line on Python2.x but a blank screen on Python3.3rc1.

@NicholasCole NicholasCole mannequin reopened this Aug 31, 2012
@NicholasCole
Copy link
Mannequin Author

NicholasCole mannequin commented Aug 31, 2012

import curses

def test_screen(screen):
    screen.addch(5,5, curses.ACS_HLINE)
    screen.addch(5,6, curses.ACS_HLINE)
    screen.refresh()
    curses.napms(2000)

curses.wrapper(test_screen)

@python-dev
Copy link
Mannequin

python-dev mannequin commented Sep 1, 2012

New changeset 27b5bd5f0e4c by Victor Stinner in branch 'default':
Close bpo-14223: Fix window.addch(curses.ACS_HLINE)
http://hg.python.org/cpython/rev/27b5bd5f0e4c

@python-dev python-dev mannequin closed this as completed Sep 1, 2012
@vstinner
Copy link
Member

vstinner commented Sep 1, 2012

I'm reopening this bug because I've noticed that in Python3.3rc1,
although trying to print curses.ACS_HLINE and other such characters
no long cause an Exception, only blank characters are printed to
the screen.

If the Python curses module is compiled in Unicode mode (if curses.unget_wch() is present), addch(int) calls the C function wadd_wch() or mvwadd_wch(), instead of waddch() or mvwaddch(). It looks like the *_wch() family does not support characters like curses.ACS_HLINE.

My commit fixes the issue.

@Nicholas.Cole: Can you please try the last development version (default branch)?

@georg.brandl: Can you please include the important fix 27b5bd5f0e4c in Python 3.3 final?

@vstinner
Copy link
Member

vstinner commented Sep 1, 2012

(keep the issue open until the fix is included in Georg's repository)

@vstinner vstinner reopened this Sep 1, 2012
@NicholasCole
Copy link
Mannequin Author

NicholasCole mannequin commented Sep 3, 2012

Unless I'm getting the build process wrong (possible, because I haven't tried testing fixes before), this fix isn't working for me.

@vstinner
Copy link
Member

vstinner commented Sep 3, 2012

Unless I'm getting the build process wrong (possible, because
I haven't tried testing fixes before), this fix isn't working for me.

Oh did you compile Python? Did you install it?

Do you have libncursesw? => do you have the function curses.unget_wch?

What is the version of your libcurses[w] library? There are issues on libncurses 5.7. I think Ned Bat changed the script to compile Python on Mac to use a builtin copy of libncurses 5.9. See:
http://bugs.python.org/issue14225#msg163323

@NicholasCole
Copy link
Mannequin Author

NicholasCole mannequin commented Sep 3, 2012

Unless I'm getting the build process wrong (possible, because
I haven't tried testing fixes before), this fix isn't working for me.

Oh did you compile Python? Did you install it?

Yes, I tried compiling it.

#./configure MACOSX_DEPLOYMENT_TARGET=10.8 --enable-framework --with-universal-archs="64-bit" CFLAGS="-arch x86_64" LDFLAGS="-arch x86_64" && make -j6 && make install

Do you have libncursesw? => do you have the function curses.unget_wch?

yes...

Python 3.3.0rc1+ (default, Sep  3 2012, 09:45:35) 
[GCC 4.2.1 Compatible Apple Clang 4.0 ((tags/Apple/clang-421.0.57))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import curses
>>> curses.unget_wch()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
_curses.error: must call initscr() first
>>> curses.version
b'2.2'
>>> 

What is the version of your libcurses[w] library? There are issues on libncurses 5.7. I think Ned Bat changed the script to compile Python on Mac to use a builtin copy of libncurses 5.9. See:
http://bugs.python.org/issue14225#msg163323

How do I check which version it was built against? The messages from ./configure just say that the tests pass, not which version it has found.

@vstinner
Copy link
Member

vstinner commented Sep 3, 2012

How do I check which version it was built against?

On Linux, I use:

$ ldd /usr/lib/python2.7/lib-dynload/_curses.so |grep curses
        libncursesw.so.5 => /lib/i386-linux-gnu/libncursesw.so.5 (0xb76d0000)
$ ls -l /lib/i386-linux-gnu/libncursesw.so.5
lrwxrwxrwx 1 root root 18 nov.  18  2011
/lib/i386-linux-gnu/libncursesw.so.5 -> libncursesw.so.5.9

=> version 5.9

@NicholasCole
Copy link
Mannequin Author

NicholasCole mannequin commented Sep 3, 2012

On Mon, Sep 3, 2012 at 3:15 PM, STINNER Victor <report@bugs.python.org> wrote:

STINNER Victor added the comment:

> How do I check which version it was built against?

On Linux, I use:

$ ldd /usr/lib/python2.7/lib-dynload/_curses.so |grep curses
libncursesw.so.5 => /lib/i386-linux-gnu/libncursesw.so.5 (0xb76d0000)
$ ls -l /lib/i386-linux-gnu/libncursesw.so.5
lrwxrwxrwx 1 root root 18 nov. 18 2011
/lib/i386-linux-gnu/libncursesw.so.5 -> libncursesw.so.5.9

=> version 5.9

I get Version 5.4, which seems very out of date (I'm running the
latest release of OS X) but:

nicholas$ ls -l /usr/lib/libncurses.
libncurses.5.4.dylib libncurses.5.dylib libncurses.dylib
NPSC:mnpyscreen nicholas$ ls -l /usr/lib/libncurses.dylib
lrwxr-xr-x 1 root wheel 20 25 Jul 18:32 /usr/lib/libncurses.dylib
-> libncurses.5.4.dylib

nicholas$ ldd /usr/lib/python2.7/lib-dynload/_curses.so |grep curses
/usr/lib/python2.7/lib-dynload/_curses.so:
/usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current
version 5.4.0)

Can that possibly be right??

@ned-deily
Copy link
Member

Can that possibly be right??

Yes. That's the version of ncurses that Apple ships with current versions of OS X. You can build it yourself and install into /usr/local and rebuild python. For ncurses 5.9, something like:

./configure --enable-widec --enable-shared --with-shared --without-normal
&& make && sudo make install

should work. FWIW, when I run your test script with tip, I now do see the two horizontal bars.

@birkenfeld
Copy link
Member

Done in d6d632f254ee.

@python-dev
Copy link
Mannequin

python-dev mannequin commented Sep 9, 2012

New changeset d6d632f254ee by Victor Stinner in branch 'default':
Close bpo-14223: Fix window.addch(curses.ACS_HLINE)
http://hg.python.org/cpython/rev/d6d632f254ee

@NicholasCole
Copy link
Mannequin Author

NicholasCole mannequin commented Sep 9, 2012

I've just tried the OS X build of 3.3rc2, and this has been fixed. Thank you!

@vstinner
Copy link
Member

vstinner commented Sep 9, 2012

I've just tried the OS X build of 3.3rc2, and this has been fixed. Thank you!

Great!

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-blocker stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants