diff --git a/MEOS.NET/Functions/Meos.Native.g.cs b/MEOS.NET/Functions/Meos.Native.g.cs index 6b22b0d..e8eba5b 100644 --- a/MEOS.NET/Functions/Meos.Native.g.cs +++ b/MEOS.NET/Functions/Meos.Native.g.cs @@ -9217,6 +9217,10 @@ private static partial class Native [return: MarshalAs(UnmanagedType.U1)] internal static partial bool GeoIsPlanarLinear(IntPtr gs); + [LibraryImport(DllPath, EntryPoint = "geo_clip_subject", StringMarshalling = StringMarshalling.Utf8)] + [return: MarshalAs(UnmanagedType.U1)] + internal static partial bool GeoClipSubject(IntPtr gs); + [LibraryImport(DllPath, EntryPoint = "geo_is_point_set", StringMarshalling = StringMarshalling.Utf8)] [return: MarshalAs(UnmanagedType.U1)] internal static partial bool GeoIsPointSet(IntPtr gs); diff --git a/MEOS.NET/Functions/Meos.meos_internal_geo.g.cs b/MEOS.NET/Functions/Meos.meos_internal_geo.g.cs index e204ad7..6948fc2 100644 --- a/MEOS.NET/Functions/Meos.meos_internal_geo.g.cs +++ b/MEOS.NET/Functions/Meos.meos_internal_geo.g.cs @@ -255,6 +255,9 @@ public static IntPtr GeoEdgeCtxMake(IntPtr gs) public static bool GeoIsPlanarLinear(IntPtr gs) => SafeExecution(() => Native.GeoIsPlanarLinear(gs)); + public static bool GeoClipSubject(IntPtr gs) + => SafeExecution(() => Native.GeoClipSubject(gs)); + public static bool GeoIsPointSet(IntPtr gs) => SafeExecution(() => Native.GeoIsPointSet(gs)); diff --git a/MEOS.NET/Types/JsonPath.g.cs b/MEOS.NET/Types/JsonPath.g.cs new file mode 100644 index 0000000..7a49ceb --- /dev/null +++ b/MEOS.NET/Types/JsonPath.g.cs @@ -0,0 +1,31 @@ +#nullable enable + +using System.Runtime.InteropServices; + +using MEOS.NET.Enums; +using MEOS.NET.Functions; +using MEOS.NET.Structures; + +namespace MEOS.NET.Types +{ + /// A path into a jsonb value. A MeosType no membership predicate admits, as Nsegment and Raquet are; the nine signatures naming it are what need it. + [System.CodeDom.Compiler.GeneratedCode("MEOS.NET.ObjectGen", "0.1.0")] + public class JsonPath : Value + { + internal JsonPath(IntPtr ptr) : base(ptr) { } + + /// The text MEOS writes this value as. + public override string ToString() + => this.Out(); + + public JsonPath? Copy() + => MEOSFactory.WrapJsonPath(Meos.JsonpathCopy(this.Ptr)); + + public string Out() + => Meos.JsonpathOut(this.Ptr); + + public static JsonPath? In(string str) + => MEOSFactory.WrapJsonPath(Meos.JsonpathIn(str)); + + } +} diff --git a/MEOS.NET/Types/Jsonb.g.cs b/MEOS.NET/Types/Jsonb.g.cs index b38b1a1..210a745 100644 --- a/MEOS.NET/Types/Jsonb.g.cs +++ b/MEOS.NET/Types/Jsonb.g.cs @@ -183,6 +183,21 @@ public ulong HashExtended(ulong seed) public string Out() => Meos.JsonbOut(this.Ptr); + public int PathExists(JsonPath jp, Jsonb vars, bool silent, bool tz) + => Meos.JsonbPathExists(this.Ptr, jp.Ptr, vars.Ptr, silent, tz); + + public bool PathMatch(JsonPath jp, Jsonb vars, bool silent, bool tz) + => Meos.JsonbPathMatch(this.Ptr, jp.Ptr, vars.Ptr, silent, tz); + + public Jsonb?[] PathQueryAll(JsonPath jp, Jsonb vars, bool silent, bool tz) + => MEOSFactory.WrapJsonbArray(Meos.JsonbPathQueryAll(this.Ptr, jp.Ptr, vars.Ptr, silent, tz)); + + public Jsonb? PathQueryArray(JsonPath jp, Jsonb vars, bool silent, bool tz) + => MEOSFactory.WrapJsonb(Meos.JsonbPathQueryArray(this.Ptr, jp.Ptr, vars.Ptr, silent, tz)); + + public Jsonb? PathQueryFirst(JsonPath jp, Jsonb vars, bool silent, bool tz) + => MEOSFactory.WrapJsonb(Meos.JsonbPathQueryFirst(this.Ptr, jp.Ptr, vars.Ptr, silent, tz)); + public Text? Pretty() => MEOSFactory.WrapText(Meos.JsonbPretty(this.Ptr)); diff --git a/MEOS.NET/Types/MEOSFactory.g.cs b/MEOS.NET/Types/MEOSFactory.g.cs index d668437..bf0c29c 100644 --- a/MEOS.NET/Types/MEOSFactory.g.cs +++ b/MEOS.NET/Types/MEOSFactory.g.cs @@ -65,6 +65,30 @@ public static class MEOSFactory return wrapped; } + /// The value at as the JsonPath + /// class the model gives its runtime type. + public static JsonPath? WrapJsonPath(IntPtr ptr) + { + if (ptr == IntPtr.Zero) + { + return null; + } + + return new JsonPath(ptr); + } + + /// Every element of a C array of JsonPath pointers, wrapped. + public static JsonPath?[] WrapJsonPathArray(IntPtr[] ptrs) + { + JsonPath?[] wrapped = new JsonPath?[ptrs.Length]; + for (int i = 0; i < ptrs.Length; i++) + { + wrapped[i] = WrapJsonPath(ptrs[i]); + } + + return wrapped; + } + /// The value at as the Jsonb /// class the model gives its runtime type. public static Jsonb? WrapJsonb(IntPtr ptr) @@ -89,6 +113,30 @@ public static class MEOSFactory return wrapped; } + /// The value at as the MeosArray + /// class the model gives its runtime type. + public static MeosArray? WrapMeosArray(IntPtr ptr) + { + if (ptr == IntPtr.Zero) + { + return null; + } + + return new MeosArray(ptr); + } + + /// Every element of a C array of MeosArray pointers, wrapped. + public static MeosArray?[] WrapMeosArrayArray(IntPtr[] ptrs) + { + MeosArray?[] wrapped = new MeosArray?[ptrs.Length]; + for (int i = 0; i < ptrs.Length; i++) + { + wrapped[i] = WrapMeosArray(ptrs[i]); + } + + return wrapped; + } + /// The value at as the Npoint /// class the model gives its runtime type. public static Npoint? WrapNpoint(IntPtr ptr) @@ -137,6 +185,30 @@ public static class MEOSFactory return wrapped; } + /// The value at as the Pcschema + /// class the model gives its runtime type. + public static Pcschema? WrapPcschema(IntPtr ptr) + { + if (ptr == IntPtr.Zero) + { + return null; + } + + return new Pcschema(ptr); + } + + /// Every element of a C array of Pcschema pointers, wrapped. + public static Pcschema?[] WrapPcschemaArray(IntPtr[] ptrs) + { + Pcschema?[] wrapped = new Pcschema?[ptrs.Length]; + for (int i = 0; i < ptrs.Length; i++) + { + wrapped[i] = WrapPcschema(ptrs[i]); + } + + return wrapped; + } + /// The value at as the Pcpatch /// class the model gives its runtime type. public static Pcpatch? WrapPcpatch(IntPtr ptr) @@ -233,6 +305,30 @@ public static class MEOSFactory return wrapped; } + /// The value at as the RTree + /// class the model gives its runtime type. + public static RTree? WrapRTree(IntPtr ptr) + { + if (ptr == IntPtr.Zero) + { + return null; + } + + return new RTree(ptr); + } + + /// Every element of a C array of RTree pointers, wrapped. + public static RTree?[] WrapRTreeArray(IntPtr[] ptrs) + { + RTree?[] wrapped = new RTree?[ptrs.Length]; + for (int i = 0; i < ptrs.Length; i++) + { + wrapped[i] = WrapRTree(ptrs[i]); + } + + return wrapped; + } + /// The value at as the Raquet /// class the model gives its runtime type. public static Raquet? WrapRaquet(IntPtr ptr) @@ -257,6 +353,30 @@ public static class MEOSFactory return wrapped; } + /// The value at as the SPTree + /// class the model gives its runtime type. + public static SPTree? WrapSPTree(IntPtr ptr) + { + if (ptr == IntPtr.Zero) + { + return null; + } + + return new SPTree(ptr); + } + + /// Every element of a C array of SPTree pointers, wrapped. + public static SPTree?[] WrapSPTreeArray(IntPtr[] ptrs) + { + SPTree?[] wrapped = new SPTree?[ptrs.Length]; + for (int i = 0; i < ptrs.Length; i++) + { + wrapped[i] = WrapSPTree(ptrs[i]); + } + + return wrapped; + } + /// The value at as the STBox /// class the model gives its runtime type. public static STBox? WrapSTBox(IntPtr ptr) diff --git a/MEOS.NET/Types/MeosArray.g.cs b/MEOS.NET/Types/MeosArray.g.cs new file mode 100644 index 0000000..2d788b1 --- /dev/null +++ b/MEOS.NET/Types/MeosArray.g.cs @@ -0,0 +1,36 @@ +#nullable enable + +using System.Runtime.InteropServices; + +using MEOS.NET.Enums; +using MEOS.NET.Functions; +using MEOS.NET.Structures; + +namespace MEOS.NET.Types +{ + /// The growable array MEOS builds its own results in. MEOS registers it in no enum, so it names no temptype. + [System.CodeDom.Compiler.GeneratedCode("MEOS.NET.ObjectGen", "0.1.0")] + public class MeosArray : Value + { + internal MeosArray(IntPtr ptr) : base(ptr) { } + + public int Count() + => Meos.MeosArrayCount(this.Ptr); + + public void Destroy() + => Meos.MeosArrayDestroy(this.Ptr); + + public void DestroyFree() + => Meos.MeosArrayDestroyFree(this.Ptr); + + public void Reset() + => Meos.MeosArrayReset(this.Ptr); + + public void ResetFree() + => Meos.MeosArrayResetFree(this.Ptr); + + public static MeosArray? Create(int elem_size) + => MEOSFactory.WrapMeosArray(Meos.MeosArrayCreate(elem_size)); + + } +} diff --git a/MEOS.NET/Types/Pcpoint.g.cs b/MEOS.NET/Types/Pcpoint.g.cs index 861f9be..f22c3f9 100644 --- a/MEOS.NET/Types/Pcpoint.g.cs +++ b/MEOS.NET/Types/Pcpoint.g.cs @@ -23,9 +23,81 @@ public int Cmp(Pcpoint pt2) public Pcpoint? Copy() => MEOSFactory.WrapPcpoint(Meos.PcpointCopy(this.Ptr)); + public double? GetDim(Pcschema schema, string name) + { + IntPtr _out = Marshal.AllocHGlobal(8); + try + { + if (!Meos.PcpointGetDim(this.Ptr, schema.Ptr, name, _out)) + { + return null; + } + + return Marshal.PtrToStructure(_out); + } + finally + { + Marshal.FreeHGlobal(_out); + } + } + public uint GetPcid() => Meos.PcpointGetPcid(this.Ptr); + public double? GetX(Pcschema schema) + { + IntPtr _out = Marshal.AllocHGlobal(8); + try + { + if (!Meos.PcpointGetX(this.Ptr, schema.Ptr, _out)) + { + return null; + } + + return Marshal.PtrToStructure(_out); + } + finally + { + Marshal.FreeHGlobal(_out); + } + } + + public double? GetY(Pcschema schema) + { + IntPtr _out = Marshal.AllocHGlobal(8); + try + { + if (!Meos.PcpointGetY(this.Ptr, schema.Ptr, _out)) + { + return null; + } + + return Marshal.PtrToStructure(_out); + } + finally + { + Marshal.FreeHGlobal(_out); + } + } + + public double? GetZ(Pcschema schema) + { + IntPtr _out = Marshal.AllocHGlobal(8); + try + { + if (!Meos.PcpointGetZ(this.Ptr, schema.Ptr, _out)) + { + return null; + } + + return Marshal.PtrToStructure(_out); + } + finally + { + Marshal.FreeHGlobal(_out); + } + } + public uint Hash() => Meos.PcpointHash(this.Ptr); @@ -38,6 +110,9 @@ public string HexOut(int maxdd) public Set? ToSet() => MEOSFactory.WrapSet(Meos.PcpointToSet(this.Ptr)); + public TPCBox? ToTpcbox(Pcschema schema) + => MEOSFactory.WrapTPCBox(Meos.PcpointToTpcbox(this.Ptr, schema.Ptr)); + public static Pcpoint? FromHEXWKB(string hexwkb) => MEOSFactory.WrapPcpoint(Meos.PcpointFromHexwkb(hexwkb)); diff --git a/MEOS.NET/Types/Pcschema.g.cs b/MEOS.NET/Types/Pcschema.g.cs new file mode 100644 index 0000000..47db74e --- /dev/null +++ b/MEOS.NET/Types/Pcschema.g.cs @@ -0,0 +1,33 @@ +#nullable enable + +using System.Runtime.InteropServices; + +using MEOS.NET.Enums; +using MEOS.NET.Functions; +using MEOS.NET.Structures; + +namespace MEOS.NET.Types +{ + /// The dimension schema a point cloud value is read through. Every pcpoint and pcpatch accessor takes one, and the process-global cache answers it for a pcid. MEOS registers it in no enum, so it names no temptype. + [System.CodeDom.Compiler.GeneratedCode("MEOS.NET.ObjectGen", "0.1.0")] + public class Pcschema : Value + { + internal Pcschema(IntPtr ptr) : base(ptr) { } + + public static string? Compression(uint pcid) + => Meos.MeosPcSchemaCompression(pcid); + + public static Pcschema? Get(uint pcid) + => MEOSFactory.WrapPcschema(Meos.MeosPcSchema(pcid)); + + public static int Ndims(uint pcid) + => Meos.MeosPcSchemaNdims(pcid); + + public static int SRID(uint pcid) + => Meos.MeosPcSchemaSrid(pcid); + + public static string? Xml(uint pcid) + => Meos.MeosPcSchemaXml(pcid); + + } +} diff --git a/MEOS.NET/Types/RTree.g.cs b/MEOS.NET/Types/RTree.g.cs new file mode 100644 index 0000000..3d5b026 --- /dev/null +++ b/MEOS.NET/Types/RTree.g.cs @@ -0,0 +1,66 @@ +#nullable enable + +using System.Runtime.InteropServices; + +using MEOS.NET.Enums; +using MEOS.NET.Functions; +using MEOS.NET.Structures; + +namespace MEOS.NET.Types +{ + /// MEOS's in-memory R-tree over spans, boxes and their kin. MEOS registers it in no enum, so it names no temptype. + [System.CodeDom.Compiler.GeneratedCode("MEOS.NET.ObjectGen", "0.1.0")] + public class RTree : Value + { + internal RTree(IntPtr ptr) : base(ptr) { } + + public void Free() + => Meos.RtreeFree(this.Ptr); + + public int Height() + => Meos.RtreeHeight(this.Ptr); + + public bool InsertTemporal(Temporal temp, long id) + => Meos.RtreeInsertTemporal(this.Ptr, temp.Ptr, id); + + public bool InsertTemporalSplit(Temporal temp, long id, int maxboxes) + => Meos.RtreeInsertTemporalSplit(this.Ptr, temp.Ptr, id, maxboxes); + + public int Join(RTree rtree2, IndexSearchOp op, MeosArray result) + => Meos.RtreeJoin(this.Ptr, rtree2.Ptr, (int) op, result.Ptr); + + public long MemSize() + => Meos.RtreeMemSize(this.Ptr); + + public int NumEntries() + => Meos.RtreeNumEntries(this.Ptr); + + public int SearchTemporal(IndexSearchOp op, Temporal temp, MeosArray result) + => Meos.RtreeSearchTemporal(this.Ptr, (int) op, temp.Ptr, result.Ptr); + + public static RTree? CreateBigintspan() + => MEOSFactory.WrapRTree(Meos.RtreeCreateBigintspan()); + + public static RTree? CreateDatespan() + => MEOSFactory.WrapRTree(Meos.RtreeCreateDatespan()); + + public static RTree? CreateFloatspan() + => MEOSFactory.WrapRTree(Meos.RtreeCreateFloatspan()); + + public static RTree? CreateIntspan() + => MEOSFactory.WrapRTree(Meos.RtreeCreateIntspan()); + + public static RTree? CreateStbox() + => MEOSFactory.WrapRTree(Meos.RtreeCreateStbox()); + + public static RTree? CreateTbox() + => MEOSFactory.WrapRTree(Meos.RtreeCreateTbox()); + + public static RTree? CreateTpcbox() + => MEOSFactory.WrapRTree(Meos.RtreeCreateTpcbox()); + + public static RTree? CreateTstzspan() + => MEOSFactory.WrapRTree(Meos.RtreeCreateTstzspan()); + + } +} diff --git a/MEOS.NET/Types/SPTree.g.cs b/MEOS.NET/Types/SPTree.g.cs new file mode 100644 index 0000000..96b211b --- /dev/null +++ b/MEOS.NET/Types/SPTree.g.cs @@ -0,0 +1,66 @@ +#nullable enable + +using System.Runtime.InteropServices; + +using MEOS.NET.Enums; +using MEOS.NET.Functions; +using MEOS.NET.Structures; + +namespace MEOS.NET.Types +{ + /// MEOS's in-memory SP-tree, the R-tree's sibling over the same key types. MEOS registers it in no enum, so it names no temptype. + [System.CodeDom.Compiler.GeneratedCode("MEOS.NET.ObjectGen", "0.1.0")] + public class SPTree : Value + { + internal SPTree(IntPtr ptr) : base(ptr) { } + + public void Free() + => Meos.SptreeFree(this.Ptr); + + public int Height() + => Meos.SptreeHeight(this.Ptr); + + public bool InsertTemporal(Temporal temp, long id) + => Meos.SptreeInsertTemporal(this.Ptr, temp.Ptr, id); + + public bool InsertTemporalSplit(Temporal temp, long id, int maxboxes) + => Meos.SptreeInsertTemporalSplit(this.Ptr, temp.Ptr, id, maxboxes); + + public int Join(SPTree sptree2, IndexSearchOp op, MeosArray result) + => Meos.SptreeJoin(this.Ptr, sptree2.Ptr, (int) op, result.Ptr); + + public long MemSize() + => Meos.SptreeMemSize(this.Ptr); + + public int NumEntries() + => Meos.SptreeNumEntries(this.Ptr); + + public int SearchTemporal(IndexSearchOp op, Temporal temp, MeosArray result) + => Meos.SptreeSearchTemporal(this.Ptr, (int) op, temp.Ptr, result.Ptr); + + public static SPTree? CreateBigintspan(SPTreeKind kind) + => MEOSFactory.WrapSPTree(Meos.SptreeCreateBigintspan((int) kind)); + + public static SPTree? CreateDatespan(SPTreeKind kind) + => MEOSFactory.WrapSPTree(Meos.SptreeCreateDatespan((int) kind)); + + public static SPTree? CreateFloatspan(SPTreeKind kind) + => MEOSFactory.WrapSPTree(Meos.SptreeCreateFloatspan((int) kind)); + + public static SPTree? CreateIntspan(SPTreeKind kind) + => MEOSFactory.WrapSPTree(Meos.SptreeCreateIntspan((int) kind)); + + public static SPTree? CreateStbox(SPTreeKind kind) + => MEOSFactory.WrapSPTree(Meos.SptreeCreateStbox((int) kind)); + + public static SPTree? CreateTbox(SPTreeKind kind) + => MEOSFactory.WrapSPTree(Meos.SptreeCreateTbox((int) kind)); + + public static SPTree? CreateTpcbox(SPTreeKind kind) + => MEOSFactory.WrapSPTree(Meos.SptreeCreateTpcbox((int) kind)); + + public static SPTree? CreateTstzspan(SPTreeKind kind) + => MEOSFactory.WrapSPTree(Meos.SptreeCreateTstzspan((int) kind)); + + } +} diff --git a/MEOS.NET/Types/TJsonb.g.cs b/MEOS.NET/Types/TJsonb.g.cs index 9534c9a..67f1774 100644 --- a/MEOS.NET/Types/TJsonb.g.cs +++ b/MEOS.NET/Types/TJsonb.g.cs @@ -181,6 +181,18 @@ public override string ToString() public string Out() => Meos.TjsonbOut(this.Ptr); + public Temporal? PathExists(JsonPath jp, Jsonb vars, bool silent, bool tz) + => MEOSFactory.WrapTemporal(Meos.TjsonbPathExists(this.Ptr, jp.Ptr, vars.Ptr, silent, tz)); + + public Temporal? PathMatch(JsonPath jp, Jsonb vars, bool silent, bool tz) + => MEOSFactory.WrapTemporal(Meos.TjsonbPathMatch(this.Ptr, jp.Ptr, vars.Ptr, silent, tz)); + + public Temporal? PathQueryArray(JsonPath jp, Jsonb vars, bool silent, bool tz) + => MEOSFactory.WrapTemporal(Meos.TjsonbPathQueryArray(this.Ptr, jp.Ptr, vars.Ptr, silent, tz)); + + public Temporal? PathQueryFirst(JsonPath jp, Jsonb vars, bool silent, bool tz) + => MEOSFactory.WrapTemporal(Meos.TjsonbPathQueryFirst(this.Ptr, jp.Ptr, vars.Ptr, silent, tz)); + public Temporal? Pretty() => MEOSFactory.WrapTemporal(Meos.TjsonbPretty(this.Ptr)); diff --git a/tools/objectgen.py b/tools/objectgen.py index 6f9cae7..95f5ac9 100644 --- a/tools/objectgen.py +++ b/tools/objectgen.py @@ -110,6 +110,15 @@ def clean(c_type: str) -> str: return " ".join(c_type.replace("const ", "").split()) +def scratch(name: str) -> str: + """The name of a local the body derives from a parameter's. + + A parameter whose name is a C# keyword is escaped to `@out`, and `_@out` is + no identifier at all — the escape belongs at the START of a name or nowhere, + so a derived name drops it.""" + return "_" + name.lstrip("@") + + def pascal(oo_name: str) -> str: return oo_name[:1].upper() + oo_name[1:] @@ -382,7 +391,7 @@ def map_param(self, c_type: str, cs_type: str, name: str) -> tuple[str, str] | N return (cls, f"{name}.Ptr") struct = self.value_struct(c) if struct and cs_type == "IntPtr": - return (struct, f"_{name}") + return (struct, scratch(name)) return None # -- emission --------------------------------------------------------- @@ -478,10 +487,10 @@ def method_for(self, cls: str, entry: dict) -> Method | None: structs: list[tuple[str, str]] = [] for cs_type, pname in params: if result_out is not None and pname == result_out[0]: - args.append(f"_{pname}") + args.append(scratch(pname)) continue if pname == length_out: - args.append(f"_{pname}") + args.append(scratch(pname)) continue if pname in count_of: cast = "" if cs_type == "int" else f"({cs_type}) " @@ -493,7 +502,7 @@ def method_for(self, cls: str, entry: dict) -> Method | None: if element is not None: sig.append((f"{element}[]", pname)) arrays.append((pname, element)) - args.append(f"_{pname}.AddrOfPinnedObject()") + args.append(f"{scratch(pname)}.AddrOfPinnedObject()") continue # A scalar element is the array itself: the values need no # gathering, so what is pinned is the caller's own array. @@ -501,7 +510,7 @@ def method_for(self, cls: str, entry: dict) -> Method | None: if scalar is not None: sig.append((f"{scalar}[]", pname)) scalar_arrays.append(pname) - args.append(f"_{pname}.AddrOfPinnedObject()") + args.append(f"{scratch(pname)}.AddrOfPinnedObject()") continue self.deferred[cls].append( f"{oo}: argument {pname} is an array of " @@ -515,14 +524,14 @@ def method_for(self, cls: str, entry: dict) -> Method | None: return None sig.append((mapped[0], pname)) args.append(mapped[1]) - if mapped[1] == f"_{pname}" and self.value_struct(c_by_name.get(pname, "")): + if mapped[1] == scratch(pname) and self.value_struct(c_by_name.get(pname, "")): structs.append((pname, mapped[0])) call = f"Meos.{codegen.public_name(fname)}({', '.join(args)})" out = None if result_out is not None: name, (_, size, reader) = result_out - out = (name, size, reader.format(f"_{name}")) + out = (name, size, reader.format(scratch(name))) if structs and (arrays or out or scalar_arrays or length_out): self.deferred[cls].append( f"{oo}: a struct argument beside a counted array or an " @@ -607,7 +616,7 @@ def out_param_body(self, method: Method) -> list[str]: name, size, reader = method.out_param return [ " {", - f" IntPtr _{name} = Marshal.AllocHGlobal({size});", + f" IntPtr {scratch(name)} = Marshal.AllocHGlobal({size});", " try", " {", f" if (!{method.body})", @@ -619,7 +628,7 @@ def out_param_body(self, method: Method) -> list[str]: " }", " finally", " {", - f" Marshal.FreeHGlobal(_{name});", + f" Marshal.FreeHGlobal({scratch(name)});", " }", " }", ] @@ -634,19 +643,19 @@ def struct_body(self, method: Method) -> list[str]: lines = [" {"] for name, struct in method.structs: lines.append( - f" IntPtr _{name} = " + f" IntPtr {scratch(name)} = " f"Marshal.AllocHGlobal(Marshal.SizeOf<{struct}>());") lines.append(" try") lines.append(" {") for name, _ in method.structs: lines.append( - f" Marshal.StructureToPtr({ident(name)}, _{name}, false);") + f" Marshal.StructureToPtr({ident(name)}, {scratch(name)}, false);") lines.append(f" return {method.body};") lines.append(" }") lines.append(" finally") lines.append(" {") for name, _ in method.structs: - lines.append(f" Marshal.FreeHGlobal(_{name});") + lines.append(f" Marshal.FreeHGlobal({scratch(name)});") lines += [" }", " }"] return lines @@ -660,7 +669,7 @@ def buffer_body(self, method: Method) -> list[str]: name = method.length_out lines = [ " {", - f" IntPtr _{name} = Marshal.AllocHGlobal(sizeof(long));", + f" IntPtr {scratch(name)} = Marshal.AllocHGlobal(sizeof(long));", " try", " {", ] @@ -672,7 +681,7 @@ def buffer_body(self, method: Method) -> list[str]: " return null;", " }", "", - f" byte[] _wkb = new byte[Marshal.ReadInt64(_{name})];", + f" byte[] _wkb = new byte[Marshal.ReadInt64({scratch(name)})];", " Marshal.Copy(_bytes, _wkb, 0, _wkb.Length);", " return _wkb;", ] @@ -682,7 +691,7 @@ def buffer_body(self, method: Method) -> list[str]: " }", " finally", " {", - f" Marshal.FreeHGlobal(_{name});", + f" Marshal.FreeHGlobal({scratch(name)});", " }", " }", ] @@ -698,17 +707,17 @@ def array_body(self, method: Method) -> list[str]: lines = [" {"] for name in method.scalar_arrays: lines.append( - f" GCHandle _{name} = " + f" GCHandle {scratch(name)} = " f"GCHandle.Alloc({ident(name)}, GCHandleType.Pinned);") for name, element in method.arrays: lines += [ - f" IntPtr[] _{name}Values = new IntPtr[{ident(name)}.Length];", + f" IntPtr[] {scratch(name)}Values = new IntPtr[{ident(name)}.Length];", f" for (int i = 0; i < {ident(name)}.Length; i++)", " {", - f" _{name}Values[i] = {ident(name)}[i].Ptr;", + f" {scratch(name)}Values[i] = {ident(name)}[i].Ptr;", " }", "", - f" GCHandle _{name} = GCHandle.Alloc(_{name}Values, GCHandleType.Pinned);", + f" GCHandle {scratch(name)} = GCHandle.Alloc({scratch(name)}Values, GCHandleType.Pinned);", ] lines.append(" try") lines.append(" {") @@ -717,9 +726,9 @@ def array_body(self, method: Method) -> list[str]: lines.append(" finally") lines.append(" {") for name in method.scalar_arrays: - lines.append(f" _{name}.Free();") + lines.append(f" {scratch(name)}.Free();") for name, _ in method.arrays: - lines.append(f" _{name}.Free();") + lines.append(f" {scratch(name)}.Free();") lines += [" }", " }"] return lines