Permalink
Browse files

Merge branch 'master' of https://github.com/BrantKyser/swig

- Remove using directives from the generated C# code and fully qualify the use of all .NET
  framework types in order to minimize potential name collisions from input files defining
  types, namespace, etc with the same name as .NET framework members.
- Globally qualify the use of .NET framework types in the System namespace
- Remove .NET 1.1 support, .NET 2 is the minimum for the C# module

Closes #79

* 'master' of https://github.com/BrantKyser/swig:
  Correct spelling of compatibility.
  Update documentation to reflect fully qualifying the use of .NET types in the generated code.
  Add support for SWIG2_CSHARP macro to create SWIG 2 backwards compatability mode.
  Remove using directives from the generated C# code and fully qualify the use of all .NET framework types in order to minimize potential name collisions from input files defining types, namespace, etc with the same name as .NET framework members.
  Since SWIG 3.0 removes support for .NET 1.1, cleanup the C# library by removing the use of the SWIG_DOTNET_1 macro.
  Globablly qualify the use of types from the .NET framework's System namespace in the C# module and library.
  Add test case to demonstrate the name collision that occurs in the generated C# code when a namespace is named System.
  • Loading branch information...
wsfulton committed Nov 9, 2013
2 parents d73f04e + 5f53503 commit c7b5316912df44db7e728cd66ba030a0502b737b
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -14,9 +14,11 @@ top_builddir = ../@top_builddir@
CPP_TEST_CASES = \
csharp_attributes \
+ csharp_swig2_compatibility \
csharp_exceptions \
csharp_features \
csharp_lib_arrays \
+ csharp_namespace_system_collision \
csharp_prepost \
csharp_typemaps \
enum_thorough_simple \
@@ -35,6 +37,7 @@ CSHARPFLAGSSPECIAL =
# Custom tests - tests with additional commandline options
intermediary_classname.cpptest: SWIGOPT += -dllimport intermediary_classname
csharp_lib_arrays.cpptest: CSHARPFLAGSSPECIAL = -unsafe
+csharp_swig2_compatibility.cpptest: SWIGOPT += -DSWIG2_CSHARP
# Rules for the different types of tests
%.cpptest:
@@ -82,17 +82,6 @@ public class li_std_vector_runme {
} catch (ArgumentException) {
}
}
-#if SWIG_DOTNET_1
- {
- // runtime check that 2D arrays fail
- double[,] outputarray = new double[collectionSize,collectionSize];
- try {
- vect.CopyTo(outputarray);
- throw new Exception("CopyTo (5a) test failed");
- } catch (ArgumentException) {
- }
- }
-#endif
{
StructVector inputvector = new StructVector();
int arrayLen = 10;
@@ -208,15 +197,13 @@ public class li_std_vector_runme {
throw new Exception("Repeat (1) test failed");
}
}
-#if !SWIG_DOTNET_1
{
System.Collections.Generic.IEnumerator<double> myEnumerator = dv.GetEnumerator();
while ( myEnumerator.MoveNext() ) {
if (myEnumerator.Current != 77.7)
throw new Exception("Repeat (2) test failed");
}
}
-#endif
}
{
@@ -0,0 +1,39 @@
+%module namespace_system_collision
+
+%{
+#include <string>
+
+namespace TopLevel
+{
+ namespace System
+ {
+ class Foo {
+ public:
+ virtual ~Foo() {}
+ virtual std::string ping() { return "TopLevel::System::Foo::ping()"; }
+ };
+ }
+}
+
+%}
+
+%include <std_string.i>
+
+// nspace feature only supported by these languages
+#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD)
+%nspace;
+#else
+#warning nspace feature not yet supported in this target language
+#endif
+
+namespace TopLevel
+{
+ namespace System
+ {
+ class Foo {
+ public:
+ virtual ~Foo();
+ virtual std::string ping();
+ };
+ }
+}
@@ -116,7 +116,7 @@ struct PrePost3 {
// Check attributes in the typemaps
%typemap(cstype, inattributes="[CustomInt]") int val "int"
%typemap(csin, pre=" int tmp_$csinput = $csinput * 100;") int val "tmp_$csinput"
-%typemap(imtype, out="IntPtr/*overridden*/", outattributes="[CustomIntPtr]") CsinAttributes * "HandleRef/*overridden*/"
+%typemap(imtype, out="global::System.IntPtr/*overridden*/", outattributes="[CustomIntPtr]") CsinAttributes * "global::System.Runtime.InteropServices.HandleRef/*overridden*/"
%inline %{
class CsinAttributes {
@@ -216,8 +216,8 @@ void subtractYears(CDate *pDate, int years) {
%typemap(csvarout, excode=SWIGEXCODE2) CDate * %{
/* csvarout typemap code */
get {
- IntPtr cPtr = $imcall;
- CDate tempDate = (cPtr == IntPtr.Zero) ? null : new CDate(cPtr, $owner);$excode
+ global::System.IntPtr cPtr = $imcall;
+ CDate tempDate = (cPtr == global::System.IntPtr.Zero) ? null : new CDate(cPtr, $owner);$excode
return new System.DateTime(tempDate.getYear(), tempDate.getMonth(), tempDate.getDay(),
0, 0, 0);
} %}
@@ -0,0 +1,48 @@
+%module csharp_swig2_compatibility
+
+%typemap(cscode) Foo %{
+
+// Without the using directives generated by the
+// SWIG 2 compatibility mode, this code would fail
+// to build.
+public void FooBar(string input)
+{
+ Console.WriteLine(input);
+}
+
+%}
+
+%pragma(csharp) imclasscode=%{
+
+// Without the using directives generated by the
+// SWIG 2 compatibility mode, this code would fail
+// to build.
+public void IntermediateClassMethod(string input)
+{
+ Console.WriteLine(input);
+}
+
+%}
+
+%pragma(csharp) modulecode=%{
+
+// Without the using directives generated by the
+// SWIG 2 compatibility mode, this code would fail
+// to build.
+public void ModuleClassMethod(string input)
+{
+ Console.WriteLine(input);
+}
+
+%}
+
+%inline %{
+class Foo {
+public:
+ Foo() {}
+
+ void Bar() {}
+};
+
+%}
+
@@ -94,7 +94,7 @@ Number times12(const Number* num) {
%typemap(csvarin, excode=SWIGEXCODE2) int %{
set {
if ($csinput < 0)
- throw new ApplicationException("number too small!");
+ throw new global::System.ApplicationException("number too small!");
$imcall;$excode
} %}
@@ -188,7 +188,7 @@ namespace Space {
#if defined(SWIGCSHARP)
%typemap(cscode) Space::RenameMe %{
- public static NewName factory(String s) {
+ public static NewName factory(System.String s) {
//below should expand to:
//return new NewName( new Name(s) );
return new $typemap(cstype, Space::RenameMe)( new $typemap(cstype, Name)(s) );
View
@@ -57,7 +57,7 @@
%typemap(ctype) CTYPE INPUT[] "CTYPE*"
%typemap(cstype) CTYPE INPUT[] "CSTYPE[]"
-%typemap(imtype, inattributes="[In, MarshalAs(UnmanagedType.LPArray)]") CTYPE INPUT[] "CSTYPE[]"
+%typemap(imtype, inattributes="[global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPArray)]") CTYPE INPUT[] "CSTYPE[]"
%typemap(csin) CTYPE INPUT[] "$csinput"
%typemap(in) CTYPE INPUT[] "$1 = $input;"
@@ -68,7 +68,7 @@
%typemap(ctype) CTYPE OUTPUT[] "CTYPE*"
%typemap(cstype) CTYPE OUTPUT[] "CSTYPE[]"
-%typemap(imtype, inattributes="[Out, MarshalAs(UnmanagedType.LPArray)]") CTYPE OUTPUT[] "CSTYPE[]"
+%typemap(imtype, inattributes="[global::System.Runtime.InteropServices.Out, global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPArray)]") CTYPE OUTPUT[] "CSTYPE[]"
%typemap(csin) CTYPE OUTPUT[] "$csinput"
%typemap(in) CTYPE OUTPUT[] "$1 = $input;"
@@ -79,7 +79,7 @@
%typemap(ctype) CTYPE INOUT[] "CTYPE*"
%typemap(cstype) CTYPE INOUT[] "CSTYPE[]"
-%typemap(imtype, inattributes="[In, Out, MarshalAs(UnmanagedType.LPArray)]") CTYPE INOUT[] "CSTYPE[]"
+%typemap(imtype, inattributes="[global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.Out, global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPArray)]") CTYPE INOUT[] "CSTYPE[]"
%typemap(csin) CTYPE INOUT[] "$csinput"
%typemap(in) CTYPE INOUT[] "$1 = $input;"
@@ -108,12 +108,12 @@ CSHARP_ARRAYS(double, double)
%define CSHARP_ARRAYS_FIXED( CTYPE, CSTYPE )
%typemap(ctype) CTYPE FIXED[] "CTYPE*"
-%typemap(imtype) CTYPE FIXED[] "IntPtr"
+%typemap(imtype) CTYPE FIXED[] "global::System.IntPtr"
%typemap(cstype) CTYPE FIXED[] "CSTYPE[]"
%typemap(csin,
pre= " fixed ( CSTYPE* swig_ptrTo_$csinput = $csinput ) {",
terminator=" }")
- CTYPE FIXED[] "(IntPtr)swig_ptrTo_$csinput"
+ CTYPE FIXED[] "(global::System.IntPtr)swig_ptrTo_$csinput"
%typemap(in) CTYPE FIXED[] "$1 = $input;"
%typemap(freearg) CTYPE FIXED[] ""
Oops, something went wrong.

0 comments on commit c7b5316

Please sign in to comment.