git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 3/9] object-file: move `xmmap()` into "wrapper.c"

From
Elijah Newren <newren@gmail.com>
Date
Apr 9, 2025, 14:36 UTC
Message-ID
<CABPp-BFL+4=vggNR8unMR9-TN04NmzqBqtd+sM1J27k70DMFGA@mail.gmail.com>
In-Reply-To
<20250408-pks-split-object-file-v1-3-f1fd50191143@pks.im>
On Tue, Apr 8, 2025 at 3:33 AM Patrick Steinhardt <ps@pks.im> wrote:
>
> The `xmmap()` function is provided by "object-file.c" even though its
> functionality got nothing to do with the object file subsystem. Move it
s/got/has/ ?
Show 128 quoted lines
> 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.682.gc9b6a7b2b0.dirty
>
>
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 10 of 53 in “Split up "object-file.c"”
  1. 0/9 Split up "object-file.c"Patrick Steinhardt, Apr 8, 2025
  2. 1/9 object-file: move `safe_create_leading_directories()` into "dir.c"Patrick Steinhardt, Apr 8, 2025
  3. Elijah NewrenApr 9, 2025
  4. Patrick SteinhardtApr 11, 2025
  5. Elijah NewrenApr 11, 2025
  6. Patrick SteinhardtApr 15, 2025
  7. Junio C HamanoApr 15, 2025
  8. 2/9 object-file: move `git_open_cloexec()` to "compat/open.c"Patrick Steinhardt, Apr 8, 2025
  9. 3/9 object-file: move `xmmap()` into "wrapper.c"Patrick Steinhardt, Apr 8, 2025
  10. Elijah NewrenApr 9, 2025
  11. 4/9 object-file: split out functions relating to object store subsystemPatrick Steinhardt, Apr 8, 2025
  12. 5/9 object-file: split up concerns of `HASH_*` flagsPatrick Steinhardt, Apr 8, 2025
  13. 6/9 object-file: split out functions relating to index subsystemPatrick Steinhardt, Apr 8, 2025
  14. 7/9 object: split out functions relating to object store subsystemPatrick Steinhardt, Apr 8, 2025
  15. 8/9 object-store: remove global array of cached objectsPatrick Steinhardt, Apr 8, 2025
  16. 9/9 object-store: merge "object-store-ll.h" and "object-store.h"Patrick Steinhardt, Apr 8, 2025
  17. Junio C HamanoApr 8, 2025
  18. Patrick SteinhardtApr 11, 2025
  19. Elijah NewrenApr 9, 2025
  20. Patrick SteinhardtApr 11, 2025
  21. 0/9 Split up "object-file.c"Patrick Steinhardt, Apr 11, 2025
  22. 1/9 object-file: move `safe_create_leading_directories()` into "dir.c"Patrick Steinhardt, Apr 11, 2025
  23. Junio C HamanoApr 11, 2025
  24. Eric SunshineApr 11, 2025
  25. Patrick SteinhardtApr 15, 2025
  26. Junio C HamanoApr 15, 2025
  27. 2/9 object-file: move `git_open_cloexec()` to "compat/open.c"Patrick Steinhardt, Apr 11, 2025
  28. 3/9 object-file: move `xmmap()` into "wrapper.c"Patrick Steinhardt, Apr 11, 2025
  29. 4/9 object-file: split out functions relating to object store subsystemPatrick Steinhardt, Apr 11, 2025
  30. 5/9 object-file: split up concerns of `HASH_*` flagsPatrick Steinhardt, Apr 11, 2025
  31. 6/9 object-file: split out functions relating to index subsystemPatrick Steinhardt, Apr 11, 2025
  32. Jeff KingApr 12, 2025
  33. Junio C HamanoApr 14, 2025
  34. Patrick SteinhardtApr 15, 2025
  35. 7/9 object: split out functions relating to object store subsystemPatrick Steinhardt, Apr 11, 2025
  36. 8/9 object-store: remove global array of cached objectsPatrick Steinhardt, Apr 11, 2025
  37. Junio C HamanoApr 11, 2025
  38. Patrick SteinhardtApr 15, 2025
  39. 9/9 object-store: merge "object-store-ll.h" and "object-store.h"Patrick Steinhardt, Apr 11, 2025
  40. 00/10 Split up "object-file.c"Patrick Steinhardt, Apr 15, 2025
  41. 01/10 object-file: move `mkdir_in_gitdir()` into "path.c"Patrick Steinhardt, Apr 15, 2025
  42. 02/10 object-file: move `safe_create_leading_directories()` into "path.c"Patrick Steinhardt, Apr 15, 2025
  43. 03/10 object-file: move `git_open_cloexec()` to "compat/open.c"Patrick Steinhardt, Apr 15, 2025
  44. 04/10 object-file: move `xmmap()` into "wrapper.c"Patrick Steinhardt, Apr 15, 2025
  45. 05/10 object-file: split out functions relating to object store subsystemPatrick Steinhardt, Apr 15, 2025
  46. 06/10 object-file: split up concerns of `HASH_*` flagsPatrick Steinhardt, Apr 15, 2025
  47. 07/10 object-file: drop `index_blob_stream()`Patrick Steinhardt, Apr 15, 2025
  48. 08/10 object: split out functions relating to object store subsystemPatrick Steinhardt, Apr 15, 2025
  49. 09/10 object-store: remove global array of cached objectsPatrick Steinhardt, Apr 15, 2025
  50. 10/10 object-store: merge "object-store-ll.h" and "object-store.h"Patrick Steinhardt, Apr 15, 2025
  51. Elijah NewrenApr 16, 2025
  52. Patrick SteinhardtApr 16, 2025
  53. Junio C HamanoApr 16, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.