From 0b2d4ab6d710a5ccaf7fe77fea2489ce354ecae2 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Fri, 9 Nov 2018 18:22:54 -0500 Subject: [PATCH] Fix iodide/#1151: PyDict_GetItem returns a borrowed reference --- src/pyimport.c | 1 - src/python2js.c | 1 - test/test_python.py | 7 +++++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/pyimport.c b/src/pyimport.c index d5608b1b5..be093e416 100644 --- a/src/pyimport.c +++ b/src/pyimport.c @@ -19,7 +19,6 @@ _pyimport(char* name) Py_DECREF(pyname); int idval = python2js(pyval); - Py_DECREF(pyval); return idval; } diff --git a/src/python2js.c b/src/python2js.c index ce6dd488d..158144634 100644 --- a/src/python2js.c +++ b/src/python2js.c @@ -297,7 +297,6 @@ _python2js_cache(PyObject* x, PyObject* map) if (result != HW_ERROR) { result = hiwire_incref(result); } - Py_DECREF(val); } else { result = _python2js(x, map); } diff --git a/test/test_python.py b/test/test_python.py index 7503badc6..763dd08fc 100644 --- a/test/test_python.py +++ b/test/test_python.py @@ -183,6 +183,13 @@ def test_import_js(selenium): assert result == 'Foo' +def test_pyimport_multiple(selenium): + """See #1151""" + selenium.run("v = 0.123") + selenium.run_js("pyodide.pyimport('v')") + selenium.run_js("pyodide.pyimport('v')") + + def test_pyproxy(selenium): selenium.run( """