Beispiel #1
0
/* Construct expanded load path and store it to cache.
   We rebuild load path partially if the cache is invalid.
   We don't cache non string object and expand it every time. We ensure that
   string objects in $LOAD_PATH are frozen.
 */
static void
rb_construct_expanded_load_path(int type, int *has_relative, int *has_non_cache)
{
    rb_vm_t *vm = GET_VM();
    VALUE load_path = vm->load_path;
    VALUE expanded_load_path = vm->expanded_load_path;
    VALUE ary;
    long i;
    int level = rb_safe_level();

    ary = rb_ary_tmp_new(RARRAY_LEN(load_path));
    for (i = 0; i < RARRAY_LEN(load_path); ++i) {
	VALUE path, as_str, expanded_path;
	int is_string, non_cache;
	char *as_cstr;
	as_str = path = RARRAY_AREF(load_path, i);
	is_string = RB_TYPE_P(path, T_STRING) ? 1 : 0;
	non_cache = !is_string ? 1 : 0;
	as_str = rb_get_path_check_to_string(path, level);
	as_cstr = RSTRING_PTR(as_str);

	if (!non_cache) {
	    if ((type == EXPAND_RELATIVE &&
		    rb_is_absolute_path(as_cstr)) ||
		(type == EXPAND_HOME &&
		    (!as_cstr[0] || as_cstr[0] != '~')) ||
		(type == EXPAND_NON_CACHE)) {
		    /* Use cached expanded path. */
		    rb_ary_push(ary, RARRAY_AREF(expanded_load_path, i));
		    continue;
	    }
	}
	if (!*has_relative && !rb_is_absolute_path(as_cstr))
	    *has_relative = 1;
	if (!*has_non_cache && non_cache)
	    *has_non_cache = 1;
	/* Freeze only string object. We expand other objects every time. */
	if (is_string)
	    rb_str_freeze(path);
	as_str = rb_get_path_check_convert(path, as_str, level);
	expanded_path = rb_file_expand_path_fast(as_str, Qnil);
	rb_str_freeze(expanded_path);
	rb_ary_push(ary, rb_fstring(expanded_path));
    }
    rb_obj_freeze(ary);
    vm->expanded_load_path = ary;
    rb_ary_replace(vm->load_path_snapshot, vm->load_path);
}
Beispiel #2
0
static st_table *
get_loaded_features_index(void)
{
    VALUE features;
    int i;
    rb_vm_t *vm = GET_VM();

    if (!rb_ary_shared_with_p(vm->loaded_features_snapshot, vm->loaded_features)) {
	/* The sharing was broken; something (other than us in rb_provide_feature())
	   modified loaded_features.  Rebuild the index. */
	st_foreach(vm->loaded_features_index, loaded_features_index_clear_i, 0);
	features = vm->loaded_features;
	for (i = 0; i < RARRAY_LEN(features); i++) {
	    VALUE entry, as_str;
	    as_str = entry = rb_ary_entry(features, i);
	    StringValue(as_str);
	    as_str = rb_fstring(rb_str_freeze(as_str));
	    if (as_str != entry)
		rb_ary_store(features, i, as_str);
	    features_index_add(as_str, INT2FIX(i));
	}
	reset_loaded_features_snapshot();
    }
    return vm->loaded_features_index;
}
Beispiel #3
0
static VALUE gl_VertexAttribPointerNV(VALUE obj,VALUE arg1,VALUE arg2,VALUE arg3,VALUE arg4,VALUE arg5)
{
	GLuint index;
	GLuint size;
	GLenum type;
	GLsizei stride;

	LOAD_GL_FUNC(glVertexAttribPointerNV, "GL_NV_vertex_program");

	index = (GLuint)NUM2UINT(arg1);
	size = (GLuint)NUM2UINT(arg2);
	type = (GLenum)NUM2INT(arg3);
	stride = (GLsizei)NUM2UINT(arg4);
	if (index>_MAX_VERTEX_ATTRIBS)
		rb_raise(rb_eArgError, "Index too large, maximum allowed value '%i'",_MAX_VERTEX_ATTRIBS);

	if (CheckBufferBinding(GL_ARRAY_BUFFER_BINDING)) {
		g_VertexAttrib_ptr[index] = arg5;
		fptr_glVertexAttribPointerNV(index,size,type,stride,(GLvoid *)NUM2LONG(arg5));
	} else {
		VALUE data;
		data = pack_array_or_pass_string(type,arg5);
		rb_str_freeze(data);
		g_VertexAttrib_ptr[index] = data;
		fptr_glVertexAttribPointerNV(index,size,type,stride,(GLvoid *)RSTRING_PTR(data));
	}

	CHECK_GLERROR_FROM("glVertexAttribPointerNV");
	return Qnil;
}
Beispiel #4
0
/*
 * call-seq:
 *   pathname.freeze -> obj
 *
 * Freezes this Pathname.
 *
 * See Object.freeze.
 */
