This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
APItest: Fix C++ compiles
authorKarl Williamson <khw@cpan.org>
Fri, 9 Feb 2018 17:10:47 +0000 (10:10 -0700)
committerKarl Williamson <khw@cpan.org>
Fri, 9 Feb 2018 17:19:12 +0000 (10:19 -0700)
0a9f8f95112ff40e13406b3e5aab49c01487f045 introduced failures on C++
compilations.  This is a better patch, suggested by ilmari.

The issue was in cases where the pointer size is 32 bits and the word
size was 64, a (STRLEN) -1 returned as an error was getting turned into
0xFFFFFFFF instead of -1.

ext/XS-APItest/APItest.xs

index 842b628..794ab40 100644 (file)
@@ -1380,18 +1380,22 @@ bytes_cmp_utf8(bytes, utf8)
        RETVAL
 
 AV *
-test_utf8_to_bytes(bytes, lenp)
+test_utf8_to_bytes(bytes, len)
         unsigned char * bytes
-        ssize_t lenp
+        STRLEN len
     PREINIT:
         char * ret;
     CODE:
         RETVAL = newAV();
         sv_2mortal((SV*)RETVAL);
 
-        ret = (char *) utf8_to_bytes(bytes, &lenp);
+        ret = (char *) utf8_to_bytes(bytes, &len);
         av_push(RETVAL, newSVpv(ret, 0));
-        av_push(RETVAL, newSViv(lenp));
+
+        /* utf8_to_bytes uses (STRLEN)-1 to signal errors, and we want to
+         * return that as -1 to perl, so cast to SSize_t in case
+         * sizeof(IV) > sizeof(STRLEN) */
+        av_push(RETVAL, newSViv((SSize_t)len));
         av_push(RETVAL, newSVpv((const char *) bytes, 0));
 
     OUTPUT: