Skip to content

Commit 82ff296

Browse files
committed
Fix #1268
1 parent deda4d1 commit 82ff296

File tree

10 files changed

+96
-71
lines changed

10 files changed

+96
-71
lines changed

pkgs/ffigen/CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
## 18.1.1-wip
1+
## 18.2.0-wip
22

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

59
## 18.1.0
610

711
- Fix a clang warning in ObjC protocol generated bindings.
812

913
## 18.0.0
1014

15+
- Use package:objective_c 7.0.0.
1116
- Add variable substitutions that can be used in the `headers.entry-points` to
1217
locate Apple APIs: `$XCODE`, `$IOS_SDK`, and `$MACOS_SDK`.
1318
- Add an empty constructor to all ObjC interfaces that have a `new` method,

pkgs/ffigen/lib/src/header_parser/type_extractor/extractor.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ _CreateTypeFromCursorResult _createTypeFromCursor(clang_types.CXType cxtype,
252252
return _CreateTypeFromCursorResult(enumClass);
253253
}
254254
case clang_types.CXTypeKind.CXType_ObjCInterface:
255+
case clang_types.CXTypeKind.CXType_ObjCObject:
255256
return _CreateTypeFromCursorResult(parseObjCInterfaceDeclaration(cursor));
256257
default:
257258
return _CreateTypeFromCursorResult(

pkgs/ffigen/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ dev_dependencies:
4141
dart_flutter_team_lints: ^2.0.0
4242
json_schema: ^5.1.1
4343
leak_tracker: ^10.0.7
44-
objective_c: ^7.0.0
44+
objective_c: ^7.2.0
4545
test: ^1.16.2
4646

4747
dependency_overrides:

pkgs/ffigen/test/native_objc_test/property_config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ objc-interfaces:
88
- PropertyInterface
99
headers:
1010
entry-points:
11-
- 'property_test.m'
11+
- 'property_test.h'
1212
preamble: |
1313
// ignore_for_file: camel_case_types, non_constant_identifier_names, unnecessary_non_null_assertion, unused_element, unused_field

pkgs/ffigen/test/native_objc_test/property_test.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'dart:ffi';
99
import 'dart:io';
1010

1111
import 'package:ffi/ffi.dart';
12+
import 'package:objective_c/objective_c.dart';
1213
import 'package:test/test.dart';
1314
import '../test_utils.dart';
1415
import 'property_bindings.dart';
@@ -50,7 +51,8 @@ void main() {
5051
});
5152
});
5253

53-
group('Regress #608', () {
54+
group('Regress #209', () {
55+
// Test for https://github.com/dart-lang/native/issues/209
5456
test('Structs', () {
5557
final inputPtr = calloc<Vec4>();
5658
final input = inputPtr.ref;
@@ -85,5 +87,12 @@ void main() {
8587
expect(testInstance.instStaticSameName, 123);
8688
expect(PropertyInterface.getInstStaticSameName$1(), 456);
8789
});
90+
91+
test('Regress #1268', () {
92+
// Test for https://github.com/dart-lang/native/issues/1268
93+
NSArray array = PropertyInterface.getRegressGH1268();
94+
expect(array.length, 1);
95+
expect(NSString.castFrom(array[0]).toDartString(), "hello");
96+
});
8897
});
8998
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#import <Foundation/NSObject.h>
2+
3+
@class UndefinedTemplate<ObjectType>;
4+
@class NSString;
5+
@class NSArray<ObjectType>;
6+
7+
typedef struct {
8+
double x;
9+
double y;
10+
double z;
11+
double w;
12+
} Vec4;
13+
14+
@interface PropertyInterface : NSObject {
15+
}
16+
17+
@property (readonly) int32_t readOnlyProperty;
18+
@property int32_t readWriteProperty;
19+
@property (class, readonly, copy) UndefinedTemplate<NSString *> *regressGH436;
20+
@property (class, readonly) int32_t classReadOnlyProperty;
21+
@property (class) int32_t classReadWriteProperty;
22+
@property float floatProperty;
23+
@property double doubleProperty;
24+
@property Vec4 structProperty;
25+
@property (class, readonly, copy) NSArray<NSString *> *regressGH1268;
26+
27+
// An instance property and a static property with the same name.
28+
// https://github.com/dart-lang/native/issues/1136
29+
@property(readonly) int32_t instStaticSameName;
30+
@property(class, readonly) int32_t instStaticSameName;
31+
32+
@end
Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,7 @@
1-
#import <Foundation/NSObject.h>
1+
#import "property_test.h"
22

3-
@class UndefinedTemplate<ObjectType>;
4-
5-
typedef struct {
6-
double x;
7-
double y;
8-
double z;
9-
double w;
10-
} Vec4;
11-
12-
@interface PropertyInterface : NSObject {
13-
}
14-
15-
@property (readonly) int32_t readOnlyProperty;
16-
@property int32_t readWriteProperty;
17-
@property (class, readonly, copy) UndefinedTemplate<NSString *> *regressGH436;
18-
@property (class, readonly) int32_t classReadOnlyProperty;
19-
@property (class) int32_t classReadWriteProperty;
20-
@property float floatProperty;
21-
@property double doubleProperty;
22-
@property Vec4 structProperty;
23-
24-
// An instance property and a static property with the same name.
25-
// https://github.com/dart-lang/native/issues/1136
26-
@property(readonly) int32_t instStaticSameName;
27-
@property(class, readonly) int32_t instStaticSameName;
28-
29-
@end
3+
#import <Foundation/NSString.h>
4+
#import <Foundation/NSArray.h>
305

316
@implementation PropertyInterface
327

@@ -56,4 +31,8 @@ + (int32_t)instStaticSameName {
5631
return 456;
5732
}
5833

34+
+ (NSArray<NSString *> *)regressGH1268 {
35+
return @[@"hello"];
36+
}
37+
5938
@end

pkgs/objective_c/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## 7.2.0-wip
22

3+
- Use ffigen 18.2.0
34
- NSArray is now a Dart Iterable and NSMutableArray is now a Dart List.
45

56
## 7.1.0

0 commit comments

Comments
 (0)