static VALUE
path_freeze(VALUE self)
{
    rb_call_super(0, 0);
    rb_str_freeze(get_strpath(self));
    return self;
}
Beispiel #5
0
/*
 * call-seq:
 *   OCI8::ConnectionPool.new(conn_min, conn_max, conn_incr, username = nil, password = nil, dbname = nil) -> connection pool
 *   OCI8::ConnectionPool.new(conn_min, conn_max, conn_incr, connect_string) -> connection pool
 *
 * Creates a connection pool.
 *
 * <i>conn_min</i> specifies the minimum number of connections in the
 * connection pool. Valid values are 0 and higher.
 *
 * <i>conn_max</i> specifies the maximum number of connections that
 * can be opened to the database. Once this value is reached, no more
 * connections are opened. Valid values are 1 and higher.
 *
 * <i>conn_incr</i> allows the application to set the next increment
 * for connections to be opened to the database if the current number
 * of connections are less than <i>conn_max</i>. Valid values are 0
 * and higher.
 *
 * <i>username</i> and <i>password</i> are required to establish an
 * implicit primary session. When both are nil, external
 * authentication is used.
 *
 * <i>dbname</i> specifies the database server to connect to.
 *
 * If the number of arguments is four, <i>username</i>,
 * <i>password</i> and <i>dbname</i> are extracted from the fourth
 * argument <i>connect_string</i>. The syntax is "username/password" or
 * "username/password@dbname".
 */
static VALUE oci8_cpool_initialize(int argc, VALUE *argv, VALUE self)
{
    VALUE conn_min;
    VALUE conn_max;
    VALUE conn_incr;
    VALUE username;
    VALUE password;
    VALUE dbname;
    oci8_cpool_t *cpool = DATA_PTR(self);
    OraText *pool_name;
    sb4 pool_name_len;
    sword rv;

    /* check arguments */
    rb_scan_args(argc, argv, "42", &conn_min, &conn_max, &conn_incr,
                 &username, &password, &dbname);
    Check_Type(conn_min, T_FIXNUM);
    Check_Type(conn_max, T_FIXNUM);
    Check_Type(conn_incr, T_FIXNUM);
    if (argc == 4) {
        VALUE mode;
        VALUE conn_str = username;

        OCI8SafeStringValue(conn_str);
        oci8_do_parse_connect_string(conn_str, &username, &password, &dbname, &mode);
        if (!NIL_P(mode)) {
            rb_raise(rb_eArgError, "invalid connect string \"%s\": Connection pooling doesn't support sysdba and sysoper privileges.", RSTRING_PTR(conn_str));
        }
    } else {
        if (!NIL_P(username)) {
            OCI8SafeStringValue(username);
        }
        if (!NIL_P(password)) {
            OCI8SafeStringValue(password);
        }
        if (!NIL_P(dbname)) {
            OCI8SafeStringValue(dbname);
        }
    }

    rv = OCIHandleAlloc(oci8_envhp, &cpool->base.hp.ptr, OCI_HTYPE_CPOOL, 0, NULL);
    if (rv != OCI_SUCCESS)
        oci8_env_raise(oci8_envhp, rv);
    cpool->base.type = OCI_HTYPE_CPOOL;

    oci_lc(OCIConnectionPoolCreate(oci8_envhp, oci8_errhp, cpool->base.hp.poolhp,
                                   &pool_name, &pool_name_len,
                                   NIL_P(dbname) ? NULL : RSTRING_ORATEXT(dbname),
                                   NIL_P(dbname) ? 0 : RSTRING_LEN(dbname),
                                   FIX2UINT(conn_min), FIX2UINT(conn_max),
                                   FIX2UINT(conn_incr),
                                   NIL_P(username) ? NULL : RSTRING_ORATEXT(username),
                                   NIL_P(username) ? 0 : RSTRING_LEN(username),
                                   NIL_P(password) ? NULL : RSTRING_ORATEXT(password),
                                   NIL_P(password) ? 0 : RSTRING_LEN(password),
                                   OCI_DEFAULT));
    cpool->pool_name = rb_str_new(TO_CHARPTR(pool_name), pool_name_len);
    rb_str_freeze(cpool->pool_name);
    return Qnil;
}
Beispiel #6
0
/*	make Mysql::Field object	*/
static VALUE make_field_obj(MYSQL_FIELD* f)
{
    VALUE obj;
    if (f == NULL)
	return Qnil;
    obj = rb_obj_alloc(cMysqlField);
    rb_iv_set(obj, "name", f->name? rb_str_freeze(rb_tainted_str_new2(f->name)): Qnil);
    rb_iv_set(obj, "table", f->table? rb_str_freeze(rb_tainted_str_new2(f->table)): Qnil);
    rb_iv_set(obj, "def", f->def? rb_str_freeze(rb_tainted_str_new2(f->def)): Qnil);
    rb_iv_set(obj, "type", INT2NUM(f->type));
    rb_iv_set(obj, "length", INT2NUM(f->length));
    rb_iv_set(obj, "max_length", INT2NUM(f->max_length));
    rb_iv_set(obj, "flags", INT2NUM(f->flags));
    rb_iv_set(obj, "decimals", INT2NUM(f->decimals));
    return obj;
}
    static VALUE
