Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@dev.tarantool.org, tarantool-patches@freelists.org
Subject: [Tarantool-patches] [PATCH 1/2] rope: fix rope name template
Date: Sat, 26 Oct 2019 00:53:48 +0200	[thread overview]
Message-ID: <f3b92e4d76ce29b11f4a4351c0ad33782b37dca2.1572043528.git.v.shpilevoy@tarantool.org> (raw)
In-Reply-To: <cover.1572043528.git.v.shpilevoy@tarantool.org>

Rope is a library to define a custom rope data
structure with specified type of a stored value, and
some rope functions such as split, alloc.

It is possible to choose a unique name for a defined
rope structure. It was implemented as

    #define rope_api(x) rope_##rope_name##_##x
    #define rope rope_##rope_name

But with such rope_api definition it was always
expanded to `rope_rope_name_<x value>`. So rope_name
was basically a constant 'rope_name' regardless what
was defined under it.

The patch fixes it and makes name generation just like
bps_tree.h.

Additionally, the name template is changed a bit, now
it is

    <rope_name>_ + rope + _<method>

instead of

    <rope> + _<rope_name>_ + <method>

It just appeared to look better. For example, consider
rope name 'xrow_update' and method 'size':

    new: xrow_update_rope_size()
    old: rope_xrow_update_size()

The second name would be generated by the old template
and looks wrong. The new name not only looks better,
but also conforms with our code style.
---
 src/lib/salad/rope.h | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/lib/salad/rope.h b/src/lib/salad/rope.h
index f38ac0e79..4fdaa90b6 100644
--- a/src/lib/salad/rope.h
+++ b/src/lib/salad/rope.h
@@ -114,13 +114,18 @@ avl_iter_check(struct avl_iter *iter);
  * ROPE_FREE_F, optional
  */
 
+#define CONCAT_R(a, b) a##b
+#define CONCAT(a, b) CONCAT_R(a, b)
+#define CONCAT3_R(a, b, c) a##b##c
+#define CONCAT3(a, b, c) CONCAT3_R(a, b, c)
+
 #if defined(ROPE_SRC)
-	#define rope_api(x) avl_##x
+	#define rope_api(x) CONCAT(avl_, x)
 #elif defined(rope_name)
-	#define rope_api(x) rope_##rope_name##_##x
-	#define rope rope_##rope_name
+	#define rope_api(x) CONCAT3(rope_name, _rope_, x)
+	#define rope CONCAT(rope_name, _rope)
 #else
-	#define rope_api(x) rope_##x
+	#define rope_api(x) CONCAT(rope_, x)
 #endif
 
 #ifndef ROPE_FREE_F
@@ -712,6 +717,11 @@ rope_pretty_print(struct rope *rope, void (*print_leaf)(rope_data_t, size_t))
 #undef ROPE_FREE_F
 #undef ROPE_FREE
 
+#undef CONCAT_R
+#undef CONCAT
+#undef CONCAT3_R
+#undef CONCAT3
+
 #if defined(__cplusplus)
 }
 #endif /* defined(__cplusplus) */
-- 
2.21.0 (Apple Git-122)

  reply	other threads:[~2019-10-25 22:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-25 22:53 [Tarantool-patches] [PATCH 0/2] JSON update pre-preparation Vladislav Shpilevoy
2019-10-25 22:53 ` Vladislav Shpilevoy [this message]
2019-10-28  7:32   ` [Tarantool-patches] [PATCH 1/2] rope: fix rope name template Konstantin Osipov
2019-10-25 22:53 ` [Tarantool-patches] [PATCH 2/2] tuple: rename update to xrow_update in tuple_update.c Vladislav Shpilevoy
2019-10-28  7:33   ` Konstantin Osipov
2019-10-28  7:52 ` [Tarantool-patches] [tarantool-patches] [PATCH 0/2] JSON update pre-preparation Kirill Yukhin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f3b92e4d76ce29b11f4a4351c0ad33782b37dca2.1572043528.git.v.shpilevoy@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [Tarantool-patches] [PATCH 1/2] rope: fix rope name template' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox