summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2016-03-15 15:41:15 +0000
committerRobin Watts <robin.watts@artifex.com>2016-03-15 16:50:28 +0000
commit15b93459af39a4ac68c055e6184be5db8c2c3aba (patch)
treeb97db67763ab1fcde68d9090151e3e945dbb3a0b
parent3f655259c2a235d742b025a9ee91b57bc1d2da14 (diff)
downloadmupdf-15b93459af39a4ac68c055e6184be5db8c2c3aba.tar.xz
Memento: Add Memento_{takeRef,dropRef,reference} functions.
These work with MEMENTO_DETAILS to allow us to store the events where reference counts change.
-rw-r--r--include/mupdf/memento.h6
-rw-r--r--source/fitz/memento.c53
2 files changed, 57 insertions, 2 deletions
diff --git a/include/mupdf/memento.h b/include/mupdf/memento.h
index 903f00b7..e2ea3562 100644
--- a/include/mupdf/memento.h
+++ b/include/mupdf/memento.h
@@ -222,6 +222,9 @@ void *Memento_calloc(size_t, size_t);
void Memento_info(void *addr);
void Memento_listBLockInfo(void);
+void *Memento_takeRef(void *blk);
+void *Memento_dropRef(void *blk);
+void *Memento_reference(void *blk);
#ifdef MEMENTO
@@ -259,6 +262,9 @@ void Memento_listBLockInfo(void);
#define Memento_label(A,B) (A)
#define Memento_info(A) do {} while (0)
#define Memento_listBlockInfo() do {} while (0)
+#define Memento_takeRef(A) (A)
+#define Memento_dropRef(A) (A)
+#define Memento_reference(A) (A)
#endif /* MEMENTO */
diff --git a/source/fitz/memento.c b/source/fitz/memento.c
index 7e256c10..79a65454 100644
--- a/source/fitz/memento.c
+++ b/source/fitz/memento.c
@@ -182,7 +182,10 @@ enum {
Memento_EventType_new = 4,
Memento_EventType_delete = 5,
Memento_EventType_newArray = 6,
- Memento_EventType_deleteArray = 7
+ Memento_EventType_deleteArray = 7,
+ Memento_EventType_takeRef = 8,
+ Memento_EventType_dropRef = 9,
+ Memento_EventType_reference = 10
};
static const char *eventType[] =
@@ -194,7 +197,10 @@ static const char *eventType[] =
"new",
"delete",
"new[]",
- "delete[]"
+ "delete[]",
+ "takeRef",
+ "dropRef",
+ "reference"
};
/* When we list leaked blocks at the end of execution, we search for pointers
@@ -1659,6 +1665,34 @@ void *Memento_calloc(size_t n, size_t s)
return block;
}
+static void do_reference(Memento_BlkHeader *blk, int event)
+{
+#ifdef MEMENTO_DETAILS
+ Memento_storeDetails(blk, event);
+#endif /* MEMENTO_DETAILS */
+}
+
+void *Memento_takeRef(void *blk)
+{
+ if (blk)
+ do_reference(MEMBLK_FROMBLK(blk), Memento_EventType_takeRef);
+ return blk;
+}
+
+void *Memento_dropRef(void *blk)
+{
+ if (blk)
+ do_reference(MEMBLK_FROMBLK(blk), Memento_EventType_dropRef);
+ return blk;
+}
+
+void *Memento_reference(void *blk)
+{
+ if (blk)
+ do_reference(MEMBLK_FROMBLK(blk), Memento_EventType_reference);
+ return blk;
+}
+
/* Treat blocks from the user with suspicion, and check them the slow
* but safe way. */
static int checkBlockUser(Memento_BlkHeader *memblk, const char *action)
@@ -2208,6 +2242,21 @@ void (Memento_breakOnRealloc)(void *a)
{
}
+void *(Memento_takeRef)(void *a)
+{
+ return a;
+}
+
+void *(Memento_dropRef)(void *a)
+{
+ return a;
+}
+
+void *(Memento_reference)(void *a)
+{
+ return a;
+}
+
#undef Memento_malloc
#undef Memento_free
#undef Memento_realloc