Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
8c52027e
Commit
8c52027e
authored
Apr 23, 2011
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #11258: Speed up ctypes.util.find_library() under Linux by a factor
of 5 to 10. Initial patch by Jonas H.
parent
877509ae
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
8 deletions
+18
-8
Lib/ctypes/util.py
Lib/ctypes/util.py
+14
-8
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/ctypes/util.py
View file @
8c52027e
import
sys
,
os
import
contextlib
import
subprocess
# find_library(name) returns the pathname of a library, or None.
if
os
.
name
==
"nt"
:
...
...
@@ -203,14 +204,19 @@ elif os.name == "posix":
abi_type
=
mach_map
.
get
(
machine
,
'libc6'
)
# XXX assuming GLIBC's ldconfig (with option -p)
expr
=
r'(\
S+)
\s+\
((%s(?:, OS ABI:[^
\)]*)?)\
)[^/]*(/[^
\(\
)
\s]*lib%s\
.[^
\(\
)
\s]*)'
\
%
(
abi_type
,
re
.
escape
(
name
))
with
contextlib
.
closing
(
os
.
popen
(
'LC_ALL=C LANG=C /sbin/ldconfig -p 2>/dev/null'
))
as
f
:
data
=
f
.
read
()
res
=
re
.
search
(
expr
,
data
)
if
not
res
:
return
None
return
res
.
group
(
1
)
regex
=
os
.
fsencode
(
'
\
s+(li
b
%s
\
.[^
\
s]+)
\
s+
\
(%s'
%
(
re
.
escape
(
name
),
abi_type
))
try
:
with
subprocess
.
Popen
([
'/sbin/ldconfig'
,
'-p'
],
stdin
=
subprocess
.
DEVNULL
,
stderr
=
subprocess
.
DEVNULL
,
stdout
=
subprocess
.
PIPE
,
env
=
{
'LC_ALL'
:
'C'
,
'LANG'
:
'C'
})
as
p
:
res
=
re
.
search
(
regex
,
p
.
stdout
.
read
())
if
res
:
return
os
.
fsdecode
(
res
.
group
(
1
))
except
OSError
:
pass
def
find_library
(
name
):
return
_findSoname_ldconfig
(
name
)
or
_get_soname
(
_findLib_gcc
(
name
))
...
...
Misc/ACKS
View file @
8c52027e
...
...
@@ -338,6 +338,7 @@ Filip Gruszczyński
Michael Guravage
Lars Gustäbel
Thomas Güttler
Jonas H.
Barry Haddow
Paul ten Hagen
Rasmus Hahn
...
...
Misc/NEWS
View file @
8c52027e
...
...
@@ -113,6 +113,9 @@ Core and Builtins
Library
-------
-
Issue
#
11258
:
Speed
up
ctypes
.
util
.
find_library
()
under
Linux
by
a
factor
of
5
to
10.
Initial
patch
by
Jonas
H
.
-
Issue
#
11382
:
Trivial
system
calls
,
such
as
dup
()
or
pipe
(),
needn
't
release the GIL. Patch by Charles-François Natali.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment