diff --git a/CHANGELOG.md b/CHANGELOG.md index 2149c4c..6544581 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.4.0-dev.2 + +- A few more updates to new FFI API + ## 0.4.0-dev.1 - Update to new FFI API diff --git a/example/ffi/ffi-win32.dart b/example/ffi/ffi-win32.dart index 5afb82a..91966bf 100644 --- a/example/ffi/ffi-win32.dart +++ b/example/ffi/ffi-win32.dart @@ -1,4 +1,5 @@ import 'dart:ffi'; +import 'package:ffi/ffi.dart' as ffi; const STD_INPUT_HANDLE = -10; const STD_OUTPUT_HANDLE = -11; @@ -30,7 +31,7 @@ typedef getConsoleScreenBufferInfoDart = int Function(int hConsoleOutput, // SMALL_RECT srWindow; // COORD dwMaximumWindowSize; // } CONSOLE_SCREEN_BUFFER_INFO; -class CONSOLE_SCREEN_BUFFER_INFO extends Struct { +class CONSOLE_SCREEN_BUFFER_INFO extends Struct { @Int16() int dwSizeX; @@ -58,33 +59,13 @@ class CONSOLE_SCREEN_BUFFER_INFO extends Struct { int dwMaximumWindowSizeX; @Int16() int dwMaximumWindowSizeY; - - factory CONSOLE_SCREEN_BUFFER_INFO.allocate( - COORD dwSize, - COORD dwCursorPosition, - int wAttributes, - SMALL_RECT srWindow, - COORD dwMaximumWindowSize) => - Pointer.allocate() - .load() - ..dwSizeX = dwSize.X - ..dwSizeY = dwSize.Y - ..dwCursorPositionX = dwCursorPosition.X - ..dwCursorPositionY = dwCursorPosition.Y - ..wAttributes = wAttributes - ..srWindowLeft = srWindow.Left - ..srWindowTop = srWindow.Top - ..srWindowRight = srWindow.Right - ..srWindowBottom = srWindow.Bottom - ..dwMaximumWindowSizeX = dwMaximumWindowSize.X - ..dwMaximumWindowSizeY = dwMaximumWindowSize.Y; } // typedef struct _COORD { // SHORT X; // SHORT Y; // } COORD, *PCOORD; -class COORD extends Struct { +class COORD extends Struct { @Int16() int X; @@ -98,7 +79,7 @@ class COORD extends Struct { // SHORT Right; // SHORT Bottom; // } SMALL_RECT; -class SMALL_RECT extends Struct { +class SMALL_RECT extends Struct { @Int16() int Left; @@ -124,9 +105,8 @@ main() { final outputHandle = GetStdHandle(STD_OUTPUT_HANDLE); print(outputHandle); - Pointer pBufferInfo = - Pointer.allocate(); - CONSOLE_SCREEN_BUFFER_INFO bufferInfo = pBufferInfo.load(); + Pointer pBufferInfo = ffi.allocate(); + CONSOLE_SCREEN_BUFFER_INFO bufferInfo = pBufferInfo.ref; GetConsoleScreenBufferInfo(outputHandle, pBufferInfo); print(bufferInfo.dwMaximumWindowSizeX); print(bufferInfo.dwMaximumWindowSizeY); diff --git a/example/ffi/ffi_ioctl.dart b/example/ffi/ffi_ioctl.dart index aa73075..9051348 100644 --- a/example/ffi/ffi_ioctl.dart +++ b/example/ffi/ffi_ioctl.dart @@ -1,5 +1,6 @@ import 'dart:ffi'; import 'dart:io'; +import 'package:ffi/ffi.dart' as ffi; // int ioctl(int, unsigned long, ...); typedef ioctlVoidNative = Int32 Function(Int32, Int64, Pointer); @@ -16,7 +17,7 @@ const STDERR_FILENO = 2; // unsigned short ws_xpixel; /* horizontal size, pixels */ // unsigned short ws_ypixel; /* vertical size, pixels */ // }; -class WinSize extends Struct { +class WinSize extends Struct { @Int16() int ws_row; @@ -28,30 +29,22 @@ class WinSize extends Struct { @Int16() int ws_ypixel; - - factory WinSize.allocate( - int ws_row, int ws_col, int ws_xpixel, int ws_ypixel) => - Pointer.allocate().load() - ..ws_row = ws_row - ..ws_col = ws_col - ..ws_xpixel = ws_xpixel - ..ws_ypixel = ws_ypixel; } main() { final DynamicLibrary libc = Platform.isMacOS - ? DynamicLibrary.open('libSystem.dylib') + ? DynamicLibrary.open("/usr/lib/libSystem.dylib") : DynamicLibrary.open("libc-2.28.so"); final ioctl = libc.lookupFunction("ioctl"); - Pointer winSizePointer = Pointer.allocate(); + Pointer winSizePointer = ffi.allocate(); final result = ioctl(STDOUT_FILENO, TIOCGWINSZ, winSizePointer.cast()); print('result is $result'); - final winSize = winSizePointer.load(); + final winSize = winSizePointer.ref; print('Per ioctl, this console window has ${winSize.ws_col} cols and ' '${winSize.ws_row} rows.'); - winSizePointer.free(); + ffi.free(winSizePointer); } diff --git a/example/ffi/ffi_rawmode.dart b/example/ffi/ffi_rawmode.dart index 6b384e0..e3f9425 100644 --- a/example/ffi/ffi_rawmode.dart +++ b/example/ffi/ffi_rawmode.dart @@ -1,5 +1,6 @@ import 'dart:ffi'; import 'dart:io'; +import 'package:ffi/ffi.dart' as ffi; // int tcgetattr(int, struct termios *); typedef tcgetattrNative = Int32 Function( @@ -86,7 +87,7 @@ const int VTIME = 17; // time in 1/10s before returning // speed_t c_ispeed; /* input speed */ // speed_t c_ospeed; /* output speed */ // }; -class TermIOS extends Struct { +class TermIOS extends Struct { @Int64() int c_iflag; @Int64() @@ -145,7 +146,7 @@ class TermIOS extends Struct { main() { final DynamicLibrary libc = Platform.isMacOS - ? DynamicLibrary.open('libSystem.dylib') + ? DynamicLibrary.open("/usr/lib/libSystem.dylib") : DynamicLibrary.open("libc-2.28.so"); final tcgetattr = @@ -153,17 +154,17 @@ main() { final tcsetattr = libc.lookupFunction("tcsetattr"); - Pointer origTermIOSPointer = Pointer.allocate(); + Pointer origTermIOSPointer = ffi.allocate(); var result = tcgetattr(STDIN_FILENO, origTermIOSPointer); print('result is $result'); - TermIOS origTermIOS = origTermIOSPointer.load(); + TermIOS origTermIOS = origTermIOSPointer.ref; print('origTermIOS.c_iflag: 0b${origTermIOS.c_iflag.toRadixString(2)}'); print('Copying and modifying...'); - Pointer newTermIOSPointer = Pointer.allocate(); - TermIOS newTermIOS = newTermIOSPointer.load(); + Pointer newTermIOSPointer = ffi.allocate(); + TermIOS newTermIOS = newTermIOSPointer.ref; newTermIOS.c_iflag = origTermIOS.c_iflag & ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON); @@ -211,6 +212,6 @@ main() { print('\nORIGINAL MODE: Here is some text.\nHere is some more text.'); - origTermIOSPointer.free(); - newTermIOSPointer.free(); + ffi.free(origTermIOSPointer); + ffi.free(newTermIOSPointer); } diff --git a/example/pubspec.yaml b/example/pubspec.yaml deleted file mode 100644 index c89f5fd..0000000 --- a/example/pubspec.yaml +++ /dev/null @@ -1,6 +0,0 @@ -name: console_example -description: Demonstrates how to use the Console package. - -dependencies: - dart_console: - path: ../ \ No newline at end of file diff --git a/lib/src/ffi/unix/termlib-unix.dart b/lib/src/ffi/unix/termlib-unix.dart index 05d1797..63f0925 100644 --- a/lib/src/ffi/unix/termlib-unix.dart +++ b/lib/src/ffi/unix/termlib-unix.dart @@ -103,7 +103,7 @@ class TermLibUnix implements TermLib { TermLibUnix() { _stdlib = Platform.isMacOS - ? DynamicLibrary.open('libSystem.dylib') + ? DynamicLibrary.open("/usr/lib/libSystem.dylib") : DynamicLibrary.open("libc.so.6"); ioctl = _stdlib.lookupFunction("ioctl"); diff --git a/pubspec.yaml b/pubspec.yaml index 19c6cb3..877c726 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,12 +2,12 @@ name: dart_console description: A helper library for command-line applications that need more control over input/output than the standard library provides. -version: 0.4.0-dev.1 +version: 0.4.0-dev.2 homepage: https://github.com/timsneath/dart_console author: Tim Sneath environment: - sdk: '>=2.6.0-dev.6.0 <3.0.0' + sdk: '>=2.6.0-dev.8.2 <3.0.0' dependencies: ffi: ^0.1.3-dev.3