[pypy-svn] r23379 - in pypy/dist/pypy/module/thread: . test
nik at codespeak.net
nik at codespeak.net
Wed Feb 15 21:58:02 CET 2006
Author: nik
Date: Wed Feb 15 21:58:01 2006
New Revision: 23379
Modified:
pypy/dist/pypy/module/thread/os_thread.py
pypy/dist/pypy/module/thread/test/test_thread.py
Log:
fixed start_new_thread argument checking (issue180). the callable check is not nice,
maybe objspaces should have a hasattr method?
Modified: pypy/dist/pypy/module/thread/os_thread.py
==============================================================================
--- pypy/dist/pypy/module/thread/os_thread.py (original)
+++ pypy/dist/pypy/module/thread/os_thread.py Wed Feb 15 21:58:01 2006
@@ -57,9 +57,17 @@
function returns; the return value is ignored. The thread will also exit
when the function raises an unhandled exception; a stack trace will be
printed unless the exception is SystemExit."""
- # XXX check that w_callable is callable
- # XXX check that w_args is a tuple
- # XXX check that w_kwargs is a dict
+ if not space.is_true(space.isinstance(w_args, space.w_tuple)):
+ raise OperationError(space.w_TypeError,
+ space.wrap("2nd arg must be a tuple"))
+ if w_kwargs is not None and not space.is_true(space.isinstance(w_kwargs, space.w_dict)):
+ raise OperationError(space.w_TypeError,
+ space.wrap("optional 3rd arg must be a dictionary"))
+ # XXX using space.lookup here is not very nice
+ if space.lookup(w_callable, "__call__") is None:
+ raise OperationError(space.w_TypeError,
+ space.wrap("first arg must be callable"))
+
args = Arguments.frompacked(space, w_args, w_kwargs)
boot = Bootstrapper()
boot.space = space
Modified: pypy/dist/pypy/module/thread/test/test_thread.py
==============================================================================
--- pypy/dist/pypy/module/thread/test/test_thread.py (original)
+++ pypy/dist/pypy/module/thread/test/test_thread.py Wed Feb 15 21:58:01 2006
@@ -16,6 +16,22 @@
self.waitfor(lambda: feedback)
assert feedback == [42]
+ def test_start_new_thread_args(self):
+ import thread
+ def f():
+ pass
+ test_args = [
+ (f, [], {}),
+ (f, (), []),
+ ("", (), {}),
+ ]
+ for args in test_args:
+ try:
+ thread.start_new_thread(*args)
+ assert False
+ except TypeError:
+ pass
+
def test_get_ident(self):
import thread
ident = thread.get_ident()
More information about the Pypy-commit
mailing list