cb_intern_string(VALUE ar, const char *str)
{
    VALUE tmp = STR_NEW_CSTR(str);
    rb_str_freeze(tmp);
    rb_ary_push(ar, tmp);
    return tmp;
}
Beispiel #8
0
static VALUE
rg_match_all(gint argc, VALUE *argv, VALUE self)
{
    VALUE rb_string, rb_start_position, rb_match_options, rb_options;
    VALUE rb_frozen_string, rb_match_info;
    GMatchInfo *match_info = NULL;
    GError *error = NULL;
    const gchar *string;
    gssize string_len = -1;
    gint start_position = 0;
    GRegexMatchFlags match_options = 0;

    rb_scan_args(argc, argv, "11", &rb_string, &rb_options);

    rbg_scan_options(rb_options,
                     "start_position", &rb_start_position,
                     "match_options", &rb_match_options,
                     NULL);

    if (OBJ_FROZEN(rb_string)) {
        rb_frozen_string = rb_string;
    } else {
        rb_frozen_string = rb_str_dup(rb_string);
        rb_str_freeze(rb_frozen_string);
    }

    string = RVAL2CSTR(rb_frozen_string);
    string_len = RSTRING_LEN(rb_frozen_string);


    if (!NIL_P(rb_start_position))
        start_position = NUM2INT(rb_start_position);
    if (!NIL_P(rb_match_options))
        match_options = RVAL2GREGEXMATCHOPTIONSFLAGS(rb_match_options);

    g_regex_match_all_full(_SELF(self),
                           string,
                           string_len,
                           start_position,
                           match_options,
                           &match_info,
                           &error);

    if (error)
        RAISE_GERROR(error);

    if (!match_info)
        return Qnil;

    rb_match_info = GMATCHINFO2RVAL(match_info);
    g_match_info_unref(match_info);
    rb_iv_set(rb_match_info, "@string", rb_frozen_string);
    return rb_match_info;
}
Beispiel #9
0
static void
rb_provide_feature(VALUE feature)
{
    VALUE features;

    features = get_loaded_features();
    if (OBJ_FROZEN(features)) {
	rb_raise(rb_eRuntimeError,
		 "$LOADED_FEATURES is frozen; cannot append feature");
    }
    rb_str_freeze(feature);

    rb_ary_push(features, rb_fstring(feature));
    features_index_add(feature, INT2FIX(RARRAY_LEN(features)-1));
    reset_loaded_features_snapshot();
}
Beispiel #10
0
VALUE
rb_get_expanded_load_path(void)
{
    VALUE load_path = rb_get_load_path();
    VALUE ary;
    long i;

    ary = rb_ary_new2(RARRAY_LEN(load_path));
    for (i = 0; i < RARRAY_LEN(load_path); ++i) {
	VALUE path = rb_file_expand_path(RARRAY_PTR(load_path)[i], Qnil);
	rb_str_freeze(path);
	rb_ary_push(ary, path);
    }
    rb_obj_freeze(ary);
    return ary;
}
Beispiel #11
0
Datei: load.c Projekt: 217/ruby
VALUE
rb_get_expanded_load_path(void)
{
    VALUE load_path = rb_get_load_path();
    VALUE ary;
    long i;

    for (i = 0; i < RARRAY_LEN(load_path); ++i) {
	VALUE str = rb_check_string_type(RARRAY_PTR(load_path)[i]);
	if (NIL_P(str) || !rb_is_absolute_path(RSTRING_PTR(str)))
	    goto relative_path_found;
    }
    return load_path;

  relative_path_found:
    ary = rb_ary_new2(RARRAY_LEN(load_path));
    for (i = 0; i < RARRAY_LEN(load_path); ++i) {
	VALUE path = rb_file_expand_path(RARRAY_PTR(load_path)[i], Qnil);
	rb_str_freeze(path);
	rb_ary_push(ary, path);
    }
    rb_obj_freeze(ary);
    return ary;
}
Beispiel #12
0
VALUE string_spec_rb_str_freeze(VALUE self, VALUE str) {
  return rb_str_freeze(str);
}
Beispiel #13
0
void CRbFont::InitLibrary()
{
	/**
	 *	@classname
	 *		Font
	 *
	 *	@desc
	 *		字体的类。
	 */
	rb_cFont = rb_define_class_under(rb_mSin, "Font", rb_cObject);

	VALUE __argv[3]		= { INT2FIX(255), INT2FIX(255), INT2FIX(255) };

	__default_name__	= rb_str_new2("simhei");
	
	rb_str_freeze(__default_name__);

	__default_size__	= INT2FIX(20);
	__default_bold__	= Qfalse;
	__default_italic__	= Qfalse;
	__default_color__	= rb_class_new_instance(3, __argv, rb_cColor);
	__default_shadow__	= Qtrue;

	rb_gc_register_address(&__default_name__);
	rb_gc_register_address(&__default_color__);

	// special method
	rb_define_alloc_func(rb_cFont, ObjAllocate<CRbFont>);
	rb_define_method(rb_cFont, "initialize", (RbFunc)dm_initialize, -1);

	// object attribute
	rb_define_method(rb_cFont, "name",		(RbFunc)dm_get_name,	0);
	rb_define_method(rb_cFont, "name=",		(RbFunc)dm_set_name,	1);
	rb_define_method(rb_cFont, "size",		(RbFunc)dm_get_size,	0);
	rb_define_method(rb_cFont, "size=",		(RbFunc)dm_set_size,	1);
	rb_define_method(rb_cFont, "bold",		(RbFunc)dm_get_bold,	0);
	rb_define_method(rb_cFont, "bold=",		(RbFunc)dm_set_bold,	1);
	rb_define_method(rb_cFont, "italic",	(RbFunc)dm_get_italic,	0);
	rb_define_method(rb_cFont, "italic=",	(RbFunc)dm_set_italic,	1);
	rb_define_method(rb_cFont, "color",		(RbFunc)dm_get_color,	0);
	rb_define_method(rb_cFont, "color=",	(RbFunc)dm_set_color,	1);
	rb_define_method(rb_cFont, "shadow",	(RbFunc)dm_get_shadow,	0);
	rb_define_method(rb_cFont, "shadow=",	(RbFunc)dm_set_shadow,	1);

	// class attribute
	rb_define_singleton_method(rb_cFont, "exist?",			(RbFunc)dm_is_exist,			1);

	rb_define_singleton_method(rb_cFont, "default_name",	(RbFunc)dm_get_default_name,	0);
	rb_define_singleton_method(rb_cFont, "default_name=",	(RbFunc)dm_set_default_name,	1);
	rb_define_singleton_method(rb_cFont, "default_size",	(RbFunc)dm_get_default_size,	0);
	rb_define_singleton_method(rb_cFont, "default_size=",	(RbFunc)dm_set_default_size,	1);
	rb_define_singleton_method(rb_cFont, "default_bold",	(RbFunc)dm_get_default_bold,	0);
	rb_define_singleton_method(rb_cFont, "default_bold=",	(RbFunc)dm_set_default_bold,	1);
	rb_define_singleton_method(rb_cFont, "default_italic",	(RbFunc)dm_get_default_italic,	0);
	rb_define_singleton_method(rb_cFont, "default_italic=",	(RbFunc)dm_set_default_italic,	1);
	rb_define_singleton_method(rb_cFont, "default_color",	(RbFunc)dm_get_default_color,	0);
	rb_define_singleton_method(rb_cFont, "default_color=",	(RbFunc)dm_set_default_color,	1);
	rb_define_singleton_method(rb_cFont, "default_shadow",	(RbFunc)dm_get_default_shadow,	0);
	rb_define_singleton_method(rb_cFont, "default_shadow=",	(RbFunc)dm_set_default_shadow,	1);

	// supplement
 	rb_define_method(rb_cFont, "to_s",	(RbFunc)dm_to_string,	0);
	rb_define_method(rb_cFont, "clone",	(RbFunc)dm_clone,		0);
}
Beispiel #14
0
void
ruby_init_loadpath_safe(int safe_level)
{
    VALUE load_path;
    ID id_initial_load_path_mark;
    extern const char ruby_initial_load_paths[];
    const char *paths = ruby_initial_load_paths;
#if defined LOAD_RELATIVE
# if defined HAVE_DLADDR || defined HAVE_CYGWIN_CONV_PATH
#   define VARIABLE_LIBPATH 1
# else
#   define VARIABLE_LIBPATH 0
# endif
# if VARIABLE_LIBPATH
    char *libpath;
    VALUE sopath;
# else
    char libpath[MAXPATHLEN + 1];
# endif
    size_t baselen;
    char *p;

#if defined _WIN32 || defined __CYGWIN__
# if VARIABLE_LIBPATH
    sopath = rb_str_new(0, MAXPATHLEN);
    libpath = RSTRING_PTR(sopath);
    GetModuleFileName(libruby, libpath, MAXPATHLEN);
# else
    GetModuleFileName(libruby, libpath, sizeof libpath);
# endif
#elif defined(__EMX__)
    _execname(libpath, sizeof(libpath) - 1);
#elif defined(HAVE_DLADDR)
    Dl_info dli;
    if (dladdr((void *)(VALUE)expand_include_path, &dli)) {
	char fbuf[MAXPATHLEN];
	char *f = dln_find_file_r(dli.dli_fname, getenv(PATH_ENV), fbuf, sizeof(fbuf));
	VALUE fname = rb_str_new_cstr(f ? f : dli.dli_fname);
	rb_str_freeze(fname);
	sopath = rb_realpath_internal(Qnil, fname, 1);
    }
    else {
	sopath = rb_str_new(0, 0);
    }
    libpath = RSTRING_PTR(sopath);
#endif

#if !VARIABLE_LIBPATH
    libpath[sizeof(libpath) - 1] = '\0';
#endif
#if defined DOSISH
    translit_char(libpath, '\\', '/');
#elif defined __CYGWIN__
    {
# if VARIABLE_LIBPATH
	const int win_to_posix = CCP_WIN_A_TO_POSIX | CCP_RELATIVE;
	size_t newsize = cygwin_conv_path(win_to_posix, libpath, 0, 0);
	if (newsize > 0) {
	    VALUE rubylib = rb_str_new(0, newsize);
	    p = RSTRING_PTR(rubylib);
	    if (cygwin_conv_path(win_to_posix, libpath, p, newsize) == 0) {
		rb_str_resize(sopath, 0);
		sopath = rubylib;
		libpath = p;
	    }
	}
# else
	char rubylib[FILENAME_MAX];
	cygwin_conv_to_posix_path(libpath, rubylib);
	strncpy(libpath, rubylib, sizeof(libpath));
# endif
    }
#endif
    p = strrchr(libpath, '/');
    if (p) {
	*p = 0;
	if (p - libpath > 3 && !(STRCASECMP(p - 4, "/bin") && strcmp(p - 4, "/lib"))) {
	    p -= 4;
	    *p = 0;
	}
    }
#if !VARIABLE_LIBPATH
    else {
	strlcpy(libpath, ".", sizeof(libpath));
	p = libpath + 1;
    }
    baselen = p - libpath;
#define PREFIX_PATH() rb_str_new(libpath, baselen)
#else
    baselen = p - libpath;
    rb_str_resize(sopath, baselen);
    libpath = RSTRING_PTR(sopath);
#define PREFIX_PATH() sopath
#endif

#define BASEPATH() rb_str_buf_cat(rb_str_buf_new(baselen+len), libpath, baselen)

#define RUBY_RELATIVE(path, len) rb_str_buf_cat(BASEPATH(), (path), (len))
#else
    static const char exec_prefix[] = RUBY_EXEC_PREFIX;
#define RUBY_RELATIVE(path, len) rubylib_mangled_path((path), (len))
#define PREFIX_PATH() RUBY_RELATIVE(exec_prefix, sizeof(exec_prefix)-1)
#endif
    load_path = GET_VM()->load_path;

    if (safe_level == 0) {
#ifdef MANGLED_PATH
	rubylib_mangled_path("", 0);
#endif
	ruby_push_include(getenv("RUBYLIB"), identical_path);
    }

    id_initial_load_path_mark = rb_intern_const("@gem_prelude_index");
    while (*paths) {
	size_t len = strlen(paths);
	VALUE path = RUBY_RELATIVE(paths, len);
	rb_ivar_set(path, id_initial_load_path_mark, path);
	rb_ary_push(load_path, path);
	paths += len + 1;
    }

    rb_const_set(rb_cObject, rb_intern_const("TMP_RUBY_PREFIX"), rb_obj_freeze(PREFIX_PATH()));
}