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

SWIG and platform-specific auth providers (Was: Python bindings build seems broken)

From: Jeremy Whitlock <jcscoobyrs_at_gmail.com>
Date: Wed, 15 Oct 2008 16:29:39 -0600

Hi All,
    There have been some notable changes to how SWIG handles
platform-specific auth providers over the last few days. As of
r33671, we now have a very versatile solution that should completely
get rid of auth provider related segfaults in the SWIG bindings and
make it easier for people to write in platform-specific auth support
into their SWIG binding based Subversion applications.

    As of r33671, you will have all platform-specific auth providers
wrapped by SWIG, regardless of your operating system. (Or so it
seems.) The way this works is we use some nice SWIG magic to get SWIG
to wrapper a function but at compile time, if the function should not
be available based on platform or missing functionality, the
Subversion-specific function is excluded from the C file and instead,
a SWIG exception is thrown in its place. So instead of the function
not being wrapped at all, to SWIG users, it "appears" to be wrapped.
What this means is when you attempt to call
"core.svn_auth_get_keychain_simple_provider" while on Windows, instead
of getting a "Symbol not found error" or some segfault, you get this
nice RuntimeError that you can handle gracefully. If you don't
believe me, check out
 In that test, we attempt to get the simple provider for keychain,
windows, gnome-keyring and kwallet all without conditionally calling
those functions based on operating system. :)

    This was done without any core Subversion modification other than
exposing the platform-specific auth functions to SWIG. That's it.
And the "magic" I mentioned earlier really isn't magic but using SWIG
to either wrap the function or pretend to wrap the function. When it
pretends to wrap, you have a language-specific RuntimeException
thrown. Now, the way we do this is with this cool little SWIG macro
in subversion/bindings/swig/include/svn_global.swg. What this does is
allow you to specify a function, tell what #ifdef should be used to
allow that function to be compiled into SWIG's core.c and then SWIG
handles the rest. The reason I'm telling you this is because this
macro might be useful to other non-auth Subversion functions that
happen to be platform-specific and desirable to be wrapped by SWIG.
Here is some pseudo code to explain how core.c might look based on
whether a function is wrapped or not:

*SWIGUNUSEDPARM(self), PyObject *args) {
"'svn_auth_get_keychain_simple_provider' is not available on this

So if the system compiling core.c has Keychain services,
svn_auth_get_keychain_simple_provider is compiled into _core.so,
otherwise, you get an exception at runtime in its place. Since the
actual Subversion symbol is conditionally compiled in, that means that
while you may have core.svn_auth_get_keychain_simple_provider
available to Python, the actual svn_auth_get_keychain_simple_provider
symbol does not need to exist in libsvn_subr-1.dylib. That lets you
actually call that on any system and handle the result appropriately.

Take care,
Jeremy Whitlock
To unsubscribe, e-mail: dev-unsubscribe_at_subversion.tigris.org
For additional commands, e-mail: dev-help_at_subversion.tigris.org
Received on 2008-10-16 00:29:53 CEST

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