Skip to content

Commit a39b400

Browse files
avargitster
authored andcommitted
grep/pcre2: add GREP_PCRE2_DEBUG_MALLOC debug mode
Add optional printing of PCREv2 allocations to stderr for a developer who manually changes the GREP_PCRE2_DEBUG_MALLOC definition to "1". You need to manually change the definition in the source file similar to the DEBUG_MAILMAP, there's no Makefile knob for this. This will be referenced a subsequent commit, and is generally useful to manually see what's going on with PCREv2 allocations while working on that code. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 588e4fb commit a39b400

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

grep.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,25 @@ static struct grep_opt grep_defaults = {
4242

4343
#ifdef USE_LIBPCRE2
4444
static pcre2_general_context *pcre2_global_context;
45+
#define GREP_PCRE2_DEBUG_MALLOC 0
4546

4647
static void *pcre2_malloc(PCRE2_SIZE size, MAYBE_UNUSED void *memory_data)
4748
{
4849
void *pointer = malloc(size);
50+
#if GREP_PCRE2_DEBUG_MALLOC
51+
static int count = 1;
52+
fprintf(stderr, "PCRE2:%p -> #%02d: alloc(%lu)\n", pointer, count++, size);
53+
#endif
4954
return pointer;
5055
}
5156

5257
static void pcre2_free(void *pointer, MAYBE_UNUSED void *memory_data)
5358
{
59+
#if GREP_PCRE2_DEBUG_MALLOC
60+
static int count = 1;
61+
if (pointer)
62+
fprintf(stderr, "PCRE2:%p -> #%02d: free()\n", pointer, count++);
63+
#endif
5464
free(pointer);
5565
}
5666
#endif

0 commit comments

Comments
 (0)