Forum archive 2000-2006

Zbigniew Fiedorowicz - Bandaid for PGsort pink pages (Perl 5.8/RH 9)

Zbigniew Fiedorowicz - Bandaid for PGsort pink pages (Perl 5.8/RH 9)

by Arnold Pizer -
Number of replies: 0
inactiveTopicBandaid for PGsort pink pages (Perl 5.8/RH 9) topic started 11/3/2003; 8:23:52 AM
last post 12/17/2003; 2:07:05 PM
userZbigniew Fiedorowicz - Bandaid for PGsort pink pages (Perl 5.8/RH 9)  blueArrow
11/3/2003; 8:23:52 AM (reads: 1936, responses: 11)
I got tired of complaints about the pink pages previously discussed here and created a temporary bandaid by editting Global.pm as follows:
 Global.pm.bak2      2003-11-03 07:47:02.000000000 -0500
--- Global.pm 2003-11-03 08:20:20.000000000 -0500

892,899 *

$Global::WARNINGS .="* " . join("
",@input) . "
n" . $out_string .
"
n--------------------------------------
n
n";
! $Global::background_plain_url = $Global::background_warn_url;
! $Global::bg_color = '#FF99CC'; #for warnings -- this change may come too late
}

$SIG{__WARN__}=&PG_warnings_handler;
--- 892,901 -




$Global::WARNINGS .="* " . join("
",@input) . "
n" . $out_string .
"
n--------------------------------------
n
n";
! if (!($Global::WARNINGS=~/Use of uninitialized value in numeric comparison/)) {
! $Global::background_plain_url = $Global::background_warn_url;
! $Global::bg_color = '#FF99CC'; #for warnings -- this change may come too late
! }
}

$SIG{__WARN__}=&PG_warnings_handler;

BTW is anyone working on a more permanent fix?

Zig Fiedorowicz

<| Post or View Comments |>


userArnold K. Pizer - Re: Bandaid for PGsort pink pages (Perl 5.8/RH 9)  blueArrow
11/4/2003; 9:45:36 AM (reads: 2127, responses: 0)

Hi Zig,

Unfortunately, the warnings indicates a real problem so that eliminating pink pages "hides" an incorrect problem.  PGsort doesn't seem to work with the new versions of Safe.pm which may be related to changes in Safe.pm that occurred with version 2.08 having to do with how @_ is passed (see http://www.perl.com/CPAN-local/modules/by-module/Safe/Safe-2.09.readme).  Further look at the discussion at http://webhost.math.rochester.edu/webworkdocs/discuss/msgReader$1862

There is no difficulty with Safe.pm 2.06 and Perl 5.6 and I assume from the above readme file there would be no problem with Safe 2.07 and perl 5.8 but I don't have a copy of 2.07 and haven't tested this.

Perl's sort for efficiency reasons passes arguments using global variable $a and $b rather than via the standard method using @_ (or $_[0], $_[1]).  But this interfered with the use of $a and $b as variables in problems and/or with using Safe compartments (I'm on shaky ground here) so Mike wrote the short subroutine PGsort which is in PGtranslator.pm.  Here it is:

sub PGsort {
 my $sort_order = shift;
 die "Must supply an ordering function with PGsort: PGsort sub {\$a cmp \$b }, \@list\n" unless ref($sort_order) eq 'CODE';
 sort {&$sort_order($a,$b)} @_;
}

and it's called e.g. as follows: PGsort sub { $_[0] <=> $_[1] }, @list;

But this no longer works in a safe compartment with versions of Safe.pm newer than 2.07. 

We are trying to work on this but none too successfully. If there are perl experts out there who would like to take a crack at this, please do.

Note that if all else fails, we could rewrite PGsort so that it does not use Perl's sort, but rather implements some standard sorting method.  This would be less efficient than  Perl's sort, but as PGsort is only used within problems we are only concerned with sorting relatively short lists and the lost efficiency would be negligible.

 

Arnie

 

<| Post or View Comments |>


userZbigniew Fiedorowicz - Re: Bandaid for PGsort pink pages (Perl 5.8/RH 9)  blueArrow
11/4/2003; 11:25:32 AM (reads: 2102, responses: 0)

Hi Arnie,

I gather that PGsort is only used in John Jones' answer evaluators number_list_cmp() and perhaps interval_cmp().  However they seem to function correctly under Perl 5.8/Safe2.09, provided that students enter their answers in already sorted order.

I am afraid to switch our new WeBWorK server to Perl 5.6 in the middle of our academic quarter, fearing that it will cause more problems than it will cure.

Are you sure that Safe-2.07 works under Perl 5.8? And that it is compatible with PGsort?  And where may I get hold of it?  Acursory search of CPAN and Google didn't turn it up.

I did try running Safe-2.06 with Perl 5.8 and that sure didn't work.

