]> git.imager.perl.org - imager.git/commitdiff
- added version/level to the API function table structure
authorTony Cook <tony@develop=help.com>
Tue, 21 Feb 2006 00:57:24 +0000 (00:57 +0000)
committerTony Cook <tony@develop=help.com>
Tue, 21 Feb 2006 00:57:24 +0000 (00:57 +0000)
Changes
imext.c
imext.h
imexttypes.h
lib/Imager/APIRef.pm

diff --git a/Changes b/Changes
index ddd6457575513aae6c6ab0766f34d8c1f93e230b..e9e7f5b5a680e3e5c8cce5469e4b941be23e8e84 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1360,6 +1360,7 @@ Revision history for Perl extension Imager.
 - IM_DEBUG_MALLOC wasn't interacting well with the API
 - make win32.c const happy
 - make raw.c C89 compliant
+- added version/level to the API function table structure
 
 =================================================================
 
diff --git a/imext.c b/imext.c
index 670e771cba0b0ba15c0ac4de9d874020e1e1ebf2..52e8d26099f654932d69be3a8b40cc600494eb93 100644 (file)
--- a/imext.c
+++ b/imext.c
@@ -6,6 +6,9 @@
 */
 im_ext_funcs imager_function_table =
   {
+    IMAGER_API_VERSION,
+    IMAGER_API_LEVEL,
+
     mymalloc,
     myfree,
     myrealloc,
diff --git a/imext.h b/imext.h
index 85a6e2491d2feae5a4a8e0e8426d574658c2dcb8..b54dbb84e316ec5712d1532f70f3e2d49884b69f 100644 (file)
--- a/imext.h
+++ b/imext.h
@@ -7,8 +7,20 @@ extern im_ext_funcs *imager_function_ext_table;
 
 #define DEFINE_IMAGER_CALLBACKS im_ext_funcs *imager_function_ext_table
 
+#ifndef IMAGER_MIN_API_LEVEL
+#define IMAGER_MIN_API_LEVEL IMAGER_API_LEVEL
+#endif
+
 #define PERL_INITIALIZE_IMAGER_CALLBACKS \
-  imager_function_ext_table = INT2PTR(im_ext_funcs *, SvIV(get_sv(PERL_FUNCTION_TABLE_NAME, 1)))
+  do {  \
+    imager_function_ext_table = INT2PTR(im_ext_funcs *, SvIV(get_sv(PERL_FUNCTION_TABLE_NAME, 1))); \
+    if (!imager_function_ext_table) \
+      croak("Imager API function table not found!"); \
+    if (imager_function_ext_table->version != IMAGER_API_VERSION) \
+      croak("Imager API version incorrect"); \
+    if (imager_function_ext_table->level < IMAGER_MIN_API_LEVEL) \
+      croak("API level %d below minimum of %d", imager_function_ext_table->level, IMAGER_MIN_API_LEVEL); \
+  } while (0)
 
 /* just for use here */
 #define im_extt imager_function_ext_table
index 892985d81fc69eb77b1ad84aa10d9dbeb6d5e771..a7ff20c655da4c4719c9341efb605349debf589e 100644 (file)
@@ -5,7 +5,26 @@
 
 #include "imdatatypes.h"
 
+/*
+ IMAGER_API_VERSION is similar to the version number in the third and
+ fourth bytes of TIFF files - if it ever changes then the API has changed
+ too much for any application to remain compatible.
+*/
+#define IMAGER_API_VERSION 1
+
+/*
+ IMAGER_API_LEVEL is the level of the structure.  New function pointers
+ will always remain at the end (unless IMAGER_API_VERSION changes), and
+ will result in an increment of IMAGER_API_LEVEL.
+*/
+
+#define IMAGER_API_LEVEL 1
+
 typedef struct {
+  int version;
+  int level;
+
+  /* IMAGER_API_LEVEL 1 functions */
   void * (*f_mymalloc)(int size);
   void (*f_myfree)(void *block);
   void * (*f_myrealloc)(void *block, size_t newsize);
@@ -115,6 +134,8 @@ typedef struct {
   void (*f_i_copyto_trans)(i_img *im, i_img *src, int x1, int y1, int x2, int y2, int tx, int ty, const i_color *trans);
   i_img *(*f_i_copy)(i_img *im);
   int (*f_i_rubthru)(i_img *im, i_img *src, int tx, int ty, int src_minx, int src_miny, int src_maxx, int src_maxy);
+
+  /* IMAGER_API_LEVEL 2 functions will be added here */
 } im_ext_funcs;
 
 #define PERL_FUNCTION_TABLE_NAME "Imager::__ext_func_table"
index f4425490ba167eedec1041f0c85026a54cd0d064..8aaadf4fa65df762db630371a105e7d421c10d04 100644 (file)
@@ -161,7 +161,7 @@ Returns the number of pixels retrieved.
 
 
 =for comment
-From: Line 199 in imext.c
+From: Line 202 in imext.c
 
 =item i_glinf(im, l, r, y, colors)
 
@@ -173,7 +173,7 @@ Returns the number of pixels retrieved.
 
 
 =for comment
-From: Line 234 in imext.c
+From: Line 237 in imext.c
 
 =item i_gpal(im, x, r, y, indexes)
 
@@ -187,7 +187,7 @@ Always returns 0 for direct color images.
 
 
 =for comment
-From: Line 298 in imext.c
+From: Line 301 in imext.c
 
 =item i_gpix(im, x, y, color)
 
@@ -198,7 +198,7 @@ Returns 0 if the pixel was retrieved, or -1 if not.
 
 
 =for comment
-From: Line 127 in imext.c
+From: Line 130 in imext.c
 
 =item i_gpixf(im, x, y, fcolor)
 
@@ -210,7 +210,7 @@ Returns 0 if the pixel was retrieved, or -1 if not.
 
 
 =for comment
-From: Line 163 in imext.c
+From: Line 166 in imext.c
 
 =item i_gsamp(im, l, r, y, samp, chans, chan_count)
 
@@ -227,7 +227,7 @@ chan_count)
 
 
 =for comment
-From: Line 252 in imext.c
+From: Line 255 in imext.c
 
 =item i_gsampf(im, l, r, y, samp, chans, chan_count)
 
@@ -244,7 +244,7 @@ chan_count)
 
 
 =for comment
