Ian Miller <[EMAIL PROTECTED]> writes:
> I've noticed some strange behaviour whilst using HTML::Parser 3.08
> with API version 2. I've whittled it down to the two attached example
> programs -- one demonstrates the segfault that I get with API v2 and
> the other demonstrates the equivalent (?) API v3 program that works as
> expected. I also attach the HTML file that causes the segfault, and
> the output that I get from the segfaulting program.
>
> Is it a bug in HTML::Parser? I don't see how it can be... but I can't
> think of anything else... or am I doing something very, very stupid?
Yes! You are doing something stupid :-)
> sub text {
> my ($self, $text) = @_;
>
> print STDERR "$text\n----- END CHUNK -----\n";
> @_ = split(/\W/, $text); ## this causes the segfault
> }
By the assignment to @_ you are clobbering $self and other stuff. Why
don't you use your own lexical array??? :-)
...but HTML::Parser was stupid enough to send the same reference to
all calls. That meant that the next handler invoked got your
clobbered $self as its argument and eventually perl got confused
during global destruction. This patch make sure that we copy the
reference for each callback invocation. That should cure the problem.
Index: hparser.c
===================================================================
RCS file: /home/cvs/aas/perl/mods/html-parser/hparser.c,v
retrieving revision 2.42
retrieving revision 2.43
diff -u -p -u -r2.42 -r2.43
--- hparser.c 2000/05/23 10:44:59 2.42
+++ hparser.c 2000/06/28 08:34:31 2.43
@@ -1,4 +1,4 @@
-/* $Id: hparser.c,v 2.42 2000/05/23 10:44:59 gisle Exp $
+/* $Id: hparser.c,v 2.43 2000/06/28 08:34:31 gisle Exp $
*
* Copyright 1999-2000, Gisle Aas
* Copyright 1999-2000, Michael A. Chase
@@ -198,7 +198,7 @@ report_event(PSTATE* p_state,
switch( argcode ) {
case ARG_SELF:
- arg = self;
+ arg = sv_mortalcopy(self);
break;
case ARG_TOKENS:
I will be uploading HTML-Parser-3.09 with this fix now.
Thanks, for your bug report!
Regards,
Gisle