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 221AAA0A0F; Thu, 8 Apr 2021 00:23:06 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B8ABA140FE4; Thu, 8 Apr 2021 00:23:01 +0200 (CEST) Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) by mails.dpdk.org (Postfix) with ESMTP id 9AA8840698 for ; Thu, 8 Apr 2021 00:23:00 +0200 (CEST) Received: by mail-lf1-f47.google.com with SMTP id b4so603799lfi.6 for ; Wed, 07 Apr 2021 15:23:00 -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=In8OCy1hR5eyvm4001qwxKvtsce5XF68RwqMafSgsNIlm94IVl/uPGPWylVhewLhwc 2MGA32RnhwQEimQ1/nIk+9Ip5CC/pmvThKBawjilbWYpOY3e3ZxGKXlDbNz3UWpeGWaB w9OtlXFTyGr7sRU1M3Bfh+dz3X8109xLxuCjelINkpIw1t6M9OeaWGCAPKl9w9oF9KiG kHbtnrJBFO0GS1M46wP5MrazLd7RlT2a4cAfCzyOZbD0zAK4fl8MZ3IXVFyolgaWXUlJ dVVsDVyD3NoJRqgfKtOQ/02ALu2dbg1zL+c1/ZihaEerxocJ1byV1gLAO1s6Ge9w03/1 ntPg== 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=Y0MoM1s+LKWxj6TbVdF2m7STSon1OOP1UJMYrsbLYGrv9zl1TunxKggGeEa/FsWbCD Nt+05/P+j5sispUP6ngFirQwQnPlBG/zmgqmW+HstypMBzDs3vxPloC4aBE9iruoFQEW 8gcZ84Msc5NjFEjPUhpKa9OTJjkpmp7wva8UTXUNp/8a1GjQabU5MuHaZL4txhPPCeDD 0bKeVL7qCsfn0gXKDp4Yybitzl3LaqRR+1/D+IL53VvtYwIBLIYG7NfdGMWfcFN0mIhW wQS0+kg2TFZPD1HHBMDJMyOFki32l/bxg9Py6NMOdWC1e5OBe1X2HqtTmSxVwc+iDDcS DAOw== X-Gm-Message-State: AOAM5319nrPtanUEMDXFo03vBczvdbuFulToO9T2INVfp/MIu86iYc5g TOB6m1rme3bBsyUnWaY4XXjvCoLZkcCTg2Cn X-Google-Smtp-Source: ABdhPJz80Ddp+VWG70fjcFZTqxJmmoHld1sHB7BH3mDnX8hP1CCynUxZjCz1tHCbE+3HYODRvcBP4Q== X-Received: by 2002:a19:911c:: with SMTP id t28mr3804017lfd.87.1617834179820; Wed, 07 Apr 2021 15:22:59 -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 u27sm441965lfk.254.2021.04.07.15.22.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Apr 2021 15:22:59 -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: Thu, 8 Apr 2021 01:22:46 +0300 Message-Id: <20210407222249.6729-2-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.29.3 In-Reply-To: <20210407222249.6729-1-dmitry.kozliuk@gmail.com> References: <20210403234129.20296-1-dmitry.kozliuk@gmail.com> <20210407222249.6729-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v8 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 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