Class: PyCall::LibPython::PyTypeObjectStruct
- Inherits:
-
PyObjectStruct
- Object
- FFI::Struct
- PyObjectStruct
- PyCall::LibPython::PyTypeObjectStruct
- Defined in:
- lib/pycall/libpython/pyobject_struct.rb,
lib/pycall/libpython/pytypeobject_struct.rb
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from PyObjectStruct
Class Method Details
.new(*args) ⇒ Object
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/pycall/libpython/pytypeobject_struct.rb', line 227 def self.new(*args) case args.length when 0, 1 super else name, basic_size = *args new.tap do |t| # NOTE: Disable autorelease for avoiding SEGV occurrance in Python's GC collect function # at which the __new__ method object of this type object is freed. t.pointer.autorelease = false # PyVarObject_HEAD_INIT(&PyType_Type, 0) t[:ob_refcnt] = 1 t[:ob_type] = LibPython.PyType_Type t[:ob_size] = 0 t[:tp_basicsize] = basic_size stackless_extension_flag = PyCall.has_stackless_extension ? Py_TPFLAGS_HAVE_STACKLESS_EXTENSION_ : 0 t[:tp_flags] = if PYTHON_VERSION >= '3' stackless_extension_flag | Py_TPFLAGS_HAVE_VERSION_TAG else Py_TPFLAGS_HAVE_GETCHARBUFFER | Py_TPFLAGS_HAVE_SEQUENCE_IN | Py_TPFLAGS_HAVE_INPLACEOPS | Py_TPFLAGS_HAVE_RICHCOMPARE | Py_TPFLAGS_HAVE_WEAKREFS | Py_TPFLAGS_HAVE_ITER | Py_TPFLAGS_HAVE_CLASS | stackless_extension_flag | Py_TPFLAGS_HAVE_INDEX end t.tp_name = name yield t if block_given? t[:tp_new] = LibPython.find_symbol(:PyType_GenericNew) if t[:tp_new] == FFI::Pointer::NULL raise PyError.fetch if LibPython.PyType_Ready(t) < 0 LibPython.Py_IncRef(t) end end end |
Instance Method Details
#tp_name=(str) ⇒ Object
267 268 269 270 |
# File 'lib/pycall/libpython/pytypeobject_struct.rb', line 267 def tp_name=(str) @saved_name = FFI::MemoryPointer.from_string(str) self.pointer.put_pointer(offset_of(:tp_name), @saved_name) end |