Android: De-duplicate vtables of exported private classes

By making the destructor (usually the first non-inline, non-pure,
virtual function, and therefore the trigger for most compilers to emit
the vtable and type_info structures for the class in that TU)
out-of-line, vtables and, more importantly, type_info structures for
the class are pinned to a single TU. This prevents false-negative
dynamic_cast and catch evaluation.

Since the classes are already exported, users of these classes are
unaffected by the change, and since it's private API, we don't need to
avoid adding code to the out-of-line destructor until Qt 6.

While at it, de-inline also the empty default implementations of
virtual (non-dtor) functions.

Task-number: QTBUG-45582
Change-Id: I3e6f37eab1dee0db445f6c13638a43ca3bf6ac62
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2015-06-01 00:22:35 +02:00
parent ee0edf1b0a
commit 5486882b52
2 changed files with 19 additions and 7 deletions

View File

@ -52,6 +52,18 @@
QT_BEGIN_NAMESPACE
namespace QtAndroidPrivate {
// *Listener virtual function implementations.
// Defined out-of-line to pin the vtable/type_info.
ActivityResultListener::~ActivityResultListener() {}
NewIntentListener::~NewIntentListener() {}
ResumePauseListener::~ResumePauseListener() {}
void ResumePauseListener::handlePause() {}
void ResumePauseListener::handleResume() {}
GenericMotionEventListener::~GenericMotionEventListener() {}
KeyEventListener::~KeyEventListener() {}
}
static JavaVM *g_javaVM = Q_NULLPTR;
static jobject g_jActivity = Q_NULLPTR;
static jobject g_jService = Q_NULLPTR;

View File

@ -65,36 +65,36 @@ namespace QtAndroidPrivate
class Q_CORE_EXPORT ActivityResultListener
{
public:
virtual ~ActivityResultListener() {}
virtual ~ActivityResultListener();
virtual bool handleActivityResult(jint requestCode, jint resultCode, jobject data) = 0;
};
class Q_CORE_EXPORT NewIntentListener
{
public:
virtual ~NewIntentListener() {}
virtual ~NewIntentListener();
virtual bool handleNewIntent(JNIEnv *env, jobject intent) = 0;
};
class Q_CORE_EXPORT ResumePauseListener
{
public:
virtual ~ResumePauseListener() {}
virtual void handlePause() {};
virtual void handleResume() {};
virtual ~ResumePauseListener();
virtual void handlePause();
virtual void handleResume();
};
class Q_CORE_EXPORT GenericMotionEventListener
{
public:
virtual ~GenericMotionEventListener() {}
virtual ~GenericMotionEventListener();
virtual bool handleGenericMotionEvent(jobject event) = 0;
};
class Q_CORE_EXPORT KeyEventListener
{
public:
virtual ~KeyEventListener() {}
virtual ~KeyEventListener();
virtual bool handleKeyEvent(jobject event) = 0;
};