Skip to content

fix: add null pointer check with std::localtime #2846

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
merged 1 commit into from
Feb 8, 2021

Conversation

knzivid
Copy link
Contributor

@knzivid knzivid commented Feb 4, 2021

Description

Related conversation https://gitter.im/pybind/Lobby?at=601be2a61ed88c58d81d719a

Suggested changelog entry:

* Add null pointer check with ``std::localtime``.

// (https://en.cppreference.com/w/cpp/chrono/c/localtime)
std::tm *localtime_ptr = std::localtime(&tt);
if (!localtime_ptr)
pybind11_fail("pybind11::chrono: Unable to represent system_clock in local time");
Copy link
Collaborator

Choose a reason for hiding this comment

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

pybind11_fail is meant for internal errors, so this is not correct. Maybe throw py::cast_error? Maybe have a look at what other casters do, please.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about now?

Copy link
Collaborator

Choose a reason for hiding this comment

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

If the CI wants to turn green, this seems better, indeed. Thanks! :-)

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 am not sure what broke in test_recarray in test_numpy_dtypes.py on CentOS 7. I will try debugging it, now that it has failed twice.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Very weird that it would be related, though

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's not, it's started breaking everywhere.

@knzivid knzivid force-pushed the localtime-nullptr-check branch from bb1628b to 438c6dd Compare February 4, 2021 18:05
@YannickJadoul YannickJadoul added this to the v2.7 milestone Feb 4, 2021
@henryiii
Copy link
Collaborator

henryiii commented Feb 8, 2021

Please don't remove the changelog part of the template, we use that to generate the changelog. Otherwise, fine!

@henryiii henryiii merged commit e791ec4 into pybind:master Feb 8, 2021
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Feb 8, 2021
@henryiii henryiii added the bug label Feb 8, 2021
@henryiii henryiii removed the needs changelog Possibly needs a changelog entry label Jul 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants