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

ruby-changes:7952

From: nobu <ko1@a...>
Date: Tue, 23 Sep 2008 17:00:24 +0900 (JST)
Subject: [ruby-changes:7952] Ruby:r19474 (trunk, ruby_1_8): * hash.c (ENVMATCH, ENVNMATCH): reduced same code.

nobu	2008-09-23 16:59:48 +0900 (Tue, 23 Sep 2008)

  New Revision: 19474

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

  Log:
    * hash.c (ENVMATCH, ENVNMATCH): reduced same code.

  Modified files:
    branches/ruby_1_8/ChangeLog
    branches/ruby_1_8/hash.c
    trunk/ChangeLog
    trunk/hash.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 19473)
+++ ChangeLog	(revision 19474)
@@ -1,3 +1,7 @@
+Tue Sep 23 16:59:45 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* hash.c (ENVMATCH, ENVNMATCH): reduced same code.
+
 Tue Sep 23 16:55:11 2008  Koichi Sasada  <ko1@a...>
 
 	* ruby.h: fix comment and rename macro HAVE_RUBY_MVM_H to
Index: hash.c
===================================================================
--- hash.c	(revision 19473)
+++ hash.c	(revision 19474)
@@ -1799,6 +1799,13 @@
 #define GET_ENVIRON(e) (e)
 #define FREE_ENVIRON(e)
 #endif
+#ifdef ENV_IGNORECASE
+#define ENVMATCH(s1, s2) (STRCASECMP(s1, s2) == 0)
+#define ENVNMATCH(s1, s2, n) (STRNCASECMP(s1, s2, n) == 0)
+#else
+#define ENVMATCH(n1, n2) (strcmp(n1, n2) == 0)
+#define ENVNMATCH(s1, s2, n) (memcmp(s1, s2, n) == 0)
+#endif
 
 static VALUE
 env_str_new(const char *ptr, long len)
@@ -1832,12 +1839,7 @@
 	VALUE value = env_str_new2(val);
 
 	ruby_setenv(nam, 0);
-#ifdef ENV_IGNORECASE
-	if (STRCASECMP(nam, PATH_ENV) == 0)
-#else
-	if (strcmp(nam, PATH_ENV) == 0)
-#endif
-	{
+	if (ENVMATCH(nam, PATH_ENV)) {
 	    path_tainted = 0;
 	}
 	return value;
@@ -1868,12 +1870,7 @@
     }
     env = getenv(nam);
     if (env) {
-#ifdef ENV_IGNORECASE
-	if (STRCASECMP(nam, PATH_ENV) == 0 && !rb_env_path_tainted())
-#else
-	if (strcmp(nam, PATH_ENV) == 0 && !rb_env_path_tainted())
-#endif
-	{
+	if (ENVMATCH(nam, PATH_ENV) && !rb_env_path_tainted()) {
 	    VALUE str = rb_str_new2(env);
 
 	    rb_obj_freeze(str);
@@ -1910,11 +1907,7 @@
 	}
 	return if_none;
     }
-#ifdef ENV_IGNORECASE
-    if (STRCASECMP(nam, PATH_ENV) == 0 && !rb_env_path_tainted())
-#else
-    if (strcmp(nam, PATH_ENV) == 0 && !rb_env_path_tainted())
-#endif
+    if (ENVMATCH(nam, PATH_ENV) && !rb_env_path_tainted())
 	return rb_str_new2(env);
     return env_str_new2(env);
 }
@@ -1943,13 +1936,7 @@
 
     env = GET_ENVIRON(environ);
     for (i = 0; env[i]; i++) {
-	if (
-#ifdef ENV_IGNORECASE
-	    STRNCASECMP(env[i],nam,len) == 0
-#else
-	    memcmp(env[i],nam,len) == 0
-#endif
-	    && env[i][len] == '=')
+	if (ENVNMATCH(env[i],nam,len) && env[i][len] == '=')
 	    break;			/* memcmp must come first to avoid */
     }					/* potential SEGV's */
     FREE_ENVIRON(environ);
@@ -2066,11 +2053,7 @@
 	rb_raise(rb_eArgError, "bad environment variable value");
 
     ruby_setenv(name, value);
