Quantcast

Passing pointers from perl

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Passing pointers from perl

Thomas.Weinmaier@t-online.de
Hi All,

I want to create an object, whose constructor looks like this:

    ClassA (ClassB, AbstractClassC*);

When I try to create the object of ClassA in perl by

    $b = new mead::ClassB();
    $c = new mead::DerivedFromC();
 
    $a = new mead::ClassA($b, $c);
 
I alway get the error "No matching function for overloaded 'new_ClassA'
at
mead.pm line 1148."

When I pass the second parameter as a reference  

    $a = new mead::ClassA($b, \$c);
 
the error is the same. I checked the _wrap.cxx file and the matching
wrapper
function does exist, but it seems not to recognize the second parameter
as a
pointer.
When I change the constructor to expect a real object of DerivedFromC

    ClassA (ClassB, DerivedFromC);

and afterwards pass a reference to DerivedFromC this part works and
perl´s
print also tells me that $a is an object of ClassA
     
     $a = mead::ClassA=HASH(0x82bf708)

but I can´t access its attributes and I get a segmentation fault later
on.      


I am stuck on this problem for several days now and I wonder whether my
perl-call is wrong or I could use some typemap to solve this problem.



Every suggestion is appreciated.

  Thomas







-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Passing pointers from perl

Matthias-54
On Tue, 08 Nov 2005 06:02:26 +0100, [hidden email]
<[hidden email]> wrote:

> Hi All,
>
> I want to create an object, whose constructor looks like this:
>
>     ClassA (ClassB, AbstractClassC*);
>
> When I try to create the object of ClassA in perl by
>
>     $b = new mead::ClassB();
>     $c = new mead::DerivedFromC();
>    $a = new mead::ClassA($b, $c);
> I alway get the error "No matching function for overloaded 'new_ClassA'
> at
> mead.pm line 1148."
>
> When I pass the second parameter as a reference
>
>     $a = new mead::ClassA($b, \$c);
>
> I am stuck on this problem for several days now and I wonder whether my
> perl-call is wrong or I could use some typemap to solve this problem.
>
> Every suggestion is appreciated.
>
>   Thomas

I think this happens because your DerivedFromC* would be casted implicitly
to an AbstractClassC* in C++. However, with SWIG matters are different I
think. You need to tell SWIG explicitly that there is an implicit cast.
Take a look at the implicit.i file somewhere in the swig library. I hope
it will work for you.

-Matthias
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Passing pointers from perl

Jason Stewart-4
In reply to this post by Thomas.Weinmaier@t-online.de
> the error is the same. I checked the _wrap.cxx file and the matching
> wrapper
> function does exist, but it seems not to recognize the second parameter
> as a
> pointer.

You have to check whether there is a conversion method that is created
which maps your DerivedFromC class to a C object. If such a method is
defined by SWIG, it means that SWIG believes that DerivedFromC ISA C,
and it will accept it anyplace that C is accepted.

If such a conversion method was *not* generated it means that SWIG
doesn't know about your DerivedFromC class.

One question: Did you define DerivedFromC in Perl or in C++? If you
defined it in Perl, then you can forget this working until directors
are ported to Perl. If you defined it in C++, then it is possible that
you did not %include or %import the correct Class headers, or it is
possible that SWIG didn't find enough information.

The method that you're looking for will be like:

static void *_p_DerivedFromCTo_p_C(void *x) {
    return (void *)((C*)  ((DerivedFromC *) x));
}

If that method doesn't exist that is your problem.

Cheers,
jas.


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Loading...