Skip to content

[ffigen] Fix #1268 #2247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pkgs/ffigen/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
## 18.1.1-wip
## 18.2.0-wip

- Use package:objective_c 7.2.0.
- Make it easier for a downstream clone to change behavior of certain utils.
- Fix [a bug](https://github.com/dart-lang/native/issues/1268) where types could
occasionally show up as a generic ObjCObjectBase, when they were supposed to
be codegenned as a more specific interface types.

## 18.1.0

- Fix a clang warning in ObjC protocol generated bindings.

## 18.0.0

- Use package:objective_c 7.0.0.
- Add variable substitutions that can be used in the `headers.entry-points` to
locate Apple APIs: `$XCODE`, `$IOS_SDK`, and `$MACOS_SDK`.
- Add an empty constructor to all ObjC interfaces that have a `new` method,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ _CreateTypeFromCursorResult _createTypeFromCursor(clang_types.CXType cxtype,
return _CreateTypeFromCursorResult(enumClass);
}
case clang_types.CXTypeKind.CXType_ObjCInterface:
case clang_types.CXTypeKind.CXType_ObjCObject:
return _CreateTypeFromCursorResult(parseObjCInterfaceDeclaration(cursor));
default:
return _CreateTypeFromCursorResult(
Expand Down
2 changes: 1 addition & 1 deletion pkgs/ffigen/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ dev_dependencies:
dart_flutter_team_lints: ^2.0.0
json_schema: ^5.1.1
leak_tracker: ^10.0.7
objective_c: ^7.0.0
objective_c: ^7.2.0
test: ^1.16.2

dependency_overrides:
Expand Down
2 changes: 1 addition & 1 deletion pkgs/ffigen/test/native_objc_test/property_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ objc-interfaces:
- PropertyInterface
headers:
entry-points:
- 'property_test.m'
- 'property_test.h'
preamble: |
// ignore_for_file: camel_case_types, non_constant_identifier_names, unnecessary_non_null_assertion, unused_element, unused_field
11 changes: 10 additions & 1 deletion pkgs/ffigen/test/native_objc_test/property_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'dart:ffi';
import 'dart:io';

import 'package:ffi/ffi.dart';
import 'package:objective_c/objective_c.dart';
import 'package:test/test.dart';
import '../test_utils.dart';
import 'property_bindings.dart';
Expand Down Expand Up @@ -50,7 +51,8 @@ void main() {
});
});

group('Regress #608', () {
group('Regress #209', () {
// Test for https://github.com/dart-lang/native/issues/209
test('Structs', () {
final inputPtr = calloc<Vec4>();
final input = inputPtr.ref;
Expand Down Expand Up @@ -85,5 +87,12 @@ void main() {
expect(testInstance.instStaticSameName, 123);
expect(PropertyInterface.getInstStaticSameName$1(), 456);
});

test('Regress #1268', () {
// Test for https://github.com/dart-lang/native/issues/1268
NSArray array = PropertyInterface.getRegressGH1268();
expect(array.length, 1);
expect(NSString.castFrom(array[0]).toDartString(), "hello");
});
});
}
32 changes: 32 additions & 0 deletions pkgs/ffigen/test/native_objc_test/property_test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#import <Foundation/NSObject.h>

@class UndefinedTemplate<ObjectType>;
@class NSString;
@class NSArray<ObjectType>;

typedef struct {
double x;
double y;
double z;
double w;
} Vec4;

@interface PropertyInterface : NSObject {
}

@property (readonly) int32_t readOnlyProperty;
@property int32_t readWriteProperty;
@property (class, readonly, copy) UndefinedTemplate<NSString *> *regressGH436;
@property (class, readonly) int32_t classReadOnlyProperty;
@property (class) int32_t classReadWriteProperty;
@property float floatProperty;
@property double doubleProperty;
@property Vec4 structProperty;
@property (class, readonly, copy) NSArray<NSString *> *regressGH1268;

// An instance property and a static property with the same name.
// https://github.com/dart-lang/native/issues/1136
@property(readonly) int32_t instStaticSameName;
@property(class, readonly) int32_t instStaticSameName;

@end
35 changes: 7 additions & 28 deletions pkgs/ffigen/test/native_objc_test/property_test.m
Original file line number Diff line number Diff line change
@@ -1,32 +1,7 @@
#import <Foundation/NSObject.h>
#import "property_test.h"

@class UndefinedTemplate<ObjectType>;

typedef struct {
double x;
double y;
double z;
double w;
} Vec4;

@interface PropertyInterface : NSObject {
}

@property (readonly) int32_t readOnlyProperty;
@property int32_t readWriteProperty;
@property (class, readonly, copy) UndefinedTemplate<NSString *> *regressGH436;
@property (class, readonly) int32_t classReadOnlyProperty;
@property (class) int32_t classReadWriteProperty;
@property float floatProperty;
@property double doubleProperty;
@property Vec4 structProperty;

// An instance property and a static property with the same name.
// https://github.com/dart-lang/native/issues/1136
@property(readonly) int32_t instStaticSameName;
@property(class, readonly) int32_t instStaticSameName;

@end
#import <Foundation/NSString.h>
#import <Foundation/NSArray.h>

@implementation PropertyInterface

Expand Down Expand Up @@ -56,4 +31,8 @@ + (int32_t)instStaticSameName {
return 456;
}

+ (NSArray<NSString *> *)regressGH1268 {
return @[@"hello"];
}

@end
1 change: 1 addition & 0 deletions pkgs/objective_c/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 7.2.0-wip

- Use ffigen 18.2.0
- NSArray is now a Dart Iterable and NSMutableArray is now a Dart List.

## 7.1.0
Expand Down
Loading
Loading