Open p5pRT opened 13 years ago
I noticed that subroutine redefinition messages from perl are not as helpful as they could be.
If we redefine something in perl\, we get:
$ perl -we 'sub blah { 1; }; sub blah { 2; }' Subroutine blah redefined at -e line 1.
Compiling a C program (using gcc) with redefinitions results in:
$ cc -std=c99 -pedantic -Wall -g -O0 -DDEBUG -I. -fPIC -c display.c -o display.o display.c:20: error: conflicting types for āusageā display.c:5: note: previous declaration of āusageā was here
In a brief chat with the #toolchain folks\, at first glance\, it might be possible to add this feature (though it could be non-trivial to handle some of the obscure cases)
\
In case this actually isn't possible\, then I apologize for the noise. I just thought it'd be a nice feature\, and could help to make perl (the binary) more friendly for new users.
Additional information was sent to me via e-mail from Brad Gilbert \b2gills@​gmail\.com:
This code should also look for places where the code was set by a GLOB assignment.
*newsub = \&oldsub sub newsub{} # redefinition warning
If you don't check for this\, your message might say where oldsub() was defined\, which wouldn't be nearly as helpful as pointing the programmer to where the GLOB assignment was.
Pushed an implementation of this to the doy/better_redefinition_warnings branch. I didn't merge it because I was having trouble with some of the tests in XS-APItest - it seems that newCONSTSUB can sometimes generate warnings with nonsensical line numbers. Looking at the source\, they seem to be coming from op.c:7252-7259\, which does some weird hacking around to try to force in the right line number\, which is probably getting it wrong somehow. If people don't consider this to be too much of a problem (or if somebody else comes up with an actual fix!)\, I'll go ahead and merge this soon.
The RT System itself - Status changed from 'new' to 'open'
On Sat Jun 23 21:32:09 2012\, doy wrote:
Pushed an implementation of this to the doy/better_redefinition_warnings branch. I didn't merge it because I was having trouble with some of the tests in XS-APItest - it seems that newCONSTSUB can sometimes generate warnings with nonsensical line numbers. Looking at the source\, they seem to be coming from op.c:7252-7259\, which does some weird hacking around to try to force in the right line number\, which is probably getting it wrong somehow. If people don't consider this to be too much of a problem (or if somebody else comes up with an actual fix!)\, I'll go ahead and merge this soon.
Maybe 28333232 was premature. What happens if you revert 28333232?
--
Father Chrysostomos
On Sat\, Jun 23\, 2012 at 11:21:20PM -0700\, Father Chrysostomos via RT wrote:
On Sat Jun 23 21:32:09 2012\, doy wrote:
Pushed an implementation of this to the doy/better_redefinition_warnings branch. I didn't merge it because I was having trouble with some of the tests in XS-APItest - it seems that newCONSTSUB can sometimes generate warnings with nonsensical line numbers. Looking at the source\, they seem to be coming from op.c:7252-7259\, which does some weird hacking around to try to force in the right line number\, which is probably getting it wrong somehow. If people don't consider this to be too much of a problem (or if somebody else comes up with an actual fix!)\, I'll go ahead and merge this soon.
Maybe 28333232 was premature. What happens if you revert 28333232?
SAVECOPSTASH no longer exists\, and I'm not sure what to use instead. Any pointers?
-doy
On Sat Jun 23 23:43:17 2012\, doy@tozt.net wrote:
On Sat\, Jun 23\, 2012 at 11:21:20PM -0700\, Father Chrysostomos via RT wrote:
On Sat Jun 23 21:32:09 2012\, doy wrote:
Pushed an implementation of this to the doy/better_redefinition_warnings branch. I didn't merge it because I was having trouble with some of the tests in XS-APItest - it seems that newCONSTSUB can sometimes generate warnings with nonsensical line numbers. Looking at the source\, they seem to be coming from op.c:7252-7259\, which does some weird hacking around to try to force in the right line number\, which is probably getting it wrong somehow. If people don't consider this to be too much of a problem (or if somebody else comes up with an actual fix!)\, I'll go ahead and merge this soon.
Maybe 28333232 was premature. What happens if you revert 28333232?
SAVECOPSTASH no longer exists\, and I'm not sure what to use instead. Any pointers?
SAVECOPSTASH_FREE will do. It doesnāt actually free anything any more.
--
Father Chrysostomos
On Sun\, Jun 24\, 2012 at 12:05:21AM -0700\, Father Chrysostomos via RT wrote:
On Sat Jun 23 23:43:17 2012\, doy@tozt.net wrote:
On Sat\, Jun 23\, 2012 at 11:21:20PM -0700\, Father Chrysostomos via RT wrote:
On Sat Jun 23 21:32:09 2012\, doy wrote:
Pushed an implementation of this to the doy/better_redefinition_warnings branch. I didn't merge it because I was having trouble with some of the tests in XS-APItest - it seems that newCONSTSUB can sometimes generate warnings with nonsensical line numbers. Looking at the source\, they seem to be coming from op.c:7252-7259\, which does some weird hacking around to try to force in the right line number\, which is probably getting it wrong somehow. If people don't consider this to be too much of a problem (or if somebody else comes up with an actual fix!)\, I'll go ahead and merge this soon.
Maybe 28333232 was premature. What happens if you revert 28333232?
SAVECOPSTASH no longer exists\, and I'm not sure what to use instead. Any pointers?
SAVECOPSTASH_FREE will do. It doesnāt actually free anything any more.
No difference. This actually looks like an off-by-one error of some kind - the line number in the first warning points to the previous time that an anonymous sub was assigned to something in the script\, and then the second warning points to where the first warning should be pointing to (which is assigning an anon sub to a glob slot). Not sure if that is enlightening at all.
-doy
On Sun Jun 24 01:20:59 2012\, doy@tozt.net wrote:
On Sun\, Jun 24\, 2012 at 12:05:21AM -0700\, Father Chrysostomos via RT wrote:
On Sat Jun 23 23:43:17 2012\, doy@tozt.net wrote:
On Sat\, Jun 23\, 2012 at 11:21:20PM -0700\, Father Chrysostomos via RT wrote:
On Sat Jun 23 21:32:09 2012\, doy wrote:
Pushed an implementation of this to the doy/better_redefinition_warnings branch. I didn't merge it because I was having trouble with some of the tests in XS-APItest - it seems that newCONSTSUB can sometimes generate warnings with nonsensical line numbers. Looking at the source\, they seem to be coming from op.c:7252-7259\, which does some weird hacking around to try to force in the right line number\, which is probably getting it wrong somehow. If people don't consider this to be too much of a problem (or if somebody else comes up with an actual fix!)\, I'll go ahead and merge this soon.
Maybe 28333232 was premature. What happens if you revert 28333232?
SAVECOPSTASH no longer exists\, and I'm not sure what to use instead. Any pointers?
SAVECOPSTASH_FREE will do. It doesnāt actually free anything any more.
No difference.
Sorry. I wasnāt thinking.
This actually looks like an off-by-one error of some kind - the line number in the first warning points to the previous time that an anonymous sub was assigned to something in the script\, and then the second warning points to where the first warning should be pointing to (which is assigning an anon sub to a glob slot). Not sure if that is enlightening at all.
What I see is this:
sensical line numbers # Failed (TODO) test 'newCONSTSUB redefinition warning + utf8' # at ext/XS-APItest/t/newCONSTSUB.t line 70. # 'Subroutine Ä redefined (previous definition at ext/XS-APItest/t/newCONSTSUB.t line 16) at ext/XS-APItest/t/newCONSTSUB.t line -1. # ' # doesn't match '(?^u:Subroutine \x{100} redefined \(previous definition at ext/XS-APItest/t/newCONSTSUB.t line 63\) at )'
Iām getting line -1.
This code for setting the line number is very odd indeed.
newCONSTSUB has everything within an ENTER/LEAVE pair\, in which it does this:
SAVECOPLINE(PL_curcop); CopLINE_set(PL_curcop\, PL_parser ? PL_parser->copline : NOLINE);
I donāt fully understand how the parser setup happens\, but I think that code is wrong.
It needs to set PL_curcop to &PL_compiling\, because it has to modify it temporarily. Hence\, it needs to make sure the line number is set in &PL_compiling (Iām assuming thatās the logic behind it). But then it gets the line number from the current parser\, instead of the current op. That probably makes sense if newCONSTSUB is called at compile time\, but not run time.
But this test script gives the right line number (it does go through newCONSTSUB; gdb told me so)\, and I donāt know why:
use constant { foo => 1\, bar => 2}; study *foo; # autovivify *foo = \&{"bar"};
And then newXS_len_flags also plays around with the line number\, as you saw:
const line_t oldline = CopLINE(PL_curcop); if (PL_parser && PL_parser->copline != NOLINE) CopLINE_set(PL_curcop\, PL_parser->copline); report_redefined_cv(newSVpvn_flags( name\,len\,(flags&SVf_UTF8)|SVs_TEMP )\, cv\, const_svp); CopLINE_set(PL_curcop\, oldline);
Iām not even sure thatās thread-safe. newXS can be called from XSLoader::load\, which many modules call at run-time. So PL_curcop is a an op in an op tree\, which is shared between threads. And here it is modified. Also\, if fatal warnings are enabled\, it will leave the line number modified.
Also\, itās probably wrongly using the parserās line number.
Iām not sure I want to debug this quagmire just yet. :-)
Iāve had a look at your patch\, and there is one problem with it (apart from the above). It uses the line number from the GV\, which is set when the GV is created:
#!perl -w
$foo = 'squiggles';
sub foo { 1 }
sub foo { 2 } __END__ Subroutine foo redefined (previous definition at - line 3) at - line 11.
I donāt even know what the line number in the GV is for. Maybe it would be acceptable to set it when a sub is defined (after the warning\, and if CvGV(cv) == gv). I donāt know.
--
Father Chrysostomos
On Sun Jun 24 11:01:21 2012\, sprout wrote:
I donāt even know what the line number in the GV is for. Maybe it would be acceptable to set it when a sub is defined (after the warning\, and if CvGV(cv) == gv). I donāt know.
I do now. :-)
It is used for āuse onceā warnings. If the GV is accessed multiple times; e.g.\, for $x and then sub x\, the GvFILE nad GvLINE fields are never used. So it should be safe to overwrite them when defining subs\, for the sake of putting this warning on the right line.
--
Father Chrysostomos
Migrated from rt.perl.org#77816 (status was 'open')
Searchable as RT77816$