[rt #77173] improve error reporting on an API version mismatch
authorTony Cook <tony@develop-help.com>
Thu, 24 May 2012 09:09:41 +0000 (19:09 +1000)
committerTony Cook <tony@develop-help.com>
Thu, 24 May 2012 09:09:41 +0000 (19:09 +1000)
Changes
Imager.pm
imext.h
lib/Imager/API.pod

diff --git a/Changes b/Changes
index 8ffd10b..3049b95 100644 (file)
--- 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
 ===========
 
index ee99409..52d8f37 100644 (file)
--- 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 912b04d..8c42b90 100644 (file)
--- 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
 
index 1096be3..dbe6414 100644 (file)
@@ -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<BOOT> 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