windows-curses icon indicating copy to clipboard operation
windows-curses copied to clipboard

setupterm exit silently on Python 3.12

Open irvinren opened this issue 2 years ago • 10 comments

after pip install windows-curses==2.3.2 setupterm failed, python process exit silently.

from _curses import setupterm setupterm(term="xterm",fd=1)

irvinren avatar Nov 20 '23 12:11 irvinren

I am running on windows 10 with the Cpython 3.12 downloaded from python.org

irvinren avatar Nov 20 '23 12:11 irvinren

can you speed up to deal with this issue? It impacts my software development.

irvinren avatar Nov 26 '23 12:11 irvinren

in the curses module of cpython 3.12,

the function initscr() will call setupterm which quit silently on my machine.

cat d:\Python312\Lib\curses\init.py

`def initscr(): import _curses, curses # we call setupterm() here because it raises an error # instead of calling exit() in error cases. setupterm(term=_os.environ.get("TERM", "unknown"), fd=_sys.stdout.fileno()) stdscr = _curses.initscr() for key, value in curses.dict.items(): if key[0:4] == 'ACS' or key in ('LINES', 'COLS'): setattr(curses, key, value)

return stdscr`

irvinren avatar Nov 26 '23 12:11 irvinren

same issue, work all right on my python3.11, exit silently on python3.12

jasonbu avatar Nov 29 '23 07:11 jasonbu

@gschizas would you have any insights?

kartben avatar Nov 29 '23 09:11 kartben

@stephanosio isn't it a bug? Is this project still active?

irvinren avatar Dec 01 '23 09:12 irvinren

@stephanosio isn't it a bug? Is this project still active?

@irvinren Hi. The original author of this project is no longer active and this project is more or less on life support. I currently lack the bandwidth to look into this issue at the moment -- any help from a third party would be greatly appreciated.

stephanosio avatar Dec 01 '23 10:12 stephanosio

@stephanosio isn't it a bug? Is this project still active?

@irvinren Hi. The original author of this project is no longer active and this project is more or less on life support. I currently lack the bandwidth to look into this issue at the moment -- any help from a third party would be greatly appreciated.

Is there anything I can do to help you? To be frank, I could support it to some degree if it doesn't cause too much effort.

irvinren avatar Dec 01 '23 14:12 irvinren

Hello all. I am the author of Leo. Leo's cursesGui2 plugin suffers the same problem.

There is an easy workaround. The cursesGui2 plugin contains only one call to curses.initscr(). I replaced it as follows:

if 1:  # Call our own version of curses.initscr().
    import _curses
    # This crashes on Python 3.12.
        # setupterm(term=_os.environ.get("TERM", "unknown"),
            # fd=_sys.__stdout__.fileno())
    stdscr = _curses.initscr()
    for key, value in _curses.__dict__.items():
        if key[0:4] == 'ACS_' or key in ('LINES', 'COLS'):
            setattr(curses, key, value)
    # return stdscr
else:
    stdscr = curses.initscr()

If your program calls curses.initscr from multiple places, wrap the code above in a function.

I tested this hack on Python 3.9, 3.11, 3.12.

HTH.

edreamleo avatar Dec 05 '23 10:12 edreamleo

The _curses module defines setupterm, so _curses.cp312-win_amd64.pyd seems the likely culprit.

Probably a bad build somehow.

edreamleo avatar Dec 05 '23 10:12 edreamleo

I don't know if this is for sure the culprit, but it's possible that the generated argument clinic code should be regenerated, since the error is a memory access violation in PyArg_UnpackKeywords. A test run of clinic.py produces a very different _cursesmodule.c.h than the one committed currently.

gotyaoi avatar Apr 27 '24 08:04 gotyaoi

Seems like I was right. With a small patch, I was able to build a new working 3.12 wheel after running clinic.py to regenerate the clinic headers.

diff --git a/py312/_cursesmodule.c b/py312/_cursesmodule.c
index 4437114..102bb41 100644
--- a/py312/_cursesmodule.c
+++ b/py312/_cursesmodule.c
@@ -1119,9 +1119,9 @@ _curses_window_border_impl(PyCursesWindowObject *self, PyObject *ls,
 _curses.window.box

     [
-    verch: object(c_default="_PyLong_GetZero()") = 0
+    verch: object(c_default="PyLong_FromLong(0)") = 0
         Left and right side.
-    horch: object(c_default="_PyLong_GetZero()") = 0
+    horch: object(c_default="PyLong_FromLong(0)") = 0
         Top and bottom side.
     ]
     /

The current clinic header for _cursesmodule.c was manually modified to include that change, so this just slips it into the source instead.

gotyaoi avatar Apr 27 '24 21:04 gotyaoi

@stephanosio I could put in a PR, if that's desired?

gotyaoi avatar May 04 '24 22:05 gotyaoi

@stephanosio I could put in a PR, if that's desired?

That would be greatly appreciated.

stephanosio avatar May 05 '24 02:05 stephanosio

Leaving this issue open until it is confirmed to be fixed by others.

stephanosio avatar May 05 '24 07:05 stephanosio

v2.3.3a1 has been released with the proposed fix from https://github.com/zephyrproject-rtos/windows-curses/pull/53. Please test it out and let me know if it fixes the issue.

stephanosio avatar May 05 '24 08:05 stephanosio

v2.3.3a1 worked for me running python 3.12.2

LewisNeal avatar May 07 '24 21:05 LewisNeal

v2.3.3, which fixes this issue, has been released.

stephanosio avatar May 09 '24 13:05 stephanosio