diff --git a/NEWS.md b/NEWS.md index fbbb4f4e..b159c019 100644 --- a/NEWS.md +++ b/NEWS.md @@ -31,6 +31,7 @@ Red Panda C++ Version 1.0.0 - fix: wrong font size of exported HTML file - fix: parse error in avxintrin.h - 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 - fix: the "gnu c++ 20" option in compiler set options is wrong diff --git a/RedPandaIDE/compiler/compilermanager.cpp b/RedPandaIDE/compiler/compilermanager.cpp index 6a146dd5..14b620ce 100644 --- a/RedPandaIDE/compiler/compilermanager.cpp +++ b/RedPandaIDE/compiler/compilermanager.cpp @@ -23,6 +23,7 @@ #include "utils.h" #include "../settings.h" #include +#include #include "projectcompiler.h" #include "../platform.h" @@ -238,16 +239,19 @@ void CompilerManager::run(const QString &filename, const QString &arguments, con consoleFlag |= RPF_PAUSE_CONSOLE; #ifdef Q_OS_WIN if (consoleFlag!=0) { - QString newArguments = QString(" %1 \"%2\" %3") + QString sharedMemoryId = QUuid::createUuid().toString(); + QString newArguments = QString(" %1 %2 \"%3\" %4") .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->setShareMemoryId(sharedMemoryId); } else { execRunner = new ExecutableRunner(filename,arguments,workDir); } #else QString newArguments; if (consoleFlag!=0) { + QString sharedMemoryId = QUuid::createUuid().toString(); QString consolePauserPath=includeTrailingPathDelimiter(pSettings->dirs().appLibexecDir())+"consolepauser"; if (!fileExists(consolePauserPath)) { QMessageBox::critical(pMainWindow, @@ -258,17 +262,18 @@ void CompilerManager::run(const QString &filename, const QString &arguments, con } if (redirectInput) { - newArguments = QString(" -e \"%1\" %2 \"%3\" \"%4\" %5") + newArguments = QString(" -e \"%1\" %2 %3 \"%4\" \"%5\" %6") .arg(consolePauserPath) .arg(consoleFlag) + .arg(sharedMemoryId) .arg(redirectInputFilename) .arg(localizePath(filename)) .arg(arguments); } else { - newArguments = QString(" -e \"%1\" %2 \"%3\" %4") + newArguments = QString(" -e \"%1\" %2 %3 \"%4\" %5") .arg(consolePauserPath) .arg(consoleFlag) - .arg(localizePath(filename)).arg(arguments); + .arg(sharedMemoryId,localizePath(filename)).arg(arguments); } } else { newArguments = QString(" -e \"%1\" %2") diff --git a/RedPandaIDE/compiler/executablerunner.cpp b/RedPandaIDE/compiler/executablerunner.cpp index 02d9d07c..c1239689 100644 --- a/RedPandaIDE/compiler/executablerunner.cpp +++ b/RedPandaIDE/compiler/executablerunner.cpp @@ -21,6 +21,7 @@ #include "../settings.h" #include "../systemconsts.h" #ifdef Q_OS_WIN +#include #include #elif defined(Q_OS_LINUX) #include @@ -51,6 +52,16 @@ void ExecutableRunner::setStartConsole(bool newStartConsole) mStartConsole = newStartConsole; } +const QString &ExecutableRunner::shareMemoryId() const +{ + return mShareMemoryId; +} + +void ExecutableRunner::setShareMemoryId(const QString &newShareMemoryId) +{ + mShareMemoryId = newShareMemoryId; +} + bool ExecutableRunner::redirectInput() const { return mRedirectInput; @@ -128,7 +139,7 @@ void ExecutableRunner::run() PAGE_READWRITE, 0, 100, - "RED_PANDA_IDE_CONSOLE_PAUSER20211223" + mShareMemoryId.toLocal8Bit().data() ); if (hSharedMemory != NULL) { @@ -199,7 +210,7 @@ void ExecutableRunner::run() UnmapViewOfFile(pBuf); pBuf = nullptr; } - if (hSharedMemory!=INVALID_HANDLE_VALUE) { + if (hSharedMemory!=INVALID_HANDLE_VALUE && hSharedMemory!=NULL) { hSharedMemory = INVALID_HANDLE_VALUE; CloseHandle(hSharedMemory); } @@ -224,7 +235,7 @@ void ExecutableRunner::run() #ifdef Q_OS_WIN if (pBuf) UnmapViewOfFile(pBuf); - if (hSharedMemory!=INVALID_HANDLE_VALUE) + if (hSharedMemory!=INVALID_HANDLE_VALUE && hSharedMemory!=NULL) CloseHandle(hSharedMemory); #elif defined(Q_OS_LINUX) if (pBuf) { diff --git a/RedPandaIDE/compiler/executablerunner.h b/RedPandaIDE/compiler/executablerunner.h index 6d35036b..bcfa15a5 100644 --- a/RedPandaIDE/compiler/executablerunner.h +++ b/RedPandaIDE/compiler/executablerunner.h @@ -37,8 +37,13 @@ public: bool startConsole() const; void setStartConsole(bool newStartConsole); + const QString &shareMemoryId() const; + + void setShareMemoryId(const QString &newShareMemoryId); + private: QString mRedirectInputFilename; + QString mShareMemoryId; bool mRedirectInput; bool mStartConsole; std::shared_ptr mProcess; diff --git a/consolepauser/main.windows.cpp b/consolepauser/main.windows.cpp index f78f0d4e..99b60565 100644 --- a/consolepauser/main.windows.cpp +++ b/consolepauser/main.windows.cpp @@ -92,7 +92,7 @@ string GetCommand(int argc,char** argv,bool &reInp,bool &pauseAfterExit) { int flags = atoi(argv[1]); reInp = flags & RPF_REDIRECT_INPUT; 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 result += string("\"") + string(argv[i]) + string("\""); @@ -144,16 +144,19 @@ DWORD ExecuteCommand(string& command,bool reInp) { int main(int argc, char** argv) { + const char *sharedMemoryId; // First make sure we aren't going to read nonexistent arrays - if(argc < 3) { + if(argc < 4) { printf("\n--------------------------------"); - printf("\nUsage: ConsolePauser.exe <0|1> \n"); + printf("\nUsage: ConsolePauser.exe <0|1> \n"); printf("\n 1 means the STDIN is redirected by Red Panda C++; 0 means not\n"); PauseExit(EXIT_SUCCESS,false); } // Make us look like the paused program - SetConsoleTitleA(argv[2]); + SetConsoleTitleA(argv[3]); + + sharedMemoryId = argv[2]; SECURITY_ATTRIBUTES sa; sa.nLength = sizeof(sa); @@ -202,7 +205,7 @@ int main(int argc, char** argv) { hSharedMemory = OpenFileMappingA( FILE_MAP_ALL_ACCESS, FALSE, - "RED_PANDA_IDE_CONSOLE_PAUSER20211223" + sharedMemoryId ); if (hSharedMemory != NULL) { @@ -227,6 +230,10 @@ int main(int argc, char** argv) { if (pBuf) { strcpy(pBuf,"FINISHED"); + UnmapViewOfFile(pBuf); + } + if (hSharedMemory != NULL && hSharedMemory!=INVALID_HANDLE_VALUE) { + CloseHandle(hSharedMemory); } // Done? Print return value of executed program