From b5431419923e8f00e2d8a4a75a20f75f66241842 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Thu, 23 Feb 2012 02:53:08 +0000 Subject: 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 Reviewed-by: Thiago Macieira --- .../qregularexpression/tst_qregularexpression.cpp | 27 ++++++++++++++++++++++ .../qregularexpression/tst_qregularexpression.h | 2 ++ 2 files changed, 29 insertions(+) (limited to 'tests/auto') 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("pattern"); + QTest::addColumn("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(); -- cgit v1.2.3