]> granicus.if.org Git - python/commitdiff
Fix _sre.CODESIZE on 64-bit machines in UCS-4 mode. Fixes #931848.
authorMartin v. Löwis <martin@v.loewis.de>
Fri, 7 May 2004 07:18:13 +0000 (07:18 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Fri, 7 May 2004 07:18:13 +0000 (07:18 +0000)
Backported to 2.3.

Lib/sre_compile.py
Lib/test/test_re.py
Modules/sre.h

index 7ddc09779a9bcbcc9728666f9f6aff86e921809d..fa21d95f56850d1cab6b572fd9a3f2a4fd77fb8e 100644 (file)
@@ -333,14 +333,16 @@ def _optimize_unicode(charset, fixup):
             block = block + 1
             data = data + _mk_bitmap(chunk)
     header = [block]
-    if MAXCODE == 65535:
+    if _sre.CODESIZE == 2:
         code = 'H'
     else:
-        code = 'L'
+        code = 'I'
     # Convert block indices to byte array of 256 bytes
     mapping = array.array('b', mapping).tostring()
     # Convert byte array to word array
-    header = header + array.array(code, mapping).tolist()
+    mapping = array.array(code, mapping)
+    assert mapping.itemsize == _sre.CODESIZE
+    header = header + mapping.tolist()
     data[0:0] = header
     return [(BIGCHARSET, data)]
 
index 9edca6eb9701afb9cf1e456b97cca427afa75659..2363ce5ee6e3e0998e8ce7accfee5d8b0a3bb6f4 100644 (file)
@@ -497,6 +497,15 @@ class ReTests(unittest.TestCase):
         self.assert_(re.compile('bug_926075') is not
                      re.compile(eval("u'bug_926075'")))
 
+    def test_bug_931848(self):
+        try:
+            unicode
+        except NameError:
+            pass
+        pattern = eval('u"[\u002E\u3002\uFF0E\uFF61]"')
+        self.assertEqual(re.compile(pattern).split("a.b.c"),
+                         ['a','b','c'])
+
 def run_re_tests():
     from test.re_tests import benchmarks, tests, SUCCEED, FAIL, SYNTAX_ERROR
     if verbose:
index ba8500b9c4576d0c1abd2b8a960392a87005efde..45028024665ba50477a87f4dbaf3418d4a1f918f 100644 (file)
@@ -16,7 +16,7 @@
 /* size of a code word (must be unsigned short or larger, and
    large enough to hold a Py_UNICODE character) */
 #ifdef Py_UNICODE_WIDE
-#define SRE_CODE unsigned long
+#define SRE_CODE Py_UCS4
 #else
 #define SRE_CODE unsigned short
 #endif