Q*GlyphCache: de-inline dtor and export vtable

The destructor is the first virtual method. By not defining it
out-of-line, we provoke multiple copies of vtables, not all of
which can be merged by the linker. If the linker fails, RTTI
such as dynamic_cast and catch-blocks involving the type will
not work.

Additionally, QFontEngineGlyphCache was not exported, and
therefore also not its vtable, making it impossible for
users outside of QtGui to get a unique RTTI for the class.

Change-Id: Ib265945934216bb609629431eb4c71996d4fd39d
Reported-by: Volker Krause <volker.krause@kdab.com>
Task-number: QTBUG-45582
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
This commit is contained in:
Marc Mutz 2015-04-14 09:37:58 +02:00
parent 10d53a3f0e
commit 16b95b65a6
5 changed files with 59 additions and 3 deletions

View File

@ -42,6 +42,11 @@ QT_BEGIN_NAMESPACE
// #define CACHE_DEBUG
// out-of-line to avoid vtable duplication, breaking e.g. RTTI
QTextureGlyphCache::~QTextureGlyphCache()
{
}
int QTextureGlyphCache::calculateSubPixelPositionCount(glyph_t glyph) const
{
// Test 12 different subpixel positions since it factors into 3*4 so it gives
@ -262,6 +267,11 @@ QImage QTextureGlyphCache::textureMapForGlyph(glyph_t g, QFixed subPixelPosition
* QImageTextureGlyphCache
*/
// out-of-line to avoid vtable duplication, breaking e.g. RTTI
QImageTextureGlyphCache::~QImageTextureGlyphCache()
{
}
void QImageTextureGlyphCache::resizeTextureData(int width, int height)
{
m_image = m_image.copy(0, 0, width, height);

View File

@ -72,7 +72,7 @@ public:
m_w(0), m_h(0), m_cx(0), m_cy(0), m_currentRowHeight(0)
{ }
virtual ~QTextureGlyphCache() { }
~QTextureGlyphCache();
struct GlyphAndSubPixelPosition
{
@ -158,6 +158,8 @@ class Q_GUI_EXPORT QImageTextureGlyphCache : public QTextureGlyphCache
public:
QImageTextureGlyphCache(QFontEngine::GlyphFormat format, const QTransform &matrix)
: QTextureGlyphCache(format, matrix) { }
~QImageTextureGlyphCache();
virtual void createTextureData(int width, int height) Q_DECL_OVERRIDE;
virtual void resizeTextureData(int width, int height) Q_DECL_OVERRIDE;
virtual void fillTexture(const Coord &c, glyph_t glyph, QFixed subPixelPosition) Q_DECL_OVERRIDE;

View File

@ -0,0 +1,43 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <private/qfontengineglyphcache_p.h>
QT_BEGIN_NAMESPACE
// out-of-line to avoid vtable duplication, breaking e.g. RTTI
QFontEngineGlyphCache::~QFontEngineGlyphCache()
{
}
QT_END_NAMESPACE

View File

@ -56,7 +56,7 @@
QT_BEGIN_NAMESPACE
class QFontEngineGlyphCache: public QSharedData
class Q_GUI_EXPORT QFontEngineGlyphCache: public QSharedData
{
public:
QFontEngineGlyphCache(QFontEngine::GlyphFormat format, const QTransform &matrix) : m_format(format), m_transform(matrix)
@ -64,7 +64,7 @@ public:
Q_ASSERT(m_format != QFontEngine::Format_None);
}
virtual ~QFontEngineGlyphCache() { }
virtual ~QFontEngineGlyphCache();
QFontEngine::GlyphFormat glyphFormat() const { return m_format; }
const QTransform &transform() const { return m_transform; }

View File

@ -47,6 +47,7 @@ HEADERS += \
SOURCES += \
text/qfont.cpp \
text/qfontengine.cpp \
text/qfontengineglyphcache.cpp \
text/qfontsubset.cpp \
text/qfontmetrics.cpp \
text/qfontdatabase.cpp \