Author: Philip Jenvey <pjen...@underboss.org> Branch: py3k Changeset: r64292:f05520ba4cf5 Date: 2013-05-18 13:49 -0700 http://bitbucket.org/pypy/pypy/changeset/f05520ba4cf5/
Log: merge default diff --git a/pypy/goal/targetpypystandalone.py b/pypy/goal/targetpypystandalone.py --- a/pypy/goal/targetpypystandalone.py +++ b/pypy/goal/targetpypystandalone.py @@ -11,6 +11,8 @@ from rpython.rlib import rlocale from pypy.tool.option import make_objspace from pypy.conftest import pypydir +from rpython.rlib import rthread +from pypy.module.thread import os_thread thisdir = py.path.local(__file__).dirpath() @@ -124,6 +126,15 @@ source = rffi.charp2str(ll_source) return _pypy_execute_source(source) + @entrypoint('main', [], c_name='pypy_init_threads') + def pypy_init_threads(): + os_thread.setup_threads(space) + rffi.aroundstate.before() + + @entrypoint('main', [], c_name='pypy_thread_attach') + def pypy_thread_attach(): + rthread.gc_thread_start() + w_globals = space.newdict() space.setitem(w_globals, space.wrap('__builtins__'), space.builtin_modules['builtins']) @@ -141,6 +152,8 @@ return 0 return entry_point, {'pypy_execute_source': pypy_execute_source, + 'pypy_init_threads': pypy_init_threads, + 'pypy_thread_attach': pypy_thread_attach, 'pypy_setup_home': pypy_setup_home} def call_finish(space): diff --git a/pypy/objspace/std/dictmultiobject.py b/pypy/objspace/std/dictmultiobject.py --- a/pypy/objspace/std/dictmultiobject.py +++ b/pypy/objspace/std/dictmultiobject.py @@ -9,7 +9,7 @@ from rpython.rlib import jit, rerased from rpython.rlib.debug import mark_dict_non_null from rpython.rlib.objectmodel import newlist_hint, r_dict, specialize -from rpython.tool.sourcetools import func_with_new_name +from rpython.tool.sourcetools import func_renamer, func_with_new_name UNROLL_CUTOFF = 5 @@ -1257,47 +1257,87 @@ return space.wrap("%s(%s)" % (space.type(self).getname(space), space.str_w(w_repr))) - def descr_eq(self, space, w_otherview): - if not space.eq_w(space.len(self), space.len(w_otherview)): - return space.w_False - - w_iter = space.iter(self) - while True: - try: - w_item = space.next(w_iter) - except OperationError, e: - if not e.match(space, space.w_StopIteration): - raise - break - if not space.is_true(space.contains(w_otherview, w_item)): - return space.w_False - return space.w_True - def descr_len(self, space): return space.len(self.w_dict) +def _all_contained_in(space, w_dictview, w_other): + w_iter = space.iter(w_dictview) + while True: + try: + w_item = space.next(w_iter) + except OperationError, e: + if not e.match(space, space.w_StopIteration): + raise + break + if not space.is_true(space.contains(w_other, w_item)): + return space.w_False + return space.w_True + +def _is_set_like(w_other): + from pypy.objspace.std.setobject import W_BaseSetObject + return (isinstance(w_other, W_BaseSetObject) or + isinstance(w_other, SetLikeDictView)) + class SetLikeDictView(object): _mixin_ = True - def descr_sub(self, space, w_otherview): - w_set = space.call_function(space.w_set, self) - space.call_method(w_set, "difference_update", w_otherview) - return w_set + def descr_eq(self, space, w_other): + if not _is_set_like(w_other): + return space.w_NotImplemented + if space.len_w(self) == space.len_w(w_other): + return _all_contained_in(space, self, w_other) + return space.w_False - def descr_and(self, space, w_otherview): - w_set = space.call_function(space.w_set, self) - space.call_method(w_set, "intersection_update", w_otherview) - return w_set + def descr_ne(self, space, w_other): + if not _is_set_like(w_other): + return space.w_NotImplemented + return space.not_(space.eq(self, w_other)) - def descr_or(self, space, w_otherview): - w_set = space.call_function(space.w_set, self) - space.call_method(w_set, "update", w_otherview) - return w_set + def descr_lt(self, space, w_other): + if not _is_set_like(w_other): + return space.w_NotImplemented + if space.len_w(self) < space.len_w(w_other): + return _all_contained_in(space, self, w_other) + return space.w_False - def descr_xor(self, space, w_otherview): - w_set = space.call_function(space.w_set, self) - space.call_method(w_set, "symmetric_difference_update", w_otherview) - return w_set + def descr_le(self, space, w_other): + if not _is_set_like(w_other): + return space.w_NotImplemented + if space.len_w(self) <= space.len_w(w_other): + return _all_contained_in(space, self, w_other) + return space.w_False + + def descr_gt(self, space, w_other): + if not _is_set_like(w_other): + return space.w_NotImplemented + if space.len_w(self) > space.len_w(w_other): + return _all_contained_in(space, w_other, self) + return space.w_False + + def descr_ge(self, space, w_other): + if not _is_set_like(w_other): + return space.w_NotImplemented + if space.len_w(self) >= space.len_w(w_other): + return _all_contained_in(space, w_other, self) + return space.w_False + + def _as_set_op(name, methname): + @func_renamer('descr_' + name) + def op(self, space, w_other): + w_set = space.call_function(space.w_set, self) + space.call_method(w_set, methname, w_other) + return w_set + @func_renamer('descr_r' + name) + def rop(self, space, w_other): + w_set = space.call_function(space.w_set, w_other) + space.call_method(w_set, methname, self) + return w_set + return op, rop + + descr_sub, descr_rsub = _as_set_op('sub', 'difference_update') + descr_and, descr_rand = _as_set_op('and', 'intersection_update') + descr_or, descr_ror = _as_set_op('or', 'update') + descr_xor, descr_rxor = _as_set_op('xor', 'symmetric_difference_update') class W_DictViewItemsObject(W_DictViewObject, SetLikeDictView): def descr_iter(self, space): @@ -1314,31 +1354,52 @@ W_DictViewItemsObject.typedef = StdTypeDef( "dict_items", __repr__ = interp2app(W_DictViewItemsObject.descr_repr), - __eq__ = interp2app(W_DictViewItemsObject.descr_eq), __len__ = interp2app(W_DictViewItemsObject.descr_len), __iter__ = interp2app(W_DictViewItemsObject.descr_iter), + + __eq__ = interp2app(W_DictViewItemsObject.descr_eq), + __ne__ = interp2app(W_DictViewItemsObject.descr_ne), + __lt__ = interp2app(W_DictViewItemsObject.descr_lt), + __le__ = interp2app(W_DictViewItemsObject.descr_le), + __gt__ = interp2app(W_DictViewItemsObject.descr_gt), + __ge__ = interp2app(W_DictViewItemsObject.descr_ge), + __sub__ = interp2app(W_DictViewItemsObject.descr_sub), + __rsub__ = interp2app(W_DictViewItemsObject.descr_rsub), __and__ = interp2app(W_DictViewItemsObject.descr_and), + __rand__ = interp2app(W_DictViewItemsObject.descr_rand), __or__ = interp2app(W_DictViewItemsObject.descr_or), - __xor__ = interp2app(W_DictViewItemsObject.descr_xor) + __ror__ = interp2app(W_DictViewItemsObject.descr_ror), + __xor__ = interp2app(W_DictViewItemsObject.descr_xor), + __rxor__ = interp2app(W_DictViewItemsObject.descr_rxor), ) W_DictViewKeysObject.typedef = StdTypeDef( "dict_keys", __repr__ = interp2app(W_DictViewKeysObject.descr_repr), - __eq__ = interp2app(W_DictViewKeysObject.descr_eq), __len__ = interp2app(W_DictViewKeysObject.descr_len), __iter__ = interp2app(W_DictViewKeysObject.descr_iter), + + __eq__ = interp2app(W_DictViewKeysObject.descr_eq), + __ne__ = interp2app(W_DictViewKeysObject.descr_ne), + __lt__ = interp2app(W_DictViewKeysObject.descr_lt), + __le__ = interp2app(W_DictViewKeysObject.descr_le), + __gt__ = interp2app(W_DictViewKeysObject.descr_gt), + __ge__ = interp2app(W_DictViewKeysObject.descr_ge), + __sub__ = interp2app(W_DictViewKeysObject.descr_sub), + __rsub__ = interp2app(W_DictViewKeysObject.descr_rsub), __and__ = interp2app(W_DictViewKeysObject.descr_and), + __rand__ = interp2app(W_DictViewKeysObject.descr_rand), __or__ = interp2app(W_DictViewKeysObject.descr_or), - __xor__ = interp2app(W_DictViewKeysObject.descr_xor) + __ror__ = interp2app(W_DictViewKeysObject.descr_ror), + __xor__ = interp2app(W_DictViewKeysObject.descr_xor), + __rxor__ = interp2app(W_DictViewKeysObject.descr_rxor), ) W_DictViewValuesObject.typedef = StdTypeDef( "dict_values", __repr__ = interp2app(W_DictViewValuesObject.descr_repr), - __eq__ = interp2app(W_DictViewValuesObject.descr_eq), __len__ = interp2app(W_DictViewValuesObject.descr_len), __iter__ = interp2app(W_DictViewValuesObject.descr_iter), ) diff --git a/pypy/objspace/std/test/test_dictmultiobject.py b/pypy/objspace/std/test/test_dictmultiobject.py --- a/pypy/objspace/std/test/test_dictmultiobject.py +++ b/pypy/objspace/std/test/test_dictmultiobject.py @@ -681,6 +681,7 @@ assert keys != set([1, "b"]) assert keys != set([1]) assert keys != 42 + assert not keys == 42 assert 1 in keys assert "a" in keys assert 10 not in keys @@ -702,6 +703,7 @@ assert items != set([(1, 10), ("a", "def")]) assert items != set([(1, 10)]) assert items != 42 + assert not items == 42 assert (1, 10) in items assert ("a", "ABC") in items assert (1, 11) not in items @@ -726,6 +728,7 @@ values = d.values() assert set(values) == set([10, "ABC"]) assert len(values) == 2 + assert not values == 42 def test_dict_repr(self): d = {1: 10, "a": "ABC"} @@ -892,7 +895,7 @@ assert not frozenset({(1, 'a'), (2, 'b'), (3, 'c')}) != d.items() """ - def test_dictviewset_unshasable_values(self): + def test_dictviewset_unhashable_values(self): class C: def __eq__(self, other): return True diff --git a/rpython/memory/gc/env.py b/rpython/memory/gc/env.py --- a/rpython/memory/gc/env.py +++ b/rpython/memory/gc/env.py @@ -1,9 +1,10 @@ """ Utilities to get environ variables and platform-specific memory-related values. """ -import os, sys +import os, sys, platform from rpython.rlib.rarithmetic import r_uint from rpython.rlib.debug import debug_print, debug_start, debug_stop +from rpython.rlib.rstring import assert_str0 from rpython.rtyper.lltypesystem import lltype, rffi from rpython.rtyper.lltypesystem.lloperation import llop @@ -130,7 +131,22 @@ # ---------- Linux2 ---------- -def get_L2cache_linux2(filename="/proc/cpuinfo"): +def get_L2cache_linux2(): + arch = platform.machine() + if arch.endswith('86') or arch == 'x86_64': + return get_L2cache_linux2_cpuinfo() + if arch in ('alpha', 'ppc', 'ppc64'): + return get_L2cache_linux2_cpuinfo(label='L2 cache') + if arch == 'ia64': + return get_L2cache_linux2_ia64() + if arch in ('parisc', 'parisc64'): + return get_L2cache_linux2_cpuinfo(label='D-cache') + if arch in ('sparc', 'sparc64'): + return get_L2cache_linux2_sparc() + return -1 + + +def get_L2cache_linux2_cpuinfo(filename="/proc/cpuinfo", label='cache size'): debug_start("gc-hardware") L2cache = sys.maxint try: @@ -149,12 +165,8 @@ else: data = ''.join(data) linepos = 0 - # Currently on ARM-linux we won't find any information about caches in - # cpuinfo - if _detect_arm_cpu(data): - return -1 while True: - start = _findend(data, '\ncache size', linepos) + start = _findend(data, '\n' + label, linepos) if start < 0: break # done linepos = _findend(data, '\n', start) @@ -194,6 +206,104 @@ "Warning: cannot find your CPU L2 cache size in /proc/cpuinfo") return -1 +def get_L2cache_linux2_sparc(): + debug_start("gc-hardware") + cpu = 0 + L2cache = sys.maxint + while True: + try: + fd = os.open('/sys/devices/system/cpu/cpu' + assert_str0(str(cpu)) + + '/l2_cache_size', os.O_RDONLY, 0644) + try: + number = int(os.read(fd, 4096)) + finally: + os.close(fd) + except OSError: + break + if number < L2cache: + L2cache = number + cpu += 1 + + debug_print("L2cache =", L2cache) + debug_stop("gc-hardware") + if L2cache < sys.maxint: + return L2cache + else: + # Print a top-level warning even in non-debug builds + llop.debug_print(lltype.Void, + "Warning: cannot find your CPU L2 cache size in " + "/sys/devices/system/cpu/cpuX/l2_cache_size") + return -1 + +def get_L2cache_linux2_ia64(): + debug_start("gc-hardware") + cpu = 0 + L2cache = sys.maxint + L3cache = sys.maxint + while True: + cpudir = '/sys/devices/system/cpu/cpu' + assert_str0(str(cpu)) + index = 0 + while True: + cachedir = cpudir + '/cache/index' + assert_str0(str(index)) + try: + fd = os.open(cachedir + '/level', os.O_RDONLY, 0644) + try: + level = int(os.read(fd, 4096)[:-1]) + finally: + os.close(fd) + except OSError: + break + if level not in (2, 3): + index += 1 + continue + try: + fd = os.open(cachedir + '/size', os.O_RDONLY, 0644) + try: + data = os.read(fd, 4096) + finally: + os.close(fd) + except OSError: + break + + end = 0 + while '0' <= data[end] <= '9': + end += 1 + if end == 0: + index += 1 + continue + if data[end] not in ('K', 'k'): # assume kilobytes for now + index += 1 + continue + + number = int(data[:end]) + number *= 1024 + + if level == 2: + if number < L2cache: + L2cache = number + if level == 3: + if number < L3cache: + L3cache = number + + index += 1 + + if index == 0: + break + cpu += 1 + + mangled = L2cache + L3cache + debug_print("L2cache =", mangled) + debug_stop("gc-hardware") + if mangled > 0: + return mangled + else: + # Print a top-level warning even in non-debug builds + llop.debug_print(lltype.Void, + "Warning: cannot find your CPU L2 & L3 cache size in " + "/sys/devices/system/cpu/cpuX/cache") + return -1 + + def _findend(data, pattern, pos): pos = data.find(pattern, pos) if pos < 0: @@ -205,11 +315,6 @@ pos += 1 return pos -def _detect_arm_cpu(data): - # check for the presence of a 'Processor' entry - p = _findend(data, 'Processor', 0) - return p >= 0 and _findend(data, 'ARMv', p) > 0 - # ---------- Darwin ---------- sysctlbyname = rffi.llexternal('sysctlbyname', diff --git a/rpython/memory/gc/test/test_env.py b/rpython/memory/gc/test/test_env.py --- a/rpython/memory/gc/test/test_env.py +++ b/rpython/memory/gc/test/test_env.py @@ -159,25 +159,9 @@ fpu : yes etc. """) - result = env.get_L2cache_linux2(str(filepath)) + result = env.get_L2cache_linux2_cpuinfo(str(filepath)) assert result == 3072 * 1024 def test_estimate_best_nursery_size_linux2_arm(): - filepath = udir.join('estimate_best_nursery_size_linux2') - filepath.write("""\ -Processor : ARMv6-compatible processor rev 7 (v6l) -# this is not actually from cpuinfo, but here for the test -cache size : 3072 KB -... -""") - result = env.get_L2cache_linux2(str(filepath)) + result = env.get_L2cache_linux2() assert result == -1 - -def test__detect_arm(): - assert env._detect_arm_cpu("Processor : ARMv6-compatible processor rev 7 (v6l)") - assert not env._detect_arm_cpu("""\ -processor : 0 -vendor_id : GenuineIntel -cpu family : 6 -model : 37 -""") diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py --- a/rpython/rlib/rbigint.py +++ b/rpython/rlib/rbigint.py @@ -447,11 +447,11 @@ @jit.elidable def repr(self): - return _format(self, BASE10, '', 'L') + return _format_decimal(self, addL=True) @jit.elidable def str(self): - return _format(self, BASE10) + return _format_decimal(self) @jit.elidable def eq(self, other): @@ -2101,6 +2101,101 @@ return ''.join(s[p:]) +DECIMAL_SHIFT = 0 # computed as max(E such that 10**E fits in a digit) +while 10 ** (DECIMAL_SHIFT + 1) <= 2 ** SHIFT: + DECIMAL_SHIFT += 1 +DECIMAL_BASE = 10 ** DECIMAL_SHIFT + +# an RPython trick: this creates a nested sequence of calls that are +# all inlined into each other, making an unrolled loop. Moreover the +# calls are done in the "wrong" order to be written as a regular loop: +# the first digit that is append-ed to the builder is the most +# significant one (corresponding to the innermost call). +_succ = specialize.memo()(lambda n: n + 1) +@specialize.arg(3) +def _add_decimal_digits(builder, value, ndigits, digit_index=1): + assert value >= 0 + if digit_index < ndigits: + assert digit_index < DECIMAL_SHIFT + _add_decimal_digits(builder, value // 10, ndigits, _succ(digit_index)) + builder.append(chr(ord('0') + value % 10)) + else: + assert value < 10 + builder.append(chr(ord('0') + value)) +_add_decimal_digits._always_inline_ = True + + +def _format_decimal(a, addL=False): + """ Optimized version of _format(a, BASE10, '', 'L' if addL else ''). """ + if a.sign == 0: + if addL: + return "0L" + else: + return "0" + + size_a = a.numdigits() + negative = a.sign < 0 + + # quick and dirty upper bound for the number of digits + # required to express a in base DECIMAL_BASE: + # + # #digits = 1 + floor(log2(a) / log2(DECIMAL_BASE)) + # + # But log2(a) < size_a * PyLong_SHIFT, and + # log2(DECIMAL_BASE) = log2(10) * DECIMAL_SHIFT + # > 3 * DECIMAL_SHIFT + + size = 1 + size_a * SHIFT // (3 * DECIMAL_SHIFT) + pout = [NULLDIGIT] * size + + # convert array of base _PyLong_BASE digits in pin to an array of + # base _PyLong_DECIMAL_BASE digits in pout, following Knuth (TAOCP, + # Volume 2 (3rd edn), section 4.4, Method 1b). + size = 0 + for i in range(size_a-1, -1, -1): + hi = a.digit(i) + for j in range(size): + z = (_widen_digit(pout[j]) << SHIFT) | hi + hi = _store_digit(z // DECIMAL_BASE) + pout[j] = _store_digit(z - _widen_digit(hi) * DECIMAL_BASE) + assert hi >= 0 + while hi: + pout[size] = hi % DECIMAL_BASE + hi //= DECIMAL_BASE + size += 1 + sizem1 = size - 1 + assert sizem1 >= 0 + + # calculate exact length of output string, and allocate + decimal_digits_in_last_part = 1 + rem = pout[sizem1] + tenpow = 10 + while rem >= tenpow: + tenpow *= 10 + decimal_digits_in_last_part += 1 + strlen = (addL + negative + + decimal_digits_in_last_part + (sizem1) * DECIMAL_SHIFT) + + builder = StringBuilder(strlen) + + # start with the negative sign, if needed + if negative: + builder.append('-') + + # pout[size-1] produces 'decimal_digits_in_last_part' digits. + # Then the remaining pout[size-2] through pout[0] contribute exactly + # DECIMAL_SHIFT digits each. + decimal_digits = decimal_digits_in_last_part + for i in range(sizem1, -1, -1): + _add_decimal_digits(builder, pout[i], decimal_digits) + decimal_digits = DECIMAL_SHIFT + + # done + if addL: + builder.append('L') + return builder.build() + + def _bitwise(a, op, b): # '&', '|', '^' """ Bitwise and/or/xor operations """ diff --git a/rpython/translator/platform/freebsd.py b/rpython/translator/platform/freebsd.py --- a/rpython/translator/platform/freebsd.py +++ b/rpython/translator/platform/freebsd.py @@ -12,3 +12,11 @@ class Freebsd_64(Freebsd): shared_only = ('-fPIC',) + +class GNUkFreebsd(Freebsd): + DEFAULT_CC = 'cc' + extra_libs = ('-lrt',) + +class GNUkFreebsd_64(Freebsd_64): + DEFAULT_CC = 'cc' + extra_libs = ('-lrt',) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit