]> git.imager.perl.org - imager.git/commitdiff
adding tracing for the slot APIs
authorTony Cook <tony@develop-help.com>
Mon, 17 Sep 2012 09:34:12 +0000 (19:34 +1000)
committerTony Cook <tony@develop-help.com>
Mon, 17 Sep 2012 09:34:12 +0000 (19:34 +1000)
FT2/freetyp2.c
context.c
fontft1.c
imager.h
imext.h
imexttypes.h
lib/Imager/API.pod
lib/Imager/APIRef.pod
t/t82inline.t

index c6aa727038d426603ab12672820d45357fa36c6a..c1e6ed540ae34075c859be0076a7e344f27cdffb 100644 (file)
@@ -65,7 +65,7 @@ static i_img_dim i_max(i_img_dim a, i_img_dim b);
 void
 i_ft2_start(void) {
   if (slot == -1)
-    slot = im_context_slot_new(ft2_final);
+    slot = im_context_slot_new(ft2_final, "FT2");
 }
 
 /*
index cab65a9fc6ab7bb80e043493e43335ff93ba3622..3e0ab769fa52fbd9842c1f1b0b64f755ed3436ab 100644 (file)
--- a/context.c
+++ b/context.c
@@ -189,7 +189,7 @@ im_context_clone(im_context_t ctx, const char *where) {
 }
 
 /*
-=item im_context_slot_new(destructor)
+=item im_context_slot_new(destructor, where)
 
 Allocate a new context-local-storage slot.
 
@@ -197,7 +197,7 @@ Allocate a new context-local-storage slot.
 */
 
 im_slot_t
