Skip to content

[jnigen] Support use arenas on nullable JObjects #2239

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

Merged
merged 5 commits into from
Apr 28, 2025

Conversation

dickermoshe
Copy link
Contributor

@dickermoshe dickermoshe commented Apr 24, 2025

The use method makes it really easy to use jni and not worry about memory management (even if the nesting get's ugly)

However this PR allows you to use use on nullable JObject?s too.
This is a very small pr which would allow you to do this.

someFunc(JObject? obj){
  obj.use(...);
}

The extension was only on JObject previosly.


  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.

@dickermoshe dickermoshe changed the title Support use arenas on nullable JObjects [jnigen] Support use arenas on nullable JObjects Apr 24, 2025
@dickermoshe dickermoshe marked this pull request as ready for review April 24, 2025 17:01
Copy link
Member

@HosseinYousefi HosseinYousefi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use method has existed for a while however I don't really recommend using it anymore (due to excessive nesting as you mentioned). We might even be fine with removing it eventually for 1.0. Instead use using:

using((arena) {
  final foo = Foo()..releasedBy(arena);
  final bar = Bar(foo)..releasedBy(arena);
});
// Now both foo and bar are released and we didn't have to nest twice.

I'm fine with landing your change though for now once you fix the test and add a changelog entry.

@dickermoshe
Copy link
Contributor Author

What should the wip header of the changelog be?

@HosseinYousefi
Copy link
Member

What should the wip header of the changelog be?

Actually, it's not a big change. So let's ignore the changelog.

Copy link

PR Health

Breaking changes ⚠️
Package Change Current Version New Version Needed Version Looking good?
jni Breaking 0.14.1 0.14.1 0.15.0
Got "0.14.1" expected >= "0.15.0" (breaking changes)
⚠️

This check can be disabled by tagging the PR with skip-breaking-check.

Changelog Entry
Package Changed Files
package:jni pkgs/jni/lib/src/jobject.dart

Changes to files need to be accounted for in their respective changelogs.

This check can be disabled by tagging the PR with skip-changelog-check.

API leaks ⚠️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbols
jni _ReferenceType
_opaque_pthread_mutex_t
_opaque_pthread_cond_t
_Dart_FinalizableHandle

This check can be disabled by tagging the PR with skip-leaking-check.

License Headers ✔️
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
Files
no missing headers

All source files should start with a license header.

Unrelated files missing license headers
Files
pkgs/jni/lib/src/third_party/generated_bindings.dart
pkgs/objective_c/lib/src/ns_input_stream.dart

@HosseinYousefi
Copy link
Member

Please run dart format on the test to satisfy the CI!

@dickermoshe
Copy link
Contributor Author

Done

@HosseinYousefi
Copy link
Member

analyze_jni step fails:

   info • Use 'const' for final variables initialized to a constant value • test/jobject_test.dart:178:5 • prefer_const_declarations

@dickermoshe
Copy link
Contributor Author

@HosseinYousefi Sorry that this became this many tries on my part.
Passes analyze and format. now.

@coveralls
Copy link

Coverage Status

coverage: 79.391% (+1.0%) from 78.421%
when pulling 3c47546 on dickermoshe:patch-2
into dcc6fc9 on dart-lang:main.

@HosseinYousefi HosseinYousefi self-requested a review April 28, 2025 16:35
@HosseinYousefi
Copy link
Member

LGTM! Thanks!

@HosseinYousefi HosseinYousefi merged commit 558625b into dart-lang:main Apr 28, 2025
27 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants