Skip to content

Commit

Permalink
[tizen_bundle, tizen_rpc_port] Fix token in finalizer to be different…
Browse files Browse the repository at this point in the history
… from value

related issue : flutter-tizen#637
  • Loading branch information
JSUYA committed Dec 11, 2023
1 parent e86f535 commit 0b99173
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/tizen_bundle/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## NEXT

* Increase the minimum Flutter version to 3.3.
* Fix token in finalizer to be different from value.

## 0.1.1

Expand Down
11 changes: 6 additions & 5 deletions packages/tizen_bundle/lib/tizen_bundle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ class Bundle extends MapMixin<String, Object> {
/// Creates an empty [Bundle].
Bundle() {
_handle = tizen.bundle_create();
_finalizer.attach(this, this, detach: this);
_finalizer.attach(this, _handle, detach: this);
}

/// Creates a [Bundle] from the encoded bundle string.
Bundle.decode(String raw) {
_handle = tizen.bundle_decode(
raw.toNativeInt8().cast<UnsignedChar>(), raw.length);
_finalizer.attach(this, this, detach: this);
_finalizer.attach(this, _handle, detach: this);
}

/// Creates a copy of the given [bundle].
Bundle.fromBundle(Bundle bundle) {
_handle = tizen.bundle_dup(bundle._handle);
_finalizer.attach(this, this, detach: this);
_finalizer.attach(this, _handle, detach: this);
}

/// Creates a [Bundle] from the given [map].
Expand All @@ -44,8 +44,9 @@ class Bundle extends MapMixin<String, Object> {
}

late final Pointer<bundle> _handle;
static final Finalizer<Bundle> _finalizer =
Finalizer<Bundle>((Bundle bundle) => tizen.bundle_free(bundle._handle));
static final Finalizer<Pointer<bundle>> _finalizer =
Finalizer<Pointer<bundle>>(
(Pointer<bundle> bundle) => tizen.bundle_free(bundle));

static final List<String> _keys = <String>[];

Expand Down
4 changes: 4 additions & 0 deletions packages/tizen_rpc_port/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## NEXT

* Fix token in finalizer to be different from value.

## 0.1.3

* Remove unnecessary `StreamHandlerError` implementation.
Expand Down
7 changes: 4 additions & 3 deletions packages/tizen_rpc_port/lib/src/proxy_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ abstract class ProxyBase {
return pProxy.value;
});

_finalizer.attach(this, this);
_finalizer.attach(this, <String, ProxyBase>{'proxy': this});
}

late final rpc_port_proxy_h _handle;

final Finalizer<ProxyBase> _finalizer =
Finalizer<ProxyBase>((ProxyBase proxy) {
final Finalizer<Map<String, ProxyBase>> _finalizer =
Finalizer<Map<String, ProxyBase>>((Map<String, ProxyBase> map) {
final ProxyBase proxy = map['proxy']!;
proxy._streamSubscription?.cancel();
tizen.rpc_port_proxy_destroy(proxy._handle);
});
Expand Down
8 changes: 5 additions & 3 deletions packages/tizen_rpc_port/lib/src/stub_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ abstract class StubBase {
return pStub.value;
});

_finalizer.attach(this, this);
_finalizer.attach(this, <String, StubBase>{'stub': this});
}

late final rpc_port_stub_h _handle;

final Finalizer<StubBase> _finalizer = Finalizer<StubBase>((StubBase stub) {
stub.close();
final Finalizer<Map<String, StubBase>> _finalizer =
Finalizer<Map<String, StubBase>>((Map<String, StubBase> map) {
final StubBase stub = map['stub']!;
stub._streamSubscription?.cancel();
});

/// A port name to use when listening for connections.
Expand Down

0 comments on commit 0b99173

Please sign in to comment.