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

ruby-changes:44096

From: shyouhei <ko1@a...>
Date: Fri, 16 Sep 2016 15:16:02 +0900 (JST)
Subject: [ruby-changes:44096] shyouhei:r56169 (trunk): * internal.h (WARN_UNUSED_RESULT): moved to configure.in, to

shyouhei	2016-09-16 15:15:55 +0900 (Fri, 16 Sep 2016)

  New Revision: 56169

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

  Log:
    * internal.h (WARN_UNUSED_RESULT): moved to configure.in, to
      actually check its availability rather to check GCC's version.
    
    * configure.in (WARN_UNUSED_RESULT): moved to here.
    
    * configure.in (RUBY_FUNC_ATTRIBUTE): change function declaration
      to return int rather than void, because it makes no sense for a
      warn_unused_result attributed function to return void.
    
      Funny thing however is that it also makes no sense for noreturn
      attributed function to return int.  So there is a fundamental
      conflict between them.  While I tested this, I confirmed both
      GCC 6 and Clang 3.8 prefers int over void to correctly detect
      necessary attributes under this setup.  Maybe subject to change
      in future.
    
    * internal.h (UNINITIALIZED_VAR): renamed to MAYBE_UNUSED, then
      moved to configure.in for the same reason we move
      WARN_UNUSED_RESULT.
    
    * configure.in (MAYBE_UNUSED): moved to here.
    
    * internal.h (__has_attribute): deleted, because it has no use now.
    
    * string.c (rb_str_enumerate_lines): refactor macro rename.
    
    * string.c (rb_str_enumerate_bytes): ditto.
    
    * string.c (rb_str_enumerate_chars): ditto.
    
    * string.c (rb_str_enumerate_codepoints): ditto.
    
    * thread.c (do_select): ditto.
    
    * vm_backtrace.c (rb_debug_inspector_open): ditto.
    
    * vsnprintf.c (BSD_vfprintf): ditto.

  Modified files:
    trunk/ChangeLog
    trunk/configure.in
    trunk/internal.h
    trunk/string.c
    trunk/thread.c
    trunk/vm_backtrace.c
    trunk/vsnprintf.c
