summaryrefslogtreecommitdiffstats
path: root/src/tools/qstring.cpp
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2013-03-21 16:20:15 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2013-03-21 16:20:15 -0500
commitd09860faff8dac4c63db6e22eeb556a15c2ffaeb (patch)
treeab7c58168fe33d8af1b9c04284cf38cb6a346139 /src/tools/qstring.cpp
parented9739fcff88bdf26974f4a80cd8df6de410d01a (diff)
downloadqt3-d09860faff8dac4c63db6e22eeb556a15c2ffaeb.tar.gz
qt3-d09860faff8dac4c63db6e22eeb556a15c2ffaeb.zip
Add unpaged memory mode to TQString and TQLineEdit
Fix designer build warnings
Diffstat (limited to 'src/tools/qstring.cpp')
-rw-r--r--src/tools/qstring.cpp79
1 files changed, 77 insertions, 2 deletions
diff --git a/src/tools/qstring.cpp b/src/tools/qstring.cpp
index 24b8164..8717f6a 100644
--- a/src/tools/qstring.cpp
+++ b/src/tools/qstring.cpp
@@ -65,10 +65,18 @@
#if defined(Q_WS_WIN)
#include "qt_windows.h"
#endif
+#if defined(Q_OS_LINUX)
+#include <sys/mman.h>
+#endif
#if !defined( QT_NO_COMPONENT ) && !defined( QT_LITE_COMPONENT )
#include "qcleanuphandler.h"
#endif
+#if defined(Q_OS_LINUX)
+#define LINUX_MEMLOCK_LIMIT_BYTES 16384
+#define LINUX_MEMLOCK_LIMIT_CHARACTERS LINUX_MEMLOCK_LIMIT_BYTES/sizeof(QChar)
+#endif
+
#ifndef LLONG_MAX
#define LLONG_MAX Q_INT64_C(9223372036854775807)
#endif
@@ -1025,6 +1033,14 @@ static inline bool format(QChar::Decomposition tag, QString & str,
} // format()
#endif
+QStringData::~QStringData() {
+ if ( unicode ) delete[] ((char*)unicode);
+ if ( ascii && security_unpaged ) {
+ munlock(ascii, LINUX_MEMLOCK_LIMIT_BYTES);
+ }
+ if ( ascii ) delete[] ascii;
+}
+
/*
QString::compose() and visual() were developed by Gordon Tisher
<tisher@uniserve.ca>, with input from Lars Knoll <knoll@mpi-hd.mpg.de>,
@@ -1203,19 +1219,34 @@ static QChar* internalLatin1ToUnicode( const char *str, uint* len,
}
/*!
+ ABI compatibility
+*/
+
+char* QString::unicodeToLatin1(const QChar *uc, uint l)
+{
+ return unicodeToLatin1(uc, l, false);
+}
+
+/*!
This utility function converts \a l 16-bit characters from \a uc
to ASCII, returning a '\0'-terminated string.
The caller is responsible for deleting the resultant string with
delete[].
*/
-char* QString::unicodeToLatin1(const QChar *uc, uint l)
+
+char* QString::unicodeToLatin1(const QChar *uc, uint l, bool unpaged)
{
if (!uc) {
return 0;
}
char *a = new char[l+1];
char *result = a;
+ if (unpaged) {
+#if defined(Q_OS_LINUX)
+ mlock(result, LINUX_MEMLOCK_LIMIT_BYTES);
+#endif
+ }
while (l--) {
*a++ = (uc->unicode() > 0xff) ? '?' : (char)uc->unicode();
uc++;
@@ -1707,8 +1738,10 @@ void QString::setLength( uint newLen )
if ( nd ) {
uint len = QMIN( d->len, newLen );
memcpy( nd, d->unicode, sizeof(QChar) * len );
+ bool unpaged = d->security_unpaged;
deref();
d = new QStringData( nd, newLen, newMax );
+ setSecurityUnPaged(unpaged);
}
} else {
d->len = newLen;
@@ -1760,8 +1793,10 @@ void QString::reserve( uint minCapacity )
uint len = d->len;
if ( len )
memcpy( nd, d->unicode, sizeof(QChar) * len );
+ bool unpaged = d->security_unpaged;
deref();
d = new QStringData( nd, len, minCapacity );
+ setSecurityUnPaged(unpaged);
}
}
}
@@ -1780,8 +1815,10 @@ void QString::squeeze()
uint len = d->len;
if ( len )
memcpy( nd, d->unicode, sizeof(QChar) * len );
+ bool unpaged = d->security_unpaged;
deref();
d = new QStringData( nd, len, len );
+ setSecurityUnPaged(unpaged);
}
}
}
@@ -2744,9 +2781,11 @@ QString& QString::fill( QChar c, int len )
if ( len == 0 ) {
*this = "";
} else {
+ bool unpaged = d->security_unpaged;
deref();
QChar * nd = QT_ALLOC_QCHAR_VEC( len );
d = new QStringData(nd,len,len);
+ setSecurityUnPaged(unpaged);
while (len--) *nd++ = c;
}
return *this;
@@ -5678,8 +5717,15 @@ QString &QString::operator+=( char c )
const char* QString::latin1() const
{
if ( !d->ascii || !d->islatin1 ) {
+ if (d->security_unpaged) {
+#if defined(Q_OS_LINUX)
+ if (d->ascii) {
+ munlock(d->ascii, LINUX_MEMLOCK_LIMIT_BYTES);
+ }
+#endif
+ }
delete [] d->ascii;
- d->ascii = unicodeToLatin1( d->unicode, d->len );
+ d->ascii = unicodeToLatin1( d->unicode, d->len, d->security_unpaged );
d->islatin1 = TRUE;
}
return d->ascii;
@@ -5699,10 +5745,22 @@ const char* QString::ascii() const
#ifndef QT_NO_TEXTCODEC
if ( QTextCodec::codecForCStrings() ) {
if ( !d->ascii || d->islatin1 ) {
+ if (d->security_unpaged) {
+#if defined(Q_OS_LINUX)
+ if (d->ascii) {
+ munlock(d->ascii, LINUX_MEMLOCK_LIMIT_BYTES);
+ }
+#endif
+ }
delete [] d->ascii;
if (d->unicode) {
QCString s = QTextCodec::codecForCStrings()->fromUnicode( *this );
d->ascii = new char[s.length() + 1];
+ if (d->security_unpaged) {
+#if defined(Q_OS_LINUX)
+ mlock(d->ascii, LINUX_MEMLOCK_LIMIT_BYTES);
+#endif
+ }
memcpy(d->ascii, s.data(), s.length() + 1);
} else {
d->ascii = 0;
@@ -5715,6 +5773,23 @@ const char* QString::ascii() const
return latin1();
}
+void QString::setSecurityUnPaged(bool lock) {
+ if (lock != d->security_unpaged) {
+ if (d->security_unpaged) {
+ if (d->ascii) {
+ munlock(d->ascii, LINUX_MEMLOCK_LIMIT_BYTES);
+ }
+ d->security_unpaged = false;
+ }
+ else {
+ if (d->ascii) {
+ mlock(d->ascii, LINUX_MEMLOCK_LIMIT_BYTES);
+ }
+ d->security_unpaged = true;
+ }
+ }
+}
+
/*!
Returns the string encoded in UTF-8 format.