Created
February 8, 2016 16:13
-
-
Save miguel-negrao/54307057f44f26c0e409 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lang/LangPrimSource/PyrUnixPrim.cpp b/lang/LangPrimSource/PyrUnixPrim.cpp | |
index 769be99..40be03c 100644 | |
--- a/lang/LangPrimSource/PyrUnixPrim.cpp | |
+++ b/lang/LangPrimSource/PyrUnixPrim.cpp | |
@@ -115,7 +115,7 @@ struct sc_process { | |
bool postOutput; | |
}; | |
-static void string_popen_thread_func(struct sc_process *process) | |
+static void string_popen_thread_func(std::unique_ptr<sc_process> process) | |
{ | |
FILE *stream = process->stream; | |
pid_t pid = process->pid; | |
@@ -134,7 +134,7 @@ static void string_popen_thread_func(struct sc_process *process) | |
if(process->postOutput) | |
postfl("RESULT = %d\n", res); | |
- delete process; | |
+ //delete process; | |
gLangMutex.lock(); | |
if(compiledOK) { | |
@@ -165,7 +165,7 @@ int prString_POpen(struct VMGlobals *g, int numArgsPushed) | |
return errNone; | |
#endif | |
- sc_process *process = new sc_process; | |
+ std::unique_ptr<sc_process> process(new sc_process); | |
process->stream = sc_popen(cmdline, &process->pid, "r"); | |
setvbuf(process->stream, 0, _IONBF, 0); | |
pid_t pid = process->pid; | |
@@ -175,11 +175,11 @@ int prString_POpen(struct VMGlobals *g, int numArgsPushed) | |
delete [] cmdline; | |
if(process->stream == NULL) { | |
- delete process; | |
+ //delete process; | |
return errFailed; | |
} | |
- thread thread(std::bind(string_popen_thread_func, process)); | |
+ thread thread(std::bind(string_popen_thread_func, std::move(process) )); | |
thread.detach(); | |
SetInt(a, pid); | |
@@ -237,7 +237,7 @@ int prArrayPOpen(struct VMGlobals *g, int numArgsPushed) | |
} | |
} | |
- sc_process *process = new sc_process; | |
+ std::unique_ptr<sc_process> process (new sc_process); | |
process->stream = sc_popen_argv(filename, argv.data(), &process->pid, "r"); | |
setvbuf(process->stream, 0, _IONBF, 0); | |
pid_t pid = process->pid; | |
@@ -245,11 +245,11 @@ int prArrayPOpen(struct VMGlobals *g, int numArgsPushed) | |
process->postOutput = IsTrue(b); | |
if(process->stream == NULL) { | |
- delete process; | |
+ //delete process; | |
return errFailed; | |
} | |
- thread thread(std::bind(string_popen_thread_func, process)); | |
+ thread thread(std::bind(string_popen_thread_func, std::move(process))); | |
thread.detach(); | |
for (int i=1; i<obj->size; ++i) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment