Skip to content

Commit e2d59af

Browse files
committed
Use hex escapes for non-ASCII bytes
This makes the resulting literals more independent from the character encoding the environment assumes for the resulting file. It requires slightly more memory, but large bytes are far less common than small bytes (zero in particular), so the cost should not be too much. If we want to, we can still make this optional later on.
1 parent 6d3b9ff commit e2d59af

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

emcc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,8 @@ try:
13761376
s = ''.join(map(chr, s))
13771377
s = s.replace('\\', '\\\\').replace("'", "\\'")
13781378
s = s.replace('\n', '\\n').replace('\r', '\\r')
1379-
s = s.decode('latin1').encode('utf8')
1379+
def escape(x): return '\\x{:02x}'.format(ord(x.group()))
1380+
s = re.sub('[\x80-\xff]', escape, s)
13801381
return "var memoryInitializer = '%s';" % s
13811382
open(memfile, 'wb').write(''.join(map(chr, membytes)))
13821383
if DEBUG:

0 commit comments

Comments
 (0)