diff --git a/pkgs/ffigen/example/c_json/cjson_generated_bindings.dart b/pkgs/ffigen/example/c_json/cjson_generated_bindings.dart index 7cb6ea7218..c17b7e5e41 100644 --- a/pkgs/ffigen/example/c_json/cjson_generated_bindings.dart +++ b/pkgs/ffigen/example/c_json/cjson_generated_bindings.dart @@ -1245,6 +1245,26 @@ final class cJSON extends ffi.Struct { external double valuedouble; external ffi.Pointer string; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer next, + required ffi.Pointer prev, + required ffi.Pointer child, + required int type, + required ffi.Pointer valuestring, + required int valueint, + required double valuedouble, + required ffi.Pointer string, + }) => allocator() + ..ref.next = next + ..ref.prev = prev + ..ref.child = child + ..ref.type = type + ..ref.valuestring = valuestring + ..ref.valueint = valueint + ..ref.valuedouble = valuedouble + ..ref.string = string; } const int cJSON_Array = 32; @@ -1261,6 +1281,20 @@ final class cJSON_Hooks extends ffi.Struct { ffi.NativeFunction ptr)> > free_fn; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer< + ffi.NativeFunction Function(ffi.Size sz)> + > + malloc_fn, + required ffi.Pointer< + ffi.NativeFunction ptr)> + > + free_fn, + }) => allocator() + ..ref.malloc_fn = malloc_fn + ..ref.free_fn = free_fn; } const int cJSON_Invalid = 0; diff --git a/pkgs/ffigen/example/libclang-example/generated_bindings.dart b/pkgs/ffigen/example/libclang-example/generated_bindings.dart index 73e7beb39c..ca6e8faf0e 100644 --- a/pkgs/ffigen/example/libclang-example/generated_bindings.dart +++ b/pkgs/ffigen/example/libclang-example/generated_bindings.dart @@ -6858,6 +6858,14 @@ final class CXCodeCompleteResults extends ffi.Struct { /// \c Results array. @ffi.UnsignedInt() external int NumResults; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer Results, + required int NumResults, + }) => allocator() + ..ref.Results = Results + ..ref.NumResults = NumResults; } /// Describes a single piece of text within a code-completion string. @@ -7054,6 +7062,14 @@ final class CXCompletionResult extends ffi.Struct { /// The code-completion string that describes how to insert this /// code-completion result into the editing buffer. external CXCompletionString CompletionString; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required CXCursorKind CursorKind, + required CXCompletionString CompletionString, + }) => allocator() + ..ref.CursorKind = CursorKind + ..ref.CompletionString = CompletionString; } /// A semantic string that describes a code-completion result. @@ -7108,6 +7124,19 @@ final class CXCursorAndRangeVisitor extends ffi.Struct { > > visit; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer context, + required ffi.Pointer< + ffi.NativeFunction< + ffi.UnsignedInt Function(ffi.Pointer, CXCursor, CXSourceRange) + > + > + visit, + }) => allocator() + ..ref.context = context + ..ref.visit = visit; } /// Describes the kind of entity that a cursor refers to. @@ -8425,6 +8454,16 @@ final class CXIdxCXXClassDeclInfo extends ffi.Struct { @ffi.UnsignedInt() external int numBases; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer declInfo, + required ffi.Pointer> bases, + required int numBases, + }) => allocator() + ..ref.declInfo = declInfo + ..ref.bases = bases + ..ref.numBases = numBases; } /// The client's data object that is associated with an AST file (PCH @@ -8768,6 +8807,14 @@ final class CXIdxObjCContainerDeclInfo extends ffi.Struct { CXIdxObjCContainerKind get kind => CXIdxObjCContainerKind.fromValue(kindAsInt); set kind(CXIdxObjCContainerKind value) => kindAsInt = value.value; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer declInfo, + required CXIdxObjCContainerKind kind, + }) => allocator() + ..ref.declInfo = declInfo + ..ref.kind = kind; } enum CXIdxObjCContainerKind { @@ -8794,6 +8841,16 @@ final class CXIdxObjCInterfaceDeclInfo extends ffi.Struct { external ffi.Pointer superInfo; external ffi.Pointer protocols; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer containerInfo, + required ffi.Pointer superInfo, + required ffi.Pointer protocols, + }) => allocator() + ..ref.containerInfo = containerInfo + ..ref.superInfo = superInfo + ..ref.protocols = protocols; } final class CXIdxObjCPropertyDeclInfo extends ffi.Struct { @@ -8802,6 +8859,16 @@ final class CXIdxObjCPropertyDeclInfo extends ffi.Struct { external ffi.Pointer getter; external ffi.Pointer setter; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer declInfo, + required ffi.Pointer getter, + required ffi.Pointer setter, + }) => allocator() + ..ref.declInfo = declInfo + ..ref.getter = getter + ..ref.setter = setter; } final class CXIdxObjCProtocolRefInfo extends ffi.Struct { @@ -8817,6 +8884,14 @@ final class CXIdxObjCProtocolRefListInfo extends ffi.Struct { @ffi.UnsignedInt() external int numProtocols; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer> protocols, + required int numProtocols, + }) => allocator() + ..ref.protocols = protocols + ..ref.numProtocols = numProtocols; } /// Visitor invoked for each file in a translation unit @@ -9134,6 +9209,14 @@ final class CXSourceRangeList extends ffi.Struct { /// An array of \c CXSourceRanges. external ffi.Pointer ranges; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int count, + required ffi.Pointer ranges, + }) => allocator() + ..ref.count = count + ..ref.ranges = ranges; } /// A character string. @@ -9147,6 +9230,14 @@ final class CXString extends ffi.Struct { @ffi.UnsignedInt() external int private_flags; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer data, + required int private_flags, + }) => allocator() + ..ref.data = data + ..ref.private_flags = private_flags; } final class CXStringSet extends ffi.Struct { @@ -9154,6 +9245,14 @@ final class CXStringSet extends ffi.Struct { @ffi.UnsignedInt() external int Count; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer Strings, + required int Count, + }) => allocator() + ..ref.Strings = Strings + ..ref.Count = Count; } /// Roles that are attributed to symbol occurrences. @@ -9216,6 +9315,16 @@ final class CXTUResourceUsage extends ffi.Struct { external int numEntries; external ffi.Pointer entries; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer data, + required int numEntries, + required ffi.Pointer entries, + }) => allocator() + ..ref.data = data + ..ref.numEntries = numEntries + ..ref.entries = entries; } final class CXTUResourceUsageEntry extends ffi.Struct { @@ -9227,6 +9336,14 @@ final class CXTUResourceUsageEntry extends ffi.Struct { @ffi.UnsignedLong() external int amount; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required CXTUResourceUsageKind kind, + required int amount, + }) => allocator() + ..ref.kind = kind + ..ref.amount = amount; } /// Categorizes how memory is being used by a translation unit. @@ -9689,6 +9806,16 @@ final class CXUnsavedFile extends ffi.Struct { /// The length of the unsaved contents of this buffer. @ffi.UnsignedLong() external int Length; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer Filename, + required ffi.Pointer Contents, + required int Length, + }) => allocator() + ..ref.Filename = Filename + ..ref.Contents = Contents + ..ref.Length = Length; } /// Describes a version number of the form major.minor.subminor. @@ -9709,6 +9836,16 @@ final class CXVersion extends ffi.Struct { /// e.g., in version '10' or '10.7'. @ffi.Int() external int Subminor; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int Major, + required int Minor, + required int Subminor, + }) => allocator() + ..ref.Major = Major + ..ref.Minor = Minor + ..ref.Subminor = Subminor; } enum CXVisibilityKind { @@ -9882,6 +10019,82 @@ final class IndexerCallbacks extends ffi.Struct { > > indexEntityReference; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + CXClientData client_data, + ffi.Pointer reserved, + ) + > + > + abortQuery, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function(CXClientData, CXDiagnosticSet, ffi.Pointer) + > + > + diagnostic, + required ffi.Pointer< + ffi.NativeFunction< + CXIdxClientFile Function( + CXClientData client_data, + CXFile mainFile, + ffi.Pointer reserved, + ) + > + > + enteredMainFile, + required ffi.Pointer< + ffi.NativeFunction< + CXIdxClientFile Function( + CXClientData, + ffi.Pointer, + ) + > + > + ppIncludedFile, + required ffi.Pointer< + ffi.NativeFunction< + CXIdxClientASTFile Function( + CXClientData, + ffi.Pointer, + ) + > + > + importedASTFile, + required ffi.Pointer< + ffi.NativeFunction< + CXIdxClientContainer Function( + CXClientData client_data, + ffi.Pointer reserved, + ) + > + > + startedTranslationUnit, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function(CXClientData, ffi.Pointer) + > + > + indexDeclaration, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function(CXClientData, ffi.Pointer) + > + > + indexEntityReference, + }) => allocator() + ..ref.abortQuery = abortQuery + ..ref.diagnostic = diagnostic + ..ref.enteredMainFile = enteredMainFile + ..ref.ppIncludedFile = ppIncludedFile + ..ref.importedASTFile = importedASTFile + ..ref.startedTranslationUnit = startedTranslationUnit + ..ref.indexDeclaration = indexDeclaration + ..ref.indexEntityReference = indexEntityReference; } typedef NativeClang_CXCursorSet_contains = diff --git a/pkgs/ffigen/example/shared_bindings/lib/generated/a_shared_b_gen.dart b/pkgs/ffigen/example/shared_bindings/lib/generated/a_shared_b_gen.dart index e02daf082c..6184724326 100644 --- a/pkgs/ffigen/example/shared_bindings/lib/generated/a_shared_b_gen.dart +++ b/pkgs/ffigen/example/shared_bindings/lib/generated/a_shared_b_gen.dart @@ -101,6 +101,11 @@ const int A_MACRO_1 = 1; final class A_Struct1 extends ffi.Struct { @ffi.Int() external int a; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int a, + }) => allocator()..ref.a = a; } final class A_Union1 extends ffi.Union { diff --git a/pkgs/ffigen/lib/src/code_generator/compound.dart b/pkgs/ffigen/lib/src/code_generator/compound.dart index 55bc5691a3..afe2634731 100644 --- a/pkgs/ffigen/lib/src/code_generator/compound.dart +++ b/pkgs/ffigen/lib/src/code_generator/compound.dart @@ -58,6 +58,103 @@ abstract class Compound extends BindingType with HasLocalScope { return type.getCType(context); } + bool _shouldGenerateAllocate() { + if (this is! Struct || isOpaque) { + return false; + } + for (final m in members) { + final memberType = m.type.typealiasType; + if (memberType is ConstantArray) { + return false; + } + if (memberType is Struct || memberType is Union) { + return false; + } + } + return true; + } + + bool _isEnumDartStyleMember(CompoundMember member) { + final type = member.type; + return type is EnumClass && type.style == EnumStyle.dartEnum; + } + + String _memberStorageName(CompoundMember member) { + if (_isEnumDartStyleMember(member)) { + return member.name; + } + return member.type.sameDartAndFfiDartType + ? member.name + : '${member.name}AsInt'; + } + + String _memberParameterType(CompoundMember member) { + if (_isEnumDartStyleMember(member)) { + return member.type.getDartType(context); + } + return member.type.getFfiDartType(context); + } + + String _makeUniqueName( + String preferred, + SymbolKind kind, + Set usedNames, + ) { + var name = preferred; + if (name.isEmpty) { + name = 'value'; + } + if (name == 'allocator') { + name = 'allocatorValue'; + } + return Namer(usedNames).add(name, kind); + } + + String _generateAllocateMethod(String enclosingClassName, String ffiPrefix) { + final usedClassMemberNames = {}; + for (final m in members) { + usedClassMemberNames.add(_memberStorageName(m)); + if (_isEnumDartStyleMember(m)) { + usedClassMemberNames.add(m.name); + } + } + final methodName = _makeUniqueName( + 'allocate', + SymbolKind.method, + usedClassMemberNames, + ); + + final usedParamNames = {'allocator'}; + final params = <({String type, String name, String assignment})>[]; + for (final m in members) { + final paramName = _makeUniqueName( + m.name, + SymbolKind.field, + usedParamNames, + ); + params.add(( + type: _memberParameterType(m), + name: paramName, + assignment: _memberStorageName(m), + )); + } + + final b = StringBuffer(); + b.write( + ' static $ffiPrefix.Pointer<$enclosingClassName> $methodName(\n' + ' $ffiPrefix.Allocator allocator, {\n', + ); + for (final p in params) { + b.write(' required ${p.type} ${p.name},\n'); + } + b.write(' }) => allocator<$enclosingClassName>()'); + for (final p in params) { + b.write('\n ..ref.${p.assignment} = ${p.name}'); + } + b.write(';\n\n'); + return b.toString(); + } + @override bool get isObjCImport => context.objCBuiltInFunctions.getBuiltInCompoundName(originalName) != null; @@ -118,6 +215,9 @@ abstract class Compound extends BindingType with HasLocalScope { ); } } + if (_shouldGenerateAllocate()) { + s.write(_generateAllocateMethod(enclosingClassName, ffiPrefix)); + } s.write('}\n\n'); final bindingType = this is Struct diff --git a/pkgs/ffigen/test/code_generator_tests/code_generator_test.dart b/pkgs/ffigen/test/code_generator_tests/code_generator_test.dart index 2a993d1e2d..a16875b673 100644 --- a/pkgs/ffigen/test/code_generator_tests/code_generator_test.dart +++ b/pkgs/ffigen/test/code_generator_tests/code_generator_test.dart @@ -197,6 +197,32 @@ void main() { _matchLib(library, 'struct'); }); + test('Struct allocate helper name collisions', () { + final context = makeContext(); + final library = Library( + context: context, + header: licenseHeader, + bindings: transformBindings([ + Struct( + context: context, + name: 'CollisionStruct', + members: [ + CompoundMember( + name: 'allocator', + type: NativeType(SupportedNativeType.int32), + ), + CompoundMember( + name: 'allocate', + type: NativeType(SupportedNativeType.int32), + ), + ], + ), + ], context), + ); + + _matchLib(library, 'struct_allocate_collision'); + }); + test('Function and Struct Binding (pointer to Struct)', () { final context = makeContext(); final structSome = Struct( diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_boolean_dartbool_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_boolean_dartbool_bindings.dart index d3db1618cd..e907c6c5e7 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_boolean_dartbool_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_boolean_dartbool_bindings.dart @@ -36,4 +36,9 @@ class Bindings { final class Test2 extends ffi.Struct { @ffi.Bool() external bool a; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required bool a, + }) => allocator()..ref.a = a; } diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_enumclass_func_and_struct_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_enumclass_func_and_struct_bindings.dart index c2fff4134d..f4b3f66c8e 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_enumclass_func_and_struct_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_enumclass_func_and_struct_bindings.dart @@ -91,4 +91,12 @@ final class StructWithEnums extends ffi.Struct { @ffi.Int() external int enum2; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required Enum1 enum1, + required int enum2, + }) => allocator() + ..ref.enum1 = enum1 + ..ref.enum2 = enum2; } diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_n_struct_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_n_struct_bindings.dart index faa7cf9586..a8cefa0159 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_n_struct_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_function_n_struct_bindings.dart @@ -46,4 +46,14 @@ final class SomeStruct extends ffi.Struct { @ffi.Uint8() external int c; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int a, + required double b, + required int c, + }) => allocator() + ..ref.a = a + ..ref.b = b + ..ref.c = c; } diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_packed_structs_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_packed_structs_bindings.dart index d1ca580ddc..450808a888 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_packed_structs_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_packed_structs_bindings.dart @@ -11,34 +11,64 @@ import 'dart:ffi' as ffi; final class NoPacking extends ffi.Struct { @ffi.Uint8() external int a; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int a, + }) => allocator()..ref.a = a; } @ffi.Packed(1) final class Pack1 extends ffi.Struct { @ffi.Uint8() external int a; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int a, + }) => allocator()..ref.a = a; } @ffi.Packed(16) final class Pack16 extends ffi.Struct { @ffi.Uint8() external int a; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int a, + }) => allocator()..ref.a = a; } @ffi.Packed(2) final class Pack2 extends ffi.Struct { @ffi.Uint8() external int a; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int a, + }) => allocator()..ref.a = a; } @ffi.Packed(4) final class Pack4 extends ffi.Struct { @ffi.Uint8() external int a; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int a, + }) => allocator()..ref.a = a; } @ffi.Packed(8) final class Pack8 extends ffi.Struct { @ffi.Uint8() external int a; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int a, + }) => allocator()..ref.a = a; } diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_struct_allocate_collision_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_struct_allocate_collision_bindings.dart new file mode 100644 index 0000000000..97dde8bb8d --- /dev/null +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_struct_allocate_collision_bindings.dart @@ -0,0 +1,25 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// AUTO GENERATED FILE, DO NOT EDIT. +// +// Generated by `package:ffigen`. +// ignore_for_file: type=lint, unused_import +import 'dart:ffi' as ffi; + +final class CollisionStruct extends ffi.Struct { + @ffi.Int32() + external int allocator; + + @ffi.Int32() + external int allocate; + + static ffi.Pointer allocate$1( + ffi.Allocator allocator, { + required int allocatorValue, + required int allocate, + }) => allocator() + ..ref.allocator = allocatorValue + ..ref.allocate = allocate; +} diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_struct_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_struct_bindings.dart index a9775c44df..87367c635c 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_struct_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_struct_bindings.dart @@ -16,6 +16,14 @@ final class WithIntPtrUintPtr extends ffi.Struct { external ffi.Pointer a; external ffi.Pointer> b; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer a, + required ffi.Pointer> b, + }) => allocator() + ..ref.a = a + ..ref.b = b; } final class WithPointerMember extends ffi.Struct { @@ -25,6 +33,16 @@ final class WithPointerMember extends ffi.Struct { @ffi.Uint8() external int c; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer a, + required ffi.Pointer> b, + required int c, + }) => allocator() + ..ref.a = a + ..ref.b = b + ..ref.c = c; } final class WithPrimitiveMember extends ffi.Struct { @@ -36,4 +54,14 @@ final class WithPrimitiveMember extends ffi.Struct { @ffi.Uint8() external int c; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int a, + required double b, + required int c, + }) => allocator() + ..ref.a = a + ..ref.b = b + ..ref.c = c; } diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_typealias_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_typealias_bindings.dart index c63259baa4..984828a019 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_typealias_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_typealias_bindings.dart @@ -50,6 +50,11 @@ final class Struct1 extends ffi.Opaque {} final class Struct2 extends ffi.Struct { @ffi.Double() external double a; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required double a, + }) => allocator()..ref.a = a; } typedef Struct2Typealias = Struct2; diff --git a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_unions_bindings.dart b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_unions_bindings.dart index a5c72e668c..ba6577167c 100644 --- a/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_unions_bindings.dart +++ b/pkgs/ffigen/test/code_generator_tests/expected_bindings/_expected_unions_bindings.dart @@ -41,6 +41,11 @@ final class PrimitivesWithPointers extends ffi.Union { final class Struct1 extends ffi.Struct { @ffi.Char() external int a; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int a, + }) => allocator()..ref.a = a; } final class Union1 extends ffi.Union { diff --git a/pkgs/ffigen/test/collision_tests/expected_bindings/_expected_decl_type_name_collision_bindings.dart b/pkgs/ffigen/test/collision_tests/expected_bindings/_expected_decl_type_name_collision_bindings.dart index 894c09c4f3..91169f376f 100644 --- a/pkgs/ffigen/test/collision_tests/expected_bindings/_expected_decl_type_name_collision_bindings.dart +++ b/pkgs/ffigen/test/collision_tests/expected_bindings/_expected_decl_type_name_collision_bindings.dart @@ -7,6 +7,9 @@ import 'dart:ffi' as ffi; final class A extends ffi.Struct { @ffi.Int() external int a; + + static ffi.Pointer allocate(ffi.Allocator allocator, {required int a}) => + allocator()..ref.a = a; } final class B extends ffi.Struct { @@ -15,6 +18,14 @@ final class B extends ffi.Struct { @ffi.Int() external int A$1; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int B$1, + required int A$1, + }) => allocator() + ..ref.B$1 = B$1 + ..ref.A$1 = A$1; } final class C extends ffi.Struct { diff --git a/pkgs/ffigen/test/collision_tests/expected_bindings/_expected_reserved_keyword_collision_bindings.dart b/pkgs/ffigen/test/collision_tests/expected_bindings/_expected_reserved_keyword_collision_bindings.dart index 35583b337b..0dfb9def7d 100644 --- a/pkgs/ffigen/test/collision_tests/expected_bindings/_expected_reserved_keyword_collision_bindings.dart +++ b/pkgs/ffigen/test/collision_tests/expected_bindings/_expected_reserved_keyword_collision_bindings.dart @@ -41,6 +41,14 @@ final class Repro2795 extends ffi.Struct { ffi.NativeFunction in$)> > var$1; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer< + ffi.NativeFunction in$)> + > + var$1, + }) => allocator()..ref.var$1 = var$1; } final class abstract$ extends ffi.Opaque {} diff --git a/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_dart_handle_bindings.dart b/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_dart_handle_bindings.dart index 51960ee1ef..7a0df41d3d 100644 --- a/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_dart_handle_bindings.dart +++ b/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_dart_handle_bindings.dart @@ -64,6 +64,11 @@ final class Struct1 extends ffi.Opaque {} final class Struct2 extends ffi.Struct { external ffi.Pointer h; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer h, + }) => allocator()..ref.h = h; } typedef Typedef1 = ffi.Pointer>; diff --git a/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_forward_decl_bindings.dart b/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_forward_decl_bindings.dart index 4f18dac1d7..f5c6a9134e 100644 --- a/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_forward_decl_bindings.dart +++ b/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_forward_decl_bindings.dart @@ -36,6 +36,14 @@ final class A extends ffi.Struct { @ffi.Int() external int b; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int a, + required int b, + }) => allocator() + ..ref.a = a + ..ref.b = b; } enum B { diff --git a/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_native_func_typedef_bindings.dart b/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_native_func_typedef_bindings.dart index 5d9e228f6a..8a7fe69cfe 100644 --- a/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_native_func_typedef_bindings.dart +++ b/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_native_func_typedef_bindings.dart @@ -85,10 +85,27 @@ final class Struct extends ffi.Struct { > > unnamed1; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer> unnamed2, + ) + > + > + unnamed1, + }) => allocator()..ref.unnamed1 = unnamed1; } final class Struct2 extends ffi.Struct { external VoidFuncPointer constFuncPointer; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required VoidFuncPointer constFuncPointer, + }) => allocator()..ref.constFuncPointer = constFuncPointer; } typedef VoidFuncPointer = diff --git a/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_opaque_dependencies_bindings.dart b/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_opaque_dependencies_bindings.dart index 31e9753408..f33f9c5cfd 100644 --- a/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_opaque_dependencies_bindings.dart +++ b/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_opaque_dependencies_bindings.dart @@ -55,6 +55,14 @@ final class D extends ffi.Struct { external int a; external ffi.Pointer nds; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int a, + required ffi.Pointer nds, + }) => allocator() + ..ref.a = a + ..ref.nds = nds; } final class DArray extends ffi.Struct { @@ -62,6 +70,14 @@ final class DArray extends ffi.Struct { external int a; external ffi.Pointer nds; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int a, + required ffi.Pointer nds, + }) => allocator() + ..ref.a = a + ..ref.nds = nds; } final class E extends ffi.Struct { diff --git a/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_packed_structs_bindings.dart b/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_packed_structs_bindings.dart index a121c1f5ca..9ea029e0ed 100644 --- a/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_packed_structs_bindings.dart +++ b/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_packed_structs_bindings.dart @@ -7,11 +7,21 @@ import 'dart:ffi' as ffi; final class NormalStruct1 extends ffi.Struct { @ffi.Char() external int a; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int a, + }) => allocator()..ref.a = a; } final class NormalStruct2 extends ffi.Struct { @ffi.Char() external int a; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int a, + }) => allocator()..ref.a = a; } /// Should be packed with 2. @@ -19,6 +29,11 @@ final class NormalStruct2 extends ffi.Struct { final class Pack2WithPragma extends ffi.Struct { @ffi.Int() external int a; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int a, + }) => allocator()..ref.a = a; } /// Should be packed with 4. @@ -26,6 +41,11 @@ final class Pack2WithPragma extends ffi.Struct { final class Pack4WithPragma extends ffi.Struct { @ffi.LongLong() external int a; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int a, + }) => allocator()..ref.a = a; } /// Should be packed with 1. @@ -33,6 +53,11 @@ final class Pack4WithPragma extends ffi.Struct { final class PackedAttr extends ffi.Struct { @ffi.Int() external int a; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int a, + }) => allocator()..ref.a = a; } /// Should be packed with 8. @@ -40,6 +65,11 @@ final class PackedAttr extends ffi.Struct { final class PackedAttrAlign8 extends ffi.Struct { @ffi.Int() external int a; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int a, + }) => allocator()..ref.a = a; } /// Should not be packed. @@ -47,4 +77,12 @@ final class StructWithAttr extends ffi.Struct { external ffi.Pointer a; external ffi.Pointer b; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer a, + required ffi.Pointer b, + }) => allocator() + ..ref.a = a + ..ref.b = b; } diff --git a/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_typedef_bindings.dart b/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_typedef_bindings.dart index 56dd695924..d8b7bba60a 100644 --- a/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_typedef_bindings.dart +++ b/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_typedef_bindings.dart @@ -108,6 +108,14 @@ final class Struct1 extends ffi.Struct { external NamedFunctionProto named; external ffi.Pointer> unnamed; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required NamedFunctionProto named, + required ffi.Pointer> unnamed, + }) => allocator() + ..ref.named = named + ..ref.unnamed = unnamed; } final class Struct2 extends ffi.Opaque {} @@ -119,6 +127,11 @@ typedef Typeref2 = AnonymousStructInTypedef; final class WithBoolAlias extends ffi.Struct { @ffi.Bool() external bool b; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required bool b, + }) => allocator()..ref.b = b; } final class _ExcludedStruct extends ffi.Opaque {} diff --git a/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_varargs_bindings.dart b/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_varargs_bindings.dart index 84c7ba9580..dd8efb1cc0 100644 --- a/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_varargs_bindings.dart +++ b/pkgs/ffigen/test/header_parser_tests/expected_bindings/_expected_varargs_bindings.dart @@ -187,9 +187,17 @@ class NativeLibrary { final class SA extends ffi.Struct { @ffi.Int() external int a; + + static ffi.Pointer allocate(ffi.Allocator allocator, {required int a}) => + allocator()..ref.a = a; } final class Struct_WithLong_Name_test extends ffi.Struct { @ffi.Int() external int a; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int a, + }) => allocator()..ref.a = a; } diff --git a/pkgs/ffigen/test/large_integration_tests/_expected_cjson_bindings.dart b/pkgs/ffigen/test/large_integration_tests/_expected_cjson_bindings.dart index 1f5fe8fe9d..51f7b76945 100644 --- a/pkgs/ffigen/test/large_integration_tests/_expected_cjson_bindings.dart +++ b/pkgs/ffigen/test/large_integration_tests/_expected_cjson_bindings.dart @@ -1225,6 +1225,26 @@ final class cJSON extends ffi.Struct { external double valuedouble; external ffi.Pointer string; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer next, + required ffi.Pointer prev, + required ffi.Pointer child, + required int type, + required ffi.Pointer valuestring, + required int valueint, + required double valuedouble, + required ffi.Pointer string, + }) => allocator() + ..ref.next = next + ..ref.prev = prev + ..ref.child = child + ..ref.type = type + ..ref.valuestring = valuestring + ..ref.valueint = valueint + ..ref.valuedouble = valuedouble + ..ref.string = string; } const int cJSON_Array = 32; @@ -1241,6 +1261,20 @@ final class cJSON_Hooks extends ffi.Struct { ffi.NativeFunction ptr)> > free_fn; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer< + ffi.NativeFunction Function(ffi.Size sz)> + > + malloc_fn, + required ffi.Pointer< + ffi.NativeFunction ptr)> + > + free_fn, + }) => allocator() + ..ref.malloc_fn = malloc_fn + ..ref.free_fn = free_fn; } const int cJSON_Invalid = 0; diff --git a/pkgs/ffigen/test/large_integration_tests/_expected_libclang_bindings.dart b/pkgs/ffigen/test/large_integration_tests/_expected_libclang_bindings.dart index e4a242fcd2..c22f07de7c 100644 --- a/pkgs/ffigen/test/large_integration_tests/_expected_libclang_bindings.dart +++ b/pkgs/ffigen/test/large_integration_tests/_expected_libclang_bindings.dart @@ -5635,6 +5635,14 @@ final class CXCodeCompleteResults extends ffi.Struct { /// The number of code-completion results stored in the Results array. @ffi.UnsignedInt() external int NumResults; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer Results, + required int NumResults, + }) => allocator() + ..ref.Results = Results + ..ref.NumResults = NumResults; } /// Flags that can be passed to clang_codeCompleteAt() to modify its behavior. @@ -5911,6 +5919,14 @@ final class CXCompletionResult extends ffi.Struct { /// The code-completion string that describes how to insert this /// code-completion result into the editing buffer. external CXCompletionString CompletionString; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required CXCursorKind CursorKind, + required CXCompletionString CompletionString, + }) => allocator() + ..ref.CursorKind = CursorKind + ..ref.CompletionString = CompletionString; } /// A semantic string that describes a code-completion result. @@ -5941,6 +5957,19 @@ final class CXCursorAndRangeVisitor extends ffi.Struct { > > visit; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer context, + required ffi.Pointer< + ffi.NativeFunction< + ffi.UnsignedInt Function(ffi.Pointer, CXCursor, CXSourceRange) + > + > + visit, + }) => allocator() + ..ref.context = context + ..ref.visit = visit; } /// Describes the kind of entity that a cursor refers to. @@ -7184,6 +7213,16 @@ final class CXIdxCXXClassDeclInfo extends ffi.Struct { @ffi.UnsignedInt() external int numBases; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer declInfo, + required ffi.Pointer> bases, + required int numBases, + }) => allocator() + ..ref.declInfo = declInfo + ..ref.bases = bases + ..ref.numBases = numBases; } /// The client's data object that is associated with an AST file (PCH or @@ -7523,6 +7562,14 @@ final class CXIdxObjCContainerDeclInfo extends ffi.Struct { CXIdxObjCContainerKind get kind => CXIdxObjCContainerKind.fromValue(kindAsInt); set kind(CXIdxObjCContainerKind value) => kindAsInt = value.value; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer declInfo, + required CXIdxObjCContainerKind kind, + }) => allocator() + ..ref.declInfo = declInfo + ..ref.kind = kind; } enum CXIdxObjCContainerKind { @@ -7549,6 +7596,16 @@ final class CXIdxObjCInterfaceDeclInfo extends ffi.Struct { external ffi.Pointer superInfo; external ffi.Pointer protocols; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer containerInfo, + required ffi.Pointer superInfo, + required ffi.Pointer protocols, + }) => allocator() + ..ref.containerInfo = containerInfo + ..ref.superInfo = superInfo + ..ref.protocols = protocols; } final class CXIdxObjCPropertyDeclInfo extends ffi.Struct { @@ -7557,6 +7614,16 @@ final class CXIdxObjCPropertyDeclInfo extends ffi.Struct { external ffi.Pointer getter; external ffi.Pointer setter; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer declInfo, + required ffi.Pointer getter, + required ffi.Pointer setter, + }) => allocator() + ..ref.declInfo = declInfo + ..ref.getter = getter + ..ref.setter = setter; } final class CXIdxObjCProtocolRefInfo extends ffi.Struct { @@ -7572,6 +7639,14 @@ final class CXIdxObjCProtocolRefListInfo extends ffi.Struct { @ffi.UnsignedInt() external int numProtocols; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer> protocols, + required int numProtocols, + }) => allocator() + ..ref.protocols = protocols + ..ref.numProtocols = numProtocols; } /// Visitor invoked for each file in a translation unit (used with @@ -8060,6 +8135,14 @@ final class CXSourceRangeList extends ffi.Struct { /// An array of CXSourceRanges. external ffi.Pointer ranges; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int count, + required ffi.Pointer ranges, + }) => allocator() + ..ref.count = count + ..ref.ranges = ranges; } /// A character string. @@ -8068,6 +8151,14 @@ final class CXString extends ffi.Struct { @ffi.UnsignedInt() external int private_flags; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer data, + required int private_flags, + }) => allocator() + ..ref.data = data + ..ref.private_flags = private_flags; } final class CXStringSet extends ffi.Struct { @@ -8075,6 +8166,14 @@ final class CXStringSet extends ffi.Struct { @ffi.UnsignedInt() external int Count; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer Strings, + required int Count, + }) => allocator() + ..ref.Strings = Strings + ..ref.Count = Count; } /// Roles that are attributed to symbol occurrences. @@ -8134,6 +8233,16 @@ final class CXTUResourceUsage extends ffi.Struct { external int numEntries; external ffi.Pointer entries; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer data, + required int numEntries, + required ffi.Pointer entries, + }) => allocator() + ..ref.data = data + ..ref.numEntries = numEntries + ..ref.entries = entries; } final class CXTUResourceUsageEntry extends ffi.Struct { @@ -8145,6 +8254,14 @@ final class CXTUResourceUsageEntry extends ffi.Struct { @ffi.UnsignedLong() external int amount; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required CXTUResourceUsageKind kind, + required int amount, + }) => allocator() + ..ref.kind = kind + ..ref.amount = amount; } /// Categorizes how memory is being used by a translation unit. @@ -8718,6 +8835,16 @@ final class CXUnsavedFile extends ffi.Struct { /// The length of the unsaved contents of this buffer. @ffi.UnsignedLong() external int Length; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer Filename, + required ffi.Pointer Contents, + required int Length, + }) => allocator() + ..ref.Filename = Filename + ..ref.Contents = Contents + ..ref.Length = Length; } /// Describes a version number of the form major.minor.subminor. @@ -8737,6 +8864,16 @@ final class CXVersion extends ffi.Struct { /// version '10' or '10.7'. @ffi.Int() external int Subminor; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int Major, + required int Minor, + required int Subminor, + }) => allocator() + ..ref.Major = Major + ..ref.Minor = Minor + ..ref.Subminor = Subminor; } /// Object encapsulating information about overlaying virtual file/directories @@ -8909,4 +9046,80 @@ final class IndexerCallbacks extends ffi.Struct { > > indexEntityReference; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + CXClientData client_data, + ffi.Pointer reserved, + ) + > + > + abortQuery, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function(CXClientData, CXDiagnosticSet, ffi.Pointer) + > + > + diagnostic, + required ffi.Pointer< + ffi.NativeFunction< + CXIdxClientFile Function( + CXClientData client_data, + CXFile mainFile, + ffi.Pointer reserved, + ) + > + > + enteredMainFile, + required ffi.Pointer< + ffi.NativeFunction< + CXIdxClientFile Function( + CXClientData, + ffi.Pointer, + ) + > + > + ppIncludedFile, + required ffi.Pointer< + ffi.NativeFunction< + CXIdxClientASTFile Function( + CXClientData, + ffi.Pointer, + ) + > + > + importedASTFile, + required ffi.Pointer< + ffi.NativeFunction< + CXIdxClientContainer Function( + CXClientData client_data, + ffi.Pointer reserved, + ) + > + > + startedTranslationUnit, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function(CXClientData, ffi.Pointer) + > + > + indexDeclaration, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function(CXClientData, ffi.Pointer) + > + > + indexEntityReference, + }) => allocator() + ..ref.abortQuery = abortQuery + ..ref.diagnostic = diagnostic + ..ref.enteredMainFile = enteredMainFile + ..ref.ppIncludedFile = ppIncludedFile + ..ref.importedASTFile = importedASTFile + ..ref.startedTranslationUnit = startedTranslationUnit + ..ref.indexDeclaration = indexDeclaration + ..ref.indexEntityReference = indexEntityReference; } diff --git a/pkgs/ffigen/test/large_integration_tests/_expected_sqlite_bindings.dart b/pkgs/ffigen/test/large_integration_tests/_expected_sqlite_bindings.dart index 2f88d6e851..458e0f5182 100644 --- a/pkgs/ffigen/test/large_integration_tests/_expected_sqlite_bindings.dart +++ b/pkgs/ffigen/test/large_integration_tests/_expected_sqlite_bindings.dart @@ -11268,12 +11268,226 @@ final class Fts5ExtensionApi extends ffi.Struct { > > xPhraseNextColumn; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int iVersion, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer) + > + > + xUserData, + required ffi.Pointer< + ffi.NativeFunction)> + > + xColumnCount, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Pointer) + > + > + xRowCount, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Int, + ffi.Pointer, + ) + > + > + xColumnTotalSize, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer, + ffi.Int, + ffi.Pointer, + ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Int, + ffi.Pointer, + ffi.Int, + ffi.Int, + ffi.Int, + ) + > + >, + ) + > + > + xTokenize, + required ffi.Pointer< + ffi.NativeFunction)> + > + xPhraseCount, + required ffi.Pointer< + ffi.NativeFunction, ffi.Int)> + > + xPhraseSize, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Pointer) + > + > + xInstCount, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Int, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ) + > + > + xInst, + required ffi.Pointer< + ffi.NativeFunction)> + > + xRowid, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Int, + ffi.Pointer>, + ffi.Pointer, + ) + > + > + xColumnText, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Int, + ffi.Pointer, + ) + > + > + xColumnSize, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Int, + ffi.Pointer, + ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ) + > + >, + ) + > + > + xQueryPhrase, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer< + ffi.NativeFunction)> + >, + ) + > + > + xSetAuxdata, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer, ffi.Int) + > + > + xGetAuxdata, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Int, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ) + > + > + xPhraseFirst, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ) + > + > + xPhraseNext, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Int, + ffi.Pointer, + ffi.Pointer, + ) + > + > + xPhraseFirstColumn, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ) + > + > + xPhraseNextColumn, + }) => allocator() + ..ref.iVersion = iVersion + ..ref.xUserData = xUserData + ..ref.xColumnCount = xColumnCount + ..ref.xRowCount = xRowCount + ..ref.xColumnTotalSize = xColumnTotalSize + ..ref.xTokenize = xTokenize + ..ref.xPhraseCount = xPhraseCount + ..ref.xPhraseSize = xPhraseSize + ..ref.xInstCount = xInstCount + ..ref.xInst = xInst + ..ref.xRowid = xRowid + ..ref.xColumnText = xColumnText + ..ref.xColumnSize = xColumnSize + ..ref.xQueryPhrase = xQueryPhrase + ..ref.xSetAuxdata = xSetAuxdata + ..ref.xGetAuxdata = xGetAuxdata + ..ref.xPhraseFirst = xPhraseFirst + ..ref.xPhraseNext = xPhraseNext + ..ref.xPhraseFirstColumn = xPhraseFirstColumn + ..ref.xPhraseNextColumn = xPhraseNextColumn; } final class Fts5PhraseIter extends ffi.Struct { external ffi.Pointer a; external ffi.Pointer b; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer a, + required ffi.Pointer b, + }) => allocator() + ..ref.a = a + ..ref.b = b; } final class Fts5Tokenizer extends ffi.Opaque {} @@ -12198,6 +12412,56 @@ final class fts5_api extends ffi.Struct { > > xCreateFunction; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int iVersion, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer pApi, + ffi.Pointer zName, + ffi.Pointer pContext, + ffi.Pointer pTokenizer, + ffi.Pointer< + ffi.NativeFunction)> + > + xDestroy, + ) + > + > + xCreateTokenizer, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer pApi, + ffi.Pointer zName, + ffi.Pointer> ppContext, + ffi.Pointer pTokenizer, + ) + > + > + xFindTokenizer, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer pApi, + ffi.Pointer zName, + ffi.Pointer pContext, + fts5_extension_function xFunction, + ffi.Pointer< + ffi.NativeFunction)> + > + xDestroy, + ) + > + > + xCreateFunction, + }) => allocator() + ..ref.iVersion = iVersion + ..ref.xCreateTokenizer = xCreateTokenizer + ..ref.xFindTokenizer = xFindTokenizer + ..ref.xCreateFunction = xCreateFunction; } typedef fts5_extension_function = @@ -12261,6 +12525,52 @@ final class fts5_tokenizer extends ffi.Struct { > > xTokenize; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer>, + ffi.Int, + ffi.Pointer>, + ) + > + > + xCreate, + required ffi.Pointer< + ffi.NativeFunction)> + > + xDelete, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer, + ffi.Int, + ffi.Pointer, + ffi.Int, + ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Int, + ffi.Pointer, + ffi.Int, + ffi.Int, + ffi.Int, + ) + > + >, + ) + > + > + xTokenize, + }) => allocator() + ..ref.xCreate = xCreate + ..ref.xDelete = xDelete + ..ref.xTokenize = xTokenize; } final class sqlite3 extends ffi.Opaque {} @@ -12315,6 +12625,11 @@ typedef Dartsqlite3_destructor_typeFunction = final class sqlite3_file extends ffi.Struct { /// Methods for an open file external ffi.Pointer pMethods; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer pMethods, + }) => allocator()..ref.pMethods = pMethods; } final class sqlite3_index_constraint extends ffi.Struct { @@ -12333,6 +12648,18 @@ final class sqlite3_index_constraint extends ffi.Struct { /// Used internally - xBestIndex should ignore @ffi.Int() external int iTermOffset; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int iColumn, + required int op, + required int usable, + required int iTermOffset, + }) => allocator() + ..ref.iColumn = iColumn + ..ref.op = op + ..ref.usable = usable + ..ref.iTermOffset = iTermOffset; } /// Outputs @@ -12344,6 +12671,14 @@ final class sqlite3_index_constraint_usage extends ffi.Struct { /// Do not code a test for this constraint @ffi.UnsignedChar() external int omit; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int argvIndex, + required int omit, + }) => allocator() + ..ref.argvIndex = argvIndex + ..ref.omit = omit; } /// CAPI3REF: Virtual Table Indexing Information @@ -12493,6 +12828,36 @@ final class sqlite3_index_info extends ffi.Struct { /// Input: Mask of columns used by statement @sqlite3_uint64() external int colUsed; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int nConstraint, + required ffi.Pointer aConstraint, + required int nOrderBy, + required ffi.Pointer aOrderBy, + required ffi.Pointer aConstraintUsage, + required int idxNum, + required ffi.Pointer idxStr, + required int needToFreeIdxStr, + required int orderByConsumed, + required double estimatedCost, + required int estimatedRows, + required int idxFlags, + required int colUsed, + }) => allocator() + ..ref.nConstraint = nConstraint + ..ref.aConstraint = aConstraint + ..ref.nOrderBy = nOrderBy + ..ref.aOrderBy = aOrderBy + ..ref.aConstraintUsage = aConstraintUsage + ..ref.idxNum = idxNum + ..ref.idxStr = idxStr + ..ref.needToFreeIdxStr = needToFreeIdxStr + ..ref.orderByConsumed = orderByConsumed + ..ref.estimatedCost = estimatedCost + ..ref.estimatedRows = estimatedRows + ..ref.idxFlags = idxFlags + ..ref.colUsed = colUsed; } final class sqlite3_index_orderby extends ffi.Struct { @@ -12503,6 +12868,14 @@ final class sqlite3_index_orderby extends ffi.Struct { /// True for DESC. False for ASC. @ffi.UnsignedChar() external int desc; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int iColumn, + required int desc, + }) => allocator() + ..ref.iColumn = iColumn + ..ref.desc = desc; } typedef sqlite3_int64 = sqlite_int64; @@ -12553,6 +12926,47 @@ final class sqlite3_mem_methods extends ffi.Struct { /// Argument to xInit() and xShutdown() external ffi.Pointer pAppData; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer< + ffi.NativeFunction Function(ffi.Int)> + > + xMalloc, + required ffi.Pointer< + ffi.NativeFunction)> + > + xFree, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Pointer, ffi.Int) + > + > + xRealloc, + required ffi.Pointer< + ffi.NativeFunction)> + > + xSize, + required ffi.Pointer> + xRoundup, + required ffi.Pointer< + ffi.NativeFunction)> + > + xInit, + required ffi.Pointer< + ffi.NativeFunction)> + > + xShutdown, + required ffi.Pointer pAppData, + }) => allocator() + ..ref.xMalloc = xMalloc + ..ref.xFree = xFree + ..ref.xRealloc = xRealloc + ..ref.xSize = xSize + ..ref.xRoundup = xRoundup + ..ref.xInit = xInit + ..ref.xShutdown = xShutdown + ..ref.pAppData = pAppData; } /// CAPI3REF: Virtual Table Object @@ -12769,6 +13183,205 @@ final class sqlite3_module extends ffi.Struct { ffi.NativeFunction)> > xShadowName; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int iVersion, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer, + ffi.Int, + ffi.Pointer>, + ffi.Pointer>, + ffi.Pointer>, + ) + > + > + xCreate, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer, + ffi.Int, + ffi.Pointer>, + ffi.Pointer>, + ffi.Pointer>, + ) + > + > + xConnect, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer, + ) + > + > + xBestIndex, + required ffi.Pointer< + ffi.NativeFunction pVTab)> + > + xDisconnect, + required ffi.Pointer< + ffi.NativeFunction pVTab)> + > + xDestroy, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer pVTab, + ffi.Pointer> ppCursor, + ) + > + > + xOpen, + required ffi.Pointer< + ffi.NativeFunction)> + > + xClose, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Int, + ffi.Pointer, + ffi.Int, + ffi.Pointer>, + ) + > + > + xFilter, + required ffi.Pointer< + ffi.NativeFunction)> + > + xNext, + required ffi.Pointer< + ffi.NativeFunction)> + > + xEof, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer, + ffi.Int, + ) + > + > + xColumn, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer, + ) + > + > + xRowid, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Int, + ffi.Pointer>, + ffi.Pointer, + ) + > + > + xUpdate, + required ffi.Pointer< + ffi.NativeFunction pVTab)> + > + xBegin, + required ffi.Pointer< + ffi.NativeFunction pVTab)> + > + xSync, + required ffi.Pointer< + ffi.NativeFunction pVTab)> + > + xCommit, + required ffi.Pointer< + ffi.NativeFunction pVTab)> + > + xRollback, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer pVtab, + ffi.Int nArg, + ffi.Pointer zName, + ffi.Pointer< + ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer, + ffi.Int, + ffi.Pointer>, + ) + > + > + > + pxFunc, + ffi.Pointer> ppArg, + ) + > + > + xFindFunction, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer pVtab, + ffi.Pointer zNew, + ) + > + > + xRename, + required ffi.Pointer< + ffi.NativeFunction, ffi.Int)> + > + xSavepoint, + required ffi.Pointer< + ffi.NativeFunction, ffi.Int)> + > + xRelease, + required ffi.Pointer< + ffi.NativeFunction, ffi.Int)> + > + xRollbackTo, + required ffi.Pointer< + ffi.NativeFunction)> + > + xShadowName, + }) => allocator() + ..ref.iVersion = iVersion + ..ref.xCreate = xCreate + ..ref.xConnect = xConnect + ..ref.xBestIndex = xBestIndex + ..ref.xDisconnect = xDisconnect + ..ref.xDestroy = xDestroy + ..ref.xOpen = xOpen + ..ref.xClose = xClose + ..ref.xFilter = xFilter + ..ref.xNext = xNext + ..ref.xEof = xEof + ..ref.xColumn = xColumn + ..ref.xRowid = xRowid + ..ref.xUpdate = xUpdate + ..ref.xBegin = xBegin + ..ref.xSync = xSync + ..ref.xCommit = xCommit + ..ref.xRollback = xRollback + ..ref.xFindFunction = xFindFunction + ..ref.xRename = xRename + ..ref.xSavepoint = xSavepoint + ..ref.xRelease = xRelease + ..ref.xRollbackTo = xRollbackTo + ..ref.xShadowName = xShadowName; } final class sqlite3_mutex extends ffi.Opaque {} @@ -12812,6 +13425,49 @@ final class sqlite3_mutex_methods extends ffi.Struct { ffi.NativeFunction)> > xMutexNotheld; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer> xMutexInit, + required ffi.Pointer> xMutexEnd, + required ffi.Pointer< + ffi.NativeFunction Function(ffi.Int)> + > + xMutexAlloc, + required ffi.Pointer< + ffi.NativeFunction)> + > + xMutexFree, + required ffi.Pointer< + ffi.NativeFunction)> + > + xMutexEnter, + required ffi.Pointer< + ffi.NativeFunction)> + > + xMutexTry, + required ffi.Pointer< + ffi.NativeFunction)> + > + xMutexLeave, + required ffi.Pointer< + ffi.NativeFunction)> + > + xMutexHeld, + required ffi.Pointer< + ffi.NativeFunction)> + > + xMutexNotheld, + }) => allocator() + ..ref.xMutexInit = xMutexInit + ..ref.xMutexEnd = xMutexEnd + ..ref.xMutexAlloc = xMutexAlloc + ..ref.xMutexFree = xMutexFree + ..ref.xMutexEnter = xMutexEnter + ..ref.xMutexTry = xMutexTry + ..ref.xMutexLeave = xMutexLeave + ..ref.xMutexHeld = xMutexHeld + ..ref.xMutexNotheld = xMutexNotheld; } final class sqlite3_pcache extends ffi.Opaque {} @@ -12891,6 +13547,87 @@ final class sqlite3_pcache_methods extends ffi.Struct { ffi.NativeFunction)> > xDestroy; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer pArg, + required ffi.Pointer< + ffi.NativeFunction)> + > + xInit, + required ffi.Pointer< + ffi.NativeFunction)> + > + xShutdown, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Int szPage, ffi.Int bPurgeable) + > + > + xCreate, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer, ffi.Int) + > + > + xCachesize, + required ffi.Pointer< + ffi.NativeFunction)> + > + xPagecount, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer, + ffi.UnsignedInt, + ffi.Int, + ) + > + > + xFetch, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer, + ffi.Pointer, + ffi.Int, + ) + > + > + xUnpin, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer, + ffi.Pointer, + ffi.UnsignedInt, + ffi.UnsignedInt, + ) + > + > + xRekey, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer, ffi.UnsignedInt) + > + > + xTruncate, + required ffi.Pointer< + ffi.NativeFunction)> + > + xDestroy, + }) => allocator() + ..ref.pArg = pArg + ..ref.xInit = xInit + ..ref.xShutdown = xShutdown + ..ref.xCreate = xCreate + ..ref.xCachesize = xCachesize + ..ref.xPagecount = xPagecount + ..ref.xFetch = xFetch + ..ref.xUnpin = xUnpin + ..ref.xRekey = xRekey + ..ref.xTruncate = xTruncate + ..ref.xDestroy = xDestroy; } final class sqlite3_pcache_methods2 extends ffi.Struct { @@ -12980,6 +13717,98 @@ final class sqlite3_pcache_methods2 extends ffi.Struct { ffi.NativeFunction)> > xShrink; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int iVersion, + required ffi.Pointer pArg, + required ffi.Pointer< + ffi.NativeFunction)> + > + xInit, + required ffi.Pointer< + ffi.NativeFunction)> + > + xShutdown, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Int szPage, + ffi.Int szExtra, + ffi.Int bPurgeable, + ) + > + > + xCreate, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer, ffi.Int) + > + > + xCachesize, + required ffi.Pointer< + ffi.NativeFunction)> + > + xPagecount, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer, + ffi.UnsignedInt, + ffi.Int, + ) + > + > + xFetch, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer, + ffi.Pointer, + ffi.Int, + ) + > + > + xUnpin, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer, + ffi.Pointer, + ffi.UnsignedInt, + ffi.UnsignedInt, + ) + > + > + xRekey, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer, ffi.UnsignedInt) + > + > + xTruncate, + required ffi.Pointer< + ffi.NativeFunction)> + > + xDestroy, + required ffi.Pointer< + ffi.NativeFunction)> + > + xShrink, + }) => allocator() + ..ref.iVersion = iVersion + ..ref.pArg = pArg + ..ref.xInit = xInit + ..ref.xShutdown = xShutdown + ..ref.xCreate = xCreate + ..ref.xCachesize = xCachesize + ..ref.xPagecount = xPagecount + ..ref.xFetch = xFetch + ..ref.xUnpin = xUnpin + ..ref.xRekey = xRekey + ..ref.xTruncate = xTruncate + ..ref.xDestroy = xDestroy + ..ref.xShrink = xShrink; } final class sqlite3_pcache_page extends ffi.Struct { @@ -12988,6 +13817,14 @@ final class sqlite3_pcache_page extends ffi.Struct { /// Extra information associated with the page external ffi.Pointer pExtra; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer pBuf, + required ffi.Pointer pExtra, + }) => allocator() + ..ref.pBuf = pBuf + ..ref.pExtra = pExtra; } typedef sqlite3_rtree_dbl = ffi.Double; @@ -13014,6 +13851,23 @@ final class sqlite3_rtree_geometry extends ffi.Struct { ffi.NativeFunction)> > xDelUser; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer pContext, + required int nParam, + required ffi.Pointer aParam, + required ffi.Pointer pUser, + required ffi.Pointer< + ffi.NativeFunction)> + > + xDelUser, + }) => allocator() + ..ref.pContext = pContext + ..ref.nParam = nParam + ..ref.aParam = aParam + ..ref.pUser = pUser + ..ref.xDelUser = xDelUser; } /// A pointer to a structure of the following type is passed as the @@ -13083,6 +13937,45 @@ final class sqlite3_rtree_query_info extends ffi.Struct { /// Original SQL values of parameters external ffi.Pointer> apSqlParam; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer pContext, + required int nParam, + required ffi.Pointer aParam, + required ffi.Pointer pUser, + required ffi.Pointer< + ffi.NativeFunction)> + > + xDelUser, + required ffi.Pointer aCoord, + required ffi.Pointer anQueue, + required int nCoord, + required int iLevel, + required int mxLevel, + required int iRowid, + required double rParentScore, + required int eParentWithin, + required int eWithin, + required double rScore, + required ffi.Pointer> apSqlParam, + }) => allocator() + ..ref.pContext = pContext + ..ref.nParam = nParam + ..ref.aParam = aParam + ..ref.pUser = pUser + ..ref.xDelUser = xDelUser + ..ref.aCoord = aCoord + ..ref.anQueue = anQueue + ..ref.nCoord = nCoord + ..ref.iLevel = iLevel + ..ref.mxLevel = mxLevel + ..ref.iRowid = iRowid + ..ref.rParentScore = rParentScore + ..ref.eParentWithin = eParentWithin + ..ref.eWithin = eWithin + ..ref.rScore = rScore + ..ref.apSqlParam = apSqlParam; } /// CAPI3REF: Database Snapshot @@ -13292,6 +14185,181 @@ final class sqlite3_vfs extends ffi.Struct { > > xNextSystemCall; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int iVersion, + required int szOsFile, + required int mxPathname, + required ffi.Pointer pNext, + required ffi.Pointer zName, + required ffi.Pointer pAppData, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Int, + ffi.Pointer, + ) + > + > + xOpen, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer, + ffi.Int, + ) + > + > + xDelete, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer, + ffi.Int, + ffi.Pointer, + ) + > + > + xAccess, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer, + ffi.Int, + ffi.Pointer, + ) + > + > + xFullPathname, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer, + ffi.Pointer, + ) + > + > + xDlOpen, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function( + ffi.Pointer, + ffi.Int, + ffi.Pointer, + ) + > + > + xDlError, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Pointer> Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ) + > + > + xDlSym, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Void Function(ffi.Pointer, ffi.Pointer) + > + > + xDlClose, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Int, + ffi.Pointer, + ) + > + > + xRandomness, + required ffi.Pointer< + ffi.NativeFunction, ffi.Int)> + > + xSleep, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Pointer) + > + > + xCurrentTime, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Int, + ffi.Pointer, + ) + > + > + xGetLastError, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function(ffi.Pointer, ffi.Pointer) + > + > + xCurrentTimeInt64, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Int Function( + ffi.Pointer, + ffi.Pointer, + sqlite3_syscall_ptr, + ) + > + > + xSetSystemCall, + required ffi.Pointer< + ffi.NativeFunction< + sqlite3_syscall_ptr Function( + ffi.Pointer, + ffi.Pointer, + ) + > + > + xGetSystemCall, + required ffi.Pointer< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Pointer, + ffi.Pointer, + ) + > + > + xNextSystemCall, + }) => allocator() + ..ref.iVersion = iVersion + ..ref.szOsFile = szOsFile + ..ref.mxPathname = mxPathname + ..ref.pNext = pNext + ..ref.zName = zName + ..ref.pAppData = pAppData + ..ref.xOpen = xOpen + ..ref.xDelete = xDelete + ..ref.xAccess = xAccess + ..ref.xFullPathname = xFullPathname + ..ref.xDlOpen = xDlOpen + ..ref.xDlError = xDlError + ..ref.xDlSym = xDlSym + ..ref.xDlClose = xDlClose + ..ref.xRandomness = xRandomness + ..ref.xSleep = xSleep + ..ref.xCurrentTime = xCurrentTime + ..ref.xGetLastError = xGetLastError + ..ref.xCurrentTimeInt64 = xCurrentTimeInt64 + ..ref.xSetSystemCall = xSetSystemCall + ..ref.xGetSystemCall = xGetSystemCall + ..ref.xNextSystemCall = xNextSystemCall; } /// CAPI3REF: Virtual Table Instance Object @@ -13320,6 +14388,16 @@ final class sqlite3_vtab extends ffi.Struct { /// Error message from sqlite3_mprintf() external ffi.Pointer zErrMsg; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer pModule, + required int nRef, + required ffi.Pointer zErrMsg, + }) => allocator() + ..ref.pModule = pModule + ..ref.nRef = nRef + ..ref.zErrMsg = zErrMsg; } /// CAPI3REF: Virtual Table Cursor Object @@ -13340,6 +14418,11 @@ final class sqlite3_vtab extends ffi.Struct { final class sqlite3_vtab_cursor extends ffi.Struct { /// Virtual table of this cursor external ffi.Pointer pVtab; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required ffi.Pointer pVtab, + }) => allocator()..ref.pVtab = pVtab; } typedef sqlite_int64 = ffi.LongLong; diff --git a/pkgs/ffigen/test/native_test/_expected_native_test_bindings.dart b/pkgs/ffigen/test/native_test/_expected_native_test_bindings.dart index d22e5981f3..9e065fb630 100644 --- a/pkgs/ffigen/test/native_test/_expected_native_test_bindings.dart +++ b/pkgs/ffigen/test/native_test/_expected_native_test_bindings.dart @@ -269,6 +269,16 @@ final class Struct3 extends ffi.Struct { @ffi.Int() external int c; + + static ffi.Pointer allocate( + ffi.Allocator allocator, { + required int a, + required int b, + required int c, + }) => allocator() + ..ref.a = a + ..ref.b = b + ..ref.c = c; } final class StructWithEnums extends ffi.Struct {