Skip to contentSkip to conversation

cmdline: make cmdline structure opaque

PATCH New Dmitry Kozlyuk 6 participants 24 messages Sep 10, 2021 – Oct 22, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cmdline: make cmdline structure opaque

Remove the definition of struct cmdline from public header. Deprecation notice:
https://mails.dpdk.org/archives/dev/2020-September/183310.html

---
Unfortunately there's no deprection notice for struct rdline. If its definition was also hidden, the line buffer size limit could be changed or removed completely in the future.

 lib/cmdline/cmdline.h         | 19 -------------------
 lib/cmdline/cmdline_private.h | 11 ++++++++++-
 2 files changed, 10 insertions(+), 20 deletions(-)
lib/cmdline/cmdline.h +0 -19
index c29762ddae..96674dfda2 100644
@@ -7,10 +7,6 @@
 #ifndef _CMDLINE_H_
 #define _CMDLINE_H_
 
-#ifndef RTE_EXEC_ENV_WINDOWS
-#include <termios.h>
-#endif
-
 #include <rte_common.h>
 #include <rte_compat.h>
 
@@ -27,23 +23,8 @@
 extern "C" {
 #endif
 
-#ifndef RTE_EXEC_ENV_WINDOWS
-
-struct cmdline {
-	int s_in;
-	int s_out;
-	cmdline_parse_ctx_t *ctx;
-	struct rdline rdl;
-	char prompt[RDLINE_PROMPT_SIZE];
-	struct termios oldterm;
-};
-
-#else
-
 struct cmdline;
 
-#endif /* RTE_EXEC_ENV_WINDOWS */
-
 struct cmdline *cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_in, int s_out);
 void cmdline_set_prompt(struct cmdline *cl, const char *prompt);
 void cmdline_free(struct cmdline *cl);
lib/cmdline/cmdline_private.h +10 -1
index a87c45275c..7743807d0b 100644
@@ -33,7 +33,16 @@ struct cmdline {
 	char repeated_char;
 	WORD repeat_count;
 };
-#endif
+#else
+struct cmdline {
+	int s_in;
+	int s_out;
+	cmdline_parse_ctx_t *ctx;
+	struct rdline rdl;
+	char prompt[RDLINE_PROMPT_SIZE];
+	struct termios oldterm;
+};
+#endif /* !RTE_EXEC_ENV_WINDOWS */
 
 /* Disable buffering and echoing, save previous settings to oldterm. */
 void terminal_adjust(struct cmdline *cl);
Signature · 1 line
2.29.3
#1 lore raw

PATCH 1/1 cmdline: reduce ABI

Remove the definition of struct cmdline from public header. Deprecation notice:
https://mails.dpdk.org/archives/dev/2020-September/183310.html

---
I would also hide struct rdline to be able to alter buffer size, but we don't have a deprecation notice for it.

 doc/guides/rel_notes/deprecation.rst   |  4 ----
 doc/guides/rel_notes/release_21_11.rst |  2 ++
 lib/cmdline/cmdline.h                  | 19 -------------------
 lib/cmdline/cmdline_private.h          |  8 +++++++-
 4 files changed, 9 insertions(+), 24 deletions(-)
doc/guides/rel_notes/deprecation.rst +0 -4
index 76a4abfd6b..a404276fa2 100644
@@ -275,10 +275,6 @@ Deprecation Notices
 * metrics: The function ``rte_metrics_init`` will have a non-void return
   in order to notify errors instead of calling ``rte_exit``.
 
-* cmdline: ``cmdline`` structure will be made opaque to hide platform-specific
-  content. On Linux and FreeBSD, supported prior to DPDK 20.11,
-  original structure will be kept until DPDK 21.11.
-
 * security: The functions ``rte_security_set_pkt_metadata`` and
   ``rte_security_get_userdata`` will be made inline functions and additional
   flags will be added in structure ``rte_security_ctx`` in DPDK 21.11.
doc/guides/rel_notes/release_21_11.rst +2 -0
index 675b573834..be73d17ef6 100644
@@ -91,6 +91,8 @@ API Changes
    Also, make sure to start the actual text at the margin.
    =======================================================
 
+* cmdline: Made ``cmdline`` structure definition hidden on Linux and FreeBSD.
+
 
 ABI Changes
 -----------
lib/cmdline/cmdline.h +0 -19
index c29762ddae..96674dfda2 100644
@@ -7,10 +7,6 @@
 #ifndef _CMDLINE_H_
 #define _CMDLINE_H_
 
-#ifndef RTE_EXEC_ENV_WINDOWS
-#include <termios.h>
-#endif
-
 #include <rte_common.h>
 #include <rte_compat.h>
 
@@ -27,23 +23,8 @@
 extern "C" {
 #endif
 
-#ifndef RTE_EXEC_ENV_WINDOWS
-
-struct cmdline {
-	int s_in;
-	int s_out;
-	cmdline_parse_ctx_t *ctx;
-	struct rdline rdl;
-	char prompt[RDLINE_PROMPT_SIZE];
-	struct termios oldterm;
-};
-
-#else
-
 struct cmdline;
 
-#endif /* RTE_EXEC_ENV_WINDOWS */
-
 struct cmdline *cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_in, int s_out);
 void cmdline_set_prompt(struct cmdline *cl, const char *prompt);
 void cmdline_free(struct cmdline *cl);
lib/cmdline/cmdline_private.h +7 -1
index a87c45275c..2e93674c66 100644
@@ -11,6 +11,8 @@
 #include <rte_os_shim.h>
 #ifdef RTE_EXEC_ENV_WINDOWS
 #include <rte_windows.h>
+#else
+#include <termios.h>
 #endif
 
 #include <cmdline.h>
@@ -22,6 +24,7 @@ struct terminal {
 	int is_console_input;
 	int is_console_output;
 };
+#endif
 
 struct cmdline {
 	int s_in;
@@ -29,11 +32,14 @@ struct cmdline {
 	cmdline_parse_ctx_t *ctx;
 	struct rdline rdl;
 	char prompt[RDLINE_PROMPT_SIZE];
+#ifdef RTE_EXEC_ENV_WINDOWS
 	struct terminal oldterm;
 	char repeated_char;
 	WORD repeat_count;
-};
+#else
+	struct termios oldterm;
 #endif
+};
 
 /* Disable buffering and echoing, save previous settings to oldterm. */
 void terminal_adjust(struct cmdline *cl);
Signature · 1 line
2.29.3
Acked-by on v1 1/1
#2 lore raw

Re: [dpdk-dev] [PATCH] cmdline: reduce ABI

Quoted 6 lines · Dmitry Kozlyuk

Remove the definition of struct cmdline from public header. Deprecation notice:
https://mails.dpdk.org/archives/dev/2020-September/183310.html

This patch lgtm.

Quoted 3 lines

---
I would also hide struct rdline to be able to alter buffer size, but we don't have a deprecation notice for it.

Fyi, I found one project looking into a rdline pointer to get the back reference to cmdline stored in opaque.
https://github.com/Gandi/packet-journey/blob/master/app/cmdline.c#L1398

This cmdline pointer is then dereferenced to get s_out.
Given that we announced cmdline becoming opaque, they would have to handle the first API change in any case.
I don't think another API change would really make a big difference to them.

Plus, this project seems stuck to 18.08 support.

--
David Marchand

Acked-by
#3 lore raw

Re: [dpdk-dev] [PATCH] cmdline: reduce ABI

Hi Dmitry,

Quoted 10 lines · David Marchand
Quoted 6 lines · Dmitry Kozlyuk

Remove the definition of struct cmdline from public header. Deprecation notice:
https://mails.dpdk.org/archives/dev/2020-September/183310.html

This patch lgtm.

Many thanks Dmitry for taking care of this.

Quoted 8 lines
Quoted 3 lines

---
I would also hide struct rdline to be able to alter buffer size, but we don't have a deprecation notice for it.

Fyi, I found one project looking into a rdline pointer to get the back reference to cmdline stored in opaque.
https://github.com/Gandi/packet-journey/blob/master/app/cmdline.c#L1398

Quoted 6 lines

This cmdline pointer is then dereferenced to get s_out.
Given that we announced cmdline becoming opaque, they would have to handle the first API change in any case.
I don't think another API change would really make a big difference to them.

Plus, this project seems stuck to 18.08 support.

I agree with you and David, it would make sense to also hide the rdline struct at the same time.

Olivier

#4 lore raw

v2 cover cmdline: reduce ABI

In reply to Dmitry Kozlyuk

Hide struct cmdline following the deprecation notice. Hide struct rdline following the v1 discussion.

