From 3533bd05049a50a0d49da25e3bf5852e759f5e15 Mon Sep 17 00:00:00 2001
From: Bruno da Silva de Oliveira
@@ -66,7 +67,7 @@ Now from Python:
@@ -20,7 +21,7 @@

- 
+ 


- 
+ 

diff --git a/pyste/doc/exporting_an_entire_header.html b/pyste/doc/exporting_an_entire_header.html
index d82b8ba2..c33bd6f9 100644
--- a/pyste/doc/exporting_an_entire_header.html
+++ b/pyste/doc/exporting_an_entire_header.html
@@ -60,6 +60,15 @@ the members of the header object like this:
+
+ AllFromHeader is broken in some cases. Until it is fixed,
+use at you own risk.
+ |
+
![]() |
diff --git a/pyste/doc/inserting_code.html b/pyste/doc/inserting_code.html
new file mode 100644
index 00000000..c834dc55
--- /dev/null
+++ b/pyste/doc/inserting_code.html
@@ -0,0 +1,73 @@
+
+
+
+
+ |
+ + Inserting Code + | +
![]() |
+ ![]() |
+ ![]() |
+
+You can insert arbitrary code in the generated cpps, just use the functions +declaration_code and module_code. This will insert the given string in the +respective sections. Example:
+
+ ##file A.pyste
+ Class("A", "A.h")
+ declaration_code("/* declaration_code() comes here */\n")
+ module_code("/* module_code() comes here */\n")
+
++Will generate:
+
+ // Includes ====================================================================
+ #include <boost/python.hpp>
+
+ // Using =======================================================================
+ using namespace boost::python;
+
+ // Declarations ================================================================
+
+ /* declaration_code() comes here */
+
+ // Module ======================================================================
+ BOOST_PYTHON_MODULE(A)
+ {
+ class_< A >("A", init< >())
+ .def(init< const A& >())
+ ;
+
+ /* module_code() comes here */
+ }
+
+![]() |
+ ![]() |
+ ![]() |
+
Copyright © 2003 Bruno da Silva de Oliveira
Copyright © 2002-2003 Joel de Guzman
+Permission to copy, use, modify, sell and distribute this document
+ is granted provided this copyright notice appears in all copies. This document
+ is provided "as is" without express or implied warranty, and with
+ no claim as to its suitability for any purpose.
-Note that, for functions that return const T&, the policy
+Note that for functions that return const T&, the policy
return_value_policy<copy_const_reference>() wil be used by default, because
that's normally what you want. You can change it to something else if you need
to, though.
diff --git a/pyste/doc/pyste.txt b/pyste/doc/pyste.txt
index 9b0ee96f..08eda4aa 100644
--- a/pyste/doc/pyste.txt
+++ b/pyste/doc/pyste.txt
@@ -73,26 +73,36 @@ Well, now let's fire it up:
'''
>python pyste.py
-Pyste version 0.6.5
+Pyste version 0.9.26
Usage:
- pyste [options] --module=
The string inside the brackets is the same as the name of the operator in C++.
-Pyste automatically generates wrappers for virtual member functions, but you -may want to disable this behaviour (for performance reasons, or to let the -code more clean) if you do not plan to override the functions in Python. To do -this, use the function final:
+Pyste automatically generates wrappers for virtual member functions, but you may +want to disable this behaviour (for performance reasons, for instance) if you do +not plan to override the functions in Python. To do this, use the function +final:
C = Class('C', 'C.h')
final(C.foo) ##C::foo is a virtual member function
diff --git a/pyste/doc/running_pyste.html b/pyste/doc/running_pyste.html
index 6acfbcd0..46bb7f46 100644
--- a/pyste/doc/running_pyste.html
+++ b/pyste/doc/running_pyste.html
@@ -47,26 +47,36 @@ Well, now let's fire it up:
>python pyste.py
-Pyste version 0.6.5
+Pyste version 0.9.26
Usage:
- pyste [options] --module=<name> interface-files
+ pyste [options] interface-files
where options are:
- -I <path> add an include path
- -D <symbol> define symbol
- --multiple create various cpps (one for each pyste file), instead
- of only one (useful during development)
- --out specify output filename (default: <module>.cpp)
- in --multiple mode, this will be a directory
- --no-using do not declare "using namespace boost";
- use explicit declarations instead
- --pyste-ns=<name> set the namespace where new types will be declared;
- default is the empty namespace
- --debug writes the xml for each file parsed in the current
- directory
- -h, --help print this help and exit
- -v, --version print version information
+ --module=<name> The name of the module that will be generated;
+ defaults to the first interface filename, without
+ the extension.
+ -I <path> Add an include path
+ -D <symbol> Define symbol
+ --multiple Create various cpps, instead of only one
+ (useful during development)
+ --out=<name> Specify output filename (default: <module>.cpp)
+ in --multiple mode, this will be a directory
+ --no-using Do not declare "using namespace boost";
+ use explicit declarations instead
+ --pyste-ns=<name> Set the namespace where new types will be declared;
+ default is the empty namespace
+ --debug Writes the xml for each file parsed in the current
+ directory
+ --cache-dir=<dir> Directory for cache files (speeds up future runs)
+ --only-create-cache Recreates all caches (doesn't generate code).
+ --generate-main Generates the _main.cpp file (in multiple mode)
+ --file-list A file with one pyste file per line. Use as a
+ substitute for passing the files in the command
+ line.
+ -h, --help Print this help and exit
+ -v, --version Print version information
+
Options explained:
@@ -76,12 +86,6 @@ GCCXML to parse the header files correctly and by Pyste to find the header files declared in the interface files.---multiple tells Pyste to generate multiple cpps for this module (one for -each header parsed) in the directory named by --out, instead of the usual -single cpp file. This mode is useful during development of a binding, because -you are constantly changing source files, re-generating the bindings and -recompiling. This saves a lot of time in compiling.
---out names the output file (default: <module>.cpp), or in multiple mode, names a output directory for the files (default: <module>).
@@ -97,6 +101,15 @@ default, Pyste uses the empty namespace.
GCCXML for each header parsed. Useful for bug reports.+--file-list names a file where each line points to a Pyste file. Use this instead +to pass the pyste files if you have a lot of them and your shell has some command line +size limit.
++The other options are explained below, in +Multiple Mode and + +Cache.
+-h, --help, -v, --version are self-explaining, I believe. ;)
So, the usage is simple enough:
@@ -104,11 +117,7 @@ So, the usage is simple enough: will generate a file mymodule.cpp in the same dir where the command was executed. Now you can compile the file using the same instructions of the -tutorial. Or, if you prefer: ->python pyste.py --module=mymodule --multiple file.pyste file2.pyste ...
-will create a directory named "mymodule" in the current directory, and will -generate a bunch of cpp files, one for each header exported. You can then -compile them all into a single shared library (or dll).
+tutorial.Don't worry: normally GCCXML is already configured correctly for your plataform, @@ -129,10 +138,52 @@ with that, you should have little trouble setting up the flags.
A note about Psyco+The multiple mode is useful in large projects, where the presence of multiple +classes in a single file makes the compilation unpractical (excessive memory +usage, mostly).
++The solution is make Pyste generate multiple files, more specifically one cpp +file for each Pyste file. This files will contain a function named after the +file, for instance Export_MyPysteFile, which will contain all the code to export +the classes, enums, etc. You can pass as much files as you want this way:
+>python pyste.py --module=mymodule file1.pyste file2.pyste
+This will create the files mymodule/file1.cpp and mymodule/file2.cpp. You +can then later do:
+>python pyste.py --module=mymodule file3.pyste
+and mymodule/file3.cpp will be generated.
++But compiling and linking this files won't be sufficient to generate your +extension. You have to also generate a file named main.cpp; call pyste with +all the Pyste files of your extension, and use the --generate-main option:
+>python pyste.py --module=mymodule --generate-main file1.pyste file2.pyste file3.pyste
+Now compile and link all this files together and your extension is ready for +use.
++Pyste now supports a form of cache, which is a way to speed up the code +generation. Most of the time that Pyste takes to generate the code comes from +having to execute +GCCXML (since being a front-end to GCC, it has to compile the +header files) and reading back the XML generated.
++When you use the --cache-dir=<dir> option, Pyste will dump in the specified +directory the generated XMLs to a file named after the Pyste file, with the +extension .pystec. The next time you run with this option, Pyste will use +the cache, instead of calling +GCCXML again:
+>python pyste.py --module=mymodule --cache-dir=cache file1.pyste
+Will generate file1.cpp and cache/file1.pystec. Next time you execute +this command, the cache file will be used. Note that Pyste doesn't do any check +to ensure that the cache is up to date, but you can configure your build system to do that for you.
++When you run Pyste with --only-create-cache, all the cache files will be +created again, but no code will be generated.
![]() |
diff --git a/pyste/doc/the_interface_files.html b/pyste/doc/the_interface_files.html
index 33ab7103..029e4302 100644
--- a/pyste/doc/the_interface_files.html
+++ b/pyste/doc/the_interface_files.html
@@ -64,6 +64,28 @@ We create a file named hello.pyste and create instances of the classes
![]() |
diff --git a/pyste/doc/wrappers.html b/pyste/doc/wrappers.html
index 3265a350..bb4057d1 100644
--- a/pyste/doc/wrappers.html
+++ b/pyste/doc/wrappers.html
@@ -30,10 +30,11 @@ Suppose you have this function:
std::vector<std::string> names();
| + Inserting Code + | +
Copyright © 2003 Bruno da Silva de Oliveira
Copyright © 2002-2003 Joel de Guzman
diff --git a/pyste/src/Pyste/ClassExporter.py b/pyste/src/Pyste/ClassExporter.py
index b8ef74ee..c680383c 100644
--- a/pyste/src/Pyste/ClassExporter.py
+++ b/pyste/src/Pyste/ClassExporter.py
@@ -1,3 +1,8 @@
+# Copyright Bruno da Silva de Oliveira 2003. Use, modification and
+# distribution is subject to the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http:#www.boost.org/LICENSE_1_0.txt)
+
import exporters
from Exporter import Exporter
from declarations import *
@@ -425,7 +430,7 @@ class ClassExporter(Exporter):
self.Add('template', holder(self.class_.FullName()))
# operators natively supported by boost
- BOOST_SUPPORTED_OPERATORS = '+ - * / % ^ & ! ~ | < > == != <= >= << >> && || += -='\
+ BOOST_SUPPORTED_OPERATORS = '+ - * / % ^ & ! ~ | < > == != <= >= << >> && || += -= '\
'*= /= %= ^= &= |= <<= >>='.split()
# create a map for faster lookup
BOOST_SUPPORTED_OPERATORS = dict(zip(BOOST_SUPPORTED_OPERATORS, range(len(BOOST_SUPPORTED_OPERATORS))))
diff --git a/pyste/src/Pyste/CodeExporter.py b/pyste/src/Pyste/CodeExporter.py
index e89d72aa..3680bb72 100644
--- a/pyste/src/Pyste/CodeExporter.py
+++ b/pyste/src/Pyste/CodeExporter.py
@@ -1,3 +1,8 @@
+# Copyright Bruno da Silva de Oliveira 2003. Use, modification and
+# distribution is subject to the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http:#www.boost.org/LICENSE_1_0.txt)
+
from Exporter import Exporter
#==============================================================================
diff --git a/pyste/src/Pyste/CppParser.py b/pyste/src/Pyste/CppParser.py
index 526d61e4..eb5e32c3 100644
--- a/pyste/src/Pyste/CppParser.py
+++ b/pyste/src/Pyste/CppParser.py
@@ -1,3 +1,8 @@
+# Copyright Bruno da Silva de Oliveira 2003. Use, modification and
+# distribution is subject to the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http:#www.boost.org/LICENSE_1_0.txt)
+
from GCCXMLParser import ParseDeclarations
import tempfile
import shutil
@@ -151,7 +156,8 @@ class CppParser:
if declarations is None:
declarations = self.ParseWithGCCXML(header, tail)
self.CreateCache(header, interface, tail, declarations)
- return declarations, header
+ header_fullpath = os.path.abspath(self.FindHeader(header))
+ return declarations, header_fullpath
def CacheFileName(self, interface):
diff --git a/pyste/src/Pyste/EnumExporter.py b/pyste/src/Pyste/EnumExporter.py
index a9763878..3206ca32 100644
--- a/pyste/src/Pyste/EnumExporter.py
+++ b/pyste/src/Pyste/EnumExporter.py
@@ -1,3 +1,8 @@
+# Copyright Bruno da Silva de Oliveira 2003. Use, modification and
+# distribution is subject to the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http:#www.boost.org/LICENSE_1_0.txt)
+
from Exporter import Exporter
from settings import *
import utils
@@ -47,44 +52,23 @@ class EnumExporter(Exporter):
exported_names[self.enum.FullName()] = 1
- UNIQUE_INT_EXPORTED = False
-
def ExportUniqueInt(self, codeunit):
- if not EnumExporter.UNIQUE_INT_EXPORTED:
- write = lambda s: codeunit.Write('declaration', s)
- write('// Unique type for unnamed enums\n')
- write('template