Merged revisions 59666-59679 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r59666 | christian.heimes | 2008-01-02 19:28:32 +0100 (Wed, 02 Jan 2008) | 1 line

  Made vs9to8 Unix compatible
........
  r59669 | guido.van.rossum | 2008-01-02 20:00:46 +0100 (Wed, 02 Jan 2008) | 2 lines

  Patch #1696.  Don't attempt to close None in dry-run mode.
........
  r59671 | jeffrey.yasskin | 2008-01-03 03:21:52 +0100 (Thu, 03 Jan 2008) | 6 lines

  Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
  the complex_pow part), r56649, r56652, r56715, r57296, r57302, r57359, r57361,
  r57372, r57738, r57739, r58017, r58039, r58040, and r59390, and new
  documentation. The only significant difference is that round(x) returns a float
  to preserve backward-compatibility. See http://bugs.python.org/issue1689.
........
  r59672 | christian.heimes | 2008-01-03 16:41:30 +0100 (Thu, 03 Jan 2008) | 1 line

  Issue #1726: Remove Python/atof.c from PCBuild/pythoncore.vcproj
........
  r59675 | guido.van.rossum | 2008-01-03 20:12:44 +0100 (Thu, 03 Jan 2008) | 4 lines

  Issue #1700, reported by Nguyen Quan Son, fix by Fredruk Lundh:
  Regular Expression inline flags not handled correctly for some unicode
  characters.  (Forward port from 2.5.2.)
........
  r59676 | christian.heimes | 2008-01-03 21:23:15 +0100 (Thu, 03 Jan 2008) | 1 line

  Added math.isinf() and math.isnan()
........
  r59677 | christian.heimes | 2008-01-03 22:14:48 +0100 (Thu, 03 Jan 2008) | 1 line

  Some build bots don't compile mathmodule. There is an issue with the long definition of pi and euler
........
  r59678 | christian.heimes | 2008-01-03 23:16:32 +0100 (Thu, 03 Jan 2008) | 2 lines

  Modified PyImport_Import and PyImport_ImportModule to always use absolute imports by calling __import__ with an explicit level of 0
  Added a new API function PyImport_ImportModuleNoBlock. It solves the problem with dead locks when mixing threads and imports
........
  r59679 | christian.heimes | 2008-01-03 23:32:26 +0100 (Thu, 03 Jan 2008) | 1 line

  Added copysign(x, y) function to the math module
........
diff --git a/Python/import.c b/Python/import.c
index a7f6a48..658cc70 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -1896,6 +1896,53 @@
 	return result;
 }
 
+/* Import a module without blocking
+ *
+ * At first it tries to fetch the module from sys.modules. If the module was
+ * never loaded before it loads it with PyImport_ImportModule() unless another
+ * thread holds the import lock. In the latter case the function raises an
+ * ImportError instead of blocking.
+ *
+ * Returns the module object with incremented ref count.
+ */
+PyObject *
+PyImport_ImportModuleNoBlock(const char *name)
+{
+	PyObject *result;
+	PyObject *modules;
+	long me;
+
+	/* Try to get the module from sys.modules[name] */
+	modules = PyImport_GetModuleDict();
+	if (modules == NULL)
+		return NULL;
+
+	result = PyDict_GetItemString(modules, name);
+	if (result != NULL) {
+		Py_INCREF(result);
+		return result;
+	}
+	else {
+		PyErr_Clear();
+	}
+
+	/* check the import lock
+	 * me might be -1 but I ignore the error here, the lock function
+	 * takes care of the problem */
+	me = PyThread_get_thread_ident();
+	if (import_lock_thread == -1 || import_lock_thread == me) {
+		/* no thread or me is holding the lock */
+		return PyImport_ImportModule(name);
+	}
+	else {
+		PyErr_Format(PyExc_ImportError,
+			     "Failed to import %.200s because the import lock"
+			     "is held by another thread.",
+			     name);
+		return NULL;
+	}
+}
+
 /* Forward declarations for helper routines */
 static PyObject *get_parent(PyObject *globals, char *buf,
 			    Py_ssize_t *p_buflen, int level);
@@ -1965,26 +2012,6 @@
 	return tail;
 }
 
-/* For DLL compatibility */
-#undef PyImport_ImportModuleEx
-PyObject *
-PyImport_ImportModuleEx(char *name, PyObject *globals, PyObject *locals,
-			PyObject *fromlist)
-{
-	PyObject *result;
-	lock_import();
-	result = import_module_level(name, globals, locals, fromlist, -1);
-	if (unlock_import() < 0) {
-		Py_XDECREF(result);
-		PyErr_SetString(PyExc_RuntimeError,
-				"not holding the import lock");
-		return NULL;
-	}
-	return result;
-}
-#define PyImport_ImportModuleEx(n, g, l, f) \
-	PyImport_ImportModuleLevel(n, g, l, f, -1);
-
 PyObject *
 PyImport_ImportModuleLevel(char *name, PyObject *globals, PyObject *locals,
 			 PyObject *fromlist, int level)
@@ -2572,9 +2599,10 @@
 	if (import == NULL)
 		goto err;
 
-	/* Call the __import__ function with the proper argument list */
-	r = PyObject_CallFunctionObjArgs(import, module_name, globals,
-					 globals, silly_list, NULL);
+	/* Call the __import__ function with the proper argument list
+	 * Always use absolute import here. */
+	r = PyObject_CallFunction(import, "OOOOi", module_name, globals,
+				  globals, silly_list, 0, NULL);
 
   err:
 	Py_XDECREF(globals);