class PyCall::LibPython::PyTypeObjectStruct

Public Class Methods

new(*args) { |t| ... } click to toggle source
Calls superclass method
# 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

Public Instance Methods

tp_name=(str) click to toggle source
# 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