Philip Jenvey avatar Philip Jenvey committed f7f0490 Merge

merge default

Comments (0)

Files changed (6)

pypy/interpreter/gateway.py

         raise TypeError("Varargs and keywords not supported in unwrap_spec")
     argspec = ', '.join([arg for arg in args.args[1:]])
     func_code = py.code.Source("""
-    def f(w_obj, %(args)s):
-        return w_obj.%(func_name)s(%(args)s)
+    def f(self, %(args)s):
+        return self.%(func_name)s(%(args)s)
     """ % {'args': argspec, 'func_name': func.func_name})
     d = {}
     exec func_code.compile() in d
     else:
         assert isinstance(unwrap_spec, dict)
         unwrap_spec = unwrap_spec.copy()
-    unwrap_spec['w_obj'] = base_cls
+    unwrap_spec['self'] = base_cls
     return interp2app(globals()['unwrap_spec'](**unwrap_spec)(f))
 
 class interp2app(W_Root):

rpython/rlib/rsocket.py

 else:
     def rsocket_startup():
         pass
- 
- 
+
+
 def ntohs(x):
     return rffi.cast(lltype.Signed, _c.ntohs(x))
 
         self.type = type
         self.proto = proto
         self.timeout = defaults.timeout
-        
+
     def __del__(self):
         fd = self.fd
         if fd != _c.INVALID_SOCKET:
             if n == 0:
                 return 1
             return 0
-        
-        
+
+
     def error_handler(self):
         return last_error()
 
             if res < 0:
                 res = errno
             return (res, False)
-        
+
     def connect(self, address):
         """Connect the socket to a remote address."""
         err, timeout = self._connect(address)
             raise SocketTimeout
         if err:
             raise CSocketError(err)
-        
+
     def connect_ex(self, address):
         """This is like connect(address), but returns an error code (the errno
         value) instead of raising an exception when an error occurs."""
                 raise self.error_handler()
             return make_socket(fd, self.family, self.type, self.proto,
                                SocketClass=SocketClass)
-        
+
     def getpeername(self):
         """Return the address of the remote endpoint."""
         address, addr_p, addrlen_p = self._addrbuf()
         """Return the timeout of the socket. A timeout < 0 means that
         timeouts are disabled in the socket."""
         return self.timeout
-    
+
     def listen(self, backlog):
         """Enable a server to accept connections.  The backlog argument
         must be at least 1; it specifies the number of unaccepted connections
     def recvfrom_into(self, rwbuffer, nbytes, flags=0):
         buf, addr = self.recvfrom(nbytes, flags)
         rwbuffer.setslice(0, buf)
-        return len(buf), addr        
+        return len(buf), addr
 
     def send_raw(self, dataptr, length, flags=0):
         """Send data from a CCHARP buffer."""
         else:
             self.timeout = timeout
         self._setblocking(self.timeout < 0.0)
-            
+
     def shutdown(self, how):
         """Shut down the reading side of the socket (flag == SHUT_RD), the
         writing side of the socket (flag == SHUT_WR), or both ends

rpython/rtyper/lltypesystem/rstr.py

             i += 1
         return count
 
-    @classmethod
-    def ll_find(cls, s1, s2, start, end):
+    def ll_find(s1, s2, start, end):
         if start < 0:
             start = 0
         if end > len(s1.chars):
 
         m = len(s2.chars)
         if m == 1:
-            return cls.ll_find_char(s1, s2.chars[0], start, end)
+            return LLHelpers.ll_find_char(s1, s2.chars[0], start, end)
 
-        return cls.ll_search(s1, s2, start, end, FAST_FIND)
+        return LLHelpers.ll_search(s1, s2, start, end, FAST_FIND)
 
-    @classmethod
-    def ll_rfind(cls, s1, s2, start, end):
+    def ll_rfind(s1, s2, start, end):
         if start < 0:
             start = 0
         if end > len(s1.chars):
 
         m = len(s2.chars)
         if m == 1:
-            return cls.ll_rfind_char(s1, s2.chars[0], start, end)
+            return LLHelpers.ll_rfind_char(s1, s2.chars[0], start, end)
 
