-
Notifications
You must be signed in to change notification settings - Fork 55
Conversation
Okay, this should be ready for review. The only issue right now is the large integration test, which I'm assuming fails because the library maybe has some globals that weren't generated before? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add a new test in test/header_parser_tests
? You can pretty much copy the unnamed_enum_test.dart
file and modify that to add a few tests. (say for a pointer, int, struct, Long Double, pointer to Long double)
Update: Also update the version in pubspec, changelog, and readme(Add globals in the configuration table in row 6, column 1)
final type = cursor.type().toCodeGenType(); | ||
if (type.broadType == BroadType.Unimplemented) { | ||
_logger | ||
.warning('Global Type not supported $type ${cursor.type().spelling()}'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add these logs instead.
_logger.fine(
'---- Removed Global, reason: unsupported type: ${cursor.completeStringRepr()}');
_logger.warning(
"Skipped global variable '$globalName', type not supported.");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
lib/src/code_generator/global.dart
Outdated
s.write( | ||
"${type.getDartType(w)} get $globalVarName => ($holderVarName ??= ${w.dylibIdentifier}.lookup<${type.getCType(w)}>('$originalName')).value;\n\n"); | ||
"late final ${type.getDartType(w)} $globalVarName = ${w.dylibIdentifier}.lookup<${type.getCType(w)}>('$originalName').$refOrValue;\n\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think global variables are not constants, they can be changed.
If that's the case, we should instead add getters and setters for this.
So for an int global variable, we can do this -
late final ffi.Pointer<ffi.Int32> _globalVar =
_dylib.lookup<ffi.Int32>('globalVar');
int get globalVar => _globalVar.value;
set globalVar(int value) => _globalVar.value = value;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this works for all types except structs, which just don't have a setter, but fields for structs can be set from the ref that is obtained via the getter.
The |
@mannprerak2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @TimWhiting, Just a few last changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm! Thanks @TimWhiting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool stuff! Some small comments.
From the CI:
Are those on purpose? |
Yes, that is on purpose. I test that the globals whose types dart:ffi does not support are not in the generated bindings and those messages are logged so the user knows those variables will not be present in the generated bindings. |
Closes dart-lang/native#378
@mannprerak2
I think I made the needed changes. Tested it locally and it seems to work.