Re: "Can't bless non-reference" error, bug or not?
[email protected] (Chunyan Wei) Tue, 18 Apr 2000 15:12:16 -0500
| Newsgroups | perl.jpl |
|---|---|
| Organization | Adhesive Software |
| Message-ID | <[email protected]> |
Thanks, Brian.
I still have a couple of questions:
1. Does somebody have any experience with JPL from Perl side on Linux
or Unix? Or have you tried to make it works? I tried it and got
"Segmentation fault (core dumped)".
2. When jpl/JNI was compiled on window NT with Perl5.5.003 and VC++,
there was compiling problem with the C++ codes. But the C codes worked
well.
Actually, there is a line "extern "C"" in the generated file JNI.c.
So I took away the C++ code in JNI.xs for the JNI functions.
Does anyone have the same problem? The changes I made are as following:
(To save the space, here I show only the first part of the output
generated by "diff -c")
diff -c JNI.xs JNI.xs.fixed
*** JNI.xs Tue Sep 14 21:49:44 1999
--- JNI.xs.fixed Mon Apr 3 16:42:16 2000
***************
*** 120,137 ****
int i;
SV** esv;
- #ifdef WIN32
- jbooleanArray ja = env->NewBooleanArray(len);
- #else
jbooleanArray ja = (*env)->NewBooleanArray(env,
len);
- #endif
for (esv = AvARRAY((AV*)rv), i = 0; i < len;
esv++, i++)
buf[i] = (jboolean)SvIV(*esv);
- #ifdef WIN32
- env->SetBooleanArrayRegion(ja, 0, len, buf);
- #else
(*env)->SetBooleanArrayRegion(env, ja, 0, len,
buf);
- #endif
free((void*)buf);
jv[ix++].l = (jobject)ja;
}
--- 120,129 ----
***************
3. For the bless problem I mentioned in my previous message, could
someone
add the changes to the CVS archive? I can do it if I get access to the
CVS
archive. Again, here is the changes I made for "AutoLoader.pm:
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 {
Thanks,
Chunyan Wei ([email protected])
Brian Jepson wrote:
>
> On Tue, 28 Mar 2000, Chunyan Wei wrote:
>
> > I am working on something using JPL from Perl side and have got
> > some errors with the bless function in "AutoLoader.pm":
> >
> > >>>Can't bless non-reference value at AutoLoader.pm line 237.
> >
> > The line 237 of Autoloader is:
> > bless $self->$callmethod($mid, \@_), $blesspack;
> >
> > I have solved my problem by adding a line to check the reference:
> >
> > if ( ref $self->$callmethod($mid, \@_)) {
> > bless $self->$callmethod($mid, \@_), $blesspack;
> > }
> >
> > Brian, what is your opinion?
> >
>
> I haven't had my hands in the code for quite some time, so I'm afraid I
> can't intelligently comment - it doesn't ring a bell with me, but it looks
> like a reasonable fix, since it checks before calling a method.
>
> Brian Jepson * ([email protected]) * http://users.ids.net/~bjepson