summaryrefslogtreecommitdiff
path: root/source/pdf
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2016-02-22 15:43:59 +0000
committerRobin Watts <robin.watts@artifex.com>2016-02-22 16:38:05 +0000
commitd9e8a0720d984f276b391800a4787f71075b5ee2 (patch)
tree73b0d96736bdd4d80a7507b45c488f01c283dbfa /source/pdf
parent8888bd47b3e3cd9089287df2320daccd98852342 (diff)
downloadmupdf-d9e8a0720d984f276b391800a4787f71075b5ee2.tar.xz
Add some helpful debugging code to the mark and sweep code.
Diffstat (limited to 'source/pdf')
-rw-r--r--source/pdf/pdf-write.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/source/pdf/pdf-write.c b/source/pdf/pdf-write.c
index d785f332..86e4ebaf 100644
--- a/source/pdf/pdf-write.c
+++ b/source/pdf/pdf-write.c
@@ -561,36 +561,70 @@ static pdf_obj *markref(fz_context *ctx, pdf_document *doc, pdf_write_state *opt
return obj;
}
+#ifdef DEBUG_MARK_AND_SWEEP
+static int depth = 0;
+
+static
+void indent()
+{
+ while (depth > 0)
+ {
+ int d = depth;
+ if (d > 16)
+ d = 16;
+ printf("%s", &" "[16-d]);
+ depth -= d;
+ }
+}
+#define DEBUGGING_MARKING(A) do { A; } while (0)
+#else
+#define DEBUGGING_MARKING(A) do { } while (0)
+#endif
+
/* Recursively mark an object. If any references found are duff, then
* replace them with nulls. */
static int markobj(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, pdf_obj *obj)
{
int i;
+ DEBUGGING_MARKING(depth++);
+
if (pdf_is_indirect(ctx, obj))
{
int duff;
+ DEBUGGING_MARKING(indent(); printf("Marking object %d\n", pdf_to_num(ctx, obj)));
obj = markref(ctx, doc, opts, obj, &duff);
if (duff)
+ {
+ DEBUGGING_MARKING(depth--);
return 1;
+ }
}
if (pdf_is_dict(ctx, obj))
{
int n = pdf_dict_len(ctx, obj);
for (i = 0; i < n; i++)
+ {
+ DEBUGGING_MARKING(indent(); printf("DICT[%d/%d] = %s\n", i, n, pdf_to_name(ctx, pdf_dict_get_key(ctx, obj, i))));
if (markobj(ctx, doc, opts, pdf_dict_get_val(ctx, obj, i)))
pdf_dict_put_val_drop(ctx, obj, i, pdf_new_null(ctx, doc));
+ }
}
else if (pdf_is_array(ctx, obj))
{
int n = pdf_array_len(ctx, obj);
for (i = 0; i < n; i++)
+ {
+ DEBUGGING_MARKING(indent(); printf("ARRAY[%d/%d]\n", i, n));
if (markobj(ctx, doc, opts, pdf_array_get(ctx, obj, i)))
pdf_array_put_drop(ctx, obj, i, pdf_new_null(ctx, doc));
+ }
}
+ DEBUGGING_MARKING(depth--);
+
return 0;
}