Skip to content

Commit

Permalink
BUGFIX: If python2js_buffer fails, python2js leaves the error flag in…
Browse files Browse the repository at this point in the history
… an invalid state (pyodide#1111)
  • Loading branch information
Hood Chatham authored Jan 12, 2021
1 parent f6a67d9 commit 2266ccf
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/numpy/test_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,21 @@ def assert_equal():
assert selenium.run_js("return pyodide.pyimport('x')[1][1]") == "string4"


def test_py2js_buffer_clear_error_flag(selenium):
selenium.load_package("numpy")
selenium.run("import numpy as np")
selenium.run("x = np.array([['string1', 'string2'], ['string3', 'string4']])")
assert (
selenium.run_js(
"""
pyodide.globals.x
return pyodide._module._PyErr_Occurred();
"""
)
== 0
)


def test_python2js_numpy_scalar(selenium_standalone):
selenium = selenium_standalone

Expand Down
1 change: 1 addition & 0 deletions src/core/python2js.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ _python2js(PyObject* x, PyObject* map)
if (ret != NULL) {
return ret;
}
PyErr_Clear();
if (PySequence_Check(x)) {
return _python2js_sequence(x, map);
}
Expand Down
17 changes: 17 additions & 0 deletions src/tests/test_typeconversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,20 @@ def test_javascript_error_back_to_js(selenium):
return pyodide.globals["py_err"] === err
"""
)


def test_memoryview_conversion(selenium):
selenium.run(
"""
import array
a = array.array("Q", [1,2,3])
"""
)
selenium.run_js(
"""
pyodide.globals.a
if(pyodide._module._PyErr_Occurred()){
pyodide._module._pythonexc2js();
}
"""
)

0 comments on commit 2266ccf

Please sign in to comment.