/*
 * This file contains a list of all
 * initializing methods which are
 * necessary to bootstrap all gems.
 *
 * This file was generated by mruby/tasks/mrbgems.rake.
 *
 * IMPORTANT:
 *   This file was generated!
 *   All manual changes will get lost.
 */

#include <mruby.h>
#include <mruby/error.h>
#include <mruby/proc.h>

void GENERATED_TMP_mrb_mruby_compar_ext_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_compar_ext_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_enum_ext_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_enum_ext_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_string_ext_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_string_ext_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_numeric_ext_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_numeric_ext_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_array_ext_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_array_ext_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_hash_ext_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_hash_ext_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_range_ext_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_range_ext_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_proc_ext_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_proc_ext_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_symbol_ext_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_symbol_ext_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_object_ext_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_object_ext_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_objectspace_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_objectspace_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_fiber_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_fiber_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_enumerator_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_enumerator_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_set_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_set_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_enum_lazy_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_enum_lazy_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_toplevel_ext_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_toplevel_ext_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_kernel_ext_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_kernel_ext_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_class_ext_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_class_ext_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_pack_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_pack_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_sprintf_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_sprintf_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_time_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_time_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_struct_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_struct_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_data_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_data_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_random_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_random_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_io_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_io_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_error_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_error_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_socket_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_socket_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_print_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_print_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_errno_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_errno_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_dir_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_dir_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_math_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_math_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_complex_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_complex_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_rational_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_rational_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_cmath_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_cmath_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_metaprog_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_metaprog_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_method_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_method_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_binding_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_binding_gem_final(mrb_state*);
void GENERATED_TMP_mrb_mruby_eval_gem_init(mrb_state*);
void GENERATED_TMP_mrb_mruby_eval_gem_final(mrb_state*);

