Skip to content

Commit

Permalink
Continuing: Use the Swift-certified idiom to take the address of obje…
Browse files Browse the repository at this point in the history
…cts, rather than the unsafe way, similar in spirit to 4394cf4.   The hubris count went from 14,340 to 3,748
  • Loading branch information
migueldeicaza committed Oct 6, 2023
1 parent f6f5341 commit 129d7b9
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Generator/Generator/MethodGen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,17 @@ func methodGen (_ p: Printer, method: MethodDefinition, className: String, cdef:
}
}
// With Godot 4.1 we need to pass the address of the handle
let prefix = String(repeating: " ", count: withUnsafeCallNestLevel * 4)
let retFromWith = returnType != "" ? "return " : ""

if refParameterIsOptional || optstorage == ".handle" {
let prefix = String(repeating: " ", count: withUnsafeCallNestLevel * 4)
let ea = escapeSwift(argref)
let retFromWith = returnType != "" ? "return " : ""
let deref = refParameterIsOptional ? "?" : ""
argSetup += "\(prefix)\(retFromWith)withUnsafePointer (to: \(ea)\(deref).handle) { p\(withUnsafeCallNestLevel) in\n\(prefix)_args.append (\(ea) == nil ? nil : p\(withUnsafeCallNestLevel))\n"
withUnsafeCallNestLevel += 1
} else {
let prefix = String(repeating: " ", count: withUnsafeCallNestLevel * 4)
argSetup += "\(prefix)_args.append (UnsafeRawPointer(\(needAddress)\(escapeSwift(argref))\(optstorage)))\n"
argSetup += "\(prefix)\(retFromWith)withUnsafePointer (to: \(needAddress)\(escapeSwift(argref))\(optstorage)) { p\(withUnsafeCallNestLevel) in\n\(prefix) _args.append (p\(withUnsafeCallNestLevel))\n"
withUnsafeCallNestLevel += 1
}
}
argSetup += varArgSetupInit
Expand Down

0 comments on commit 129d7b9

Please sign in to comment.