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

Re: C# SWIG Bindings

From: Denis Gervalle <dgl_at_softec.st>
Date: 2004-10-14 10:13:40 CEST


I have reviewed the svncpp, which is a C++ wrapper over the subversion
Client C API. In fact, we provide a similar approach, but for C#. We
have not written our wrapper over the C++ API for the following reasons:

- Currently, managed C++ is not supported under Linux. Even if we have
managed to interface svncpp, depending on svncpp would have required a
recompilation of svncpp for each platform. To be portable on all
platforms supporting .NET and Subversion dynamic libraries, our C#
wrapper is exclusively written in C# and, this way, is platform
independent at the binary level.

- We do not want to have an intermediate level between our C# API and
Subversion. If we do, we have a risk that this intermediate level is no
more maintain, or not as actively maintained as Subversion itself (this
is a general comment, I have no particular opinion about svncpp).

- Svncpp API is partly based on the stable relationship between
Constructor/Destructor to manage memory allocation using APR pool. C#
does not provide "true" destructor, and we have to marshal some types
between the managed and unmanaged memory. Memory allocation using pool
was a challenge to interface with garbage collected memory used by .NET.
Adding an intermediate object-oriented level, does not help.

We have try to use constant rules to embed each type and wrap each
function when possible. This way, you can use the Subversion C API
documentation as a source for using our C# API. If you have already use
the C API, using our API is a breeze and is not a limitation.

Added to the simple wrapping of the C API which is obviously not object
oriented, we have start a lightweight object-oriented approach through
our SvnClient class. Using this one, the most used function can easily
be called without the need of understanding all the complex Subversion C
Some of the structures, like AprArray, has been extended to be type-safe
under C# and implement ICollection interface, so you can easily iterate
on them. Callbacks are also embedded to provide native C# types to the
user callback function.
This is our progressive approach toward what svncpp is providing to the
C++ world.

To illustrate all this, here a sample code that verbosely checkout our

using System;
using Softec.AprSharp;
using Softec.SubversionSharp;
class MainClass
        public static int Main() {
           SvnClient client = new SvnClient();
           client.AddSimpleProvider(); // not required since there is no
           client.Context.NotifyFunc =
               new SvnDelegate(new SvnWcNotify.Func(NotifyCallback));
               new SvnRevision(Svn.Revision.Head),

       public static void NotifyCallback(IntPtr baton, SvnPath Path,
                           SvnWcNotify.Action action, Svn.NodeKind kind,
                           AprString mimeType, SvnWcNotify.State
                           SvnWcNotify.State propState, int revNum) {
            switch(action) {
                case SvnWcNotify.Action.UpdateAdd:

I hope that I have appropriatly explain to you that our approach is more
elegant and flexible than you may expect it to be using svncpp. I have
nothing against svncpp, it is just not appropriate for our goals.

Thanks for your time.


Boris wrote:

>>Denis Gervalle wrote:
>>We have tryied using SWIG to bind the subversion client API with C#, but
>>all our efforts were unsucessful. This was mostly due to some unions and
>>special structures frequently used by subversion and also to the
>>frequent callbacks required.
>>Finally, we have manually written a C# front-end interface to the
>>Subversion Client API using Interop. You could find the result of this
>>effort at:
>Why didn't you use something like svncpp
>(http://rapidsvn.tigris.org/svncpp.html) to create a c# svn wrapper api. It
>seems to me like a much nicer way to create c# platform independent
>subversion bindings.
>- Boris

Denis Gervalle    
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Thu Oct 14 10:14:04 2004

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