Try to make including patchlevel.h a bit more
[p5sagit/p5-mst-13.2.git] / ext / Data / Dumper / Dumper.xs
index a129c3f..8bf9f75 100644 (file)
@@ -4,8 +4,11 @@
 #include "XSUB.h"
 
 #ifndef PERL_VERSION
-#include "patchlevel.h"
-#define PERL_VERSION PATCHLEVEL
+#    include <patchlevel.h>
+#    ifndef PERL_VERSION
+#        include <could_not_find_Perl_patchlevel.h>
+#    endif
+#    define PERL_VERSION PATCHLEVEL
 #endif
 
 #if PERL_VERSION < 5
@@ -152,7 +155,16 @@ esc_q_utf8(pTHX_ SV* sv, register char *src, register STRLEN slen)
             else if (k < 0x80)
                 *r++ = (char)k;
             else {
-                r += sprintf(r, "\\x{%"UVxf"}", k);
+             /* The return value of sprintf() is unportable.
+              * In modern systems it returns (int) the number of characters,
+              * but in older systems it might return (char*) the original
+              * buffer, or it might even be (void).  The easiest portable
+              * thing to do is probably use sprintf() in void context and
+              * then strlen(buffer) for the length.  The more proper way
+              * would of course be to figure out the prototype of sprintf.
+              * --jhi */
+               sprintf(r, "\\x{%"UVxf"}", k);
+                r += strlen(r);
             }
         }
         *r++ = '"';
@@ -243,8 +255,7 @@ DD_dump(pTHX_ SV *val, char *name, STRLEN namelen, SV *retval, HV *seenhv,
            i = perl_call_method(SvPVX(freezer), G_EVAL|G_SCALAR);
            SPAGAIN;
            if (SvTRUE(ERRSV))
-               warn("WARNING(Freezer method call failed): %s",
-                    SvPVX(ERRSV));
+               warn("WARNING(Freezer method call failed): %"SVf"", ERRSV);
            else if (i)
                val = newSVsv(POPs);
            PUTBACK; FREETMPS; LEAVE;