Skip to content

Commit

Permalink
Remove keepAlive pseudo functions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nielsenko committed May 27, 2024
1 parent 5e4e6a7 commit 8898319
Show file tree
Hide file tree
Showing 14 changed files with 18 additions and 124 deletions.
8 changes: 1 addition & 7 deletions packages/realm_dart/lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

import 'dart:convert';
import 'dart:ffi';
import 'dart:io';
import 'dart:isolate';

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

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

/// @nodoc
extension AppInternal on App {
@pragma('vm:never-inline')
void keepAlive() {
_handle.keepAlive();
}

AppHandle get handle => _handle;

static App create(AppHandle handle) => App._(handle);
Expand Down
8 changes: 1 addition & 7 deletions packages/realm_dart/lib/src/collections.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2022 MongoDB, Inc.
// SPDX-License-Identifier: Apache-2.0

import 'dart:ffi';
import 'native/collection_changes_handle.dart';

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

/// Describes the changes in a Realm collection since the last time the notification callback was invoked.
class RealmCollectionChanges implements Finalizable {
class RealmCollectionChanges {
final CollectionChangesHandle _handle;
late final CollectionChanges _changes = _handle.changes;

Expand All @@ -73,10 +72,5 @@ class RealmCollectionChanges implements Finalizable {
}

extension RealmCollectionChangesInternal on RealmCollectionChanges {
@pragma('vm:never-inline')
void keepAlive() {
_handle.keepAlive();
}

CollectionChanges get changes => _changes;
}
8 changes: 1 addition & 7 deletions packages/realm_dart/lib/src/configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

import 'dart:async';
import 'dart:ffi';
import 'dart:io';

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

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

extension FlexibleSyncConfigurationInternal on FlexibleSyncConfiguration {
@pragma('vm:never-inline')
void keepAlive() {
user.keepAlive();
}

SessionStopPolicy get sessionStopPolicy => _sessionStopPolicy;
set sessionStopPolicy(SessionStopPolicy value) => _sessionStopPolicy = value;
}
Expand Down
15 changes: 2 additions & 13 deletions packages/realm_dart/lib/src/credentials.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

import 'dart:convert';
import 'dart:ffi';

import 'app.dart';
import 'native/convert.dart';
Expand Down Expand Up @@ -57,7 +56,7 @@ extension AuthProviderTypeInternal on AuthProviderType {

/// A class, representing the credentials used for authenticating a [User]
/// {@category Application}
class Credentials implements Finalizable {
class Credentials {
final CredentialsHandle _handle;

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

/// @nodoc
extension CredentialsInternal on Credentials {
@pragma('vm:never-inline')
void keepAlive() {
_handle.keepAlive();
}

CredentialsHandle get handle => _handle;
}

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

/// Create a new EmailPasswordAuthProvider for the [app]
Expand Down Expand Up @@ -160,10 +154,5 @@ class EmailPasswordAuthProvider implements Finalizable {
}

extension EmailPasswordAuthProviderInternal on EmailPasswordAuthProvider {
@pragma('vm:never-inline')
void keepAlive() {
app.keepAlive();
}

static EmailPasswordAuthProvider create(App app) => EmailPasswordAuthProvider(app);
}
12 changes: 1 addition & 11 deletions packages/realm_dart/lib/src/list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import 'dart:core';
import 'dart:async';
import 'dart:collection';
import 'dart:ffi';

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

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

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

/// @nodoc
extension RealmListInternal<T extends Object?> on RealmList<T> {
@pragma('vm:never-inline')
void keepAlive() {
final self = this;
if (self is ManagedRealmList<T>) {
realm.keepAlive();
self._handle.keepAlive();
}
}

ManagedRealmList<T> asManaged() => this is ManagedRealmList<T> ? this as ManagedRealmList<T> : throw RealmStateError('$this is not managed');

ListHandle get handle {
Expand Down
12 changes: 1 addition & 11 deletions packages/realm_dart/lib/src/map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'dart:collection';

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

import 'dart:ffi';

import 'collections.dart';
import 'native/handle_base.dart';
Expand All @@ -19,7 +18,7 @@ import 'realm_class.dart';
import 'results.dart';

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

/// @nodoc
extension RealmMapInternal<T extends Object?> on RealmMap<T> {
@pragma('vm:never-inline')
void keepAlive() {
final self = this;
if (self is ManagedRealmMap<T>) {
realm.keepAlive();
self._handle.keepAlive();
}
}

ManagedRealmMap<T> asManaged() => this is ManagedRealmMap<T> ? this as ManagedRealmMap<T> : throw RealmStateError('$this is not managed');

MapHandle get handle {
Expand Down
3 changes: 0 additions & 3 deletions packages/realm_dart/lib/src/native/handle_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ abstract class HandleBase<T extends NativeType> implements Finalizable {
bool get released => pointer == nullptr;
final bool isUnowned;

@pragma('vm:never-inline')
void keepAlive() {}

HandleBase(this.pointer, int size) : isUnowned = false {
pointer.raiseLastErrorIfNull();
_finalizableHandle = realmLib.realm_attach_finalizer(this, pointer.cast(), size);
Expand Down
14 changes: 2 additions & 12 deletions packages/realm_dart/lib/src/realm_class.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

import 'dart:async';
import 'dart:ffi';
import 'dart:io';

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

/// @nodoc
extension RealmInternal on Realm {
@pragma('vm:never-inline')
void keepAlive() {
_handle.keepAlive();
final c = config;
if (c is FlexibleSyncConfiguration) {
c.keepAlive();
}
}

RealmHandle get handle {
if (_handle.released) {
throw RealmClosedError('Cannot access realm that has been closed');
Expand Down Expand Up @@ -864,7 +854,7 @@ extension RealmInternal on Realm {
}

/// @nodoc
abstract class NotificationsController implements Finalizable {
abstract class NotificationsController {
NotificationTokenHandle? handle;

NotificationTokenHandle subscribe();
Expand Down
18 changes: 3 additions & 15 deletions packages/realm_dart/lib/src/realm_object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

import 'dart:async';
import 'dart:ffi';

import 'package:collection/collection.dart';
import 'package:realm_common/realm_common.dart';
Expand Down Expand Up @@ -365,7 +364,7 @@ extension RealmEntityInternal on RealmEntity {
///
/// [RealmObject] should not be used directly as it is part of the generated class hierarchy. ex: `MyClass extends _MyClass with RealmObject`.
/// {@category Realm}
mixin RealmObjectBase on RealmEntity implements RealmObjectBaseMarker, Finalizable {
mixin RealmObjectBase on RealmEntity implements RealmObjectBaseMarker {
ObjectHandle? _handle;
RealmAccessor _accessor = RealmValuesAccessor();
static final Map<Type, RealmObjectBase Function()> _factories = <Type, RealmObjectBase Function()>{
Expand Down Expand Up @@ -646,12 +645,6 @@ extension EmbeddedObjectExtension on EmbeddedObject {
/// @nodoc
//RealmObject package internal members
extension RealmObjectInternal on RealmObjectBase {
@pragma('vm:never-inline')
void keepAlive() {
_realm?.keepAlive();
_handle?.keepAlive();
}

void manage(Realm realm, ObjectHandle handle, RealmCoreAccessor accessor, bool update) {
if (_handle != null) {
//most certainly a bug hence we throw an Error
Expand Down Expand Up @@ -726,7 +719,7 @@ class UserCallbackException extends RealmException {
}

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

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

/// @nodoc
extension RealmObjectChangesInternal<T extends RealmObject> on RealmObjectChanges<T> {
@pragma('vm:never-inline')
void keepAlive() {
_handle.keepAlive();
}
}
extension RealmObjectChangesInternal<T extends RealmObject> on RealmObjectChanges<T> {}

/// @nodoc
class RealmObjectNotificationsController<T extends RealmObjectBase> extends NotificationsController {
Expand Down
8 changes: 1 addition & 7 deletions packages/realm_dart/lib/src/results.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

import 'dart:async';
import 'dart:ffi';

import 'package:cancellation_token/cancellation_token.dart';

Expand All @@ -19,7 +18,7 @@ import 'realm_object.dart';
/// added to or deleted from the Realm that match the underlying query.
///
/// {@category Realm}
class RealmResults<T extends Object?> extends Iterable<T> with RealmEntity implements Finalizable {
class RealmResults<T extends Object?> extends Iterable<T> with RealmEntity {
final RealmObjectMetadata? _metadata;
final ResultsHandle _handle;
final int _skipOffset; // to support skip efficiently
Expand Down Expand Up @@ -278,11 +277,6 @@ extension RealmResultsOfRealmObject<T extends RealmObject> on RealmResults<T> {
/// @nodoc
//RealmResults package internal members
extension RealmResultsInternal on RealmResults {
@pragma('vm:never-inline')
void keepAlive() {
_handle.keepAlive();
}

ResultsHandle get handle {
if (_handle.released) {
throw RealmClosedError('Cannot access Results that belongs to a closed Realm');
Expand Down
8 changes: 1 addition & 7 deletions packages/realm_dart/lib/src/session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

import 'dart:async';
import 'dart:ffi';

import '../realm.dart';
import '../src/native/realm_bindings.dart';
Expand All @@ -14,7 +13,7 @@ import 'user.dart';
/// server. Sessions are always created by the SDK and vended out through various
/// APIs. The lifespans of sessions associated with Realms are managed automatically.
/// {@category Sync}
class Session implements Finalizable {
class Session {
final SessionHandle _handle;

/// The on-disk path of the file backing the [Realm] this [Session] represents
Expand Down Expand Up @@ -98,11 +97,6 @@ class ConnectionStateChange {
}

extension SessionInternal on Session {
@pragma('vm:never-inline')
void keepAlive() {
_handle.keepAlive();
}

static Session create(SessionHandle handle) => Session._(handle);

SessionHandle get handle {
Expand Down
3 changes: 1 addition & 2 deletions packages/realm_dart/lib/src/set.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import 'dart:core';
import 'dart:async';
import 'dart:collection';
import 'dart:ffi';

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

Expand All @@ -19,7 +18,7 @@ import 'collections.dart';
import 'results.dart';

/// RealmSet is a collection that contains no duplicate elements.
abstract class RealmSet<T extends Object?> extends SetBase<T> with RealmEntity implements Finalizable {
abstract class RealmSet<T extends Object?> extends SetBase<T> with RealmEntity {
RealmObjectMetadata? _metadata;

/// Gets a value indicating whether this collection is still valid to use.
Expand Down
Loading

0 comments on commit 8898319

Please sign in to comment.