Skip to content

Commit b3b0cb4

Browse files
authored
Remove asstr() helper function. NFC. (#13617)
This was mostly useful in the python2 compatability world.
1 parent 2d9b106 commit b3b0cb4

File tree

4 files changed

+10
-30
lines changed

4 files changed

+10
-30
lines changed

emscripten.py

+6-16
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from tools import shared
2424
from tools import gen_struct_info
2525
from tools import webassembly
26-
from tools.shared import WINDOWS, asstr, path_from_root, exit_with_error, asmjs_mangle, treat_as_user_function
26+
from tools.shared import WINDOWS, path_from_root, exit_with_error, asmjs_mangle, treat_as_user_function
2727
from tools.toolchain_profiler import ToolchainProfiler
2828

2929
logger = logging.getLogger('emscripten')
@@ -188,12 +188,11 @@ def set_memory(static_bump):
188188
def report_missing_symbols(all_implemented, pre):
189189
# the initial list of missing functions are that the user explicitly exported
190190
# but were not implemented in compiled code
191-
missing = list(set(shared.Settings.USER_EXPORTED_FUNCTIONS) - all_implemented)
191+
missing = set(shared.Settings.USER_EXPORTED_FUNCTIONS) - all_implemented
192192

193-
for requested in missing:
194-
if ('function ' + asstr(requested) + '(') in pre:
195-
continue
196-
diagnostics.warning('undefined', 'undefined exported symbol: "%s"', requested)
193+
for requested in sorted(missing):
194+
if (f'function {requested}(') not in pre:
195+
diagnostics.warning('undefined', f'undefined exported symbol: "{requested}"')
197196

198197
# Special hanlding for the `_main` symbol
199198

@@ -455,7 +454,6 @@ def finalize_wasm(infile, outfile, memfile, DEBUG):
455454
def create_asm_consts(metadata):
456455
asm_consts = {}
457456
for addr, const in metadata['asmConsts'].items():
458-
const = asstr(const)
459457
const = trim_asm_const_body(const)
460458
args = []
461459
max_arity = 16
@@ -484,7 +482,7 @@ def create_em_js(forwarded_json, metadata):
484482
else:
485483
args = args.split(',')
486484
arg_names = [arg.split()[-1].replace("*", "") for arg in args if arg]
487-
func = 'function {}({}){}'.format(name, ','.join(arg_names), asstr(body))
485+
func = 'function {}({}){}'.format(name, ','.join(arg_names), body)
488486
em_js_funcs.append(func)
489487
forwarded_json['Functions']['libraryFunctions'][name] = 1
490488

@@ -778,14 +776,6 @@ def load_metadata_wasm(metadata_raw, DEBUG):
778776
for key, value in metadata_json.items():
779777
if key in legacy_keys:
780778
continue
781-
# json.loads returns `unicode` for strings but other code in this file
782-
# generally works with utf8 encoded `str` objects, and they don't alwasy
783-
# mix well. e.g. s.replace(x, y) will blow up is `s` a uts8 str containing
784-
# non-ascii and either x or y are unicode objects.
785-
# TODO(sbc): Remove this encoding if we switch to unicode elsewhere
786-
# (specifically the glue returned from compile_settings)
787-
if type(value) == list:
788-
value = [asstr(v) for v in value]
789779
if key not in metadata:
790780
exit_with_error('unexpected metadata key received from wasm-emscripten-finalize: %s', key)
791781
metadata[key] = value

tests/runner.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
from tools.shared import TEMP_DIR, EMCC, EMXX, DEBUG
6060
from tools.shared import EMSCRIPTEN_TEMP_DIR
6161
from tools.shared import EM_BUILD_VERBOSE
62-
from tools.shared import asstr, get_canonical_temp_dir, try_delete
62+
from tools.shared import get_canonical_temp_dir, try_delete
6363
from tools.shared import asbytes
6464
from tools.utils import MACOS, WINDOWS
6565
from tools import shared, line_endings, building, config
@@ -743,7 +743,6 @@ def assertTextDataContained(self, text1, text2):
743743
def assertContained(self, values, string, additional_info=''):
744744
if type(values) not in [list, tuple]:
745745
values = [values]
746-
values = list(map(asstr, values))
747746
if callable(string):
748747
string = string()
749748

tools/shared.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ def get_subresource_location(path, data_uri=None):
809809
return ''
810810
with open(path, 'rb') as f:
811811
data = base64.b64encode(f.read())
812-
return 'data:application/octet-stream;base64,' + asstr(data)
812+
return 'data:application/octet-stream;base64,' + data.decode('ascii')
813813
else:
814814
return os.path.basename(path)
815815

@@ -881,13 +881,6 @@ def make_invoke(sig, named=True):
881881
return ret
882882

883883

884-
# Converts a string to the native str type.
885-
def asstr(s):
886-
if isinstance(s, bytes):
887-
return s.decode('utf-8')
888-
return s
889-
890-
891884
def asbytes(s):
892885
if isinstance(s, bytes):
893886
# Do not attempt to encode bytes

tools/wasm-sourcemap.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222

2323
sys.path.insert(1, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
2424

25-
from tools.shared import asstr
26-
2725
logger = logging.getLogger('wasm-sourcemap')
2826

2927

@@ -178,7 +176,7 @@ def remove_dead_entries(entries):
178176

179177
def read_dwarf_entries(wasm, options):
180178
if options.dwarfdump_output:
181-
output = open(options.dwarfdump_output, 'r').read()
179+
output = open(options.dwarfdump_output, 'rb').read()
182180
elif options.dwarfdump:
183181
logger.debug('Reading DWARF information from %s' % wasm)
184182
if not os.path.exists(options.dwarfdump):
@@ -195,7 +193,7 @@ def read_dwarf_entries(wasm, options):
195193
sys.exit(1)
196194

197195
entries = []
198-
debug_line_chunks = re.split(r"debug_line\[(0x[0-9a-f]*)\]", asstr(output))
196+
debug_line_chunks = re.split(r"debug_line\[(0x[0-9a-f]*)\]", output.decode('utf-8'))
199197
maybe_debug_info_content = debug_line_chunks[0]
200198
for i in range(1, len(debug_line_chunks), 2):
201199
stmt_list = debug_line_chunks[i]

0 commit comments

Comments
 (0)