You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Joel Reed <jr...@support.ddiworld.com> on 2000/03/23 20:21:03 UTC

Apache::ASP - Not a hash reference errors on cleanup

i'm getting the following error msgs from Apache::ASP...

Errors Output

>       (in cleanup) Not a HASH reference at /usr/lib/perl5/site_perl/5.005/i386-linux/opal.pm line 70.
        (in cleanup) Not a HASH reference at /usr/lib/perl5/site_perl/5.005/i386-linux/opal.pm line 117.
        (in cleanup) Not a HASH reference at /usr/lib/perl5/site_perl/5.005/i386-linux/opal.pm line 1699.
, /usr/lib/perl5/site_perl/5.005/Apache/ASP.pm line 1229

the code referenced in opal.pm is 

sub DESTROY {
    my $self = tied(%{$_[0]}); <<<<<<<<<<<<<<<<< THIS IS LINE 70
    delete $ITERATORS{$self};
    if (exists $OWNER{$self}) {
        opalc::delete_o_connection_pool($self);
        delete $OWNER{$self};
    }
}

the script code i use looks like this:

<%@ LANGUAGE=PerlScript %>

<html>
<body>
<%
my $pool = new o_connection_pool();
$pool->init("opal", 5);

my $connection = new o_connection();
if (!$connection->grab_from_pool($pool))
{
	  print "database connection failed.\n";
	  return;
}

my $sit = new o_sit(0, $connection->handle());
$sit->open_id(2);
$Response->Write($sit->name() . "<br>");
%>

</body>
</html>


i'm thinking there is some perl knowledge i'm missing to get
$_[0] to refer to the right thing.

can anyone give me a pointer or 2 ?

thanks,
jr
-- 
------------------------------------------------------------------------
Joel W. Reed                              http://ruby.ddiworld.com/jreed
----------------Useless Invention: Non-stick Cellotape.----------------



Re: Not a hash reference errors on cleanup - FIXED ?

Posted by Joel Reed <jr...@support.ddiworld.com>.
On Mar 23, joshua@chamas.com hacked the bitstream to say...
Joshua> Joel Reed wrote:
Joshua> > 
Joshua> > i'm getting the following error msgs from Apache::ASP...
Joshua> > 
Joshua> > Errors Output
Joshua> > 
Joshua> > >       (in cleanup) Not a HASH reference at /usr/lib/perl5/site_perl/5.005/i386-linux/opal.pm line 70.
Joshua> >         (in cleanup) Not a HASH reference at /usr/lib/perl5/site_perl/5.005/i386-linux/opal.pm line 117.
Joshua> >         (in cleanup) Not a HASH reference at /usr/lib/perl5/site_perl/5.005/i386-linux/opal.pm line 1699.
Joshua> > , /usr/lib/perl5/site_perl/5.005/Apache/ASP.pm line 1229
Joshua> > 
Joshua> 
Joshua> There are some times when opal.pm is expecting a HASH reference 
Joshua> and is not getting one.  You could try adding some $main::Response->Debug()
Joshua> lines to your code to see what you really have, like to print 
Joshua> $_[0] at line 70.  DESTROY's can be tricky to get right sometimes,
Joshua> and you might have to do something like 
Joshua>   return unless (ref $_[0]) =~ /HASH/)

adding that line to DESTROY got rid of the Error msgs i described above. 
i'm wondering if anyone has any insight into 2 remaining questions i have.

1. what would make the DESTROY function (shown below) work when running
	on a terminal using perl but not work under mod_perl? does mod_perl
	do some extra BLESSING or TIEING or something?

2. i'm confused about why DESTROY is called twice & whether its really ok
to ignore DESTROY calls when $_[0] is not a HASH. from the perlobj doc i see...

	If you arrange to re-bless the reference before the destructor returns,
	perl will again call the DESTROY method for the re-blessed object after
	the current one returns. This can be used for clean delegation of
	object destruction, or for ensuring that destructors in the base
	classes of your choosing get called. Explicitly calling DESTROY is
	 also possible, but is usually never needed. 

but i don't know what 

	re-bless the reference before the destructor returns

really means.

thanks for your help.
jr

the new DESTORY that works is shown below... 

############# Class : o_connection_pool ##############

package o_connection_pool;
@ISA = qw( opal );
%OWNER = ();
%ITERATORS = ();
sub new {
    my $self = shift;
    my @args = @_;
    $self = opalc::new_o_connection_pool(@args);
    return undef if (!defined($self));
    bless $self, "o_connection_pool";
    $OWNER{$self} = 1;
    my %retval;
    tie %retval, "o_connection_pool", $self;
    return bless \%retval,"o_connection_pool";
}

sub DESTROY {
    return unless ($_[0] =~ m/HASH/);          <<<<<<<<<<<<THIS LINE FIXES IT
    my $self = tied(%{$_[0]});
    delete $ITERATORS{$self};
    if (exists $OWNER{$self}) {
        opalc::delete_o_connection_pool($self);
        delete $OWNER{$self};
    }
}

sub init {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
    my $result = opalc::o_connection_pool_init(@args);
    return $result;
}
sub DISOWN {
    my $self = shift;
    my $ptr = tied(%$self);
    delete $OWNER{$ptr};
    };

sub ACQUIRE {
    my $self = shift;
    my $ptr = tied(%$self);
    $OWNER{$ptr} = 1;
    };

-- 
------------------------------------------------------------------------
Joel W. Reed                              http://ruby.ddiworld.com/jreed
---------------Help! I'm modeming... and I can't hang up!---------------



Re: Apache::ASP - Not a hash reference errors on cleanup [swig]

Posted by Joel Reed <jr...@support.ddiworld.com>.
On Mar 23, ged@jubileegroup.co.uk hacked the bitstream to say...
G.W.> Is there a reason that you create $self and then overwrite it without
G.W.> using the first value?  I'd have grabbed @_ and then popped the first
G.W.> element off if I'd wanted to discard it.  Then $self would only ever
G.W.> have been what I wanted really wanted.  Hopefully.

no reason - this code is generated from swig. (www.swig.org)
has anyone out there successfully run c++ swig'd to perl
under mod_perl?

G.W.> 
G.W.> Have you got a "use strict" somewhere in your script(s)?  And a "-w"?

i'll check. thanks for all your suggestions.
jr

-- 
------------------------------------------------------------------------
Joel W. Reed                              http://ruby.ddiworld.com/jreed
-------------------Why am I asking all these things?-------------------



Re: Apache::ASP - Not a hash reference errors on cleanup

Posted by "G.W. Haywood" <ge...@jubileegroup.co.uk>.
Hi there,

On Thu, 23 Mar 2000, Joel Reed wrote:

> here's the "new" subroutine...
> 
> sub new {
>     my $self = shift;
>     my @args = @_;
>     $self = opalc::new_o_connection_pool(@args);
>     return undef if (!defined($self));
>     bless $self, "o_connection_pool";
>     $OWNER{$self} = 1;
>     my %retval;
>     tie %retval, "o_connection_pool", $self;
>     return bless \%retval,"o_connection_pool";
> }

I'd check after

>     my $self = shift;

that $self is what you think it is.

Then after

>     $self = opalc::new_o_connection_pool(@args);

I'd do it again.

Is there a reason that you create $self and then overwrite it without
using the first value?  I'd have grabbed @_ and then popped the first
element off if I'd wanted to discard it.  Then $self would only ever
have been what I wanted really wanted.  Hopefully.

Have you got a "use strict" somewhere in your script(s)?  And a "-w"?

73,
Ged.



Re: Apache::ASP - Not a hash reference errors on cleanup

