Пример #1
0
void Init_Detect_Implicit_Variables_c(){ 
 cls_Detect_Implicit_Variables=rb_define_class("Detect_Implicit_Variables",rb_const_get(rb_cObject,rb_intern("Visitor"))); 
                    failobj=rb_eval_string("FAIL");
                    rb_define_method(cls_Detect_Implicit_Variables,"profile_report",profile_report_Detect_Implicit_Variables,0);
switchhash_Detect_Implicit_Variables_1=rb_eval_string("Hash.new{|h,k|next h[k]=0 if k<=Apply\nnext h[k]=1 if k<=Object\n}");rb_global_variable(&switchhash_Detect_Implicit_Variables_1);;
switchhash_Detect_Implicit_Variables_2=rb_eval_string("Hash.new{|h,k|next h[k]=0 if k<=AmethystAST\nnext h[k]=1 if k<=Array\nnext h[k]=2 if k<=Object\n}");rb_global_variable(&switchhash_Detect_Implicit_Variables_2);;
switchhash_Detect_Implicit_Variables_3=rb_eval_string("Hash.new{|h,k|next h[k]=0 if k<=Apply\nnext h[k]=1 if k<=Object\n}");rb_global_variable(&switchhash_Detect_Implicit_Variables_3);;
switchhash_Detect_Implicit_Variables_4=rb_eval_string("Hash.new{|h,k|next h[k]=0 if k<=Apply\nnext h[k]=1 if k<=Object\n}");rb_global_variable(&switchhash_Detect_Implicit_Variables_4);;
switchhash_Detect_Implicit_Variables_5=rb_eval_string("Hash.new{|h,k|next h[k]=0 if k<=Apply\nnext h[k]=1 if k<=Object\n}");rb_global_variable(&switchhash_Detect_Implicit_Variables_5);;
sy_Detect_Implicit_Variables__at_vars_a187=rb_intern("Detect_Implicit_Variables__at_vars_a187");
sy_Detect_Implicit_Variables__at_vars_eq_Ha_dec8=rb_intern("Detect_Implicit_Variables__at_vars_eq_Ha_dec8");
sy_Detect_Implicit_Variables__at_vars_lb_bi_edce=rb_intern("Detect_Implicit_Variables__at_vars_lb_bi_edce");
sy_Detect_Implicit_Variables__lp_src_dot_ins_a413=rb_intern("Detect_Implicit_Variables__lp_src_dot_ins_a413");
                    rb_define_method(cls_Detect_Implicit_Variables,"root",Detect_Implicit_Variables_root,0);
rb_define_method(cls_Detect_Implicit_Variables,"traverse",Detect_Implicit_Variables_traverse,0);
rb_define_method(cls_Detect_Implicit_Variables,"traverse_item",Detect_Implicit_Variables_traverse_item,0);
rb_define_method(cls_Detect_Implicit_Variables,"visit",Detect_Implicit_Variables_visit,0);
                    }
Пример #2
0
void Init_rsruby_c(){

  cRRuby = rb_define_class("RSRuby",rb_cObject);

  rb_define_method(cRRuby, "r_init", rr_init, 0);
  rb_define_method(cRRuby, "get_fun", get_fun, 1);
  rb_define_method(cRRuby, "shutdown", rs_shutdown, 0);

  rb_define_method(cRRuby, "crash", crash, 0);

  //Add the lcall method to RObj
  cRObj  = rb_const_get(rb_cObject,rb_intern("RObj"));
  rb_define_method(cRObj, "lcall", RObj_lcall, 1);
  rb_define_method(cRObj, "__init_lcall__", RObj_init_lcall, 1);  
  rb_define_method(cRObj, "to_ruby", RObj_to_ruby, -2);
  rb_define_method(cRObj, "to_R", ruby_to_R, 1);

}
Пример #3
0
void
rbffi_StructByReference_Init(VALUE moduleFFI)
{
    /*
     * Document-class: FFI::StructByReference
     * This class includes {FFI::DataConverter} module.
     */
    rbffi_StructByReferenceClass = rb_define_class_under(moduleFFI, "StructByReference", rb_cObject);
    rb_global_variable(&rbffi_StructByReferenceClass);
    rb_include_module(rbffi_StructByReferenceClass, rb_const_get(moduleFFI, rb_intern("DataConverter")));
    
    rb_define_alloc_func(rbffi_StructByReferenceClass, sbr_allocate);
    rb_define_method(rbffi_StructByReferenceClass, "initialize", sbr_initialize, 1);
    rb_define_method(rbffi_StructByReferenceClass, "struct_class", sbr_struct_class, 0);
    rb_define_method(rbffi_StructByReferenceClass, "native_type", sbr_native_type, 0);
    rb_define_method(rbffi_StructByReferenceClass, "to_native", sbr_to_native, 2);
    rb_define_method(rbffi_StructByReferenceClass, "from_native", sbr_from_native, 2);
}
Пример #4
0
/*
 * @api private
 */