Index: thread.c
===================================================================
--- thread.c	(revision 56168)
+++ thread.c	(revision 56169)
@@ -3660,11 +3660,11 @@ static int https://github.com/ruby/ruby/blob/trunk/thread.c#L3660
 do_select(int n, rb_fdset_t *readfds, rb_fdset_t *writefds,
 	  rb_fdset_t *exceptfds, struct timeval *timeout)
 {
-    int UNINITIALIZED_VAR(result);
+    int MAYBE_UNUSED(result);
     int lerrno;
-    rb_fdset_t UNINITIALIZED_VAR(orig_read);
-    rb_fdset_t UNINITIALIZED_VAR(orig_write);
-    rb_fdset_t UNINITIALIZED_VAR(orig_except);
+    rb_fdset_t MAYBE_UNUSED(orig_read);
+    rb_fdset_t MAYBE_UNUSED(orig_write);
+    rb_fdset_t MAYBE_UNUSED(orig_except);
     double limit = 0;
     struct timeval wait_rest;
     rb_thread_t *th = GET_THREAD();
Index: configure.in
===================================================================
--- configure.in	(revision 56168)
+++ configure.in	(revision 56169)
@@ -1809,7 +1809,7 @@ AS_VAR_POPDEF([rbcv])dnl https://github.com/ruby/ruby/blob/trunk/configure.in#L1809
 dnl RUBY_FUNC_ATTRIBUTE(attrib, macroname, cachevar, condition)
 AC_DEFUN([RUBY_FUNC_ATTRIBUTE], [dnl
     RUBY_DECL_ATTRIBUTE([$1], [$2], [$3], [$4],
-	[function], [@%:@define x void conftest_attribute_check(void)]
+	[function], [@%:@define x int conftest_attribute_check(void)]
     )
 ])
 
@@ -1829,6 +1829,8 @@ RUBY_FUNC_ATTRIBUTE(__deprecated__("by " https://github.com/ruby/ruby/blob/trunk/configure.in#L1829
 RUBY_TYPE_ATTRIBUTE(__deprecated__ mesg, DEPRECATED_TYPE(mesg,x), rb_cv_type_deprecated)
 RUBY_FUNC_ATTRIBUTE(__noinline__, NOINLINE)
 RUBY_FUNC_ATTRIBUTE(__always_inline__, ALWAYS_INLINE)
+RUBY_FUNC_ATTRIBUTE(__warn_unused_result__, WARN_UNUSED_RESULT)
+RUBY_FUNC_ATTRIBUTE(__unused__, MAYBE_UNUSED)
 RUBY_FUNC_ATTRIBUTE(__error__ mesg, ERRORFUNC(mesg,x), rb_cv_func___error__)
 RUBY_FUNC_ATTRIBUTE(__warning__ mesg, WARNINGFUNC(mesg,x), rb_cv_func___warning__)
 RUBY_FUNC_ATTRIBUTE(__weak__, WEAK, rb_cv_func_weak)
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 56168)
+++ ChangeLog	(revision 56169)
@@ -1,3 +1,43 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Sep 16 14:54:34 2016  URABE Shyouhei  <shyouhei@r...>
+
+	* internal.h (WARN_UNUSED_RESULT): moved to configure.in, to
+	  actually check its availability rather to check GCC's version.
+
+	* configure.in (WARN_UNUSED_RESULT): moved to here.
+
+	* configure.in (RUBY_FUNC_ATTRIBUTE): change function declaration
+	  to return int rather than void, because it makes no sense for a
+	  warn_unused_result attributed function to return void.
+
+	  Funny thing however is that it also makes no sense for noreturn
+	  attributed function to return int.  So there is a fundamental
+	  conflict between them.  While I tested this, I confirmed both
+	  GCC 6 and Clang 3.8 prefers int over void to correctly detect
+	  necessary attributes under this setup.  Maybe subject to change
+	  in future.
+
+	* internal.h (UNINITIALIZED_VAR): renamed to MAYBE_UNUSED, then
+	  moved to configure.in for the same reason we move
+	  WARN_UNUSED_RESULT.
+
+	* configure.in (MAYBE_UNUSED): moved to here.
+
+	* internal.h (__has_attribute): deleted, because it has no use now.
+
+	* string.c (rb_str_enumerate_lines): refactor macro rename.
+
+	* string.c (rb_str_enumerate_bytes): ditto.
+
+	* string.c (rb_str_enumerate_chars): ditto.
+
+	* string.c (rb_str_enumerate_codepoints): ditto.
+
+	* thread.c (do_select): ditto.
+
+	* vm_backtrace.c (rb_debug_inspector_open): ditto.
+
+	* vsnprintf.c (BSD_vfprintf): ditto.
+
 Fri Sep 16 14:35:55 2016  URABE Shyouhei  <shyouhei@r...>
 
 	* ChangeLog (add-log-time-format): Not exactly sure when but
Index: internal.h
===================================================================
--- internal.h	(revision 56168)
+++ internal.h	(revision 56169)
@@ -26,26 +26,6 @@ extern "C" { https://github.com/ruby/ruby/blob/trunk/internal.h#L26
 #define LIKELY(x) RB_LIKELY(x)
 #define UNLIKELY(x) RB_UNLIKELY(x)
 
-#ifndef __has_attribute
-# define __has_attribute(x) 0
-#endif
-
-#if __has_attribute(__unused__)
-#define UNINITIALIZED_VAR(x) x __attribute__((__unused__))
-#elif defined(__GNUC__) && __GNUC__ >= 3
-#define UNINITIALIZED_VAR(x) x = x
-#else
-#define UNINITIALIZED_VAR(x) x
-#endif
-
-#if __has_attribute(__warn_unused_result__)
-#define WARN_UNUSED_RESULT(x) x __attribute__((__warn_unused_result__))
-#elif GCC_VERSION_SINCE(3,4,0)
-#define WARN_UNUSED_RESULT(x) x __attribute__((__warn_unused_result__))
-#else
-#define WARN_UNUSED_RESULT(x) x
-#endif
-
 #ifdef HAVE_VALGRIND_MEMCHECK_H
 # include <valgrind/memcheck.h>
 # ifndef VALGRIND_MAKE_MEM_DEFINED
Index: vsnprintf.c
===================================================================
--- vsnprintf.c	(revision 56168)
+++ vsnprintf.c	(revision 56169)
@@ -558,9 +558,9 @@ BSD_vfprintf(FILE *fp, const char *fmt0, https://github.com/ruby/ruby/blob/trunk/vsnprintf.c#L558
 	int fprec = 0;		/* floating point precision */
 	char expstr[7];		/* buffer for exponent string */
 #endif
-	u_long UNINITIALIZED_VAR(ulval); /* integer arguments %[diouxX] */
+	u_long MAYBE_UNUSED(ulval); /* integer arguments %[diouxX] */
 #ifdef _HAVE_SANE_QUAD_
-	u_quad_t UNINITIALIZED_VAR(uqval); /* %q integers */
+	u_quad_t MAYBE_UNUSED(uqval); /* %q integers */
 #endif /* _HAVE_SANE_QUAD_ */
 	int base;		/* base for [diouxX] conversion */
 	int dprec;		/* a copy of prec if [diouxX], 0 otherwise */
Index: vm_backtrace.c
===================================================================
--- vm_backtrace.c	(revision 56168)
+++ vm_backtrace.c	(revision 56169)
@@ -1173,7 +1173,7 @@ rb_debug_inspector_open(rb_debug_inspect https://github.com/ruby/ruby/blob/trunk/vm_backtrace.c#L1173
     rb_debug_inspector_t dbg_context;
     rb_thread_t *th = GET_THREAD();
     int state;
-    volatile VALUE UNINITIALIZED_VAR(result);
+    volatile VALUE MAYBE_UNUSED(result);
 
     dbg_context.th = th;
     dbg_context.cfp = dbg_context.th->cfp;
Index: string.c
===================================================================
--- string.c	(revision 56168)
+++ string.c	(revision 56169)
@@ -7348,7 +7348,7 @@ rb_str_enumerate_lines(int argc, VALUE * https://github.com/ruby/ruby/blob/trunk/string.c#L7348
     long pos, len, rslen;
     int paragraph_mode = 0;
 
-    VALUE UNINITIALIZED_VAR(ary);
+    VALUE MAYBE_UNUSED(ary);
 
     if (argc == 0)
 	rs = rb_rs;
@@ -7522,7 +7522,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/string.c#L7522
 rb_str_enumerate_bytes(VALUE str, int wantarray)
 {
     long i;
-    VALUE UNINITIALIZED_VAR(ary);
+    VALUE MAYBE_UNUSED(ary);
 
     if (rb_block_given_p()) {
 	if (wantarray) {
@@ -7606,7 +7606,7 @@ rb_str_enumerate_chars(VALUE str, int wa https://github.com/ruby/ruby/blob/trunk/string.c#L7606
     long i, len, n;
     const char *ptr;
     rb_encoding *enc;
-    VALUE UNINITIALIZED_VAR(ary);
+    VALUE MAYBE_UNUSED(ary);
 
     str = rb_str_new_frozen(str);
     ptr = RSTRING_PTR(str);
@@ -7705,7 +7705,7 @@ rb_str_enumerate_codepoints(VALUE str, i https://github.com/ruby/ruby/blob/trunk/string.c#L7705
     unsigned int c;
     const char *ptr, *end;
     rb_encoding *enc;
-    VALUE UNINITIALIZED_VAR(ary);
+    VALUE MAYBE_UNUSED(ary);
 
     if (single_byte_optimizable(str))
 	return rb_str_enumerate_bytes(str, wantarray);

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

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