Author: Maciej Fijalkowski <fij...@gmail.com> Branch: Changeset: r48277:39882f1dfd15 Date: 2011-10-20 19:50 +0200 http://bitbucket.org/pypy/pypy/changeset/39882f1dfd15/
Log: merge default diff --git a/lib_pypy/pyrepl/readline.py b/lib_pypy/pyrepl/readline.py --- a/lib_pypy/pyrepl/readline.py +++ b/lib_pypy/pyrepl/readline.py @@ -395,9 +395,21 @@ _wrapper.f_in = f_in _wrapper.f_out = f_out - if hasattr(sys, '__raw_input__'): # PyPy - _old_raw_input = sys.__raw_input__ + if '__pypy__' in sys.builtin_module_names: # PyPy + + def _old_raw_input(prompt=''): + # sys.__raw_input__() is only called when stdin and stdout are + # as expected and are ttys. If it is the case, then get_reader() + # should not really fail in _wrapper.raw_input(). If it still + # does, then we will just cancel the redirection and call again + # the built-in raw_input(). + try: + del sys.__raw_input__ + except AttributeError: + pass + return raw_input(prompt) sys.__raw_input__ = _wrapper.raw_input + else: # this is not really what readline.c does. Better than nothing I guess import __builtin__ diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py --- a/pypy/config/pypyoption.py +++ b/pypy/config/pypyoption.py @@ -72,6 +72,7 @@ del working_modules['fcntl'] # LOCK_NB not defined del working_modules["_minimal_curses"] del working_modules["termios"] + del working_modules["_multiprocessing"] # depends on rctime diff --git a/pypy/jit/metainterp/optimizeopt/rewrite.py b/pypy/jit/metainterp/optimizeopt/rewrite.py --- a/pypy/jit/metainterp/optimizeopt/rewrite.py +++ b/pypy/jit/metainterp/optimizeopt/rewrite.py @@ -106,10 +106,9 @@ self.make_equal_to(op.result, v1) else: self.emit_operation(op) - - # Synthesize the reverse ops for optimize_default to reuse - self.pure(rop.INT_ADD, [op.result, op.getarg(1)], op.getarg(0)) - self.pure(rop.INT_SUB, [op.getarg(0), op.result], op.getarg(1)) + # Synthesize the reverse ops for optimize_default to reuse + self.pure(rop.INT_ADD, [op.result, op.getarg(1)], op.getarg(0)) + self.pure(rop.INT_SUB, [op.getarg(0), op.result], op.getarg(1)) def optimize_INT_ADD(self, op): v1 = self.getvalue(op.getarg(0)) @@ -122,10 +121,9 @@ self.make_equal_to(op.result, v1) else: self.emit_operation(op) - - # Synthesize the reverse op for optimize_default to reuse - self.pure(rop.INT_SUB, [op.result, op.getarg(1)], op.getarg(0)) - self.pure(rop.INT_SUB, [op.result, op.getarg(0)], op.getarg(1)) + # Synthesize the reverse op for optimize_default to reuse + self.pure(rop.INT_SUB, [op.result, op.getarg(1)], op.getarg(0)) + self.pure(rop.INT_SUB, [op.result, op.getarg(0)], op.getarg(1)) def optimize_INT_MUL(self, op): v1 = self.getvalue(op.getarg(0)) @@ -141,13 +139,13 @@ self.make_constant_int(op.result, 0) else: for lhs, rhs in [(v1, v2), (v2, v1)]: - # x & (x -1) == 0 is a quick test for power of 2 - if (lhs.is_constant() and - (lhs.box.getint() & (lhs.box.getint() - 1)) == 0): - new_rhs = ConstInt(highest_bit(lhs.box.getint())) - op = op.copy_and_change(rop.INT_LSHIFT, args=[rhs.box, new_rhs]) - break - + if lhs.is_constant(): + x = lhs.box.getint() + # x & (x - 1) == 0 is a quick test for power of 2 + if x & (x - 1) == 0: + new_rhs = ConstInt(highest_bit(lhs.box.getint())) + op = op.copy_and_change(rop.INT_LSHIFT, args=[rhs.box, new_rhs]) + break self.emit_operation(op) def optimize_UINT_FLOORDIV(self, op): @@ -462,6 +460,14 @@ self.optimizer.opaque_pointers[value] = True self.make_equal_to(op.result, value) + def optimize_CAST_PTR_TO_INT(self, op): + self.pure(rop.CAST_INT_TO_PTR, [op.result], op.getarg(0)) + self.emit_operation(op) + + def optimize_CAST_INT_TO_PTR(self, op): + self.pure(rop.CAST_PTR_TO_INT, [op.result], op.getarg(0)) + self.emit_operation(op) + dispatch_opt = make_dispatcher_method(OptRewrite, 'optimize_', default=OptRewrite.emit_operation) optimize_guards = _findall(OptRewrite, 'optimize_', 'GUARD') diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py --- a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py +++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py @@ -234,6 +234,30 @@ """ % expected_value self.optimize_loop(ops, expected) + def test_reverse_of_cast(self): + ops = """ + [i0] + p0 = cast_int_to_ptr(i0) + i1 = cast_ptr_to_int(p0) + jump(i1) + """ + expected = """ + [i0] + jump(i0) + """ + self.optimize_loop(ops, expected) + ops = """ + [p0] + i1 = cast_ptr_to_int(p0) + p1 = cast_int_to_ptr(i1) + jump(p1) + """ + expected = """ + [p0] + jump(p0) + """ + self.optimize_loop(ops, expected) + # ---------- def test_remove_guard_class_1(self): diff --git a/pypy/jit/metainterp/quasiimmut.py b/pypy/jit/metainterp/quasiimmut.py --- a/pypy/jit/metainterp/quasiimmut.py +++ b/pypy/jit/metainterp/quasiimmut.py @@ -74,8 +74,10 @@ self.looptokens_wrefs.append(wref_looptoken) def compress_looptokens_list(self): - self.looptokens_wref = [wref for wref in self.looptokens_wrefs - if wref() is not None] + self.looptokens_wrefs = [wref for wref in self.looptokens_wrefs + if wref() is not None] + # NB. we must keep around the looptoken_wrefs that are + # already invalidated; see below self.compress_limit = (len(self.looptokens_wrefs) + 15) * 2 def invalidate(self): @@ -89,6 +91,11 @@ if looptoken is not None: looptoken.invalidated = True self.cpu.invalidate_loop(looptoken) + # NB. we must call cpu.invalidate_loop() even if + # looptoken.invalidated was already set to True. + # It's possible to invalidate several times the + # same looptoken; see comments in jit.backend.model + # in invalidate_loop(). if not we_are_translated(): self.cpu.stats.invalidated_token_numbers.add( looptoken.number) diff --git a/pypy/module/__builtin__/__init__.py b/pypy/module/__builtin__/__init__.py --- a/pypy/module/__builtin__/__init__.py +++ b/pypy/module/__builtin__/__init__.py @@ -23,6 +23,7 @@ 'map' : 'app_functional.map', 'reduce' : 'app_functional.reduce', 'filter' : 'app_functional.filter', + 'zip' : 'app_functional.zip', 'vars' : 'app_inspect.vars', 'dir' : 'app_inspect.dir', @@ -89,7 +90,6 @@ 'enumerate' : 'functional.W_Enumerate', 'min' : 'functional.min', 'max' : 'functional.max', - 'zip' : 'functional.zip', 'reversed' : 'functional.reversed', 'super' : 'descriptor.W_Super', 'staticmethod' : 'descriptor.StaticMethod', diff --git a/pypy/module/__builtin__/app_functional.py b/pypy/module/__builtin__/app_functional.py --- a/pypy/module/__builtin__/app_functional.py +++ b/pypy/module/__builtin__/app_functional.py @@ -162,4 +162,21 @@ item = seq[i] if func(item): result.append(item) - return tuple(result) \ No newline at end of file + return tuple(result) + +def zip(*sequences): + """zip(seq1 [, seq2 [...]]) -> [(seq1[0], seq2[0] ...), (...)] + +Return a list of tuples, where each tuple contains the i-th element +from each of the argument sequences. The returned list is truncated +in length to the length of the shortest argument sequence.""" + if not sequences: + return [] + result = [] + iterators = [iter(seq) for seq in sequences] + while True: + try: + items = [next(it) for it in iterators] + except StopIteration: + return result + result.append(tuple(items)) diff --git a/pypy/module/__builtin__/app_io.py b/pypy/module/__builtin__/app_io.py --- a/pypy/module/__builtin__/app_io.py +++ b/pypy/module/__builtin__/app_io.py @@ -27,7 +27,20 @@ co = compile(source.rstrip()+"\n", filename, 'exec') exec co in glob, loc -def raw_input(prompt=None): +def _write_prompt(stdout, prompt): + print >> stdout, prompt, + try: + flush = stdout.flush + except AttributeError: + pass + else: + flush() + try: + stdout.softspace = 0 + except (AttributeError, TypeError): + pass + +def raw_input(prompt=''): """raw_input([prompt]) -> string Read a string from standard input. The trailing newline is stripped. @@ -47,18 +60,10 @@ if (hasattr(sys, '__raw_input__') and isinstance(stdin, file) and stdin.fileno() == 0 and stdin.isatty() and isinstance(stdout, file) and stdout.fileno() == 1): - if prompt is None: - prompt = '' - return sys.__raw_input__(prompt) + _write_prompt(stdout, '') + return sys.__raw_input__(str(prompt)) - if prompt is not None: - stdout.write(prompt) - try: - flush = stdout.flush - except AttributeError: - pass - else: - flush() + _write_prompt(stdout, prompt) line = stdin.readline() if not line: # inputting an empty line gives line == '\n' raise EOFError diff --git a/pypy/module/__builtin__/functional.py b/pypy/module/__builtin__/functional.py --- a/pypy/module/__builtin__/functional.py +++ b/pypy/module/__builtin__/functional.py @@ -201,27 +201,6 @@ """ return min_max(space, __args__, "min") -@unwrap_spec(sequences_w="args_w") -def zip(space, sequences_w): - """Return a list of tuples, where the nth tuple contains every nth item of - each collection. - - If the collections have different lengths, zip returns a list as long as the - shortest collection, ignoring the trailing items in the other collections. - """ - if not sequences_w: - return space.newlist([]) - result_w = [] - iterators_w = [space.iter(w_seq) for w_seq in sequences_w] - while True: - try: - items_w = [space.next(w_it) for w_it in iterators_w] - except OperationError, e: - if not e.match(space, space.w_StopIteration): - raise - return space.newlist(result_w) - result_w.append(space.newtuple(items_w)) - class W_Enumerate(Wrappable): def __init__(self, w_iter, w_start): diff --git a/pypy/module/__builtin__/test/test_rawinput.py b/pypy/module/__builtin__/test/test_rawinput.py new file mode 100644 --- /dev/null +++ b/pypy/module/__builtin__/test/test_rawinput.py @@ -0,0 +1,77 @@ +import autopath + + +class AppTestRawInput(): + + def test_raw_input(self): + import sys, StringIO + for prompt, expected in [("def:", "abc/ def:/ghi\n"), + ("", "abc/ /ghi\n"), + (42, "abc/ 42/ghi\n"), + (None, "abc/ None/ghi\n"), + (Ellipsis, "abc/ /ghi\n")]: + save = sys.stdin, sys.stdout + try: + sys.stdin = StringIO.StringIO("foo\nbar\n") + out = sys.stdout = StringIO.StringIO() + print "abc", # softspace = 1 + out.write('/') + if prompt is Ellipsis: + got = raw_input() + else: + got = raw_input(prompt) + out.write('/') + print "ghi" + finally: + sys.stdin, sys.stdout = save + assert out.getvalue() == expected + assert got == "foo" + + def test_softspace(self): + import sys + import StringIO + fin = StringIO.StringIO() + fout = StringIO.StringIO() + + fin.write("Coconuts\n") + fin.seek(0) + + sys_stdin_orig = sys.stdin + sys_stdout_orig = sys.stdout + + sys.stdin = fin + sys.stdout = fout + + print "test", + raw_input("test") + + sys.stdin = sys_stdin_orig + sys.stdout = sys_stdout_orig + + fout.seek(0) + assert fout.read() == "test test" + + def test_softspace_carryover(self): + import sys + import StringIO + fin = StringIO.StringIO() + fout = StringIO.StringIO() + + fin.write("Coconuts\n") + fin.seek(0) + + sys_stdin_orig = sys.stdin + sys_stdout_orig = sys.stdout + + sys.stdin = fin + sys.stdout = fout + + print "test", + raw_input("test") + print "test", + + sys.stdin = sys_stdin_orig + sys.stdout = sys_stdout_orig + + fout.seek(0) + assert fout.read() == "test testtest" diff --git a/pypy/module/pyexpat/__init__.py b/pypy/module/pyexpat/__init__.py --- a/pypy/module/pyexpat/__init__.py +++ b/pypy/module/pyexpat/__init__.py @@ -4,12 +4,8 @@ class ErrorsModule(MixedModule): "Definition of pyexpat.errors module." - - appleveldefs = { - } - - interpleveldefs = { - } + appleveldefs = {} + interpleveldefs = {} def setup_after_space_initialization(self): from pypy.module.pyexpat import interp_pyexpat @@ -18,6 +14,18 @@ interp_pyexpat.ErrorString(self.space, getattr(interp_pyexpat, name))) +class ModelModule(MixedModule): + "Definition of pyexpat.model module." + appleveldefs = {} + interpleveldefs = {} + + def setup_after_space_initialization(self): + from pypy.module.pyexpat import interp_pyexpat + space = self.space + for name in interp_pyexpat.xml_model_list: + value = getattr(interp_pyexpat, name) + space.setattr(self, space.wrap(name), space.wrap(value)) + class Module(MixedModule): "Python wrapper for Expat parser." @@ -39,6 +47,7 @@ submodules = { 'errors': ErrorsModule, + 'model': ModelModule, } for name in ['XML_PARAM_ENTITY_PARSING_NEVER', diff --git a/pypy/module/pyexpat/interp_pyexpat.py b/pypy/module/pyexpat/interp_pyexpat.py --- a/pypy/module/pyexpat/interp_pyexpat.py +++ b/pypy/module/pyexpat/interp_pyexpat.py @@ -76,6 +76,18 @@ "XML_ERROR_FINISHED", "XML_ERROR_SUSPEND_PE", ] +xml_model_list = [ + "XML_CTYPE_EMPTY", + "XML_CTYPE_ANY", + "XML_CTYPE_MIXED", + "XML_CTYPE_NAME", + "XML_CTYPE_CHOICE", + "XML_CTYPE_SEQ", + "XML_CQUANT_NONE", + "XML_CQUANT_OPT", + "XML_CQUANT_REP", + "XML_CQUANT_PLUS", + ] class CConfigure: _compilation_info_ = eci @@ -104,6 +116,8 @@ for name in xml_error_list: locals()[name] = rffi_platform.ConstantInteger(name) + for name in xml_model_list: + locals()[name] = rffi_platform.ConstantInteger(name) for k, v in rffi_platform.configure(CConfigure).items(): globals()[k] = v diff --git a/pypy/module/pyexpat/test/test_parser.py b/pypy/module/pyexpat/test/test_parser.py --- a/pypy/module/pyexpat/test/test_parser.py +++ b/pypy/module/pyexpat/test/test_parser.py @@ -131,3 +131,7 @@ 'encoding specified in XML declaration is incorrect') assert (pyexpat.errors.XML_ERROR_XML_DECL == 'XML declaration not well-formed') + + def test_model(self): + import pyexpat + assert isinstance(pyexpat.model.XML_CTYPE_EMPTY, int) diff --git a/pypy/objspace/std/strutil.py b/pypy/objspace/std/strutil.py --- a/pypy/objspace/std/strutil.py +++ b/pypy/objspace/std/strutil.py @@ -35,7 +35,7 @@ def error(self): raise ParseStringError("invalid literal for %s() with base %d: '%s'" % - (self.fname, self.base, self.literal)) + (self.fname, self.original_base, self.literal)) def __init__(self, s, literal, base, fname): self.literal = literal @@ -47,7 +47,8 @@ elif s.startswith('+'): s = strip_spaces(s[1:]) self.sign = sign - + self.original_base = base + if base == 0: if s.startswith('0x') or s.startswith('0X'): base = 16 diff --git a/pypy/objspace/std/test/test_strutil.py b/pypy/objspace/std/test/test_strutil.py --- a/pypy/objspace/std/test/test_strutil.py +++ b/pypy/objspace/std/test/test_strutil.py @@ -89,6 +89,8 @@ exc = raises(ParseStringError, string_to_int, '') assert exc.value.msg == "invalid literal for int() with base 10: ''" + exc = raises(ParseStringError, string_to_int, '', 0) + assert exc.value.msg == "invalid literal for int() with base 0: ''" def test_string_to_int_overflow(self): import sys diff --git a/pypy/rlib/_rsocket_rffi.py b/pypy/rlib/_rsocket_rffi.py --- a/pypy/rlib/_rsocket_rffi.py +++ b/pypy/rlib/_rsocket_rffi.py @@ -16,6 +16,7 @@ _MINGW = target_platform.name == "mingw32" _SOLARIS = sys.platform == "sunos5" _MACOSX = sys.platform == "darwin" +_HAS_AF_PACKET = sys.platform.startswith('linux') # only Linux for now if _POSIX: includes = ('sys/types.h', @@ -34,11 +35,12 @@ 'stdint.h', 'errno.h', ) + if _HAS_AF_PACKET: + includes += ('netpacket/packet.h', + 'sys/ioctl.h', + 'net/if.h') - cond_includes = [('AF_NETLINK', 'linux/netlink.h'), - ('AF_PACKET', 'netpacket/packet.h'), - ('AF_PACKET', 'sys/ioctl.h'), - ('AF_PACKET', 'net/if.h')] + cond_includes = [('AF_NETLINK', 'linux/netlink.h')] libraries = () calling_conv = 'c' @@ -320,18 +322,18 @@ ('events', rffi.SHORT), ('revents', rffi.SHORT)]) - CConfig.sockaddr_ll = platform.Struct('struct sockaddr_ll', + if _HAS_AF_PACKET: + CConfig.sockaddr_ll = platform.Struct('struct sockaddr_ll', [('sll_ifindex', rffi.INT), ('sll_protocol', rffi.INT), ('sll_pkttype', rffi.INT), ('sll_hatype', rffi.INT), ('sll_addr', rffi.CFixedArray(rffi.CHAR, 8)), - ('sll_halen', rffi.INT)], - ifdef='AF_PACKET') + ('sll_halen', rffi.INT)]) - CConfig.ifreq = platform.Struct('struct ifreq', [('ifr_ifindex', rffi.INT), - ('ifr_name', rffi.CFixedArray(rffi.CHAR, 8))], - ifdef='AF_PACKET') + CConfig.ifreq = platform.Struct('struct ifreq', + [('ifr_ifindex', rffi.INT), + ('ifr_name', rffi.CFixedArray(rffi.CHAR, 8))]) if _WIN32: CConfig.WSAEVENT = platform.SimpleType('WSAEVENT', rffi.VOIDP) @@ -386,6 +388,8 @@ constants[name] = value else: constants[name] = default +if not _HAS_AF_PACKET and 'AF_PACKET' in constants: + del constants['AF_PACKET'] constants['has_ipv6'] = True # This is a configuration option in CPython for name, value in constants.items(): @@ -439,21 +443,14 @@ if _POSIX: nfds_t = cConfig.nfds_t pollfd = cConfig.pollfd - if cConfig.sockaddr_ll is not None: + if _HAS_AF_PACKET: sockaddr_ll = cConfig.sockaddr_ll - ifreq = cConfig.ifreq + ifreq = cConfig.ifreq if WIN32: WSAEVENT = cConfig.WSAEVENT WSANETWORKEVENTS = cConfig.WSANETWORKEVENTS timeval = cConfig.timeval -#if _POSIX: -# includes = list(includes) -# for _name, _header in cond_includes: -# if getattr(cConfig, _name) is not None: -# includes.append(_header) -# eci = ExternalCompilationInfo(includes=includes, libraries=libraries, -# separate_module_sources=sources) def external(name, args, result, **kwds): return rffi.llexternal(name, args, result, compilation_info=eci, @@ -544,7 +541,7 @@ socketpair_t = rffi.CArray(socketfd_type) socketpair = external('socketpair', [rffi.INT, rffi.INT, rffi.INT, lltype.Ptr(socketpair_t)], rffi.INT) - if ifreq is not None: + if _HAS_AF_PACKET: ioctl = external('ioctl', [socketfd_type, rffi.INT, lltype.Ptr(ifreq)], rffi.INT) diff --git a/pypy/rlib/rsocket.py b/pypy/rlib/rsocket.py --- a/pypy/rlib/rsocket.py +++ b/pypy/rlib/rsocket.py @@ -8,6 +8,7 @@ # Known missing features: # # - address families other than AF_INET, AF_INET6, AF_UNIX, AF_PACKET +# - AF_PACKET is only supported on Linux # - methods makefile(), # - SSL # diff --git a/pypy/rpython/lltypesystem/rbuilder.py b/pypy/rpython/lltypesystem/rbuilder.py --- a/pypy/rpython/lltypesystem/rbuilder.py +++ b/pypy/rpython/lltypesystem/rbuilder.py @@ -29,7 +29,7 @@ except OverflowError: raise MemoryError newbuf = mallocfn(new_allocated) - copycontentsfn(ll_builder.buf, newbuf, 0, 0, ll_builder.allocated) + copycontentsfn(ll_builder.buf, newbuf, 0, 0, ll_builder.used) ll_builder.buf = newbuf ll_builder.allocated = new_allocated return func_with_new_name(stringbuilder_grow, name) @@ -56,7 +56,7 @@ class BaseStringBuilderRepr(AbstractStringBuilderRepr): def empty(self): return nullptr(self.lowleveltype.TO) - + @classmethod def ll_new(cls, init_size): if init_size < 0 or init_size > MAX: 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 @@ -1292,10 +1292,12 @@ # if a prebuilt GcStruct contains a pointer to a young object, # then the write_barrier must have ensured that the prebuilt # GcStruct is in the list self.old_objects_pointing_to_young. + debug_start("gc-minor-walkroots") self.root_walker.walk_roots( MiniMarkGC._trace_drag_out1, # stack roots MiniMarkGC._trace_drag_out1, # static in prebuilt non-gc None) # static in prebuilt gc + debug_stop("gc-minor-walkroots") def collect_cardrefs_to_nursery(self): size_gc_header = self.gcheaderbuilder.size_gc_header diff --git a/pypy/translator/platform/posix.py b/pypy/translator/platform/posix.py --- a/pypy/translator/platform/posix.py +++ b/pypy/translator/platform/posix.py @@ -157,7 +157,7 @@ rules = [ ('all', '$(DEFAULT_TARGET)', []), - ('$(TARGET)', '$(OBJECTS)', '$(CC_LINK) $(LDFLAGS) $(LDFLAGSEXTRA) -o $@ $(OBJECTS) $(LIBDIRS) $(LIBS) $(LINKFILES)'), + ('$(TARGET)', '$(OBJECTS)', '$(CC_LINK) $(LDFLAGSEXTRA) -o $@ $(OBJECTS) $(LIBDIRS) $(LIBS) $(LINKFILES) $(LDFLAGS)'), ('%.o', '%.c', '$(CC) $(CFLAGS) $(CFLAGSEXTRA) -o $@ -c $< $(INCLUDEDIRS)'), ] _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit