From 4acb81869069aac93488190ff7f66187de63d00f Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Sat, 8 Jul 2023 14:42:03 +1000 Subject: [PATCH] don't pass "0" as the afm filename if it isn't supplied This came up while debugging #510 and prevents one of the tests from crashing, but doesn't fix the underlying problem that that build of t1lib is crashing when an afm filename is supplied. --- T1/T1.pm | 27 ++++++++++++++------------- T1/T1.xs | 6 ++++-- T1/typemap | 7 +++++++ 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/T1/T1.pm b/T1/T1.pm index fa67a19a..3b701b6c 100644 --- a/T1/T1.pm +++ b/T1/T1.pm @@ -6,7 +6,7 @@ our @ISA = qw(Imager::Font); use Scalar::Util (); BEGIN { - our $VERSION = "1.029"; + our $VERSION = "1.030"; require XSLoader; XSLoader::load('Imager::Font::T1', $VERSION); @@ -42,18 +42,19 @@ sub new { $hsh{file} = './' . $hsh{file}; } - if($hsh{afm}) { - unless (-e $hsh{afm}) { - $Imager::ERRSTR = "Afm file $hsh{afm} not found"; - return; - } - unless ($hsh{afm} =~ m!^/! - || $hsh{afm} =~ m!^\./! - || $^O =~ /^(MSWin32|cygwin)$/ && $hsh{file} =~ /^[a-z]:/i) { - $hsh{file} = './' . $hsh{file}; - } - } else { - $hsh{afm} = 0; + if(defined $hsh{afm} && length $hsh{afm}) { + unless (-e $hsh{afm}) { + $Imager::ERRSTR = "Afm file $hsh{afm} not found"; + return; + } + unless ($hsh{afm} =~ m!^/! + || $hsh{afm} =~ m!^\./! + || $^O =~ /^(MSWin32|cygwin)$/ && $hsh{file} =~ /^[a-z]:/i) { + $hsh{file} = './' . $hsh{file}; + } + } + else { + $hsh{afm} = undef; } my $font = Imager::Font::T1xs->new($hsh{file},$hsh{afm}); diff --git a/T1/T1.xs b/T1/T1.xs index ff30c958..fb6eafcc 100644 --- a/T1/T1.xs +++ b/T1/T1.xs @@ -15,6 +15,8 @@ typedef i_t1_font_t Imager__Font__T1xs; #define i_t1_DESTROY(font) i_t1_destroy(font) +typedef char * possible_str; + MODULE = Imager::Font::T1 PACKAGE = Imager::Font::T1 undef_int @@ -25,8 +27,8 @@ MODULE = Imager::Font::T1 PACKAGE = Imager::Font::T1xs PREFIX = i_t1_ Imager::Font::T1xs i_t1_new(class,pfb,afm) - char* pfb - char* afm + char* pfb + possible_str afm C_ARGS: pfb, afm diff --git a/T1/typemap b/T1/typemap index 95e197e0..14040d1d 100644 --- a/T1/typemap +++ b/T1/typemap @@ -1 +1,8 @@ Imager::Font::T1xs T_PTROBJ +possible_str T_POSSIBLESTR + +INPUT + +T_POSSIBLESTR + SvGETMAGIC($arg); + $var = SvOK($arg) ? SvPV_nomg_nolen($arg) : NULL;