[pypy-commit] pypy default: Cast these fields to a Python-level 'int', i.e. a C 'long'.
Author: Armin Rigo Branch: Changeset: r47101:9efba345739c Date: 2011-09-06 13:01 +0200 http://bitbucket.org/pypy/pypy/changeset/9efba345739c/ Log:Cast these fields to a Python-level 'int', i.e. a C 'long'. This is the same as CPython does. diff --git a/pypy/module/pwd/interp_pwd.py b/pypy/module/pwd/interp_pwd.py --- a/pypy/module/pwd/interp_pwd.py +++ b/pypy/module/pwd/interp_pwd.py @@ -3,6 +3,7 @@ from pypy.rpython.lltypesystem import rffi, lltype from pypy.interpreter.gateway import interp2app, unwrap_spec from pypy.interpreter.error import OperationError, operationerrfmt +from pypy.rlib.rarithmetic import intmask eci = ExternalCompilationInfo( includes=['pwd.h'] @@ -43,8 +44,8 @@ w_tuple = space.newtuple([ space.wrap(rffi.charp2str(pw.c_pw_name)), space.wrap(rffi.charp2str(pw.c_pw_passwd)), -space.wrap(pw.c_pw_uid), -space.wrap(pw.c_pw_gid), +space.wrap(intmask(pw.c_pw_uid)), +space.wrap(intmask(pw.c_pw_gid)), space.wrap(rffi.charp2str(pw.c_pw_gecos)), space.wrap(rffi.charp2str(pw.c_pw_dir)), space.wrap(rffi.charp2str(pw.c_pw_shell)), diff --git a/pypy/module/pwd/test/test_pwd.py b/pypy/module/pwd/test/test_pwd.py --- a/pypy/module/pwd/test/test_pwd.py +++ b/pypy/module/pwd/test/test_pwd.py @@ -14,6 +14,9 @@ assert pw.pw_gid == 0 assert pw.pw_dir == '/root' assert pw.pw_shell.startswith('/') +# +assert type(pw.pw_uid) is int +assert type(pw.pw_gid) is int def test_getpwnam(self): import pwd ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Fix this test on 64-bit: avoids that random unrelated operations
Author: Armin Rigo Branch: Changeset: r47102:a41ea5a18e1c Date: 2011-09-06 13:36 +0200 http://bitbucket.org/pypy/pypy/changeset/a41ea5a18e1c/ Log:Fix this test on 64-bit: avoids that random unrelated operations show up here, by adding a dummy getattr previously in the loop. diff --git a/pypy/module/pypyjit/test_pypy_c/test_instance.py b/pypy/module/pypyjit/test_pypy_c/test_instance.py --- a/pypy/module/pypyjit/test_pypy_c/test_instance.py +++ b/pypy/module/pypyjit/test_pypy_c/test_instance.py @@ -142,6 +142,7 @@ i = 0 b = B(1) while i < 100: +b.x v = b.x # ID: loadattr i += v return i @@ -150,8 +151,6 @@ loop, = log.loops_by_filename(self.filepath) assert loop.match_by_id('loadattr', ''' -guard_not_invalidated(descr=...) -i16 = arraylen_gc(p10, descr=) i19 = call(ConstClass(ll_dict_lookup), _, _, _, descr=...) guard_no_exception(descr=...) i21 = int_and(i19, _) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Python 2.5 compatibility.
Author: Armin Rigo Branch: Changeset: r47104:572d0576c166 Date: 2011-09-06 17:26 +0200 http://bitbucket.org/pypy/pypy/changeset/572d0576c166/ Log:Python 2.5 compatibility. diff --git a/pypy/module/pypyjit/test_pypy_c/model.py b/pypy/module/pypyjit/test_pypy_c/model.py --- a/pypy/module/pypyjit/test_pypy_c/model.py +++ b/pypy/module/pypyjit/test_pypy_c/model.py @@ -2,7 +2,10 @@ import sys import re import os.path -from _pytest.assertion import newinterpret +try: +from _pytest.assertion import newinterpret +except ImportError: # e.g. Python 2.5 +newinterpret = None from pypy.tool.jitlogparser.parser import SimpleParser, Function, TraceForOpcode from pypy.tool.jitlogparser.storage import LoopStorage @@ -196,7 +199,7 @@ source = str(source.deindent()).strip() except py.error.ENOENT: source = None -if source and source.startswith('self._assert('): +if source and source.startswith('self._assert(') and newinterpret: # transform self._assert(x, 'foo') into assert x, 'foo' source = source.replace('self._assert(', 'assert ') source = source[:-1] # remove the trailing ')' diff --git a/pypy/module/pypyjit/test_pypy_c/test_00_model.py b/pypy/module/pypyjit/test_pypy_c/test_00_model.py --- a/pypy/module/pypyjit/test_pypy_c/test_00_model.py +++ b/pypy/module/pypyjit/test_pypy_c/test_00_model.py @@ -1,3 +1,4 @@ +from __future__ import with_statement import sys import types import subprocess ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Store the failargs too. Not used right now.
Author: Armin Rigo Branch: Changeset: r47103:862346e1db81 Date: 2011-09-06 17:26 +0200 http://bitbucket.org/pypy/pypy/changeset/862346e1db81/ Log:Store the failargs too. Not used right now. diff --git a/pypy/tool/jitlogparser/parser.py b/pypy/tool/jitlogparser/parser.py --- a/pypy/tool/jitlogparser/parser.py +++ b/pypy/tool/jitlogparser/parser.py @@ -8,6 +8,7 @@ bridge = None offset = None asm = None +failargs = () def __init__(self, name, args, res, descr): self.name = name @@ -18,8 +19,8 @@ if self._is_guard: self.guard_no = int(self.descr[len('http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy gc-trace-faster: Attempt to reduce calls to trace_and_drag_out_of_nursery_partial. Not as effective as hoped, but still gives some improvement.
Author: Justin Peel Branch: gc-trace-faster Changeset: r47105:2f505084ea21 Date: 2011-09-06 09:38 -0600 http://bitbucket.org/pypy/pypy/changeset/2f505084ea21/ Log:Attempt to reduce calls to trace_and_drag_out_of_nursery_partial. Not as effective as hoped, but still gives some improvement. diff --git a/pypy/rpython/memory/gc/minimark.py b/pypy/rpython/memory/gc/minimark.py --- a/pypy/rpython/memory/gc/minimark.py +++ b/pypy/rpython/memory/gc/minimark.py @@ -1334,8 +1334,47 @@ while bytes > 0: p -= 1 cardbyte = ord(p.char[0]) +bytes -= 1 +if cardbyte == 0: +# keep moving along while there are unmarked bytes +if bytes == 0: +break +p -= 1 +cardbyte = ord(p.char[0]) +bytes -= 1 +counter = 1 +while bytes > 0 and cardbyte == 0: +p -= 1 +cardbyte = ord(p.char[0]) +bytes -= 1 +counter += 1 +interval_start = interval_start + counter*8*self.card_page_indices +if cardbyte == 255 and bytes > 0: +# keep moving until we find a byte that isn't fully marked +p.char[0] = '\x00' +counter = 1 +p -= 1 +cardbyte = ord(p.char[0]) +bytes -= 1 +while bytes > 0 and cardbyte == 255: +p.char[0] = '\x00' +p -= 1 +cardbyte = ord(p.char[0]) +bytes -= 1 +counter += 1 +interval_stop = interval_start + counter*8*self.card_page_indices +if interval_stop > length: +interval_stop = length +ll_assert(bytes == 0, +"premature end of object") +if bool(self.young_rawmalloced_objects): + self.trace_and_drag_out_of_nursery_partial_young_raw( +obj, interval_start, interval_stop) +else: +self.trace_and_drag_out_of_nursery_partial( +obj, interval_start, interval_stop) +interval_start = interval_stop p.char[0] = '\x00' # reset the bits -bytes -= 1 next_byte_start = interval_start + 8*self.card_page_indices # while cardbyte != 0: ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy ffistruct: a branch to implement a JIT friendly struct type in _ffi
Author: Antonio Cuni Branch: ffistruct Changeset: r47106:8b5b5a7627cf Date: 2011-09-05 15:43 +0200 http://bitbucket.org/pypy/pypy/changeset/8b5b5a7627cf/ Log:a branch to implement a JIT friendly struct type in _ffi ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy ffistruct: implement FFIType.sizeof(); put some test logic into a base class
Author: Antonio Cuni Branch: ffistruct Changeset: r47107:318937fd8e2e Date: 2011-09-05 16:24 +0200 http://bitbucket.org/pypy/pypy/changeset/318937fd8e2e/ Log:implement FFIType.sizeof(); put some test logic into a base class diff --git a/pypy/module/_ffi/__init__.py b/pypy/module/_ffi/__init__.py --- a/pypy/module/_ffi/__init__.py +++ b/pypy/module/_ffi/__init__.py @@ -10,4 +10,7 @@ 'get_libc':'interp_ffi.get_libc', } -appleveldefs = {} +appleveldefs = { +'Structure': 'app_struct.Structure', +'Field': 'app_struct.Field', +} diff --git a/pypy/module/_ffi/interp_ffi.py b/pypy/module/_ffi/interp_ffi.py --- a/pypy/module/_ffi/interp_ffi.py +++ b/pypy/module/_ffi/interp_ffi.py @@ -30,6 +30,12 @@ return space.w_None return self.w_pointer_to +def descr_sizeof(self, space): +return space.wrap(self.sizeof()) + +def sizeof(self): +return intmask(self.ffitype.c_size) + def repr(self, space): return space.wrap(self.__repr__()) @@ -86,6 +92,7 @@ 'FFIType', __repr__ = interp2app(W_FFIType.repr), deref_pointer = interp2app(W_FFIType.descr_deref_pointer), +sizeof = interp2app(W_FFIType.descr_sizeof), ) diff --git a/pypy/module/_ffi/test/test__ffi.py b/pypy/module/_ffi/test/test__ffi.py --- a/pypy/module/_ffi/test/test__ffi.py +++ b/pypy/module/_ffi/test/test__ffi.py @@ -7,7 +7,7 @@ import os, sys, py -class AppTestFfi: +class BaseAppTestFFI(object): @classmethod def prepare_c_example(cls): @@ -36,7 +36,6 @@ eci = ExternalCompilationInfo(export_symbols=[]) return str(platform.compile([c_file], eci, 'x', standalone=False)) - def setup_class(cls): from pypy.rpython.lltypesystem import rffi from pypy.rlib.libffi import get_libc_name, CDLL, types @@ -52,7 +51,12 @@ pow = libm.getpointer('pow', [], types.void) pow_addr = rffi.cast(rffi.LONG, pow.funcsym) cls.w_pow_addr = space.wrap(pow_addr) -# + +class AppTestFFI(BaseAppTestFFI): + +def setup_class(cls): +BaseAppTestFFI.setup_class.im_func(cls) +space = cls.space # these are needed for test_single_float_args from ctypes import c_float f_12_34 = c_float(12.34).value @@ -82,7 +86,12 @@ from _ffi import types assert str(types.sint) == "" assert str(types.uint) == "" - + +def test_sizeof(self): +from _ffi import types +assert types.sbyte.sizeof() == 1 +assert types.sint.sizeof() == 4 + def test_callfunc(self): from _ffi import CDLL, types libm = CDLL(self.libm_name) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy ffistruct: start to implement _ffi.Structure
Author: Antonio Cuni Branch: ffistruct Changeset: r47108:6fe3c422d545 Date: 2011-09-05 16:37 +0200 http://bitbucket.org/pypy/pypy/changeset/6fe3c422d545/ Log:start to implement _ffi.Structure diff --git a/pypy/module/_ffi/app_struct.py b/pypy/module/_ffi/app_struct.py new file mode 100644 --- /dev/null +++ b/pypy/module/_ffi/app_struct.py @@ -0,0 +1,29 @@ +class Field(object): + +def __init__(self, name, ffitype): +self.name = name +self.ffitype = ffitype +self.offset = -1 + +class MetaStructure(type): + +def __new__(cls, name, bases, dic): +cls._compute_shape(dic) +return type.__new__(cls, name, bases, dic) + +@classmethod +def _compute_shape(cls, dic): +fields = dic.get('_fields_') +if fields is None: +return +size = 0 +for field in fields: +field.offset = size # XXX: alignment! +size += field.ffitype.sizeof() +dic[field.name] = field +dic['_size_'] = size + + +class Structure(object): + +__metaclass__ = MetaStructure diff --git a/pypy/module/_ffi/test/test_struct.py b/pypy/module/_ffi/test/test_struct.py new file mode 100644 --- /dev/null +++ b/pypy/module/_ffi/test/test_struct.py @@ -0,0 +1,19 @@ +from pypy.module._ffi.test.test__ffi import BaseAppTestFFI + +class AppTestStruct(BaseAppTestFFI): + +def test_compute_shape(self): +from _ffi import Structure, Field, types +class Point(Structure): +_fields_ = [ +Field('x', types.slong), +Field('y', types.slong), +] + +longsize = types.slong.sizeof() +assert isinstance(Point.x, Field) +assert isinstance(Point.y, Field) +assert Point.x.offset == 0 +assert Point.y.offset == longsize +assert Point._size_ == longsize*2 + ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy ffistruct: split the implementation/tests of W_FFIType and W_FuncPtr into two separate files
Author: Antonio Cuni Branch: ffistruct Changeset: r47109:edee74efbb9c Date: 2011-09-05 16:47 +0200 http://bitbucket.org/pypy/pypy/changeset/edee74efbb9c/ Log:split the implementation/tests of W_FFIType and W_FuncPtr into two separate files diff --git a/pypy/module/_ffi/__init__.py b/pypy/module/_ffi/__init__.py --- a/pypy/module/_ffi/__init__.py +++ b/pypy/module/_ffi/__init__.py @@ -1,13 +1,12 @@ from pypy.interpreter.mixedmodule import MixedModule -from pypy.module._ffi import interp_ffi class Module(MixedModule): interpleveldefs = { -'CDLL':'interp_ffi.W_CDLL', -'types': 'interp_ffi.W_types', -'FuncPtr': 'interp_ffi.W_FuncPtr', -'get_libc':'interp_ffi.get_libc', +'types': 'interp_ffitype.W_types', +'CDLL':'interp_funcptr.W_CDLL', +'FuncPtr': 'interp_funcptr.W_FuncPtr', +'get_libc':'interp_funcptr.get_libc', } appleveldefs = { diff --git a/pypy/module/_ffi/app_struct.py b/pypy/module/_ffi/app_struct.py --- a/pypy/module/_ffi/app_struct.py +++ b/pypy/module/_ffi/app_struct.py @@ -5,6 +5,15 @@ self.ffitype = ffitype self.offset = -1 +## def __get__(self, obj, cls=None): +## if obj is None: +## return self +## return getfield(obj._buffer, self.ffitype, self.offset) + +## def __set__(self, obj, value): +## setfield(obj._buffer, self.ffitype, self.offset, value) + + class MetaStructure(type): def __new__(cls, name, bases, dic): diff --git a/pypy/module/_ffi/interp_ffitype.py b/pypy/module/_ffi/interp_ffitype.py new file mode 100644 --- /dev/null +++ b/pypy/module/_ffi/interp_ffitype.py @@ -0,0 +1,156 @@ +from pypy.rlib import libffi +from pypy.rlib.rarithmetic import intmask +from pypy.interpreter.baseobjspace import Wrappable +from pypy.interpreter.typedef import TypeDef +from pypy.interpreter.gateway import interp2app + +class W_FFIType(Wrappable): + +_immutable_fields_ = ['name', 'ffitype', 'w_datashape', 'w_pointer_to'] + +def __init__(self, name, ffitype, w_datashape=None, w_pointer_to=None): +self.name = name +self.ffitype = ffitype +self.w_datashape = w_datashape +self.w_pointer_to = w_pointer_to +if self.is_struct(): +assert w_datashape is not None + +def descr_deref_pointer(self, space): +if self.w_pointer_to is None: +return space.w_None +return self.w_pointer_to + +def descr_sizeof(self, space): +return space.wrap(self.sizeof()) + +def sizeof(self): +return intmask(self.ffitype.c_size) + +def repr(self, space): +return space.wrap(self.__repr__()) + +def __repr__(self): +return "" % self.name + +def is_signed(self): +return (self is app_types.slong or +self is app_types.sint or +self is app_types.sshort or +self is app_types.sbyte or +self is app_types.slonglong) + +def is_unsigned(self): +return (self is app_types.ulong or +self is app_types.uint or +self is app_types.ushort or +self is app_types.ubyte or +self is app_types.ulonglong) + +def is_pointer(self): +return self.ffitype is libffi.types.pointer + +def is_char(self): +return self is app_types.char + +def is_unichar(self): +return self is app_types.unichar + +def is_longlong(self): +return libffi.IS_32_BIT and (self is app_types.slonglong or + self is app_types.ulonglong) + +def is_double(self): +return self is app_types.double + +def is_singlefloat(self): +return self is app_types.float + +def is_void(self): +return self is app_types.void + +def is_struct(self): +return libffi.types.is_struct(self.ffitype) + +def is_char_p(self): +return self is app_types.char_p + +def is_unichar_p(self): +return self is app_types.unichar_p + + +W_FFIType.typedef = TypeDef( +'FFIType', +__repr__ = interp2app(W_FFIType.repr), +deref_pointer = interp2app(W_FFIType.descr_deref_pointer), +sizeof = interp2app(W_FFIType.descr_sizeof), +) + + +def build_ffi_types(): +types = [ +# note: most of the type name directly come from the C equivalent, +# with the exception of bytes: in C, ubyte and char are equivalent, +# but for _ffi the first expects a number while the second a 1-length +# string +W_FFIType('slong', libffi.types.slong), +W_FFIType('sint', libffi.types.sint), +W_FFIType('sshort',libffi.types.sshort), +W_FFIType('sbyte', libffi.types.schar), +W_FFIType('slonglong', libffi.types.slonglong), +# +W_FFIType('ulong', libffi.types.ulong), +W_FFIType('uint', libffi.types.uint), +W_FFIType
[pypy-commit] pypy ffistruct: introduce the concept of _StructDescr, which describes the layout and ffitype of a structure
Author: Antonio Cuni Branch: ffistruct Changeset: r47110:b8cb7ac0d45a Date: 2011-09-06 16:33 +0200 http://bitbucket.org/pypy/pypy/changeset/b8cb7ac0d45a/ Log:introduce the concept of _StructDescr, which describes the layout and ffitype of a structure diff --git a/pypy/module/_ffi/__init__.py b/pypy/module/_ffi/__init__.py --- a/pypy/module/_ffi/__init__.py +++ b/pypy/module/_ffi/__init__.py @@ -7,6 +7,7 @@ 'CDLL':'interp_funcptr.W_CDLL', 'FuncPtr': 'interp_funcptr.W_FuncPtr', 'get_libc':'interp_funcptr.get_libc', +'_StructDescr': 'interp_struct.W__StructDescr', } appleveldefs = { diff --git a/pypy/module/_ffi/app_struct.py b/pypy/module/_ffi/app_struct.py --- a/pypy/module/_ffi/app_struct.py +++ b/pypy/module/_ffi/app_struct.py @@ -1,3 +1,5 @@ +import _ffi + class Field(object): def __init__(self, name, ffitype): @@ -13,7 +15,6 @@ ## def __set__(self, obj, value): ## setfield(obj._buffer, self.ffitype, self.offset, value) - class MetaStructure(type): def __new__(cls, name, bases, dic): @@ -26,13 +27,16 @@ if fields is None: return size = 0 +ffitypes = [] for field in fields: field.offset = size # XXX: alignment! size += field.ffitype.sizeof() +ffitypes.append(field.ffitype) dic[field.name] = field -dic['_size_'] = size +alignment = 0 # XXX +struct_descr = _ffi._StructDescr(size, alignment, ffitypes) +dic['_struct_'] = struct_descr class Structure(object): - __metaclass__ = MetaStructure diff --git a/pypy/module/_ffi/test/test_struct.py b/pypy/module/_ffi/test/test_struct.py --- a/pypy/module/_ffi/test/test_struct.py +++ b/pypy/module/_ffi/test/test_struct.py @@ -2,6 +2,13 @@ class AppTestStruct(BaseAppTestFFI): +def test__StructDescr(self): +from _ffi import _StructDescr, types +longsize = types.slong.sizeof() +descr = _StructDescr(longsize*2, 0, [types.slong, types.slong]) +assert descr.ffitype.sizeof() == longsize*2 +assert repr(descr.ffitype) == '>' + def test_compute_shape(self): from _ffi import Structure, Field, types class Point(Structure): @@ -15,5 +22,4 @@ assert isinstance(Point.y, Field) assert Point.x.offset == 0 assert Point.y.offset == longsize -assert Point._size_ == longsize*2 - +assert Point._struct_.ffitype.sizeof() == longsize*2 ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy ffistruct: store also the struct name in the descr
Author: Antonio Cuni Branch: ffistruct Changeset: r47111:69a6b100e900 Date: 2011-09-06 16:36 +0200 http://bitbucket.org/pypy/pypy/changeset/69a6b100e900/ Log:store also the struct name in the descr diff --git a/pypy/module/_ffi/app_struct.py b/pypy/module/_ffi/app_struct.py --- a/pypy/module/_ffi/app_struct.py +++ b/pypy/module/_ffi/app_struct.py @@ -18,11 +18,11 @@ class MetaStructure(type): def __new__(cls, name, bases, dic): -cls._compute_shape(dic) +cls._compute_shape(name, dic) return type.__new__(cls, name, bases, dic) @classmethod -def _compute_shape(cls, dic): +def _compute_shape(cls, name, dic): fields = dic.get('_fields_') if fields is None: return @@ -34,7 +34,7 @@ ffitypes.append(field.ffitype) dic[field.name] = field alignment = 0 # XXX -struct_descr = _ffi._StructDescr(size, alignment, ffitypes) +struct_descr = _ffi._StructDescr(name, size, alignment, ffitypes) dic['_struct_'] = struct_descr diff --git a/pypy/module/_ffi/test/test_struct.py b/pypy/module/_ffi/test/test_struct.py --- a/pypy/module/_ffi/test/test_struct.py +++ b/pypy/module/_ffi/test/test_struct.py @@ -5,9 +5,10 @@ def test__StructDescr(self): from _ffi import _StructDescr, types longsize = types.slong.sizeof() -descr = _StructDescr(longsize*2, 0, [types.slong, types.slong]) +descr = _StructDescr('foo', longsize*2, 0, [types.slong, types.slong]) +assert descr.name == 'foo' assert descr.ffitype.sizeof() == longsize*2 -assert repr(descr.ffitype) == '>' +assert repr(descr.ffitype) == '' def test_compute_shape(self): from _ffi import Structure, Field, types @@ -22,4 +23,5 @@ assert isinstance(Point.y, Field) assert Point.x.offset == 0 assert Point.y.offset == longsize +assert Point._struct_.name == 'Point' assert Point._struct_.ffitype.sizeof() == longsize*2 ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy ffistruct: don't store the name on the struct descr, but make it accessible from the ffi type
Author: Antonio Cuni Branch: ffistruct Changeset: r47112:ced67009fa52 Date: 2011-09-06 16:39 +0200 http://bitbucket.org/pypy/pypy/changeset/ced67009fa52/ Log:don't store the name on the struct descr, but make it accessible from the ffi type diff --git a/pypy/module/_ffi/interp_ffitype.py b/pypy/module/_ffi/interp_ffitype.py --- a/pypy/module/_ffi/interp_ffitype.py +++ b/pypy/module/_ffi/interp_ffitype.py @@ -1,7 +1,7 @@ from pypy.rlib import libffi from pypy.rlib.rarithmetic import intmask from pypy.interpreter.baseobjspace import Wrappable -from pypy.interpreter.typedef import TypeDef +from pypy.interpreter.typedef import TypeDef, interp_attrproperty from pypy.interpreter.gateway import interp2app class W_FFIType(Wrappable): @@ -81,6 +81,7 @@ W_FFIType.typedef = TypeDef( 'FFIType', +name = interp_attrproperty('name', W_FFIType), __repr__ = interp2app(W_FFIType.repr), deref_pointer = interp2app(W_FFIType.descr_deref_pointer), sizeof = interp2app(W_FFIType.descr_sizeof), diff --git a/pypy/module/_ffi/test/test_ffitype.py b/pypy/module/_ffi/test/test_ffitype.py --- a/pypy/module/_ffi/test/test_ffitype.py +++ b/pypy/module/_ffi/test/test_ffitype.py @@ -6,7 +6,9 @@ from _ffi import types assert str(types.sint) == "" assert str(types.uint) == "" - +assert types.sint.name == 'sint' +assert types.uint.name == 'uint' + def test_sizeof(self): from _ffi import types assert types.sbyte.sizeof() == 1 diff --git a/pypy/module/_ffi/test/test_struct.py b/pypy/module/_ffi/test/test_struct.py --- a/pypy/module/_ffi/test/test_struct.py +++ b/pypy/module/_ffi/test/test_struct.py @@ -6,9 +6,8 @@ from _ffi import _StructDescr, types longsize = types.slong.sizeof() descr = _StructDescr('foo', longsize*2, 0, [types.slong, types.slong]) -assert descr.name == 'foo' assert descr.ffitype.sizeof() == longsize*2 -assert repr(descr.ffitype) == '' +assert descr.ffitype.name == 'struct foo' def test_compute_shape(self): from _ffi import Structure, Field, types @@ -23,5 +22,6 @@ assert isinstance(Point.y, Field) assert Point.x.offset == 0 assert Point.y.offset == longsize -assert Point._struct_.name == 'Point' assert Point._struct_.ffitype.sizeof() == longsize*2 +assert Point._struct_.ffitype.name == 'struct Point' + ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy numpy-indexing-by-arrays: Branch for adding "index arrays" to numpy
Author: Ilya Osadchiy Branch: numpy-indexing-by-arrays Changeset: r47113:41bb9c2e7f3a Date: 2011-09-03 14:25 +0300 http://bitbucket.org/pypy/pypy/changeset/41bb9c2e7f3a/ Log:Branch for adding "index arrays" to numpy ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy numpy-indexing-by-arrays: Initial implementation
Author: Ilya Osadchiy Branch: numpy-indexing-by-arrays Changeset: r47114:7e7b4f1c2c5c Date: 2011-09-05 22:24 +0300 http://bitbucket.org/pypy/pypy/changeset/7e7b4f1c2c5c/ Log:Initial implementation diff --git a/pypy/module/micronumpy/interp_numarray.py b/pypy/module/micronumpy/interp_numarray.py --- a/pypy/module/micronumpy/interp_numarray.py +++ b/pypy/module/micronumpy/interp_numarray.py @@ -217,7 +217,6 @@ return space.wrap("[" + " ".join(concrete._getnums(True)) + "]") def descr_getitem(self, space, w_idx): -# TODO: indexing by arrays and lists if space.isinstance_w(w_idx, space.w_tuple): length = space.len_w(w_idx) if length == 0: @@ -226,6 +225,24 @@ raise OperationError(space.w_IndexError, space.wrap("invalid index")) w_idx = space.getitem(w_idx, space.wrap(0)) +elif space.issequence_w(w_idx): +w_idx = convert_to_array(space, w_idx) +bool_dtype = space.fromcache(interp_dtype.W_BoolDtype) +int_dtype = space.fromcache(interp_dtype.W_Int64Dtype) +if w_idx.find_dtype() is bool_dtype: +# TODO: indexing by bool array +raise NotImplementedError("sorry, not yet implemented") +else: +# Indexing by array + +# FIXME: should raise exception if any index in +# array is out od bound, but this kills lazy execution +new_sig = signature.Signature.find_sig([ +IndexedByArray.signature, self.signature +]) +res = IndexedByArray(new_sig, int_dtype, self, w_idx) +return space.wrap(res) + start, stop, step, slice_length = space.decode_index4(w_idx, self.find_size()) if step == 0: # Single index @@ -430,6 +447,29 @@ assert isinstance(call_sig, signature.Call2) return call_sig.func(self.res_dtype, lhs, rhs) +class IndexedByArray(VirtualArray): +""" +Intermediate class for performing indexing of array by another array +""" +signature = signature.BaseSignature() +def __init__(self, signature, int_dtype, source, index): +VirtualArray.__init__(self, signature, source.find_dtype()) +self.source = source +self.index = index +self.int_dtype = int_dtype + +def _del_sources(self): +self.source = None +self.index = None + +def _find_size(self): +return self.index.find_size() + +def _eval(self, i): +idx = self.int_dtype.unbox(self.index.eval(i).convert_to(self.int_dtype)) +val = self.source.eval(idx).convert_to(self.res_dtype) +return val + class ViewArray(BaseArray): """ Class for representing views of arrays, they will reflect changes of parent diff --git a/pypy/module/micronumpy/interp_ufuncs.py b/pypy/module/micronumpy/interp_ufuncs.py --- a/pypy/module/micronumpy/interp_ufuncs.py +++ b/pypy/module/micronumpy/interp_ufuncs.py @@ -200,7 +200,7 @@ int64_dtype = space.fromcache(interp_dtype.W_Int64Dtype) if space.is_w(w_type, space.w_bool): -if current_guess is None: +if current_guess is None or current_guess is bool_dtype: return bool_dtype elif space.is_w(w_type, space.w_int): if (current_guess is None or current_guess is bool_dtype or @@ -270,4 +270,4 @@ setattr(self, ufunc_name, ufunc) def get(space): -return space.fromcache(UfuncState) \ No newline at end of file +return space.fromcache(UfuncState) diff --git a/pypy/module/micronumpy/test/test_numarray.py b/pypy/module/micronumpy/test/test_numarray.py --- a/pypy/module/micronumpy/test/test_numarray.py +++ b/pypy/module/micronumpy/test/test_numarray.py @@ -119,6 +119,20 @@ for i in xrange(5): assert a[i] == b[i] +def test_index_by_array(self): +from numpy import array +a = array(range(5)) +idx_list = [3, 1, 3, 2, 0, 4] +idx_arr = array(idx_list) +a_by_arr = a[idx_arr] +assert len(a_by_arr) == 6 +for i in xrange(6): +assert a_by_arr[i] == range(5)[idx_list[i]] +a_by_list = a[idx_list] +assert len(a_by_list) == 6 +for i in xrange(6): +assert a_by_list[i] == range(5)[idx_list[i]] + def test_setitem(self): from numpy import array a = array(range(5)) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy ppc-jit-backend: PPC64 updates
Author: edelsohn Branch: ppc-jit-backend Changeset: r47116:c0df6acc9e45 Date: 2011-09-06 13:26 -0400 http://bitbucket.org/pypy/pypy/changeset/c0df6acc9e45/ Log:PPC64 updates diff --git a/pypy/jit/backend/ppc/runner.py b/pypy/jit/backend/ppc/runner.py --- a/pypy/jit/backend/ppc/runner.py +++ b/pypy/jit/backend/ppc/runner.py @@ -12,7 +12,7 @@ from pypy.jit.backend.x86 import regloc from pypy.jit.backend.x86.support import values_array from pypy.jit.backend.ppc.ppcgen.ppc_assembler import PPCBuilder -from pypy.jit.backend.ppc.ppcgen.arch import NONVOLATILES +from pypy.jit.backend.ppc.ppcgen.arch import IS_PPC_32, NONVOLATILES import sys from pypy.tool.ansi_print import ansi_log @@ -111,10 +111,15 @@ return reg def _make_prologue(self, codebuilder): -framesize = 64 + 80 -codebuilder.stwu(1, 1, -framesize) -codebuilder.mflr(0) -codebuilder.stw(0, 1, framesize + 4) +framesize = 16 * WORD + 20 * WORD +if IS_PPC_32: +codebuilder.stwu(1, 1, -framesize) +codebuilder.mflr(0) +codebuilder.stw(0, 1, framesize + WORD) +else: +codebuilder.stdu(1, 1, -framesize) +codebuilder.mflr(0) +codebuilder.std(0, 1, framesize + WORD) codebuilder.save_nonvolatiles(framesize) def _make_epilogue(self, codebuilder): @@ -142,10 +147,13 @@ descr.patch_pos = patch_pos descr.used_mem_indices = used_mem_indices -framesize = 64 + 80 +framesize = 16 * WORD + 20 * WORD codebuilder.restore_nonvolatiles(framesize) -codebuilder.lwz(0, 1, framesize + 4) # 36 +if IS_PPC_32: +codebuilder.lwz(0, 1, framesize + WORD) # 36 +else: +codebuilder.ld(0, 1, framesize + WORD) # 36 codebuilder.mtlr(0) codebuilder.addi(1, 1, framesize) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy ppc-jit-backend: PPC64 updates
Author: edelsohn Branch: ppc-jit-backend Changeset: r47117:6e91461f4d96 Date: 2011-09-06 13:26 -0400 http://bitbucket.org/pypy/pypy/changeset/6e91461f4d96/ Log:PPC64 updates diff --git a/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py b/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py --- a/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py +++ b/pypy/jit/backend/ppc/ppcgen/ppc_assembler.py @@ -936,16 +936,21 @@ if IS_PPC_32: self.stwx(source_reg, 0, 0) else: -# ? -self.std(source_reg, 0, 10) +self.stdx(source_reg, 0, 0) def save_nonvolatiles(self, framesize): for i, reg in enumerate(NONVOLATILES): -self.stw(reg, 1, framesize - 4 * i) +if IS_PPC_32: +self.stw(reg, 1, framesize - WORD * i) +else: +self.std(reg, 1, framesize - WORD * i) def restore_nonvolatiles(self, framesize): for i, reg in enumerate(NONVOLATILES): -self.lwz(reg, 1, framesize - i * 4) +if IS_PPC_32: +self.lwz(reg, 1, framesize - WORD * i) +else: +self.ld(reg, 1, framesize - WORD * i) # translate a trace operation to corresponding machine code @@ -1430,10 +1435,16 @@ for i, arg in enumerate(remaining_args): if isinstance(arg, Box): #self.mr(0, cpu.reg_map[arg]) -self.stw(cpu.reg_map[arg], 1, 8 + WORD * i) +if IS_PPC_32: +self.stw(cpu.reg_map[arg], 1, 8 + WORD * i) +else: +self.std(cpu.reg_map[arg], 1, 8 + WORD * i) elif isinstance(arg, Const): self.load_word(0, arg.value) -self.stw(0, 1, 8 + WORD * i) +if IS_PPC_32: +self.stw(0, 1, 8 + WORD * i) +else: +self.std(0, 1, 8 + WORD * i) else: assert 0, "%s not supported yet" % arg @@ -1590,11 +1601,14 @@ else: assert 0, "arg type not suported" -framesize = 64 + 80 +framesize = 16 * WORD + 20 * WORD self.restore_nonvolatiles(framesize) -self.lwz(0, 1, framesize + 4) # 36 +if IS_PPC_32: +self.lwz(0, 1, framesize + WORD) # 36 +else: +self.ld(0, 1, framesize + WORD) # 36 self.mtlr(0) self.addi(1, 1, framesize) self.load_word(3, identifier) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: 'Python 2.7 -A' raises TypeError in this corner case.
Author: Armin Rigo Branch: Changeset: r47118:ebe7ce81d5a1 Date: 2011-09-06 19:08 +0200 http://bitbucket.org/pypy/pypy/changeset/ebe7ce81d5a1/ Log:'Python 2.7 -A' raises TypeError in this corner case. diff --git a/pypy/objspace/std/test/test_stringformat.py b/pypy/objspace/std/test/test_stringformat.py --- a/pypy/objspace/std/test/test_stringformat.py +++ b/pypy/objspace/std/test/test_stringformat.py @@ -168,7 +168,7 @@ def test_incomplete_format(self): raises(ValueError, '%'.__mod__, ((23,),)) -raises(ValueError, '%('.__mod__, ({},)) +raises((ValueError, TypeError), '%('.__mod__, ({},)) def test_format_char(self): import sys ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Add comment.
Author: Armin Rigo Branch: Changeset: r47120:ddff981df9d5 Date: 2011-09-06 19:34 +0200 http://bitbucket.org/pypy/pypy/changeset/ddff981df9d5/ Log:Add comment. diff --git a/pypy/objspace/std/test/test_obj.py b/pypy/objspace/std/test/test_obj.py --- a/pypy/objspace/std/test/test_obj.py +++ b/pypy/objspace/std/test/test_obj.py @@ -96,7 +96,8 @@ #assert type(log[0].message) is DeprecationWarning def test_object_str(self): -# obscure case +# obscure case: __str__() must delegate to __repr__() without adding +# type checking on its own class A(object): def __repr__(self): return 123456 ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Tests and fix:
Author: Armin Rigo Branch: Changeset: r47119:09816858a87a Date: 2011-09-06 19:33 +0200 http://bitbucket.org/pypy/pypy/changeset/09816858a87a/ Log:Tests and fix: object.__str__() was implemented by calling space.repr(), instead of directly calling the __repr__() method. The difference is that the first does type checking on the result, while the latter does not. It's not the job of object.__str__() to do type checking, but of its callers. diff --git a/pypy/objspace/std/objecttype.py b/pypy/objspace/std/objecttype.py --- a/pypy/objspace/std/objecttype.py +++ b/pypy/objspace/std/objecttype.py @@ -24,7 +24,12 @@ return w_obj.getrepr(space, '%s object' % (classname,)) def descr__str__(space, w_obj): -return space.repr(w_obj) +w_type = space.type(w_obj) +w_impl = w_type.lookup("__repr__") +if w_impl is None: +raise OperationError(space.w_TypeError, # can it really occur? + space.wrap("operand does not support unary str")) +return space.get_and_call_function(w_impl, w_obj) def descr__class__(space, w_obj): return space.type(w_obj) diff --git a/pypy/objspace/std/test/test_obj.py b/pypy/objspace/std/test/test_obj.py --- a/pypy/objspace/std/test/test_obj.py +++ b/pypy/objspace/std/test/test_obj.py @@ -94,3 +94,10 @@ #assert len(log) == 1 #assert log[0].message.args == ("object.__init__() takes no parameters",) #assert type(log[0].message) is DeprecationWarning + +def test_object_str(self): +# obscure case +class A(object): +def __repr__(self): +return 123456 +assert A().__str__() == 123456 diff --git a/pypy/objspace/std/test/test_unicodeobject.py b/pypy/objspace/std/test/test_unicodeobject.py --- a/pypy/objspace/std/test/test_unicodeobject.py +++ b/pypy/objspace/std/test/test_unicodeobject.py @@ -780,8 +780,22 @@ assert type(s) is unicode assert s == u'\u1234' +# now the same with a new-style class... +class A(object): +def __init__(self, num): +self.num = num +def __str__(self): +return unichr(self.num) + +s = '%s' % A(111)# this is ASCII +assert type(s) is unicode +assert s == chr(111) + +s = '%s' % A(0x1234)# this is not ASCII +assert type(s) is unicode +assert s == u'\u1234' + def test_formatting_unicode__str__2(self): -skip("this is completely insane") class A: def __str__(self): return u'baz' @@ -798,9 +812,22 @@ s = '%s %s' % (a, b) assert s == u'baz bar' +skip("but this case here is completely insane") s = '%s %s' % (b, a) assert s == u'foo baz' +def test_formatting_unicode__str__3(self): +# "bah" is all I can say +class X(object): +def __repr__(self): +return u'\u1234' +'%s' % X() +# +class X(object): +def __str__(self): +return u'\u1234' +'%s' % X() + def test_str_subclass(self): class Foo9(str): def __unicode__(self): ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy inline-dict-ops: fix tests
Author: Maciej Fijalkowski Branch: inline-dict-ops Changeset: r47121:2227e3fb86ed Date: 2011-09-06 22:46 +0200 http://bitbucket.org/pypy/pypy/changeset/2227e3fb86ed/ Log:fix tests diff --git a/pypy/jit/backend/llsupport/test/test_asmmemmgr.py b/pypy/jit/backend/llsupport/test/test_asmmemmgr.py --- a/pypy/jit/backend/llsupport/test/test_asmmemmgr.py +++ b/pypy/jit/backend/llsupport/test/test_asmmemmgr.py @@ -211,14 +211,14 @@ debug._log = debug.DebugLog() try: mc._dump(addr, 'test-logname-section') -log = list(debug._log) +log = list(debug._log) finally: debug._log = None encoded = ''.join(writtencode).encode('hex').upper() ataddr = '@%x' % addr assert log == [('test-logname-section', [('debug_print', 'CODE_DUMP', ataddr, '+0 ', encoded)])] -# + lltype.free(p, flavor='raw') def test_blockbuildermixin2(): diff --git a/pypy/jit/backend/llsupport/test/test_descr.py b/pypy/jit/backend/llsupport/test/test_descr.py --- a/pypy/jit/backend/llsupport/test/test_descr.py +++ b/pypy/jit/backend/llsupport/test/test_descr.py @@ -159,7 +159,7 @@ clsf = getArrayDescrClass(A4) assert clsf != cls assert clsf == getArrayDescrClass(lltype.GcArray(lltype.Float)) -clss = getArrayDescrClass(A5) +clss = getArrayDescrClass(A6) assert clss not in (clsf, cls) assert clss == getArrayDescrClass(lltype.GcArray(rffi.UINT)) # @@ -174,7 +174,7 @@ assert descr2.__class__ is GcPtrArrayDescr assert descr3.__class__ is NonGcPtrArrayDescr assert descr4.__class__ is clsf -assert descr5.__class__ is clss +assert descr6.__class__ is clss assert descr1 == get_array_descr(c0, lltype.GcArray(lltype.Char)) assert not descr1.is_array_of_pointers() assert descr2.is_array_of_pointers() ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] lang-scheme default: Split tests for symbols & strings out of test_simple
Author: Juergen Boemmels Branch: Changeset: r5:324223d56732 Date: 2011-09-05 23:02 +0200 http://bitbucket.org/pypy/lang-scheme/changeset/324223d56732/ Log:Split tests for symbols & strings out of test_simple diff --git a/scheme/test/test_parser.py b/scheme/test/test_parser.py --- a/scheme/test/test_parser.py +++ b/scheme/test/test_parser.py @@ -39,8 +39,13 @@ w_fixnum = parse_sexpr('1123') assert unwrap(w_fixnum) == 1123 assert isinstance(w_fixnum, W_Integer) -w_fixnum = parse_sexpr('abfa__') -assert isinstance(w_fixnum, W_Symbol) + +def test_symbol(): +w_sym = parse_sexpr('abfa__') +assert isinstance(w_sym, W_Symbol) +assert w_sym.to_string() == 'abfa__' + +def test_string(): t = parse_sexpr(r'''"don't believe \"them\""''') assert isinstance(t, W_String) assert unwrap(t) == 'don\'t believe "them"' ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] lang-scheme default: More symbol test
Author: Juergen Boemmels Branch: Changeset: r6:7702fffadbc2 Date: 2011-09-05 23:19 +0200 http://bitbucket.org/pypy/lang-scheme/changeset/7702fffadbc2/ Log:More symbol test diff --git a/scheme/test/test_parser.py b/scheme/test/test_parser.py --- a/scheme/test/test_parser.py +++ b/scheme/test/test_parser.py @@ -44,6 +44,18 @@ w_sym = parse_sexpr('abfa__') assert isinstance(w_sym, W_Symbol) assert w_sym.to_string() == 'abfa__' + +more_syms = ['abc', + 'call/cc', + '+', + '-', + 'set!', + 'eqv?', +] +for s in more_syms: +w_sym = parse_sexpr(s) +assert isinstance(w_sym, W_Symbol) +assert w_sym.to_string() == s def test_string(): t = parse_sexpr(r'''"don't believe \"them\""''') ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] lang-scheme default: Fix strings: Allow escaped backslash
Author: Juergen Boemmels Branch: Changeset: r7:0e79d2ada637 Date: 2011-09-06 22:58 +0200 http://bitbucket.org/pypy/lang-scheme/changeset/0e79d2ada637/ Log:Fix strings: Allow escaped backslash diff --git a/scheme/ssparser.py b/scheme/ssparser.py --- a/scheme/ssparser.py +++ b/scheme/ssparser.py @@ -2,18 +2,25 @@ from pypy.rlib.parsing.makepackrat import BacktrackException, Status from scheme.object import W_Pair, W_Integer, W_String, symbol, \ w_nil, W_Boolean, W_Real, quote, qq, unquote, unquote_splicing, \ -w_ellipsis +w_ellipsis, SchemeSyntaxError def str_unquote(s): str_lst = [] -last_ch = '' -for c in s[1:]: -if last_ch == '\\' and c == '"': -pass +pos = 1 +last = len(s)-1 +while pos < last: +ch = s[pos] +if ch == '\\': +pos += 1 +ch = s[pos] +if ch == '\\' or ch == '\"': +str_lst.append(ch) +else: +raise SchemeSyntaxError else: -str_lst.append(last_ch) +str_lst.append(ch) -last_ch = c +pos += 1 return ''.join(str_lst) diff --git a/scheme/test/test_parser.py b/scheme/test/test_parser.py --- a/scheme/test/test_parser.py +++ b/scheme/test/test_parser.py @@ -62,6 +62,16 @@ assert isinstance(t, W_String) assert unwrap(t) == 'don\'t believe "them"' +more_strings = [(r'''"simple string"''', r'''simple string'''), +(r'''"\\ backslash"''', r'''\ backslash'''), +(r'''""''',r'''\\'''), +(r'''"with \"quotes\""''', r'''with "quotes"'''), + ] +for code, contents in more_strings: +w_string = parse_sexpr(code) +assert isinstance(w_string, W_String) +assert unwrap(w_string) == contents + def test_objects(): w_fixnum = parse_sexpr('-12345') assert isinstance(w_fixnum, W_Integer) ___ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit