Files
langkit/testsuite/tests/python_api/array-struct-array/test.py
Pierre-Marie de Rodat 0a9619bf83 Python API: fix unwrapping of arrays of structs
Unwrapping an array of structs is meant to take the ownership share for
these structs, and thus to clear them. This means that the destructor of
Python wrappers for structs must handle the case where they no longer
have the ownership of a struct value: they didn't so far, which
triggered crashes.

TN: UA05-027
2021-10-18 11:46:46 +02:00

32 lines
775 B
Python

"""
Check that the Python bindings to wrap/unwrap arrays of structs of arrays work
as expected.
"""
from langkit.dsl import ASTNode, Struct, T, UserField
from langkit.expressions import Entity, langkit_property
from utils import build_and_run
class FooNode(ASTNode):
pass
class ExampleHolder(Struct):
examples = UserField(type=T.Example.entity.array)
class Example(FooNode):
@langkit_property(return_type=ExampleHolder.array, public=True)
def example_holders():
return ExampleHolder.new(examples=Entity.singleton).singleton
@langkit_property(return_type=ExampleHolder.array, public=True)
def identity(a=ExampleHolder.array):
return a
build_and_run(lkt_file='expected_concrete_syntax.lkt', py_script='main.py')
print('Done')