From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.3 required=3.0 tests=ALL_TRUSTED,BAYES_00, RP_MATCHES_RCVD shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: spew@80x24.org Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 96033633810 for ; Thu, 30 Jul 2015 00:17:44 +0000 (UTC) From: Eric Wong To: spew@80x24.org Subject: [PATCH] st: constify st_table * in public API Date: Thu, 30 Jul 2015 00:17:44 +0000 Message-Id: <1438215464-5881-1-git-send-email-e@80x24.org> List-Id: --- include/ruby/st.h | 14 +++++++------- st.c | 16 +++++++++------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/include/ruby/st.h b/include/ruby/st.h index 190bad2..bfb1e1d 100644 --- a/include/ruby/st.h +++ b/include/ruby/st.h @@ -112,8 +112,8 @@ int st_delete_safe(st_table *, st_data_t *, st_data_t *, st_data_t); int st_shift(st_table *, st_data_t *, st_data_t *); /* returns 0:notfound 1:deleted */ int st_insert(st_table *, st_data_t, st_data_t); int st_insert2(st_table *, st_data_t, st_data_t, st_data_t (*)(st_data_t)); -int st_lookup(st_table *, st_data_t, st_data_t *); -int st_get_key(st_table *, st_data_t, st_data_t *); +int st_lookup(const st_table *, st_data_t, st_data_t *); +int st_get_key(const st_table *, st_data_t, st_data_t *); typedef int st_update_callback_func(st_data_t *key, st_data_t *value, st_data_t arg, int existing); /* *key may be altered, but must equal to the old key, i.e., the * results of hash() are same and compare() returns 0, otherwise the @@ -122,15 +122,15 @@ int st_update(st_table *table, st_data_t key, st_update_callback_func *func, st_ int st_foreach(st_table *, int (*)(ANYARGS), st_data_t); int st_foreach_check(st_table *, int (*)(ANYARGS), st_data_t, st_data_t); int st_reverse_foreach(st_table *, int (*)(ANYARGS), st_data_t); -st_index_t st_keys(st_table *table, st_data_t *keys, st_index_t size); -st_index_t st_keys_check(st_table *table, st_data_t *keys, st_index_t size, st_data_t never); -st_index_t st_values(st_table *table, st_data_t *values, st_index_t size); -st_index_t st_values_check(st_table *table, st_data_t *values, st_index_t size, st_data_t never); +st_index_t st_keys(const st_table *table, st_data_t *keys, st_index_t size); +st_index_t st_keys_check(const st_table *table, st_data_t *keys, st_index_t size, st_data_t never); +st_index_t st_values(const st_table *table, st_data_t *values, st_index_t size); +st_index_t st_values_check(const st_table *table, st_data_t *values, st_index_t size, st_data_t never); void st_add_direct(st_table *, st_data_t, st_data_t); void st_free_table(st_table *); void st_cleanup_safe(st_table *, st_data_t); void st_clear(st_table *); -st_table *st_copy(st_table *); +st_table *st_copy(const st_table *); int st_numcmp(st_data_t, st_data_t); st_index_t st_numhash(st_data_t); int st_locale_insensitive_strcasecmp(const char *s1, const char *s2); diff --git a/st.c b/st.c index 9b79704..2144d97 100644 --- a/st.c +++ b/st.c @@ -382,7 +382,7 @@ find_packed_index(const st_table *table, st_index_t hash_val, st_data_t key) #define collision_check 0 int -st_lookup(st_table *table, register st_data_t key, st_data_t *value) +st_lookup(const st_table *table, register st_data_t key, st_data_t *value) { st_index_t hash_val; register st_table_entry *ptr; @@ -410,7 +410,7 @@ st_lookup(st_table *table, register st_data_t key, st_data_t *value) } int -st_get_key(st_table *table, register st_data_t key, st_data_t *result) +st_get_key(const st_table *table, register st_data_t key, st_data_t *result) { st_index_t hash_val; register st_table_entry *ptr; @@ -622,7 +622,7 @@ rehash(register st_table *table) } st_table* -st_copy(st_table *old_table) +st_copy(const st_table *old_table) { st_table *new_table; st_table_entry *ptr = 0, *entry; @@ -1072,13 +1072,14 @@ get_keys(const st_table *table, st_data_t *keys, st_index_t size, } st_index_t -st_keys(st_table *table, st_data_t *keys, st_index_t size) +st_keys(const st_table *table, st_data_t *keys, st_index_t size) { return get_keys(table, keys, size, 0, 0); } st_index_t -st_keys_check(st_table *table, st_data_t *keys, st_index_t size, st_data_t never) +st_keys_check(const st_table *table, st_data_t *keys, st_index_t size, + st_data_t never) { return get_keys(table, keys, size, 1, never); } @@ -1116,13 +1117,14 @@ get_values(const st_table *table, st_data_t *values, st_index_t size, } st_index_t -st_values(st_table *table, st_data_t *values, st_index_t size) +st_values(const st_table *table, st_data_t *values, st_index_t size) { return get_values(table, values, size, 0, 0); } st_index_t -st_values_check(st_table *table, st_data_t *values, st_index_t size, st_data_t never) +st_values_check(const st_table *table, st_data_t *values, st_index_t size, + st_data_t never) { return get_values(table, values, size, 1, never); } -- EW