kkaempf / swig-issues

Issues from SWIG (testing)
0 stars 0 forks source link

[c#] struct with array of struct member #89

Open SwigAtSF opened 11 years ago

SwigAtSF commented 11 years ago

I've a struct that contains an array of another struct as a member:

struct TestComplexStruct2 { int iMember1; TestSimpleStruct1 asMember2[255]; TestBigStruct1 asMember3[10]; };

Swig generates the following c# code (cmdline: swig.exe" -DWIN32 -csharp -c++ -Wall TestInterOp.i)

/* ----------------------------------------------------------------------------

  • This file was automatically generated by SWIG (http://www.swig.org).
  • Version 1.3.31 *
  • Do not make changes to this file unless you know what you are doing--modify
  • the SWIG interface file instead.
  • ----------------------------------------------------------------------------- */

using System; using System.Runtime.InteropServices;

public class TestComplexStruct2 : IDisposable { private HandleRef swigCPtr; protected bool swigCMemOwn;

internal TestComplexStruct2(IntPtr cPtr, bool cMemoryOwn) { swigCMemOwn = cMemoryOwn; swigCPtr = new HandleRef(this, cPtr); }

internal static HandleRef getCPtr(TestComplexStruct2 obj) { return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr; }

~TestComplexStruct2() { Dispose(); }

public virtual void Dispose() { lock(this) { if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) { swigCMemOwn = false; TestInterOpModulePINVOKE.delete_TestComplexStruct2(swigCPtr); } swigCPtr = new HandleRef(null, IntPtr.Zero); GC.SuppressFinalize(this); } }

public int iMember1 { set { TestInterOpModulePINVOKE.TestComplexStruct2_iMember1_set(swigCPtr, value); } get { int ret = TestInterOpModulePINVOKE.TestComplexStruct2_iMember1_get(swigCPtr); return ret; } }

public TestSimpleStruct1 asMember2 { set { TestInterOpModulePINVOKE.TestComplexStruct2_asMember2_set(swigCPtr, TestSimpleStruct1.getCPtr(value)); } get { IntPtr cPtr = TestInterOpModulePINVOKE.TestComplexStruct2_asMember2_get(swigCPtr); TestSimpleStruct1 ret = (cPtr == IntPtr.Zero) ? null : new TestSimpleStruct1(cPtr, false); return ret; } }

public TestBigStruct1 asMember3 { set { TestInterOpModulePINVOKE.TestComplexStruct2_asMember3_set(swigCPtr, TestBigStruct1.getCPtr(value)); } get { IntPtr cPtr = TestInterOpModulePINVOKE.TestComplexStruct2_asMember3_get(swigCPtr); TestBigStruct1 ret = (cPtr == IntPtr.Zero) ? null : new TestBigStruct1(cPtr, false); return ret; } }

public TestComplexStruct2() : this(TestInterOpModulePINVOKE.new_TestComplexStruct2(), true) { }

}

So array of struct members are wrapped as a member of struct type instead of a swig-generated type for array access (basic type members do work).

In addition my TestInterOp.i file - just for completeness, it does not set any options:

/* File : TestInterOp.i */ %module TestInterOpModule

%{

include "StructDefs.h"

include "TestInterOp.h"

%}

%include "StructDefs.h" %include "TestInterOp.h"