summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/animation/qpropertyanimation.cpp7
-rw-r--r--src/corelib/animation/qvariantanimation.cpp65
-rw-r--r--src/corelib/animation/qvariantanimation_p.h4
-rw-r--r--src/corelib/global/qglobal.h33
-rw-r--r--src/corelib/io/qfsfileengine_win.cpp198
-rw-r--r--src/corelib/io/qurl.cpp23
-rw-r--r--src/corelib/io/qurl.h5
-rw-r--r--src/corelib/kernel/qfunctions_wince.cpp7
-rw-r--r--src/corelib/kernel/qvariant.cpp58
-rw-r--r--src/corelib/kernel/qvariant.h2
-rw-r--r--src/corelib/tools/qalgorithms.h17
-rw-r--r--src/corelib/tools/qshareddata.h14
-rw-r--r--src/corelib/tools/qsharedpointer.cpp266
-rw-r--r--src/corelib/tools/qsharedpointer_impl.h76
14 files changed, 529 insertions, 246 deletions
diff --git a/src/corelib/animation/qpropertyanimation.cpp b/src/corelib/animation/qpropertyanimation.cpp
index 598e994..0c1feee 100644
--- a/src/corelib/animation/qpropertyanimation.cpp
+++ b/src/corelib/animation/qpropertyanimation.cpp
@@ -293,7 +293,12 @@ void QPropertyAnimation::updateState(QAbstractAnimation::State oldState,
hash.insert(key, this);
// update the default start value
if (oldState == Stopped) {
- d->setDefaultStartValue(d->target->property(d->propertyName.constData()));
+ d->setDefaultStartEndValue(d->target->property(d->propertyName.constData()));
+ //let's check if we have a start value and an end value
+ if (d->direction == Forward && !startValue().isValid() && !d->defaultStartEndValue.isValid())
+ qWarning("QPropertyAnimation::updateState: starting an animation without start value");
+ if (d->direction == Backward && !endValue().isValid() && !d->defaultStartEndValue.isValid())
+ qWarning("QPropertyAnimation::updateState: starting an animation without end value");
}
} else if (hash.value(key) == this) {
hash.remove(key);
diff --git a/src/corelib/animation/qvariantanimation.cpp b/src/corelib/animation/qvariantanimation.cpp
index e647318..fc11815 100644
--- a/src/corelib/animation/qvariantanimation.cpp
+++ b/src/corelib/animation/qvariantanimation.cpp
@@ -220,52 +220,39 @@ void QVariantAnimationPrivate::updateInterpolator()
*/
void QVariantAnimationPrivate::recalculateCurrentInterval(bool force/*=false*/)
{
- // can't interpolate if we have only 1 key value
- if ((keyValues.count() + (defaultStartValue.isValid() ? 1 : 0)) <=1)
+ // can't interpolate if we don't have at least 2 values
+ if ((keyValues.count() + (defaultStartEndValue.isValid() ? 1 : 0)) < 2)
return;
const qreal progress = easing.valueForProgress(((duration == 0) ? qreal(1) : qreal(currentTime) / qreal(duration)));
- if (force || progress < currentInterval.start.first || progress > currentInterval.end.first) {
+ //0 and 1 are still the boundaries
+ if (force || (currentInterval.start.first > 0 && progress < currentInterval.start.first)
+ || (currentInterval.end.first < 1 && progress > currentInterval.end.first)) {
//let's update currentInterval
QVariantAnimation::KeyValues::const_iterator it = qLowerBound(keyValues.constBegin(),
- keyValues.constEnd(),
- qMakePair(progress, QVariant()),
- animationValueLessThan);
- if (it == keyValues.constEnd()) {
- if (direction == QVariantAnimation::Backward && defaultStartValue.isValid()) {
- --it;
- if (it->first == 1) {
- //we have an end value (item with progress = 1)
- currentInterval.start = *(it-1);
- currentInterval.end = *it;
- } else if (direction == QVariantAnimation::Backward && defaultStartValue.isValid()) {
- //the default start value should be used as the default end value
- currentInterval.start = *it;
- currentInterval.end = qMakePair(qreal(1), defaultStartValue);
- } else {
- ///This should not happen
- }
- }
- } else if (it == keyValues.constBegin()) {
- if (it+1 != keyValues.constEnd() && (it->first == progress || it->first == 0)) {
- //the item pointed to by it is the start element in the range
- //we also test if the current element is for progress 0 (ie the real start) because
- //some easing curves might get the progress below 0.
+ keyValues.constEnd(),
+ qMakePair(progress, QVariant()),
+ animationValueLessThan);
+ if (it == keyValues.constBegin()) {
+ //the item pointed to by it is the start element in the range
+ if (it->first == 0 && keyValues.count() > 1) {
currentInterval.start = *it;
currentInterval.end = *(it+1);
- } else if (defaultStartValue.isValid()) {
- if (direction == QVariantAnimation::Forward) {
- //we should have an end value
- currentInterval.start = qMakePair(qreal(0), defaultStartValue);
- currentInterval.end = *it;
- } else {
- //we should have a start value
- currentInterval.start = *it;
- currentInterval.end = qMakePair(qreal(1), defaultStartValue);
- }
} else {
- ///this should not happen
+ currentInterval.start = qMakePair(qreal(0), defaultStartEndValue);
+ currentInterval.end = *it;
+ }
+ } else if (it == keyValues.constEnd()) {
+ --it; //position the iterator on the last item
+ if (it->first == 1 && keyValues.count() > 1) {
+ //we have an end value (item with progress = 1)
+ currentInterval.start = *(it-1);
+ currentInterval.end = *it;
+ } else {
+ //we use the default end value here
+ currentInterval.start = *it;
+ currentInterval.end = qMakePair(qreal(1), defaultStartEndValue);
}
} else {
currentInterval.start = *(it-1);
@@ -329,9 +316,9 @@ void QVariantAnimationPrivate::setValueAt(qreal step, const QVariant &value)
recalculateCurrentInterval(/*force=*/true);
}
-void QVariantAnimationPrivate::setDefaultStartValue(const QVariant &value)
+void QVariantAnimationPrivate::setDefaultStartEndValue(const QVariant &value)
{
- defaultStartValue = value;
+ defaultStartEndValue = value;
recalculateCurrentInterval(/*force=*/true);
}
diff --git a/src/corelib/animation/qvariantanimation_p.h b/src/corelib/animation/qvariantanimation_p.h
index 9c9d25b..ef57a4c 100644
--- a/src/corelib/animation/qvariantanimation_p.h
+++ b/src/corelib/animation/qvariantanimation_p.h
@@ -76,14 +76,14 @@ public:
return q->d_func();
}
- void setDefaultStartValue(const QVariant &value);
+ void setDefaultStartEndValue(const QVariant &value);
int duration;
QEasingCurve easing;
QVariantAnimation::KeyValues keyValues;
QVariant currentValue;
- QVariant defaultStartValue;
+ QVariant defaultStartEndValue;
//this is used to keep track of the KeyValue interval in which we currently are
struct
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h
index 1b6c3ba..04e171d 100644
--- a/src/corelib/global/qglobal.h
+++ b/src/corelib/global/qglobal.h
@@ -848,6 +848,8 @@ typedef quint64 qulonglong;
&& sizeof(void *) == sizeof(qptrdiff)
*/
template <int> struct QIntegerForSize;
+template <> struct QIntegerForSize<1> { typedef quint8 Unsigned; typedef qint8 Signed; };
+template <> struct QIntegerForSize<2> { typedef quint16 Unsigned; typedef qint16 Signed; };
template <> struct QIntegerForSize<4> { typedef quint32 Unsigned; typedef qint32 Signed; };
template <> struct QIntegerForSize<8> { typedef quint64 Unsigned; typedef qint64 Signed; };
template <class T> struct QIntegerForSizeof: QIntegerForSize<sizeof(T)> { };
@@ -1912,6 +1914,14 @@ public: \
static inline const char *name() { return #TYPE; } \
}
+template <typename T>
+inline void qSwap(T &value1, T &value2)
+{
+ const T t = value1;
+ value1 = value2;
+ value2 = t;
+}
+
/*
Specialize a shared type with:
@@ -1921,33 +1931,12 @@ public: \
types must declare a 'bool isDetached(void) const;' member for this
to work.
*/
-#if defined Q_CC_MSVC && _MSC_VER < 1300
-template <typename T>
-inline void qSwap_helper(T &value1, T &value2, T*)
-{
- T t = value1;
- value1 = value2;
- value2 = t;
-}
#define Q_DECLARE_SHARED(TYPE) \
template <> inline bool qIsDetached<TYPE>(TYPE &t) { return t.isDetached(); } \
-template <> inline void qSwap_helper<TYPE>(TYPE &value1, TYPE &value2, TYPE*) \
-{ \
- const TYPE::DataPtr t = value1.data_ptr(); \
- value1.data_ptr() = value2.data_ptr(); \
- value2.data_ptr() = t; \
-}
-#else
-#define Q_DECLARE_SHARED(TYPE) \
-template <> inline bool qIsDetached<TYPE>(TYPE &t) { return t.isDetached(); } \
-template <typename T> inline void qSwap(T &, T &); \
template <> inline void qSwap<TYPE>(TYPE &value1, TYPE &value2) \
{ \
- const TYPE::DataPtr t = value1.data_ptr(); \
- value1.data_ptr() = value2.data_ptr(); \
- value2.data_ptr() = t; \
+ qSwap<TYPE::DataPtr>(value1.data_ptr(), value2.data_ptr()); \
}
-#endif
/*
QTypeInfo primitive specializations
diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp
index 3394a00..4bae9f4 100644
--- a/src/corelib/io/qfsfileengine_win.cpp
+++ b/src/corelib/io/qfsfileengine_win.cpp
@@ -107,24 +107,15 @@ typedef DWORD (WINAPI *PtrGetNamedSecurityInfoW)(LPWSTR, SE_OBJECT_TYPE, SECURIT
static PtrGetNamedSecurityInfoW ptrGetNamedSecurityInfoW = 0;
typedef BOOL (WINAPI *PtrLookupAccountSidW)(LPCWSTR, PSID, LPWSTR, LPDWORD, LPWSTR, LPDWORD, PSID_NAME_USE);
static PtrLookupAccountSidW ptrLookupAccountSidW = 0;
-typedef BOOL (WINAPI *PtrAllocateAndInitializeSid)(PSID_IDENTIFIER_AUTHORITY, BYTE, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, PSID*);
-static PtrAllocateAndInitializeSid ptrAllocateAndInitializeSid = 0;
typedef VOID (WINAPI *PtrBuildTrusteeWithSidW)(PTRUSTEE_W, PSID);
static PtrBuildTrusteeWithSidW ptrBuildTrusteeWithSidW = 0;
-typedef VOID (WINAPI *PtrBuildTrusteeWithNameW)(PTRUSTEE_W, unsigned short*);
-static PtrBuildTrusteeWithNameW ptrBuildTrusteeWithNameW = 0;
typedef DWORD (WINAPI *PtrGetEffectiveRightsFromAclW)(PACL, PTRUSTEE_W, OUT PACCESS_MASK);
static PtrGetEffectiveRightsFromAclW ptrGetEffectiveRightsFromAclW = 0;
-typedef PVOID (WINAPI *PtrFreeSid)(PSID);
-static PtrFreeSid ptrFreeSid = 0;
static TRUSTEE_W currentUserTrusteeW;
+static TRUSTEE_W worldTrusteeW;
-typedef BOOL (WINAPI *PtrOpenProcessToken)(HANDLE, DWORD, PHANDLE );
-static PtrOpenProcessToken ptrOpenProcessToken = 0;
typedef BOOL (WINAPI *PtrGetUserProfileDirectoryW)(HANDLE, LPWSTR, LPDWORD);
static PtrGetUserProfileDirectoryW ptrGetUserProfileDirectoryW = 0;
-typedef BOOL (WINAPI *PtrSetFilePointerEx)(HANDLE, LARGE_INTEGER, PLARGE_INTEGER, DWORD);
-static PtrSetFilePointerEx ptrSetFilePointerEx = 0;
QT_END_INCLUDE_NAMESPACE
@@ -152,67 +143,37 @@ void QFSFileEnginePrivate::resolveLibs()
if (advapiHnd) {
ptrGetNamedSecurityInfoW = (PtrGetNamedSecurityInfoW)GetProcAddress(advapiHnd, "GetNamedSecurityInfoW");
ptrLookupAccountSidW = (PtrLookupAccountSidW)GetProcAddress(advapiHnd, "LookupAccountSidW");
- ptrAllocateAndInitializeSid = (PtrAllocateAndInitializeSid)GetProcAddress(advapiHnd, "AllocateAndInitializeSid");
ptrBuildTrusteeWithSidW = (PtrBuildTrusteeWithSidW)GetProcAddress(advapiHnd, "BuildTrusteeWithSidW");
- ptrBuildTrusteeWithNameW = (PtrBuildTrusteeWithNameW)GetProcAddress(advapiHnd, "BuildTrusteeWithNameW");
ptrGetEffectiveRightsFromAclW = (PtrGetEffectiveRightsFromAclW)GetProcAddress(advapiHnd, "GetEffectiveRightsFromAclW");
- ptrFreeSid = (PtrFreeSid)GetProcAddress(advapiHnd, "FreeSid");
}
- if (ptrBuildTrusteeWithNameW) {
- HINSTANCE versionHnd = LoadLibraryW(L"version");
- if (versionHnd) {
- typedef DWORD (WINAPI *PtrGetFileVersionInfoSizeW)(LPCWSTR lptstrFilename,LPDWORD lpdwHandle);
- PtrGetFileVersionInfoSizeW ptrGetFileVersionInfoSizeW = (PtrGetFileVersionInfoSizeW)GetProcAddress(versionHnd, "GetFileVersionInfoSizeW");
- typedef BOOL (WINAPI *PtrGetFileVersionInfoW)(LPCWSTR lptstrFilename,DWORD dwHandle,DWORD dwLen,LPVOID lpData);
- PtrGetFileVersionInfoW ptrGetFileVersionInfoW = (PtrGetFileVersionInfoW)GetProcAddress(versionHnd, "GetFileVersionInfoW");
- typedef BOOL (WINAPI *PtrVerQueryValueW)(const LPVOID pBlock,LPCWSTR lpSubBlock,LPVOID *lplpBuffer,PUINT puLen);
- PtrVerQueryValueW ptrVerQueryValueW = (PtrVerQueryValueW)GetProcAddress(versionHnd, "VerQueryValueW");
- if(ptrGetFileVersionInfoSizeW && ptrGetFileVersionInfoW && ptrVerQueryValueW) {
- DWORD fakeHandle;
- DWORD versionSize = ptrGetFileVersionInfoSizeW(L"secur32.dll", &fakeHandle);
- if(versionSize) {
- LPVOID versionData;
- versionData = malloc(versionSize);
- if(ptrGetFileVersionInfoW(L"secur32.dll", 0, versionSize, versionData)) {
- UINT puLen;
- VS_FIXEDFILEINFO *pLocalInfo;
- if(ptrVerQueryValueW(versionData, L"\\", (void**)&pLocalInfo, &puLen)) {
- WORD wVer1, wVer2, wVer3, wVer4;
- wVer1 = HIWORD(pLocalInfo->dwFileVersionMS);
- wVer2 = LOWORD(pLocalInfo->dwFileVersionMS);
- wVer3 = HIWORD(pLocalInfo->dwFileVersionLS);
- wVer4 = LOWORD(pLocalInfo->dwFileVersionLS);
- // It will not work with secur32.dll version 5.0.2195.2862
- if(!(wVer1 == 5 && wVer2 == 0 && wVer3 == 2195 && (wVer4 == 2862 || wVer4 == 4587))) {
- HINSTANCE userHnd = LoadLibraryW(L"secur32");
- if (userHnd) {
- typedef BOOL (WINAPI *PtrGetUserNameExW)(EXTENDED_NAME_FORMAT nameFormat, ushort* lpBuffer, LPDWORD nSize);
- PtrGetUserNameExW ptrGetUserNameExW = (PtrGetUserNameExW)GetProcAddress(userHnd, "GetUserNameExW");
- if(ptrGetUserNameExW) {
- static wchar_t buffer[258];
- DWORD bufferSize = 257;
- ptrGetUserNameExW(NameSamCompatible, (ushort*)buffer, &bufferSize);
- ptrBuildTrusteeWithNameW(&currentUserTrusteeW, (ushort*)buffer);
- }
- FreeLibrary(userHnd);
- }
- }
- }
- }
- free(versionData);
- }
- }
- FreeLibrary(versionHnd);
+ if (ptrBuildTrusteeWithSidW) {
+ // Create TRUSTEE for current user
+ HANDLE hnd = ::GetCurrentProcess();
+ HANDLE token = 0;
+ if (::OpenProcessToken(hnd, TOKEN_QUERY, &token)) {
+ TOKEN_USER tu;
+ DWORD retsize;
+ if (::GetTokenInformation(token, TokenUser, &tu, sizeof(tu), &retsize))
+ ptrBuildTrusteeWithSidW(&currentUserTrusteeW, tu.User.Sid);
+ ::CloseHandle(token);
}
- ptrOpenProcessToken = (PtrOpenProcessToken)GetProcAddress(advapiHnd, "OpenProcessToken");
- HINSTANCE userenvHnd = LoadLibraryW(L"userenv");
- if (userenvHnd) {
- ptrGetUserProfileDirectoryW = (PtrGetUserProfileDirectoryW)GetProcAddress(userenvHnd, "GetUserProfileDirectoryW");
+
+ typedef BOOL (WINAPI *PtrAllocateAndInitializeSid)(PSID_IDENTIFIER_AUTHORITY, BYTE, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, DWORD, PSID*);
+ PtrAllocateAndInitializeSid ptrAllocateAndInitializeSid = (PtrAllocateAndInitializeSid)GetProcAddress(advapiHnd, "AllocateAndInitializeSid");
+ typedef PVOID (WINAPI *PtrFreeSid)(PSID);
+ PtrFreeSid ptrFreeSid = (PtrFreeSid)GetProcAddress(advapiHnd, "FreeSid");
+ if (ptrAllocateAndInitializeSid && ptrFreeSid) {
+ // Create TRUSTEE for Everyone (World)
+ SID_IDENTIFIER_AUTHORITY worldAuth = { SECURITY_WORLD_SID_AUTHORITY };
+ PSID pWorld = 0;
+ if (ptrAllocateAndInitializeSid(&worldAuth, 1, SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0, &pWorld))
+ ptrBuildTrusteeWithSidW(&worldTrusteeW, pWorld);
+ ptrFreeSid(pWorld);
}
- HINSTANCE kernelHnd = LoadLibraryW(L"kernel32");
- if (kernelHnd)
- ptrSetFilePointerEx = (PtrSetFilePointerEx)GetProcAddress(kernelHnd, "SetFilePointerEx");
}
+ HINSTANCE userenvHnd = LoadLibraryW(L"userenv");
+ if (userenvHnd)
+ ptrGetUserProfileDirectoryW = (PtrGetUserProfileDirectoryW)GetProcAddress(userenvHnd, "GetUserProfileDirectoryW");
#endif
}
}
@@ -596,34 +557,27 @@ qint64 QFSFileEnginePrivate::nativePos() const
if (fileHandle == INVALID_HANDLE_VALUE)
return 0;
-#if !defined(QT_NO_LIBRARY) && !defined(Q_OS_WINCE)
- QFSFileEnginePrivate::resolveLibs();
- if (!ptrSetFilePointerEx) {
-#endif
- LARGE_INTEGER filepos;
- filepos.HighPart = 0;
- DWORD newFilePointer = SetFilePointer(fileHandle, 0, &filepos.HighPart, FILE_CURRENT);
- if (newFilePointer == 0xFFFFFFFF && GetLastError() != NO_ERROR) {
- thatQ->setError(QFile::UnspecifiedError, qt_error_string());
- return 0;
- }
-
- // Note: This is the case for MOC, UIC, qmake and other
- // bootstrapped tools, and for Windows CE.
- filepos.LowPart = newFilePointer;
- return filepos.QuadPart;
-#if !defined(QT_NO_LIBRARY) && !defined(Q_OS_WINCE)
- }
-
+#if !defined(Q_OS_WINCE)
LARGE_INTEGER currentFilePos;
LARGE_INTEGER offset;
offset.QuadPart = 0;
- if (!ptrSetFilePointerEx(fileHandle, offset, &currentFilePos, FILE_CURRENT)) {
+ if (!::SetFilePointerEx(fileHandle, offset, &currentFilePos, FILE_CURRENT)) {
thatQ->setError(QFile::UnspecifiedError, qt_error_string());
return 0;
}
return qint64(currentFilePos.QuadPart);
+#else
+ LARGE_INTEGER filepos;
+ filepos.HighPart = 0;
+ DWORD newFilePointer = SetFilePointer(fileHandle, 0, &filepos.HighPart, FILE_CURRENT);
+ if (newFilePointer == 0xFFFFFFFF && GetLastError() != NO_ERROR) {
+ thatQ->setError(QFile::UnspecifiedError, qt_error_string());
+ return 0;
+ }
+
+ filepos.LowPart = newFilePointer;
+ return filepos.QuadPart;
#endif
}
@@ -632,39 +586,32 @@ qint64 QFSFileEnginePrivate::nativePos() const
*/
bool QFSFileEnginePrivate::nativeSeek(qint64 pos)
{
- Q_Q(const QFSFileEngine);
- QFSFileEngine *thatQ = const_cast<QFSFileEngine *>(q);
+ Q_Q(QFSFileEngine);
if (fh || fd != -1) {
// stdlib / stdio mode.
return seekFdFh(pos);
}
-#if !defined(QT_NO_LIBRARY) && !defined(Q_OS_WINCE)
- QFSFileEnginePrivate::resolveLibs();
- if (!ptrSetFilePointerEx) {
-#endif
- DWORD newFilePointer;
- LARGE_INTEGER *li = reinterpret_cast<LARGE_INTEGER*>(&pos);
- newFilePointer = SetFilePointer(fileHandle, li->LowPart, &li->HighPart, FILE_BEGIN);
- if (newFilePointer == 0xFFFFFFFF && GetLastError() != NO_ERROR) {
- thatQ->setError(QFile::PositionError, qt_error_string());
- return false;
- }
-
- // Note: This is the case for MOC, UIC, qmake and other
- // bootstrapped tools, and for Windows CE.
- return true;
-#if !defined(QT_NO_LIBRARY) && !defined(Q_OS_WINCE)
- }
-
+#if !defined(Q_OS_WINCE)
LARGE_INTEGER currentFilePos;
LARGE_INTEGER offset;
offset.QuadPart = pos;
- if (ptrSetFilePointerEx(fileHandle, offset, &currentFilePos, FILE_BEGIN) == 0) {
- thatQ->setError(QFile::UnspecifiedError, qt_error_string());
+ if (!::SetFilePointerEx(fileHandle, offset, &currentFilePos, FILE_BEGIN)) {
+ q->setError(QFile::UnspecifiedError, qt_error_string());
return false;
}
+
+ return true;
+#else
+ DWORD newFilePointer;
+ LARGE_INTEGER *li = reinterpret_cast<LARGE_INTEGER*>(&pos);
+ newFilePointer = SetFilePointer(fileHandle, li->LowPart, &li->HighPart, FILE_BEGIN);
+ if (newFilePointer == 0xFFFFFFFF && GetLastError() != NO_ERROR) {
+ q->setError(QFile::PositionError, qt_error_string());
+ return false;
+ }
+
return true;
#endif
}
@@ -1044,10 +991,10 @@ QString QFSFileEngine::homePath()
QString ret;
#if !defined(QT_NO_LIBRARY)
QFSFileEnginePrivate::resolveLibs();
- if (ptrOpenProcessToken && ptrGetUserProfileDirectoryW) {
+ if (ptrGetUserProfileDirectoryW) {
HANDLE hnd = ::GetCurrentProcess();
HANDLE token = 0;
- BOOL ok = ::ptrOpenProcessToken(hnd, TOKEN_QUERY, &token);
+ BOOL ok = ::OpenProcessToken(hnd, TOKEN_QUERY, &token);
if (ok) {
DWORD dwBufferSize = 0;
// First call, to determine size of the strings (with '\0').
@@ -1393,7 +1340,7 @@ QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions() const
enum { ReadMask = 0x00000001, WriteMask = 0x00000002, ExecMask = 0x00000020 };
resolveLibs();
- if(ptrGetNamedSecurityInfoW && ptrAllocateAndInitializeSid && ptrBuildTrusteeWithSidW && ptrGetEffectiveRightsFromAclW && ptrFreeSid) {
+ if(ptrGetNamedSecurityInfoW && ptrBuildTrusteeWithSidW && ptrGetEffectiveRightsFromAclW) {
QString fname = filePath.endsWith(QLatin1String(".lnk")) ? readLink(filePath) : filePath;
DWORD res = ptrGetNamedSecurityInfoW((wchar_t*)fname.utf16(), SE_FILE_OBJECT,
@@ -1435,21 +1382,14 @@ QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions() const
ret |= QAbstractFileEngine::ExeGroupPerm;
}
{ //other (world)
- // Create SID for Everyone (World)
- SID_IDENTIFIER_AUTHORITY worldAuth = { SECURITY_WORLD_SID_AUTHORITY };
- PSID pWorld = 0;
- if(ptrAllocateAndInitializeSid(&worldAuth, 1, SECURITY_WORLD_RID, 0,0,0,0,0,0,0, &pWorld)) {
- ptrBuildTrusteeWithSidW(&trustee, pWorld);
- if(ptrGetEffectiveRightsFromAclW(pDacl, &trustee, &access_mask) != ERROR_SUCCESS)
- access_mask = (ACCESS_MASK)-1; // ###
- if(access_mask & ReadMask)
- ret |= QAbstractFileEngine::ReadOtherPerm;
- if(access_mask & WriteMask)
- ret |= QAbstractFileEngine::WriteOtherPerm;
- if(access_mask & ExecMask)
- ret |= QAbstractFileEngine::ExeOtherPerm;
- }
- ptrFreeSid(pWorld);
+ if(ptrGetEffectiveRightsFromAclW(pDacl, &worldTrusteeW, &access_mask) != ERROR_SUCCESS)
+ access_mask = (ACCESS_MASK)-1; // ###
+ if(access_mask & ReadMask)
+ ret |= QAbstractFileEngine::ReadOtherPerm;
+ if(access_mask & WriteMask)
+ ret |= QAbstractFileEngine::WriteOtherPerm;
+ if(access_mask & ExecMask)
+ ret |= QAbstractFileEngine::ExeOtherPerm;
}
LocalFree(pSD);
}
@@ -1703,12 +1643,8 @@ bool QFSFileEngine::setPermissions(uint perms)
if (mode == 0) // not supported
return false;
-#if !defined(Q_OS_WINCE)
- ret = ::_wchmod((wchar_t*)d->filePath.utf16(), mode) == 0;
-#else
- ret = ::_wchmod((wchar_t*)d->longFileName(d->filePath).utf16(), mode);
-#endif
- return ret;
+ ret = ::_wchmod((wchar_t*)d->longFileName(d->filePath).utf16(), mode) == 0;
+ return ret;
}
bool QFSFileEngine::setSize(qint64 size)
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp
index 77df601..423f5e2 100644
--- a/src/corelib/io/qurl.cpp
+++ b/src/corelib/io/qurl.cpp
@@ -4024,6 +4024,29 @@ QString QUrlPrivate::createErrorString()
}
/*!
+ \macro QT_NO_URL_CAST_FROM_STRING
+ \relates QUrl
+
+ Disables automatic conversions from QString (or char *) to QUrl.
+
+ Compiling your code with this define is useful when you have a lot of
+ code that uses QString for file names and you wish to convert it to
+ use QUrl for network transparency. In any code that uses QUrl, it can
+ help avoid missing QUrl::resolved() calls, and other misuses of
+ QString to QUrl conversions.
+
+ \oldcode
+ url = filename; // probably not what you want
+ \newcode
+ url = QUrl::fromLocalFile(filename);
+ url = baseurl.resolved(QUrl(filename));
+ \endcode
+
+ \sa QT_NO_CAST_FROM_ASCII
+*/
+
+
+/*!
Constructs a URL by parsing \a url. \a url is assumed to be in human
readable representation, with no percent encoding. QUrl will automatically
percent encode all characters that are not allowed in a URL.
diff --git a/src/corelib/io/qurl.h b/src/corelib/io/qurl.h
index febaf4a..65da5bf 100644
--- a/src/corelib/io/qurl.h
+++ b/src/corelib/io/qurl.h
@@ -81,12 +81,17 @@ public:
Q_DECLARE_FLAGS(FormattingOptions, FormattingOption)
QUrl();
+#ifdef QT_NO_URL_CAST_FROM_STRING
+ explicit
+#endif
QUrl(const QString &url);
QUrl(const QString &url, ParsingMode mode);
// ### Qt 5: merge the two constructors, with mode = TolerantMode
QUrl(const QUrl &copy);
QUrl &operator =(const QUrl &copy);
+#ifndef QT_NO_URL_CAST_FROM_STRING
QUrl &operator =(const QString &url);
+#endif
~QUrl();
void setUrl(const QString &url);
diff --git a/src/corelib/kernel/qfunctions_wince.cpp b/src/corelib/kernel/qfunctions_wince.cpp
index 2b5d4fe..77f680a 100644
--- a/src/corelib/kernel/qfunctions_wince.cpp
+++ b/src/corelib/kernel/qfunctions_wince.cpp
@@ -292,13 +292,14 @@ bool qt_wince__chmod(const char *file, int mode)
bool qt_wince__wchmod(const wchar_t *file, int mode)
{
+ BOOL success = FALSE;
// ### Does not work properly, what about just adding one property?
if(mode&_S_IWRITE) {
- return SetFileAttributes(file, FILE_ATTRIBUTE_NORMAL);
+ success = SetFileAttributes(file, FILE_ATTRIBUTE_NORMAL);
} else if((mode&_S_IREAD) && !(mode&_S_IWRITE)) {
- return SetFileAttributes(file, FILE_ATTRIBUTE_READONLY);
+ success = SetFileAttributes(file, FILE_ATTRIBUTE_READONLY);
}
- return false;
+ return success ? 0 : -1;
}
HANDLE qt_wince_CreateFileA(LPCSTR filename, DWORD access, DWORD share, LPSECURITY_ATTRIBUTES attr, DWORD dispo, DWORD flags, HANDLE tempFile)
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp
index dfed4db..3c430eb 100644
--- a/src/corelib/kernel/qvariant.cpp
+++ b/src/corelib/kernel/qvariant.cpp
@@ -658,6 +658,7 @@ static bool convert(const QVariant::Private *d, QVariant::Type t, void *result,
break;
case QVariant::Url:
*str = v_cast<QUrl>(d)->toString();
+ break;
default:
return false;
}
@@ -935,10 +936,10 @@ static bool convert(const QVariant::Private *d, QVariant::Type t, void *result,
float *f = static_cast<float *>(result);
switch (d->type) {
case QVariant::String:
- *f = float(v_cast<QString>(d)->toDouble(ok));
+ *f = v_cast<QString>(d)->toFloat(ok);
break;
case QVariant::ByteArray:
- *f = float(v_cast<QByteArray>(d)->toDouble(ok));
+ *f = v_cast<QByteArray>(d)->toFloat(ok);
break;
case QVariant::Bool:
*f = float(d->data.b);
@@ -1053,7 +1054,7 @@ static void streamDebug(QDebug dbg, const QVariant &v)
dbg.nospace() << v.toULongLong();
break;
case QMetaType::Float:
- dbg.nospace() << qVariantValue<float>(v);
+ dbg.nospace() << v.toFloat();
break;
case QMetaType::QObjectStar:
dbg.nospace() << qVariantValue<QObject *>(v);
@@ -2330,16 +2331,17 @@ QBitArray QVariant::toBitArray() const
}
template <typename T>
-inline T qNumVariantToHelper(const QVariant::Private &d, QVariant::Type t,
+inline T qNumVariantToHelper(const QVariant::Private &d,
const QVariant::Handler *handler, bool *ok, const T& val)
{
+ uint t = qMetaTypeId<T>();
if (ok)
*ok = true;
if (d.type == t)
return val;
T ret;
- if (!handler->convert(&d, t, &ret, ok) && ok)
+ if (!handler->convert(&d, QVariant::Type(t), &ret, ok) && ok)
*ok = false;
return ret;
}
@@ -2361,7 +2363,7 @@ inline T qNumVariantToHelper(const QVariant::Private &d, QVariant::Type t,
*/
int QVariant::toInt(bool *ok) const
{
- return qNumVariantToHelper<int>(d, Int, handler, ok, d.data.i);
+ return qNumVariantToHelper<int>(d, handler, ok, d.data.i);
}
/*!
@@ -2381,7 +2383,7 @@ int QVariant::toInt(bool *ok) const
*/
uint QVariant::toUInt(bool *ok) const
{
- return qNumVariantToHelper<uint>(d, UInt, handler, ok, d.data.u);
+ return qNumVariantToHelper<uint>(d, handler, ok, d.data.u);
}
/*!
@@ -2396,7 +2398,7 @@ uint QVariant::toUInt(bool *ok) const
*/
qlonglong QVariant::toLongLong(bool *ok) const
{
- return qNumVariantToHelper<qlonglong>(d, LongLong, handler, ok, d.data.ll);
+ return qNumVariantToHelper<qlonglong>(d, handler, ok, d.data.ll);
}
/*!
@@ -2412,7 +2414,7 @@ qlonglong QVariant::toLongLong(bool *ok) const
*/
qulonglong QVariant::toULongLong(bool *ok) const
{
- return qNumVariantToHelper<qulonglong>(d, ULongLong, handler, ok, d.data.ull);
+ return qNumVariantToHelper<qulonglong>(d, handler, ok, d.data.ull);
}
/*!
@@ -2439,7 +2441,7 @@ bool QVariant::toBool() const
/*!
Returns the variant as a double if the variant has type() \l
- Double, \l Bool, \l ByteArray, \l Int, \l LongLong, \l String, \l
+ Double, \l QMetaType::Float, \l Bool, \l ByteArray, \l Int, \l LongLong, \l String, \l
UInt, or \l ULongLong; otherwise returns 0.0.
If \a ok is non-null: \c{*}\a{ok} is set to true if the value could be
@@ -2449,7 +2451,41 @@ bool QVariant::toBool() const
*/
double QVariant::toDouble(bool *ok) const
{
- return qNumVariantToHelper<double>(d, Double, handler, ok, d.data.d);
+ return qNumVariantToHelper<double>(d, handler, ok, d.data.d);
+}
+
+/*!
+ Returns the variant as a float if the variant has type() \l
+ Double, \l QMetaType::Float, \l Bool, \l ByteArray, \l Int, \l LongLong, \l String, \l
+ UInt, or \l ULongLong; otherwise returns 0.0.
+
+ \since 4.6
+
+ If \a ok is non-null: \c{*}\a{ok} is set to true if the value could be
+ converted to a double; otherwise \c{*}\a{ok} is set to false.
+
+ \sa canConvert(), convert()
+*/
+float QVariant::toFloat(bool *ok) const
+{
+ return qNumVariantToHelper<float>(d, handler, ok, d.data.d);
+}
+
+/*!
+ Returns the variant as a qreal if the variant has type() \l
+ Double, \l QMetaType::Float, \l Bool, \l ByteArray, \l Int, \l LongLong, \l String, \l
+ UInt, or \l ULongLong; otherwise returns 0.0.
+
+ \since 4.6
+
+ If \a ok is non-null: \c{*}\a{ok} is set to true if the value could be
+ converted to a double; otherwise \c{*}\a{ok} is set to false.
+
+ \sa canConvert(), convert()
+*/
+qreal QVariant::toReal(bool *ok) const
+{
+ return qNumVariantToHelper<qreal>(d, handler, ok, d.data.d);
}
/*!
diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h
index 569355a..79bd5b8 100644
--- a/src/corelib/kernel/qvariant.h
+++ b/src/corelib/kernel/qvariant.h
@@ -250,6 +250,8 @@ class Q_CORE_EXPORT QVariant
qulonglong toULongLong(bool *ok = 0) const;
bool toBool() const;
double toDouble(bool *ok = 0) const;
+ float toFloat(bool *ok = 0) const;
+ qreal toReal(bool *ok = 0) const;
QByteArray toByteArray() const;
QBitArray toBitArray() const;
QString toString() const;
diff --git a/src/corelib/tools/qalgorithms.h b/src/corelib/tools/qalgorithms.h
index 6f623d9..3e5c3cc 100644
--- a/src/corelib/tools/qalgorithms.h
+++ b/src/corelib/tools/qalgorithms.h
@@ -141,23 +141,6 @@ inline void qCount(const Container &container, const T &value, Size &n)
qCount(container.constBegin(), container.constEnd(), value, n);
}
-
-#if defined Q_CC_MSVC && _MSC_VER < 1300
-template <typename T>
-inline void qSwap(T &value1, T &value2)
-{
- qSwap_helper<T>(value1, value2, (T *)0);
-}
-#else
-template <typename T>
-inline void qSwap(T &value1, T &value2)
-{
- T t = value1;
- value1 = value2;
- value2 = t;
-}
-#endif
-
#ifdef qdoc
template <typename T>
LessThan qLess()
diff --git a/src/corelib/tools/qshareddata.h b/src/corelib/tools/qshareddata.h
index e13e37c..dde6e88 100644
--- a/src/corelib/tools/qshareddata.h
+++ b/src/corelib/tools/qshareddata.h
@@ -111,6 +111,9 @@ public:
inline bool operator!() const { return !d; }
+ inline void swap(QSharedDataPointer &other)
+ { qSwap(d, other.d); }
+
protected:
T *clone();
@@ -186,6 +189,9 @@ public:
inline bool operator!() const { return !d; }
+ inline void swap(QExplicitlySharedDataPointer &other)
+ { qSwap(d, other.d); }
+
protected:
T *clone();
@@ -235,6 +241,14 @@ template <class T>
Q_INLINE_TEMPLATE QExplicitlySharedDataPointer<T>::QExplicitlySharedDataPointer(T *adata) : d(adata)
{ if (d) d->ref.ref(); }
+template <class T>
+Q_INLINE_TEMPLATE void qSwap(QSharedDataPointer<T> &p1, QSharedDataPointer<T> &p2)
+{ p1.swap(p2); }
+
+template <class T>
+Q_INLINE_TEMPLATE void qSwap(QExplicitlySharedDataPointer<T> &p1, QExplicitlySharedDataPointer<T> &p2)
+{ p1.swap(p2); }
+
QT_END_NAMESPACE
QT_END_HEADER
diff --git a/src/corelib/tools/qsharedpointer.cpp b/src/corelib/tools/qsharedpointer.cpp
index e3e1db6..60c7db4 100644
--- a/src/corelib/tools/qsharedpointer.cpp
+++ b/src/corelib/tools/qsharedpointer.cpp
@@ -107,6 +107,249 @@
cases, since they have the same functionality. See
\l{QWeakPointer#tracking-qobject} for more information.
+ \section1 Optional pointer tracking
+
+ A feature of QSharedPointer that can be enabled at compile-time for
+ debugging purposes is a pointer tracking mechanism. When enabled,
+ QSharedPointer registers in a global set all the pointers that it tracks.
+ This allows one to catch mistakes like assigning the same pointer to two
+ QSharedPointer objects.
+
+ This function is enabled by defining the \tt{QT_SHAREDPOINTER_TRACK_POINTERS}
+ macro before including the QSharedPointer header.
+
+ It is safe to use this feature even with code compiled without the
+ feature. QSharedPointer will ensure that the pointer is removed from the
+ tracker even from code compiled without pointer tracking.
+
+ Note, however, that the pointer tracking feature has limitations on
+ multiple- or virtual-inheritance (that is, in cases where two different
+ pointer addresses can refer to the same object). In that case, if a
+ pointer is cast to a different type and its value changes,
+ QSharedPointer's pointer tracking mechanism mail fail to detect that the
+ object being tracked is the same.
+
+ \omit
+ \secton1 QSharedPointer internals
+
+ QSharedPointer is in reality implemented by two ancestor classes:
+ QtSharedPointer::Basic and QtSharedPointer::ExternalRefCount. The reason
+ for having that split is now mostly legacy: in the beginning,
+ QSharedPointer was meant to support both internal reference counting and
+ external reference counting.
+
+ QtSharedPointer::Basic implements the basic functionality that is shared
+ between internal- and external-reference counting. That is, it's mostly
+ the accessor functions into QSharedPointer. Those are all inherited by
+ QSharedPointer, which adds another level of shared functionality (the
+ constructors and assignment operators). The Basic class has one member
+ variable, which is the actual pointer being tracked.
+
+ QtSharedPointer::ExternalRefCount implements the actual reference
+ counting and introduces the d-pointer for QSharedPointer. That d-pointer
+ itself is shared with with other QSharedPointer objects as well as
+ QWeakPointer.
+
+ The reason for keeping the pointer value itself outside the d-pointer is
+ because of multiple inheritance needs. If you have two QSharedPointer
+ objects of different pointer types, but pointing to the same object in
+ memory, it could happen that the pointer values are different. The \tt
+ differentPointers autotest exemplifies this problem. The same thing could
+ happen in the case of virtual inheritance: a pointer of class matching
+ the virtual base has different address compared to the pointer of the
+ complete object. See the \tt virtualBaseDifferentPointers autotest for
+ this problem.
+
+ The d pointer is of type QtSharedPointer::ExternalRefCountData for simple
+ QSharedPointer objects, but could be of a derived type in some cases. It
+ is basically a reference-counted reference-counter.
+
+ \section2 d-pointer
+ \section3 QtSharedPointer::ExternalRefCountData
+
+ This class is basically a reference-counted reference-counter. It has two
+ members: \tt strongref and \tt weakref. The strong reference counter is
+ controlling the lifetime of the object tracked by QSharedPointer. a
+ positive value indicates that the object is alive. It's also the number
+ of QSharedObject instances that are attached to this Data.
+
+ When the strong reference count decreases to zero, the object is deleted
+ (see below for information on custom deleters). The strong reference
+ count can also exceptionally be -1, indicating that there are no
+ QSharedPointers attached to an object, which is tracked too. The only
+ case where this is possible is that of
+ \l{QWeakPointer#tracking-qobject}{QWeakPointers tracking a QObject}.
+
+ The weak reference count controls the lifetime of the d-pointer itself.
+ It can be thought of as an internal/intrusive reference count for
+ ExternalRefCountData itself. This count is equal to the number of
+ QSharedPointers and QWeakPointers that are tracking this object. (In case
+ the object tracked derives from QObject, this number is increased by 1,
+ since QObjectPrivate tracks it too).
+
+ ExternalRefCountData is a virtual class: it has a virtual destructor and
+ a virtual destroy() function. The destroy() function is supposed to
+ delete the object being tracked and return true if it does so. Otherwise,
+ it returns false to indicate that the caller must simply call delete.
+ This allows the normal use-case of QSharedPointer without custom deleters
+ to use only one 12- or 16-byte (depending on whether it's a 32- or 64-bit
+ architecture) external descriptor structure, without paying the price for
+ the custom deleter that it isn't using.
+
+ \section3 QtSharedPointer::ExternalRefCountDataWithDestroyFn
+
+ This class is not used directly, per se. It only exists to enable the two
+ classes that derive from it. It adds one member variable, which is a
+ pointer to a function (which returns void and takes an
+ ExternalRefCountData* as a parameter). It also overrides the destroy()
+ function: it calls that function pointer with \tt this as parameter, and
+ returns true.
+
+ That means when ExternalRefCountDataWithDestroyFn is used, the \tt
+ destroyer field must be set to a valid function that \b will delete the
+ object tracked.
+
+ This class also adds an operator delete function to ensure that simply
+ calls the global operator delete. That should be the behaviour in all
+ compilers already, but to be on the safe side, this class ensures that no
+ funny business happens.
+
+ On a 32-bit architecture, this class is 16 bytes in size, whereas it's 24
+ bytes on 64-bit. (On Itanium where function pointers contain the global
+ pointer, it can be 32 bytes).
+
+ \section3 QtSharedPointer::ExternalRefCountWithCustomDeleter
+
+ This class derives from ExternalRefCountDataWithDestroyFn and is a
+ template class. As template parameters, it has the type of the pointer
+ being tracked (\tt T) and a \tt Deleter, which is anything. It adds two
+ fields to its parent class, matching those template parameters: a member
+ of type \tt Deleter and a member of type \tt T*.
+
+ The purpose of this class is to store the pointer to be deleted and the
+ deleter code along with the d-pointer. This allows the last strong
+ reference to call any arbitrary function that disposes of the object. For
+ example, this allows calling QObject::deleteLater() on a given object.
+ The pointer to the object is kept here to avoid the extra cost of keeping
+ the deleter in the generic case.
+
+ This class is never instantiated directly: the constructors and
+ destructor are private. Only the create() function may be called to
+ return an object of this type. See below for construction details.
+
+ The size of this class depends on the size of \tt Deleter. If it's an
+ empty functor (i.e., no members), ABIs generally assign it the size of 1.
+ But given that it's followed by a pointer, up to 3 or 7 padding bytes may
+ be inserted: in that case, the size of this class is 16+4+4 = 24 bytes on
+ 32-bit architectures, or 24+8+8 = 40 bytes on 64-bit architectures (48
+ bytes on Itanium with global pointers stored). If \tt Deleter is a
+ function pointer, the size should be the same as the empty structure
+ case, except for Itanium where it may be 56 bytes due to another global
+ pointer. If \tt Deleter is a pointer to a member function (PMF), the size
+ will be even bigger and will depend on the ABI. For architectures using
+ the Itanium C++ ABI, a PMF is twice the size of a normal pointer, or 24
+ bytes on Itanium itself. In that case, the size of this structure will be
+ 16+8+4 = 28 bytes on 32-bit architectures, 24+16+8 = 48 bytes on 64-bit,
+ and 32+24+8 = 64 bytes on Itanium.
+
+ (Values for Itanium consider an LP64 architecture; for ILP32, pointers
+ are 32-bit in length, function pointers are 64-bit and PMF are 96-bit, so
+ the sizes are slightly less)
+
+ \section3 QtSharedPointer::ExternalRefCountWithContiguousData
+
+ This class also derives from ExternalRefCountDataWithDestroyFn and it is
+ also a template class. The template parameter is the type \tt T of the
+ class which QSharedPointer tracks. It adds only one member to its parent,
+ which is of type \tt T (the actual type, not a pointer to it).
+
+ The purpose of this class is to lay the \tt T object out next to the
+ reference counts, saving one memory allocation per shared pointer. This
+ is particularly interesting for small \tt T or for the cases when there
+ are few if any QWeakPointer tracking the object. This class exists to
+ implement the QSharedPointer::create() call.
+
+ Like ExternalRefCountWithCustomDeleter, this class is never instantiated
+ directly. This class also provides a create() member that returns the
+ pointer, and hides its constructors and destructor. (With C++0x, we'd
+ delete them).
+
+ The size of this class depends on the size of \tt T.
+
+ \section3 Instantiating ExternalRefCountWithCustomDeleter and ExternalRefCountWithContiguousData
+
+ Like explained above, these classes have private constructors. Moreover,
+ they are not defined anywhere, so trying to call \tt{new ClassType} would
+ result in a compilation or linker error. Instead, these classes must be
+ constructed via their create() methods.
+
+ Instead of instantiating the class by the normal way, the create() method
+ calls \tt{operator new} directly with the size of the class, then calls
+ the parent class's constructor only (ExternalRefCountDataWithDestroyFn).
+ This ensures that the inherited members are initialised properly, as well
+ as the virtual table pointer, which must point to
+ ExternalRefCountDataWithDestroyFn's virtual table. That way, we also
+ ensure that the virtual destructor being called is
+ ExternalRefCountDataWithDestroyFn's.
+
+ After initialising the base class, the
+ ExternalRefCountWithCustomDeleter::create() function initialises the new
+ members directly, by using the placement \tt{operator new}. In the case
+ of the ExternalRefCountWithContiguousData::create() function, the address
+ to the still-uninitialised \tt T member is saved for the callee to use.
+ The member is only initialised in QSharedPointer::create(), so that we
+ avoid having many variants of the internal functions according to the
+ arguments in use for calling the constructor.
+
+ When initialising the parent class, the create() functions pass the
+ address of the static deleter() member function. That is, when the
+ virtual destroy() is called by QSharedPointer, the deleter() functions
+ are called instead. These functiosn static_cast the ExternalRefCountData*
+ parameter to their own type and execute their deletion: for the
+ ExternalRefCountWithCustomDeleter::deleter() case, it runs the user's
+ custom deleter, then destroys the deleter; for
+ ExternalRefCountWithContiguousData::deleter, it simply calls the \tt T
+ destructor directly.
+
+ By not calling the constructor of the derived classes, we avoid
+ instantiating their virtual tables. Since these classes are
+ template-based, there would be one virtual table per \tt T and \tt
+ Deleter type. (This is what Qt 4.5 did)
+
+ Instead, only one non-inline function is required per template, which is
+ the deleter() static member. All the other functions can be inlined.
+ What's more, the address of deleter() is calculated only in code, which
+ can be resolved at link-time if the linker can determine that the
+ function lies in the current application or library module (since these
+ classes are not exported, that is the case for Windows or for builds with
+ \tt{-fvisibility=hidden}).
+
+ In contrast, a virtual table would require at least 3 relocations to be
+ resolved at module load-time, per module where these classes are used.
+ (In the Itanium C++ ABI, there would be more relocations, due to the
+ RTTI)
+
+ \section3 Modifications due to pointer-tracking
+
+ To ensure that pointers created with pointer-tracking enabled get
+ un-tracked when destroyed, even if destroyed by code compiled without the
+ feature, QSharedPointer modifies slightly the instructions of the
+ previous sections.
+
+ When ExternalRefCountWithCustomDeleter or
+ ExternalRefCountWithContiguousData are used, their create() functions
+ will set the ExternalRefCountDataWithDestroyFn::destroyer function
+ pointer to safetyCheckDeleter() instead. These static member functions
+ simply call internalSafetyCheckRemove2() before passing control to the
+ normal deleter() function.
+
+ If neither custom deleter nor QSharedPointer::create() are used, then
+ QSharedPointer uses a custom deleter of its own: the normalDeleter()
+ function, which simply calls \tt delete. By using a custom deleter, the
+ safetyCheckDeleter() procedure described above kicks in.
+
+ \endomit
+
\sa QSharedDataPointer, QWeakPointer
*/
@@ -182,6 +425,29 @@
QWeakPointers created from QObject should never be passed to code that
hasn't been recompiled.
+ \omit
+ \secton1 QWeakPointer internals
+
+ QWeakPointer shares most of its internal functionality with
+ \l{QSharedPointer#qsharedpointer-internals}{QSharedPointer}, so see that
+ class's internal documentation for more information.
+
+ QWeakPointer requires an external reference counter in order to operate.
+ Therefore, it is incompatible by design with \l QSharedData-derived
+ classes.
+
+ It has a special QObject constructor, which works by calling
+ QtSharedPointer::ExternalRefCountData::getAndRef, which retrieves the
+ d-pointer from QObjectPrivate. If one isn't set yet, that function
+ creates the d-pointer and atomically sets it.
+
+ If getAndRef needs to create a d-pointer, it sets the strongref to -1,
+ indicating that the QObject is not shared: QWeakPointer is used only to
+ determine whether the QObject has been deleted. In that case, it cannot
+ be upgraded to QSharedPointer (see the previous section).
+
+ \endomit
+
\sa QSharedPointer
*/
diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h
index ba479f9..1136aa9 100644
--- a/src/corelib/tools/qsharedpointer_impl.h
+++ b/src/corelib/tools/qsharedpointer_impl.h
@@ -115,6 +115,9 @@ namespace QtSharedPointer {
template <class T> struct RemovePointer<QSharedPointer<T> > { typedef T Type; };
template <class T> struct RemovePointer<QWeakPointer<T> > { typedef T Type; };
+ // This class provides the basic functionality of a pointer wrapper.
+ // Its existence is mostly legacy, since originally QSharedPointer
+ // could also be used for internally-refcounted objects.
template <class T>
class Basic
{
@@ -155,6 +158,12 @@ namespace QtSharedPointer {
Type *value;
};
+ // This class is the d-pointer of QSharedPointer and QWeakPointer.
+ //
+ // It is a reference-counted reference counter. "strongref" is the inner
+ // reference counter, and it tracks the lifetime of the pointer itself.
+ // "weakref" is the outer reference counter and it tracks the lifetime of
+ // the ExternalRefCountData object.
struct ExternalRefCountData
{
QBasicAtomicInt weakref;
@@ -162,12 +171,15 @@ namespace QtSharedPointer {
inline ExternalRefCountData()
{
- QBasicAtomicInt proto = Q_BASIC_ATOMIC_INITIALIZER(1);
- weakref = strongref = proto;
+ strongref = 1;
+ weakref = 1;
}
inline ExternalRefCountData(Qt::Initialization) { }
virtual inline ~ExternalRefCountData() { Q_ASSERT(!weakref); Q_ASSERT(strongref <= 0); }
+ // overridden by derived classes
+ // returns false to indicate caller should delete the pointer
+ // returns true in case it has already done so
virtual inline bool destroy() { return false; }
#ifndef QT_NO_QOBJECT
@@ -178,18 +190,8 @@ namespace QtSharedPointer {
};
// sizeof(ExternalRefCount) = 12 (32-bit) / 16 (64-bit)
- template <class T, typename Deleter>
- struct CustomDeleter
- {
- Deleter deleter;
- T *ptr;
-
- inline CustomDeleter(T *p, Deleter d) : deleter(d), ptr(p) {}
- };
- // sizeof(CustomDeleter) = sizeof(Deleter) + sizeof(void*)
- // for Deleter = function pointer: 8 (32-bit) / 16 (64-bit)
- // for Deleter = PMF: 12 (32-bit) / 24 (64-bit) (GCC)
-
+ // This class extends ExternalRefCountData with a pointer
+ // to a function, which is called by the destroy() function.
struct ExternalRefCountWithDestroyFn: public ExternalRefCountData
{
typedef void (*DestroyerFn)(ExternalRefCountData *);
@@ -204,13 +206,26 @@ namespace QtSharedPointer {
};
// sizeof(ExternalRefCountWithDestroyFn) = 16 (32-bit) / 24 (64-bit)
+ // This class extends ExternalRefCountWithDestroyFn and implements
+ // the static function that deletes the object. The pointer and the
+ // custom deleter are kept in the "extra" member.
template <class T, typename Deleter>
struct ExternalRefCountWithCustomDeleter: public ExternalRefCountWithDestroyFn
{
typedef ExternalRefCountWithCustomDeleter Self;
- typedef ExternalRefCountWithDestroyFn Parent;
- typedef CustomDeleter<T, Deleter> Next;
- Next extra;
+ typedef ExternalRefCountWithDestroyFn BaseClass;
+
+ struct CustomDeleter
+ {
+ Deleter deleter;
+ T *ptr;
+
+ inline CustomDeleter(T *p, Deleter d) : deleter(d), ptr(p) {}
+ };
+ CustomDeleter extra;
+ // sizeof(CustomDeleter) = sizeof(Deleter) + sizeof(void*)
+ // for Deleter = function pointer: 8 (32-bit) / 16 (64-bit)
+ // for Deleter = PMF: 12 (32-bit) / 24 (64-bit) (GCC)
static inline void deleter(ExternalRefCountData *self)
{
@@ -218,7 +233,7 @@ namespace QtSharedPointer {
executeDeleter(realself->extra.ptr, realself->extra.deleter);
// delete the deleter too
- realself->extra.~Next();
+ realself->extra.~CustomDeleter();
}
static void safetyCheckDeleter(ExternalRefCountData *self)
{
@@ -236,8 +251,8 @@ namespace QtSharedPointer {
Self *d = static_cast<Self *>(::operator new(sizeof(Self)));
// initialize the two sub-objects
- new (&d->extra) Next(ptr, userDeleter);
- new (d) Parent(destroy); // can't throw
+ new (&d->extra) CustomDeleter(ptr, userDeleter);
+ new (d) BaseClass(destroy); // can't throw
return d;
}
@@ -247,6 +262,10 @@ namespace QtSharedPointer {
~ExternalRefCountWithCustomDeleter();
};
+ // This class extends ExternalRefCountWithDestroyFn and adds a "T"
+ // member. That way, when the create() function is called, we allocate
+ // memory for both QSharedPointer's d-pointer and the actual object being
+ // tracked.
template <class T>
struct ExternalRefCountWithContiguousData: public ExternalRefCountWithDestroyFn
{
@@ -289,6 +308,8 @@ namespace QtSharedPointer {
~ExternalRefCountWithContiguousData();
};
+ // This is the main body of QSharedPointer. It implements the
+ // external reference counting functionality.
template <class T>
class ExternalRefCount: public Basic<T>
{
@@ -364,6 +385,12 @@ namespace QtSharedPointer {
delete this->value;
}
+ inline void internalSwap(ExternalRefCount &other)
+ {
+ qSwap(d, other.d);
+ qSwap(this->value, other.value);
+ }
+
#if defined(Q_NO_TEMPLATE_FRIENDS)
public:
#else
@@ -444,6 +471,9 @@ public:
inline QSharedPointer<T> &operator=(const QWeakPointer<X> &other)
{ internalSet(other.d, other.value); return *this; }
+ inline void swap(QSharedPointer &other)
+ { internalSwap(other); }
+
template <class X>
QSharedPointer<X> staticCast() const
{
@@ -661,6 +691,12 @@ Q_INLINE_TEMPLATE QWeakPointer<T> QSharedPointer<T>::toWeakRef() const
return QWeakPointer<T>(*this);
}
+template <class T>
+inline void qSwap(QSharedPointer<T> &p1, QSharedPointer<T> &p2)
+{
+ p1.swap(p2);
+}
+
namespace QtSharedPointer {
// helper functions:
template <class X, class T>