Skip to content

Segmentation fault when editing a list in-place in a C extesnion #136388

Closed as not planned
@dd-dreams

Description

@dd-dreams

Bug report

Bug description:

Short untested example:

lst = ... # a numpy darray
res = func(lst.tolist()) # function in the C extension. edits in-place lst.tolist() -> returns a List. res depends on `lst`
print(res[0]) # Segmentation fault when accessing res in some way

func edits lst.tolist() in-place, and res depends on lst.tolist(), possibly res is lst.tolist().
We get a segfault when printing. It results of a GC collection error, probably because lst.tolist() is invalidly being freed. Assigning lst.tolist() to a variable fixes the segfault.

It might be Python intent to act like this.

CPython versions tested on:

3.9

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-crashA hard crash of the interpreter, possibly with a core dump

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions