[C++-SIG] [Announce] CXX Alpha 2

Paul F. Dubois dubois1 at llnl.gov
Fri Mar 27 17:48:50 CET 1998


>
>I wanted to let you know that I have developed a Python extension
>package using the same "curiosly recursive template" pattern.
>Perhaps it is worth comparing notes?

Obviously. I'm anxious to see your code. The part I can see has some
interesting differences.

I knew that using member template functions was not going to fly except with
a few compilers. We have KCC (Kuck and Associates) on our Unix box, which is
slow to compile, quick to run, and very close to the standard. Is your
"latest SGI compiler" from SGI? If so maybe we ought to get it. My stuff
didn't work with egcs but maybe yours would. I used namespaces and lots of
the STL.

>
>There are two techniques that I used that take advantage of the
>recursive template pattern.  The first is automatic management
>of reference-counted objects, so that your C++ application can use
>the objects in a reference-counted way (using smart pointers), and
>also interchange the objects with Python code.  There is nothing
>too magical about this.

Well, for the basics, no. But maybe you'll like what I've done. In
particular, I have put in enough machinery that you can use STL algorithms
on Python containers. If PyObject* p points to a Python list, for example,
you can do:
List mylist(p);
sort(mylist);
for(List::iterator j = mylist.begin(); j != mylist.end(); ++j) {
   do_something_to_the_element (*j);
}

Also stuff like
Dict m;
m["hello"] = "world";

>The second trick is to handle automatic
>argument conversion for member functions.  This is the part that
>breaks the compiler :-).

Geoff Furnish has also worked on and off on a scheme to allow direct calling
of member functions. I didn't try to do any of that because he is working on
it. You stuff looks interestingly different. I'm sure we'd both like to
study it.

>A pass-by-value extension class looks like:
>
>class MRTest : public Scripting::ValueBase< MRTest >
>{
>public:
> MRTest( ) { }
> MRTest Create( );
>
> static void SetupScripting( )
> {
> RegisterClassName( "MRTest" );
>
> GlobalRegistry::Register( "MRTest", Create );
>
> RegisterMember( "Func0", Func0 );
> RegisterMember( "Func1", Func1 );
> RegisterMember( "Func2", Func2 );
> RegisterMember( "Func3", Func3 );
> RegisterMember( "Func4", Func4 );
> }
>
> const char * Func0( );
> int  Func1( int a );
> double Func2( int a, double b );
> MRTest Func3( int a, int b, int c );
> MRTest const & Func4( double a, int b, char const * c, int d );
>};
>
>Unfortunately, I stretched the compiler a bit too far.  When I start
>building real test cases, the Visual C++ 5.0sp3 compiler crashes :-).
>The lack of out-of-line templates and proper handling of template
>members of template classes also cause trouble, so that the code
>becomes very ugly.  The most recent SGI compiler is great for all
>of this, but obviously doesn't do much good for Windows development.
>
>Regards,
>Garth A. Dickie
>

I hope you can pick up my distribution at
ftp-icf.llnl.gov/pub/python/CXX-2a.zip and (a) see if it works with your SGI
compiler, and (b) let me know what you think of it. I worked about 80% of
the effort on the CXX_Objects.h file; the CXX_Extensions.h I view as purely
a first attempt and I would be glad to merge with something better from you
and/or Geoff. CXX_Objects does not depend on the extension stuff.

The start of my documentation, which covers class Object at least, is at
http://xfiles.llnl.gov. The basic philosophy is that an Object owns a
reference to the PyObject* it contains.







More information about the Cplusplus-sig mailing list