Use functions that take symbols to reduce string litrals in C.
MODIFY
mrbgems/mruby-complex/src/complex.c
mrbgems/mruby-complex/src/complex.c
@@ -69,7 +69,7 @@ complex_ptr(mrb_state *mrb, mrb_value v)
static mrb_value
complex_new(mrb_state *mrb, mrb_float real, mrb_float imaginary)
{
- struct RClass *c = mrb_class_get(mrb, "Complex");
+ struct RClass *c = mrb_class_get_id(mrb, MRB_SYM(Complex));
struct mrb_complex *p;
struct RBasic *comp = complex_alloc(mrb, c, &p);
p->real = real;
@@ -224,7 +224,7 @@ void mrb_mruby_complex_gem_init(mrb_state *mrb)
#ifdef COMPLEX_USE_ISTRUCT
mrb_assert(sizeof(struct mrb_complex) < ISTRUCT_DATA_SIZE);
#endif
- comp = mrb_define_class(mrb, "Complex", mrb_class_get(mrb, "Numeric"));
+ comp = mrb_define_class(mrb, "Complex", mrb_class_get_id(mrb, MRB_SYM(Numeric)));
#ifdef COMPLEX_USE_ISTRUCT
MRB_SET_INSTANCE_TT(comp, MRB_TT_ISTRUCT);
#else

MODIFY
mrbgems/mruby-eval/src/eval.c
mrbgems/mruby-eval/src/eval.c
@@ -179,7 +179,7 @@ void
mrb_mruby_eval_gem_init(mrb_state* mrb)
{
mrb_define_module_function(mrb, mrb->kernel_module, "eval", f_eval, MRB_ARGS_ARG(1, 3));
- mrb_define_method(mrb, mrb_class_get(mrb, "BasicObject"), "instance_eval", f_instance_eval, MRB_ARGS_OPT(3)|MRB_ARGS_BLOCK());
+ mrb_define_method(mrb, mrb_class_get_id(mrb, MRB_SYM(BasicObject)), "instance_eval", f_instance_eval, MRB_ARGS_OPT(3)|MRB_ARGS_BLOCK());
}
void

MODIFY
mrbgems/mruby-io/src/file.c
mrbgems/mruby-io/src/file.c
@@ -614,36 +614,36 @@ mrb_init_file(mrb_state *mrb)
mrb_define_method(mrb, file, "size", mrb_file_size, MRB_ARGS_NONE());
mrb_define_method(mrb, file, "truncate", mrb_file_truncate, MRB_ARGS_REQ(1));
- cnst = mrb_define_module_under(mrb, file, "Constants");
- mrb_define_const(mrb, cnst, "LOCK_SH", mrb_fixnum_value(LOCK_SH));
- mrb_define_const(mrb, cnst, "LOCK_EX", mrb_fixnum_value(LOCK_EX));
- mrb_define_const(mrb, cnst, "LOCK_UN", mrb_fixnum_value(LOCK_UN));
- mrb_define_const(mrb, cnst, "LOCK_NB", mrb_fixnum_value(LOCK_NB));
- mrb_define_const(mrb, cnst, "SEPARATOR", mrb_str_new_cstr(mrb, FILE_SEPARATOR));
- mrb_define_const(mrb, cnst, "PATH_SEPARATOR", mrb_str_new_cstr(mrb, PATH_SEPARATOR));
+ cnst = mrb_define_module_under_id(mrb, file, MRB_SYM(Constants));
+ mrb_define_const_id(mrb, cnst, MRB_SYM(LOCK_SH), mrb_fixnum_value(LOCK_SH));
+ mrb_define_const_id(mrb, cnst, MRB_SYM(LOCK_EX), mrb_fixnum_value(LOCK_EX));
+ mrb_define_const_id(mrb, cnst, MRB_SYM(LOCK_UN), mrb_fixnum_value(LOCK_UN));
+ mrb_define_const_id(mrb, cnst, MRB_SYM(LOCK_NB), mrb_fixnum_value(LOCK_NB));
+ mrb_define_const_id(mrb, cnst, MRB_SYM(SEPARATOR), mrb_str_new_cstr(mrb, FILE_SEPARATOR));
+ mrb_define_const_id(mrb, cnst, MRB_SYM(PATH_SEPARATOR), mrb_str_new_cstr(mrb, PATH_SEPARATOR));
#if defined(_WIN32) || defined(_WIN64)
- mrb_define_const(mrb, cnst, "ALT_SEPARATOR", mrb_str_new_cstr(mrb, FILE_ALT_SEPARATOR));
+ mrb_define_const_id(mrb, cnst, MRB_SYM(ALT_SEPARATOR), mrb_str_new_cstr(mrb, FILE_ALT_SEPARATOR));
#else
- mrb_define_const(mrb, cnst, "ALT_SEPARATOR", mrb_nil_value());
+ mrb_define_const_id(mrb, cnst, MRB_SYM(ALT_SEPARATOR), mrb_nil_value());
#endif
- mrb_define_const(mrb, cnst, "NULL", mrb_str_new_cstr(mrb, NULL_FILE));
-
- mrb_define_const(mrb, cnst, "RDONLY", mrb_fixnum_value(MRB_O_RDONLY));
- mrb_define_const(mrb, cnst, "WRONLY", mrb_fixnum_value(MRB_O_WRONLY));
- mrb_define_const(mrb, cnst, "RDWR", mrb_fixnum_value(MRB_O_RDWR));
- mrb_define_const(mrb, cnst, "APPEND", mrb_fixnum_value(MRB_O_APPEND));
- mrb_define_const(mrb, cnst, "CREAT", mrb_fixnum_value(MRB_O_CREAT));
- mrb_define_const(mrb, cnst, "EXCL", mrb_fixnum_value(MRB_O_EXCL));
- mrb_define_const(mrb, cnst, "TRUNC", mrb_fixnum_value(MRB_O_TRUNC));
- mrb_define_const(mrb, cnst, "NONBLOCK", mrb_fixnum_value(MRB_O_NONBLOCK));
- mrb_define_const(mrb, cnst, "NOCTTY", mrb_fixnum_value(MRB_O_NOCTTY));
- mrb_define_const(mrb, cnst, "BINARY", mrb_fixnum_value(MRB_O_BINARY));
- mrb_define_const(mrb, cnst, "SHARE_DELETE", mrb_fixnum_value(MRB_O_SHARE_DELETE));
- mrb_define_const(mrb, cnst, "SYNC", mrb_fixnum_value(MRB_O_SYNC));
- mrb_define_const(mrb, cnst, "DSYNC", mrb_fixnum_value(MRB_O_DSYNC));
- mrb_define_const(mrb, cnst, "RSYNC", mrb_fixnum_value(MRB_O_RSYNC));
- mrb_define_const(mrb, cnst, "NOFOLLOW", mrb_fixnum_value(MRB_O_NOFOLLOW));
- mrb_define_const(mrb, cnst, "NOATIME", mrb_fixnum_value(MRB_O_NOATIME));
- mrb_define_const(mrb, cnst, "DIRECT", mrb_fixnum_value(MRB_O_DIRECT));
- mrb_define_const(mrb, cnst, "TMPFILE", mrb_fixnum_value(MRB_O_TMPFILE));
+ mrb_define_const_id(mrb, cnst, MRB_SYM(NULL), mrb_str_new_cstr(mrb, NULL_FILE));
+
+ mrb_define_const_id(mrb, cnst, MRB_SYM(RDONLY), mrb_fixnum_value(MRB_O_RDONLY));
+ mrb_define_const_id(mrb, cnst, MRB_SYM(WRONLY), mrb_fixnum_value(MRB_O_WRONLY));
+ mrb_define_const_id(mrb, cnst, MRB_SYM(RDWR), mrb_fixnum_value(MRB_O_RDWR));
+ mrb_define_const_id(mrb, cnst, MRB_SYM(APPEND), mrb_fixnum_value(MRB_O_APPEND));
+ mrb_define_const_id(mrb, cnst, MRB_SYM(CREAT), mrb_fixnum_value(MRB_O_CREAT));
+ mrb_define_const_id(mrb, cnst, MRB_SYM(EXCL), mrb_fixnum_value(MRB_O_EXCL));
+ mrb_define_const_id(mrb, cnst, MRB_SYM(TRUNC), mrb_fixnum_value(MRB_O_TRUNC));
+ mrb_define_const_id(mrb, cnst, MRB_SYM(NONBLOCK), mrb_fixnum_value(MRB_O_NONBLOCK));
+ mrb_define_const_id(mrb, cnst, MRB_SYM(NOCTTY), mrb_fixnum_value(MRB_O_NOCTTY));
+ mrb_define_const_id(mrb, cnst, MRB_SYM(BINARY), mrb_fixnum_value(MRB_O_BINARY));
+ mrb_define_const_id(mrb, cnst, MRB_SYM(SHARE_DELETE), mrb_fixnum_value(MRB_O_SHARE_DELETE));
+ mrb_define_const_id(mrb, cnst, MRB_SYM(SYNC), mrb_fixnum_value(MRB_O_SYNC));
+ mrb_define_const_id(mrb, cnst, MRB_SYM(DSYNC), mrb_fixnum_value(MRB_O_DSYNC));
+ mrb_define_const_id(mrb, cnst, MRB_SYM(RSYNC), mrb_fixnum_value(MRB_O_RSYNC));
+ mrb_define_const_id(mrb, cnst, MRB_SYM(NOFOLLOW), mrb_fixnum_value(MRB_O_NOFOLLOW));
+ mrb_define_const_id(mrb, cnst, MRB_SYM(NOATIME), mrb_fixnum_value(MRB_O_NOATIME));
+ mrb_define_const_id(mrb, cnst, MRB_SYM(DIRECT), mrb_fixnum_value(MRB_O_DIRECT));
+ mrb_define_const_id(mrb, cnst, MRB_SYM(TMPFILE), mrb_fixnum_value(MRB_O_TMPFILE));
}

