Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSharp Crash Fix: passing Struct through bindings as ref #215

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Source/buildbindingcsharp.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ func BuildBindingCSharp(component ComponentDefinition, outputFolder string, outp
return err
}

CSharpImplFile.WriteCLicenseHeader(component,
fmt.Sprintf("This is an autogenerated CSharp file in order to allow an easy\n use of %s", libraryName),
true)
CSharpImplFile.WriteCLicenseHeader(component,
fmt.Sprintf("This is an autogenerated CSharp file in order to allow an easy\n use of %s", libraryName),
true)
err = buildBindingCSharpImplementation(component, CSharpImplFile, namespace, baseName)

if len(outputFolderExample) > 0 {
Expand Down Expand Up @@ -240,9 +240,9 @@ func getCSharpPlainParameters(method ComponentDefinitionMethod, NameSpace string
parameters = parameters + fmt.Sprintf("UInt64 size%s, IntPtr data%s", param.ParamName, param.ParamName)
case "structarray":
parameters = parameters + fmt.Sprintf("UInt64 size%s, IntPtr data%s", param.ParamName, param.ParamName)

case "struct":
parameters = parameters + "ref " + ParamTypeName + " A" + param.ParamName
default:

parameters = parameters + ParamTypeName + " A" + param.ParamName
}

Expand Down Expand Up @@ -377,7 +377,7 @@ func writeCSharpClassMethodImplementation(method ComponentDefinitionMethod, w La

case "struct":
defineCommands = append(defineCommands, fmt.Sprintf(" Internal.Internal%s int%s = Internal.%sWrapper.convertStructToInternal_%s (A%s);", param.ParamClass, param.ParamName, NameSpace, param.ParamClass, param.ParamName))
callFunctionParameter = "int" + param.ParamName
callFunctionParameter = "ref int" + param.ParamName
initCallParameter = callFunctionParameter

case "basicarray":
Expand Down Expand Up @@ -407,15 +407,15 @@ func writeCSharpClassMethodImplementation(method ComponentDefinitionMethod, w La
initCallParameter = callFunctionParameter

case "class", "optionalclass":
if (ParamTypeName == "IntPtr") {
if ParamTypeName == "IntPtr" {
callFunctionParameter = "A" + param.ParamName
} else {
defineCommands = append(defineCommands, fmt.Sprintf(" IntPtr A%sHandle = IntPtr.Zero;", param.ParamName))
defineCommands = append(defineCommands, fmt.Sprintf(" if (A%s != null)", param.ParamName))
defineCommands = append(defineCommands, fmt.Sprintf(" A%sHandle = A%s.GetHandle();", param.ParamName, param.ParamName))
callFunctionParameter = "A" + param.ParamName + "Handle"
}

initCallParameter = callFunctionParameter

default:
Expand Down Expand Up @@ -585,7 +585,7 @@ func writeCSharpClassMethodImplementation(method ComponentDefinitionMethod, w La
defineCommands = append(defineCommands, fmt.Sprintf(" IntPtr new%s = IntPtr.Zero;", param.ParamName))
callFunctionParameter = "out new" + param.ParamName
initCallParameter = callFunctionParameter
if (ParamTypeName == "IntPtr") {
if ParamTypeName == "IntPtr" {
returnCodeLines = append(returnCodeLines, fmt.Sprintf(" return new%s;", param.ParamName))
} else {
// TODO: Using plain NameSpace here for calling PolymorphicFactory is most likely incorrect.
Expand Down Expand Up @@ -1128,7 +1128,7 @@ func buildBindingCSharpImplementation(component ComponentDefinition, w LanguageW
} else {
writeCSharpClassMethodImplementation(method, w, NameSpace, "Wrapper", true, " ")
}

w.Writeln(" }")
w.Writeln("")
}
Expand Down
Loading