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

ruby-changes:28441

From: akr <ko1@a...>
Date: Sat, 27 Apr 2013 15:52:27 +0900 (JST)
Subject: [ruby-changes:28441] akr:r40493 (trunk): * internal.h (SIGNED_INTEGER_TYPE_P): New macro.

akr	2013-04-27 15:52:17 +0900 (Sat, 27 Apr 2013)

  New Revision: 40493

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40493

  Log:
    * internal.h (SIGNED_INTEGER_TYPE_P): New macro.
      (SIGNED_INTEGER_MAX): Ditto.
      (SIGNED_INTEGER_MIN): Ditto.
      (UNSIGNED_INTEGER_MAX): Ditto.
      (TIMET_MAX): Use SIGNED_INTEGER_MAX and UNSIGNED_INTEGER_MAX.
      (TIMET_MIN): Use SIGNED_INTEGER_MIN.
    
    * thread.c (TIMEVAL_SEC_MAX): Use SIGNED_INTEGER_MAX.
      (TIMEVAL_SEC_MIN): Use SIGNED_INTEGER_MIN.

  Modified files:
    trunk/ChangeLog
    trunk/internal.h
    trunk/thread.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40492)
+++ ChangeLog	(revision 40493)
@@ -1,3 +1,15 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Apr 27 15:50:40 2013  Tanaka Akira  <akr@f...>
+
+	* internal.h (SIGNED_INTEGER_TYPE_P): New macro.
+	  (SIGNED_INTEGER_MAX): Ditto.
+	  (SIGNED_INTEGER_MIN): Ditto.
+	  (UNSIGNED_INTEGER_MAX): Ditto.
+	  (TIMET_MAX): Use SIGNED_INTEGER_MAX and UNSIGNED_INTEGER_MAX.
+	  (TIMET_MIN): Use SIGNED_INTEGER_MIN.
+
+	* thread.c (TIMEVAL_SEC_MAX): Use SIGNED_INTEGER_MAX.
+	  (TIMEVAL_SEC_MIN): Use SIGNED_INTEGER_MIN.
+
 Sat Apr 27 10:52:52 2013  Tanaka Akira  <akr@f...>
 
 	* thread.c (TIMEVAL_SEC_MAX, TIMEVAL_SEC_MIN): Consider environments,
Index: thread.c
===================================================================
--- thread.c	(revision 40492)
+++ thread.c	(revision 40493)
@@ -922,10 +922,8 @@ thread_value(VALUE self) https://github.com/ruby/ruby/blob/trunk/thread.c#L922
  */
 
 #if SIGNEDNESS_OF_TIME_T < 0	/* signed */
-# define TIMEVAL_SEC_MAXBIT \
-  (((TYPEOF_TIMEVAL_TV_SEC)1) << (sizeof(TYPEOF_TIMEVAL_TV_SEC) * CHAR_BIT - 2))
-# define TIMEVAL_SEC_MAX (TIMEVAL_SEC_MAXBIT | (TIMEVAL_SEC_MAXBIT-1))
-# define TIMEVAL_SEC_MIN (-TIMEVAL_SEC_MAX-1)
+# define TIMEVAL_SEC_MAX SIGNED_INTEGER_MAX(TYPEOF_TIMEVAL_TV_SEC)
+# define TIMEVAL_SEC_MIN SIGNED_INTEGER_MIN(TYPEOF_TIMEVAL_TV_SEC)
 #elif SIGNEDNESS_OF_TIME_T > 0	/* unsigned */
 # define TIMEVAL_SEC_MAX ((TYPEOF_TIMEVAL_TV_SEC)(~(unsigned_time_t)0))
 # define TIMEVAL_SEC_MIN ((TYPEOF_TIMEVAL_TV_SEC)0)
Index: internal.h
===================================================================
--- internal.h	(revision 40492)
+++ internal.h	(revision 40493)
@@ -25,12 +25,19 @@ extern "C" { https://github.com/ruby/ruby/blob/trunk/internal.h#L25
     (__GNUC__ == (major) && __GNUC_MINOR__ > (minor)) || \
     (__GNUC__ == (major) && __GNUC_MINOR__ == (minor) && __GNUC_PATCHLEVEL__ >= (patchlevel))))
 
+#define SIGNED_INTEGER_TYPE_P(int_type) (0 > ((int_type)0)-1)
+#define SIGNED_INTEGER_MAX(sint_type) \
+  ((((sint_type)1) << (sizeof(sint_type) * CHAR_BIT - 2)) | \
+  ((((sint_type)1) << (sizeof(sint_type) * CHAR_BIT - 2)) - 1))
+#define SIGNED_INTEGER_MIN(sint_type) (-SIGNED_INTEGER_MAX(sint_type)-1)
+#define UNSIGNED_INTEGER_MAX(uint_type) (~(uint_type)0)
+
 #if SIGNEDNESS_OF_TIME_T < 0	/* signed */
-# define TIMET_MAX (time_t)((~(unsigned_time_t)0) >> 1)
-# define TIMET_MIN (time_t)(((unsigned_time_t)1) << (sizeof(time_t) * CHAR_BIT - 1))
+# define TIMET_MAX SIGNED_INTEGER_MAX(time_t)
+# define TIMET_MIN SIGNED_INTEGER_MIN(time_t)
 #elif SIGNEDNESS_OF_TIME_T > 0	/* unsigned */
-# define TIMET_MAX (time_t)(~(unsigned_time_t)0)
-# define TIMET_MIN (time_t)0
+# define TIMET_MAX UNSIGNED_INTEGER_MAX(time_t)
+# define TIMET_MIN ((time_t)0)
 #endif
 #define TIMET_MAX_PLUS_ONE (2*(double)(TIMET_MAX/2+1))
 

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

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