develooper Front page | perl.perl5.porters | Postings from November 2003

Re: $^E bug and perl 5.8.0

Thread Previous | Thread Next
Chris Nandor
November 19, 2003 08:37
Re: $^E bug and perl 5.8.0
Message ID:
At 16:50 +0100 2003.11.19, Rafael Garcia-Suarez wrote:
>Try this naive patch :
>--- mg.c.orig	Wed Nov 19 16:41:47 2003
>+++ mg.c	Wed Nov 19 16:44:14 2003
>@@ -623,8 +623,12 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg)
> 		  SetLastError(dwErr);
> 	     }
> #else
>-	     sv_setnv(sv, (NV)errno);
>-	     sv_setpv(sv, errno ? Strerror(errno) : "");
>+	     {
>+		 int saveerrno = errno;
>+		 sv_setnv(sv, (NV)errno);
>+		 sv_setpv(sv, errno ? Strerror(errno) : "");
>+		 errno = saveerrno;
>+	     }
> #endif
> #endif
> #endif

I'm a tool ... I neglected to remove the first two lines.  D'oh!  I think
you are on to it there, that Strerror() is failing and setting errno, which
is Bad.  This patch does indeed fix the problem.  Sorry for the false
negative the first time through.

Now I wonder why this DOESN'T fail with ithreads?

Some background: I use $^E in several Mac:: modules, from back when they
were for Mac OS only.  Now, I do a little fudging and use the Mac::Errors
module to provide the same support on Mac OS X.  $^E and $! don't work
together on Mac OS like they do on Mac OS X, so I can't just change to $!.

I've been quite careful to not depend on $^E after system calls, or if I
need it, to save it and restore it later.  In this case, it was changing
its value here:

	$^E = exists $evt->{ERRNO} ? $evt->{ERRNO} : 0; # restore errno

	my $return = 1;
	# if error handler, only return if error handler returns true
	# what should error handler be passed?
	if ($^E && $error_handler) {
		# ... call $error_handler

	return $return;

And even if $error_handler was false, $^E would end up incorrect after the
return.  No syscalls.

However, the code above is broken anyway, as Dan might point out, since
$error_handler COULD contain syscalls, so I am modifying this particular
code to set $^E right before the return, and use a lexical var for the
other stuff.  That fixes the immediate problem, and it is more robust in
case $error_handler does contain a syscall.

Anyway, thanks for the patch; I recommend its inclusion for 5.8.3/5.9, and
a test for it might be reasonable (I can come up with one, but not sure
where to put it, and not sure if I would cover all the bases properly ...).

Chris Nandor            
Open Source Development Network

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About