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 B739AA0524; Sat, 20 Mar 2021 14:05:58 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 58149141097; Sat, 20 Mar 2021 14:05:52 +0100 (CET) Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) by mails.dpdk.org (Postfix) with ESMTP id 26E654067A for ; Sat, 20 Mar 2021 14:05:50 +0100 (CET) Received: by mail-lj1-f174.google.com with SMTP id z25so15290801lja.3 for ; Sat, 20 Mar 2021 06:05:50 -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=MArFPjIlL4GVujy8IhDC+Gb3oAVqevXZD0N3E/6IAg4=; b=cKjTNqSJ7pcIp2M7VngjLiyjsx++84gmTOLbQJ/nzkWJDGhhdiCeIWGSPYXCDUtkwJ Flw2NScG1AZjeM+vaTjur1ztOKntg9zHMM3sFbo1/0fr/AnbavX/WRedvKlnWntqWMvp JS17/P6OZsG65Gmq0KUiZAeukxmA3b4+E+skhUuxNwf5FVyG4I1ERSrD51DxX+6tNhew 81/Btv5j3VjDEDIASbzErAM9oNRRHyFXdTwkloPOWWonHAWRMppSRxuG5koj5hGsPWuP 7iCLCo67/mOld3Q7JwgPUImtdIIadCGJEEGffvflV+PWWlh1SFfSWE2b5X3pTvqCRUHl e3CQ== 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=MArFPjIlL4GVujy8IhDC+Gb3oAVqevXZD0N3E/6IAg4=; b=g3lYSVQWA+q/aJQ8G/If+LJmZZhjKVbE7svKeo69zaufdJsn8IYbnxFpMVV4F97pPB 7XmXk5FQxg3WnwECB5+V32dmpwJxuqeKUvyecNq9O/M7D0VupkzAfAnAY+9/MGVbDwPE N7JbJNlz/FvpOhdcFG+utqVybT+pr2qJxGAqTIPx4oGh4EtDEfeLYE0jY3CDQ/gO6dpk 6wJnY+cKgXuW78lYgBWaGoDACtwNl9+L8oKQVqBEuau2PIszblHDI0WiWA+N+9xldwpM rhKKE01f5b4eefrevGc9Bc1J77GJ4VF8ezyT8PfhpyXYamf7ZS2OvnQ8sLD+fcdbC8MA es2A== X-Gm-Message-State: AOAM5314v9/4h0kMY/Nj+TrZ1rUm30x767udqcUIDvQSRWnp3WB9FYIT gIbrL9CGjOWLVug5VTYNC6Y5J1WEIBSaQACY X-Google-Smtp-Source: ABdhPJxLIOxqgf9ZLquxbk2TrDpigoczPfUXPzKM5S1xoS4U9MBIhvpiarP0wsJ0ii0cXLaG3eKgww== X-Received: by 2002:a2e:720c:: with SMTP id n12mr3871285ljc.67.1616245549445; Sat, 20 Mar 2021 06:05:49 -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 r66sm929610lff.93.2021.03.20.06.05.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 06:05:48 -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 16:05:22 +0300 Message-Id: <20210320130525.16452-3-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.29.3 In-Reply-To: <20210320130525.16452-1-dmitry.kozliuk@gmail.com> References: <20210320112733.13160-1-dmitry.kozliuk@gmail.com> <20210320130525.16452-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v6 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.3