MODIFY
mrbgems/mruby-io/src/io.c
mrbgems/mruby-io/src/io.c
@@ -102,10 +102,10 @@ io_set_process_status(mrb_state *mrb, pid_t pid, int status)
mrb_value v;
c_status = NULL;
- if (mrb_class_defined(mrb, "Process")) {
- c_process = mrb_module_get(mrb, "Process");
- if (mrb_const_defined(mrb, mrb_obj_value(c_process), mrb_intern_cstr(mrb, "Status"))) {
- c_status = mrb_class_get_under(mrb, c_process, "Status");
+ if (mrb_class_defined_id(mrb, MRB_SYM(Process))) {
+ c_process = mrb_module_get_id(mrb, MRB_SYM(Process));
+ if (mrb_const_defined(mrb, mrb_obj_value(c_process), MRB_SYM(Status))) {
+ c_status = mrb_class_get_under_id(mrb, c_process, MRB_SYM(Status));
}
}
if (c_status != NULL) {

MODIFY
mrbgems/mruby-math/src/math.c
mrbgems/mruby-math/src/math.c
static void
domain_error(mrb_state *mrb, const char *func)
{
- struct RClass *math = mrb_module_get(mrb, "Math");
- struct RClass *domainerror = mrb_class_get_under(mrb, math, "DomainError");
+ struct RClass *math = mrb_module_get_id(mrb, MRB_SYM(Math));
+ struct RClass *domainerror = mrb_class_get_under_id(mrb, math, MRB_SYM(DomainError));
mrb_raisef(mrb, domainerror, "Numerical argument is out of domain - %s", func);
}
@@ -730,18 +730,18 @@ mrb_mruby_math_gem_init(mrb_state* mrb)
struct RClass *mrb_math;
mrb_math = mrb_define_module(mrb, "Math");
- mrb_define_class_under(mrb, mrb_math, "DomainError", mrb->eStandardError_class);
+ mrb_define_class_under_id(mrb, mrb_math, MRB_SYM(DomainError), mrb->eStandardError_class);
#ifdef M_PI
- mrb_define_const(mrb, mrb_math, "PI", mrb_float_value(mrb, M_PI));
+ mrb_define_const_id(mrb, mrb_math, MRB_SYM(PI), mrb_float_value(mrb, M_PI));
#else
- mrb_define_const(mrb, mrb_math, "PI", mrb_float_value(mrb, atan(1.0)*4.0));
+ mrb_define_const_id(mrb, mrb_math, MRB_SYM(PI), mrb_float_value(mrb, atan(1.0)*4.0));
#endif
#ifdef M_E
- mrb_define_const(mrb, mrb_math, "E", mrb_float_value(mrb, M_E));
+ mrb_define_const_id(mrb, mrb_math, MRB_SYM(E), mrb_float_value(mrb, M_E));
#else
- mrb_define_const(mrb, mrb_math, "E", mrb_float_value(mrb, exp(1.0)));
+ mrb_define_const_id(mrb, mrb_math, MRB_SYM(E), mrb_float_value(mrb, exp(1.0)));
#endif
mrb_define_module_function(mrb, mrb_math, "sin", math_sin, MRB_ARGS_REQ(1));

MODIFY
mrbgems/mruby-method/src/method.c
mrbgems/mruby-method/src/method.c
@@ -36,7 +36,7 @@ unbound_method_bind(mrb_state *mrb, mrb_value self)
mrb_value recv = mrb_get_arg1(mrb);
bind_check(mrb, recv, owner);
- me = method_object_alloc(mrb, mrb_class_get(mrb, "Method"));
+ me = method_object_alloc(mrb, mrb_class_get_id(mrb, MRB_SYM(Method)));
mrb_obj_iv_set(mrb, me, MRB_SYM(_owner), owner);
mrb_obj_iv_set(mrb, me, MRB_SYM(_recv), recv);
mrb_obj_iv_set(mrb, me, MRB_SYM(_name), name);

MODIFY
mrbgems/mruby-numeric-ext/src/numeric_ext.c
mrbgems/mruby-numeric-ext/src/numeric_ext.c
@@ -60,16 +60,16 @@ mrb_mruby_numeric_ext_gem_init(mrb_state* mrb)
mrb_define_method(mrb, i, "nobits?", mrb_int_nobits, MRB_ARGS_REQ(1));
#ifndef MRB_WITHOUT_FLOAT
- mrb_define_const(mrb, mrb->float_class, "RADIX", mrb_fixnum_value(MRB_FLT_RADIX));
- mrb_define_const(mrb, mrb->float_class, "MANT_DIG", mrb_fixnum_value(MRB_FLT_MANT_DIG));
- mrb_define_const(mrb, mrb->float_class, "EPSILON", mrb_float_value(mrb, MRB_FLT_EPSILON));
- mrb_define_const(mrb, mrb->float_class, "DIG", mrb_fixnum_value(MRB_FLT_DIG));
- mrb_define_const(mrb, mrb->float_class, "MIN_EXP", mrb_fixnum_value(MRB_FLT_MIN_EXP));
- mrb_define_const(mrb, mrb->float_class, "MIN", mrb_float_value(mrb, MRB_FLT_MIN));
- mrb_define_const(mrb, mrb->float_class, "MIN_10_EXP", mrb_fixnum_value(MRB_FLT_MIN_10_EXP));
- mrb_define_const(mrb, mrb->float_class, "MAX_EXP", mrb_fixnum_value(MRB_FLT_MAX_EXP));
- mrb_define_const(mrb, mrb->float_class, "MAX", mrb_float_value(mrb, MRB_FLT_MAX));
- mrb_define_const(mrb, mrb->float_class, "MAX_10_EXP", mrb_fixnum_value(MRB_FLT_MAX_10_EXP));
+ mrb_define_const_id(mrb, mrb->float_class, MRB_SYM(RADIX), mrb_fixnum_value(MRB_FLT_RADIX));
+ mrb_define_const_id(mrb, mrb->float_class, MRB_SYM(MANT_DIG), mrb_fixnum_value(MRB_FLT_MANT_DIG));
+ mrb_define_const_id(mrb, mrb->float_class, MRB_SYM(EPSILON), mrb_float_value(mrb, MRB_FLT_EPSILON));
+ mrb_define_const_id(mrb, mrb->float_class, MRB_SYM(DIG), mrb_fixnum_value(MRB_FLT_DIG));
+ mrb_define_const_id(mrb, mrb->float_class, MRB_SYM(MIN_EXP), mrb_fixnum_value(MRB_FLT_MIN_EXP));
+ mrb_define_const_id(mrb, mrb->float_class, MRB_SYM(MIN), mrb_float_value(mrb, MRB_FLT_MIN));
+ mrb_define_const_id(mrb, mrb->float_class, MRB_SYM(MIN_10_EXP), mrb_fixnum_value(MRB_FLT_MIN_10_EXP));
+ mrb_define_const_id(mrb, mrb->float_class, MRB_SYM(MAX_EXP), mrb_fixnum_value(MRB_FLT_MAX_EXP));
+ mrb_define_const_id(mrb, mrb->float_class, MRB_SYM(MAX), mrb_float_value(mrb, MRB_FLT_MAX));
+ mrb_define_const_id(mrb, mrb->float_class, MRB_SYM(MAX_10_EXP), mrb_fixnum_value(MRB_FLT_MAX_10_EXP));
#endif /* MRB_WITHOUT_FLOAT */
}

MODIFY
mrbgems/mruby-object-ext/src/object.c
mrbgems/mruby-object-ext/src/object.c
@@ -123,7 +123,7 @@ mrb_mruby_object_ext_gem_init(mrb_state* mrb)
mrb_define_method(mrb, mrb->kernel_module, "itself", mrb_f_itself, MRB_ARGS_NONE());
- mrb_define_method(mrb, mrb_class_get(mrb, "BasicObject"), "instance_exec", mrb_obj_instance_exec, MRB_ARGS_ANY() | MRB_ARGS_BLOCK());
+ mrb_define_method(mrb, mrb_class_get_id(mrb, MRB_SYM(BasicObject)), "instance_exec", mrb_obj_instance_exec, MRB_ARGS_ANY() | MRB_ARGS_BLOCK());
}
void

MODIFY
mrbgems/mruby-random/src/random.c
mrbgems/mruby-random/src/random.c
@@ -135,7 +135,7 @@ get_opt(mrb_state* mrb)
static void
random_check(mrb_state *mrb, mrb_value random) {
- struct RClass *c = mrb_class_get(mrb, "Random");
+ struct RClass *c = mrb_class_get_id(mrb, MRB_SYM(Random));
if (!mrb_obj_is_kind_of(mrb, random, c) || !mrb_istruct_p(random)) {
mrb_raise(mrb, E_TYPE_ERROR, "Random instance required");
}

MODIFY
mrbgems/mruby-socket/src/socket.c
mrbgems/mruby-socket/src/socket.c
#endif
#endif
-#define E_SOCKET_ERROR (mrb_class_get(mrb, "SocketError"))
+#define E_SOCKET_ERROR mrb_class_get_id(mrb, MRB_SYM(SocketError))
#if !defined(mrb_cptr)
#define mrb_cptr_value(m,p) mrb_voidp_value((m),(p))
@@ -347,7 +347,7 @@ mrb_basicsocket_getsockopt(mrb_state *mrb, mrb_value self)
optlen = sizeof(opt);
if (getsockopt(s, (int)level, (int)optname, opt, &optlen) == -1)
mrb_sys_fail(mrb, "getsockopt");
- c = mrb_const_get(mrb, mrb_obj_value(mrb_class_get(mrb, "Socket")), MRB_SYM(Option));
+ c = mrb_const_get(mrb, mrb_obj_value(mrb_class_get_id(mrb, MRB_SYM(Socket))), MRB_SYM(Option));
family = socket_family(s);
data = mrb_str_new(mrb, opt, optlen);
return mrb_funcall_id(mrb, c, MRB_SYM(new), 4, mrb_fixnum_value(family), mrb_fixnum_value(level), mrb_fixnum_value(optname), data);
@@ -869,7 +869,7 @@ mrb_mruby_socket_gem_init(mrb_state* mrb)
mrb_define_method(mrb, ai, "unix_path", mrb_addrinfo_unix_path, MRB_ARGS_NONE());
#endif
- io = mrb_class_get(mrb, "IO");
+ io = mrb_class_get_id(mrb, MRB_SYM(IO));
bsock = mrb_define_class(mrb, "BasicSocket", io);
mrb_define_method(mrb, bsock, "_recvfrom", mrb_basicsocket_recvfrom, MRB_ARGS_REQ(1)|MRB_ARGS_OPT(1));
@@ -948,7 +948,7 @@ void
mrb_mruby_socket_gem_final(mrb_state* mrb)
{
mrb_value ai;
- ai = mrb_mod_cv_get(mrb, mrb_class_get(mrb, "Addrinfo"), MRB_SYM(_lastai));
+ ai = mrb_mod_cv_get(mrb, mrb_class_get_id(mrb, MRB_SYM(Addrinfo)), MRB_SYM(_lastai));
if (mrb_cptr_p(ai)) {
freeaddrinfo((struct addrinfo*)mrb_cptr(ai));
}

MODIFY
mrbgems/mruby-struct/src/struct.c
mrbgems/mruby-struct/src/struct.c
static struct RClass *
struct_class(mrb_state *mrb)
{
- return mrb_class_get(mrb, "Struct");
+ return mrb_class_get_id(mrb, MRB_SYM(Struct));
}
static inline mrb_value

MODIFY
mrbgems/mruby-time/src/time.c
mrbgems/mruby-time/src/time.c
@@ -420,7 +420,7 @@ mrb_time_now(mrb_state *mrb, mrb_value self)
MRB_API mrb_value
mrb_time_at(mrb_state *mrb, time_t sec, time_t usec, enum mrb_timezone zone)
{
- return mrb_time_make_time(mrb, mrb_class_get(mrb, "Time"), sec, usec, zone);
+ return mrb_time_make_time(mrb, mrb_class_get_id(mrb, MRB_SYM(Time)), sec, usec, zone);
}
/* 15.2.19.6.1 */

MODIFY
src/class.c
src/class.c
@@ -2353,10 +2353,10 @@ mrb_init_class(mrb_state *mrb)
make_metaclass(mrb, cls);
/* name basic classes */
- mrb_define_const(mrb, bob, "BasicObject", mrb_obj_value(bob));
- mrb_define_const(mrb, obj, "Object", mrb_obj_value(obj));
- mrb_define_const(mrb, obj, "Module", mrb_obj_value(mod));
- mrb_define_const(mrb, obj, "Class", mrb_obj_value(cls));
+ mrb_define_const_id(mrb, bob, MRB_SYM(BasicObject), mrb_obj_value(bob));
+ mrb_define_const_id(mrb, obj, MRB_SYM(Object), mrb_obj_value(obj));
+ mrb_define_const_id(mrb, obj, MRB_SYM(Module), mrb_obj_value(mod));
+ mrb_define_const_id(mrb, obj, MRB_SYM(Class), mrb_obj_value(cls));
/* name each classes */
mrb_class_name_class(mrb, NULL, bob, MRB_SYM(BasicObject));

MODIFY
src/numeric.c
src/numeric.c
@@ -1688,10 +1688,10 @@ mrb_init_numeric(mrb_state *mrb)
mrb_define_method(mrb, fl, "nan?", flo_nan_p, MRB_ARGS_NONE());
#ifdef INFINITY
- mrb_define_const(mrb, fl, "INFINITY", mrb_float_value(mrb, INFINITY));
+ mrb_define_const_id(mrb, fl, MRB_SYM(INFINITY), mrb_float_value(mrb, INFINITY));
#endif
#ifdef NAN
- mrb_define_const(mrb, fl, "NAN", mrb_float_value(mrb, NAN));
+ mrb_define_const_id(mrb, fl, MRB_SYM(NAN), mrb_float_value(mrb, NAN));
#endif
mrb_include_module(mrb, fl, integral);

Use functions that take symbols to reduce string litrals in C.