static const struct {
  void (*init)(mrb_state*);
  void (*final)(mrb_state*);
} gem_funcs[] = {
  { GENERATED_TMP_mrb_mruby_compar_ext_gem_init, GENERATED_TMP_mrb_mruby_compar_ext_gem_final },
  { GENERATED_TMP_mrb_mruby_enum_ext_gem_init, GENERATED_TMP_mrb_mruby_enum_ext_gem_final },
  { GENERATED_TMP_mrb_mruby_string_ext_gem_init, GENERATED_TMP_mrb_mruby_string_ext_gem_final },
  { GENERATED_TMP_mrb_mruby_numeric_ext_gem_init, GENERATED_TMP_mrb_mruby_numeric_ext_gem_final },
  { GENERATED_TMP_mrb_mruby_array_ext_gem_init, GENERATED_TMP_mrb_mruby_array_ext_gem_final },
  { GENERATED_TMP_mrb_mruby_hash_ext_gem_init, GENERATED_TMP_mrb_mruby_hash_ext_gem_final },
  { GENERATED_TMP_mrb_mruby_range_ext_gem_init, GENERATED_TMP_mrb_mruby_range_ext_gem_final },
  { GENERATED_TMP_mrb_mruby_proc_ext_gem_init, GENERATED_TMP_mrb_mruby_proc_ext_gem_final },
  { GENERATED_TMP_mrb_mruby_symbol_ext_gem_init, GENERATED_TMP_mrb_mruby_symbol_ext_gem_final },
  { GENERATED_TMP_mrb_mruby_object_ext_gem_init, GENERATED_TMP_mrb_mruby_object_ext_gem_final },
  { GENERATED_TMP_mrb_mruby_objectspace_gem_init, GENERATED_TMP_mrb_mruby_objectspace_gem_final },
  { GENERATED_TMP_mrb_mruby_fiber_gem_init, GENERATED_TMP_mrb_mruby_fiber_gem_final },
  { GENERATED_TMP_mrb_mruby_enumerator_gem_init, GENERATED_TMP_mrb_mruby_enumerator_gem_final },
  { GENERATED_TMP_mrb_mruby_set_gem_init, GENERATED_TMP_mrb_mruby_set_gem_final },
  { GENERATED_TMP_mrb_mruby_enum_lazy_gem_init, GENERATED_TMP_mrb_mruby_enum_lazy_gem_final },
  { GENERATED_TMP_mrb_mruby_toplevel_ext_gem_init, GENERATED_TMP_mrb_mruby_toplevel_ext_gem_final },
  { GENERATED_TMP_mrb_mruby_kernel_ext_gem_init, GENERATED_TMP_mrb_mruby_kernel_ext_gem_final },
  { GENERATED_TMP_mrb_mruby_class_ext_gem_init, GENERATED_TMP_mrb_mruby_class_ext_gem_final },
  { GENERATED_TMP_mrb_mruby_pack_gem_init, GENERATED_TMP_mrb_mruby_pack_gem_final },
  { GENERATED_TMP_mrb_mruby_sprintf_gem_init, GENERATED_TMP_mrb_mruby_sprintf_gem_final },
  { GENERATED_TMP_mrb_mruby_time_gem_init, GENERATED_TMP_mrb_mruby_time_gem_final },
  { GENERATED_TMP_mrb_mruby_struct_gem_init, GENERATED_TMP_mrb_mruby_struct_gem_final },
  { GENERATED_TMP_mrb_mruby_data_gem_init, GENERATED_TMP_mrb_mruby_data_gem_final },
  { GENERATED_TMP_mrb_mruby_random_gem_init, GENERATED_TMP_mrb_mruby_random_gem_final },
  { GENERATED_TMP_mrb_mruby_io_gem_init, GENERATED_TMP_mrb_mruby_io_gem_final },
  { GENERATED_TMP_mrb_mruby_error_gem_init, GENERATED_TMP_mrb_mruby_error_gem_final },
  { GENERATED_TMP_mrb_mruby_socket_gem_init, GENERATED_TMP_mrb_mruby_socket_gem_final },
  { GENERATED_TMP_mrb_mruby_print_gem_init, GENERATED_TMP_mrb_mruby_print_gem_final },
  { GENERATED_TMP_mrb_mruby_errno_gem_init, GENERATED_TMP_mrb_mruby_errno_gem_final },
  { GENERATED_TMP_mrb_mruby_dir_gem_init, GENERATED_TMP_mrb_mruby_dir_gem_final },
  { GENERATED_TMP_mrb_mruby_math_gem_init, GENERATED_TMP_mrb_mruby_math_gem_final },
  { GENERATED_TMP_mrb_mruby_complex_gem_init, GENERATED_TMP_mrb_mruby_complex_gem_final },
  { GENERATED_TMP_mrb_mruby_rational_gem_init, GENERATED_TMP_mrb_mruby_rational_gem_final },
  { GENERATED_TMP_mrb_mruby_cmath_gem_init, GENERATED_TMP_mrb_mruby_cmath_gem_final },
  { GENERATED_TMP_mrb_mruby_metaprog_gem_init, GENERATED_TMP_mrb_mruby_metaprog_gem_final },
  { GENERATED_TMP_mrb_mruby_method_gem_init, GENERATED_TMP_mrb_mruby_method_gem_final },
  { GENERATED_TMP_mrb_mruby_binding_gem_init, GENERATED_TMP_mrb_mruby_binding_gem_final },
  { GENERATED_TMP_mrb_mruby_eval_gem_init, GENERATED_TMP_mrb_mruby_eval_gem_final },
};

#define NUM_GEMS ((int)(sizeof(gem_funcs) / sizeof(gem_funcs[0])))

struct final_mrbgems {
  int i;
  int ai;
};

static mrb_value
final_mrbgems_body(mrb_state *mrb, void *ud) {
  struct final_mrbgems *p = (struct final_mrbgems*)ud;
  for (; p->i >= 0; p->i--) {
    gem_funcs[p->i].final(mrb);
    mrb_gc_arena_restore(mrb, p->ai);
  }
  return mrb_nil_value();
}

static void
mrb_final_mrbgems(mrb_state *mrb) {
  struct final_mrbgems a = { NUM_GEMS - 1, mrb_gc_arena_save(mrb) };
  for (; a.i >= 0; a.i--) {
    mrb_protect_error(mrb, final_mrbgems_body, &a, NULL);
    mrb_gc_arena_restore(mrb, a.ai);
  }
}

void
mrb_init_mrbgems(mrb_state *mrb) {
  int ai = mrb_gc_arena_save(mrb);
  for (int i = 0; i < NUM_GEMS; i++) {
    gem_funcs[i].init(mrb);
    mrb_gc_arena_restore(mrb, ai);
    mrb_vm_ci_env_clear(mrb, mrb->c->cibase);
    if (mrb->exc) {
      mrb_exc_raise(mrb, mrb_obj_value(mrb->exc));
    }
  }
  mrb_state_atexit(mrb, mrb_final_mrbgems);
}
