summaryrefslogtreecommitdiff
path: root/fitz/base_object.c
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2011-12-16 16:26:48 +0000
committerRobin Watts <robin.watts@artifex.com>2011-12-16 16:26:48 +0000
commit09a016ee7c5c81580b27db3bd193b38cb3bd4f0e (patch)
tree90d0fad103f7aa592451f493a3d091ca9db7c866 /fitz/base_object.c
parent1f8cccdeca9cf9082061b40d66fc8201c8b3ce80 (diff)
downloadmupdf-09a016ee7c5c81580b27db3bd193b38cb3bd4f0e.tar.xz
Add fz_malloc_struct, and make code use it.
The new fz_malloc_struct(A,B) macro allocates sizeof(B) bytes using fz_malloc, and then passes the resultant pointer to Memento_label to label it with "B". This costs nothing in non-memento builds, but gives much nicer listings of leaked blocks when memento is enabled.
Diffstat (limited to 'fitz/base_object.c')
-rw-r--r--fitz/base_object.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/fitz/base_object.c b/fitz/base_object.c
index ced40414..a0e3ecc0 100644
--- a/fitz/base_object.c
+++ b/fitz/base_object.c
@@ -57,6 +57,7 @@ fz_obj *
fz_new_null(fz_context *ctx)
{
fz_obj *obj = fz_malloc(ctx, sizeof(fz_obj));
+ Memento_label(obj, "fz_obj(null)");
obj->ctx = ctx;
obj->refs = 1;
obj->kind = FZ_NULL;
@@ -67,6 +68,7 @@ fz_obj *
fz_new_bool(fz_context *ctx, int b)
{
fz_obj *obj = fz_malloc(ctx, sizeof(fz_obj));
+ Memento_label(obj, "fz_obj(bool)");
obj->ctx = ctx;
obj->refs = 1;
obj->kind = FZ_BOOL;
@@ -78,6 +80,7 @@ fz_obj *
fz_new_int(fz_context *ctx, int i)
{
fz_obj *obj = fz_malloc(ctx, sizeof(fz_obj));
+ Memento_label(obj, "fz_obj(int)");
obj->ctx = ctx;
obj->refs = 1;
obj->kind = FZ_INT;
@@ -89,6 +92,7 @@ fz_obj *
fz_new_real(fz_context *ctx, float f)
{
fz_obj *obj = fz_malloc(ctx, sizeof(fz_obj));
+ Memento_label(obj, "fz_obj(real)");
obj->ctx = ctx;
obj->refs = 1;
obj->kind = FZ_REAL;
@@ -100,6 +104,7 @@ fz_obj *
fz_new_string(fz_context *ctx, char *str, int len)
{
fz_obj *obj = fz_malloc(ctx, offsetof(fz_obj, u.s.buf) + len + 1);
+ Memento_label(obj, "fz_obj(string)");
obj->ctx = ctx;
obj->refs = 1;
obj->kind = FZ_STRING;
@@ -113,6 +118,7 @@ fz_obj *
fz_new_name(fz_context *ctx, char *str)
{
fz_obj *obj = fz_malloc(ctx, offsetof(fz_obj, u.n) + strlen(str) + 1);
+ Memento_label(obj, "fz_obj(name)");
obj->ctx = ctx;
obj->refs = 1;
obj->kind = FZ_NAME;
@@ -124,6 +130,7 @@ fz_obj *
fz_new_indirect(fz_context *ctx, int num, int gen, void *xref)
{
fz_obj *obj = fz_malloc(ctx, sizeof(fz_obj));
+ Memento_label(obj, "fz_obj(indirect)");
obj->ctx = ctx;
obj->refs = 1;
obj->kind = FZ_INDIRECT;
@@ -382,6 +389,7 @@ fz_new_array(fz_context *ctx, int initialcap)
int i;
obj = fz_malloc(ctx, sizeof(fz_obj));
+ Memento_label(obj, "fz_obj(array)");
obj->ctx = ctx;
obj->refs = 1;
obj->kind = FZ_ARRAY;
@@ -392,6 +400,7 @@ fz_new_array(fz_context *ctx, int initialcap)
fz_try(ctx)
{
obj->u.a.items = fz_malloc_array(ctx, obj->u.a.cap, sizeof(fz_obj*));
+ Memento_label(obj->u.a.items, "fz_obj(array items)");
}
fz_catch(ctx)
{
@@ -537,6 +546,7 @@ fz_new_dict(fz_context *ctx, int initialcap)
int i;
obj = fz_malloc(ctx, sizeof(fz_obj));
+ Memento_label(obj, "fz_obj(dict)");
obj->ctx = ctx;
obj->refs = 1;
obj->kind = FZ_DICT;
@@ -548,6 +558,7 @@ fz_new_dict(fz_context *ctx, int initialcap)
fz_try(ctx)
{
obj->u.d.items = fz_malloc_array(ctx, obj->u.d.cap, sizeof(struct keyval));
+ Memento_label(obj->u.d.items, "fz_obj(dict items)");
}
fz_catch(ctx)
{