Re: "Can't bless non-reference" error, bug or not?
[email protected] (Larry Wall) Mon, 15 May 2000 20:38:40 -0700 (PDT)
| Newsgroups | perl.jpl |
|---|---|
| Message-ID | <[email protected]> |
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