diff --git a/DEPS b/DEPS index efc882c4de7a..529211f6f35e 100644 --- a/DEPS +++ b/DEPS @@ -140,7 +140,7 @@ vars = { "term_glyph_tag": "1.0.1", "test_reflective_loader_tag": "0.1.9", "test_tag": "test-v1.6.4", - "tflite_native_rev": "4e8216d8fd3d5ccc8a56a056ec43d44cf99bf5c0", + "tflite_native_rev": "ff18d205bb4eb4db98439658066e72a238044e28", "typed_data_tag": "1.1.6", "unittest_rev": "2b8375bc98bb9dc81c539c91aaea6adce12e1072", "usage_tag": "3.4.0", diff --git a/pkg/front_end/lib/src/api_unstable/vm.dart b/pkg/front_end/lib/src/api_unstable/vm.dart index e8ecc56152bc..6da41e16b20a 100644 --- a/pkg/front_end/lib/src/api_unstable/vm.dart +++ b/pkg/front_end/lib/src/api_unstable/vm.dart @@ -54,7 +54,6 @@ export '../fasta/fasta_codes.dart' templateFfiStructGeneric, templateFfiTypeInvalid, templateFfiTypeMismatch, - templateFfiTypeUnsized, templateIllegalRecursiveType; export '../fasta/hybrid_file_system.dart' show HybridFileSystem; diff --git a/pkg/front_end/lib/src/fasta/fasta_codes_generated.dart b/pkg/front_end/lib/src/fasta/fasta_codes_generated.dart index b47e5b065c9c..1ad47c1dfcc8 100644 --- a/pkg/front_end/lib/src/fasta/fasta_codes_generated.dart +++ b/pkg/front_end/lib/src/fasta/fasta_codes_generated.dart @@ -4060,38 +4060,6 @@ Message _withArgumentsFfiTypeMismatch( arguments: {'type': _type, 'type2': _type2, 'type3': _type3}); } -// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. -const Template< - Message Function( - String name, - DartType - _type)> templateFfiTypeUnsized = const Template< - Message Function(String name, DartType _type)>( - messageTemplate: - r"""Method '#name' cannot be called on something of type '#type' as this type is unsized.""", - withArguments: _withArgumentsFfiTypeUnsized); - -// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. -const Code codeFfiTypeUnsized = - const Code( - "FfiTypeUnsized", - templateFfiTypeUnsized, -); - -// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. -Message _withArgumentsFfiTypeUnsized(String name, DartType _type) { - if (name.isEmpty) throw 'No name provided'; - name = demangleMixinApplicationName(name); - TypeLabeler labeler = new TypeLabeler(); - List typeParts = labeler.labelType(_type); - String type = typeParts.join(); - return new Message(codeFfiTypeUnsized, - message: - """Method '${name}' cannot be called on something of type '${type}' as this type is unsized.""" + - labeler.originMessages, - arguments: {'name': name, 'type': _type}); -} - // DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE. const Code codeFieldInitializedOutsideDeclaringClass = messageFieldInitializedOutsideDeclaringClass; diff --git a/pkg/front_end/messages.status b/pkg/front_end/messages.status index fc289b921d48..de43c6a4365b 100644 --- a/pkg/front_end/messages.status +++ b/pkg/front_end/messages.status @@ -263,7 +263,6 @@ FfiNotStatic/analyzerCode: Fail FfiStructAnnotation/analyzerCode: Fail FfiTypeInvalid/analyzerCode: Fail FfiTypeMismatch/analyzerCode: Fail -FfiTypeUnsized/analyzerCode: Fail FfiDartTypeMismatch/analyzerCode: Fail FfiExtendsOrImplementsSealedClass/analyzerCode: Fail FfiStructGeneric/analyzerCode: Fail diff --git a/pkg/front_end/messages.yaml b/pkg/front_end/messages.yaml index eecec32c9c03..290619ad0b7d 100644 --- a/pkg/front_end/messages.yaml +++ b/pkg/front_end/messages.yaml @@ -3475,11 +3475,6 @@ FfiTypeInvalid: template: "Expected type '#type' to be a valid and instantiated subtype of 'NativeType'." external: test/ffi_test.dart -FfiTypeUnsized: - # Used by dart:ffi - template: "Method '#name' cannot be called on something of type '#type' as this type is unsized." - external: test/ffi_test.dart - FfiFieldAnnotation: # Used by dart:ffi template: "Field '#name' requires exactly one annotation to declare its native type, which cannot be Void. dart:ffi Structs cannot have regular Dart fields." diff --git a/pkg/vm/lib/transformations/ffi.dart b/pkg/vm/lib/transformations/ffi.dart index 27200900a930..e807469fd1ac 100644 --- a/pkg/vm/lib/transformations/ffi.dart +++ b/pkg/vm/lib/transformations/ffi.dart @@ -191,8 +191,6 @@ class FfiTransformer extends Transformer { final Class pointerClass; final Class structClass; final Procedure castMethod; - final Procedure loadMethod; - final Procedure storeMethod; final Procedure offsetByMethod; final Procedure elementAtMethod; final Procedure asFunctionMethod; @@ -227,8 +225,6 @@ class FfiTransformer extends Transformer { pointerClass = index.getClass('dart:ffi', 'Pointer'), structClass = index.getClass('dart:ffi', 'Struct'), castMethod = index.getMember('dart:ffi', 'Pointer', 'cast'), - loadMethod = index.getMember('dart:ffi', 'Pointer', 'load'), - storeMethod = index.getMember('dart:ffi', 'Pointer', 'store'), offsetByMethod = index.getMember('dart:ffi', 'Pointer', '_offsetBy'), elementAtMethod = index.getMember('dart:ffi', 'Pointer', 'elementAt'), addressOfField = index.getMember('dart:ffi', 'Struct', '_addressOf'), diff --git a/pkg/vm/lib/transformations/ffi_definitions.dart b/pkg/vm/lib/transformations/ffi_definitions.dart index cf69f9bfadab..d48f9fcadd70 100644 --- a/pkg/vm/lib/transformations/ffi_definitions.dart +++ b/pkg/vm/lib/transformations/ffi_definitions.dart @@ -298,6 +298,14 @@ class _FfiDefinitionTransformer extends FfiTransformer { pointer = MethodInvocation(pointer, offsetByMethod.name, Arguments([_runtimeBranchOnLayout(offsets)]), offsetByMethod); } + + final Class nativeClass = (nativeType as InterfaceType).classNode; + final NativeType nt = getType(nativeClass); + final typeArguments = [ + if (nt == NativeType.kPointer && pointerType is InterfaceType) + pointerType.typeArguments[0] + ]; + final Procedure pointerGetter = Procedure( pointerName, ProcedureKind.Getter, @@ -307,20 +315,24 @@ class _FfiDefinitionTransformer extends FfiTransformer { returnType: pointerType)); // Sample output: - // double get x => _xPtr.load(); + // double get x => _xPtr.value; + final loadMethod = + optimizedTypes.contains(nt) ? loadMethods[nt] : loadStructMethod; final Procedure getter = Procedure( field.name, ProcedureKind.Getter, FunctionNode( - ReturnStatement(MethodInvocation( - PropertyGet(ThisExpression(), pointerName, pointerGetter), - loadMethod.name, - Arguments([], types: [field.type]), - loadMethod)), + ReturnStatement(StaticInvocation( + loadMethod, + Arguments([ + PropertyGet(ThisExpression(), pointerName, pointerGetter), + ConstantExpression(IntConstant(0)) + ], types: typeArguments))), returnType: field.type)); // Sample output: - // set x(double v) => _xPtr.store(v); + // set x(double v) { _xPtr.value = v; }; + final storeMethod = storeMethods[nt]; Procedure setter = null; if (!field.isFinal) { final VariableDeclaration argument = @@ -329,11 +341,13 @@ class _FfiDefinitionTransformer extends FfiTransformer { field.name, ProcedureKind.Setter, FunctionNode( - ReturnStatement(MethodInvocation( - PropertyGet(ThisExpression(), pointerName, pointerGetter), - storeMethod.name, - Arguments([VariableGet(argument)]), - storeMethod)), + ReturnStatement(StaticInvocation( + storeMethod, + Arguments([ + PropertyGet(ThisExpression(), pointerName, pointerGetter), + ConstantExpression(IntConstant(0)), + VariableGet(argument) + ], types: typeArguments))), returnType: VoidType(), positionalParameters: [argument])); } diff --git a/pkg/vm/lib/transformations/ffi_use_sites.dart b/pkg/vm/lib/transformations/ffi_use_sites.dart index fd7cf2e02e94..3cb0dfcbd1f6 100644 --- a/pkg/vm/lib/transformations/ffi_use_sites.dart +++ b/pkg/vm/lib/transformations/ffi_use_sites.dart @@ -14,8 +14,7 @@ import 'package:front_end/src/api_unstable/vm.dart' templateFfiExtendsOrImplementsSealedClass, templateFfiNotStatic, templateFfiTypeInvalid, - templateFfiTypeMismatch, - templateFfiTypeUnsized; + templateFfiTypeMismatch; import 'package:kernel/ast.dart'; import 'package:kernel/class_hierarchy.dart' show ClassHierarchy; @@ -25,13 +24,7 @@ import 'package:kernel/target/targets.dart' show DiagnosticReporter; import 'package:kernel/type_environment.dart'; import 'ffi.dart' - show - ReplacedMembers, - NativeType, - kNativeTypeIntStart, - kNativeTypeIntEnd, - FfiTransformer, - optimizedTypes; + show ReplacedMembers, NativeType, FfiTransformer, optimizedTypes; /// Checks and replaces calls to dart:ffi struct fields and methods. void transformLibraries( @@ -316,53 +309,6 @@ class _FfiUseSiteTransformer extends FfiTransformer { (nativeType as InterfaceType).typeArguments[0]; return StaticInvocation(asFunctionInternal, Arguments([node.receiver], types: [dartType, nativeSignature])); - } else if (target == loadMethod) { - final DartType dartType = node.arguments.types[0]; - final DartType pointerType = node.receiver.getStaticType(env); - final DartType nativeType = _pointerTypeGetTypeArg(pointerType); - - _ensureNativeTypeValid(pointerType, node); - _ensureNativeTypeValid(nativeType, node, allowStructs: true); - _ensureNativeTypeSized(nativeType, node, target.name); - _ensureNativeTypeToDartType(nativeType, dartType, node, - allowStructs: true); - - // TODO(37773): When moving to extension methods we can get rid of - // this rewiring. - final Class nativeClass = (nativeType as InterfaceType).classNode; - final NativeType nt = getType(nativeClass); - final typeArguments = [ - if (nt == NativeType.kPointer) _pointerTypeGetTypeArg(nativeType) - ]; - return StaticInvocation( - optimizedTypes.contains(nt) ? loadMethods[nt] : loadStructMethod, - Arguments([node.receiver, ConstantExpression(IntConstant(0))], - types: typeArguments)); - } else if (target == storeMethod) { - final Expression storeValue = node.arguments.positional.single; - final DartType dartType = storeValue.getStaticType(env); - final DartType pointerType = node.receiver.getStaticType(env); - final DartType nativeType = _pointerTypeGetTypeArg(pointerType); - - // TODO(36730): Allow storing an entire struct to memory. - // TODO(36780): Emit a better error message for the struct case. - _ensureNativeTypeValid(pointerType, node); - _ensureNativeTypeValid(nativeType, node); - _ensureNativeTypeSized(nativeType, node, target.name); - _ensureNativeTypeToDartType(nativeType, dartType, node); - - // TODO(37773): When moving to extension methods we can get rid of - // this rewiring. - final Class nativeClass = (nativeType as InterfaceType).classNode; - final NativeType nt = getType(nativeClass); - final typeArguments = [ - if (nt == NativeType.kPointer) _pointerTypeGetTypeArg(nativeType) - ]; - return StaticInvocation( - storeMethods[nt], - Arguments( - [node.receiver, ConstantExpression(IntConstant(0)), storeValue], - types: typeArguments)); } else if (target == elementAtMethod) { // TODO(37773): When moving to extension methods we can get rid of // this rewiring. @@ -433,50 +379,6 @@ class _FfiUseSiteTransformer extends FfiTransformer { return convertNativeTypeToDartType(nativeType, allowStructs) != null; } - void _ensureNativeTypeSized( - DartType nativeType, Expression node, Name targetName) { - if (!_nativeTypeSized(nativeType)) { - diagnosticReporter.report( - templateFfiTypeUnsized.withArguments(targetName.name, nativeType), - node.fileOffset, - 1, - node.location.file); - throw _FfiStaticTypeError(); - } - } - - /// Unsized NativeTypes do not support [sizeOf] because their size is unknown. - /// Consequently, [allocate], [Pointer.load], [Pointer.store], and - /// [Pointer.elementAt] are not available. - bool _nativeTypeSized(DartType nativeType) { - if (nativeType is! InterfaceType) { - return false; - } - final Class nativeClass = (nativeType as InterfaceType).classNode; - if (env.isSubtypeOf(InterfaceType(nativeClass), InterfaceType(pointerClass), - SubtypeCheckMode.ignoringNullabilities)) { - return true; - } - if (hierarchy.isSubclassOf(nativeClass, structClass)) { - return true; - } - final NativeType nativeType_ = getType(nativeClass); - if (nativeType_ == null) { - return false; - } - if (kNativeTypeIntStart.index <= nativeType_.index && - nativeType_.index <= kNativeTypeIntEnd.index) { - return true; - } - if (nativeType_ == NativeType.kFloat || nativeType_ == NativeType.kDouble) { - return true; - } - if (nativeType_ == NativeType.kPointer) { - return true; - } - return false; - } - void _ensureIsStaticFunction(Expression node) { if ((node is StaticGet && node.target is Procedure) || (node is ConstantExpression && node.constant is TearOffConstant)) { diff --git a/runtime/lib/ffi.cc b/runtime/lib/ffi.cc index d67ffe07f823..eb1ee9476ded 100644 --- a/runtime/lib/ffi.cc +++ b/runtime/lib/ffi.cc @@ -88,40 +88,12 @@ static size_t SizeOf(const AbstractType& type) { // The remainder of this file implements the dart:ffi native methods. -DEFINE_NATIVE_ENTRY(Ffi_allocate, 1, 1) { - GET_NATIVE_TYPE_ARGUMENT(type_arg, arguments->NativeTypeArgAt(0)); - - CheckSized(type_arg); - size_t element_size = SizeOf(type_arg); - - GET_NON_NULL_NATIVE_ARGUMENT(Integer, argCount, arguments->NativeArgAt(0)); - int64_t count = argCount.AsInt64Value(); - size_t size = element_size * count; // Truncates overflow. - size_t memory = reinterpret_cast(malloc(size)); - if (memory == 0) { - const String& error = String::Handle(String::NewFormatted( - "allocating (%" Pd ") bytes of memory failed", size)); - Exceptions::ThrowArgumentError(error); - } - - RawPointer* result = Pointer::New(type_arg, memory); - return result; -} - DEFINE_NATIVE_ENTRY(Ffi_fromAddress, 1, 1) { GET_NATIVE_TYPE_ARGUMENT(type_arg, arguments->NativeTypeArgAt(0)); GET_NON_NULL_NATIVE_ARGUMENT(Integer, arg_ptr, arguments->NativeArgAt(0)); return Pointer::New(type_arg, arg_ptr.AsInt64Value()); } -DEFINE_NATIVE_ENTRY(Ffi_free, 0, 1) { - GET_NON_NULL_NATIVE_ARGUMENT(Pointer, pointer, arguments->NativeArgAt(0)); - - free(reinterpret_cast(pointer.NativeAddress())); - - return Object::null(); -} - DEFINE_NATIVE_ENTRY(Ffi_address, 0, 1) { GET_NON_NULL_NATIVE_ARGUMENT(Pointer, pointer, arguments->NativeArgAt(0)); return Integer::New(pointer.NativeAddress()); diff --git a/runtime/vm/bootstrap_natives.h b/runtime/vm/bootstrap_natives.h index 1d6f3c5f90f1..7fceaf7cedbe 100644 --- a/runtime/vm/bootstrap_natives.h +++ b/runtime/vm/bootstrap_natives.h @@ -370,8 +370,6 @@ namespace dart { V(VMService_RequestAssets, 0) \ V(VMService_DecodeAssets, 1) \ V(VMService_spawnUriNotify, 2) \ - V(Ffi_allocate, 1) \ - V(Ffi_free, 1) \ V(Ffi_loadInt8, 2) \ V(Ffi_loadInt16, 2) \ V(Ffi_loadInt32, 2) \ diff --git a/sdk/lib/_internal/vm/lib/ffi_patch.dart b/sdk/lib/_internal/vm/lib/ffi_patch.dart index 1407b6ba0521..69e6b207d73b 100644 --- a/sdk/lib/_internal/vm/lib/ffi_patch.dart +++ b/sdk/lib/_internal/vm/lib/ffi_patch.dart @@ -37,8 +37,6 @@ int sizeOf() { int _sizeOf() native "Ffi_sizeOf"; -Pointer _allocate(int count) native "Ffi_allocate"; - // Implemented in the method recognizer, bytecode interpreter uses runtime. Pointer _fromAddress(int ptr) native "Ffi_fromAddress"; @@ -73,9 +71,6 @@ Pointer _pointerFromFunction(Object function) @patch @pragma("vm:entry-point") class Pointer { - @patch - factory Pointer.allocate({int count: 1}) => _allocate(count); - @patch factory Pointer.fromAddress(int ptr) => _fromAddress(ptr); @@ -92,18 +87,6 @@ class Pointer { "Pointer.fromFunction cannot be called dynamically."); } - // TODO(sjindel): When NNBD is available, we should change `value` to be - // non-null. - // For statically known types, this is rewired. - @patch - void store(Object value) => - throw UnsupportedError("Pointer.store cannot be called dynamically."); - - // For statically known types, this is rewired. - @patch - R load() => - throw UnsupportedError("Pointer.load cannot be called dynamically."); - // Implemented in the method recognizer, bytecode interpreter uses runtime. @patch int get address native "Ffi_address"; @@ -125,13 +108,6 @@ class Pointer { R asFunction() { throw UnsupportedError("Pointer.asFunction cannot be called dynamically."); } - - @patch - void free() native "Ffi_free"; - - @patch - TypedData asExternalTypedData({int count: 1}) => - _asExternalTypedData(this, count); } /// Returns an integer encoding the ABI used for size and alignment diff --git a/sdk/lib/ffi/ffi.dart b/sdk/lib/ffi/ffi.dart index 35094b82efdf..422788f08d06 100644 --- a/sdk/lib/ffi/ffi.dart +++ b/sdk/lib/ffi/ffi.dart @@ -33,18 +33,6 @@ final Pointer nullptr = Pointer.fromAddress(0); /// Represents a pointer into the native C memory. Cannot be extended. @pragma("vm:entry-point") class Pointer extends NativeType { - /// Allocate [count] elements of type [T] on the native heap via malloc() and - /// return a pointer to the newly allocated memory. - /// - /// Note that the memory is uninitialized. - /// - /// On Windows, this memory may only be freed via [Pointer.free]. - /// - /// This method is deprecated. Please resolve allocation methods via - /// [DynamicLibrary] instead, or use "package:ffi". - @deprecated - external factory Pointer.allocate({int count: 1}); - /// Construction from raw integer. external factory Pointer.fromAddress(int ptr); @@ -68,31 +56,6 @@ class Pointer extends NativeType { @DartRepresentationOf("T") Function f, [Object exceptionalReturn]); - /// Store a Dart value into this location. - /// - /// The `value` is automatically marshalled into its native representation. - /// Note that ints which do not fit in [T] are truncated and sign extended, - /// and doubles stored into Pointer<[Float]> lose precision. - /// - /// Note that `this.address` needs to be aligned to the size of `T`. - /// - /// Deprecated, use `pointer[...] =` and `pointer.value =` instead, or use - /// "package:ffi". - @deprecated - external void store(@DartRepresentationOf("T") Object value); - - /// Load a Dart value from this location. - /// - /// The value is automatically unmarshalled from its native representation. - /// Loading a [Struct] reference returns a reference backed by native memory - /// (the same pointer as it's loaded from). - /// - /// Note that `this.address` needs to be aligned to the size of `T`. - /// - /// Deprecated, use `pointer[...]` and `pointer.value` instead. - @deprecated - external R load<@DartRepresentationOf("T") R>(); - /// Access to the raw pointer value. /// On 32-bit systems, the upper 32-bits of the result are 0. external int get address; @@ -110,44 +73,6 @@ class Pointer extends NativeType { /// invocations -- where the type of the receiver is [dynamic]. external R asFunction<@DartRepresentationOf("T") R extends Function>(); - /// Free memory on the C heap pointed to by this pointer with free(). - /// - /// On Windows, this method may only be used with a pointer allocated via - /// [Pointer.allocate]. - /// - /// This method is deprecated. Please resolve allocation methods via - /// [DynamicLibrary] instead. - @deprecated - external void free(); - - /// Creates an *external* typed data array backed by this pointer. - /// - /// The typed data array returned is only valid for as long as the backing - /// [Pointer]. Accessing any element of the type data array after this - /// [Pointer] has been [Pointer.free()]d will cause undefined behavior. - /// - /// Since [Pointer]s do not know their length, the size of the typed data is - /// controlled by `count`, in units of the size of the native type for this - /// [Pointer] (similarly to [Pointer.allocate]). - /// - /// The kind of TypedData produced depends on the native type: - /// - /// Pointer -> Int8List - /// Pointer -> Uint8List - /// etc. up to Int64/Uint64 - /// Pointer -> Int32List/Int64List depending on platform word size - /// Pointer -> Float32List - /// Pointer -> Float64List - /// - /// Creation of a [Uint8ClampedList] is not supported. Creation of a typed - /// data from a [Pointer] to any other native type is not supported. - /// - /// The pointer must be aligned to a multiple of the native type's size. - /// - /// Deprecated, replace with `asTypedList()`. - @deprecated - external TypedData asExternalTypedData({int count: 1}); - /// Equality for Pointers only depends on their address. bool operator ==(other) { if (other == null) return false; diff --git a/sdk_nnbd/lib/_internal/vm/lib/ffi_patch.dart b/sdk_nnbd/lib/_internal/vm/lib/ffi_patch.dart index 43c209885ab1..55ba5882f6f9 100644 --- a/sdk_nnbd/lib/_internal/vm/lib/ffi_patch.dart +++ b/sdk_nnbd/lib/_internal/vm/lib/ffi_patch.dart @@ -39,8 +39,6 @@ int sizeOf() { int _sizeOf() native "Ffi_sizeOf"; -Pointer _allocate(int count) native "Ffi_allocate"; - // Implemented in the method recognizer, bytecode interpreter uses runtime. Pointer _fromAddress(int ptr) native "Ffi_fromAddress"; @@ -75,9 +73,6 @@ Pointer _pointerFromFunction(Object function) @patch @pragma("vm:entry-point") class Pointer { - @patch - factory Pointer.allocate({int count: 1}) => _allocate(count); - @patch factory Pointer.fromAddress(int ptr) => _fromAddress(ptr); @@ -94,18 +89,6 @@ class Pointer { "Pointer.fromFunction cannot be called dynamically."); } - // TODO(sjindel): When NNBD is available, we should change `value` to be - // non-null. - // For statically known types, this is rewired. - @patch - void store(Object value) => - throw UnsupportedError("Pointer.store cannot be called dynamically."); - - // For statically known types, this is rewired. - @patch - R load() => - throw UnsupportedError("Pointer.load cannot be called dynamically."); - // Implemented in the method recognizer, bytecode interpreter uses runtime. @patch int get address native "Ffi_address"; @@ -127,13 +110,6 @@ class Pointer { R asFunction() { throw UnsupportedError("Pointer.asFunction cannot be called dynamically."); } - - @patch - void free() native "Ffi_free"; - - @patch - TypedData asExternalTypedData({int count: 1}) => - _asExternalTypedData(this, count); } /// Returns an integer encoding the ABI used for size and alignment diff --git a/sdk_nnbd/lib/ffi/ffi.dart b/sdk_nnbd/lib/ffi/ffi.dart index f0491952d68c..c00226f0477e 100644 --- a/sdk_nnbd/lib/ffi/ffi.dart +++ b/sdk_nnbd/lib/ffi/ffi.dart @@ -35,18 +35,6 @@ final Pointer nullptr = Pointer.fromAddress(0); /// Represents a pointer into the native C memory. Cannot be extended. @pragma("vm:entry-point") class Pointer extends NativeType { - /// Allocate [count] elements of type [T] on the native heap via malloc() and - /// return a pointer to the newly allocated memory. - /// - /// Note that the memory is uninitialized. - /// - /// On Windows, this memory may only be freed via [Pointer.free]. - /// - /// This method is deprecated. Please resolve allocation methods via - /// [DynamicLibrary] instead, or use "package:ffi". - @deprecated - external factory Pointer.allocate({int count: 1}); - /// Construction from raw integer. external factory Pointer.fromAddress(int ptr); @@ -70,31 +58,6 @@ class Pointer extends NativeType { @DartRepresentationOf("T") Function f, [Object exceptionalReturn]); - /// Store a Dart value into this location. - /// - /// The `value` is automatically marshalled into its native representation. - /// Note that ints which do not fit in [T] are truncated and sign extended, - /// and doubles stored into Pointer<[Float]> lose precision. - /// - /// Note that `this.address` needs to be aligned to the size of `T`. - /// - /// Deprecated, use `pointer[...] =` and `pointer.value =` instead, or use - /// "package:ffi". - @deprecated - external void store(@DartRepresentationOf("T") Object value); - - /// Load a Dart value from this location. - /// - /// The value is automatically unmarshalled from its native representation. - /// Loading a [Struct] reference returns a reference backed by native memory - /// (the same pointer as it's loaded from). - /// - /// Note that `this.address` needs to be aligned to the size of `T`. - /// - /// Deprecated, use `pointer[...]` and `pointer.value` instead. - @deprecated - external R load<@DartRepresentationOf("T") R>(); - /// Access to the raw pointer value. /// On 32-bit systems, the upper 32-bits of the result are 0. external int get address; @@ -112,44 +75,6 @@ class Pointer extends NativeType { /// invocations -- where the type of the receiver is [dynamic]. external R asFunction<@DartRepresentationOf("T") R extends Function>(); - /// Free memory on the C heap pointed to by this pointer with free(). - /// - /// On Windows, this method may only be used with a pointer allocated via - /// [Pointer.allocate]. - /// - /// This method is deprecated. Please resolve allocation methods via - /// [DynamicLibrary] instead. - @deprecated - external void free(); - - /// Creates an *external* typed data array backed by this pointer. - /// - /// The typed data array returned is only valid for as long as the backing - /// [Pointer]. Accessing any element of the type data array after this - /// [Pointer] has been [Pointer.free()]d will cause undefined behavior. - /// - /// Since [Pointer]s do not know their length, the size of the typed data is - /// controlled by `count`, in units of the size of the native type for this - /// [Pointer] (similarly to [Pointer.allocate]). - /// - /// The kind of TypedData produced depends on the native type: - /// - /// Pointer -> Int8List - /// Pointer -> Uint8List - /// etc. up to Int64/Uint64 - /// Pointer -> Int32List/Int64List depending on platform word size - /// Pointer -> Float32List - /// Pointer -> Float64List - /// - /// Creation of a [Uint8ClampedList] is not supported. Creation of a typed - /// data from a [Pointer] to any other native type is not supported. - /// - /// The pointer must be aligned to a multiple of the native type's size. - /// - /// Deprecated, replace with `asTypedList()`. - @deprecated - external TypedData asExternalTypedData({int count: 1}); - /// Equality for Pointers only depends on their address. bool operator ==(other) { if (other == null) return false;