Skip to content

Commit

Permalink
Refactor ->slurp XS
Browse files Browse the repository at this point in the history
  • Loading branch information
karpet committed Jun 3, 2024
1 parent 3cd6dea commit cf1b985
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
9 changes: 5 additions & 4 deletions bindings/perl/3.xs
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,14 @@ slurp(self, filename, ...)
else {
buf = swish_io_slurp_file_len((xmlChar*)filename, buflen, binmode);
}
RETVAL = newSV(0);
// warn("%s re-using SV with strlen %d\n", filename, (int)buflen);
if (buf[buflen] != '\0') {
croak("Buffer was not NUL-terminated (buflen=%d)\n", (int)buflen);
}
sv_usepvn_flags(RETVAL, (char*)buf, buflen, SV_SMAGIC | SV_HAS_TRAILING_NUL);
swish_memcount_dec(); // must do manually since Perl will free() buf
// copy our buf into a new SV
// this is somewhat inefficient in terms of malloc/free, but re-using our pointer
// is buggy on some Perls.
RETVAL = newSVpvn(buf, buflen);
swish_xfree(buf);

OUTPUT:
RETVAL
Expand Down
3 changes: 3 additions & 0 deletions bindings/perl/Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Revision history for SWISH::3, libswish3 Perl bindings.

1.000016 xxx
- slurp() now creates new SV with copy of C string rather than re-using C pointer.

1.000015 01 April 2017
- segfault fix in libswish3.c via https://github.com/karpet/libswish3/pull/1
- fix Perl test failures related to null-termination of re-used char* pointer in SV*.
Expand Down
2 changes: 1 addition & 1 deletion bindings/perl/lib/SWISH/3.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use 5.008_003;

package SWISH::3;

our $VERSION = '1.000015';
our $VERSION = '1.000016';
my $version = $VERSION;
$VERSION = eval $VERSION; # numerify

Expand Down

0 comments on commit cf1b985

Please sign in to comment.