static VALUE qml_init(VALUE module, VALUE args) {
    if (!NIL_P(rbqml_application)) {
        rb_raise(rb_eRuntimeError, "QML already initialized");
    }

    rbqml_application = rb_funcall(rbqml_cApplication, rb_intern("new"), 1, args);
    rbqml_engine = rb_funcall(rbqml_cEngine, rb_intern("new"), 0);

    rb_gc_register_address(&rbqml_application);
    rb_gc_register_address(&rbqml_engine);

    VALUE blocks = rb_const_get(module, rb_intern("INIT_BLOCKS"));
    for (int i = 0; i < RARRAY_LEN(blocks); ++i) {
        rb_proc_call(RARRAY_AREF(blocks, i), rb_ary_new());
    }

    return module;
}
Пример #5
0
static VALUE
timestamp_new(ValueStruct *val)
{
    VALUE cTime
		, ret;

ENTER_FUNC;
    cTime = rb_const_get(rb_cObject, rb_intern("Time"));
    ret = rb_funcall(cTime, rb_intern("local"), 6,
					 INT2NUM((ValueDateTimeYear(val))),
					 INT2NUM((ValueDateTimeMon(val)+1)),
					 INT2NUM((ValueDateTimeMDay(val))),
					 INT2NUM((ValueDateTimeHour(val))),
					 INT2NUM((ValueDateTimeMin(val))),
					 INT2NUM((ValueDateTimeSec(val))));
LEAVE_FUNC;
	return	ret;
}
Пример #6
0
static void check_kcode()
{
    VALUE rb_iconv_klass = rb_const_get(rb_cObject, rb_intern("Iconv"));
    VALUE kcode = rb_gv_get("$KCODE");
    if (RTEST(rb_iconv_klass) && TYPE(kcode) == T_STRING) {
        char* kcodep = StringValuePtr(kcode);
        char upper_kcode = toupper(*kcodep);
        if (Kcode != upper_kcode)
        {
            Kcode = upper_kcode;
            reinit();
        }
    }
    else
    {
        objIconvR2J = objIconvJ2R = Qnil;
    }
}
Пример #7
0
// Use the info in a Curl handle to create a new Response object.
static VALUE create_response(CURL* curl) {
  VALUE response = rb_class_new_instance(0, 0,
                      rb_const_get(mPatron, rb_intern("Response")));

  char* url = NULL;
  curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url);
  rb_iv_set(response, "@url", rb_str_new2(url));

  long code = 0;
  curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
  rb_iv_set(response, "@status", INT2NUM(code));

  long count = 0;
  curl_easy_getinfo(curl, CURLINFO_REDIRECT_COUNT, &count);
  rb_iv_set(response, "@redirect_count", INT2NUM(count));

  return response;
}
Пример #8
0
VALUE ltns_parse_ruby(VALUE module __attribute__ ((unused)), VALUE string)
{
	VALUE ret = Qnil;

	if (TYPE(string) != T_STRING)
	{
		VALUE rb_eArgumentError = rb_const_get(rb_cObject, rb_intern("ArgumentError"));
		rb_raise(rb_eArgumentError, "Invalid argument");
	}

	char* tnetstring = StringValueCStr(string);
	char* tnet_end = tnetstring + RSTRING_LEN(string);
	if (!ltns_parse(tnetstring, tnet_end, &ret))
	{
		rb_raise(eInvalidTNetString, "Invalid TNetstring");
	}
	return ret;
}
Пример #9
0
VALUE read_new_reference(unsigned char **pData) {
  if(read_1(pData) != ERL_NEW_REF) {
    rb_raise(rb_eStandardError, "Invalid Type, not a new-style reference");
  }
  
  int size = read_2(pData);
  VALUE node = read_atom(pData);
  VALUE creation = INT2FIX(read_1(pData));
  
  VALUE id = rb_ary_new2(size);
  int i;
  for(i = 0; i < size; ++i) {
    rb_ary_store(id, i, INT2NUM(read_4(pData)));
  }
  
  VALUE newref_class = rb_const_get(mErlectricity, rb_intern("NewReference"));
  return rb_funcall(newref_class, rb_intern("new"), 3, node, creation, id);
}
Пример #10
0
/**
 * Initialize the bson c extension.
 *
 * @since 2.0.0
 */
