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

Imaging.h: confusion with system #4923

Merged
merged 7 commits into from Oct 14, 2020
Merged

Conversation

ax3l
Copy link
Contributor

@ax3l ax3l commented Sep 16, 2020

The file libImaging/Imaging.h gets installed on Ubuntu flat into the public Python includes.

When building a newer version of Pillow from source and hinting the Python includes "too early" in includes, e.g. in package managers, this can confuse the two files and pick up the external file over the internal one. With different versions, this mismatch can lead to build errors, e.g. undefined macros.

The most robust way to avoid this is to prefix the internal include accordingly, so that the relative path to the including file has to match as well.

The file `libImaging/Imaging.h` gets installed flat on
Ubuntus into the public Python includes.

When building a newer version of Pillow from source and
hinting the Python includes "too early" in includes, e.g.
in package managers, this can confuse the two files and
pick up the external file over the internal one. With
different versions, this mismatch can lead to build errors,
e.g. undefined macros.

The most robust way to avoid this is to pre-fix the internal
include accordingly, so that the relative path to the including
file has to match as well.
@radarhere
Copy link
Member

I've created ax3l#1 as a suggestion to expand on this - prefixing more header includes.

@wiredfool
Copy link
Member

I think this is a bug in the debian packaging. Imaging.h is an internal file, not a supported set of external interfaces.

Following the debian rules for splitting and naming packages, if the header is actually required (e.g, for other debian packages), it should be in a package named python-pillow-dev, not in the primary python-pillow package. (e.g, libfoo and libfoo-dev for compilation).

@radarhere
Copy link
Member

If it's not a problem though, is it worth doing just because it makes it clearer to the reader where the header file is located?

@ax3l
Copy link
Contributor Author

ax3l commented Sep 29, 2020

That's also what I was thinking. Even if it were in a -dev package, we would have the same problem of missing isolation when building from source (if it's installed).

An alternative solution that we considered would be to change the order in which include_dirs are applied in setup.py. I feared that this would have significantly more potential for side-effects for existing workflows.

Another question is if those headers should be installed in the install prefix without further directory namespace around it or at all. Is this a vendored third-party library?

Considering all of the above and aiming for a small change set as an outside contributor, the proposed diff was the least invasive and most stable approach I could come up with.

@ax3l
Copy link
Contributor Author

ax3l commented Oct 13, 2020

Thank you for the update, LGTM.

@nulano
Copy link
Contributor

nulano commented Oct 13, 2020

I tried to remove the libImaging directory from the includes added in setup.py so future includes can't omit the prefix by accident, but this causes a failure building _imagingft.c on systems without libraqm. Fixing this requires changing

#include <raqm.h>

to

#include "libImaging/raqm.h"

so I'm not sure it is worth it. Thoughts?

ax3l/Pillow@fix-imagingHinclude...nulano:fix-imagingHinclude

@ax3l
Copy link
Contributor Author

ax3l commented Oct 14, 2020

Oh, but that means instead of the internally shipped raqm.h it was always picking up a system header. That is another source of potential issues then.
Yes, would add this. Great catch!

@hugovk
Copy link
Member

hugovk commented Oct 14, 2020

Merged in master to include #4978 to fix the unrelated CI failure.

@hugovk hugovk merged commit 2c0aa5d into python-pillow:master Oct 14, 2020
@ax3l ax3l deleted the fix-imagingHinclude branch October 15, 2020 07:59
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.

None yet

5 participants