Skip to content

Conversation

@Ricardicus
Copy link
Contributor

Adding some includes that the file 'include/pybind11/pybind11.h' is depending on, but not including itself.

Add #include for unique_ptr<> (include/pybind11/pybind11.h:1132)
Add #include for vector<> (include/pybind11/pybind11.h:1735)
Add #include for string (include/pybind11/pybind11.h:2139)
Add #include for move (include/pybind11/pybind11.h:2197)

@henryiii henryiii closed this Sep 17, 2020
@henryiii henryiii reopened this Sep 17, 2020
Comment on lines 44 to 48
#include <memory>
#include <vector>
#include <string>
#include <utility>

Copy link
Collaborator

Choose a reason for hiding this comment

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

Before or after the other pybind11 headers? I tend to include stdlib as last includes, but I'm not sure if there's a policy or habit, here. Apart from that, fine with me! :-)

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 can change the order, if you like? :)

Copy link
Contributor Author

@Ricardicus Ricardicus Sep 18, 2020

Choose a reason for hiding this comment

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

Here: https://google.github.io/styleguide/cppguide.html#Names_and_Order_of_Includes
I read:

Include headers in the following order: Related header, C system headers, C++ standard library headers, other libraries' headers, your project's headers.

But that is Googles C++ guidelines, not necessarily yours. With reservations, I might have misinterpreted something.. :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think LLVM and therefore the clang-* tools have the same ordering recommendation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

PS: There is one hard requirement for all Python modules, though: Python.h must precede all stdlib headers.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also fine to keep it this way, then. Just wanted to open this for discussion, and check whether this is what we want :-)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, I think this has to be moved. This puts stdlib includes above <Python.h>, which causes massive numbers of warnings on Python 2.7 on older Linux systems (at least). The rule is Python.h must be above any stdlib includes for any extension module, and that rule is kept by by pybind11.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok! I will do another commit soon, within the hour, moving them under the project headers!

@henryiii
Copy link
Collaborator

Why does this break appveyor? AFAICT, it's working on other branches, but not this, twice now?

@Ricardicus
Copy link
Contributor Author

Ricardicus commented Sep 18, 2020

Interesting. I thought standard C++ library headers were safe to include anywhere. I have no experience of your pipeline, curious to know why it breaks.

Edit: now I know, will commit a reordering as soon as I get home to my machine.

@henryiii
Copy link
Collaborator

I thought standard C++ library headers were safe to include anywhere.

It's a requirement listed in the CPython docs:

https://docs.python.org/3.8/c-api/intro.html#include-files

The easiest way I know of to trigger it doing something bad is to use CentOS 7 and the built-in Python 2. You get massive numbers of mismatched redefine warnings if you don't put Python.h first.

@Ricardicus
Copy link
Contributor Author

Ricardicus commented Sep 18, 2020

Let's see if it fails, still.

@Ricardicus
Copy link
Contributor Author

Looks like it went well 👍

@YannickJadoul
Copy link
Collaborator

Thanks, @Ricardicus! :-)

@YannickJadoul YannickJadoul merged commit 5a8ec8e into pybind:master Sep 19, 2020
@Ricardicus
Copy link
Contributor Author

Thank you!

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.

3 participants