Skip to content
This repository was archived by the owner on Aug 5, 2021. It is now read-only.

Segfault when iterating through Python globals dictionary #177

@pont-us

Description

@pont-us

This bug manifested itself as a failure of the unit test PyObjectTest.testDictCopy(). It can also be triggered by the following minimal snippet (Python 3.8, 64-bit Ubuntu Linux 20.04) (after setting the necessary jpy configuration properties and calling PyLib.startPython()):

final Map<PyObject, PyObject> globalsDict = PyLib.getMainGlobals().asDict();
for (Map.Entry<PyObject, PyObject> entry : globalsDict.entrySet()) {
    System.out.println("Entry: " + entry.getKey() + " -> " + entry.getValue());
}

The iteration succeeds for two loops, printing Entry: __name__ -> __main__ and Entry: __doc__ -> None. At the start of the third iteration it crashes with a segmentation fault. The culprit appears to be builtins.call("next", it) in the iterator returned by PyDictWrapper.EntrySet.iterator(). This calls through to PyObject.call(). The control flow continues into PyLib_CallAndReturnObject in org_jpy_PyLib.c, and eventually to this line:

pyReturnValue = PyObject_CallObject(pyCallable, argCount > 0 ? pyArgs : NULL);

It is this call to PyObject_CallObject in Python's C API which directly triggers the segmentation fault.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions