RE: "Can't bless non-reference" error, bug or not?
[email protected] ("Chunyan Wei") Tue, 16 May 2000 11:48:53 -0500
| Newsgroups | perl.jpl |
|---|---|
| Message-ID | <[email protected]> |
Larry, You are right. We shouldn't call the method twice. Thanks a lot, Chunyan Wei -----Original Message----- From: Larry Wall [mailto:[email protected]] Sent: Monday, May 15, 2000 10:39 PM To: [email protected] Cc: '[email protected]'; Brian Jepson Subject: Re: "Can't bless non-reference" error, bug or not? Chunyan Wei writes: : diff -c AutoLoader.pm AutoLoader.pm.fixed : *** AutoLoader.pm Tue Sep 14 21:13:19 1999 : --- AutoLoader.pm.fixed Tue Apr 18 13:57:22 2000 : *************** : *** 225,231 **** : $METHOD = sub { : my $self = shift; : my $class = JNI::FindClass($jclassname); : ! bless $class->JNI::NewObjectA($mid, \@_), $classname; : }; : } : elsif (ref $_[0]) { : --- 225,233 ---- : $METHOD = sub { : my $self = shift; : my $class = JNI::FindClass($jclassname); : ! if ( ref $class->JNI::NewObjectA($mid, \@_)) { : ! bless $class->JNI::NewObjectA($mid, \@_), $classname; : ! } : }; : } : elsif (ref $_[0]) { : *************** : *** 234,244 **** : my $self = shift; : if (ref $self eq $classname) { : my $callmethod = "JNI::Call${rettype}MethodA"; : ! bless $self->$callmethod($mid, \@_), $blesspack; : } : else { : my $callmethod = : "JNI::CallNonvirtual${rettype}MethodA"; : ! bless $self->$callmethod($class, $mid, \@_), : $blesspack; : } : }; : } : --- 236,250 ---- : my $self = shift; : if (ref $self eq $classname) { : my $callmethod = "JNI::Call${rettype}MethodA"; : ! if ( ref $self->$callmethod($mid, \@_)) { : ! bless $self->$callmethod($mid, \@_), : $blesspack; : ! } : } : else { : my $callmethod = : "JNI::CallNonvirtual${rettype}MethodA"; : ! if ( ref $self->$callmethod($class, $mid, \@_)) { : ! bless $self->$callmethod($class, $mid, \@_), : $blesspack; : ! } : } : }; : } : *************** : *** 261,267 **** : if ($blesspack) { : $METHOD = sub { : my $self = shift; : ! bless $class->$callmethod($mid, \@_), $blesspack; : }; : } : else { : --- 267,275 ---- : if ($blesspack) { : $METHOD = sub { : my $self = shift; : ! if ( ref $class->$callmethod($mid, \@_)) { : ! bless $class->$callmethod($mid, \@_), $blesspack; : ! } : }; : } : else { Why do you call the method twice in each case? It'd be much more efficient to store the result of the first call in a temporary and just bless that if it's a ref. Worse than that, in some cases calling the same method twice can produce totally incorrect results, if the method has side effects. Larry