Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Don't confuse uintptr_t and Py_ssize_t.#12569

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
tacaswell merged 1 commit intomatplotlib:masterfromanntzer:uintptr_t
Oct 22, 2018

Conversation

anntzer
Copy link
Contributor

PR Summary

Should hopefullyclose#12567.

PR Checklist

  • Has Pytest style unit tests
  • Code isFlake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@anntzeranntzer added this to thev3.0.x milestoneOct 19, 2018
@jklymakjklymak added the Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. labelOct 19, 2018
int convert_voidptr(PyObject *obj, void *p)
{
*(void **)p = PyLong_AsVoidPtr(obj);
return !PyErr_Occurred();
Copy link
Contributor

Choose a reason for hiding this comment

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

You can get a maybe get a speed improvement here by checking this only if*(void **)p == NULL

Copy link
ContributorAuthor

@anntzeranntzerOct 21, 2018
edited
Loading

Choose a reason for hiding this comment

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

I strongly doubt this would have any measurable effect on speed, so I'd rather just avoid a conditional path to keep things simple.

Copy link
Contributor

@eric-wiesereric-wieserOct 21, 2018
edited
Loading

Choose a reason for hiding this comment

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

PyErr_Occured callsPyThreadState_GET, which involves atomic operations. This is just like using the common pattern ofret == -1 && PyErr_Occurred() when converting integers. It may be unnecessary, but it does seem to be typical within CPython.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Changed it...

Copy link
Member

Choose a reason for hiding this comment

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

It's not actually clear to me from the docs that the result would necessarily beNULL when an error occurs.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

https://docs.python.org/3/c-api/long.html#c.PyLong_AsVoidPtr
Returns NULL on error. Use PyErr_Occurred() to disambiguate.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I was looking at 3.5 docs which didn't seem to have that line.

{
void **val = (void **)p;
*val = PyLong_AsVoidPtr(obj);
return *val != NULL ? 1 : !PyErr_Occurred();
Copy link
Contributor

@eric-wiesereric-wieserOct 21, 2018
edited
Loading

Choose a reason for hiding this comment

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

nit: more readable asval == NULL && PyErr_Occurred() ? 0 : 1 or!(val == NULL && PyErr_Occurred())

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

That's exactly why I wanted to leave it at the old version: I don't think this discussion really helps (and I think my version is more readable: if it's non-null, PyLong_AsVoidPtr succeeded and we don't need to check for an error, otherwise do check).
I could even write the whole thing asreturn ((void **)p = PyLong_AsVoidPtr(obj)) ? 1 : !PyErr_Occurred(); but that's just silly.

@tacaswelltacaswell merged commite02f2c5 intomatplotlib:masterOct 22, 2018
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull requestOct 22, 2018
@anntzeranntzer deleted the uintptr_t branchOctober 22, 2018 21:23
dstansby added a commit that referenced this pull requestOct 25, 2018
…569-on-v3.0.xBackport PR#12569 on branch v3.0.x (Don't confuse uintptr_t and Py_ssize_t.)
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@QuLogicQuLogicQuLogic approved these changes

@eric-wiesereric-wiesereric-wieser left review comments

@jklymakjklymakjklymak approved these changes

Assignees
No one assigned
Labels
Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Milestone
v3.0.1
Development

Successfully merging this pull request may close these issues.

Calling pyplot.show() with TkAgg backend on x86 machine raises OverflowError.
5 participants
@anntzer@QuLogic@eric-wieser@jklymak@tacaswell

[8]ページ先頭

©2009-2025 Movatter.jp