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 47E8DA0A02; Thu, 15 Apr 2021 00:07:07 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 12B0C161D70; Thu, 15 Apr 2021 00:07:06 +0200 (CEST) Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) by mails.dpdk.org (Postfix) with ESMTP id 8850E40685 for ; Thu, 15 Apr 2021 00:07:01 +0200 (CEST) Received: by mail-lf1-f48.google.com with SMTP id x19so5342138lfa.2 for ; Wed, 14 Apr 2021 15:07:01 -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=cQFDOb309YnT7nxvUJfm9vl/Al/wDVZLeqExIlgjCXY=; b=K0BmtpXuq+/sSFbCYrObrCPKTlb3RlJrKOa5tZUjo4U9pQ3mXFvN5I0Xu06rLzMHck o5PqFEeKJ2kLEv+LYVi2xSSuK4aqdL1PcaDQxxjG7rNBYQZkVoZLBnkoNaOzUPb8oMXO Rfsgn2v7e+Ypq1r45r8uiWvvlOO9585UbungEDNdbuctPww33J1Ff5TTkDufiSl1vaN8 bAuniKlVZpXu+1mi7vrMm2FtWhwC98sGjAE9ftGtU4CgYxpIx8VOZIKiKfV6jFvsfSV3 r3RgPxdq/5dS3n/kguOCnQ0HaxuOe/xBpkSHT4CG20XFjyImA/wHMaM8AShK+gPcP/JT xv0A== 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=cQFDOb309YnT7nxvUJfm9vl/Al/wDVZLeqExIlgjCXY=; b=pR1OvAf2y1foAomollD2mtccPMCDN/FhoSQscKRHDxpdtf+MiYEZf+gTcytHppR7GI qviKBaK+Cj2JXSqhOX4i/XsbpXTvPyCZIAKVRa6DJCGqfxzELVGdD9RxRB0oJUZMo3Q6 1Ysnd2b4XTkBZutN1JsZv5moWnbX2Vyq9r72GSyomDgXr+pUDwgM/6zzZT69Rh1JYQBy 9D/UDfQtBh3gJMPjHFMNhLXILr4/WCRNrLaFDDL+RLxy2ci1+HIMKKzlh74bSyIngavt INTLfmgoyklCVmipLom81upggvIwMBoliestKv2zHrHtEZWkZjmYP14wHRKwxIruC612 djWA== X-Gm-Message-State: AOAM531zflPx/jWX/U2wRQ0RchMi9obDbss03MRN2X7JpOFf3SlJ6WGk txmKMSWue6n7i2szLnqJMc2p/ZQNvXOwFHOr X-Google-Smtp-Source: ABdhPJyo/2d3I5U+Va6pZZxB3c2Mk6rTT9p0Ey5Td4tyo2NhIBdb2mGaYet9JArg/vJPp1UunZtzGw== X-Received: by 2002:a05:6512:ba6:: with SMTP id b38mr235128lfv.128.1618438020766; Wed, 14 Apr 2021 15:07:00 -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 m28sm271489lfo.278.2021.04.14.15.06.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Apr 2021 15:06:59 -0700 (PDT) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Dmitry Kozlyuk , Khoa To , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam Date: Thu, 15 Apr 2021 01:06:48 +0300 Message-Id: <20210414220651.28691-2-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.29.3 In-Reply-To: <20210414220651.28691-1-dmitry.kozliuk@gmail.com> References: <20210410224732.20234-1-dmitry.kozliuk@gmail.com> <20210414220651.28691-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v10 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 --- 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