]> granicus.if.org Git - python/commitdiff
Cleanup from patch #683257:
authorNeal Norwitz <nnorwitz@gmail.com>
Wed, 12 Feb 2003 23:02:21 +0000 (23:02 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Wed, 12 Feb 2003 23:02:21 +0000 (23:02 +0000)
 Add missing INCREFs and re-indent returns to be consistent.
 Add \n\ for lines in docstring
 Add a pathetic test
 Add docs

Doc/lib/libimp.tex
Lib/test/test_imp.py [new file with mode: 0644]
Python/import.c

index 150f5b4202152518896e35c372a6f184fae934fe..31368f43c6e9f612a7bd9e8b9c20c921166f6160 100644 (file)
@@ -106,6 +106,19 @@ the process of completing its import (and the imports, if any,
 triggered by that).
 \end{funcdesc}
 
+\begin{funcdesc}{acquire_lock}{}
+Acquires the interpreter's import lock for the current thread.  This lock
+should be used by import hooks to ensure thread-safety when importing modules.
+On platforms without threads, this function does nothing.
+\versionadded{2.3}
+\end{funcdesc}
+
+\begin{funcdesc}{release_lock}{}
+Release the interpreter's import lock.
+On platforms without threads, this function does nothing.
+\versionadded{2.3}
+\end{funcdesc}
+
 The following constants with integer values, defined in this module,
 are used to indicate the search result of \function{find_module()}.
 
diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py
new file mode 100644 (file)
index 0000000..ebecf82
--- /dev/null
@@ -0,0 +1,26 @@
+
+import imp
+import unittest
+from test_support import TestFailed
+
+class ImpLock(unittest.TestCase):
+
+    # XXX this test is woefully inadequate, please fix me
+    def testLock(self):
+        LOOPS = 50
+        for i in range(LOOPS):
+            imp.acquire_lock()
+        for i in range(LOOPS):
+            imp.release_lock()
+
+        for i in range(LOOPS):
+            try:
+                imp.release_lock()
+            except RuntimeError:
+                pass
+            else:
+                raise TestFailed, \
+                    "release_lock() without lock should raise RuntimeError"
+
+if __name__ == "__main__":
+    test_support.run_unittest(ImpLock)
index f1d3d0cdf6be5e6941d2377318180ffc61597f08..07fff18d0b45293981a848e7c2447a9ba6f2dc86 100644 (file)
@@ -305,7 +305,8 @@ imp_acquire_lock(PyObject *self, PyObject *args)
 #ifdef WITH_THREAD
        lock_import();
 #endif
-    return Py_None;
+       Py_INCREF(Py_None);
+       return Py_None;
 }
 
 static PyObject *
@@ -320,7 +321,8 @@ imp_release_lock(PyObject *self, PyObject *args)
                return NULL;
        }
 #endif
-    return Py_None;
+       Py_INCREF(Py_None);
+       return Py_None;
 }
 
 /* Helper for sys */
@@ -2778,8 +2780,9 @@ On platforms without threads, return 0.");
 
 PyDoc_STRVAR(doc_acquire_lock,
 "acquire_lock() -> None\n\
-Acquires the interpreter's import lock for the current thread.  This lock
-should be used by import hooks to ensure thread-safety when importing modules.
+Acquires the interpreter's import lock for the current thread.\n\
+This lock should be used by import hooks to ensure thread-safety\n\
+when importing modules.\n\
 On platforms without threads, this function does nothing.");
 
 PyDoc_STRVAR(doc_release_lock,