https://github.com/python/cpython/commit/e2064d67504bc360c20e03eeea8b360d605cb439
commit: e2064d67504bc360c20e03eeea8b360d605cb439
branch: main
author: Agriya Khetarpal <[email protected]>
committer: freakboy3742 <[email protected]>
date: 2025-02-07T12:55:27+08:00
summary:
Emscripten: use better `_Py_Version` computation for worker module (#129757)
Use integer bit shifting instead of conversion to strings to compute Python
version.
files:
M Tools/wasm/emscripten/web_example/python.worker.mjs
diff --git a/Tools/wasm/emscripten/web_example/python.worker.mjs
b/Tools/wasm/emscripten/web_example/python.worker.mjs
index 8043e419966743..5f9012a492a399 100644
--- a/Tools/wasm/emscripten/web_example/python.worker.mjs
+++ b/Tools/wasm/emscripten/web_example/python.worker.mjs
@@ -70,12 +70,9 @@ const emscriptenSettings = {
postMessage({ type: "ready", stdinBuffer: stdinBuffer.sab });
},
async preRun(Module) {
- const versionHex = Module.HEAPU32[Module._Py_Version / 4].toString(16);
- const versionTuple = versionHex
- .padStart(8, "0")
- .match(/.{1,2}/g)
- .map((x) => parseInt(x, 16));
- const [major, minor, ..._] = versionTuple;
+ const versionInt = Module.HEAPU32[Module._Py_Version >>> 2];
+ const major = (versionInt >>> 24) & 0xff;
+ const minor = (versionInt >>> 16) & 0xff;
// Prevent complaints about not finding exec-prefix by making a
lib-dynload directory
Module.FS.mkdirTree(`/lib/python${major}.${minor}/lib-dynload/`);
Module.addRunDependency("install-stdlib");
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]