Dmitry Kozlyuk (2):
cmdline: make struct cmdline opaque
cmdline: make struct rdline opaque

 app/test-cmdline/commands.c            |  2 +-
 app/test/test_cmdline_lib.c            | 19 +++---
 doc/guides/rel_notes/deprecation.rst   |  4 --
 doc/guides/rel_notes/release_21_11.rst |  2 +
 lib/cmdline/cmdline.c                  |  3 +-
 lib/cmdline/cmdline.h                  | 19 ------
 lib/cmdline/cmdline_cirbuf.c           |  1 -
 lib/cmdline/cmdline_private.h          | 57 +++++++++++++++++-
 lib/cmdline/cmdline_rdline.c           | 50 +++++++++++++++-
 lib/cmdline/cmdline_rdline.h           | 83 +++++++++-----------------
 lib/cmdline/version.map                |  8 ++-
 11 files changed, 155 insertions(+), 93 deletions(-)
Signature · 1 line
2.29.3
#5 lore raw

PATCH v2 1/2 cmdline: make struct cmdline opaque

Remove the definition of struct cmdline from public header. Deprecation notice:
https://mails.dpdk.org/archives/dev/2020-September/183310.html

---
 doc/guides/rel_notes/deprecation.rst   |  4 ----
 doc/guides/rel_notes/release_21_11.rst |  2 ++
 lib/cmdline/cmdline.h                  | 19 -------------------
 lib/cmdline/cmdline_private.h          |  8 +++++++-
 4 files changed, 9 insertions(+), 24 deletions(-)
doc/guides/rel_notes/deprecation.rst +0 -4
index 76a4abfd6b..a404276fa2 100644
@@ -275,10 +275,6 @@ Deprecation Notices
 * metrics: The function ``rte_metrics_init`` will have a non-void return
   in order to notify errors instead of calling ``rte_exit``.
 
-* cmdline: ``cmdline`` structure will be made opaque to hide platform-specific
-  content. On Linux and FreeBSD, supported prior to DPDK 20.11,
-  original structure will be kept until DPDK 21.11.
-
 * security: The functions ``rte_security_set_pkt_metadata`` and
   ``rte_security_get_userdata`` will be made inline functions and additional
   flags will be added in structure ``rte_security_ctx`` in DPDK 21.11.
doc/guides/rel_notes/release_21_11.rst +2 -0
index b55900936d..18377e5813 100644
@@ -101,6 +101,8 @@ API Changes
    Also, make sure to start the actual text at the margin.
    =======================================================
 
+* cmdline: Made ``cmdline`` structure definition hidden on Linux and FreeBSD.
+
 
 ABI Changes
 -----------
lib/cmdline/cmdline.h +0 -19
index c29762ddae..96674dfda2 100644
@@ -7,10 +7,6 @@
 #ifndef _CMDLINE_H_
 #define _CMDLINE_H_
 
-#ifndef RTE_EXEC_ENV_WINDOWS
-#include <termios.h>
-#endif
-
 #include <rte_common.h>
 #include <rte_compat.h>
 
@@ -27,23 +23,8 @@
 extern "C" {
 #endif
 
-#ifndef RTE_EXEC_ENV_WINDOWS
-
-struct cmdline {
-	int s_in;
-	int s_out;
-	cmdline_parse_ctx_t *ctx;
-	struct rdline rdl;
-	char prompt[RDLINE_PROMPT_SIZE];
-	struct termios oldterm;
-};
-
-#else
-
 struct cmdline;
 
-#endif /* RTE_EXEC_ENV_WINDOWS */
-
 struct cmdline *cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_in, int s_out);
 void cmdline_set_prompt(struct cmdline *cl, const char *prompt);
 void cmdline_free(struct cmdline *cl);
lib/cmdline/cmdline_private.h +7 -1
index a87c45275c..2e93674c66 100644
@@ -11,6 +11,8 @@
 #include <rte_os_shim.h>
 #ifdef RTE_EXEC_ENV_WINDOWS
 #include <rte_windows.h>
+#else
+#include <termios.h>
 #endif
 
 #include <cmdline.h>
@@ -22,6 +24,7 @@ struct terminal {
 	int is_console_input;
 	int is_console_output;
 };
+#endif
 
 struct cmdline {
 	int s_in;
@@ -29,11 +32,14 @@ struct cmdline {
 	cmdline_parse_ctx_t *ctx;
 	struct rdline rdl;
 	char prompt[RDLINE_PROMPT_SIZE];
+#ifdef RTE_EXEC_ENV_WINDOWS
 	struct terminal oldterm;
 	char repeated_char;
 	WORD repeat_count;
-};
+#else
+	struct termios oldterm;
 #endif
+};
 
 /* Disable buffering and echoing, save previous settings to oldterm. */
 void terminal_adjust(struct cmdline *cl);
Signature · 1 line
2.29.3
#6 lore raw

PATCH v2 2/2 cmdline: make struct rdline opaque

In reply to Dmitry Kozlyuk

Hide struct rdline definition and some RDLINE_* constants in order to be able to change internal buffer sizes transparently to the user. Add new functions:

* rdline_create(): allocate and initialize struct rdline. This function replaces rdline_init() and takes an extra parameter:
opaque user data for the callbacks.
* rdline_free(): deallocate struct rdline.
* rdline_get_history_buffer_size(): for use in tests.
* rdline_get_opaque(): to obtain user data in callback functions.

Remove rdline_init() function from library headers and export list, because using it requires the knowledge of sizeof(struct rdline).

---
 app/test-cmdline/commands.c   |  2 +-
 app/test/test_cmdline_lib.c   | 19 +++++---
 lib/cmdline/cmdline.c         |  3 +-
 lib/cmdline/cmdline_cirbuf.c  |  1 -
 lib/cmdline/cmdline_private.h | 49 +++++++++++++++++++++
 lib/cmdline/cmdline_rdline.c  | 50 +++++++++++++++++++--
 lib/cmdline/cmdline_rdline.h  | 83 ++++++++++++-----------------------
 lib/cmdline/version.map       |  8 +++-
 8 files changed, 146 insertions(+), 69 deletions(-)
app/test-cmdline/commands.c +1 -1
index d732976f08..a13e1d1afd 100644
@@ -297,7 +297,7 @@ cmd_get_history_bufsize_parsed(__rte_unused void *parsed_result,
 	struct rdline *rdl = cmdline_get_rdline(cl);
 
 	cmdline_printf(cl, "History buffer size: %zu\n",
-			sizeof(rdl->history_buf));
+			rdline_get_history_buffer_size(rdl));
 }
 
 cmdline_parse_token_string_t cmd_get_history_bufsize_tok =
app/test/test_cmdline_lib.c +12 -7
index d5a09b4541..367dcad5be 100644
@@ -83,18 +83,18 @@ test_cmdline_parse_fns(void)
 static int
 test_cmdline_rdline_fns(void)
 {
-	struct rdline rdl;
+	struct rdline *rdl = NULL;
 	rdline_write_char_t *wc = &cmdline_write_char;
 	rdline_validate_t *v = &valid_buffer;
 	rdline_complete_t *c = &complete_buffer;
 
-	if (rdline_init(NULL, wc, v, c) >= 0)
+	if (rdline_create(NULL, wc, v, c, NULL) >= 0)
 		goto error;
-	if (rdline_init(&rdl, NULL, v, c) >= 0)
+	if (rdline_create(&rdl, NULL, v, c, NULL) >= 0)
 		goto error;
-	if (rdline_init(&rdl, wc, NULL, c) >= 0)
+	if (rdline_create(&rdl, wc, NULL, c, NULL) >= 0)
 		goto error;
-	if (rdline_init(&rdl, wc, v, NULL) >= 0)
+	if (rdline_create(&rdl, wc, v, NULL, NULL) >= 0)
 		goto error;
 	if (rdline_char_in(NULL, 0) >= 0)
 		goto error;
@@ -102,25 +102,30 @@ test_cmdline_rdline_fns(void)
 		goto error;
 	if (rdline_add_history(NULL, "history") >= 0)
 		goto error;
-	if (rdline_add_history(&rdl, NULL) >= 0)
+	if (rdline_add_history(rdl, NULL) >= 0)
 		goto error;
 	if (rdline_get_history_item(NULL, 0) != NULL)
 		goto error;
 
 	/* void functions */
+	rdline_get_history_buffer_size(NULL);
+	rdline_get_opaque(NULL);
 	rdline_newline(NULL, "prompt");
-	rdline_newline(&rdl, NULL);
+	rdline_newline(rdl, NULL);
 	rdline_stop(NULL);
 	rdline_quit(NULL);
 	rdline_restart(NULL);
 	rdline_redisplay(NULL);
 	rdline_reset(NULL);
 	rdline_clear_history(NULL);
+	rdline_free(NULL);
 
+	rdline_free(rdl);
 	return 0;
 
 error:
 	printf("Error: function accepted null parameter!\n");
+	rdline_free(rdl);
 	return -1;
 }
 
lib/cmdline/cmdline.c +1 -2
index a176d15130..8f1854cb0b 100644
@@ -85,13 +85,12 @@ cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_in, int s_out)
 	cl->ctx = ctx;
 
 	ret = rdline_init(&cl->rdl, cmdline_write_char, cmdline_valid_buffer,
-			cmdline_complete_buffer);
+			cmdline_complete_buffer, cl);
 	if (ret != 0) {
 		free(cl);
 		return NULL;
 	}
 
