On Thu, Apr 14, 2005 at 02:24:36PM -0400 Scott Lanning wrote:
> On Mon, 11 Apr 2005, Tassilo von Parseval wrote:
> >On Mon, Apr 11, 2005 at 08:34:56PM +0100 Nick Ing-Simmons wrote:
> >>We could do with updating (and making easier to find) the various
> >>tips and tricks of C++/xs.
> >
> >Which would imply that there is actually an amount of C++/XS tricks
> >available in a variety of places. The only two I know of is perlxs.pod
> >whose information on that matter are fairly puny, and - of course -
> >existing XS modules written in C++ on the CPAN.
> 
> What would be some (good) examples of XS modules using C++?

Good question. I could have sworn that MP3::Id3lib was a good example
but now looking at it again, it's hardly C++-ish. An extension
definitely written in XS/C++ (with all bells and whistles) is Wx. But
this is already so huge and complex, that it's hardly useful for a
beginner.

> Using http://search.cpan.org and
> 
>   cpan> i /c\\+\\+/
> 
> didn't find anything. I also have an rsync of CPAN which could
> be trawled through by gunzipping every distribution and grepping
> Makefile.PL for c++, but I didn't try that yet...

I very much assume that there wont be so many distributions around.  For
some reason, C++ isn't nearly as popular as plain C when it comes to XS.
Maybe it's because most useful libraries are in fact written in C.

For demonstration purpose, I uploaded the little and cursory XS wrapper around
<vector> to http://www-users.rwth-aachen.de/Tassilo.Parseval/Vector-0.01.tar.gz
and everybody is free to have a look at it. It mainly demonstrates how
to use '::' in method names to avoid some typing. Also, it does some
overloading in XS, although this is not C++ specific.

> Searching on http://perlmonks.org showed a couple relevant threads.
> http://perlmonks.org/index.pl?node_id=197028
> ->http://www.johnkeiser.com/perl-xs-c++.html
>  ->http://cpan.org/authors/id/DMR/
> http://perlmonks.org/index.pl?node_id=225498
> ->http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2002-12/msg00807.html
> 
> 
> For the most part, it's pretty straightforward,
> but for example how do you deal with passing values
> into methods by reference? The ampersand (&) has a special
> meaning for XSUB arguments. And return values with references,
> since that seems to not work in typemaps (might've been my
> mistake, though).

I don't know anything about the special meaning of ampersands in XSUB
arguments. Is that mentioned somewhere in the docs? Other than that, C++
references are probably best avoided. It severely collides with perl's
garbage-collecting when you use C++'s default memory allocator and then
pass references to this object around. So the only safe way is to use
'new' and pass the pointer instead of the reference. C++ wont mind.

Tassilo
-- 
use bigint;
$n=71423350343770280161397026330337371139054411854220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);

Reply via email to