################################################################################
# !!!!! Do NOT edit this file directly! -- Edit PPPort_pm.PL instead. !!!!!
################################################################################
# Perl/Pollution/Portability
################################################################################
# $Date: 2005/06/25 17:56:28 +0200 $
################################################################################
# Version 3.x, Copyright (C) 2004-2005, Marcus Holland-Moritz.
# Version 2.x, Copyright (C) 2001, Paul Marquess.
# Version 1.x, Copyright (C) 1999, Kenneth Albanowski.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
################################################################################
Devel::PPPort - Perl/Pollution/Portability
Devel::PPPort::WriteFile(); # defaults to ./ppport.h
Devel::PPPort::WriteFile('someheader.h');
Perl's API has changed over time, gaining new features, new functions,
increasing its flexibility, and reducing the impact on the C namespace
environment (reduced pollution). The header file written by this module,
typically F<ppport.h>, attempts to bring some of the newer Perl API
features to older versions of Perl, so that you can worry less about
keeping track of old releases, but users can still reap the benefit.
C<Devel::PPPort> contains a single function, called C<WriteFile>. Its
only purpose is to write the F<ppport.h> C header file. This file
contains a series of macros and, if explicitly requested, functions that
allow XS modules to be built using older versions of Perl. Currently,
Perl versions from 5.003 to 5.9.3 are supported.
This module is used by C<h2xs> to write the file F<ppport.h>.
You should use F<ppport.h> in modern code so that your code will work
with the widest range of Perl interpreters possible, without significant
You should attempt older code to fully use F<ppport.h>, because the
reduced pollution of newer Perl versions is an important thing. It's so
important that the old polluting ways of original Perl modules will not be
supported very far into the future, and your module will almost certainly
break! By adapting to it now, you'll gain compatibility and a sense of
having done the electronic ecology some good.
=head2 How to use ppport.h
Don't direct the users of your module to download C<Devel::PPPort>.
They are most probably no XS writers. Also, don't make F<ppport.h>
optional. Rather, just take the most recent copy of F<ppport.h> that
you can find (e.g. by generating it with the latest C<Devel::PPPort>
release from CPAN), copy it into your project, adjust your project to
use it, and distribute the header along with your module.
But F<ppport.h> is more than just a C header. It's also a Perl script
that can check your source code. It will suggest hints and portability
notes, and can even make suggestions on how to change your code. You
can run it like any other Perl program:
perl ppport.h [options] [files]
It also has embedded documentation, so you can use
to find out more about how to use it.
C<WriteFile> takes one optional argument. When called with one
argument, it expects to be passed a filename. When called with
no arguments, it defaults to the filename F<ppport.h>.
The function returns a true value if the file was written successfully.
Otherwise it returns a false value.
F<ppport.h> supports Perl versions from 5.003 to 5.9.3
in threaded and non-threaded configurations.
=head2 Provided Perl compatibility API
The header file written by this module, typically F<ppport.h>, provides
access to the following elements of the Perl API that is not available
IS_NUMBER_GREATER_THAN_UV_MAX
PERL_GCC_BRACE_GROUPS_FORBIDDEN
PERL_MAGIC_overload_table
PERL_SCAN_ALLOW_UNDERSCORES
PERL_SCAN_DISALLOW_PREFIX
PERL_SCAN_GREATER_THAN_UV_MAX
PERL_SCAN_SILENT_ILLDIGIT
=head2 Perl API not supported by ppport.h
There is still a big part of the API not supported by F<ppport.h>.
Either because it doesn't make sense to back-port that part of the API,
or simply because it hasn't been implemented yet. Patches welcome!
Here's a list of the currently unsupported API, and also the version of
Perl below which it is unsupported:
If you find any bugs, C<Devel::PPPort> doesn't seem to build on your
system or any of its tests fail, please use the CPAN Request Tracker
at L<http://rt.cpan.org/> to create a ticket for the module.
Version 1.x of Devel::PPPort was written by Kenneth Albanowski.
Version 2.x was ported to the Perl core by Paul Marquess.
Version 3.x was ported back to CPAN by Marcus Holland-Moritz.
Version 3.x, Copyright (C) 2004-2005, Marcus Holland-Moritz.
Version 2.x, Copyright (C) 2001, Paul Marquess.
Version 1.x, Copyright (C) 1999, Kenneth Albanowski.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
See L<h2xs>, L<ppport.h>.
use vars
qw($VERSION @ISA $data);
$VERSION = do { my @r = '$Snapshot: /Devel-PPPort/3.06_01 $' =~ /(\d+\.\d+(?:_\d+)?)/; @r ? $r[0] : '9.99' };
$data = do { local $/; <DATA
> };
my $pkg = 'Devel::PPPort';
$data =~ s/__PERL_VERSION__/$]/g;
$data =~ s/__VERSION__/$VERSION/g;
$data =~ s/__DATE__/$now/g;
$data =~ s/__PKG__/$pkg/g;
my $file = shift || 'ppport.h';
defined $data or _init_data
();
$copy =~ s/\bppport\.h\b/$file/g;
open F
, ">$file" or return undef;
----------------------------------------------------------------------
ppport.h -- Perl/Pollution/Portability Version __VERSION__
Automatically created by __PKG__ running under
perl __PERL_VERSION__ on __DATE__.
Do NOT edit this file directly! -- Edit PPPort_pm.PL and the
includes in parts/inc/ instead.
Use 'perldoc ppport.h' to view the documentation below.
----------------------------------------------------------------------
|>ppport
.h
- Perl
/Pollution/Portability version __VERSION__
|> perl ppport
.h
[options
] [source files
]
|> Searches current directory
for files
if no [source files
] are
given
|> --help show short help
|> --patch
=file
write one patch file with changes
|> --copy
=suffix
write changed copies with suffix
|> --diff
=program
use diff program
and options
|> --compat
-version
=version provide compatibility with Perl version
|> --cplusplus
accept C
++ comments
|> --quiet don
't output anything except fatal errors
|> --nodiag don't show diagnostics
|> --nohints don
't show hints
|> --nochanges don't suggest changes
|> --nofilter don
't filter input files
|> --list-provided list provided API
|> --list-unsupported list unsupported API
|> --api-info=name show Perl API portability information
|>This version of F<ppport.h> is designed to support operation with Perl
|>installations back to 5.003, and has been tested up to 5.9.3.
|>Display a brief usage summary.
|>If this option is given, a single patch file will be created if
|>any changes are suggested. This requires a working diff program
|>to be installed on your system.
|>=head2 --copy=I<suffix>
|>If this option is given, a copy of each file will be saved with
|>the given suffix that contains the suggested changes. This does
|>not require any external programs.
|>If neither C<--patch> or C<--copy> are given, the default is to
|>simply print the diffs for each file. This requires either
|>C<Text::Diff> or a C<diff> program to be installed.
|>=head2 --diff=I<program>
|>Manually set the diff program and options to use. The default
|>is to use C<Text::Diff>, when installed, and output unified
|>=head2 --compat-version=I<version>
|>Tell F<ppport.h> to check for compatibility with the given
|>Perl version. The default is to check for compatibility with Perl
|>version 5.003. You can use this option to reduce the output
|>of F<ppport.h> if you intend to be backward compatible only
|>up to a certain Perl version.
|>Usually, F<ppport.h> will detect C++ style comments and
|>replace them with C style comments for portability reasons.
|>Using this option instructs F<ppport.h> to leave C++
|>Be quiet. Don't
print anything except fatal errors
.
|>Don
't output any diagnostic messages. Only portability
|>alerts will be printed.
|>Don't output any hints
. Hints often contain useful portability
|>Don
't suggest any changes. Only give diagnostic output and hints
|>unless these are also deactivated.
|>Don't filter the list of input files
. By
default, files
not looking
|>like source code
(i
.e
. not *.xs
, *.c
, *.cc
, *.cpp
or *.h
) are skipped
.
|>Lists the API elements
for which compatibility is provided by
|>F
<ppport
.h
>. Also lists
if it must be explicitly requested
,
|>if it has dependencies
, and if there are hints
for it
.
|>=head2
--list
-unsupported
|>Lists the API elements that are known
not to be supported by
|>F
<ppport
.h
> and below which version of Perl they probably
|>won
't be available or work.
|>=head2 --api-info=I<name>
|>Show portability information for API elements matching I<name>.
|>If I<name> is surrounded by slashes, it is interpreted as a regular
|>In order for a Perl extension (XS) module to be as portable as possible
|>across differing versions of Perl itself, certain steps need to be taken.
|>Including this header is the first major one. This alone will give you
|>access to a large part of the Perl API that hasn't been available
in
|>earlier Perl releases
. Use
|> perl ppport
.h
--list
-provided
|>to see which API elements are provided by ppport
.h
.
|>You should avoid using deprecated parts of the API
. For example
, using
|>global Perl variables without the C
<PL_
> prefix is deprecated
. Also
,
|>some API functions used to have a C
<perl_
> prefix
. Using this form is
|>also deprecated
. You can safely
use the supported API
, as F
<ppport
.h
>
|>will provide wrappers
for older Perl versions
.
|>If you
use one of a few functions that were
not present
in earlier
|>versions of Perl
, and that can
't be provided using a macro, you have
|>to explicitly request support for these functions by adding one or
|>more C<#define>s in your source code before the inclusion of F<ppport.h>.
|>These functions will be marked C<explicit> in the list shown by
|>Depending on whether you module has a single or multiple files that
|>use such functions, you want either C<static> or global variants.
|>For a C<static> function, use:
|>For a global function, use:
|> #define NEED_function_GLOBAL
|>Note that you mustn't have more than one global request
for one
|>function
in your project
.
|> Function Static Request Global Request
|> -----------------------------------------------------------------------------------------
|> eval_pv
() NEED_eval_pv NEED_eval_pv_GLOBAL
|> grok_bin
() NEED_grok_bin NEED_grok_bin_GLOBAL
|> grok_hex
() NEED_grok_hex NEED_grok_hex_GLOBAL
|> grok_number
() NEED_grok_number NEED_grok_number_GLOBAL
|> grok_numeric_radix
() NEED_grok_numeric_radix NEED_grok_numeric_radix_GLOBAL
|> grok_oct
() NEED_grok_oct NEED_grok_oct_GLOBAL
|> newCONSTSUB
() NEED_newCONSTSUB NEED_newCONSTSUB_GLOBAL
|> newRV_noinc
() NEED_newRV_noinc NEED_newRV_noinc_GLOBAL
|> sv_2pv_nolen
() NEED_sv_2pv_nolen NEED_sv_2pv_nolen_GLOBAL
|> sv_2pvbyte
() NEED_sv_2pvbyte NEED_sv_2pvbyte_GLOBAL
|> sv_catpvf_mg
() NEED_sv_catpvf_mg NEED_sv_catpvf_mg_GLOBAL
|> sv_catpvf_mg_nocontext
() NEED_sv_catpvf_mg_nocontext NEED_sv_catpvf_mg_nocontext_GLOBAL
|> sv_setpvf_mg
() NEED_sv_setpvf_mg NEED_sv_setpvf_mg_GLOBAL
|> sv_setpvf_mg_nocontext
() NEED_sv_setpvf_mg_nocontext NEED_sv_setpvf_mg_nocontext_GLOBAL
|> vnewSVpvf
() NEED_vnewSVpvf NEED_vnewSVpvf_GLOBAL
|>To avoid namespace conflicts
, you can change the namespace of the
|>explicitly exported functions using the C
<DPPP_NAMESPACE
> macro
.
|>Just C
<#define> the macro before including C<ppport.h>:
|> #define DPPP_NAMESPACE MyOwnNamespace_
|>The
default namespace is C
<DPPP_
>.
|>The good thing is that most of the above can be checked by running
|>F
<ppport
.h
> on your source code
. See the
next section
for
|>To verify whether F
<ppport
.h
> is needed
for your module
, whether you
|>should make any changes to your code
, and whether any special defines
|>should be used
, F
<ppport
.h
> can be run as a Perl script to check your
|>source code
. Simply
say:
|>The result will usually be a list of patches suggesting changes
|>that should at least be acceptable
, if not necessarily the most
|>efficient solution
, or a fix
for all possible problems
.
|>If you know that your XS module uses features only available
in
|>newer Perl releases
, if you
're aware that it uses C++ comments,
|>and if you want all suggestions as a single patch file, you could
|>use something like this:
|> perl ppport.h --compat-version=5.6.0 --cplusplus --patch=test.diff
|>If you only want your code to be scanned without any suggestions
|> perl ppport.h --nochanges
|>You can specify a different C<diff> program or options, using
|> perl ppport.h --diff='diff
-C
10'
|>This would output context diffs with 10 lines of context.
|>To display portability information for the C<newSVpvn> function,
|> perl ppport.h --api-info=newSVpvn
|>Since the argument to C<--api-info> can be a regular expression,
|> perl ppport.h --api-info=/_nomg$/
|>to display portability information for all C<_nomg> functions or
|> perl ppport.h --api-info=/./
|>to display information for all known API elements.
|>If this version of F<ppport.h> is causing failure during
|>the compilation of this module, please check if newer versions
|>of either this module or C<Devel::PPPort> are available on CPAN
|>before sending a bug report.
|>If F<ppport.h> was generated using the latest version of
|>C<Devel::PPPort> and is causing failure of this module, please
|>file a bug report using the CPAN Request Tracker at L<http://rt.cpan.org/>.
|>Please include the following information:
|>The complete output from running "perl -V"
|>The name and version of the module you were trying to build.
|>A full log of the build that failed.
|>Any other information that you think could be relevant.
|>For the latest version of this code, please get the C<Devel::PPPort>
|>Version 3.x, Copyright (c) 2004-2005, Marcus Holland-Moritz.
|>Version 2.x, Copyright (C) 2001, Paul Marquess.
|>Version 1.x, Copyright (C) 1999, Kenneth Albanowski.
|>This program is free software; you can redistribute it and/or
|>modify it under the same terms as Perl itself.
my($ppport) = $0 =~ /([\w.]+)$/;
my $LF = '(?
:\r\n|[\r\n])'; # line feed
my $HS = "[ \t]"; # horizontal whitespace
Getopt::Long::GetOptions(\%opt, qw(
help quiet diag! filter! hints! changes! cplusplus
patch=s copy=s diff=s compat-version=s
list-provided list-unsupported api-info=s
if ($@
and grep /^-/, @ARGV) {
usage
() if "@ARGV" =~ /^--?h(?:elp)?$/;
die "Getopt::Long not found. Please don't use any options.\n";
if (exists $opt{'compat-version'}) {
my($r,$v,$s) = eval { parse_version
($opt{'compat-version'}) };
die "Invalid version number format: '$opt{'compat-version'}'\n";
die "Only Perl 5 is supported\n" if $r != 5;
die "Invalid version number: $opt{'compat-version'}\n" if $v >= 1000 || $s >= 1000;
$opt{'compat-version'} = sprintf "%d.%03d%03d", $r, $v, $s;
$opt{'compat-version'} = 5;
# Never use C comments in this file!!!!!
my $rccs = quotemeta $ccs;
my $rcce = quotemeta $cce;
my %API = map { /^(\w+)\|([^|]*)\|([^|]*)\|(\w*)$/
($2 ?
( base
=> $2 ) : ()),
($3 ?
( todo
=> $3 ) : ()),
(index($4, 'v') >= 0 ?
( varargs
=> 1 ) : ()),
(index($4, 'p') >= 0 ?
( provided
=> 1 ) : ()),
(index($4, 'n') >= 0 ?
( nothxarg
=> 1 ) : ()),
: die "invalid spec: $_" } qw(
CopFILEGV_set|5.006000||p
CopSTASHPV_set|5.006000||p
GROK_NUMERIC_RADIX|5.007002||p
IN_LOCALE_COMPILETIME|5.007002||p
IN_LOCALE_RUNTIME|5.007002||p
IN_PERL_COMPILETIME|5.008001||p
IS_NUMBER_GREATER_THAN_UV_MAX|5.007002||p
IS_NUMBER_INFINITY|5.007002||p
IS_NUMBER_IN_UV|5.007002||p
IS_NUMBER_NAN|5.007003||p
IS_NUMBER_NEG|5.007002||p
IS_NUMBER_NOT_INT|5.007002||p
PERL_BCDVERSION|5.009003||p
PERL_GCC_BRACE_GROUPS_FORBIDDEN|5.008001||p
PERL_LONG_MAX|5.004000||p
PERL_LONG_MIN|5.004000||p
PERL_MAGIC_arylen|5.007002||p
PERL_MAGIC_backref|5.007002||p
PERL_MAGIC_bm|5.007002||p
PERL_MAGIC_collxfrm|5.007002||p
PERL_MAGIC_dbfile|5.007002||p
PERL_MAGIC_dbline|5.007002||p
PERL_MAGIC_defelem|5.007002||p
PERL_MAGIC_envelem|5.007002||p
PERL_MAGIC_env|5.007002||p
PERL_MAGIC_ext|5.007002||p
PERL_MAGIC_fm|5.007002||p
PERL_MAGIC_glob|5.007002||p
PERL_MAGIC_isaelem|5.007002||p
PERL_MAGIC_isa|5.007002||p
PERL_MAGIC_mutex|5.007002||p
PERL_MAGIC_nkeys|5.007002||p
PERL_MAGIC_overload_elem|5.007002||p
PERL_MAGIC_overload_table|5.007002||p
PERL_MAGIC_overload|5.007002||p
PERL_MAGIC_pos|5.007002||p
PERL_MAGIC_qr|5.007002||p
PERL_MAGIC_regdata|5.007002||p
PERL_MAGIC_regdatum|5.007002||p
PERL_MAGIC_regex_global|5.007002||p
PERL_MAGIC_shared_scalar|5.007003||p
PERL_MAGIC_shared|5.007003||p
PERL_MAGIC_sigelem|5.007002||p
PERL_MAGIC_sig|5.007002||p
PERL_MAGIC_substr|5.007002||p
PERL_MAGIC_sv|5.007002||p
PERL_MAGIC_taint|5.007002||p
PERL_MAGIC_tiedelem|5.007002||p
PERL_MAGIC_tiedscalar|5.007002||p
PERL_MAGIC_tied|5.007002||p
PERL_MAGIC_utf8|5.008001||p
PERL_MAGIC_uvar_elem|5.007003||p
PERL_MAGIC_uvar|5.007002||p
PERL_MAGIC_vec|5.007002||p
PERL_MAGIC_vstring|5.008001||p
PERL_QUAD_MAX|5.004000||p
PERL_QUAD_MIN|5.004000||p
PERL_REVISION|5.006000||p
PERL_SCAN_ALLOW_UNDERSCORES|5.007003||p
PERL_SCAN_DISALLOW_PREFIX|5.007003||p
PERL_SCAN_GREATER_THAN_UV_MAX|5.007003||p
PERL_SCAN_SILENT_ILLDIGIT|5.008001||p
PERL_SHORT_MAX|5.004000||p
PERL_SHORT_MIN|5.004000||p
PERL_SUBVERSION|5.006000||p
PERL_UCHAR_MAX|5.004000||p
PERL_UCHAR_MIN|5.004000||p
PERL_UINT_MAX|5.004000||p
PERL_UINT_MIN|5.004000||p
PERL_ULONG_MAX|5.004000||p
PERL_ULONG_MIN|5.004000||p
PERL_UNUSED_DECL|5.007002||p
PERL_UQUAD_MAX|5.004000||p
PERL_UQUAD_MIN|5.004000||p
PERL_USHORT_MAX|5.004000||p
PERL_USHORT_MIN|5.004000||p
PL_perl_destruct_level|5.004050||p
PL_rsfp_filters|5.004050||p
PL_stack_base|5.004050||p
PL_sv_arenaroot|5.004050||p
PerlIO_clearerr||5.007003|
PerlIO_get_base||5.007003|
PerlIO_get_bufsiz||5.007003|
PerlIO_get_cnt||5.007003|
PerlIO_get_ptr||5.007003|
PerlIO_set_cnt||5.007003|
PerlIO_set_ptrcnt||5.007003|
PerlIO_setlinebuf||5.007003|
START_EXTERN_C|5.005000||p
SvIsCOW_shared_hash||5.008003|
SvPOK_only_UTF8||5.006000|
SvPV_force_nomg|5.007002||p
SvPVbyte_force||5.009002|
SvPVbyte_nolen||5.006000|
SvPVbytex_force||5.006000|
SvPVutf8_force||5.006000|
SvPVutf8_nolen||5.006000|
SvPVutf8x_force||5.006000|
SvSetMagicSV_nosteal||5.004000|
SvSetSV_nosteal||5.004000|
XCPT_TRY_START|5.009002||p
apply_attrs_string||5.006001|
atfork_unlock||5.007003|n
bytes_from_utf8||5.007001|
custom_op_desc||5.007003|
custom_op_name||5.007003|
despatch_signals||5.007001|
find_rundefsvoffset||5.009002|
grok_numeric_radix|5.007002||p
gv_fetchmeth_autoload||5.007003|
gv_fetchmethod_autoload||5.004000|
gv_fetchpvn_flags||5.009002|
hv_clear_placeholders||5.009001|
hv_delayfree_ent||5.004000|
hv_iternext_flags||5.008000|
hv_placeholders_get||5.009003|
hv_placeholders_p||5.009003|
hv_placeholders_set||5.009003|
hv_store_flags||5.008000|
is_uni_alnum_lc||5.006000|
is_uni_alnumc_lc||5.006000|
is_uni_alpha_lc||5.006000|
is_uni_ascii_lc||5.006000|
is_uni_cntrl_lc||5.006000|
is_uni_digit_lc||5.006000|
is_uni_graph_lc||5.006000|
is_uni_idfirst_lc||5.006000|
is_uni_idfirst||5.006000|
is_uni_lower_lc||5.006000|
is_uni_print_lc||5.006000|
is_uni_punct_lc||5.006000|
is_uni_space_lc||5.006000|
is_uni_upper_lc||5.006000|
is_uni_xdigit_lc||5.006000|
is_utf8_alnumc||5.006000|
is_utf8_idcont||5.008000|
is_utf8_idfirst||5.006000|
is_utf8_string_loclen||5.009003|
is_utf8_string_loc||5.008001|
is_utf8_string||5.006001|
is_utf8_xdigit||5.006000|
load_module_nocontext|||vn
my_failure_exit||5.004000|
my_socketpair||5.007003|n
newANONATTRSUB||5.006000|
newSVpvn_share||5.007001|
op_refcnt_lock||5.009002|
op_refcnt_unlock||5.009002|
perl_destruct||5.007003|n
pv_uni_display||5.007003|
re_intuit_start||5.006000|
re_intuit_string||5.006000|
regclass_swash||5.007003|
runops_standard||5.005000|
safesyscalloc||5.006000|n
safesysmalloc||5.006000|n
safesysrealloc||5.006000|n
save_destructor_x||5.006000|
save_destructor||5.006000|
save_generic_pvref||5.006001|
save_generic_svref||5.005030|
save_mortalizesv||5.007001|
save_re_context||5.006000|
save_set_svflags||5.009000|
save_shared_pvref||5.007003|
savestack_grow_cnt||5.008001|
set_numeric_local||5.006000|
set_numeric_radix||5.006000|
set_numeric_standard||5.006000|
start_subparse||5.004000|
stashpv_hvname_match||5.009003|
str_to_version||5.006000|
sv_2pvutf8_nolen||5.006000|
sv_catpvf_mg_nocontext|||pvn
sv_catpvf_mg|5.006000|5.004000|pv
sv_catpvn_flags||5.007002|
sv_catpvn_nomg|5.007002||p
sv_catsv_flags||5.007002|
sv_catsv_nomg|5.007002||p
sv_compile_2op||5.008001|
sv_derived_from||5.004000|
sv_force_normal_flags||5.007001|
sv_force_normal||5.006000|
sv_nounlocking||5.007003|
sv_pvbyten_force||5.006000|
sv_pvn_force_flags||5.007002|
sv_pvutf8n_force||5.006000|
sv_recode_to_utf8||5.007003|
sv_setpvf_mg_nocontext|||pvn
sv_setpvf_mg|5.006000|5.004000|pv
sv_setsv_flags||5.007002|
sv_setsv_nomg|5.007002||p
sv_uni_display||5.007003|
sv_unref_flags||5.007001|
sv_utf8_decode||5.006000|
sv_utf8_downgrade||5.006000|
sv_utf8_encode||5.006000|
sv_utf8_upgrade_flags||5.007002|
sv_utf8_upgrade||5.007001|
sv_vcatpvf_mg|5.006000|5.004000|p
sv_vcatpvf|5.006000|5.004000|p
sv_vsetpvf_mg|5.006000|5.004000|p
sv_vsetpvf|5.006000|5.004000|p
to_uni_lower_lc||5.006000|
to_uni_title_lc||5.006000|
to_uni_upper_lc||5.006000|
utf16_to_utf8_reversed||5.006001|
utf8n_to_uvchr||5.007001|
utf8n_to_uvuni||5.007001|
uvchr_to_utf8_flags||5.007003|
uvuni_to_utf8_flags||5.007003|
vnewSVpvf|5.006000|5.004000|p
if (exists $opt{'list-unsupported'}) {
for $f (sort { lc $a cmp lc $b } keys %API) {
next unless $API{$f}{todo
};
print "$f ", '.'x
(40-length($f)), " ", format_version
($API{$f}{todo
}), "\n";
# Scan for possible replacement candidates
my(%replace, %need, %hints, %depends);
if (m{^\s*\*\s(.*?)\s*$}) {
$hints{$hint} ||= ''; # suppress warning with older perls
$hint = $1 if m{^\s*$rccs\sHint:\s+(\w+)\s*$};
$replace = $1 if m{^\s*$rccs\s+Replace:\s+(\d+)\s+$rcce\s*$};
$replace{$2} = $1 if $replace and m{^\s*#\s*define\s+(\w+)(?:\([^)]*\))?\s+(\w+)};
$replace{$2} = $1 if m{^\s*#\s*define\s+(\w+)(?:\([^)]*\))?\s+(\w+).*$rccs\s+Replace\s+$rcce};
$replace{$1} = $2 if m{^\s*$rccs\s+Replace (\w+) with (\w+)\s+$rcce\s*$};
if (m{^\s*$rccs\s+(\w+)\s+depends\s+on\s+(\w+(\s*,\s*\w+)*)\s+$rcce\s*$}) {
push @
{$depends{$1}}, map { s/\s+//g; $_ } split /,/, $2;
$need{$1} = 1 if m{^#if\s+defined\(NEED_(\w+)(?:_GLOBAL)?\)};
if (exists $opt{'api-info'}) {
my $match = $opt{'api-info'} =~ m!^/(.*)/$! ?
$1 : "^\Q$opt{'api-info'}\E\$";
for $f (sort { lc $a cmp lc $b } keys %API) {
next unless $f =~ /$match/;
print "\n=== $f ===\n\n";
if ($API{$f}{base
} || $API{$f}{todo
}) {
my $base = format_version
($API{$f}{base
} || $API{$f}{todo
});
print "Supported at least starting from perl-$base.\n";
if ($API{$f}{provided
}) {
my $todo = $API{$f}{todo
} ? format_version
($API{$f}{todo
}) : "5.003";
print "Support by $ppport provided back to perl-$todo.\n";
print "Support needs to be explicitly requested by NEED_$f.\n" if exists $need{$f};
print "Depends on: ", join(', ', @
{$depends{$f}}), ".\n" if exists $depends{$f};
print "$hints{$f}" if exists $hints{$f};
print "No portability information available.\n";
print "Found no API matching '$opt{'api-info'}'.\n";
if (exists $opt{'list-provided'}) {
for $f (sort { lc $a cmp lc $b } keys %API) {
next unless $API{$f}{provided
};
push @flags, 'explicit' if exists $need{$f};
push @flags, 'depend' if exists $depends{$f};
push @flags, 'hint' if exists $hints{$f};
my $flags = @flags ?
' ['.join(', ', @flags).']' : '';
my @srcext = qw( xs c h cc cpp );
my $srcext = join '|', @srcext;
@files = grep { -f
&& !exists $seen{$_} } map { glob $_ } @ARGV;
$File::Find
::name
=~ /\.($srcext)$/i
and push @files, $File::Find
::name
;
@files = map { glob "*.$_" } @srcext;
if (!@ARGV || $opt{filter
}) {
my %xsc = map { /(.*)\.xs$/ ?
("$1.c" => 1, "$1.cc" => 1) : () } @files;
my $out = exists $xsc{$_} || /\b\Q$ppport\E$/i || !/\.($srcext)$/i;
push @
{ $out ? \
@out : \
@in }, $_;
warning
("Skipping the following files (use --nofilter to avoid this):\n| ", join "\n| ", @out);
die "No input files given!\n";
my(%files, %global, %revreplace);
%revreplace = reverse %replace;
unless (open IN
, "<$filename") {
warn "Unable to read from $filename: $!\n";
info
("Scanning $filename ...");
my $c = do { local $/; <IN
> };
my %file = (orig
=> $c, changes
=> 0);
# temporarily remove C comments from the code
(?:"[^"\\]*(?:\\.[^"\\]*)*" [^"'/]*)+
(?:'[^'\\]*(?:\\.[^'\\]*)*' [^"'/]*)+
\
*[^*]*\
*+(?
:[^$ccs][^*]*\
*+)* /
defined $2 and push @ccom, $2;
defined $1 ?
$1 : "$ccs$#ccom$cce";
$file{has_inc_ppport
} = ($c =~ /#.*include.*\Q$ppport\E/);
$match .= "|$revreplace{$func}" if exists $revreplace{$func};
if ($c =~ /\b(?:Perl_)?($match)\b/) {
$file{uses_replace
}{$1}++ if exists $revreplace{$func} && $1 eq $revreplace{$func};
$file{uses_Perl
}{$func}++ if $c =~ /\bPerl_$func\b/;
if (exists $API{$func}{provided
}) {
if (!exists $API{$func}{base
} || $API{$func}{base
} > $opt{'compat-version'}) {
my @deps = rec_depend
($func);
$file{uses_deps
}{$func} = \
@deps;
$file{uses
}{$_} = 0 unless exists $file{uses
}{$_};
$file{needs
}{$_} = 'static';
if (exists $API{$func}{todo
} && $API{$func}{todo
} > $opt{'compat-version'}) {
$file{uses_todo
}{$func}++;
while ($c =~ /^$HS*#$HS*define$HS+(NEED_(\w+?)(_GLOBAL)?)\b/mg) {
$file{defined $3 ?
'needed_global' : 'needed_static'}{$2}++;
warning
("Possibly wrong #define $1 in $filename");
for (qw(uses needs uses_todo needed_global needed_static)) {
for $func (keys %{$file{$_}}) {
push @
{$global{$_}{$func}}, $filename;
$files{$filename} = \
%file;
# Globally resolve NEED_'s
for $need (keys %{$global{needs
}}) {
if (@
{$global{needs
}{$need}} > 1) {
my @targets = @
{$global{needs
}{$need}};
my @t = grep $files{$_}{needed_global
}{$need}, @targets;
@t = grep /\.xs$/i, @targets;
my $target = shift @targets;
$files{$target}{needs
}{$need} = 'global';
for (@
{$global{needs
}{$need}}) {
$files{$_}{needs
}{$need} = 'extern' if $_ ne $target;
exists $files{$filename} or next;
info
("=== Analyzing $filename ===");
my %file = %{$files{$filename}};
for $func (sort keys %{$file{uses_Perl
}}) {
if ($API{$func}{varargs
}) {
my $changes = ($c =~ s
{\b(Perl_
$func\s
*\
(\s
*)(?
!aTHX_?
)(\
)|[^\s
)]*\
))}
{ $1 . ($2 eq ')' ?
'aTHX' : 'aTHX_ ') . $2 }ge);
warning
("Doesn't pass interpreter argument aTHX to Perl_$func");
$file{changes
} += $changes;
warning
("Uses Perl_$func instead of $func");
$file{changes
} += ($c =~ s
{\bPerl_
$func(\s
*)\
((\s
*aTHX_?
)?\s
*}
for $func (sort keys %{$file{uses_replace
}}) {
warning
("Uses $func instead of $replace{$func}");
$file{changes
} += ($c =~ s/\b$func\b/$replace{$func}/g);
for $func (sort keys %{$file{uses
}}) {
next unless $file{uses
}{$func}; # if it's only a dependency
if (exists $file{uses_deps
}{$func}) {
diag
("Uses $func, which depends on ", join(', ', @
{$file{uses_deps
}{$func}}));
elsif (exists $replace{$func}) {
warning
("Uses $func instead of $replace{$func}");
$file{changes
} += ($c =~ s/\b$func\b/$replace{$func}/g);
for $func (sort keys %{$file{uses_todo
}}) {
warning
("Uses $func, which may not be portable below perl ",
format_version
($API{$func}{todo
}));
for $func (sort keys %{$file{needed_static
}}) {
if (not exists $file{uses
}{$func}) {
$message = "No need to define NEED_$func if $func is never used";
elsif (exists $file{needs
}{$func} && $file{needs
}{$func} ne 'static') {
$message = "No need to define NEED_$func when already needed globally";
$file{changes
} += ($c =~ s/^$HS*#$HS*define$HS+NEED_$func\b.*$LF//mg);
for $func (sort keys %{$file{needed_global
}}) {
if (not exists $global{uses
}{$func}) {
$message = "No need to define NEED_${func}_GLOBAL if $func is never used";
elsif (exists $file{needs
}{$func}) {
if ($file{needs
}{$func} eq 'extern') {
$message = "No need to define NEED_${func}_GLOBAL when already needed globally";
elsif ($file{needs
}{$func} eq 'static') {
$message = "No need to define NEED_${func}_GLOBAL when only used in this file";
$file{changes
} += ($c =~ s/^$HS*#$HS*define$HS+NEED_${func}_GLOBAL\b.*$LF//mg);
$file{needs_inc_ppport
} = keys %{$file{uses
}};
if ($file{needs_inc_ppport
}) {
for $func (sort keys %{$file{needs
}}) {
my $type = $file{needs
}{$func};
next if $type eq 'extern';
my $suffix = $type eq 'global' ?
'_GLOBAL' : '';
unless (exists $file{"needed_$type"}{$func}) {
diag
("Files [@{$global{needs}{$func}}] need $func, adding global request");
diag
("File needs $func, adding static request");
$pp .= "#define NEED_$func$suffix\n";
if ($pp && ($c =~ s/^(?=$HS*#$HS*define$HS+NEED_\w+)/$pp/m)) {
unless ($file{has_inc_ppport
}) {
diag
("Needs to include '$ppport'");
$pp .= qq(#include "$ppport"\n)
$file{changes
} += ($c =~ s/^($HS*#$HS*define$HS+NEED_\w+.*?)^/$1$pp/ms)
|| ($c =~ s/^(?=$HS*#$HS*include.*\Q$ppport\E)/$pp/m)
|| ($c =~ s/^($HS*#$HS*include.*XSUB.*\s*?)^/$1$pp/m)
if ($file{has_inc_ppport
}) {
diag
("No need to include '$ppport'");
$file{changes
} += ($c =~ s/^$HS*?#$HS*include.*\Q$ppport\E.*?$LF//m);
# put back in our C comments
my @ccom = @
{$file{ccom
}};
if (!$opt{cplusplus
} && $ccom[$ix] =~ s!^//!!) {
$file{changes
} += $c =~ s/$rccs$ix$rcce/$ccs$ccom[$ix] $cce/;
$c =~ s/$rccs$ix$rcce/$ccom[$ix]/;
my $s = $cppc != 1 ?
's' : '';
warning
("Uses $cppc C++ style comment$s, which is not portable");
my $newfile = "$filename$opt{copy}";
error
("'$newfile' already exists, refusing to write copy of '$filename'");
if (open F
, ">$newfile") {
info
("Writing copy of '$filename' with changes to '$newfile'");
error
("Cannot open '$newfile' for writing: $!");
elsif (exists $opt{patch
} || $opt{changes
}) {
if (exists $opt{patch
}) {
if (open PATCH
, ">$opt{patch}") {
error
("Cannot open '$opt{patch}' for writing: $!");
mydiff
(\
*PATCH
, $filename, $c);
info
("Suggested changes:");
mydiff
(\
*STDOUT
, $filename, $c);
my $s = $file{changes
} == 1 ?
'' : 's';
info
("$file{changes} potentially required change$s detected");
close PATCH
if $patch_opened;
$diff = run_diff
($opt{diff
}, $file, $str);
if (!defined $diff and can_use
('Text::Diff')) {
$diff = Text
::Diff
::diff
($file, \
$str, { STYLE
=> 'Unified' });
$diff = <<HEADER . $diff;
$diff = run_diff
('diff -u', $file, $str);
$diff = run_diff
('diff', $file, $str);
error
("Cannot generate a diff. Please install Text::Diff or use --copy.");
my($prog, $file, $str) = @_;
while (-e
"$tmp.$suf") { $suf++ }
if (open F
, "$prog $file $tmp |") {
s/\Q$tmp\E/$file.patched/;
error
("Cannot open '$tmp' for writing: $!");
return () unless exists $depends{$func};
grep !$seen{$_}++, map { ($_, rec_depend
($_)) } @
{$depends{$func}};
if ($ver =~ /^(\d+)\.(\d+)\.(\d+)$/) {
elsif ($ver !~ /^\d+\.[\d_]+$/) {
die "cannot parse version '$ver'\n";
my($r,$v,$s) = $ver =~ /(\d+)\.(\d{3})(\d{3})/;
if ($r < 5 || ($r == 5 && $v < 6)) {
die "cannot parse version '$ver'\n";
my($r,$v,$s) = $ver =~ /(\d+)\.(\d{3})(\d{3})/;
if ($r < 5 || ($r == 5 && $v < 6)) {
die "invalid version '$ver'\n";
$ver = sprintf "%d.%03d", $r, $v;
$s > 0 and $ver .= sprintf "_%02d", $s;
return sprintf "%d.%d.%d", $r, $v, $s;
$opt{diag
} and print @_, "\n";
print "*** ERROR: ", @_, "\n";
exists $hints{$func} or return;
$given_hints{$func}++ and return;
my $hint = $hints{$func};
print " --- hint for $func ---\n", $hint;
my($usage) = do { local(@ARGV,$/)=($0); <> } =~ /^=head\d
$HS+SYNOPSIS\s
*^(.*?
)\s
*^=/ms
;
$usage =~ s/^\s*perl\s+\S+/$^X $0/;
$usage =~ s/([A-Z])<([^>]+)>/$M{$1}$2$M{$1}/g;
See perldoc $0 for details.
#ifndef _P_P_PORTABILITY_H_
#define _P_P_PORTABILITY_H_
# define DPPP_NAMESPACE DPPP_
#define DPPP_CAT2(x,y) CAT2(x,y)
#define DPPP_(name) DPPP_CAT2(DPPP_NAMESPACE, name)
# if !defined(__PATCHLEVEL_H_INCLUDED__) && !(defined(PATCHLEVEL) && defined(SUBVERSION))
# define PERL_PATCHLEVEL_H_IMPLICIT
# if !(defined(PERL_VERSION) || (defined(SUBVERSION) && defined(PATCHLEVEL)))
# include <could_not_find_Perl_patchlevel.h>
# define PERL_REVISION (5)
# define PERL_VERSION PATCHLEVEL
# define PERL_SUBVERSION SUBVERSION
/* Replace PERL_PATCHLEVEL with PERL_VERSION */
#define PERL_BCDVERSION ((PERL_REVISION * 0x1000000L) + (PERL_VERSION * 0x1000L) + PERL_SUBVERSION)
/* It is very unlikely that anyone will try to
use this with Perl
6
(or greater
), but who knows
.
# error ppport.h only works with Perl version 5
#endif /* PERL_REVISION != 5 */
# define PERL_UCHAR_MIN ((unsigned char)0)
# define PERL_UCHAR_MAX ((unsigned char)UCHAR_MAX)
# define PERL_UCHAR_MAX ((unsigned char)MAXUCHAR)
# define PERL_UCHAR_MAX ((unsigned char)~(unsigned)0)
# define PERL_USHORT_MIN ((unsigned short)0)
# define PERL_USHORT_MAX ((unsigned short)USHORT_MAX)
# define PERL_USHORT_MAX ((unsigned short)MAXUSHORT)
# define PERL_USHORT_MAX ((unsigned short)USHRT_MAX)
# define PERL_USHORT_MAX ((unsigned short)~(unsigned)0)
# define PERL_SHORT_MAX ((short)SHORT_MAX)
# ifdef MAXSHORT /* Often used in <values.h> */
# define PERL_SHORT_MAX ((short)MAXSHORT)
# define PERL_SHORT_MAX ((short)SHRT_MAX)
# define PERL_SHORT_MAX ((short) (PERL_USHORT_MAX >> 1))
# define PERL_SHORT_MIN ((short)SHORT_MIN)
# define PERL_SHORT_MIN ((short)MINSHORT)
# define PERL_SHORT_MIN ((short)SHRT_MIN)
# define PERL_SHORT_MIN (-PERL_SHORT_MAX - ((3 & -1) == 3))
# define PERL_UINT_MAX ((unsigned int)UINT_MAX)
# define PERL_UINT_MAX ((unsigned int)MAXUINT)
# define PERL_UINT_MAX (~(unsigned int)0)
# define PERL_UINT_MIN ((unsigned int)0)
# define PERL_INT_MAX ((int)INT_MAX)
# ifdef MAXINT /* Often used in <values.h> */
# define PERL_INT_MAX ((int)MAXINT)
# define PERL_INT_MAX ((int)(PERL_UINT_MAX >> 1))
# define PERL_INT_MIN ((int)INT_MIN)
# define PERL_INT_MIN ((int)MININT)
# define PERL_INT_MIN (-PERL_INT_MAX - ((3 & -1) == 3))
# define PERL_ULONG_MAX ((unsigned long)ULONG_MAX)
# define PERL_ULONG_MAX ((unsigned long)MAXULONG)
# define PERL_ULONG_MAX (~(unsigned long)0)
# define PERL_ULONG_MIN ((unsigned long)0L)
# define PERL_LONG_MAX ((long)LONG_MAX)
# define PERL_LONG_MAX ((long)MAXLONG)
# define PERL_LONG_MAX ((long) (PERL_ULONG_MAX >> 1))
# define PERL_LONG_MIN ((long)LONG_MIN)
# define PERL_LONG_MIN ((long)MINLONG)
# define PERL_LONG_MIN (-PERL_LONG_MAX - ((3 & -1) == 3))
#if defined(HAS_QUAD) && (defined(convex) || defined(uts))
# define PERL_UQUAD_MAX ((unsigned long long)ULONGLONG_MAX)
# define PERL_UQUAD_MAX ((unsigned long long)MAXULONGLONG)
# define PERL_UQUAD_MAX (~(unsigned long long)0)
# define PERL_UQUAD_MIN ((unsigned long long)0L)
# define PERL_QUAD_MAX ((long long)LONGLONG_MAX)
# define PERL_QUAD_MAX ((long long)MAXLONGLONG)
# define PERL_QUAD_MAX ((long long) (PERL_UQUAD_MAX >> 1))
# define PERL_QUAD_MIN ((long long)LONGLONG_MIN)
# define PERL_QUAD_MIN ((long long)MINLONGLONG)
# define PERL_QUAD_MIN (-PERL_QUAD_MAX - ((3 & -1) == 3))
/* This is based on code from 5.003 perl.h */
# define IV_MIN PERL_INT_MIN
# define IV_MAX PERL_INT_MAX
# define UV_MIN PERL_UINT_MIN
# define UV_MAX PERL_UINT_MAX
# if defined(convex) || defined(uts)
# define IVTYPE long long
# define IV_MIN PERL_QUAD_MIN
# define IV_MAX PERL_QUAD_MAX
# define UV_MIN PERL_UQUAD_MIN
# define UV_MAX PERL_UQUAD_MAX
# define IVSIZE LONGLONGSIZE
# define IV_MIN PERL_LONG_MIN
# define IV_MAX PERL_LONG_MAX
# define UV_MIN PERL_ULONG_MIN
# define UV_MAX PERL_ULONG_MAX
# define PERL_QUAD_MIN IV_MIN
# define PERL_QUAD_MAX IV_MAX
# define PERL_UQUAD_MIN UV_MIN
# define PERL_UQUAD_MAX UV_MAX
# define IV_MIN PERL_LONG_MIN
# define IV_MAX PERL_LONG_MAX
# define UV_MIN PERL_ULONG_MIN
# define UV_MAX PERL_ULONG_MAX
# define IVSIZE 4 /* A bold guess, but the best we can make. */
# define UVTYPE unsigned IVTYPE
# define sv_setuv(sv, uv) \
sv_setnv
(sv
, (double
)TeMpUv
); \
# define newSVuv(uv) ((uv) <= IV_MAX ? newSViv((IV)uv) : newSVnv((NV)uv))
# define sv_2uv(sv) ((PL_Sv = (sv)), (UV) (SvNOK(PL_Sv) ? SvNV(PL_Sv) : sv_2nv(PL_Sv)))
# define SvUVX(sv) ((UV)SvIVX(sv))
# define SvUVXx(sv) SvUVX(sv)
# define SvUV(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv(sv))
# define SvUVx(sv) ((PL_Sv = (sv)), SvUV(PL_Sv))
* Always
use the SvUVx
() macro instead of sv_uv
().
# define sv_uv(sv) SvUVx(sv)
# define XST_mUV(i,v) (ST(i) = sv_2mortal(newSVuv(v)) )
# define XSRETURN_UV(v) STMT_START { XST_mUV(0,v); XSRETURN(1); } STMT_END
# define PUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); PUSHTARG; } STMT_END
# define XPUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); XPUSHTARG; } STMT_END
#if (PERL_VERSION < 4) || ((PERL_VERSION == 4) && (PERL_SUBVERSION <= 5))
# define PL_DBsingle DBsingle
# define PL_compiling compiling
# define PL_copline copline
# define PL_curcop curcop
# define PL_curstash curstash
# define PL_debstash debstash
# define PL_diehook diehook
# define PL_dowarn dowarn
# define PL_hexdigit hexdigit
# define PL_no_modify no_modify
# define PL_perl_destruct_level perl_destruct_level
# define PL_perldb perldb
# define PL_ppaddr ppaddr
# define PL_rsfp_filters rsfp_filters
# define PL_stack_base stack_base
# define PL_stack_sp stack_sp
# define PL_stdingv stdingv
# define PL_sv_arenaroot sv_arenaroot
# define PL_sv_undef sv_undef
# define PL_sv_yes sv_yes
# define PL_tainted tainted
# define PL_tainting tainting
# if (defined(__GNUC__) && defined(__cplusplus)) || defined(__INTEL_COMPILER)
# define PERL_UNUSED_DECL
# define PERL_UNUSED_DECL __attribute__((unused))
# define PERL_UNUSED_DECL
# define dNOOP extern int Perl___notused PERL_UNUSED_DECL
# if defined(USE_LONG_DOUBLE) && defined(HAS_LONG_DOUBLE)
# define NVTYPE long double
# if (IVSIZE == PTRSIZE) && (UVSIZE == PTRSIZE)
# define INT2PTR(any,d) (any)(d)
# define PTRV unsigned long
# define INT2PTR(any,d) (any)(PTRV)(d)
# define NUM2PTR(any,d) (any)(PTRV)(d)
# define PTR2IV(p) INT2PTR(IV,p)
# define PTR2UV(p) INT2PTR(UV,p)
# define PTR2NV(p) NUM2PTR(NV,p)
# define PTR2ul(p) (unsigned long)(p)
# define PTR2ul(p) INT2PTR(unsigned long,p)
# define START_EXTERN_C extern "C" {
# define EXTERN_C extern "C"
#ifndef PERL_GCC_BRACE_GROUPS_FORBIDDEN
# if defined(__STRICT_ANSI__) && defined(PERL_GCC_PEDANTIC)
# define PERL_GCC_BRACE_GROUPS_FORBIDDEN
#if defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN) && !defined(__cplusplus)
# define STMT_START (void)( /* gcc supports ``({ STATEMENTS; })'' */
# if defined(VOIDFLAGS) && (VOIDFLAGS) && (defined(sun) || defined(__sun__)) && !defined(__GNUC__)
# define STMT_START if (1)
# define STMT_END else (void)0
# define STMT_END while (0)
# define boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no)
/* DEFSV appears first in 5.004_56 */
# define DEFSV GvSV(PL_defgv)
# define SAVE_DEFSV SAVESPTR(GvSV(PL_defgv))
/* Older perls (<=5.003) lack AvFILLp */
# define ERRSV get_sv("@",FALSE)
# define newSVpvn(data,len) ((data) \
?
((len
) ? newSVpv
((data
), (len
)) : newSVpv
("", 0)) \
* This function
's backport doesn't support the
length parameter
, but
* rather ignores it
. Portability can only be ensured
if the
length
* parameter is used
for speed reasons
, but the
length can always be
* correctly computed from the string argument
.
# define gv_stashpvn(str,len,create) gv_stashpv(str,create)
# define get_cv perl_get_cv
# define get_sv perl_get_sv
# define get_av perl_get_av
# define get_hv perl_get_hv
# define memNE(s1,s2,l) (memcmp(s1,s2,l))
# define memEQ(s1,s2,l) (!memcmp(s1,s2,l))
# define memNE(s1,s2,l) (bcmp(s1,s2,l))
# define memEQ(s1,s2,l) (!bcmp(s1,s2,l))
# define MoveD(s,d,n,t) memmove((char*)(d),(char*)(s), (n) * sizeof(t))
# define CopyD(s,d,n,t) memcpy((char*)(d),(char*)(s), (n) * sizeof(t))
# define ZeroD(d,n,t) memzero((char*)(d), (n) * sizeof(t))
# define ZeroD(d,n,t) ((void)memzero((char*)(d), (n) * sizeof(t)),d)
# define Poison(d,n,t) (void)memset((char*)(d), 0xAB, (n) * sizeof(t))
# define dAX I32 ax = MARK - PL_stack_base + 1
# define dITEMS I32 items = SP - MARK
# define dXSTARG SV * targ = sv_newmortal()
# define dTHXoa(x) dTHXa(x)
# define PUSHmortal PUSHs(sv_newmortal())
# define mPUSHp(p,l) sv_setpvn_mg(PUSHmortal, (p), (l))
# define mPUSHn(n) sv_setnv_mg(PUSHmortal, (NV)(n))
# define mPUSHi(i) sv_setiv_mg(PUSHmortal, (IV)(i))
# define mPUSHu(u) sv_setuv_mg(PUSHmortal, (UV)(u))
# define XPUSHmortal XPUSHs(sv_newmortal())
# define mXPUSHp(p,l) STMT_START { EXTEND(sp,1); sv_setpvn_mg(PUSHmortal, (p), (l)); } STMT_END
# define mXPUSHn(n) STMT_START { EXTEND(sp,1); sv_setnv_mg(PUSHmortal, (NV)(n)); } STMT_END
# define mXPUSHi(i) STMT_START { EXTEND(sp,1); sv_setiv_mg(PUSHmortal, (IV)(i)); } STMT_END
# define mXPUSHu(u) STMT_START { EXTEND(sp,1); sv_setuv_mg(PUSHmortal, (UV)(u)); } STMT_END
# define call_sv perl_call_sv
# define call_pv perl_call_pv
# define call_argv perl_call_argv
# define call_method perl_call_method
# define eval_sv perl_eval_sv
/* Replace perl_eval_pv with eval_pv */
/* eval_pv depends on eval_sv */
#if defined(NEED_eval_pv)
static SV
* DPPP_
(my_eval_pv
)(char
*p
, I32 croak_on_error
);
extern SV
* DPPP_
(my_eval_pv
)(char
*p
, I32 croak_on_error
);
#define eval_pv(a,b) DPPP_(my_eval_pv)(aTHX_ a,b)
#define Perl_eval_pv DPPP_(my_eval_pv)
#if defined(NEED_eval_pv) || defined(NEED_eval_pv_GLOBAL)
DPPP_
(my_eval_pv
)(char
*p
, I32 croak_on_error
)
if (croak_on_error
&& SvTRUE
(GvSV
(errgv
)))
croak
(SvPVx
(GvSV
(errgv
), na
));
# define newRV_inc(sv) newRV(sv) /* Replace */
#if defined(NEED_newRV_noinc)
static SV
* DPPP_
(my_newRV_noinc
)(SV
*sv
);
extern SV
* DPPP_
(my_newRV_noinc
)(SV
*sv
);
#define newRV_noinc(a) DPPP_(my_newRV_noinc)(aTHX_ a)
#define Perl_newRV_noinc DPPP_(my_newRV_noinc)
#if defined(NEED_newRV_noinc) || defined(NEED_newRV_noinc_GLOBAL)
DPPP_
(my_newRV_noinc
)(SV
*sv
)
SV
*rv
= (SV
*)newRV
(sv
);
* Returns a CV
* as of perl
-5.7.1. This
return value is
not supported
/* newCONSTSUB from IO.xs is in the core starting with 5.004_63 */
#if ((PERL_VERSION < 4) || ((PERL_VERSION == 4) && (PERL_SUBVERSION < 63))) && ((PERL_VERSION != 4) || (PERL_SUBVERSION != 5))
#if defined(NEED_newCONSTSUB)
static void DPPP_
(my_newCONSTSUB
)(HV
*stash
, char
*name
, SV
*sv
);
extern void DPPP_
(my_newCONSTSUB
)(HV
*stash
, char
*name
, SV
*sv
);
#define newCONSTSUB(a,b,c) DPPP_(my_newCONSTSUB)(aTHX_ a,b,c)
#define Perl_newCONSTSUB DPPP_(my_newCONSTSUB)
#if defined(NEED_newCONSTSUB) || defined(NEED_newCONSTSUB_GLOBAL)
DPPP_
(my_newCONSTSUB
)(HV
*stash
, char
*name
, SV
*sv
)
HV
*old_cop_stash
= PL_curcop
->cop_stash;
HV
*old_curstash
= PL_curstash
;
line_t oldline
= PL_curcop
->cop_line;
PL_curcop
->cop_line = PL_copline
;
PL_hints
&= ~HINT_BLOCK_SCOPE
;
PL_curstash
= PL_curcop
->cop_stash = stash
;
#if ((PERL_VERSION < 3) || ((PERL_VERSION == 3) && (PERL_SUBVERSION < 22)))
#elif ((PERL_VERSION == 3) && (PERL_SUBVERSION == 22))
#else /* 5.003_23 onwards */
start_subparse
(FALSE
, 0),
newSVOP
(OP_CONST
, 0, newSVpv
(name
,0)),
newSVOP
(OP_CONST
, 0, &PL_sv_no
), /* SvPV(&PL_sv_no) == "" -- GMB */
newSTATEOP
(0, Nullch
, newSVOP
(OP_CONST
, 0, sv
))
PL_curcop
->cop_stash = old_cop_stash
;
PL_curstash
= old_curstash
;
PL_curcop
->cop_line = oldline
;
* Boilerplate macros
for initializing
and accessing interpreter
-local
* data from C
. All statics
in extensions should be reworked to
use
* this
, if you want to make the extension thread
-safe
. See ext
/re/re
.xs
* for an example of the
use of these macros
.
* Code that uses these macros is responsible
for the following
:
* 1. #define MY_CXT_KEY to a unique string, e.g. "DynaLoader_guts"
* 2. Declare a typedef named my_cxt_t that is a structure that contains
* all the data that needs to be interpreter
-local.
* 3. Use the START_MY_CXT macro after the declaration of my_cxt_t
.
* 4. Use the MY_CXT_INIT macro such that it is called exactly once
* (typically put
in the BOOT
: section
).
* 5. Use the members of the my_cxt_t structure everywhere as
* 6. Use the dMY_CXT macro
(a declaration
) in all the functions that
#if defined(MULTIPLICITY) || defined(PERL_OBJECT) || \
defined(PERL_CAPI
) || defined(PERL_IMPLICIT_CONTEXT
)
/* This must appear
in all extensions that define a my_cxt_t structure
,
* right after the definition
(i
.e
. at file scope
). The non
-threads
* case below uses it to declare the data as static
. */
#if (PERL_VERSION < 4 || (PERL_VERSION == 4 && PERL_SUBVERSION < 68 ))
/* Fetches the SV that keeps the per-interpreter data. */
SV
*my_cxt_sv
= get_sv
(MY_CXT_KEY
, FALSE
)
#else /* >= perl5.004_68 */
SV
*my_cxt_sv
= *hv_fetch
(PL_modglobal
, MY_CXT_KEY
, \
sizeof
(MY_CXT_KEY
)-1, TRUE
)
#endif /* < perl5.004_68 */
/* This declaration should be used within all functions that
use the
* interpreter
-local data
. */
my_cxt_t
*my_cxtp
= INT2PTR
(my_cxt_t
*,SvUV
(my_cxt_sv
))
/* Creates
and zeroes the per
-interpreter data
.
* (We allocate my_cxtp
in a Perl SV so that it will be released
when
* the interpreter goes away
.) */
/* newSV() allocates one more than needed */ \
my_cxt_t
*my_cxtp
= (my_cxt_t
*)SvPVX
(newSV
(sizeof
(my_cxt_t
)-1));\
Zero
(my_cxtp
, 1, my_cxt_t
); \
sv_setuv
(my_cxt_sv
, PTR2UV
(my_cxtp
))
/* This macro must be used to access members of the my_cxt_t structure
.
* e
.g
. MYCXT
.some_data
*/
#define MY_CXT (*my_cxtp)
/* Judicious
use of these macros can reduce the number of
times dMY_CXT
* is used
. Use is similar to pTHX
, aTHX etc
. */
#define pMY_CXT my_cxt_t *my_cxtp
#define pMY_CXT_ pMY_CXT,
#define _pMY_CXT ,pMY_CXT
#define aMY_CXT_ aMY_CXT,
#define _aMY_CXT ,aMY_CXT
#endif /* START_MY_CXT */
/* Clones the per-interpreter data. */
my_cxt_t
*my_cxtp
= (my_cxt_t
*)SvPVX
(newSV
(sizeof
(my_cxt_t
)-1));\
Copy
(INT2PTR
(my_cxt_t
*, SvUV
(my_cxt_sv
)), my_cxtp
, 1, my_cxt_t
);\
sv_setuv
(my_cxt_sv
, PTR2UV
(my_cxtp
))
#else /* single interpreter */
#define START_MY_CXT static my_cxt_t my_cxt;
#endif /* START_MY_CXT */
#define MY_CXT_CLONE NOOP
# if defined(USE_LONG_DOUBLE) && defined(HAS_LONG_DOUBLE) && \
defined(PERL_PRIfldbl
) /* Not very likely, but let's try anyway. */
# define NVef PERL_PRIeldbl
# define NVff PERL_PRIfldbl
# define NVgf PERL_PRIgldbl
#if defined(NEED_sv_2pv_nolen)
static char
* DPPP_
(my_sv_2pv_nolen
)(pTHX_ register SV
*sv
);
extern char
* DPPP_
(my_sv_2pv_nolen
)(pTHX_ register SV
*sv
);
#define sv_2pv_nolen(a) DPPP_(my_sv_2pv_nolen)(aTHX_ a)
#define Perl_sv_2pv_nolen DPPP_(my_sv_2pv_nolen)
#if defined(NEED_sv_2pv_nolen) || defined(NEED_sv_2pv_nolen_GLOBAL)
DPPP_
(my_sv_2pv_nolen
)(pTHX_ register SV
*sv
)
* Use the SvPV_nolen
() macro instead of sv_2pv_nolen
().
/* SvPV_nolen depends on sv_2pv_nolen */
((SvFLAGS
(sv
) & (SVf_POK
)) == SVf_POK \
? SvPVX
(sv
) : sv_2pv_nolen
(sv
))
* Does
not work
in perl
-5.6.1, ppport
.h implements a version
* borrowed from perl
-5.7.3.
#if ((PERL_VERSION < 7) || ((PERL_VERSION == 7) && (PERL_SUBVERSION < 0)))
#if defined(NEED_sv_2pvbyte)
static char
* DPPP_
(my_sv_2pvbyte
)(pTHX_ register SV
*sv
, STRLEN
*lp
);
extern char
* DPPP_
(my_sv_2pvbyte
)(pTHX_ register SV
*sv
, STRLEN
*lp
);
#define sv_2pvbyte(a,b) DPPP_(my_sv_2pvbyte)(aTHX_ a,b)
#define Perl_sv_2pvbyte DPPP_(my_sv_2pvbyte)
#if defined(NEED_sv_2pvbyte) || defined(NEED_sv_2pvbyte_GLOBAL)
DPPP_
(my_sv_2pvbyte
)(pTHX_ register SV
*sv
, STRLEN
*lp
)
* Use the SvPVbyte
() macro instead of sv_2pvbyte
().
/* SvPVbyte depends on sv_2pvbyte */
#define SvPVbyte(sv, lp) \
((SvFLAGS
(sv
) & (SVf_POK
|SVf_UTF8
)) == (SVf_POK
) \
?
((lp
= SvCUR
(sv
)), SvPVX
(sv
)) : sv_2pvbyte
(sv
, &lp
))
# define sv_2pvbyte sv_2pv
/* sv_2pvbyte_nolen depends on sv_2pv_nolen */
# define sv_2pvbyte_nolen sv_2pv_nolen
* Always
use the SvPV
() macro instead of sv_pvn
().
# define sv_pvn(sv, len) SvPV(sv, len)
* Always
use the SvPV_force
() macro instead of sv_pvn_force
().
# define sv_pvn_force(sv, len) SvPV_force(sv, len)
#if ((PERL_VERSION > 4) || ((PERL_VERSION == 4) && (PERL_SUBVERSION >= 0))) && !defined(vnewSVpvf)
#if defined(NEED_vnewSVpvf)
static SV
* DPPP_
(my_vnewSVpvf
)(pTHX_ const char
* pat
, va_list
* args
);
extern SV
* DPPP_
(my_vnewSVpvf
)(pTHX_ const char
* pat
, va_list
* args
);
#define vnewSVpvf(a,b) DPPP_(my_vnewSVpvf)(aTHX_ a,b)
#define Perl_vnewSVpvf DPPP_(my_vnewSVpvf)
#if defined(NEED_vnewSVpvf) || defined(NEED_vnewSVpvf_GLOBAL)
DPPP_
(my_vnewSVpvf
)(pTHX_ const char
*pat
, va_list
*args
)
register SV
*sv
= newSV
(0);
sv_vsetpvfn
(sv
, pat
, strlen
(pat
), args
, Null
(SV
**), 0, Null
(bool
*));
/* sv_vcatpvf depends on sv_vcatpvfn */
#if ((PERL_VERSION > 4) || ((PERL_VERSION == 4) && (PERL_SUBVERSION >= 0))) && !defined(sv_vcatpvf)
# define sv_vcatpvf(sv, pat, args) sv_vcatpvfn(sv, pat, strlen(pat), args, Null(SV**), 0, Null(bool*))
/* sv_vsetpvf depends on sv_vsetpvfn */
#if ((PERL_VERSION > 4) || ((PERL_VERSION == 4) && (PERL_SUBVERSION >= 0))) && !defined(sv_vsetpvf)
# define sv_vsetpvf(sv, pat, args) sv_vsetpvfn(sv, pat, strlen(pat), args, Null(SV**), 0, Null(bool*))
/* sv_catpvf_mg depends on sv_vcatpvfn, sv_catpvf_mg_nocontext */
#if ((PERL_VERSION > 4) || ((PERL_VERSION == 4) && (PERL_SUBVERSION >= 0))) && !defined(sv_catpvf_mg)
#if defined(NEED_sv_catpvf_mg)
static void DPPP_
(my_sv_catpvf_mg
)(pTHX_ SV
* sv
, const char
* pat
, ...);
extern void DPPP_
(my_sv_catpvf_mg
)(pTHX_ SV
* sv
, const char
* pat
, ...);
#define Perl_sv_catpvf_mg DPPP_(my_sv_catpvf_mg)
#if defined(NEED_sv_catpvf_mg) || defined(NEED_sv_catpvf_mg_GLOBAL)
DPPP_
(my_sv_catpvf_mg
)(pTHX_ SV
*sv
, const char
*pat
, ...)
sv_vcatpvfn
(sv
, pat
, strlen
(pat
), &args
, Null
(SV
**), 0, Null
(bool
*));
/* sv_catpvf_mg_nocontext depends on sv_vcatpvfn */
#ifdef PERL_IMPLICIT_CONTEXT
#if ((PERL_VERSION > 4) || ((PERL_VERSION == 4) && (PERL_SUBVERSION >= 0))) && !defined(sv_catpvf_mg_nocontext)
#if defined(NEED_sv_catpvf_mg_nocontext)
static void DPPP_
(my_sv_catpvf_mg_nocontext
)(SV
* sv
, const char
* pat
, ...);
extern void DPPP_
(my_sv_catpvf_mg_nocontext
)(SV
* sv
, const char
* pat
, ...);
#define sv_catpvf_mg_nocontext DPPP_(my_sv_catpvf_mg_nocontext)
#define Perl_sv_catpvf_mg_nocontext DPPP_(my_sv_catpvf_mg_nocontext)
#if defined(NEED_sv_catpvf_mg_nocontext) || defined(NEED_sv_catpvf_mg_nocontext_GLOBAL)
DPPP_
(my_sv_catpvf_mg_nocontext
)(SV
*sv
, const char
*pat
, ...)
sv_vcatpvfn
(sv
, pat
, strlen
(pat
), &args
, Null
(SV
**), 0, Null
(bool
*));
# ifdef PERL_IMPLICIT_CONTEXT
# define sv_catpvf_mg Perl_sv_catpvf_mg_nocontext
# define sv_catpvf_mg Perl_sv_catpvf_mg
/* sv_vcatpvf_mg depends on sv_vcatpvfn */
#if ((PERL_VERSION > 4) || ((PERL_VERSION == 4) && (PERL_SUBVERSION >= 0))) && !defined(sv_vcatpvf_mg)
# define sv_vcatpvf_mg(sv, pat, args) \
sv_vcatpvfn
(sv
, pat
, strlen
(pat
), args
, Null
(SV
**), 0, Null
(bool
*)); \
/* sv_setpvf_mg depends on sv_vsetpvfn, sv_setpvf_mg_nocontext */
#if ((PERL_VERSION > 4) || ((PERL_VERSION == 4) && (PERL_SUBVERSION >= 0))) && !defined(sv_setpvf_mg)
#if defined(NEED_sv_setpvf_mg)
static void DPPP_
(my_sv_setpvf_mg
)(pTHX_ SV
* sv
, const char
* pat
, ...);
extern void DPPP_
(my_sv_setpvf_mg
)(pTHX_ SV
* sv
, const char
* pat
, ...);
#define Perl_sv_setpvf_mg DPPP_(my_sv_setpvf_mg)
#if defined(NEED_sv_setpvf_mg) || defined(NEED_sv_setpvf_mg_GLOBAL)
DPPP_
(my_sv_setpvf_mg
)(pTHX_ SV
*sv
, const char
*pat
, ...)
sv_vsetpvfn
(sv
, pat
, strlen
(pat
), &args
, Null
(SV
**), 0, Null
(bool
*));
/* sv_setpvf_mg_nocontext depends on sv_vsetpvfn */
#ifdef PERL_IMPLICIT_CONTEXT
#if ((PERL_VERSION > 4) || ((PERL_VERSION == 4) && (PERL_SUBVERSION >= 0))) && !defined(sv_setpvf_mg_nocontext)
#if defined(NEED_sv_setpvf_mg_nocontext)
static void DPPP_
(my_sv_setpvf_mg_nocontext
)(SV
* sv
, const char
* pat
, ...);
extern void DPPP_
(my_sv_setpvf_mg_nocontext
)(SV
* sv
, const char
* pat
, ...);
#define sv_setpvf_mg_nocontext DPPP_(my_sv_setpvf_mg_nocontext)
#define Perl_sv_setpvf_mg_nocontext DPPP_(my_sv_setpvf_mg_nocontext)
#if defined(NEED_sv_setpvf_mg_nocontext) || defined(NEED_sv_setpvf_mg_nocontext_GLOBAL)
DPPP_
(my_sv_setpvf_mg_nocontext
)(SV
*sv
, const char
*pat
, ...)
sv_vsetpvfn
(sv
, pat
, strlen
(pat
), &args
, Null
(SV
**), 0, Null
(bool
*));
# ifdef PERL_IMPLICIT_CONTEXT
# define sv_setpvf_mg Perl_sv_setpvf_mg_nocontext
# define sv_setpvf_mg Perl_sv_setpvf_mg
/* sv_vsetpvf_mg depends on sv_vsetpvfn */
#if ((PERL_VERSION > 4) || ((PERL_VERSION == 4) && (PERL_SUBVERSION >= 0))) && !defined(sv_vsetpvf_mg)
# define sv_vsetpvf_mg(sv, pat, args) \
sv_vsetpvfn
(sv
, pat
, strlen
(pat
), args
, Null
(SV
**), 0, Null
(bool
*)); \
# define SvGETMAGIC(x) STMT_START { if (SvGMAGICAL(x)) mg_get(x); } STMT_END
# define PERL_MAGIC_sv '\0'
#ifndef PERL_MAGIC_overload
# define PERL_MAGIC_overload 'A'
#ifndef PERL_MAGIC_overload_elem
# define PERL_MAGIC_overload_elem 'a'
#ifndef PERL_MAGIC_overload_table
# define PERL_MAGIC_overload_table 'c'
# define PERL_MAGIC_bm 'B'
#ifndef PERL_MAGIC_regdata
# define PERL_MAGIC_regdata 'D'
#ifndef PERL_MAGIC_regdatum
# define PERL_MAGIC_regdatum 'd'
# define PERL_MAGIC_env 'E'
#ifndef PERL_MAGIC_envelem
# define PERL_MAGIC_envelem 'e'
# define PERL_MAGIC_fm 'f'
#ifndef PERL_MAGIC_regex_global
# define PERL_MAGIC_regex_global 'g'
# define PERL_MAGIC_isa 'I'
#ifndef PERL_MAGIC_isaelem
# define PERL_MAGIC_isaelem 'i'
# define PERL_MAGIC_nkeys 'k'
#ifndef PERL_MAGIC_dbfile
# define PERL_MAGIC_dbfile 'L'
#ifndef PERL_MAGIC_dbline
# define PERL_MAGIC_dbline 'l'
# define PERL_MAGIC_mutex 'm'
#ifndef PERL_MAGIC_shared
# define PERL_MAGIC_shared 'N'
#ifndef PERL_MAGIC_shared_scalar
# define PERL_MAGIC_shared_scalar 'n'
#ifndef PERL_MAGIC_collxfrm
# define PERL_MAGIC_collxfrm 'o'
# define PERL_MAGIC_tied 'P'
#ifndef PERL_MAGIC_tiedelem
# define PERL_MAGIC_tiedelem 'p'
#ifndef PERL_MAGIC_tiedscalar
# define PERL_MAGIC_tiedscalar 'q'
# define PERL_MAGIC_qr 'r'
# define PERL_MAGIC_sig 'S'
#ifndef PERL_MAGIC_sigelem
# define PERL_MAGIC_sigelem 's'
# define PERL_MAGIC_taint 't'
# define PERL_MAGIC_uvar 'U'
#ifndef PERL_MAGIC_uvar_elem
# define PERL_MAGIC_uvar_elem 'u'
#ifndef PERL_MAGIC_vstring
# define PERL_MAGIC_vstring 'V'
# define PERL_MAGIC_vec 'v'
# define PERL_MAGIC_utf8 'w'
#ifndef PERL_MAGIC_substr
# define PERL_MAGIC_substr 'x'
#ifndef PERL_MAGIC_defelem
# define PERL_MAGIC_defelem 'y'
# define PERL_MAGIC_glob '*'
#ifndef PERL_MAGIC_arylen
# define PERL_MAGIC_arylen '#'
# define PERL_MAGIC_pos '.'
#ifndef PERL_MAGIC_backref
# define PERL_MAGIC_backref '<'
# define PERL_MAGIC_ext '~'
/* That's the best we can do... */
# define SvPV_force_nomg SvPV_force
# define sv_catpvn_nomg sv_catpvn
# define sv_catsv_nomg sv_catsv
# define sv_setsv_nomg sv_setsv
# define sv_pvn_nomg sv_pvn
# define sv_catpv_mg(sv, ptr) \
# define sv_catpvn_mg(sv, ptr, len) \
sv_catpvn
(TeMpSv
,ptr
,len
); \
# define sv_catsv_mg(dsv, ssv) \
# define sv_setiv_mg(sv, i) \
# define sv_setnv_mg(sv, num) \
# define sv_setpv_mg(sv, ptr) \
# define sv_setpvn_mg(sv, ptr, len) \
sv_setpvn
(TeMpSv
,ptr
,len
); \
# define sv_setsv_mg(dsv, ssv) \
# define sv_setuv_mg(sv, i) \
# define sv_usepvn_mg(sv, ptr, len) \
sv_usepvn
(TeMpSv
,ptr
,len
); \
# define CopFILE(c) ((c)->cop_file)
# define CopFILEGV(c) (CopFILE(c) ? gv_fetchfile(CopFILE(c)) : Nullgv)
# define CopFILE_set(c,pv) ((c)->cop_file = savepv(pv))
# define CopFILESV(c) (CopFILE(c) ? GvSV(gv_fetchfile(CopFILE(c))) : Nullsv)
# define CopFILEAV(c) (CopFILE(c) ? GvAV(gv_fetchfile(CopFILE(c))) : Nullav)
# define CopSTASHPV(c) ((c)->cop_stashpv)
# define CopSTASHPV_set(c,pv) ((c)->cop_stashpv = ((pv) ? savepv(pv) : Nullch))
# define CopSTASH(c) (CopSTASHPV(c) ? gv_stashpv(CopSTASHPV(c),GV_ADD) : Nullhv)
# define CopSTASH_set(c,hv) CopSTASHPV_set(c, (hv) ? HvNAME(hv) : Nullch)
# define CopSTASH_eq(c,hv) ((hv) && (CopSTASHPV(c) == HvNAME(hv) \
|| (CopSTASHPV
(c
) && HvNAME
(hv
) \
&& strEQ
(CopSTASHPV
(c
), HvNAME
(hv
)))))
# define CopFILEGV(c) ((c)->cop_filegv)
# define CopFILEGV_set(c,gv) ((c)->cop_filegv = (GV*)SvREFCNT_inc(gv))
# define CopFILE_set(c,pv) CopFILEGV_set((c), gv_fetchfile(pv))
# define CopFILESV(c) (CopFILEGV(c) ? GvSV(CopFILEGV(c)) : Nullsv)
# define CopFILEAV(c) (CopFILEGV(c) ? GvAV(CopFILEGV(c)) : Nullav)
# define CopFILE(c) (CopFILESV(c) ? SvPVX(CopFILESV(c)) : Nullch)
# define CopSTASH(c) ((c)->cop_stash)
# define CopSTASH_set(c,hv) ((c)->cop_stash = (hv))
# define CopSTASHPV(c) (CopSTASH(c) ? HvNAME(CopSTASH(c)) : Nullch)
# define CopSTASHPV_set(c,pv) CopSTASH_set((c), gv_stashpv(pv,GV_ADD))
# define CopSTASH_eq(c,hv) (CopSTASH(c) == (hv))
#endif /* USE_ITHREADS */
#ifndef IN_PERL_COMPILETIME
# define IN_PERL_COMPILETIME (PL_curcop == &PL_compiling)
#ifndef IN_LOCALE_RUNTIME
# define IN_LOCALE_RUNTIME (PL_curcop->op_private & HINT_LOCALE)
#ifndef IN_LOCALE_COMPILETIME
# define IN_LOCALE_COMPILETIME (PL_hints & HINT_LOCALE)
# define IN_LOCALE (IN_PERL_COMPILETIME ? IN_LOCALE_COMPILETIME : IN_LOCALE_RUNTIME)
# define IS_NUMBER_IN_UV 0x01
#ifndef IS_NUMBER_GREATER_THAN_UV_MAX
# define IS_NUMBER_GREATER_THAN_UV_MAX 0x02
#ifndef IS_NUMBER_NOT_INT
# define IS_NUMBER_NOT_INT 0x04
# define IS_NUMBER_NEG 0x08
#ifndef IS_NUMBER_INFINITY
# define IS_NUMBER_INFINITY 0x10
# define IS_NUMBER_NAN 0x20
/* GROK_NUMERIC_RADIX depends on grok_numeric_radix */
#ifndef GROK_NUMERIC_RADIX
# define GROK_NUMERIC_RADIX(sp, send) grok_numeric_radix(sp, send)
#ifndef PERL_SCAN_GREATER_THAN_UV_MAX
# define PERL_SCAN_GREATER_THAN_UV_MAX 0x02
#ifndef PERL_SCAN_SILENT_ILLDIGIT
# define PERL_SCAN_SILENT_ILLDIGIT 0x04
#ifndef PERL_SCAN_ALLOW_UNDERSCORES
# define PERL_SCAN_ALLOW_UNDERSCORES 0x01
#ifndef PERL_SCAN_DISALLOW_PREFIX
# define PERL_SCAN_DISALLOW_PREFIX 0x02
#ifndef grok_numeric_radix
#if defined(NEED_grok_numeric_radix)
static bool DPPP_
(my_grok_numeric_radix
)(pTHX_ const char
** sp
, const char
* send);
extern bool DPPP_
(my_grok_numeric_radix
)(pTHX_ const char
** sp
, const char
* send);
#ifdef grok_numeric_radix
# undef grok_numeric_radix
#define grok_numeric_radix(a,b) DPPP_(my_grok_numeric_radix)(aTHX_ a,b)
#define Perl_grok_numeric_radix DPPP_(my_grok_numeric_radix)
#if defined(NEED_grok_numeric_radix) || defined(NEED_grok_numeric_radix_GLOBAL)
DPPP_
(my_grok_numeric_radix
)(pTHX_ const char
**sp
, const char
*send)
#ifdef USE_LOCALE_NUMERIC
#ifdef PL_numeric_radix_sv
if (PL_numeric_radix_sv
&& IN_LOCALE
) {
char
* radix
= SvPV
(PL_numeric_radix_sv
, len
);
if (*sp
+ len
<= send && memEQ
(*sp
, radix
, len
)) {
/* older perls don
't have PL_numeric_radix_sv so the radix
* must manually be requested from locale.h
dTHR; /* needed for older threaded perls */
struct lconv *lc = localeconv();
char *radix = lc->decimal_point;
if (radix && IN_LOCALE) {
STRLEN len = strlen(radix);
if (*sp + len <= send && memEQ(*sp, radix, len)) {
#endif /* PERL_VERSION */
#endif /* USE_LOCALE_NUMERIC */
/* always try "." if numeric radix didn't match because
* we may have data from different locales mixed
*/
if (*sp
< send && **sp
== '.') {
/* grok_number depends on grok_numeric_radix */
#if defined(NEED_grok_number)
static
int DPPP_
(my_grok_number
)(pTHX_ const char
* pv
, STRLEN len
, UV
* valuep
);
extern
int DPPP_
(my_grok_number
)(pTHX_ const char
* pv
, STRLEN len
, UV
* valuep
);
#define grok_number(a,b,c) DPPP_(my_grok_number)(aTHX_ a,b,c)
#define Perl_grok_number DPPP_(my_grok_number)
#if defined(NEED_grok_number) || defined(NEED_grok_number_GLOBAL)
DPPP_
(my_grok_number
)(pTHX_ const char
*pv
, STRLEN len
, UV
*valuep
)
const char
*send = pv
+ len
;
const UV max_div_10
= UV_MAX
/ 10;
const char max_mod_10
= UV_MAX
% 10;
while (s
< send && isSPACE
(*s
))
/* next must be digit or the radix separator or beginning of infinity */
/* UVs are at least
32 bits
, so the first
9 decimal digits cannot
/* This construction seems to be more optimiser friendly
.
(without it gcc does the isDIGIT test
and the
*s
- '0' separately
)
With it gcc on arm is managing
6 instructions
(6 cycles
) per digit
.
In theory the optimiser could deduce how far to unroll the
loop
before checking
for overflow
. */
if (digit
>= 0 && digit
<= 9) {
value
= value
* 10 + digit
;
if (digit
>= 0 && digit
<= 9) {
value
= value
* 10 + digit
;
if (digit
>= 0 && digit
<= 9) {
value
= value
* 10 + digit
;
if (digit
>= 0 && digit
<= 9) {
value
= value
* 10 + digit
;
if (digit
>= 0 && digit
<= 9) {
value
= value
* 10 + digit
;
if (digit
>= 0 && digit
<= 9) {
value
= value
* 10 + digit
;
if (digit
>= 0 && digit
<= 9) {
value
= value
* 10 + digit
;
if (digit
>= 0 && digit
<= 9) {
value
= value
* 10 + digit
;
/* Now got
9 digits
, so need to check
each time for overflow
. */
while (digit
>= 0 && digit
<= 9
&& digit
<= max_mod_10
))) {
value
= value
* 10 + digit
;
if (digit
>= 0 && digit
<= 9
skip the remaining digits
, don
't
worry about setting *valuep. */
} while (s < send && isDIGIT(*s));
IS_NUMBER_GREATER_THAN_UV_MAX;
numtype |= IS_NUMBER_IN_UV;
if (GROK_NUMERIC_RADIX(&s, send)) {
numtype |= IS_NUMBER_NOT_INT;
while (s < send && isDIGIT(*s)) /* optional digits after the radix */
else if (GROK_NUMERIC_RADIX(&s, send)) {
numtype |= IS_NUMBER_NOT_INT | IS_NUMBER_IN_UV; /* valuep assigned below */
/* no digits before the radix means we need digits after it */
if (s < send && isDIGIT(*s)) {
} while (s < send && isDIGIT(*s));
/* integer approximation is valid - it's
0. */
} else if (*s
== 'I' || *s
== 'i') {
s
++; if (s
== send || (*s
!= 'N' && *s
!= 'n')) return 0;
s
++; if (s
== send || (*s
!= 'F' && *s
!= 'f')) return 0;
s
++; if (s
< send && (*s
== 'I' || *s
== 'i')) {
s
++; if (s
== send || (*s
!= 'N' && *s
!= 'n')) return 0;
s
++; if (s
== send || (*s
!= 'I' && *s
!= 'i')) return 0;
s
++; if (s
== send || (*s
!= 'T' && *s
!= 't')) return 0;
s
++; if (s
== send || (*s
!= 'Y' && *s
!= 'y')) return 0;
} else if (*s
== 'N' || *s
== 'n') {
/* XXX TODO: There are signaling NaNs and quiet NaNs. */
s
++; if (s
== send || (*s
!= 'A' && *s
!= 'a')) return 0;
s
++; if (s
== send || (*s
!= 'N' && *s
!= 'n')) return 0;
numtype
&= IS_NUMBER_NEG
; /* Keep track of sign */
numtype
|= IS_NUMBER_INFINITY
| IS_NUMBER_NOT_INT
;
numtype
&= IS_NUMBER_NEG
; /* Keep track of sign */
numtype
|= IS_NUMBER_NAN
| IS_NUMBER_NOT_INT
;
/* we can have an optional exponent part */
if (*s
== 'e' || *s
== 'E') {
/* The only flag we keep is sign. Blow away any "it's UV" */
numtype
&= IS_NUMBER_NEG
;
numtype
|= IS_NUMBER_NOT_INT
;
if (s
< send && (*s
== '-' || *s
== '+'))
if (s
< send && isDIGIT
(*s
)) {
} while (s
< send && isDIGIT
(*s
));
while (s
< send && isSPACE
(*s
))
if (len
== 10 && memEQ
(pv
, "0 but true", 10)) {
* The grok_
* routines have been modified to
use warn() instead of
* Perl_warner
(). Also
, 'hexdigit' was the former name of PL_hexdigit
,
* which is why the stack variable has been renamed to
'xdigit'.
#if defined(NEED_grok_bin)
static UV DPPP_
(my_grok_bin
)(pTHX_ char
*start
, STRLEN
*len_p
, I32
*flags
, NV
*result
);
extern UV DPPP_
(my_grok_bin
)(pTHX_ char
*start
, STRLEN
*len_p
, I32
*flags
, NV
*result
);
#define grok_bin(a,b,c,d) DPPP_(my_grok_bin)(aTHX_ a,b,c,d)
#define Perl_grok_bin DPPP_(my_grok_bin)
#if defined(NEED_grok_bin) || defined(NEED_grok_bin_GLOBAL)
DPPP_
(my_grok_bin
)(pTHX_ char
*start
, STRLEN
*len_p
, I32
*flags
, NV
*result
)
const UV max_div_2
= UV_MAX
/ 2;
bool allow_underscores
= *flags
& PERL_SCAN_ALLOW_UNDERSCORES
;
if (!(*flags
& PERL_SCAN_DISALLOW_PREFIX
)) {
/* strip off leading b
or 0b
.
for compatibility silently suffer
"b" and "0b" as valid binary
else if (len
>= 2 && s
[0] == '0' && s
[1] == 'b') {
for (; len
-- && *s
; s
++) {
if (bit
== '0' || bit
== '1') {
/* Write it
in this wonky order with a
goto to attempt to get the
compiler to make the common case integer
-only
loop pretty tight
.
With gcc seems to be much straighter code than old scan_bin
. */
if (value
<= max_div_2
) {
value
= (value
<< 1) | (bit
- '0');
/* Bah. We're just overflowed. */
warn("Integer overflow in binary number");
/* If an NV has
not enough bits
in its mantissa to
* represent a UV this summing of small low
-order numbers
* is a waste of
time (because the NV cannot preserve
* the low
-order bits anyway
): we could just remember
when
* did we overflow
and in the end just multiply value_nv by the
value_nv
+= (NV
)(bit
- '0');
if (bit
== '_' && len
&& allow_underscores
&& (bit
= s
[1])
&& (bit
== '0' || bit
== '1'))
if (!(*flags
& PERL_SCAN_SILENT_ILLDIGIT
))
warn("Illegal binary digit '%c' ignored", *s
);
if ( ( overflowed
&& value_nv
> 4294967295.0)
|| (!overflowed
&& value
> 0xffffffff )
warn("Binary number > 0b11111111111111111111111111111111 non-portable");
*flags
= PERL_SCAN_GREATER_THAN_UV_MAX
;
#if defined(NEED_grok_hex)
static UV DPPP_
(my_grok_hex
)(pTHX_ char
*start
, STRLEN
*len_p
, I32
*flags
, NV
*result
);
extern UV DPPP_
(my_grok_hex
)(pTHX_ char
*start
, STRLEN
*len_p
, I32
*flags
, NV
*result
);
#define grok_hex(a,b,c,d) DPPP_(my_grok_hex)(aTHX_ a,b,c,d)
#define Perl_grok_hex DPPP_(my_grok_hex)
#if defined(NEED_grok_hex) || defined(NEED_grok_hex_GLOBAL)
DPPP_
(my_grok_hex
)(pTHX_ char
*start
, STRLEN
*len_p
, I32
*flags
, NV
*result
)
const UV max_div_16
= UV_MAX
/ 16;
bool allow_underscores
= *flags
& PERL_SCAN_ALLOW_UNDERSCORES
;
if (!(*flags
& PERL_SCAN_DISALLOW_PREFIX
)) {
/* strip off leading x
or 0x
.
for compatibility silently suffer
"x" and "0x" as valid
hex numbers
.
else if (len
>= 2 && s
[0] == '0' && s
[1] == 'x') {
for (; len
-- && *s
; s
++) {
xdigit
= strchr
((char
*) PL_hexdigit
, *s
);
/* Write it
in this wonky order with a
goto to attempt to get the
compiler to make the common case integer
-only
loop pretty tight
.
With gcc seems to be much straighter code than old scan_hex
. */
if (value
<= max_div_16
) {
value
= (value
<< 4) | ((xdigit
- PL_hexdigit
) & 15);
warn("Integer overflow in hexadecimal number");
/* If an NV has
not enough bits
in its mantissa to
* represent a UV this summing of small low
-order numbers
* is a waste of
time (because the NV cannot preserve
* the low
-order bits anyway
): we could just remember
when
* did we overflow
and in the end just multiply value_nv by the
* right amount of
16-tuples
. */
value_nv
+= (NV
)((xdigit
- PL_hexdigit
) & 15);
if (*s
== '_' && len
&& allow_underscores
&& s
[1]
&& (xdigit
= strchr
((char
*) PL_hexdigit
, s
[1])))
if (!(*flags
& PERL_SCAN_SILENT_ILLDIGIT
))
warn("Illegal hexadecimal digit '%c' ignored", *s
);
if ( ( overflowed
&& value_nv
> 4294967295.0)
|| (!overflowed
&& value
> 0xffffffff )
warn("Hexadecimal number > 0xffffffff non-portable");
*flags
= PERL_SCAN_GREATER_THAN_UV_MAX
;
#if defined(NEED_grok_oct)
static UV DPPP_
(my_grok_oct
)(pTHX_ char
*start
, STRLEN
*len_p
, I32
*flags
, NV
*result
);
extern UV DPPP_
(my_grok_oct
)(pTHX_ char
*start
, STRLEN
*len_p
, I32
*flags
, NV
*result
);
#define grok_oct(a,b,c,d) DPPP_(my_grok_oct)(aTHX_ a,b,c,d)
#define Perl_grok_oct DPPP_(my_grok_oct)
#if defined(NEED_grok_oct) || defined(NEED_grok_oct_GLOBAL)
DPPP_
(my_grok_oct
)(pTHX_ char
*start
, STRLEN
*len_p
, I32
*flags
, NV
*result
)
const UV max_div_8
= UV_MAX
/ 8;
bool allow_underscores
= *flags
& PERL_SCAN_ALLOW_UNDERSCORES
;
for (; len
-- && *s
; s
++) {
/* gcc
2.95 optimiser
not smart enough to figure that this subtraction
out front allows slicker code
. */
if (digit
>= 0 && digit
<= 7) {
/* Write it
in this wonky order with a
goto to attempt to get the
compiler to make the common case integer
-only
loop pretty tight
.
if (value
<= max_div_8
) {
value
= (value
<< 3) | digit
;
/* Bah. We're just overflowed. */
warn("Integer overflow in octal number");
/* If an NV has
not enough bits
in its mantissa to
* represent a UV this summing of small low
-order numbers
* is a waste of
time (because the NV cannot preserve
* the low
-order bits anyway
): we could just remember
when
* did we overflow
and in the end just multiply value_nv by the
* right amount of
8-tuples
. */
if (digit
== ('_' - '0') && len
&& allow_underscores
&& (digit
= s
[1] - '0') && (digit
>= 0 && digit
<= 7))
/* Allow \octal to work the DWIM way
(that is
, stop scanning
* as soon as non
-octal characters are seen
, complain only iff
* someone seems to want to
use the digits eight
and nine
). */
if (digit
== 8 || digit
== 9) {
if (!(*flags
& PERL_SCAN_SILENT_ILLDIGIT
))
warn("Illegal octal digit '%c' ignored", *s
);
if ( ( overflowed
&& value_nv
> 4294967295.0)
|| (!overflowed
&& value
> 0xffffffff )
warn("Octal number > 037777777777 non-portable");
*flags
= PERL_SCAN_GREATER_THAN_UV_MAX
;
# define dXCPT dJMPENV; int rEtV = 0
# define XCPT_TRY_START JMPENV_PUSH(rEtV); if (rEtV == 0)
# define XCPT_TRY_END JMPENV_POP;
# define XCPT_CATCH if (rEtV != 0)
# define XCPT_RETHROW JMPENV_JUMP(rEtV)
# define dXCPT Sigjmp_buf oldTOP; int rEtV = 0
# define XCPT_TRY_START Copy(top_env, oldTOP, 1, Sigjmp_buf); rEtV = Sigsetjmp(top_env, 1); if (rEtV == 0)
# define XCPT_TRY_END Copy(oldTOP, top_env, 1, Sigjmp_buf);
# define XCPT_CATCH if (rEtV != 0)
# define XCPT_RETHROW Siglongjmp(top_env, rEtV)
#endif /* _P_P_PORTABILITY_H_ */
/* End of File ppport.h */