Skip to content

Commit 2294c0d

Browse files
committed
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
1 parent c4f4ca9 commit 2294c0d

3 files changed

Lines changed: 46 additions & 4 deletions

File tree

Doc/lib/libimp.tex

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,19 @@ \section{\module{imp} ---
106106
triggered by that).
107107
\end{funcdesc}
108108

109+
\begin{funcdesc}{acquire_lock}{}
110+
Acquires the interpreter's import lock for the current thread. This lock
111+
should be used by import hooks to ensure thread-safety when importing modules.
112+
On platforms without threads, this function does nothing.
113+
\versionadded{2.3}
114+
\end{funcdesc}
115+
116+
\begin{funcdesc}{release_lock}{}
117+
Release the interpreter's import lock.
118+
On platforms without threads, this function does nothing.
119+
\versionadded{2.3}
120+
\end{funcdesc}
121+
109122
The following constants with integer values, defined in this module,
110123
are used to indicate the search result of \function{find_module()}.
111124

Lib/test/test_imp.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
import imp
3+
import unittest
4+
from test_support import TestFailed
5+
6+
class ImpLock(unittest.TestCase):
7+
8+
# XXX this test is woefully inadequate, please fix me
9+
def testLock(self):
10+
LOOPS = 50
11+
for i in range(LOOPS):
12+
imp.acquire_lock()
13+
for i in range(LOOPS):
14+
imp.release_lock()
15+
16+
for i in range(LOOPS):
17+
try:
18+
imp.release_lock()
19+
except RuntimeError:
20+
pass
21+
else:
22+
raise TestFailed, \
23+
"release_lock() without lock should raise RuntimeError"
24+
25+
if __name__ == "__main__":
26+
test_support.run_unittest(ImpLock)

Python/import.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,8 @@ imp_acquire_lock(PyObject *self, PyObject *args)
305305
#ifdef WITH_THREAD
306306
lock_import();
307307
#endif
308-
return Py_None;
308+
Py_INCREF(Py_None);
309+
return Py_None;
309310
}
310311

311312
static PyObject *
@@ -320,7 +321,8 @@ imp_release_lock(PyObject *self, PyObject *args)
320321
return NULL;
321322
}
322323
#endif
323-
return Py_None;
324+
Py_INCREF(Py_None);
325+
return Py_None;
324326
}
325327

326328
/* Helper for sys */
@@ -2778,8 +2780,9 @@ On platforms without threads, return 0.");
27782780

27792781
PyDoc_STRVAR(doc_acquire_lock,
27802782
"acquire_lock() -> None\n\
2781-
Acquires the interpreter's import lock for the current thread. This lock
2782-
should be used by import hooks to ensure thread-safety when importing modules.
2783+
Acquires the interpreter's import lock for the current thread.\n\
2784+
This lock should be used by import hooks to ensure thread-safety\n\
2785+
when importing modules.\n\
27832786
On platforms without threads, this function does nothing.");
27842787

27852788
PyDoc_STRVAR(doc_release_lock,

0 commit comments

Comments
 (0)