This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
shmwrite: treat the string as bytes
authorTony Cook <tony@develop-help.com>
Wed, 18 Nov 2020 04:01:13 +0000 (15:01 +1100)
committerTony Cook <tony@develop-help.com>
Tue, 24 Nov 2020 02:35:21 +0000 (13:35 +1100)
doio.c
t/io/shm.t

diff --git a/doio.c b/doio.c
index df6e62c..439f2d0 100644 (file)
--- a/doio.c
+++ b/doio.c
@@ -3251,7 +3251,7 @@ Perl_do_shmio(pTHX_ I32 optype, SV **mark, SV **sp)
     else {
        STRLEN len;
 
-       const char *mbuf = SvPV_const(mstr, len);
+       const char *mbuf = SvPVbyte(mstr, len);
        const I32 n = ((I32)len > msize) ? msize : (I32)len;
        Copy(mbuf, shm + mpos, n, char);
        if (n < msize)
index 3feb303..ced92a6 100644 (file)
@@ -53,7 +53,7 @@ if (not defined $key) {
   }
 }
 else {
-       plan(tests => 15);
+       plan(tests => 21);
        pass('acquired shared mem');
 }
 
@@ -88,3 +88,19 @@ tie $ct, 'Counted';
 shmread $key, $ct, 0, 1;
 is($fetch, 1, "shmread FETCH once");
 is($store, 1, "shmread STORE once");
+
+{
+    # check reading into an upgraded buffer is sane
+    my $text = "\xC0\F0AB";
+    ok(shmwrite($key, $text, 0, 4), "setup text");
+    my $rdbuf = "\x{101}";
+    ok(shmread($key, $rdbuf, 0, 4), "read it back");
+    is($rdbuf, $text, "check we got back the expected");
+
+    # check writing from an upgraded buffer
+    utf8::upgrade(my $utext = $text);
+    ok(shmwrite($key, $utext, 0, 4), "setup text (upgraded source)");
+    $rdbuf = "";
+    ok(shmread($key, $rdbuf, 0, 4), "read it back (upgraded source)");
+    is($rdbuf, $text, "check we got back the expected (upgraded source)");
+}