From 075530a6850ebf899e8874d7675fd900577c9554 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 31 May 2008 09:28:20 +0000 Subject: [PATCH] * suppress warnings with -Wwrite-string. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16716 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ compile.c | 4 ++-- dir.c | 2 +- eval.c | 2 +- eval_error.c | 4 ++-- include/ruby/intern.h | 2 +- include/ruby/ruby.h | 4 ++-- insns.def | 2 +- io.c | 8 ++++---- iseq.c | 2 +- keywords | 2 +- lex.c.blt | 2 +- lex.c.src | 2 +- marshal.c | 2 +- math.c | 2 +- missing/vsnprintf.c | 27 ++++++++++++++------------- object.c | 11 +++++------ pack.c | 4 ++-- proc.c | 4 ++-- re.c | 2 +- regerror.c | 2 +- ruby.c | 2 +- string.c | 3 ++- struct.c | 4 ++-- thread.c | 6 +++--- time.c | 2 +- util.c | 2 +- variable.c | 4 ++-- vm_dump.c | 1 - vm_eval.c | 6 +++--- vm_method.c | 2 +- 31 files changed, 65 insertions(+), 61 deletions(-) diff --git a/ChangeLog b/ChangeLog index d3fcb18335..5f7f90d898 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Sat May 31 18:28:17 2008 Nobuyoshi Nakada + + * suppress warnings with -Wwrite-string. + Sat May 31 18:26:33 2008 Yukihiro Matsumoto * array.c (rb_ary_delete_if): should return enumerator if no block diff --git a/compile.c b/compile.c index f92f58cb64..7362a0e6a5 100644 --- a/compile.c +++ b/compile.c @@ -134,7 +134,7 @@ static int iseq_set_optargs_table(rb_iseq_t *iseq); */ static void -verify_list(ISEQ_ARG_DECLARE char *info, LINK_ANCHOR *anchor) +verify_list(ISEQ_ARG_DECLARE const char *info, LINK_ANCHOR *anchor) { #if CPDEBUG int flag = 0; @@ -2302,7 +2302,7 @@ static int defined_expr(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE *node, LABEL **lfinish, VALUE needstr) { - char *estr = 0; + const char *estr = 0; enum node_type type; switch (type = nd_type(node)) { diff --git a/dir.c b/dir.c index 672720167c..7958d685cd 100644 --- a/dir.c +++ b/dir.c @@ -458,7 +458,7 @@ dir_inspect(VALUE dir) Data_Get_Struct(dir, struct dir_data, dirp); if (dirp->path) { - char *c = rb_obj_classname(dir); + const char *c = rb_obj_classname(dir); int len = strlen(c) + strlen(dirp->path) + 4; VALUE s = rb_str_new(0, len); snprintf(RSTRING_PTR(s), len+1, "#<%s:%s>", c, dirp->path); diff --git a/eval.c b/eval.c index c594f5b56c..76b0f35cdc 100644 --- a/eval.c +++ b/eval.c @@ -326,7 +326,7 @@ rb_mod_s_constants(int argc, VALUE *argv, VALUE mod) void rb_frozen_class_p(VALUE klass) { - char *desc = "something(?!)"; + const char *desc = "something(?!)"; if (OBJ_FROZEN(klass)) { if (FL_TEST(klass, FL_SINGLETON)) diff --git a/eval_error.c b/eval_error.c index d22b865e19..622ae4fdd9 100644 --- a/eval_error.c +++ b/eval_error.c @@ -69,7 +69,7 @@ error_print(void) VALUE errat = Qnil; /* OK */ VALUE errinfo = GET_THREAD()->errinfo; volatile VALUE eclass, e; - char *einfo; + const char *einfo; long elen; if (NIL_P(errinfo)) @@ -188,7 +188,7 @@ ruby_error_print(void) void rb_print_undef(VALUE klass, ID id, int scope) { - char *v; + const char *v; switch (scope) { default: diff --git a/include/ruby/intern.h b/include/ruby/intern.h index b95f2d02d3..7de34b1e8d 100644 --- a/include/ruby/intern.h +++ b/include/ruby/intern.h @@ -583,7 +583,7 @@ VALUE rb_struct_iv_get(VALUE, const char*); VALUE rb_struct_s_members(VALUE); VALUE rb_struct_members(VALUE); VALUE rb_struct_alloc_noinit(VALUE); -VALUE rb_struct_define_without_accessor(char *, VALUE, rb_alloc_func_t, ...); +VALUE rb_struct_define_without_accessor(const char *, VALUE, rb_alloc_func_t, ...); /* thread.c */ typedef void rb_unblock_function_t(void *); typedef VALUE rb_blocking_function_t(void *); diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index 307bd1c820..db6f98023a 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -778,8 +778,8 @@ VALUE rb_id2str(ID); rb_intern(str)) #endif -char *rb_class2name(VALUE); -char *rb_obj_classname(VALUE); +const char *rb_class2name(VALUE); +const char *rb_obj_classname(VALUE); void rb_p(VALUE); diff --git a/insns.def b/insns.def index 348f956ed6..4e45d5e532 100644 --- a/insns.def +++ b/insns.def @@ -775,7 +775,7 @@ defined (VALUE val) { VALUE klass; - char *expr_type = 0; + const char *expr_type = 0; val = Qnil; switch (type) { diff --git a/io.c b/io.c index 88074cbd54..88811a9387 100644 --- a/io.c +++ b/io.c @@ -1248,7 +1248,7 @@ static VALUE rb_io_inspect(VALUE obj) { rb_io_t *fptr; - char *cname; + const char *cname; const char *st = ""; fptr = RFILE(rb_io_taint_check(obj))->fptr; @@ -5057,7 +5057,7 @@ static VALUE rb_io_s_new(int argc, VALUE *argv, VALUE klass) { if (rb_block_given_p()) { - char *cname = rb_class2name(klass); + const char *cname = rb_class2name(klass); rb_warn("%s::new() does not take block; use %s::open() instead", cname, cname); @@ -6345,9 +6345,9 @@ struct copy_stream_struct { int close_src; int close_dst; off_t total; - char *syserr; + const char *syserr; int error_no; - char *notimp; + const char *notimp; rb_fdset_t fds; rb_thread_t *th; }; diff --git a/iseq.c b/iseq.c index 030927ab37..9e6cf56d16 100644 --- a/iseq.c +++ b/iseq.c @@ -774,7 +774,7 @@ ruby_iseq_disasm_insn(VALUE ret, VALUE *iseq, int pos, return len; } -static char * +static const char * catch_type(int type) { switch (type) { diff --git a/keywords b/keywords index 76cd2437a9..504d5230bf 100644 --- a/keywords +++ b/keywords @@ -1,5 +1,5 @@ %{ -struct kwtable {char *name; int id[2]; enum lex_state_e state;}; +struct kwtable {const char *name; int id[2]; enum lex_state_e state;}; const struct kwtable *rb_reserved_word(const char *, unsigned int); #ifndef RIPPER %} diff --git a/lex.c.blt b/lex.c.blt index 1b6c31e964..7bf3a8264f 100644 --- a/lex.c.blt +++ b/lex.c.blt @@ -30,7 +30,7 @@ error "gperf generated tables don't work with this execution character set. Plea #line 1 "keywords" -struct kwtable {char *name; int id[2]; enum lex_state_e state;}; +struct kwtable {const char *name; int id[2]; enum lex_state_e state;}; const struct kwtable *rb_reserved_word(const char *, unsigned int); #ifndef RIPPER #line 7 "keywords" diff --git a/lex.c.src b/lex.c.src index 76cd2437a9..504d5230bf 100644 --- a/lex.c.src +++ b/lex.c.src @@ -1,5 +1,5 @@ %{ -struct kwtable {char *name; int id[2]; enum lex_state_e state;}; +struct kwtable {const char *name; int id[2]; enum lex_state_e state;}; const struct kwtable *rb_reserved_word(const char *, unsigned int); #ifndef RIPPER %} diff --git a/marshal.c b/marshal.c index 478d17d888..f78464d16e 100644 --- a/marshal.c +++ b/marshal.c @@ -414,7 +414,7 @@ hash_each(VALUE key, VALUE value, struct dump_call_arg *arg) static void w_extended(VALUE klass, struct dump_arg *arg, int check) { - char *path; + const char *path; if (check && FL_TEST(klass, FL_SINGLETON)) { if (RCLASS_M_TBL(klass)->num_entries || diff --git a/math.c b/math.c index 37d019bc70..6bf233acee 100644 --- a/math.c +++ b/math.c @@ -35,7 +35,7 @@ to_flo(VALUE x) } while (0) static void -domain_check(double x, char *msg) +domain_check(double x, const char *msg) { while(1) { if (errno) { diff --git a/missing/vsnprintf.c b/missing/vsnprintf.c index 352005bd33..1d70d0b92a 100644 --- a/missing/vsnprintf.c +++ b/missing/vsnprintf.c @@ -217,7 +217,7 @@ typedef struct __sFILE { * I/O descriptors for __sfvwrite(). */ struct __siov { - void *iov_base; + const void *iov_base; size_t iov_len; }; struct __suio { @@ -422,7 +422,7 @@ BSD__uqtoa(register u_quad_t val, char *endp, int base, int octzero, char *xdigs * use the given digits. */ static char * -BSD__ultoa(register u_long val, char *endp, int base, int octzero, char *xdigs) +BSD__ultoa(register u_long val, char *endp, int base, int octzero, const char *xdigs) { register char *cp = endp; register long sval; @@ -523,10 +523,10 @@ static int exponent __P((char *, int, int)); static int BSD_vfprintf(FILE *fp, const char *fmt0, va_list ap) { - register char *fmt; /* format string */ + register const char *fmt; /* format string */ register int ch; /* character from fmt */ register int n; /* handy integer (short term usage) */ - register char *cp; /* handy char pointer (short term usage) */ + register const char *cp;/* handy char pointer (short term usage) */ register struct __siov *iovp;/* for PRINT macro */ register int flags; /* flags as above */ int ret; /* return value accumulator */ @@ -550,12 +550,13 @@ BSD_vfprintf(FILE *fp, const char *fmt0, va_list ap) int fieldsz; /* field size expanded by sign, etc */ int realsz; /* field size expanded by dprec */ int size; /* size of converted field or string */ - char *xdigs = 0; /* digits for [xX] conversion */ + const char *xdigs = 0; /* digits for [xX] conversion */ #define NIOV 8 struct __suio uio; /* output information: summary */ struct __siov iov[NIOV];/* ... and individual io vectors */ char buf[BUF]; /* space for %c, %[diouxX], %[eEfgG] */ char ox[2]; /* space for 0x hex-prefix */ + char *const ebuf = buf + sizeof(buf); /* * Choose PADSIZE to trade efficiency vs. size. If larger printf @@ -616,7 +617,7 @@ BSD_vfprintf(FILE *fp, const char *fmt0, va_list ap) fp->_file >= 0) return (BSD__sbprintf(fp, fmt0, ap)); - fmt = (char *)fmt0; + fmt = fmt0; uio.uio_iov = iovp = iov; uio.uio_resid = 0; uio.uio_iovcnt = 0; @@ -720,7 +721,8 @@ reswitch: switch (ch) { goto rflag; #endif /* _HAVE_SANE_QUAD_ */ case 'c': - *(cp = buf) = va_arg(ap, int); + cp = buf; + *buf = (char)va_arg(ap, int); size = 1; sign = '\0'; break; @@ -868,7 +870,7 @@ fp_begin: _double = va_arg(ap, double); * NUL in the first `prec' characters, and * strlen() will go further. */ - char *p = (char *)memchr(cp, 0, prec); + const char *p = (char *)memchr(cp, 0, prec); if (p != NULL) { size = p - cp; @@ -930,28 +932,27 @@ number: if ((dprec = prec) >= 0) * explicit precision of zero is no characters.'' * -- ANSI X3J11 */ - cp = buf + BUF; #ifdef _HAVE_SANE_QUAD_ if (flags & QUADINT) { if (uqval != 0 || prec != 0) - cp = BSD__uqtoa(uqval, cp, base, + cp = BSD__uqtoa(uqval, ebuf, base, flags & ALT, xdigs); } else #else /* _HAVE_SANE_QUAD_ */ #endif /* _HAVE_SANE_QUAD_ */ { if (ulval != 0 || prec != 0) - cp = BSD__ultoa(ulval, cp, base, + cp = BSD__ultoa(ulval, ebuf, base, flags & ALT, xdigs); } - size = buf + BUF - cp; + size = ebuf - cp; break; default: /* "%?" prints ?, unless ? is NUL */ if (ch == '\0') goto done; /* pretend it was %c with argument ch */ cp = buf; - *cp = ch; + *buf = ch; size = 1; sign = '\0'; break; diff --git a/object.c b/object.c index 2105b1ac50..5d49b2ab6f 100644 --- a/object.c +++ b/object.c @@ -298,7 +298,7 @@ rb_obj_init_copy(VALUE obj, VALUE orig) VALUE rb_any_to_s(VALUE obj) { - char *cname = rb_obj_classname(obj); + const char *cname = rb_obj_classname(obj); VALUE str; str = rb_sprintf("#<%s:%p>", cname, (void*)obj); @@ -387,9 +387,8 @@ rb_obj_inspect(VALUE obj) if (has_ivar) { VALUE str; - char *c; + const char *c = rb_obj_classname(obj); - c = rb_obj_classname(obj); str = rb_sprintf("-<%s:%p", c, (void*)obj); return rb_exec_recursive(inspect_obj, obj, str); } @@ -1916,7 +1915,7 @@ rb_convert_type(VALUE val, int type, const char *tname, const char *method) if (TYPE(val) == type) return val; v = convert_type(val, tname, method, Qtrue); if (TYPE(v) != type) { - char *cname = rb_obj_classname(val); + const char *cname = rb_obj_classname(val); rb_raise(rb_eTypeError, "can't convert %s to %s (%s#%s gives %s)", cname, tname, cname, method, rb_obj_classname(v)); } @@ -1933,7 +1932,7 @@ rb_check_convert_type(VALUE val, int type, const char *tname, const char *method v = convert_type(val, tname, method, Qfalse); if (NIL_P(v)) return Qnil; if (TYPE(v) != type) { - char *cname = rb_obj_classname(val); + const char *cname = rb_obj_classname(val); rb_raise(rb_eTypeError, "can't convert %s to %s (%s#%s gives %s)", cname, tname, cname, method, rb_obj_classname(v)); } @@ -1949,7 +1948,7 @@ rb_to_integer(VALUE val, const char *method) if (FIXNUM_P(val)) return val; v = convert_type(val, "Integer", method, Qtrue); if (!rb_obj_is_kind_of(v, rb_cInteger)) { - char *cname = rb_obj_classname(val); + const char *cname = rb_obj_classname(val); rb_raise(rb_eTypeError, "can't convert %s to Integer (%s#%s gives %s)", cname, cname, method, rb_obj_classname(v)); } diff --git a/pack.c b/pack.c index 255f74de82..5408f7e9b2 100644 --- a/pack.c +++ b/pack.c @@ -475,7 +475,7 @@ pack_pack(VALUE ary, VALUE fmt) continue; } if (*p == '_' || *p == '!') { - const char *natstr = "sSiIlL"; + static const char natstr[] = "sSiIlL"; if (strchr(natstr, type)) { #ifdef NATINT_PACK @@ -1335,7 +1335,7 @@ pack_unpack(VALUE str, VALUE fmt) } star = 0; if (*p == '_' || *p == '!') { - const char *natstr = "sSiIlL"; + static const char natstr[] = "sSiIlL"; if (strchr(natstr, type)) { #ifdef NATINT_PACK diff --git a/proc.c b/proc.c index d1562588e7..f0934a5a4d 100644 --- a/proc.c +++ b/proc.c @@ -661,7 +661,7 @@ proc_to_s(VALUE self) { VALUE str = 0; rb_proc_t *proc; - char *cname = rb_obj_classname(self); + const char *cname = rb_obj_classname(self); rb_iseq_t *iseq; const char *is_lambda; @@ -1417,7 +1417,7 @@ method_inspect(VALUE method) struct METHOD *data; VALUE str; const char *s; - char *sharp = "#"; + const char *sharp = "#"; Data_Get_Struct(method, struct METHOD, data); str = rb_str_buf_new2("#<"); diff --git a/re.c b/re.c index c5b47c46b7..c21ca3a37a 100644 --- a/re.c +++ b/re.c @@ -1753,7 +1753,7 @@ match_inspect_name_iter(const OnigUChar *name, const OnigUChar *name_end, static VALUE match_inspect(VALUE match) { - char *cname = rb_obj_classname(match); + const char *cname = rb_obj_classname(match); VALUE str; int i; struct re_registers *regs = RMATCH_REGS(match); diff --git a/regerror.c b/regerror.c index 2bc2da4c71..d5d1f4008e 100644 --- a/regerror.c +++ b/regerror.c @@ -41,7 +41,7 @@ extern UChar* onig_error_code_to_format(int code) { - char *p; + const char *p; if (code >= 0) return (UChar* )0; diff --git a/ruby.c b/ruby.c index 0f587f8459..97a9ab6e69 100644 --- a/ruby.c +++ b/ruby.c @@ -89,7 +89,7 @@ struct cmdline_options { int verbose; int yydebug; unsigned int dump; - char *script; + const char *script; VALUE script_name; VALUE e_script; struct { diff --git a/string.c b/string.c index eb41c0db10..457ac6d54c 100644 --- a/string.c +++ b/string.c @@ -5914,7 +5914,8 @@ rb_str_justify(int argc, VALUE *argv, VALUE str, char jflag) VALUE w; long width, len, flen = 1, fclen = 1; VALUE res; - char *p, *f = " "; + char *p; + const char *f = " "; long n, llen, rlen; volatile VALUE pad; int singlebyte = 1; diff --git a/struct.c b/struct.c index 415032bed4..eecc47254e 100644 --- a/struct.c +++ b/struct.c @@ -223,7 +223,7 @@ rb_struct_alloc_noinit(VALUE klass) } VALUE -rb_struct_define_without_accessor(char *class_name, VALUE super, rb_alloc_func_t alloc, ...) +rb_struct_define_without_accessor(const char *class_name, VALUE super, rb_alloc_func_t alloc, ...) { VALUE klass; va_list ar; @@ -479,7 +479,7 @@ rb_struct_each_pair(VALUE s) static VALUE inspect_struct(VALUE s, VALUE dummy, int recur) { - char *cname = rb_class2name(rb_obj_class(s)); + const char *cname = rb_class2name(rb_obj_class(s)); VALUE str, members; long i; diff --git a/thread.c b/thread.c index 7bcf64741c..5c1deb7448 100644 --- a/thread.c +++ b/thread.c @@ -1471,7 +1471,7 @@ rb_thread_safe_level(VALUE thread) static VALUE rb_thread_inspect(VALUE thread) { - char *cname = rb_obj_classname(thread); + const char *cname = rb_obj_classname(thread); rb_thread_t *th; const char *status; VALUE str; @@ -2491,7 +2491,7 @@ VALUE rb_mutex_unlock(VALUE self) { mutex_t *mutex; - char *err = NULL; + const char *err = NULL; GetMutexPtr(self, mutex); native_mutex_lock(&mutex->lock); @@ -3039,7 +3039,7 @@ thread_set_trace_func_m(VALUE obj, VALUE trace) return trace; } -static char * +static const char * get_event_name(rb_event_flag_t event) { switch (event) { diff --git a/time.c b/time.c index 0107c6a033..e1aba184f6 100644 --- a/time.c +++ b/time.c @@ -333,7 +333,7 @@ time_s_at(int argc, VALUE *argv, VALUE klass) return t; } -static const char *const months[] = { +static const char const months[][4] = { "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec", }; diff --git a/util.c b/util.c index 55c7e567f6..5e3470f7b1 100644 --- a/util.c +++ b/util.c @@ -3202,7 +3202,7 @@ rv_alloc(int i) } static char * -nrv_alloc(char *s, char **rve, int n) +nrv_alloc(const char *s, char **rve, int n) { char *rv, *t; diff --git a/variable.c b/variable.c index a935c51d3a..572c329dad 100644 --- a/variable.c +++ b/variable.c @@ -270,13 +270,13 @@ rb_class_name(VALUE klass) return rb_class_path(rb_class_real(klass)); } -char * +const char * rb_class2name(VALUE klass) { return RSTRING_PTR(rb_class_name(klass)); } -char * +const char * rb_obj_classname(VALUE obj) { return rb_class2name(CLASS_OF(obj)); diff --git a/vm_dump.c b/vm_dump.c index 38b8f25eeb..23413cdcf5 100644 --- a/vm_dump.c +++ b/vm_dump.c @@ -576,7 +576,6 @@ VALUE rb_make_backtrace(void); void rb_vm_bugreport(void) { - rb_thread_t *th = GET_THREAD(); VALUE bt; if (GET_THREAD()->vm) { diff --git a/vm_eval.c b/vm_eval.c index 324e3cadc1..a00b33bdce 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -293,7 +293,7 @@ rb_method_missing(int argc, const VALUE *argv, VALUE obj) { ID id; VALUE exc = rb_eNoMethodError; - char *format = 0; + const char *format = 0; rb_thread_t *th = GET_THREAD(); int last_call_status = th->method_missing_reason; if (argc == 0 || !SYMBOL_P(argv[0])) { @@ -773,7 +773,7 @@ VALUE rb_f_eval(int argc, VALUE *argv, VALUE self) { VALUE src, scope, vfile, vline; - char *file = "(eval)"; + const char *file = "(eval)"; int line = 1; rb_scan_args(argc, argv, "13", &src, &scope, &vfile, &vline); @@ -925,7 +925,7 @@ specific_eval(int argc, VALUE *argv, VALUE klass, VALUE self) return yield_under(klass, self, Qundef); } else { - char *file = "(eval)"; + const char *file = "(eval)"; int line = 1; if (argc == 0) { diff --git a/vm_method.c b/vm_method.c index 8c3f7f0a60..d7160fcd9d 100644 --- a/vm_method.c +++ b/vm_method.c @@ -484,7 +484,7 @@ rb_undef(VALUE klass, ID id) } body = search_method(klass, id, &origin); if (!body || !body->nd_body) { - char *s0 = " class"; + const char *s0 = " class"; VALUE c = klass; if (FL_TEST(c, FL_SINGLETON)) {