-        return cls.ll_search(s1, s2, start, end, FAST_RFIND)
+        return LLHelpers.ll_search(s1, s2, start, end, FAST_RFIND)
 
     @classmethod
     def ll_count(cls, s1, s2, start, end):
         item.copy_contents(s, item, i, 0, j - i)
         return res
 
+    def ll_split(LIST, s, c, max):
+        count = 1
+        if max == -1:
+            max = len(s.chars)
+        pos = 0
+        last = len(s.chars)
+        markerlen = len(c.chars)
+        pos = s.find(c, 0, last)
+        while pos >= 0 and count <= max:
+            pos = s.find(c, pos + markerlen, last)
+            count += 1
+        res = LIST.ll_newlist(count)
+        items = res.ll_items()
+        pos = 0
+        count = 0
+        pos = s.find(c, 0, last)
+        prev_pos = 0
+        if pos < 0:
+            items[0] = s
+            return res
+        while pos >= 0 and count < max:
+            item = items[count] = s.malloc(pos - prev_pos)
+            item.copy_contents(s, item, prev_pos, 0, pos -
+                               prev_pos)
+            count += 1
+            prev_pos = pos + markerlen
+            pos = s.find(c, pos + markerlen, last)
+        item = items[count] = s.malloc(last - prev_pos)
+        item.copy_contents(s, item, prev_pos, 0, last - prev_pos)
+        return res
+
     def ll_rsplit_chr(LIST, s, c, max):
         chars = s.chars
         strlen = len(chars)
         item.copy_contents(s, item, j, 0, i - j)
         return res
 
+    def ll_rsplit(LIST, s, c, max):
+        count = 1
+        if max == -1:
+            max = len(s.chars)
+        pos = len(s.chars)
+        markerlen = len(c.chars)
+        pos = s.rfind(c, 0, pos)
+        while pos >= 0 and count <= max:
+            pos = s.rfind(c, 0, pos - markerlen)
+            count += 1
+        res = LIST.ll_newlist(count)
+        items = res.ll_items()
+        pos = 0
+        pos = len(s.chars)
+        prev_pos = pos
+        pos = s.rfind(c, 0, pos)
+        if pos < 0:
+            items[0] = s
+            return res
+        count -= 1
+        while pos >= 0 and count > 0:
+            item = items[count] = s.malloc(prev_pos - pos - markerlen)
+            item.copy_contents(s, item, pos + markerlen, 0,
+                               prev_pos - pos - markerlen)
+            count -= 1
+            prev_pos = pos
+            pos = s.rfind(c, 0, pos)
+        item = items[count] = s.malloc(prev_pos)
+        item.copy_contents(s, item, 0, 0, prev_pos)
+        return res
+
     @jit.elidable
     def ll_replace_chr_chr(s, c1, c2):
         length = len(s.chars)
                               'copy_contents' : staticAdtMethod(copy_string_contents),
                               'copy_contents_from_str' : staticAdtMethod(copy_string_contents),
                               'gethash': LLHelpers.ll_strhash,
