summaryrefslogtreecommitdiff
path: root/grep.c
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2021-02-18 00:07:23 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-02-18 00:32:19 (GMT)
commita39b4003f0e4515da5d88480c24ec27196dabfb7 (patch)
tree60f6ebbb791e8a95922c46c596b33f5b0107262b /grep.c
parent588e4fb19190c03319a2b67d447dd40f97d85531 (diff)
downloadgit-a39b4003f0e4515da5d88480c24ec27196dabfb7.zip
git-a39b4003f0e4515da5d88480c24ec27196dabfb7.tar.gz
git-a39b4003f0e4515da5d88480c24ec27196dabfb7.tar.bz2
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 <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'grep.c')
-rw-r--r--grep.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/grep.c b/grep.c
index f96d86c..7d262a2 100644
--- a/grep.c
+++ b/grep.c
@@ -42,15 +42,25 @@ static struct grep_opt grep_defaults = {
#ifdef USE_LIBPCRE2
static pcre2_general_context *pcre2_global_context;
+#define GREP_PCRE2_DEBUG_MALLOC 0
static void *pcre2_malloc(PCRE2_SIZE size, MAYBE_UNUSED void *memory_data)
{
void *pointer = malloc(size);
+#if GREP_PCRE2_DEBUG_MALLOC
+ static int count = 1;
+ fprintf(stderr, "PCRE2:%p -> #%02d: alloc(%lu)\n", pointer, count++, size);
+#endif
return pointer;
}
static void pcre2_free(void *pointer, MAYBE_UNUSED void *memory_data)
{
+#if GREP_PCRE2_DEBUG_MALLOC
+ static int count = 1;
+ if (pointer)
+ fprintf(stderr, "PCRE2:%p -> #%02d: free()\n", pointer, count++);
+#endif
free(pointer);
}
#endif