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

ruby-changes:57320

From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Tue, 27 Aug 2019 17:48:39 +0900 (JST)
Subject: [ruby-changes:57320] 卜部昌平: 78628618da (master): struct st_hash_type now free from ANYARGS

https://git.ruby-lang.org/ruby.git/commit/?id=78628618da

From 78628618da98236fc1bf702079185b36ed394e2a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?=
 <shyouhei@r...>
Date: Tue, 27 Aug 2019 12:21:36 +0900
Subject: struct st_hash_type now free from ANYARGS

After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is
dangerous and should be extinct.  This commit adds function prototypes
for struct st_hash_type.  Honestly I don't understand why they were
commented out at the first place.

diff --git a/include/ruby/st.h b/include/ruby/st.h
index 9b48d51..2ca4384 100644
--- a/include/ruby/st.h
+++ b/include/ruby/st.h
@@ -59,8 +59,8 @@ typedef char st_check_for_sizeof_st_index_t[SIZEOF_VOIDP == (int)sizeof(st_index https://github.com/ruby/ruby/blob/trunk/include/ruby/st.h#L59
 #define SIZEOF_ST_INDEX_T SIZEOF_VOIDP
 
 struct st_hash_type {
-    int (*compare)(ANYARGS /*st_data_t, st_data_t*/); /* st_compare_func* */
-    st_index_t (*hash)(ANYARGS /*st_data_t*/);        /* st_hash_func* */
+    int (*compare)(st_data_t, st_data_t); /* st_compare_func* */
+    st_index_t (*hash)(st_data_t);        /* st_hash_func* */
 };
 
 #define ST_INDEX_BITS (SIZEOF_ST_INDEX_T * CHAR_BIT)
diff --git a/st.c b/st.c
index c32a7ed..880ab87 100644
--- a/st.c
+++ b/st.c
@@ -145,16 +145,17 @@ static const struct st_hash_type st_hashtype_num = { https://github.com/ruby/ruby/blob/trunk/st.c#L145
     st_numhash,
 };
 
-/* extern int strcmp(const char *, const char *); */
+static int st_strcmp(st_data_t, st_data_t);
 static st_index_t strhash(st_data_t);
 static const struct st_hash_type type_strhash = {
-    strcmp,
+    st_strcmp,
     strhash,
 };
 
+static int st_locale_insensitive_strcasecmp_i(st_data_t lhs, st_data_t rhs);
 static st_index_t strcasehash(st_data_t);
 static const struct st_hash_type type_strcasehash = {
-    st_locale_insensitive_strcasecmp,
+    st_locale_insensitive_strcasecmp_i,
     strcasehash,
 };
 
@@ -2091,6 +2092,22 @@ st_locale_insensitive_strncasecmp(const char *s1, const char *s2, size_t n) https://github.com/ruby/ruby/blob/trunk/st.c#L2092
     return 0;
 }
 
+static int
+st_strcmp(st_data_t lhs, st_data_t rhs)
+{
+    const char *s1 = (char *)lhs;
+    const char *s2 = (char *)rhs;
+    return strcmp(s1, s2);
+}
+
+static int
+st_locale_insensitive_strcasecmp_i(st_data_t lhs, st_data_t rhs)
+{
+    const char *s1 = (char *)lhs;
+    const char *s2 = (char *)rhs;
+    return st_locale_insensitive_strcasecmp(s1, s2);
+}
+
 NO_SANITIZE("unsigned-integer-overflow", PUREFUNC(static st_index_t strcasehash(st_data_t)));
 static st_index_t
 strcasehash(st_data_t arg)
-- 
cgit v0.10.2


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

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