Module: RubyPython::Macros

Defined in:
lib/rubypython/macros.rb

Overview

Contains Python C API macros reimplemented in Ruby. For internal use only.

Class Method Summary collapse

Class Method Details

.Py_FalseObject



34
35
36
# File 'lib/rubypython/macros.rb', line 34

def self.Py_False
  RubyPython::Python.Py_ZeroStruct.to_ptr
end

.Py_NoneObject



38
39
40
# File 'lib/rubypython/macros.rb', line 38

def self.Py_None
  RubyPython::Python.Py_NoneStruct.to_ptr
end

.Py_REFCNT(pObjPointer) ⇒ Object

Returns the reference count for the provided pointer.



7
8
9
10
# File 'lib/rubypython/macros.rb', line 7

def self.Py_REFCNT(pObjPointer)
  pStruct = RubyPython::Python::PyObjectStruct.new pObjPointer
  pStruct[:ob_refcnt]
end

.Py_RETURN_FALSEObject



42
43
44
45
# File 'lib/rubypython/macros.rb', line 42

def self.Py_RETURN_FALSE
  RubyPython::Python.Py_IncRef(self.Py_False)
  self.Py_False
end

.Py_RETURN_NONEObject



52
53
54
55
# File 'lib/rubypython/macros.rb', line 52

def self.Py_RETURN_NONE
  RubyPython::Python.Py_IncRef(self.Py_None)
  self.Py_None
end

.Py_RETURN_TRUEObject



47
48
49
50
# File 'lib/rubypython/macros.rb', line 47

def self.Py_RETURN_TRUE
  RubyPython::Python.Py_IncRef(self.Py_True)
  self.Py_True
end

.Py_TrueObject



30
31
32
# File 'lib/rubypython/macros.rb', line 30

def self.Py_True
  RubyPython::Python.Py_TrueStruct.to_ptr
end

.Py_TYPE(pObjPointer) ⇒ Object

Returns the object type for the provided pointer.



13
14
15
16
# File 'lib/rubypython/macros.rb', line 13

def self.Py_TYPE(pObjPointer)
  pStruct = RubyPython::Python::PyObjectStruct.new pObjPointer
  pStruct[:ob_type]
end

.PyObject_TypeCheck(pObject, pTypePointer) ⇒ Object

This has been modified from the C API macro to allow for multiple pointer objects to be passed. It simplifies a number of checks.



20
21
22
23
24
25
26
27
28
# File 'lib/rubypython/macros.rb', line 20

def self.PyObject_TypeCheck(pObject, pTypePointer)
  type = self.Py_TYPE(pObject)

  [ pTypePointer ].flatten.each do |pointer|
    return 1 if type == pointer
  end

  return 0
end