Skip Menu |

This queue is for tickets about the Safe CPAN distribution.

Report information
The Basics
Id: 31286
Status: resolved
Priority: 0/
Queue: Safe

People
Owner: Nobody in particular
Requestors: eagle42 [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 2.11
Fixed in: (no value)



Subject: Problems with Safe and utf8
Safe does not work if I "use encoding 'utf8';". All I get is an error message: Can't locate object method "renewed" via package "Encode::utf8" (perhaps you forgot to load "Encode::utf8"?) at (eval 2) line 1. As far as I know, there is no Encode::utf8 (it's supposed to be internal), and commenting out that "use encoding 'utf8';" makes the same source not die anymore. I use perl 5.8.8 with its included Safe.pm 2.12, but have also tried using the 2.11 from CPAN instead. I have tested it on default perl included on Debian 4.0, compiled from vanilla source, and the one bundled with Mac OS X 10.5.1. The result is always the same. There is a workaround to the problem, however, I don't really understand how or why this works. :) In reval() inside Safe; just after the $evalsub has been retrieved from lexless_anon_sub(), if I append anything (even an empty string) to the $expr, the problem disappears! In code: my $evalsub = lexless_anon_sub($root,$strict, $expr); $expr.""; return Opcode::_safe_call_sv($root, $obj->{Mask}, $evalsub); Attached is a trivial script which can be used to reproduce the error.
Subject: safe.pl
#!/usr/bin/perl use encoding 'utf8'; use Safe; sub foo { my $expr = shift(); if (my $safe = new Safe()) { $ret = $safe->reval ("$expr"); } if ($@) { print "Error while evaluating \"$expr\": $@\n"; } } &foo('print "eval OK\n";');
See the proposed resolution and discussion at the bug report for perl: http://rt.perl.org/rt3/Ticket/Display.html?id=48419 The real workaround would be to permit the called method to be imported in the Safe compartment. That is, once $safe is created, and before the call to reval(), do: $safe->share('Encode::Encoding::renewed'); I'm not sure that bug can be safely fixed in Safe.