-im_context_slot_new(im_slot_destroy_t destructor) {
+im_context_slot_new(im_slot_destroy_t destructor, const char *where) {
   im_slot_t new_slot;
   im_slot_destroy_t *new_destructors;
   if (!slot_mutex)
@@ -213,6 +213,11 @@ im_context_slot_new(im_slot_destroy_t destructor) {
 
   slot_destructors[new_slot] = destructor;
 
+#ifdef IMAGER_TRACE_CONTEXT
+  fprintf(stderr, "im_context: slot %d allocated for %s\n",
+         (int)new_slot, where);
+#endif
+
   i_mutex_unlock(slot_mutex);
 
   return new_slot;
@@ -257,6 +262,11 @@ im_context_slot_set(im_context_t ctx, im_slot_t slot, void *value) {
 
   ctx->slots[slot] = value;
 
+#ifdef IMAGER_TRACE_CONTEXT
+  fprintf(stderr, "im_context: ctx %p slot %d set to %p\n",
+         ctx, (int)slot, value);
+#endif
+
   return 1;
 }
 
@@ -280,5 +290,10 @@ im_context_slot_get(im_context_t ctx, im_slot_t slot) {
   if (slot >= ctx->slot_alloc)
     return NULL;
 
+#ifdef IMAGER_TRACE_CONTEXT
+  fprintf(stderr, "im_context: ctx %p slot %d retrieved as %p\n",
+         ctx, (int)slot, ctx->slots[slot]);
+#endif
+
   return ctx->slots[slot];
 }
index e0332f1262aa5a4c003971387d25322c7951022f..591d68b8cd336ac3a486cc6d94e77d75f7d7e1ef 100644 (file)
--- a/fontft1.c
+++ b/fontft1.c
@@ -150,9 +150,8 @@ static int  LTT_hinted = 1;  /* FIXME: this too */
 
 void
 i_tt_start(void) {
-  im_context_t ctx = im_get_context();
   if (slot == -1)
-    slot = im_context_slot_new(i_tt_uninit);
+    slot = im_context_slot_new(i_tt_uninit, "TT");
 }
 
 
index 087a0e9a3981a4be4b11d21f57c1bdef7d4b3eb6..a62c6761f5f579b596fcd9e1cb02eaeec7c6862c 100644 (file)
--- a/imager.h
+++ b/imager.h
@@ -386,7 +386,7 @@ extern im_context_t im_context_new(void);
 extern void im_context_refinc(im_context_t ctx, const char *where);
 extern void im_context_refdec(im_context_t ctx, const char *where);
 extern im_context_t im_context_clone(im_context_t ctx, const char *where);
-extern im_slot_t im_context_slot_new(im_slot_destroy_t);
+extern im_slot_t im_context_slot_new(im_slot_destroy_t, const char *);
 extern void *im_context_slot_get(im_context_t ctx, im_slot_t slot);
 extern int im_context_slot_set(im_context_t ctx, im_slot_t slot, void *);
 
diff --git a/imext.h b/imext.h
index 6e834b25b3cea13de297ded1e37b1b00d644a892..3cab9e32ceb60b20fc1b974aa3c1d344039aab4e 100644 (file)
--- a/imext.h
+++ b/imext.h
@@ -232,7 +232,7 @@ extern im_ext_funcs *imager_function_ext_table;
 #define i_mutex_lock(m) ((im_extt->f_i_mutex_lock)(m))
 #define i_mutex_unlock(m) ((im_extt->f_i_mutex_unlock)(m))
 
-#define im_context_slot_new(destructor) ((im_extt->f_im_context_slot_new)(destructor))
+#define im_context_slot_new(destructor, where) ((im_extt->f_im_context_slot_new)((destructor), (where)))
 #define im_context_slot_get(ctx, slot) ((im_extt->f_im_context_slot_get)((ctx), (slot)))
 #define im_context_slot_set(ctx, slot, value) ((im_extt->f_im_context_slot_set)((ctx), (slot), (value)))
 
index 673aded2b9a486c864f58c053829af0de2ebddb3..b92d4ee82bd75150216ae38aeb5deb1454f9aae1 100644 (file)
@@ -232,7 +232,7 @@ typedef struct {
   void (*f_i_mutex_destroy)(i_mutex_t m);
   void (*f_i_mutex_lock)(i_mutex_t m);
   void (*f_i_mutex_unlock)(i_mutex_t m);
-  im_slot_t (*f_im_context_slot_new)(im_slot_destroy_t);
+  im_slot_t (*f_im_context_slot_new)(im_slot_destroy_t, const char *);
   int (*f_im_context_slot_set)(im_context_t, im_slot_t, void *);
   void *(*f_im_context_slot_get)(im_context_t, im_slot_t);
 } im_ext_funcs;
index 2f49ef5a06dd96d5ef23c1b49832d54826302b4e..80c7265533d9a5980d60215461dfbe8c94a41025 100644 (file)
@@ -447,10 +447,11 @@ Imager provides simple APIs for storing per-context information.
 
 To allocate a slot:
 
-  im_slot_t slot = im_context_slot_new(callback)
+  im_slot_t slot = im_context_slot_new(callback, where)
 
-where callback is a (possibly NULL) function pointer called when the
-context object is destroyed.
+where I<callback> is a (possibly NULL) function pointer called when
+the context object is destroyed, and I<where> is a brief description
+of what the slot is used for.
 
 By default, the stored value for a slot is NULL, whether for a new
 context or for a cloned context.
index e0341e1af74d265e8697b8a92f05d282aaa20d12..e6ba91806e713c8a158e90c645d15c5a5f9c73c4 100644 (file)
@@ -2302,7 +2302,7 @@ object.
 =for comment
 From: File context.c
 
-=item im_context_slot_new(destructor)
+=item im_context_slot_new(destructor, where)
 
 Allocate a new context-local-storage slot.
 
index 2a462b5196622cf61f956e3f204d3e5d66fbcc99..8746bb499c3d267a26e89b29d32d3e49e8ace065 100644 (file)
@@ -422,7 +422,7 @@ test_mutex() {
 
 int
 test_slots() {
-  im_slot_t slot = im_context_slot_new(NULL);
+  im_slot_t slot = im_context_slot_new(NULL, "t82inline");
 
   if (im_context_slot_get(aIMCTX, slot)) {
     fprintf(stderr, "slots should default to NULL\n");