As I said in my first message, my solution is only a bandaid. However it doesn't cause any harm and seems to satisfy our students and instructors.

 

Zig

 

<| Post or View Comments |>


userZbigniew Fiedorowicz - Re: Bandaid for PGsort pink pages (Perl 5.8/RH 9)  blueArrow
11/4/2003; 1:39:34 PM (reads: 2087, responses: 0)

Hi Arnie,

I managed to locate Safe.pm version 2.07 on the CPAN site.  [It was in a perl5.7.2 tarball.]  It does work with Perl 5.8, but it is not compatible with PGsort any more than the later versions - the same compiler warning messages are generated.  Moreover there is essentially only one difference between Safe.pm version 2.07 and Safe.pm version 2.06: the line

Opcode::_safe_pkg_prep($obj->{Root});

has been added. [The other differences are just in the formatting and comments.] In Safe.pm version 2.09 this line is changed to:

Opcode::_safe_pkg_prep($obj->{Root}) if($Opcode::VERSION > 1.04);

Zig

<| Post or View Comments |>


userZbigniew Fiedorowicz - Re: Bandaid for PGsort pink pages (Perl 5.8/RH 9)  blueArrow
11/4/2003; 8:24:21 PM (reads: 2109, responses: 0)

Hi Mike and Arnie,

I was looking through the compiler warnings generated by this bug and noticed that the only mention of Safe.pm was the following:

Safe::reval called at /web/webwork/system/lib//PGtranslator.pm line 942

which refers to the following line:

$rh_ans_evaluation_result = $self->{safe} ->reval( '&{ $rf_fun }($temp_ans)' ) ;

This means that safe->reval() is being called on a pointer to code, rather than a string as the Safe module docs indicate should be the argument. It looks to me like you are relying on some undocumented feature of safe->reval() which has no guarantee of support between version changes.

Zig

<| Post or View Comments |>


userMichael Gage - Re: Bandaid for PGsort pink pages (Perl 5.8/RH 9)  blueArrow
11/4/2003; 10:36:54 PM (reads: 2080, responses: 0)
This code works correctly on Safe 2.09 and perl 5.6.0 under MacOS X.

Zig and I have verified that it does not work on red hat linux using perl 5.8.0 and Safe 2.09. (The list is not sorted numerically in that case.)

Is this a feature of all implimentations of perl 5.8.0? I would appreciate it if someone could run this code under perl 5.8.0 and a Solaris operating system, or one of the other unix operating systems.

Thanks. --Mike

 

#################################################
#!/usr/bin/perl -w



use strict;
# Lines used on my
# Mac to make sure that Safe2.09 was used instead of 2.06
#use lib ".";
#require "/Volumes/Riemann/webwork/webwork_sort_testing/Safe.pm";



use Safe;



sub PGsort {
local($a,$b);
my $compare = shift;
sort {&$compare($a, $b) } @_;
}




my $cmp = new Safe;
print "Safe version $Safe::VERSION\n";
$cmp->share('&PGsort');
my $string = <<'EOF';
my @list = (4,6,2, 5 ,10, 8, 9 );
my $str = join( " ", PGsort sub {$_[0] <=> $_[1] } , @list );
print $str;
EOF



#print $string;
#print "next\n\n";



$cmp->reval($string);
#output
#Safe version 2.09
#2 4 5 6 8 9 10
# perl version is
#This is perl, v5.6.0 built for darwin
#################################################

<| Post or View Comments |>


userZbigniew Fiedorowicz - Re: Bandaid for PGsort pink pages (Perl 5.8/RH 9)  blueArrow
11/5/2003; 7:56:14 AM (reads: 2081, responses: 0)

Mike,

I've posted your code to comp.lang.perl.modules and comp.lang.perl.misc

Zig

 

<| Post or View Comments |>


userGavin LaRose - Re: Bandaid for PGsort pink pages (Perl 5.8/RH 9)  blueArrow
11/5/2003; 8:26:48 AM (reads: 2093, responses: 0)
Results on my box:

frisbee:glarose% uname -sr
SunOS 5.8
frisbee:glarose% perl -v | head -2

This is perl, v5.8.0 built for sun4-solaris
frisbee:glarose% ./perltest
Safe version 2.07
2 4 5 6 8 9 10
frisbee:glarose%

Cheers,
Gavin

<| Post or View Comments |>


userZbigniew Fiedorowicz - Re: Bandaid for PGsort pink pages (Perl 5.8/RH 9)  blueArrow
11/5/2003; 3:52:06 PM (reads: 2120, responses: 1)
Here's a response to my post in comp.lang.perl.modules.  He seems to
have diagnosed the problem. I do get



webwork2 fiedorow [3] perl -V:useithreads
useithreads='define';




