[v2,11/19] app/testpmd: remove use of VLAs for Windows built code

Message ID 1713470562-17415-12-git-send-email-roretzla@linux.microsoft.com (mailing list archive)
State Superseded
Delegated to: Thomas Monjalon
Headers
Series remove use of VLAs for Windows |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Tyler Retzlaff April 18, 2024, 8:02 p.m. UTC
  MSVC does not support VLAs, replace VLAs with standard C arrays
or alloca(). alloca() is available for all toolchain/platform
combinations officially supported by DPDK.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 app/test-pmd/cmdline.c        |  2 +-
 app/test-pmd/cmdline_flow.c   |  9 ++++-----
 app/test-pmd/config.c         | 16 +++++++++-------
 app/test-pmd/shared_rxq_fwd.c |  2 +-
 4 files changed, 15 insertions(+), 14 deletions(-)
  

Patch

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index b7759e3..dee8f5f 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -12902,7 +12902,7 @@  struct cmd_set_port_ptypes_result {
 		return;
 	}
 
-	uint32_t ptypes[ret];
+	uint32_t *ptypes = alloca(sizeof(uint32_t) * ret);
 
 	ret = rte_eth_dev_set_ptypes(port_id, ptype_mask, ptypes, ret);
 	if (ret < 0) {
diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 60ee933..a4fe8d9 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -11546,8 +11546,7 @@  struct indlst_conf {
 	char tmp[16]; /* Ought to be enough. */
 	int ret;
 	unsigned int hexlen = len;
-	unsigned int length = 256;
-	uint8_t hex_tmp[length];
+	uint8_t hex_tmp[256];
 
 	/* Arguments are expected. */
 	if (!arg_data)
@@ -11574,7 +11573,7 @@  struct indlst_conf {
 		str += 2;
 		hexlen -= 2;
 	}
-	if (hexlen > length)
+	if (hexlen > RTE_DIM(hex_tmp))
 		goto error;
 	ret = parse_hex_string(str, hex_tmp, &hexlen);
 	if (ret < 0)
@@ -11707,7 +11706,7 @@  struct indlst_conf {
 		void *buf, unsigned int size)
 {
 	const struct arg *arg = pop_args(ctx);
-	char str2[len + 1];
+	char *str2 = alloca(len + 1);
 	struct in_addr tmp;
 	int ret;
 
@@ -11753,7 +11752,7 @@  struct indlst_conf {
 		void *buf, unsigned int size)
 {
 	const struct arg *arg = pop_args(ctx);
-	char str2[len + 1];
+	char *str2 = alloca(len + 1);
 	struct in6_addr tmp;
 	int ret;
 
diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index ba1007a..4dce6fa 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -1760,7 +1760,8 @@  void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops)
 {
 	struct rte_port *port;
 	struct rte_flow_error error;
-	const struct rte_flow_queue_attr *attr_list[nb_queue];
+	const struct rte_flow_queue_attr **attr_list =
+	    alloca(sizeof(struct rte_flow_queue_attr *) * nb_queue);
 	int std_queue;
 
 	if (port_id_is_invalid(port_id, ENABLED_WARN) ||
@@ -2577,10 +2578,10 @@  struct rte_flow_meter_policy *
 	int ret;
 	uint32_t i;
 	struct rte_flow_error error;
-	struct rte_flow_pattern_template
-			*flow_pattern_templates[nb_pattern_templates];
-	struct rte_flow_actions_template
-			*flow_actions_templates[nb_actions_templates];
+	struct rte_flow_pattern_template **flow_pattern_templates =
+	    alloca(sizeof(struct rte_flow_pattern_template *) * nb_pattern_templates);
+	struct rte_flow_actions_template **flow_actions_templates =
+	    alloca(sizeof(struct rte_flow_actions_template *) * nb_actions_templates);
 
 	if (port_id_is_invalid(port_id, ENABLED_WARN) ||
 	    port_id == (portid_t)RTE_PORT_ALL)
@@ -5460,7 +5461,7 @@  struct igb_ring_desc_16_bytes {
 	char *end = NULL;
 	int min, max;
 	int value, i;
-	unsigned int marked[maxsize];
+	unsigned int *marked = alloca(sizeof(unsigned int) * maxsize);
 
 	if (list == NULL || values == NULL)
 		return 0;
@@ -7201,7 +7202,8 @@  static const char *get_ptype_str(uint32_t ptype)
 	if (eth_dev_info_get_print_err(port_id, &dev_info))
 		return;
 
-	struct rte_ether_addr addr[dev_info.max_mac_addrs];
+	struct rte_ether_addr *addr =
+	    alloca(sizeof(struct rte_ether_addr) * dev_info.max_mac_addrs);
 	rc = rte_eth_macaddrs_get(port_id, addr, dev_info.max_mac_addrs);
 	if (rc < 0)
 		return;
diff --git a/app/test-pmd/shared_rxq_fwd.c b/app/test-pmd/shared_rxq_fwd.c
index 623d62d..5d4ffff 100644
--- a/app/test-pmd/shared_rxq_fwd.c
+++ b/app/test-pmd/shared_rxq_fwd.c
@@ -92,7 +92,7 @@ 
 static bool
 shared_rxq_fwd(struct fwd_stream *fs)
 {
-	struct rte_mbuf *pkts_burst[nb_pkt_per_burst];
+	struct rte_mbuf **pkts_burst = alloca(sizeof(struct rte_mbuf *) * nb_pkt_per_burst);
 	uint16_t nb_rx;
 
 	nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);