// Copyright (c) 2019, 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. import "dart:_internal" show patch; @patch Pointer allocate({int count: 1}) native "Ffi_allocate"; @patch T fromAddress(int ptr) native "Ffi_fromAddress"; @patch int sizeOf() native "Ffi_sizeOf"; @patch Pointer> fromFunction( @DartRepresentationOf("T") Function f) native "Ffi_fromFunction"; @patch @pragma("vm:entry-point") class Pointer { @patch void store(Object value) native "Ffi_store"; @patch R load() native "Ffi_load"; @patch int get address native "Ffi_address"; // Note this could also be implmented without an extra native as offsetBy // (elementSize()*index). This would be 2 native calls rather than one. What // would be better? @patch Pointer elementAt(int index) native "Ffi_elementAt"; // Note this could also be implmented without an extra native as // fromAddress(address). This would be 2 native calls rather than one. // What would be better? @patch Pointer offsetBy(int offsetInBytes) native "Ffi_offsetBy"; // Note this could also be implemented without an extra native as // fromAddress(address). This would be 2 native calls rather than one. // What would be better? @patch U cast() native "Ffi_cast"; @patch R asFunction() native "Ffi_asFunction"; @patch void free() native "Ffi_free"; } // This method gets called when an exception bubbles up to the native -> Dart // boundary from an FFI native callback. Since native code does not have any // concept of exceptions, the exception cannot be propagated any further. // Instead, print a warning with the exception and return 0/0.0 from the // callback. // // TODO(36856): Iron out the story behind exceptions. @pragma("vm:entry-point") void _handleExposedException(dynamic exception, dynamic stackTrace) { print( "==================== UNHANDLED EXCEPTION FROM FFI CALLBACK ===================="); print( """ ** Native callbacks should not throw exceptions because they cannot be propagated into native code. **"""); print("EXCEPTION: $exception"); print(stackTrace); }