#1088 Segfault in managed code when accessing protected methods

csharp (36)

Hi, I'm using SWIG 1.3.36 to wrap a rather complex C++ library into Java and C# classes. In both cases, when calling protected methods which have been wrapped with

%module (directors="1", allprotected="1") libtisch
%feature("director") Widget;

I get segfaults in native code when calling any protected method from managed code.

However, when I change the C++ header and declare the methods public, it suddenly works without a recompile of the native code - just SWIG has to be re-run. So I suppose this is really a bug in SWIG relating to directors.



  • William Fulton

    William Fulton - 2011-02-05

    I cannot replicate using trunk which is the basis for the upcoming swig-2.0.2 release. I'm using the code below. Please test again and if still not working provide a full example that fails.

    // SWIG interface file
    %module (directors="1", allprotected="1") example

    %feature("director") Widget;

    %inline %{
    struct Widget {
    virtual ~Widget() {}
    int protectedMethod(int a) { return a; }

    // C# test program

    using System;

    public class WidgetDotnet : Widget {
    public int protectedMethod(int a) {
    int ret = base.protectedMethod(a);
    return ret * 10;

    public class runme
    static void Main()
    Console.WriteLine( "starting" );

    WidgetDotnet w = new WidgetDotnet();
    int a = w.protectedMethod(11);
    Console.WriteLine("a: {0}", a);

    Console.WriteLine( "finished" );

  • William Fulton

    William Fulton - 2011-02-05
    • labels: 505206 --> csharp
    • status: open --> closed-works-for-me

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks