From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 69CFCA0548; Sun, 4 Apr 2021 01:41:55 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3CF33140E3D; Sun, 4 Apr 2021 01:41:42 +0200 (CEST) Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) by mails.dpdk.org (Postfix) with ESMTP id F0BF7140E0C for ; Sun, 4 Apr 2021 01:41:39 +0200 (CEST) Received: by mail-lf1-f41.google.com with SMTP id 12so12334968lfq.13 for ; Sat, 03 Apr 2021 16:41:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RtorkMybMXGXOW0X5DNzOp1pbVPKmkvt51lm4C1nVBA=; b=gyrZ0efwpSvqdohuyhZB4eygKZ2oflPvdSwv0WAzvMY6llUTWYlGbpq2oG4yCxPrmA tvcEf8n4jPRKklS2Uom/Pa9nEDlZgK0YibV3M9hwiZDh3Ea6N7CWl+cfKZmeHRxDb2pe PIJ8YIjPzzDHFIjb0kZpnqorlSNw6Cf/nJHmGgajT7rHg/c5G+DK640+efvzspxmzyiG cRVYVAXHYS6jZCJi371cU8GZB7XMZwKEavOr7WXWvhW72yaZVvO4fN+LgZgaJYFZhTlu 83aBZkahfewyG5G0d+jalHPaBM5iemAj6ZgALK8R2rfBnB3rlGlKSqpNE0q2t4ixhuVj TRVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RtorkMybMXGXOW0X5DNzOp1pbVPKmkvt51lm4C1nVBA=; b=jFhqsq2loMIqTqlhfbO0U1o0oi/aYQKhbPXMrG9WeRwlBdDxsMTqqp5oAlOrEwv13P +/mXaAHze7jp8erG2fiewJnY1DLRI+k9jxXwHT2Nln+8GAitDkcNpX5Qrw+EBokUhvh2 UdjXGkQ6gCYL2zcTNqrh6ia4IoSr+pMGQ3v4guvJx/f4GzDvQK4MjEf9GloZ+S5OWf2t DfPDzzT44Pr0RovVvMfNBvLRbX0TqQ5pAJ0RuPp5xH8PuyY39Q8b6eUIFHkuQR3ycZ60 0YLX6Qywo45Mn+UKE1gaFNO0dBCAB61LXqj9PGq47y0GCR6fska/h9QRPUqzprZufYxY v9Tg== X-Gm-Message-State: AOAM532UrjDQoAujkktKfAISCdMBbzVkegUdaD+aDy2fW7er1+WpMoQr xOUh9ox6XdTkPFyOSfxPA7aU7QNrjoJW5ioK X-Google-Smtp-Source: ABdhPJx47kOyhR20IQ+SJ3rZEefRYxheY49PNR3QE2BRil1P66Z4RTLWArSi77j6BRo0U5MAEmdeRA== X-Received: by 2002:a19:c0f:: with SMTP id 15mr13360415lfm.580.1617493299319; Sat, 03 Apr 2021 16:41:39 -0700 (PDT) Received: from localhost.localdomain (broadband-37-110-65-23.ip.moscow.rt.ru. [37.110.65.23]) by smtp.gmail.com with ESMTPSA id f23sm1374927lja.43.2021.04.03.16.41.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Apr 2021 16:41:38 -0700 (PDT) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Tyler Retzlaff , Jie Zhou , Nick Connolly , Dmitry Kozlyuk , Khoa To , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam Date: Sun, 4 Apr 2021 02:41:26 +0300 Message-Id: <20210403234129.20296-3-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.29.3 In-Reply-To: <20210403234129.20296-1-dmitry.kozliuk@gmail.com> References: <20210320130525.16452-1-dmitry.kozliuk@gmail.com> <20210403234129.20296-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v7 2/5] eal/windows: hide asprintf() shim X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Make asprintf(3) implementation for Windows private to EAL, so that it's hidden from external consumers. It is not exposed to internal consumers either, because they don't need asprintf() and also because callers from other modules would have no reliable way to free allocated memory. Signed-off-by: Dmitry Kozlyuk Acked-by: Khoa To --- lib/librte_eal/common/eal_private.h | 11 +++++++++ lib/librte_eal/windows/eal.c | 30 +++++++++++++++++++++++++ lib/librte_eal/windows/include/rte_os.h | 30 ------------------------- 3 files changed, 41 insertions(+), 30 deletions(-) diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h index b8a0d20021..31eda4d2da 100644 --- a/lib/librte_eal/common/eal_private.h +++ b/lib/librte_eal/common/eal_private.h @@ -745,4 +745,15 @@ void __rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset); */ void __rte_thread_uninit(void); +/** + * asprintf(3) replacement for Windows. + */ +#ifdef RTE_EXEC_ENV_WINDOWS +__rte_format_printf(2, 3) +int eal_asprintf(char **buffer, const char *format, ...); + +#define asprintf(buffer, format, ...) \ + eal_asprintf(buffer, format, ##__VA_ARGS__) +#endif + #endif /* _EAL_PRIVATE_H_ */ diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c index 2fc3d6141c..162671f9ce 100644 --- a/lib/librte_eal/windows/eal.c +++ b/lib/librte_eal/windows/eal.c @@ -2,6 +2,8 @@ * Copyright(c) 2019 Intel Corporation */ +#include + #include #include #include @@ -411,6 +413,34 @@ rte_eal_init(int argc, char **argv) return fctret; } +/* Don't use MinGW asprintf() to have identical code with all toolchains. */ +int +eal_asprintf(char **buffer, const char *format, ...) +{ + int size, ret; + va_list arg; + + va_start(arg, format); + size = vsnprintf(NULL, 0, format, arg); + va_end(arg); + if (size < 0) + return -1; + size++; + + *buffer = malloc(size); + if (*buffer == NULL) + return -1; + + va_start(arg, format); + ret = vsnprintf(*buffer, size, format, arg); + va_end(arg); + if (ret != size - 1) { + free(*buffer); + return -1; + } + return ret; +} + int rte_vfio_container_dma_map(__rte_unused int container_fd, __rte_unused uint64_t vaddr, diff --git a/lib/librte_eal/windows/include/rte_os.h b/lib/librte_eal/windows/include/rte_os.h index f0512f20a6..1afe49f35e 100644 --- a/lib/librte_eal/windows/include/rte_os.h +++ b/lib/librte_eal/windows/include/rte_os.h @@ -10,7 +10,6 @@ * which is not supported natively or named differently in Windows. */ -#include #include #include #include @@ -71,34 +70,6 @@ extern "C" { typedef long long ssize_t; #ifndef RTE_TOOLCHAIN_GCC - -static inline int -asprintf(char **buffer, const char *format, ...) -{ - int size, ret; - va_list arg; - - va_start(arg, format); - size = vsnprintf(NULL, 0, format, arg); - va_end(arg); - if (size < 0) - return -1; - size++; - - *buffer = (char *)malloc(size); - if (*buffer == NULL) - return -1; - - va_start(arg, format); - ret = vsnprintf(*buffer, size, format, arg); - va_end(arg); - if (ret != size - 1) { - free(*buffer); - return -1; - } - return ret; -} - static inline const char * eal_strerror(int code) { @@ -111,7 +82,6 @@ eal_strerror(int code) #ifndef strerror #define strerror eal_strerror #endif - #endif /* RTE_TOOLCHAIN_GCC */ #ifdef __cplusplus -- 2.29.3