How to have perl allocate pointers predictably.

[email protected] (Shlomi Fish)
Newsgroups perl.xs
Message-ID <[email protected]>
Hi all,

with the included script below, Devel::Leak keeps outputting different pointers each time for
the leaked SVs. This makes debugging harder. Can I have perl somehow allocate the same pointers
each time when an allocation is being requested? I don't mind rebuilding a dedicated perl for that
using perlbrew or whatever. Note that this also happens if make_trouble() is as simple as
"my $x; $x = \$x;".

Regards,

-- Shlomi Fish

# Feeding XML::LibXML with an invalid file, triggering memory leaks

use strict;
use warnings;

use Devel::Leak;

use Encode;
use XML::LibXML;

use Carp;

binmode STDOUT, ':encoding(UTF-8)';

check_libxml_memory();

sub check_libxml_memory {
    print "running\n";
    my $handle;
    my $leaveCount = 0;
    my $enterCount = Devel::Leak::NoteSV($handle);
    print STDERR "\nENTER: $enterCount SVs\n";
    {
        make_trouble(); # Trace how loading a bad doc affects memory
    }
    $leaveCount = Devel::Leak::CheckSV($handle);
    print STDERR "\nLEAVE: $leaveCount SVs\n";
}

sub make_trouble {
    # Tries to load a bad XML file into XML::LibXML
    my $filenameIn = 'libxml-trouble-sample.html';
    local $/; #Read whole file
    open(my $FILEIN,'<', $filenameIn)
        or die "Can't read file '$filenameIn' [$!]\n";
    my $str = <$FILEIN>;
    close ($FILEIN);

    # Feeds the bad file to XML::LibXML.
    my $parser = XML::LibXML->new;
    my $success=1;
    # if recover is set to 0 or 1, the problem ceases to exist
    my $doc = $parser->parse_html_string($str,
        {recover => 2, encoding => 'UTF-8'}
    );

    return;
}

1;

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Funny Anti-Terrorism Story - http://shlom.in/enemy

What is is. Perceive It. Integrate it. Act on it. Idealize it.
    — Leonard Peikoff

Please reply to list if it's a mailing list post - http://shlom.in/reply .
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.