Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3eaaeb4

Browse files
author
Thomas Heller
committed
Merged revisions 63395-63396,63511,63522-63523 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r63395 | thomas.heller | 2008-05-16 22:06:31 +0200 (Fr, 16 Mai 2008) | 4 lines Issue 1793: Add ctypes.util.find_msvcrt() function (on Windows). ........ r63396 | thomas.heller | 2008-05-16 22:19:07 +0200 (Fr, 16 Mai 2008) | 4 lines Very simple test for ctypes.util.find_library on Windows. ........ r63511 | thomas.heller | 2008-05-20 21:53:47 +0200 (Di, 20 Mai 2008) | 6 lines On HPUX, -fPIC must be used for linking. _ctypes now builds on HP-UX IA64 and PA machines. The ctypes unittests work fine on the IA64, but dump core in test_qsort on the PA. ........ r63522 | thomas.heller | 2008-05-21 20:47:02 +0200 (Mi, 21 Mai 2008) | 2 lines The -x <test1[,test2...]> flag allows to exclude tests. ........ r63523 | thomas.heller | 2008-05-21 21:47:44 +0200 (Mi, 21 Mai 2008) | 2 lines Oops, get_tests may be called with 3 arguments. ........
1 parent ab081cf commit 3eaaeb4

6 files changed

Lines changed: 64 additions & 6 deletions

File tree

Lib/ctypes/test/__init__.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,16 @@ def find_package_modules(package, mask):
5050
if fnmatch.fnmatchcase(fnm, mask):
5151
yield "%s.%s" % (package.__name__, os.path.splitext(fnm)[0])
5252

53-
def get_tests(package, mask, verbosity):
53+
def get_tests(package, mask, verbosity, exclude=()):
5454
"""Return a list of skipped test modules, and a list of test cases."""
5555
tests = []
5656
skipped = []
5757
for modname in find_package_modules(package, mask):
58+
if modname.split(".")[-1] in exclude:
59+
skipped.append(modname)
60+
if verbosity > 1:
61+
print >> sys.stderr, "Skipped %s: excluded" % modname
62+
continue
5863
try:
5964
mod = __import__(modname, globals(), locals(), ['*'])
6065
except ResourceDenied as detail:
@@ -151,12 +156,13 @@ def run(self, test, skipped):
151156

152157
def main(*packages):
153158
try:
154-
opts, args = getopt.getopt(sys.argv[1:], "rqvu:")
159+
opts, args = getopt.getopt(sys.argv[1:], "rqvu:x:")
155160
except getopt.error:
156161
return usage()
157162

158163
verbosity = 1
159164
search_leaks = False
165+
exclude = []
160166
for flag, value in opts:
161167
if flag == "-q":
162168
verbosity -= 1
@@ -171,17 +177,19 @@ def main(*packages):
171177
search_leaks = True
172178
elif flag == "-u":
173179
use_resources.extend(value.split(","))
180+
elif flag == "-x":
181+
exclude.append(value.split(","))
174182

175183
mask = "test_*.py"
176184
if args:
177185
mask = args[0]
178186

179187
for package in packages:
180-
run_tests(package, mask, verbosity, search_leaks)
188+
run_tests(package, mask, verbosity, search_leaks, exclude)
181189

182190

183-
def run_tests(package, mask, verbosity, search_leaks):
184-
skipped, testcases = get_tests(package, mask, verbosity)
191+
def run_tests(package, mask, verbosity, search_leaks, exclude):
192+
skipped, testcases = get_tests(package, mask, verbosity, exclude)
185193
runner = TestRunner(verbosity=verbosity)
186194

187195
suites = [unittest.makeSuite(o) for o in testcases]

Lib/ctypes/test/runtests.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
Add resources to the lits of allowed resources. '*' allows all
99
resources.
1010
-v verbose mode: print the test currently executed
11+
-x<test1[,test2...]>
12+
Exclude specified tests.
1113
mask mask to select filenames containing testcases, wildcards allowed
1214
"""
1315
import sys

Lib/ctypes/test/test_loading.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
libc_name = None
88
if os.name == "nt":
9-
libc_name = "msvcrt"
9+
libc_name = find_library("c")
1010
elif os.name == "ce":
1111
libc_name = "coredll"
1212
elif sys.platform == "cygwin":
@@ -43,6 +43,7 @@ def test_find(self):
4343

4444
if os.name in ("nt", "ce"):
4545
def test_load_library(self):
46+
self.failIf(libc_name is None)
4647
if is_resource_enabled("printing"):
4748
print(find_library("kernel32"))
4849
print(find_library("user32"))

Lib/ctypes/util.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,50 @@
22

33
# find_library(name) returns the pathname of a library, or None.
44
if os.name == "nt":
5+
6+
def _get_build_version():
7+
"""Return the version of MSVC that was used to build Python.
8+
9+
For Python 2.3 and up, the version number is included in
10+
sys.version. For earlier versions, assume the compiler is MSVC 6.
11+
"""
12+
# This function was copied from Lib/distutils/msvccompiler.py
13+
prefix = "MSC v."
14+
i = sys.version.find(prefix)
15+
if i == -1:
16+
return 6
17+
i = i + len(prefix)
18+
s, rest = sys.version[i:].split(" ", 1)
19+
majorVersion = int(s[:-2]) - 6
20+
minorVersion = int(s[2:3]) / 10.0
21+
# I don't think paths are affected by minor version in version 6
22+
if majorVersion == 6:
23+
minorVersion = 0
24+
if majorVersion >= 6:
25+
return majorVersion + minorVersion
26+
# else we don't know what version of the compiler this is
27+
return None
28+
29+
def find_msvcrt():
30+
"""Return the name of the VC runtime dll"""
31+
version = _get_build_version()
32+
if version is None:
33+
# better be safe than sorry
34+
return None
35+
if version <= 6:
36+
clibname = 'msvcrt'
37+
else:
38+
clibname = 'msvcr%d' % (version * 10)
39+
40+
# If python was built with in debug mode
41+
import imp
42+
if imp.get_suffixes()[0][0] == '_d.pyd':
43+
clibname += 'd'
44+
return clibname+'.dll'
45+
546
def find_library(name):
47+
if name in ('c', 'm'):
48+
return find_msvcrt()
649
# See MSDN for the REAL search order.
750
for directory in os.environ['PATH'].split(os.pathsep):
851
fname = os.path.join(directory, name)

Modules/_ctypes/libffi/fficonfig.py.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ ffi_platforms = {
2525
'SH64': ['src/sh64/sysv.S', 'src/sh64/ffi.c'],
2626
'PA': ['src/pa/linux.S', 'src/pa/ffi.c'],
2727
'PA_LINUX': ['src/pa/linux.S', 'src/pa/ffi.c'],
28+
'PA_HPUX': ['src/pa/hpux32.s', 'src/pa/ffi.c'],
2829
}
2930

3031
ffi_srcdir = '@srcdir@'

setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,6 +1408,9 @@ def detect_ctypes(self, inc_dirs, lib_dirs):
14081408
# finding some -z option for the Sun compiler.
14091409
extra_link_args.append('-mimpure-text')
14101410

1411+
elif sys.platform.startswith('hpux'):
1412+
extra_link_args.append('-fPIC')
1413+
14111414
ext = Extension('_ctypes',
14121415
include_dirs=include_dirs,
14131416
extra_compile_args=extra_compile_args,

0 commit comments

Comments
 (0)