]> git.imager.perl.org - imager.git/blobdiff - Imager.xs
clean up some old junk in log.c
[imager.git] / Imager.xs
index 95c6f8eb1550f0a2af663ca52dfe4d5fb65d9cfd..c47884ec541809af28ee2c1f4dc3b41a3f5acbea 100644 (file)
--- a/Imager.xs
+++ b/Imager.xs
@@ -29,6 +29,69 @@ extern "C" {
 
 #include "imperl.h"
 
+/*
+
+Context object management
+
+*/
+
+typedef im_context_t Imager__Context;
+
+#define im_context_DESTROY(ctx) im_context_refdec((ctx), "DESTROY")
+
+#ifdef PERL_IMPLICIT_CONTEXT
+
+#define MY_CXT_KEY "Imager::_context" XS_VERSION
+
+typedef struct {
+  im_context_t ctx;
+} my_cxt_t;
+
+START_MY_CXT
+
+im_context_t fallback_context;
+
+static void
+start_context(pTHX) {
+  dMY_CXT;
+  MY_CXT.ctx = im_context_new();
+  sv_setref_pv(get_sv("Imager::_context", GV_ADD), "Imager::Context", MY_CXT.ctx);
+
+  /* Ideally we'd free this reference, but the error message memory
+     was never released on exit, so the associated memory here is reasonable
+     to keep.
+     With logging enabled we always need at least one context, since
+     objects may be released fairly late and attempt to get the log file.
+  */
+  im_context_refinc(MY_CXT.ctx, "start_context");
+  fallback_context = MY_CXT.ctx;
+}
+
+static im_context_t
+perl_get_context(void) {
+  dTHX;
+  dMY_CXT;
+  
+  return MY_CXT.ctx ? MY_CXT.ctx : fallback_context;
+}
+
+#else
+
+static im_context_t perl_context;
+
+static void
+start_context(pTHX) {
+  perl_context = im_context_new();
+  im_context_refinc(perl_context, "start_context");
+}
+
+static im_context_t
+perl_get_context(void) {
+  return perl_context;
+}
+
+#endif
+
 /* used to represent channel lists parameters */
 typedef struct i_channel_list_tag {
   int *channels;
@@ -727,7 +790,6 @@ validate_i_ppal(i_img *im, i_palidx const *indexes, int count) {
   }
 }
 
-
 /* I don't think ICLF_* names belong at the C interface
    this makes the XS code think we have them, to let us avoid 
    putting function bodies in the XS code
@@ -1059,6 +1121,14 @@ i_get_image_file_limits()
           PUSHs(sv_2mortal(newSVuv(bytes)));
         }
 
+bool
+i_int_check_image_file_limits(width, height, channels, sample_size)
+       i_img_dim width
+       i_img_dim height
+       int channels
+       size_t sample_size
+  PROTOTYPE: DISABLE
+
 MODULE = Imager                PACKAGE = Imager::IO    PREFIX = io_
 
 Imager::IO
@@ -1401,22 +1471,6 @@ i_list_formats()
                      PUSHs(sv_2mortal(newSVpv(item,0)));
               }
 
-Imager::ImgRaw
-i_img_new()
-
-Imager::ImgRaw
-i_img_empty(im,x,y)
-    Imager::ImgRaw     im
-               i_img_dim     x
-              i_img_dim     y
-
-Imager::ImgRaw
-i_img_empty_ch(im,x,y,ch)
-    Imager::ImgRaw     im
-               i_img_dim     x
-              i_img_dim     y
-              int     ch
-
 Imager::ImgRaw
 i_sametype(im, x, y)
     Imager::ImgRaw im
@@ -1449,14 +1503,6 @@ i_log_entry(string,level)
 int
 i_log_enabled()
 
-void
-i_img_exorcise(im)
-    Imager::ImgRaw     im
-
-void
-i_img_destroy(im)
-    Imager::ImgRaw     im
-
 void
 i_img_info(im)
     Imager::ImgRaw     im
@@ -2051,6 +2097,10 @@ i_convert(src, avmain)
              if (len > inchan)
                inchan = len;
            }
+           else {
+             i_push_errorf(0, "invalid matrix: element %d is not an array ref", j);
+             XSRETURN(0);
+           }
           }
           coeff = mymalloc(sizeof(double) * outchan * inchan);
          for (j = 0; j < outchan; ++j) {
@@ -4005,6 +4055,37 @@ i_int_hlines_CLONE_SKIP(cls)
 
 #endif
 
+MODULE = Imager  PACKAGE = Imager::Context PREFIX=im_context_
+
+void
+im_context_DESTROY(ctx)
+   Imager::Context ctx
+
+#ifdef PERL_IMPLICIT_CONTEXT
+
+void
+im_context_CLONE(...)
+    CODE:
+      MY_CXT_CLONE;
+      (void)items;
+      /* the following sv_setref_pv() will free this inc */
+      im_context_refinc(MY_CXT.ctx, "CLONE");
+      MY_CXT.ctx = im_context_clone(MY_CXT.ctx, "CLONE");
+      sv_setref_pv(get_sv("Imager::_context", GV_ADD), "Imager::Context", MY_CXT.ctx);
+
+#endif
+
 BOOT:
         PERL_SET_GLOBAL_CALLBACKS;
        PERL_PL_SET_GLOBAL_CALLBACKS;
+#ifdef PERL_IMPLICIT_CONTEXT
+       {
+          MY_CXT_INIT;
+         (void)MY_CXT;
+       }
+#endif
+       start_context(aTHX);
+       im_get_context = perl_get_context;
+#ifdef HAVE_LIBTT
+        i_tt_start();
+#endif