Skip to content

Commit

Permalink
Merge pull request #103 from pali/master
Browse files Browse the repository at this point in the history
Run Encode XS BOOT code at compile time
  • Loading branch information
dankogai authored May 30, 2017
2 parents 20ed8f3 + f1894ea commit a668497
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
16 changes: 10 additions & 6 deletions Encode.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
package Encode;
use strict;
use warnings;
our $VERSION = sprintf "%d.%02d", q$Revision: 2.89 $ =~ /(\d+)/g;
use constant DEBUG => !!$ENV{PERL_ENCODE_DEBUG};
use XSLoader ();
XSLoader::load( __PACKAGE__, $VERSION );
our $VERSION;
BEGIN {
$VERSION = sprintf "%d.%02d", q$Revision: 2.89 $ =~ /(\d+)/g;
require XSLoader;
XSLoader::load( __PACKAGE__, $VERSION );
}

use Exporter 5.57 'import';

Expand Down Expand Up @@ -187,7 +190,7 @@ sub encode($$;$) {
else {
$octets = $enc->encode( $string, $check );
}
$_[1] = $string if $check and !ref $check and !( $check & LEAVE_SRC() );
$_[1] = $string if $check and !ref $check and !( $check & LEAVE_SRC );
return $octets;
}
*str2bytes = \&encode;
Expand Down Expand Up @@ -216,7 +219,7 @@ sub decode($$;$) {
else {
$string = $enc->decode( $octets, $check );
}
$_[1] = $octets if $check and !ref $check and !( $check & LEAVE_SRC() );
$_[1] = $octets if $check and !ref $check and !( $check & LEAVE_SRC );
return $string;
}
*bytes2str = \&decode;
Expand Down Expand Up @@ -283,7 +286,7 @@ sub decode_utf8($;$) {
$check ||= 0;
$utf8enc ||= find_encoding('utf8');
my $string = $utf8enc->decode( $octets, $check );
$_[0] = $octets if $check and !ref $check and !( $check & LEAVE_SRC() );
$_[0] = $octets if $check and !ref $check and !( $check & LEAVE_SRC );
return $string;
}

Expand All @@ -299,6 +302,7 @@ sub decode_utf8($;$) {
# }
# }

onBOOT;
predefine_encodings(1);

#
Expand Down
10 changes: 7 additions & 3 deletions Encode.xs
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,13 @@ CODE:
OUTPUT:
RETVAL

void
onBOOT()
CODE:
{
#include "def_t.exh"
}

BOOT:
{
HV *stash = gv_stashpvn("Encode", strlen("Encode"), GV_ADD);
Expand All @@ -1109,6 +1116,3 @@ BOOT:
newCONSTSUB(stash, "FB_HTMLCREF", newSViv(ENCODE_FB_HTMLCREF));
newCONSTSUB(stash, "FB_XMLCREF", newSViv(ENCODE_FB_XMLCREF));
}
{
#include "def_t.exh"
}

0 comments on commit a668497

Please sign in to comment.