Avatar
なるほど
2:41 AM
ARC 化してる・・・ public init(borrowed: UnsafeMutablePointer<PyObject>) { state = borrowed Py_IncRef(state) } public init?(borrowedNullable: UnsafeMutablePointer<PyObject>?) { if let borrowed = borrowedNullable { state = borrowed Py_IncRef(state) } else { return nil } } public convenience init(python: PyVal) { self.init(owned: python.ownedPyObject) } deinit { Py_DecRef(state) }
2:41 AM
owned と borrowed と区別してるのか
2:42 AM
もうちょっと上があった。 public final class PyRef : PyVal { private var state : OwnedPyObject public init(owned: OwnedPyObject) { state = owned } public init?(ownedNullable: OwnedPyObject?) { if let owned = ownedNullable { state = owned } else { return nil } } public init(borrowed: UnsafeMutablePointer<PyObject>) { state = borrowed Py_IncRef(state) } public init?(borrowedNullable: UnsafeMutablePointer<PyObject>?) { if let borrowed = borrowedNullable { state = borrowed Py_IncRef(state) } else { return nil } } public convenience init(python: PyVal) { self.init(owned: python.ownedPyObject) } deinit { Py_DecRef(state) } public var borrowedPyObject : UnsafeMutablePointer<PyObject> { return state } public var ownedPyObject : OwnedPyObject { Py_IncRef(state) return state } }