static mrb_value mrb_skkdic_dict_data(mrb_state *mrb, mrb_value self) { mrb_value path, block, argv[4], table; char line[2048], *cstr, *p; int okuri_pos = 0; FILE *f; int i = 0; mrb_get_args(mrb, "&S", &block, &path); f = fopen(RSTRING_PTR(path), "r"); if (f == NULL) { puts("file open error\n"); } else { while(fgets(line, sizeof(line), f) != NULL) { int ai = mrb_gc_arena_save(mrb); if (strcmp(line, ";; okuri-ari entries.\n") == 0) { okuri_pos++; continue; } if (strcmp(line, ";; okuri-nasi entries.\n") == 0) { okuri_pos++; continue; } if (line[0] == ';') { continue; } cstr = strtok(line, " "); argv[1] = mrb_str_new_cstr(mrb, cstr); cstr = strtok(NULL, " "); p = strtok(cstr, "/"); table = mrb_ary_new(mrb); while (p != NULL) { int ai2 = mrb_gc_arena_save(mrb); mrb_ary_push(mrb, table, mrb_str_new_cstr(mrb, p)); p = strtok(NULL, "/"); mrb_gc_arena_restore(mrb, ai2); } mrb_ary_pop(mrb, table); argv[2] = table; if (okuri_pos == 1) { // okuri_ari argv[0] = mrb_fixnum_value(0); mrb_yield_argv(mrb, block, 3, argv); } else if(okuri_pos == 2) { // okuri_nasi argv[0] = mrb_fixnum_value(1); mrb_yield_argv(mrb, block, 3, argv); } mrb_gc_arena_restore(mrb, ai); } } return self; }
static void load_mrb_file(mrb_state *mrb, mrb_value filepath) { char *fpath = RSTRING_PTR(filepath); int arena_idx; FILE *fp; mrb_irep *irep; { FILE *fp = fopen(fpath, "rb"); if (fp == NULL) { mrb_load_fail( mrb, mrb_str_new_cstr(mrb, fpath), "cannot load such file" ); return; } fclose(fp); } arena_idx = mrb_gc_arena_save(mrb); fp = fopen(fpath, "rb"); irep = mrb_read_irep_file(mrb, fp); fclose(fp); mrb_gc_arena_restore(mrb, arena_idx); if (irep) { struct RProc *proc; /* size_t i; for (i = sirep; i < mrb->irep_len; i++) { mrb->irep[i]->filename = mrb_string_value_ptr(mrb, filepath); } */ replace_stop_with_return(mrb, irep); proc = mrb_proc_new(mrb, irep); proc->target_class = mrb->object_class; arena_idx = mrb_gc_arena_save(mrb); mrb_yield_with_class(mrb, mrb_obj_value(proc), 0, NULL, mrb_top_self(mrb), mrb->object_class); mrb_gc_arena_restore(mrb, arena_idx); } else if (mrb->exc) { // fail to load longjmp(*(jmp_buf*)mrb->jmp, 1); } }
static void load_mrb_file(mrb_state *mrb, mrb_value filepath) { char *fpath = RSTRING_PTR(filepath); int ai; FILE *fp; mrb_irep *irep; fp = fopen(fpath, "rb"); if (fp == NULL) { mrb_load_fail( mrb, mrb_str_new_cstr(mrb, fpath), "cannot load such file" ); return; } ai = mrb_gc_arena_save(mrb); irep = mrb_read_irep_file(mrb, fp); fclose(fp); mrb_gc_arena_restore(mrb, ai); if (irep) { struct RProc *proc; /* size_t i; for (i = sirep; i < mrb->irep_len; i++) { mrb->irep[i]->filename = mrb_string_value_ptr(mrb, filepath); } */ #ifdef USE_MRUBY_OLD_BYTE_CODE replace_stop_with_return(mrb, irep); #endif proc = mrb_proc_new(mrb, irep); MRB_PROC_SET_TARGET_CLASS(proc, mrb->object_class); ai = mrb_gc_arena_save(mrb); mrb_yield_with_class(mrb, mrb_obj_value(proc), 0, NULL, mrb_top_self(mrb), mrb->object_class); mrb_gc_arena_restore(mrb, ai); } else if (mrb->exc) { // fail to load longjmp(*(jmp_buf*)mrb->jmp, 1); } }
static void on_dispose(void *_ctx) { struct st_h2o_mruby_http_request_context_t *ctx = _ctx; /* clear the refs */ if (ctx->client != NULL) { h2o_http1client_cancel(ctx->client); ctx->client = NULL; } if (!mrb_nil_p(ctx->refs.request)) DATA_PTR(ctx->refs.request) = NULL; if (!mrb_nil_p(ctx->refs.input_stream)) DATA_PTR(ctx->refs.input_stream) = NULL; /* clear bufs */ h2o_buffer_dispose(&ctx->req.buf); h2o_buffer_dispose(&ctx->resp.after_closed); /* notify the app, if it is waiting to hear from us */ if (!mrb_nil_p(ctx->receiver)) { mrb_state *mrb = ctx->generator->ctx->mrb; int gc_arena = mrb_gc_arena_save(mrb); h2o_mruby_run_fiber(ctx->generator, detach_receiver(ctx), create_downstream_closed_exception(mrb), gc_arena, NULL); } }
static int on_body(h2o_http1client_t *client, const char *errstr) { struct st_h2o_mruby_http_request_context_t *ctx = client->data; if (errstr != NULL) { h2o_buffer_t *tmp = ctx->resp.after_closed; ctx->resp.after_closed = client->sock->input; client->sock->input = tmp; ctx->client = NULL; ctx->resp.has_content = 1; } else if (client->sock->input->size != 0) { ctx->resp.has_content = 1; } if (ctx->resp.has_content) { if (ctx->shortcut_notify_cb != NULL) { ctx->shortcut_notify_cb(ctx->generator); } else if (!mrb_nil_p(ctx->receiver)) { int gc_arena = mrb_gc_arena_save(ctx->generator->ctx->mrb); mrb_value chunk = build_chunk(ctx); h2o_mruby_run_fiber(ctx->generator, detach_receiver(ctx), chunk, gc_arena, NULL); } } return 0; }
static grn_rc grn_plugin_call_register_mrb(grn_ctx *ctx, grn_id id, grn_plugin *plugin) { grn_mrb_data *data = &(ctx->impl->mrb); mrb_state *mrb = data->state; struct RClass *module = data->module; struct RClass *plugin_loader_class; int arena_index; { int added; grn_hash_add(ctx, ctx->impl->mrb.registered_plugins, &id, sizeof(grn_id), NULL, &added); if (!added) { return ctx->rc; } } arena_index = mrb_gc_arena_save(mrb); plugin_loader_class = mrb_class_get_under(mrb, module, "PluginLoader"); mrb_funcall(mrb, mrb_obj_value(plugin_loader_class), "load_file", 1, mrb_str_new_cstr(mrb, ctx->impl->plugin_path)); mrb_gc_arena_restore(mrb, arena_index); return ctx->rc; }
void cfunc_closure_call_binding(ffi_cif *cif, void *ret, void **args, void *self_) { mrb_value self = mrb_obj_value(self_); struct cfunc_closure_data *data = DATA_PTR(self); int ai = mrb_gc_arena_save(data->mrb); mrb_value *ary = mrb_malloc(data->mrb, sizeof(mrb_value) * data->argc); int i; for (i = 0; i < data->argc; ++i) { // TODO: I felt too much consume memory void *p = mrb_malloc(data->mrb, data->arg_ffi_types[i]->size); memcpy(p, args[i], data->arg_ffi_types[i]->size); mrb_value pointer = cfunc_pointer_new_with_pointer(data->mrb, p, true); ary[i] = mrb_funcall(data->mrb, data->arg_types[i], "refer", 1, pointer); } mrb_value block = mrb_iv_get(data->mrb, self, mrb_intern_cstr(data->mrb, "@block")); mrb_value result = mrb_funcall_argv(data->mrb, block, mrb_intern_cstr(data->mrb, "call"), data->argc, ary); mrb_free(data->mrb, ary); mrb_value ret_pointer = cfunc_pointer_new_with_pointer(data->mrb, ret, false); mrb_funcall(data->mrb, data->return_type, "set", 2, ret_pointer, result); mrb_gc_arena_restore(data->mrb, ai); }
static ngx_int_t ngx_mrb_init_file(char *code_file_path, size_t len, ngx_mrb_state_t *state) { FILE *mrb_file; mrb_state *mrb; struct mrb_parser_state *p; if ((mrb_file = fopen((char *)code_file_path, "r")) == NULL) { return NGX_ERROR; } mrb = mrb_open(); ngx_mrb_class_init(mrb); state->ai = mrb_gc_arena_save(mrb); p = mrb_parse_file(mrb, mrb_file, NULL); state->mrb = mrb; state->n = mrb_generate_code(mrb, p); ngx_cpystrn((u_char *)state->code.file, (u_char *)code_file_path, len + 1); state->code_type = NGX_MRB_CODE_TYPE_FILE; mrb_pool_close(p->pool); fclose(mrb_file); return NGX_OK; }
static void get_backtrace_i(mrb_state *mrb, struct backtrace_location *loc, void *data) { mrb_value ary, str; char buf[32]; int ai = mrb_gc_arena_save(mrb); ary = mrb_obj_value((struct RArray*)data); str = mrb_str_new_cstr(mrb, loc->filename); snprintf(buf, sizeof(buf), ":%d", loc->lineno); mrb_str_cat_cstr(mrb, str, buf); if (loc->method) { mrb_str_cat_lit(mrb, str, ":in "); if (loc->class_name) { mrb_str_cat_cstr(mrb, str, loc->class_name); mrb_str_cat(mrb, str, &loc->sep, 1); } mrb_str_cat_cstr(mrb, str, loc->method); } mrb_ary_push(mrb, ary, str); mrb_gc_arena_restore(mrb, ai); }
static void print_backtrace_saved(mrb_state *mrb) { int i, ai; FILE *stream = stderr; fprintf(stream, "trace:\n"); ai = mrb_gc_arena_save(mrb); for (i = 0; i < mrb->backtrace.n; i++) { mrb_backtrace_entry *entry; entry = &(mrb->backtrace.entries[i]); fprintf(stream, "\t[%d] %s:%d", i, entry->filename, entry->lineno); if (entry->method_id != 0) { const char *method_name; method_name = mrb_sym2name(mrb, entry->method_id); if (entry->klass) { fprintf(stream, ":in %s%c%s", mrb_class_name(mrb, entry->klass), entry->sep, method_name); } else { fprintf(stream, ":in %s", method_name); } mrb_gc_arena_restore(mrb, ai); } fprintf(stream, "\n"); } }
mrb_value mrb_mraa_i2c_read(mrb_state *mrb, mrb_value self){ mraa_i2c_context i2c; mrb_int length; uint8_t *rbuf; mrb_int num_of_read; int ai, i; mrb_value mrv_rbuf; Data_Get_Struct(mrb, self, &mrb_mraa_i2c_ctx_type, i2c); mrb_get_args(mrb, "i", &length); rbuf = (uint8_t*)mrb_malloc(mrb, sizeof(uint8_t) * length); memset(rbuf, 0, sizeof(uint8_t) * length); num_of_read = mraa_i2c_read(i2c, rbuf, length); mrv_rbuf = mrb_ary_new_capa(mrb, num_of_read); ai = mrb_gc_arena_save(mrb); for (i = 0; i < num_of_read; i++){ mrb_ary_push(mrb, mrv_rbuf, mrb_fixnum_value(rbuf[i])); mrb_gc_arena_restore(mrb, ai); } mrb_free(mrb, rbuf); return mrb_assoc_new(mrb, mrv_rbuf, mrb_fixnum_value(num_of_read)); }
void setup_api(mrb_state *mrb) { // class = mrb_define_class(mrb, "D3Probe", mrb->object_class); // struct RClass *class = mrb_class_get(mrb, "D3Probe"); struct RClass *kernel = mrb->kernel_module; int ai = mrb_gc_arena_save(mrb); // Kernel mrb_define_method(mrb, kernel, "sleep", plugin_sleep, MRB_ARGS_REQ(1)); mrb_define_method(mrb, kernel, "ms_sleep", plugin_ms_sleep, MRB_ARGS_REQ(1)); mrb_define_method(mrb, kernel, "time", plugin_gettime, MRB_ARGS_REQ(0)); mrb_define_method(mrb, kernel, "getpid", plugin_getpid, MRB_ARGS_REQ(0)); mrb_define_method(mrb, kernel, "cycle_interval", _plugin_cycle_interval, MRB_ARGS_REQ(0)); // D3Probe // mrb_define_singleton_method(mrb, class, "report", plugin_report, ARGS_REQ(1)); // mrb_define_singleton_method(mrb, class, "register_plugin", register_plugin, ARGS_REQ(2)); setup_plugin_api(mrb); setup_sigar_api(mrb); setup_snmp_api(mrb); setup_pf_api(mrb); mrb_gc_arena_restore(mrb, ai); }
static mrb_value mrb_file_s_readlink(mrb_state *mrb, mrb_value klass) { #if defined(_WIN32) || defined(_WIN64) mrb_raise(mrb, E_NOTIMP_ERROR, "readlink is not supported on this platform"); return mrb_nil_value(); // unreachable #else char *path, *buf, *tmp; size_t bufsize = 100; ssize_t rc; mrb_value ret; int ai = mrb_gc_arena_save(mrb); mrb_get_args(mrb, "z", &path); tmp = mrb_locale_from_utf8(path, -1); buf = (char *)mrb_malloc(mrb, bufsize); while ((rc = readlink(tmp, buf, bufsize)) == (ssize_t)bufsize && rc != -1) { bufsize *= 2; buf = (char *)mrb_realloc(mrb, buf, bufsize); } mrb_locale_free(tmp); if (rc == -1) { mrb_free(mrb, buf); mrb_sys_fail(mrb, path); } tmp = mrb_utf8_from_locale(buf, -1); ret = mrb_str_new(mrb, tmp, rc); mrb_locale_free(tmp); mrb_free(mrb, buf); mrb_gc_arena_restore(mrb, ai); return ret; #endif }
static mrb_value bs_protocols_per_handle(mrb_state *mrb, mrb_value self) { mrb_value handle; mrb_value ret; EFI_HANDLE raw_handle; EFI_GUID **ppguids; UINTN size; EFI_STATUS status; mrb_get_args(mrb, "o", &handle); raw_handle = mrb_uefi_handle_raw_value(mrb, handle); status = gBS->ProtocolsPerHandle(raw_handle, &ppguids, &size); if (EFI_ERROR(status)){ return mrb_nil_value(); } ret = mrb_ary_new_capa(mrb, (int)size); { UINTN i; for (i=0; i<size; i++){ int arena = mrb_gc_arena_save(mrb); mrb_ary_push(mrb, ret, mrb_uefi_guid_set_guid(mrb, ppguids[i])); mrb_gc_arena_restore(mrb, arena); } } gBS->FreePool(ppguids); return ret; }
static mrb_value inspect_hash(mrb_state *mrb, mrb_value hash, int recur) { mrb_value str, str2; khash_t(ht) *h = RHASH_TBL(hash); khiter_t k; if (recur) return mrb_str_new_lit(mrb, "{...}"); str = mrb_str_new_lit(mrb, "{"); if (h && kh_size(h) > 0) { for (k = kh_begin(h); k != kh_end(h); k++) { int ai; if (!kh_exist(h,k)) continue; ai = mrb_gc_arena_save(mrb); if (RSTRING_LEN(str) > 1) mrb_str_cat_lit(mrb, str, ", "); str2 = mrb_inspect(mrb, kh_key(h,k)); mrb_str_append(mrb, str, str2); mrb_str_cat_lit(mrb, str, "=>"); str2 = mrb_inspect(mrb, kh_value(h,k)); mrb_str_append(mrb, str, str2); mrb_gc_arena_restore(mrb, ai); } } mrb_str_cat_lit(mrb, str, "}"); return str; }
void mrb_exc_set(mrb_state *mrb, mrb_value exc) { if (!mrb->gc.out_of_memory && mrb->backtrace.n > 0) { mrb_value target_exc = mrb_nil_value(); int ai; ai = mrb_gc_arena_save(mrb); if ((mrb->exc && !have_backtrace(mrb, mrb->exc))) { target_exc = mrb_obj_value(mrb->exc); } else if (!mrb_nil_p(exc) && mrb->backtrace.exc) { target_exc = mrb_obj_value(mrb->backtrace.exc); mrb_gc_protect(mrb, target_exc); } if (!mrb_nil_p(target_exc)) { mrb_value backtrace; backtrace = mrb_restore_backtrace(mrb); set_backtrace(mrb, target_exc, backtrace); } mrb_gc_arena_restore(mrb, ai); } mrb->backtrace.n = 0; if (mrb_nil_p(exc)) { mrb->exc = 0; } else { if (!mrb_obj_is_kind_of(mrb, exc, mrb->eException_class)) mrb_raise(mrb, E_TYPE_ERROR, "exception object expected"); mrb->exc = mrb_obj_ptr(exc); } }
void EXPORT mrb_mruby_require_example_gem_init(mrb_state* mrb) { int ai = mrb_gc_arena_save(mrb); _class_example = mrb_define_module(mrb, "Example"); mrb_define_class_method(mrb, _class_example, "helloworld", mrb_example_helloworld, ARGS_NONE()); mrb_gc_arena_restore(mrb, ai); }
unsigned int grn_mrb_expr_estimate_size(grn_ctx *ctx, grn_obj *expr, grn_obj *table) { grn_mrb_data *data = &(ctx->impl->mrb); mrb_state *mrb = data->state; mrb_value mrb_expression; mrb_value mrb_table; mrb_value mrb_size; unsigned int size; int arena_index; arena_index = mrb_gc_arena_save(mrb); mrb_expression = grn_mrb_value_from_grn_obj(mrb, expr); mrb_table = grn_mrb_value_from_grn_obj(mrb, table); mrb_size = mrb_funcall(mrb, mrb_expression, "estimate_size", 1, mrb_table); if (mrb->exc) { size = grn_table_size(ctx, table); } else { size = mrb_fixnum(mrb_size); } mrb_gc_arena_restore(mrb, arena_index); return size; }
static mrb_value mrb_hash_dup(mrb_state *mrb, mrb_value hash) { struct RHash* ret; khash_t(ht) *h, *ret_h; khiter_t k, ret_k; h = RHASH_TBL(hash); ret = (struct RHash*)mrb_obj_alloc(mrb, MRB_TT_HASH, mrb->hash_class); ret->ht = kh_init(ht, mrb); if (kh_size(h) > 0) { ret_h = ret->ht; for (k = kh_begin(h); k != kh_end(h); k++) { if (kh_exist(h,k)) { int ai = mrb_gc_arena_save(mrb); ret_k = kh_put(ht, mrb, ret_h, KEY(kh_key(h,k))); mrb_gc_arena_restore(mrb, ai); kh_val(ret_h, ret_k) = kh_val(h,k); } } } return mrb_obj_value(ret); }
static mrb_value mrb_hash_replace(mrb_state *mrb, mrb_value hash) { mrb_value hash2, ifnone; khash_t(ht) *h2; khiter_t k; mrb_get_args(mrb, "o", &hash2); hash2 = to_hash(mrb, hash2); if (mrb_obj_equal(mrb, hash, hash2)) return hash; mrb_hash_clear(mrb, hash); h2 = RHASH_TBL(hash2); if (h2) { int hi = mrb_gc_arena_save(mrb); for (k = kh_begin(h2); k != kh_end(h2); k++) { if (kh_exist(h2, k)) mrb_hash_set(mrb, hash, kh_key(h2, k), kh_value(h2, k)); mrb_gc_arena_restore(mrb, hi); } } if (MRB_RHASH_PROCDEFAULT_P(hash2)) { RHASH(hash)->flags |= MRB_HASH_PROC_DEFAULT; ifnone = RHASH_PROCDEFAULT(hash2); } else { ifnone = RHASH_IFNONE(hash2); } mrb_iv_set(mrb, hash, mrb_intern_lit(mrb, "ifnone"), ifnone); return hash; }
static void get_backtrace_i(mrb_state *mrb, void *stream, int level, const char *format, ...) { va_list ap; mrb_value ary, str; int ai; if (level > 0) { return; } ai = mrb_gc_arena_save(mrb); ary = mrb_obj_value((struct RArray*)stream); va_start(ap, format); str = mrb_str_new(mrb, 0, vsnprintf(NULL, 0, format, ap) + 1); va_end(ap); va_start(ap, format); vsnprintf(RSTRING_PTR(str), RSTRING_LEN(str), format, ap); va_end(ap); mrb_str_resize(mrb, str, RSTRING_LEN(str) - 1); mrb_ary_push(mrb, ary, str); mrb_gc_arena_restore(mrb, ai); }
grn_obj * grn_mrb_expr_rewrite(grn_ctx *ctx, grn_obj *expr) { grn_mrb_data *data = &(ctx->impl->mrb); mrb_state *mrb = data->state; mrb_value mrb_expression; mrb_value mrb_rewritten_expression; grn_obj *rewritten_expression = NULL; int arena_index; arena_index = mrb_gc_arena_save(mrb); mrb_expression = grn_mrb_value_from_grn_obj(mrb, expr); mrb_rewritten_expression = mrb_funcall(mrb, mrb_expression, "rewrite", 0); if (mrb_nil_p(mrb_rewritten_expression)) { goto exit; } if (mrb_type(mrb_rewritten_expression) == MRB_TT_EXCEPTION) { mrb->exc = mrb_obj_ptr(mrb_rewritten_expression); mrb_print_error(mrb); goto exit; } rewritten_expression = DATA_PTR(mrb_rewritten_expression); exit: mrb_gc_arena_restore(mrb, arena_index); return rewritten_expression; }
static mrb_value mrb_file_s_symlink(mrb_state *mrb, mrb_value klass) { #if defined(_WIN32) || defined(_WIN64) mrb_raise(mrb, E_NOTIMP_ERROR, "symlink is not supported on this platform"); #else mrb_value from, to; const char *src, *dst; int ai = mrb_gc_arena_save(mrb); mrb_get_args(mrb, "SS", &from, &to); src = mrb_locale_from_utf8(mrb_str_to_cstr(mrb, from), -1); dst = mrb_locale_from_utf8(mrb_str_to_cstr(mrb, to), -1); if (symlink(src, dst) == -1) { mrb_locale_free(src); mrb_locale_free(dst); mrb_sys_fail(mrb, mrb_str_to_cstr(mrb, mrb_format(mrb, "(%S, %S)", from, to))); } mrb_locale_free(src); mrb_locale_free(dst); mrb_gc_arena_restore(mrb, ai); #endif return mrb_fixnum_value(0); }
MRB_API void mrb_hash_set(mrb_state *mrb, mrb_value hash, mrb_value key, mrb_value val) { khash_t(ht) *h; khiter_t k; int r; mrb_hash_modify(mrb, hash); h = RHASH_TBL(hash); if (!h) h = RHASH_TBL(hash) = kh_init(ht, mrb); k = kh_put2(ht, mrb, h, key, &r); kh_value(h, k).v = val; if (r != 0) { /* expand */ int ai = mrb_gc_arena_save(mrb); key = kh_key(h, k) = KEY(key); mrb_gc_arena_restore(mrb, ai); kh_value(h, k).n = kh_size(h)-1; } mrb_field_write_barrier_value(mrb, (struct RBasic*)RHASH(hash), key); mrb_field_write_barrier_value(mrb, (struct RBasic*)RHASH(hash), val); return; }
static void get_backtrace_i(mrb_state *mrb, struct backtrace_location *loc, void *data) { mrb_value ary, str; int ai; ai = mrb_gc_arena_save(mrb); ary = mrb_obj_value((struct RArray*)data); str = mrb_str_new_cstr(mrb, loc->filename); mrb_str_cat_lit(mrb, str, ":"); mrb_str_concat(mrb, str, mrb_fixnum_to_str(mrb, mrb_fixnum_value(loc->lineno), 10)); if (loc->method) { mrb_str_cat_lit(mrb, str, ":in "); if (loc->class_name) { mrb_str_cat_cstr(mrb, str, loc->class_name); mrb_str_cat_cstr(mrb, str, loc->sep); } mrb_str_cat_cstr(mrb, str, loc->method); } mrb_ary_push(mrb, ary, str); mrb_gc_arena_restore(mrb, ai); }
static ssize_t mrb_wslay_event_recv_callback(wslay_event_context_ptr ctx, uint8_t *buf, size_t len, int flags, void *user_data) { mrb_wslay_user_data *data = (mrb_wslay_user_data *) user_data; mrb_state*mrb = data->mrb; int ai = mrb_gc_arena_save(mrb); struct mrb_jmpbuf *prev_jmp = mrb->jmp; struct mrb_jmpbuf c_jmp; mrb_int ret = -1; MRB_TRY(&c_jmp) { mrb->jmp = &c_jmp; mrb_value argv[2]; argv[0] = mrb_cptr_value(mrb, buf); argv[1] = mrb_fixnum_value(len); errno = 0; mrb_assert(mrb_type(data->recv_callback) == MRB_TT_PROC); mrb_value buf_obj = mrb_yield_argv(mrb, data->recv_callback, NELEMS(argv), argv); if (mrb_fixnum_p(buf_obj)) { ret = mrb_fixnum(buf_obj); } else { buf_obj = mrb_str_to_str(mrb, buf_obj); ret = RSTRING_LEN(buf_obj); if (ret < 0||ret > len) { mrb_raise(mrb, E_RANGE_ERROR, "returned buf doesn't fit"); } if (ret > 0) { memmove(buf, (uint8_t *) RSTRING_PTR(buf_obj), ret); } } mrb->jmp = prev_jmp; } MRB_CATCH(&c_jmp) { mrb->jmp = prev_jmp; if (mrb_obj_is_kind_of(mrb, mrb_obj_value(mrb->exc), mrb_class_get_under(mrb, mrb_module_get(mrb, "Errno"), "EAGAIN"))|| mrb_obj_is_kind_of(mrb, mrb_obj_value(mrb->exc), mrb_class_get_under(mrb, mrb_module_get(mrb, "Errno"), "EWOULDBLOCK"))) { mrb->exc = NULL; wslay_event_set_error(ctx, WSLAY_ERR_WOULDBLOCK); } else { wslay_event_set_error(ctx, WSLAY_ERR_CALLBACK_FAILURE); } } MRB_END_EXC(&c_jmp); mrb_gc_arena_restore(mrb, ai); return ret; }
//---------------------------------------------------------- void ScriptEngine::funcallIf(const char* aName, mrb_value aArg1, mrb_value aArg2, mrb_value aArg3) { if (mMrb && isExistFunction(kernel_obj(), aName)) { int ai = mrb_gc_arena_save(mMrb); mrb_funcall(mMrb, kernel_obj(), aName, 3, aArg1, aArg2, aArg3); mrb_gc_arena_restore(mMrb, ai); closeOnException(); } }
void GENERATED_TMP_mrb_mruby_enum_ext_gem_init(mrb_state *mrb) { int ai = mrb_gc_arena_save(mrb); mrb_load_irep(mrb, gem_mrblib_irep_mruby_enum_ext); if (mrb->exc) { mrb_p(mrb, mrb_obj_value(mrb->exc)); exit(EXIT_FAILURE); } mrb_gc_arena_restore(mrb, ai); }
//---------------------------------------------------------- void ScriptEngine::funcallIf(mrb_value aModule, const char* aName) { if (mMrb && isExistFunction(aModule, aName)) { int ai = mrb_gc_arena_save(mMrb); mrb_funcall(mMrb, aModule, aName, 0); mrb_gc_arena_restore(mMrb, ai); closeOnException(); } }
void GENERATED_TMP_mrb_mruby_numeric_ext_gem_init(mrb_state *mrb) { int ai = mrb_gc_arena_save(mrb); mrb_mruby_numeric_ext_gem_init(mrb); mrb_load_irep(mrb, gem_mrblib_irep_mruby_numeric_ext); if (mrb->exc) { mrb_print_error(mrb); exit(EXIT_FAILURE); } mrb_gc_arena_restore(mrb, ai); }