Add check for smart pointer type in generated code for director connection. This fixes a crash in the generated code caused by the dynamic_cast returning 0 because the specified types are incorrect for smart pointer types.
Add runtime test to the C# test suite's director smartptr test that demonstrates crash in generated code when directors are used with smart pointer types. Closes #34
This commit is contained in:
parent
28c033dd90
commit
25eaee49f3
2 changed files with 53 additions and 2 deletions
41
Examples/test-suite/csharp/director_smartptr_runme.cs
Normal file
41
Examples/test-suite/csharp/director_smartptr_runme.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
using director_smartptrNamespace;
|
||||||
|
|
||||||
|
public class runme
|
||||||
|
{
|
||||||
|
|
||||||
|
private class director_smartptr_MyBarFoo : Foo
|
||||||
|
{
|
||||||
|
public override string ping()
|
||||||
|
{
|
||||||
|
return "director_smartptr_MyBarFoo.ping();";
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string pong()
|
||||||
|
{
|
||||||
|
return "director_smartptr_MyBarFoo.pong();" + ping();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string fooBar(FooBar fooBar)
|
||||||
|
{
|
||||||
|
return fooBar.FooBarDo();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Foo makeFoo()
|
||||||
|
{
|
||||||
|
return new Foo();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override FooBar makeFooBar()
|
||||||
|
{
|
||||||
|
return new FooBar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Main()
|
||||||
|
{
|
||||||
|
director_smartptr_MyBarFoo myBarFoo =
|
||||||
|
new director_smartptr_MyBarFoo();
|
||||||
|
|
||||||
|
myBarFoo.ping();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3382,6 +3382,7 @@ public:
|
||||||
String *qualified_classname = Copy(sym_name);
|
String *qualified_classname = Copy(sym_name);
|
||||||
String *nspace = getNSpace();
|
String *nspace = getNSpace();
|
||||||
String *dirClassName = directorClassName(n);
|
String *dirClassName = directorClassName(n);
|
||||||
|
String *smartptr_feature = Getattr(n, "feature:smartptr");
|
||||||
|
|
||||||
if (nspace)
|
if (nspace)
|
||||||
Insert(qualified_classname, 0, NewStringf("%s.", nspace));
|
Insert(qualified_classname, 0, NewStringf("%s.", nspace));
|
||||||
|
|
@ -3392,8 +3393,17 @@ public:
|
||||||
Wrapper *code_wrap = NewWrapper();
|
Wrapper *code_wrap = NewWrapper();
|
||||||
Printf(code_wrap->def, "SWIGEXPORT void SWIGSTDCALL %s(void *objarg", wname);
|
Printf(code_wrap->def, "SWIGEXPORT void SWIGSTDCALL %s(void *objarg", wname);
|
||||||
|
|
||||||
Printf(code_wrap->code, " %s *obj = (%s *)objarg;\n", norm_name, norm_name);
|
if (Len(smartptr_feature)) {
|
||||||
Printf(code_wrap->code, " %s *director = dynamic_cast<%s *>(obj);\n", dirClassName, dirClassName);
|
Printf(code_wrap->code, " %s *obj = (%s *)objarg;\n", smartptr_feature, smartptr_feature);
|
||||||
|
Printf(code_wrap->code, " // Keep a local instance of the smart pointer around while we are using the raw pointer\n");
|
||||||
|
Printf(code_wrap->code, " // Avoids using smart pointer specific API.\n");
|
||||||
|
Printf(code_wrap->code, " %s *director = dynamic_cast<%s *>(obj->operator->());\n", dirClassName, dirClassName);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Printf(code_wrap->code, " %s *obj = (%s *)objarg;\n", norm_name, norm_name);
|
||||||
|
Printf(code_wrap->code, " %s *director = dynamic_cast<%s *>(obj);\n", dirClassName, dirClassName);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: if statement not needed?? - Java too
|
// TODO: if statement not needed?? - Java too
|
||||||
Printf(code_wrap->code, " if (director) {\n");
|
Printf(code_wrap->code, " if (director) {\n");
|
||||||
Printf(code_wrap->code, " director->swig_connect_director(");
|
Printf(code_wrap->code, " director->swig_connect_director(");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue