static bool
im_SvREFSCALAR(SV *sv) {
svtype type = SvTYPE(sv);
- return type == SVt_PV || type == SVt_PVIV || type == SVt_PVNV
- || type == SVt_PVMG || type == SVt_IV || type == SVt_NV
- || type == SVt_PVLV || type == SVt_REGEXP;
+
+ switch (type) {
+ case SVt_PV:
+ case SVt_PVIV:
+ case SVt_PVNV:
+ case SVt_PVMG:
+ case SVt_IV:
+ case SVt_NV:
+ case SVt_PVLV:
+#if PERL_VERSION > 10
+ case SVt_REGEXP:
+#endif
+ return 1;
+
+ default:
+ return 0;
+ }
+}
+
+static const char *
+describe_sv(SV *sv) {
+ if (SvOK(sv)) {
+ if (SvROK(sv)) {
+ svtype type = SvTYPE(SvRV(sv));
+ switch (type) {
+ case SVt_PVCV: return "CV";
+ case SVt_PVGV: return "GV";
+ case SVt_PVLV: return "LV";
+ default: return "some reference";
+ }
+ }
+ else {
+ return "non-reference scalar";
+ }
+ }
+ else {
+ return "undef";
+ }
}
static i_io_glue_t *
SvGETMAGIC(data_sv);
if (SvROK(data_sv)) {
- if (im_SvREFSCALAR(data_sv)) {
+ if (im_SvREFSCALAR(SvRV(data_sv))) {
sv = SvRV(data_sv);
}
else {
- i_push_error(0, "data is not a scalar or a reference to scalar");
+ i_push_errorf(0, "data is not a scalar or a reference to scalar");
return NULL;
}
}
return io_new_buffer(data_copy, length, free_buffer, data_copy);
}
-static const char *
-describe_sv(SV *sv) {
- if (SvOK(sv)) {
- if (SvROK(sv)) {
- svtype type = SvTYPE(SvRV(sv));
- switch (type) {
- case SVt_PVCV: return "CV";
- case SVt_PVGV: return "GV";
- case SVt_PVLV: return "LV";
- default: return "some reference";
- }
- }
- else {
- return "non-reference scalar";
- }
- }
- else {
- return "undef";
- }
-}
-
static i_io_glue_t *
do_io_new_cb(pTHX_ SV *writecb, SV *readcb, SV *seekcb, SV *closecb) {
struct cbdata *cbd;
#!perl -w
use strict;
-use Test::More tests => 275;
+use Test::More tests => 287;
use Imager::Test qw(is_image);
# for SEEK_SET etc, Fcntl doesn't provide these in 5.005_03
use IO::Seekable;
{ # pass buffer by reference
my $data = "This is a test";
my $data2 = $data;
- my $io = Imager::IO->new_buffer(\$data2);
+ my $io = Imager::IO->new_buffer(\$data2)
+ or diag "Can't create from SV REF:", Imager->_error_as_msg;
undef $data2;
my $tmp = $io->read2(1000);
is($tmp, $data, "buffer io created by reference");
}
+{
+ my @buffer_tests =
+ (
+ [ 1000, "IV" ],
+ [ 1000.1, "NV" ],
+ [ qr/abcd/, "regexp",
+ $> >= 5.012 && "Can't use regexps as a buffer before 5.14" ],
+ );
+ for my $test (@buffer_tests) {
+ my ($val, $note, $skip) = @$test;
+ SKIP:
+ {
+ $skip and skip $skip, 4;
+ SKIP:
+ {
+ my $temp = $val;
+ my $io = Imager::IO->new_buffer(\$temp);
+ ok($io, "$note/ref: open_buffer")
+ or skip "couldn't open", 1;
+ my $read = $io->read2(1000);
+ is($read, "$val", "$note/ref: read result");
+ }
+
+ SKIP:
+ {
+ my $temp = $val;
+ my $io = Imager::IO->new_buffer($temp);
+ ok($io, "$note: open_buffer")
+ or skip "couldn't open", 1;
+ my $read = $io->read2(1000);
+ is($read, "$val", "$note: read result");
+ }
+ }
+ }
+}
+
Imager->close_log;
unless ($ENV{IMAGER_KEEP_FILES}) {