Skip to content

Commit e8c818e

Browse files
author
Kasper Overgård Nielsen
authored
RDART-1038: Drop keep alive hack (#1691)
* Remove keepAlive pseudo functions The keepAlive hack introduced as a work-around for dart-lang/sdk#49643 is no longer needed, as of dart 2.19.0 or later. * Update CHANGELOG
1 parent 5e4e6a7 commit e8c818e

File tree

15 files changed

+19
-124
lines changed

15 files changed

+19
-124
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@
313313

314314
### Internal
315315
* Using Core 13.26.0-13-gd12c3
316+
* Drop work-around for pre-dart-2.19 bug. ([#1691](https://github.com/realm/realm-dart/pull/1691))
316317

317318
## 1.8.0 (2024-01-29)
318319

packages/realm_dart/lib/src/app.dart

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import 'dart:convert';
5-
import 'dart:ffi';
65
import 'dart:io';
76
import 'dart:isolate';
87

@@ -140,7 +139,7 @@ class AppConfiguration {
140139
/// * Register uses and perform various user-related operations through authentication providers
141140
/// * Synchronize data between the local device and a remote Realm App with Synchronized Realms
142141
/// {@category Application}
143-
class App implements Finalizable {
142+
class App {
144143
final AppHandle _handle;
145144

146145
/// The id of this application. This is the same as the appId in the [AppConfiguration] used to
@@ -260,11 +259,6 @@ enum MetadataPersistenceMode {
260259

261260
/// @nodoc
262261
extension AppInternal on App {
263-
@pragma('vm:never-inline')
264-
void keepAlive() {
265-
_handle.keepAlive();
266-
}
267-
268262
AppHandle get handle => _handle;
269263

270264
static App create(AppHandle handle) => App._(handle);

packages/realm_dart/lib/src/collections.dart

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2022 MongoDB, Inc.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
import 'dart:ffi';
54
import 'native/collection_changes_handle.dart';
65

76
/// Contains index information about objects that moved within the same collection.
@@ -46,7 +45,7 @@ class MapChanges {
4645
}
4746

4847
/// Describes the changes in a Realm collection since the last time the notification callback was invoked.
49-
class RealmCollectionChanges implements Finalizable {
48+
class RealmCollectionChanges {
5049
final CollectionChangesHandle _handle;
5150
late final CollectionChanges _changes = _handle.changes;
5251

@@ -73,10 +72,5 @@ class RealmCollectionChanges implements Finalizable {
7372
}
7473

7574
extension RealmCollectionChangesInternal on RealmCollectionChanges {
76-
@pragma('vm:never-inline')
77-
void keepAlive() {
78-
_handle.keepAlive();
79-
}
80-
8175
CollectionChanges get changes => _changes;
8276
}

packages/realm_dart/lib/src/configuration.dart

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import 'dart:async';
5-
import 'dart:ffi';
65
import 'dart:io';
76

87
// ignore: no_leading_underscores_for_library_prefixes
@@ -69,7 +68,7 @@ typedef AfterResetCallback = FutureOr<void> Function(Realm beforeResetRealm, Rea
6968

7069
/// Configuration used to create a `Realm` instance
7170
/// {@category Configuration}
72-
abstract class Configuration implements Finalizable {
71+
abstract class Configuration {
7372
/// The default realm filename to be used.
7473
static String get defaultRealmName => _path.basename(defaultRealmPath);
7574
static set defaultRealmName(String name) => defaultRealmPath = _path.join(_path.dirname(defaultRealmPath), _path.basename(name));
@@ -377,11 +376,6 @@ class FlexibleSyncConfiguration extends Configuration {
377376
}
378377

379378
extension FlexibleSyncConfigurationInternal on FlexibleSyncConfiguration {
380-
@pragma('vm:never-inline')
381-
void keepAlive() {
382-
user.keepAlive();
383-
}
384-
385379
SessionStopPolicy get sessionStopPolicy => _sessionStopPolicy;
386380
set sessionStopPolicy(SessionStopPolicy value) => _sessionStopPolicy = value;
387381
}

packages/realm_dart/lib/src/credentials.dart

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import 'dart:convert';
5-
import 'dart:ffi';
65

76
import 'app.dart';
87
import 'native/convert.dart';
@@ -57,7 +56,7 @@ extension AuthProviderTypeInternal on AuthProviderType {
5756

5857
/// A class, representing the credentials used for authenticating a [User]
5958
/// {@category Application}
60-
class Credentials implements Finalizable {
59+
class Credentials {
6160
final CredentialsHandle _handle;
6261

6362
/// Returns a [Credentials] object that can be used to authenticate an anonymous user.
@@ -100,18 +99,13 @@ class Credentials implements Finalizable {
10099

101100
/// @nodoc
102101
extension CredentialsInternal on Credentials {
103-
@pragma('vm:never-inline')
104-
void keepAlive() {
105-
_handle.keepAlive();
106-
}
107-
108102
CredentialsHandle get handle => _handle;
109103
}
110104

111105
/// A class, encapsulating functionality for users, logged in with [Credentials.emailPassword()].
112106
/// It is always scoped to a particular app.
113107
/// {@category Application}
114-
class EmailPasswordAuthProvider implements Finalizable {
108+
class EmailPasswordAuthProvider {
115109
final App app;
116110

117111
/// Create a new EmailPasswordAuthProvider for the [app]
@@ -160,10 +154,5 @@ class EmailPasswordAuthProvider implements Finalizable {
160154
}
161155

162156
extension EmailPasswordAuthProviderInternal on EmailPasswordAuthProvider {
163-
@pragma('vm:never-inline')
164-
void keepAlive() {
165-
app.keepAlive();
166-
}
167-
168157
static EmailPasswordAuthProvider create(App app) => EmailPasswordAuthProvider(app);
169158
}

packages/realm_dart/lib/src/list.dart

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import 'dart:core';
55
import 'dart:async';
66
import 'dart:collection';
7-
import 'dart:ffi';
87

98
import 'package:collection/collection.dart' as collection;
109

@@ -22,7 +21,7 @@ import 'results.dart';
2221
/// added to or deleted from the collection or from the Realm.
2322
///
2423
/// {@category Realm}
25-
abstract class RealmList<T extends Object?> with RealmEntity implements List<T>, Finalizable {
24+
abstract class RealmList<T extends Object?> with RealmEntity implements List<T> {
2625
late final RealmObjectMetadata? _metadata;
2726

2827
/// Gets a value indicating whether this collection is still valid to use.
@@ -255,15 +254,6 @@ extension RealmListOfObject<T extends RealmObjectBase> on RealmList<T> {
255254

256255
/// @nodoc
257256
extension RealmListInternal<T extends Object?> on RealmList<T> {
258-
@pragma('vm:never-inline')
259-
void keepAlive() {
260-
final self = this;
261-
if (self is ManagedRealmList<T>) {
262-
realm.keepAlive();
263-
self._handle.keepAlive();
264-
}
265-
}
266-
267257
ManagedRealmList<T> asManaged() => this is ManagedRealmList<T> ? this as ManagedRealmList<T> : throw RealmStateError('$this is not managed');
268258

269259
ListHandle get handle {

packages/realm_dart/lib/src/map.dart

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'dart:collection';
66

77
import 'package:collection/collection.dart' as collection;
88

9-
import 'dart:ffi';
109

1110
import 'collections.dart';
1211
import 'native/handle_base.dart';
@@ -19,7 +18,7 @@ import 'realm_class.dart';
1918
import 'results.dart';
2019

2120
/// RealmMap is a collection that contains key-value pairs of <String, T>.
22-
abstract class RealmMap<T extends Object?> with RealmEntity implements MapBase<String, T>, Finalizable {
21+
abstract class RealmMap<T extends Object?> with RealmEntity implements MapBase<String, T> {
2322
/// Gets a value indicating whether this collection is still valid to use.
2423
///
2524
/// Indicates whether the [Realm] instance hasn't been closed,
@@ -228,15 +227,6 @@ extension RealmMapOfObject<T extends RealmObjectBase> on RealmMap<T?> {
228227

229228
/// @nodoc
230229
extension RealmMapInternal<T extends Object?> on RealmMap<T> {
231-
@pragma('vm:never-inline')
232-
void keepAlive() {
233-
final self = this;
234-
if (self is ManagedRealmMap<T>) {
235-
realm.keepAlive();
236-
self._handle.keepAlive();
237-
}
238-
}
239-
240230
ManagedRealmMap<T> asManaged() => this is ManagedRealmMap<T> ? this as ManagedRealmMap<T> : throw RealmStateError('$this is not managed');
241231

242232
MapHandle get handle {

packages/realm_dart/lib/src/native/handle_base.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ abstract class HandleBase<T extends NativeType> implements Finalizable {
3939
bool get released => pointer == nullptr;
4040
final bool isUnowned;
4141

42-
@pragma('vm:never-inline')
43-
void keepAlive() {}
44-
4542
HandleBase(this.pointer, int size) : isUnowned = false {
4643
pointer.raiseLastErrorIfNull();
4744
_finalizableHandle = realmLib.realm_attach_finalizer(this, pointer.cast(), size);

packages/realm_dart/lib/src/realm_class.dart

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import 'dart:async';
5-
import 'dart:ffi';
65
import 'dart:io';
76

87
import 'package:cancellation_token/cancellation_token.dart';
@@ -116,7 +115,7 @@ export 'user.dart' show User, UserState, ApiKeyClient, UserIdentity, ApiKey, Fun
116115
/// A [Realm] instance represents a `Realm` database.
117116
///
118117
/// {@category Realm}
119-
class Realm implements Finalizable {
118+
class Realm {
120119
late final RealmMetadata _metadata;
121120
late final RealmHandle _handle;
122121
final bool _isInMigration;
@@ -727,15 +726,6 @@ class Transaction {
727726

728727
/// @nodoc
729728
extension RealmInternal on Realm {
730-
@pragma('vm:never-inline')
731-
void keepAlive() {
732-
_handle.keepAlive();
733-
final c = config;
734-
if (c is FlexibleSyncConfiguration) {
735-
c.keepAlive();
736-
}
737-
}
738-
739729
RealmHandle get handle {
740730
if (_handle.released) {
741731
throw RealmClosedError('Cannot access realm that has been closed');
@@ -864,7 +854,7 @@ extension RealmInternal on Realm {
864854
}
865855

866856
/// @nodoc
867-
abstract class NotificationsController implements Finalizable {
857+
abstract class NotificationsController {
868858
NotificationTokenHandle? handle;
869859

870860
NotificationTokenHandle subscribe();

packages/realm_dart/lib/src/realm_object.dart

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import 'dart:async';
5-
import 'dart:ffi';
65

76
import 'package:collection/collection.dart';
87
import 'package:realm_common/realm_common.dart';
@@ -365,7 +364,7 @@ extension RealmEntityInternal on RealmEntity {
365364
///
366365
/// [RealmObject] should not be used directly as it is part of the generated class hierarchy. ex: `MyClass extends _MyClass with RealmObject`.
367366
/// {@category Realm}
368-
mixin RealmObjectBase on RealmEntity implements RealmObjectBaseMarker, Finalizable {
367+
mixin RealmObjectBase on RealmEntity implements RealmObjectBaseMarker {
369368
ObjectHandle? _handle;
370369
RealmAccessor _accessor = RealmValuesAccessor();
371370
static final Map<Type, RealmObjectBase Function()> _factories = <Type, RealmObjectBase Function()>{
@@ -646,12 +645,6 @@ extension EmbeddedObjectExtension on EmbeddedObject {
646645
/// @nodoc
647646
//RealmObject package internal members
648647
extension RealmObjectInternal on RealmObjectBase {
649-
@pragma('vm:never-inline')
650-
void keepAlive() {
651-
_realm?.keepAlive();
652-
_handle?.keepAlive();
653-
}
654-
655648
void manage(Realm realm, ObjectHandle handle, RealmCoreAccessor accessor, bool update) {
656649
if (_handle != null) {
657650
//most certainly a bug hence we throw an Error
@@ -726,7 +719,7 @@ class UserCallbackException extends RealmException {
726719
}
727720

728721
/// Describes the changes in on a single RealmObject since the last time the notification callback was invoked.
729-
class RealmObjectChanges<T extends RealmObjectBase> implements Finalizable {
722+
class RealmObjectChanges<T extends RealmObjectBase> {
730723
// ignore: unused_field
731724
final ObjectChangesHandle _handle;
732725

@@ -749,12 +742,7 @@ class RealmObjectChanges<T extends RealmObjectBase> implements Finalizable {
749742
}
750743

751744
/// @nodoc
752-
extension RealmObjectChangesInternal<T extends RealmObject> on RealmObjectChanges<T> {
753-
@pragma('vm:never-inline')
754-
void keepAlive() {
755-
_handle.keepAlive();
756-
}
757-
}
745+
extension RealmObjectChangesInternal<T extends RealmObject> on RealmObjectChanges<T> {}
758746

759747
/// @nodoc
760748
class RealmObjectNotificationsController<T extends RealmObjectBase> extends NotificationsController {

0 commit comments

Comments
 (0)