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

distutils.ccompiler: Make has_function work with more C99 compilers #3723

Closed
wants to merge 1 commit into from

Conversation

fweimer-rh
Copy link
Contributor

@fweimer-rh fweimer-rh commented Dec 14, 2022

Summary of changes

C99 removed support for implicit function declarations. This means that just calling a function, without declaring the function first, can result in a compilation error. Today, has_function works with most compilers because they issue just a warning, create an object file, and attempt a link, which then detects available of the symbol at link time, as intended. With future compilers, compilation will already fail, and no link test is performed.

The has_function interface provides the caller with a way to supply a list of header files to include. However, even with today's compilers, this only works if the function does not expect any parameters. Otherwise, the function call in the C fragment created by has_function will not supply the correct argument list and fail compilation. Therefore, this change supplies and incorrect prototype without arguments. This is what autoconf does today in a very similar situation, so it is quite likely that compilers will support this construct in this context in the future.

The includes and include_dirs arguments are deprecated because of the parameter list mismatch issue.

Closes #3648.

Pull Request Checklist

  • Changes have tests
  • News fragment added in [changelog.d/].

C99 removed support for implicit function declarations.  This means
that just calling a function, without declaring the function first,
can result in a compilation error.  Today, has_function works with
most compilers because they issue just a warning, create an object
file, and attempt a link, which then detects available of the symbol
at link time, as intended.  With future compilers, compilation will
already fail, and no link test is performed.

The has_function interface provides the caller with a way to supply
a list of header files to include.  However, even with today's
compilers, this only works if the function does not expect any
parameters.  Otherwise, the function call in the C fragment created
by has_function will not supply the correct argument list and fail
compilation.  Therefore, this change supplies and incorrect prototype
without arguments.  This is what autoconf does today in a very
similar situation, so it is quite likely that compilers will support
this construct in this context in the future.

The includes and include_dirs arguments are deprecated because of
the parameter list mismatch issue.

Fixes pypa#3648.
@abravalheri
Copy link
Contributor

abravalheri commented Dec 15, 2022

Hi @fweimer-rh thank you very much for the contribution.

Since the _distutils folder comes directly from the pypa/distutils repository (unaltered) I think the best would be suggesting these changes directly to that other repository (otherwise we have problems for merging/risk of overwriting it in a future change).

Would you like to submit the PR to pypa/distutils so the distutils maintainers can have a look?

Alternatively you can try to implement the changes without touching the _distutils folder (I don't know if it is possible...)

@fweimer-rh
Copy link
Contributor Author

Fair enough, I submitted pypa/distutils#195 and will come back once I've managed to get that merged.

@jaraco jaraco force-pushed the main branch 3 times, most recently from a85759c to 93ce5a0 Compare December 16, 2022 18:21
@thesamesam
Copy link
Contributor

thesamesam commented Feb 11, 2023

pypa/distutils#195 is now merged and landed in setuptools via #3809 in release 67.2.0.

It seems a shame to not fix it in cpython itself for at least 3.10/3.11 but python/cpython#98529 makes it seem like that's not going to happen.

@jaraco
Copy link
Member

jaraco commented Feb 12, 2023

Sounds like this work is complete. Thanks thesamesam.

By the way, you do get the fix in Python 3.7+ by way of the distutils hack. As long as you have setuptools installed and haven't set SETUPTOOLS_USE_DISTUTILS=stdlib, import distutils will pull in the distutils from Setuptools. I would avoid depending too heavily on that behavior, however, as we'd like to remove it. If you have a use-case for distutils that isn't served by the core interfaces of Setuptools (i.e. requires import distutils), please report that as a bug to the distutils project.

@jaraco jaraco closed this Feb 12, 2023
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.

Unclear how CCompiler.has_function works for functions with parameters
4 participants