void rb_check_type(VALUE x, int t) { int xt; if (x == Qundef) { rb_bug("undef leaked to the Ruby space"); } xt = TYPE(x); if (xt != t || (xt == T_DATA && RTYPEDDATA_P(x))) { const char *tname = rb_builtin_type_name(t); if (tname) { rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)", builtin_class_name(x), tname); } if (xt > T_MASK && xt <= 0x3f) { rb_fatal("unknown type 0x%x (0x%x given, probably comes from extension library for ruby 1.8)", t, xt); } rb_bug("unknown type 0x%x (0x%x given)", t, xt); } }
static void w32_error(void) { LPVOID lpMsgBuf; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) & lpMsgBuf, 0, NULL); rb_bug("%s", (char*)lpMsgBuf); }
static VALUE make_errno_exc_str(VALUE mesg) { int n = errno; errno = 0; if (!mesg) mesg = Qnil; if (n == 0) { const char *s = !NIL_P(mesg) ? RSTRING_PTR(mesg) : ""; rb_bug("rb_sys_fail_str(%s) - errno == 0", s); } return rb_syserr_new_str(n, mesg); }
void rb_check_type(VALUE x, int t) { const struct types *type = builtin_types; const struct types *const typeend = builtin_types + sizeof(builtin_types) / sizeof(builtin_types[0]); if (x == Qundef) { rb_bug("undef leaked to the Ruby space"); } if (TYPE(x) != t) { while (type < typeend) { if (type->type == t) { const char *etype; if (NIL_P(x)) { etype = "nil"; } else if (FIXNUM_P(x)) { etype = "Fixnum"; } else if (SYMBOL_P(x)) { etype = "Symbol"; } else if (rb_special_const_p(x)) { etype = RSTRING_PTR(rb_obj_as_string(x)); } else { etype = rb_obj_classname(x); } rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)", etype, type->name); } type++; } rb_bug("unknown type 0x%x (0x%x given)", t, TYPE(x)); } }
static RETSIGTYPE sigbus(int sig SIGINFO_ARG) { /* * Mac OS X makes KERN_PROTECTION_FAILURE when thread touch guard page. * and it's delivered as SIGBUS instaed of SIGSEGV to userland. It's crazy * wrong IMHO. but anyway we have to care it. Sigh. */ #if defined __APPLE__ CHECK_STACK_OVERFLOW(); #endif rb_bug("Bus Error"); }
VALUE rbgobj_define_class(GType gtype, const gchar *name, VALUE module, void *mark, void *free, VALUE parent) { RGObjClassInfo* cinfo; if (gtype == 0) rb_bug("rbgobj_define_class: Invalid gtype [%s]\n", name); cinfo = (RGObjClassInfo*)rbgobj_lookup_class_by_gtype(gtype, parent); cinfo->mark = mark; cinfo->free = free; rb_define_const(module, name, cinfo->klass); return cinfo->klass; }
rb_method_entry_t * rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *opts, rb_method_flag_t noex) { rb_thread_t *th; rb_control_frame_t *cfp; int line; rb_method_entry_t *me = rb_method_entry_make(klass, mid, type, 0, noex); rb_method_definition_t *def = ALLOC(rb_method_definition_t); me->def = def; def->type = type; def->original_id = mid; def->alias_count = 0; switch (type) { case VM_METHOD_TYPE_ISEQ: def->body.iseq = (rb_iseq_t *)opts; break; case VM_METHOD_TYPE_CFUNC: def->body.cfunc = *(rb_method_cfunc_t *)opts; break; case VM_METHOD_TYPE_ATTRSET: case VM_METHOD_TYPE_IVAR: def->body.attr.id = (ID)opts; def->body.attr.location = Qfalse; th = GET_THREAD(); cfp = rb_vm_get_ruby_level_next_cfp(th, th->cfp); if (cfp && (line = rb_vm_get_sourceline(cfp))) { VALUE location = rb_ary_new3(2, cfp->iseq->filename, INT2FIX(line)); def->body.attr.location = rb_ary_freeze(location); } break; case VM_METHOD_TYPE_BMETHOD: def->body.proc = (VALUE)opts; break; case VM_METHOD_TYPE_NOTIMPLEMENTED: def->body.cfunc.func = rb_f_notimplement; def->body.cfunc.argc = -1; break; case VM_METHOD_TYPE_OPTIMIZED: def->body.optimize_type = (enum method_optimized_type)opts; break; case VM_METHOD_TYPE_ZSUPER: case VM_METHOD_TYPE_UNDEF: break; default: rb_bug("rb_add_method: unsupported method type (%d)\n", type); } if (type != VM_METHOD_TYPE_UNDEF) { method_added(klass, mid); } return me; }
VALUE rb_tracearg_object(rb_trace_arg_t *trace_arg) { if (trace_arg->event & (RUBY_INTERNAL_EVENT_NEWOBJ | RUBY_INTERNAL_EVENT_FREEOBJ)) { /* ok */ } else { rb_raise(rb_eRuntimeError, "not supported by this event"); } if (trace_arg->data == Qundef) { rb_bug("tp_attr_raised_exception_m: unreachable"); } return trace_arg->data; }
VALUE virtualmachine_vme_eax(VALUE self) { VALUE vctx = rb_iv_get(self, "@ctx"); VALUE vvme = rb_iv_get(self, "@vmexit"); struct vmctx *ctx; struct vm_exit *vme; Data_Get_Struct(vctx, struct vmctx, ctx); if (!ctx) rb_bug("ctx is null"); Data_Get_Struct(vvme, struct vm_exit, vme); if (!vme) tb_bug("vme is null"); return INT2FIX(vme->u.inout.eax); }
VALUE virtualmachine_vme_rip(VALUE self) { VALUE vctx = rb_iv_get(self, "@ctx"); VALUE vvme = rb_iv_get(self, "@vmexit"); struct vmctx *ctx; struct vm_exit *vme; Data_Get_Struct(vctx, struct vmctx, ctx); if (!ctx) rb_bug("ctx is null"); Data_Get_Struct(vvme, struct vm_exit, vme); if (!vme) tb_bug("vme is null"); return ULL2NUM(vme->rip); }
VALUE virtualmachine_load_binary(VALUE self, VALUE program) { VALUE vctx = rb_iv_get(self, "@ctx"); struct vmctx *ctx; unsigned char *entry; Data_Get_Struct(vctx, struct vmctx, ctx); if (!ctx) rb_bug("ctx is null"); entry = _vm_map_gpa(ctx, ADDR_ENTRY, RSTRING_LEN(program)); memcpy(entry, StringValuePtr(program), RSTRING_LEN(program)); _vm_set_register(ctx, 0, VM_REG_GUEST_RIP, ADDR_ENTRY); return Qnil; }
static void native_cond_signal(rb_thread_cond_t *cond) { /* cond is guarded by mutex */ struct cond_event_entry *e = cond->next; if (e) { cond->next = e->next; SetEvent(e->event); } else { rb_bug("native_cond_signal: no pending threads"); } }
static RETSIGTYPE sigsegv(int sig) { if (segv_received) { fprintf(stderr, "SEGV recieved in SEGV handler\n"); exit(EXIT_FAILURE); } else { extern int ruby_disable_gc_stress; segv_received = 1; ruby_disable_gc_stress = 1; rb_bug("Segmentation fault"); } }
void rb_sys_fail(const char *mesg) { int n = errno; VALUE arg; errno = 0; if (n == 0) { rb_bug("rb_sys_fail(%s) - errno == 0", mesg ? mesg : ""); } arg = mesg ? rb_str_new2(mesg) : Qnil; rb_exc_raise(rb_class_new_instance(1, &arg, get_syserr(n))); }
VALUE rb_tracearg_return_value(rb_trace_arg_t *trace_arg) { if (trace_arg->event & (RUBY_EVENT_RETURN | RUBY_EVENT_C_RETURN | RUBY_EVENT_B_RETURN)) { /* ok */ } else { rb_raise(rb_eRuntimeError, "not supported by this event"); } if (trace_arg->data == Qundef) { rb_bug("tp_attr_return_value_m: unreachable"); } return trace_arg->data; }
VALUE rb_tracearg_raised_exception(rb_trace_arg_t *trace_arg) { if (trace_arg->event & (RUBY_EVENT_RAISE)) { /* ok */ } else { rb_raise(rb_eRuntimeError, "not supported by this event"); } if (trace_arg->data == Qundef) { rb_bug("tp_attr_raised_exception_m: unreachable"); } return trace_arg->data; }
static inline int native_mutex_trylock(pthread_mutex_t *lock) { int r; if ((r = pthread_mutex_trylock(lock)) != 0) { if (r == EBUSY) { return EBUSY; } else { rb_bug("native_mutex_trylock return non-zero: %d", r); } } return 0; }
/* alternate stack for SIGSEGV */ void rb_register_sigaltstack(rb_thread_t *th) { stack_t newSS, oldSS; if (!th->altstack) rb_bug("rb_register_sigaltstack: th->altstack not initialized\n"); newSS.ss_sp = th->altstack; newSS.ss_size = rb_sigaltstack_size(); newSS.ss_flags = 0; sigaltstack(&newSS, &oldSS); /* ignore error. */ }
static VALUE make_errno_exc(const char *mesg) { int n = errno; VALUE arg; errno = 0; if (n == 0) { rb_bug("rb_sys_fail(%s) - errno == 0", mesg ? mesg : ""); } arg = mesg ? rb_str_new2(mesg) : Qnil; return rb_class_new_instance(1, &arg, get_syserr(n)); }
static void w32_error(const char *func) { #if defined(OS_WP8) LPVOID lpMsgBuf = malloc( 1001 ); int nError = GetLastError(); DWORD flFormat = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS; FormatMessage(flFormat, NULL, nError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) & lpMsgBuf, 1000, NULL); if ( lpMsgBuf ) rb_bug("%s;Error code: %d; Func: %s", (char*)lpMsgBuf, nError, func); else rb_bug("Error code: %d; Func: %s", nError, func); free(lpMsgBuf); #else LPVOID lpMsgBuf = 0; int nError = GetLastError(); DWORD flFormat = FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS; FormatMessage(flFormat, NULL, nError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) & lpMsgBuf, 0, NULL); if ( lpMsgBuf ) rb_bug("%s;Error code: %d; Func: %s", (char*)lpMsgBuf, nError, func); else rb_bug("Error code: %d; Func: %s", nError, func); #endif }
static RETSIGTYPE sigsegv(int sig SIGINFO_ARG) { if (segv_received) { char msg[] = "SEGV received in SEGV handler\n"; write(2, msg, sizeof(msg)); ruby_abort(); } CHECK_STACK_OVERFLOW(); segv_received = 1; ruby_disable_gc_stress = 1; rb_bug("Segmentation fault"); }
//RHO /*static*/ int //RHO native_mutex_lock(rb_thread_lock_t *lock) { #if USE_WIN32_MUTEX DWORD result; while (1) { thread_debug("native_mutex_lock: %p\n", *lock); result = w32_wait_events(&*lock, 1, INFINITE, 0); switch (result) { case WAIT_OBJECT_0: /* get mutex object */ thread_debug("acquire mutex: %p\n", *lock); return 0; case WAIT_OBJECT_0 + 1: /* interrupt */ errno = EINTR; thread_debug("acquire mutex interrupted: %p\n", *lock); return 0; case WAIT_TIMEOUT: thread_debug("timeout mutex: %p\n", *lock); break; case WAIT_ABANDONED: rb_bug("win32_mutex_lock: WAIT_ABANDONED"); break; default: rb_bug("win32_mutex_lock: unknown result (%d)", result); break; } } return 0; #else EnterCriticalSection(lock); return 0; #endif }
VALUE virtualmachine_run(VALUE self, VALUE rip) { VALUE vctx = rb_iv_get(self, "@ctx"); VALUE vvme = rb_iv_get(self, "@vmexit"); struct vmctx *ctx; struct vm_exit *vme; Data_Get_Struct(vctx, struct vmctx, ctx); if (!ctx) rb_bug("ctx is null"); Data_Get_Struct(vvme, struct vm_exit, vme); if (!vme) tb_bug("vme is null"); _vm_run(ctx, 0, NUM2ULL(rip), vme); return Qnil; }
static void mutex_free(void *ptr) { if (ptr) { rb_mutex_t *mutex = ptr; if (mutex->th) { /* rb_warn("free locked mutex"); */ const char *err = rb_mutex_unlock_th(mutex, mutex->th); if (err) rb_bug("%s", err); } native_mutex_destroy(&mutex->lock); native_cond_destroy(&mutex->cond); } ruby_xfree(ptr); }
static void * do_loop(void *p) { struct loop_ctl *ctl = p; /* tell the waiting process they can interrupt us, now */ ssize_t err = write(ctl->notify_fd, "", 1); if (err == -1) rb_bug("write error"); while (!ctl->stop) { struct timeval tv = { 0, 10000 }; select(0, NULL, NULL, NULL, &tv); } return 0; }
static VALUE location_base_label(rb_backtrace_location_t *loc) { switch (loc->type) { case LOCATION_TYPE_ISEQ: case LOCATION_TYPE_ISEQ_CALCED: return loc->body.iseq.iseq->location.base_label; case LOCATION_TYPE_CFUNC: return rb_sym_to_s(ID2SYM(loc->body.cfunc.mid)); case LOCATION_TYPE_IFUNC: default: rb_bug("location_base_label: unreachable"); UNREACHABLE; } }
/* * call-seq: * coder.encode( value [, encoding] ) * * Encodes the given Ruby object into string representation, without * sending data to/from the database server. * * A nil value is passed through. * */ static VALUE pg_coder_encode(int argc, VALUE *argv, VALUE self) { VALUE res; VALUE intermediate; VALUE value; int len, len2; int enc_idx; t_pg_coder *this = DATA_PTR(self); if(argc < 1 || argc > 2){ rb_raise(rb_eArgError, "wrong number of arguments (%i for 1..2)", argc); }else if(argc == 1){ enc_idx = rb_ascii8bit_encindex(); }else{ enc_idx = rb_to_encoding_index(argv[1]); } value = argv[0]; if( NIL_P(value) ) return Qnil; if( !this->enc_func ){ rb_raise(rb_eRuntimeError, "no encoder function defined"); } len = this->enc_func( this, value, NULL, &intermediate, enc_idx ); if( len == -1 ){ /* The intermediate value is a String that can be used directly. */ OBJ_INFECT(intermediate, value); return intermediate; } res = rb_str_new(NULL, len); PG_ENCODING_SET_NOCHECK(res, enc_idx); len2 = this->enc_func( this, value, RSTRING_PTR(res), &intermediate, enc_idx ); if( len < len2 ){ rb_bug("%s: result length of first encoder run (%i) is less than second run (%i)", rb_obj_classname( self ), len, len2 ); } rb_str_set_len( res, len2 ); OBJ_INFECT(res, value); RB_GC_GUARD(intermediate); return res; }
static void rb_objc_recorder(task_t task, void *context, unsigned type_mask, vm_range_t *ranges, unsigned range_count) { struct rb_objc_recorder_context *ctx; vm_range_t *r, *end; ctx = (struct rb_objc_recorder_context *)context; for (r = ranges, end = ranges + range_count; r < end; r++) { auto_memory_type_t type = auto_zone_get_layout_type(__auto_zone, (void *)r->address); if (type != AUTO_OBJECT_SCANNED && type != AUTO_OBJECT_UNSCANNED) { continue; } if (*(Class *)r->address == NULL) { continue; } if (ctx->class_of != 0) { Class c; bool ok = false; for (c = *(Class *)r->address; c != NULL; c = class_getSuperclass(c)) { if (c == (Class)ctx->class_of) { ok = true; break; } } if (!ok) { continue; } } switch (TYPE(r->address)) { case T_NONE: case T_NODE: continue; case T_ICLASS: case T_CLASS: case T_MODULE: rb_bug("object %p of type %d should not be recorded", (void *)r->address, TYPE(r->address)); } rb_yield((VALUE)r->address); ctx->break_value = rb_vm_pop_broken_value(); ctx->count++; } }
VALUE rb_dlhandle_initialize(int argc, VALUE argv[], VALUE self) { void *ptr; struct dl_handle *dlhandle; VALUE lib, flag; char *clib = 0; int cflag = 0; const char *err; switch (rb_scan_args(argc, argv, "11", &lib, &flag)) { case 1: clib = NIL_P(lib) ? NULL : StringValuePtr(lib); cflag = RTLD_LAZY | RTLD_GLOBAL; break; case 2: clib = NIL_P(lib) ? NULL : StringValuePtr(lib); cflag = NUM2INT(flag); break; default: rb_bug("rb_dlhandle_new"); } ptr = dlopen(clib, cflag); #if defined(HAVE_DLERROR) if (!ptr && (err = dlerror())) { rb_raise(rb_eRuntimeError, "%s", err); } #else if (!ptr) { err = dlerror(); rb_raise(rb_eRuntimeError, "%s", err); } #endif Data_Get_Struct(self, struct dl_handle, dlhandle); if (dlhandle->ptr && dlhandle->open && dlhandle->enable_close) { dlclose(dlhandle->ptr); } dlhandle->ptr = ptr; dlhandle->open = 1; dlhandle->enable_close = 0; if (rb_block_given_p()) { rb_ensure(rb_yield, self, rb_dlhandle_close, self); } return Qnil; }
void rb_syserr_fail_path_in(const char *func_name, int n, VALUE path) { VALUE args[2]; if (!path) path = Qnil; if (n == 0) { const char *s = !NIL_P(path) ? RSTRING_PTR(path) : ""; if (!func_name) func_name = "(null)"; rb_bug("rb_sys_fail_path_in(%s, %s) - errno == 0", func_name, s); } args[0] = path; args[1] = rb_str_new_cstr(func_name); rb_exc_raise(rb_class_new_instance(2, args, get_syserr(n))); }