Skip to content
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

[Windows]CONST fails ffigen when not include directives #390

Closed
Sunbreak opened this issue Feb 28, 2021 · 7 comments
Closed

[Windows]CONST fails ffigen when not include directives #390

Sunbreak opened this issue Feb 28, 2021 · 7 comments

Comments

@Sunbreak
Copy link
Contributor

Reproduce

  • pubspec.yaml
dev_dependencies:
  pedantic: ^1.10.0
  ffigen: ^2.0.1

ffigen:
  name: SetupAPI
  description: Bindings to `SetupAPI.h`.
  llvm-lib: 'C:\Program Files\LLVM\bin'
  output: 'lib/src/windows/setupapi.dart'
  headers:
    entry-points:
      - 'windows/SetupAPI_.h'
    include-directives: # include only these header files and necessary structs from other header files
      # - '**SetupAPI.h'
      - '**SetupAPI_.h'
  • SetupAPI_.h
/* Windows */
#include <Windows.h>
#include <SetupAPI.h>

/**
 * SetupDiGetClassDevsW
 */
_Check_return_
WINSETUPAPI
HDEVINFO
WINAPI
SetupDiGetClassDevs_(
    _In_opt_ CONST GUID *ClassGuid,
    _In_opt_ PCWSTR Enumerator,
    _In_opt_ HWND hwndParent,
    _In_ DWORD Flags
    );
  • log
C:\Users\Admin\sunbreak\logic_conf.dart>%flutter-dev% pub run ffigen --config windows\SetupApi.yaml
Running in Directory: 'C:\Users\Admin\sunbreak\logic_conf.dart'
Input Headers: [windows\SetupAPI_.h]
[WARNING]: Removed All Struct Members from: const GUID(const GUID), Array members not supported
[SEVERE] : Could not format because the source could not be parsed:

