Skip to content

fix: String retry + suspend ByteArray support + unsupported features docs#3

Open
kdroidFilter wants to merge 10 commits intomainfrom
fix/unbounded-string-reinterpret
Open

fix: String retry + suspend ByteArray support + unsupported features docs#3
kdroidFilter wants to merge 10 commits intomainfrom
fix/unbounded-string-reinterpret

Conversation

@kdroidFilter
Copy link
Copy Markdown
Owner

@kdroidFilter kdroidFilter commented Mar 29, 2026

Summary

1. String buffer retry (JetBrains-style)

  • Replace hardcoded reinterpret(8192) with dynamic retry-on-truncation pattern
  • Allocate initial 8KB, call native, if returned size >= buffer size, reallocate with exact size and retry
  • Applies to all string/bytearray return paths: functions, properties, suspend, StableRef reads
  • Extract appendStringReadWithRetry helper to DRY logic across codegen sites

2. Suspend ByteArray support (NEW)

  • Add native readByteArrayRef helper (mirrors STRING pattern)
  • Add BYTE_ARRAY case to suspend result encode/decode (NativeBridgeGenerator + FfmProxyGenerator)
  • Add readByteArrayFromRef method + MethodHandle on JVM side (with retry)
  • Enables: suspend fun(): ByteArray, suspend fun(): ByteArray?, large arrays >8KB

3. Comprehensive "What's NOT supported" documentation (NEW)

  • Language features (interfaces, inheritance, generics, etc.)
  • Suspend limitations (DataClass return, collections return)
  • Flow limitations (ByteArray elements, collections elements)
  • Callback limitations (nullable params, ByteArray param, lambda return)
  • Collection/property/data class field limitations
  • Each gap explains the reason + suggests alternative approach

Testing

  • All existing tests pass (calculator + systeminfo)
  • Added 7 new suspend ByteArray tests:
    • Basic return + state mutation
    • Nullable (null + non-null case)
    • Large arrays (16KB, exceeds initial 8KB buffer)
    • Concurrent calls (20 concurrent async tasks)

Files Changed

  • NativeBridgeGenerator.kt — add readByteArrayRef helper + BYTE_ARRAY suspend encode
  • FfmProxyGenerator.kt — add string retry helper, update all string return paths, add BYTE_ARRAY suspend decode + MethodHandle
  • Calculator.kt — add 3 suspend ByteArray functions
  • SuspendFunctionTest.kt — add 7 suspend ByteArray tests
  • README.md — add detailed "What's NOT supported" section with 3 tables

Test Plan

  • Plugin compiles
  • calculator:jvmTest (780+ tests pass, including 60 suspend)
  • systeminfo:jvmTest passes
  • Strings >8KB work correctly (retry logic validates)
  • Suspend ByteArray: basic, nullable, large, concurrent

Replace hardcoded 8192 buffer limit in reinterpret() calls with
Long.MAX_VALUE, matching the swift-java approach. This prevents
potential crashes or corrupted reads when native strings exceed 8KB.
…tion args

Integrate a retry mechanism for reading string output buffers when initial capacity is exceeded. Refactor to remove unused buffer args and use a consistent pattern for parsing nullable and non-nullable string outputs.
Introduce support for serializing and deserializing byte arrays in FFM bridges. Added mechanisms to handle StableRef for byte arrays, including Java and native implementations with custom method handles. Updated infrastructure for BYTE_ARRAY KneType.
- Add readByteArrayRef helper on native side (StableRef pattern)
- Add BYTE_ARRAY case to suspend result encode/decode
- Add readByteArrayFromRef with retry on FFM side
- Add 3 suspend ByteArray functions to Calculator example
- Add 7 tests: basic, nullable, large (>8KB), concurrent
- Update README with comprehensive unsupported features table
@kdroidFilter kdroidFilter changed the title fix: Use Long.MAX_VALUE for string reinterpret instead of hardcoded 8192 fix: String retry + suspend ByteArray support + unsupported features docs Mar 30, 2026
…ntations

- Introduced `captureScreen` suspend function for cross-platform screen capture support.
- Added macOS implementation using `CGWindowListCreateImage` for native screenshot handling.
- Provided stub implementations for other platforms (Linux, Windows).
- Integrated screen capture feature into the system info UI with `rememberCoroutineScope`.
- Updated dependencies to include `kotlinx-coroutines-swing`.
- Implemented `captureScreen` for Linux using D-Bus Portal API with GLib bindings.
- Integrated GIO native interop for GLib/Portal communication.
- Updated build configuration to include `gio.def` for native interop.
- Updated dependencies to include required libraries (`libpipewire-0.3-dev`).
- Enhanced system info UI to reflect Linux screenshot capabilities.
…ents

- Fully replace C interop implementation with Kotlin code using GLib bindings.
- Refactor `captureScreen` to leverage stable references and coroutine-based flow.
- Adjust GIO interop to include updated header filters for GLib and GObject.
- Improve compatibility and maintainability by removing legacy C code.
… using GLib

- Migrated system tray logic to `TrayManager` class leveraging GLib bindings.
- Removed C-based interop code and systray functions from `systray.def`.
- Updated `SystemDesktop` to use `TrayManager` for system tray operations.
- Improved maintainability by fully transitioning to Kotlin-native code.
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

Successfully merging this pull request may close these issues.

1 participant