Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Inline CPAN distribution.

Report information
The Basics
Id: 81375
Status: resolved
Priority: 0/
Queue: Inline

People
Owner: Nobody in particular
Requestors: bernhard+cpan [...] lsmod.de
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.50
Fixed in: (no value)



Subject: chdir without cc
I used Inline C in eval to make optional acceleration and fallback to generic perl if unavailable, but this failed when no gcc was installed, because Inline would chdir to the _Inline/build/xxx_xxxx dir and remain there when the program started This caused errors with modules in "." not being found and output files going to the wrong place.
On Fri Nov 23 07:52:45 2012, bmwiedemann wrote: Show quoted text
> I used Inline C in eval > to make optional acceleration > and fallback to generic perl if unavailable, > but this failed when no gcc was installed, > because Inline would chdir to the _Inline/build/xxx_xxxx dir > and remain there when the program started > > This caused errors with modules in "." not being found > and output files going to the wrong place.
Could you post a simple demo script ? I can't reproduce the problem. I tried the following test script: ######################## use strict; use warnings; eval { require Inline; Inline->import (C => Config => BUILD_NOISY => 1); require Inline; Inline->import (C =><<' EOC'); int foo() { warn("Using Inline\n"); return 42; } EOC }; # If Inline is unavailable, foo() simply calls # the sub bar() pure perl implementation. if($@) { *foo =\&bar; } sub bar { warn("Using Pure Perl Implementation\n"); return 42; } my $x = foo(); print "$x\n"; ######################## If I hide cc (gcc.exe in my case), the build fails for that reason, and the script falls back to the pure perl implementation (sub bar). This is as it's meant to be, and as it should be. Cheers, Rob
From: bitcardbmw [...] lsmod.de
Am Fr 23. Nov 2012, 20:17:08, SISYPHUS schrieb: Show quoted text
> If I hide cc (gcc.exe in my case), the build fails for that reason, and > the script falls back to the pure perl implementation (sub bar). > This is as it's meant to be, and as it should be.
I appended to your script: system("pwd"); then did mv /usr/bin/cc{,.bak} rm -rf _Inline perl testc.pl [...] Starting "make" Stage /usr/bin/perl /usr/lib/perl5/5.16.0/ExtUtils/xsubpp -typemap "/usr/lib/perl5/5.16.0/ExtUtils/typemap" testc_pl_b91d.xs > testc_pl_b91d.xsc && mv testc_pl_b91d.xsc testc_pl_b91d.c cc -c -I"/home/bernhard/temp" -D_REENTRANT -D_GNU_SOURCE -DPERL_USE_SAFE_PUTENV -fno-strict-aliasing -pipe -fstack-protector -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -Wall -pipe -DVERSION=\"0.00\" -DXS_VERSION=\"0.00\" -fPIC "-I/usr/lib/perl5/5.16.0/x86_64-linux-thread-multi/CORE" testc_pl_b91d.c /bin/sh: cc: command not found make: *** [testc_pl_b91d.o] Error 127 Using Pure Perl Implementation 42 /home/bernhard/temp/_Inline/build/testc_pl_b91d and it showed that it changed the current dir for the perl process
On Sat Nov 24 07:56:37 2012, bmwiedemann wrote: Show quoted text
> I appended to your script: > system("pwd");
[snip] Show quoted text
> Using Pure Perl Implementation > 42 > /home/bernhard/temp/_Inline/build/testc_pl_b91d > > and it showed that it changed the current dir for the perl process
Yes, this could be fixed from within the script I provided as follows: ################################# use strict; use warnings; use Cwd; my $cwd = getcwd(); eval { require Inline; Inline->import (C => Config => #CC => 'bogus', # Easy way to make the build fail BUILD_NOISY => 1); require Inline; Inline->import (C =><<' EOC'); int foo() { warn("Using Inline\n"); return 42; } EOC }; # If Inline is unavailable, foo() simply calls # the sub bar() pure perl implementation. if($@) { chdir $cwd or warn "Couldn't chdir to $cwd"; *foo =\&bar; } sub bar { warn("Using Pure Perl Implementation\n"); return 42; } my $x = foo(); print "$x\n"; print $cwd, "\n"; ################################# (I've used Cwd::getcwd instead of the pwd system call because pwd is not available on all systems.) However, I think (not yet fully tested) this can also be fixed quite simply from within C.pm by rewriting sub compile as: ################################# sub compile { my $o = shift; my $build_dir = $o->{API}{build_dir}; my $cwd = &cwd; ($cwd) = $cwd =~ /(.*)/ if $o->UNTAINT; chdir $build_dir; eval { $o->call('makefile_pl', '"perl Makefile.PL"', 2); $o->call('make', '"make"', 2); $o->call('make_install', '"make install"', 2); }; chdir $cwd; die if $@; $o->call('cleanup', 'Cleaning Up', 2); } ################################# So I'll go with that changed version of C.pm's sub compile unless, in the course of more thorough testing, I discover a problem with it. If it tests ok for me, I'll release an Inline-0.51_03 that contains the fix in a day or two. Thanks for the report ! Cheers, Rob
Subject: Re: [rt.cpan.org #81375] chdir without cc
Date: Mon, 26 Nov 2012 17:53:18 -0600
To: bug-Inline [...] rt.cpan.org
From: David Mertens <dcmertens.perl [...] gmail.com>
For the curious, a CPAN solution that handles this *very* nicely is p3rl.org/File::chdir David On Nov 24, 2012 6:52 PM, "Sisyphus via RT" <bug-Inline@rt.cpan.org> wrote: Show quoted text
> Sat Nov 24 19:52:30 2012: Request 81375 was acted upon. > Transaction: Correspondence added by SISYPHUS > Queue: Inline > Subject: chdir without cc > Broken in: 0.50 > Severity: Normal > Owner: Nobody > Requestors: bernhard+cpan@lsmod.de > Status: open > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=81375 > > > > On Sat Nov 24 07:56:37 2012, bmwiedemann wrote: >
> > I appended to your script: > > system("pwd");
> > [snip] >
> > Using Pure Perl Implementation > > 42 > > /home/bernhard/temp/_Inline/build/testc_pl_b91d > > > > and it showed that it changed the current dir for the perl process
> > Yes, this could be fixed from within the script I provided as follows: > > ################################# > use strict; > use warnings; > use Cwd; > > > my $cwd = getcwd(); > > eval { > require Inline; Inline->import (C => Config => > #CC => 'bogus', # Easy way to make the build fail > BUILD_NOISY => 1); > > require Inline; Inline->import (C =><<' EOC'); > > int foo() { > warn("Using Inline\n"); > return 42; > } > > EOC > }; > > # If Inline is unavailable, foo() simply calls > # the sub bar() pure perl implementation. > if($@) { > chdir $cwd or warn "Couldn't chdir to $cwd"; > *foo =\&bar; > } > > sub bar { > warn("Using Pure Perl Implementation\n"); > return 42; > } > > my $x = foo(); > print "$x\n"; > print $cwd, "\n"; > ################################# > > (I've used Cwd::getcwd instead of the pwd system call because pwd is not > available on all systems.) > > However, I think (not yet fully tested) this can also be fixed quite > simply from within C.pm by rewriting sub compile as: > > ################################# > sub compile { > my $o = shift; > > my $build_dir = $o->{API}{build_dir}; > my $cwd = &cwd; > ($cwd) = $cwd =~ /(.*)/ if $o->UNTAINT; > > chdir $build_dir; > eval { > $o->call('makefile_pl', '"perl Makefile.PL"', 2); > $o->call('make', '"make"', 2); > $o->call('make_install', '"make install"', 2); > }; > chdir $cwd; > die if $@; > $o->call('cleanup', 'Cleaning Up', 2); > } > ################################# > > So I'll go with that changed version of C.pm's sub compile unless, in > the course of more thorough testing, I discover a problem with it. > If it tests ok for me, I'll release an Inline-0.51_03 that contains the > fix in a day or two. > > Thanks for the report ! > > Cheers, > Rob > > >
CC: inline [...] perl.org
Subject: Re: [rt.cpan.org #81375] chdir without cc
Date: Tue, 27 Nov 2012 10:02:28 +0800
To: bug-Inline [...] rt.cpan.org
From: Xiao Yafeng <xyf.xiao [...] gmail.com>
I vote for David, It's a bug from chdir other than Inline. On Tue, Nov 27, 2012 at 7:53 AM, dcmertens.perl@gmail.com via RT < bug-Inline@rt.cpan.org> wrote: Show quoted text
> Mon Nov 26 18:53:28 2012: Request 81375 was acted upon. > Transaction: Correspondence added by dcmertens.perl@gmail.com > Queue: Inline > Subject: Re: [rt.cpan.org #81375] chdir without cc > Broken in: 0.50 > Severity: Normal > Owner: Nobody > Requestors: bernhard+cpan@lsmod.de > Status: open > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=81375 > > > > For the curious, a CPAN solution that handles this *very* nicely is > p3rl.org/File::chdir > > David > On Nov 24, 2012 6:52 PM, "Sisyphus via RT" <bug-Inline@rt.cpan.org> wrote: >
> > Sat Nov 24 19:52:30 2012: Request 81375 was acted upon. > > Transaction: Correspondence added by SISYPHUS > > Queue: Inline > > Subject: chdir without cc > > Broken in: 0.50 > > Severity: Normal > > Owner: Nobody > > Requestors: bernhard+cpan@lsmod.de > > Status: open > > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=81375 > > > > > > > On Sat Nov 24 07:56:37 2012, bmwiedemann wrote: > >
> > > I appended to your script: > > > system("pwd");
> > > > [snip] > >
> > > Using Pure Perl Implementation > > > 42 > > > /home/bernhard/temp/_Inline/build/testc_pl_b91d > > > > > > and it showed that it changed the current dir for the perl process
> > > > Yes, this could be fixed from within the script I provided as follows: > > > > ################################# > > use strict; > > use warnings; > > use Cwd; > > > > > > my $cwd = getcwd(); > > > > eval { > > require Inline; Inline->import (C => Config => > > #CC => 'bogus', # Easy way to make the build fail > > BUILD_NOISY => 1); > > > > require Inline; Inline->import (C =><<' EOC'); > > > > int foo() { > > warn("Using Inline\n"); > > return 42; > > } > > > > EOC > > }; > > > > # If Inline is unavailable, foo() simply calls > > # the sub bar() pure perl implementation. > > if($@) { > > chdir $cwd or warn "Couldn't chdir to $cwd"; > > *foo =\&bar; > > } > > > > sub bar { > > warn("Using Pure Perl Implementation\n"); > > return 42; > > } > > > > my $x = foo(); > > print "$x\n"; > > print $cwd, "\n"; > > ################################# > > > > (I've used Cwd::getcwd instead of the pwd system call because pwd is not > > available on all systems.) > > > > However, I think (not yet fully tested) this can also be fixed quite > > simply from within C.pm by rewriting sub compile as: > > > > ################################# > > sub compile { > > my $o = shift; > > > > my $build_dir = $o->{API}{build_dir}; > > my $cwd = &cwd; > > ($cwd) = $cwd =~ /(.*)/ if $o->UNTAINT; > > > > chdir $build_dir; > > eval { > > $o->call('makefile_pl', '"perl Makefile.PL"', 2); > > $o->call('make', '"make"', 2); > > $o->call('make_install', '"make install"', 2); > > }; > > chdir $cwd; > > die if $@; > > $o->call('cleanup', 'Cleaning Up', 2); > > } > > ################################# > > > > So I'll go with that changed version of C.pm's sub compile unless, in > > the course of more thorough testing, I discover a problem with it. > > If it tests ok for me, I'll release an Inline-0.51_03 that contains the > > fix in a day or two. > > > > Thanks for the report ! > > > > Cheers, > > Rob > > > > > >
> >
CC: Perl Inline Mail List <inline [...] perl.org>
Subject: Re: [rt.cpan.org #81375] chdir without cc
Date: Mon, 26 Nov 2012 22:13:25 -0600
To: bug-Inline [...] rt.cpan.org
From: David Mertens <dcmertens.perl [...] gmail.com>
Er, sorry, I wasn't trying to argue that this is an error in Perl or a CPAN dependency. Rather, my comment was meant for the edification of anybody following this list of communication. As it is, if Inline doesn't mind adding a dependency, then perhaps adding the dependency on File::chdir would make this a little easier. But I don't think that such a dependency is necessary by any means. David On Mon, Nov 26, 2012 at 8:03 PM, Xiao Yafeng via RT <bug-Inline@rt.cpan.org>wrote: Show quoted text
> Mon Nov 26 21:03:00 2012: Request 81375 was acted upon. > Transaction: Correspondence added by xyf.xiao@gmail.com > Queue: Inline > Subject: Re: [rt.cpan.org #81375] chdir without cc > Broken in: 0.50 > Severity: Normal > Owner: Nobody > Requestors: bernhard+cpan@lsmod.de > Status: open > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=81375 > > > > I vote for David, It's a bug from chdir other than Inline. > > On Tue, Nov 27, 2012 at 7:53 AM, dcmertens.perl@gmail.com via RT < > bug-Inline@rt.cpan.org> wrote: >
> > Mon Nov 26 18:53:28 2012: Request 81375 was acted upon. > > Transaction: Correspondence added by dcmertens.perl@gmail.com > > Queue: Inline > > Subject: Re: [rt.cpan.org #81375] chdir without cc > > Broken in: 0.50 > > Severity: Normal > > Owner: Nobody > > Requestors: bernhard+cpan@lsmod.de > > Status: open > > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=81375 > > > > > > > For the curious, a CPAN solution that handles this *very* nicely is > > p3rl.org/File::chdir > > > > David > > On Nov 24, 2012 6:52 PM, "Sisyphus via RT" <bug-Inline@rt.cpan.org>
> wrote:
> >
> > > Sat Nov 24 19:52:30 2012: Request 81375 was acted upon. > > > Transaction: Correspondence added by SISYPHUS > > > Queue: Inline > > > Subject: chdir without cc > > > Broken in: 0.50 > > > Severity: Normal > > > Owner: Nobody > > > Requestors: bernhard+cpan@lsmod.de > > > Status: open > > > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=81375 > > > > > > > > > > On Sat Nov 24 07:56:37 2012, bmwiedemann wrote: > > >
> > > > I appended to your script: > > > > system("pwd");
> > > > > > [snip] > > >
> > > > Using Pure Perl Implementation > > > > 42 > > > > /home/bernhard/temp/_Inline/build/testc_pl_b91d > > > > > > > > and it showed that it changed the current dir for the perl process
> > > > > > Yes, this could be fixed from within the script I provided as follows: > > > > > > ################################# > > > use strict; > > > use warnings; > > > use Cwd; > > > > > > > > > my $cwd = getcwd(); > > > > > > eval { > > > require Inline; Inline->import (C => Config => > > > #CC => 'bogus', # Easy way to make the build fail > > > BUILD_NOISY => 1); > > > > > > require Inline; Inline->import (C =><<' EOC'); > > > > > > int foo() { > > > warn("Using Inline\n"); > > > return 42; > > > } > > > > > > EOC > > > }; > > > > > > # If Inline is unavailable, foo() simply calls > > > # the sub bar() pure perl implementation. > > > if($@) { > > > chdir $cwd or warn "Couldn't chdir to $cwd"; > > > *foo =\&bar; > > > } > > > > > > sub bar { > > > warn("Using Pure Perl Implementation\n"); > > > return 42; > > > } > > > > > > my $x = foo(); > > > print "$x\n"; > > > print $cwd, "\n"; > > > ################################# > > > > > > (I've used Cwd::getcwd instead of the pwd system call because pwd is
> not
> > > available on all systems.) > > > > > > However, I think (not yet fully tested) this can also be fixed quite > > > simply from within C.pm by rewriting sub compile as: > > > > > > ################################# > > > sub compile { > > > my $o = shift; > > > > > > my $build_dir = $o->{API}{build_dir}; > > > my $cwd = &cwd; > > > ($cwd) = $cwd =~ /(.*)/ if $o->UNTAINT; > > > > > > chdir $build_dir; > > > eval { > > > $o->call('makefile_pl', '"perl Makefile.PL"', 2); > > > $o->call('make', '"make"', 2); > > > $o->call('make_install', '"make install"', 2); > > > }; > > > chdir $cwd; > > > die if $@; > > > $o->call('cleanup', 'Cleaning Up', 2); > > > } > > > ################################# > > > > > > So I'll go with that changed version of C.pm's sub compile unless, in > > > the course of more thorough testing, I discover a problem with it. > > > If it tests ok for me, I'll release an Inline-0.51_03 that contains the > > > fix in a day or two. > > > > > > Thanks for the report ! > > > > > > Cheers, > > > Rob > > > > > > > > >
> > > >
> >
-- "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." -- Brian Kernighan
On Mon Nov 26 21:03:00 2012, xyf.xiao@gmail.com wrote: Show quoted text
> I vote for David, It's a bug from chdir other than Inline.
File::chdir certainly provides an elegant solution to the problem, but I'll stick with using the eval{} safety net, for the moment at least. I'm not really all that keen to introduce a new dependency just to save a couple of lines of code. I do think it's an Inline::C bug. Admittedly, it's a bit unusual to want to safeguard Inline::C code against the absence of a C compiler (or of a missing make utility or of uncompilable code, etc.), but I think one is entitled to do that. And if one wants to do that by using eval{} (as the OP does), then one has every right to expect that the script will return to the *original* cwd if $@ gets set. I think chdir() is behaving as it should. If we want to claim that it's not an Inline::C bug, then we would have to argue that the OP is doing something that's not allowed. (But of course, IMO, he isn't doing anything wrong.) Cheers, Rob
On Sat Nov 24 19:52:30 2012, SISYPHUS wrote: Show quoted text
> ################################# > sub compile { > my $o = shift; > > my $build_dir = $o->{API}{build_dir}; > my $cwd = &cwd; > ($cwd) = $cwd =~ /(.*)/ if $o->UNTAINT; > > chdir $build_dir; > eval { > $o->call('makefile_pl', '"perl Makefile.PL"', 2); > $o->call('make', '"make"', 2); > $o->call('make_install', '"make install"', 2); > }; > chdir $cwd; > die if $@; > $o->call('cleanup', 'Cleaning Up', 2); > } > #################################
I've just uploaded Inline-0.51_03 to CPAN. It contains the (above) modified sub compile, along with an additional test script (C/t/20eval.t) that's designed to check that it works as expected. Feel free to give this change a good prod and a poke ... and let me know if it's inadequate in any way. Cheers, Rob
Fixed in 0.52. Thank you for the report.