summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/global/qglobalstatic.h2
-rw-r--r--src/corelib/io/qfilesystemengine.cpp14
-rw-r--r--src/corelib/io/qfilesystemengine_win.cpp5
-rw-r--r--src/corelib/io/qprocess.cpp23
-rw-r--r--src/corelib/io/qprocess_p.h2
-rw-r--r--src/corelib/io/qprocess_unix.cpp35
-rw-r--r--src/corelib/io/qprocess_win.cpp10
-rw-r--r--src/corelib/io/qprocess_wince.cpp6
-rw-r--r--src/corelib/io/qwindowspipewriter.cpp41
-rw-r--r--src/corelib/io/qwindowspipewriter_p.h4
-rw-r--r--src/corelib/kernel/qobject.cpp8
-rw-r--r--src/corelib/plugin/qplugin.qdoc6
-rw-r--r--src/corelib/thread/qthread.cpp6
-rw-r--r--src/corelib/thread/qthread_p.h1
-rw-r--r--src/corelib/thread/qthread_unix.cpp33
15 files changed, 108 insertions, 88 deletions
diff --git a/src/corelib/global/qglobalstatic.h b/src/corelib/global/qglobalstatic.h
index 4fb3c4f91f..7a6dea9b92 100644
--- a/src/corelib/global/qglobalstatic.h
+++ b/src/corelib/global/qglobalstatic.h
@@ -116,7 +116,7 @@ QT_BEGIN_NAMESPACE
guard.store(QtGlobalStatic::Destroyed); \
} \
} cleanup; \
- guard.store(QtGlobalStatic::Initialized); \
+ guard.storeRelease(QtGlobalStatic::Initialized); \
} \
} \
return d; \
diff --git a/src/corelib/io/qfilesystemengine.cpp b/src/corelib/io/qfilesystemengine.cpp
index 2dad56befd..fd8f251ccb 100644
--- a/src/corelib/io/qfilesystemengine.cpp
+++ b/src/corelib/io/qfilesystemengine.cpp
@@ -264,7 +264,7 @@ void QFileSystemMetaData::fillFromStatBuf(const QT_STATBUF &statBuffer)
entryFlags |= QFileSystemMetaData::FileType;
else if ((statBuffer.st_mode & S_IFMT) == S_IFDIR)
entryFlags |= QFileSystemMetaData::DirectoryType;
- else
+ else if ((statBuffer.st_mode & S_IFMT) != S_IFBLK)
entryFlags |= QFileSystemMetaData::SequentialType;
// Attributes
@@ -347,6 +347,18 @@ void QFileSystemMetaData::fillFromDirEnt(const QT_DIRENT &entry)
break;
case DT_BLK:
+ knownFlagsMask = QFileSystemMetaData::LinkType
+ | QFileSystemMetaData::FileType
+ | QFileSystemMetaData::DirectoryType
+ | QFileSystemMetaData::BundleType
+ | QFileSystemMetaData::AliasType
+ | QFileSystemMetaData::SequentialType
+ | QFileSystemMetaData::ExistsAttribute;
+
+ entryFlags = QFileSystemMetaData::ExistsAttribute;
+
+ break;
+
case DT_CHR:
case DT_FIFO:
case DT_SOCK:
diff --git a/src/corelib/io/qfilesystemengine_win.cpp b/src/corelib/io/qfilesystemengine_win.cpp
index 0829bbc6e8..115b31dd2e 100644
--- a/src/corelib/io/qfilesystemengine_win.cpp
+++ b/src/corelib/io/qfilesystemengine_win.cpp
@@ -1422,8 +1422,9 @@ bool QFileSystemEngine::copyFile(const QFileSystemEntry &source, const QFileSyst
COPYFILE2_EXTENDED_PARAMETERS copyParams = {
sizeof(copyParams), COPY_FILE_FAIL_IF_EXISTS, NULL, NULL, NULL
};
- bool ret = ::CopyFile2((const wchar_t*)source.nativeFilePath().utf16(),
- (const wchar_t*)target.nativeFilePath().utf16(), &copyParams) != 0;
+ HRESULT hres = ::CopyFile2((const wchar_t*)source.nativeFilePath().utf16(),
+ (const wchar_t*)target.nativeFilePath().utf16(), &copyParams);
+ bool ret = SUCCEEDED(hres);
#endif // Q_OS_WINRT
if(!ret)
error = QSystemError(::GetLastError(), QSystemError::NativeError);
diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp
index 854db31a79..a9d3e0bfe8 100644
--- a/src/corelib/io/qprocess.cpp
+++ b/src/corelib/io/qprocess.cpp
@@ -1103,7 +1103,6 @@ bool QProcessPrivate::_q_canReadStandardError()
*/
bool QProcessPrivate::_q_canWrite()
{
- Q_Q(QProcess);
if (stdinChannel.notifier)
stdinChannel.notifier->setEnabled(false);
@@ -1114,31 +1113,13 @@ bool QProcessPrivate::_q_canWrite()
return false;
}
- qint64 written = writeToStdin(writeBuffer.readPointer(), writeBuffer.nextDataBlockSize());
- if (written < 0) {
- closeChannel(&stdinChannel);
- setErrorAndEmit(QProcess::WriteError);
- return false;
- }
+ const bool writeSucceeded = writeToStdin();
-#if defined QPROCESS_DEBUG
- qDebug("QProcessPrivate::canWrite(), wrote %d bytes to the process input", int(written));
-#endif
-
- if (written != 0) {
- writeBuffer.free(written);
- if (!emittedBytesWritten) {
- emittedBytesWritten = true;
- emit q->bytesWritten(written);
- emittedBytesWritten = false;
- }
- emit q->channelBytesWritten(0, written);
- }
if (stdinChannel.notifier && !writeBuffer.isEmpty())
stdinChannel.notifier->setEnabled(true);
if (writeBuffer.isEmpty() && stdinChannel.closed)
closeWriteChannel();
- return true;
+ return writeSucceeded;
}
/*!
diff --git a/src/corelib/io/qprocess_p.h b/src/corelib/io/qprocess_p.h
index 1f88c3a043..ae236c8c60 100644
--- a/src/corelib/io/qprocess_p.h
+++ b/src/corelib/io/qprocess_p.h
@@ -379,7 +379,7 @@ public:
qint64 bytesAvailableInChannel(const Channel *channel) const;
qint64 readFromChannel(const Channel *channel, char *data, qint64 maxlen);
- qint64 writeToStdin(const char *data, qint64 maxlen);
+ bool writeToStdin();
void cleanup();
void setError(QProcess::ProcessError error, const QString &description = QString());
diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp
index a5b7692fc9..8c5589538d 100644
--- a/src/corelib/io/qprocess_unix.cpp
+++ b/src/corelib/io/qprocess_unix.cpp
@@ -681,21 +681,36 @@ qint64 QProcessPrivate::readFromChannel(const Channel *channel, char *data, qint
return bytesRead;
}
-qint64 QProcessPrivate::writeToStdin(const char *data, qint64 maxlen)
+bool QProcessPrivate::writeToStdin()
{
- qint64 written = qt_safe_write_nosignal(stdinChannel.pipe[1], data, maxlen);
+ const char *data = writeBuffer.readPointer();
+ const qint64 bytesToWrite = writeBuffer.nextDataBlockSize();
+
+ qint64 written = qt_safe_write_nosignal(stdinChannel.pipe[1], data, bytesToWrite);
#if defined QPROCESS_DEBUG
- qDebug("QProcessPrivate::writeToStdin(%p \"%s\", %lld) == %lld",
- data, qt_prettyDebug(data, maxlen, 16).constData(), maxlen, written);
+ qDebug("QProcessPrivate::writeToStdin(), write(%p \"%s\", %lld) == %lld",
+ data, qt_prettyDebug(data, bytesToWrite, 16).constData(), bytesToWrite, written);
if (written == -1)
qDebug("QProcessPrivate::writeToStdin(), failed to write (%s)", qPrintable(qt_error_string(errno)));
#endif
- // If the O_NONBLOCK flag is set and If some data can be written without blocking
- // the process, write() will transfer what it can and return the number of bytes written.
- // Otherwise, it will return -1 and set errno to EAGAIN
- if (written == -1 && errno == EAGAIN)
- written = 0;
- return written;
+ if (written == -1) {
+ // If the O_NONBLOCK flag is set and If some data can be written without blocking
+ // the process, write() will transfer what it can and return the number of bytes written.
+ // Otherwise, it will return -1 and set errno to EAGAIN
+ if (errno == EAGAIN)
+ return true;
+
+ closeChannel(&stdinChannel);
+ setErrorAndEmit(QProcess::WriteError);
+ return false;
+ }
+ writeBuffer.free(written);
+ if (!emittedBytesWritten && written != 0) {
+ emittedBytesWritten = true;
+ emit q_func()->bytesWritten(written);
+ emittedBytesWritten = false;
+ }
+ return true;
}
void QProcessPrivate::terminateProcess()
diff --git a/src/corelib/io/qprocess_win.cpp b/src/corelib/io/qprocess_win.cpp
index ed540f9e5b..96b39efe3a 100644
--- a/src/corelib/io/qprocess_win.cpp
+++ b/src/corelib/io/qprocess_win.cpp
@@ -805,17 +805,23 @@ qint64 QProcessPrivate::pipeWriterBytesToWrite() const
return stdinChannel.writer ? stdinChannel.writer->bytesToWrite() : qint64(0);
}
-qint64 QProcessPrivate::writeToStdin(const char *data, qint64 maxlen)
+bool QProcessPrivate::writeToStdin()
{
Q_Q(QProcess);
if (!stdinChannel.writer) {
stdinChannel.writer = new QWindowsPipeWriter(stdinChannel.pipe[1], q);
+ QObject::connect(stdinChannel.writer, &QWindowsPipeWriter::bytesWritten,
+ q, &QProcess::bytesWritten);
QObjectPrivate::connect(stdinChannel.writer, &QWindowsPipeWriter::canWrite,
this, &QProcessPrivate::_q_canWrite);
+ } else {
+ if (stdinChannel.writer->isWriteOperationActive())
+ return true;
}
- return stdinChannel.writer->write(data, maxlen);
+ stdinChannel.writer->write(writeBuffer.read());
+ return true;
}
// Use ShellExecuteEx() to trigger an UAC prompt when CreateProcess()fails
diff --git a/src/corelib/io/qprocess_wince.cpp b/src/corelib/io/qprocess_wince.cpp
index 564b3f520d..824a6158dc 100644
--- a/src/corelib/io/qprocess_wince.cpp
+++ b/src/corelib/io/qprocess_wince.cpp
@@ -271,11 +271,9 @@ qint64 QProcessPrivate::pipeWriterBytesToWrite() const
return 0;
}
-qint64 QProcessPrivate::writeToStdin(const char *data, qint64 maxlen)
+bool QProcessPrivate::writeToStdin()
{
- Q_UNUSED(data);
- Q_UNUSED(maxlen);
- return -1;
+ return false;
}
bool QProcessPrivate::startDetached(const QString &program, const QStringList &arguments, const QString &workingDir, qint64 *pid)
diff --git a/src/corelib/io/qwindowspipewriter.cpp b/src/corelib/io/qwindowspipewriter.cpp
index 79e7d13eb5..ab179641f8 100644
--- a/src/corelib/io/qwindowspipewriter.cpp
+++ b/src/corelib/io/qwindowspipewriter.cpp
@@ -79,21 +79,19 @@ QWindowsPipeWriter::~QWindowsPipeWriter()
bool QWindowsPipeWriter::waitForWrite(int msecs)
{
- if (!writeSequenceStarted)
- return false;
-
if (bytesWrittenPending) {
- if (!inBytesWritten)
- emitPendingBytesWrittenValue();
+ emitPendingBytesWrittenValue();
return true;
}
+ if (!writeSequenceStarted)
+ return false;
+
if (!waitForNotification(msecs))
return false;
if (bytesWrittenPending) {
- if (!inBytesWritten)
- emitPendingBytesWrittenValue();
+ emitPendingBytesWrittenValue();
return true;
}
@@ -102,20 +100,24 @@ bool QWindowsPipeWriter::waitForWrite(int msecs)
qint64 QWindowsPipeWriter::bytesToWrite() const
{
- return numberOfBytesToWrite;
+ return numberOfBytesToWrite + pendingBytesWrittenValue;
}
void QWindowsPipeWriter::emitPendingBytesWrittenValue()
{
if (bytesWrittenPending) {
+ // Reset the state even if we don't emit bytesWritten().
+ // It's a defined behavior to not re-emit this signal recursively.
bytesWrittenPending = false;
const qint64 bytes = pendingBytesWrittenValue;
pendingBytesWrittenValue = 0;
- inBytesWritten = true;
- emit bytesWritten(bytes);
- inBytesWritten = false;
emit canWrite();
+ if (!inBytesWritten) {
+ inBytesWritten = true;
+ emit bytesWritten(bytes);
+ inBytesWritten = false;
+ }
}
}
@@ -135,6 +137,8 @@ void QWindowsPipeWriter::notified(DWORD errorCode, DWORD numberOfBytesWritten)
notifiedCalled = true;
writeSequenceStarted = false;
numberOfBytesToWrite = 0;
+ Q_ASSERT(errorCode != ERROR_SUCCESS || numberOfBytesWritten == DWORD(buffer.size()));
+ buffer.clear();
switch (errorCode) {
case ERROR_SUCCESS:
@@ -179,21 +183,26 @@ bool QWindowsPipeWriter::waitForNotification(int timeout)
return notifiedCalled;
}
-qint64 QWindowsPipeWriter::write(const char *ptr, qint64 maxlen)
+bool QWindowsPipeWriter::write(const QByteArray &ba)
{
if (writeSequenceStarted)
- return 0;
+ return false;
overlapped.clear();
- numberOfBytesToWrite = maxlen;
+ buffer = ba;
+ numberOfBytesToWrite = buffer.size();
stopped = false;
writeSequenceStarted = true;
- if (!WriteFileEx(handle, ptr, maxlen, &overlapped, &writeFileCompleted)) {
+ if (!WriteFileEx(handle, buffer.constData(), numberOfBytesToWrite,
+ &overlapped, &writeFileCompleted)) {
writeSequenceStarted = false;
+ numberOfBytesToWrite = 0;
+ buffer.clear();
qErrnoWarning("QWindowsPipeWriter::write failed.");
+ return false;
}
- return maxlen;
+ return true;
}
void QWindowsPipeWriter::stop()
diff --git a/src/corelib/io/qwindowspipewriter_p.h b/src/corelib/io/qwindowspipewriter_p.h
index 59f20edae0..3c641670b6 100644
--- a/src/corelib/io/qwindowspipewriter_p.h
+++ b/src/corelib/io/qwindowspipewriter_p.h
@@ -53,6 +53,7 @@
#include <qelapsedtimer.h>
#include <qobject.h>
+#include <qbytearray.h>
#include <qt_windows.h>
QT_BEGIN_NAMESPACE
@@ -112,7 +113,7 @@ public:
explicit QWindowsPipeWriter(HANDLE pipeWriteEnd, QObject *parent = 0);
~QWindowsPipeWriter();
- qint64 write(const char *data, qint64 maxlen);
+ bool write(const QByteArray &ba);
void stop();
bool waitForWrite(int msecs);
bool isWriteOperationActive() const { return writeSequenceStarted; }
@@ -142,6 +143,7 @@ private:
HANDLE handle;
Overlapped overlapped;
+ QByteArray buffer;
qint64 numberOfBytesToWrite;
qint64 pendingBytesWrittenValue;
bool stopped;
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index 04ec713522..9b421d6a78 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -1130,7 +1130,7 @@ QObjectPrivate::Connection::~Connection()
RTTI support and it works across dynamic library boundaries.
qobject_cast() can also be used in conjunction with interfaces;
- see the \l{tools/plugandpaint}{Plug & Paint} example for details.
+ see the \l{tools/plugandpaint/app}{Plug & Paint} example for details.
\warning If T isn't declared with the Q_OBJECT macro, this
function's return value is undefined.
@@ -4160,11 +4160,11 @@ QDebug operator<<(QDebug dbg, const QObject *o)
Example:
- \snippet ../widgets/tools/plugandpaintplugins/basictools/basictoolsplugin.h 1
+ \snippet ../widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.h 1
\dots
- \snippet ../widgets/tools/plugandpaintplugins/basictools/basictoolsplugin.h 3
+ \snippet ../widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.h 3
- See the \l{tools/plugandpaintplugins/basictools}{Plug & Paint
+ See the \l{tools/plugandpaint/plugins/basictools}{Plug & Paint
Basic Tools} example for details.
\sa Q_DECLARE_INTERFACE(), Q_PLUGIN_METADATA(), {How to Create Qt Plugins}
diff --git a/src/corelib/plugin/qplugin.qdoc b/src/corelib/plugin/qplugin.qdoc
index 5dcc14b64b..968fb4820a 100644
--- a/src/corelib/plugin/qplugin.qdoc
+++ b/src/corelib/plugin/qplugin.qdoc
@@ -44,11 +44,11 @@
to the interface class called \a ClassName. The \a Identifier must
be unique. For example:
- \snippet plugandpaint/interfaces.h 3
+ \snippet plugandpaint/app/interfaces.h 3
This macro is normally used right after the class definition for
\a ClassName, in a header file. See the
- \l{tools/plugandpaint}{Plug & Paint} example for details.
+ \l{tools/plugandpaint/app}{Plug & Paint} example for details.
If you want to use Q_DECLARE_INTERFACE with interface classes
declared in a namespace then you have to make sure the Q_DECLARE_INTERFACE
@@ -76,7 +76,7 @@
\snippet code/doc_src_qplugin.cpp 1
- See the \l{tools/plugandpaint}{Plug & Paint} example for details.
+ See the \l{tools/plugandpaint/app}{Plug & Paint} example for details.
Note that the class this macro appears on must be default-constructible.
diff --git a/src/corelib/thread/qthread.cpp b/src/corelib/thread/qthread.cpp
index 8a797772fc..4aac24f454 100644
--- a/src/corelib/thread/qthread.cpp
+++ b/src/corelib/thread/qthread.cpp
@@ -149,16 +149,12 @@ QThreadPrivate::QThreadPrivate(QThreadData *d)
exited(false), returnCode(-1),
stackSize(0), priority(QThread::InheritPriority), data(d)
{
-#if defined (Q_OS_UNIX)
- thread_id = 0;
-#elif defined (Q_OS_WIN)
+#if defined (Q_OS_WIN)
handle = 0;
# ifndef Q_OS_WINRT
id = 0;
# endif
waiters = 0;
-#endif
-#if defined (Q_OS_WIN)
terminationEnabled = true;
terminatePending = false;
#endif
diff --git a/src/corelib/thread/qthread_p.h b/src/corelib/thread/qthread_p.h
index adcd98b609..37eca9c612 100644
--- a/src/corelib/thread/qthread_p.h
+++ b/src/corelib/thread/qthread_p.h
@@ -176,7 +176,6 @@ public:
static QThread *threadForId(int id);
#ifdef Q_OS_UNIX
- pthread_t thread_id;
QWaitCondition thread_done;
static void *start(void *arg);
diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp
index f456e56a9c..e7a31e0b70 100644
--- a/src/corelib/thread/qthread_unix.cpp
+++ b/src/corelib/thread/qthread_unix.cpp
@@ -110,6 +110,8 @@ QT_BEGIN_NAMESPACE
#ifndef QT_NO_THREAD
+Q_STATIC_ASSERT(sizeof(pthread_t) == sizeof(Qt::HANDLE));
+
enum { ThreadPriorityResetFlag = 0x80000000 };
#if defined(Q_OS_LINUX) && defined(__GLIBC__) && (defined(Q_CC_GNU) || defined(Q_CC_INTEL)) && !defined(QT_LINUXBASE)
@@ -239,8 +241,6 @@ QThreadData *QThreadData::current(bool createIfNecessary)
void QAdoptedThread::init()
{
- Q_D(QThread);
- d->thread_id = pthread_self();
}
/*
@@ -328,10 +328,11 @@ void *QThreadPrivate::start(void *arg)
// sets the name of the current thread.
QString objectName = thr->objectName();
+ pthread_t thread_id = reinterpret_cast<pthread_t>(data->threadId);
if (Q_LIKELY(objectName.isEmpty()))
- setCurrentThreadName(thr->d_func()->thread_id, thr->metaObject()->className());
+ setCurrentThreadName(thread_id, thr->metaObject()->className());
else
- setCurrentThreadName(thr->d_func()->thread_id, objectName.toLocal8Bit());
+ setCurrentThreadName(thread_id, objectName.toLocal8Bit());
}
#endif
@@ -372,7 +373,6 @@ void QThreadPrivate::finish(void *arg)
locker.relock();
}
- d->thread_id = 0;
d->running = false;
d->finished = true;
d->interruptionRequested = false;
@@ -618,15 +618,16 @@ void QThread::start(Priority priority)
}
int code =
- pthread_create(&d->thread_id, &attr, QThreadPrivate::start, this);
+ pthread_create(reinterpret_cast<pthread_t *>(&d->data->threadId), &attr,
+ QThreadPrivate::start, this);
if (code == EPERM) {
// caller does not have permission to set the scheduling
// parameters/policy
#if defined(QT_HAS_THREAD_PRIORITY_SCHEDULING)
pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED);
#endif
- code =
- pthread_create(&d->thread_id, &attr, QThreadPrivate::start, this);
+ code = pthread_create(reinterpret_cast<pthread_t *>(&d->data->threadId), &attr,
+ QThreadPrivate::start, this);
}
pthread_attr_destroy(&attr);
@@ -636,7 +637,7 @@ void QThread::start(Priority priority)
d->running = false;
d->finished = false;
- d->thread_id = 0;
+ d->data->threadId = 0;
}
}
@@ -646,10 +647,10 @@ void QThread::terminate()
Q_D(QThread);
QMutexLocker locker(&d->mutex);
- if (!d->thread_id)
+ if (!d->data->threadId)
return;
- int code = pthread_cancel(d->thread_id);
+ int code = pthread_cancel(reinterpret_cast<pthread_t>(d->data->threadId));
if (code) {
qWarning("QThread::start: Thread termination error: %s",
qPrintable(qt_error_string((code))));
@@ -662,7 +663,7 @@ bool QThread::wait(unsigned long time)
Q_D(QThread);
QMutexLocker locker(&d->mutex);
- if (d->thread_id == pthread_self()) {
+ if (reinterpret_cast<pthread_t>(d->data->threadId) == pthread_self()) {
qWarning("QThread::wait: Thread tried to wait on itself");
return false;
}
@@ -704,7 +705,7 @@ void QThreadPrivate::setPriority(QThread::Priority threadPriority)
int sched_policy;
sched_param param;
- if (pthread_getschedparam(thread_id, &sched_policy, &param) != 0) {
+ if (pthread_getschedparam(reinterpret_cast<pthread_t>(data->threadId), &sched_policy, &param) != 0) {
// failed to get the scheduling policy, don't bother setting
// the priority
qWarning("QThread::setPriority: Cannot get scheduler parameters");
@@ -720,15 +721,15 @@ void QThreadPrivate::setPriority(QThread::Priority threadPriority)
}
param.sched_priority = prio;
- int status = pthread_setschedparam(thread_id, sched_policy, &param);
+ int status = pthread_setschedparam(reinterpret_cast<pthread_t>(data->threadId), sched_policy, &param);
# ifdef SCHED_IDLE
// were we trying to set to idle priority and failed?
if (status == -1 && sched_policy == SCHED_IDLE && errno == EINVAL) {
// reset to lowest priority possible
- pthread_getschedparam(thread_id, &sched_policy, &param);
+ pthread_getschedparam(reinterpret_cast<pthread_t>(data->threadId), &sched_policy, &param);
param.sched_priority = sched_get_priority_min(sched_policy);
- pthread_setschedparam(thread_id, sched_policy, &param);
+ pthread_setschedparam(reinterpret_cast<pthread_t>(data->threadId), sched_policy, &param);
}
# else
Q_UNUSED(status);