From 129d7b98999cc4871d28e0480334c1945b5819fd Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Fri, 6 Oct 2023 15:20:20 -0400 Subject: [PATCH] Continuing: Use the Swift-certified idiom to take the address of objects, rather than the unsafe way, similar in spirit to 4394cf45fb8d456068419cc1316efbf07882f862. The hubris count went from 14,340 to 3,748 --- Generator/Generator/MethodGen.swift | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Generator/Generator/MethodGen.swift b/Generator/Generator/MethodGen.swift index 5151a8b76..08c0cdf95 100644 --- a/Generator/Generator/MethodGen.swift +++ b/Generator/Generator/MethodGen.swift @@ -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