-	cl->rdl.opaque = cl;
 	cmdline_set_prompt(cl, prompt);
 	rdline_newline(&cl->rdl, cl->prompt);
 
lib/cmdline/cmdline_cirbuf.c +0 -1
index 829a8af563..cbb76a7016 100644
@@ -10,7 +10,6 @@
 
 #include "cmdline_cirbuf.h"
 
-
 int
 cirbuf_init(struct cirbuf *cbuf, char *buf, unsigned int start, unsigned int maxlen)
 {
lib/cmdline/cmdline_private.h +49 -0

59 lines not on this page · raw message

lib/cmdline/cmdline_rdline.c +47 -3

78 lines not on this page · raw message

lib/cmdline/cmdline_rdline.h +29 -54

115 lines not on this page · raw message

lib/cmdline/version.map +7 -1
index 980adb4f23..13feb4d0a5 100644
@@ -57,7 +57,6 @@ DPDK_22 {
 	rdline_clear_history;
 	rdline_get_buffer;
 	rdline_get_history_item;
-	rdline_init;
 	rdline_newline;
 	rdline_quit;
 	rdline_redisplay;
@@ -73,7 +72,14 @@ DPDK_22 {
 EXPERIMENTAL {
 	global:
 
+	# added in 20.11
 	cmdline_get_rdline;
 
+	# added in 21.11
+	rdline_create;
+	rdline_free;
+	rdline_get_history_buffer_size;
+	rdline_get_opaque;
+
 	local: *;
 };
Signature · 1 line
2.29.3
#7 lore raw

v3 cover cmdline: reduce ABI

In reply to Dmitry Kozlyuk

Hide struct cmdline following the deprecation notice. Hide struct rdline following the v1 discussion.

v3: add experimental tags and releae notes for rdline.
v2: also hide struct rdline (David, Olivier).

Dmitry Kozlyuk (2):
cmdline: make struct cmdline opaque
cmdline: make struct rdline opaque

 app/test-cmdline/commands.c            |  2 +-
 app/test/test_cmdline_lib.c            | 19 ++++--
 doc/guides/rel_notes/deprecation.rst   |  4 --
 doc/guides/rel_notes/release_21_11.rst |  5 ++
 lib/cmdline/cmdline.c                  |  3 +-
 lib/cmdline/cmdline.h                  | 19 ------
 lib/cmdline/cmdline_cirbuf.c           |  1 -
 lib/cmdline/cmdline_private.h          | 57 ++++++++++++++++-
 lib/cmdline/cmdline_rdline.c           | 50 ++++++++++++++-
 lib/cmdline/cmdline_rdline.h           | 88 ++++++++++----------------
 lib/cmdline/version.map                |  8 ++-
 11 files changed, 163 insertions(+), 93 deletions(-)
Signature · 1 line
2.29.3
#8 lore raw

PATCH v3 1/2 cmdline: make struct cmdline opaque

Remove the definition of struct cmdline from public header. Deprecation notice:
https://mails.dpdk.org/archives/dev/2020-September/183310.html

---
 doc/guides/rel_notes/deprecation.rst   |  4 ----
 doc/guides/rel_notes/release_21_11.rst |  2 ++
 lib/cmdline/cmdline.h                  | 19 -------------------
 lib/cmdline/cmdline_private.h          |  8 +++++++-
 4 files changed, 9 insertions(+), 24 deletions(-)
doc/guides/rel_notes/deprecation.rst +0 -4
index 76a4abfd6b..a404276fa2 100644
@@ -275,10 +275,6 @@ Deprecation Notices
 * metrics: The function ``rte_metrics_init`` will have a non-void return
   in order to notify errors instead of calling ``rte_exit``.
 
-* cmdline: ``cmdline`` structure will be made opaque to hide platform-specific
-  content. On Linux and FreeBSD, supported prior to DPDK 20.11,
-  original structure will be kept until DPDK 21.11.
-
 * security: The functions ``rte_security_set_pkt_metadata`` and
   ``rte_security_get_userdata`` will be made inline functions and additional
   flags will be added in structure ``rte_security_ctx`` in DPDK 21.11.
doc/guides/rel_notes/release_21_11.rst +2 -0
index b55900936d..18377e5813 100644
@@ -101,6 +101,8 @@ API Changes
    Also, make sure to start the actual text at the margin.
    =======================================================
 
+* cmdline: Made ``cmdline`` structure definition hidden on Linux and FreeBSD.
+
 
 ABI Changes
 -----------
lib/cmdline/cmdline.h +0 -19
index c29762ddae..96674dfda2 100644
@@ -7,10 +7,6 @@
 #ifndef _CMDLINE_H_
 #define _CMDLINE_H_
 
-#ifndef RTE_EXEC_ENV_WINDOWS
-#include <termios.h>
-#endif
-
 #include <rte_common.h>
 #include <rte_compat.h>
 
@@ -27,23 +23,8 @@
 extern "C" {
 #endif
 
-#ifndef RTE_EXEC_ENV_WINDOWS
-
-struct cmdline {
-	int s_in;
-	int s_out;
-	cmdline_parse_ctx_t *ctx;
-	struct rdline rdl;
-	char prompt[RDLINE_PROMPT_SIZE];
-	struct termios oldterm;
-};
-
-#else
-
 struct cmdline;
 
-#endif /* RTE_EXEC_ENV_WINDOWS */
-
 struct cmdline *cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_in, int s_out);
 void cmdline_set_prompt(struct cmdline *cl, const char *prompt);
 void cmdline_free(struct cmdline *cl);
lib/cmdline/cmdline_private.h +7 -1
index a87c45275c..2e93674c66 100644
@@ -11,6 +11,8 @@
 #include <rte_os_shim.h>
 #ifdef RTE_EXEC_ENV_WINDOWS
 #include <rte_windows.h>
+#else
+#include <termios.h>
 #endif
 
 #include <cmdline.h>
@@ -22,6 +24,7 @@ struct terminal {
 	int is_console_input;
 	int is_console_output;
 };
+#endif
 
 struct cmdline {
 	int s_in;
@@ -29,11 +32,14 @@ struct cmdline {
 	cmdline_parse_ctx_t *ctx;
 	struct rdline rdl;
 	char prompt[RDLINE_PROMPT_SIZE];
+#ifdef RTE_EXEC_ENV_WINDOWS
 	struct terminal oldterm;
 	char repeated_char;
 	WORD repeat_count;
-};
+#else
+	struct termios oldterm;
 #endif
+};
 
 /* Disable buffering and echoing, save previous settings to oldterm. */
 void terminal_adjust(struct cmdline *cl);
Signature · 1 line
2.29.3
#9 lore raw

PATCH v3 2/2 cmdline: make struct rdline opaque

In reply to Dmitry Kozlyuk

Hide struct rdline definition and some RDLINE_* constants in order to be able to change internal buffer sizes transparently to the user. Add new functions:

* rdline_create(): allocate and initialize struct rdline. This function replaces rdline_init() and takes an extra parameter:
opaque user data for the callbacks.
* rdline_free(): deallocate struct rdline.
* rdline_get_history_buffer_size(): for use in tests.
* rdline_get_opaque(): to obtain user data in callback functions.

Remove rdline_init() function from library headers and export list, because using it requires the knowledge of sizeof(struct rdline).

---
 app/test-cmdline/commands.c            |  2 +-
 app/test/test_cmdline_lib.c            | 19 ++++--
 doc/guides/rel_notes/release_21_11.rst |  3 +
 lib/cmdline/cmdline.c                  |  3 +-
 lib/cmdline/cmdline_cirbuf.c           |  1 -
 lib/cmdline/cmdline_private.h          | 49 ++++++++++++++
 lib/cmdline/cmdline_rdline.c           | 50 ++++++++++++++-
 lib/cmdline/cmdline_rdline.h           | 88 ++++++++++----------------
 lib/cmdline/version.map                |  8 ++-
 9 files changed, 154 insertions(+), 69 deletions(-)
app/test-cmdline/commands.c +1 -1
index d732976f08..a13e1d1afd 100644
@@ -297,7 +297,7 @@ cmd_get_history_bufsize_parsed(__rte_unused void *parsed_result,
 	struct rdline *rdl = cmdline_get_rdline(cl);
 
 	cmdline_printf(cl, "History buffer size: %zu\n",
-			sizeof(rdl->history_buf));
+			rdline_get_history_buffer_size(rdl));
 }
 
 cmdline_parse_token_string_t cmd_get_history_bufsize_tok =
app/test/test_cmdline_lib.c +12 -7
index d5a09b4541..367dcad5be 100644
@@ -83,18 +83,18 @@ test_cmdline_parse_fns(void)
 static int
 test_cmdline_rdline_fns(void)
 {
-	struct rdline rdl;
+	struct rdline *rdl = NULL;
 	rdline_write_char_t *wc = &cmdline_write_char;
 	rdline_validate_t *v = &valid_buffer;
 	rdline_complete_t *c = &complete_buffer;
 
-	if (rdline_init(NULL, wc, v, c) >= 0)
+	if (rdline_create(NULL, wc, v, c, NULL) >= 0)
 		goto error;
-	if (rdline_init(&rdl, NULL, v, c) >= 0)
+	if (rdline_create(&rdl, NULL, v, c, NULL) >= 0)
 		goto error;
-	if (rdline_init(&rdl, wc, NULL, c) >= 0)
+	if (rdline_create(&rdl, wc, NULL, c, NULL) >= 0)
 		goto error;
-	if (rdline_init(&rdl, wc, v, NULL) >= 0)
+	if (rdline_create(&rdl, wc, v, NULL, NULL) >= 0)
 		goto error;
 	if (rdline_char_in(NULL, 0) >= 0)
 		goto error;
@@ -102,25 +102,30 @@ test_cmdline_rdline_fns(void)
 		goto error;
 	if (rdline_add_history(NULL, "history") >= 0)
 		goto error;
-	if (rdline_add_history(&rdl, NULL) >= 0)
+	if (rdline_add_history(rdl, NULL) >= 0)
 		goto error;
 	if (rdline_get_history_item(NULL, 0) != NULL)
 		goto error;
 
 	/* void functions */
+	rdline_get_history_buffer_size(NULL);
+	rdline_get_opaque(NULL);
 	rdline_newline(NULL, "prompt");
-	rdline_newline(&rdl, NULL);
+	rdline_newline(rdl, NULL);
 	rdline_stop(NULL);
 	rdline_quit(NULL);
 	rdline_restart(NULL);
 	rdline_redisplay(NULL);
 	rdline_reset(NULL);
 	rdline_clear_history(NULL);
+	rdline_free(NULL);
 
+	rdline_free(rdl);
 	return 0;
 
 error:
 	printf("Error: function accepted null parameter!\n");
+	rdline_free(rdl);
 	return -1;
 }
 
doc/guides/rel_notes/release_21_11.rst +3 -0
index 18377e5813..af11f4a656 100644
@@ -103,6 +103,9 @@ API Changes
 
 * cmdline: Made ``cmdline`` structure definition hidden on Linux and FreeBSD.
 
+* cmdline: Made ``rdline`` structure definition hidden. Functions are added
+  to dynamically allocate and free it, and to access user data in callbacks.
+
 
 ABI Changes
 -----------
lib/cmdline/cmdline.c +1 -2
index a176d15130..8f1854cb0b 100644
@@ -85,13 +85,12 @@ cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_in, int s_out)
 	cl->ctx = ctx;
 
 	ret = rdline_init(&cl->rdl, cmdline_write_char, cmdline_valid_buffer,
-			cmdline_complete_buffer);
+			cmdline_complete_buffer, cl);
 	if (ret != 0) {
 		free(cl);
 		return NULL;
 	}
 
