'Collect exported methods and emit a PyMethodDef array.
:returns: a pointer to the PyMethodDef array.'

def _emit_method_array(self, llvm_module):

    method_defs = []
    for entry in self.export_entries:
        name = entry.symbol
        llvm_func_name = self._mangle_method_symbol(name)
        fnty = self.exported_function_types[entry]
        lfunc = llvm_module.add_function(fnty, name=llvm_func_name)
        method_name = self.context.insert_const_string(llvm_module, name)
        method_def_const = lc.Constant.struct((method_name, lc.Constant.bitcast(lfunc, lt._void_star), METH_VARARGS_AND_KEYWORDS, NULL))
        method_defs.append(method_def_const)
    sentinel = lc.Constant.struct([NULL, NULL, ZERO, NULL])
    method_defs.append(sentinel)
    method_array_init = lc.Constant.array(self.method_def_ty, method_defs)
    method_array = llvm_module.add_global_variable(method_array_init.type, '.module_methods')
    method_array.initializer = method_array_init
    method_array.linkage = lc.LINKAGE_INTERNAL
    method_array_ptr = lc.Constant.gep(method_array, [ZERO, ZERO])
    return method_array_ptr