-From: Line 275 in imext.c
+From: Line 278 in imext.c
 
 =item i_line(im, x1, y1, x2, y2, val, endp)
 
@@ -284,7 +284,7 @@ Returns the number of pixels set.
 
 
 =for comment
-From: Line 181 in imext.c
+From: Line 184 in imext.c
 
 =item i_plinf(im, l, r, fcolors)
 
@@ -296,7 +296,7 @@ Returns the number of pixels set.
 
 
 =for comment
-From: Line 216 in imext.c
+From: Line 219 in imext.c
 
 =item i_ppal(im, x, r, y, indexes)
 
@@ -310,7 +310,7 @@ Always returns 0 for direct color images.
 
 
 =for comment
-From: Line 317 in imext.c
+From: Line 320 in imext.c
 
 =item i_ppix(im, x, y, color)
 
@@ -324,7 +324,7 @@ color to the image.
 
 
 =for comment
-From: Line 107 in imext.c
+From: Line 110 in imext.c
 
 =item i_ppixf(im, x, y, fcolor)
 
@@ -338,7 +338,7 @@ color to the image.
 
 
 =for comment
-From: Line 144 in imext.c
+From: Line 147 in imext.c
 
 
 =back
@@ -715,7 +715,7 @@ Always fails for direct color images.
 
 
 =for comment
-From: Line 336 in imext.c
+From: Line 339 in imext.c
 
 =item i_colorcount(im)
 
@@ -726,7 +726,7 @@ Returns -1 for direct images.
 
 
 =for comment
-From: Line 382 in imext.c
+From: Line 385 in imext.c
 
 =item i_findcolor(im, color, &entry)
 
@@ -741,7 +741,7 @@ Always fails on direct color images.
 
 
 =for comment
-From: Line 417 in imext.c
+From: Line 420 in imext.c
 
 =item i_getcolors(im, index, colors, count)
 
@@ -760,7 +760,7 @@ palette.
 
 
 =for comment
-From: Line 357 in imext.c
+From: Line 360 in imext.c
 
 =item i_maxcolors(im)
 
@@ -772,7 +772,7 @@ Returns -1 for direct color images.
 
 
 =for comment
-From: Line 399 in imext.c
+From: Line 402 in imext.c
 
 =item i_setcolors(im, index, colors, count)
 
@@ -790,7 +790,7 @@ Always fails on direct color images.
 
 
 =for comment
-From: Line 437 in imext.c
+From: Line 440 in imext.c
 
 
 =back