FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Make path extension a bit safer by QuLogic · Pull Request #30208 · matplotlib/matplotlib · GitHub

Repository navigation

Make path extension a bit safer - #30208

Merged
anntzer merged 4 commits into
matplotlib:mainfrom
QuLogic:more-cpp17
Sep 18, 2025
Merged

anntzer merged 4 commits into
matplotlib:mainfrom
QuLogic:more-cpp17

Conversation

QuLogic commented Jun 24, 2025

Copy link
Copy Markdown
Member

PR summary

By replacing double pointers by std::array and returned tuples. AFAICT, this doesn't have any effect on code size, but ensures that several places are checked at compile time. And for now, we already know these to be correct, but this would prevent any future problems if some sizes change.

PR checklist

QuLogic added the CI: Run cibuildwheel Run wheel building tests on a PR label Jun 24, 2025
Comment thread src/_path.h
Comment thread src/_path.h
Comment thread src/_path.h

for (size_t i = 1; i < size; ++i) {
unsigned subcode = path.vertex(&x[i], &y[i]);
unsigned subcode = path.vertex(&x.at(i), &y.at(i));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I don't think the compiler can safely elide the bounds check here, because it'll have trouble proving that size is small enough (I guess the "modern C++" way of ensuring that is to make NUM_VERTICES an int templated on code etc.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Well, x.at is the bounds-checked version, and x[i] isn't, but somehow the compiled code remains the same size either way. (Perhaps this is because the Fedora compiler has hardening enabled somewhere?)

Comment thread src/_path_wrapper.cpp Outdated
github-actions Bot removed the CI: Run cibuildwheel Run wheel building tests on a PR label Jun 24, 2025

QuLogic commented Sep 11, 2025

Copy link
Copy Markdown
Member Author

Instead of the tuple, I thought it better to use the XY type we already have here. Also tacked on changing to that for the extent limits struct as well.

QuLogic commented Sep 12, 2025

Copy link
Copy Markdown
Member Author

Instead of the tuple, I thought it better to use the XY type we already have here.

A secondary reason is it makes extension to 3D a bit simpler, as we can eventually template on XY and (to be PR'd) XYZ somewhat straightforwardly.

QuLogic mentioned this pull request Sep 12, 2025
1 of 5 tasks

scottshambaugh left a comment •
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Looks cleaner & safer to me, no changes stand out

... by replacing double pointers by fixed-size `std::array`, or a return
`tuple`. With gcc (and optimization enabled?), this has no effect on
code size, but gives compile-time (and better runtime) checks that there
are no out-of-bounds access.
It is `bool` for the Python wrapper, while internally `int`, but can be
`bool` consistently.

Also mark it as `inline` since it's used in a template and the compiler
warns about a possible ODR violation (which isn't a problem since it's
only used in one file.)
By using the existing `XY` type to replace x/y pairs, and taking
advantage of struct methods.
Use `XY` type to shorten internals, and `agg::rect_d::normalize` to
shorten initialization.

QuLogic commented Sep 16, 2025

Copy link
Copy Markdown
Member Author

I just noticed that 6d5dd9a was empty, so I'll rebase that out.

Comment thread src/_path.h

void update(double x, double y)
{
start.x = std::min(start.x, x);

anntzer Sep 17, 2025 •
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Is the new form equivalent to the old one if either start.x or x is nan? (Ditto for all other similar changes.)
(It's also possible that the answer is "we never have nans here and it doesn't matter", I haven't checked.)

QuLogic Sep 18, 2025 •
edited
Loading

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

get_path_collection_extents always starts with a reset so it should start with max/min infinity. And then update_path_extents calls .update after a PathNanRemover. So we should never have NaN in either.

anntzer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Approval modulo one question re: interactions with nans.

anntzer merged commit 74beb8d into matplotlib:main Sep 18, 2025
39 of 42 checks passed
QuLogic deleted the more-cpp17 branch September 18, 2025 07:11
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
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.

5 participants


Back | FazBrowse Home | New Git URL