Don't split long literals at backslash.
authorRobert Bradshaw <robertwb@math.washington.edu>
Fri, 12 Feb 2010 11:20:54 +0000 (03:20 -0800)
committerRobert Bradshaw <robertwb@math.washington.edu>
Fri, 12 Feb 2010 11:20:54 +0000 (03:20 -0800)
Cython/Compiler/Code.py
Cython/Compiler/Nodes.py
Cython/Compiler/StringEncoding.py

index 1e46d2c7359588b4b3ece2a2be2871df76e6f9fb..e7cf8400ed84ede01c3dac86fc55071a05c7f4f7 100644 (file)
@@ -669,7 +669,7 @@ class GlobalState(object):
         decls_writer = self.parts['decls']
         for _, cname, c in c_consts:
             decls_writer.putln('static char %s[] = "%s";' % (
-                cname, StringEncoding.split_docstring(c.escaped_value)))
+                cname, StringEncoding.split_string_literal(c.escaped_value)))
             if c.py_strings is not None:
                 for py_string in c.py_strings.itervalues():
                     py_strings.append((c.cname, len(py_string.cname), py_string))
index 8e271c284823324bbb888d752588e36513e9a26f..fd4460cbb49f44c48d0241dc7c70e1e09e4e9e96 100644 (file)
@@ -22,7 +22,7 @@ from Symtab import ModuleScope, LocalScope, GeneratorLocalScope, \
     StructOrUnionScope, PyClassScope, CClassScope, CppClassScope
 from Cython.Utils import open_new_file, replace_suffix
 from Code import UtilityCode
-from StringEncoding import EncodedString, escape_byte_string, split_docstring
+from StringEncoding import EncodedString, escape_byte_string, split_string_literal
 import Options
 import ControlFlow
 import DebugFlags
@@ -2052,7 +2052,7 @@ class DefNode(FuncDefNode):
             code.putln(
                 'static char %s[] = "%s";' % (
                     self.entry.doc_cname,
-                    split_docstring(escape_byte_string(docstr))))
+                    split_string_literal(escape_byte_string(docstr))))
         if with_pymethdef:
             code.put(
                 "static PyMethodDef %s = " % 
index cd790014391c9871809051a7c6a07b0dc8daadde..059ce3693c95d97f4e12ab2bfbf74224846225f4 100644 (file)
@@ -185,9 +185,9 @@ def escape_byte_string(s):
                 append(c)
         return join_bytes(l).decode('ISO-8859-1')
 
-def split_docstring(s):
+def split_string_literal(s):
     # MSVC can't handle long string literals.
     if len(s) < 2047:
         return s
     else:
-        return '""'.join([s[i:i+2000] for i in range(0, len(s), 2000)])
+        return '""'.join([s[i:i+2000] for i in range(0, len(s), 2000)]).replace(r'\""', '""\\')