[前][次][番号順一覧][スレッド一覧]

ruby-changes:44083

From: rhe <ko1@a...>
Date: Tue, 13 Sep 2016 21:33:19 +0900 (JST)
Subject: [ruby-changes:44083] rhe:r56156 (trunk): Use PRIuSIZE format specifier for size_t values

rhe	2016-09-13 21:33:13 +0900 (Tue, 13 Sep 2016)

  New Revision: 56156

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56156

  Log:
    Use PRIuSIZE format specifier for size_t values
    
    Use PRIuSIZE instead of PRIdSIZE. This fixes the exception message shown
    on too large xmalloc2. This commit also fixes other incorrect use of
    PRIdSIZE in other functions; though most of them are debug print.
    
    * gc.c (heap_extend_pages, get_envparam_size, ruby_malloc_size_overflow,
      gc_profile_dump_on): Use PRIuSIZE instead of PRIdSIZE as the passed
      value is size_t, not ssize_t.
    
    * iseq.c (get_line_info, rb_iseq_disasm_insn): Ditto.
    
    * sprintf.c (rb_str_format): Ditto.
    
    * thread_win32.c (native_thread_create): Ditto.
    
    * vm.c (get_param): Ditto.
    
    * ext/objspace/objspace_dump.c (dump_append_string_content,
      dump_object): Ditto.
    
    * ext/socket/raddrinfo.c (host_str, port_str): Ditto.

  Modified files:
    trunk/ChangeLog
    trunk/ext/objspace/objspace_dump.c
    trunk/ext/socket/raddrinfo.c
    trunk/gc.c
    trunk/iseq.c
    trunk/sprintf.c
    trunk/thread_win32.c
    trunk/vm.c
Index: thread_win32.c
===================================================================
--- thread_win32.c	(revision 56155)
+++ thread_win32.c	(revision 56156)
@@ -614,7 +614,7 @@ native_thread_create(rb_thread_t *th) https://github.com/ruby/ruby/blob/trunk/thread_win32.c#L614
 
     if (THREAD_DEBUG) {
 	Sleep(0);
-	thread_debug("create: (th: %p, thid: %p, intr: %p), stack size: %"PRIdSIZE"\n",
+	thread_debug("create: (th: %p, thid: %p, intr: %p), stack size: %"PRIuSIZE"\n",
 		     th, th->thread_id,
 		     th->native_thread_data.interrupt_event, stack_size);
     }
Index: vm.c
===================================================================
--- vm.c	(revision 56155)
+++ vm.c	(revision 56156)
@@ -2185,7 +2185,7 @@ get_param(const char *name, size_t defau https://github.com/ruby/ruby/blob/trunk/vm.c#L2185
 	}
 	result = (size_t)(((val -1 + RUBY_VM_SIZE_ALIGN) / RUBY_VM_SIZE_ALIGN) * RUBY_VM_SIZE_ALIGN);
     }
-    if (0) fprintf(stderr, "%s: %"PRIdSIZE"\n", name, result); /* debug print */
+    if (0) fprintf(stderr, "%s: %"PRIuSIZE"\n", name, result); /* debug print */
 
     return result;
 }
Index: sprintf.c
===================================================================
--- sprintf.c	(revision 56155)
+++ sprintf.c	(revision 56156)
@@ -602,7 +602,7 @@ rb_str_format(int argc, const VALUE *arg https://github.com/ruby/ruby/blob/trunk/sprintf.c#L602
 		    const int message_limit = 20;
 		    len = (int)(rb_enc_right_char_head(start, start + message_limit, p, enc) - start);
 		    rb_enc_raise(enc, rb_eArgError,
-				 "too long name (%"PRIdSIZE" bytes) - %.*s...%c",
+				 "too long name (%"PRIuSIZE" bytes) - %.*s...%c",
 				 (size_t)(p - start - 2), len, start, term);
 		}
 #endif
