D8544: KTextEditor : avoiding QML crashes

René J.V. Bertin noreply at phabricator.kde.org
Sun Oct 29 13:47:29 UTC 2017


rjvbb created this revision.
rjvbb added a reviewer: Frameworks.
rjvbb added a project: KTextEditor.
Restricted Application added projects: Kate, Frameworks.

REVISION SUMMARY
  The transition from QtScript to QML introduced a propensity to crashing somewhere deep in Qt (in the V4 JIT engine to be exact), at often unexpected moments while editing texts, for users of certain versions of Qt5. It seems these crashes do not occur with Qt 5.9.1 and newer, but not everyone can update (readily) to that version.
  
  Upstream bug report: https://bugreports.qt.io/browse/QTBUG-63045
  
  I have tried to trace the JavaScript expressions that trigger the crashes I've seen myself, come up with a fix or at least a suitable and acceptable workaround (see https://bugs.kde.org/show_bug.cgi?id=385413). This review is for a patch that contains a fix for a specific crash as well as a general workaround.
  
  As far as I can tell the crashes I get (when hitting enter at the end of a line in documents using C style indentation) occur when unwinding the script interpreter stack, for instance when exiting from a `while` loop (or the equivalent `for` loop). This particular crash can be avoided by returning early from the procedure containing the loop, instead of exiting from the loop and returning via the shared return statement; see the patch to `cstyle.js`.
  
  Gentoo have come up with a blunt-force "solution": build QtDeclarative with the V4 JIT disabled. It works just as well to launch applications that are susceptible to the crash with the `QV4_FORCE_INTERPRETER` env. variable set which has less undesirable effects but is also more cumbersome.
  My patch explores an even less invasive approach: it uses the env. variable to disable the JIT when KTextEditor scripts are loaded/parsed, resetting (or unsetting) the variable when the crucial operation is done. The env.var manipulation is done in a dedicated KateScript subclass and is a noop for Qt version 5.9.1 and up.
  
  BUG: 385413

TEST PLAN
  Tested on Mac and Linux with Qt 5.8.0 . This works for me (read: I haven't seen any other crashes - yet!) but apparently does not prevent crashing with Qt 5.7.1 (see the Qt bug report referenced in the summary).
  
  If necessary we can of course disable the JIT proactively in a KTextEditor initialiser routine (if possible reenabling it for plugins).

REPOSITORY
  R39 KTextEditor

REVISION DETAIL
  https://phabricator.kde.org/D8544

AFFECTED FILES
  src/script/data/indentation/cstyle.js
  src/script/katecommandlinescript.cpp
  src/script/kateindentscript.cpp
  src/script/katescript.cpp
  src/script/katescript.h
  src/script/katescripthelpers.cpp

To: rjvbb, #frameworks
Cc: kde-frameworks-devel, kevinapavew, demsking, head7, cullmann, kfunk, sars, dhaumann
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-frameworks-devel/attachments/20171029/0a9243d4/attachment.html>


More information about the Kde-frameworks-devel mailing list