void Init_native()
{
  // Get all the constants to be used in the extensions.
  VALUE bson = rb_const_get(rb_cObject, rb_intern("BSON"));
  VALUE integer = rb_const_get(bson, rb_intern("Integer"));
  VALUE time = rb_const_get(bson, rb_intern("Time"));
  VALUE int32 = rb_const_get(bson, rb_intern("Int32"));
  VALUE int32_class = rb_singleton_class(int32);
  VALUE int64 = rb_const_get(bson, rb_intern("Int64"));
  VALUE int64_class = rb_singleton_class(int64);
  VALUE object_id = rb_const_get(bson, rb_intern("ObjectId"));
  VALUE generator = rb_const_get(object_id, rb_intern("Generator"));
  VALUE string = rb_const_get(bson, rb_intern("String"));

  // Redefine the serialization methods on the Integer class.
  rb_undef_method(integer, "to_bson_int32");
  rb_define_method(integer, "to_bson_int32", rb_integer_to_bson_int32, 1);
  rb_undef_method(integer, "to_bson_int64");
  rb_define_method(integer, "to_bson_int64", rb_integer_to_bson_int64, 1);

  // Redefine deserialization methods on Int32 class.
  rb_undef_method(int32_class, "from_bson_int32");
  rb_define_private_method(int32_class, "from_bson_int32", rb_integer_from_bson_int32, 1);

  // Redefine deserialization methods on Int64 class.
  rb_undef_method(int64_class, "from_bson_int64");
  rb_define_private_method(int64_class, "from_bson_int64", rb_integer_from_bson_int64, 1);

  // Redefine the serialization methods on the time class.
  rb_undef_method(time, "to_bson_time");
  rb_define_method(time, "to_bson_time", rb_time_to_bson, 2);

  // Redefine the setint32 method on the String class.
  rb_undef_method(string, "setint32");
  rb_define_method(string, "setint32", rb_string_setint32, 2);

  // Setup the machine id for object id generation.
  /* memcpy(rb_bson_machine_id, RSTRING_PTR(machine_id), 16); */
  rb_undef_method(generator, "next");
  rb_define_method(generator, "next", rb_object_id_generator_next, -1);
}
Пример #11
0
void Init_session_ext() {
  curl_global_init(CURL_GLOBAL_ALL);
  rb_require("patron/error");

  mPatron = rb_define_module("Patron");

  ePatronError = rb_const_get(mPatron, rb_intern("Error"));

  eUnsupportedProtocol = rb_const_get(mPatron, rb_intern("UnsupportedProtocol"));
  eURLFormatError = rb_const_get(mPatron, rb_intern("URLFormatError"));
  eHostResolutionError = rb_const_get(mPatron, rb_intern("HostResolutionError"));
  eConnectionFailed = rb_const_get(mPatron, rb_intern("ConnectionFailed"));
  ePartialFileError = rb_const_get(mPatron, rb_intern("PartialFileError"));
  eTimeoutError = rb_const_get(mPatron, rb_intern("TimeoutError"));
  eTooManyRedirects = rb_const_get(mPatron, rb_intern("TooManyRedirects"));

  rb_define_module_function(mPatron, "libcurl_version", libcurl_version, 0);

  cSession = rb_define_class_under(mPatron, "Session", rb_cObject);
  cRequest = rb_define_class_under(mPatron, "Request", rb_cObject);
  rb_define_alloc_func(cSession, session_alloc);

  rb_define_method(cSession, "ext_initialize", session_ext_initialize, 0);
  rb_define_method(cSession, "escape",         session_escape,         1);
  rb_define_method(cSession, "unescape",       session_unescape,       1);
  rb_define_method(cSession, "handle_request", session_handle_request, 1);
  rb_define_method(cSession, "enable_cookie_session", enable_cookie_session, 1);
  rb_define_method(cSession, "set_debug_file", set_debug_file, 1);

  rb_define_const(cRequest, "AuthBasic",  INT2FIX(CURLAUTH_BASIC));
  rb_define_const(cRequest, "AuthDigest", INT2FIX(CURLAUTH_DIGEST));
  rb_define_const(cRequest, "AuthAny",    INT2FIX(CURLAUTH_ANY));

  mProxyType = rb_define_module_under(mPatron, "ProxyType");
  rb_define_const(mProxyType, "HTTP", INT2FIX(CURLPROXY_HTTP));
  rb_define_const(mProxyType, "HTTP_1_0", INT2FIX(CURLPROXY_HTTP_1_0));
  rb_define_const(mProxyType, "SOCKS4", INT2FIX(CURLPROXY_SOCKS4));
  rb_define_const(mProxyType, "SOCKS5", INT2FIX(CURLPROXY_SOCKS5));
  rb_define_const(mProxyType, "SOCKS4A", INT2FIX(CURLPROXY_SOCKS4A));
  rb_define_const(mProxyType, "SOCKS5_HOSTNAME", INT2FIX(CURLPROXY_SOCKS5_HOSTNAME));
}
Пример #12
0
static VALUE
syserr_eqq(VALUE self, VALUE exc)
{
    VALUE num, e;

    if (!rb_obj_is_kind_of(exc, rb_eSystemCallError)) {
	if (!rb_respond_to(exc, id_errno)) return Qfalse;
    }
    else if (self == rb_eSystemCallError) return Qtrue;

    num = rb_attr_get(exc, id_errno);
    if (NIL_P(num)) {
	num = rb_funcallv(exc, id_errno, 0, 0);
    }
    e = rb_const_get(self, id_Errno);
    if (FIXNUM_P(num) ? num == e : rb_equal(num, e))
	return Qtrue;
    return Qfalse;
}
Пример #13
0
VALUE
rb_define_module(const char *name)
{
    VALUE module;
    ID id;

    id = rb_intern(name);
    if (rb_const_defined(rb_cObject, id)) {
	module = rb_const_get(rb_cObject, id);
	if (RB_TYPE_P(module, T_MODULE))
	    return module;
	rb_raise(rb_eTypeError, "%s is not a module", rb_obj_classname(module));
    }
    module = rb_define_module_id(id);
    rb_vm_add_root_module(id, module);
    rb_const_set(rb_cObject, id, module);

    return module;
}
Пример #14
0
void
g_rclosure_attach(GClosure *closure, VALUE object)
{
    static VALUE mGLibObject = (VALUE)NULL;
    GRClosure *rclosure = (GRClosure *)closure;

    G_RELATIVE2(object, Qnil, id_closures, rclosure->rb_holder);

    if (!mGLibObject) {
        mGLibObject = rb_const_get(mGLib, rb_intern("Object"));
    }
    if (rb_obj_is_kind_of(object, mGLibObject)) {
        GObject *gobject;
        gobject = RVAL2GOBJ(object);
        rclosure->count++;
        g_object_weak_ref(gobject, rclosure_weak_notify, rclosure);
        rclosure->objects = g_list_prepend(rclosure->objects, gobject);
    }
}
Пример #15
0
void
Init_objspace(void)
{
    VALUE rb_mObjSpace = rb_const_get(rb_cObject, rb_intern("ObjectSpace"));

    rb_define_module_function(rb_mObjSpace, "memsize_of", memsize_of_m, 1);
    rb_define_module_function(rb_mObjSpace, "memsize_of_all", memsize_of_all_m, -1);

    rb_define_module_function(rb_mObjSpace, "count_objects_size", count_objects_size, -1);
    rb_define_module_function(rb_mObjSpace, "count_nodes", count_nodes, -1);
    rb_define_module_function(rb_mObjSpace, "count_tdata_objects", count_tdata_objects, -1);

    rb_define_module_function(rb_mObjSpace, "reachable_objects_from", reachable_objects_from, 1);

    rb_mInternalObjectWrapper = rb_define_class_under(rb_mObjSpace, "InternalObjectWrapper", rb_cObject);
    rb_define_method(rb_mInternalObjectWrapper, "type", iow_type, 0);
    rb_define_method(rb_mInternalObjectWrapper, "inspect", iow_inspect, 0);
    rb_define_method(rb_mInternalObjectWrapper, "internal_object_id", iow_internal_object_id, 0);
}
Пример #16
0
Файл: ext.c Проект: sebrose/bool
void Init_bool_ext() {
    VALUE rb_mBool; 
    VALUE rb_eStandardError;
    VALUE rb_cBinary;
    VALUE rb_cUnary;

    rb_eStandardError = rb_const_get(rb_cObject, rb_intern("StandardError"));
    rb_mBool = rb_define_module("Bool");
    rb_eParseError = rb_define_class_under(rb_mBool, "ParseError", rb_eStandardError);

    rb_cBinary = rb_define_class_under(rb_mBool, "Binary", rb_cObject);
    rb_cUnary = rb_define_class_under(rb_mBool, "Unary", rb_cObject);
    rb_cVar = rb_define_class_under(rb_mBool, "Var", rb_cObject);
    rb_cAnd = rb_define_class_under(rb_mBool, "And", rb_cBinary);
    rb_cOr  = rb_define_class_under(rb_mBool, "Or", rb_cBinary);
    rb_cNot = rb_define_class_under(rb_mBool, "Not", rb_cUnary);

    rb_define_singleton_method(rb_mBool, "parse", Bool_parse, 1);
}
Пример #17
0
long double 
rbffi_num2longdouble(VALUE value)
{
    if (TYPE(value) == T_FLOAT) {
        return rb_num2dbl(value);
    }
    
    if (!RTEST(rb_cBigDecimal) && rb_const_defined(rb_cObject, rb_intern("BigDecimal"))) {
        rb_cBigDecimal = rb_const_get(rb_cObject, rb_intern("BigDecimal"));
    }

    if (RTEST(rb_cBigDecimal) && rb_cBigDecimal != rb_cObject && RTEST(rb_obj_is_kind_of(value, rb_cBigDecimal))) {
        VALUE s = rb_funcall(value, rb_intern("to_s"), 1, rb_str_new2("E"));
        return strtold(RSTRING_PTR(s), NULL);
    }

    /* Fall through to handling as a float */
    return rb_num2dbl(value);
}
Пример #18
0
void InitReader(VALUE mod) {
    klass_reader = rb_define_class_under(mod, "Reader", rb_cObject);
    rb_global_variable(&klass_reader);
    rb_define_alloc_func(klass_reader, reader_allocate);
    rb_define_method(klass_reader, "feed", reader_feed, 1);
    rb_define_method(klass_reader, "gets", reader_gets, 0);

    /* If the Encoding class is present, #default_external should be used to
     * determine the encoding for new strings. The "enc_default_external"
     * ID is non-zero when encoding should be set on new strings. */
    if (rb_const_defined(rb_cObject, rb_intern("Encoding"))) {
        enc_klass = rb_const_get(rb_cObject, rb_intern("Encoding"));
        enc_default_external = rb_intern("default_external");
        str_force_encoding = rb_intern("force_encoding");
        rb_global_variable(&enc_klass);
    } else {
        enc_default_external = 0;
    }
}
Пример #19
0
static int
load_script(int argc, char **argv)
{
  VALUE r_argv, fname;
  int state, i;

  if (argc < 1) {
    return 0;
  }

  r_argv = rb_const_get(rb_mKernel, rb_intern("ARGV"));
  rb_ary_clear(r_argv);
  for (i = 1; i < argc; i++) {
    rb_ary_push(r_argv, rb_tainted_str_new2(argv[i]));
  }

  fname = rb_funcall(rb_cFile, ExpandPath, 1, rb_str_new2(argv[0]));
  rb_load_protect(fname, 1, &state);
  if (state) {
    VALUE errinfo, errstr, errat;
    int n, i;
    const char *cstr;

    errinfo = rb_errinfo();
    errstr = rb_obj_as_string(errinfo);
    cstr = StringValueCStr(errstr);
    if (strcmp(cstr, "exit")) {
      ngraph_err_puts(cstr);
      errat = rb_funcall(errinfo, rb_intern("backtrace"), 0);
      if (! NIL_P(errat)) {
	n = RARRAY_LEN(errat);
	for (i = 0; i < n; i ++) {
	  errstr = rb_str_new2("\tfrom ");
	  rb_str_append(errstr, rb_ary_entry(errat, i));
	  ngraph_err_puts(StringValueCStr(errstr));
	}
      }
    }
  }
  rb_gc_start();

  return 0;
}
Пример #20
0
void Init_melbourne20(void) {
  VALUE rb_cMelbourne;

  melbourne::init_symbols20();

#ifndef RUBINIUS
  VALUE rb_mRubinius = rb_const_get(rb_cObject, rb_intern("Rubinius"));
#endif

  rb_cMelbourne = rb_define_class_under(rb_mRubinius, "Melbourne", rb_cObject);
  rb_define_method(rb_cMelbourne, "string_to_ast_18",
      RUBY_METHOD_FUNC(melbourne18_string_to_ast), 3);
  rb_define_method(rb_cMelbourne, "file_to_ast_18",
      RUBY_METHOD_FUNC(melbourne18_file_to_ast), 2);
  rb_define_method(rb_cMelbourne, "string_to_ast_19",
      RUBY_METHOD_FUNC(melbourne19_string_to_ast), 3);
  rb_define_method(rb_cMelbourne, "file_to_ast_19",
      RUBY_METHOD_FUNC(melbourne19_file_to_ast), 2);
}
Пример #21
0
static int getButtonArg(VALUE self, int argc, VALUE *argv)
{
	int num;

#ifdef RGSS3
	ID sym;
	rb_get_args(argc, argv, "n", &sym RB_ARG_END);

	if (rb_const_defined(self, sym))
		num = FIX2INT(rb_const_get(self, sym));
	else
		num = 0;
#else
	(void) self;
	rb_get_args(argc, argv, "i", &num RB_ARG_END);
#endif

	return num;
}
Пример #22
0
void Init_cmultibyte() {
  idUnpack = rb_intern("unpack");
  idPack = rb_intern("pack");
  idForceEncoding = rb_intern("force_encoding");

  rb_funcall(rb_cObject, rb_intern("require"), 1, rb_str_new2("active_support/all"));

  ActiveSupport = rb_const_get(rb_cObject, rb_intern("ActiveSupport"));
  Multibyte = rb_const_get_at(ActiveSupport, rb_intern("Multibyte"));
  Unicode = rb_const_get_at(Multibyte, rb_intern("Unicode"));

  VALUE database = rb_funcall(Unicode, rb_intern("database"), 0);
  rb_funcall(database, rb_intern("load"), 0);
  VALUE cp1252_hash = rb_ivar_get(database, rb_intern("@cp1252"));
  cp1252_hash_to_array(cp1252_hash);

  rb_define_singleton_method(Unicode, "tidy_byte", rb_tidy_byte, 1);
  rb_define_singleton_method(Unicode, "tidy_bytes", rb_tidy_bytes, -1);
}
Пример #23
0
static VALUE rbkit_status_as_hash(VALUE self) {
  VALUE status = rb_hash_new();
  VALUE pid = rb_funcall(rb_path2class("Process"), rb_intern("pid"), 0, 0);
  VALUE processName = rb_funcall(rb_path2class("Process"), rb_intern("argv0"), 0, 0);
  VALUE rbkitModule = rb_define_module("Rbkit");
  int object_trace_enabled = (logger && logger->enabled) ? 1 : 0;
  int cpu_profiling_enabled = (logger && logger->sampling_profiler_enabled) ? 1 : 0;

  rb_hash_aset(status, ID2SYM(rb_intern("rbkit_server_version")), rb_const_get(rbkitModule, rb_intern("VERSION")));
  rb_hash_aset(status, ID2SYM(rb_intern("rbkit_protocol_version")), rbkit_protocol_version());
  rb_hash_aset(status, ID2SYM(rb_intern("process_name")), processName);
  rb_hash_aset(status, ID2SYM(rb_intern("pwd")), rb_dir_getwd());
  rb_hash_aset(status, ID2SYM(rb_intern("pid")), pid);
  rb_hash_aset(status, ID2SYM(rb_intern("object_trace_enabled")), INT2FIX(object_trace_enabled));
  rb_hash_aset(status, ID2SYM(rb_intern("cpu_profiling_enabled")), INT2FIX(cpu_profiling_enabled));
  rb_hash_aset(status, ID2SYM(rb_intern("clock_type")), rb_ivar_get(self, rb_intern("@clock_type")));
  rb_hash_aset(status, ID2SYM(rb_intern("cpu_profiling_mode")), rb_ivar_get(self, rb_intern("@cpu_profiling_mode")));
  return status;
}
Пример #24
0
VALUE
rb_define_module(const char *name)
{
    VALUE module;
    ID id;

    id = rb_intern(name);
    if (rb_const_defined(rb_cObject, id)) {
	module = rb_const_get(rb_cObject, id);
	if (TYPE(module) == T_MODULE)
	    return module;
	rb_raise(rb_eTypeError, "%s is not a module", rb_obj_classname(module));
    }
    module = rb_define_module_id(id);
    st_add_direct(rb_class_tbl, id, module);
    rb_const_set(rb_cObject, id, module);

    return module;
}
Пример #25
0
static VALUE
syserr_initialize(int argc, VALUE *argv, VALUE self)
{
#if !defined(_WIN32)
    char *strerror();
#endif
    const char *err;
    VALUE mesg, error;
    VALUE klass = rb_obj_class(self);

    if (klass == rb_eSystemCallError) {
	rb_scan_args(argc, argv, "11", &mesg, &error);
	if (argc == 1 && FIXNUM_P(mesg)) {
	    error = mesg; mesg = Qnil;
	}
	if (!NIL_P(error) && st_lookup(syserr_tbl, NUM2LONG(error), &klass)) {
	    /* change class */
	    if (TYPE(self) != T_OBJECT) { /* insurance to avoid type crash */
		rb_raise(rb_eTypeError, "invalid instance type");
	    }
	    RBASIC(self)->klass = klass;
	}
    }
    else {
	rb_scan_args(argc, argv, "01", &mesg);
	error = rb_const_get(klass, rb_intern("Errno"));
    }
    if (!NIL_P(error)) err = strerror(NUM2INT(error));
    else err = "unknown error";
    if (!NIL_P(mesg)) {
	VALUE str = mesg;

	StringValue(str);
	mesg = rb_sprintf("%s - %.*s", err,
			  (int)RSTRING_LEN(str), RSTRING_PTR(str));
    }
    else {
	mesg = rb_str_new2(err);
    }
    rb_call_super(1, &mesg);
    rb_iv_set(self, "errno", error);
    return self;
}
Пример #26
0
/* This converts a 3x3 array of doubles into a ruby matrix, or into
 * nil for the case of an invalid dbl_array
 */
