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
726dcf34
Commit
726dcf34
authored
Apr 05, 2006
by
Thomas Heller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use 'ldd' to find the libc library to load. Based on an idea from Matthias Klose.
parent
a2a26b9e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
40 deletions
+40
-40
Lib/ctypes/test/test_loading.py
Lib/ctypes/test/test_loading.py
+40
-40
No files found.
Lib/ctypes/test/test_loading.py
View file @
726dcf34
...
...
@@ -2,47 +2,48 @@ from ctypes import *
import
sys
,
unittest
import
os
,
StringIO
libc_name
=
None
if
os
.
name
==
"nt"
:
libc_name
=
"msvcrt"
elif
os
.
name
==
"ce"
:
libc_name
=
"coredll"
elif
sys
.
platform
==
"darwin"
:
libc_name
=
"libc.dylib"
elif
sys
.
platform
==
"cygwin"
:
libc_name
=
"cygwin1.dll"
else
:
for
line
in
os
.
popen
(
"ldd %s"
%
sys
.
executable
):
if
"libc.so"
in
line
:
if
sys
.
platform
==
"openbsd3"
:
libc_name
=
line
.
split
()[
4
]
else
:
libc_name
=
line
.
split
()[
2
]
## print "libc_name is", libc_name
break
class
LoaderTest
(
unittest
.
TestCase
):
unknowndll
=
"xxrandomnamexx"
if
libc_name
is
not
None
:
def
test_load
(
self
):
if
os
.
name
==
"nt"
:
name
=
"msvcrt"
elif
os
.
name
==
"ce"
:
name
=
"coredll"
elif
sys
.
platform
==
"darwin"
:
name
=
"libc.dylib"
elif
sys
.
platform
.
startswith
(
"freebsd"
):
name
=
"libc.so"
elif
sys
.
platform
in
(
"sunos5"
,
"osf1V5"
):
name
=
"libc.so"
elif
sys
.
platform
.
startswith
(
"netbsd"
)
or
sys
.
platform
.
startswith
(
"openbsd"
):
name
=
"libc.so"
else
:
name
=
"libc.so.6"
## print (sys.platform, os.name)
try
:
cdll
.
load
(
name
)
except
Exception
,
details
:
self
.
fail
((
str
(
details
),
name
,
(
os
.
name
,
sys
.
platform
)))
cdll
.
load
(
libc_name
)
cdll
.
load
(
os
.
path
.
basename
(
libc_name
))
self
.
assertRaises
(
OSError
,
cdll
.
load
,
self
.
unknowndll
)
if
libc_name
is
not
None
and
"libc.so.6"
in
libc_name
:
def
test_load_version
(
self
):
version
=
"6"
name
=
"c"
if
sys
.
platform
==
"linux2"
:
cdll
.
load_version
(
name
,
version
)
cdll
.
load_version
(
"c"
,
"6"
)
# linux uses version, libc 9 should not exist
self
.
assertRaises
(
OSError
,
cdll
.
load_version
,
name
,
"9"
)
self
.
assertRaises
(
OSError
,
cdll
.
load_version
,
"c"
,
"9"
)
self
.
assertRaises
(
OSError
,
cdll
.
load_version
,
self
.
unknowndll
,
""
)
if
os
.
name
==
"posix"
and
sys
.
platform
!=
"sunos5"
:
def
test_find
(
self
):
name
=
"c"
cdll
.
find
(
name
)
self
.
assertRaises
(
OSError
,
cdll
.
find
,
self
.
unknowndll
)
if
os
.
name
in
(
"nt"
,
"ce"
):
def
test_load_library
(
self
):
if
os
.
name
==
"nt"
:
windll
.
load_library
(
"kernel32"
).
GetModuleHandleW
...
...
@@ -54,7 +55,6 @@ class LoaderTest(unittest.TestCase):
WinDLL
(
"coredll"
).
GetModuleHandleW
def
test_load_ordinal_functions
(
self
):
if
os
.
name
in
(
"nt"
,
"ce"
):
import
_ctypes_test
dll
=
WinDLL
(
_ctypes_test
.
__file__
)
# We load the same function both via ordinal and name
...
...
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