summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2020-11-22 15:27:02 +0100
committersfan5 <sfan5@live.de>2020-11-22 17:16:57 +0100
commit6bb73040dd7447f9f45685f7f8dd5b53abc58485 (patch)
treebad6a40cf42f6d4e19ded1fe4e9925eb00e36897
parent4dcaf70b9653cd04c2159fac6545f25f8e1cbcf9 (diff)
downloadmpv-6bb73040dd7447f9f45685f7f8dd5b53abc58485.tar.bz2
mpv-6bb73040dd7447f9f45685f7f8dd5b53abc58485.tar.xz
file2string: remove question mark from safe chars
Trigraphs such as "??=" (which are enabled by default with -std=c11) can mess up strings, so avoid them entirely by escaping question marks. This also drops Python 2 compatibility from file2string, making the change to the waf rule necessary. The input file is now opened in binary mode which is also more correct versus the old text mode which just happened to work even on binary files.
-rwxr-xr-xTOOLS/file2string.py11
-rw-r--r--waftools/generators/sources.py2
2 files changed, 4 insertions, 9 deletions
diff --git a/TOOLS/file2string.py b/TOOLS/file2string.py
index bdeb18ce86..b641a1df2f 100755
--- a/TOOLS/file2string.py
+++ b/TOOLS/file2string.py
@@ -22,26 +22,21 @@
# License along with mpv. If not, see <http://www.gnu.org/licenses/>.
#
-from __future__ import unicode_literals
import sys
-# Indexing a byte string yields int on Python 3.x, and a str on Python 2.x
-def pord(c):
- return ord(c) if type(c) == str else c
-
def file2string(infilename, infile, outfile):
outfile.write("// Generated from %s\n\n" % infilename)
- conv = ['\\' + ("%03o" % c) for c in range(256)]
+ conv = ["\\%03o" % c for c in range(256)]
safe_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" \
- "0123456789!#%&'()*+,-./:;<=>?[]^_{|}~ "
+ "0123456789!#%&'()*+,-./:;<=>[]^_{|}~ "
for c in safe_chars:
conv[ord(c)] = c
for c, esc in ("\nn", "\tt", r"\\", '""'):
conv[ord(c)] = '\\' + esc
for line in infile:
- outfile.write('"' + ''.join(conv[pord(c)] for c in line) + '"\n')
+ outfile.write('"' + ''.join(conv[c] for c in line) + '"\n')
if __name__ == "__main__":
with open(sys.argv[1], 'rb') as infile:
diff --git a/waftools/generators/sources.py b/waftools/generators/sources.py
index 0f5b993758..dae1985e2d 100644
--- a/waftools/generators/sources.py
+++ b/waftools/generators/sources.py
@@ -34,7 +34,7 @@ def f2s(self):
def fn(out):
source = getattr(self, 'source', None)
src = self.path.find_resource(source)
- file2string(source, iter(src.read().splitlines(True)), out)
+ file2string(source, iter(src.read('rb').splitlines(True)), out)
execf(self, fn)
@TaskGen.feature('ebml_header')