Index: iseq.c
===================================================================
--- iseq.c	(revision 56155)
+++ iseq.c	(revision 56156)
@@ -1176,8 +1176,8 @@ get_line_info(const rb_iseq_t *iseq, siz https://github.com/ruby/ruby/blob/trunk/iseq.c#L1176
     const int debug = 0;
 
     if (debug) {
-	printf("size: %"PRIdSIZE"\n", size);
-	printf("table[%"PRIdSIZE"]: position: %d, line: %d, pos: %"PRIdSIZE"\n",
+	printf("size: %"PRIuSIZE"\n", size);
+	printf("table[%"PRIuSIZE"]: position: %d, line: %d, pos: %"PRIuSIZE"\n",
 	       i, table[i].position, table[i].line_no, pos);
     }
 
@@ -1189,7 +1189,7 @@ get_line_info(const rb_iseq_t *iseq, siz https://github.com/ruby/ruby/blob/trunk/iseq.c#L1189
     }
     else {
 	for (i=1; i<size; i++) {
-	    if (debug) printf("table[%"PRIdSIZE"]: position: %d, line: %d, pos: %"PRIdSIZE"\n",
+	    if (debug) printf("table[%"PRIuSIZE"]: position: %d, line: %d, pos: %"PRIuSIZE"\n",
 			      i, table[i].position, table[i].line_no, pos);
 
 	    if (table[i].position == pos) {
@@ -1397,10 +1397,10 @@ rb_iseq_disasm_insn(VALUE ret, const VAL https://github.com/ruby/ruby/blob/trunk/iseq.c#L1397
 
     insn_name_buff = insn_name(insn);
     if (1) {
-	rb_str_catf(str, "%04"PRIdSIZE" %-16s ", pos, insn_name_buff);
+	rb_str_catf(str, "%04"PRIuSIZE" %-16s ", pos, insn_name_buff);
     }
     else {
-	rb_str_catf(str, "%04"PRIdSIZE" %-16.*s ", pos,
+	rb_str_catf(str, "%04"PRIuSIZE" %-16.*s ", pos,
 		    (int)strcspn(insn_name_buff, "_"), insn_name_buff);
     }
 
Index: ext/socket/raddrinfo.c
===================================================================
--- ext/socket/raddrinfo.c	(revision 56155)
+++ ext/socket/raddrinfo.c	(revision 56156)
@@ -462,7 +462,7 @@ host_str(VALUE host, char *hbuf, size_t https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L462
             if (flags_ptr) *flags_ptr |= AI_NUMERICHOST;
         }
         else if (len >= hbuflen) {
-            rb_raise(rb_eArgError, "hostname too long (%"PRIdSIZE")",
+            rb_raise(rb_eArgError, "hostname too long (%"PRIuSIZE")",
                      len);
         }
         else {
@@ -493,7 +493,7 @@ port_str(VALUE port, char *pbuf, size_t https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L493
         SafeStringValueCStr(port);
         RSTRING_GETMEM(port, serv, len);
         if (len >= pbuflen) {
-            rb_raise(rb_eArgError, "service name too long (%"PRIdSIZE")",
+            rb_raise(rb_eArgError, "service name too long (%"PRIuSIZE")",
                      len);
         }
         memcpy(pbuf, serv, len);
Index: ext/objspace/objspace_dump.c
===================================================================
--- ext/objspace/objspace_dump.c	(revision 56155)
+++ ext/objspace/objspace_dump.c	(revision 56156)
@@ -182,7 +182,7 @@ dump_append_string_content(struct dump_c https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace_dump.c#L182
 {
     dump_append(dc, ", \"bytesize\":%ld", RSTRING_LEN(obj));
     if (!STR_EMBED_P(obj) && !STR_SHARED_P(obj) && (long)rb_str_capacity(obj) != RSTRING_LEN(obj))
-	dump_append(dc, ", \"capacity\":%"PRIdSIZE, rb_str_capacity(obj));
+	dump_append(dc, ", \"capacity\":%"PRIuSIZE, rb_str_capacity(obj));
 
     if (is_ascii_string(obj)) {
 	dump_append(dc, ", \"value\":");
@@ -248,7 +248,7 @@ dump_object(VALUE obj, struct dump_confi https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace_dump.c#L248
 	break;
 
       case T_HASH:
-	dump_append(dc, ", \"size\":%"PRIdSIZE, (size_t)RHASH_SIZE(obj));
+	dump_append(dc, ", \"size\":%"PRIuSIZE, (size_t)RHASH_SIZE(obj));
 	if (FL_TEST(obj, HASH_PROC_DEFAULT))
 	    dump_append(dc, ", \"default\":\"%p\"", (void *)RHASH_IFNONE(obj));
 	break;
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 56155)
+++ ChangeLog	(revision 56156)
@@ -1,3 +1,22 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Sep 13 21:30:53 2016  Kazuki Yamaguchi  <k@r...>
+
+	* gc.c (heap_extend_pages, get_envparam_size, ruby_malloc_size_overflow,
+	  gc_profile_dump_on): Use PRIuSIZE instead of PRIdSIZE as the passed
+	  value is size_t, not ssize_t.
+
+	* iseq.c (get_line_info, rb_iseq_disasm_insn): Ditto.
+
+	* sprintf.c (rb_str_format): Ditto.
+
+	* thread_win32.c (native_thread_create): Ditto.
+
+	* vm.c (get_param): Ditto.
+
+	* ext/objspace/objspace_dump.c (dump_append_string_content,
+	  dump_object): Ditto.
+
+	* ext/socket/raddrinfo.c (host_str, port_str): Ditto.
+
 Tue Sep 13 21:27:35 2016  Kazuki Yamaguchi  <k@r...>
 
 	* string.c (STR_EMBEDDABLE_P): Renamed from STR_EMBEDABLE_P(). And use
Index: gc.c
===================================================================
--- gc.c	(revision 56155)
+++ gc.c	(revision 56156)
@@ -1628,9 +1628,9 @@ heap_extend_pages(rb_objspace_t *objspac https://github.com/ruby/ruby/blob/trunk/gc.c#L1628
 
 	if (0) {
 	    fprintf(stderr,
-		    "free_slots(%8"PRIdSIZE")/total_slots(%8"PRIdSIZE")=%1.2f,"
+		    "free_slots(%8"PRIuSIZE")/total_slots(%8"PRIuSIZE")=%1.2f,"
 		    " G(%1.2f), f(%1.2f),"
-		    " used(%8"PRIdSIZE") => next_used(%8"PRIdSIZE")\n",
+		    " used(%8"PRIuSIZE") => next_used(%8"PRIuSIZE")\n",
 		    free_slots, total_slots, free_slots/(double)total_slots,
 		    goal_ratio, f, used, next_used);
 	}
@@ -7340,14 +7340,14 @@ get_envparam_size(const char *name, size https://github.com/ruby/ruby/blob/trunk/gc.c#L7340
 	}
 	if (val > 0 && (size_t)val > lower_bound) {
 	    if (RTEST(ruby_verbose)) {
-		fprintf(stderr, "%s=%"PRIdSIZE" (default value: %"PRIdSIZE")\n", name, val, *default_value);
+		fprintf(stderr, "%s=%"PRIdSIZE" (default value: %"PRIuSIZE")\n", name, val, *default_value);
 	    }
 	    *default_value = (size_t)val;
 	    return 1;
 	}
 	else {
 	    if (RTEST(ruby_verbose)) {
-		fprintf(stderr, "%s=%"PRIdSIZE" (default value: %"PRIdSIZE") is ignored because it must be greater than %"PRIdSIZE".\n",
+		fprintf(stderr, "%s=%"PRIdSIZE" (default value: %"PRIuSIZE") is ignored because it must be greater than %"PRIuSIZE".\n",
 			name, val, *default_value, lower_bound);
 	    }
 	    return 0;
@@ -7916,7 +7916,7 @@ void https://github.com/ruby/ruby/blob/trunk/gc.c#L7916
 ruby_malloc_size_overflow(size_t count, size_t elsize)
 {
     rb_raise(rb_eArgError,
-	     "malloc: possible integer overflow (%"PRIdSIZE"*%"PRIdSIZE")",
+	     "malloc: possible integer overflow (%"PRIuSIZE"*%"PRIuSIZE")",
 	     count, elsize);
 }
 
@@ -8901,7 +8901,7 @@ gc_profile_dump_on(VALUE out, VALUE (*ap https://github.com/ruby/ruby/blob/trunk/gc.c#L8901
 
 	for (i = 0; i < count; i++) {
 	    record = &objspace->profile.records[i];
-	    append(out, rb_sprintf("%5"PRIdSIZE" %19.3f %20"PRIuSIZE" %20"PRIuSIZE" %20"PRIuSIZE" %30.20f\n",
+	    append(out, rb_sprintf("%5"PRIuSIZE" %19.3f %20"PRIuSIZE" %20"PRIuSIZE" %20"PRIuSIZE" %30.20f\n",
 				   i+1, record->gc_invoke_time, record->heap_use_size,
 				   record->heap_total_size, record->heap_total_objects, record->gc_time*1000));
 	}
@@ -8925,7 +8925,7 @@ gc_profile_dump_on(VALUE out, VALUE (*ap https://github.com/ruby/ruby/blob/trunk/gc.c#L8925
 
 	for (i = 0; i < count; i++) {
 	    record = &objspace->profile.records[i];
-	    append(out, rb_sprintf("%5"PRIdSIZE" %4s/%c/%6s%c %13"PRIuSIZE" %15"PRIuSIZE
+	    append(out, rb_sprintf("%5"PRIuSIZE" %4s/%c/%6s%c %13"PRIuSIZE" %15"PRIuSIZE
 #if CALC_EXACT_MALLOC_SIZE
 				   " %15"PRIuSIZE
 #endif

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]