From: Robert Bradshaw Date: Fri, 12 Feb 2010 11:20:54 +0000 (-0800) Subject: Don't split long literals at backslash. X-Git-Tag: 0.13.beta0~340^2~13 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=fabe1ee50cbb8d272fa834fc61cb88db06d44a79;p=cython.git Don't split long literals at backslash. --- diff --git a/Cython/Compiler/Code.py b/Cython/Compiler/Code.py index 1e46d2c7..e7cf8400 100644 --- a/Cython/Compiler/Code.py +++ b/Cython/Compiler/Code.py @@ -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)) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 8e271c28..fd4460cb 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -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 = " % diff --git a/Cython/Compiler/StringEncoding.py b/Cython/Compiler/StringEncoding.py index cd790014..059ce369 100644 --- a/Cython/Compiler/StringEncoding.py +++ b/Cython/Compiler/StringEncoding.py @@ -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'\""', '""\\')