dart-lang / native

Dart packages related to FFI and native assets bundling.
BSD 3-Clause "New" or "Revised" License
151 stars 42 forks source link

Generation of CGRect property is changed to Pointer<CGRect> after upgrade ffigen to 10.0.0 #1003

Closed yanshouwang closed 7 months ago

yanshouwang commented 7 months ago

When use ffigen 9.0.0 to generate CoreImage bindings, the bounds property of CIFeature is generated like this:

class CIFeature extends NSObject {
  ...
  CGRect get bounds {
    return _lib._objc_msgSend_56(_id, _lib._sel_bounds1);
  }
  ...

But after upgrade ffi to 10.0.0 or 11.0.0, the bounds property is changed to a method with a Pointer arguments:


class CIFeature extends NSObject {
  ...
  void getBounds(ffi.Pointer<CGRect> stret) {
    _lib._objc_msgSend_61(stret, _id, _lib._sel_bounds1);
  }
  ...

Is this behavior correct?

Here is my ffigen.yaml file.

# Run with `dart run ffigen --config ffigen.yaml`.
name: CoreImage
description: |
  Bindings for CoreImage.

  Regenerate bindings with `dart run ffigen --config ffigen.yaml`.
language: objc
output: 'lib/src/core_image.dart'
exclude-all-by-default: true
objc-interfaces:
  include:
    - 'CIDetector'
    - 'CIImage'
    - 'CIFeature'
headers:
  entry-points:
    - '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreImage.framework/Headers/CoreImage.h'
preamble: |
  // ignore_for_file: always_specify_types
  // ignore_for_file: camel_case_types
  // ignore_for_file: non_constant_identifier_names
liamappelbe commented 7 months ago

This is working as intended. CGRect is a struct, and you can't reliably return structs by value from ObjC methods on all platforms. The old signature was a bug. See https://github.com/dart-lang/native/issues/449