diff options
author | Christian Tismer <tismer@stackless.com> | 2019-04-12 10:58:02 +0200 |
---|---|---|
committer | Christian Tismer <tismer@stackless.com> | 2019-04-16 08:07:38 +0000 |
commit | c9f522f082485186dcd8be80186e3c11b55f2b77 (patch) | |
tree | 24a95c682a4ba6ce712c229228c7b74e733b67f8 /sources/shiboken2/generator | |
parent | e0aa898c068006a7b6aef4cdb0528f2d0b8e0a94 (diff) |
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 <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/shiboken2/generator')
-rw-r--r-- | sources/shiboken2/generator/shiboken2/cppgenerator.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
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. |