Re: [PATCH v2 1/2] t: add "test-tool genbytes" to avoid slow tr(1) on macOS
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Nov 9, 2026, 01:39 UTC
- Message-ID
- <xmqqeccu3hqq.fsf@gitster.g>
- In-Reply-To
- <54139a3a97127732e11fc5abbc9a3687542669f6.1794165304.git.gitgitgadget@gmail.com>
"Kristofer Karlsson via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 19 quoted lines
> diff --git a/t/helper/test-genbytes.c b/t/helper/test-genbytes.c
> new file mode 100644
> index 0000000000..b760326b24
> --- /dev/null
> +++ b/t/helper/test-genbytes.c
> @@ -0,0 +1,61 @@
> +#define DISABLE_SIGN_COMPARE_WARNINGS
> +
> +#include "test-tool.h"
> +#include "git-compat-util.h"
> +#include "hex-ll.h"
> +
> +/*
> + * Write "count" copies of "byte" to stdout, or an endless stream of them if
> + * "count" is negative.
> + */
> +static int generate_bytes(char byte, intmax_t count)
> +{
> + char buf[256 * 1024];Allocating 256kB on stack may not be a great practice, but this may sufficiently work on most reasonable systems, as this is an internal of a "run once and exit" test helper function.
Still, the stack memory for the primary thread of a process is limited to 8MB or so on modern Linux systems, and I hear macOS also uses 8MB. I am not familiar with Windows, but some documentation found on the Web seems to say that their linker gives 1MB to their product by default, and among 1MB, 256kB is not an insignificant fraction.
Again, this is an internal of a "run once and exit" test helper, so declaring this as "static char buf[]" should not pose an issue; it is not like you would need to have multiple simultaneous invocations of this function, each of which needs to fill this buffer with different values.