From d1f5892c122cd93e9be46cd4dddd031a85102c4f Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Tue, 21 Feb 2006 00:57:24 +0000 Subject: [PATCH] - added version/level to the API function table structure --- Changes | 1 + imext.c | 3 +++ imext.h | 14 +++++++++++++- imexttypes.h | 21 +++++++++++++++++++++ lib/Imager/APIRef.pm | 36 ++++++++++++++++++------------------ 5 files changed, 56 insertions(+), 19 deletions(-) diff --git a/Changes b/Changes index ddd64575..e9e7f5b5 100644 --- 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 670e771c..52e8d260 100644 --- 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 85a6e249..b54dbb84 100644 --- 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 diff --git a/imexttypes.h b/imexttypes.h index 892985d8..a7ff20c6 100644 --- a/imexttypes.h +++ b/imexttypes.h @@ -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" diff --git a/lib/Imager/APIRef.pm b/lib/Imager/APIRef.pm index f4425490..8aaadf4f 100644 --- a/lib/Imager/APIRef.pm +++ b/lib/Imager/APIRef.pm @@ -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 -- 2.39.5