dart-lang / dart-lang/native

Better string support if all strings in a C API follow the same encoding

Open
#315 3 comments 2 reactions 0 assignees View on GitHub
package:ffigen type-enhancement
Dominant language
Dart
Stars
275
Forks
144
Avg merge
2d 10h
Merged PRs (30d)
47

Description

If we have a header file for which we know all the `char*` are UTF-8 null-terminated strings, we can do the following:

```c
int my_strlen(char *a);

char *my_substr(char *a, int start, int end);
```

```yaml
type-map:
native-types:
'char':
'lib': 'pkg_ffi'
'c-type': 'Utf8'
'dart-type': 'Utf8'
```

However, this does not support any `char` (without `*`) in the API.

The following doesn't work:

```yaml
type-map:
native-types:
'char*':
'lib': 'dart_ffi'
'c-type': 'Pointer'
'dart-type': 'Pointer'
```

Matching on `char*` isn't supported.

Also, there's no way to filter only replacing the type in certain functions but not everywhere.

For libraries that do not have any `char` in their API, and for which all `char*` are consistently `Pointer` this works though.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.