From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: Kirill Shcherbatov <kshcherbatov@tarantool.org>
Cc: tarantool-patches@freelists.org,
Kirill Shcherbatov <kshcherbatov@gmail.com>
Subject: Re: [PATCH v2 1/1] Implement mp_stack class
Date: Mon, 4 Feb 2019 12:41:31 +0300 [thread overview]
Message-ID: <20190204094131.vw5kdo3rhuj4xxz3@esperanza> (raw)
In-Reply-To: <473372ec0b111ff0731857bb4c45409866cb3a5d.1549009319.git.kshcherbatov@gmail.com>
On Sun, Feb 03, 2019 at 01:21:43PM +0300, Kirill Shcherbatov wrote:
> diff --git a/msgpuck.c b/msgpuck.c
> index 72b800c..cb93d68 100644
> --- a/msgpuck.c
> +++ b/msgpuck.c
> @@ -323,25 +334,14 @@ mp_fprint_internal(FILE *file, const char **data)
> total_bytes += bytes; \
> } while (0)
> #define PRINT(...) HANDLE(fprintf, __VA_ARGS__)
> -#define SELF(...) HANDLE(mp_fprint_internal, __VA_ARGS__)
> -MP_PRINT(SELF, PRINT)
> +MP_PRINT(PRINT)
> #undef HANDLE
HANDLE is redundant, I removed it.
> -#undef SELF
> #undef PRINT
> return total_bytes;
> }
> +/**
> + * \brief Initialize mp_stack \a stack of specified size \a size
> + * and user-allocated array \a frames.
> + * The \a frames allocation must have at least \a size mp_frame
> + * items.
> + * \param stack - the pointer to a mp_stack to initialize.
> + * \param size - stack size, count of stack::frames to use.
> + * \param frames - mp_frame preallocated array of size \a size
> + * of struct mp_frame items
> + */
> +MP_PROTO void
> +mp_stack_create(struct mp_stack *stack, uint32_t size, struct mp_frame *frames);
> +
> +/**
> + * \brief Construct a new mp_frame and push it on to mp_stack
> + * \a stack.
> + * \param stack - the pointer to a stack to operate with.
> + * \param type - the type of mp_frame to create.
> + * \param count - the count of itemes of mp_frame to create.
> + * \pre mp_stack_is_full(stack) == false
> + */
> +MP_PROTO void
> +mp_stack_push(struct mp_stack *stack, enum mp_type type, uint32_t count);
s/uint32_t/int - Fixed.
Pushed to the master. My incremental diff is below.
diff --git a/msgpuck.c b/msgpuck.c
index cb93d68902bd..3338a3c38698 100644
--- a/msgpuck.c
+++ b/msgpuck.c
@@ -327,15 +327,13 @@ mp_fprint(FILE *file, const char *data)
if (!file)
file = stdout;
int total_bytes = 0;
-#define HANDLE(FUN, ...) do { \
- int bytes = FUN(file, __VA_ARGS__); \
+#define PRINT(...) do { \
+ int bytes = fprintf(file, __VA_ARGS__); \
if (mp_unlikely(bytes < 0)) \
return -1; \
total_bytes += bytes; \
} while (0)
-#define PRINT(...) HANDLE(fprintf, __VA_ARGS__)
-MP_PRINT(PRINT)
-#undef HANDLE
+ MP_PRINT(PRINT)
#undef PRINT
return total_bytes;
}
@@ -344,8 +342,8 @@ int
mp_snprint(char *buf, int size, const char *data)
{
int total_bytes = 0;
-#define HANDLE(FUN, ...) do { \
- int bytes = FUN(buf, size, __VA_ARGS__); \
+#define PRINT(...) do { \
+ int bytes = snprintf(buf, size, __VA_ARGS__); \
if (mp_unlikely(bytes < 0)) \
return -1; \
total_bytes += bytes; \
@@ -358,9 +356,7 @@ mp_snprint(char *buf, int size, const char *data)
size = 0; \
} \
} while (0)
-#define PRINT(...) HANDLE(snprintf, __VA_ARGS__)
-MP_PRINT(PRINT)
-#undef HANDLE
+ MP_PRINT(PRINT)
#undef PRINT
return total_bytes;
}
diff --git a/msgpuck.h b/msgpuck.h
index 15a6c9b36855..ab84f0b4936f 100644
--- a/msgpuck.h
+++ b/msgpuck.h
@@ -1237,7 +1237,7 @@ struct mp_stack {
* of struct mp_frame items
*/
MP_PROTO void
-mp_stack_create(struct mp_stack *stack, uint32_t size, struct mp_frame *frames);
+mp_stack_create(struct mp_stack *stack, int size, struct mp_frame *frames);
/**
* \brief Test if mp_stack \a stack is empty.
@@ -1272,7 +1272,7 @@ mp_stack_pop(struct mp_stack *stack);
* \pre mp_stack_is_full(stack) == false
*/
MP_PROTO void
-mp_stack_push(struct mp_stack *stack, enum mp_type type, uint32_t count);
+mp_stack_push(struct mp_stack *stack, enum mp_type type, int count);
/**
* \brief Get type attribute of the \a stack top frame.
@@ -2304,7 +2304,7 @@ mp_check(const char **data, const char *end)
}
MP_IMPL void
-mp_stack_create(struct mp_stack *stack, uint32_t size, struct mp_frame *frames)
+mp_stack_create(struct mp_stack *stack, int size, struct mp_frame *frames)
{
stack->frames = frames;
stack->size = size;
@@ -2331,10 +2331,10 @@ mp_stack_pop(struct mp_stack *stack)
}
MP_IMPL void
-mp_stack_push(struct mp_stack *stack, enum mp_type type, uint32_t count)
+mp_stack_push(struct mp_stack *stack, enum mp_type type, int count)
{
assert(!mp_stack_is_full(stack));
- uint32_t idx = stack->used++;
+ int idx = stack->used++;
stack->frames[idx].type = type;
stack->frames[idx].count = count;
stack->frames[idx].curr = -1;
prev parent reply other threads:[~2019-02-04 9:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-03 10:21 Kirill Shcherbatov
2019-02-04 9:41 ` Vladimir Davydov [this message]
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=20190204094131.vw5kdo3rhuj4xxz3@esperanza \
--to=vdavydov.dev@gmail.com \
--cc=kshcherbatov@gmail.com \
--cc=kshcherbatov@tarantool.org \
--cc=tarantool-patches@freelists.org \
--subject='Re: [PATCH v2 1/1] Implement mp_stack class' \
/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