Skip to content

Instantly share code, notes, and snippets.

@mattn
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattn/35ce0c2a4b377aae05ff to your computer and use it in GitHub Desktop.
Save mattn/35ce0c2a4b377aae05ff to your computer and use it in GitHub Desktop.
perl -e "use open qw{:encoding(UTF-8) :std}; fork;" で落ちる問題のパッチを書こう(まだ駄目です)
#! perl.exe
use strict;
use warnings;
#use open qw{:std :encoding(UTF-8)}; # これは落ちる
use open qw{:encoding(UTF-8)}; # これは落ちなくなった
my $i = 1;
my $pid = fork;
die "Cannot fork: $!" unless defined $pid;
if ($pid) {
print "foo $i\n";
} else {
print "bar\n";
}
diff --git a/ext/PerlIO-encoding/encoding.xs b/ext/PerlIO-encoding/encoding.xs
index 03b8850..f9120e4 100644
--- a/ext/PerlIO-encoding/encoding.xs
+++ b/ext/PerlIO-encoding/encoding.xs
@@ -560,6 +560,9 @@ PerlIO *
PerlIOEncode_dup(pTHX_ PerlIO * f, PerlIO * o,
CLONE_PARAMS * params, int flags)
{
+ if (!PL_curstackinfo) {
+ return f;
+ }
if ((f = PerlIOBase_dup(aTHX_ f, o, params, flags))) {
PerlIOEncode *fe = PerlIOSelf(f, PerlIOEncode);
PerlIOEncode *oe = PerlIOSelf(o, PerlIOEncode);
diff --git a/perlio.c b/perlio.c
index 92fa2be..fa88c5e 100644
--- a/perlio.c
+++ b/perlio.c
@@ -453,7 +453,7 @@ PerlIO_verify_head(pTHX_ PerlIO *f)
*/
#define PERLIO_TABLE_SIZE 64
-static void
+void
PerlIO_init_table(pTHX)
{
if (PL_perlio)
diff --git a/sv.c b/sv.c
index 2bb0346..94e20d5 100644
--- a/sv.c
+++ b/sv.c
@@ -14762,7 +14762,13 @@ perl_clone_using(PerlInterpreter *proto_perl, UV flags,
#ifdef PERLIO_LAYERS
/* Clone PerlIO tables as soon as we can handle general xx_dup() */
- PerlIO_clone(aTHX_ proto_perl, param);
+ //PerlIO_clone(aTHX_ proto_perl, param);
+ PL_perlio = NULL;
+ PL_known_layers = (PerlIO_list_t*) PerlIO_clone_list(aTHX_ proto_perl->Iknown_layers, param);
+ PL_def_layerlist = (PerlIO_list_t*) PerlIO_clone_list(aTHX_ proto_perl->Idef_layerlist, param);
+ //PerlIO_stdstreams(aTHX);
+ extern PerlIO_init_table(pTHX);
+ PerlIO_init_table(aTHX);
#endif
PL_envgv = gv_dup_inc(proto_perl->Ienvgv, param);
@@ -15108,6 +15114,8 @@ perl_clone_using(PerlInterpreter *proto_perl, UV flags,
SAVEFREESV(PL_compcv);
}
+ //PerlIO_clone(aTHX_ proto_perl, param);
+
return my_perl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment