grep/pcre2: move definitions of pcre2_{malloc,free}

Move the definitions of the pcre2_{malloc,free} functions above the compile_pcre2_pattern() function they're used in. Before the preceding commit they used to be needed earlier, but now we can move them to be adjacent to the other PCREv2 functions. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Feb 18, 2021 at 01:07 UTC c1760352e0b27cfbdffd97dec50a9eb552318993
1 file changed +22 -24
grep.c
+22 -24
@@ -40,30 +40,6 @@ static struct grep_opt grep_defaults = {
40 .output = std_output,
41 };
42
43 -#ifdef USE_LIBPCRE2
44 -#define GREP_PCRE2_DEBUG_MALLOC 0
45 -
46 -static void *pcre2_malloc(PCRE2_SIZE size, MAYBE_UNUSED void *memory_data)
47 -{
48 - void *pointer = malloc(size);
49 -#if GREP_PCRE2_DEBUG_MALLOC
50 - static int count = 1;
51 - fprintf(stderr, "PCRE2:%p -> #%02d: alloc(%lu)\n", pointer, count++, size);
52 -#endif
53 - return pointer;
54 -}
55 -
56 -static void pcre2_free(void *pointer, MAYBE_UNUSED void *memory_data)
57 -{
58 -#if GREP_PCRE2_DEBUG_MALLOC
59 - static int count = 1;
60 - if (pointer)
61 - fprintf(stderr, "PCRE2:%p -> #%02d: free()\n", pointer, count++);
62 -#endif
63 - free(pointer);
64 -}
65 -#endif
66 -
43 static const char *color_grep_slots[] = {
44 [GREP_COLOR_CONTEXT] = "context",
45 [GREP_COLOR_FILENAME] = "filename",
@@ -355,6 +331,28 @@ static int is_fixed(const char *s, size_t len)
331 }
332
333 #ifdef USE_LIBPCRE2
334 +#define GREP_PCRE2_DEBUG_MALLOC 0
335 +
336 +static void *pcre2_malloc(PCRE2_SIZE size, MAYBE_UNUSED void *memory_data)
337 +{
338 + void *pointer = malloc(size);
339 +#if GREP_PCRE2_DEBUG_MALLOC
340 + static int count = 1;
341 + fprintf(stderr, "PCRE2:%p -> #%02d: alloc(%lu)\n", pointer, count++, size);
342 +#endif
343 + return pointer;
344 +}
345 +
346 +static void pcre2_free(void *pointer, MAYBE_UNUSED void *memory_data)
347 +{
348 +#if GREP_PCRE2_DEBUG_MALLOC
349 + static int count = 1;
350 + if (pointer)
351 + fprintf(stderr, "PCRE2:%p -> #%02d: free()\n", pointer, count++);
352 +#endif
353 + free(pointer);
354 +}
355 +
356 static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt)
357 {
358 int error;