Skip to content

Commit c176035

Browse files
avargitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cbe81e6 commit c176035

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

grep.c

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,30 +40,6 @@ static struct grep_opt grep_defaults = {
4040
.output = std_output,
4141
};
4242

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-
6743
static const char *color_grep_slots[] = {
6844
[GREP_COLOR_CONTEXT] = "context",
6945
[GREP_COLOR_FILENAME] = "filename",
@@ -355,6 +331,28 @@ static int is_fixed(const char *s, size_t len)
355331
}
356332

357333
#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+
358356
static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt)
359357
{
360358
int error;

0 commit comments

Comments
 (0)