Skip to content

Commit 027f81d

Browse files
committed
Add support for Python codegen
1 parent 3cdb077 commit 027f81d

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

engine/ApiWrapperGenerator/ArgConversion.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ public class TransientArgumentConversion
1818
/// Statements disposing of the local variable prior to the API call
1919
/// </summary>
2020
public string LocalVarCleanup;
21+
22+
public bool IsPointer;
23+
2124
}
2225

2326
public abstract class BaseValueConversion
@@ -62,22 +65,26 @@ public class ArgConversion : BaseValueConversion
6265
/// </summary>
6366
string CleanupTemplate;
6467

68+
public bool IsPointer;
69+
6570
public TransientArgumentConversion Apply(string variableName)
6671
{
6772
return new TransientArgumentConversion()
6873
{
6974
ApiVarname = variableName,
7075
LocalVarname = GetTransientVarname(variableName),
7176
LocalVarSetup = GetSetup(variableName),
72-
LocalVarCleanup = GetCleanup(variableName)
77+
LocalVarCleanup = GetCleanup(variableName),
78+
IsPointer = this.IsPointer
7379
};
7480
}
7581

76-
public ArgConversion(string variablePostfix, string setupTemplate, string cleanupTemplate)
82+
public ArgConversion(string variablePostfix, string setupTemplate, string cleanupTemplate, bool isPointer)
7783
{
7884
VariablePostfix = variablePostfix;
7985
SetupTemplate = setupTemplate;
8086
CleanupTemplate = cleanupTemplate;
87+
IsPointer = isPointer;
8188
}
8289

8390
public string GetSetup(string vname)

engine/ApiWrapperGenerator/BaseApiConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ private T matchByRegex<T>(Dictionary<string, T> transientArgConversion, string t
394394
/// <param name="cleanupTemplate">Template code specifying how to dispose of the transient argument after the API call</param>
395395
public void SetTransientArgConversion(string cArgType, string variablePostfix, string setupTemplate, string cleanupTemplate)
396396
{
397-
transientArgConversion[cArgType] = new ArgConversion(variablePostfix, setupTemplate, cleanupTemplate);
397+
transientArgConversion[cArgType] = new ArgConversion(variablePostfix, setupTemplate, cleanupTemplate, this.IsPointer(cArgType));
398398
}
399399

400400
public void SetReturnedValueConversion(string cArgType, string conversionTemplate)

engine/ApiWrapperGenerator/PythonCffiWrapperGenerator.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ public CustomFunctionWrapperImpl ReturnsVectorWrapper(System.Func<string, bool>
104104
def %WRAPFUNCTION%(%WRAPARGS%):
105105
%WRAPFUNCTIONDOCSTRING%
106106
%TRANSARGS%
107-
size = marshal.new_int_array(1)
107+
size = marshal.new_int_scalar_ptr()
108108
values = %FUNCTION%(%ARGS%, size)
109109
%CLEANTRANSARGS%
110-
result = " + convertingFunc + @"(values, size, True)
110+
result = " + convertingFunc + @"(values, size[0], True)
111111
return result
112112
"
113113
};
@@ -147,7 +147,9 @@ private void PythonApiToCApiType(StringBuilder sb, string typename, string varna
147147
if (t != null)
148148
{
149149
// All transient arguments in python Cffi will be wrapped in a class, to keep alive all native resources; we need to pass the cffi pointer however
150-
sb.Append(t.LocalVarname + ".ptr"); // Call with the transient variable name e.g. argname_char_pp
150+
// TODO: generalise
151+
string apiCallUnwrap = t.IsPointer ? ".ptr" : ".obj";
152+
sb.Append(t.LocalVarname + apiCallUnwrap); // Call with the transient variable name e.g. argname_char_pp
151153
}
152154
// If this is a pointer, take precedence on known types.\
153155
// else if (IsPointer(typename)) // HYPERCUBE_PTR

0 commit comments

Comments
 (0)