diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 42834a8..d3575b5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -23,7 +23,7 @@ jobs: include: - emsdk_ver: "3.1.73" python_version: "3.13" - pybind11_version: "" + pybind11_version: "<3" steps: - uses: actions/checkout@v2 diff --git a/build_mkdocs.sh b/build_mkdocs.sh index 8f34d22..f97b0b6 100755 --- a/build_mkdocs.sh +++ b/build_mkdocs.sh @@ -21,7 +21,7 @@ if [ ! -d "$WASM_ENV_PREFIX" ]; then -c https://repo.prefix.dev/emscripten-forge-dev\ -c https://repo.prefix.dev/conda-forge \ --yes \ - python=$PYTHON_VERSION "pybind11" nlohmann_json pybind11_json numpy \ + python=$PYTHON_VERSION "pybind11<3" nlohmann_json pybind11_json numpy \ bzip2 sqlite zlib zstd libffi exceptiongroup\ "xeus" "xeus-lite" xeus-python "xeus-javascript" xtl "ipython" "traitlets>=5.14.2" \ openssl liblzma diff --git a/include/pyjs/convert.hpp b/include/pyjs/convert.hpp index 998b50a..a2ed991 100644 --- a/include/pyjs/convert.hpp +++ b/include/pyjs/convert.hpp @@ -56,6 +56,6 @@ namespace pyjs em::val py_1d_buffer_to_typed_array(py::buffer buffer, bool view); - em::val bytes_to_js(char* data); + em::val bytes_to_js(char* data, std::size_t length); } diff --git a/module/pyjs/convert_py_to_js.py b/module/pyjs/convert_py_to_js.py index d41c114..0233bf3 100644 --- a/module/pyjs/convert_py_to_js.py +++ b/module/pyjs/convert_py_to_js.py @@ -80,7 +80,8 @@ def to_js(value, cache=None, depth=0, max_depth=None): # # bytestring elif isinstance(value, bytes): - return internal.bytes_to_typed_array(value).buffer + l = len(value) + return internal.bytes_to_typed_array(value, l).buffer elif hasattr(value, "explicit_to_js"): return value.explicit_to_js() diff --git a/src/convert.cpp b/src/convert.cpp index 58cb312..86c2fcd 100644 --- a/src/convert.cpp +++ b/src/convert.cpp @@ -205,10 +205,9 @@ namespace pyjs } - em::val bytes_to_js(char * binary_string) + em::val bytes_to_js(char * binary_string, std::size_t length) { // get the length of the string - std::size_t length = std::strlen(binary_string); em::val mem_view = em::val(em::typed_memory_view(length, binary_string)); em::val mem_copy = em::val::global("Uint8Array").new_(mem_view); return mem_copy; diff --git a/src/js_timestamp.cpp b/src/js_timestamp.cpp index 2a2c129..a1588d5 100644 --- a/src/js_timestamp.cpp +++ b/src/js_timestamp.cpp @@ -1 +1 @@ -#define PYJS_JS_UTC_TIMESTAMP "2025-07-04 07:29:10.089112" \ No newline at end of file +#define PYJS_JS_UTC_TIMESTAMP "2025-09-01 06:22:09.224255" \ No newline at end of file diff --git a/tests/tests/test_pyjs.py b/tests/tests/test_pyjs.py index 5125d2e..94497d2 100644 --- a/tests/tests/test_pyjs.py +++ b/tests/tests/test_pyjs.py @@ -246,6 +246,11 @@ def test_to_js_dict(): assert jsmap.get(1) == "a" +def test_bytes_to_js(): + pyjs.to_js(b"\x00").byteLength == 1 + + + def test_to_js_none(): jsval = pyjs.to_js(None)