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 47DC0A0524; Sat, 20 Mar 2021 12:28:00 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 743AA141088; Sat, 20 Mar 2021 12:27:50 +0100 (CET) Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) by mails.dpdk.org (Postfix) with ESMTP id DA57B14107F for ; Sat, 20 Mar 2021 12:27:46 +0100 (CET) Received: by mail-lf1-f48.google.com with SMTP id g8so6889901lfv.12 for ; Sat, 20 Mar 2021 04:27:46 -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=WMAJfZVfuoZsfl9IOLzQwhDY4S3F7r2zJpixD8HO93s=; b=WopQM1iKlrucSrrGblU1p8M+F/D4nUnFR9iEz9t6xM0mhA8gHCq9blznPhykFGT8lh 6x+VI6axM7079niP80GcnyY75Hqy+X9KLz9pXZaCvdpFAddpOdbCtd6zWUp/knOPjRIc loKXkrjPeyRud19PxmzWD6QbSQbV72itTfTGvEDG0Tfkpyj+pv9k4xREgJH4q1ZNIWTw JPHHm6ZVebYL2A3XgeGmkTpAxRMl3vk/FyIv3ZlwgCn2VQnEYxxNzTr8JZ504Kna7lyJ asswJvzW7HyCMwBdnDJVQQ8PvAyzegKrHMa/rPc4xPnYk6bopyzgZurUhqBEY+zb1jHx 1SUg== 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=WMAJfZVfuoZsfl9IOLzQwhDY4S3F7r2zJpixD8HO93s=; b=NROzwypWx9vTrgMTMyk56SrUweIc+D0JmcaOwijwg16upUVNq2fZPkVUzg6TXIFETr OGLTvcH/jnkrkc1DZO4C7yYzTMAVz5/BLb8Aeg1XxAuWTs5Bztum490l2BPlfNVUhsXO 1rEpynrUTuxThHXGjCLjyd0VI0LDZc5qT2vrkFlbnyflVvJkMzI9Hn/JPgWDRI4oA5NN UHpXTVmS2j163aPgkVD/AFTsJBUblaoEjukm2CTJtAIjkZ5/gqVD2fOZ3zofQgB/E+nC TUjjD8o5X6VTpElQfiA4BmgzdFNnHp6lD9VWQPWTVRtjCjCyuHX6ahDnwq2OtXi71QeO 0Svw== X-Gm-Message-State: AOAM533xgc3yB3ZCHeW1LDZ6ecXdO7qiGcvorytIaONAqwxJoUDlZI+J D+Rl+Fp7aYqjSu/GWmuicxGwJ5M3lDuuJtBW X-Google-Smtp-Source: ABdhPJyw1UargWGpoVXgd5Q7ARjSRGB9kAND9jqfDUmlJPjMepfa2Fy199wscgsRZunznvPkOHbO9Q== X-Received: by 2002:a19:224d:: with SMTP id i74mr3584956lfi.224.1616239666231; Sat, 20 Mar 2021 04:27:46 -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 v26sm913976lfe.276.2021.03.20.04.27.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 04:27:45 -0700 (PDT) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Tyler Retzlaff , Jie Zhou , Dmitry Kozlyuk , Khoa To , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam Date: Sat, 20 Mar 2021 14:27:30 +0300 Message-Id: <20210320112733.13160-3-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.29.3 In-Reply-To: <20210320112733.13160-1-dmitry.kozliuk@gmail.com> References: <20210306000500.8698-1-dmitry.kozliuk@gmail.com> <20210320112733.13160-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v5 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 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) 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, -- 2.29.2