From c9f522f082485186dcd8be80186e3c11b55f2b77 Mon Sep 17 00:00:00 2001 From: Christian Tismer Date: Fri, 12 Apr 2019 10:58:02 +0200 Subject: Ensure that signature strings never overflow again The signature module used to use large strings with the signatures of all functions in a class. This can lead to an overflow in MSVC, because the maximum string length funnily still is 32K unicode characters. This patch solves that by using a single string per function. Instead of a huge string, a list of strings is passed to each class. To prevent any runtime increase, the string list creation is deferred until the actual usage. At initialization time only a ssize_t holding the structure address is passed. As a result, the signature module should be even slightly faster. Task-number: PYSIDE-955 Change-Id: I99faf942a3cca03456928b8aec5e8a4b9924b8b2 Reviewed-by: Friedemann Kleint --- .../shiboken2/generator/shiboken2/cppgenerator.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'sources/shiboken2/generator/shiboken2') diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp index b6d3687ac..29220c739 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp @@ -664,7 +664,7 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext) s << NULL_PTR; s << "}," << endl; } - s << INDENT << '{' << NULL_PTR << "} // Sentinel" << endl; + s << INDENT << '{' << NULL_PTR << "} // Sentinel" << endl; s << "};" << endl << endl; } @@ -4924,11 +4924,11 @@ void CppGenerator::writeClassRegister(QTextStream &s, // PYSIDE-510: Create a signatures string for the introspection feature. s << "// The signatures string for the functions." << endl; s << "// Multiple signatures have their index \"n:\" in front." << endl; - s << "const char " << initFunctionName << "_SignaturesString[] = \"\"" << endl; + s << "static const char *" << initFunctionName << "_SignatureStrings[] = {" << endl; QString line; while (signatureStream.readLineInto(&line)) - s << INDENT << '"' << line << "\\n\"" << endl; - s << ';' << endl << endl; + s << INDENT << '"' << line << "\"," << endl; + s << INDENT << NULL_PTR << "}; // Sentinel" << endl << endl; s << "void init_" << initFunctionName; s << "(PyObject* " << enclosingObjectVariable << ")" << endl; s << '{' << endl; @@ -4981,8 +4981,8 @@ void CppGenerator::writeClassRegister(QTextStream &s, // 4:typeSpec s << INDENT << '&' << chopType(pyTypeName) << "_spec," << endl; - // 5:signaturesString - s << INDENT << initFunctionName << "_SignaturesString," << endl; + // 5:signatureStrings + s << INDENT << initFunctionName << "_SignatureStrings," << endl; // 6:cppObjDtor s << INDENT; @@ -5661,11 +5661,11 @@ bool CppGenerator::finishGeneration() // PYSIDE-510: Create a signatures string for the introspection feature. s << "// The signatures string for the global functions." << endl; s << "// Multiple signatures have their index \"n:\" in front." << endl; - s << "const char " << moduleName() << "_SignaturesString[] = \"\"" << endl; + s << "static const char *" << moduleName() << "_SignatureStrings[] = {" << endl; QString line; while (signatureStream.readLineInto(&line)) - s << INDENT << '"' << line << "\\n\"" << endl; - s << INDENT << ';' << endl << endl; + s << INDENT << '"' << line << "\"," << endl; + s << INDENT << NULL_PTR << "}; // Sentinel" << endl << endl; s << "SBK_MODULE_INIT_FUNCTION_BEGIN(" << moduleName() << ")" << endl; @@ -5799,7 +5799,7 @@ bool CppGenerator::finishGeneration() // finish the rest of __signature__ initialization. s << INDENT << "FinishSignatureInitialization(module, " << moduleName() - << "_SignaturesString);" << endl; + << "_SignatureStrings);" << endl; if (usePySideExtensions()) { // initialize the qApp module. -- cgit v1.2.3