-	cl->rdl.opaque = cl;
 	cmdline_set_prompt(cl, prompt);
 	rdline_newline(&cl->rdl, cl->prompt);
 
lib/cmdline/cmdline_cirbuf.c +0 -1
index 829a8af563..cbb76a7016 100644
@@ -10,7 +10,6 @@
 
 #include "cmdline_cirbuf.h"
 
-
 int
 cirbuf_init(struct cirbuf *cbuf, char *buf, unsigned int start, unsigned int maxlen)
 {
lib/cmdline/cmdline_private.h +49 -0

59 lines not on this page · raw message

lib/cmdline/cmdline_rdline.c +47 -3

78 lines not on this page · raw message

lib/cmdline/cmdline_rdline.h +34 -54

126 lines not on this page · raw message

lib/cmdline/version.map +7 -1
index 980adb4f23..13feb4d0a5 100644
@@ -57,7 +57,6 @@ DPDK_22 {
 	rdline_clear_history;
 	rdline_get_buffer;
 	rdline_get_history_item;
-	rdline_init;
 	rdline_newline;
 	rdline_quit;
 	rdline_redisplay;
@@ -73,7 +72,14 @@ DPDK_22 {
 EXPERIMENTAL {
 	global:
 
+	# added in 20.11
 	cmdline_get_rdline;
 
+	# added in 21.11
+	rdline_create;
+	rdline_free;
+	rdline_get_history_buffer_size;
+	rdline_get_opaque;
+
 	local: *;
 };
Signature · 1 line
2.29.3
#10 lore raw

Re: [dpdk-dev] [PATCH v3 2/2] cmdline: make struct rdline opaque

Hi Dmitry,

Few comments below.

Quoted 32 lines · Dmitry Kozlyuk

Hide struct rdline definition and some RDLINE_* constants in order to be able to change internal buffer sizes transparently to the user. Add new functions:

* rdline_create(): allocate and initialize struct rdline. This function replaces rdline_init() and takes an extra parameter:
opaque user data for the callbacks.
* rdline_free(): deallocate struct rdline.
* rdline_get_history_buffer_size(): for use in tests.
* rdline_get_opaque(): to obtain user data in callback functions.

Remove rdline_init() function from library headers and export list, because using it requires the knowledge of sizeof(struct rdline).

---
 app/test-cmdline/commands.c            |  2 +-
 app/test/test_cmdline_lib.c            | 19 ++++--
 doc/guides/rel_notes/release_21_11.rst |  3 +
 lib/cmdline/cmdline.c                  |  3 +-
 lib/cmdline/cmdline_cirbuf.c           |  1 -
 lib/cmdline/cmdline_private.h          | 49 ++++++++++++++
 lib/cmdline/cmdline_rdline.c           | 50 ++++++++++++++-
 lib/cmdline/cmdline_rdline.h           | 88 ++++++++++----------------
 lib/cmdline/version.map                |  8 ++-
 9 files changed, 154 insertions(+), 69 deletions(-)
app/test-cmdline/commands.c +0 -0
index d732976f08..a13e1d1afd 100644

app/test-cmdline/commands.c cmd_get_history_bufsize_parsed(__rte_unused void *parsed_result, · line 300

Quoted 5 lines
app/test-cmdline/commands.c +1 -1
@@ -297,7 +297,7 @@ cmd_get_history_bufsize_parsed(__rte_unused void *parsed_result,
 	struct rdline *rdl = cmdline_get_rdline(cl);
 
 	cmdline_printf(cl, "History buffer size: %zu\n",
-			sizeof(rdl->history_buf));
+			rdline_get_history_buffer_size(rdl));

My first impression was that having this function just for the tests was not really useful.

But thinking a bit more about it, now that the structure is hidden, we could have an API in the future to change the size of the history buffer, in which case this function makes sense.

[...]

lib/cmdline/cmdline_cirbuf.c line 15

Quoted 12 lines
lib/cmdline/cmdline_cirbuf.c +0 -1
index 829a8af563..cbb76a7016 100644
@@ -10,7 +10,6 @@
 
 #include "cmdline_cirbuf.h"
 
-
 int
 cirbuf_init(struct cirbuf *cbuf, char *buf, unsigned int start, unsigned int maxlen)
 {

unexpected change

[...]

Quoted 30 lines
lib/cmdline/cmdline_rdline.c +6 -3
@@ -13,6 +13,7 @@
 #include <ctype.h>
 
 #include "cmdline_cirbuf.h"
+#include "cmdline_private.h"
 #include "cmdline_rdline.h"
 
 static void rdline_puts(struct rdline *rdl, const char *buf);
@@ -37,9 +38,10 @@ isblank2(char c)
 
 int
 rdline_init(struct rdline *rdl,
-		 rdline_write_char_t *write_char,
-		 rdline_validate_t *validate,
-		 rdline_complete_t *complete)
+	    rdline_write_char_t *write_char,
+	    rdline_validate_t *validate,
+	    rdline_complete_t *complete,
+	    void *opaque)
 {
 	if (!rdl || !write_char || !validate || !complete)
 		return -EINVAL;
@@ -47,10 +49,40 @@ rdline_init(struct rdline *rdl,
 	rdl->validate = validate;
 	rdl->complete = complete;
 	rdl->write_char = write_char;
+	rdl->opaque = opaque;
 	rdl->status = RDLINE_INIT;

lib/cmdline/cmdline_rdline.c rdline_init(struct rdline *rdl, · line 63

Quoted 10 lines
lib/cmdline/cmdline_rdline.c +7 -0
 	return cirbuf_init(&rdl->history, rdl->history_buf, 0, RDLINE_HISTORY_BUF_SIZE);
 }
 
+int
+rdline_create(struct rdline **out,
+	      rdline_write_char_t *write_char,
+	      rdline_validate_t *validate,
+	      rdline_complete_t *complete,
+	      void *opaque)
+{

For consistency, wouldn't it be better to keep the same model than cmdline_new()? I mean return a pointer and name it rdline_new().

Quoted 15 lines
lib/cmdline/cmdline_rdline.c +15 -0
+	struct rdline *rdl;
+	int ret;
+
+	if (out == NULL)
+		return -EINVAL;
+	rdl = malloc(sizeof(*rdl));
+	if (rdl == NULL)
+		return -ENOMEM;
+	ret = rdline_init(rdl, write_char, validate, complete, opaque);
+	if (ret < 0)
+		free(rdl);
+	else
+		*out = rdl;
+	return ret;
+}

[...]

lib/cmdline/cmdline_rdline.c rdline_get_history_item(struct rdline * rdl, unsigned int idx) · line 609

Quoted 11 lines
lib/cmdline/cmdline_rdline.c +11 -0
+size_t
+rdline_get_history_buffer_size(struct rdline *rdl)
+{
+	return sizeof(rdl->history_buf);
+}
+
+void *
+rdline_get_opaque(struct rdline *rdl)
+{
+	return rdl != NULL ? rdl->opaque : NULL;
+}

rdline_get_opaque() is safe when rdl is NULL, but
rdline_get_history_buffer_size() is not.

To me, both are acceptable but I'd prefer to have the same behavior for these 2 functions.

Apart from that, looks good to me.

Thanks!
Olivier

#11 lore raw

Re: [dpdk-dev] [PATCH v3 2/2] cmdline: make struct rdline opaque

Hi Olivier,

Thanks for the review, please see below.

2021-10-05 10:27 (UTC+0200), Olivier Matz:

Quoted 7 lines

[...]

Quoted 6 lines
lib/cmdline/cmdline_cirbuf.c +0 -0
index 829a8af563..cbb76a7016 100644
@@ -10,7 +10,6 @@
 
Quoted 8 lines

lib/cmdline/cmdline_cirbuf.c line 15

Quoted 6 lines
lib/cmdline/cmdline_cirbuf.c +0 -1
 #include "cmdline_cirbuf.h"
 
-
 int
 cirbuf_init(struct cirbuf *cbuf, char *buf, unsigned int start, unsigned int maxlen)
 {  

unexpected change

Will remove in v4.

Quoted 35 lines

[...]

Quoted 33 lines
lib/cmdline/cmdline_rdline.c +6 -3
@@ -13,6 +13,7 @@
 #include <ctype.h>
 
 #include "cmdline_cirbuf.h"
+#include "cmdline_private.h"
 #include "cmdline_rdline.h"
 
 static void rdline_puts(struct rdline *rdl, const char *buf);
@@ -37,9 +38,10 @@ isblank2(char c)
 
 int
 rdline_init(struct rdline *rdl,
-		 rdline_write_char_t *write_char,
-		 rdline_validate_t *validate,
-		 rdline_complete_t *complete)
+	    rdline_write_char_t *write_char,
+	    rdline_validate_t *validate,
+	    rdline_complete_t *complete,
+	    void *opaque)
 {
 	if (!rdl || !write_char || !validate || !complete)
 		return -EINVAL;
@@ -47,10 +49,40 @@ rdline_init(struct rdline *rdl,
 	rdl->validate = validate;
 	rdl->complete = complete;
 	rdl->write_char = write_char;
+	rdl->opaque = opaque;
 	rdl->status = RDLINE_INIT;
 	return cirbuf_init(&rdl->history, rdl->history_buf, 0, RDLINE_HISTORY_BUF_SIZE);
 }
 
Quoted 10 lines

lib/cmdline/cmdline_rdline.c rdline_init(struct rdline *rdl, · line 63

Quoted 7 lines
lib/cmdline/cmdline_rdline.c +7 -0
+int
+rdline_create(struct rdline **out,
+	      rdline_write_char_t *write_char,
+	      rdline_validate_t *validate,
+	      rdline_complete_t *complete,
+	      void *opaque)
+{  

For consistency, wouldn't it be better to keep the same model than cmdline_new()? I mean return a pointer and name it rdline_new().

If we don't really need to distinguish EINVAL and ENOMEM errors here, then I agree. Otherwise, do you propose to return the error code via rte_errno? Currenly no cmdline functions use it. This would also add a runtime dependency on EAL (currently cmdline only depends on its headers).

Quoted 16 lines

[...]

lib/cmdline/cmdline_rdline.c rdline_get_history_item(struct rdline * rdl, unsigned int idx) · line 609

Quoted 11 lines
lib/cmdline/cmdline_rdline.c +11 -0
+size_t
+rdline_get_history_buffer_size(struct rdline *rdl)
+{
+	return sizeof(rdl->history_buf);
+}
+
+void *
+rdline_get_opaque(struct rdline *rdl)
+{
+	return rdl != NULL ? rdl->opaque : NULL;
+}  

rdline_get_opaque() is safe when rdl is NULL, but
rdline_get_history_buffer_size() is not.

Quoted 2 lines

To me, both are acceptable but I'd prefer to have the same behavior for these 2 functions.

rdline_get_history_buffer_size() is safe because sizeof() is evaluated at compile time. There's a unit test checking that all functions are NULL-safe.

#12 lore raw

Re: [dpdk-dev] [PATCH v3 2/2] cmdline: make struct rdline opaque

Quoted 69 lines · Dmitry Kozlyuk

Hi Olivier,

Thanks for the review, please see below.

2021-10-05 10:27 (UTC+0200), Olivier Matz:

Quoted 7 lines

[...]

Quoted 6 lines
lib/cmdline/cmdline_cirbuf.c +0 -0
index 829a8af563..cbb76a7016 100644
@@ -10,7 +10,6 @@
 
Quoted 8 lines

lib/cmdline/cmdline_cirbuf.c line 15

Quoted 6 lines
lib/cmdline/cmdline_cirbuf.c +0 -1
 #include "cmdline_cirbuf.h"
 
-
 int
 cirbuf_init(struct cirbuf *cbuf, char *buf, unsigned int start, unsigned int maxlen)
 {  

unexpected change

Will remove in v4.

Quoted 35 lines

[...]

Quoted 33 lines
lib/cmdline/cmdline_rdline.c +6 -3
@@ -13,6 +13,7 @@
 #include <ctype.h>
 
 #include "cmdline_cirbuf.h"
+#include "cmdline_private.h"
 #include "cmdline_rdline.h"
 
 static void rdline_puts(struct rdline *rdl, const char *buf);
@@ -37,9 +38,10 @@ isblank2(char c)
 
 int
 rdline_init(struct rdline *rdl,
-		 rdline_write_char_t *write_char,
-		 rdline_validate_t *validate,
-		 rdline_complete_t *complete)
+	    rdline_write_char_t *write_char,
+	    rdline_validate_t *validate,
+	    rdline_complete_t *complete,
+	    void *opaque)
 {
 	if (!rdl || !write_char || !validate || !complete)
 		return -EINVAL;
@@ -47,10 +49,40 @@ rdline_init(struct rdline *rdl,
 	rdl->validate = validate;
 	rdl->complete = complete;
 	rdl->write_char = write_char;
+	rdl->opaque = opaque;
 	rdl->status = RDLINE_INIT;
 	return cirbuf_init(&rdl->history, rdl->history_buf, 0, RDLINE_HISTORY_BUF_SIZE);
 }
 
Quoted 10 lines

lib/cmdline/cmdline_rdline.c rdline_init(struct rdline *rdl, · line 63

Quoted 7 lines
lib/cmdline/cmdline_rdline.c +7 -0
+int
+rdline_create(struct rdline **out,
+	      rdline_write_char_t *write_char,
+	      rdline_validate_t *validate,
+	      rdline_complete_t *complete,
+	      void *opaque)
+{  

For consistency, wouldn't it be better to keep the same model than cmdline_new()? I mean return a pointer and name it rdline_new().

Quoted 4 lines

If we don't really need to distinguish EINVAL and ENOMEM errors here, then I agree. Otherwise, do you propose to return the error code via rte_errno? Currenly no cmdline functions use it. This would also add a runtime dependency on EAL (currently cmdline only depends on its headers).

Good point, I was indeed thinking about NULL + rte_errno, but I did not anticipate the new dependency to eal.

Given there's no errno in cmdline_new(), which is the main user API, I think we can do the same for rdline_new().

Quoted 16 lines
Quoted 16 lines

[...]

lib/cmdline/cmdline_rdline.c rdline_get_history_item(struct rdline * rdl, unsigned int idx) · line 609

Quoted 11 lines
lib/cmdline/cmdline_rdline.c +11 -0
+size_t
+rdline_get_history_buffer_size(struct rdline *rdl)
+{
+	return sizeof(rdl->history_buf);
+}
+
+void *
+rdline_get_opaque(struct rdline *rdl)
+{
+	return rdl != NULL ? rdl->opaque : NULL;
+}  

rdline_get_opaque() is safe when rdl is NULL, but
rdline_get_history_buffer_size() is not.

Quoted 5 lines
Quoted 2 lines

To me, both are acceptable but I'd prefer to have the same behavior for these 2 functions.

rdline_get_history_buffer_size() is safe because sizeof() is evaluated at compile time. There's a unit test checking that all functions are NULL-safe.

Oh yes, of course, thanks.

#13 lore raw

v4 cover cmdline: reduce ABI

In reply to Dmitry Kozlyuk

Hide struct cmdline following the deprecation notice. Hide struct rdline following the v1 discussion.

v4: rdline_create -> rdline_new, restore empty line (Olivier).
v3: add experimental tags and releae notes for rdline.
v2: also hide struct rdline (David, Olivier).

Dmitry Kozlyuk (2):
cmdline: make struct cmdline opaque
cmdline: make struct rdline opaque

 app/test-cmdline/commands.c            |  2 +-
 app/test/test_cmdline_lib.c            | 22 ++++---
 doc/guides/rel_notes/deprecation.rst   |  4 --
 doc/guides/rel_notes/release_21_11.rst |  5 ++
 lib/cmdline/cmdline.c                  |  3 +-
 lib/cmdline/cmdline.h                  | 19 ------
 lib/cmdline/cmdline_private.h          | 57 ++++++++++++++++-
 lib/cmdline/cmdline_rdline.c           | 43 ++++++++++++-
 lib/cmdline/cmdline_rdline.h           | 87 ++++++++++----------------
 lib/cmdline/version.map                |  8 ++-
 10 files changed, 157 insertions(+), 93 deletions(-)
Signature · 1 line
2.29.3
#14 lore raw

PATCH v4 1/2 cmdline: make struct cmdline opaque

Remove the definition of struct cmdline from public header. Deprecation notice:
https://mails.dpdk.org/archives/dev/2020-September/183310.html

---
 doc/guides/rel_notes/deprecation.rst   |  4 ----
 doc/guides/rel_notes/release_21_11.rst |  2 ++
 lib/cmdline/cmdline.h                  | 19 -------------------
 lib/cmdline/cmdline_private.h          |  8 +++++++-
 4 files changed, 9 insertions(+), 24 deletions(-)
doc/guides/rel_notes/deprecation.rst +0 -4
index 76a4abfd6b..a404276fa2 100644
@@ -275,10 +275,6 @@ Deprecation Notices
 * metrics: The function ``rte_metrics_init`` will have a non-void return
   in order to notify errors instead of calling ``rte_exit``.
 
-* cmdline: ``cmdline`` structure will be made opaque to hide platform-specific
-  content. On Linux and FreeBSD, supported prior to DPDK 20.11,
-  original structure will be kept until DPDK 21.11.
-
 * security: The functions ``rte_security_set_pkt_metadata`` and
   ``rte_security_get_userdata`` will be made inline functions and additional
   flags will be added in structure ``rte_security_ctx`` in DPDK 21.11.
doc/guides/rel_notes/release_21_11.rst +2 -0
index b55900936d..18377e5813 100644
@@ -101,6 +101,8 @@ API Changes
    Also, make sure to start the actual text at the margin.
    =======================================================
 
+* cmdline: Made ``cmdline`` structure definition hidden on Linux and FreeBSD.
+
 
 ABI Changes
 -----------
lib/cmdline/cmdline.h +0 -19
index c29762ddae..96674dfda2 100644
@@ -7,10 +7,6 @@
 #ifndef _CMDLINE_H_
 #define _CMDLINE_H_
 
-#ifndef RTE_EXEC_ENV_WINDOWS
-#include <termios.h>
-#endif
-
 #include <rte_common.h>
 #include <rte_compat.h>
 
@@ -27,23 +23,8 @@
 extern "C" {
 #endif
 
-#ifndef RTE_EXEC_ENV_WINDOWS
-
-struct cmdline {
-	int s_in;
-	int s_out;
-	cmdline_parse_ctx_t *ctx;
-	struct rdline rdl;
-	char prompt[RDLINE_PROMPT_SIZE];
-	struct termios oldterm;
-};
-
-#else
-
 struct cmdline;
 
-#endif /* RTE_EXEC_ENV_WINDOWS */
-
 struct cmdline *cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_in, int s_out);
 void cmdline_set_prompt(struct cmdline *cl, const char *prompt);
 void cmdline_free(struct cmdline *cl);
lib/cmdline/cmdline_private.h +7 -1
index a87c45275c..2e93674c66 100644
@@ -11,6 +11,8 @@
 #include <rte_os_shim.h>
 #ifdef RTE_EXEC_ENV_WINDOWS
 #include <rte_windows.h>
+#else
+#include <termios.h>
 #endif
 
 #include <cmdline.h>
@@ -22,6 +24,7 @@ struct terminal {
 	int is_console_input;
 	int is_console_output;
 };
+#endif
 
 struct cmdline {
 	int s_in;
@@ -29,11 +32,14 @@ struct cmdline {
 	cmdline_parse_ctx_t *ctx;
 	struct rdline rdl;
 	char prompt[RDLINE_PROMPT_SIZE];
+#ifdef RTE_EXEC_ENV_WINDOWS
 	struct terminal oldterm;
 	char repeated_char;
 	WORD repeat_count;
-};
+#else
+	struct termios oldterm;
 #endif
+};
 
 /* Disable buffering and echoing, save previous settings to oldterm. */
 void terminal_adjust(struct cmdline *cl);
Signature · 1 line
2.29.3
#15 lore raw

PATCH v4 2/2 cmdline: make struct rdline opaque

In reply to Dmitry Kozlyuk

Hide struct rdline definition and some RDLINE_* constants in order to be able to change internal buffer sizes transparently to the user. Add new functions:

* rdline_new(): allocate and initialize struct rdline. This function replaces rdline_init() and takes an extra parameter:
opaque user data for the callbacks.
* rdline_free(): deallocate struct rdline.
* rdline_get_history_buffer_size(): for use in tests.
* rdline_get_opaque(): to obtain user data in callback functions.

Remove rdline_init() function from library headers and export list, because using it requires the knowledge of sizeof(struct rdline).

---
 app/test-cmdline/commands.c            |  2 +-
 app/test/test_cmdline_lib.c            | 22 ++++---
 doc/guides/rel_notes/release_21_11.rst |  3 +
 lib/cmdline/cmdline.c                  |  3 +-
 lib/cmdline/cmdline_private.h          | 49 +++++++++++++++
 lib/cmdline/cmdline_rdline.c           | 43 ++++++++++++-
 lib/cmdline/cmdline_rdline.h           | 87 ++++++++++----------------
 lib/cmdline/version.map                |  8 ++-
 8 files changed, 148 insertions(+), 69 deletions(-)
app/test-cmdline/commands.c +1 -1
index d732976f08..a13e1d1afd 100644
@@ -297,7 +297,7 @@ cmd_get_history_bufsize_parsed(__rte_unused void *parsed_result,
 	struct rdline *rdl = cmdline_get_rdline(cl);
 
 	cmdline_printf(cl, "History buffer size: %zu\n",
-			sizeof(rdl->history_buf));
+			rdline_get_history_buffer_size(rdl));
 }
 
 cmdline_parse_token_string_t cmd_get_history_bufsize_tok =
app/test/test_cmdline_lib.c +14 -8
index d5a09b4541..24bc03fccb 100644
@@ -83,18 +83,19 @@ test_cmdline_parse_fns(void)
 static int
 test_cmdline_rdline_fns(void)
 {
-	struct rdline rdl;
+	struct rdline *rdl = NULL;
 	rdline_write_char_t *wc = &cmdline_write_char;
 	rdline_validate_t *v = &valid_buffer;
 	rdline_complete_t *c = &complete_buffer;
 
-	if (rdline_init(NULL, wc, v, c) >= 0)
+	rdl = rdline_new(NULL, v, c, NULL);
+	if (rdl != NULL)
 		goto error;
-	if (rdline_init(&rdl, NULL, v, c) >= 0)
+	rdl = rdline_new(wc, NULL, c, NULL);
+	if (rdl != NULL)
 		goto error;
-	if (rdline_init(&rdl, wc, NULL, c) >= 0)
-		goto error;
-	if (rdline_init(&rdl, wc, v, NULL) >= 0)
+	rdl = rdline_new(wc, v, NULL, NULL);
+	if (rdl != NULL)
 		goto error;
 	if (rdline_char_in(NULL, 0) >= 0)
 		goto error;
@@ -102,25 +103,30 @@ test_cmdline_rdline_fns(void)
 		goto error;
 	if (rdline_add_history(NULL, "history") >= 0)
 		goto error;
-	if (rdline_add_history(&rdl, NULL) >= 0)
+	if (rdline_add_history(rdl, NULL) >= 0)
 		goto error;
 	if (rdline_get_history_item(NULL, 0) != NULL)
 		goto error;
 
 	/* void functions */
+	rdline_get_history_buffer_size(NULL);
+	rdline_get_opaque(NULL);
 	rdline_newline(NULL, "prompt");
-	rdline_newline(&rdl, NULL);
+	rdline_newline(rdl, NULL);
 	rdline_stop(NULL);
 	rdline_quit(NULL);
 	rdline_restart(NULL);
 	rdline_redisplay(NULL);
 	rdline_reset(NULL);
 	rdline_clear_history(NULL);
+	rdline_free(NULL);
 
+	rdline_free(rdl);
 	return 0;
 
 error:
 	printf("Error: function accepted null parameter!\n");
+	rdline_free(rdl);
 	return -1;
 }
 
doc/guides/rel_notes/release_21_11.rst +3 -0
index 18377e5813..af11f4a656 100644
@@ -103,6 +103,9 @@ API Changes
 
 * cmdline: Made ``cmdline`` structure definition hidden on Linux and FreeBSD.
 
+* cmdline: Made ``rdline`` structure definition hidden. Functions are added
+  to dynamically allocate and free it, and to access user data in callbacks.
+
 
 ABI Changes
 -----------
lib/cmdline/cmdline.c +1 -2
index a176d15130..8f1854cb0b 100644
@@ -85,13 +85,12 @@ cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_in, int s_out)
 	cl->ctx = ctx;
 
 	ret = rdline_init(&cl->rdl, cmdline_write_char, cmdline_valid_buffer,
-			cmdline_complete_buffer);
+			cmdline_complete_buffer, cl);
 	if (ret != 0) {
 		free(cl);
 		return NULL;
 	}
 
-	cl->rdl.opaque = cl;
 	cmdline_set_prompt(cl, prompt);
 	rdline_newline(&cl->rdl, cl->prompt);
 
lib/cmdline/cmdline_private.h +49 -0

59 lines not on this page · raw message

lib/cmdline/cmdline_rdline.c +40 -3

71 lines not on this page · raw message

lib/cmdline/cmdline_rdline.h +33 -54

125 lines not on this page · raw message

lib/cmdline/version.map +7 -1
index 980adb4f23..b9bbb87510 100644
@@ -57,7 +57,6 @@ DPDK_22 {
 	rdline_clear_history;
 	rdline_get_buffer;
 	rdline_get_history_item;
-	rdline_init;
 	rdline_newline;
 	rdline_quit;
 	rdline_redisplay;
@@ -73,7 +72,14 @@ DPDK_22 {
 EXPERIMENTAL {
 	global:
 
+	# added in 20.11
 	cmdline_get_rdline;
 
+	# added in 21.11
+	rdline_new;
+	rdline_free;
+	rdline_get_history_buffer_size;
+	rdline_get_opaque;
+
 	local: *;
 };
Signature · 1 line
2.29.3
#16 lore raw

Re: [dpdk-dev] [PATCH v4 2/2] cmdline: make struct rdline opaque

app/test/test_cmdline_lib.c test_cmdline_parse_fns(void) · line 86

Quoted 7 lines · On Tue, 5 Oct 2021 23:15:45 +0300 Dmitry Kozlyuk <[email protected]>…

+++ b/app/test/test_cmdline_lib.c

app/test/test_cmdline_lib.c +1 -1
@@ -83,18 +83,19 @@ test_cmdline_parse_fns(void)
 static int
 test_cmdline_rdline_fns(void)
 {
-	struct rdline rdl;
+	struct rdline *rdl = NULL;

Very minor nit. The variable does not need to be initialized since first statement assigns the value.

#17 lore raw

Re: [dpdk-dev] [PATCH v4 2/2] cmdline: make struct rdline opaque

In reply to Dmitry Kozlyuk

Hi Dmitry,

Quoted 15 lines · Dmitry Kozlyuk

Hide struct rdline definition and some RDLINE_* constants in order to be able to change internal buffer sizes transparently to the user. Add new functions:

* rdline_new(): allocate and initialize struct rdline. This function replaces rdline_init() and takes an extra parameter:
opaque user data for the callbacks.
* rdline_free(): deallocate struct rdline.
* rdline_get_history_buffer_size(): for use in tests.
* rdline_get_opaque(): to obtain user data in callback functions.

Remove rdline_init() function from library headers and export list, because using it requires the knowledge of sizeof(struct rdline).

[...]

Quoted 16 lines

/**
- * Init fields for a struct rdline. Call this only once at the beginning
- * of your program.
- * \param rdl A pointer to an uninitialized struct rdline
+ * Allocate and initialize a new rdline instance.
+ *
+ * \param rdl Receives a pointer to the allocated structure.
* \param write_char The function used by the function to write a character
* \param validate A pointer to the function to execute when the
* user validates the buffer.
* \param complete A pointer to the function to execute when the
* user completes the buffer.
+ * \param opaque User data for use in the callbacks.
+ *
+ * \return 0 on success, negative errno-style code in failure. */

lib/cmdline/cmdline_rdline.h typedef int (rdline_complete_t)(struct rdline *rdl, const char *buf, · line 66

Quoted 9 lines
lib/cmdline/cmdline_rdline.h +5 -4
-int rdline_init(struct rdline *rdl,
-		 rdline_write_char_t *write_char,
-		 rdline_validate_t *validate,
-		 rdline_complete_t *complete);
+__rte_experimental
+struct rdline *rdline_new(rdline_write_char_t *write_char,
+			  rdline_validate_t *validate,
+			  rdline_complete_t *complete,
+			  void *opaque);

The API documentation was not updated after the v4 changes.

Apart from this, LGTM, you can directly add my ack in the next version.

Thanks,
Olivier

#18 lore raw

v5 cover cmdline: reduce ABI

In reply to Dmitry Kozlyuk

Hide struct cmdline following the deprecation notice. Hide struct rdline following the v1 discussion.

v5: fix API documentation (Olivier),
remove useless NULL assignment (Stephen).
v4: rdline_create -> rdline_new, restore empty line (Olivier).
v3: add experimental tags and releae notes for rdline.
v2: also hide struct rdline (David, Olivier).

Dmitry Kozlyuk (2):
cmdline: make struct cmdline opaque
cmdline: make struct rdline opaque

 app/test-cmdline/commands.c            |  2 +-
 app/test/test_cmdline_lib.c            | 22 ++++---
 doc/guides/rel_notes/deprecation.rst   |  4 --
 doc/guides/rel_notes/release_21_11.rst |  5 ++
 lib/cmdline/cmdline.c                  |  3 +-
 lib/cmdline/cmdline.h                  | 19 ------
 lib/cmdline/cmdline_private.h          | 57 ++++++++++++++++-
 lib/cmdline/cmdline_rdline.c           | 43 ++++++++++++-
 lib/cmdline/cmdline_rdline.h           | 86 ++++++++++----------------
 lib/cmdline/version.map                |  8 ++-
 10 files changed, 156 insertions(+), 93 deletions(-)
Signature · 1 line
2.29.3
#19 lore raw

PATCH v5 1/2 cmdline: make struct cmdline opaque

Remove the definition of struct cmdline from public header. Deprecation notice:
https://mails.dpdk.org/archives/dev/2020-September/183310.html

---
 doc/guides/rel_notes/deprecation.rst   |  4 ----
 doc/guides/rel_notes/release_21_11.rst |  2 ++
 lib/cmdline/cmdline.h                  | 19 -------------------
 lib/cmdline/cmdline_private.h          |  8 +++++++-
 4 files changed, 9 insertions(+), 24 deletions(-)
doc/guides/rel_notes/deprecation.rst +0 -4
index 76a4abfd6b..a404276fa2 100644
@@ -275,10 +275,6 @@ Deprecation Notices
 * metrics: The function ``rte_metrics_init`` will have a non-void return
   in order to notify errors instead of calling ``rte_exit``.
 
-* cmdline: ``cmdline`` structure will be made opaque to hide platform-specific
-  content. On Linux and FreeBSD, supported prior to DPDK 20.11,
-  original structure will be kept until DPDK 21.11.
-
 * security: The functions ``rte_security_set_pkt_metadata`` and
   ``rte_security_get_userdata`` will be made inline functions and additional
   flags will be added in structure ``rte_security_ctx`` in DPDK 21.11.
doc/guides/rel_notes/release_21_11.rst +2 -0
index b55900936d..18377e5813 100644
@@ -101,6 +101,8 @@ API Changes
    Also, make sure to start the actual text at the margin.
    =======================================================
 
+* cmdline: Made ``cmdline`` structure definition hidden on Linux and FreeBSD.
+
 
 ABI Changes
 -----------
lib/cmdline/cmdline.h +0 -19
index c29762ddae..96674dfda2 100644
@@ -7,10 +7,6 @@
 #ifndef _CMDLINE_H_
 #define _CMDLINE_H_
 
-#ifndef RTE_EXEC_ENV_WINDOWS
-#include <termios.h>
-#endif
-
 #include <rte_common.h>
 #include <rte_compat.h>
 
@@ -27,23 +23,8 @@
 extern "C" {
 #endif
 
-#ifndef RTE_EXEC_ENV_WINDOWS
-
-struct cmdline {
-	int s_in;
-	int s_out;
-	cmdline_parse_ctx_t *ctx;
-	struct rdline rdl;
-	char prompt[RDLINE_PROMPT_SIZE];
-	struct termios oldterm;
-};
-
-#else
-
 struct cmdline;
 
-#endif /* RTE_EXEC_ENV_WINDOWS */
-
 struct cmdline *cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_in, int s_out);
 void cmdline_set_prompt(struct cmdline *cl, const char *prompt);
 void cmdline_free(struct cmdline *cl);
lib/cmdline/cmdline_private.h +7 -1
index a87c45275c..2e93674c66 100644
@@ -11,6 +11,8 @@
 #include <rte_os_shim.h>
 #ifdef RTE_EXEC_ENV_WINDOWS
 #include <rte_windows.h>
+#else
+#include <termios.h>
 #endif
 
 #include <cmdline.h>
@@ -22,6 +24,7 @@ struct terminal {
 	int is_console_input;
 	int is_console_output;
 };
+#endif
 
 struct cmdline {
 	int s_in;
@@ -29,11 +32,14 @@ struct cmdline {
 	cmdline_parse_ctx_t *ctx;
 	struct rdline rdl;
 	char prompt[RDLINE_PROMPT_SIZE];
+#ifdef RTE_EXEC_ENV_WINDOWS
 	struct terminal oldterm;
 	char repeated_char;
 	WORD repeat_count;
-};
+#else
+	struct termios oldterm;
 #endif
+};
 
 /* Disable buffering and echoing, save previous settings to oldterm. */
 void terminal_adjust(struct cmdline *cl);
Signature · 1 line
2.29.3
Acked-by on v5 1/2
#20 lore raw

Re: [dpdk-dev] [PATCH v5 1/2] cmdline: make struct cmdline opaque

Quoted 8 lines · Dmitry Kozlyuk

Remove the definition of struct cmdline from public header. Deprecation notice:
https://mails.dpdk.org/archives/dev/2020-September/183310.html

---

#21 lore raw

PATCH v5 2/2 cmdline: make struct rdline opaque

In reply to Dmitry Kozlyuk

Hide struct rdline definition and some RDLINE_* constants in order to be able to change internal buffer sizes transparently to the user. Add new functions:

* rdline_new(): allocate and initialize struct rdline. This function replaces rdline_init() and takes an extra parameter:
opaque user data for the callbacks.
* rdline_free(): deallocate struct rdline.
* rdline_get_history_buffer_size(): for use in tests.
* rdline_get_opaque(): to obtain user data in callback functions.

Remove rdline_init() function from library headers and export list, because using it requires the knowledge of sizeof(struct rdline).

---
 app/test-cmdline/commands.c            |  2 +-
 app/test/test_cmdline_lib.c            | 22 ++++---
 doc/guides/rel_notes/release_21_11.rst |  3 +
 lib/cmdline/cmdline.c                  |  3 +-
 lib/cmdline/cmdline_private.h          | 49 +++++++++++++++
 lib/cmdline/cmdline_rdline.c           | 43 ++++++++++++-
 lib/cmdline/cmdline_rdline.h           | 86 ++++++++++----------------
 lib/cmdline/version.map                |  8 ++-
 8 files changed, 147 insertions(+), 69 deletions(-)
app/test-cmdline/commands.c +1 -1
index d732976f08..a13e1d1afd 100644
@@ -297,7 +297,7 @@ cmd_get_history_bufsize_parsed(__rte_unused void *parsed_result,
 	struct rdline *rdl = cmdline_get_rdline(cl);
 
 	cmdline_printf(cl, "History buffer size: %zu\n",
-			sizeof(rdl->history_buf));
+			rdline_get_history_buffer_size(rdl));
 }
 
 cmdline_parse_token_string_t cmd_get_history_bufsize_tok =
app/test/test_cmdline_lib.c +14 -8
index d5a09b4541..054ebf5e9d 100644
@@ -83,18 +83,19 @@ test_cmdline_parse_fns(void)
 static int
 test_cmdline_rdline_fns(void)
 {
-	struct rdline rdl;
+	struct rdline *rdl;
 	rdline_write_char_t *wc = &cmdline_write_char;
 	rdline_validate_t *v = &valid_buffer;
 	rdline_complete_t *c = &complete_buffer;
 
-	if (rdline_init(NULL, wc, v, c) >= 0)
+	rdl = rdline_new(NULL, v, c, NULL);
+	if (rdl != NULL)
 		goto error;
-	if (rdline_init(&rdl, NULL, v, c) >= 0)
+	rdl = rdline_new(wc, NULL, c, NULL);
+	if (rdl != NULL)
 		goto error;
-	if (rdline_init(&rdl, wc, NULL, c) >= 0)
-		goto error;
-	if (rdline_init(&rdl, wc, v, NULL) >= 0)
+	rdl = rdline_new(wc, v, NULL, NULL);
+	if (rdl != NULL)
 		goto error;
 	if (rdline_char_in(NULL, 0) >= 0)
 		goto error;
@@ -102,25 +103,30 @@ test_cmdline_rdline_fns(void)
 		goto error;
 	if (rdline_add_history(NULL, "history") >= 0)
 		goto error;
-	if (rdline_add_history(&rdl, NULL) >= 0)
+	if (rdline_add_history(rdl, NULL) >= 0)
 		goto error;
 	if (rdline_get_history_item(NULL, 0) != NULL)
 		goto error;
 
 	/* void functions */
+	rdline_get_history_buffer_size(NULL);
+	rdline_get_opaque(NULL);
 	rdline_newline(NULL, "prompt");
-	rdline_newline(&rdl, NULL);
+	rdline_newline(rdl, NULL);
 	rdline_stop(NULL);
 	rdline_quit(NULL);
 	rdline_restart(NULL);
 	rdline_redisplay(NULL);
 	rdline_reset(NULL);
 	rdline_clear_history(NULL);
+	rdline_free(NULL);
 
+	rdline_free(rdl);
 	return 0;
 
 error:
 	printf("Error: function accepted null parameter!\n");
+	rdline_free(rdl);
 	return -1;
 }
 
doc/guides/rel_notes/release_21_11.rst +3 -0
index 18377e5813..af11f4a656 100644
@@ -103,6 +103,9 @@ API Changes
 
 * cmdline: Made ``cmdline`` structure definition hidden on Linux and FreeBSD.
 
+* cmdline: Made ``rdline`` structure definition hidden. Functions are added
+  to dynamically allocate and free it, and to access user data in callbacks.
+
 
 ABI Changes
 -----------
lib/cmdline/cmdline.c +1 -2
index a176d15130..8f1854cb0b 100644
@@ -85,13 +85,12 @@ cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_in, int s_out)
 	cl->ctx = ctx;
 
 	ret = rdline_init(&cl->rdl, cmdline_write_char, cmdline_valid_buffer,
-			cmdline_complete_buffer);
+			cmdline_complete_buffer, cl);
 	if (ret != 0) {
 		free(cl);
 		return NULL;
 	}
 
-	cl->rdl.opaque = cl;
 	cmdline_set_prompt(cl, prompt);
 	rdline_newline(&cl->rdl, cl->prompt);
 
lib/cmdline/cmdline_private.h +49 -0

59 lines not on this page · raw message

lib/cmdline/cmdline_rdline.c +40 -3

71 lines not on this page · raw message

lib/cmdline/cmdline_rdline.h +32 -54

124 lines not on this page · raw message

lib/cmdline/version.map +7 -1
index 980adb4f23..b9bbb87510 100644
@@ -57,7 +57,6 @@ DPDK_22 {
 	rdline_clear_history;
 	rdline_get_buffer;
 	rdline_get_history_item;
-	rdline_init;
 	rdline_newline;
 	rdline_quit;
 	rdline_redisplay;
@@ -73,7 +72,14 @@ DPDK_22 {
 EXPERIMENTAL {
 	global:
 
+	# added in 20.11
 	cmdline_get_rdline;
 
+	# added in 21.11
+	rdline_new;
+	rdline_free;
+	rdline_get_history_buffer_size;
+	rdline_get_opaque;
+
 	local: *;
 };
Signature · 1 line
2.29.3
Acked-by on v5 2/2
#22 lore raw

Re: [dpdk-dev] [PATCH v5 2/2] cmdline: make struct rdline opaque

Quoted 11 lines · Dmitry Kozlyuk

Hide struct rdline definition and some RDLINE_* constants in order to be able to change internal buffer sizes transparently to the user. Add new functions:

* rdline_new(): allocate and initialize struct rdline. This function replaces rdline_init() and takes an extra parameter:
opaque user data for the callbacks.
* rdline_free(): deallocate struct rdline.
* rdline_get_history_buffer_size(): for use in tests.
* rdline_get_opaque(): to obtain user data in callback functions.

Quoted 6 lines

Remove rdline_init() function from library headers and export list, because using it requires the knowledge of sizeof(struct rdline).

---

#23 lore raw

Re: [dpdk-dev] [PATCH v5 0/2] cmdline: reduce ABI

In reply to Dmitry Kozlyuk
Quoted 3 lines

Dmitry Kozlyuk (2):
cmdline: make struct cmdline opaque
cmdline: make struct rdline opaque

Applied, thanks.