Newsgroups: comp.lang.perl.modules
From: Rafael Garcia-Suarez <rgarciasuarez@free.fr>
Subject: Re: Sorting in Safe compartments under Perl 5.8.0

Zbigniew Fiedorowicz wrote in comp.lang.perl.modules :
> I've run into problem in using sort under Perl 5.8.0 running under the
> Linux Redhat 9.0 distribution. The code works flawlessly under Perl
> 5.6.0 under Linux Redhat 7.2. Under 5.8.0/RH 9.0 sorting fails with
> error messages of the form:
>
> Use of uninitialized value in numeric comparison (<=>) at (eval 2)
>
> I'd be particularly interested in hearing whether this code works under
> Perl 5.8.0 under other operating systems.

Preliminary remark : RH 9 doesn't come with the standard perl 5.8.0,
but with a modified version, containing many patches that are part of
perl 5.8.1.

I can reproduce your bug, but only with a perl built with ithreads
(check "perl -V:useithreads" to know whether a perl interpreter contains
support for multithreading.) It doesn't surprise me very much, since
Safe is arguably broken regarding thread support.

Short-term solution : recompile perl 5.8.1 (or .2, available in the near
future) without support for threads.

<| Post or View Comments |>


userThomas R. Shemanske - Re: Bandaid for PGsort pink pages (Perl 5.8/RH 9)  blueArrow
11/10/2003; 10:10:11 AM (reads: 2341, responses: 0)
I didn't  know if Mike wanted reports from NonRH systems (as well as nonLinux), but here it is.

I forgot I had upgraded perl on our webwork machine from 5.6.1 to 5.8.0 for other reasons.  The output of Mike's script is below.  This is a Debian system with more or less only perl (and dependencies) upgraded. 

webwork:~# perl -V:useithreads

useithreads='define';

webwork:~# perl -V

Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:

webwork:~# ./test.sh
Safe version 2.09
Use of uninitialized value in numeric comparison (<=>) at (eval 2) line 2.
Use of uninitialized value in numeric comparison (<=>) at (eval 2) line 2.
Use of uninitialized value in numeric comparison (<=>) at (eval 2) line 2.
Use of uninitialized value in numeric comparison (<=>) at (eval 2) line 2.
Use of uninitialized value in numeric comparison (<=>) at (eval 2) line 2.
Use of uninitialized value in numeric comparison (<=>) at (eval 2) line 2.
Use of uninitialized value in numeric comparison (<=>) at (eval 2) line 2.
Use of uninitialized value in numeric comparison (<=>) at (eval 2) line 2.
Use of uninitialized value in numeric comparison (<=>) at (eval 2) line 2.
Use of uninitialized value in numeric comparison (<=>) at (eval 2) line 2.
Use of uninitialized value in numeric comparison (<=>) at (eval 2) line 2.
Use of uninitialized value in numeric comparison (<=>) at (eval 2) line 2.
Use of uninitialized value in numeric comparison (<=>) at (eval 2) line 2.
Use of uninitialized value in numeric comparison (<=>) at (eval 2) line 2.
Use of uninitialized value in numeric comparison (<=>) at (eval 2) line 2.
Use of uninitialized value in numeric comparison (<=>) at (eval 2) line 2.
Use of uninitialized value in numeric comparison (<=>) at (eval 2) line 2.
Use of uninitialized value in numeric comparison (<=>) at (eval 2) line 2.
Use of uninitialized value in numeric comparison (<=>) at (eval 2) line 2.
Use of uninitialized value in numeric comparison (<=>) at (eval 2) line 2.
Use of uninitialized value in numeric comparison (<=>) at (eval 2) line 2.
Use of uninitialized value in numeric comparison (<=>) at (eval 2) line 2.
4 6 2 5 10 8 9[1]+  Done                    emacs test.sh


<| Post or View Comments |>


userMichael Gage - Re: Bandaid for PGsort pink pages (Perl 5.8/RH 9)  blueArrow
11/10/2003; 10:59:41 AM (reads: 2079, responses: 0)
Thanks, Tom.

I see that the communication with sort is broken on your version (with threads compiled) of the Debian system as well.

The current suspicion would seem to be that the interaction of threads and Safe.pm are to blame for the problem. I don't know if there is a work around for this problem (other than not using threads) or even whether it is our problem in the long run -- it could well be that the implementors of Safe and threads are working on the problem, and we need only be patient.

Take care, Mike

<| Post or View Comments |>


userZbigniew Fiedorowicz - Re: Bandaid for PGsort pink pages (Perl 5.8/RH 9)  blueArrow
12/17/2003; 2:07:05 PM (reads: 1980, responses: 0)
Now that the quarter is over, I asked our sysadmin to recompile Perl 5.8 without ithreads (on our RedHat 9.0 server). As expected this fixes the problem with sort in safe mode.

Zig

<| Post or View Comments |>