diff options
author | Giuseppe D'Angelo <dangelog@gmail.com> | 2012-02-23 02:53:08 +0000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-08 22:00:47 +0100 |
commit | b5431419923e8f00e2d8a4a75a20f75f66241842 (patch) | |
tree | b2fcea2e3933c6fa4e4a98afb0b5f41eeb986994 /tests/auto | |
parent | c35d65e27d9232452d2e57973cdb132181440bbf (diff) |
QRegularExpression: improve JIT memory handling
PCRE's JIT uses by default 32K on the pcre_exec caller's stack. This
is fine for most situations, but in some cases (esp. patterns with
lot of recursion) more memory is required.
Therefore, if a match execution fails due to exhausting JIT memory,
we let PCRE allocate up to 512KB to be used for the JIT's stack.
The pointer to the allocated memory is put in thread local storage
(so it can be reused from the same thread, if needed, and automatically
goes away when the thread dies).
Change-Id: Ica5fb7d517068befff88ebb198a603a26ec5d8a7
Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp | 27 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h | 2 |
2 files changed, 29 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp index 72157c0536..38b82ecf77 100644 --- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp +++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp @@ -1196,3 +1196,30 @@ void tst_QRegularExpression::captureCount() if (!re.isValid()) QCOMPARE(re.captureCount(), -1); } + +void tst_QRegularExpression::pcreJitStackUsage_data() +{ + QTest::addColumn<QString>("pattern"); + QTest::addColumn<QString>("subject"); + // these patterns cause enough backtrack (or even infinite recursion) + // in the regexp engine, so that JIT requests more memory. + QTest::newRow("jitstack01") << "(?(R)a*(?1)|((?R))b)" << "aaaabcde"; + QTest::newRow("jitstack02") << "(?(R)a*(?1)|((?R))b)" << "aaaaaaabcde"; +} + +void tst_QRegularExpression::pcreJitStackUsage() +{ + QFETCH(QString, pattern); + QFETCH(QString, subject); + + QRegularExpression re(pattern); + QVERIFY(re.isValid()); + QRegularExpressionMatch match = re.match(subject); + consistencyCheck(match); + QRegularExpressionMatchIterator iterator = re.globalMatch(subject); + consistencyCheck(iterator); + while (iterator.hasNext()) { + match = iterator.next(); + consistencyCheck(match); + } +} diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h index 1a703a8f92..fd8bdfa3af 100644 --- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h +++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h @@ -71,6 +71,8 @@ private slots: void operatoreq(); void captureCount_data(); void captureCount(); + void pcreJitStackUsage_data(); + void pcreJitStackUsage(); private: void provideRegularExpressions(); |