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

BUG: don't mutate list of fake libraries while iterating over it #18295

Merged
merged 5 commits into from
Feb 4, 2021

Conversation

mckib2
Copy link
Contributor

@mckib2 mckib2 commented Feb 2, 2021

@@ -570,12 +570,13 @@ def _process_unlinkable_fobjects(self, objects, libraries,
unlinkable_fobjects = list(unlinkable_fobjects)

# Expand possible fake static libraries to objects
to_remove = []
for lib in libraries:
Copy link
Member

Choose a reason for hiding this comment

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

If we know that libraries is a list, could also do libraries[:], but not sure that we do, so this is probably good. Should it even mutate the libraries that were passed in?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The list does need to change or else the linker will try to link nonexistent or empty .lib files and crash. libraries is converted to a list at the top of this function

Copy link
Member

Choose a reason for hiding this comment

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

libraries[:] will mean it iterates a copy of the list, which should be safe, basically undoing the PR you linked.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to libraries[:] in latest push

Copy link
Member

Choose a reason for hiding this comment

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

Would it be possible to create a short regression test for this (I am just fishing here, but every test helps).

Copy link
Contributor Author

@mckib2 mckib2 Feb 2, 2021

Choose a reason for hiding this comment

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

A simple build test (exactly like the one linked in description) could do the job. I'm not familiar with the numpy conventions of how to do this. What I have in mind is building an extension and then testing to see if the extension exists (i.e., was built successfully). Is there a simple example you can point me to?

EDIT: looking now at tests for random extending and cooking up something similar to that, don't have a lot more time to look at this tonight, will probably have something tomorrow evening

Copy link
Contributor Author

@mckib2 mckib2 Feb 3, 2021

Choose a reason for hiding this comment

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

Test added to protect against regression

@seberg seberg added this to the 1.20.1 release milestone Feb 2, 2021
@seberg seberg added the 09 - Backport-Candidate PRs tagged should be backported label Feb 2, 2021
* TST: add build test for build_ext fix

* TST: clearer test name

* STY: use triple quotes instead of lists of strings
@mckib2
Copy link
Contributor Author

mckib2 commented Feb 3, 2021

Build errors appear not from this PR, see #18312

@@ -570,7 +570,7 @@ def _process_unlinkable_fobjects(self, objects, libraries,
unlinkable_fobjects = list(unlinkable_fobjects)

# Expand possible fake static libraries to objects
for lib in libraries:
for lib in libraries[:]:
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment above this line that [:] is on purpose, to not modify the original list? Otherwise the next over-eager code cleanup may undo the fix again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added an explanation is latest push, feel free to resolve or suggest different wording

@charris
Copy link
Member

charris commented Feb 3, 2021

The test failures look legitimate.

@charris
Copy link
Member

charris commented Feb 3, 2021

If the test becomes to convoluted we might want to omit it.

@mckib2
Copy link
Contributor Author

mckib2 commented Feb 4, 2021

The test failures look legitimate.

Yes, was looking on mobile and didn't read correctly. I'll start looking at this right now. If it does indeed seem like a headache, will omit the tests. Fingers crossed for an easy fix.

@mckib2
Copy link
Contributor Author

mckib2 commented Feb 4, 2021

So I've reproduced the issue in a Docker container and there seems to be a spurious extra -c compile option given to the gfortran command (extra line breaks added for clarity):

------------------------------------------------------------ Captured stderr call ------------------------------------------------------------
error: Command "gfortran-5 -Wall -g -ffixed-form -fno-second-underscore -fPIC -O3 -funroll-loops 
-I/home/numpy/venv/lib/python3.8/site-packages/numpy/distutils/tests/../../../numpy/core/include
-Ibuild/src.linux-i686-3.8/numpy/distutils/include -c -c ./_dummy1.f   # <--- spurious "-c" argument here
-o build/temp.linux-i686-3.8/_dummy1.o" failed with exit status 127

Has anyone encountered this before? This almost looks like another bug to me

EDIT: this does not appear to be what's causing the error and might not be interesting at all

EDIT EDIT:

I've identified the issue: there is no Fortran 77 compiler available. This f2py test check prevents most of the tests from running in these Docker containers. The test in this PR needs a similar check.

@charris charris merged commit d376319 into numpy:master Feb 4, 2021
@charris
Copy link
Member

charris commented Feb 4, 2021

Thanks @mckib2

charris pushed a commit to charris/numpy that referenced this pull request Feb 4, 2021
…py#18295)

* BUG: don't mutate list of fake libraries while iterating over it

* BUG: iterate over copy of list

* TST: add build test for build_ext fix (#1)

* TST: add build test for build_ext fix

* TST: clearer test name

* STY: use triple quotes instead of lists of strings

* FIX: check for f77 compiler before test is run

* DOC: add comment explaining that a list copy is necessary
@charris charris added component: numpy.distutils and removed 09 - Backport-Candidate PRs tagged should be backported labels Feb 4, 2021
@charris charris removed this from the 1.20.1 release milestone Feb 4, 2021
@mckib2 mckib2 deleted the bug-fix-fake-libs branch February 4, 2021 19:26
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

4 participants