Skip to content

Commit

Permalink
remove schema copies in RLMCreateTables - now the callers responsibli…
Browse files Browse the repository at this point in the history
…ty to pass in a properly copied schema
  • Loading branch information
alazier committed Jan 29, 2015
1 parent 376de17 commit 26d809e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 6 additions & 0 deletions Realm/RLMObjectStore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,16 @@ extern "C" {
// updates a Realm to a given target schema/version
// creates tables as necessary
// optionally runs migration block if schema is out of date
//
// NOTE: the schema passed in will be set on the Realm and may later be mutated. sharing a targetSchema accross
// even the same Realm with different column orderings will cause issues
NSError *RLMUpdateRealmToSchemaVersion(RLMRealm *realm, NSUInteger version, RLMSchema *targetSchema, NSError *(^migrationBlock)());

// sets a realm's schema to a copy of targetSchema
// caches table accessors on each objectSchema
//
// NOTE: the schema passed in will be set on the Realm and may later be mutated. sharing a targetSchema accross
// even the same Realm with different column orderings will cause issues
void RLMRealmSetSchema(RLMRealm *realm, RLMSchema *targetSchema, bool verifyAndAlignColumns);

// create or get cached accessors for the given schema
Expand Down
4 changes: 2 additions & 2 deletions Realm/RLMObjectStore.mm
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void RLMRealmCreateAccessors(RLMSchema *schema) {
objectSchema.accessorClass = RLMAccessorClassForObjectClass(objectSchema.objectClass, objectSchema, prefix);
}
}
[s_accessorSchema addObject:[schema copy]];
[s_accessorSchema addObject:schema];
}
}

Expand Down Expand Up @@ -173,7 +173,7 @@ static bool RLMRealmCreateTables(RLMRealm *realm, RLMSchema *targetSchema, bool
// create metadata tables if neded
bool changed = RLMRealmCreateMetadataTables(realm);

realm.schema = [targetSchema copy];
realm.schema = targetSchema;

// first pass to create missing tables
NSMutableArray *objectSchemaToUpdate = [NSMutableArray array];
Expand Down
4 changes: 2 additions & 2 deletions Realm/RLMRealm.mm
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ + (instancetype)realmWithPath:(NSString *)path
}
else {
// if we are the first realm at this path, set/align schema or perform migration if needed
RLMSchema *targetSchema = customSchema ?: RLMSchema.sharedSchema;
RLMSchema *targetSchema = customSchema ?: [RLMSchema.sharedSchema copy];
NSError *error = RLMUpdateRealmToSchemaVersion(realm, schemaVersionForPath(path), targetSchema, [realm migrationBlock:key]);
if (error) {
setOrThrowError(error, outError);
Expand Down Expand Up @@ -900,7 +900,7 @@ + (NSError *)migrateRealmAtPath:(NSString *)realmPath key:(NSData *)key {
if (error)
return error;

return RLMUpdateRealmToSchemaVersion(realm, schemaVersionForPath(realmPath), RLMSchema.sharedSchema, [realm migrationBlock:key]);
return RLMUpdateRealmToSchemaVersion(realm, schemaVersionForPath(realmPath), [RLMSchema.sharedSchema copy], [realm migrationBlock:key]);
}

- (RLMObject *)createObject:(NSString *)className withObject:(id)object {
Expand Down

0 comments on commit 26d809e

Please sign in to comment.