 public typealias ArgumentExtractor = (Int, UnsafeMutableRawPointer?) -> Void
 public typealias ReturnValueSetter = (UnsafeMutableRawPointer?) -> Void
 
+fileprivate func arg<T>(_ extractor: ArgumentExtractor, _ pos: Int) -> T {
+  let arg = UnsafeMutablePointer<T>.allocate(capacity: 1)
+  extractor(pos, arg)
+  return arg.pointee
+}
+
 public class ProtocolProxy: RKProtocolProxyBase {
 
   private var invokers: [Selector: (ArgumentExtractor, ReturnValueSetter?) -> Void] = [:]


  private func registerInvoker<T, U, V, W, R>(for selector: Selector, block: @escaping (T, U, V, W) -> R) {
    invokers[selector] = { extractor, setReturnValue in
      let a1 = UnsafeMutablePointer<T>.allocate(capacity: 1)
      extractor(2, a1)
      let a2 = UnsafeMutablePointer<U>.allocate(capacity: 1)
      extractor(3, a2)
      let a3 = UnsafeMutablePointer<V>.allocate(capacity: 1)
      extractor(4, a3)
      let a4 = UnsafeMutablePointer<W>.allocate(capacity: 1)
      extractor(5, a4)
      var r = block(a1.pointee as T, a2.pointee as U, a3.pointee as V, a4.pointee as W)
      if let setReturnValue = setReturnValue { setReturnValue(&r) }
    }
    registerDelegate()


  private func registerInvoker<T, R>(for selector: Selector, block: @escaping (T) -> R) {
    invokers[selector] = { extractor, setReturnValue in
      var r = block(arg(extractor, 2))
      if let setReturnValue = setReturnValue { setReturnValue(&r) }
    }
    registerDelegate()
