Skip to content

Commit

Permalink
Use threads only for git processes on windows
Browse files Browse the repository at this point in the history
On Ubuntu, threads can cause seg faults, see:
HaxeFoundation/neko#281
  • Loading branch information
tobil4sk committed Apr 4, 2023
1 parent fe3db3f commit e694d37
Showing 1 changed file with 36 additions and 22 deletions.
58 changes: 36 additions & 22 deletions src/haxelib/client/Vcs.hx
Original file line number Diff line number Diff line change
Expand Up @@ -158,32 +158,46 @@ class Vcs implements IVcs {
code: -1,
out: Std.string(e)
}
}
var streamsLock = new sys.thread.Lock();
function readFrom(stream:haxe.io.Input, to: {value: String}) {
to.value = stream.readAll().toString();
streamsLock.release();
}
};
var ret = if (Sys.systemName() == "Windows") {
var streamsLock = new sys.thread.Lock();
function readFrom(stream:haxe.io.Input, to: {value: String}) {
to.value = stream.readAll().toString();
streamsLock.release();
}

var out = {value: ""};
var err = {value: ""};
Thread.create(readFrom.bind(p.stdout, out));
Thread.create(readFrom.bind(p.stderr, err));
var out = {value: ""};
var err = {value: ""};
Thread.create(readFrom.bind(p.stdout, out));
Thread.create(readFrom.bind(p.stderr, err));

var code = p.exitCode();
for (_ in 0...2) {
// wait until we finish reading from both streams
streamsLock.wait();
}
var code = p.exitCode();
for (_ in 0...2) {
// wait until we finish reading from both streams
streamsLock.wait();
}

if (settings.debug && out.value != "")
Sys.println(out.value);
if (settings.debug && err.value != "")
Sys.stderr().writeString(err.value);
if (settings.debug && out.value != "")
Sys.println(out.value);
if (settings.debug && err.value != "")
Sys.stderr().writeString(err.value);

var ret = {
code: code,
out: code == 0 ? out.value : err.value
{
code: code,
out: code == 0 ? out.value : err.value
};
} else {
var out = p.stdout.readAll().toString();
var err = p.stderr.readAll().toString();
if (settings.debug && out != "")
Sys.println(out);
if (settings.debug && err != "")
Sys.stderr().writeString(err);
var code = p.exitCode();
{
code: code,
out: code == 0 ? out : err
};
};
p.close();
return ret;
Expand Down

0 comments on commit e694d37

Please sign in to comment.