Skip to content

Commit

Permalink
[rt #77173] improve error reporting on an API version mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
tonycoz committed May 24, 2012
1 parent bdd4c63 commit 38742a1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
7 changes: 7 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -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
===========

Expand Down
3 changes: 2 additions & 1 deletion Imager.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 6 additions & 4 deletions imext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions lib/Imager/API.pod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 38742a1

Please sign in to comment.