Author: Amaury Forgeot d'Arc <amaur...@gmail.com> Branch: py3.3 Changeset: r78081:38c4a6aa6559 Date: 2015-05-02 22:38 +0200 http://bitbucket.org/pypy/pypy/changeset/38c4a6aa6559/
Log: Fix sys.thread_info diff --git a/pypy/module/sys/__init__.py b/pypy/module/sys/__init__.py --- a/pypy/module/sys/__init__.py +++ b/pypy/module/sys/__init__.py @@ -78,7 +78,7 @@ 'int_info' : 'system.get_int_info(space)', 'hash_info' : 'system.get_hash_info(space)', 'float_repr_style' : 'system.get_float_repr_style(space)', - 'thread_info' : 'system.get_thread_info(space)' + 'thread_info' : 'system.get_thread_info(space)', } if sys.platform == 'win32': diff --git a/pypy/module/sys/system.py b/pypy/module/sys/system.py --- a/pypy/module/sys/system.py +++ b/pypy/module/sys/system.py @@ -1,5 +1,6 @@ """Information about the current system.""" import sys +import os from pypy.objspace.std.complexobject import HASH_IMAG from pypy.objspace.std.floatobject import HASH_INF, HASH_NAN @@ -91,10 +92,21 @@ # every field if not space.config.objspace.usemodules.thread: return None + from rpython.rlib import rthread + if rthread.RPYTHREAD_NAME == "pthread": + w_lock = space.wrap("semaphore" if rthread.USE_SEMAPHORES + else "mutex+cond") + if rthread.CS_GNU_LIBPTHREAD_VERSION is not None: + w_version = space.wrap( + os.confstr(rthread.CS_GNU_LIBPTHREAD_VERSION)) + else: + w_version = space.w_None + else: + w_lock = space.w_None + w_version = space.w_None info_w = [ - space.wrap(space.w_None), - space.wrap(space.w_None), - space.wrap(space.w_None), + space.wrap(rthread.RPYTHREAD_NAME), + w_lock, w_version, ] w_thread_info = app.wget(space, "thread_info") return space.call_function(w_thread_info, space.newtuple(info_w)) diff --git a/pypy/module/sys/test/test_sysmodule.py b/pypy/module/sys/test/test_sysmodule.py --- a/pypy/module/sys/test/test_sysmodule.py +++ b/pypy/module/sys/test/test_sysmodule.py @@ -38,6 +38,9 @@ space.setattr(w_sys, space.wrap('stderr'), w_sys.get('__stderr__')) class AppTestAppSysTests: + spaceconfig = { + "usemodules": ["thread"], + } def setup_class(cls): cls.w_appdirect = cls.space.wrap(cls.runappdirect) @@ -201,6 +204,13 @@ exc = raises(SystemExit, sys.exit, (1, 2, 3)) assert exc.value.code == (1, 2, 3) + def test_sys_thread_info(self): + import sys + info = sys.thread_info + assert isinstance(info.name, str) + assert isinstance(info.lock, (str, type(None))) + assert isinstance(info.version, (str, type(None))) + class AppTestSysModulePortedFromCPython: def setup_class(cls): diff --git a/rpython/rlib/rthread.py b/rpython/rlib/rthread.py --- a/rpython/rlib/rthread.py +++ b/rpython/rlib/rthread.py @@ -22,6 +22,16 @@ include_dirs = [translator_c_dir], ) +class CConfig: + _compilation_info_ = eci + RPYTHREAD_NAME = rffi_platform.DefinedConstantString('RPYTHREAD_NAME') + USE_SEMAPHORES = rffi_platform.Defined('USE_SEMAPHORES') + CS_GNU_LIBPTHREAD_VERSION = rffi_platform.DefinedConstantInteger( + '_CS_GNU_LIBPTHREAD_VERSION') +cconfig = rffi_platform.configure(CConfig) +globals().update(cconfig) + + def llexternal(name, args, result, **kwds): kwds.setdefault('sandboxsafe', True) return rffi.llexternal(name, args, result, compilation_info=eci, diff --git a/rpython/translator/c/src/thread.h b/rpython/translator/c/src/thread.h --- a/rpython/translator/c/src/thread.h +++ b/rpython/translator/c/src/thread.h @@ -12,6 +12,7 @@ } RPyLockStatus; #ifdef _WIN32 +#define RPYTHREAD_NAME "nt" #include "thread_nt.h" #define inline _inline #else @@ -22,6 +23,7 @@ always go ahead and use them, assuming they are supported on all platforms for which we care. If not, do some detecting again. */ +#define RPYTHREAD_NAME "pthread" #include "thread_pthread.h" #endif /* !_WIN32 */ _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit