-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
bpo-31680: Add curses.ncurses_version. #4217
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
Merged
serhiy-storchaka
merged 6 commits into
python:master
from
serhiy-storchaka:ncurses_version
Oct 30, 2018
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
718334a
bpo-31680: Added curses.ncurses_version.
serhiy-storchaka d3db79d
Merge branch 'master' into ncurses_version
serhiy-storchaka 78f71d9
Use curses.ncurses_version for conditionally skipping a test.
serhiy-storchaka b2e4185
Address review comments.
serhiy-storchaka 04db7df
Merge branch 'master' into ncurses_version
serhiy-storchaka 0686f77
Add a What's New entry.
serhiy-storchaka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
Misc/NEWS.d/next/Library/2017-11-01-15-44-48.bpo-31680.yO6oSC.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Added :data:`curses.ncurses_version`. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may add it to Doc/whatsnew/3.7.rst as well. It's up to you. |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4289,6 +4289,59 @@ _curses_use_default_colors_impl(PyObject *module) | |
| } | ||
| #endif /* STRICT_SYSV_CURSES */ | ||
|
|
||
|
|
||
| #ifdef NCURSES_VERSION | ||
|
|
||
| PyDoc_STRVAR(ncurses_version__doc__, | ||
| "curses.ncurses_version\n\ | ||
| \n\ | ||
| Ncurses version information as a named tuple."); | ||
|
|
||
| static PyTypeObject NcursesVersionType; | ||
|
|
||
| static PyStructSequence_Field ncurses_version_fields[] = { | ||
| {"major", "Major release number"}, | ||
| {"minor", "Minor release number"}, | ||
| {"patch", "Patch release number"}, | ||
| {0} | ||
| }; | ||
|
|
||
| static PyStructSequence_Desc ncurses_version_desc = { | ||
| "curses.ncurses_version", /* name */ | ||
| ncurses_version__doc__, /* doc */ | ||
| ncurses_version_fields, /* fields */ | ||
| 3 | ||
| }; | ||
|
|
||
| static PyObject * | ||
| make_ncurses_version(void) | ||
| { | ||
| PyObject *ncurses_version; | ||
| int pos = 0; | ||
|
|
||
| ncurses_version = PyStructSequence_New(&NcursesVersionType); | ||
| if (ncurses_version == NULL) { | ||
| return NULL; | ||
| } | ||
|
|
||
| #define SetIntItem(flag) \ | ||
| PyStructSequence_SET_ITEM(ncurses_version, pos++, PyLong_FromLong(flag)); \ | ||
| if (PyErr_Occurred()) { \ | ||
| Py_CLEAR(ncurses_version); \ | ||
| return NULL; \ | ||
| } | ||
|
|
||
| SetIntItem(NCURSES_VERSION_MAJOR) | ||
| SetIntItem(NCURSES_VERSION_MINOR) | ||
| SetIntItem(NCURSES_VERSION_PATCH) | ||
| #undef SetIntItem | ||
|
|
||
| return ncurses_version; | ||
| } | ||
|
|
||
| #endif /* NCURSES_VERSION */ | ||
|
|
||
|
|
||
| /* List of functions defined in the module */ | ||
|
|
||
| static PyMethodDef PyCurses_methods[] = { | ||
|
|
@@ -4426,6 +4479,30 @@ PyInit__curses(void) | |
| PyDict_SetItemString(d, "__version__", v); | ||
| Py_DECREF(v); | ||
|
|
||
| #ifdef NCURSES_VERSION | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah ok, now it's more explicit :-) |
||
| /* ncurses_version */ | ||
| if (NcursesVersionType.tp_name == NULL) { | ||
| if (PyStructSequence_InitType2(&NcursesVersionType, | ||
| &ncurses_version_desc) < 0) | ||
| return NULL; | ||
| } | ||
| v = make_ncurses_version(); | ||
| if (v == NULL) { | ||
| return NULL; | ||
| } | ||
| PyDict_SetItemString(d, "ncurses_version", v); | ||
| Py_DECREF(v); | ||
|
|
||
| /* prevent user from creating new instances */ | ||
| NcursesVersionType.tp_init = NULL; | ||
| NcursesVersionType.tp_new = NULL; | ||
| if (PyDict_DelItemString(NcursesVersionType.tp_dict, "__new__") < 0 && | ||
| PyErr_ExceptionMatches(PyExc_KeyError)) | ||
| { | ||
| PyErr_Clear(); | ||
| } | ||
| #endif /* NCURSES_VERSION */ | ||
|
|
||
| SetDictInt("ERR", ERR); | ||
| SetDictInt("OK", OK); | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, thank you :-)