Author: Carl Friedrich Bolz <cfb...@gmx.de> Branch: value-profiling Changeset: r78959:72c1b4d38529 Date: 2015-08-13 13:34 +0200 http://bitbucket.org/pypy/pypy/changeset/72c1b4d38529/
Log: merge default diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst --- a/pypy/doc/whatsnew-head.rst +++ b/pypy/doc/whatsnew-head.rst @@ -63,3 +63,6 @@ .. branch: fix-tinylang-goals Update tinylang goals to match current rpython + +.. branch: vmprof-review + diff --git a/pypy/module/micronumpy/descriptor.py b/pypy/module/micronumpy/descriptor.py --- a/pypy/module/micronumpy/descriptor.py +++ b/pypy/module/micronumpy/descriptor.py @@ -588,7 +588,8 @@ return space.newtuple([w_class, builder_args, data]) def descr_setstate(self, space, w_data): - if self.fields is None: # if builtin dtype + if self.fields is None and not isinstance(self.itemtype, types.VoidType): + # if builtin dtype (but not w_voiddtype) return space.w_None version = space.int_w(space.getitem(w_data, space.wrap(0))) diff --git a/pypy/module/micronumpy/test/test_dtypes.py b/pypy/module/micronumpy/test/test_dtypes.py --- a/pypy/module/micronumpy/test/test_dtypes.py +++ b/pypy/module/micronumpy/test/test_dtypes.py @@ -350,8 +350,8 @@ assert np.dtype(xyz).name == 'xyz' # another obscure API, used in numpy record.py # it seems numpy throws away the subclass type and parses the spec - a = np.dtype((xyz, [('x', int), ('y', float)])) - assert repr(a) == "dtype([('x', '<i8'), ('y', '<f8')])" + a = np.dtype((xyz, [('x', 'int32'), ('y', 'float32')])) + assert repr(a) == "dtype([('x', '<i4'), ('y', '<f4')])" def test_index(self): import numpy as np diff --git a/pypy/module/micronumpy/test/test_ndarray.py b/pypy/module/micronumpy/test/test_ndarray.py --- a/pypy/module/micronumpy/test/test_ndarray.py +++ b/pypy/module/micronumpy/test/test_ndarray.py @@ -3808,7 +3808,7 @@ assert (a == [1, 2]).all() def test_pickle(self): - from numpy import dtype, array + from numpy import dtype, array, int32 from cPickle import loads, dumps d = dtype([('x', str), ('y', 'int32')]) @@ -3825,6 +3825,11 @@ assert a[0]['y'] == 2 assert a[1]['y'] == 1 + + a = array([(1, [])], dtype=[('a', int32), ('b', int32, 0)]) + assert a['b'].shape == (1, 0) + b = loads(dumps(a)) + assert b['b'].shape == (1, 0) def test_subarrays(self): from numpy import dtype, array, zeros diff --git a/rpython/rlib/rvmprof/cintf.py b/rpython/rlib/rvmprof/cintf.py --- a/rpython/rlib/rvmprof/cintf.py +++ b/rpython/rlib/rvmprof/cintf.py @@ -6,54 +6,69 @@ from rpython.rtyper.tool import rffi_platform as platform from rpython.jit.backend import detect_cpu -if not detect_cpu.autodetect().startswith(detect_cpu.MODEL_X86_64): - py.test.skip("rvmprof only supports x86-64 CPUs for now") +class VMProfPlatformUnsupported(Exception): + pass -ROOT = py.path.local(__file__).join('..') -SRC = ROOT.join('src') +def setup(): + if not detect_cpu.autodetect().startswith(detect_cpu.MODEL_X86_64): + raise VMProfPlatformUnsupported("rvmprof only supports" + " x86-64 CPUs for now") -if sys.platform.startswith('linux'): - libs = ['dl'] -else: - libs = [] + ROOT = py.path.local(__file__).join('..') + SRC = ROOT.join('src') -eci_kwds = dict( - include_dirs = [SRC], - includes = ['rvmprof.h'], - libraries = libs, - separate_module_files = [SRC.join('rvmprof.c')], - post_include_bits=['#define RPYTHON_VMPROF\n'], - ) -eci = ExternalCompilationInfo(**eci_kwds) -platform.verify_eci(ExternalCompilationInfo( - compile_extra=['-DRPYTHON_LL2CTYPES'], - **eci_kwds)) + if sys.platform.startswith('linux'): + libs = ['dl'] + else: + libs = [] + eci_kwds = dict( + include_dirs = [SRC], + includes = ['rvmprof.h'], + libraries = libs, + separate_module_files = [SRC.join('rvmprof.c')], + post_include_bits=['#define RPYTHON_VMPROF\n'], + ) + eci = ExternalCompilationInfo(**eci_kwds) -vmprof_init = rffi.llexternal("rpython_vmprof_init", [rffi.INT], rffi.CCHARP, - compilation_info=eci) -vmprof_enable = rffi.llexternal("rpython_vmprof_enable", [rffi.LONG], rffi.INT, - compilation_info=eci, - save_err=rffi.RFFI_SAVE_ERRNO) -vmprof_disable = rffi.llexternal("rpython_vmprof_disable", [], rffi.INT, - compilation_info=eci, - save_err=rffi.RFFI_SAVE_ERRNO) -vmprof_write_buf = rffi.llexternal("rpython_vmprof_write_buf", - [rffi.CCHARP, rffi.LONG], - lltype.Void, compilation_info=eci) + platform.verify_eci(ExternalCompilationInfo( + compile_extra=['-DRPYTHON_LL2CTYPES'], + **eci_kwds)) -## vmprof_register_virtual_function = rffi.llexternal( -## "vmprof_register_virtual_function", -## [rffi.CCHARP, rffi.VOIDP, rffi.VOIDP], lltype.Void, -## compilation_info=eci, _nowrapper=True) -vmprof_ignore_signals = rffi.llexternal("rpython_vmprof_ignore_signals", - [rffi.INT], lltype.Void, - compilation_info=eci) + vmprof_init = rffi.llexternal("rpython_vmprof_init", [rffi.INT], rffi.CCHARP, + compilation_info=eci) + vmprof_enable = rffi.llexternal("rpython_vmprof_enable", [rffi.LONG], rffi.INT, + compilation_info=eci, + save_err=rffi.RFFI_SAVE_ERRNO) + vmprof_disable = rffi.llexternal("rpython_vmprof_disable", [], rffi.INT, + compilation_info=eci, + save_err=rffi.RFFI_SAVE_ERRNO) + vmprof_write_buf = rffi.llexternal("rpython_vmprof_write_buf", + [rffi.CCHARP, rffi.LONG], + lltype.Void, compilation_info=eci) + ## vmprof_register_virtual_function = rffi.llexternal( + ## "vmprof_register_virtual_function", + ## [rffi.CCHARP, rffi.VOIDP, rffi.VOIDP], lltype.Void, + ## compilation_info=eci, _nowrapper=True) + + vmprof_ignore_signals = rffi.llexternal("rpython_vmprof_ignore_signals", + [rffi.INT], lltype.Void, + compilation_info=eci) + return CInterface(locals()) + + +class CInterface(object): + def __init__(self, namespace): + for k, v in namespace.iteritems(): + setattr(self, k, v) + + def _freeze_(self): + return True def token2lltype(tok): if tok == 'i': diff --git a/rpython/rlib/rvmprof/rvmprof.py b/rpython/rlib/rvmprof/rvmprof.py --- a/rpython/rlib/rvmprof/rvmprof.py +++ b/rpython/rlib/rvmprof/rvmprof.py @@ -19,7 +19,6 @@ def __str__(self): return self.msg - class VMProf(object): def __init__(self): @@ -31,6 +30,7 @@ self._code_unique_id = 0 # XXX this is wrong, it won't work on 32bit else: self._code_unique_id = 0x7000000000000000 + self.cintf = cintf.setup() def _cleanup_(self): self.is_enabled = False @@ -106,14 +106,14 @@ raise VMProfError("bad value for 'interval'") interval_usec = int(interval * 1000000.0) - p_error = cintf.vmprof_init(fileno) + p_error = self.cintf.vmprof_init(fileno) if p_error: raise VMProfError(rffi.charp2str(p_error)) self.fileno = fileno self._write_header(interval_usec) self._gather_all_code_objs() - res = cintf.vmprof_enable(interval_usec) + res = self.cintf.vmprof_enable(interval_usec) if res < 0: raise VMProfError(os.strerror(rposix.get_saved_errno())) self.is_enabled = True @@ -128,7 +128,7 @@ if self._current_codes is not None: self._flush_codes() self.fileno = -1 - res = cintf.vmprof_disable() + res = self.cintf.vmprof_disable() if res < 0: raise VMProfError(os.strerror(rposix.get_saved_errno())) @@ -149,7 +149,7 @@ def _flush_codes(self): buf = self._current_codes.build() self._current_codes = None - cintf.vmprof_write_buf(buf, len(buf)) + self.cintf.vmprof_write_buf(buf, len(buf)) # NOTE: keep in mind that vmprof_write_buf() can only write # a maximum of 8184 bytes. This should be guaranteed here because: assert MAX_CODES + 17 + MAX_FUNC_NAME <= 8184 @@ -165,7 +165,7 @@ b.append(chr(len('pypy'))) b.append('pypy') buf = b.build() - cintf.vmprof_write_buf(buf, len(buf)) + self.cintf.vmprof_write_buf(buf, len(buf)) def _write_long_to_string_builder(l, b): diff --git a/rpython/rtyper/rpbc.py b/rpython/rtyper/rpbc.py --- a/rpython/rtyper/rpbc.py +++ b/rpython/rtyper/rpbc.py @@ -750,6 +750,10 @@ def get_ll_eq_function(self): return None + def ll_str(self, ptr): + cls = lltype.cast_pointer(CLASSTYPE, ptr) + return cls.name + def ll_cls_hash(cls): if not cls: diff --git a/rpython/rtyper/test/test_rpbc.py b/rpython/rtyper/test/test_rpbc.py --- a/rpython/rtyper/test/test_rpbc.py +++ b/rpython/rtyper/test/test_rpbc.py @@ -1656,6 +1656,20 @@ res = self.interpret(g, [2]) assert self.ll_to_string(res) == "ASub" + def test_str_class(self): + class Base(object): pass + class ASub(Base): pass + def g(n): + if n == 1: + x = Base() + else: + x = ASub() + return str(x.__class__) + res = self.interpret(g, [1]) + assert self.ll_to_string(res) == "Base" + res = self.interpret(g, [2]) + assert self.ll_to_string(res) == "ASub" + def test_bug_callfamily(self): def cb1(): xxx # never actually called _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit