Skip to content

Commit

Permalink
[ffigen] Update urls after repo merge
Browse files Browse the repository at this point in the history
  • Loading branch information
dcharkes committed Nov 15, 2023
1 parent b90e4e8 commit bfb6f3a
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 56 deletions.
5 changes: 3 additions & 2 deletions pkgs/ffigen/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[![pub package](https://img.shields.io/pub/v/ffigen.svg)](https://pub.dev/packages/ffigen)
[![ffigen](https://github.com/dart-lang/native/actions/workflows/ffigen.yml/badge.svg)](https://github.com/dart-lang/native/actions/workflows/ffigen.yml)
[![Build Status](https://github.com/dart-lang/native/actions/workflows/ffigen.yml/badge.svg)](https://github.com/dart-lang/native/actions/workflows/ffigen.yml)
[![Coverage Status](https://coveralls.io/repos/github/dart-lang/native/badge.svg?branch=main)](https://coveralls.io/github/dart-lang/native?branch=main)
[![pub package](https://img.shields.io/pub/v/ffigen.svg)](https://pub.dev/packages/ffigen)
[![package publisher](https://img.shields.io/pub/publisher/ffigen.svg)](https://pub.dev/packages/ffigen/publisher)

Binding generator for [FFI](https://dart.dev/guides/libraries/c-interop) bindings.

Expand Down
10 changes: 5 additions & 5 deletions pkgs/ffigen/example/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Examples

- [Simple](https://github.com/dart-lang/ffigen/tree/main/example/simple)
- [cJSON](https://github.com/dart-lang/ffigen/tree/main/example/c_json)
- [LibClang](https://github.com/dart-lang/ffigen/tree/main/example/libclang-example)
- [ObjectiveC](https://github.com/dart-lang/ffigen/tree/main/example/objective_c)
- [Swift](https://github.com/dart-lang/ffigen/tree/main/example/swift)
- [Simple](https://github.com/dart-lang/native/tree/main/pkgs/ffigen/example/simple)
- [cJSON](https://github.com/dart-lang/native/tree/main/pkgs/ffigen/example/c_json)
- [LibClang](https://github.com/dart-lang/native/tree/main/pkgs/ffigen/example/libclang-example)
- [ObjectiveC](https://github.com/dart-lang/native/tree/main/pkgs/ffigen/example/objective_c)
- [Swift](https://github.com/dart-lang/native/tree/main/pkgs/ffigen/example/swift)
5 changes: 3 additions & 2 deletions pkgs/ffigen/example/libclang-example/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ output: 'generated_bindings.dart'
# - '/usr/local/opt/llvm'

# Bash style Glob matching is also supported.
# TODO(11): Globs dont work on windows if they begin with '.' or '..'.
# TODO(https://github.com/dart-lang/ffigen/issues/11): Globs dont work on
# windows if they begin with '.' or '..'.
headers:
entry-points:
- ../../third_party/libclang/include/clang-c/Index.h
Expand All @@ -33,7 +34,7 @@ functions:
- 'clang_.*' # Typedefs for Native and Dart type for these functions will be generated.
structs:
include:
- 'CX.*'
- 'CX.*'
enums:
include:
- 'CXTypeKind' # Full names are given higher priority than regexp.
Expand Down
2 changes: 1 addition & 1 deletion pkgs/ffigen/example/swift/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'dart:ffi';
import 'swift_api_bindings.dart';

void main() {
// TODO(#443): Add a test for this.
// TODO(https://github.com/dart-lang/ffigen/issues/443): Add a test for this.
final lib = SwiftLibrary(DynamicLibrary.open('libswiftapi.dylib'));
final object = SwiftClass.new1(lib);
print(object.sayHello());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,13 @@ int _compoundMembersVisitor(clang_types.CXCursor cursor,

final mt = cursor.toCodeGenType();
if (mt is IncompleteArray) {
// TODO(68): Structs with flexible Array Members are not supported.
// TODO(https://github.com/dart-lang/ffigen/issues/68): Structs with
// flexible Array Members are not supported.
parsed.flexibleArrayMember = true;
}
if (clang.clang_getFieldDeclBitWidth(cursor) != -1) {
// TODO(84): Struct with bitfields are not suppoorted.
// TODO(https://github.com/dart-lang/ffigen/issues/84): Struct with
// bitfields are not suppoorted.
parsed.bitFieldMember = true;
}
if (mt is HandleType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ BindingType? parseObjCCategoryDeclaration(clang_types.CXCursor cursor) {
return null;
}

// TODO(#347): Currently any interface with a category bypasses the filters.
// TODO(https://github.com/dart-lang/ffigen/issues/347): Currently any
// interface with a category bypasses the filters.
final itf = itfCursor.type().toCodeGenType();
if (itf is! ObjCInterface) {
_logger.severe(
Expand Down
9 changes: 3 additions & 6 deletions pkgs/ffigen/test/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[![Build Status](https://github.com/dart-lang/ffigen/workflows/Dart%20CI/badge.svg)](https://github.com/dart-lang/ffigen/actions?query=workflow%3A"Dart+CI")
[![Coverage Status](https://coveralls.io/repos/github/dart-lang/ffigen/badge.svg?branch=main)](https://coveralls.io/github/dart-lang/ffigen?branch=main)

# ffigen testing

## Running Tests
Expand All @@ -23,18 +20,18 @@
Some tests verify that the generated Dart FFI bindings match a golden file.

For example, the test
[`test/native_test/native_test.dart`](https://github.com/dart-lang/ffigen/blob/main/test/native_test/native_test.dart)
[`test/native_test/native_test.dart`](https://github.com/dart-lang/native/tree/main/pkgs/ffigen/test/native_test/native_test.dart)
works by:

1. Loading the dynamic library for
[`test/native_test/native_test.c`](https://github.com/dart-lang/ffigen/blob/main/test/native_test/native_test.c)
[`test/native_test/native_test.c`](https://github.com/dart-lang/native/tree/main/pkgs/ffigen/test/native_test/native_test.c)
(which was generated by `dart run test/setup.dart`).

2. Generating binding files for that dynamic library in the
`test/debug_generated` directory.

3. Comparing the golden file (i.e.
[`test/native_test/_expected_native_test_bindings.dart`](https://github.com/dart-lang/ffigen/blob/main/test/native_test/_expected_native_test_bindings.dart))
[`test/native_test/_expected_native_test_bindings.dart`](https://github.com/dart-lang/native/tree/main/pkgs/ffigen/test/native_test/_expected_native_test_bindings.dart))
to the generated file and generating a test failure if they do not match.

4. Using the *golden* bindings to excercise the dynamic library.
Expand Down
65 changes: 32 additions & 33 deletions pkgs/ffigen/test/header_parser_tests/struct_fptr_fields.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,37 @@

typedef int (*ArithmeticOperation)(int a, int b);

struct S
{
// Function pointer field, but no parameters.
int (*func1)(void);
// Function pointer field with parameters.
int (*comparator)(int a, int b);
// Function pointer field with lot of parameters
int (*veryManyArguments)(double a, float b, char *c, int d, long long e);
// Function pointer field with parameters, but no names
int (*argsDontHaveNames)(int, int, int, float, char *);
// Function pointer through typedef
ArithmeticOperation operation;
// Pointer to function pointer
void (**sortPtr)(int *array, int len);
// Function pointer with a function pointer parameter
void (*sortBy)(int *array, int len, int (*evaluator)(int x));
// Function where few parameters are named. This should not
// produce parameters in output.
void (*improperlyDeclaredParams)(int a, int, char);
// Function pointer with 2 function pointer parameters
void (*sortByWithFallback)(int *array,
int (*primaryEvaluator)(int x),
int (*fallbackEvaluator)(int x));
struct S {
// Function pointer field, but no parameters.
int (*func1)(void);
// Function pointer field with parameters.
int (*comparator)(int a, int b);
// Function pointer field with lot of parameters
int (*veryManyArguments)(double a, float b, char *c, int d, long long e);
// Function pointer field with parameters, but no names
int (*argsDontHaveNames)(int, int, int, float, char *);
// Function pointer through typedef
ArithmeticOperation operation;
// Pointer to function pointer
void (**sortPtr)(int *array, int len);
// Function pointer with a function pointer parameter
void (*sortBy)(int *array, int len, int (*evaluator)(int x));
// Function where few parameters are named. This should not
// produce parameters in output.
void (*improperlyDeclaredParams)(int a, int, char);
// Function pointer with 2 function pointer parameters
void (*sortByWithFallback)(int *array, int (*primaryEvaluator)(int x),
int (*fallbackEvaluator)(int x));

// TODO(#545): Handle remaining cases of parsing param names
// ---
// Array of function pointers. Does not produce proper output right now.
void (*manyFunctions[2])(char a, char b);
// Function pointer returning function pointer. Does not produce valid output.
int (*(*functionReturningFunction)(int a, int b))(int c, int d);
// Function pointer returning function pointer. The return type has param
// names, but the function itself doesn't. This also shouldn't produce
// any parameters in output.
int (*(*functionReturningFunctionImproper)(int a, int b))(int, int);
// TODO(https://github.com/dart-lang/ffigen/issues/545): Handle remaining
// cases of parsing param names.
// ---
// Array of function pointers. Does not produce proper output right now.
void (*manyFunctions[2])(char a, char b);
// Function pointer returning function pointer. Does not produce valid output.
int (*(*functionReturningFunction)(int a, int b))(int c, int d);
// Function pointer returning function pointer. The return type has param
// names, but the function itself doesn't. This also shouldn't produce
// any parameters in output.
int (*(*functionReturningFunctionImproper)(int a, int b))(int, int);
};
10 changes: 6 additions & 4 deletions pkgs/ffigen/test/native_objc_test/string_test.m
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#import <Foundation/NSObject.h>
#import <Foundation/NSString.h>

// TODO(#309): strConcat should just be a static function.
@interface StringUtil : NSObject {}
+ (NSString*)strConcat:(NSString*)a with:(NSString*)b;
// TODO(https://github.com/dart-lang/ffigen/issues/309): strConcat should just
// be a static function.
@interface StringUtil : NSObject {
}
+ (NSString *)strConcat:(NSString *)a with:(NSString *)b;
@end

@implementation StringUtil
+ (NSString*)strConcat:(NSString*)a with:(NSString*)b {
+ (NSString *)strConcat:(NSString *)a with:(NSString *)b {
return [a stringByAppendingString:b];
}
@end

0 comments on commit bfb6f3a

Please sign in to comment.