PerlFFI / FFI-Platypus

Write Perl bindings to non-Perl libraries with FFI. No XS required.
89 stars 23 forks source link

Bundle test hung on Cygwin environment #320

Closed albertlotw closed 3 years ago

albertlotw commented 3 years ago

I have successfully compiled FFI::Platypus module in my Cygwin environment. However, running make test got hung. It occurred on running test file t/ffi_platypus_bundle.t. After disabling Capture::Tiny and running the test program alone, I got the error outputs

perl t/ffi_platypus_bund.t
# Subtest: from installed
    # spew(start)[/home/user/git/FFI-Platypus/t/.tmp/kS0WTAde4y/lib/Foo/Bar1.pm]
    #     package Foo::Bar1;
    #     use strict;
    #     use warnings;
    #     use FFI::Platypus;
    #     my $ffi = FFI::Platypus->new( api => 1, lang => 'ASM' );
    #     $ffi->bundle;
    #     $ffi->attach("bar1" => [] => 'sint32');
    #     1;
    # spew(end)
    # +gcc -DPERL_USE_SAFE_PUTENV -U__STRICT_ANSI__ -D_GNU_SOURCE -ggdb -O2 -pipe -Wall -Werror=format-security -D_FORTIFY_SOURCE=2 -fstack-protector-strong --param=ssp-buffer-size=4 -fdebug-prefix-map=/mnt/share/cygpkgs/perl/perl.x86_64/build=/usr/src/debug/perl-5.32.1-1 -fdebug-prefix-map=/mnt/share/cygpkgs/perl/perl.x86_64/src/perl-5.32.1=/usr/src/debug/perl-5.32.1-1 -fwrapv -fno-strict-aliasing -O3 -I/usr/local/lib/perl5/site_perl/5.32/x86_64-cygwin-threads/auto/share/dist/FFI-Platypus/include -c /home/user/git/FFI-Platypus/t/.tmp/ffi_build_M5YoLS.c -o /home/user/git/FFI-Platypus/t/.tmp/_build/ffi_build_M5YoLS.c.o
    # 0+g++ --shared -Wl,--enable-auto-import -Wl,--export-all-symbols -Wl,--enable-auto-image-base -fstack-protector-strong /home/user/git/FFI-Platypus/t/.tmp/_build/ffi_build_M5YoLS.c.o -o /home/user/git/FFI-Platypus/t/.tmp/kS0WTAde4y/lib/auto/share/dist/Foo-Bar1/cygbar1.dll
    # spew(start)[/home/user/git/FFI-Platypus/t/.tmp/kS0WTAde4y/lib/auto/Foo/Bar1/Bar1.txt]
    # FFI::Build@auto/share/dist/Foo-Bar1/cygbar1.dll
    # spew(end)
    ok 1
    ok 2
    ok 3
    ok 4
    1..4
ok 1 - from installed
# Subtest: from blib
    # spew(start)[/home/user/git/FFI-Platypus/t/.tmp/InjpzIve7C/lib/Foo/Bar2.pm]
    #     package Foo::Bar2;
    #     use strict;
    #     use warnings;
    #     use FFI::Platypus;
    #     my $ffi = FFI::Platypus->new( api => 1, lang => 'ASM' );
    #     $ffi->bundle;
    #     $ffi->attach("bar2" => [] => 'sint32');
    #     1;
    # spew(end)
+gcc -DPERL_USE_SAFE_PUTENV -U__STRICT_ANSI__ -D_GNU_SOURCE -ggdb -O2 -pipe -Wall -Werror=format-security -D_FORTIFY_SOURCE=2 -fstack-protector-strong --param=ssp-buffer-size=4 -fdebug-prefix-map=/mnt/share/cygpkgs/perl/perl.x86_64/build=/usr/src/debug/perl-5.32.1-1 -fdebug-prefix-map=/mnt/share/cygpkgs/perl/perl.x86_64/src/perl-5.32.1=/usr/src/debug/perl-5.32.1-1 -fwrapv -fno-strict-aliasing -O3 -I/usr/local/lib/perl5/site_perl/5.32/x86_64-cygwin-threads/auto/share/dist/FFI-Platypus/include -c /home/user/git/FFI-Platypus/t/.tmp/ffi_build_IHrpUk.c -o /home/user/git/FFI-Platypus/t/.tmp/_build/ffi_build_IHrpUk.c.o
      0 [main] perl 35446 child_info_fork::abort: unable to map \??\D:\cyg_home\user\git\FFI-Platypus\t\.tmp\kS0WTAde4y\lib\auto\share\dist\Foo-Bar1\cygbar1.dll (using D:\cyg_home\user\git\FFI-Platypus\t\.tmp\kS0WTAde4y\lib\auto\share\dist\Foo-Bar1\cygbar1.dll), Win32 error 126
      1 [main] perl 35447 child_info_fork::abort: unable to map \??\D:\cyg_home\user\git\FFI-Platypus\t\.tmp\kS0WTAde4y\lib\auto\share\dist\Foo-Bar1\cygbar1.dll (using D:\cyg_home\user\git\FFI-Platypus\t\.tmp\kS0WTAde4y\lib\auto\share\dist\Foo-Bar1\cygbar1.dll), Win32 error 126
      0 [main] perl 35448 child_info_fork::abort: unable to map \??\D:\cyg_home\user\git\FFI-Platypus\t\.tmp\kS0WTAde4y\lib\auto\share\dist\Foo-Bar1\cygbar1.dll (using D:\cyg_home\user\git\FFI-Platypus\t\.tmp\kS0WTAde4y\lib\auto\share\dist\Foo-Bar1\cygbar1.dll), Win32 error 126
      1 [main] perl 35449 child_info_fork::abort: unable to map \??\D:\cyg_home\user\git\FFI-Platypus\t\.tmp\kS0WTAde4y\lib\auto\share\dist\Foo-Bar1\cygbar1.dll (using D:\cyg_home\user\git\FFI-Platypus\t\.tmp\kS0WTAde4y\lib\auto\share\dist\Foo-Bar1\cygbar1.dll), Win32 error 126

It shows child_info_fork::abort error repeated endlessly.

After some tracing and trying, I figure out it was due to deleting of cygbar1.dll after require Foo::Bar1. The deletion of the DLL was done on calling $build->clean, where $build is a FFI::Build object. The deletion also happens on destruction of $root, which is a FFI::Temp object. I made a modification of the test file as attached, where it preserves $build and $root of each test and destroys them only after all bundle test finished. After the modify, all the bundle tests run smoothly on my Cygwin.

bundle_test.patch.gz

plicease commented 3 years ago

Thank you for reporting this. Can you please let me know if #321 would also resolve this bug?

albertlotw commented 3 years ago

I just tried the newly created branch graham/fix-cygwin-hang. It is improved, but it still hangs on a later test item. I think it's because this object got destroyed early.

plicease commented 3 years ago

@sjaluo thanks. I've updated the PR can you check it?

albertlotw commented 3 years ago

Yes. I can finish and pass all the test items on Cygwin now. Thanks!

plicease commented 3 years ago

@sjaluo FYI- I released this as 1.43.

plicease commented 3 years ago

I am pretty sure I have made changes like this in the past to get cygwin working, so I've added cygwin (and msys2) to CI so that we can catch this when incompatible changes happen rather than afterward #322