VALUE double3x3_to_matrix_rb(double m3x3[][3]) {
  if (!m3x3) return Qnil;

  // To compose a Matrix, we need a 3x3 array of floats:
  VALUE aryRet = rb_ary_new2(3);
  for (unsigned int i=0; i < 3; i++) {
    VALUE arRow = rb_ary_new2(3);

    for (unsigned int j=0; j < 3; j++)
      rb_ary_store(arRow, j, rb_float_new(m3x3[i][j]));

    rb_ary_store(aryRet, i, arRow);
  }

  VALUE c_Matrix = rb_const_get( rb_cObject, rb_intern("Matrix") );
  VALUE rbMatrixRet = rb_funcall(c_Matrix, rb_intern("rows"), 2, aryRet, Qfalse);     
  
  return rbMatrixRet;  
}
Пример #27
0
/*
 *  Extern:     rm_get_geometry
 *  Purpose:    Get the values from a Geometry object and return
 *              them in C variables.
*/
void
rm_get_geometry(
    VALUE geom,
    long *x,
    long *y,
    unsigned long *width,
    unsigned long *height,
    int *flag)
{
    VALUE v;

    v = rb_funcall(geom, rm_ID_x, 0);
    *x = NUM2LONG(v);
    v = rb_funcall(geom, rm_ID_y, 0);
    *y = NUM2LONG(v);
    v = rb_funcall(geom, rm_ID_width, 0);
    *width = NUM2ULONG(v);
    v = rb_funcall(geom, rm_ID_height, 0);
    *height = NUM2ULONG(v);

    // Getting the flag field is a bit more difficult since it's
    // supposed to be an instance of the GeometryValue Enum class. We
    // may not know the VALUE for the GeometryValue class, and we
    // need to check that the flag field is an instance of that class.
    if (flag)
    {
        MagickEnum *magick_enum;

        v = rb_funcall(geom, rm_ID_flag, 0);
        if (!Class_GeometryValue)
        {
            Class_GeometryValue = rb_const_get(Module_Magick, rm_ID_GeometryValue);
        }
        if (CLASS_OF(v) != Class_GeometryValue)
        {
            rb_raise(rb_eTypeError, "wrong enumeration type - expected %s, got %s"
                        , rb_class2name(Class_GeometryValue),rb_class2name(CLASS_OF(v)));
        }
        Data_Get_Struct(v, MagickEnum, magick_enum);
        *flag = magick_enum->val;
    }

}
Пример #28
0
VALUE read_list(unsigned char **pData) {
  if(read_1(pData) != ERL_LIST) {
    rb_raise(rb_eStandardError, "Invalid Type, not an erlang list");
  }

  unsigned int size = read_4(pData);

  VALUE newref_class = rb_const_get(mErlectricity, rb_intern("List"));
  VALUE array = rb_funcall(newref_class, rb_intern("new"), 1, INT2NUM(size));

  int i;
  for(i = 0; i < size; ++i) {
    rb_ary_store(array, i, read_any_raw(pData));
  }

  read_1(pData);

  return array;
}
Пример #29
0
void
Init_gnome_print_unit(VALUE mGnome)
{
    VALUE cUnit = G_DEF_CLASS(GNOME_TYPE_PRINT_UNIT, "PrintUnit", mGnome);
    VALUE cBase;
  
    cBase = G_DEF_CLASS(GNOME_TYPE_PRINT_PRINT_UNIT_BASE,
                        "PrintUnitBase", mGnome);

    G_DEF_CONSTANTS(cUnit, GNOME_TYPE_PRINT_PRINT_UNIT_BASE, "GNOME_PRINT_");
 
    rb_define_const(cUnit, "PS_UNIT", CONST_GPU2RVAL(GNOME_PRINT_PS_UNIT));
 
    rb_define_const(cUnit,
                    "UNIT_ALL",
                    rb_funcall(cBase,
                               rb_intern("new"),
                               1,
                               GPUB2RVAL(GNOME_PRINT_UNITS_ALL)));
    rb_define_const(cBase, "ALL", rb_const_get(cUnit, rb_intern("UNIT_ALL")));

    rb_define_method(cUnit, "version", gp_unit_get_version, 0);
    rb_define_method(cUnit, "base", gp_unit_get_base, 0);
    rb_define_method(cUnit, "unit_to_base", gp_unit_get_unittobase, 0);
    rb_define_method(cUnit, "name", gp_unit_get_name, 0);
    rb_define_method(cUnit, "abbr", gp_unit_get_abbr, 0);
    rb_define_method(cUnit, "plural", gp_unit_get_plural, 0);
    rb_define_method(cUnit, "abbr_plural", gp_unit_get_abbr_plural, 0);
  
    rb_define_module_function(cUnit, "get_identity", gp_unit_get_identity, 1);
    rb_define_module_function(cUnit, "default", gp_unit_get_default, 0);
    rb_define_module_function(cUnit, "get_by_name", gp_unit_get_by_name, 1);
    rb_define_module_function(cUnit, "get_by_abbreviation",
                              gp_unit_get_by_abbreviation, 1);
    rb_define_module_function(cUnit, "get_list", gp_unit_get_list, 1);


    /* Utility */
    rb_define_method(cUnit, "convert_distance",
                     gp_generic_convert_distance, -1);
    rb_define_method(cUnit, "convert_distance_full",
                     gp_convert_distance_full, 4);
}
Пример #30
0
static VALUE con_set_rounding(VALUE self, VALUE new_rounding) {
  decContext *self_ptr;
  enum rounding round;
  VALUE rounding_numbers;

  Data_Get_Struct(self, decContext, self_ptr);

  if ( SYMBOL_P( new_rounding ) ) {
    rounding_numbers = rb_const_get( cDecContext, rb_intern("ROUNDING_NUMBERS") );
    new_rounding = rb_hash_aref( rounding_numbers, new_rounding );
  }
  if( ! FIXNUM_P( new_rounding ) ) {
    rb_raise(rb_eTypeError, "wrong argument type");
  }

  round = FIX2INT(new_rounding);
  decContextSetRounding(self_ptr,round);
  return new_rounding;
}