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 D6CAEA0547; Sun, 11 Apr 2021 00:47:47 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AA3F914131E; Sun, 11 Apr 2021 00:47:45 +0200 (CEST) Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) by mails.dpdk.org (Postfix) with ESMTP id 67BE71412F0 for ; Sun, 11 Apr 2021 00:47:42 +0200 (CEST) Received: by mail-lf1-f54.google.com with SMTP id b4so15345992lfi.6 for ; Sat, 10 Apr 2021 15:47:42 -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=R4TeunL59d1iplrfiowX1KEGm6Hi2DSeWMgA8pw6POI=; b=p8gYaX3QE+cEVLSP4LKQrbb7wDDHzw2RFRPNaA5242CmjZp7F7cbjLvEZ/YAXcBxv2 pDxYs5s6UigNVd0g78+mr1mJQ+TxJ90jlPe8UBk8BvD+S+Nw94CfxyrXqEzdqPLjbfAu wQjXBcf9pDLFXFxqCxanlMR7Ey5HK2TCaX6Hw7UndI56Vaf05HEhYfqmJKA3KIJ6URKC SbvaiAQwXtUKSELo/E6R/eCDrSYvx9gdReWzwyLeJPfmORbPzhwLkyCQeja+uqJHIrEu nc9JgmGyIkOPyKbtdBWC3H62gm+phmoaeca1n+5Qo+KbwIa2tVNu/QyNhnA9l+JNK1NZ 6yfw== 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=R4TeunL59d1iplrfiowX1KEGm6Hi2DSeWMgA8pw6POI=; b=fJuYf0tg/UpZ+zkakHvzuj/iG4xOxfLO0pkVJbjEXPXnEw68w2ibaS6Q3eERi+sWS1 OEPvinGlloQuk9CTYKvTXp4fMJNBZUKbr+urT4zZP8ytywwLIxwQRw3wefCQpCS7WQJ1 rOAtX6D6u2gron9GaNh0ZZp2KHBYdJEA+RCW2NojUbWXnOalGfTzg8zbMTN7tCIg4vBR kMR3/GIo6Az2kpd/7H3XZUIXizK22XIkUsIsaCS802gg0scZMiOL2KMQ6KeKnaT2mrnw sMeemJZMlUybA6zlwpXjcLB0OTf86QHQy0IvV7KAXrdgk2TClBf5GY/SMoa8CgCD6Nt6 pQgQ== X-Gm-Message-State: AOAM530Q/aPjw8OcmjLoR5mvGVPb/BhXLaK/86urmLgtqHkh4aoAMYBx cIyHq0qyDF0MJJ1fQlHhMhP0UG4SqS6Yhw== X-Google-Smtp-Source: ABdhPJwPifdUhv2QxAVdYbBHKHdYbWFj5gKsuv51zU4N/gRwL7xG6Kl7Jew7ctabWVAIHHIuBUctQw== X-Received: by 2002:a19:5d55:: with SMTP id p21mr14091982lfj.316.1618094861683; Sat, 10 Apr 2021 15:47:41 -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 o15sm370270lfu.155.2021.04.10.15.47.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Apr 2021 15:47:40 -0700 (PDT) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Dmitry Kozlyuk , Khoa To , Nick Connolly , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam Date: Sun, 11 Apr 2021 01:47:29 +0300 Message-Id: <20210410224732.20234-2-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.29.3 In-Reply-To: <20210410224732.20234-1-dmitry.kozliuk@gmail.com> References: <20210407222249.6729-1-dmitry.kozliuk@gmail.com> <20210410224732.20234-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v9 1/4] 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 Acked-by: Nick Connolly --- 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 e3512111d9..64cf4e81c8 100644 --- a/lib/librte_eal/common/eal_private.h +++ b/lib/librte_eal/common/eal_private.h @@ -716,4 +716,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 41be20d89f..28c787c0b0 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 @@ -416,6 +418,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