Hi.

The cross language polymorphism with std::shared_ptr does not seem to work correctly. When I tested (the test codes which follows at the end) using normal pointers, it works, but it fails to show correct result with std::shared_ptr. 

$ python test_swig_sp.py 
Base
Base

The output on the last line should be 'Derived'. Do I miss something? I'm using swig-2.0.7 and Python 2.7 on Ubuntu 11.10.

$ uname -a
Linux groove 3.0.0-20-generic #34-Ubuntu SMP Tue May 1 17:24:39 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
$ python --version
Python 2.7.2+

The followings are the test codes which I used.

Regards.

// swig_sp.hh
#include <iostream>
#include <memory>

struct Base
{
  virtual ~Base() {}
  virtual void info()
  {
    std::cout << "Base" << std::endl;
  }
};

struct Container
{
  Container(std::shared_ptr<Base> o): val(o) {}
  std::shared_ptr<Base> val;
};
// end of swig_sp.hh

// swig_sp.cc
#include "swig_sp.hh"
// end of swig_sp.cc

// swig_sp.i
%module(directors="1") swig_sp

%{
#define SWIG_FILE_WITH_INIT
#include "swig_sp.hh"
%}

%include <std_shared_ptr.i>
%shared_ptr(Base)
%feature("director") Base;
%include "swig_sp.hh"
// end of swig_sp.i

# setup.py
from distutils.core import setup, Extension

swig_sp_module = Extension(name = '_swig_sp',
                           sources = ['swig_sp.cc', 'swig_sp.i'],
                           depends = ['swig_sp.hh'],
                           swig_opts = ['-c++'],
                           language = 'c++',
                           extra_compile_args = ['-std=c++0x'])

setup(ext_modules = [swig_sp_module])
# end of setup.py

# test_swig_sp.py
from swig_sp import *

class Derived(Base):
    def info(self):
        print 'Derived'

b = Container(Base())
d = Container(Derived())

b.val.info()
d.val.info()
# end of test_swig_sp.py