diff options
Diffstat (limited to 'ext/tk')
-rw-r--r-- | ext/tk/tcltklib.c | 17 | ||||
-rw-r--r-- | ext/tk/tkutil/tkutil.c | 84 |
2 files changed, 55 insertions, 46 deletions
diff --git a/ext/tk/tcltklib.c b/ext/tk/tcltklib.c index 2906cb7281..fed21d3709 100644 --- a/ext/tk/tcltklib.c +++ b/ext/tk/tcltklib.c @@ -42,6 +42,9 @@ int rb_thread_check_trap_pending(void); #define RARRAY_PTR(s) (RARRAY(s)->ptr) #define RARRAY_LEN(s) (RARRAY(s)->len) #endif +#if !defined(RARRAY_CONST_PTR) +#define RARRAY_CONST_PTR(s) (const VALUE *)RARRAY_PTR(s) +#endif #ifdef OBJ_UNTRUST #define RbTk_OBJ_UNTRUST(x) do {OBJ_TAINT(x); OBJ_UNTRUST(x);} while (0) @@ -1889,15 +1892,15 @@ set_max_block_time(self, time) case T_BIGNUM: /* time is micro-second value */ divmod = rb_funcall(time, rb_intern("divmod"), 1, LONG2NUM(1000000)); - tcl_time.sec = NUM2LONG(RARRAY_PTR(divmod)[0]); - tcl_time.usec = NUM2LONG(RARRAY_PTR(divmod)[1]); + tcl_time.sec = NUM2LONG(RARRAY_CONST_PTR(divmod)[0]); + tcl_time.usec = NUM2LONG(RARRAY_CONST_PTR(divmod)[1]); break; case T_FLOAT: /* time is second value */ divmod = rb_funcall(time, rb_intern("divmod"), 1, INT2FIX(1)); - tcl_time.sec = NUM2LONG(RARRAY_PTR(divmod)[0]); - tcl_time.usec = (long)(NUM2DBL(RARRAY_PTR(divmod)[1]) * 1000000); + tcl_time.sec = NUM2LONG(RARRAY_CONST_PTR(divmod)[0]); + tcl_time.usec = (long)(NUM2DBL(RARRAY_CONST_PTR(divmod)[1]) * 1000000); default: { @@ -7210,7 +7213,7 @@ tk_funcall(func, argc, argv, obj) DUMP2("back from handler (current thread:%"PRIxVALUE")", current); /* get result & free allocated memory */ - ret = RARRAY_PTR(result)[0]; + ret = RARRAY_CONST_PTR(result)[0]; #if 0 /* use Tcl_EventuallyFree */ Tcl_EventuallyFree((ClientData)alloc_done, TCL_DYNAMIC); /* XXXXXXXX */ #else @@ -7694,7 +7697,7 @@ ip_eval(self, str) DUMP2("back from handler (current thread:%"PRIxVALUE")", current); /* get result & free allocated memory */ - ret = RARRAY_PTR(result)[0]; + ret = RARRAY_CONST_PTR(result)[0]; #if 0 /* use Tcl_EventuallyFree */ Tcl_EventuallyFree((ClientData)alloc_done, TCL_DYNAMIC); /* XXXXXXXX */ @@ -9193,7 +9196,7 @@ ip_invoke_with_position(argc, argv, obj, position) DUMP2("back from handler (current thread:%"PRIxVALUE")", current); /* get result & free allocated memory */ - ret = RARRAY_PTR(result)[0]; + ret = RARRAY_CONST_PTR(result)[0]; #if 0 /* use Tcl_EventuallyFree */ Tcl_EventuallyFree((ClientData)alloc_done, TCL_DYNAMIC); /* XXXXXXXX */ #else diff --git a/ext/tk/tkutil/tkutil.c b/ext/tk/tkutil/tkutil.c index 676581d641..2bfb6bf50a 100644 --- a/ext/tk/tkutil/tkutil.c +++ b/ext/tk/tkutil/tkutil.c @@ -37,6 +37,9 @@ static int rb_thread_critical; /* dummy */ #define RARRAY_PTR(s) (RARRAY(s)->ptr) #define RARRAY_LEN(s) (RARRAY(s)->len) #endif +#if !defined(RARRAY_CONST_PTR) +#define RARRAY_CONST_PTR(s) (const VALUE *)RARRAY_PTR(s) +#endif #if defined(HAVE_STRNDUP) && !defined(_GNU_SOURCE) extern char *strndup(const char* _ptr, size_t _len); @@ -334,8 +337,8 @@ ary2list(ary, enc_flag, self) /* size = RARRAY_LEN(ary); */ size = 0; for(idx = 0; idx < RARRAY_LEN(ary); idx++) { - if (RB_TYPE_P(RARRAY_PTR(ary)[idx], T_HASH)) { - size += 2 * RHASH_SIZE(RARRAY_PTR(ary)[idx]); + if (RB_TYPE_P(RARRAY_CONST_PTR(ary)[idx], T_HASH)) { + size += 2 * RHASH_SIZE(RARRAY_CONST_PTR(ary)[idx]); } else { size++; } @@ -343,7 +346,7 @@ ary2list(ary, enc_flag, self) dst = rb_ary_new2(size); for(idx = 0; idx < RARRAY_LEN(ary); idx++) { - val = RARRAY_PTR(ary)[idx]; + val = RARRAY_CONST_PTR(ary)[idx]; str_val = Qnil; switch(TYPE(val)) { case T_ARRAY: @@ -374,7 +377,7 @@ ary2list(ary, enc_flag, self) } size2 = RARRAY_LEN(val); for(idx2 = 0; idx2 < size2; idx2++) { - val2 = RARRAY_PTR(val)[idx2]; + val2 = RARRAY_CONST_PTR(val)[idx2]; switch(TYPE(val2)) { case T_ARRAY: str_val = ary2list(val2, enc_flag, self); @@ -435,7 +438,7 @@ ary2list(ary, enc_flag, self) if (RTEST(dst_enc) && !NIL_P(sys_enc)) { for(idx = 0; idx < RARRAY_LEN(dst); idx++) { - str_val = RARRAY_PTR(dst)[idx]; + str_val = RARRAY_CONST_PTR(dst)[idx]; if (rb_obj_respond_to(self, ID_toUTF8, Qtrue)) { str_val = rb_funcall(self, ID_toUTF8, 1, str_val); } else { @@ -488,7 +491,7 @@ ary2list2(ary, enc_flag, self) size = RARRAY_LEN(ary); dst = rb_ary_new2(size); for(idx = 0; idx < RARRAY_LEN(ary); idx++) { - val = RARRAY_PTR(ary)[idx]; + val = RARRAY_CONST_PTR(ary)[idx]; str_val = Qnil; switch(TYPE(val)) { case T_ARRAY: @@ -529,7 +532,7 @@ ary2list2(ary, enc_flag, self) if (RTEST(dst_enc) && !NIL_P(sys_enc)) { for(idx = 0; idx < RARRAY_LEN(dst); idx++) { - str_val = RARRAY_PTR(dst)[idx]; + str_val = RARRAY_CONST_PTR(dst)[idx]; if (rb_obj_respond_to(self, ID_toUTF8, Qtrue)) { str_val = rb_funcall(self, ID_toUTF8, 1, str_val); } else { @@ -571,27 +574,27 @@ assoc2kv(assoc, ary, self) len = RARRAY_LEN(assoc); for(i = 0; i < len; i++) { - pair = RARRAY_PTR(assoc)[i]; + pair = RARRAY_CONST_PTR(assoc)[i]; if (!RB_TYPE_P(pair, T_ARRAY)) { rb_ary_push(dst, key2keyname(pair)); continue; } switch(RARRAY_LEN(assoc)) { case 2: - rb_ary_push(dst, RARRAY_PTR(pair)[2]); + rb_ary_push(dst, RARRAY_CONST_PTR(pair)[2]); case 1: - rb_ary_push(dst, key2keyname(RARRAY_PTR(pair)[0])); + rb_ary_push(dst, key2keyname(RARRAY_CONST_PTR(pair)[0])); case 0: continue; default: - rb_ary_push(dst, key2keyname(RARRAY_PTR(pair)[0])); + rb_ary_push(dst, key2keyname(RARRAY_CONST_PTR(pair)[0])); val = rb_ary_new2(RARRAY_LEN(pair) - 1); for(j = 1; j < RARRAY_LEN(pair); j++) { - rb_ary_push(val, RARRAY_PTR(pair)[j]); + rb_ary_push(val, RARRAY_CONST_PTR(pair)[j]); } rb_ary_push(dst, val); @@ -619,27 +622,27 @@ assoc2kv_enc(assoc, ary, self) len = RARRAY_LEN(assoc); for(i = 0; i < len; i++) { - pair = RARRAY_PTR(assoc)[i]; + pair = RARRAY_CONST_PTR(assoc)[i]; if (!RB_TYPE_P(pair, T_ARRAY)) { rb_ary_push(dst, key2keyname(pair)); continue; } switch(RARRAY_LEN(assoc)) { case 2: - rb_ary_push(dst, get_eval_string_core(RARRAY_PTR(pair)[2], Qtrue, self)); + rb_ary_push(dst, get_eval_string_core(RARRAY_CONST_PTR(pair)[2], Qtrue, self)); case 1: - rb_ary_push(dst, key2keyname(RARRAY_PTR(pair)[0])); + rb_ary_push(dst, key2keyname(RARRAY_CONST_PTR(pair)[0])); case 0: continue; default: - rb_ary_push(dst, key2keyname(RARRAY_PTR(pair)[0])); + rb_ary_push(dst, key2keyname(RARRAY_CONST_PTR(pair)[0])); val = rb_ary_new2(RARRAY_LEN(pair) - 1); for(j = 1; j < RARRAY_LEN(pair); j++) { - rb_ary_push(val, RARRAY_PTR(pair)[j]); + rb_ary_push(val, RARRAY_CONST_PTR(pair)[j]); } rb_ary_push(dst, get_eval_string_core(val, Qtrue, self)); @@ -661,7 +664,7 @@ push_kv(key, val, args) { volatile VALUE ary; - ary = RARRAY_PTR(args)[0]; + ary = RARRAY_CONST_PTR(args)[0]; #if 0 rb_ary_push(ary, key2keyname(key)); @@ -671,7 +674,7 @@ push_kv(key, val, args) if (val == TK_None) return ST_CHECK; - rb_ary_push(ary, get_eval_string_core(val, Qnil, RARRAY_PTR(args)[1])); + rb_ary_push(ary, get_eval_string_core(val, Qnil, RARRAY_CONST_PTR(args)[1])); return ST_CHECK; } @@ -702,20 +705,20 @@ push_kv_enc(key, val, args) { volatile VALUE ary; - ary = RARRAY_PTR(args)[0]; + ary = RARRAY_CONST_PTR(args)[0]; #if 0 rb_ary_push(ary, key2keyname(key)); if (val != TK_None) { rb_ary_push(ary, get_eval_string_core(val, Qtrue, - RARRAY_PTR(args)[1])); + RARRAY_CONST_PTR(args)[1])); } #endif rb_ary_push(ary, key2keyname(key)); if (val == TK_None) return ST_CHECK; - rb_ary_push(ary, get_eval_string_core(val, Qtrue, RARRAY_PTR(args)[1])); + rb_ary_push(ary, get_eval_string_core(val, Qtrue, RARRAY_CONST_PTR(args)[1])); return ST_CHECK; } @@ -1529,6 +1532,7 @@ cbsubst_table_setup(argc, argv, self) volatile VALUE longkey_inf; volatile VALUE proc_inf; VALUE inf; + const VALUE *infp; ID id; struct cbsubst_info *subst_inf; long idx, len; @@ -1559,15 +1563,16 @@ cbsubst_table_setup(argc, argv, self) */ len = RARRAY_LEN(key_inf); for(idx = 0; idx < len; idx++) { - inf = RARRAY_PTR(key_inf)[idx]; + inf = RARRAY_CONST_PTR(key_inf)[idx]; if (!RB_TYPE_P(inf, T_ARRAY)) continue; + infp = RARRAY_CONST_PTR(inf); - chr = NUM2CHR(RARRAY_PTR(inf)[0]); - subst_inf->type[chr] = NUM2CHR(RARRAY_PTR(inf)[1]); + chr = NUM2CHR(infp[0]); + subst_inf->type[chr] = NUM2CHR(infp[1]); subst_inf->full_subst_length += 3; - id = SYM2ID(RARRAY_PTR(inf)[2]); + id = SYM2ID(infp[2]); subst_inf->ivar[chr] = rb_intern_str(rb_sprintf("@%"PRIsVALUE, rb_id2str(id))); rb_attr(self, id, 1, 0, Qtrue); @@ -1582,27 +1587,28 @@ cbsubst_table_setup(argc, argv, self) */ len = RARRAY_LEN(longkey_inf); for(idx = 0; idx < len; idx++) { - inf = RARRAY_PTR(longkey_inf)[idx]; + inf = RARRAY_CONST_PTR(longkey_inf)[idx]; if (!RB_TYPE_P(inf, T_ARRAY)) continue; + infp = RARRAY_CONST_PTR(inf); chr = (unsigned char)(0x80 + idx); - subst_inf->keylen[chr] = RSTRING_LEN(RARRAY_PTR(inf)[0]); + subst_inf->keylen[chr] = RSTRING_LEN(infp[0]); #if HAVE_STRNDUP - subst_inf->key[chr] = strndup(RSTRING_PTR(RARRAY_PTR(inf)[0]), - RSTRING_LEN(RARRAY_PTR(inf)[0])); + subst_inf->key[chr] = strndup(RSTRING_PTR(infp[0]), + RSTRING_LEN(infp[0])); #else - subst_inf->key[chr] = malloc(RSTRING_LEN(RARRAY_PTR(inf)[0]) + 1); + subst_inf->key[chr] = malloc(RSTRING_LEN(infp[0]) + 1); if (subst_inf->key[chr]) { - strncpy(subst_inf->key[chr], RSTRING_PTR(RARRAY_PTR(inf)[0]), - RSTRING_LEN(RARRAY_PTR(inf)[0]) + 1); - subst_inf->key[chr][RSTRING_LEN(RARRAY_PTR(inf)[0])] = '\0'; + strncpy(subst_inf->key[chr], RSTRING_PTR(infp[0]), + RSTRING_LEN(infp[0]) + 1); + subst_inf->key[chr][RSTRING_LEN(infp[0])] = '\0'; } #endif - subst_inf->type[chr] = NUM2CHR(RARRAY_PTR(inf)[1]); + subst_inf->type[chr] = NUM2CHR(infp[1]); subst_inf->full_subst_length += (subst_inf->keylen[chr] + 2); - id = SYM2ID(RARRAY_PTR(inf)[2]); + id = SYM2ID(infp[2]); subst_inf->ivar[chr] = rb_intern_str(rb_sprintf("@%"PRIsVALUE, rb_id2str(id))); rb_attr(self, id, 1, 0, Qtrue); @@ -1616,7 +1622,7 @@ cbsubst_table_setup(argc, argv, self) len = RARRAY_LEN(proc_inf); for(idx = 0; idx < len; idx++) { VALUE type, proc; - inf = RARRAY_PTR(proc_inf)[idx]; + inf = RARRAY_CONST_PTR(proc_inf)[idx]; if (!RB_TYPE_P(inf, T_ARRAY)) continue; if (RARRAY_LEN(inf) < 2) continue; type = rb_ary_entry(inf, 0); @@ -1676,10 +1682,10 @@ cbsubst_scan_args(self, arg_key, val_ary) } if (NIL_P(proc)) { - rb_ary_push(dst, RARRAY_PTR(val_ary)[idx]); + rb_ary_push(dst, RARRAY_CONST_PTR(val_ary)[idx]); } else { rb_ary_push(dst, rb_funcall(proc, ID_call, 1, - RARRAY_PTR(val_ary)[idx])); + RARRAY_CONST_PTR(val_ary)[idx])); } } |