diff Python/codecs.c @ 72918:d76338eacf7c

Issue #13088: Add shared Py_hexdigits constant to format a number into base 16
author Victor Stinner <victor.stinner@haypocalc.com>
date Fri, 14 Oct 2011 02:13:11 +0200
parents 81380082d216
children 7109f31300fb
line wrap: on
line diff
--- a/Python/codecs.c	Fri Oct 14 00:08:29 2011 +0200
+++ b/Python/codecs.c	Fri Oct 14 02:13:11 2011 +0200
@@ -11,6 +11,8 @@
 #include "Python.h"
 #include <ctype.h>
 
+const char *Py_hexdigits = "0123456789abcdef";
+
 /* --- Codec Registry ----------------------------------------------------- */
 
 /* Import the standard encodings package which will register the first
@@ -673,8 +675,6 @@
     }
 }
 
-static const char *hexdigits = "0123456789abcdef";
-
 PyObject *PyCodec_BackslashReplaceErrors(PyObject *exc)
 {
 #ifndef Py_UNICODE_WIDE
@@ -731,22 +731,22 @@
             }
             if (c >= 0x00010000) {
                 *outp++ = 'U';
-                *outp++ = hexdigits[(c>>28)&0xf];
-                *outp++ = hexdigits[(c>>24)&0xf];
-                *outp++ = hexdigits[(c>>20)&0xf];
-                *outp++ = hexdigits[(c>>16)&0xf];
-                *outp++ = hexdigits[(c>>12)&0xf];
-                *outp++ = hexdigits[(c>>8)&0xf];
+                *outp++ = Py_hexdigits[(c>>28)&0xf];
+                *outp++ = Py_hexdigits[(c>>24)&0xf];
+                *outp++ = Py_hexdigits[(c>>20)&0xf];
+                *outp++ = Py_hexdigits[(c>>16)&0xf];
+                *outp++ = Py_hexdigits[(c>>12)&0xf];
+                *outp++ = Py_hexdigits[(c>>8)&0xf];
             }
             else if (c >= 0x100) {
                 *outp++ = 'u';
-                *outp++ = hexdigits[(c>>12)&0xf];
-                *outp++ = hexdigits[(c>>8)&0xf];
+                *outp++ = Py_hexdigits[(c>>12)&0xf];
+                *outp++ = Py_hexdigits[(c>>8)&0xf];
             }
             else
                 *outp++ = 'x';
-            *outp++ = hexdigits[(c>>4)&0xf];
-            *outp++ = hexdigits[c&0xf];
+            *outp++ = Py_hexdigits[(c>>4)&0xf];
+            *outp++ = Py_hexdigits[c&0xf];
         }
 
         restuple = Py_BuildValue("(On)", res, end);