Skip to content

gh-125843: indicate which C function caused a curses.error #125844

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

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

picnixz
Copy link
Member

@picnixz picnixz commented Oct 22, 2024

@picnixz picnixz marked this pull request as draft April 25, 2025 11:02
@picnixz picnixz changed the title gh-125843: store the name of the curses C function or macro in curses.error gh-125843: include which C function caused a curses.error Apr 25, 2025
@picnixz picnixz changed the title gh-125843: include which C function caused a curses.error gh-125843: indicate which C function caused a curses.error Apr 25, 2025
@picnixz picnixz marked this pull request as ready for review April 25, 2025 19:35
Copy link
Member Author

@picnixz picnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, there are some funcname that should be corrected but I need to see how they should really be corrected.

@picnixz picnixz marked this pull request as draft April 25, 2025 19:50
@picnixz picnixz marked this pull request as ready for review April 26, 2025 07:44
@picnixz picnixz requested review from encukou and Yhg1s April 26, 2025 07:45
Copy link
Member

@encukou encukou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This should add some clarity.

Comment on lines +216 to +220
#define CURSES_ERROR_FORMAT "%s() returned ERR"
#define CURSES_ERROR_VERBOSE_FORMAT "%s() (called by %s()) returned ERR"
#define CURSES_ERROR_NULL_FORMAT "%s() returned NULL"
#define CURSES_ERROR_NULL_VERBOSE_FORMAT "%s() (called by %s()) returned NULL"
#define CURSES_ERROR_MUST_CALL_FORMAT "must call %s() first"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the names are too useful, given that most are used in the consolidated function, so they're meant be used only once.

Comment on lines +227 to +228
* A NULL 'python_funcname' falls back to 'curses_funcname' and vice-versa.
* If both names are NULL, the error message is 'catchall_ERR'.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it valid for python_funcname to be NUL but curses_funcname to be set?

I see only these cases:

  • the function names are the same, or PyCursesCheckERR was called by the user (only python_funcname is non-NULL)
  • they names are different (both are non-NULL)
  • PyCursesCheckERR called by user with NULL (so both are NULL)

Is it worth an assert?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmh. Semantically, yes. In practice no. Sorry, it was a relic of the previous implementatiom. So either python and curses names are the different, or only python function name is given (and matches that of curses).

I won't be able to put anything before the beta release but I don't mind delaying this one for 3.15. However if you find time, I'd be happy if you make the change!

Comment on lines +251 to +252
static void
PyCursesSetError_ForWin_From(PyCursesWindowObject *win,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, don't use Py, the prefix for public API, for new static functions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I should just have a curses_set_error_* prefix? I don't remember whether I unfortunately introduced this naming in this or in a previous PR :(

@@ -3408,7 +3564,7 @@ _curses_initscr_impl(PyObject *module)
WINDOW *win;

if (curses_initscr_called) {
wrefresh(stdscr);
(void)wrefresh(stdscr); // TODO(picnixz): should we report an error?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please open issues for TODOs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I'll do so when I'm back (in 10 days)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants