static inline int args_setup_opt_parameters(struct args_info *args, int opt_max, VALUE *locals) { int i; if (args->argc >= opt_max) { args->argc -= opt_max; args->argv += opt_max; i = opt_max; } else { int j; i = args->argc; args->argc = 0; if (args->rest) { int len = RARRAY_LENINT(args->rest); const VALUE *argv = RARRAY_CONST_PTR(args->rest); for (; i<opt_max && args->rest_index < len; i++, args->rest_index++) { locals[i] = argv[args->rest_index]; } } /* initialize by nil */ for (j=i; j<opt_max; j++) { locals[j] = Qnil; } } return i; }
static VALUE setup_struct(VALUE nstr, VALUE members) { const VALUE *ptr_members; long i, len; OBJ_FREEZE(members); rb_ivar_set(nstr, id_members, members); rb_define_alloc_func(nstr, struct_alloc); rb_define_singleton_method(nstr, "new", rb_class_new_instance, -1); rb_define_singleton_method(nstr, "[]", rb_class_new_instance, -1); rb_define_singleton_method(nstr, "members", rb_struct_s_members_m, 0); ptr_members = RARRAY_CONST_PTR(members); len = RARRAY_LEN(members); for (i=0; i< len; i++) { ID id = SYM2ID(ptr_members[i]); if (i < N_REF_FUNC) { rb_define_method_id(nstr, id, ref_func[i], 0); } else { rb_define_method_id(nstr, id, rb_struct_ref, 0); } rb_define_method_id(nstr, rb_id_attrset(id), rb_struct_set, 1); } return nstr; }
static inline void args_setup_post_parameters(struct args_info *args, int argc, VALUE *locals) { long len; args_copy(args); len = RARRAY_LEN(args->rest); MEMCPY(locals, RARRAY_CONST_PTR(args->rest) + len - argc, VALUE, argc); rb_ary_resize(args->rest, len - argc); }
/* * call-seq: * io.winsize = [rows, columns] * * Tries to set console size. The effect depends on the platform and * the running environment. * * You must require 'io/console' to use this method. */ static VALUE console_set_winsize(VALUE io, VALUE size) { rb_io_t *fptr; rb_console_size_t ws; #if defined _WIN32 HANDLE wh; int newrow, newcol; #endif VALUE row, col, xpixel, ypixel; const VALUE *sz; int fd; GetOpenFile(io, fptr); size = rb_Array(size); rb_check_arity(RARRAY_LENINT(size), 2, 4); sz = RARRAY_CONST_PTR(size); row = sz[0], col = sz[1], xpixel = sz[2], ypixel = sz[3]; fd = GetWriteFD(fptr); #if defined TIOCSWINSZ ws.ws_row = ws.ws_col = ws.ws_xpixel = ws.ws_ypixel = 0; #define SET(m) ws.ws_##m = NIL_P(m) ? 0 : (unsigned short)NUM2UINT(m) SET(row); SET(col); SET(xpixel); SET(ypixel); #undef SET if (!setwinsize(fd, &ws)) rb_sys_fail(0); #elif defined _WIN32 wh = (HANDLE)rb_w32_get_osfhandle(fd); #define SET(m) new##m = NIL_P(m) ? 0 : (unsigned short)NUM2UINT(m) SET(row); SET(col); #undef SET if (!NIL_P(xpixel)) (void)NUM2UINT(xpixel); if (!NIL_P(ypixel)) (void)NUM2UINT(ypixel); if (!GetConsoleScreenBufferInfo(wh, &ws)) { rb_syserr_fail(LAST_ERROR, "GetConsoleScreenBufferInfo"); } if ((ws.dwSize.X < newcol && (ws.dwSize.X = newcol, 1)) || (ws.dwSize.Y < newrow && (ws.dwSize.Y = newrow, 1))) { if (!SetConsoleScreenBufferSize(wh, ws.dwSize)) { rb_syserr_fail(LAST_ERROR, "SetConsoleScreenBufferInfo"); } } ws.srWindow.Left = 0; ws.srWindow.Top = 0; ws.srWindow.Right = newcol; ws.srWindow.Bottom = newrow; if (!SetConsoleWindowInfo(wh, FALSE, &ws.srWindow)) { rb_syserr_fail(LAST_ERROR, "SetConsoleWindowInfo"); } #endif return io; }
static VALUE rval2gslist_body(VALUE data) { struct rval2gslist_args *args = (struct rval2gslist_args *)data; VALUE rb_array; int i, n; rb_array = rbg_to_array(args->rb_array); n = RARRAY_LEN(rb_array); for (i = 0; i < n; i++) { VALUE rb_element = RARRAY_CONST_PTR(rb_array)[i]; args->list = g_slist_append(args->list, RVAL2GOBJ(rb_element)); } return Qnil; }
static inline void vm_caller_setup_arg_splat(rb_control_frame_t *cfp, struct rb_calling_info *calling) { int argc = calling->argc; VALUE *argv = cfp->sp - argc; VALUE ary = argv[argc-1]; cfp->sp--; if (!NIL_P(ary)) { const VALUE *ptr = RARRAY_CONST_PTR(ary); long len = RARRAY_LEN(ary), i; CHECK_VM_STACK_OVERFLOW(cfp, len); for (i = 0; i < len; i++) { *cfp->sp++ = ptr[i]; } calling->argc += i - 1; } }
VALUE rb_struct_initialize(VALUE self, VALUE values) { return rb_struct_initialize_m(RARRAY_LENINT(values), RARRAY_CONST_PTR(values), self); }
void *oci8_find_symbol(const char *symbol_name) { #if defined _WIN32 /* Windows */ static HMODULE hModule = NULL; if (hModule == NULL) { hModule = LoadLibrary("OCI.DLL"); if (hModule == NULL) { char message[512]; int error = GetLastError(); char *p; memset(message, 0, sizeof(message)); FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), message, sizeof(message), NULL); for (p = message; *p; p++) { if (*p == '\n' || *p == '\r') *p = ' '; } rb_raise(rb_eLoadError, "OCI.DLL: %d(%s)", error, message); } } return GetProcAddress(hModule, symbol_name); #else /* UNIX */ static void *handle = NULL; if (handle == NULL) { static const char * const sonames[] = { #if defined(__CYGWIN__) /* Windows(Cygwin) */ "OCI.DLL", #elif defined(_AIX) /* AIX */ "libclntsh.a(shr.o)", #elif defined(__hppa) /* HP-UX(PA-RISC) */ "libclntsh.sl.12.1", "libclntsh.sl.11.1", "libclntsh.sl.10.1", "libclntsh.sl.9.0", "libclntsh.sl.8.0", #elif defined(__APPLE__) /* Mac OS X */ "libclntsh.dylib.12.1", "libclntsh.dylib.11.1", "libclntsh.dylib.10.1", #else /* Linux, Solaris and HP-UX(IA64) */ "libclntsh.so.12.1", "libclntsh.so.11.1", "libclntsh.so.10.1", "libclntsh.so.9.0", "libclntsh.so.8.0", #endif }; #define NUM_SONAMES (sizeof(sonames)/sizeof(sonames[0])) size_t idx; volatile VALUE err = rb_ary_new(); #ifdef _AIX #define DLOPEN_FLAG (RTLD_LAZY|RTLD_GLOBAL|RTLD_MEMBER) #else #define DLOPEN_FLAG (RTLD_LAZY|RTLD_GLOBAL) #endif for (idx = 0; idx < NUM_SONAMES; idx++) { handle = dlopen(sonames[idx], DLOPEN_FLAG); if (handle != NULL) { break; } rb_ary_push(err, rb_locale_str_new_cstr(dlerror())); } if (handle == NULL) { VALUE msg; const char *ary = RARRAY_CONST_PTR(err); msg = rb_str_buf_new(NUM_SONAMES * 50); for (idx = 0; idx < NUM_SONAMES; idx++) { const char *errmsg = RSTRING_PTR(arr[idx]); if (idx != 0) { rb_str_buf_cat2(msg, " "); } if (strstr(errmsg, sonames[idx]) == NULL) { /* prepend "soname: " if soname is not found in * the error message. */ rb_str_buf_cat2(msg, sonames[idx]); rb_str_buf_cat2(msg, ": "); } rb_str_buf_append(msg, arr[idx]); rb_str_buf_cat2(msg, ";"); } rb_exc_raise(rb_exc_new3(rb_eLoadError, msg)); } } return dlsym(handle, symbol_name); #endif /* defined _WIN32 */ }
static inline const VALUE * args_rest_argv(struct args_info *args) { return RARRAY_CONST_PTR(args->rest) + args->rest_index; }