summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/ctypes/test/__init__.py18
-rw-r--r--Lib/ctypes/test/runtests.py2
-rw-r--r--Lib/ctypes/test/test_loading.py3
-rw-r--r--Lib/ctypes/util.py43
-rw-r--r--Modules/_ctypes/libffi/fficonfig.py.in1
-rw-r--r--setup.py3
6 files changed, 64 insertions, 6 deletions
diff --git a/Lib/ctypes/test/__init__.py b/Lib/ctypes/test/__init__.py
index 60b4975..97eef1b 100644
--- a/Lib/ctypes/test/__init__.py
+++ b/Lib/ctypes/test/__init__.py
@@ -50,11 +50,16 @@ def find_package_modules(package, mask):
if fnmatch.fnmatchcase(fnm, mask):
yield "%s.%s" % (package.__name__, os.path.splitext(fnm)[0])
-def get_tests(package, mask, verbosity):
+def get_tests(package, mask, verbosity, exclude=()):
"""Return a list of skipped test modules, and a list of test cases."""
tests = []
skipped = []
for modname in find_package_modules(package, mask):
+ if modname.split(".")[-1] in exclude:
+ skipped.append(modname)
+ if verbosity > 1:
+ print >> sys.stderr, "Skipped %s: excluded" % modname
+ continue
try:
mod = __import__(modname, globals(), locals(), ['*'])
except ResourceDenied as detail:
@@ -151,12 +156,13 @@ class TestRunner(unittest.TextTestRunner):
def main(*packages):
try:
- opts, args = getopt.getopt(sys.argv[1:], "rqvu:")
+ opts, args = getopt.getopt(sys.argv[1:], "rqvu:x:")
except getopt.error:
return usage()
verbosity = 1
search_leaks = False
+ exclude = []
for flag, value in opts:
if flag == "-q":
verbosity -= 1
@@ -171,17 +177,19 @@ def main(*packages):
search_leaks = True
elif flag == "-u":
use_resources.extend(value.split(","))
+ elif flag == "-x":
+ exclude.append(value.split(","))
mask = "test_*.py"
if args:
mask = args[0]
for package in packages:
- run_tests(package, mask, verbosity, search_leaks)
+ run_tests(package, mask, verbosity, search_leaks, exclude)
-def run_tests(package, mask, verbosity, search_leaks):
- skipped, testcases = get_tests(package, mask, verbosity)
+def run_tests(package, mask, verbosity, search_leaks, exclude):
+ skipped, testcases = get_tests(package, mask, verbosity, exclude)
runner = TestRunner(verbosity=verbosity)
suites = [unittest.makeSuite(o) for o in testcases]
diff --git a/Lib/ctypes/test/runtests.py b/Lib/ctypes/test/runtests.py
index 14d7caa..ec31fc8 100644
--- a/Lib/ctypes/test/runtests.py
+++ b/Lib/ctypes/test/runtests.py
@@ -8,6 +8,8 @@ Command line flags:
Add resources to the lits of allowed resources. '*' allows all
resources.
-v verbose mode: print the test currently executed
+ -x<test1[,test2...]>
+ Exclude specified tests.
mask mask to select filenames containing testcases, wildcards allowed
"""
import sys
diff --git a/Lib/ctypes/test/test_loading.py b/Lib/ctypes/test/test_loading.py
index fa2b7e2..b83828a 100644
--- a/Lib/ctypes/test/test_loading.py
+++ b/Lib/ctypes/test/test_loading.py
@@ -6,7 +6,7 @@ from ctypes.test import is_resource_enabled
libc_name = None
if os.name == "nt":
- libc_name = "msvcrt"
+ libc_name = find_library("c")
elif os.name == "ce":
libc_name = "coredll"
elif sys.platform == "cygwin":
@@ -43,6 +43,7 @@ class LoaderTest(unittest.TestCase):
if os.name in ("nt", "ce"):
def test_load_library(self):
+ self.failIf(libc_name is None)
if is_resource_enabled("printing"):
print(find_library("kernel32"))
print(find_library("user32"))
diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py
index 3e6ae01..29bc488 100644
--- a/Lib/ctypes/util.py
+++ b/Lib/ctypes/util.py
@@ -2,7 +2,50 @@ import sys, os
# find_library(name) returns the pathname of a library, or None.
if os.name == "nt":
+
+ def _get_build_version():
+ """Return the version of MSVC that was used to build Python.
+
+ For Python 2.3 and up, the version number is included in
+ sys.version. For earlier versions, assume the compiler is MSVC 6.
+ """
+ # This function was copied from Lib/distutils/msvccompiler.py
+ prefix = "MSC v."
+ i = sys.version.find(prefix)
+ if i == -1:
+ return 6
+ i = i + len(prefix)
+ s, rest = sys.version[i:].split(" ", 1)
+ majorVersion = int(s[:-2]) - 6
+ minorVersion = int(s[2:3]) / 10.0
+ # I don't think paths are affected by minor version in version 6
+ if majorVersion == 6:
+ minorVersion = 0
+ if majorVersion >= 6:
+ return majorVersion + minorVersion
+ # else we don't know what version of the compiler this is
+ return None
+
+ def find_msvcrt():
+ """Return the name of the VC runtime dll"""
+ version = _get_build_version()
+ if version is None:
+ # better be safe than sorry
+ return None
+ if version <= 6:
+ clibname = 'msvcrt'
+ else:
+ clibname = 'msvcr%d' % (version * 10)
+
+ # If python was built with in debug mode
+ import imp
+ if imp.get_suffixes()[0][0] == '_d.pyd':
+ clibname += 'd'
+ return clibname+'.dll'
+
def find_library(name):
+ if name in ('c', 'm'):
+ return find_msvcrt()
# See MSDN for the REAL search order.
for directory in os.environ['PATH'].split(os.pathsep):
fname = os.path.join(directory, name)
diff --git a/Modules/_ctypes/libffi/fficonfig.py.in b/Modules/_ctypes/libffi/fficonfig.py.in
index 09c13db..f5f3810 100644
--- a/Modules/_ctypes/libffi/fficonfig.py.in
+++ b/Modules/_ctypes/libffi/fficonfig.py.in
@@ -25,6 +25,7 @@ ffi_platforms = {
'SH64': ['src/sh64/sysv.S', 'src/sh64/ffi.c'],
'PA': ['src/pa/linux.S', 'src/pa/ffi.c'],
'PA_LINUX': ['src/pa/linux.S', 'src/pa/ffi.c'],
+ 'PA_HPUX': ['src/pa/hpux32.s', 'src/pa/ffi.c'],
}
ffi_srcdir = '@srcdir@'
diff --git a/setup.py b/setup.py
index c339ba8..34e6c39 100644
--- a/setup.py
+++ b/setup.py
@@ -1408,6 +1408,9 @@ class PyBuildExt(build_ext):
# finding some -z option for the Sun compiler.
extra_link_args.append('-mimpure-text')
+ elif sys.platform.startswith('hpux'):
+ extra_link_args.append('-fPIC')
+
ext = Extension('_ctypes',
include_dirs=include_dirs,
extra_compile_args=extra_compile_args,