From patchwork Tue Oct 1 09:41:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13817697 Received: from fhigh-a7-smtp.messagingengine.com (fhigh-a7-smtp.messagingengine.com [103.168.172.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 524BC19F102 for ; Tue, 1 Oct 2024 09:41:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727775717; cv=none; b=LF5XtL7hmk4fsHcozx8qHhmSQQgt+NmGXdtnYB06gqfZND9ZaYGzXDeP7dENNvvM1yFehpISGrLA53yaPe6qLpPbDdMRFeyHpDLPOY/NLBQx8LM80yINlczll5NTvtHCvy/B0tRU/tg5h6mNJ7TzD2Og2XTcBFyt9lNN0b0xOoM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727775717; c=relaxed/simple; bh=b2gm5e6VuNcFw4M9Tw2VQu8j+T/hUd4g9wcPToddLhg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JKcP6DlODo/JFpBsWhZN7rueYzTXIBlIwEjdm1RjaDljcXk/hmT8Ybok1xC5TUAV+7hFRtAPCVror2LMTfs7Wx9oCk7TvrVlLW+IYfVoYTuX6dAxtlKb7RWKnKGhEjS/F6XBrGv9R7EPT87H6w3QjSvHZLaSsVFFRMLvUJQsUH4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=CAa5Lqex; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=eNVDtnKA; arc=none smtp.client-ip=103.168.172.158 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="CAa5Lqex"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="eNVDtnKA" Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfhigh.phl.internal (Postfix) with ESMTP id 9BF1D1140A72; Tue, 1 Oct 2024 05:41:54 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Tue, 01 Oct 2024 05:41:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1727775714; x=1727862114; bh=kaL379fZ/R biuQABPX9C936DoOsFwVDWSc6IHeiN1qE=; b=CAa5LqexahXl8hrd/nSTRzNo+M hkBdH51gbqCpePAJEQx6qpWtNtfGJJ6o0Z2Sia986x8hKeRHLnGluMB0S+JhgplK XUCc4NExxo0qAde71Xb+nCWgeAbeWCg4+RXmfhohmgIUaUeBPHPYC6gZXlt4NRIa 33a9CuGmhBAa5M5yV+9U2QRHkmgSIw076ybpbFbVdh55uaawpE1VtLl1URYY7qie 4Tf6Xoh3EXGqfi7USfssLN+xuSgKf//Hu5lewl1zO5WDX0OtpRSvwhDXv6EUoiC7 PYiHHb3Ggld3G96hAplZJDabkVTk2GdXKUzXKo6uDAA1kOGvuTCJvQJZQuPQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1727775714; x=1727862114; bh=kaL379fZ/RbiuQABPX9C936DoOsF wVDWSc6IHeiN1qE=; b=eNVDtnKAN+nyakE//MC78+n794+zzkP+JtrUT1NC4EPl CJeSFlOVcgi26EBgzHLBQDwtm915NNiOtNFmcSl54AZaRFslsEEAE5Rx86R8tXSw eSl3AeVj4H1Z6kgts7P28PJ5BSsRbS8+snOnAEh+nhOwq47QCmf74Jn2FHR0TWfa 30r/9B8miWh9/K1LvYTSCh9orR2EHXZClyjBtr92vsnQT9MDYktTMYtUxuJqetjt yoXbFKBPNuREuq/C8kP4iWatzSGT6IKshZHQj9JrQUwTMdAQkiFXlcWXqdMan8wC /DtLju+AoA0NLpv8jdpEhq2E/3i9UJPGhaabFXWF6A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddujedgudejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimh eqnecuggftrfgrthhtvghrnhepveekkeffhfeitdeludeigfejtdetvdelvdduhefgueeg udfghfeukefhjedvkedtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepgedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepvghthhhomhhsohhnsegvugifrghrughthhhomhhsoh hnrdgtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgt phhtthhopehgihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtoheplhdrshdrrh esfigvsgdruggv X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 1 Oct 2024 05:41:53 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 535c4f54 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 1 Oct 2024 09:41:05 +0000 (UTC) Date: Tue, 1 Oct 2024 11:41:50 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Edward Thomson , Junio C Hamano , =?utf-8?b?UmVuw6k=?= Scharfe Subject: [PATCH v4 03/25] reftable: introduce `reftable_strdup()` Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The reftable library provides the ability to swap out allocators. There is a gap here though, because we continue to use `xstrdup()` even in the case where all the other allocators have been swapped out. Introduce `reftable_strdup()` that uses `reftable_malloc()` to do the allocation. Signed-off-by: Patrick Steinhardt --- reftable/basics.c | 10 ++++++++++ reftable/basics.h | 1 + 2 files changed, 11 insertions(+) diff --git a/reftable/basics.c b/reftable/basics.c index cf072935c8..4adc98cf5d 100644 --- a/reftable/basics.c +++ b/reftable/basics.c @@ -43,6 +43,16 @@ void *reftable_calloc(size_t nelem, size_t elsize) return p; } +char *reftable_strdup(const char *str) +{ + size_t len = strlen(str); + char *result = reftable_malloc(len + 1); + if (!result) + return NULL; + memcpy(result, str, len + 1); + return result; +} + void reftable_set_alloc(void *(*malloc)(size_t), void *(*realloc)(void *, size_t), void (*free)(void *)) { diff --git a/reftable/basics.h b/reftable/basics.h index 4e2e76014a..f107e14860 100644 --- a/reftable/basics.h +++ b/reftable/basics.h @@ -54,6 +54,7 @@ void *reftable_malloc(size_t sz); void *reftable_realloc(void *p, size_t sz); void reftable_free(void *p); void *reftable_calloc(size_t nelem, size_t elsize); +char *reftable_strdup(const char *str); #define REFTABLE_ALLOC_ARRAY(x, alloc) (x) = reftable_malloc(st_mult(sizeof(*(x)), (alloc))) #define REFTABLE_CALLOC_ARRAY(x, alloc) (x) = reftable_calloc((alloc), sizeof(*(x)))