-                              'length': LLHelpers.ll_length}))
+                              'length': LLHelpers.ll_length,
+                              'find': LLHelpers.ll_find,
+                              'rfind': LLHelpers.ll_rfind}))
 UNICODE.become(GcStruct('rpy_unicode', ('hash', Signed),
                         ('chars', Array(UniChar, hints={'immutable': True})),
                         adtmeths={'malloc' : staticAdtMethod(mallocunicode),

rpython/rtyper/rstr.py

 
     def rtype_method_split(self, hop):
         rstr = hop.args_r[0].repr
+        v_str = hop.inputarg(rstr.repr, 0)
+        if isinstance(hop.args_s[1], annmodel.SomeString):
+            v_chr = hop.inputarg(rstr.repr, 1)
+            fn = self.ll.ll_split
+        else:
+            v_chr = hop.inputarg(rstr.char_repr, 1)
+            fn = self.ll.ll_split_chr
         if hop.nb_args == 3:
-            v_str, v_chr, v_max = hop.inputargs(rstr.repr, rstr.char_repr, Signed)
+            v_max = hop.inputarg(Signed, 2)
         else:
-            v_str, v_chr = hop.inputargs(rstr.repr, rstr.char_repr)
             v_max = hop.inputconst(Signed, -1)
         try:
             list_type = hop.r_result.lowleveltype.TO
             list_type = hop.r_result.lowleveltype
         cLIST = hop.inputconst(Void, list_type)
         hop.exception_cannot_occur()
-        return hop.gendirectcall(self.ll.ll_split_chr, cLIST, v_str, v_chr, v_max)
+        return hop.gendirectcall(fn, cLIST, v_str, v_chr, v_max)
 
     def rtype_method_rsplit(self, hop):
         rstr = hop.args_r[0].repr
+        v_str = hop.inputarg(rstr.repr, 0)
+        if isinstance(hop.args_s[1], annmodel.SomeString):
+            v_chr = hop.inputarg(rstr.repr, 1)
+            fn = self.ll.ll_rsplit
+        else:
+            v_chr = hop.inputarg(rstr.char_repr, 1)
+            fn = self.ll.ll_rsplit_chr
         if hop.nb_args == 3:
-            v_str, v_chr, v_max = hop.inputargs(rstr.repr, rstr.char_repr, Signed)
+            v_max = hop.inputarg(Signed, 2)
         else:
-            v_str, v_chr = hop.inputargs(rstr.repr, rstr.char_repr)
             v_max = hop.inputconst(Signed, -1)
         try:
             list_type = hop.r_result.lowleveltype.TO
             list_type = hop.r_result.lowleveltype
         cLIST = hop.inputconst(Void, list_type)
         hop.exception_cannot_occur()
-        return hop.gendirectcall(self.ll.ll_rsplit_chr, cLIST, v_str, v_chr, v_max)
+        return hop.gendirectcall(fn, cLIST, v_str, v_chr, v_max)
 
     def rtype_method_replace(self, hop):
         rstr = hop.args_r[0].repr

rpython/rtyper/rtyper.py

                 callee_graph = graph,
                 position_tag = object())
 
-    def convertvar(self, v, r_from, r_to):
-        assert isinstance(v, (Variable, Constant))
+    def convertvar(self, orig_v, r_from, r_to):
+        assert isinstance(orig_v, (Variable, Constant))
         if r_from != r_to:
-            v = pair(r_from, r_to).convert_from_to(v, self)
+            v = pair(r_from, r_to).convert_from_to(orig_v, self)
             if v is NotImplemented:
                 raise TyperError("don't know how to convert from %r to %r" %
                                  (r_from, r_to))
                 raise TyperError("bug in conversion from %r to %r: "
                                  "returned a %r" % (r_from, r_to,
                                                     v.concretetype))
+        else:
+            v = orig_v
         return v
 
     def genop(self, opname, args_v, resulttype=None):

rpython/rtyper/test/test_rstr.py

             res = self.interpret(fn, [i])
             assert res == fn(i)
 
+    def test_split_multichar(self):
+        l = ["abc::z", "abc", "abc::def:::x"]
+        exp = [["abc", "z"], ["abc"], ["abc", "def", ":x"]]
+        exp2 = [["abc", "z"], ["abc"], ["abc", "def:::x"]]
+
+        def f(i):
+            s = l[i]
+            return s.split("::") == exp[i] and s.split("::", 1) == exp2[i]
+
+        for i in range(3):
+            res = self.interpret(f, [i])
+            assert res == True
+
+    def test_rsplit_multichar(self):
+        l = ["abc::z", "abc", "abc::def:::x"]
+        exp = [["abc", "z"], ["abc"], ["abc", "def:", "x"]]
+        exp2 = [["abc", "z"], ["abc"], ["abc::def:", "x"]]
+
+        def f(i):
+            s = l[i]
+            return s.rsplit("::") == exp[i] and s.rsplit("::", 1) == exp2[i]
+
+        for i in range(3):
+            res = self.interpret(f, [i])
+            assert res == True
+
     def test_rsplit(self):
         fn = self._make_split_test('rsplit')
         for i in range(5):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.