mirror of
https://github.com/AdaCore/langkit.git
synced 2026-02-12 12:28:12 -08:00
Python API: do not dec_ref C array values when coming from struct fields
TN: T423-042
This commit is contained in:
committed by
Pierre-Marie de Rodat
parent
69e5f782c4
commit
f352c7a361
@@ -0,0 +1,18 @@
|
||||
import lexer_example
|
||||
grammar foo_grammar {
|
||||
@main_rule main_rule <- Example("example")
|
||||
|
||||
}
|
||||
|
||||
@root_node class FooNode {
|
||||
}
|
||||
|
||||
class Example : FooNode {
|
||||
|
||||
@export fun example_holders (): Array[ExampleHolder] =
|
||||
[ExampleHolder(examples=[self])]
|
||||
}
|
||||
|
||||
struct ExampleHolder {
|
||||
examples : Array[Example]
|
||||
}
|
||||
8
testsuite/tests/python_api/array-struct-array/main.py
Normal file
8
testsuite/tests/python_api/array-struct-array/main.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
import libfoolang as lfl
|
||||
|
||||
|
||||
ctx = lfl.AnalysisContext()
|
||||
u = ctx.get_from_buffer("test", "example")
|
||||
print(u.root.p_example_holders)
|
||||
2
testsuite/tests/python_api/array-struct-array/test.out
Normal file
2
testsuite/tests/python_api/array-struct-array/test.out
Normal file
@@ -0,0 +1,2 @@
|
||||
[<ExampleHolder examples=[<Example test:1:1-1:8>]>]
|
||||
Done
|
||||
24
testsuite/tests/python_api/array-struct-array/test.py
Normal file
24
testsuite/tests/python_api/array-struct-array/test.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
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
|
||||
|
||||
|
||||
build_and_run(lkt_file='expected_concrete_syntax.lkt', py_script='main.py')
|
||||
print('Done')
|
||||
1
testsuite/tests/python_api/array-struct-array/test.yaml
Normal file
1
testsuite/tests/python_api/array-struct-array/test.yaml
Normal file
@@ -0,0 +1 @@
|
||||
driver: python
|
||||
Reference in New Issue
Block a user