From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Cc: Elijah Newren <newren@gmail.com>, Junio C Hamano <gitster@pobox.com>
Subject: [PATCH v2 3/9] object-file: move `xmmap()` into "wrapper.c"
Date: Fri, 11 Apr 2025 11:29:52 +0200 [thread overview]
Message-ID: <20250411-pks-split-object-file-v2-3-2bea0c9033ae@pks.im> (raw)
In-Reply-To: <20250411-pks-split-object-file-v2-0-2bea0c9033ae@pks.im>
The `xmmap()` function is provided by "object-file.c" even though its
functionality has nothing to do with the object file subsystem. Move it
into "wrapper.c", whose header already declares those functions.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
object-file.c | 48 ------------------------------------------------
wrapper.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+), 48 deletions(-)
diff --git a/object-file.c b/object-file.c
index 1a20c7fa072..ea2ed7628e6 100644
--- a/object-file.c
+++ b/object-file.c
@@ -719,54 +719,6 @@ int has_loose_object(const struct object_id *oid)
return check_and_freshen(oid, 0);
}
-static void mmap_limit_check(size_t length)
-{
- static size_t limit = 0;
- if (!limit) {
- limit = git_env_ulong("GIT_MMAP_LIMIT", 0);
- if (!limit)
- limit = SIZE_MAX;
- }
- if (length > limit)
- die(_("attempting to mmap %"PRIuMAX" over limit %"PRIuMAX),
- (uintmax_t)length, (uintmax_t)limit);
-}
-
-void *xmmap_gently(void *start, size_t length,
- int prot, int flags, int fd, off_t offset)
-{
- void *ret;
-
- mmap_limit_check(length);
- ret = mmap(start, length, prot, flags, fd, offset);
- if (ret == MAP_FAILED && !length)
- ret = NULL;
- return ret;
-}
-
-const char *mmap_os_err(void)
-{
- static const char blank[] = "";
-#if defined(__linux__)
- if (errno == ENOMEM) {
- /* this continues an existing error message: */
- static const char enomem[] =
-", check sys.vm.max_map_count and/or RLIMIT_DATA";
- return enomem;
- }
-#endif /* OS-specific bits */
- return blank;
-}
-
-void *xmmap(void *start, size_t length,
- int prot, int flags, int fd, off_t offset)
-{
- void *ret = xmmap_gently(start, length, prot, flags, fd, offset);
- if (ret == MAP_FAILED)
- die_errno(_("mmap failed%s"), mmap_os_err());
- return ret;
-}
-
static int format_object_header_literally(char *str, size_t size,
const char *type, size_t objsize)
{
diff --git a/wrapper.c b/wrapper.c
index 8b985931490..3c79778055e 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -829,3 +829,51 @@ uint32_t git_rand(unsigned flags)
return result;
}
+
+static void mmap_limit_check(size_t length)
+{
+ static size_t limit = 0;
+ if (!limit) {
+ limit = git_env_ulong("GIT_MMAP_LIMIT", 0);
+ if (!limit)
+ limit = SIZE_MAX;
+ }
+ if (length > limit)
+ die(_("attempting to mmap %"PRIuMAX" over limit %"PRIuMAX),
+ (uintmax_t)length, (uintmax_t)limit);
+}
+
+void *xmmap_gently(void *start, size_t length,
+ int prot, int flags, int fd, off_t offset)
+{
+ void *ret;
+
+ mmap_limit_check(length);
+ ret = mmap(start, length, prot, flags, fd, offset);
+ if (ret == MAP_FAILED && !length)
+ ret = NULL;
+ return ret;
+}
+
+const char *mmap_os_err(void)
+{
+ static const char blank[] = "";
+#if defined(__linux__)
+ if (errno == ENOMEM) {
+ /* this continues an existing error message: */
+ static const char enomem[] =
+", check sys.vm.max_map_count and/or RLIMIT_DATA";
+ return enomem;
+ }
+#endif /* OS-specific bits */
+ return blank;
+}
+
+void *xmmap(void *start, size_t length,
+ int prot, int flags, int fd, off_t offset)
+{
+ void *ret = xmmap_gently(start, length, prot, flags, fd, offset);
+ if (ret == MAP_FAILED)
+ die_errno(_("mmap failed%s"), mmap_os_err());
+ return ret;
+}
--
2.49.0.777.g153de2bbd5.dirty
next prev parent reply other threads:[~2025-04-11 9:30 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-08 10:24 [PATCH 0/9] Split up "object-file.c" Patrick Steinhardt
2025-04-08 10:24 ` [PATCH 1/9] object-file: move `safe_create_leading_directories()` into "dir.c" Patrick Steinhardt
2025-04-09 14:36 ` Elijah Newren
2025-04-11 9:27 ` Patrick Steinhardt
2025-04-11 17:11 ` Elijah Newren
2025-04-15 9:19 ` Patrick Steinhardt
2025-04-15 15:11 ` Junio C Hamano
2025-04-08 10:24 ` [PATCH 2/9] object-file: move `git_open_cloexec()` to "compat/open.c" Patrick Steinhardt
2025-04-08 10:24 ` [PATCH 3/9] object-file: move `xmmap()` into "wrapper.c" Patrick Steinhardt
2025-04-09 14:36 ` Elijah Newren
2025-04-08 10:24 ` [PATCH 4/9] object-file: split out functions relating to object store subsystem Patrick Steinhardt
2025-04-08 10:24 ` [PATCH 5/9] object-file: split up concerns of `HASH_*` flags Patrick Steinhardt
2025-04-08 10:24 ` [PATCH 6/9] object-file: split out functions relating to index subsystem Patrick Steinhardt
2025-04-08 10:24 ` [PATCH 7/9] object: split out functions relating to object store subsystem Patrick Steinhardt
2025-04-08 10:24 ` [PATCH 8/9] object-store: remove global array of cached objects Patrick Steinhardt
2025-04-08 10:24 ` [PATCH 9/9] object-store: merge "object-store-ll.h" and "object-store.h" Patrick Steinhardt
2025-04-08 23:29 ` [PATCH 0/9] Split up "object-file.c" Junio C Hamano
2025-04-11 9:26 ` Patrick Steinhardt
2025-04-09 14:42 ` Elijah Newren
2025-04-11 9:27 ` Patrick Steinhardt
2025-04-11 9:29 ` [PATCH v2 " Patrick Steinhardt
2025-04-11 9:29 ` [PATCH v2 1/9] object-file: move `safe_create_leading_directories()` into "dir.c" Patrick Steinhardt
2025-04-11 20:09 ` Junio C Hamano
2025-04-11 21:29 ` Eric Sunshine
2025-04-15 9:19 ` Patrick Steinhardt
2025-04-15 15:09 ` Junio C Hamano
2025-04-11 9:29 ` [PATCH v2 2/9] object-file: move `git_open_cloexec()` to "compat/open.c" Patrick Steinhardt
2025-04-11 9:29 ` Patrick Steinhardt [this message]
2025-04-11 9:29 ` [PATCH v2 4/9] object-file: split out functions relating to object store subsystem Patrick Steinhardt
2025-04-11 9:29 ` [PATCH v2 5/9] object-file: split up concerns of `HASH_*` flags Patrick Steinhardt
2025-04-11 9:29 ` [PATCH v2 6/9] object-file: split out functions relating to index subsystem Patrick Steinhardt
2025-04-12 8:17 ` Jeff King
2025-04-14 11:49 ` Junio C Hamano
2025-04-15 9:19 ` Patrick Steinhardt
2025-04-11 9:29 ` [PATCH v2 7/9] object: split out functions relating to object store subsystem Patrick Steinhardt
2025-04-11 9:29 ` [PATCH v2 8/9] object-store: remove global array of cached objects Patrick Steinhardt
2025-04-11 22:58 ` Junio C Hamano
2025-04-15 9:19 ` Patrick Steinhardt
2025-04-11 9:29 ` [PATCH v2 9/9] object-store: merge "object-store-ll.h" and "object-store.h" Patrick Steinhardt
2025-04-15 9:38 ` [PATCH v3 00/10] Split up "object-file.c" Patrick Steinhardt
2025-04-15 9:38 ` [PATCH v3 01/10] object-file: move `mkdir_in_gitdir()` into "path.c" Patrick Steinhardt
2025-04-15 9:38 ` [PATCH v3 02/10] object-file: move `safe_create_leading_directories()` " Patrick Steinhardt
2025-04-15 9:38 ` [PATCH v3 03/10] object-file: move `git_open_cloexec()` to "compat/open.c" Patrick Steinhardt
2025-04-15 9:38 ` [PATCH v3 04/10] object-file: move `xmmap()` into "wrapper.c" Patrick Steinhardt
2025-04-15 9:38 ` [PATCH v3 05/10] object-file: split out functions relating to object store subsystem Patrick Steinhardt
2025-04-15 9:38 ` [PATCH v3 06/10] object-file: split up concerns of `HASH_*` flags Patrick Steinhardt
2025-04-15 9:38 ` [PATCH v3 07/10] object-file: drop `index_blob_stream()` Patrick Steinhardt
2025-04-15 9:38 ` [PATCH v3 08/10] object: split out functions relating to object store subsystem Patrick Steinhardt
2025-04-15 9:38 ` [PATCH v3 09/10] object-store: remove global array of cached objects Patrick Steinhardt
2025-04-15 9:38 ` [PATCH v3 10/10] object-store: merge "object-store-ll.h" and "object-store.h" Patrick Steinhardt
2025-04-16 6:41 ` [PATCH v3 00/10] Split up "object-file.c" Elijah Newren
2025-04-16 7:44 ` Patrick Steinhardt
2025-04-16 16:21 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250411-pks-split-object-file-v2-3-2bea0c9033ae@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=newren@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).