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: 55607
Status: resolved
Priority: 0/
Queue: Inline

People
Owner: Nobody in particular
Requestors: MOB [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in:
  • 0.45
  • 0.46
Fixed in: (no value)



Subject: Bind at runtime can cause "Modification of a read-only value attempted" error
This code produces a "Modification of a read-only value attempted" error in the Inline::bind method: 1: use strict qw(vars subs); 2: for ('function') { 3: $_->(); 4: } 5: 6: sub function { 7: require Inline; 8: Inline->bind(C => <<'__CODE__'); 9: void foo() 10: { 11: } 12: __CODE__ 13: } With '-MCarp::Always', the output is: Modification of a read-only value attempted at /usr/lib/perl5/site_perl/5.10/Inline/denter.pm line 191 Inline::denter::_setup_line('Inline::denter=HASH(0x101a4940)') called at /usr/lib/perl5/site_perl/5.10/Inline/denter.pm line 30 Inline::denter::undent('Inline::denter=HASH(0x101a4940)', 'version : 0.45\x{d}\x{a}languages : %\x{d}\x{a} C : C\x{d}\x{a} Foo : Foo\x{d}\x{a} ...') called at blib/lib/Inline.pm (autosplit into blib/lib/auto/Inline/check_config_file.al) line 704 Inline::check_config_file('Inline=HASH(0x1013a890)') called at /usr/lib/perl5/site_perl/5.10/Inline.pm line 244 Inline::glue('Inline=HASH(0x1013a890)') called at /usr/lib/perl5/site_perl/5.10/Inline.pm line 182 Inline::bind('Inline', 'C', 'void foo()\x{a}{\x{a}}\x{a}') called at inline_issue.pl line 8 main::function1() called at inline_issue.pl line 3 I see there are functions in the Inline module, including Inline::denter::_next_line, Inline::denter::_setup_line, Inline::denter::indent, and Inline::C::get_types, that overwrite the value of $_ without localizing or lexically scoping it. When $_ is used in a way that makes it a read-only value, as it is on line 3 of the test script, the error occurs. Now that I know what causes this problem, it is easy to workaround it in the code that calls Inline, but it would also be possible to prevent this problem inside the Inline module.
On Mon Mar 15 17:07:01 2010, MOB wrote: Show quoted text
> I see there are functions in the Inline module, including > Inline::denter::_next_line, Inline::denter::_setup_line, > Inline::denter::indent, and Inline::C::get_types, that overwrite the > value of $_ without localizing or lexically scoping it.
In Inline-0.46 I think you'll find that Inline::denter already local() ises $_ where necessary. It just remains to do a 'local $_;' declaration at the beginning of Inline::C::get_types() and the script you posted runs fine for me. Could you confirm for me that fixes your problems, too ? Thanks for the report. Sorry I've been a bit slow getting back to you - I actually didn't notice your report until a couple of days ago. Cheers, Rob
On Tue Mar 30 05:59:43 2010, SISYPHUS wrote: Show quoted text
> On Mon Mar 15 17:07:01 2010, MOB wrote: >
> > I see there are functions in the Inline module, including > > Inline::denter::_next_line, Inline::denter::_setup_line, > > Inline::denter::indent, and Inline::C::get_types, that overwrite the > > value of $_ without localizing or lexically scoping it.
> > In Inline-0.46 I think you'll find that Inline::denter already local() > ises $_ where necessary. It just remains to do a 'local $_;' > declaration at the beginning of Inline::C::get_types() and the script > you posted runs fine for me. Could you confirm for me that fixes your > problems, too ? > > Thanks for the report. Sorry I've been a bit slow getting back to you
- Show quoted text
> I actually didn't notice your report until a couple of days ago. > > Cheers, > Rob
Hi Rob, Adding a "local $_" inside Inline::C::get_types() fixes the issue in Inline-0.46. Here's a test script that passes after the change is made: ################################################################ use Test::More tests => 1; use strict qw(vars subs); use warnings; for ('function') { $_->(); } sub function { require Inline; Inline->bind(C => <<'__CODE__'); int foo() { return 42; } __CODE__ } ok(42==foo(), "run-time bind successful while \$_ is read-only"); ############################################################# Keep up the great work, Marty O'Brien
On Wed Mar 31 00:37:52 2010, MOB wrote: Show quoted text
> Adding a "local $_" inside Inline::C::get_types() fixes the issue in > Inline-0.46.
Thanks Marty. Inline-0.46_01 (uploaded to CPAN yesterday) contains the fix, and a test script (C/t/11default_readonly.t) that's based on the scripts you provided. I'll leave this bug report open until 0.47 is released ... not sure when that will be. Cheers, Rob
RT-Send-CC: MOB [...] cpan.org
Hi Marty, Inline-0.47 uploaded to CPAN today - therefore closing this ticket. Cheers, Rob