                 }
                 Code.block {
                     "typealias SwiftHandler = \(signalClosureHolderDecl(record: record, signal: signal))"
-                    "let swiftHandlerBoxed = Unmanaged.passRetained(SwiftHandler(handler)).toOpaque()"
                     Code.line {
                         "let cCallback: "
                         cCallbackDecl(record: record, signal: signal)
                         " = { "
+                        cCallbackArgumentsDecl(record: record, signal: signal)
+                        " in"
                     }
                     Code.block {
-                        "let holder = Unmanaged<SwiftHandler>.fromOpaque($\(signal.args.count + 1)).takeUnretainedValue()"
+                        "let holder = Unmanaged<SwiftHandler>.fromOpaque(userData).takeUnretainedValue()"
                         "let output = holder.\(generaceCCallbackCall(record: record, signal: signal))"
                         generateReturnStatement(record: record, signal: signal)
                     }
                     "}"
-                    "let __gCallback__ = unsafeBitCast(cCallback, to: GCallback.self)"
-                    Code.line {
-                        "let rv = "
-                        if record is GIR.Interface {
-                            "GLibObject.ObjectRef(raw: ptr)."
-                        }
-                        "signalConnectData("
-                    }
+                    "return \(record is GIR.Interface ? "GLibObject.ObjectRef(raw: ptr)." : "" )signalConnectData("
                     Code.block {
                         #"detailedSignal: "\#(signal.name)", "#
-                        "cHandler: __gCallback__, "
-                        "data: swiftHandlerBoxed, "
-                        "destroyData: {"
-                        Code.block {
-                            "if let swift = $0 {"
-                            Code.block {
-                                "let holder = Unmanaged<SwiftHandler>.fromOpaque(swift)"
-                                "holder.release()"
-                            }
-                            "}"
-                            "let _ = $1"
-                        }
-                        "}, "
+                        "cHandler: unsafeBitCast(cCallback, to: GCallback.self), "
+                        "data: Unmanaged.passRetained(SwiftHandler(handler)).toOpaque(), "
+                        "destroyData: { userData, _ in UnsafeRawPointer(userData).flatMap(Unmanaged<SwiftHandler>.fromOpaque(_:))?.release() },"
                         "connectFlags: flags"
                     }
                     ")"
-                    "return rv"
                 }
                 "}"
                 "\n"

        case is GIR.Enumeration:
            return self.argumentTypeName
        default: // Treat as fundamental (if not a fundamental, report error)
            return self.argumentTypeName
        }
    }
    

import Foundation

func signalSanityCheck(_ signal: GIR.Signal) -> String? {

    if !signal.args.allSatisfy({ $0.ownershipTransfer == .none }) {
        return "// Warning: signal \(signal.name) is ignored because of argument with owner transfership is not allowed"
    }
    
    if !signal.args.allSatisfy({ $0.direction == .in }) {
        return "// Warning: signal \(signal.name) is ignored because of argument out or inout direction is not allowed"
    }

    if !signal.args.allSatisfy({ $0.typeRef.type.name != "Void" }) {
        return "// Warning: signal \(signal.name) is ignored because of Void argument is not yet supported"
    }