line 16, column 15 of lib\src\windows\setupapi.dart: Expected to find ')'.
   鈺?16 鈹?  ffi.Pointer<const GUID> ClassGuid,
   鈹?              ^^^^^
   鈺?line 32, column 29 of lib\src\windows\setupapi.dart: Expected a method, getter, setter or operator declaration.
   鈺?32 鈹?class const GUID extends ffi.Opaque{
   鈹?                            ^
   鈺?line 42, column 14 of lib\src\windows\setupapi.dart: Expected to find ')'.
   鈺?42 鈹?  ffi.Pointer<const GUID> ClassGuid,
   鈹?             ^
   鈺?line 16, column 14 of lib\src\windows\setupapi.dart: Expected an identifier.
   鈺?16 鈹?  ffi.Pointer<const GUID> ClassGuid,
   鈹?             ^
   鈺?line 32, column 18 of lib\src\windows\setupapi.dart: Variables must be declared using the keywords 'const', 'final', 'var' or a type name.
   鈺?32 鈹?class const GUID extends ffi.Opaque{
   鈹?                 ^^^^^^^
   鈺?line 32, column 18 of lib\src\windows\setupapi.dart: Expected to find ';'.
   鈺?32 鈹?class const GUID extends ffi.Opaque{
   鈹?                 ^^^^^^^
   鈺?line 32, column 13 of lib\src\windows\setupapi.dart: Expected to find ';'.
   鈺?32 鈹?class const GUID extends ffi.Opaque{
   鈹?            ^^^^
   鈺?line 49, column 14 of lib\src\windows\setupapi.dart: Expected to find ')'.
   鈺?49 鈹?  ffi.Pointer<const GUID> ClassGuid,
   鈹?             ^
   鈺?line 32, column 18 of lib\src\windows\setupapi.dart: 'extends' can't be used as an identifier because it's a keyword.
   鈺?32 鈹?class const GUID extends ffi.Opaque{
   鈹?                 ^^^^^^^
   鈺?line 32, column 26 of lib\src\windows\setupapi.dart: Functions must have an explicit list of parameters.
   鈺?32 鈹?class const GUID extends ffi.Opaque{
   鈹?                         ^^^
   鈺?(4 more errors...)

Unhandled exception:
FormatException: Unable to format generated file: lib\src\windows\setupapi.dart.
#0      Library._dartFmt (package:ffigen/src/code_generator/library.dart:104:7)
dart-lang/ffigen#1      Library.generateFile (package:ffigen/src/code_generator/library.dart:92:7)
dart-lang/ffigen#2      main (package:ffigen/src/executables/ffigen.dart:46:11)
dart-lang/ffigen#3      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:281:32)
dart-lang/ffigen#4      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
pub finished with exit code 255
  • setupapi.dart
// AUTO GENERATED FILE, DO NOT EDIT.
// 
// Generated by `package:ffigen`.
import 'dart:ffi' as ffi;

/// Bindings to `SetupAPI.h`.
class SetupAPI{
/// Holds the Dynamic library.
final ffi.DynamicLibrary _dylib;

/// The symbols are looked up in [dynamicLibrary].
SetupAPI(ffi.DynamicLibrary dynamicLibrary): _dylib = dynamicLibrary;

/// SetupDiGetClassDevsW
ffi.Pointer<ffi.Void> SetupDiGetClassDevs_(
  ffi.Pointer<const GUID> ClassGuid,
  ffi.Pointer<ffi.Uint16> Enumerator,
  ffi.Pointer<HWND> hwndParent,
  int Flags,
) {
return (_SetupDiGetClassDevs_ ??= _dylib.lookupFunction<_c_SetupDiGetClassDevs_,_dart_SetupDiGetClassDevs_>('SetupDiGetClassDevs_'))(
    ClassGuid,
    Enumerator,
    hwndParent,
    Flags,
  );
}
_dart_SetupDiGetClassDevs_? _SetupDiGetClassDevs_;

}

class const GUID extends ffi.Opaque{
}

class HWND extends ffi.Struct{
  @ffi.Int32()
  external int unused;

}

typedef _c_SetupDiGetClassDevs_ = ffi.Pointer<ffi.Void> Function(
  ffi.Pointer<const GUID> ClassGuid,
  ffi.Pointer<ffi.Uint16> Enumerator,
  ffi.Pointer<HWND> hwndParent,
  ffi.Uint64 Flags,
);

typedef _dart_SetupDiGetClassDevs_ = ffi.Pointer<ffi.Void> Function(
  ffi.Pointer<const GUID> ClassGuid,
  ffi.Pointer<ffi.Uint16> Enumerator,
  ffi.Pointer<HWND> hwndParent,
  int Flags,
);
@Sunbreak
Copy link
Contributor Author

More specifically, uncommenting - '**SetupAPI.h' works

    include-directives: # include only these header files and necessary structs from other header files
      - '**SetupAPI.h'
      - '**SetupAPI_.h'

SetupDiGetClassDevsA, SetupDiGetClassDevsW and custom SetupDiGetClassDevs_ are generated correct

/// SetupDiGetClassDevsW
  ffi.Pointer<ffi.Void> SetupDiGetClassDevs_(
    ffi.Pointer<GUID> ClassGuid,
    ffi.Pointer<ffi.Uint16> Enumerator,
    ffi.Pointer<HWND> hwndParent,
    int Flags,
  ) {
    return (_SetupDiGetClassDevs_ ??= _dylib.lookupFunction<
        _c_SetupDiGetClassDevs_,
        _dart_SetupDiGetClassDevs_>('SetupDiGetClassDevs_'))(
      ClassGuid,
      Enumerator,
      hwndParent,
      Flags,
    );
  }

  _dart_SetupDiGetClassDevs_? _SetupDiGetClassDevs_;
}

@Sunbreak
Copy link
Contributor Author

Possible related: #382

@Sunbreak Sunbreak changed the title CONST fails ffigen when not include directives [Windows]CONST fails ffigen when not include directives Feb 28, 2021
@mannprerak2
Copy link
Contributor

I have a fix for this here which will soon be merged.

I am closing this issue since we already have a similar one (#145)

@mannprerak2
Copy link
Contributor

Hey @Sunbreak. The fix for this has landed in version 2.0.2 https://pub.dev/packages/ffigen/versions/2.0.2

@Sunbreak
Copy link
Contributor Author

Sunbreak commented Mar 3, 2021

Thanks a lot. I'll try later

@Sunbreak
Copy link
Contributor Author

Sunbreak commented Mar 3, 2021

Hey @Sunbreak. The fix for this has landed in version 2.0.2 https://pub.dev/packages/ffigen/versions/2.0.2

Works like a charm!

BTW, I'd like to proposal some feature requests for dart:ffi/ffigen. It is OK to file issue here or post on Google group: https://groups.google.com/forum/#!forum/dart-ffi ?

@mannprerak2
Copy link
Contributor

You can file one here or on dart-lang/sdk or both depending on the issue.

@liamappelbe liamappelbe transferred this issue from dart-archive/ffigen Nov 15, 2023
HosseinYousefi added a commit that referenced this issue Nov 16, 2023
…rom `Uint8List` (#390)

`JBuffer` is now the default binding for `java.nio.Buffer` and `JByteBuffer` for `java.nio.ByteBuffer`.
HosseinYousefi added a commit that referenced this issue Nov 16, 2023
…rom `Uint8List` (#390)

`JBuffer` is now the default binding for `java.nio.Buffer` and `JByteBuffer` for `java.nio.ByteBuffer`.
parlough pushed a commit to parlough/native that referenced this issue Apr 8, 2024
* Test autorelease pools and more copying cases

* Test assign/retain/copy properties
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants