[03/16] ethdev: remove use of VLAs for Windows built code

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

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Tyler Retzlaff April 17, 2024, 11:41 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>
---
 lib/ethdev/rte_ethdev.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
  

Patch

diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index f1c658f..cd2ed74 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -3241,7 +3241,8 @@  enum {
 	}
 
 	/* Get id-name lookup table */
-	struct rte_eth_xstat_name xstats_names[cnt_xstats];
+	struct rte_eth_xstat_name *xstats_names =
+	    alloca(sizeof(struct rte_eth_xstat_name) * cnt_xstats);
 
 	if (cnt_xstats != rte_eth_xstats_get_names_by_id(
 			port_id, xstats_names, cnt_xstats, NULL)) {
@@ -3342,7 +3343,7 @@  enum {
 		return -EINVAL;
 
 	if (ids && dev->dev_ops->xstats_get_names_by_id != NULL && size > 0) {
-		uint64_t ids_copy[size];
+		uint64_t *ids_copy = alloca(sizeof(uint64_t) * size);
 
 		for (i = 0; i < size; i++) {
 			if (ids[i] < basic_count) {
@@ -3535,7 +3536,7 @@  enum {
 	if (ret < 0)
 		return ret;
 	expected_entries = (uint16_t)ret;
-	struct rte_eth_xstat xstats[expected_entries];
+	struct rte_eth_xstat *xstats = alloca(sizeof(struct rte_eth_xstat) * expected_entries);
 	basic_count = eth_dev_get_xstats_basic_count(dev);
 
 	/* Return max number of stats if no ids given */
@@ -3551,7 +3552,7 @@  enum {
 
 	if (ids && dev->dev_ops->xstats_get_by_id != NULL && size) {
 		unsigned int basic_count = eth_dev_get_xstats_basic_count(dev);
-		uint64_t ids_copy[size];
+		uint64_t *ids_copy = alloca(sizeof(uint64_t) * size);
 
 		for (i = 0; i < size; i++) {
 			if (ids[i] < basic_count) {