Posted by Joel Reed <jr...@support.ddiworld.com>.
On Mar 23, joshua@chamas.com hacked the bitstream to say...
Joshua> Joel Reed wrote:
Joshua> > 
Joshua> > On Mar 23, joshua@chamas.com hacked the bitstream to say...
Joshua> > Joshua> and is not getting one.  You could try adding some $main::Response->Debug()
Joshua> > Joshua> lines to your code to see what you really have, like to print
Joshua> > Joshua> $_[0] at line 70.
Joshua> > 
Joshua> > this is what i got...
Joshua> > 
Joshua> > > [test.html] - DEBUG: o_connection_pool=HASH(0x8354e04)
Joshua> > > [test.html] - DEBUG: o_connection_pool=SCALAR(0x861e8d0)
Joshua> > 
Joshua> > HASH is what i want right? is it a problem that there is SCALAR as well?
Joshua> > (sorry i'm not more of a perl expert)
Joshua> > 
Joshua> 
Joshua> So now you have to figure how how your object is being
Joshua> blessed as a SCALAR sometimes, and a HASH others.  This
Joshua> is highly odd, and I am sure this bug will be no fun to 
Joshua> track down.

here's the "new" subroutine...

sub new {
    my $self = shift;
    my @args = @_;
    $self = opalc::new_o_connection_pool(@args);
    return undef if (!defined($self));
    bless $self, "o_connection_pool";
    $OWNER{$self} = 1;
    my %retval;
    tie %retval, "o_connection_pool", $self;
    return bless \%retval,"o_connection_pool";
}

should i be looking for any "bless" stmts in Apache::ASP or mod_perl ?

jr

-- 
------------------------------------------------------------------------
Joel W. Reed                              http://ruby.ddiworld.com/jreed
------------There must be more to life than compile-and-go.------------



Re: Apache::ASP - Not a hash reference errors on cleanup

Posted by Joshua Chamas <jo...@chamas.com>.
Joel Reed wrote:
> 
> On Mar 23, joshua@chamas.com hacked the bitstream to say...
> Joshua> and is not getting one.  You could try adding some $main::Response->Debug()
> Joshua> lines to your code to see what you really have, like to print
> Joshua> $_[0] at line 70.
> 
> this is what i got...
> 
> > [test.html] - DEBUG: o_connection_pool=HASH(0x8354e04)
> > [test.html] - DEBUG: o_connection_pool=SCALAR(0x861e8d0)
> 
> HASH is what i want right? is it a problem that there is SCALAR as well?
> (sorry i'm not more of a perl expert)
> 

So now you have to figure how how your object is being
blessed as a SCALAR sometimes, and a HASH others.  This
is highly odd, and I am sure this bug will be no fun to 
track down.

-- Joshua
_________________________________________________________________
Joshua Chamas			        Chamas Enterprises Inc.
NodeWorks >> free web link monitoring	Huntington Beach, CA  USA 
http://www.nodeworks.com                1-714-625-4051

Re: Apache::ASP - Not a hash reference errors on cleanup

Posted by Joel Reed <jr...@support.ddiworld.com>.
On Mar 23, joshua@chamas.com hacked the bitstream to say...
Joshua> and is not getting one.  You could try adding some $main::Response->Debug()
Joshua> lines to your code to see what you really have, like to print 
Joshua> $_[0] at line 70.

this is what i got...

> [test.html] - DEBUG: o_connection_pool=HASH(0x8354e04)
> [test.html] - DEBUG: o_connection_pool=SCALAR(0x861e8d0)

HASH is what i want right? is it a problem that there is SCALAR as well?
(sorry i'm not more of a perl expert)

thanks for your help Joshua.

jr

-- 
------------------------------------------------------------------------
Joel W. Reed                              http://ruby.ddiworld.com/jreed
------------Marriage is one of the chief causes of divorce.------------



Re: Apache::ASP - Not a hash reference errors on cleanup

Posted by Joshua Chamas <jo...@chamas.com>.
Joel Reed wrote:
> 
> i'm getting the following error msgs from Apache::ASP...
> 
> Errors Output
> 
> >       (in cleanup) Not a HASH reference at /usr/lib/perl5/site_perl/5.005/i386-linux/opal.pm line 70.
>         (in cleanup) Not a HASH reference at /usr/lib/perl5/site_perl/5.005/i386-linux/opal.pm line 117.
>         (in cleanup) Not a HASH reference at /usr/lib/perl5/site_perl/5.005/i386-linux/opal.pm line 1699.
> , /usr/lib/perl5/site_perl/5.005/Apache/ASP.pm line 1229
> 

There are some times when opal.pm is expecting a HASH reference 
and is not getting one.  You could try adding some $main::Response->Debug()
lines to your code to see what you really have, like to print 
$_[0] at line 70.  DESTROY's can be tricky to get right sometimes,
and you might have to do something like 
  return unless (ref $_[0]) =~ /HASH/)

You must have Debug set to >= 1 to see output from $Response->Debug().

Also, it looked to me that your code was doing db connection pooling.
You might want to look into using Apache::DBI potentially, or 
subclassing off it, if it is not quite right for your needs.

--Joshua
_________________________________________________________________
Joshua Chamas			        Chamas Enterprises Inc.
NodeWorks >> free web link monitoring	Huntington Beach, CA  USA 
http://www.nodeworks.com                1-714-625-4051