From patchwork Fri Feb 7 11:51:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13964872 Received: from fout-a8-smtp.messagingengine.com (fout-a8-smtp.messagingengine.com [103.168.172.151]) (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 231231DEFF4 for ; Fri, 7 Feb 2025 11:52:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929128; cv=none; b=gizNMsIp2+5F1IZEM2r0KCCmlg/zEwD03Fnh6XYvBp9fZpVt/PZWEy3UlRRmh7SedIMJdT1g8+i9InnrE1V3wqaz+5uE3X9aFaTkR7W1EiJdepmFuv1eOiBKte6l2iHFfURCuKj0G6lc64uZHVf9rd+h5Xok//HSh8j5gsRmoOA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929128; c=relaxed/simple; bh=81LTn7UZRORPY2teFOFZFj1OqCLhZ9jWJcErZRHzdVE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=C1OpzqP1NLrRPtgi8orNLfZ2QKtZlgC7SOF8uyYyV5o/B89qCOr3i6K8i3ly2B7KpOtX0HV5s1Mgpqv5Y0TWMOI0+cGol0IhvZQVRpAI61+w1rSlje9xSr30oi9AQjFQQELHGa8QP6YFn6WcxfbiLjZ/11h7SC4bXv/56qU4NNk= 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=JbOjvOIa; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=MnML3KLR; arc=none smtp.client-ip=103.168.172.151 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="JbOjvOIa"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="MnML3KLR" Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfout.phl.internal (Postfix) with ESMTP id 65533138016B; Fri, 7 Feb 2025 06:52:04 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-12.internal (MEProxy); Fri, 07 Feb 2025 06:52:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding: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=fm3; t=1738929124; x=1739015524; bh=nIlvnYQGf294FuH8JnUpltKC/aiSknWtZvi3roloRoU=; b= JbOjvOIadfOjqRVJTsAV7zcrFc1comRmTBgyXGv8ud8nlIJEn+SBr8zczkzmLBgG 4A+RekK9WbUe3KBLYH/Qy88+theD8SHnBuU84WmCS0hkFQQapH9atPsmABeWiotj 8w8CEWjWMkiaqtlIzBUy5lPi8438EwpL/ahj5ZPrkA+C5Rncun8D7LImAaaEixo4 mU0rsXXnR7rkFRaX5tj4kv1CZv0MZGOgnBgigMbX7jGRICW8KyMQ0Fz/y+mFvgP2 yW94Lkzj/Ms5Rav9pJfYqtwNv445bEOxndFiVQARyacWpqKQiAnjnrNQU59MbrsF ud0hOuUMzUNvvwbOR/lryQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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-sender:x-me-sender:x-sasl-enc; s=fm3; t=1738929124; x= 1739015524; bh=nIlvnYQGf294FuH8JnUpltKC/aiSknWtZvi3roloRoU=; b=M nML3KLR/goLb4vPj9iUaPbG3WM9DYe3TuR/AdX6SDr83qq0zIBxR3WQ/oGhMzbEd oC0ykhPp4JWEaXTRwzbxmKfhP/Bu248rgynAjFNsNQpp0M2HF9+W/mV9NrqUmxJ4 sO4Lo54isqBM7LS8hK5Z1NoepN8sd72HCyDxzXjmxGtQJwLblGs4zuRdIavhJbbq 6COZODg4JZRt3tD7kUX9lSIirVSNiD57sJf9g6WPHPFp1kvVOrsCYD9iSie/SY5a oFfL50rIZGbwZhb1KEQSSl3a6PxpQwV8gwZjsmgFPVGxjlvomeq7wB3NmR1CyG0F 5AV77T3xTk8Uvf+ypKbQQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvledvtdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredt jeenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrd himheqnecuggftrfgrthhtvghrnhepffeuiedujedvkeehuedvkeefffeivdeuleetkedu heejteekgedvudfgtdfgieelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh dprhgtphhtthhopehjlhhtohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopegv thhhohhmshhonhesvggufigrrhguthhhohhmshhonhdrtghomhdprhgtphhtthhopehgih htshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtohepjheitheskhgusghgrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Feb 2025 06:52:02 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 73103caa (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 7 Feb 2025 11:52:01 +0000 (UTC) From: Patrick Steinhardt Date: Fri, 07 Feb 2025 12:51:56 +0100 Subject: [PATCH v5 01/18] reftable/stack: stop using `read_in_full()` Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250207-pks-reftable-drop-git-compat-util-v5-1-ba2adc79110f@pks.im> References: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> In-Reply-To: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> To: git@vger.kernel.org Cc: Edward Thomson , Justin Tobler , Junio C Hamano , Johannes Sixt X-Mailer: b4 0.14.2 There is a single callsite of `read_in_full()` in the reftable library. Open-code the function to reduce our dependency on the Git library. Note that we only partially port over the logic from `read_in_full()` and its underlying `xread()` helper. Most importantly, the latter also knows to handle `EWOULDBLOCK` via `handle_nonblock()`. This logic is irrelevant for us though because the reftable library never sets the `O_NONBLOCK` option in the first place. Signed-off-by: Patrick Steinhardt --- reftable/stack.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/reftable/stack.c b/reftable/stack.c index f7c1845e15..d57acd9540 100644 --- a/reftable/stack.c +++ b/reftable/stack.c @@ -115,13 +115,16 @@ int reftable_new_stack(struct reftable_stack **dest, const char *dir, static int fd_read_lines(int fd, char ***namesp) { - off_t size = lseek(fd, 0, SEEK_END); char *buf = NULL; int err = 0; + off_t size; + + size = lseek(fd, 0, SEEK_END); if (size < 0) { err = REFTABLE_IO_ERROR; goto done; } + err = lseek(fd, 0, SEEK_SET); if (err < 0) { err = REFTABLE_IO_ERROR; @@ -134,9 +137,16 @@ static int fd_read_lines(int fd, char ***namesp) goto done; } - if (read_in_full(fd, buf, size) != size) { - err = REFTABLE_IO_ERROR; - goto done; + for (off_t total_read = 0; total_read < size; ) { + ssize_t bytes_read = read(fd, buf + total_read, size - total_read); + if (bytes_read < 0 && (errno == EAGAIN || errno == EINTR)) + continue; + if (bytes_read < 0 || !bytes_read) { + err = REFTABLE_IO_ERROR; + goto done; + } + + total_read += bytes_read; } buf[size] = 0; From patchwork Fri Feb 7 11:51:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13964873 Received: from fout-a8-smtp.messagingengine.com (fout-a8-smtp.messagingengine.com [103.168.172.151]) (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 231821DEFF7 for ; Fri, 7 Feb 2025 11:52:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929129; cv=none; b=ct6ZBXUlO9TtrlKS9FEYnNiYtBNsCXUPlsYkeIgGt075X+i8nMGwwl1q82okAZpaBT/hHpp0sRztRxQ2R49y5I7IK/tig//k2KZmbSfC4kYSehTnhrLFYk30K/0OACjoUKyPmQ0FMsO+7WNq+t/04DFTl0c4oydpROpSollj9vM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929129; c=relaxed/simple; bh=DRli0EDBg6LEhX0SobEDNZwu4aBVnUCI6NfiuJLblnk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZXCe+A0jTBPCDYHzNuPcA20+2+fct3CB6/s9bzn8NM1lgXX5nfPTxmKy5kcOf/IeIfesxW+tf+F2Y0OXrgOjKlbe4OtPBhDP/eV4oYNgqXKrNQ/MnEvUgz/l7Luv27pKjrMCiRA7gc/FrA1rm2ul5KtKqoHFTAfSHY+9sdaPTXE= 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=h7/Q5dYq; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Nwcbj+ww; arc=none smtp.client-ip=103.168.172.151 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="h7/Q5dYq"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Nwcbj+ww" Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfout.phl.internal (Postfix) with ESMTP id 165B713801B4; Fri, 7 Feb 2025 06:52:06 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-09.internal (MEProxy); Fri, 07 Feb 2025 06:52:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding: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=fm3; t=1738929126; x=1739015526; bh=0gV166oCJt0XD15OCQi4cHbM6whojCeNI4Y8xLFoMoY=; b= h7/Q5dYq3h1vEuAh8hZqWVT/xn08gSSsmCYDqHTUJ1wBnNBm+kP4h1vD7KbQtd8e Tjva843dUkq22wBj8dLfeyO8vGnAVin4R0rXdhZIwkzzZFzxgIJLhT9uXM0ND8b2 4qEGb3U+3z5rHACR5/XP/0MS4F918Sf/KQ3h2EVYw5ftIMJndDhVvVXLpr0662pm /9XcSF6PIxb49g8RgHVNuXSxUgPk/4Dcq2jz2z5MO2zXqMij4GSlZvhpTdchM1WE mAlzGW30sBNh76n0KbxeFOM4MBvaJjj8P77gPqNpOJFNOI0gz4AbJep0OExtA2KJ /gQs7x2f3iGc57EEY8byGQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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-sender:x-me-sender:x-sasl-enc; s=fm3; t=1738929126; x= 1739015526; bh=0gV166oCJt0XD15OCQi4cHbM6whojCeNI4Y8xLFoMoY=; b=N wcbj+ww9PKU2f5Br4bNwrbHH6K9oNUgZ2R9Y9QFxTQ6BHvGW6mjNs2UL4YuHo12O eDQEosM+zQ13fobElOgnm6cCk0iiUdGnKBR+vbnmJOPpMZ2fPt7+jnkJD2iwyVV9 dOHBN4biEPQ4NUygU+LtdjeuosDOsmMRqgFMxDOfJ+8x/OknGbl4C1Ws81+c5OcL LSF/JealIn142SD0kI9mBlRofw4Dmlrk49RV4Saap+ivuXeZd1e2OmAcCPZheQbi M95zMkJRgFt3nIHdviLc8fipE54KJ+YnaGviucbTvJKIsN5b1w7LXJFstqZleI2U WMT5nt7MXpUUFlLX2HOcQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvledvudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredt jeenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrd himheqnecuggftrfgrthhtvghrnhepffeuiedujedvkeehuedvkeefffeivdeuleetkedu heejteekgedvudfgtdfgieelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprh gtphhtthhopehjiehtsehkuggsghdrohhrghdprhgtphhtthhopegvthhhohhmshhonhes vggufigrrhguthhhohhmshhonhdrtghomhdprhgtphhtthhopehgihhtsehvghgvrhdrkh gvrhhnvghlrdhorhhgpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Feb 2025 06:52:04 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 122e2f1b (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 7 Feb 2025 11:52:02 +0000 (UTC) From: Patrick Steinhardt Date: Fri, 07 Feb 2025 12:51:57 +0100 Subject: [PATCH v5 02/18] reftable/stack: stop using `write_in_full()` Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250207-pks-reftable-drop-git-compat-util-v5-2-ba2adc79110f@pks.im> References: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> In-Reply-To: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> To: git@vger.kernel.org Cc: Edward Thomson , Justin Tobler , Junio C Hamano , Johannes Sixt X-Mailer: b4 0.14.2 Similar to the preceding commit, drop our use of `write_in_full()` and implement a new wrapper `reftable_write_full()` that handles this logic for us. This is done to reduce our dependency on the Git library. Signed-off-by: Patrick Steinhardt --- reftable/stack.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/reftable/stack.c b/reftable/stack.c index d57acd9540..46abf51ec5 100644 --- a/reftable/stack.c +++ b/reftable/stack.c @@ -48,6 +48,25 @@ static int stack_fsync(const struct reftable_write_options *opts, int fd) return fsync(fd); } +static ssize_t reftable_write_data(int fd, const void *data, size_t size) +{ + size_t total_written = 0; + const char *p = data; + + while (total_written < size) { + ssize_t bytes_written = write(fd, p, size - total_written); + if (bytes_written < 0 && (errno == EAGAIN || errno == EINTR)) + continue; + if (bytes_written < 0) + return REFTABLE_IO_ERROR; + + total_written += bytes_written; + p += bytes_written; + } + + return total_written; +} + struct fd_writer { const struct reftable_write_options *opts; int fd; @@ -56,7 +75,7 @@ struct fd_writer { static ssize_t fd_writer_write(void *arg, const void *data, size_t sz) { struct fd_writer *writer = arg; - return write_in_full(writer->fd, data, sz); + return reftable_write_data(writer->fd, data, sz); } static int fd_writer_flush(void *arg) @@ -784,7 +803,8 @@ int reftable_addition_commit(struct reftable_addition *add) goto done; } - err = write_in_full(add->tables_list_lock.fd, table_list.buf, table_list.len); + err = reftable_write_data(add->tables_list_lock.fd, + table_list.buf, table_list.len); reftable_buf_release(&table_list); if (err < 0) { err = REFTABLE_IO_ERROR; @@ -1468,8 +1488,8 @@ static int stack_compact_range(struct reftable_stack *st, goto done; } - err = write_in_full(tables_list_lock.fd, - tables_list_buf.buf, tables_list_buf.len); + err = reftable_write_data(tables_list_lock.fd, + tables_list_buf.buf, tables_list_buf.len); if (err < 0) { err = REFTABLE_IO_ERROR; unlink(new_table_path.buf); From patchwork Fri Feb 7 11:51:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13964874 Received: from fout-a8-smtp.messagingengine.com (fout-a8-smtp.messagingengine.com [103.168.172.151]) (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 80CA51A4F12 for ; Fri, 7 Feb 2025 11:52:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929130; cv=none; b=K8lsQpjWD2fhLAWAFYmx/WRNVW3mNs9weJS88PS+8jX65kLhBYd0RKP1zSFJW9HgpP77GlGGsw91/IVNlO6elvguknRbCR4hlAXngDtUpu1wvP/rF9hSx0i0aNi+PjdZRJxb9WUbN4eZtbgiNsN1ZSyXuf4B03gt9cSdGtBXZW4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929130; c=relaxed/simple; bh=Lb6B1HNb1RFqbdcwYW/aT4a9hLJ862UJnyNuvrlc2kM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=epDtTQrbkOzsIdV5hN4JxYYzRwskb10KVOsnxRPFs2BiBKjbqxZlNyYTJ8F1gY/YGoLCy0Tk70TXPFqJY3mbOBBqgH71jQZ8tSqE+R7tOMsD1wuEwpq3qMU3OPTOo5i6SpwEwc//WSpQFSlrxowV1lsEEkilMRW+K5ItK3znonY= 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=jE91DOLa; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=kjT7LEK5; arc=none smtp.client-ip=103.168.172.151 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="jE91DOLa"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="kjT7LEK5" Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfout.phl.internal (Postfix) with ESMTP id 8598B13801A7; Fri, 7 Feb 2025 06:52:07 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Fri, 07 Feb 2025 06:52:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding: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=fm3; t=1738929127; x=1739015527; bh=Hn3nnoVMXPt9SS+UntNoPYSlAzfDwFyx/kqG2hw1lr4=; b= jE91DOLa0ZgVB5EmLmWoNTvv5h4U5lXPz/iU8tjqlAZuUJT5qVnhnhjY0hq9gqFS IhHMk84VBcUBmG1IUCec8aL+xTnXWl1bH3gnhT/a8A+IYYayldAVeyZOCH3CvYN9 gyUL4Grx/kBAUuCA5zc/2FOaO5PjrzTP+V2zy1hJJpMboEczwOoiEYU+8uSr4VVs kPi5Su3HCVpW0FUMOlyz2HQlGBvR6FuDMr5jOcJtNjfOJ6GuGW3IbS9neqtDUFo8 7CN7nXCakqwHY7oldc91RnhVCYDDf42eR4ukrIdRn6gpCW8esR/dyiNGidpwh1M2 /HleV4Q5K8NCowORSP+7GQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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-sender:x-me-sender:x-sasl-enc; s=fm3; t=1738929127; x= 1739015527; bh=Hn3nnoVMXPt9SS+UntNoPYSlAzfDwFyx/kqG2hw1lr4=; b=k jT7LEK50tkoH/iYAnqXodYPEHmn4Ne3KmfF5BxaSlObK7ofv48zLetgI+P4QIOQx n5I8GO2+hLb5+27DQH6LexrT/iDu3o1oL/YLzucpCckaoBWR8O9IJfsN+jIONg/f Zdapn/4/zlsZRtaPTAZUInQfyTnBE16w/4KpsqTsDyzRfq4puVv56nOjNFxDu4+J C+Dbna/iexx4bTec2gSe2yZfTIVvUmtntaIKlpFXkiKvXCH+iQ9KkialFgVkwws+ fnPVqzkSZ0dXQuq6misNdYzl2j4c0amRllqkKFz/LiGlXWp5eDat74RUGxAGT5mb 5E1uEeuSVcP7ERiCE8+2g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvledvudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredt jeenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrd himheqnecuggftrfgrthhtvghrnhepffeuiedujedvkeehuedvkeefffeivdeuleetkedu heejteekgedvudfgtdfgieelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepvghthhhomhhsohhnsegvugifrghrughthhhomh hsohhnrdgtohhmpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhr tghpthhtohepjheitheskhgusghgrdhorhhgpdhrtghpthhtohepghhithhsthgvrhesph hosghogidrtghomhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Feb 2025 06:52:06 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 6d4f9b01 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 7 Feb 2025 11:52:03 +0000 (UTC) From: Patrick Steinhardt Date: Fri, 07 Feb 2025 12:51:58 +0100 Subject: [PATCH v5 03/18] reftable/blocksource: stop using `xmmap()` Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250207-pks-reftable-drop-git-compat-util-v5-3-ba2adc79110f@pks.im> References: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> In-Reply-To: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> To: git@vger.kernel.org Cc: Edward Thomson , Justin Tobler , Junio C Hamano , Johannes Sixt X-Mailer: b4 0.14.2 We use `xmmap()` to map reftables into memory. This function has two problems: - It causes us to die in case the mmap fails. - It ties us to the Git codebase. Refactor the code to use mmap(3p) instead with manual error checking. Note that this function may not be the system-provided mmap(3p), but may point to our `git_mmap()` wrapper that emulates the syscall on systems that do not have mmap(3p) available. Fix `reftable_block_source_from_file()` to properly bubble up the error code in case the map(3p) call fails. Signed-off-by: Patrick Steinhardt --- reftable/blocksource.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/reftable/blocksource.c b/reftable/blocksource.c index bba4a45b98..02972c46f4 100644 --- a/reftable/blocksource.c +++ b/reftable/blocksource.c @@ -98,7 +98,7 @@ static struct reftable_block_source_vtable file_vtable = { int reftable_block_source_from_file(struct reftable_block_source *bs, const char *name) { - struct file_block_source *p; + struct file_block_source *p = NULL; struct stat st; int fd, err; @@ -122,7 +122,12 @@ int reftable_block_source_from_file(struct reftable_block_source *bs, } p->size = st.st_size; - p->data = xmmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + p->data = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + if (p->data == MAP_FAILED) { + err = REFTABLE_IO_ERROR; + p->data = NULL; + goto out; + } assert(!bs->ops); bs->ops = &file_vtable; @@ -135,5 +140,5 @@ int reftable_block_source_from_file(struct reftable_block_source *bs, close(fd); if (err < 0) reftable_free(p); - return 0; + return err; } From patchwork Fri Feb 7 11:51:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13964875 Received: from fout-a8-smtp.messagingengine.com (fout-a8-smtp.messagingengine.com [103.168.172.151]) (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 D3E711DF752 for ; Fri, 7 Feb 2025 11:52:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929132; cv=none; b=dd560MRkS2RY2FEkxthh5yyKEx3bguiSFNX+7FjyWoKFLxDS5gdz4funOy1U4p0HuVkBo8ucv9IFQmmaQmj1MemUB9rxqQl7tYQUedmJzgzjok9eI7UbEIX+Aeg7GeVlHlVjzbLpI++Jsi6r5VevN18f9qISNpfHyUTSpBsTpus= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929132; c=relaxed/simple; bh=+sfDFJ9ndI2wqkFzPAkNIaU0EeKHSdWxl33c5nvqNz0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ctOGdQPtkGaxeXpIKcMTTlJgtiZY638YMO/Wfxv1W86mUAURmeTmRpEU9BbUHJGOaqUXOtBgiLruyPJdjiYOzBsjyyWDSxum33rjYw/7SGx3j82IZWGHo86YdNsO21PQ8KFW509MEDMSAIZBbsus94f5LQ9NyObiEkEkxDQs7qc= 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=dnDdaewK; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=WerveR/7; arc=none smtp.client-ip=103.168.172.151 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="dnDdaewK"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="WerveR/7" Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfout.phl.internal (Postfix) with ESMTP id E4122138016B; Fri, 7 Feb 2025 06:52:08 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Fri, 07 Feb 2025 06:52:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding: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=fm3; t=1738929128; x=1739015528; bh=C7QV0kCJ4r1t8KXYpuFP34bogFrxND3jDhV8HS9ZL3s=; b= dnDdaewK2BEhMWGzC2CBvlPCcbGMLLUo0DIYl2MJPglxZXxSnIkLkYFJmYK3CNeu FmP+EPmvli+/zphbEgqRKtf1jzM0xLhRnIZxKQciONRwjyvmjQK+gdk/UU43tbyG o6uvfuAgpEj9SXBBSOVNqbqTSVdQq82f2RRmKMRJ/kqIj9G+bufgTKrqkoAYOpXJ KApiKqcRM1aCGH6zA4f+pbAfG1jrQz+XuzelszAK+E9vOGOcFA76ankcPCq+rQrl 5Pk+hrncAsfVSyCPRSD8XIpWgBwUmSFwV26THqJ/qGH3txCjQ/9nNhbptG7Tm7lG voT2IKBHYi3YsVtKRz5JWA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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-sender:x-me-sender:x-sasl-enc; s=fm3; t=1738929128; x= 1739015528; bh=C7QV0kCJ4r1t8KXYpuFP34bogFrxND3jDhV8HS9ZL3s=; b=W erveR/798wS3/AGUvNWQT7yc+j3qxouti2j0o9r3y+uGNXgF5eM+jeq/IE3hAKKB 9P7zTippFxmFXxmBQYP3RSRTC4WzY4vKsKh90vGyv54EXNLrHFMV29/5NDOqoaXx ddg2XsvPqc6ht9V1wo6g5mU1zQxawA2NE1DX/IX5XZQ3yvWt58z3NURgr7DDmXki 2kLQ2LSjVScwPv3jVqsQ1WVu7rQtH4aYoU7nNmi2t50GlI0Rzr7spomjFgbXpaov aayaabVh1PFn+PnvsnTqG9tprbXtTiA2QInyBoaeukXsS6Vk0ZIb5Eo4VfpQmtI1 XQrwYnePmbmjjkaZCI3Ng== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvledvudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredt jeenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrd himheqnecuggftrfgrthhtvghrnhepffeuiedujedvkeehuedvkeefffeivdeuleetkedu heejteekgedvudfgtdfgieelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh dprhgtphhtthhopehgihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtohepjhhl thhosghlvghrsehgmhgrihhlrdgtohhmpdhrtghpthhtohepjheitheskhgusghgrdhorh hgpdhrtghpthhtohepvghthhhomhhsohhnsegvugifrghrughthhhomhhsohhnrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Feb 2025 06:52:07 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 2586e381 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 7 Feb 2025 11:52:04 +0000 (UTC) From: Patrick Steinhardt Date: Fri, 07 Feb 2025 12:51:59 +0100 Subject: [PATCH v5 04/18] reftable/record: stop using `COPY_ARRAY()` Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250207-pks-reftable-drop-git-compat-util-v5-4-ba2adc79110f@pks.im> References: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> In-Reply-To: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> To: git@vger.kernel.org Cc: Edward Thomson , Justin Tobler , Junio C Hamano , Johannes Sixt X-Mailer: b4 0.14.2 Drop our use of `COPY_ARRAY()`, replacing it with an open-coded variant thereof. This is done to reduce our dependency on the Git library. While at it, guard the whole array copy logic so that we only copy it in case there actually is anything to be copied. Otherwise, we may end up trying to allocate a zero-sized array, which will return a NULL pointer and thus cause us to return an `REFTABLE_OUT_OF_MEMORY_ERROR`. Signed-off-by: Patrick Steinhardt --- reftable/record.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/reftable/record.c b/reftable/record.c index 8919df8a4d..2c0cc32cbd 100644 --- a/reftable/record.c +++ b/reftable/record.c @@ -504,11 +504,17 @@ static int reftable_obj_record_copy_from(void *rec, const void *src_rec, if (src->hash_prefix_len) memcpy(obj->hash_prefix, src->hash_prefix, obj->hash_prefix_len); - REFTABLE_ALLOC_ARRAY(obj->offsets, src->offset_len); - if (!obj->offsets) - return REFTABLE_OUT_OF_MEMORY_ERROR; - obj->offset_len = src->offset_len; - COPY_ARRAY(obj->offsets, src->offsets, src->offset_len); + if (src->offset_len) { + if (sizeof(*src->offsets) > SIZE_MAX / src->offset_len) + return REFTABLE_OUT_OF_MEMORY_ERROR; + + REFTABLE_ALLOC_ARRAY(obj->offsets, src->offset_len); + if (!obj->offsets) + return REFTABLE_OUT_OF_MEMORY_ERROR; + + memcpy(obj->offsets, src->offsets, sizeof(*src->offsets) * src->offset_len); + obj->offset_len = src->offset_len; + } return 0; } From patchwork Fri Feb 7 11:52:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13964876 Received: from fout-a8-smtp.messagingengine.com (fout-a8-smtp.messagingengine.com [103.168.172.151]) (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 091A91DF967 for ; Fri, 7 Feb 2025 11:52:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929132; cv=none; b=j7lQ+lfEGwkV5TKg0lZg1XLx649L0jfbr9GJd3f9pqOrz1g25O+H55bUeovsCw6cjnS56woHzyqB5R3eQpcRHkK3uzCMRCd3HA3eCuZaVlra+cpkz6KDPk56Sykx878LppkRHhke/StUj2mXmKVcV0d++i4P0lR+iKAEHMa/tJY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929132; c=relaxed/simple; bh=9/A1Bccc2cIxVF/mcHaqQ905YH53c82cafmO7EtfsUE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HtBg3rZifCxpP9dXRelkOJZLaedQV/LNrT/Rtjhg9xDEVus87T7HG+5waCnNcMMKxjPCskT9dzSEo2cO3AOaBvfi96KNjnTr2T7Zepy/moiUCrYZfGN93hfqDYZUH5YiKjnvifuD28QaBOvbIxiPMnU6/Si1wHUAbDteeqamkhM= 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=dmTul//w; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=jmhqCFBE; arc=none smtp.client-ip=103.168.172.151 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="dmTul//w"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="jmhqCFBE" Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfout.phl.internal (Postfix) with ESMTP id 602FE13801A7; Fri, 7 Feb 2025 06:52:10 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Fri, 07 Feb 2025 06:52:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding: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=fm3; t=1738929130; x=1739015530; bh=ZJx+EF7rq9i9fC06psF/6Mk0ZFHRyDowMH9Dx6Yzo0I=; b= dmTul//wJbn6VLvD3Hpb2eFG2b6cAjRKpUeuvQvBQXFV01wu72CSVuSftJW2CSmd 93N+/e9Keb/7VW8IuWV+gCuI7iqNo5s2R7rK/6ZjGqhy5CUXiOvZ4u8g5IHiLifV BVn8BbbYc1VSaukBeuSVHtvVp/utJ9s2yPH5lb+HjocWvZd4yo+BjCaZhQ0O3phu TC4LWxFeIl1wF8AmXlg8TuFSpeSQYr/r0iJ2FyK5IuSZ20AHCqwgJdH9n1Ni2pqv xV4EeRoYjW3VbUAZVK09UVQqBH+twijrbyHXi1t3f71nvQ34N/yrHPaekCn87j1i HNgqA7rYPY/pUs472gBfZg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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-sender:x-me-sender:x-sasl-enc; s=fm3; t=1738929130; x= 1739015530; bh=ZJx+EF7rq9i9fC06psF/6Mk0ZFHRyDowMH9Dx6Yzo0I=; b=j mhqCFBEkpV5EKUKfbZW6asIhVqfIwz/d1QEcr7PPHHvFhKXsORTCoxIVCdHqcPeH uMiRRoYayhrR8b3i2kOIim+viyALmW+fBqnwQWpbApz7x3Iii9mXUwkpy0SHIp5T MUzchYG43ErnYBgURE4BGLnfIxvdRkV8ldhcI+9imBahnnLzDCVe6qMu1xsZkozt G1d0/Zhe+jbLK0vwr7EfWlZ3/TyYNG0OaR+2iV9CKXt/zf9BPknCv2DQaeCxczuX Iq5zuCo5LU7ZdksT71GvI7rFJd3v47ehZHDJWyyUx/p5sivZCbXJ5yGn3T3uJvLM U8X7VPL8MMvbU4VQckQGw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvledvudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredt jeenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrd himheqnecuggftrfgrthhtvghrnhepffeuiedujedvkeehuedvkeefffeivdeuleetkedu heejteekgedvudfgtdfgieelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepjheitheskhgusghgrdhorhhgpdhrtghpthhtoh epvghthhhomhhsohhnsegvugifrghrughthhhomhhsohhnrdgtohhmpdhrtghpthhtohep jhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtghpthhtohepghhithhsthgvrhesph hosghogidrtghomhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Feb 2025 06:52:09 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 2462f6c9 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 7 Feb 2025 11:52:05 +0000 (UTC) From: Patrick Steinhardt Date: Fri, 07 Feb 2025 12:52:00 +0100 Subject: [PATCH v5 05/18] reftable/record: stop using `BUG()` in `reftable_record_init()` Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250207-pks-reftable-drop-git-compat-util-v5-5-ba2adc79110f@pks.im> References: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> In-Reply-To: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> To: git@vger.kernel.org Cc: Edward Thomson , Justin Tobler , Junio C Hamano , Johannes Sixt X-Mailer: b4 0.14.2 We're aborting the program via `BUG()` in case `reftable_record_init()` was invoked with an unknown record type. This is bad because we may now die in library code, and because it makes us depend on the Git codebase. Refactor the code such that `reftable_record_init()` can return an error code to the caller. Adapt any callers accordingly. Signed-off-by: Patrick Steinhardt --- reftable/block.c | 4 +++- reftable/merged.c | 5 ++++- reftable/reader.c | 5 ++++- reftable/record.c | 8 ++++---- reftable/record.h | 4 ++-- t/unit-tests/t-reftable-pq.c | 6 +++--- t/unit-tests/t-reftable-record.c | 2 +- 7 files changed, 21 insertions(+), 13 deletions(-) diff --git a/reftable/block.c b/reftable/block.c index 8ac865ce78..255d566854 100644 --- a/reftable/block.c +++ b/reftable/block.c @@ -509,7 +509,9 @@ int block_iter_seek_key(struct block_iter *it, const struct block_reader *br, it->block_len = br->block_len; it->hash_size = br->hash_size; - reftable_record_init(&rec, block_reader_type(br)); + err = reftable_record_init(&rec, block_reader_type(br)); + if (err < 0) + goto done; /* * We're looking for the last entry less than the wanted key so that diff --git a/reftable/merged.c b/reftable/merged.c index e72b39e178..4156eec07f 100644 --- a/reftable/merged.c +++ b/reftable/merged.c @@ -253,7 +253,10 @@ int merged_table_init_iter(struct reftable_merged_table *mt, } for (size_t i = 0; i < mt->readers_len; i++) { - reftable_record_init(&subiters[i].rec, typ); + ret = reftable_record_init(&subiters[i].rec, typ); + if (ret < 0) + goto out; + ret = reader_init_iter(mt->readers[i], &subiters[i].iter, typ); if (ret < 0) goto out; diff --git a/reftable/reader.c b/reftable/reader.c index 3f2e4b2800..de6e6dd932 100644 --- a/reftable/reader.c +++ b/reftable/reader.c @@ -360,7 +360,10 @@ static int table_iter_seek_linear(struct table_iter *ti, struct reftable_record rec; int err; - reftable_record_init(&rec, reftable_record_type(want)); + err = reftable_record_init(&rec, reftable_record_type(want)); + if (err < 0) + goto done; + err = reftable_record_key(want, &want_key); if (err < 0) goto done; diff --git a/reftable/record.c b/reftable/record.c index 2c0cc32cbd..1e18f8dffb 100644 --- a/reftable/record.c +++ b/reftable/record.c @@ -1306,7 +1306,7 @@ reftable_record_vtable(struct reftable_record *rec) abort(); } -void reftable_record_init(struct reftable_record *rec, uint8_t typ) +int reftable_record_init(struct reftable_record *rec, uint8_t typ) { memset(rec, 0, sizeof(*rec)); rec->type = typ; @@ -1315,11 +1315,11 @@ void reftable_record_init(struct reftable_record *rec, uint8_t typ) case BLOCK_TYPE_REF: case BLOCK_TYPE_LOG: case BLOCK_TYPE_OBJ: - return; + return 0; case BLOCK_TYPE_INDEX: reftable_buf_init(&rec->u.idx.last_key); - return; + return 0; default: - BUG("unhandled record type"); + return REFTABLE_API_ERROR; } } diff --git a/reftable/record.h b/reftable/record.h index c7755a4d75..e1846c294b 100644 --- a/reftable/record.h +++ b/reftable/record.h @@ -130,8 +130,8 @@ struct reftable_record { } u; }; -/* Initialize the reftable record for the given type */ -void reftable_record_init(struct reftable_record *rec, uint8_t typ); +/* Initialize the reftable record for the given type. */ +int reftable_record_init(struct reftable_record *rec, uint8_t typ); /* see struct record_vtable */ int reftable_record_cmp(struct reftable_record *a, struct reftable_record *b); diff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c index f3f8a0cdf3..d8a4c283a1 100644 --- a/t/unit-tests/t-reftable-pq.c +++ b/t/unit-tests/t-reftable-pq.c @@ -32,7 +32,7 @@ static void t_pq_record(void) char *last = NULL; for (i = 0; i < N; i++) { - reftable_record_init(&recs[i], BLOCK_TYPE_REF); + check(!reftable_record_init(&recs[i], BLOCK_TYPE_REF)); recs[i].u.ref.refname = xstrfmt("%02"PRIuMAX, (uintmax_t)i); } @@ -72,7 +72,7 @@ static void t_pq_index(void) size_t N = ARRAY_SIZE(recs), i; for (i = 0; i < N; i++) { - reftable_record_init(&recs[i], BLOCK_TYPE_REF); + check(!reftable_record_init(&recs[i], BLOCK_TYPE_REF)); recs[i].u.ref.refname = (char *) "refs/heads/master"; } @@ -111,7 +111,7 @@ static void t_merged_iter_pqueue_top(void) size_t N = ARRAY_SIZE(recs), i; for (i = 0; i < N; i++) { - reftable_record_init(&recs[i], BLOCK_TYPE_REF); + check(!reftable_record_init(&recs[i], BLOCK_TYPE_REF)); recs[i].u.ref.refname = (char *) "refs/heads/master"; } diff --git a/t/unit-tests/t-reftable-record.c b/t/unit-tests/t-reftable-record.c index d49d2a2729..6540bd20e3 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -17,7 +17,7 @@ static void t_copy(struct reftable_record *rec) uint8_t typ; typ = reftable_record_type(rec); - reftable_record_init(©, typ); + check(!reftable_record_init(©, typ)); reftable_record_copy_from(©, rec, REFTABLE_HASH_SIZE_SHA1); /* do it twice to catch memory leaks */ reftable_record_copy_from(©, rec, REFTABLE_HASH_SIZE_SHA1); From patchwork Fri Feb 7 11:52:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13964877 Received: from fout-a8-smtp.messagingengine.com (fout-a8-smtp.messagingengine.com [103.168.172.151]) (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 CD1F51DF99C for ; Fri, 7 Feb 2025 11:52:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929134; cv=none; b=jofUfAd0rb7UZkv7wMhUWoPflB7aAnLi1LmAZsBp2nWYCb/40c3xwvrOOQyvNwOpBedTbIgk/LlId0F6w55+F8Gd8BCIqnhrDk25koims4c3R2aUqUPw2Z8ISO9X9Jnrl2qUwbDobmNsVtfPCvT+d7/M3YZ5Mz4zB1VeZRGXybs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929134; c=relaxed/simple; bh=XSjG9z41CmKEsDZ/fUO+OPNB38R0eaXQMZTWodfyJUo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=I3Y2wqbVmYuvONr6RNzymBMhGDQOjG9fvpxaKspZSvIh0UvZn036DhEWbzrjSLL+Q/m6HsHLP3mgsrEkdbnfdjKnI+tEV7csUZLUNPU+jKUKXvwRCPk9Y8qE5koi3yEvYi/Fjxpo62/7X3Xi29Q7i0tmoym7CQ1HYQqIKWkMFpM= 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=g7cnU2cn; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=aWnYGmAd; arc=none smtp.client-ip=103.168.172.151 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="g7cnU2cn"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="aWnYGmAd" Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfout.phl.internal (Postfix) with ESMTP id DA8DE138017E; Fri, 7 Feb 2025 06:52:11 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Fri, 07 Feb 2025 06:52:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding: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=fm3; t=1738929131; x=1739015531; bh=CXMlbB6PZhUKKeSFpMTSVch5btyEgkbcpsjmrCti1kw=; b= g7cnU2cnELBQVxB2ybRmqj1rnWcdiCkBizcYgnXAv9WE5J66JZmLcK92kAy3iwQF RXLG2wjBGJMVYsdqsUWO469jJpBgsVM3vBvaZFvVK7Op6S0Kkp2f/2fYLjw1vv8l zZOmKJFlxlOF5EVEkYTApSboWCQVS/2p6uUmbok291ZGEBNjWaFpQ2Z/H3DGhbi6 4SjNiUN0ZrgCFGu0lAPKrg0S/jWcuOR5FO1+8MUI+RNc21rHFGeqg5BcQGW1WNsT VrA0LU7ZjK8JV8ChsEXtfQ352gjoSoWUzn0gMC47bU5SrI/F1afA+NghgbI0EVuu TCGyZ0qsMSgjx2WuiSlhUw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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-sender:x-me-sender:x-sasl-enc; s=fm3; t=1738929131; x= 1739015531; bh=CXMlbB6PZhUKKeSFpMTSVch5btyEgkbcpsjmrCti1kw=; b=a WnYGmAd3Hu+PkrKIpdw+rSlmHSd/SafAcSlsjnVoQuZ0E0jwWoaHfNy+2um6iNtS inJeDRg2Lqa541qM+nVbhQmsPRmbAG49ux9xP6tfpQIAOdKQ+PtK6hfmJv0/+A4U DD+4KCSovqCblo1JiyYRyxpCKDbUPJM9pehngH1fh7cqEOYI8ggrJQ+mLmEl9Km8 558PegUK7Ac8DfxkUPbFXv3Y8cnPpzYqWJt1pNsyEdpqRDiQLn+u63P0z0W71xIm HqeBfdk1SnhdHTVJ/dL/SjY2dmWf1Q90OvQYTVDFdsx7uBTB64rOyNxz/auvXs+m S93huEVa6o+m769pNkHwA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvledvudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredt jeenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrd himheqnecuggftrfgrthhtvghrnhepffeuiedujedvkeehuedvkeefffeivdeuleetkedu heejteekgedvudfgtdfgieelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepvghthhhomhhsohhnsegvugifrghrughthhhomh hsohhnrdgtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdp rhgtphhtthhopehjiehtsehkuggsghdrohhrghdprhgtphhtthhopehgihhtshhtvghrse hpohgsohigrdgtohhmpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Feb 2025 06:52:10 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 19567067 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 7 Feb 2025 11:52:06 +0000 (UTC) From: Patrick Steinhardt Date: Fri, 07 Feb 2025 12:52:01 +0100 Subject: [PATCH v5 06/18] reftable/record: don't `BUG()` in `reftable_record_cmp()` Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250207-pks-reftable-drop-git-compat-util-v5-6-ba2adc79110f@pks.im> References: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> In-Reply-To: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> To: git@vger.kernel.org Cc: Edward Thomson , Justin Tobler , Junio C Hamano , Johannes Sixt X-Mailer: b4 0.14.2 The reftable library aborts with a bug in case `reftable_record_cmp()` is invoked with two records of differing types. This would cause the program to die without the caller being able to handle the error, which is not something we want in the context of library code. And it ties us to the Git codebase. Refactor the code such that `reftable_record_cmp()` returns an error code separate from the actual comparison result. This requires us to also adapt some callers up the callchain in a similar fashion. Signed-off-by: Patrick Steinhardt --- reftable/merged.c | 20 +++++++++++++++----- reftable/pq.c | 36 +++++++++++++++++++++++++++++------- reftable/pq.h | 2 +- reftable/record.c | 10 ++++++---- reftable/record.h | 2 +- t/unit-tests/t-reftable-pq.c | 16 ++++++++++++---- t/unit-tests/t-reftable-record.c | 40 ++++++++++++++++++++++++++++------------ 7 files changed, 92 insertions(+), 34 deletions(-) diff --git a/reftable/merged.c b/reftable/merged.c index 4156eec07f..563864068c 100644 --- a/reftable/merged.c +++ b/reftable/merged.c @@ -66,8 +66,11 @@ static int merged_iter_seek(struct merged_iter *mi, struct reftable_record *want int err; mi->advance_index = -1; - while (!merged_iter_pqueue_is_empty(mi->pq)) - merged_iter_pqueue_remove(&mi->pq); + while (!merged_iter_pqueue_is_empty(mi->pq)) { + err = merged_iter_pqueue_remove(&mi->pq, NULL); + if (err < 0) + return err; + } for (size_t i = 0; i < mi->subiters_len; i++) { err = iterator_seek(&mi->subiters[i].iter, want); @@ -120,7 +123,9 @@ static int merged_iter_next_entry(struct merged_iter *mi, if (empty) return 1; - entry = merged_iter_pqueue_remove(&mi->pq); + err = merged_iter_pqueue_remove(&mi->pq, &entry); + if (err < 0) + return err; /* One can also use reftable as datacenter-local storage, where the ref @@ -134,11 +139,16 @@ static int merged_iter_next_entry(struct merged_iter *mi, struct pq_entry top = merged_iter_pqueue_top(mi->pq); int cmp; - cmp = reftable_record_cmp(top.rec, entry.rec); + err = reftable_record_cmp(top.rec, entry.rec, &cmp); + if (err < 0) + return err; if (cmp > 0) break; - merged_iter_pqueue_remove(&mi->pq); + err = merged_iter_pqueue_remove(&mi->pq, NULL); + if (err < 0) + return err; + err = merged_iter_advance_subiter(mi, top.index); if (err < 0) return err; diff --git a/reftable/pq.c b/reftable/pq.c index 5591e875e1..ef8035cfd9 100644 --- a/reftable/pq.c +++ b/reftable/pq.c @@ -15,13 +15,18 @@ license that can be found in the LICENSE file or at int pq_less(struct pq_entry *a, struct pq_entry *b) { - int cmp = reftable_record_cmp(a->rec, b->rec); + int cmp, err; + + err = reftable_record_cmp(a->rec, b->rec, &cmp); + if (err < 0) + return err; + if (cmp == 0) return a->index > b->index; return cmp < 0; } -struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq) +int merged_iter_pqueue_remove(struct merged_iter_pqueue *pq, struct pq_entry *out) { size_t i = 0; struct pq_entry e = pq->heap[0]; @@ -32,17 +37,34 @@ struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq) size_t min = i; size_t j = 2 * i + 1; size_t k = 2 * i + 2; - if (j < pq->len && pq_less(&pq->heap[j], &pq->heap[i])) - min = j; - if (k < pq->len && pq_less(&pq->heap[k], &pq->heap[min])) - min = k; + int cmp; + + if (j < pq->len) { + cmp = pq_less(&pq->heap[j], &pq->heap[i]); + if (cmp < 0) + return -1; + else if (cmp) + min = j; + } + + if (k < pq->len) { + cmp = pq_less(&pq->heap[k], &pq->heap[min]); + if (cmp < 0) + return -1; + else if (cmp) + min = k; + } + if (min == i) break; SWAP(pq->heap[i], pq->heap[min]); i = min; } - return e; + if (out) + *out = e; + + return 0; } int merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry *e) diff --git a/reftable/pq.h b/reftable/pq.h index 83c062eeca..ff39016445 100644 --- a/reftable/pq.h +++ b/reftable/pq.h @@ -22,7 +22,7 @@ struct merged_iter_pqueue { size_t cap; }; -struct pq_entry merged_iter_pqueue_remove(struct merged_iter_pqueue *pq); +int merged_iter_pqueue_remove(struct merged_iter_pqueue *pq, struct pq_entry *out); int merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry *e); void merged_iter_pqueue_release(struct merged_iter_pqueue *pq); int pq_less(struct pq_entry *a, struct pq_entry *b); diff --git a/reftable/record.c b/reftable/record.c index 1e18f8dffb..b39d99fcc7 100644 --- a/reftable/record.c +++ b/reftable/record.c @@ -1195,12 +1195,14 @@ int reftable_record_is_deletion(struct reftable_record *rec) reftable_record_data(rec)); } -int reftable_record_cmp(struct reftable_record *a, struct reftable_record *b) +int reftable_record_cmp(struct reftable_record *a, struct reftable_record *b, + int *cmp) { if (a->type != b->type) - BUG("cannot compare reftable records of different type"); - return reftable_record_vtable(a)->cmp( - reftable_record_data(a), reftable_record_data(b)); + return -1; + *cmp = reftable_record_vtable(a)->cmp(reftable_record_data(a), + reftable_record_data(b)); + return 0; } int reftable_record_equal(struct reftable_record *a, struct reftable_record *b, uint32_t hash_size) diff --git a/reftable/record.h b/reftable/record.h index e1846c294b..867810a932 100644 --- a/reftable/record.h +++ b/reftable/record.h @@ -134,7 +134,7 @@ struct reftable_record { int reftable_record_init(struct reftable_record *rec, uint8_t typ); /* see struct record_vtable */ -int reftable_record_cmp(struct reftable_record *a, struct reftable_record *b); +int reftable_record_cmp(struct reftable_record *a, struct reftable_record *b, int *cmp); int reftable_record_equal(struct reftable_record *a, struct reftable_record *b, uint32_t hash_size); int reftable_record_key(struct reftable_record *rec, struct reftable_buf *dest); int reftable_record_copy_from(struct reftable_record *rec, diff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c index d8a4c283a1..c128fe8616 100644 --- a/t/unit-tests/t-reftable-pq.c +++ b/t/unit-tests/t-reftable-pq.c @@ -21,7 +21,9 @@ static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq) static int pq_entry_equal(struct pq_entry *a, struct pq_entry *b) { - return !reftable_record_cmp(a->rec, b->rec) && (a->index == b->index); + int cmp; + check(!reftable_record_cmp(a->rec, b->rec, &cmp)); + return !cmp && (a->index == b->index); } static void t_pq_record(void) @@ -49,7 +51,9 @@ static void t_pq_record(void) while (!merged_iter_pqueue_is_empty(pq)) { struct pq_entry top = merged_iter_pqueue_top(pq); - struct pq_entry e = merged_iter_pqueue_remove(&pq); + struct pq_entry e; + + check(!merged_iter_pqueue_remove(&pq, &e)); merged_iter_pqueue_check(&pq); check(pq_entry_equal(&top, &e)); @@ -90,7 +94,9 @@ static void t_pq_index(void) for (i = N - 1; i > 0; i--) { struct pq_entry top = merged_iter_pqueue_top(pq); - struct pq_entry e = merged_iter_pqueue_remove(&pq); + struct pq_entry e; + + check(!merged_iter_pqueue_remove(&pq, &e)); merged_iter_pqueue_check(&pq); check(pq_entry_equal(&top, &e)); @@ -129,7 +135,9 @@ static void t_merged_iter_pqueue_top(void) for (i = N - 1; i > 0; i--) { struct pq_entry top = merged_iter_pqueue_top(pq); - struct pq_entry e = merged_iter_pqueue_remove(&pq); + struct pq_entry e; + + check(!merged_iter_pqueue_remove(&pq, &e)); merged_iter_pqueue_check(&pq); check(pq_entry_equal(&top, &e)); diff --git a/t/unit-tests/t-reftable-record.c b/t/unit-tests/t-reftable-record.c index 6540bd20e3..5954966373 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -100,16 +100,20 @@ static void t_reftable_ref_record_comparison(void) .u.ref.value.symref = (char *) "refs/heads/master", }, }; + int cmp; check(!reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1)); - check(!reftable_record_cmp(&in[0], &in[1])); + check(!reftable_record_cmp(&in[0], &in[1], &cmp)); + check(!cmp); check(!reftable_record_equal(&in[1], &in[2], REFTABLE_HASH_SIZE_SHA1)); - check_int(reftable_record_cmp(&in[1], &in[2]), >, 0); + check(!reftable_record_cmp(&in[1], &in[2], &cmp)); + check_int(cmp, >, 0); in[1].u.ref.value_type = in[0].u.ref.value_type; check(reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1)); - check(!reftable_record_cmp(&in[0], &in[1])); + check(!reftable_record_cmp(&in[0], &in[1], &cmp)); + check(!cmp); } static void t_reftable_ref_record_compare_name(void) @@ -209,17 +213,20 @@ static void t_reftable_log_record_comparison(void) .u.log.update_index = 22, }, }; + int cmp; check(!reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1)); check(!reftable_record_equal(&in[1], &in[2], REFTABLE_HASH_SIZE_SHA1)); - check_int(reftable_record_cmp(&in[1], &in[2]), >, 0); + check(!reftable_record_cmp(&in[1], &in[2], &cmp)); + check_int(cmp, >, 0); /* comparison should be reversed for equal keys, because * comparison is now performed on the basis of update indices */ - check_int(reftable_record_cmp(&in[0], &in[1]), <, 0); + check(!reftable_record_cmp(&in[0], &in[1], &cmp)); + check_int(cmp, <, 0); in[1].u.log.update_index = in[0].u.log.update_index; check(reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1)); - check(!reftable_record_cmp(&in[0], &in[1])); + check(!reftable_record_cmp(&in[0], &in[1], &cmp)); } static void t_reftable_log_record_compare_key(void) @@ -396,16 +403,20 @@ static void t_reftable_obj_record_comparison(void) .u.obj.hash_prefix_len = 5, }, }; + int cmp; check(!reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1)); - check(!reftable_record_cmp(&in[0], &in[1])); + check(!reftable_record_cmp(&in[0], &in[1], &cmp)); + check(!cmp); check(!reftable_record_equal(&in[1], &in[2], REFTABLE_HASH_SIZE_SHA1)); - check_int(reftable_record_cmp(&in[1], &in[2]), >, 0); + check(!reftable_record_cmp(&in[1], &in[2], &cmp)); + check_int(cmp, >, 0); in[1].u.obj.offset_len = in[0].u.obj.offset_len; check(reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1)); - check(!reftable_record_cmp(&in[0], &in[1])); + check(!reftable_record_cmp(&in[0], &in[1], &cmp)); + check(!cmp); } static void t_reftable_obj_record_roundtrip(void) @@ -486,19 +497,24 @@ static void t_reftable_index_record_comparison(void) .u.idx.last_key = REFTABLE_BUF_INIT, }, }; + int cmp; + check(!reftable_buf_addstr(&in[0].u.idx.last_key, "refs/heads/master")); check(!reftable_buf_addstr(&in[1].u.idx.last_key, "refs/heads/master")); check(!reftable_buf_addstr(&in[2].u.idx.last_key, "refs/heads/branch")); check(!reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1)); - check(!reftable_record_cmp(&in[0], &in[1])); + check(!reftable_record_cmp(&in[0], &in[1], &cmp)); + check(!cmp); check(!reftable_record_equal(&in[1], &in[2], REFTABLE_HASH_SIZE_SHA1)); - check_int(reftable_record_cmp(&in[1], &in[2]), >, 0); + check(!reftable_record_cmp(&in[1], &in[2], &cmp)); + check_int(cmp, >, 0); in[1].u.idx.offset = in[0].u.idx.offset; check(reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1)); - check(!reftable_record_cmp(&in[0], &in[1])); + check(!reftable_record_cmp(&in[0], &in[1], &cmp)); + check(!cmp); for (size_t i = 0; i < ARRAY_SIZE(in); i++) reftable_record_release(&in[i]); From patchwork Fri Feb 7 11:52:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13964880 Received: from fout-a8-smtp.messagingengine.com (fout-a8-smtp.messagingengine.com [103.168.172.151]) (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 CA2F81E0086 for ; Fri, 7 Feb 2025 11:52:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929138; cv=none; b=c3dfN/rjeNQefz+7PPNEmNKz36+sYFgD+ay4PdRZC1ELbrxckDTJX/dwYGUcjo2/CxcKLAvyLJpR8PB2khtnMY4eGxuUcKcWEu9mnBCEIq9TAzpidQJnTucQhnRT5oGvybCOG/mYfsiS34jdVuZYfxUJvp9KwkLWazlf7+de70Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929138; c=relaxed/simple; bh=kPKuX8zhwCLYorG3555jZ8E4+OmEvwNW9Za2IYdBUhM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=I3ABMsWMjRYGEF3QYsll73pGa9DOK2V85uo+JGonuHyVYCJo5bXuVC0GHNFDBgDc/U4VMpjG8OGEs70A4wVI8QfhjVCr0pMmfldTIMzHyqWcdXT6smohI8EOoRjY92KM+Hf8+yyPERwU0ywWhT9G78Dn6fDbyOgv+EdteC/Fyuw= 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=O6MAEb27; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=kpTejGof; arc=none smtp.client-ip=103.168.172.151 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="O6MAEb27"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="kpTejGof" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfout.phl.internal (Postfix) with ESMTP id 7E9BA13801A7; Fri, 7 Feb 2025 06:52:13 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Fri, 07 Feb 2025 06:52:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding: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=fm3; t=1738929133; x=1739015533; bh=mM1aJiXiGx/mftefjDbbDUQyfUe75piBTX7KwSqp554=; b= O6MAEb27ocA5GmXhREVXWD5MzDV3XicSMlFLQ5SC7ncNgnIPuWehtWNJzo252p39 4XcSa6sn+DgV88T+JsASNqyGrouHr6gkkJIb5gTvG/HDyqxObQLajFVvgp5FyNLL bDDoZiVTiyLY9EKQaxhMNgiQLHnsrLYEizeQ3L9ZmTIOItc3zy2+HjYgAWqUaqUq vvT97g9b0rPm3RZnNQAbBSQTpznL+QxiOFn51Uy50q5kSxDqEruq1extC/qooFY6 ok3OW8w5IFuMb8acFnVATYd/Iho+7xeBc+G4X+VwfUGxvmu0vm7D+P+QQosdZQsI sqkygkqdVa2mEpyKupoj9g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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-sender:x-me-sender:x-sasl-enc; s=fm3; t=1738929133; x= 1739015533; bh=mM1aJiXiGx/mftefjDbbDUQyfUe75piBTX7KwSqp554=; b=k pTejGofGgZATxNQ0fk7gjZtCZjKLFllLLfLGiEdlRqi3mbPhSH5ihn4D1Vf7De2/ Gncbst3qMayURTI5fPjQhJX9NyToFpicxF0CkPPymhwM4hczfkkcAGTmcSKKILn+ NmhxsUPgV7yXYU5CENaqUkJ+vmBipXWlvAPxE6OMQLcTOkXyM/Rz9vYXnOKCHx3z C3FTcu5DDJ3Qi+K01ihvHZAl6VRV6w9jbSCGLRjsaxebSSPvuXE5f8wIXaobRsSV NvZazQ28riT9p60rGIdDolZSKcHoMZRPF9oszvS9LT91H/ggpOPEgictuCqizw0I wV8HZZomrZvU7+WX5UB3Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvledvtdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredt jeenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrd himheqnecuggftrfgrthhtvghrnhepffeuiedujedvkeehuedvkeefffeivdeuleetkedu heejteekgedvudfgtdfgieelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpd hrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehg ihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtohepvghthhhomhhsohhnsegvug ifrghrughthhhomhhsohhnrdgtohhmpdhrtghpthhtohepjheitheskhgusghgrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Feb 2025 06:52:12 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 09611234 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 7 Feb 2025 11:52:07 +0000 (UTC) From: Patrick Steinhardt Date: Fri, 07 Feb 2025 12:52:02 +0100 Subject: [PATCH v5 07/18] reftable: stop using `BUG()` in trivial cases Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250207-pks-reftable-drop-git-compat-util-v5-7-ba2adc79110f@pks.im> References: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> In-Reply-To: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> To: git@vger.kernel.org Cc: Edward Thomson , Justin Tobler , Junio C Hamano , Johannes Sixt X-Mailer: b4 0.14.2 Stop using `BUG()` in the remaining trivial cases that we still have in the reftable library. Instead of aborting the program, we'll now bubble up a `REFTABLE_API_ERROR` to indicate misuse of the calling conventions. Note that in both `reftable_reader_{inc,dec}ref()` we simply stop calling `BUG()` altogether. The only situation where the counter should be zero is when the structure has already been free'd anyway, so we would run into undefined behaviour regardless of whether we try to abort the program or not. Signed-off-by: Patrick Steinhardt --- reftable/iter.c | 3 +-- reftable/reader.c | 4 ---- reftable/writer.c | 5 ++--- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/reftable/iter.c b/reftable/iter.c index 86e801ca9f..b2ffb09c16 100644 --- a/reftable/iter.c +++ b/reftable/iter.c @@ -146,8 +146,7 @@ static int indexed_table_ref_iter_next_block(struct indexed_table_ref_iter *it) static int indexed_table_ref_iter_seek(void *p UNUSED, struct reftable_record *want UNUSED) { - BUG("seeking indexed table is not supported"); - return -1; + return REFTABLE_API_ERROR; } static int indexed_table_ref_iter_next(void *p, struct reftable_record *rec) diff --git a/reftable/reader.c b/reftable/reader.c index de6e6dd932..36a5633ede 100644 --- a/reftable/reader.c +++ b/reftable/reader.c @@ -677,8 +677,6 @@ int reftable_reader_new(struct reftable_reader **out, void reftable_reader_incref(struct reftable_reader *r) { - if (!r->refcount) - BUG("cannot increment ref counter of dead reader"); r->refcount++; } @@ -686,8 +684,6 @@ void reftable_reader_decref(struct reftable_reader *r) { if (!r) return; - if (!r->refcount) - BUG("cannot decrement ref counter of dead reader"); if (--r->refcount) return; block_source_close(&r->source); diff --git a/reftable/writer.c b/reftable/writer.c index 91d6629486..155863ee5f 100644 --- a/reftable/writer.c +++ b/reftable/writer.c @@ -158,7 +158,7 @@ int reftable_writer_new(struct reftable_writer **out, opts = *_opts; options_set_defaults(&opts); if (opts.block_size >= (1 << 24)) - BUG("configured block size exceeds 16MB"); + return REFTABLE_API_ERROR; reftable_buf_init(&wp->block_writer_data.last_key); reftable_buf_init(&wp->last_key); @@ -289,8 +289,7 @@ static int writer_add_record(struct reftable_writer *w, } if (block_writer_type(w->block_writer) != reftable_record_type(rec)) - BUG("record of type %d added to writer of type %d", - reftable_record_type(rec), block_writer_type(w->block_writer)); + return REFTABLE_API_ERROR; /* * Try to add the record to the writer. If this succeeds then we're From patchwork Fri Feb 7 11:52:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13964878 Received: from fhigh-a3-smtp.messagingengine.com (fhigh-a3-smtp.messagingengine.com [103.168.172.154]) (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 A73FC1DF267 for ; Fri, 7 Feb 2025 11:52:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929137; cv=none; b=iXYmu3yRnwY5j34K6IyhYfbF7KLty2UT9eKKLYeOHA9gaQsw5KwlSYZI4YahZTAy2A17qmu/o9YoUFt0YRx1Ky43xMH7zwhjuaWKiEhV7bU6EsepyujWGOwnss8jK2bcs/kvi943GQeGZOTb74W8VfPZWtS8qWofqtMyHvd2qd0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929137; c=relaxed/simple; bh=knuekfm47Y4pJI1AsxWUejZz/ZFP7Z5CGrhY4gdlhmA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mB340IIVq6JnL9bF3slel9TKpuHVSUIUxFledAwgUkDVbgNkhHqf8zr4JbLoEjbEsLZ8WFbujun2eWiL/XJUcjgW6xj1qtQxYvNsEv4m6n6sASIF8NSYVf819pTDZTvj56Nw0ZG2o8Kut5R9i5oRrOajPDR7soF+PlTzcj9vcxs= 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=KMX+FjDF; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=EKBqMH2A; arc=none smtp.client-ip=103.168.172.154 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="KMX+FjDF"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="EKBqMH2A" Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfhigh.phl.internal (Postfix) with ESMTP id 9401611400FB; Fri, 7 Feb 2025 06:52:13 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Fri, 07 Feb 2025 06:52:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding: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=fm3; t=1738929133; x=1739015533; bh=90cILya0hlcij7yaSMuAS2CDXIQCI9SHwbES56WXxsc=; b= KMX+FjDFXec2Qx3KoKSTn2kYKRoGkfhWoSHE8+dsgRgOkZUw0dDJb0c4ksUtSrSz GNPPaziHAuLh6r8M9grJQ+rsqkpGvizisiaqM88SlHXAIp/i+osUnuq3XEYHwr4l bpgwRSbB6ORt/yC8FMkU8oiF9JpC4LPWcvLzfZdlydAKueA1PWnGchbM7YGM/C3A hClzdwOhjkOqcg6fm93IjhtwbwNa/pPupA2q8co+332mokdrE3bw+GMffMIxgo9c q+090xRXerznq1u5KyNBmfVWdXtJ47WmpHOqE21p/lMZx0usm6awmDoI+C6D6whB HXukWyE96BEgsizqorRFhQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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-sender:x-me-sender:x-sasl-enc; s=fm3; t=1738929133; x= 1739015533; bh=90cILya0hlcij7yaSMuAS2CDXIQCI9SHwbES56WXxsc=; b=E KBqMH2AeZindykFQfrxe/J4c/tdSTk2kyoNcMAtJKtFXyWinHsakmerO5x6Rd72s 22a0vVpWIJTbDwqwavAwjIJSDI13yQryvEKcoIwWk34TOxwEwv7HIW6bO6ihqzs9 4aCRDf5MXegDP1Gkye++vi4bvnvHrhIrVZbqTspqif//ARgeDaK92prlJJXe6RLh tSqWthdhwcD+/GXXljn0PzLfcbQH87qof/z9FbarRFGf+8ElYGEHGCNnjLueZLL9 pmfS8hJXC98a7fSPuLpFFW9bjHU6QTRbwFukb3CeVsqUwbbgR9HFU+J9IrIWQNmx SJmK/1UNG2wHBmck5g6OA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvledvudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredt jeenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrd himheqnecuggftrfgrthhtvghrnhepffeuiedujedvkeehuedvkeefffeivdeuleetkedu heejteekgedvudfgtdfgieelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpd hrtghpthhtohepvghthhhomhhsohhnsegvugifrghrughthhhomhhsohhnrdgtohhmpdhr tghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtphhtthhopehjiehtse hkuggsghdrohhrghdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Feb 2025 06:52:12 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 4ff6c6bc (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 7 Feb 2025 11:52:08 +0000 (UTC) From: Patrick Steinhardt Date: Fri, 07 Feb 2025 12:52:03 +0100 Subject: [PATCH v5 08/18] reftable/basics: stop using `st_mult()` in array allocators Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250207-pks-reftable-drop-git-compat-util-v5-8-ba2adc79110f@pks.im> References: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> In-Reply-To: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> To: git@vger.kernel.org Cc: Edward Thomson , Justin Tobler , Junio C Hamano , Johannes Sixt X-Mailer: b4 0.14.2 We're using `st_mult()` as part of our macro helpers that allocate arrays. This is bad due two two reasons: - `st_mult()` causes us to die in case the multiplication overflows. - `st_mult()` ties us to the Git codebase. Refactor the code to instead detect overflows manually and return an error in such cases. Signed-off-by: Patrick Steinhardt --- reftable/basics.h | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/reftable/basics.h b/reftable/basics.h index a2a010a0e1..646f8d67f2 100644 --- a/reftable/basics.h +++ b/reftable/basics.h @@ -117,18 +117,46 @@ 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))) +static inline int reftable_alloc_size(size_t nelem, size_t elsize, size_t *out) +{ + if (nelem && elsize > SIZE_MAX / nelem) + return -1; + *out = nelem * elsize; + return 0; +} + +#define REFTABLE_ALLOC_ARRAY(x, alloc) do { \ + size_t alloc_size; \ + if (reftable_alloc_size(sizeof(*(x)), (alloc), &alloc_size) < 0) { \ + errno = ENOMEM; \ + (x) = NULL; \ + } else { \ + (x) = reftable_malloc(alloc_size); \ + } \ + } while (0) #define REFTABLE_CALLOC_ARRAY(x, alloc) (x) = reftable_calloc((alloc), sizeof(*(x))) -#define REFTABLE_REALLOC_ARRAY(x, alloc) (x) = reftable_realloc((x), st_mult(sizeof(*(x)), (alloc))) +#define REFTABLE_REALLOC_ARRAY(x, alloc) do { \ + size_t alloc_size; \ + if (reftable_alloc_size(sizeof(*(x)), (alloc), &alloc_size) < 0) { \ + errno = ENOMEM; \ + (x) = NULL; \ + } else { \ + (x) = reftable_realloc((x), alloc_size); \ + } \ + } while (0) static inline void *reftable_alloc_grow(void *p, size_t nelem, size_t elsize, size_t *allocp) { void *new_p; - size_t alloc = *allocp * 2 + 1; + size_t alloc = *allocp * 2 + 1, alloc_bytes; if (alloc < nelem) alloc = nelem; - new_p = reftable_realloc(p, st_mult(elsize, alloc)); + if (reftable_alloc_size(elsize, alloc, &alloc_bytes) < 0) { + errno = ENOMEM; + return p; + } + new_p = reftable_realloc(p, alloc_bytes); if (!new_p) return p; *allocp = alloc; From patchwork Fri Feb 7 11:52:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13964879 Received: from fout-a8-smtp.messagingengine.com (fout-a8-smtp.messagingengine.com [103.168.172.151]) (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 CA3541E008E for ; Fri, 7 Feb 2025 11:52:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929137; cv=none; b=RSNzowZq+Ufvedx0ZqBmpPEYO4kSSPyyaYwcNEPH2xMlESaGcCLWc2O9qccM8TIQUzHc68MPc+odHr/T//dG6hML801t1ypnx0JUw6rxcmt6+PQGemvkEW2ruM+y4mA5e9o2pvgC7vMjxTwXX4x8oRy5AAd3EH4kH95ZBfZGa5c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929137; c=relaxed/simple; bh=x2mGm07+izREe8Y0rddoQtlUiQhuo+VxiYb4e+FX7Jw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Zz6ufZSp8VvJ1yL8LrlEXUUKbFKV9gEXyOUtEG7RJZvGPNVKPuhLr4BGRs2asxIWcd1DqGItYuhN0DSMLHLAEhyXpfqdH6AMvx1dWOAsqpwQC2NMD4RZaN/z1yNRqa6vf2T6UqsW4YWHVPMNfWJlkLPf5b3lnNY1kZb8nyiLmYY= 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=p45EiuTM; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=HBuoBnxP; arc=none smtp.client-ip=103.168.172.151 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="p45EiuTM"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="HBuoBnxP" Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfout.phl.internal (Postfix) with ESMTP id E78A013801AE; Fri, 7 Feb 2025 06:52:14 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-11.internal (MEProxy); Fri, 07 Feb 2025 06:52:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding: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=fm3; t=1738929134; x=1739015534; bh=TyhVGiG6cUdrBF7vCZTrX0L7pOhpAOfn6lX/mnSvmW4=; b= p45EiuTMGxEr9W+onziv61gOad4xqrPwbgBjjQNAjRT7oynjml/i6AABGUHCmp7c 8wh844OcwZfrFN3doZkP4vwvPZxUYdDx8uaga3P1LpHm1NuaJVBjacyTyydQzw7z hcNeYLhe8ymkPYyIW2EpdBD0LqnIPiM4Qt4rQnoaa7IB9Udcf5OsQMPA7PY8/Xr5 ZK63sgIdx7YdbALb45UpdDvQ6PX3uRrP6AKKlaYLbFhNfwEm4NNHuYFqZHhjQ/7C tyjiP/xcTMwbN724nYeyMu2cHxXN0bbVyzll4T1+i8hHy4L5xPFkbqDm8L7mQrfZ BNK4JIxOH+J8gOJZf3ghnw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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-sender:x-me-sender:x-sasl-enc; s=fm3; t=1738929134; x= 1739015534; bh=TyhVGiG6cUdrBF7vCZTrX0L7pOhpAOfn6lX/mnSvmW4=; b=H BuoBnxPGp82/V/1sjw0jWEb8EdF+38oIpzWQx9Y/emmFqE/J6g1IS4oKEcVl3vq9 DuCc3Mt0ZtuJb3W0RJqpEsvDDsSIB/hiT+FfZrAnA1+i5iU/ot+pRsIDhRkxUcB+ 6lCgmxDfKv7h/Ct0XY/wveC73vOkjDaB2gCjfO4QvNuY4pCYwBtsfIxO3YuxDpzC UWeMJ+53fHxHcSvbiKPd5iOWLmDFl39qGguOrnkNbWWj9j7U+PoL+hXgFubIzUMW VUocJ7DkGejWslrqM5ZPMpjkEJxZuLbpQ+kYkpJSNN4hZVWU6F229ySpadVjQn8h Ak5oSU0Dsh8EF8I0STgaw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvledvudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredt jeenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrd himheqnecuggftrfgrthhtvghrnhephfefieevffduhfejvdevfffhudekhfdvkeevveeg ueeiteetveeglefghfevtdfgnecuffhomhgrihhnpehuphgurghtvgdrthiinecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhi mhdpnhgspghrtghpthhtohephedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepjh hlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtghpthhtohepvghthhhomhhsohhnsegv ugifrghrughthhhomhhsohhnrdgtohhmpdhrtghpthhtohepjheitheskhgusghgrdhorh hgpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprhgtphhtthhopehg ihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Feb 2025 06:52:13 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 55f11561 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 7 Feb 2025 11:52:09 +0000 (UTC) From: Patrick Steinhardt Date: Fri, 07 Feb 2025 12:52:04 +0100 Subject: [PATCH v5 09/18] reftable/basics: provide wrappers for big endian conversion Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250207-pks-reftable-drop-git-compat-util-v5-9-ba2adc79110f@pks.im> References: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> In-Reply-To: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> To: git@vger.kernel.org Cc: Edward Thomson , Justin Tobler , Junio C Hamano , Johannes Sixt X-Mailer: b4 0.14.2 We're using a mixture of big endian conversion functions provided by both the reftable library, but also by the Git codebase. Refactor the code so that we exclusively use reftable-provided wrappers in order to untangle us from the Git codebase. Signed-off-by: Patrick Steinhardt --- reftable/basics.c | 19 ---------- reftable/basics.h | 76 ++++++++++++++++++++++++++++++++++++++-- reftable/block.c | 12 +++---- reftable/reader.c | 22 ++++++------ reftable/record.c | 8 ++--- reftable/writer.c | 20 +++++------ t/unit-tests/t-reftable-basics.c | 28 ++++++++++++--- 7 files changed, 127 insertions(+), 58 deletions(-) diff --git a/reftable/basics.c b/reftable/basics.c index 3b5ea27bbd..8c4a4433e4 100644 --- a/reftable/basics.c +++ b/reftable/basics.c @@ -147,25 +147,6 @@ char *reftable_buf_detach(struct reftable_buf *buf) return result; } -void put_be24(uint8_t *out, uint32_t i) -{ - out[0] = (uint8_t)((i >> 16) & 0xff); - out[1] = (uint8_t)((i >> 8) & 0xff); - out[2] = (uint8_t)(i & 0xff); -} - -uint32_t get_be24(uint8_t *in) -{ - return (uint32_t)(in[0]) << 16 | (uint32_t)(in[1]) << 8 | - (uint32_t)(in[2]); -} - -void put_be16(uint8_t *out, uint16_t i) -{ - out[0] = (uint8_t)((i >> 8) & 0xff); - out[1] = (uint8_t)(i & 0xff); -} - size_t binsearch(size_t sz, int (*f)(size_t k, void *args), void *args) { size_t lo = 0; diff --git a/reftable/basics.h b/reftable/basics.h index 646f8d67f2..c1ddbaec3f 100644 --- a/reftable/basics.h +++ b/reftable/basics.h @@ -76,9 +76,79 @@ char *reftable_buf_detach(struct reftable_buf *buf); /* Bigendian en/decoding of integers */ -void put_be24(uint8_t *out, uint32_t i); -uint32_t get_be24(uint8_t *in); -void put_be16(uint8_t *out, uint16_t i); +static inline void reftable_put_be16(void *out, uint16_t i) +{ + unsigned char *p = out; + p[0] = (uint8_t)((i >> 8) & 0xff); + p[1] = (uint8_t)((i >> 0) & 0xff); +} + +static inline void reftable_put_be24(void *out, uint32_t i) +{ + unsigned char *p = out; + p[0] = (uint8_t)((i >> 16) & 0xff); + p[1] = (uint8_t)((i >> 8) & 0xff); + p[2] = (uint8_t)((i >> 0) & 0xff); +} + +static inline void reftable_put_be32(void *out, uint32_t i) +{ + unsigned char *p = out; + p[0] = (uint8_t)((i >> 24) & 0xff); + p[1] = (uint8_t)((i >> 16) & 0xff); + p[2] = (uint8_t)((i >> 8) & 0xff); + p[3] = (uint8_t)((i >> 0) & 0xff); +} + +static inline void reftable_put_be64(void *out, uint64_t i) +{ + unsigned char *p = out; + p[0] = (uint8_t)((i >> 56) & 0xff); + p[1] = (uint8_t)((i >> 48) & 0xff); + p[2] = (uint8_t)((i >> 40) & 0xff); + p[3] = (uint8_t)((i >> 32) & 0xff); + p[4] = (uint8_t)((i >> 24) & 0xff); + p[5] = (uint8_t)((i >> 16) & 0xff); + p[6] = (uint8_t)((i >> 8) & 0xff); + p[7] = (uint8_t)((i >> 0) & 0xff); +} + +static inline uint16_t reftable_get_be16(const void *in) +{ + const unsigned char *p = in; + return (uint16_t)(p[0]) << 8 | + (uint16_t)(p[1]) << 0; +} + +static inline uint32_t reftable_get_be24(const void *in) +{ + const unsigned char *p = in; + return (uint32_t)(p[0]) << 16 | + (uint32_t)(p[1]) << 8 | + (uint32_t)(p[2]) << 0; +} + +static inline uint32_t reftable_get_be32(const void *in) +{ + const unsigned char *p = in; + return (uint32_t)(p[0]) << 24 | + (uint32_t)(p[1]) << 16 | + (uint32_t)(p[2]) << 8| + (uint32_t)(p[3]) << 0; +} + +static inline uint64_t reftable_get_be64(const void *in) +{ + const unsigned char *p = in; + return (uint64_t)(p[0]) << 56 | + (uint64_t)(p[1]) << 48 | + (uint64_t)(p[2]) << 40 | + (uint64_t)(p[3]) << 32 | + (uint64_t)(p[4]) << 24 | + (uint64_t)(p[5]) << 16 | + (uint64_t)(p[6]) << 8 | + (uint64_t)(p[7]) << 0; +} /* * find smallest index i in [0, sz) at which `f(i) > 0`, assuming that f is diff --git a/reftable/block.c b/reftable/block.c index 255d566854..373908807e 100644 --- a/reftable/block.c +++ b/reftable/block.c @@ -148,13 +148,13 @@ int block_writer_add(struct block_writer *w, struct reftable_record *rec) int block_writer_finish(struct block_writer *w) { for (uint32_t i = 0; i < w->restart_len; i++) { - put_be24(w->block + w->next, w->restarts[i]); + reftable_put_be24(w->block + w->next, w->restarts[i]); w->next += 3; } - put_be16(w->block + w->next, w->restart_len); + reftable_put_be16(w->block + w->next, w->restart_len); w->next += 2; - put_be24(w->block + 1 + w->header_off, w->next); + reftable_put_be24(w->block + 1 + w->header_off, w->next); /* * Log records are stored zlib-compressed. Note that the compression @@ -216,7 +216,7 @@ int block_reader_init(struct block_reader *br, struct reftable_block *block, { uint32_t full_block_size = table_block_size; uint8_t typ = block->data[header_off]; - uint32_t sz = get_be24(block->data + header_off + 1); + uint32_t sz = reftable_get_be24(block->data + header_off + 1); int err = 0; uint16_t restart_count = 0; uint32_t restart_start = 0; @@ -300,7 +300,7 @@ int block_reader_init(struct block_reader *br, struct reftable_block *block, full_block_size = sz; } - restart_count = get_be16(block->data + sz - 2); + restart_count = reftable_get_be16(block->data + sz - 2); restart_start = sz - 2 - 3 * restart_count; restart_bytes = block->data + restart_start; @@ -355,7 +355,7 @@ int block_reader_first_key(const struct block_reader *br, struct reftable_buf *k static uint32_t block_reader_restart_offset(const struct block_reader *br, size_t idx) { - return get_be24(br->restart_bytes + 3 * idx); + return reftable_get_be24(br->restart_bytes + 3 * idx); } void block_iter_seek_start(struct block_iter *it, const struct block_reader *br) diff --git a/reftable/reader.c b/reftable/reader.c index 36a5633ede..bf07a0a586 100644 --- a/reftable/reader.c +++ b/reftable/reader.c @@ -101,18 +101,18 @@ static int parse_footer(struct reftable_reader *r, uint8_t *footer, } f++; - r->block_size = get_be24(f); + r->block_size = reftable_get_be24(f); f += 3; - r->min_update_index = get_be64(f); + r->min_update_index = reftable_get_be64(f); f += 8; - r->max_update_index = get_be64(f); + r->max_update_index = reftable_get_be64(f); f += 8; if (r->version == 1) { r->hash_id = REFTABLE_HASH_SHA1; } else { - switch (get_be32(f)) { + switch (reftable_get_be32(f)) { case REFTABLE_FORMAT_ID_SHA1: r->hash_id = REFTABLE_HASH_SHA1; break; @@ -127,24 +127,24 @@ static int parse_footer(struct reftable_reader *r, uint8_t *footer, f += 4; } - r->ref_offsets.index_offset = get_be64(f); + r->ref_offsets.index_offset = reftable_get_be64(f); f += 8; - r->obj_offsets.offset = get_be64(f); + r->obj_offsets.offset = reftable_get_be64(f); f += 8; r->object_id_len = r->obj_offsets.offset & ((1 << 5) - 1); r->obj_offsets.offset >>= 5; - r->obj_offsets.index_offset = get_be64(f); + r->obj_offsets.index_offset = reftable_get_be64(f); f += 8; - r->log_offsets.offset = get_be64(f); + r->log_offsets.offset = reftable_get_be64(f); f += 8; - r->log_offsets.index_offset = get_be64(f); + r->log_offsets.index_offset = reftable_get_be64(f); f += 8; computed_crc = crc32(0, footer, f - footer); - file_crc = get_be32(f); + file_crc = reftable_get_be32(f); f += 4; if (computed_crc != file_crc) { err = REFTABLE_FORMAT_ERROR; @@ -214,7 +214,7 @@ static int32_t extract_block_size(uint8_t *data, uint8_t *typ, uint64_t off, *typ = data[0]; if (reftable_is_block_type(*typ)) { - result = get_be24(data + 1); + result = reftable_get_be24(data + 1); } return result; } diff --git a/reftable/record.c b/reftable/record.c index b39d99fcc7..3552bafa99 100644 --- a/reftable/record.c +++ b/reftable/record.c @@ -689,7 +689,7 @@ static int reftable_log_record_key(const void *r, struct reftable_buf *dest) return err; ts = (~ts) - rec->update_index; - put_be64(&i64[0], ts); + reftable_put_be64(&i64[0], ts); err = reftable_buf_add(dest, i64, sizeof(i64)); if (err < 0) @@ -814,7 +814,7 @@ static int reftable_log_record_encode(const void *rec, struct string_view s, if (s.len < 2) return -1; - put_be16(s.buf, r->value.update.tz_offset); + reftable_put_be16(s.buf, r->value.update.tz_offset); string_view_consume(&s, 2); n = encode_string( @@ -846,7 +846,7 @@ static int reftable_log_record_decode(void *rec, struct reftable_buf key, } memcpy(r->refname, key.buf, key.len - 8); - ts = get_be64(key.buf + key.len - 8); + ts = reftable_get_be64((unsigned char *)key.buf + key.len - 8); r->update_index = (~max) - ts; @@ -937,7 +937,7 @@ static int reftable_log_record_decode(void *rec, struct reftable_buf key, goto done; } - r->value.update.tz_offset = get_be16(in.buf); + r->value.update.tz_offset = reftable_get_be16(in.buf); string_view_consume(&in, 2); n = decode_string(scratch, in); diff --git a/reftable/writer.c b/reftable/writer.c index 155863ee5f..5961698311 100644 --- a/reftable/writer.c +++ b/reftable/writer.c @@ -99,9 +99,9 @@ static int writer_write_header(struct reftable_writer *w, uint8_t *dest) dest[4] = writer_version(w); - put_be24(dest + 5, w->opts.block_size); - put_be64(dest + 8, w->min_update_index); - put_be64(dest + 16, w->max_update_index); + reftable_put_be24(dest + 5, w->opts.block_size); + reftable_put_be64(dest + 8, w->min_update_index); + reftable_put_be64(dest + 16, w->max_update_index); if (writer_version(w) == 2) { uint32_t hash_id; @@ -116,7 +116,7 @@ static int writer_write_header(struct reftable_writer *w, uint8_t *dest) return -1; } - put_be32(dest + 24, hash_id); + reftable_put_be32(dest + 24, hash_id); } return header_size(writer_version(w)); @@ -717,19 +717,19 @@ int reftable_writer_close(struct reftable_writer *w) } p += writer_write_header(w, footer); - put_be64(p, w->stats.ref_stats.index_offset); + reftable_put_be64(p, w->stats.ref_stats.index_offset); p += 8; - put_be64(p, (w->stats.obj_stats.offset) << 5 | w->stats.object_id_len); + reftable_put_be64(p, (w->stats.obj_stats.offset) << 5 | w->stats.object_id_len); p += 8; - put_be64(p, w->stats.obj_stats.index_offset); + reftable_put_be64(p, w->stats.obj_stats.index_offset); p += 8; - put_be64(p, w->stats.log_stats.offset); + reftable_put_be64(p, w->stats.log_stats.offset); p += 8; - put_be64(p, w->stats.log_stats.index_offset); + reftable_put_be64(p, w->stats.log_stats.index_offset); p += 8; - put_be32(p, crc32(0, footer, p - footer)); + reftable_put_be32(p, crc32(0, footer, p - footer)); p += 4; err = w->flush(w->write_arg); diff --git a/t/unit-tests/t-reftable-basics.c b/t/unit-tests/t-reftable-basics.c index 9ba7eb05ad..c9e751e49e 100644 --- a/t/unit-tests/t-reftable-basics.c +++ b/t/unit-tests/t-reftable-basics.c @@ -128,12 +128,30 @@ int cmd_main(int argc UNUSED, const char *argv[] UNUSED) reftable_buf_release(&b); } - if_test ("put_be24 and get_be24 work") { + if_test ("reftable_put_be64 and reftable_get_be64 work") { + uint64_t in = 0x1122334455667788; + uint8_t dest[8]; + uint64_t out; + reftable_put_be64(dest, in); + out = reftable_get_be64(dest); + check_int(in, ==, out); + } + + if_test ("reftable_put_be32 and reftable_get_be32 work") { + uint32_t in = 0x11223344; + uint8_t dest[4]; + uint32_t out; + reftable_put_be32(dest, in); + out = reftable_get_be32(dest); + check_int(in, ==, out); + } + + if_test ("reftable_put_be24 and reftable_get_be24 work") { uint32_t in = 0x112233; uint8_t dest[3]; uint32_t out; - put_be24(dest, in); - out = get_be24(dest); + reftable_put_be24(dest, in); + out = reftable_get_be24(dest); check_int(in, ==, out); } @@ -141,8 +159,8 @@ int cmd_main(int argc UNUSED, const char *argv[] UNUSED) uint32_t in = 0xfef1; uint8_t dest[3]; uint32_t out; - put_be16(dest, in); - out = get_be16(dest); + reftable_put_be16(dest, in); + out = reftable_get_be16(dest); check_int(in, ==, out); } From patchwork Fri Feb 7 11:52:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13964881 Received: from fout-a8-smtp.messagingengine.com (fout-a8-smtp.messagingengine.com [103.168.172.151]) (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 8F0621DF99C for ; Fri, 7 Feb 2025 11:52:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929138; cv=none; b=pCIP1V1Qi/StghrjARGp+Jck+HQii+JIMmeNXAGvLAbkH7Lxjk+fKPintGv0VNhwGRzBC2hLUBcE+3YEpBi0MCzkto33QouIBPinBRMEggf2FaMnuskfneKu+1LMEEAuSTdJdPpTQp2Op8eAml5SoTxd3ltBYAad+zdL6jlmrew= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929138; c=relaxed/simple; bh=PwtwJgqncRkQ+/QmJZLIt67toje4FcAFM/hKDh3beEE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kQIsP05OgChylWVojqANnV5r3YIJFbqQwJnO636MlqeMmwiBmBURd5Ik6H7luGZHpCnmtT5Aqg53NCAUPiZelaHv2VFyXQDv7I/1BRbKFK/Ccln7UGWDY6FlRn7wRkBzsP6iT5D3GEdXWfWlFBfl8JTJqZl+O6fvqxX2g3JtVKo= 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=GJS8mD+P; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=U8fukNf7; arc=none smtp.client-ip=103.168.172.151 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="GJS8mD+P"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="U8fukNf7" Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfout.phl.internal (Postfix) with ESMTP id 0DAAF138017E; Fri, 7 Feb 2025 06:52:15 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Fri, 07 Feb 2025 06:52:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding: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=fm3; t=1738929135; x=1739015535; bh=WfB8amsHkYCbCUYxXEFCoq/KZGT+ysKHg7ZmZqXzx94=; b= GJS8mD+PDMBjCZOXC7HfUIXMaWCWbSFTsfFVIPGut+lseTaZ3vnELEec0FP1nyY/ rpednJI/S61ZcZbzO/y9FOU2edqIVRtqjg77miK4lwjdapBymEJXkDl1t+f3HnsU 0fDBFNoEHTSUk5MyXn25bnYLFtoZP9x47dqst+Ah7Rpr5UpWo7QTEjp7b6FspPtG qj4H3CF0HmpInkqVdET85NvckMlCo0mOX1gHIZM91n1I9i4BVCPtnMNp2VbTW1sy DyXhiIVdeMOVJenGoFdAueTvfQEEJ4cav/4H9lMBMqhhviGdsOp11ZS4xRFAHOft CPCqf0tS1ah66z6cEDGDrg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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-sender:x-me-sender:x-sasl-enc; s=fm3; t=1738929135; x= 1739015535; bh=WfB8amsHkYCbCUYxXEFCoq/KZGT+ysKHg7ZmZqXzx94=; b=U 8fukNf7Bqluz8AveyrPLPrxqbjUebe0F0E1urdJX9IMbVZ2L+Ci7h+q8vG9Ei8Kc ee/AqOuZz84XlqhePKMwHxJjshrtvYj9+uQ1MjWAZ3TrJ/TVo3s6zXoE2k790Tf9 mDKiduKNWHBbE4X4sayjwWrVIeWQFA4pmgqRPtMgY7POKO/krsANtbl8I5AVBLbx fNAoEzbEE68WL6vtceFCfzGORVmUvh9ixN4LZvbLu1tdvSu6nwLEq6I5OStvUL6P R3WABWo6rgPQvGSJWJ78vF45O3hFokMuj9+mShYJ7YhiePJVDT9WSydHVsZKCbC5 mHCA8SKvAf9t1l8l+PIRw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvledvtdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredt jeenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrd himheqnecuggftrfgrthhtvghrnhepffeuiedujedvkeehuedvkeefffeivdeuleetkedu heejteekgedvudfgtdfgieelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprh gtphhtthhopehjiehtsehkuggsghdrohhrghdprhgtphhtthhopegvthhhohhmshhonhes vggufigrrhguthhhohhmshhonhdrtghomhdprhgtphhtthhopehjlhhtohgslhgvrhesgh hmrghilhdrtghomhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Feb 2025 06:52:13 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 1bfbef8f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 7 Feb 2025 11:52:10 +0000 (UTC) From: Patrick Steinhardt Date: Fri, 07 Feb 2025 12:52:05 +0100 Subject: [PATCH v5 10/18] reftable/reader: stop using `ARRAY_SIZE()` macro Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250207-pks-reftable-drop-git-compat-util-v5-10-ba2adc79110f@pks.im> References: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> In-Reply-To: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> To: git@vger.kernel.org Cc: Edward Thomson , Justin Tobler , Junio C Hamano , Johannes Sixt X-Mailer: b4 0.14.2 We have a single user of the `ARRAY_SIZE()` macro in the reftable reader. Drop its use to reduce our dependence on the Git codebase. Signed-off-by: Patrick Steinhardt --- reftable/reader.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reftable/reader.c b/reftable/reader.c index bf07a0a586..c3a3674665 100644 --- a/reftable/reader.c +++ b/reftable/reader.c @@ -849,7 +849,7 @@ int reftable_reader_print_blocks(const char *tablename) printf("header:\n"); printf(" block_size: %d\n", r->block_size); - for (i = 0; i < ARRAY_SIZE(sections); i++) { + for (i = 0; i < sizeof(sections) / sizeof(*sections); i++) { err = table_iter_seek_start(&ti, sections[i].type, 0); if (err < 0) goto done; From patchwork Fri Feb 7 11:52:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13964882 Received: from fout-a8-smtp.messagingengine.com (fout-a8-smtp.messagingengine.com [103.168.172.151]) (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 8F0CA1E00BE for ; Fri, 7 Feb 2025 11:52:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929138; cv=none; b=uXS0CPy/9IsSFwJ+aSabqnYJ6E6mAy5gtKiKjpz5Oq514DEXvMe6JBHoOuzr3HhpwVWJln71da1f7jnklThRTHi75WeVieKl+TAU2M+TlcbOfDyyJbFEmAbubTM4p5tESwZnV8K22jCNuOnhAtYonFJ4jnYBSODiReqsbnLIYnY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929138; c=relaxed/simple; bh=Lxpgj1O4BqZGL/ZxQOEef5rHjZudctr5TxTybCrqB/4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gwt+NJZccNth5ct1CF2EPFKTgk6XR76QdXOV9VoZWowukPHduINQyLE5cB+Wr+dMxc2FogtRy/4E+8INUPOyN8080N8LlhSBAt7n24tiLLt351fKl1yfXGXVgYV0Q9c/KF1RnYWY5dGzQS1MGCWPCTFjhbheQC67cJl4f4kuSK4= 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=Fpvuwa5M; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=bLLuVqjF; arc=none smtp.client-ip=103.168.172.151 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="Fpvuwa5M"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="bLLuVqjF" Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfout.phl.internal (Postfix) with ESMTP id 86D0E13801B6; Fri, 7 Feb 2025 06:52:15 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Fri, 07 Feb 2025 06:52:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding: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=fm3; t=1738929135; x=1739015535; bh=twqLDGPZSXwut8sVG8SfsH2zYlOtFP/hSAcnJDe3mO8=; b= Fpvuwa5MtYHAfj01C3kMnrFlxEk/RSMm6EmJh/v3JMKwYqWVONzo9esmj3gBMQn7 qxsLb7EGycMcOuiNzsu68QaCPzlhgufuS+Ix+h3yk5foeBh/Y+h3rmvIZVmAenRf q9Dwrkqwde5J+g4DxIKyk6LP6bs8qovLhttk19F5eucnJBCwVYWOB+XEE2p0Qk9Z 6/fd0ii4cXBd9OIIKJm4poSH5l7M70tyTnw/3sNVF6aHdc2UCIAuh2v84UMJt+q7 zhfKTSls+qm07tll9FKrsZ/Vttau9pe4gUYC0ExH+Xl0H+EsjPFgxEENXYC4bmtF QIUg+Zb7oyE4AtdrmEIQ8A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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-sender:x-me-sender:x-sasl-enc; s=fm3; t=1738929135; x= 1739015535; bh=twqLDGPZSXwut8sVG8SfsH2zYlOtFP/hSAcnJDe3mO8=; b=b LLuVqjFlMKxWdSC6XQX5XcgKp7Tq/ZmtjpZOr+urXJleJ0kdQMoIm33ssGCOfUse LaJQPdX1Mi0uEIONFujLYGiDEX+d+OsrXvPphR+Vm868+0SKXwNDcrbOBjEgI8EQ IZLqLsRHtAnyVl3tJ1zr9MwCTcHRajwdCEIifsYUH8lid1V2CNcZoPW8vLJumkox Kp4hWxmre1OnZv8DuWPPCr4TxW4UjvFGvItL7PP1Ei1AReuxWItaF8+b8VhqrBkv zkyusVccPuOHZ5sXjVQRj3yKCy1TfHycjIZTohsP8xT0W+dl3PAleukfinTE78WY JBw0jHOU86WgO76c9p21Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvledvtdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredt jeenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrd himheqnecuggftrfgrthhtvghrnhepffeuiedujedvkeehuedvkeefffeivdeuleetkedu heejteekgedvudfgtdfgieelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepghhithhsthgvrhesphhosghogidrtghomhdprh gtphhtthhopehjlhhtohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopegvthhh ohhmshhonhesvggufigrrhguthhhohhmshhonhdrtghomhdprhgtphhtthhopehjiehtse hkuggsghdrohhrghdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Feb 2025 06:52:14 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id b51d7c20 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 7 Feb 2025 11:52:11 +0000 (UTC) From: Patrick Steinhardt Date: Fri, 07 Feb 2025 12:52:06 +0100 Subject: [PATCH v5 11/18] reftable/system: introduce `reftable_rand()` Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250207-pks-reftable-drop-git-compat-util-v5-11-ba2adc79110f@pks.im> References: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> In-Reply-To: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> To: git@vger.kernel.org Cc: Edward Thomson , Justin Tobler , Junio C Hamano , Johannes Sixt X-Mailer: b4 0.14.2 Introduce a new system-level `reftable_rand()` function that generates a single unsigned integer for us. The implementation of this function is to be provided by the calling codebase, which allows us to more easily hook into pre-seeded random number generators. Adapt the two callsites where we generated random data. Signed-off-by: Patrick Steinhardt --- reftable/stack.c | 4 ++-- reftable/system.c | 5 +++++ reftable/system.h | 6 ++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/reftable/stack.c b/reftable/stack.c index 46abf51ec5..e22577ec77 100644 --- a/reftable/stack.c +++ b/reftable/stack.c @@ -523,7 +523,7 @@ static int reftable_stack_reload_maybe_reuse(struct reftable_stack *st, close(fd); fd = -1; - delay = delay + (delay * git_rand(CSPRNG_BYTES_INSECURE)) / UINT32_MAX + 1; + delay = delay + (delay * reftable_rand()) / UINT32_MAX + 1; sleep_millisec(delay); } @@ -688,7 +688,7 @@ int reftable_stack_add(struct reftable_stack *st, static int format_name(struct reftable_buf *dest, uint64_t min, uint64_t max) { char buf[100]; - uint32_t rnd = git_rand(CSPRNG_BYTES_INSECURE); + uint32_t rnd = reftable_rand(); snprintf(buf, sizeof(buf), "0x%012" PRIx64 "-0x%012" PRIx64 "-%08x", min, max, rnd); reftable_buf_reset(dest); diff --git a/reftable/system.c b/reftable/system.c index adf8e4d30b..e25ccc0da3 100644 --- a/reftable/system.c +++ b/reftable/system.c @@ -4,6 +4,11 @@ #include "../lockfile.h" #include "../tempfile.h" +uint32_t reftable_rand(void) +{ + return git_rand(CSPRNG_BYTES_INSECURE); +} + int tmpfile_from_pattern(struct reftable_tmpfile *out, const char *pattern) { struct tempfile *tempfile; diff --git a/reftable/system.h b/reftable/system.h index 7d5f803eeb..3bd4a4e322 100644 --- a/reftable/system.h +++ b/reftable/system.h @@ -13,6 +13,12 @@ license that can be found in the LICENSE file or at #include "git-compat-util.h" +/* + * Return a random 32 bit integer. This function is expected to return + * pre-seeded data. + */ +uint32_t reftable_rand(void); + /* * An implementation-specific temporary file. By making this specific to the * implementation it becomes possible to tie temporary files into any kind of From patchwork Fri Feb 7 11:52:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13964884 Received: from fout-a8-smtp.messagingengine.com (fout-a8-smtp.messagingengine.com [103.168.172.151]) (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 ED37D1E00BF for ; Fri, 7 Feb 2025 11:52:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929138; cv=none; b=bqsOxX/aABjUNuPywtmZpqC712s+8aZn12n2vBU7R5l3Q/OJUI9I9W4cfUGcIgR3VrSBu7TwoXtPta/GljHKq9HbChRn8rigN80pja4++t0z6D2lrHsfIc/Bw1WhtQEMbhZgjJQLsO109cMkIiGdNs8T9xxGZn7rdkD+QJp+Meo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929138; c=relaxed/simple; bh=pec/R90NLvALy9Gbnjmrz/7P3RrBUqxoAtOfzWm3SF4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FB1PZyMDJoU7S9/2tcVn0fSPslp7KJND+eKfbTbwy5Ok66B8kReejEXVdHLENZMwsl/3UvvWc36ysE3TvQ52/aGbGxKRrew/ELJEyb0+PNH4FkX83QBNuepdm/tarTt7ajfhmhdk35481tj/6qNGC0kGz3KQ/tYM4jU8tt5NZfU= 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=kxF/Y2oI; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=WFi45AP/; arc=none smtp.client-ip=103.168.172.151 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="kxF/Y2oI"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="WFi45AP/" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfout.phl.internal (Postfix) with ESMTP id 45FFF13801CD; Fri, 7 Feb 2025 06:52:16 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Fri, 07 Feb 2025 06:52:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding: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=fm3; t=1738929136; x=1739015536; bh=lDC0UHBOoKIXw58CdUlY3qbgPWOqWxkPRrpmO7ofue4=; b= kxF/Y2oI6+msHOyTxlzdPCvASwxH37VYuXPC7OCMrWC/tHcFvrLsy5UoUXYbpuF+ qnR8rwobv9NIsNocX01a2e0rkKStMULxFYvGQAw7dngGHavBXU4wuv0glzHWACi4 vJEKsC9wgAfYxluw+DDIduiWTbmYvm4k0j1CYgWYqYd4D5nTyqaYIIqav2hLFlZg wYC7O/fhEY6sjbXzC1HTmGYilwSQKsdRCuif3dXSBVH6IhmBtgqXDnVCD0j+UPBz ymqoXAc+BWrTdw7bdbnKMq+VbbNGMj1j9XPquQTxqylFQ0YzaBsOeaQWo4xucjPo rZ7zLCuGg1NaW/uXBR+FnA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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-sender:x-me-sender:x-sasl-enc; s=fm3; t=1738929136; x= 1739015536; bh=lDC0UHBOoKIXw58CdUlY3qbgPWOqWxkPRrpmO7ofue4=; b=W Fi45AP/cYHKtpnWSPdYn/dzOIJ9wqmcD5DCa0+AoXeJY4jvtnkukXlkF7aga8eQJ oFjUZVcRBzssfQGCvDkQu8z8t4fN36G6U1sxbfPNMCGBB59kbZiA65TABI8P8mTP rauZeM+wH8LQg1Pvj+vK3LtAneXUvFs/U5FzsjAb70hRd805jk+zPX2RRHaKOQ6U Ss39xe0nh5d2oIe8peQgN7hqssgqemn+/upnHYgi5yWlb33rzlklkzPr8Kxf/bhQ hoJf5XZkj6Gs5gRCwISdhMdzwzas+RhbYeDSgRaX4B2/gRjjhlXpoAV+uB+Vusub 40GdT6ngYE1pQ8DiBWDhA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvledvtdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredt jeenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrd himheqnecuggftrfgrthhtvghrnhepffeuiedujedvkeehuedvkeefffeivdeuleetkedu heejteekgedvudfgtdfgieelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh dprhgtphhtthhopehjiehtsehkuggsghdrohhrghdprhgtphhtthhopehgihhtshhtvghr sehpohgsohigrdgtohhmpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtoh hmpdhrtghpthhtohepvghthhhomhhsohhnsegvugifrghrughthhhomhhsohhnrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Feb 2025 06:52:15 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 9c742320 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 7 Feb 2025 11:52:12 +0000 (UTC) From: Patrick Steinhardt Date: Fri, 07 Feb 2025 12:52:07 +0100 Subject: [PATCH v5 12/18] reftable/stack: stop using `sleep_millisec()` Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250207-pks-reftable-drop-git-compat-util-v5-12-ba2adc79110f@pks.im> References: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> In-Reply-To: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> To: git@vger.kernel.org Cc: Edward Thomson , Justin Tobler , Junio C Hamano , Johannes Sixt X-Mailer: b4 0.14.2 Refactor our use of `sleep_millisec()` by open-coding it with poll(3p), which is the current implementation of this function. Ideally, we'd use a more direct way to sleep, but there is no equivalent to sleep(3p) that would accept milliseconds as input. Signed-off-by: Patrick Steinhardt --- reftable/stack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reftable/stack.c b/reftable/stack.c index e22577ec77..7b0b10cd38 100644 --- a/reftable/stack.c +++ b/reftable/stack.c @@ -524,7 +524,7 @@ static int reftable_stack_reload_maybe_reuse(struct reftable_stack *st, fd = -1; delay = delay + (delay * reftable_rand()) / UINT32_MAX + 1; - sleep_millisec(delay); + poll(NULL, 0, delay); } out: From patchwork Fri Feb 7 11:52:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13964883 Received: from fhigh-a3-smtp.messagingengine.com (fhigh-a3-smtp.messagingengine.com [103.168.172.154]) (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 79A481E0487 for ; Fri, 7 Feb 2025 11:52:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929139; cv=none; b=PYbonxQnlD2UczyxuhzSag9RqpkExEHyicY2Qi3hGnY6y5ccYMnh6N0AsesH3v57QgKUubqYxeLIepx/Z2SX2yZYf0umsuV5nOpYGHKq+gJZmKVB0HnctKdDaEvNAa4YI48Ac6Aq6M2eJG+GFl130RBTVZr60URSp93j1Hfnk88= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929139; c=relaxed/simple; bh=wJQB3Xwbb3brOH65MuUuYdVulAsCToeuEBz+zJ4dqE8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=n0T6THj0fh/ry6DAPxO71TQs2XAhaAXfcMgNedeLzu9H1187jFeiAMoJ3tCTXZIzG1Vuto9lFIMmUTZr9WEZhc2OH9qi9dsIwPF5d8b4FEZ9FdA1IS0Xvg8C/jf6nTJDxSeK59e93L9dzMHLsZSyxXFiTzTRNoDRIsSehQSSA7U= 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=eghb0Gfe; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=EIUT2dHe; arc=none smtp.client-ip=103.168.172.154 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="eghb0Gfe"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="EIUT2dHe" Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfhigh.phl.internal (Postfix) with ESMTP id 70AFC11400D8; Fri, 7 Feb 2025 06:52:16 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Fri, 07 Feb 2025 06:52:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding: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=fm3; t=1738929136; x=1739015536; bh=xolPDAwbMxvxkjDgj336+/U2TWPKlfYMJZsI25zUOS8=; b= eghb0GfeFTyHas1pdIFFu1PFAQsr0f62mgVWhwyI+arZvyrrMRWdnPWNZ60msrI2 j4VrTvmJmtsO2bSBXBiuicPVnfrSlXZl6UVZu1+uboCHFb7dOHfmIk/NHf67xdqG /AfX1c8Wcxb62nWVO2Gf7JHt3Pt9OX0O7EkTa42kMkoFQum/hTwi4vWibNYzQTGI HrwrPGB8vdAs7rhs8nLmUMnOlsFs2EtHnXMEL41KJWxgn6MtJSiM6FLxj1j1kH3O JNx4EEF8f0oW5GN2Fs7cVWl/T+8gusSrbdiTTAbQAmolo1dgeRfPFdkyezvJJt9v sybsRBx7CY94xAqM6gG1fQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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-sender:x-me-sender:x-sasl-enc; s=fm3; t=1738929136; x= 1739015536; bh=xolPDAwbMxvxkjDgj336+/U2TWPKlfYMJZsI25zUOS8=; b=E IUT2dHeWRZDAmOrdXeA+IMoDRXkPBgN5yy1DOtQrDCUnGNlfvQi4m2BTHiExh+LN GVeXsJdacFwbJFe5nT6M7aK/0wIKI01XUhsgdsxU6mMh6ixvFgDEotwADSXpolU/ it5uboPeepnsUL+dVcM4t3YUDTQe+FrkvwVrIM+YKAofX+TJ/j+MjGBUNFbLXzb9 UlRjl1nGTbwgSbbcTMV0piaJ/TABaZt/JXBi4wDN94Ii4GiJun9HsAj9kcq4xTsV AClI4no89nE1yej/HKNRFpt+8oUtNZnTnpbVGnfEq0JObNfpHozmPFHrWRlC6aKI IlavHpA3CwZClDvl35DJA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvledvudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredt jeenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrd himheqnecuggftrfgrthhtvghrnhepffeuiedujedvkeehuedvkeefffeivdeuleetkedu heejteekgedvudfgtdfgieelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepjheitheskhgusghgrdhorhhgpdhrtghpthhtoh epvghthhhomhhsohhnsegvugifrghrughthhhomhhsohhnrdgtohhmpdhrtghpthhtohep jhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtghpthhtohepghhithhsthgvrhesph hosghogidrtghomhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Feb 2025 06:52:15 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 9caa1253 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 7 Feb 2025 11:52:13 +0000 (UTC) From: Patrick Steinhardt Date: Fri, 07 Feb 2025 12:52:08 +0100 Subject: [PATCH v5 13/18] reftable/basics: stop using `SWAP()` macro Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250207-pks-reftable-drop-git-compat-util-v5-13-ba2adc79110f@pks.im> References: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> In-Reply-To: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> To: git@vger.kernel.org Cc: Edward Thomson , Justin Tobler , Junio C Hamano , Johannes Sixt X-Mailer: b4 0.14.2 Stop using `SWAP()` macro in favor of an open-coded variant of it. Note that this also requires us to open-code the build assert that `SWAP()` itself uses to verify that the size of both variables matches. This is done to reduce our dependency on the Git codebase. Signed-off-by: Patrick Steinhardt --- reftable/basics.h | 9 +++++++++ reftable/merged.c | 2 +- reftable/pq.c | 4 ++-- reftable/record.c | 16 ++++++++-------- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/reftable/basics.h b/reftable/basics.h index c1ddbaec3f..59000798f0 100644 --- a/reftable/basics.h +++ b/reftable/basics.h @@ -266,6 +266,15 @@ static inline void *reftable_alloc_grow(void *p, size_t nelem, size_t elsize, # define strdup(str) REFTABLE_BANNED(strdup) #endif +#define REFTABLE_SWAP(a, b) do { \ + void *_swap_a_ptr = &(a); \ + void *_swap_b_ptr = &(b); \ + unsigned char _swap_buffer[sizeof(a) - 2 * sizeof(a) * (sizeof(a) != sizeof(b))]; \ + memcpy(_swap_buffer, _swap_a_ptr, sizeof(a)); \ + memcpy(_swap_a_ptr, _swap_b_ptr, sizeof(a)); \ + memcpy(_swap_b_ptr, _swap_buffer, sizeof(a)); \ +} while (0) + /* Find the longest shared prefix size of `a` and `b` */ size_t common_prefix_size(struct reftable_buf *a, struct reftable_buf *b); diff --git a/reftable/merged.c b/reftable/merged.c index 563864068c..4ff1553772 100644 --- a/reftable/merged.c +++ b/reftable/merged.c @@ -155,7 +155,7 @@ static int merged_iter_next_entry(struct merged_iter *mi, } mi->advance_index = entry.index; - SWAP(*rec, *entry.rec); + REFTABLE_SWAP(*rec, *entry.rec); return 0; } diff --git a/reftable/pq.c b/reftable/pq.c index ef8035cfd9..82394a972d 100644 --- a/reftable/pq.c +++ b/reftable/pq.c @@ -57,7 +57,7 @@ int merged_iter_pqueue_remove(struct merged_iter_pqueue *pq, struct pq_entry *ou if (min == i) break; - SWAP(pq->heap[i], pq->heap[min]); + REFTABLE_SWAP(pq->heap[i], pq->heap[min]); i = min; } @@ -81,7 +81,7 @@ int merged_iter_pqueue_add(struct merged_iter_pqueue *pq, const struct pq_entry size_t j = (i - 1) / 2; if (pq_less(&pq->heap[j], &pq->heap[i])) break; - SWAP(pq->heap[j], pq->heap[i]); + REFTABLE_SWAP(pq->heap[j], pq->heap[i]); i = j; } diff --git a/reftable/record.c b/reftable/record.c index 3552bafa99..9a1edf39a0 100644 --- a/reftable/record.c +++ b/reftable/record.c @@ -237,11 +237,11 @@ static int reftable_ref_record_copy_from(void *rec, const void *src_rec, size_t refname_cap = 0; int err; - SWAP(refname, ref->refname); - SWAP(refname_cap, ref->refname_cap); + REFTABLE_SWAP(refname, ref->refname); + REFTABLE_SWAP(refname_cap, ref->refname_cap); reftable_ref_record_release(ref); - SWAP(ref->refname, refname); - SWAP(ref->refname_cap, refname_cap); + REFTABLE_SWAP(ref->refname, refname); + REFTABLE_SWAP(ref->refname_cap, refname_cap); if (src->refname) { size_t refname_len = strlen(src->refname); @@ -376,11 +376,11 @@ static int reftable_ref_record_decode(void *rec, struct reftable_buf key, return n; string_view_consume(&in, n); - SWAP(refname, r->refname); - SWAP(refname_cap, r->refname_cap); + REFTABLE_SWAP(refname, r->refname); + REFTABLE_SWAP(refname_cap, r->refname_cap); reftable_ref_record_release(r); - SWAP(r->refname, refname); - SWAP(r->refname_cap, refname_cap); + REFTABLE_SWAP(r->refname, refname); + REFTABLE_SWAP(r->refname_cap, refname_cap); REFTABLE_ALLOC_GROW_OR_NULL(r->refname, key.len + 1, r->refname_cap); if (!r->refname) { From patchwork Fri Feb 7 11:52:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13964885 Received: from fhigh-a3-smtp.messagingengine.com (fhigh-a3-smtp.messagingengine.com [103.168.172.154]) (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 016CB1E04AE for ; Fri, 7 Feb 2025 11:52:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929139; cv=none; b=Msrid6cX9jNaKXDK6qvzbKot8wxYefJmnnUDbD2GNa+z28EVI0nNaxg/+2Bjut5I9T9bi3RizzH31ojDcXyP9trCAsaE0Cur4aRqRSPlha+/WqT/MhRXot1uSY9jFemOCUaxeqR6ASV23ouSkgzQoxrZrPbkrDtXYu/ZUcYG+9U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929139; c=relaxed/simple; bh=U2Vhsoxu1LFLXCm8YsuXM7KkoMNbAV29TjYndfPvVAM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=txMQ4U3Pe2fJjmpUqlqrUAg5adKfjEHR42COBN76oV2GgmivoDtF8HwkaplXBogHCizk7UsQmpWRkfIvDHfoqwZJa5zk2LqR4EAJU42J3msmDrcBLTpLiB8wce/Q0MNIsLd0IIzSjXsMip9Js89meKvmxM3tVdFd4HIzStlYvNk= 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=GikCAkq6; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=a8nKzJmn; arc=none smtp.client-ip=103.168.172.154 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="GikCAkq6"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="a8nKzJmn" Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfhigh.phl.internal (Postfix) with ESMTP id 23FE711400F8; Fri, 7 Feb 2025 06:52:17 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Fri, 07 Feb 2025 06:52:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding: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=fm3; t=1738929137; x=1739015537; bh=xKjvrxGaBaDgi1/zS8y2h9vrnaEd4qCZUC/EGlL5EBc=; b= GikCAkq6KwHMxCaVoWL75M2IucjCQ18LHK0gHF+LxxycF8uw6xwiradCPEl+wMt6 Bn09kqmG6U+PHFtECLltPjr67etFeDJjPSjYiENb3UaGyfRLGn3hEvmYODjTgfbk fnMmBnDNb6P2FI3GWurxTZgk6K049WsFTS3fuOo0uKXHoDU8/jMsmpyidtJSOVd7 yqdSprmPS/hHxPWaNt2EmD/TOiL3nVx2EbeXLncR1NQAAJPwSuhI4+hqhZalZKUJ TJwuyg7KvCjktun9Dvg3wA66X3p33c75MeW0KpXfxSie3nxLXX9lzoMqQBp/rx1d ZI9+b5rdMzc26FRzUEzIgA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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-sender:x-me-sender:x-sasl-enc; s=fm3; t=1738929137; x= 1739015537; bh=xKjvrxGaBaDgi1/zS8y2h9vrnaEd4qCZUC/EGlL5EBc=; b=a 8nKzJmnUvfQ1sKMYp6Wq67pyxt825Xqtm0sJeTnTsv80mq+p9ybzNEc3IfepWnNs uJBGrnBQBLY2M82xd829MxBOFLaN+ogPAN4owYP5gZn7ejvP7TaEmIjH3NmcDybt HsNxdZ+vOhz2p4tDabdRLaErDjUWi7BrnpyruHRmjXP37B7p+PRR7h29SCTLlAeJ bCFPNAv0LMkDGI2509g5A6X49FfzjtX9ab43JPctuh0f22W6+Pkeu/uIkiywQB/8 5kCby4+xxLeBc5zIcuV8F6FCnQKWzdcuojlsJm5JHpEIKKAv3kYKzsaQ6gzjmMpB Q4g1QcWDqzwox+r4Wslyw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvledvtdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredt jeenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrd himheqnecuggftrfgrthhtvghrnhepffeuiedujedvkeehuedvkeefffeivdeuleetkedu heejteekgedvudfgtdfgieelnecuvehluhhsthgvrhfuihiivgepheenucfrrghrrghmpe hmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepiedpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepvghthhhomhhsohhnsegvugifrghrughthhhomh hsohhnrdgtohhmpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhr tghpthhtohepjheitheskhgusghgrdhorhhgpdhrtghpthhtohepghhithesvhhgvghrrd hkvghrnhgvlhdrohhrghdprhgtphhtthhopehgihhtshhtvghrsehpohgsohigrdgtohhm pdhrtghpthhtohepthhoohhnsehiohhttghlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Feb 2025 06:52:15 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 0689193d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 7 Feb 2025 11:52:13 +0000 (UTC) From: Patrick Steinhardt Date: Fri, 07 Feb 2025 12:52:09 +0100 Subject: [PATCH v5 14/18] reftable/basics: introduce `REFTABLE_UNUSED` annotation Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250207-pks-reftable-drop-git-compat-util-v5-14-ba2adc79110f@pks.im> References: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> In-Reply-To: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> To: git@vger.kernel.org Cc: Edward Thomson , Justin Tobler , Junio C Hamano , Johannes Sixt , Toon Claes X-Mailer: b4 0.14.2 Introduce the `REFTABLE_UNUSED` annotation and replace all existing users of `UNUSED` in the reftable library to use the new macro instead. Note that we unconditionally define `MAYBE_UNUSED` in the exact same way, so doing so unconditionally for `REFTABLE_UNUSED` should be fine, too. Suggested-by: Toon Claes Signed-off-by: Patrick Steinhardt --- reftable/basics.h | 2 ++ reftable/blocksource.c | 6 +++--- reftable/iter.c | 10 +++++----- reftable/record.c | 26 +++++++++++++------------- reftable/writer.c | 2 +- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/reftable/basics.h b/reftable/basics.h index 59000798f0..fd59cbb772 100644 --- a/reftable/basics.h +++ b/reftable/basics.h @@ -16,6 +16,8 @@ license that can be found in the LICENSE file or at #include "system.h" #include "reftable-basics.h" +#define REFTABLE_UNUSED __attribute__((__unused__)) + struct reftable_buf { size_t alloc; size_t len; diff --git a/reftable/blocksource.c b/reftable/blocksource.c index 02972c46f4..78c1be2337 100644 --- a/reftable/blocksource.c +++ b/reftable/blocksource.c @@ -13,14 +13,14 @@ license that can be found in the LICENSE file or at #include "reftable-blocksource.h" #include "reftable-error.h" -static void reftable_buf_return_block(void *b UNUSED, struct reftable_block *dest) +static void reftable_buf_return_block(void *b REFTABLE_UNUSED, struct reftable_block *dest) { if (dest->len) memset(dest->data, 0xff, dest->len); reftable_free(dest->data); } -static void reftable_buf_close(void *b UNUSED) +static void reftable_buf_close(void *b REFTABLE_UNUSED) { } @@ -67,7 +67,7 @@ static uint64_t file_size(void *b) return ((struct file_block_source *)b)->size; } -static void file_return_block(void *b UNUSED, struct reftable_block *dest UNUSED) +static void file_return_block(void *b REFTABLE_UNUSED, struct reftable_block *dest REFTABLE_UNUSED) { } diff --git a/reftable/iter.c b/reftable/iter.c index b2ffb09c16..f520382e70 100644 --- a/reftable/iter.c +++ b/reftable/iter.c @@ -25,17 +25,17 @@ int iterator_next(struct reftable_iterator *it, struct reftable_record *rec) return it->ops->next(it->iter_arg, rec); } -static int empty_iterator_seek(void *arg UNUSED, struct reftable_record *want UNUSED) +static int empty_iterator_seek(void *arg REFTABLE_UNUSED, struct reftable_record *want REFTABLE_UNUSED) { return 0; } -static int empty_iterator_next(void *arg UNUSED, struct reftable_record *rec UNUSED) +static int empty_iterator_next(void *arg REFTABLE_UNUSED, struct reftable_record *rec REFTABLE_UNUSED) { return 1; } -static void empty_iterator_close(void *arg UNUSED) +static void empty_iterator_close(void *arg REFTABLE_UNUSED) { } @@ -143,8 +143,8 @@ static int indexed_table_ref_iter_next_block(struct indexed_table_ref_iter *it) return 0; } -static int indexed_table_ref_iter_seek(void *p UNUSED, - struct reftable_record *want UNUSED) +static int indexed_table_ref_iter_seek(void *p REFTABLE_UNUSED, + struct reftable_record *want REFTABLE_UNUSED) { return REFTABLE_API_ERROR; } diff --git a/reftable/record.c b/reftable/record.c index 9a1edf39a0..142853d507 100644 --- a/reftable/record.c +++ b/reftable/record.c @@ -490,7 +490,7 @@ static void reftable_obj_record_release(void *rec) } static int reftable_obj_record_copy_from(void *rec, const void *src_rec, - uint32_t hash_size UNUSED) + uint32_t hash_size REFTABLE_UNUSED) { struct reftable_obj_record *obj = rec; const struct reftable_obj_record *src = src_rec; @@ -528,7 +528,7 @@ static uint8_t reftable_obj_record_val_type(const void *rec) } static int reftable_obj_record_encode(const void *rec, struct string_view s, - uint32_t hash_size UNUSED) + uint32_t hash_size REFTABLE_UNUSED) { const struct reftable_obj_record *r = rec; struct string_view start = s; @@ -563,8 +563,8 @@ static int reftable_obj_record_encode(const void *rec, struct string_view s, static int reftable_obj_record_decode(void *rec, struct reftable_buf key, uint8_t val_type, struct string_view in, - uint32_t hash_size UNUSED, - struct reftable_buf *scratch UNUSED) + uint32_t hash_size REFTABLE_UNUSED, + struct reftable_buf *scratch REFTABLE_UNUSED) { struct string_view start = in; struct reftable_obj_record *r = rec; @@ -618,13 +618,13 @@ static int reftable_obj_record_decode(void *rec, struct reftable_buf key, return start.len - in.len; } -static int not_a_deletion(const void *p UNUSED) +static int not_a_deletion(const void *p REFTABLE_UNUSED) { return 0; } static int reftable_obj_record_equal_void(const void *a, const void *b, - uint32_t hash_size UNUSED) + uint32_t hash_size REFTABLE_UNUSED) { struct reftable_obj_record *ra = (struct reftable_obj_record *) a; struct reftable_obj_record *rb = (struct reftable_obj_record *) b; @@ -1054,7 +1054,7 @@ static int reftable_index_record_key(const void *r, struct reftable_buf *dest) } static int reftable_index_record_copy_from(void *rec, const void *src_rec, - uint32_t hash_size UNUSED) + uint32_t hash_size REFTABLE_UNUSED) { struct reftable_index_record *dst = rec; const struct reftable_index_record *src = src_rec; @@ -1075,13 +1075,13 @@ static void reftable_index_record_release(void *rec) reftable_buf_release(&idx->last_key); } -static uint8_t reftable_index_record_val_type(const void *rec UNUSED) +static uint8_t reftable_index_record_val_type(const void *rec REFTABLE_UNUSED) { return 0; } static int reftable_index_record_encode(const void *rec, struct string_view out, - uint32_t hash_size UNUSED) + uint32_t hash_size REFTABLE_UNUSED) { const struct reftable_index_record *r = (const struct reftable_index_record *)rec; @@ -1097,10 +1097,10 @@ static int reftable_index_record_encode(const void *rec, struct string_view out, } static int reftable_index_record_decode(void *rec, struct reftable_buf key, - uint8_t val_type UNUSED, + uint8_t val_type REFTABLE_UNUSED, struct string_view in, - uint32_t hash_size UNUSED, - struct reftable_buf *scratch UNUSED) + uint32_t hash_size REFTABLE_UNUSED, + struct reftable_buf *scratch REFTABLE_UNUSED) { struct string_view start = in; struct reftable_index_record *r = rec; @@ -1120,7 +1120,7 @@ static int reftable_index_record_decode(void *rec, struct reftable_buf key, } static int reftable_index_record_equal(const void *a, const void *b, - uint32_t hash_size UNUSED) + uint32_t hash_size REFTABLE_UNUSED) { struct reftable_index_record *ia = (struct reftable_index_record *) a; struct reftable_index_record *ib = (struct reftable_index_record *) b; diff --git a/reftable/writer.c b/reftable/writer.c index 5961698311..bb00e89f53 100644 --- a/reftable/writer.c +++ b/reftable/writer.c @@ -636,7 +636,7 @@ static void write_object_record(void *void_arg, void *key) done:; } -static void object_record_free(void *void_arg UNUSED, void *key) +static void object_record_free(void *void_arg REFTABLE_UNUSED, void *key) { struct obj_index_tree_node *entry = key; From patchwork Fri Feb 7 11:52:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13964887 Received: from fout-a8-smtp.messagingengine.com (fout-a8-smtp.messagingengine.com [103.168.172.151]) (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 4DEF11E0DE5 for ; Fri, 7 Feb 2025 11:52:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929140; cv=none; b=QfHZMWWUZvsFguRRIr2bA2Xbt7HKcXGboB3eZuy0MnzRTCvyG6PUfMMJUWM87anoLwqOezsfR7bozMrPUVu0m9ZdcYe+Ty+hHQh5qIC5BR5aD688E7K1y7qSA67282MSwWy7rcnK1egkmscHYCZxdoXekl/FM3fSSCMQeieZ6iQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929140; c=relaxed/simple; bh=QBN6QdjvJkhCYXL4zX2vgsfcRkQiSHaM/D1GXD8I6yE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QFlDD60LG21Ktbjw//99D5S7AWmycte/Iy2nENkmoMidFvo/6glVdhjiIJLaS80Jn2hMMLNLzrzEb05n1gi693728PBAaIzHIhfc83ycKCxnTg9+Quus396roNC1T/Gf+J29KgvlfTYz/StIt1uzIfPLFEvlK933LQ69NLsCBoc= 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=ASFm0DRi; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Wugo88AJ; arc=none smtp.client-ip=103.168.172.151 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="ASFm0DRi"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Wugo88AJ" Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfout.phl.internal (Postfix) with ESMTP id A61E213801B4; Fri, 7 Feb 2025 06:52:17 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-09.internal (MEProxy); Fri, 07 Feb 2025 06:52:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding: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=fm3; t=1738929137; x=1739015537; bh=O66LlVZtMgZxHJqMJE4mlcQbyP2PMFzhH/4tLppxD0s=; b= ASFm0DRiPsX9YXXxzn8k2HthkGC0m/9Md8343cCLQzXEEyfMi+H8byZezUHWbkVu dJvz42XvVrR0DbYc+bggXp9D5SWPms2HEDfOMBKrsHfJXlJ9lGoU640elc3H9EIn SkOuc58TwPcIeqh2ZGwl3N3gRcNyfFwFrZU6DAE6qOOW7V+CX2WVZykvuc+bQM4+ GBDjCSwB6PDz+ndUTP1SY3Dm8XzPytMDXAqRLTdcll25I+qZhflvI87PWlUDME// EENRi84nK7uYV5WGNODomZi4v3hSNfu5uS3qzI/AH7CPPVLI3ccKa2XlC5KilrwV E1bvd7VNicWJQYzS+bgYhg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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-sender:x-me-sender:x-sasl-enc; s=fm3; t=1738929137; x= 1739015537; bh=O66LlVZtMgZxHJqMJE4mlcQbyP2PMFzhH/4tLppxD0s=; b=W ugo88AJdo3HHEMILpvVNN0r3+k+LJGSMTEiLScRxBzpB3YRDkjL0AgxrtHeLWYxG rBZURboCLT10aSKykMXOL8J2T1tSEsvtBn8pZASsaw96389B6A8rB1y2+Q2sEMuO 3HYoJUNCgzpmcQtdPmrwcUJBNdhWYMqWULiCSuNNw139Ss6uk0TRnQdO0pfa8HRS rh2Lhc/nnBBXuLlvSRINuAsW+bQiqtkUtbxk8cNQiulMr58FUO+CbQwS7ClbocxH G+fZbIFRleHI9iSYeHJ1+hZ0b2HsqrCCQ18v2T07cH/SgqU2JTiHkO6IXPZWsRbu FU3ar8zXuxx7cTq6+yIrg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvledvudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredt jeenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrd himheqnecuggftrfgrthhtvghrnhepffeuiedujedvkeehuedvkeefffeivdeuleetkedu heejteekgedvudfgtdfgieelnecuvehluhhsthgvrhfuihiivgepheenucfrrghrrghmpe hmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh dprhgtphhtthhopehjlhhtohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopegv thhhohhmshhonhesvggufigrrhguthhhohhmshhonhdrtghomhdprhgtphhtthhopehgih htshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtohepjheitheskhgusghgrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Feb 2025 06:52:16 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 1ef53191 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 7 Feb 2025 11:52:14 +0000 (UTC) From: Patrick Steinhardt Date: Fri, 07 Feb 2025 12:52:10 +0100 Subject: [PATCH v5 15/18] compat/mingw: split out POSIX-related bits Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250207-pks-reftable-drop-git-compat-util-v5-15-ba2adc79110f@pks.im> References: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> In-Reply-To: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> To: git@vger.kernel.org Cc: Edward Thomson , Justin Tobler , Junio C Hamano , Johannes Sixt X-Mailer: b4 0.14.2 Split out the POSIX-related bits from "compat/mingw.h". This is in preparation for splitting up "git-compat-utils.h" into a header that provides POSIX-compatibility and a header that provides common wrappers used by the Git project. Signed-off-by: Patrick Steinhardt --- compat/{mingw.c => mingw/compat-util.c} | 28 ++-- compat/mingw/compat-util.h | 220 ++++++++++++++++++++++++++++++++ compat/{mingw.h => mingw/posix.h} | 216 +------------------------------ compat/msvc.c | 6 - compat/msvc/compat-util.c | 6 + compat/msvc/compat-util.h | 7 + compat/{msvc.h => msvc/posix.h} | 8 +- config.mak.uname | 6 +- contrib/buildsystems/CMakeLists.txt | 2 +- git-compat-util.h | 4 +- meson.build | 8 +- 11 files changed, 266 insertions(+), 245 deletions(-) diff --git a/compat/mingw.c b/compat/mingw/compat-util.c similarity index 99% rename from compat/mingw.c rename to compat/mingw/compat-util.c index 1d5b211b54..aeb569bcea 100644 --- a/compat/mingw.c +++ b/compat/mingw/compat-util.c @@ -1,24 +1,24 @@ #define USE_THE_REPOSITORY_VARIABLE #define DISABLE_SIGN_COMPARE_WARNINGS -#include "../git-compat-util.h" -#include "win32.h" +#include "../../git-compat-util.h" +#include "../win32.h" #include #include #include #include -#include "../strbuf.h" -#include "../run-command.h" -#include "../abspath.h" -#include "../alloc.h" -#include "win32/lazyload.h" -#include "../config.h" -#include "../environment.h" -#include "../trace2.h" -#include "../symlinks.h" -#include "../wrapper.h" -#include "dir.h" -#include "gettext.h" +#include "../../strbuf.h" +#include "../../run-command.h" +#include "../../abspath.h" +#include "../../alloc.h" +#include "../win32/lazyload.h" +#include "../../config.h" +#include "../../environment.h" +#include "../../trace2.h" +#include "../../symlinks.h" +#include "../../wrapper.h" +#include "../../dir.h" +#include "../../gettext.h" #define SECURITY_WIN32 #include diff --git a/compat/mingw/compat-util.h b/compat/mingw/compat-util.h new file mode 100644 index 0000000000..470542d309 --- /dev/null +++ b/compat/mingw/compat-util.h @@ -0,0 +1,220 @@ +#ifndef COMPAT_MINGW_COMPAT_UTIL_H +#define COMPAT_MINGW_COMPAT_UTIL_H + +#include "posix.h" + +struct config_context; +int mingw_core_config(const char *var, const char *value, + const struct config_context *ctx, void *cb); +#define platform_core_config mingw_core_config + +#ifndef NO_OPENSSL +#include +static inline int mingw_SSL_set_fd(SSL *ssl, int fd) +{ + return SSL_set_fd(ssl, _get_osfhandle(fd)); +} +#define SSL_set_fd mingw_SSL_set_fd + +static inline int mingw_SSL_set_rfd(SSL *ssl, int fd) +{ + return SSL_set_rfd(ssl, _get_osfhandle(fd)); +} +#define SSL_set_rfd mingw_SSL_set_rfd + +static inline int mingw_SSL_set_wfd(SSL *ssl, int fd) +{ + return SSL_set_wfd(ssl, _get_osfhandle(fd)); +} +#define SSL_set_wfd mingw_SSL_set_wfd +#endif + +/* + * git specific compatibility + */ + +static inline void convert_slashes(char *path) +{ + for (; *path; path++) + if (*path == '\\') + *path = '/'; +} +#define PATH_SEP ';' +char *mingw_query_user_email(void); +#define query_user_email mingw_query_user_email + +/** + * Verifies that the specified path is owned by the user running the + * current process. + */ +int is_path_owned_by_current_sid(const char *path, struct strbuf *report); +#define is_path_owned_by_current_user is_path_owned_by_current_sid + +/** + * Verifies that the given path is a valid one on Windows. + * + * In particular, path segments are disallowed which + * + * - end in a period or a space (except the special directories `.` and `..`). + * + * - contain any of the reserved characters, e.g. `:`, `;`, `*`, etc + * + * - correspond to reserved names (such as `AUX`, `PRN`, etc) + * + * The `allow_literal_nul` parameter controls whether the path `NUL` should + * be considered valid (this makes sense e.g. before opening files, as it is + * perfectly legitimate to open `NUL` on Windows, just as it is to open + * `/dev/null` on Unix/Linux). + * + * Returns 1 upon success, otherwise 0. + */ +int is_valid_win32_path(const char *path, int allow_literal_nul); +#define is_valid_path(path) is_valid_win32_path(path, 0) + +/** + * Converts UTF-8 encoded string to UTF-16LE. + * + * To support repositories with legacy-encoded file names, invalid UTF-8 bytes + * 0xa0 - 0xff are converted to corresponding printable Unicode chars \u00a0 - + * \u00ff, and invalid UTF-8 bytes 0x80 - 0x9f (which would make non-printable + * Unicode) are converted to hex-code. + * + * Lead-bytes not followed by an appropriate number of trail-bytes, over-long + * encodings and 4-byte encodings > \u10ffff are detected as invalid UTF-8. + * + * Maximum space requirement for the target buffer is two wide chars per UTF-8 + * char (((strlen(utf) * 2) + 1) [* sizeof(wchar_t)]). + * + * The maximum space is needed only if the entire input string consists of + * invalid UTF-8 bytes in range 0x80-0x9f, as per the following table: + * + * | | UTF-8 | UTF-16 | + * Code point | UTF-8 sequence | bytes | words | ratio + * --------------+-------------------+-------+--------+------- + * 000000-00007f | 0-7f | 1 | 1 | 1 + * 000080-0007ff | c2-df + 80-bf | 2 | 1 | 0.5 + * 000800-00ffff | e0-ef + 2 * 80-bf | 3 | 1 | 0.33 + * 010000-10ffff | f0-f4 + 3 * 80-bf | 4 | 2 (a) | 0.5 + * invalid | 80-9f | 1 | 2 (b) | 2 + * invalid | a0-ff | 1 | 1 | 1 + * + * (a) encoded as UTF-16 surrogate pair + * (b) encoded as two hex digits + * + * Note that, while the UTF-8 encoding scheme can be extended to 5-byte, 6-byte + * or even indefinite-byte sequences, the largest valid code point \u10ffff + * encodes as only 4 UTF-8 bytes. + * + * Parameters: + * wcs: wide char target buffer + * utf: string to convert + * wcslen: size of target buffer (in wchar_t's) + * utflen: size of string to convert, or -1 if 0-terminated + * + * Returns: + * length of converted string (_wcslen(wcs)), or -1 on failure + * + * Errors: + * EINVAL: one of the input parameters is invalid (e.g. NULL) + * ERANGE: the output buffer is too small + */ +int xutftowcsn(wchar_t *wcs, const char *utf, size_t wcslen, int utflen); + +/** + * Simplified variant of xutftowcsn, assumes input string is \0-terminated. + */ +static inline int xutftowcs(wchar_t *wcs, const char *utf, size_t wcslen) +{ + return xutftowcsn(wcs, utf, wcslen, -1); +} + +/** + * Simplified file system specific variant of xutftowcsn, assumes output + * buffer size is MAX_PATH wide chars and input string is \0-terminated, + * fails with ENAMETOOLONG if input string is too long. + */ +static inline int xutftowcs_path(wchar_t *wcs, const char *utf) +{ + int result = xutftowcsn(wcs, utf, MAX_PATH, -1); + if (result < 0 && errno == ERANGE) + errno = ENAMETOOLONG; + return result; +} + +/** + * Converts UTF-16LE encoded string to UTF-8. + * + * Maximum space requirement for the target buffer is three UTF-8 chars per + * wide char ((_wcslen(wcs) * 3) + 1). + * + * The maximum space is needed only if the entire input string consists of + * UTF-16 words in range 0x0800-0xd7ff or 0xe000-0xffff (i.e. \u0800-\uffff + * modulo surrogate pairs), as per the following table: + * + * | | UTF-16 | UTF-8 | + * Code point | UTF-16 sequence | words | bytes | ratio + * --------------+-----------------------+--------+-------+------- + * 000000-00007f | 0000-007f | 1 | 1 | 1 + * 000080-0007ff | 0080-07ff | 1 | 2 | 2 + * 000800-00ffff | 0800-d7ff / e000-ffff | 1 | 3 | 3 + * 010000-10ffff | d800-dbff + dc00-dfff | 2 | 4 | 2 + * + * Note that invalid code points > 10ffff cannot be represented in UTF-16. + * + * Parameters: + * utf: target buffer + * wcs: wide string to convert + * utflen: size of target buffer + * + * Returns: + * length of converted string, or -1 on failure + * + * Errors: + * EINVAL: one of the input parameters is invalid (e.g. NULL) + * ERANGE: the output buffer is too small + */ +int xwcstoutf(char *utf, const wchar_t *wcs, size_t utflen); + +/* + * A critical section used in the implementation of the spawn + * functions (mingw_spawnv[p]e()) and waitpid(). Initialised in + * the replacement main() macro below. + */ +extern CRITICAL_SECTION pinfo_cs; + +/* + * Git, like most portable C applications, implements a main() function. On + * Windows, this main() function would receive parameters encoded in the + * current locale, but Git for Windows would prefer UTF-8 encoded parameters. + * + * To make that happen, we still declare main() here, and then declare and + * implement wmain() (which is the Unicode variant of main()) and compile with + * -municode. This wmain() function reencodes the parameters from UTF-16 to + * UTF-8 format, sets up a couple of other things as required on Windows, and + * then hands off to the main() function. + */ +int wmain(int argc, const wchar_t **w_argv); +int main(int argc, const char **argv); + +/* + * For debugging: if a problem occurs, say, in a Git process that is spawned + * from another Git process which in turn is spawned from yet another Git + * process, it can be quite daunting to figure out what is going on. + * + * Call this function to open a new MinTTY (this assumes you are in Git for + * Windows' SDK) with a GDB that attaches to the current process right away. + */ +void open_in_gdb(void); + +/* + * Used by Pthread API implementation for Windows + */ +int err_win_to_posix(DWORD winerr); + +#ifndef NO_UNIX_SOCKETS +int mingw_have_unix_sockets(void); +#undef have_unix_sockets +#define have_unix_sockets mingw_have_unix_sockets +#endif + +#endif /* COMPAT_MINGW_COMPAT_UTIL_H */ diff --git a/compat/mingw.h b/compat/mingw/posix.h similarity index 59% rename from compat/mingw.h rename to compat/mingw/posix.h index ebfb8ba423..8dddfa818d 100644 --- a/compat/mingw.h +++ b/compat/mingw/posix.h @@ -1,3 +1,6 @@ +#ifndef COMPAT_MINGW_POSIX_H +#define COMPAT_MINGW_POSIX_H + #ifdef __MINGW64_VERSION_MAJOR #include #include @@ -11,11 +14,6 @@ typedef _sigset_t sigset_t; #undef _POSIX_THREAD_SAFE_FUNCTIONS #endif -struct config_context; -int mingw_core_config(const char *var, const char *value, - const struct config_context *ctx, void *cb); -#define platform_core_config mingw_core_config - /* * things that are not available in header files */ @@ -180,27 +178,6 @@ int mingw_kill(pid_t pid, int sig); #define locate_in_PATH mingw_locate_in_PATH char *mingw_locate_in_PATH(const char *cmd); -#ifndef NO_OPENSSL -#include -static inline int mingw_SSL_set_fd(SSL *ssl, int fd) -{ - return SSL_set_fd(ssl, _get_osfhandle(fd)); -} -#define SSL_set_fd mingw_SSL_set_fd - -static inline int mingw_SSL_set_rfd(SSL *ssl, int fd) -{ - return SSL_set_rfd(ssl, _get_osfhandle(fd)); -} -#define SSL_set_rfd mingw_SSL_set_rfd - -static inline int mingw_SSL_set_wfd(SSL *ssl, int fd) -{ - return SSL_set_wfd(ssl, _get_osfhandle(fd)); -} -#define SSL_set_wfd mingw_SSL_set_wfd -#endif - /* * implementations of missing functions */ @@ -444,19 +421,6 @@ int winansi_dup2(int oldfd, int newfd); void winansi_init(void); HANDLE winansi_get_osfhandle(int fd); -/* - * git specific compatibility - */ - -static inline void convert_slashes(char *path) -{ - for (; *path; path++) - if (*path == '\\') - *path = '/'; -} -#define PATH_SEP ';' -char *mingw_query_user_email(void); -#define query_user_email mingw_query_user_email #if !defined(__MINGW64_VERSION_MAJOR) && (!defined(_MSC_VER) || _MSC_VER < 1800) #define PRIuMAX "I64u" #define PRId64 "I64d" @@ -464,176 +428,4 @@ char *mingw_query_user_email(void); #include #endif -/** - * Verifies that the specified path is owned by the user running the - * current process. - */ -int is_path_owned_by_current_sid(const char *path, struct strbuf *report); -#define is_path_owned_by_current_user is_path_owned_by_current_sid - -/** - * Verifies that the given path is a valid one on Windows. - * - * In particular, path segments are disallowed which - * - * - end in a period or a space (except the special directories `.` and `..`). - * - * - contain any of the reserved characters, e.g. `:`, `;`, `*`, etc - * - * - correspond to reserved names (such as `AUX`, `PRN`, etc) - * - * The `allow_literal_nul` parameter controls whether the path `NUL` should - * be considered valid (this makes sense e.g. before opening files, as it is - * perfectly legitimate to open `NUL` on Windows, just as it is to open - * `/dev/null` on Unix/Linux). - * - * Returns 1 upon success, otherwise 0. - */ -int is_valid_win32_path(const char *path, int allow_literal_nul); -#define is_valid_path(path) is_valid_win32_path(path, 0) - -/** - * Converts UTF-8 encoded string to UTF-16LE. - * - * To support repositories with legacy-encoded file names, invalid UTF-8 bytes - * 0xa0 - 0xff are converted to corresponding printable Unicode chars \u00a0 - - * \u00ff, and invalid UTF-8 bytes 0x80 - 0x9f (which would make non-printable - * Unicode) are converted to hex-code. - * - * Lead-bytes not followed by an appropriate number of trail-bytes, over-long - * encodings and 4-byte encodings > \u10ffff are detected as invalid UTF-8. - * - * Maximum space requirement for the target buffer is two wide chars per UTF-8 - * char (((strlen(utf) * 2) + 1) [* sizeof(wchar_t)]). - * - * The maximum space is needed only if the entire input string consists of - * invalid UTF-8 bytes in range 0x80-0x9f, as per the following table: - * - * | | UTF-8 | UTF-16 | - * Code point | UTF-8 sequence | bytes | words | ratio - * --------------+-------------------+-------+--------+------- - * 000000-00007f | 0-7f | 1 | 1 | 1 - * 000080-0007ff | c2-df + 80-bf | 2 | 1 | 0.5 - * 000800-00ffff | e0-ef + 2 * 80-bf | 3 | 1 | 0.33 - * 010000-10ffff | f0-f4 + 3 * 80-bf | 4 | 2 (a) | 0.5 - * invalid | 80-9f | 1 | 2 (b) | 2 - * invalid | a0-ff | 1 | 1 | 1 - * - * (a) encoded as UTF-16 surrogate pair - * (b) encoded as two hex digits - * - * Note that, while the UTF-8 encoding scheme can be extended to 5-byte, 6-byte - * or even indefinite-byte sequences, the largest valid code point \u10ffff - * encodes as only 4 UTF-8 bytes. - * - * Parameters: - * wcs: wide char target buffer - * utf: string to convert - * wcslen: size of target buffer (in wchar_t's) - * utflen: size of string to convert, or -1 if 0-terminated - * - * Returns: - * length of converted string (_wcslen(wcs)), or -1 on failure - * - * Errors: - * EINVAL: one of the input parameters is invalid (e.g. NULL) - * ERANGE: the output buffer is too small - */ -int xutftowcsn(wchar_t *wcs, const char *utf, size_t wcslen, int utflen); - -/** - * Simplified variant of xutftowcsn, assumes input string is \0-terminated. - */ -static inline int xutftowcs(wchar_t *wcs, const char *utf, size_t wcslen) -{ - return xutftowcsn(wcs, utf, wcslen, -1); -} - -/** - * Simplified file system specific variant of xutftowcsn, assumes output - * buffer size is MAX_PATH wide chars and input string is \0-terminated, - * fails with ENAMETOOLONG if input string is too long. - */ -static inline int xutftowcs_path(wchar_t *wcs, const char *utf) -{ - int result = xutftowcsn(wcs, utf, MAX_PATH, -1); - if (result < 0 && errno == ERANGE) - errno = ENAMETOOLONG; - return result; -} - -/** - * Converts UTF-16LE encoded string to UTF-8. - * - * Maximum space requirement for the target buffer is three UTF-8 chars per - * wide char ((_wcslen(wcs) * 3) + 1). - * - * The maximum space is needed only if the entire input string consists of - * UTF-16 words in range 0x0800-0xd7ff or 0xe000-0xffff (i.e. \u0800-\uffff - * modulo surrogate pairs), as per the following table: - * - * | | UTF-16 | UTF-8 | - * Code point | UTF-16 sequence | words | bytes | ratio - * --------------+-----------------------+--------+-------+------- - * 000000-00007f | 0000-007f | 1 | 1 | 1 - * 000080-0007ff | 0080-07ff | 1 | 2 | 2 - * 000800-00ffff | 0800-d7ff / e000-ffff | 1 | 3 | 3 - * 010000-10ffff | d800-dbff + dc00-dfff | 2 | 4 | 2 - * - * Note that invalid code points > 10ffff cannot be represented in UTF-16. - * - * Parameters: - * utf: target buffer - * wcs: wide string to convert - * utflen: size of target buffer - * - * Returns: - * length of converted string, or -1 on failure - * - * Errors: - * EINVAL: one of the input parameters is invalid (e.g. NULL) - * ERANGE: the output buffer is too small - */ -int xwcstoutf(char *utf, const wchar_t *wcs, size_t utflen); - -/* - * A critical section used in the implementation of the spawn - * functions (mingw_spawnv[p]e()) and waitpid(). Initialised in - * the replacement main() macro below. - */ -extern CRITICAL_SECTION pinfo_cs; - -/* - * Git, like most portable C applications, implements a main() function. On - * Windows, this main() function would receive parameters encoded in the - * current locale, but Git for Windows would prefer UTF-8 encoded parameters. - * - * To make that happen, we still declare main() here, and then declare and - * implement wmain() (which is the Unicode variant of main()) and compile with - * -municode. This wmain() function reencodes the parameters from UTF-16 to - * UTF-8 format, sets up a couple of other things as required on Windows, and - * then hands off to the main() function. - */ -int wmain(int argc, const wchar_t **w_argv); -int main(int argc, const char **argv); - -/* - * For debugging: if a problem occurs, say, in a Git process that is spawned - * from another Git process which in turn is spawned from yet another Git - * process, it can be quite daunting to figure out what is going on. - * - * Call this function to open a new MinTTY (this assumes you are in Git for - * Windows' SDK) with a GDB that attaches to the current process right away. - */ -void open_in_gdb(void); - -/* - * Used by Pthread API implementation for Windows - */ -int err_win_to_posix(DWORD winerr); - -#ifndef NO_UNIX_SOCKETS -int mingw_have_unix_sockets(void); -#undef have_unix_sockets -#define have_unix_sockets mingw_have_unix_sockets -#endif +#endif /* COMPAT_MINGW_POSIX_H */ diff --git a/compat/msvc.c b/compat/msvc.c deleted file mode 100644 index 71843d7eef..0000000000 --- a/compat/msvc.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "../git-compat-util.h" -#include "win32.h" -#include -#include "../strbuf.h" - -#include "mingw.c" diff --git a/compat/msvc/compat-util.c b/compat/msvc/compat-util.c new file mode 100644 index 0000000000..b92e52b8b8 --- /dev/null +++ b/compat/msvc/compat-util.c @@ -0,0 +1,6 @@ +#include "../../git-compat-util.h" +#include "../win32.h" +#include +#include "../../strbuf.h" + +#include "../mingw/compat-util.c" diff --git a/compat/msvc/compat-util.h b/compat/msvc/compat-util.h new file mode 100644 index 0000000000..404af236b5 --- /dev/null +++ b/compat/msvc/compat-util.h @@ -0,0 +1,7 @@ +#ifndef COMPAT_MSVC_COMPAT_UTIL_H +#define COMPAT_MSVC_COMPAT_UTIL_H + +#include "posix.h" +#include "../mingw/compat-util.h" + +#endif /* COMPAT_MSVC_COMPAT_UTIL_H */ diff --git a/compat/msvc.h b/compat/msvc/posix.h similarity index 86% rename from compat/msvc.h rename to compat/msvc/posix.h index 1d7a8c6145..703a7c2067 100644 --- a/compat/msvc.h +++ b/compat/msvc/posix.h @@ -1,5 +1,5 @@ -#ifndef __MSVC__HEAD -#define __MSVC__HEAD +#ifndef COMPAT_MSVC_POSIX_H +#define COMPAT_MSVC_POSIX_H #include #include @@ -28,6 +28,6 @@ typedef int sigset_t; /* open for reading, writing, or both (not in fcntl.h) */ #define O_ACCMODE (_O_RDONLY | _O_WRONLY | _O_RDWR) -#include "compat/mingw.h" +#include "../mingw/posix.h" -#endif +#endif /* COMPAT_MSVC_POSIX_H */ diff --git a/config.mak.uname b/config.mak.uname index b12d4e168a..dbd05adb5d 100644 --- a/config.mak.uname +++ b/config.mak.uname @@ -495,7 +495,7 @@ endif AR = compat/vcbuild/scripts/lib.pl CFLAGS = BASIC_CFLAGS = -nologo -I. -Icompat/vcbuild/include -DWIN32 -D_CONSOLE -DHAVE_STRING_H -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE - COMPAT_OBJS = compat/msvc.o compat/winansi.o \ + COMPAT_OBJS = compat/msvc/compat-util.o compat/winansi.o \ compat/win32/flush.o \ compat/win32/path-utils.o \ compat/win32/pthread.o compat/win32/syslog.o \ @@ -541,7 +541,7 @@ endif EXTRA_PROGRAMS += headless-git$X -compat/msvc.o: compat/msvc.c compat/mingw.c GIT-CFLAGS +compat/msvc/compat-util.o: compat/msvc/compat-util.c compat/mingw/compat-util.c GIT-CFLAGS endif ifeq ($(uname_S),Interix) NO_INITGROUPS = YesPlease @@ -694,7 +694,7 @@ ifeq ($(uname_S),MINGW) BASIC_LDFLAGS += -municode COMPAT_CFLAGS += -DNOGDI -Icompat -Icompat/win32 COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\" - COMPAT_OBJS += compat/mingw.o compat/winansi.o \ + COMPAT_OBJS += compat/mingw/compat-util.o compat/winansi.o \ compat/win32/trace2_win32_process_info.o \ compat/win32/flush.o \ compat/win32/path-utils.o \ diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt index 10dc54fdcb..65ce8705f0 100644 --- a/contrib/buildsystems/CMakeLists.txt +++ b/contrib/buildsystems/CMakeLists.txt @@ -258,7 +258,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows") USE_NED_ALLOCATOR OVERRIDE_STRDUP MMAP_PREVENTS_DELETE USE_WIN32_MMAP HAVE_WPGMPTR ENSURE_MSYSTEM_IS_SET HAVE_RTLGENRANDOM) list(APPEND compat_SOURCES - compat/mingw.c + compat/mingw/compat-util.c compat/winansi.c compat/win32/flush.c compat/win32/path-utils.c diff --git a/git-compat-util.h b/git-compat-util.h index e283c46c6f..b96fb98e1e 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -304,10 +304,10 @@ static inline int is_xplatform_dir_sep(int c) #if defined(__MINGW32__) /* pull in Windows compatibility stuff */ #include "compat/win32/path-utils.h" -#include "compat/mingw.h" +#include "compat/mingw/compat-util.h" #elif defined(_MSC_VER) #include "compat/win32/path-utils.h" -#include "compat/msvc.h" +#include "compat/msvc/compat-util.h" #else #include #include diff --git a/meson.build b/meson.build index 2297f5e9dd..e8abf798f5 100644 --- a/meson.build +++ b/meson.build @@ -1054,7 +1054,6 @@ if host_machine.system() == 'cygwin' ] elif host_machine.system() == 'windows' libgit_sources += [ - 'compat/mingw.c', 'compat/winansi.c', 'compat/win32/flush.c', 'compat/win32/path-utils.c', @@ -1081,6 +1080,9 @@ elif host_machine.system() == 'windows' libgit_include_directories += 'compat/win32' if compiler.get_id() == 'msvc' libgit_include_directories += 'compat/vcbuild/include' + libgit_sources += 'compat/msvc/compat-util.c' + else + libgit_sources += 'compat/mingw/compat-util.c' endif endif @@ -1157,7 +1159,7 @@ else error('Native regex support requested but not found') endif -# setitimer and friends are provided by compat/mingw.c. +# setitimer and friends are provided by compat/mingw/compat-util.c. if host_machine.system() != 'windows' if not compiler.compiles(''' #include @@ -1237,7 +1239,7 @@ if not compiler.has_function('qsort') endif libgit_sources += 'compat/qsort_s.c' -# unsetenv is provided by compat/mingw.c. +# unsetenv is provided by compat/mingw/compat-util.c. if host_machine.system() != 'windows' and not compiler.has_function('unsetenv') libgit_c_args += '-DNO_UNSETENV' libgit_sources += 'compat/unsetenv.c' From patchwork Fri Feb 7 11:52:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13964888 Received: from fhigh-a3-smtp.messagingengine.com (fhigh-a3-smtp.messagingengine.com [103.168.172.154]) (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 C4DAA1E1A33 for ; Fri, 7 Feb 2025 11:52:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929141; cv=none; b=jicNpgwPXdCQN5rEWHoBdlwViyRE86mqTGEeSOOjPjcUjcqlsU8t+UxHh4B+WHeKqY2SlFfvqNyTmOkK1eyWEHBkbsIzNFHRS6WRkgD01YvrnQx5hIQLbg1mgF9lzRTcHAXGDUelofj1TjJiSEhtzvmZwcHJBNasVGo1iYeZs3k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929141; c=relaxed/simple; bh=a7yWLJap3M98CA80Dnu9G5FxSju0nYBa8EHc7c5jOeo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=s/+oEqdc6Ds5VA4r2UnImG9QqUkQuyIDRfObFdC4AO8AoSE9Ys+Wvc5eZHDbw7pgQkagwsAAmV5blPmIgjumwxulb9QRvP0dW2MIqAI1qG7q4bwXWEUo0Ys1nRkPKE5WOLOc5D1pOcnS1pDVy65Z14305xtZb5XdpaE6tunLnHE= 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=Qim4pLKK; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Uj07FRdz; arc=none smtp.client-ip=103.168.172.154 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="Qim4pLKK"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Uj07FRdz" Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfhigh.phl.internal (Postfix) with ESMTP id E017711400FB; Fri, 7 Feb 2025 06:52:17 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Fri, 07 Feb 2025 06:52:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding: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=fm3; t=1738929137; x=1739015537; bh=MuwjvRoWdYUm15bJL1fH9c2ftC3rU5JfU3J2+Fes43U=; b= Qim4pLKKX6zoEcVFT0wsdg4JZq+KsoQ7Ub7Ft9C96BSYfuWcY25kft4IRDWYnLaA ij8HMJrpxCd2QNDbTJF1M1LSQYSwojaxra/taY54aWgSRJ+H0e78RAG/rAWjeIZy bJKLTiQTdpbGBXghNBtlr5xXhDByfRjJsj1TtX9OMWmVuI/rW8MabAxCOtBRPIYI F6HvHR9ifIs3GhE3AClQtUOW1+3xixq0YwbiV7vjYZKQlarBHdpxBI/Px0+yfZhN HzTvdyxVMlJoPhSfZD06Vrah9kuOhw9ETfmk/zPba8mP6fU63A5rPxs/JLMwMyk2 GiPmzFnEtycnigL0bmgvZw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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-sender:x-me-sender:x-sasl-enc; s=fm3; t=1738929137; x= 1739015537; bh=MuwjvRoWdYUm15bJL1fH9c2ftC3rU5JfU3J2+Fes43U=; b=U j07FRdzjmayJvyfUz7MOqFI3+TMCnoiwH+9SvJTid4S/32A0AARl8m9SpMah3woC Hr8DPtqUTekpvSxvEfywsHFCvh+cdCjAp7G/YxBJvqW0itQgq7hg2qCxrn4axcZ0 U0j/DhPGl2qHQW/Lb8g2wXKNDYj0tp+bTFdkrGJDUr0gg8pG203CL1RRjgmimzy2 eSYSITy2fUP9Uk154jrJJ6XzcjMDUSVSPnCN9+DUIAiFxFuO5ezz61aALhpwVkut gVTy/VerBQvd2Zt4IYQoQ5RG9SHShZVyhXFIBMN3Ehsab2cKxUlBmVrFDEJSpnFn PTyZE6DIZplCewStOx71A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvledvtdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredt jeenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrd himheqnecuggftrfgrthhtvghrnhepffeuiedujedvkeehuedvkeefffeivdeuleetkedu heejteekgedvudfgtdfgieelnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpe hmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepvghthhhomhhsohhnsegvugifrghrughthhhomh hsohhnrdgtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdp rhgtphhtthhopehgihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtohepjheith eskhgusghgrdhorhhgpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Feb 2025 06:52:16 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 948c74f4 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 7 Feb 2025 11:52:15 +0000 (UTC) From: Patrick Steinhardt Date: Fri, 07 Feb 2025 12:52:11 +0100 Subject: [PATCH v5 16/18] git-compat-util.h: split out POSIX-emulating bits Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250207-pks-reftable-drop-git-compat-util-v5-16-ba2adc79110f@pks.im> References: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> In-Reply-To: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> To: git@vger.kernel.org Cc: Edward Thomson , Justin Tobler , Junio C Hamano , Johannes Sixt X-Mailer: b4 0.14.2 The "git-compat-util.h" header is a treasure trove of various bits and pieces used throughout the project. It basically mixes two different things into one: - Providing a POSIX-like interface even on platforms that aren't POSIX-compliant. - Providing low-level functionality that is specific to Git. This intermixing is a bit of a problem for the reftable library as we don't want to recreate the POSIX-like interface there. But neither do we want to pull in the Git-specific functionality, as it is otherwise quite easy to start depending on the Git codebase again. Split out a new header "compat/posix.h" that only contains the bits and pieces relevant for the emulation of POSIX, which we will start using in the next commit. Signed-off-by: Patrick Steinhardt --- compat/posix.h | 541 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ git-compat-util.h | 531 +---------------------------------------------------- 2 files changed, 543 insertions(+), 529 deletions(-) diff --git a/compat/posix.h b/compat/posix.h new file mode 100644 index 0000000000..7e6c4c1a1f --- /dev/null +++ b/compat/posix.h @@ -0,0 +1,541 @@ +#ifndef COMPAT_POSIX_H +#define COMPAT_POSIX_H + +#define _FILE_OFFSET_BITS 64 + +/* + * Derived from Linux "Features Test Macro" header + * Convenience macros to test the versions of gcc (or + * a compatible compiler). + * Use them like this: + * #if GIT_GNUC_PREREQ (2,8) + * ... code requiring gcc 2.8 or later ... + * #endif + * + * This macro of course is not part of POSIX, but we need it for the UNUSED + * macro which is used by some of our POSIX compatibility wrappers. +*/ +#if defined(__GNUC__) && defined(__GNUC_MINOR__) +# define GIT_GNUC_PREREQ(maj, min) \ + ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) +#else + #define GIT_GNUC_PREREQ(maj, min) 0 +#endif + +/* + * UNUSED marks a function parameter that is always unused. It also + * can be used to annotate a function, a variable, or a type that is + * always unused. + * + * A callback interface may dictate that a function accepts a + * parameter at that position, but the implementation of the function + * may not need to use the parameter. In such a case, mark the parameter + * with UNUSED. + * + * When a parameter may be used or unused, depending on conditional + * compilation, consider using MAYBE_UNUSED instead. + */ +#if GIT_GNUC_PREREQ(4, 5) +#define UNUSED __attribute__((unused)) \ + __attribute__((deprecated ("parameter declared as UNUSED"))) +#elif defined(__GNUC__) +#define UNUSED __attribute__((unused)) \ + __attribute__((deprecated)) +#else +#define UNUSED +#endif + +#ifdef __MINGW64__ +#define _POSIX_C_SOURCE 1 +#elif defined(__sun__) + /* + * On Solaris, when _XOPEN_EXTENDED is set, its header file + * forces the programs to be XPG4v2, defeating any _XOPEN_SOURCE + * setting to say we are XPG5 or XPG6. Also on Solaris, + * XPG6 programs must be compiled with a c99 compiler, while + * non XPG6 programs must be compiled with a pre-c99 compiler. + */ +# if __STDC_VERSION__ - 0 >= 199901L +# define _XOPEN_SOURCE 600 +# else +# define _XOPEN_SOURCE 500 +# endif +#elif !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__USLC__) && \ + !defined(_M_UNIX) && !defined(__sgi) && !defined(__DragonFly__) && \ + !defined(__TANDEM) && !defined(__QNX__) && !defined(__MirBSD__) && \ + !defined(__CYGWIN__) +#define _XOPEN_SOURCE 600 /* glibc2 and AIX 5.3L need 500, OpenBSD needs 600 for S_ISLNK() */ +#define _XOPEN_SOURCE_EXTENDED 1 /* AIX 5.3L needs this */ +#endif +#define _ALL_SOURCE 1 +#define _GNU_SOURCE 1 +#define _BSD_SOURCE 1 +#define _DEFAULT_SOURCE 1 +#define _NETBSD_SOURCE 1 +#define _SGI_SOURCE 1 + +#if defined(WIN32) && !defined(__CYGWIN__) /* Both MinGW and MSVC */ +# if !defined(_WIN32_WINNT) +# define _WIN32_WINNT 0x0600 +# endif +#define WIN32_LEAN_AND_MEAN /* stops windows.h including winsock.h */ +#include +#ifndef NO_UNIX_SOCKETS +#include +#endif +#include +#define GIT_WINDOWS_NATIVE +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef HAVE_STRINGS_H +#include /* for strcasecmp() */ +#endif +#include +#include +#include +#ifdef NEEDS_SYS_PARAM_H +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#if !defined(NO_POLL_H) +#include +#elif !defined(NO_SYS_POLL_H) +#include +#else +/* Pull the compat stuff */ +#include +#endif +#ifdef HAVE_BSD_SYSCTL +#include +#endif + +#if defined(__MINGW32__) +#include "mingw/posix.h" +#elif defined(_MSC_VER) +#include "msvc/posix.h" +#else +#include +#include +#include +#include +#include +#include +#include +#ifndef NO_SYS_SELECT_H +#include +#endif +#include +#include +#include +#include +#include +#include +#ifndef NO_INTTYPES_H +#include +#else +#include +#endif +#ifdef HAVE_ARC4RANDOM_LIBBSD +#include +#endif +#ifdef HAVE_GETRANDOM +#include +#endif +#ifdef NO_INTPTR_T +/* + * On I16LP32, ILP32 and LP64 "long" is the safe bet, however + * on LLP86, IL33LLP64 and P64 it needs to be "long long", + * while on IP16 and IP16L32 it is "int" (resp. "short") + * Size needs to match (or exceed) 'sizeof(void *)'. + * We can't take "long long" here as not everybody has it. + */ +typedef long intptr_t; +typedef unsigned long uintptr_t; +#endif +#undef _ALL_SOURCE /* AIX 5.3L defines a struct list with _ALL_SOURCE. */ +#include +#define _ALL_SOURCE 1 +#endif + +#ifdef MKDIR_WO_TRAILING_SLASH +#define mkdir(a,b) compat_mkdir_wo_trailing_slash((a),(b)) +int compat_mkdir_wo_trailing_slash(const char*, mode_t); +#endif + +#ifdef time +#undef time +#endif +static inline time_t git_time(time_t *tloc) +{ + struct timeval tv; + + /* + * Avoid time(NULL), which can disagree with gettimeofday(2) + * and filesystem timestamps. + */ + gettimeofday(&tv, NULL); + + if (tloc) + *tloc = tv.tv_sec; + return tv.tv_sec; +} +#define time git_time + +#ifdef NO_STRUCT_ITIMERVAL +struct itimerval { + struct timeval it_interval; + struct timeval it_value; +}; +#endif + +#ifdef NO_SETITIMER +static inline int git_setitimer(int which UNUSED, + const struct itimerval *value UNUSED, + struct itimerval *newvalue UNUSED) { + return 0; /* pretend success */ +} +#undef setitimer +#define setitimer(which,value,ovalue) git_setitimer(which,value,ovalue) +#endif + +#ifndef NO_LIBGEN_H +#include +#else +#define basename gitbasename +char *gitbasename(char *); +#define dirname gitdirname +char *gitdirname(char *); +#endif + +#ifndef NO_ICONV +#include +#endif + +/* On most systems would have given us this, but + * not on some systems (e.g. z/OS). + */ +#ifndef NI_MAXHOST +#define NI_MAXHOST 1025 +#endif + +#ifndef NI_MAXSERV +#define NI_MAXSERV 32 +#endif + +/* On most systems would have given us this, but + * not on some systems (e.g. GNU/Hurd). + */ +#ifndef PATH_MAX +#define PATH_MAX 4096 +#endif + +#ifndef NAME_MAX +#define NAME_MAX 255 +#endif + +typedef uintmax_t timestamp_t; +#define PRItime PRIuMAX +#define parse_timestamp strtoumax +#define TIME_MAX UINTMAX_MAX +#define TIME_MIN 0 + +int lstat_cache_aware_rmdir(const char *path); +#if !defined(__MINGW32__) && !defined(_MSC_VER) +#define rmdir lstat_cache_aware_rmdir +#endif + +#if defined(NO_MMAP) || defined(USE_WIN32_MMAP) + +#ifndef PROT_READ +#define PROT_READ 1 +#define PROT_WRITE 2 +#define MAP_PRIVATE 1 +#endif + +#define mmap git_mmap +#define munmap git_munmap +void *git_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset); +int git_munmap(void *start, size_t length); + +#else /* NO_MMAP || USE_WIN32_MMAP */ + +#include + +#endif /* NO_MMAP || USE_WIN32_MMAP */ + +#ifndef MAP_FAILED +#define MAP_FAILED ((void *)-1) +#endif + +#ifdef NEEDS_MODE_TRANSLATION +#undef S_IFMT +#undef S_IFREG +#undef S_IFDIR +#undef S_IFLNK +#undef S_IFBLK +#undef S_IFCHR +#undef S_IFIFO +#undef S_IFSOCK +#define S_IFMT 0170000 +#define S_IFREG 0100000 +#define S_IFDIR 0040000 +#define S_IFLNK 0120000 +#define S_IFBLK 0060000 +#define S_IFCHR 0020000 +#define S_IFIFO 0010000 +#define S_IFSOCK 0140000 +#ifdef stat +#undef stat +#endif +#define stat(path, buf) git_stat(path, buf) +int git_stat(const char *, struct stat *); +#ifdef fstat +#undef fstat +#endif +#define fstat(fd, buf) git_fstat(fd, buf) +int git_fstat(int, struct stat *); +#ifdef lstat +#undef lstat +#endif +#define lstat(path, buf) git_lstat(path, buf) +int git_lstat(const char *, struct stat *); +#endif + +#ifdef NO_PREAD +#define pread git_pread +ssize_t git_pread(int fd, void *buf, size_t count, off_t offset); +#endif + +#ifdef NO_SETENV +#define setenv gitsetenv +int gitsetenv(const char *, const char *, int); +#endif + +#ifdef NO_MKDTEMP +#define mkdtemp gitmkdtemp +char *gitmkdtemp(char *); +#endif + +#ifdef NO_UNSETENV +#define unsetenv gitunsetenv +int gitunsetenv(const char *); +#endif + +#ifdef NO_STRCASESTR +#define strcasestr gitstrcasestr +char *gitstrcasestr(const char *haystack, const char *needle); +#endif + +#ifdef NO_STRLCPY +#define strlcpy gitstrlcpy +size_t gitstrlcpy(char *, const char *, size_t); +#endif + +#ifdef NO_STRTOUMAX +#define strtoumax gitstrtoumax +uintmax_t gitstrtoumax(const char *, char **, int); +#define strtoimax gitstrtoimax +intmax_t gitstrtoimax(const char *, char **, int); +#endif + +#ifdef NO_HSTRERROR +#define hstrerror githstrerror +const char *githstrerror(int herror); +#endif + +#ifdef NO_MEMMEM +#define memmem gitmemmem +void *gitmemmem(const void *haystack, size_t haystacklen, + const void *needle, size_t needlelen); +#endif + +#ifdef OVERRIDE_STRDUP +#ifdef strdup +#undef strdup +#endif +#define strdup gitstrdup +char *gitstrdup(const char *s); +#endif + +#ifdef NO_GETPAGESIZE +#define getpagesize() sysconf(_SC_PAGESIZE) +#endif + +#ifndef O_CLOEXEC +#define O_CLOEXEC 0 +#endif + +#ifdef FREAD_READS_DIRECTORIES +# if !defined(SUPPRESS_FOPEN_REDEFINITION) +# ifdef fopen +# undef fopen +# endif +# define fopen(a,b) git_fopen(a,b) +# endif +FILE *git_fopen(const char*, const char*); +#endif + +#ifdef SNPRINTF_RETURNS_BOGUS +#ifdef snprintf +#undef snprintf +#endif +#define snprintf git_snprintf +int git_snprintf(char *str, size_t maxsize, + const char *format, ...); +#ifdef vsnprintf +#undef vsnprintf +#endif +#define vsnprintf git_vsnprintf +int git_vsnprintf(char *str, size_t maxsize, + const char *format, va_list ap); +#endif + +#ifdef OPEN_RETURNS_EINTR +#undef open +#define open git_open_with_retry +int git_open_with_retry(const char *path, int flag, ...); +#endif + +#ifdef __GLIBC_PREREQ +#if __GLIBC_PREREQ(2, 1) +#define HAVE_STRCHRNUL +#endif +#endif + +#ifndef HAVE_STRCHRNUL +#define strchrnul gitstrchrnul +static inline char *gitstrchrnul(const char *s, int c) +{ + while (*s && *s != c) + s++; + return (char *)s; +} +#endif + +#ifdef NO_INET_PTON +int inet_pton(int af, const char *src, void *dst); +#endif + +#ifdef NO_INET_NTOP +const char *inet_ntop(int af, const void *src, char *dst, size_t size); +#endif + +#ifdef NO_PTHREADS +#define atexit git_atexit +int git_atexit(void (*handler)(void)); +#endif + +#ifndef HOST_NAME_MAX +#define HOST_NAME_MAX 256 +#endif + +#include "../sane-ctype.h" + +void git_stable_qsort(void *base, size_t nmemb, size_t size, + int(*compar)(const void *, const void *)); +#ifdef INTERNAL_QSORT +#define qsort git_stable_qsort +#endif + +#define QSORT(base, n, compar) sane_qsort((base), (n), sizeof(*(base)), compar) +static inline void sane_qsort(void *base, size_t nmemb, size_t size, + int(*compar)(const void *, const void *)) +{ + if (nmemb > 1) + qsort(base, nmemb, size, compar); +} + +#define STABLE_QSORT(base, n, compar) \ + git_stable_qsort((base), (n), sizeof(*(base)), compar) + +#ifndef HAVE_ISO_QSORT_S +int git_qsort_s(void *base, size_t nmemb, size_t size, + int (*compar)(const void *, const void *, void *), void *ctx); +#define qsort_s git_qsort_s +#endif + +#define QSORT_S(base, n, compar, ctx) do { \ + if (qsort_s((base), (n), sizeof(*(base)), compar, ctx)) \ + BUG("qsort_s() failed"); \ +} while (0) + +#ifdef NO_NSEC +#undef USE_NSEC +#define ST_CTIME_NSEC(st) 0 +#define ST_MTIME_NSEC(st) 0 +#else +#ifdef USE_ST_TIMESPEC +#define ST_CTIME_NSEC(st) ((unsigned int)((st).st_ctimespec.tv_nsec)) +#define ST_MTIME_NSEC(st) ((unsigned int)((st).st_mtimespec.tv_nsec)) +#else +#define ST_CTIME_NSEC(st) ((unsigned int)((st).st_ctim.tv_nsec)) +#define ST_MTIME_NSEC(st) ((unsigned int)((st).st_mtim.tv_nsec)) +#endif +#endif + +#ifndef va_copy +/* + * Since an obvious implementation of va_list would be to make it a + * pointer into the stack frame, a simple assignment will work on + * many systems. But let's try to be more portable. + */ +#ifdef __va_copy +#define va_copy(dst, src) __va_copy(dst, src) +#else +#define va_copy(dst, src) ((dst) = (src)) +#endif +#endif + +#ifndef _POSIX_THREAD_SAFE_FUNCTIONS +static inline void git_flockfile(FILE *fh UNUSED) +{ + ; /* nothing */ +} +static inline void git_funlockfile(FILE *fh UNUSED) +{ + ; /* nothing */ +} +#undef flockfile +#undef funlockfile +#undef getc_unlocked +#define flockfile(fh) git_flockfile(fh) +#define funlockfile(fh) git_funlockfile(fh) +#define getc_unlocked(fh) getc(fh) +#endif + +#ifdef FILENO_IS_A_MACRO +int git_fileno(FILE *stream); +# ifndef COMPAT_CODE_FILENO +# undef fileno +# define fileno(p) git_fileno(p) +# endif +#endif + +#ifdef NEED_ACCESS_ROOT_HANDLER +int git_access(const char *path, int mode); +# ifndef COMPAT_CODE_ACCESS +# ifdef access +# undef access +# endif +# define access(path, mode) git_access(path, mode) +# endif +#endif + +#endif /* COMPAT_POSIX_H */ diff --git a/git-compat-util.h b/git-compat-util.h index b96fb98e1e..30ad0725fb 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -23,26 +23,9 @@ #include #endif -struct strbuf; - - -#define _FILE_OFFSET_BITS 64 +#include "compat/posix.h" - -/* Derived from Linux "Features Test Macro" header - * Convenience macros to test the versions of gcc (or - * a compatible compiler). - * Use them like this: - * #if GIT_GNUC_PREREQ (2,8) - * ... code requiring gcc 2.8 or later ... - * #endif -*/ -#if defined(__GNUC__) && defined(__GNUC_MINOR__) -# define GIT_GNUC_PREREQ(maj, min) \ - ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) -#else - #define GIT_GNUC_PREREQ(maj, min) 0 -#endif +struct strbuf; #if defined(__GNUC__) || defined(__clang__) # define PRAGMA(pragma) _Pragma(#pragma) @@ -176,71 +159,6 @@ DISABLE_WARNING(-Wsign-compare) /* Approximation of the length of the decimal representation of this type. */ #define decimal_length(x) ((int)(sizeof(x) * 2.56 + 0.5) + 1) -#ifdef __MINGW64__ -#define _POSIX_C_SOURCE 1 -#elif defined(__sun__) - /* - * On Solaris, when _XOPEN_EXTENDED is set, its header file - * forces the programs to be XPG4v2, defeating any _XOPEN_SOURCE - * setting to say we are XPG5 or XPG6. Also on Solaris, - * XPG6 programs must be compiled with a c99 compiler, while - * non XPG6 programs must be compiled with a pre-c99 compiler. - */ -# if __STDC_VERSION__ - 0 >= 199901L -# define _XOPEN_SOURCE 600 -# else -# define _XOPEN_SOURCE 500 -# endif -#elif !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__USLC__) && \ - !defined(_M_UNIX) && !defined(__sgi) && !defined(__DragonFly__) && \ - !defined(__TANDEM) && !defined(__QNX__) && !defined(__MirBSD__) && \ - !defined(__CYGWIN__) -#define _XOPEN_SOURCE 600 /* glibc2 and AIX 5.3L need 500, OpenBSD needs 600 for S_ISLNK() */ -#define _XOPEN_SOURCE_EXTENDED 1 /* AIX 5.3L needs this */ -#endif -#define _ALL_SOURCE 1 -#define _GNU_SOURCE 1 -#define _BSD_SOURCE 1 -#define _DEFAULT_SOURCE 1 -#define _NETBSD_SOURCE 1 -#define _SGI_SOURCE 1 - -/* - * UNUSED marks a function parameter that is always unused. It also - * can be used to annotate a function, a variable, or a type that is - * always unused. - * - * A callback interface may dictate that a function accepts a - * parameter at that position, but the implementation of the function - * may not need to use the parameter. In such a case, mark the parameter - * with UNUSED. - * - * When a parameter may be used or unused, depending on conditional - * compilation, consider using MAYBE_UNUSED instead. - */ -#if GIT_GNUC_PREREQ(4, 5) -#define UNUSED __attribute__((unused)) \ - __attribute__((deprecated ("parameter declared as UNUSED"))) -#elif defined(__GNUC__) -#define UNUSED __attribute__((unused)) \ - __attribute__((deprecated)) -#else -#define UNUSED -#endif - -#if defined(WIN32) && !defined(__CYGWIN__) /* Both MinGW and MSVC */ -# if !defined(_WIN32_WINNT) -# define _WIN32_WINNT 0x0600 -# endif -#define WIN32_LEAN_AND_MEAN /* stops windows.h including winsock.h */ -#include -#ifndef NO_UNIX_SOCKETS -#include -#endif -#include -#define GIT_WINDOWS_NATIVE -#endif - #if defined(NO_UNIX_SOCKETS) || !defined(GIT_WINDOWS_NATIVE) static inline int _have_unix_sockets(void) { @@ -253,45 +171,6 @@ static inline int _have_unix_sockets(void) #define have_unix_sockets _have_unix_sockets #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef HAVE_STRINGS_H -#include /* for strcasecmp() */ -#endif -#include -#include -#include -#ifdef NEEDS_SYS_PARAM_H -#include -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#if !defined(NO_POLL_H) -#include -#elif !defined(NO_SYS_POLL_H) -#include -#else -/* Pull the compat stuff */ -#include -#endif -#ifdef HAVE_BSD_SYSCTL -#include -#endif - /* Used by compat/win32/path-utils.h, and more */ static inline int is_xplatform_dir_sep(int c) { @@ -308,48 +187,6 @@ static inline int is_xplatform_dir_sep(int c) #elif defined(_MSC_VER) #include "compat/win32/path-utils.h" #include "compat/msvc/compat-util.h" -#else -#include -#include -#include -#include -#include -#include -#include -#ifndef NO_SYS_SELECT_H -#include -#endif -#include -#include -#include -#include -#include -#include -#ifndef NO_INTTYPES_H -#include -#else -#include -#endif -#ifdef HAVE_ARC4RANDOM_LIBBSD -#include -#endif -#ifdef HAVE_GETRANDOM -#include -#endif -#ifdef NO_INTPTR_T -/* - * On I16LP32, ILP32 and LP64 "long" is the safe bet, however - * on LLP86, IL33LLP64 and P64 it needs to be "long long", - * while on IP16 and IP16L32 it is "int" (resp. "short") - * Size needs to match (or exceed) 'sizeof(void *)'. - * We can't take "long long" here as not everybody has it. - */ -typedef long intptr_t; -typedef unsigned long uintptr_t; -#endif -#undef _ALL_SOURCE /* AIX 5.3L defines a struct list with _ALL_SOURCE. */ -#include -#define _ALL_SOURCE 1 #endif /* used on Mac OS X */ @@ -370,60 +207,6 @@ static inline const char *precompose_string_if_needed(const char *in) #define probe_utf8_pathname_composition() #endif -#ifdef MKDIR_WO_TRAILING_SLASH -#define mkdir(a,b) compat_mkdir_wo_trailing_slash((a),(b)) -int compat_mkdir_wo_trailing_slash(const char*, mode_t); -#endif - -#ifdef time -#undef time -#endif -static inline time_t git_time(time_t *tloc) -{ - struct timeval tv; - - /* - * Avoid time(NULL), which can disagree with gettimeofday(2) - * and filesystem timestamps. - */ - gettimeofday(&tv, NULL); - - if (tloc) - *tloc = tv.tv_sec; - return tv.tv_sec; -} -#define time git_time - -#ifdef NO_STRUCT_ITIMERVAL -struct itimerval { - struct timeval it_interval; - struct timeval it_value; -}; -#endif - -#ifdef NO_SETITIMER -static inline int git_setitimer(int which UNUSED, - const struct itimerval *value UNUSED, - struct itimerval *newvalue UNUSED) { - return 0; /* pretend success */ -} -#undef setitimer -#define setitimer(which,value,ovalue) git_setitimer(which,value,ovalue) -#endif - -#ifndef NO_LIBGEN_H -#include -#else -#define basename gitbasename -char *gitbasename(char *); -#define dirname gitdirname -char *gitdirname(char *); -#endif - -#ifndef NO_ICONV -#include -#endif - #ifndef NO_OPENSSL #ifdef __APPLE__ #undef __AVAILABILITY_MACROS_USES_AVAILABILITY @@ -441,34 +224,6 @@ char *gitdirname(char *); # include #endif -/* On most systems would have given us this, but - * not on some systems (e.g. z/OS). - */ -#ifndef NI_MAXHOST -#define NI_MAXHOST 1025 -#endif - -#ifndef NI_MAXSERV -#define NI_MAXSERV 32 -#endif - -/* On most systems would have given us this, but - * not on some systems (e.g. GNU/Hurd). - */ -#ifndef PATH_MAX -#define PATH_MAX 4096 -#endif - -#ifndef NAME_MAX -#define NAME_MAX 255 -#endif - -typedef uintmax_t timestamp_t; -#define PRItime PRIuMAX -#define parse_timestamp strtoumax -#define TIME_MAX UINTMAX_MAX -#define TIME_MIN 0 - #ifndef PATH_SEP #define PATH_SEP ':' #endif @@ -492,11 +247,6 @@ static inline int noop_core_config(const char *var UNUSED, #define platform_core_config noop_core_config #endif -int lstat_cache_aware_rmdir(const char *path); -#if !defined(__MINGW32__) && !defined(_MSC_VER) -#define rmdir lstat_cache_aware_rmdir -#endif - #ifndef has_dos_drive_prefix static inline int git_has_dos_drive_prefix(const char *path UNUSED) { @@ -822,25 +572,6 @@ static inline bool strip_suffix(const char *str, const char *suffix, memcpy(_swap_b_ptr, _swap_buffer, sizeof(a)); \ } while (0) -#if defined(NO_MMAP) || defined(USE_WIN32_MMAP) - -#ifndef PROT_READ -#define PROT_READ 1 -#define PROT_WRITE 2 -#define MAP_PRIVATE 1 -#endif - -#define mmap git_mmap -#define munmap git_munmap -void *git_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset); -int git_munmap(void *start, size_t length); - -#else /* NO_MMAP || USE_WIN32_MMAP */ - -#include - -#endif /* NO_MMAP || USE_WIN32_MMAP */ - #ifdef NO_MMAP /* This value must be multiple of (pagesize * 2) */ @@ -856,177 +587,15 @@ int git_munmap(void *start, size_t length); #endif /* NO_MMAP */ -#ifndef MAP_FAILED -#define MAP_FAILED ((void *)-1) -#endif - #ifdef NO_ST_BLOCKS_IN_STRUCT_STAT #define on_disk_bytes(st) ((st).st_size) #else #define on_disk_bytes(st) ((st).st_blocks * 512) #endif -#ifdef NEEDS_MODE_TRANSLATION -#undef S_IFMT -#undef S_IFREG -#undef S_IFDIR -#undef S_IFLNK -#undef S_IFBLK -#undef S_IFCHR -#undef S_IFIFO -#undef S_IFSOCK -#define S_IFMT 0170000 -#define S_IFREG 0100000 -#define S_IFDIR 0040000 -#define S_IFLNK 0120000 -#define S_IFBLK 0060000 -#define S_IFCHR 0020000 -#define S_IFIFO 0010000 -#define S_IFSOCK 0140000 -#ifdef stat -#undef stat -#endif -#define stat(path, buf) git_stat(path, buf) -int git_stat(const char *, struct stat *); -#ifdef fstat -#undef fstat -#endif -#define fstat(fd, buf) git_fstat(fd, buf) -int git_fstat(int, struct stat *); -#ifdef lstat -#undef lstat -#endif -#define lstat(path, buf) git_lstat(path, buf) -int git_lstat(const char *, struct stat *); -#endif - #define DEFAULT_PACKED_GIT_LIMIT \ ((1024L * 1024L) * (size_t)(sizeof(void*) >= 8 ? (32 * 1024L * 1024L) : 256)) -#ifdef NO_PREAD -#define pread git_pread -ssize_t git_pread(int fd, void *buf, size_t count, off_t offset); -#endif - -#ifdef NO_SETENV -#define setenv gitsetenv -int gitsetenv(const char *, const char *, int); -#endif - -#ifdef NO_MKDTEMP -#define mkdtemp gitmkdtemp -char *gitmkdtemp(char *); -#endif - -#ifdef NO_UNSETENV -#define unsetenv gitunsetenv -int gitunsetenv(const char *); -#endif - -#ifdef NO_STRCASESTR -#define strcasestr gitstrcasestr -char *gitstrcasestr(const char *haystack, const char *needle); -#endif - -#ifdef NO_STRLCPY -#define strlcpy gitstrlcpy -size_t gitstrlcpy(char *, const char *, size_t); -#endif - -#ifdef NO_STRTOUMAX -#define strtoumax gitstrtoumax -uintmax_t gitstrtoumax(const char *, char **, int); -#define strtoimax gitstrtoimax -intmax_t gitstrtoimax(const char *, char **, int); -#endif - -#ifdef NO_HSTRERROR -#define hstrerror githstrerror -const char *githstrerror(int herror); -#endif - -#ifdef NO_MEMMEM -#define memmem gitmemmem -void *gitmemmem(const void *haystack, size_t haystacklen, - const void *needle, size_t needlelen); -#endif - -#ifdef OVERRIDE_STRDUP -#ifdef strdup -#undef strdup -#endif -#define strdup gitstrdup -char *gitstrdup(const char *s); -#endif - -#ifdef NO_GETPAGESIZE -#define getpagesize() sysconf(_SC_PAGESIZE) -#endif - -#ifndef O_CLOEXEC -#define O_CLOEXEC 0 -#endif - -#ifdef FREAD_READS_DIRECTORIES -# if !defined(SUPPRESS_FOPEN_REDEFINITION) -# ifdef fopen -# undef fopen -# endif -# define fopen(a,b) git_fopen(a,b) -# endif -FILE *git_fopen(const char*, const char*); -#endif - -#ifdef SNPRINTF_RETURNS_BOGUS -#ifdef snprintf -#undef snprintf -#endif -#define snprintf git_snprintf -int git_snprintf(char *str, size_t maxsize, - const char *format, ...); -#ifdef vsnprintf -#undef vsnprintf -#endif -#define vsnprintf git_vsnprintf -int git_vsnprintf(char *str, size_t maxsize, - const char *format, va_list ap); -#endif - -#ifdef OPEN_RETURNS_EINTR -#undef open -#define open git_open_with_retry -int git_open_with_retry(const char *path, int flag, ...); -#endif - -#ifdef __GLIBC_PREREQ -#if __GLIBC_PREREQ(2, 1) -#define HAVE_STRCHRNUL -#endif -#endif - -#ifndef HAVE_STRCHRNUL -#define strchrnul gitstrchrnul -static inline char *gitstrchrnul(const char *s, int c) -{ - while (*s && *s != c) - s++; - return (char *)s; -} -#endif - -#ifdef NO_INET_PTON -int inet_pton(int af, const char *src, void *dst); -#endif - -#ifdef NO_INET_NTOP -const char *inet_ntop(int af, const void *src, char *dst, size_t size); -#endif - -#ifdef NO_PTHREADS -#define atexit git_atexit -int git_atexit(void (*handler)(void)); -#endif - static inline size_t st_add(size_t a, size_t b) { if (unsigned_add_overflows(a, b)) @@ -1293,12 +862,6 @@ static inline size_t xsize_t(off_t len) return (size_t) len; } -#ifndef HOST_NAME_MAX -#define HOST_NAME_MAX 256 -#endif - -#include "sane-ctype.h" - /* * Like skip_prefix, but compare case-insensitively. Note that the comparison * is done via tolower(), so it is strictly ASCII (no multi-byte characters or @@ -1364,34 +927,6 @@ static inline int strtol_i(char const *s, int base, int *result) return 0; } -void git_stable_qsort(void *base, size_t nmemb, size_t size, - int(*compar)(const void *, const void *)); -#ifdef INTERNAL_QSORT -#define qsort git_stable_qsort -#endif - -#define QSORT(base, n, compar) sane_qsort((base), (n), sizeof(*(base)), compar) -static inline void sane_qsort(void *base, size_t nmemb, size_t size, - int(*compar)(const void *, const void *)) -{ - if (nmemb > 1) - qsort(base, nmemb, size, compar); -} - -#define STABLE_QSORT(base, n, compar) \ - git_stable_qsort((base), (n), sizeof(*(base)), compar) - -#ifndef HAVE_ISO_QSORT_S -int git_qsort_s(void *base, size_t nmemb, size_t size, - int (*compar)(const void *, const void *, void *), void *ctx); -#define qsort_s git_qsort_s -#endif - -#define QSORT_S(base, n, compar, ctx) do { \ - if (qsort_s((base), (n), sizeof(*(base)), compar, ctx)) \ - BUG("qsort_s() failed"); \ -} while (0) - #ifndef REG_STARTEND #error "Git requires REG_STARTEND support. Compile with NO_REGEX=NeedsStartEnd" #endif @@ -1416,39 +951,12 @@ int git_regcomp(regex_t *preg, const char *pattern, int cflags); # define FORCE_DIR_SET_GID 0 #endif -#ifdef NO_NSEC -#undef USE_NSEC -#define ST_CTIME_NSEC(st) 0 -#define ST_MTIME_NSEC(st) 0 -#else -#ifdef USE_ST_TIMESPEC -#define ST_CTIME_NSEC(st) ((unsigned int)((st).st_ctimespec.tv_nsec)) -#define ST_MTIME_NSEC(st) ((unsigned int)((st).st_mtimespec.tv_nsec)) -#else -#define ST_CTIME_NSEC(st) ((unsigned int)((st).st_ctim.tv_nsec)) -#define ST_MTIME_NSEC(st) ((unsigned int)((st).st_mtim.tv_nsec)) -#endif -#endif - #ifdef UNRELIABLE_FSTAT #define fstat_is_reliable() 0 #else #define fstat_is_reliable() 1 #endif -#ifndef va_copy -/* - * Since an obvious implementation of va_list would be to make it a - * pointer into the stack frame, a simple assignment will work on - * many systems. But let's try to be more portable. - */ -#ifdef __va_copy -#define va_copy(dst, src) __va_copy(dst, src) -#else -#define va_copy(dst, src) ((dst) = (src)) -#endif -#endif - /* usage.c: only to be used for testing BUG() implementation (see test-tool) */ extern int BUG_exit_code; @@ -1478,41 +986,6 @@ void bug_fl(const char *file, int line, const char *fmt, ...); # define SHELL_PATH "/bin/sh" #endif -#ifndef _POSIX_THREAD_SAFE_FUNCTIONS -static inline void git_flockfile(FILE *fh UNUSED) -{ - ; /* nothing */ -} -static inline void git_funlockfile(FILE *fh UNUSED) -{ - ; /* nothing */ -} -#undef flockfile -#undef funlockfile -#undef getc_unlocked -#define flockfile(fh) git_flockfile(fh) -#define funlockfile(fh) git_funlockfile(fh) -#define getc_unlocked(fh) getc(fh) -#endif - -#ifdef FILENO_IS_A_MACRO -int git_fileno(FILE *stream); -# ifndef COMPAT_CODE_FILENO -# undef fileno -# define fileno(p) git_fileno(p) -# endif -#endif - -#ifdef NEED_ACCESS_ROOT_HANDLER -int git_access(const char *path, int mode); -# ifndef COMPAT_CODE_ACCESS -# ifdef access -# undef access -# endif -# define access(path, mode) git_access(path, mode) -# endif -#endif - /* * Our code often opens a path to an optional file, to work on its * contents when we can successfully open it. We can ignore a failure From patchwork Fri Feb 7 11:52:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13964886 Received: from fout-a8-smtp.messagingengine.com (fout-a8-smtp.messagingengine.com [103.168.172.151]) (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 338791E5B67 for ; Fri, 7 Feb 2025 11:52:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929140; cv=none; b=fe1SMW4G9WASVt5A27TUUG8/QKWpj0idv2TyGhqaDADEQALBaKEdkxkwJ8ZwxYPfn7E+s4aSNVsFeel8zfyggfVPVhDk87rBs/v1GCUqPdHQYNfdykeHwRwtpB6n36ESM+J58xZt3azbPEt6JLdU+2HxJGTNFo5bzlazKjIygrs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929140; c=relaxed/simple; bh=0zzM+2czzRAkYhbvM5bN90P3r+/rn9lE+fLpLyyJyQQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=molOoeg/UNANNDHh75LYT/T4is5BZB+7bn3EW8wyPfunZac/W4yl9QumjW7nOHqBm77lyb7Xs5tQbjKJ3HerWeqX/ltZ5voCkfNOQyKa+OlkuVbFHChUvPLizT7JsKtMLJzkYbRKgSBXViGAQfJq/A+0LemVMVtO7K/Dh8FIb/4= 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=dWA34H2B; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=IFhL9xsy; arc=none smtp.client-ip=103.168.172.151 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="dWA34H2B"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="IFhL9xsy" Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfout.phl.internal (Postfix) with ESMTP id 8787B138017E; Fri, 7 Feb 2025 06:52:18 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Fri, 07 Feb 2025 06:52:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding: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=fm3; t=1738929138; x=1739015538; bh=YVhcg1aFDrdX2uHQZN3UE/+/DjM6zfjjL12G1uMB3t0=; b= dWA34H2Bsd4JJyrV7XQdSa7p7yeoAn8dUT9hhGswkuVeGAap+3NjQRAQeA4HQ5P/ Uaq6ZOkcvTRkZvlV/IM3/0BX7pZeOECbQKGEz3Fh20QRIzQcpuHg6qKQyViVfj5F uV0LJIyEm0OusHdyYz78BDBwg4RofapO5gfxvw86Lvp2MbfYEUhd/v9465s8rmO0 Jx2FVP0aC1SmaSllsEgTNCdgYelh46ZpOB7aMgIsDKAoa0mRtULXiPeTusd7I1/o VqM3OEOGGHHQn/XLYIwTfn2aCd8R6NGOpVK0b7Cw1C3XzqkPxRgQDMBNlRGyxIJw KboJNJOgnYXO38koUDYzdg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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-sender:x-me-sender:x-sasl-enc; s=fm3; t=1738929138; x= 1739015538; bh=YVhcg1aFDrdX2uHQZN3UE/+/DjM6zfjjL12G1uMB3t0=; b=I FhL9xsyQlVQFX2UqRTn90/hSCUnByvX9Pll47m326tLo9ybDNNyBSOBkTLGPJHAt owdaU6/8pmweoaA3rENJkQMlbzJH6pGL8gxZQiBiG/eRFvd9nVu7lHBqCpHuWpu3 7vtOiIUQ10bLC+BZYzF2wJCoAYwBiC7agj7W6UoHCkeWIsgBLyAFEywaAhx5zHxI ymWX5u/nWxDGuVmquJBkaGfKU4MLG5PWiNBe50yve5ZfYX8eYXTvM9C90mUkQu7M Lzw2b4Vn/aUSSy5giJxe56+paxFoGNz3bvvIRv06+y08ng0SMDOnipFOv/dNQRzo SgvRA2G+Ob2pj2acXBGCg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvledvtdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredt jeenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrd himheqnecuggftrfgrthhtvghrnhepffeuiedujedvkeehuedvkeefffeivdeuleetkedu heejteekgedvudfgtdfgieelnecuvehluhhsthgvrhfuihiivgepheenucfrrghrrghmpe hmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepjheitheskhgusghgrdhorhhgpdhrtghpthhtoh epjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtghpthhtohepvghthhhomhhsohhn segvugifrghrughthhhomhhsohhnrdgtohhmpdhrtghpthhtohepghhithhsthgvrhesph hosghogidrtghomhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Feb 2025 06:52:17 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 4b8ee0a2 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 7 Feb 2025 11:52:16 +0000 (UTC) From: Patrick Steinhardt Date: Fri, 07 Feb 2025 12:52:12 +0100 Subject: [PATCH v5 17/18] reftable: decouple from Git codebase by pulling in "compat/posix.h" Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250207-pks-reftable-drop-git-compat-util-v5-17-ba2adc79110f@pks.im> References: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> In-Reply-To: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> To: git@vger.kernel.org Cc: Edward Thomson , Justin Tobler , Junio C Hamano , Johannes Sixt X-Mailer: b4 0.14.2 The reftable library includes "git-compat-util.h" in order to get a POSIX-like programming environment that papers over various differences between platforms. The header also brings with it a couple of helpers specific to the Git codebase though, and over time we have started to use these helpers in the reftable library, as well. This makes it very hard to use the reftable library as a standalone library without the rest of the Git codebase, so other libraries like e.g. libgit2 cannot easily use it. But now that we have removed all calls to Git-specific functionality and have split out "compat/posix.h" as a separate header we can address this. Stop including "git-compat-util.h" and instead include "compat/posix.h" to finalize the decoupling of the reftable library from the rest of the Git codebase. The only bits which remain specific to Git are "system.h" and "system.c", which projects will have to provide. Signed-off-by: Patrick Steinhardt --- reftable/system.c | 2 ++ reftable/system.h | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/reftable/system.c b/reftable/system.c index e25ccc0da3..1ee268b125 100644 --- a/reftable/system.c +++ b/reftable/system.c @@ -1,3 +1,5 @@ +#include "../git-compat-util.h" + #include "system.h" #include "basics.h" #include "reftable-error.h" diff --git a/reftable/system.h b/reftable/system.h index 3bd4a4e322..dccdf11f76 100644 --- a/reftable/system.h +++ b/reftable/system.h @@ -11,7 +11,8 @@ license that can be found in the LICENSE file or at /* This header glues the reftable library to the rest of Git */ -#include "git-compat-util.h" +#include "../compat/posix.h" +#include /* * Return a random 32 bit integer. This function is expected to return From patchwork Fri Feb 7 11:52:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13964889 Received: from fout-a8-smtp.messagingengine.com (fout-a8-smtp.messagingengine.com [103.168.172.151]) (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 06D571EA7D3 for ; Fri, 7 Feb 2025 11:52:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929141; cv=none; b=nxtp9K5pjidT/gO/eJ5nRJcRPuzJYzX2z4x/NFswYRU5bL+uTXjbmtB6qIDYVjq8Sag03SyBJcJ6dsUWUO2vM6DkD1UDnjL0FFb9b9oYaBKGn51ji5i/rRGC1P59z+YUgyXem93aMMb5jq+iBIIx18mjWuulCxTSu33BzadRBEM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738929141; c=relaxed/simple; bh=UZSyDGHmyvtglQ5JWIG+H3n9BOt/hfmR8oI12SvqJoo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GK1+V9Jr8mVTxE2LN8Quo4NzTSw+uC/EE01daARs5X/DPf/boXEusIY7tRr97i4DEbFfXhnnXE/iYLBsJs6uWkpOHQpNFWeuiEBeqPEzAGwVkT99PIv85H+VPrYVAYwZzL1deeGyqu4RJP4HRYKQwdrUDKjJ+Vac88xkwhof6/w= 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=PGAO7cnl; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=k4fL+MzQ; arc=none smtp.client-ip=103.168.172.151 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="PGAO7cnl"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="k4fL+MzQ" Received: from phl-compute-09.internal (phl-compute-09.phl.internal [10.202.2.49]) by mailfout.phl.internal (Postfix) with ESMTP id 144F213801AE; Fri, 7 Feb 2025 06:52:19 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-09.internal (MEProxy); Fri, 07 Feb 2025 06:52:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding: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=fm3; t=1738929139; x=1739015539; bh=0cll7B6pvDOi+gm1xYCTi3Yl2LtzE0zaIQ/Na/k6dpc=; b= PGAO7cnl6AnxlQIXTcBrB/Ae+Kc63YKC8HXshUpvNHQeBeeVR8oJuAQflLrOpZOD Ov/c1e/arZ923rTbNXn+OzrY7+4nIMHAY9ld0Yo64wozoZAfYHojTXwDsviZP6l+ zKVs8hkiPC4M1VG6l1Q02TDolSuSEY3KPwoavhuu0tDQkD/1D6Y64JNRQ7qlgKyX 2zYSapNnrcUC7JYjicV4hrqmfRLkECOAvo2bUEePrjnnTdXC9SxdUrl+2DLN13UL nKbks8VEfm6EhnZon8gEin48ECdviwfKUFZt0NAFXbe9kYU5E+RJL2AFFvRWdVxE yvpPf3kUaMBaCv+RYses/g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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-sender:x-me-sender:x-sasl-enc; s=fm3; t=1738929139; x= 1739015539; bh=0cll7B6pvDOi+gm1xYCTi3Yl2LtzE0zaIQ/Na/k6dpc=; b=k 4fL+MzQbidy8tbDKWYH8ZkiTLGcDsetWWv31EnoGfM9uZEg4WXYdyzhmLkaqmq6h /12jeBnQCpr9S6OzXywOC2rL+/A4oLgy/QeiCvEfDr0vw21wFFEd26ldj6nckYE3 Zpra3PfQ5XRQUBJz69kLadHtYX9qR3DEDUB67pmEJG6DymIvqUHjnFkCraD/RzmT Vg6J35Cr2Ax8pJw0EojB0S6cL5sju+DmD5FoHtwuNO2KllNovHEGnR37qMmFLNvU KGPTfNTXCV2I/O7q9tOqVw48je47S4fnUqpq2GYwypLU2djK9tTpzwtKlwAPRs7h DpCv7WnAzafUGOgRgOHUw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvledvudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredt jeenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrd himheqnecuggftrfgrthhtvghrnhepffeuiedujedvkeehuedvkeefffeivdeuleetkedu heejteekgedvudfgtdfgieelnecuvehluhhsthgvrhfuihiivgepheenucfrrghrrghmpe hmrghilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohephedpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh dprhgtphhtthhopegvthhhohhmshhonhesvggufigrrhguthhhohhmshhonhdrtghomhdp rhgtphhtthhopehgihhtshhtvghrsehpohgsohigrdgtohhmpdhrtghpthhtohepjhhlth hosghlvghrsehgmhgrihhlrdgtohhmpdhrtghpthhtohepjheitheskhgusghgrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Feb 2025 06:52:17 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 1867b355 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 7 Feb 2025 11:52:17 +0000 (UTC) From: Patrick Steinhardt Date: Fri, 07 Feb 2025 12:52:13 +0100 Subject: [PATCH v5 18/18] Makefile: skip reftable library for Coccinelle Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250207-pks-reftable-drop-git-compat-util-v5-18-ba2adc79110f@pks.im> References: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> In-Reply-To: <20250207-pks-reftable-drop-git-compat-util-v5-0-ba2adc79110f@pks.im> To: git@vger.kernel.org Cc: Edward Thomson , Justin Tobler , Junio C Hamano , Johannes Sixt X-Mailer: b4 0.14.2 The reftable library does not use any of the common helpers that the Git project has. Consequently, most of the rules that we have in Coccinelle do not apply to the library at all and may even generate false positives when a pattern can be converted to use a Git helper function. Exclude reftable library sources from being checked by Coccinelle to avoid such false positives. Signed-off-by: Patrick Steinhardt --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d3011e30f7..dc2ac32e4a 100644 --- a/Makefile +++ b/Makefile @@ -946,7 +946,7 @@ FOUND_SOURCE_FILES := $(filter-out $(GENERATED_H),$(shell $(SOURCES_CMD))) FOUND_C_SOURCES = $(filter %.c,$(FOUND_SOURCE_FILES)) FOUND_H_SOURCES = $(filter %.h,$(FOUND_SOURCE_FILES)) -COCCI_SOURCES = $(filter-out $(THIRD_PARTY_SOURCES),$(FOUND_C_SOURCES)) +COCCI_SOURCES = $(filter-out $(THIRD_PARTY_SOURCES) reftable/%,$(FOUND_C_SOURCES)) LIB_H = $(FOUND_H_SOURCES)