classification
Title: ctypes.util.find_library not working on macOS
Type: behavior Stage: resolved
Components: ctypes Versions: Python 3.8, Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Ian Burgwin, Michael.Felt, Ray.Donnelly, amaury.forgeotdarc, belopolsky, meador.inge, ned.deily, vstinner
Priority: Keywords: patch

Created on 2018-04-15 05:24 by Ian Burgwin, last changed 2018-05-02 02:56 by ned.deily. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 6625 merged python-dev, 2018-04-28 12:39
PR 6680 merged miss-islington, 2018-05-02 02:31
PR 6681 merged ned.deily, 2018-05-02 02:37
PR 6682 merged miss-islington, 2018-05-02 02:41
Messages (8)
msg315309 - (view) Author: Ian Burgwin (Ian Burgwin) Date: 2018-04-15 05:24
On Python 3.7.0a4 and later (including 3.7.0b4), find_library currently always returns None on macOS. It works on 3.7.0a3 and earlier. Tested on macOS 10.11 and 10.13.

Expected result: Tested on 3.6.5, 3.7.0a1 and 3.7.0a3:

>>> from ctypes.util import find_library
>>> find_library('iconv')
'/usr/lib/libiconv.dylib'
>>> find_library('c')
'/usr/lib/libc.dylib'
>>>

Current output on 3.7.0a4 to 3.7.0b3:

>>> from ctypes.util import find_library
>>> find_library('iconv')
>>> find_library('c')
>>>
msg315310 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-04-15 05:56
Thanks for the report and the good detective work!  I see the same results.  It appears that the error was introduced by c5ae169e1b73315672770517bf51cf8464286c76 for Issue26439.  It looks we need both a fix and a test for this.  This really needs to be fixed for 3.7.0b4.
msg315742 - (view) Author: Michael Felt (Michael.Felt) * Date: 2018-04-25 14:54
On 15/04/2018 07:56, Ned Deily wrote:
> Ned Deily <nad@python.org> added the comment:
>
> Thanks for the report and the good detective work!  I see the same results.  It appears that the error was introduced by c5ae169e1b73315672770517bf51cf8464286c76 for Issue26439.  It looks we need both a fix and a test for this.  This really needs to be fixed for 3.7.0b4.

Perhaps he can give a bit more info. I do not understand how this could 
break things, as the darwin code is earlier in the queue.

if os.name == "posix" and sys.platform == "darwin":
     from ctypes.macholib.dyld import dyld_find as _dyld_find
     def find_library(name):
         possible = ['lib%s.dylib' % name,
                     '%s.dylib' % name,
                     '%s.framework/%s' % (name, name)]
         for name in possible:
             try:
                 return _dyld_find(name)
             except ValueError:
                 continue
         return None

if sys.platform.startswith("aix"):
     # AIX has two styles of storing shared libraries
     # GNU auto_tools refer to these as svr4 and aix
     # svr4 (System V Release 4) is a regular file, often with .so as suffix
     # AIX style uses an archive (suffix .a) with members (e.g., shr.o, 
libssl.so)
     # see issue#26439 and _aix.py for more details

     from ctypes._aix import find_library

elif os.name == "posix":
     # Andreas Degert's find functions, using gcc, /sbin/ldconfig, objdump
     import re, tempfile

     def _findLib_gcc(name):

As I understand the code above (and maybe I am wrong) - the code should 
be calling the unchanged routines in the macholib subdirectory. A simple 
test on macOS would be to comment out the two lines

if sys.platform.startswith("aix"):
     from ctypes._aix import find_library

That will "delete" the AIX find_library logic.

In other words - can someone check whether the unchanged 
Lib/ctypes/macholib/* files are being used? And if not, then something 
surprising is preventing that. If they are - no idea how the macholib 
code got effected by this. The goal was to have all changes in the 
_aix.py file, rather than in util.py.

>
> ----------
> nosy: +Michael.Felt, ned.deily, vstinner
> priority: normal -> release blocker
> stage:  -> needs patch
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue33281>
> _______________________________________
>
msg316035 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-05-02 02:31
New changeset d06d345f04b3f7e5b318df69b1d179328a64ca9c by Ned Deily (Ray Donnelly) in branch 'master':
bpo-33281:  Fix ctypes.util.find_library regression on macOS (GH-6625)
https://github.com/python/cpython/commit/d06d345f04b3f7e5b318df69b1d179328a64ca9c
msg316037 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-05-02 02:41
New changeset 69a013ec189f93a0dea97cfdbb3adc348648a666 by Ned Deily in branch 'master':
bpo-33281: NEWS and ACK (GH-6681)
https://github.com/python/cpython/commit/69a013ec189f93a0dea97cfdbb3adc348648a666
msg316038 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-05-02 02:51
New changeset c74ca5396aa7740d4fc90617e6b2315e849fa71f by Ned Deily (Miss Islington (bot)) in branch '3.7':
bpo-33281:  Fix ctypes.util.find_library regression on macOS (GH-6625) (GH-6680)
https://github.com/python/cpython/commit/c74ca5396aa7740d4fc90617e6b2315e849fa71f
msg316039 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-05-02 02:52
New changeset d74f35331f176e0679f0614b6cccf0dc0422e31a by Ned Deily (Miss Islington (bot)) in branch '3.7':
bpo-33281: NEWS and ACK (GH-6681) (GH-6682)
https://github.com/python/cpython/commit/d74f35331f176e0679f0614b6cccf0dc0422e31a
msg316040 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2018-05-02 02:56
Thanks for the PR, Ray.  Merged for 3.7.0b4 (and 3.8.0).
History
Date User Action Args
2018-05-02 02:56:57ned.deilysetstatus: open -> closed
priority: release blocker ->

versions: + Python 3.8
nosy: + Ray.Donnelly

messages: + msg316040
resolution: fixed
stage: patch review -> resolved
2018-05-02 02:52:45ned.deilysetmessages: + msg316039
2018-05-02 02:51:34ned.deilysetmessages: + msg316038
2018-05-02 02:41:55miss-islingtonsetpull_requests: + pull_request6378
2018-05-02 02:41:45ned.deilysetmessages: + msg316037
2018-05-02 02:37:52ned.deilysetpull_requests: + pull_request6377
2018-05-02 02:31:56miss-islingtonsetpull_requests: + pull_request6376
2018-05-02 02:31:45ned.deilysetmessages: + msg316035
2018-04-28 12:39:29python-devsetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request6321
2018-04-25 14:54:41Michael.Feltsetmessages: + msg315742
2018-04-15 06:05:01ned.deilysetnosy: + amaury.forgeotdarc, belopolsky, meador.inge
2018-04-15 05:56:41ned.deilysetpriority: normal -> release blocker

nosy: + Michael.Felt, vstinner, ned.deily
messages: + msg315310

stage: needs patch
2018-04-15 05:24:20Ian Burgwincreate