Skip to content

Commit d6dd677

Browse files
committedNov 23, 2017
Workaround windows bug with fork and Encode
1 parent 25018df commit d6dd677

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed
 

‎bin/psass

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ use CSS::Sass::Plugins qw(%plugins);
2828

2929
# setup encodings for std streams
3030
# not sure why this is not default
31-
binmode(STDIN,":encoding(locale)");
32-
binmode(STDOUT,":encoding(locale)");
33-
binmode(STDERR,":encoding(locale)");
31+
binmode(STDIN, ":encoding(console_in)");
32+
binmode(STDOUT, ":encoding(console_out)");
33+
binmode(STDERR, ":encoding(console_out)");
3434

3535
####################################################################################################
3636
# normalize command arguments to utf8

‎lib/CSS/Sass/Watchdog.pm

+29-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,33 @@ my $benchmark = eval "use Benchmark; 1";
4343
# declare package variables
4444
my ($parent_pid, $child_pid) = ($$, 0);
4545

46+
####################################################################################################
47+
# reset/reinit is needed to avoid a bug on windows
48+
# version strawberry-perl-5.22.2.1-32bit-portable
49+
# https://github.com/sass/perl-libsass/issues/33
50+
####################################################################################################
51+
52+
sub reset_encoding()
53+
{
54+
binmode(STDIN, ":raw");
55+
binmode(STDOUT, ":raw");
56+
binmode(STDERR, ":raw");
57+
}
58+
59+
sub reinit_encoding()
60+
{
61+
binmode(STDIN, ":encoding(console_in)");
62+
binmode(STDOUT, ":encoding(console_out)");
63+
binmode(STDERR, ":encoding(console_out)");
64+
}
65+
66+
sub forks {
67+
reset_encoding();
68+
my $pid = fork();
69+
reinit_encoding();
70+
return $pid;
71+
}
72+
4673
####################################################################################################
4774
# the watchdog process (maybe put in own module)
4875
####################################################################################################
@@ -128,7 +155,7 @@ sub watchdog_parent ($$$)
128155
# new watch file list
129156
$files = \@includes;
130157
# start new child process
131-
unless ($child_pid = fork())
158+
unless ($child_pid = forks())
132159
{ watchdog_child($changes, $files); }
133160
}
134161

@@ -240,7 +267,7 @@ sub start_watchdog ($$)
240267
my @files = @{$stats->{'included_files'} || []};
241268

242269
# start child process
243-
if ($child_pid = fork())
270+
if ($child_pid = forks())
244271
{ watchdog_parent($changes, \@files, $compile); }
245272
else { watchdog_child($changes, \@files); }
246273

0 commit comments

Comments
 (0)
Please sign in to comment.