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

bpo-22674: signal: add strsignal() #6017

Merged
merged 1 commit into from
Mar 12, 2018
Merged

bpo-22674: signal: add strsignal() #6017

merged 1 commit into from
Mar 12, 2018

Conversation

seirl
Copy link
Contributor

@seirl seirl commented Mar 7, 2018

I updated @vajrasky 's patch in https://bugs.python.org/issue22674 to rebase it onto master, use the clinic argument parser and improve the docs.

https://bugs.python.org/issue22674

@seirl
Copy link
Contributor Author

seirl commented Mar 7, 2018

Updated with a NEWS entry.

@seirl seirl force-pushed the strsignal branch 4 times, most recently from 828fa2e to 66aa723 Compare March 8, 2018 20:30
@seirl
Copy link
Contributor Author

seirl commented Mar 8, 2018

Updated with a special case for Windows. The tests are all passing now, just waiting for a review.

/*[clinic end generated code: output=44e12e1e3b666261 input=5369187c5b204b2a]*/
{
int position;
const char *res, *pch;
Copy link
Member

Choose a reason for hiding this comment

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

According to POSIX, strsignal returns non-const char*, so let's keep it like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't understand this one. Why would we want to keep it not const? We're not planning on modifying it, adding constness to make sure of that doesn't hurt.

Copy link
Member

Choose a reason for hiding this comment

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

Py_BuildValue doesn't specify that it takes only const arguments, so you may get compiler warnings or even errors depending on compiler settings. The benefit of using const in such a simple function seem rather low, so it's better to drop it iMHO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, I just looked at the docs of Py_Buildvalue. I fixed it, thanks.

#else
res = strsignal(signalnum);

if (res == NULL || strstr(res, "Unknown signal") != NULL)
Copy link
Member

@pitrou pitrou Mar 11, 2018

Choose a reason for hiding this comment

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

According to POSIX, you may also want to check for errno after the call (and set it to zero before).

if (res == NULL || strstr(res, "Unknown signal") != NULL)
Py_RETURN_NONE;

/* On Mac, it returns 'Quit: 3', while on Linux it returns 'Quit'. */
Copy link
Member

Choose a reason for hiding this comment

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

Let's not add this kind of post-processing. If someone wants the same return values on all systems, they should simply not use strsignal at all (it's not very hard to come up with descriptions for a dozen or less well-known signals).

.. function:: strsignal(signalnum)

Return the system description of the signal *signalnum*, such as
'Interrupt', 'Segmentation fault', etc. Returns :const:`None` if the signal
Copy link
Member

Choose a reason for hiding this comment

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

Please use double quotes: this is English prose, not Python :-)

res = strsignal(signalnum);

if (res == NULL || strstr(res, "Unknown signal") != NULL)
Py_RETURN_NONE;
Copy link
Member

Choose a reason for hiding this comment

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

Note that we indent C code by 4-space indentations, not 2. See PEP 7 for more details.

Copy link
Member

@pitrou pitrou left a comment

Choose a reason for hiding this comment

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

Thanks for posting this PR! I've added some comments to the code, please make the necessary changes :-)

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

And if you don't make the requested changes, you will be put in the comfy chair!

@seirl
Copy link
Contributor Author

seirl commented Mar 11, 2018

I have made the requested changes; please review again.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@pitrou: please review the changes made to this pull request.

Co-authored-by: Vajrasky Kok <sky.kok@speaklikeaking.com>
@pitrou
Copy link
Member

pitrou commented Mar 12, 2018

Thank you @seirl ! This looks good to me now.

@pitrou pitrou merged commit 5d2a27d into python:master Mar 12, 2018
@bedevere-bot
Copy link

@pitrou: Please replace # with GH- in the commit message next time. Thanks!

jo2y pushed a commit to jo2y/cpython that referenced this pull request Mar 23, 2018
Co-authored-by: Vajrasky Kok <sky.kok@speaklikeaking.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants