- fix: if there is a Red Panda C++ process running program, other Red Panda C++ processes can't run program correctly.

This commit is contained in:
Roy Qu 2022-03-16 20:08:39 +08:00
parent eb2e2bb58f
commit c67e196e72
5 changed files with 42 additions and 13 deletions

View File

@ -31,6 +31,7 @@ Red Panda C++ Version 1.0.0
- fix: wrong font size of exported HTML file - fix: wrong font size of exported HTML file
- fix: parse error in avxintrin.h - fix: parse error in avxintrin.h
- fix: switch disassembly mode doesn't update contents - fix: switch disassembly mode doesn't update contents
- fix: if there is a Red Panda C++ process running program, other Red Panda C++ processes can't run program correctly.
Red Panda C++ Version 0.14.5 Red Panda C++ Version 0.14.5
- fix: the "gnu c++ 20" option in compiler set options is wrong - fix: the "gnu c++ 20" option in compiler set options is wrong

View File

@ -23,6 +23,7 @@
#include "utils.h" #include "utils.h"
#include "../settings.h" #include "../settings.h"
#include <QMessageBox> #include <QMessageBox>
#include <QUuid>
#include "projectcompiler.h" #include "projectcompiler.h"
#include "../platform.h" #include "../platform.h"
@ -238,16 +239,19 @@ void CompilerManager::run(const QString &filename, const QString &arguments, con
consoleFlag |= RPF_PAUSE_CONSOLE; consoleFlag |= RPF_PAUSE_CONSOLE;
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
if (consoleFlag!=0) { if (consoleFlag!=0) {
QString newArguments = QString(" %1 \"%2\" %3") QString sharedMemoryId = QUuid::createUuid().toString();
QString newArguments = QString(" %1 %2 \"%3\" %4")
.arg(consoleFlag) .arg(consoleFlag)
.arg(localizePath(filename)).arg(arguments); .arg(sharedMemoryId,localizePath(filename)).arg(arguments);
execRunner = new ExecutableRunner(includeTrailingPathDelimiter(pSettings->dirs().appDir())+"ConsolePauser.exe",newArguments,workDir); execRunner = new ExecutableRunner(includeTrailingPathDelimiter(pSettings->dirs().appDir())+"ConsolePauser.exe",newArguments,workDir);
execRunner->setShareMemoryId(sharedMemoryId);
} else { } else {
execRunner = new ExecutableRunner(filename,arguments,workDir); execRunner = new ExecutableRunner(filename,arguments,workDir);
} }
#else #else
QString newArguments; QString newArguments;
if (consoleFlag!=0) { if (consoleFlag!=0) {
QString sharedMemoryId = QUuid::createUuid().toString();
QString consolePauserPath=includeTrailingPathDelimiter(pSettings->dirs().appLibexecDir())+"consolepauser"; QString consolePauserPath=includeTrailingPathDelimiter(pSettings->dirs().appLibexecDir())+"consolepauser";
if (!fileExists(consolePauserPath)) { if (!fileExists(consolePauserPath)) {
QMessageBox::critical(pMainWindow, QMessageBox::critical(pMainWindow,
@ -258,17 +262,18 @@ void CompilerManager::run(const QString &filename, const QString &arguments, con
} }
if (redirectInput) { if (redirectInput) {
newArguments = QString(" -e \"%1\" %2 \"%3\" \"%4\" %5") newArguments = QString(" -e \"%1\" %2 %3 \"%4\" \"%5\" %6")
.arg(consolePauserPath) .arg(consolePauserPath)
.arg(consoleFlag) .arg(consoleFlag)
.arg(sharedMemoryId)
.arg(redirectInputFilename) .arg(redirectInputFilename)
.arg(localizePath(filename)) .arg(localizePath(filename))
.arg(arguments); .arg(arguments);
} else { } else {
newArguments = QString(" -e \"%1\" %2 \"%3\" %4") newArguments = QString(" -e \"%1\" %2 %3 \"%4\" %5")
.arg(consolePauserPath) .arg(consolePauserPath)
.arg(consoleFlag) .arg(consoleFlag)
.arg(localizePath(filename)).arg(arguments); .arg(sharedMemoryId,localizePath(filename)).arg(arguments);
} }
} else { } else {
newArguments = QString(" -e \"%1\" %2") newArguments = QString(" -e \"%1\" %2")

View File

@ -21,6 +21,7 @@
#include "../settings.h" #include "../settings.h"
#include "../systemconsts.h" #include "../systemconsts.h"
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include <QUuid>
#include <windows.h> #include <windows.h>
#elif defined(Q_OS_LINUX) #elif defined(Q_OS_LINUX)
#include <sys/mman.h> #include <sys/mman.h>
@ -51,6 +52,16 @@ void ExecutableRunner::setStartConsole(bool newStartConsole)
mStartConsole = newStartConsole; mStartConsole = newStartConsole;
} }
const QString &ExecutableRunner::shareMemoryId() const
{
return mShareMemoryId;
}
void ExecutableRunner::setShareMemoryId(const QString &newShareMemoryId)
{
mShareMemoryId = newShareMemoryId;
}
bool ExecutableRunner::redirectInput() const bool ExecutableRunner::redirectInput() const
{ {
return mRedirectInput; return mRedirectInput;
@ -128,7 +139,7 @@ void ExecutableRunner::run()
PAGE_READWRITE, PAGE_READWRITE,
0, 0,
100, 100,
"RED_PANDA_IDE_CONSOLE_PAUSER20211223" mShareMemoryId.toLocal8Bit().data()
); );
if (hSharedMemory != NULL) if (hSharedMemory != NULL)
{ {
@ -199,7 +210,7 @@ void ExecutableRunner::run()
UnmapViewOfFile(pBuf); UnmapViewOfFile(pBuf);
pBuf = nullptr; pBuf = nullptr;
} }
if (hSharedMemory!=INVALID_HANDLE_VALUE) { if (hSharedMemory!=INVALID_HANDLE_VALUE && hSharedMemory!=NULL) {
hSharedMemory = INVALID_HANDLE_VALUE; hSharedMemory = INVALID_HANDLE_VALUE;
CloseHandle(hSharedMemory); CloseHandle(hSharedMemory);
} }
@ -224,7 +235,7 @@ void ExecutableRunner::run()
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
if (pBuf) if (pBuf)
UnmapViewOfFile(pBuf); UnmapViewOfFile(pBuf);
if (hSharedMemory!=INVALID_HANDLE_VALUE) if (hSharedMemory!=INVALID_HANDLE_VALUE && hSharedMemory!=NULL)
CloseHandle(hSharedMemory); CloseHandle(hSharedMemory);
#elif defined(Q_OS_LINUX) #elif defined(Q_OS_LINUX)
if (pBuf) { if (pBuf) {

View File

@ -37,8 +37,13 @@ public:
bool startConsole() const; bool startConsole() const;
void setStartConsole(bool newStartConsole); void setStartConsole(bool newStartConsole);
const QString &shareMemoryId() const;
void setShareMemoryId(const QString &newShareMemoryId);
private: private:
QString mRedirectInputFilename; QString mRedirectInputFilename;
QString mShareMemoryId;
bool mRedirectInput; bool mRedirectInput;
bool mStartConsole; bool mStartConsole;
std::shared_ptr<QProcess> mProcess; std::shared_ptr<QProcess> mProcess;

View File

@ -92,7 +92,7 @@ string GetCommand(int argc,char** argv,bool &reInp,bool &pauseAfterExit) {
int flags = atoi(argv[1]); int flags = atoi(argv[1]);
reInp = flags & RPF_REDIRECT_INPUT; reInp = flags & RPF_REDIRECT_INPUT;
pauseAfterExit = flags & RPF_PAUSE_CONSOLE; pauseAfterExit = flags & RPF_PAUSE_CONSOLE;
for(int i = 2;i < argc;i++) { for(int i = 3;i < argc;i++) {
// Quote the argument in case the path name contains spaces // Quote the argument in case the path name contains spaces
result += string("\"") + string(argv[i]) + string("\""); result += string("\"") + string(argv[i]) + string("\"");
@ -144,16 +144,19 @@ DWORD ExecuteCommand(string& command,bool reInp) {
int main(int argc, char** argv) { int main(int argc, char** argv) {
const char *sharedMemoryId;
// First make sure we aren't going to read nonexistent arrays // First make sure we aren't going to read nonexistent arrays
if(argc < 3) { if(argc < 4) {
printf("\n--------------------------------"); printf("\n--------------------------------");
printf("\nUsage: ConsolePauser.exe <0|1> <filename> <parameters>\n"); printf("\nUsage: ConsolePauser.exe <0|1> <shared_memory_id> <filename> <parameters>\n");
printf("\n 1 means the STDIN is redirected by Red Panda C++; 0 means not\n"); printf("\n 1 means the STDIN is redirected by Red Panda C++; 0 means not\n");
PauseExit(EXIT_SUCCESS,false); PauseExit(EXIT_SUCCESS,false);
} }
// Make us look like the paused program // Make us look like the paused program
SetConsoleTitleA(argv[2]); SetConsoleTitleA(argv[3]);
sharedMemoryId = argv[2];
SECURITY_ATTRIBUTES sa; SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(sa); sa.nLength = sizeof(sa);
@ -202,7 +205,7 @@ int main(int argc, char** argv) {
hSharedMemory = OpenFileMappingA( hSharedMemory = OpenFileMappingA(
FILE_MAP_ALL_ACCESS, FILE_MAP_ALL_ACCESS,
FALSE, FALSE,
"RED_PANDA_IDE_CONSOLE_PAUSER20211223" sharedMemoryId
); );
if (hSharedMemory != NULL) if (hSharedMemory != NULL)
{ {
@ -227,6 +230,10 @@ int main(int argc, char** argv) {
if (pBuf) { if (pBuf) {
strcpy(pBuf,"FINISHED"); strcpy(pBuf,"FINISHED");
UnmapViewOfFile(pBuf);
}
if (hSharedMemory != NULL && hSharedMemory!=INVALID_HANDLE_VALUE) {
CloseHandle(hSharedMemory);
} }
// Done? Print return value of executed program // Done? Print return value of executed program