Skip to content

Commit

Permalink
APItest.xs: remove unneeded SvPV_force_nolen()
Browse files Browse the repository at this point in the history
The two API test wrappers utf16_to_utf8_reversed() and
utf8_to_utf16(_reversed() included a call to SvPV_force_nolen(), because
the underlying functions in utf8.c which they were wrapping used to
modify the src buffer.

However since v5.35.2-236-g5fd26678bf, these functions no longer modify
the buffer, so the force is superfluous. So this commit removes force.

As a side-effect, this fixes a failure in

    cd t; ./TEST -deparse ../ext/XS-APItest/t/utf16_to_utf8.t

because the test file has this line:

    $utf16_of_U10302 = utf8_to_utf16_reversed(chr 0x10302);

which after a round trip through deparse becomes:

    $utf16_of_U10302 = utf8_to_utf16_reversed("\x{10302}");

and it so happens that at compile time, the chr() form gets constant-
folded into a modifiable PADTMP string constant, which survives a call
to  SvPV_force(), while the latter form is a pure read-only constant SV
which croaks with "Modification of a read-only value attempted"
  • Loading branch information
iabyn committed Sep 10, 2021
1 parent 1e0e4aa commit 7731dc3
Showing 1 changed file with 0 additions and 2 deletions.
2 changes: 0 additions & 2 deletions ext/XS-APItest/APItest.xs
Expand Up @@ -3077,7 +3077,6 @@ utf16_to_utf8 (sv, ...)
SV *dest;
Size_t got;
CODE:
if (ix) (void)SvPV_force_nolen(sv);
source = (U8 *)SvPVbyte(sv, len);
/* Optionally only convert part of the buffer. */
if (items > 1) {
Expand Down Expand Up @@ -3107,7 +3106,6 @@ utf8_to_utf16 (sv, ...)
SV *dest;
Size_t got;
CODE:
if (ix) (void)SvPV_force_nolen(sv);
source = (U8 *)SvPV(sv, len);
/* Optionally only convert part of the buffer. */
if (items > 1) {
Expand Down

0 comments on commit 7731dc3

Please sign in to comment.