[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[PATCH] Pythonic Memory Pools for the Python Bindings

From: David James <james82_at_gmail.com>
Date: 2005-07-19 01:05:04 CEST

This patch implements Pythonic pool management for the Python bindings.

Mark Rowe <code@bdash.net.nz> donated his automatic pool management
code as a starting point for my patch. Thanks Mark!

- Python creates an application-scoped pool when the application
starts, and deletes it when the application exits. APR initialization
and termination is now handled automatically.
- All pool parameters to SWIG functions are now optional. If no pool
is specified, the default application-scoped pool will be used. The
application-scoped pool will also be used if "None" is passed in as
the pool.
- If a pool is not destroyed, it will be automatically
garbage-collected when it goes out of scope.
- I have created a new object-oriented interface for creating memory
pools. The old C-like interface has been deprecated. In a separate
patch, I plan to upgrade the existing Python bindings and examples to
use the new object-oriented interface.
  * To create a pool, simply use the Pool() constuctor in svn.core.
  * To destroy a pool, use Pool.destroy. If you do not destroy the
pool, it will be garbage-collected automatically.
  * To clear a pool, use Pool.clear().
- All functions will now check the validity of their memory pool
before executing. If the memory pool is invalid, a Python
AssertionError message will be raised. If you pass in a different
datatype where you should have passed in a pool, a Python TypeError
message will be raised.
- Functions which need pools but do not have them can use the
application-scoped pool to perform their work. This means that
svn_string_t and svn_stringbuf_t structures can now be mutable. I plan
to implement this change in a separate patch.

- Existing Python code should work fine without any changes. Existing
code using the old interface will still benefit from all of the new
features, including Pythonic error messages and garbage collection.

- I've also submitted unit tests to test my new code and the
compatibility layer. These tests will form the first tests of the new
Python test suite. I plan to extend the Python test suite further in
my future patches.


Implement Pythonic pool management for the Python bindings.

Submitted by: David James <james@cs.toronto.edu>
Assisted by: Mark Rowe <code@bdash.net.nz>
(Mark donated his automatic pool management code as a starting point
for my patch. Thanks Mark!)

  (svn_swig_py_set_application_pool, svn_swig_py_clear_application_pool,
   svn_swig_py_get_application_pool): New wrappers for new functions.
  (run_app, svn_pool_destroy, svn_pool_create, svn_pool_clear):
  Deprecate. Reimplemented interface using Pythonic pools.

  (apr_pool_clear, apr_pool_destroy): Remove functions. These functions
  can be accessed by directly including libsvn.core. I did not create a
  compatibility layer for these functions because svn_pool_clear and
  svn_pool_destroy are favored over apr_pool_clear and apr_pool_destroy.

  (apr_initialize, apr_terminate): Deprecate. APR initialization and
  termination is now handled automatically. Old functions are now no-ops.
  (application_pool): New variable. Global application pool.
  (Pool): New object. A Pythonic pool object, managed by Python.
  (Pool.init): New method. Create a new memory pool.
  (Pool.valid): New method. Check whether this memory pool is still valid.
  (Pool.assert_valid): New method. Assert that this memory_pool is still valid.
  (Pool.clear): New method. Clear embedded memory pool.
  (Pool.destroy): New method. Destroy embedded memory pool.
  (Pool.__del__): New method. Automatically destroys memory pools, if necessary.
  (_global_pool): New variable. Contains application pool.
  Intentionally uses same variable name as function-level global pool
  so that the SWIG/C code will fall-back to the application-level pool
  if no function-level global pool is available.

  (svn_swig_py_set_application_pool): New function. Sets the
  application-level global pool.

  (svn_swig_py_clear_application_pool): New function. Clears the
  application-level global pool.

  (svn_swig_py_get_application_pool): New function. Gets the
  application-level global pool.

  (svn_swig_py_convert_pool): New function. Converts a Python pool
  object into a SWIG Pool object. Raises a Python AssertionError or
  TypeError if the Python pool object is invalid.

  (_global_pool): Add declaration for new global variable.
  (svn_swig_py_set_application_pool, svn_swig_py_clear_application_pool,
   svn_swig_py_get_application_pool, svn_swig_py_convert_pool): Add
  declarations for new functions.

  (apr_pool_t): Update typemap for apr_pool_t to convert Python pools
  into APR pools, and to use the application-level pool if no local
  pool is available.

  New file. Contains test case for the new automatic pool management

  New file. Run all of the Python test cases.


David James -- http://www.cs.toronto.edu/~james

To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Received on Tue Jul 19 02:04:10 2005

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.