Commits

Maciej Fijalkowski committed 39882f1 Merge

merge default

Comments (0)

Files changed (22)

lib_pypy/pyrepl/readline.py

     _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__

pypy/config/pypyoption.py

     del working_modules['fcntl']  # LOCK_NB not defined
     del working_modules["_minimal_curses"]
     del working_modules["termios"]
+    del working_modules["_multiprocessing"]   # depends on rctime
 
 
 

pypy/jit/metainterp/optimizeopt/rewrite.py

             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))
             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))
             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):
         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')

pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py

File contents unchanged.

pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py

             """ % 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):

pypy/jit/metainterp/quasiimmut.py

         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):
             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)

pypy/module/__builtin__/__init__.py

         'map'           : 'app_functional.map',
         'reduce'        : 'app_functional.reduce',
         'filter'        : 'app_functional.filter',
+        'zip'           : 'app_functional.zip',
         'vars'          : 'app_inspect.vars',
         'dir'           : 'app_inspect.dir',
 
         'enumerate'     : 'functional.W_Enumerate',
         'min'           : 'functional.min',
         'max'           : 'functional.max',
-        'zip'           : 'functional.zip',
         'reversed'      : 'functional.reversed',
         'super'         : 'descriptor.W_Super',
         'staticmethod'  : 'descriptor.StaticMethod',

pypy/module/__builtin__/app_functional.py

         item = seq[i]
         if func(item):
             result.append(item)
-    return tuple(result)
+    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))

pypy/module/__builtin__/app_io.py

     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.
     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

pypy/module/__builtin__/functional.py

     """
     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):

pypy/module/__builtin__/test/test_builtin.py

File contents unchanged.

pypy/module/__builtin__/test/test_rawinput.py

+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"

pypy/module/pyexpat/__init__.py

 
 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
                     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."
 
 
     submodules = {
         'errors': ErrorsModule,
+        'model':  ModelModule,
     }
 
     for name in ['XML_PARAM_ENTITY_PARSING_NEVER',

pypy/module/pyexpat/interp_pyexpat.py

     "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
 
     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

pypy/module/pyexpat/test/test_parser.py

                '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)

pypy/objspace/std/strutil.py

 
     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
         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

pypy/objspace/std/test/test_strutil.py

 
         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

pypy/rlib/_rsocket_rffi.py

 _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',
                 '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'
                                              ('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)
         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():
 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,
     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)
 

pypy/rlib/rsocket.py

 # 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
 #

pypy/rpython/lltypesystem/rbuilder.py

         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)
 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:

pypy/rpython/memory/gc/minimark.py

         # 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

pypy/translator/platform/posix.py

 
         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)'),
             ]