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

Unable to open DSM after upgrade to null-safety #2

Closed
Sunbreak opened this issue Mar 9, 2021 · 0 comments
Closed

Unable to open DSM after upgrade to null-safety #2

Sunbreak opened this issue Mar 9, 2021 · 0 comments

Comments

@Sunbreak
Copy link
Collaborator

Sunbreak commented Mar 9, 2021

In branch: https://github.com/woodemi/twaindsm.dart/tree/repro/nullsafety-pointer-failure

Before null-safety

✅ allocate with empty struct: 0f8504b

Dart-beta: Dart SDK version: 2.12.0-259.16.beta (beta) (Tue Feb 23 00:10:18 2021 +0100) on "windows_x64"

class pTW_IDENTITY extends ffi.Struct {}

var identityPtr = ffi.allocate<pTW_IDENTITY>();
var connect = twainDsm.DSM_Entry(identityPtr,
  nullptr, DG_CONTROL, DAT_PARENT, MSG_OPENDSM, parentPtr.cast<Void>());

✅ allocate with Uint8 pointer: ed97d5e

Dart-beta: Dart SDK version: 2.12.0-259.16.beta (beta) (Tue Feb 23 00:10:18 2021 +0100) on "windows_x64"

...
var identityPtr = ffi.allocate<Uint8>(count: 156);
var connect = twainDsm.DSM_Entry(identityPtr.cast(), ...

After upgrading to null-safety

❌ calloc with opaque: 0ba8788

Dart-beta: Dart SDK version: 2.12.0-259.16.beta (beta) (Tue Feb 23 00:10:18 2021 +0100) on "windows_x64"

This doesn't compile: Opaque cannot...

class pTW_IDENTITY extends ffi.Opaque {}

var identityPtr = ffi.calloc<pTW_IDENTITY>();

❌ calloc with Uint8 pointer again: 84e0b7b

Dart-beta: Dart SDK version: 2.12.0-259.16.beta (beta) (Tue Feb 23 00:10:18 2021 +0100) on "windows_x64"

...
var identityPtr = ffi.allocate<Uint8>(count: 156);
var connect = twainDsm.DSM_Entry(identityPtr.cast(), ...

✅ use empty struct instead of opaque: 1f8168c

Dart-beta: Dart SDK version: 2.12.0-259.16.beta (beta) (Tue Feb 23 00:10:18 2021 +0100) on "windows_x64"

class pTW_IDENTITY extends ffi.Struct {}

var identityPtr = ffi.calloc<pTW_IDENTITY>();
...

❌ use inline-array & nested-struct: 4a151b8

Dart-dev: Dart SDK version: 2.13.0-97.0.dev (dev) (Tue Mar 2 19:57:46 2021 -0800) on "windows_x64"

class TW_VERSION extends ffi.Struct {
  @ffi.Uint16()
  external int MajorNum;

  @ffi.Uint16()
  external int MinorNum;

  @ffi.Uint16()
  external int Language;

  @ffi.Uint16()
  external int Country;
  
  @ffi.Array(34)
  external ffi.Array<ffi.Int8> Info;
}

class pTW_IDENTITY extends ffi.Struct {
  @ffi.Uint32()
  external int Id;

  external TW_VERSION Version;

  @ffi.Uint16()
  external int ProtocolMajor;

  @ffi.Uint16()
  external int ProtocolMinor;

  @ffi.Uint32()
  external int SupportedGroups;

  @ffi.Array(34)
  external ffi.Array<ffi.Int8> Manufacturer;

  @ffi.Array(34)
  external ffi.Array<ffi.Int8> ProductFamily;

  @ffi.Array(34)
  external ffi.Array<ffi.Int8> ProductName;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant