Rewrite bignum’s hex and oct overrides

As mentioned in <https://rt.cpan.org/Ticket/Display.html?id=79915>,
bigint.pm does not use any prototype when globally overriding hex.
This means that map { hex } ... will stop working in completely unre-
lated code if bigint happens to be loaded.  (Explicit $_ will con-
tinue to work.)

I thought it would be a simple matter of adding the right prototype
depending on perl version (and inferring $_), but the basic tests
I added failed for other reasons after I fixed the prototype and
$_ handling.

It turns out this whole thing is a mess, so I have basically reimple-
mented these two overrides.

What bigint, bignum and bigrat were doing was this: In import,
*CORE::GLOBAL::hex and ::oct are assigned functions that create
Math::BigInt objects if the pragma is in effect.  If import is passed
'hex' or 'oct', then the function assigned does not check the pragma
hints, but simply creates Math::BigInt objects regardless.

This means that ‘use bigrat’ stops hex() and oct() from creating
objects in ‘use bigint’ scopes, and vice versa.  In fact, whichever
pragma is loaded last wins.  Any scopes elsewhere in the program that
use the same pragma will have special hex() and oct() behaviour.  But
the other two lowercase big* pragmata will be disabled with regard to
hex and oct.

Having ‘use bigint 'hex'’ override hex globally makes no sense to me.
I have no qualms about changing it, as it was already broken.  Any
subsequent ‘use bigint;’ would turn off the global override.  So now
it exports hex or oct to the calling package, just like a normal mod-
ule.  You can now also call bigint::hex.

Also, in writing tests I found that oct("20") gives me 20.  Apparently
this was never tested properly.

I also found notes about ‘5.9.4 or later’ when the code checked
$] > 5.009004.  (Actually, in one place the code checked > 5.009003,
so I made it match, as we use the _ prototype now, which was intro-
duced in 5.9.5.)  One was in the docs, so I changed it to 5.10.0,
since  it is not helpful to mention dev versions.  The docs were also
wrong to imply that ‘no bigint’ would countermand ‘use bigint 'hex'’.
Increase bignum versions to 0.31 after the preceding change
bignum overrides.t: Skip some tests under 5.8
bigint: Fix new oct override for older Math::BigInt

Older versions of Math::BigInt required the input to from_oct to
begin with a 0.
bignum overrides.t: Fix for 5.8

We use the ;$ prototype for testing global overrides under 5.8, as it
had no _ prototype.  But back then (before 5.14, in fact) ;$ did not
give a function unary precedence.

Comparing against 5.009004 in bigint scope is the same as comparing
against 5, resulting in incorrect version checks and skips being
skipped.
bignum: Suppress warnings under 5.6

5.6 does not like it when a sub is declared with a prototype after a
reference to it has been taken.

5.6 does not think lowercase module names should be exempt from
reserved word warnings before ->.
Refactor Porting/Maintainers.pm to use Test::More instead of making TAP by hand.

With a small fix from committer: No use to eval {} module loading.
Note new Data::Dumper release in Porting/Maintainers.pl
Revert to string evals: EBCDIC

Archaeology tells me that it's string evals for a reason.

commit 933bc096593f55b9633fb193815ddd81d5b5ec1b
Author: Jarkko Hietaniemi <jhi@iki.fi>
Date:   Tue Nov 27 01:22:22 2001 +0000

    \141 is malformed "unexpected continuation byte" in UTF-EBCDIC.
    Delay the match until runtime.
Remove exports of dummy set[ug]id functions on Windows

These are surely not required by anything, and are only stub functions
anyway so can easily be provided locally by anything that really does need
them. Also hide the declarations other than when building the core itself
as per the fix for [perl #114516].
Make PerlIO::encoding more resilient to buffer changes

I was trying to figure out why Encode’s perlio.t was sometimes failing
under PERL_OLD_COPY_ON_WRITE (depending on the number of comments in
the source code, or metereological conditions).

I noticed that PerlIO::encoding assumes that the buffer passed to
the encode method will come back SvPOKp.  (It accesses SvCUR without
checking any flags.)

That means it can come back as a typeglob, reference, or undefined,
and PerlIO::encoding won’t care.  This can result in crashes.  Assign-
ing $_[1] = *foo inside an encode method is not a smart thing to do,
but it shouldn’t crash.

PerlIO::encoding was also assuming that SvPVX would not change between
calls to encode.  It is very easy to reallocate it.  This means the
internal buffer used by the encoding layer (which is owned by the
SV buffer passed to the encode method) can be freed and still subse-
quently written too, which is not good.

This commit makes PerlIO::encoding force stringification of the value
returned.  If it does not match its internal buffer pointers, it
resets them based on the buffer SV.

This probably makes Encode pass its tests under
PERL_OLD_COPY_ON_WRITE, but I have yet to confirm it.  Encoding mod-
ules are expected to write to the buffer ($_[1] = '') in certain
cases.  If COW is enabled, that would cause the buffer’s SvPVX to
point to the same string as the rhs, which would explain why the lack
of accounting for SvPVX changes caused test failures under
PERL_OLD_COPY_ON_WRITE.
Increase $PerlIO::encoding::VERSION to 0.16
[perl #79824] Don’t cow for sv_mortalcopy call from XS

XS code doing sv_mortalcopy(sv) will expect to get a true copy, and
not a COW ‘copy’.

So make sv_mortalcopy and wrapper around the new sv_mortalcopy_flags
that passes it SV_DO_COW_SVSETSV, which is defined as 0 for XS code.
Silence an uninitialized value warning.

As per precedent about 15 lines earlier in file, with respect to same
variable.
Fix spurious "uninitialized value" warning in regex match

The warning appeared if the pattern contains a floating substring for
which utf8 is needed, and the target string isn't in utf8.  In this
situation, downgrading the floating substring yields undef, which
triggers the warning.

Matching can't succeed in this situation, because it's impossible for
the non-utf8 target string to contain any string which needs utf8 for
its own representation.  So the warning is quelled by aborting the match
early.

Anchored substrings already have a check of this form; this commit makes
the corresponding change in the floating-substring case.
regexec.c: PATCH: [perl #114808]

Commit c72077c4fff72b66cdde1621c62fb4fd383ce093 fixed a place where
to_byte_substr() fails, but the code continued as if it had succeeded.

There is yet another place where the return is not checked.  This commit
adds a check there.

However, it turns out that there is another underlying problem to
[perl #114808].  The function to_byte_substr() tries to downgrade the
substr fields in the regex program it is passed.  If it fails (because
something in it is expressible only in UTF-8), it permanently changes
that field to point to PL_sv_undef, thus losing the original
information.  This is fine as long as the program will be used once and
discarded.  However, there are places where the program is re-used, as
in the test case introduced by this commit, and the original value has
been lost.

To solve this, this commit also changes to_byte_substr() from returning
void to instead returning bool, indicating success or failure.   On
failure, the original substrs are left intact.

The calls to this function are correspondingly changed.  One of them had
a trace statement when the failure happens, I reworded it to be more
general and accurate (it was slightly misleading), and added the trace
to every such place, not just the one.

In addition, I found the use of the same ternary operation in 3 or 4
consecutive lines very hard to understand; and is inefficient unless
compiled under C optimization which avoids recalculating things.  So I
expanded the several nearly identical places in the code that do that so
that I could quickly see what is going on.
sv.c: perlapi pod grammar
Fix infinite loop with $tied =~ s/non-utf8/utf8/

Commit 3e462cdc208 fixed bug #41530 (s/non-utf8/utf8/ was not working
properly at all) by upgrading the target and redoing the substitution
if the replacement was utf8 and the target was not.

Commit c95ca9b8cd1 fixed one problem with it calling get-magic too
many times, by checking whether the upgrade caused a string realloca-
tion and only then redoing the substitution.  But it only fixed it
when magic returns a pure ASCII string.

Redoing the substitution meant going back to where the target was
initially stringified and starting again.  That meant calling get-
magic again.

So in those cases where magic returned something other than a UTF8 or
pure ASCII string the substitution restarted and magic would be trig-
gered again, possibly resulting in infinite loops (because it would
have to be upgraded again, resulting a reallocation, and a restart).

This happens with:

• Latin-1 strings
• Copy-on-write non-UTF8 strings
• References that stringify without UTF8

c95ca9b8cd1 also added SvPVX without checking first that it is SvPVX-
able, so a typeglob causes an assertion failure.

It turned out that there were also two other places in pp_subst that
were calling FETCH a second time (the tests I added for the looping/
assertion bugs found this), so I changed them, too.
Add TODO tests for RT#115156
Perl_sv_mortalcopy expects a return value.

Courtesy of the OpenVMS C compiler, which said:

SV *
^
%CC-I-MISSINGRETURN, Non-void function "Perl_sv_mortalcopy" does not contain a return statement.
at line number 1206 in file D0:[craig.blead]mathoms.c;1