[Python-3000-checkins] r63565 - in python/branches/py3k: Lib/ctypes/test/__init__.py Lib/ctypes/test/runtests.py Lib/ctypes/test/test_loading.py Lib/ctypes/util.py Modules/_ctypes/libffi/fficonfig.py.in setup.py

thomas.heller python-3000-checkins at python.org
Fri May 23 19:26:47 CEST 2008


Author: thomas.heller
Date: Fri May 23 19:26:46 2008
New Revision: 63565

Log:
Merged revisions 63395-63396,63511,63522-63523 via svnmerge from 
svn+ssh://pythondev@svn.python.org/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.
........


Modified:
   python/branches/py3k/   (props changed)
   python/branches/py3k/Lib/ctypes/test/__init__.py
   python/branches/py3k/Lib/ctypes/test/runtests.py
   python/branches/py3k/Lib/ctypes/test/test_loading.py
   python/branches/py3k/Lib/ctypes/util.py
   python/branches/py3k/Modules/_ctypes/libffi/fficonfig.py.in
   python/branches/py3k/setup.py

Modified: python/branches/py3k/Lib/ctypes/test/__init__.py
==============================================================================
--- python/branches/py3k/Lib/ctypes/test/__init__.py	(original)
+++ python/branches/py3k/Lib/ctypes/test/__init__.py	Fri May 23 19:26:46 2008
@@ -50,11 +50,16 @@
             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 @@
 
 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 @@
             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]

Modified: python/branches/py3k/Lib/ctypes/test/runtests.py
==============================================================================
--- python/branches/py3k/Lib/ctypes/test/runtests.py	(original)
+++ python/branches/py3k/Lib/ctypes/test/runtests.py	Fri May 23 19:26:46 2008
@@ -8,6 +8,8 @@
          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

Modified: python/branches/py3k/Lib/ctypes/test/test_loading.py
==============================================================================
--- python/branches/py3k/Lib/ctypes/test/test_loading.py	(original)
+++ python/branches/py3k/Lib/ctypes/test/test_loading.py	Fri May 23 19:26:46 2008
@@ -6,7 +6,7 @@
 
 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 @@
 
     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"))

Modified: python/branches/py3k/Lib/ctypes/util.py
==============================================================================
--- python/branches/py3k/Lib/ctypes/util.py	(original)
+++ python/branches/py3k/Lib/ctypes/util.py	Fri May 23 19:26:46 2008
@@ -2,7 +2,50 @@
 
 # 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)

Modified: python/branches/py3k/Modules/_ctypes/libffi/fficonfig.py.in
==============================================================================
--- python/branches/py3k/Modules/_ctypes/libffi/fficonfig.py.in	(original)
+++ python/branches/py3k/Modules/_ctypes/libffi/fficonfig.py.in	Fri May 23 19:26:46 2008
@@ -25,6 +25,7 @@
     '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@'

Modified: python/branches/py3k/setup.py
==============================================================================
--- python/branches/py3k/setup.py	(original)
+++ python/branches/py3k/setup.py	Fri May 23 19:26:46 2008
@@ -1408,6 +1408,9 @@
             # 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,


More information about the Python-3000-checkins mailing list