Author: Armin Rigo <ar...@tunes.org>
Branch: py3.5
Changeset: r86694:c00dea582ece
Date: 2016-08-29 14:36 +0200
http://bitbucket.org/pypy/pypy/changeset/c00dea582ece/

Log:    hg merge py3k

diff --git a/.hgtags b/.hgtags
--- a/.hgtags
+++ b/.hgtags
@@ -28,3 +28,5 @@
 c09c19272c990a0611b17569a0085ad1ab00c8ff release-pypy2.7-v5.3
 7e8df3df96417c16c2d55b41352ec82c9c69c978 release-pypy2.7-v5.3.1
 68bb3510d8212ae9efb687e12e58c09d29e74f87 release-pypy2.7-v5.4.0
+68bb3510d8212ae9efb687e12e58c09d29e74f87 release-pypy2.7-v5.4.0
+77392ad263504df011ccfcabf6a62e21d04086d0 release-pypy2.7-v5.4.0
diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py
--- a/rpython/rlib/rposix.py
+++ b/rpython/rlib/rposix.py
@@ -1159,23 +1159,18 @@
     # 'flags' might be ignored.  Check the result.
     if _WIN32:
         # 'flags' ignored
-        pread  = lltype.malloc(rwin32.LPHANDLE.TO, 1, flavor='raw')
-        pwrite = lltype.malloc(rwin32.LPHANDLE.TO, 1, flavor='raw')
-        try:
-            ok = CreatePipe(
-                    pread, pwrite, lltype.nullptr(rffi.VOIDP.TO), 0)
-            hread = rffi.cast(rffi.INTPTR_T, pread[0])
-            hwrite = rffi.cast(rffi.INTPTR_T, pwrite[0])
-        finally:
-            lltype.free(pwrite, flavor='raw')
-            lltype.free(pread, flavor='raw')
-        if ok:
-            fdread = c_open_osfhandle(hread, 0)
-            fdwrite = c_open_osfhandle(hwrite, 1)
-            if not (fdread == -1 or fdwrite == -1):
-                return (fdread, fdwrite)
-            rwin32.CloseHandle(pread)
-            rwin32.CloseHandle(pwrite)
+        ralloc = lltype.scoped_alloc(rwin32.LPHANDLE.TO, 1)
+        walloc = lltype.scoped_alloc(rwin32.LPHANDLE.TO, 1)
+        with ralloc as pread, walloc as pwrite:
+            if CreatePipe(pread, pwrite, lltype.nullptr(rffi.VOIDP.TO), 0):
+                fdread = c_open_osfhandle(
+                    rffi.cast(rffi.INTPTR_T, pread[0]), 0)
+                fdwrite = c_open_osfhandle(
+                    rffi.cast(rffi.INTPTR_T, pwrite[0]), 1)
+                if not (fdread == -1 or fdwrite == -1):
+                    return (fdread, fdwrite)
+                rwin32.CloseHandle(pread)
+                rwin32.CloseHandle(pwrite)
         raise WindowsError(rwin32.GetLastError_saved(), "CreatePipe failed")
     else:
         filedes = lltype.malloc(INT_ARRAY_P.TO, 2, flavor='raw')
diff --git a/rpython/rlib/rsre/rsre_char.py b/rpython/rlib/rsre/rsre_char.py
--- a/rpython/rlib/rsre/rsre_char.py
+++ b/rpython/rlib/rsre/rsre_char.py
@@ -52,6 +52,7 @@
 SRE_INFO_CHARSET = 4
 SRE_FLAG_LOCALE = 4 # honour system locale
 SRE_FLAG_UNICODE = 32 # use unicode locale
+SRE_FLAG_FULLMATCH = 0x4000   # PyPy extension, for CPython >= 3.4
 
 
 def getlower(char_ord, flags):
diff --git a/rpython/rlib/rsre/rsre_core.py b/rpython/rlib/rsre/rsre_core.py
--- a/rpython/rlib/rsre/rsre_core.py
+++ b/rpython/rlib/rsre/rsre_core.py
@@ -526,9 +526,16 @@
         if op == OPCODE_FAILURE:
             return
 
-        if (op == OPCODE_SUCCESS or
-            op == OPCODE_MAX_UNTIL or
-            op == OPCODE_MIN_UNTIL):
+        elif op == OPCODE_SUCCESS:
+            if ctx.flags & rsre_char.SRE_FLAG_FULLMATCH:
+                if ptr != ctx.end:
+                    return     # not a full match
+            ctx.match_end = ptr
+            ctx.match_marks = marks
+            return MATCHED_OK
+
+        elif (op == OPCODE_MAX_UNTIL or
+              op == OPCODE_MIN_UNTIL):
             ctx.match_end = ptr
             ctx.match_marks = marks
             return MATCHED_OK
@@ -1007,6 +1014,10 @@
     else:
         return None
 
+def fullmatch(pattern, string, start=0, end=sys.maxint, flags=0):
+    return match(pattern, string, start, end,
+                 flags | rsre_char.SRE_FLAG_FULLMATCH)
+
 def search(pattern, string, start=0, end=sys.maxint, flags=0):
     start, end = _adjust(start, end, len(string))
     ctx = StrMatchContext(pattern, string, start, end, flags)
diff --git a/rpython/rlib/rsre/test/test_match.py 
b/rpython/rlib/rsre/test/test_match.py
--- a/rpython/rlib/rsre/test/test_match.py
+++ b/rpython/rlib/rsre/test/test_match.py
@@ -272,3 +272,24 @@
         r = get_code("\\{\\{((?:.*?)+)\\}\\}")
         match = rsre_core.match(r, "{{a}}{{b}}")
         assert match.group(1) == "a"
+
+    def test_fullmatch_1(self):
+        r = get_code(r"ab*c")
+        assert not rsre_core.fullmatch(r, "abbbcdef")
+        assert rsre_core.fullmatch(r, "abbbc")
+
+    def test_fullmatch_2(self):
+        r = get_code(r"a(b*?)")
+        match = rsre_core.fullmatch(r, "abbb")
+        assert match.group(1) == "bbb"
+        assert not rsre_core.fullmatch(r, "abbbc")
+
+    def test_fullmatch_3(self):
+        r = get_code(r"a((bp)*?)c")
+        match = rsre_core.fullmatch(r, "abpbpbpc")
+        assert match.group(1) == "bpbpbp"
+
+    def test_fullmatch_4(self):
+        r = get_code(r"a((bp)*)c")
+        match = rsre_core.fullmatch(r, "abpbpbpc")
+        assert match.group(1) == "bpbpbp"
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to