[C++-sig] module too big.

Roman Yakovenko romany at actimize.com
Mon Sep 1 14:06:13 CEST 2003


Hi Nicodemus. Thanks for your quick and helpfull responce.
But it didn't help me in all cases. The reason is simple my compiler
( VC 6.0 SP 5 ) is too limited. I had to devide even single class 
( 15 functions ) to 2 files. Thanks a lot for good tool.

Roman.

> -----Original Message-----
> From: Nicodemus [mailto:nicodemus at globalite.com.br]
> Sent: Friday, August 29, 2003 1:06 AM
> To: Development of Python/C++ integration
> Subject: Re: [C++-sig] module too big.
> 
> 
> Hi Roman,
> 
> Roman Yakovenko wrote:
> 
> >Hi. Using Pyste I succedded to generate wrapper for my library.
> >The file I got is 4000 lines. My question is how can I devide
> >this file to a few small ones ?
> >  
> >
> 
> The support for big wrappers has improved a lot in the last 
> few weeks, 
> thanks to a combinated effort of Prabhu Ramachandran and myself. We 
> discussed a lot, shared lots of code, and came up with a 
> solution that 
> he and I are quite happy with it. 8)
> I didn't write the documentation about it, thought, so I will 
> describe 
> the procedure here. Let's use this class hierarchy as an example:
> 
> // A.h
> struct A { /* ... */ };
> 
> // B.h
> #include "A.h"
> struct B: A { /* ... */ };
> 
> // C.h
> #include "B.h"
> struct C: B { /* ... */ };
> 
> First thing, you must divide your classes in multiple Pyste 
> files. Mind 
> you, Boost.Python needs base classes to be instantiated 
> before derived 
> classes, and Pyste did that automatically for you, but not 
> anymore, so 
> you have to do it by hand. Let's write one Pyste file for our 
> library then:
> 
> 
>     # mylib.pyste
>     Class("A", "A.h")
>     Class("B", "B.h")
>     Class("C", "C.h")
> 
> 
> Notice that the base class, A, has been declared first. This is the 
> simplest usage. We use this command line:
> 
>     pyste.py --module=mylib mylib.pyste
> 
> This will generate a file named "mylib.cpp" in the current directory 
> with all the classes exported.
> 
> Now suppose this file is too big (as is your case) and it 
> takes ages to 
> compile, plus after any little change you do in both your code or the 
> Pyste file you will have to re-generate the wrapper code 
> (which can take 
> a while) and recompile it (which taks *quite* a while 8) ).
> 
> The first step to solve this problem is to split your classes in 
> multiple Pyste files. Here, let's put A and B in their own Pyste file 
> (AB.pyste), and put C in another (C.pyste). But we have to 
> declare also 
> that C.pyste depends on AB.pyste, so that Pyste knows that A 
> and B are 
> also being exported to generate the correct code. Here are 
> the contents 
> of then:
> 
> 
>     # AB.pyste
>     Class("A", "A.h")
>     Class("B", "B.h")
> 
>     # C.pyste
>     Import("AB.pyste")  # that's how we declare the dependency
>     Class("C", "C.h")
> 
> 
> Ok, now we have to generate the code. You use the --multiple flag to 
> specify that your are sharing your wrapping code across 
> multiple cpp files:
> 
>     pyste.py --multiple --module=mylib AB.pyste
> 
> This will generate the file mylib/_AB.cpp.
> 
>     pyste.py --multiple --module=mylib C.pyste
> 
> This will generate the file mylib/_C.cpp.
> 
> Those files contain the definition of the classes, but they don't 
> declare BOOST_PYTHON_MODULE. This is done in a separate file, 
> that you 
> create with this command line:
> 
>     pyste.py --multiple --module=mylib --generate-main 
> AB.pyste C.pyste
> 
> This will generate the file mylib/_main.cpp. To correctly 
> generate it, 
> you have to pass in the command line *all* the Pyste files of your 
> library. Fortunately, the generation of this file is almost 
> instantly. ;)
> 
> Now, we have in the mylib folder all the files needed by our library:
> 
>     _AB.cpp
>     _C.cpp
>     _main.cpp
> 
> You now just compile them all normaly to object files, and 
> link them all 
> together. You will have an extension module as before, but with a few 
> advantages:
>    
>     * If you change a header file used by a Pyste file, only the 
> corresponding cpp of that Pyste file will have to be regenerated and 
> recompiled, the rest stays intact.
>     * Compile time will normally be reduced, since with very 
> big files 
> the memory consumption by the compiler gets out of hand.
> 
> There's a feature that will also speed-up the re-generation of the 
> wrappers (not compilation), the possibility to create Pyste 
> caches. You 
> just have to add a new option to the command lines above: 
> "--cache-dir=<dir name>". In the directory specified, Pyste 
> will cache 
> the output by GCCXML, which should give a boost of about 3 to 4 times 
> over the normal usage. Example:
> 
>     pyste.py --multiple --module=mylib --cache-dir=cache C.pyste
> 
> This will generate, besides mylib/_C.cpp, a file named 
> cache/C.pystec. 
> The next time you run this same command, it should create the 
> wrappers 
> much quicker than before. But note that C.pystec depends on all the 
> headers of the declarations in C.pyste, so if you change C.h, 
> you should 
> re-generate the cache. You can either delete C.pystec, or run:
> 
>     pyste.py --multiple --module=mylib --cache-dir=cache 
> --only-create-cache C.pyste
> 
> This will recreate the C.pystec file, but will not generate 
> any wrapper 
> code.
> 
> 
> Whew! Hope that gets you moving! 8)
> Feel free to ask any questions you may have!
> 
> Regards,
> Nicodemus.
> 
> 
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
> 




More information about the Cplusplus-sig mailing list