Python - remove duplicate proxy method definitions for global function wrappers.

Global functions previously generated two definitions, eg:

  def foo():
      return _example.foo()
  foo = _example.foo

The first definition is replaced by the second definition and so the second definition
is the one used when the method is actually called. Now just the first definition is
generated by default and if the -fastproxy command line option is used, just the second
definition is generated. The second definition is faster as it avoids the proxy Python
method as it calls the low-level C wrapper directly. Using both -fastproxy and -olddefs
command line options will restore the previously generated code as it will generate both
method definitions.

With this change, the wrappers for global C/C++ functions and C++ class methods now work
in the same way wrt to generating just a proxy method by default and control via
-fastproxy/-olddefs options.

Closes #639.
This commit is contained in:
William S Fulton 2019-01-01 12:12:56 +00:00
commit 07884f10ee
3 changed files with 57 additions and 15 deletions

View file

@ -3913,6 +3913,7 @@ class Go(object):
</div>
<p>
Each method in the Python class contains a Python proxy method which passes the arguments on to the underlying function in the low-level C/C++ module (_example in this case).
The generated proxy class when using <tt>-fastproxy</tt> is:
</p>
@ -3928,7 +3929,12 @@ class Go(object):
</div>
<p>
where <tt>_swig_new_instance_method</tt> adds the method to the proxy class via C API calls.
where <tt>_swig_new_instance_method</tt> adds the method to the proxy class via C API calls for direct access to the underlying function in the low-level C/C++ module.
Note that for some methods it is not possible to generate the direct access call and so <tt>-fastproxy</tt> is ignored.
This happens, for example, when adding <a href="#Python_nn42">additional code</a> to Python proxy methods, such as using <tt>%pythonprepend</tt>.
</p>
<p>
The overhead calling into C/C++ from Python is reduced slightly using <tt>-fastproxy</tt>.
Below are some timings in microseconds calling the 3 functions in the example above.
Also included in the table for comparison is using the <tt>-builtin</tt> option covered in the
@ -3995,6 +4001,10 @@ The class defines each method in two different ways. The first definition is rep
While this possibly provides the best of both worlds, the time to import the module will be slighly slower when the class is defined due to the additional method definitions.
</p>
<p>
The command line options mentioned above also apply to wrapped C/C++ global functions, not just class methods.
</p>
<H2><a name="Python_nn45">38.7 Tips and techniques</a></H2>