From: Tony Cook Date: Thu, 24 May 2012 09:09:41 +0000 (+1000) Subject: [rt #77173] improve error reporting on an API version mismatch X-Git-Tag: v0.91~7 X-Git-Url: http://git.imager.perl.org/imager.git/commitdiff_plain/38742a130cd34135e9927f55575cf10f93ef1601 [rt #77173] improve error reporting on an API version mismatch --- diff --git a/Changes b/Changes index 8ffd10b9..3049b95d 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,13 @@ Imager release history. Older releases can be found in Changes.old - eliminate the old IIM_new(), IIM_DESTROY() names from Imager's internals, those names only matter for the XS interface. + - improve error reporting when PERL_INITIALIZE_IMAGER_CALLBACKS finds + the API level compiled into a loadable module such as + Imager::File::GIF doesn't match that of Imager. Previously it + could be difficult to determine exactly which module was failing to + load. + https://rt.cpan.org/Ticket/Display.html?id=77173 + Imager 0.90 - 30 Apr 2012 =========== diff --git a/Imager.pm b/Imager.pm index ee99409f..52d8f372 100644 --- a/Imager.pm +++ b/Imager.pm @@ -1605,10 +1605,11 @@ sub _load_file { return 1; } else { - my $work = $@ || "Unknown error loading $file"; + my $work = $@ || "Unknown error"; chomp $work; $work =~ s/\n?Compilation failed in require at .*Imager\.pm line .*\z//m; $work =~ s/\n/\\n/g; + $work =~ s/\s*\.?\z/ loading $file/; $file_load_errors{$file} = $work; $$error = $work; return 0; diff --git a/imext.h b/imext.h index 912b04d3..8c42b903 100644 --- a/imext.h +++ b/imext.h @@ -12,19 +12,21 @@ extern im_ext_funcs *imager_function_ext_table; #define IMAGER_MIN_API_LEVEL IMAGER_API_LEVEL #endif -#define PERL_INITIALIZE_IMAGER_CALLBACKS \ +#define PERL_INITIALIZE_IMAGER_CALLBACKS_NAME(name) \ 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 loaded %d vs expected %d", \ - imager_function_ext_table->version, IMAGER_API_VERSION); \ + croak("Imager API version incorrect loaded %d vs expected %d in %s", \ + imager_function_ext_table->version, IMAGER_API_VERSION, (name)); \ } \ 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); \ + croak("API level %d below minimum of %d in %s", imager_function_ext_table->level, IMAGER_MIN_API_LEVEL, (name)); \ } while (0) +#define PERL_INITIALIZE_IMAGER_CALLBACKS PERL_INITIALIZE_IMAGER_CALLBACKS_NAME(__FILE__) + /* just for use here */ #define im_extt imager_function_ext_table diff --git a/lib/Imager/API.pod b/lib/Imager/API.pod index 1096be3d..dbe6414b 100644 --- a/lib/Imager/API.pod +++ b/lib/Imager/API.pod @@ -14,7 +14,10 @@ Imager::API - Imager's C API - introduction. ... BOOT: + /* any release with the API */ PERL_INITIALIZE_IMAGER_CALLBACKS; + /* preferred from Imager 0.91 */ + PERL_INITIALIZE_IMAGER_CALLBACKS_NAME("My::Module"); =head1 DESCRIPTION @@ -189,6 +192,12 @@ initialize the callback table in your C code: BOOT: PERL_INITIALIZE_IMAGER_CALLBACKS; +From Imager 0.91 you can supply your module name to improve error +reporting: + + BOOT: + PERL_INITIALIZE_IMAGER_CALLBACKS_NAME("My::Module"); + =back =head2 foo.c