Python API: do not dec_ref C array values when coming from struct fields

TN: T423-042
This commit is contained in:
Pierre-Marie de Rodat
2020-04-27 15:42:41 +02:00
committed by Pierre-Marie de Rodat
parent 69e5f782c4
commit f352c7a361
7 changed files with 63 additions and 4 deletions

View File

@@ -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]
}

View 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)

View File

@@ -0,0 +1,2 @@
[<ExampleHolder examples=[<Example test:1:1-1:8>]>]
Done

View 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')

View File

@@ -0,0 +1 @@
driver: python