summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2003-02-12 23:02:21 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2003-02-12 23:02:21 (GMT)
commit2294c0d4ecd81d01ddf741fff02cc04bd8de0638 (patch)
tree1e30d22150343825a5bbb7ff3d00f76aaae88f4a
parentc4f4ca91e112a55b2fac5853718a5f05797f30b5 (diff)
downloadcpython-2294c0d4ecd81d01ddf741fff02cc04bd8de0638.zip
cpython-2294c0d4ecd81d01ddf741fff02cc04bd8de0638.tar.gz
cpython-2294c0d4ecd81d01ddf741fff02cc04bd8de0638.tar.bz2
Cleanup from patch #683257:
Add missing INCREFs and re-indent returns to be consistent. Add \n\ for lines in docstring Add a pathetic test Add docs
-rw-r--r--Doc/lib/libimp.tex13
-rw-r--r--Lib/test/test_imp.py26
-rw-r--r--Python/import.c11
3 files changed, 46 insertions, 4 deletions
diff --git a/Doc/lib/libimp.tex b/Doc/lib/libimp.tex
index 150f5b4..31368f4 100644
--- a/Doc/lib/libimp.tex
+++ b/Doc/lib/libimp.tex
@@ -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
index 0000000..ebecf82
--- /dev/null
+++ b/Lib/test/test_imp.py
@@ -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)
diff --git a/Python/import.c b/Python/import.c
index f1d3d0c..07fff18 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -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,