Class: WrapperFunction

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
MemberNames
Defined in:
ext/generate_gvl_code.rb

Overview

the zkrb_gvl_zoo_* function

Constant Summary collapse

PREFIX =
'zkrb_gvl'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MemberNames

#member_names

Constructor Details

#initialize(zoo_fn_name, struct) ⇒ WrapperFunction

Returns a new instance of WrapperFunction


104
105
106
107
108
# File 'ext/generate_gvl_code.rb', line 104

def initialize(zoo_fn_name, struct)
  @zoo_fn_name = zoo_fn_name
  @struct = struct
  @name = "#{PREFIX}_#{zoo_fn_name}"
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


102
103
104
# File 'ext/generate_gvl_code.rb', line 102

def name
  @name
end

#structObject (readonly)

Returns the value of attribute struct


102
103
104
# File 'ext/generate_gvl_code.rb', line 102

def struct
  @struct
end

#zoo_fn_nameObject (readonly)

Returns the value of attribute zoo_fn_name


102
103
104
# File 'ext/generate_gvl_code.rb', line 102

def zoo_fn_name
  @zoo_fn_name
end

Instance Method Details

#bodyObject


114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'ext/generate_gvl_code.rb', line 114

def body
  @body ||= (
    lines = ["#{fn_signature} {"]
    lines << "  #{struct.name} *a = (#{struct.name} *)data;"

    funcall = "  a->rc = #{zoo_fn_name}("
    funcall << member_names.map { |m| "a->#{m}" }.join(', ')
    funcall << ');'

    lines << funcall

    lines << "  return Qnil;"
    lines << "}"
    lines.join("\n")
  )
end

#fn_signatureObject


110
111
112
# File 'ext/generate_gvl_code.rb', line 110

def fn_signature
  @fn_signature ||= "static VALUE #{name}(void *data)"
end