diff --git a/src/pyTypeFactory.cc b/src/pyTypeFactory.cc index dc6135bf..b18c333c 100644 --- a/src/pyTypeFactory.cc +++ b/src/pyTypeFactory.cc @@ -154,7 +154,9 @@ static PyObject *callJSFunc(PyObject *jsCxThisFuncTuple, PyObject *args) { JS::RootedVector jsArgsVector(cx); for (size_t i = 0; i < PyTuple_Size(args); i++) { - JS::Value jsValue = jsTypeFactory(cx, PyTuple_GetItem(args, i)); + PyObject *pyObj = PyTuple_GetItem(args, i); + Py_INCREF(pyObj); + JS::Value jsValue = jsTypeFactory(cx, pyObj); if (PyErr_Occurred()) { // Check if an exception has already been set in the flow of control return NULL; // Fail-fast } diff --git a/tests/python/test_pythonmonkey_eval.py b/tests/python/test_pythonmonkey_eval.py index fa06e497..4222ac49 100644 --- a/tests/python/test_pythonmonkey_eval.py +++ b/tests/python/test_pythonmonkey_eval.py @@ -600,6 +600,17 @@ def add(a, b): int2 = random.randint(0x0000, 0xFFFF) assert caller(add, int1, int2) == int1 + int2 +def test_eval_functions_pyfunction_in_closure(): + # BF-58 https://github.com/Distributive-Network/PythonMonkey/pull/19 + def fn1(): + def fn0(n): + return n + 100 + return fn0 + assert 101.9 == fn1()(1.9) + assert 101.9 == pm.eval("(fn1) => { return fn1 }")(fn1())(1.9) + assert 101.9 == pm.eval("(fn1, x) => { return fn1()(x) }")(fn1, 1.9) + assert 101.9 == pm.eval("(fn1) => { return fn1() }")(fn1)(1.9) + def test_eval_functions_pyfunctions_strs(): caller = pm.eval("(func, param1, param2) => { return func(param1, param2) }") def concatenate(a, b):