- 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: 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

View File

@ -23,6 +23,7 @@
#include "utils.h"
#include "../settings.h"
#include <QMessageBox>
#include <QUuid>
#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")

View File

@ -21,6 +21,7 @@
#include "../settings.h"
#include "../systemconsts.h"
#ifdef Q_OS_WIN
#include <QUuid>
#include <windows.h>
#elif defined(Q_OS_LINUX)
#include <sys/mman.h>
@ -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) {

View File

@ -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<QProcess> mProcess;

View File

@ -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> <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");
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