-#ifdef ENV_IGNORECASE
-    if (STRCASECMP(name, PATH_ENV) == 0) {
-#else
-    if (strcmp(name, PATH_ENV) == 0) {
-#endif
+    if (ENVMATCH(name, PATH_ENV)) {
 	if (OBJ_TAINTED(val)) {
 	    /* already tainted, no check */
 	    path_tainted = 1;
Index: ruby_1_8/hash.c
===================================================================
--- ruby_1_8/hash.c	(revision 19473)
+++ ruby_1_8/hash.c	(revision 19474)
@@ -1820,6 +1820,13 @@
 #define GET_ENVIRON(e) (e)
 #define FREE_ENVIRON(e)
 #endif
+#ifdef ENV_IGNORECASE
+#define ENVMATCH(s1, s2) (strcasecmp(s1, s2) == 0)
+#define ENVNMATCH(s1, s2, n) (strncasecmp(s1, s2, n) == 0)
+#else
+#define ENVMATCH(n1, n2) (strcmp(n1, n2) == 0)
+#define ENVNMATCH(s1, s2, n) (memcmp(s1, s2, n) == 0)
+#endif
 
 static VALUE
 env_str_new(ptr, len)
@@ -1857,12 +1864,7 @@
 	VALUE value = env_str_new2(val);
 
 	ruby_setenv(nam, 0);
-#ifdef ENV_IGNORECASE
-	if (strcasecmp(nam, PATH_ENV) == 0)
-#else
-	if (strcmp(nam, PATH_ENV) == 0)
-#endif
-	{
+	if (ENVMATCH(nam, PATH_ENV)) {
 	    path_tainted = 0;
 	}
 	return value;
@@ -1895,12 +1897,7 @@
     }
     env = getenv(nam);
     if (env) {
-#ifdef ENV_IGNORECASE
-	if (strcasecmp(nam, PATH_ENV) == 0 && !rb_env_path_tainted())
-#else
-	if (strcmp(nam, PATH_ENV) == 0 && !rb_env_path_tainted())
-#endif
-	{
+	if (ENVMATCH(nam, PATH_ENV) && !rb_env_path_tainted()) {
 	    VALUE str = rb_str_new2(env);
 
 	    rb_obj_freeze(str);
@@ -1939,11 +1936,7 @@
 	}
 	return if_none;
     }
-#ifdef ENV_IGNORECASE
-    if (strcasecmp(nam, PATH_ENV) == 0 && !rb_env_path_tainted())
-#else
-    if (strcmp(nam, PATH_ENV) == 0 && !rb_env_path_tainted())
-#endif
+    if (ENVMATCH(nam, PATH_ENV) && !rb_env_path_tainted())
 	return rb_str_new2(env);
     return env_str_new2(env);
 }
@@ -1974,13 +1967,7 @@
 
     env = GET_ENVIRON(environ);
     for (i = 0; env[i]; i++) {
-	if (
-#ifdef ENV_IGNORECASE
-	    strncasecmp(env[i],nam,len) == 0
-#else
-	    memcmp(env[i],nam,len) == 0
-#endif
-	    && env[i][len] == '=')
+	if (ENVNMATCH(env[i],nam,len) && env[i][len] == '=')
 	    break;			/* memcmp must come first to avoid */
     }					/* potential SEGV's */
     FREE_ENVIRON(environ);
@@ -2102,11 +2089,7 @@
 	rb_raise(rb_eArgError, "bad environment variable value");
 
     ruby_setenv(name, value);
-#ifdef ENV_IGNORECASE
-    if (strcasecmp(name, PATH_ENV) == 0) {
-#else
-    if (strcmp(name, PATH_ENV) == 0) {
-#endif
+    if (ENVMATCH(name, PATH_ENV)) {
 	if (OBJ_TAINTED(val)) {
 	    /* already tainted, no check */
 	    path_tainted = 1;
Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog	(revision 19473)
+++ ruby_1_8/ChangeLog	(revision 19474)
@@ -1,3 +1,7 @@
+Tue Sep 23 16:59:45 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* hash.c (ENVMATCH, ENVNMATCH): reduced same code.
+
 Tue Sep 23 08:20:59 2008  Yukihiro Matsumoto  <matz@r...>
 
 	* misc/ruby-mode.el: updated to the latest trunk (without encoding

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

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