Skip to content
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

[WIP] - More error handling (From Thomas) #34

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 33 additions & 29 deletions TightDbObjcDyn/TightDbObjcDyn.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@
objects = {

/* Begin PBXBuildFile section */
E9106BC61785E31400113590 /* data_type.mm in Sources */ = {isa = PBXBuildFile; fileRef = E91890E7177B71E400653D7A /* data_type.mm */; };
E9106BC71785E31400113590 /* enumerator.m in Sources */ = {isa = PBXBuildFile; fileRef = E91890E8177B71E400653D7A /* enumerator.m */; };
E9106BC81785E31400113590 /* err_handling.mm in Sources */ = {isa = PBXBuildFile; fileRef = E91890E9177B71E400653D7A /* err_handling.mm */; };
E9106BC91785E31400113590 /* get_subtable.m in Sources */ = {isa = PBXBuildFile; fileRef = E91890EA177B71E400653D7A /* get_subtable.m */; };
E9106BCA1785E31400113590 /* group_misc_2.m in Sources */ = {isa = PBXBuildFile; fileRef = E91890EB177B71E400653D7A /* group_misc_2.m */; };
E9106BCB1785E31400113590 /* group.m in Sources */ = {isa = PBXBuildFile; fileRef = E91890EC177B71E400653D7A /* group.m */; };
E9106BCC1785E31400113590 /* mixed.m in Sources */ = {isa = PBXBuildFile; fileRef = E91890ED177B71E400653D7A /* mixed.m */; };
E9106BCD1785E31400113590 /* shared_group.mm in Sources */ = {isa = PBXBuildFile; fileRef = E91890EF177B71E400653D7A /* shared_group.mm */; };
E9106BCE1785E31400113590 /* subtable.m in Sources */ = {isa = PBXBuildFile; fileRef = E91890F0177B71E400653D7A /* subtable.m */; };
E9106BCF1785E31400113590 /* table_delete_all.m in Sources */ = {isa = PBXBuildFile; fileRef = E91890F1177B71E400653D7A /* table_delete_all.m */; };
E9106BD01785E31400113590 /* table.m in Sources */ = {isa = PBXBuildFile; fileRef = E91890F2177B71E400653D7A /* table.m */; };
E9106BD11785E31400113590 /* tutorial.m in Sources */ = {isa = PBXBuildFile; fileRef = E91890F4177B71E400653D7A /* tutorial.m */; };
E9106BD21785E31400113590 /* threads.m in Sources */ = {isa = PBXBuildFile; fileRef = E94EA3E017831986001AE3DA /* threads.m */; };
E918909D177B677900653D7A /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E918909C177B677900653D7A /* Cocoa.framework */; };
E91890AF177B677900653D7A /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E91890AE177B677900653D7A /* SenTestingKit.framework */; };
E91890B0177B677900653D7A /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E918909C177B677900653D7A /* Cocoa.framework */; };
Expand All @@ -29,20 +42,7 @@
E91890E4177B67AB00653D7A /* tightdb.h in Headers */ = {isa = PBXBuildFile; fileRef = E91890D3177B67AB00653D7A /* tightdb.h */; };
E91890E5177B67AB00653D7A /* type.h in Headers */ = {isa = PBXBuildFile; fileRef = E91890D4177B67AB00653D7A /* type.h */; };
E91890E6177B67AB00653D7A /* util.hpp in Headers */ = {isa = PBXBuildFile; fileRef = E91890D5177B67AB00653D7A /* util.hpp */; };
E91890F5177B71E400653D7A /* data_type.mm in Sources */ = {isa = PBXBuildFile; fileRef = E91890E7177B71E400653D7A /* data_type.mm */; };
E91890F6177B71E400653D7A /* enumerator.m in Sources */ = {isa = PBXBuildFile; fileRef = E91890E8177B71E400653D7A /* enumerator.m */; };
E91890F7177B71E400653D7A /* err_handling.mm in Sources */ = {isa = PBXBuildFile; fileRef = E91890E9177B71E400653D7A /* err_handling.mm */; };
E91890F8177B71E400653D7A /* get_subtable.m in Sources */ = {isa = PBXBuildFile; fileRef = E91890EA177B71E400653D7A /* get_subtable.m */; };
E91890F9177B71E400653D7A /* group_misc_2.m in Sources */ = {isa = PBXBuildFile; fileRef = E91890EB177B71E400653D7A /* group_misc_2.m */; };
E91890FA177B71E400653D7A /* group.m in Sources */ = {isa = PBXBuildFile; fileRef = E91890EC177B71E400653D7A /* group.m */; };
E91890FB177B71E400653D7A /* mixed.m in Sources */ = {isa = PBXBuildFile; fileRef = E91890ED177B71E400653D7A /* mixed.m */; };
E91890FC177B71E400653D7A /* query.m in Sources */ = {isa = PBXBuildFile; fileRef = E91890EE177B71E400653D7A /* query.m */; };
E91890FD177B71E400653D7A /* shared_group.m in Sources */ = {isa = PBXBuildFile; fileRef = E91890EF177B71E400653D7A /* shared_group.m */; };
E91890FE177B71E400653D7A /* subtable.m in Sources */ = {isa = PBXBuildFile; fileRef = E91890F0177B71E400653D7A /* subtable.m */; };
E91890FF177B71E400653D7A /* table_delete_all.m in Sources */ = {isa = PBXBuildFile; fileRef = E91890F1177B71E400653D7A /* table_delete_all.m */; };
E9189100177B71E400653D7A /* table.m in Sources */ = {isa = PBXBuildFile; fileRef = E91890F2177B71E400653D7A /* table.m */; };
E9189101177B71E400653D7A /* template.m in Sources */ = {isa = PBXBuildFile; fileRef = E91890F3177B71E400653D7A /* template.m */; };
E9189102177B71E400653D7A /* tutorial.m in Sources */ = {isa = PBXBuildFile; fileRef = E91890F4177B71E400653D7A /* tutorial.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -91,12 +91,14 @@
E91890EC177B71E400653D7A /* group.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = group.m; path = ../../src/tightdb/objc/test/group.m; sourceTree = "<group>"; };
E91890ED177B71E400653D7A /* mixed.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = mixed.m; path = ../../src/tightdb/objc/test/mixed.m; sourceTree = "<group>"; };
E91890EE177B71E400653D7A /* query.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = query.m; path = ../../src/tightdb/objc/test/query.m; sourceTree = "<group>"; };
E91890EF177B71E400653D7A /* shared_group.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = shared_group.m; path = ../../src/tightdb/objc/test/shared_group.m; sourceTree = "<group>"; };
E91890EF177B71E400653D7A /* shared_group.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = shared_group.mm; path = ../../src/tightdb/objc/test/shared_group.mm; sourceTree = "<group>"; };
E91890F0177B71E400653D7A /* subtable.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = subtable.m; path = ../../src/tightdb/objc/test/subtable.m; sourceTree = "<group>"; };
E91890F1177B71E400653D7A /* table_delete_all.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = table_delete_all.m; path = ../../src/tightdb/objc/test/table_delete_all.m; sourceTree = "<group>"; };
E91890F2177B71E400653D7A /* table.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = table.m; path = ../../src/tightdb/objc/test/table.m; sourceTree = "<group>"; };
E91890F3177B71E400653D7A /* template.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = template.m; path = ../../src/tightdb/objc/test/template.m; sourceTree = "<group>"; };
E91890F4177B71E400653D7A /* tutorial.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = tutorial.m; path = ../../src/tightdb/objc/test/tutorial.m; sourceTree = "<group>"; };
E94EA3E017831986001AE3DA /* threads.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = threads.m; path = ../../src/tightdb/objc/test/threads.m; sourceTree = "<group>"; };
E9F2A7B11781FAB600292661 /* TestHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TestHelper.h; path = ../../src/tightdb/objc/test/TestHelper.h; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -204,12 +206,14 @@
E91890EC177B71E400653D7A /* group.m */,
E91890ED177B71E400653D7A /* mixed.m */,
E91890EE177B71E400653D7A /* query.m */,
E91890EF177B71E400653D7A /* shared_group.m */,
E91890EF177B71E400653D7A /* shared_group.mm */,
E91890F0177B71E400653D7A /* subtable.m */,
E91890F1177B71E400653D7A /* table_delete_all.m */,
E91890F2177B71E400653D7A /* table.m */,
E91890F3177B71E400653D7A /* template.m */,
E91890F4177B71E400653D7A /* tutorial.m */,
E9F2A7B11781FAB600292661 /* TestHelper.h */,
E91890F3177B71E400653D7A /* template.m */,
E94EA3E017831986001AE3DA /* threads.m */,
E91890B5177B677900653D7A /* Supporting Files */,
);
path = TightDbObjcDynTests;
Expand Down Expand Up @@ -356,20 +360,20 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
E91890F5177B71E400653D7A /* data_type.mm in Sources */,
E91890F6177B71E400653D7A /* enumerator.m in Sources */,
E91890F7177B71E400653D7A /* err_handling.mm in Sources */,
E91890F8177B71E400653D7A /* get_subtable.m in Sources */,
E91890F9177B71E400653D7A /* group_misc_2.m in Sources */,
E91890FA177B71E400653D7A /* group.m in Sources */,
E91890FB177B71E400653D7A /* mixed.m in Sources */,
E91890FC177B71E400653D7A /* query.m in Sources */,
E91890FD177B71E400653D7A /* shared_group.m in Sources */,
E91890FE177B71E400653D7A /* subtable.m in Sources */,
E91890FF177B71E400653D7A /* table_delete_all.m in Sources */,
E9189100177B71E400653D7A /* table.m in Sources */,
E9189101177B71E400653D7A /* template.m in Sources */,
E9189102177B71E400653D7A /* tutorial.m in Sources */,
E9106BC61785E31400113590 /* data_type.mm in Sources */,
E9106BC71785E31400113590 /* enumerator.m in Sources */,
E9106BC81785E31400113590 /* err_handling.mm in Sources */,
E9106BC91785E31400113590 /* get_subtable.m in Sources */,
E9106BCA1785E31400113590 /* group_misc_2.m in Sources */,
E9106BCB1785E31400113590 /* group.m in Sources */,
E9106BCC1785E31400113590 /* mixed.m in Sources */,
E9106BCD1785E31400113590 /* shared_group.mm in Sources */,
E9106BCE1785E31400113590 /* subtable.m in Sources */,
E9106BCF1785E31400113590 /* table_delete_all.m in Sources */,
E9106BD01785E31400113590 /* table.m in Sources */,
E9106BD11785E31400113590 /* tutorial.m in Sources */,
E9106BD21785E31400113590 /* threads.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
7 changes: 7 additions & 0 deletions src/tightdb/objc/cursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,23 @@
@interface TightdbAccessor: NSObject
-(id)initWithCursor:(TightdbCursor *)cursor columnId:(size_t)columnId;
-(BOOL)getBool;
-(NSNumber *)getBoolWithError:(NSError *__autoreleasing *)error;
-(BOOL)setBool:(BOOL)value;
-(BOOL)setBool:(BOOL)value error:(NSError *__autoreleasing *)error;
-(int64_t)getInt;
-(NSNumber *)getIntWithError:(NSError *__autoreleasing *)error;
-(BOOL)setInt:(int64_t)value;
-(BOOL)setInt:(int64_t)value error:(NSError *__autoreleasing *)error;
-(float)getFloat;
-(NSNumber *)getFloatWithError:(NSError *__autoreleasing *)error;
-(BOOL)setFloat:(float)value;
-(BOOL)setFloat:(float)value error:(NSError *__autoreleasing *)error;
-(double)getDouble;
-(NSNumber *)getDoubleWithError:(NSError *__autoreleasing *)error;
-(BOOL)setDouble:(double)value;
-(BOOL)setDouble:(double)value error:(NSError *__autoreleasing *)error;
-(NSString *)getString;
-(NSString *)getStringWithError:(NSError *__autoreleasing *)error;
-(BOOL)setString:(NSString *)value;
-(BOOL)setString:(NSString *)value error:(NSError *__autoreleasing *)error;
-(TightdbBinary *)getBinary;
Expand All @@ -57,10 +62,12 @@
-(BOOL)setBinary:(const char *)data size:(size_t)size;
-(BOOL)setBinary:(const char *)data size:(size_t)size error:(NSError *__autoreleasing *)error;
-(time_t)getDate;
-(NSNumber *)getDateWithError:(NSError *__autoreleasing *)error;
-(BOOL)setDate:(time_t)value;
-(BOOL)setDate:(time_t)value error:(NSError *__autoreleasing *)error;
-(id)getSubtable:(Class)obj;
-(TightdbMixed *)getMixed;
-(TightdbMixed *)getMixedWithError:(NSError *__autoreleasing *)error;
-(BOOL)setMixed:(TightdbMixed *)value;
-(BOOL)setMixed:(TightdbMixed *)value error:(NSError *__autoreleasing *)error;
@end
51 changes: 43 additions & 8 deletions src/tightdb/objc/cursor_objc.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

using namespace std;

#ifdef TIGHTDB_DEBUG
_Atomic(int) TightdbCursorAllocateCount = 0;
#endif

@interface TightdbCursor()
@property (nonatomic, weak) TightdbTable *table;
Expand All @@ -25,6 +28,10 @@ -(id)initWithTable:(TightdbTable *)table ndx:(size_t)ndx
{
self = [super init];
if (self) {
#ifdef TIGHTDB_DEBUG
NSLog(@"TightdbCursor init");
++TightdbCursorAllocateCount;
#endif
_table = table;
_ndx = ndx;
}
Expand All @@ -38,6 +45,7 @@ -(void)dealloc
{
#ifdef TIGHTDB_DEBUG
NSLog(@"TightdbCursor dealloc");
--TightdbCursorAllocateCount;
#endif
_table = nil;
}
Expand All @@ -60,10 +68,13 @@ -(id)initWithCursor:(TightdbCursor *)cursor columnId:(size_t)columnId
return self;
}


-(BOOL)getBool
{
return [_cursor.table getBool:_columnId ndx:_cursor.ndx];
return [[self getBoolWithError:nil] boolValue];
}
-(NSNumber *)getBoolWithError:(NSError *__autoreleasing *)error
{
return [_cursor.table getBool:_columnId ndx:_cursor.ndx error:error];
}

-(BOOL)setBool:(BOOL)value
Expand All @@ -78,7 +89,11 @@ -(BOOL)setBool:(BOOL)value error:(NSError *__autoreleasing *)error

-(int64_t)getInt
{
return [_cursor.table get:_columnId ndx:_cursor.ndx];
return [[self getIntWithError:nil] longLongValue];
}
-(NSNumber *)getIntWithError:(NSError *__autoreleasing *)error
{
return [_cursor.table get:_columnId ndx:_cursor.ndx error:error];
}

-(BOOL)setInt:(int64_t)value
Expand All @@ -93,7 +108,11 @@ -(BOOL)setInt:(int64_t)value error:(NSError *__autoreleasing *)error

-(float)getFloat
{
return [_cursor.table getFloat:_columnId ndx:_cursor.ndx];
return [[self getFloatWithError:nil] floatValue];
}
-(NSNumber *)getFloatWithError:(NSError *__autoreleasing *)error
{
return [_cursor.table getFloat:_columnId ndx:_cursor.ndx error:error];
}

-(BOOL)setFloat:(float)value
Expand All @@ -108,7 +127,11 @@ -(BOOL)setFloat:(float)value error:(NSError *__autoreleasing *)error

-(double)getDouble
{
return [_cursor.table getDouble:_columnId ndx:_cursor.ndx];
return [[self getDoubleWithError:nil] doubleValue];
}
-(NSNumber *)getDoubleWithError:(NSError *__autoreleasing *)error
{
return [_cursor.table getDouble:_columnId ndx:_cursor.ndx error:error];
}

-(BOOL)setDouble:(double)value
Expand All @@ -123,7 +146,11 @@ -(BOOL)setDouble:(double)value error:(NSError *__autoreleasing *)error

-(NSString *)getString
{
return [_cursor.table getString:_columnId ndx:_cursor.ndx];
return [self getStringWithError:nil];
}
-(NSString *)getStringWithError:(NSError *__autoreleasing *)error
{
return [_cursor.table getString:_columnId ndx:_cursor.ndx error:error];
}

-(BOOL)setString:(NSString *)value
Expand Down Expand Up @@ -163,7 +190,11 @@ -(BOOL)setBinary:(const char *)data size:(size_t)size error:(NSError *__autorele

-(time_t)getDate
{
return [_cursor.table getDate:_columnId ndx:_cursor.ndx];
return [[self getDateWithError:nil] longLongValue];
}
-(NSNumber *)getDateWithError:(NSError *__autoreleasing *)error
{
return [_cursor.table getDate:_columnId ndx:_cursor.ndx error:error];
}

-(BOOL)setDate:(time_t)value
Expand All @@ -183,7 +214,11 @@ -(id)getSubtable:(Class)obj

-(TightdbMixed *)getMixed
{
return [_cursor.table getMixed:_columnId ndx:_cursor.ndx];
return [self getMixedWithError:nil];
}
-(TightdbMixed *)getMixedWithError:(NSError *__autoreleasing *)error
{
return [_cursor.table getMixed:_columnId ndx:_cursor.ndx error:error];
}

-(BOOL)setMixed:(TightdbMixed *)value
Expand Down
30 changes: 23 additions & 7 deletions src/tightdb/objc/group_objc.mm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

using namespace std;

#ifdef TIGHTDB_DEBUG
_Atomic(int) TightdbGroupAllocateCount = 0;
#endif

@interface TightdbGroup()
@property(nonatomic) tightdb::Group *group;
Expand All @@ -34,8 +37,11 @@ +(TightdbGroup *)groupWithError:(NSError *__autoreleasing *)error
TightdbGroup *group = [[TightdbGroup alloc] init];
TIGHTDB_EXCEPTION_ERRHANDLER(
group.group = new tightdb::Group();
, @"com.tightdb.group", nil);
, @"com.tightdb.group", return nil);
group.readOnly = NO;
#ifdef TIGHTDB_DEBUG
++TightdbGroupAllocateCount;
#endif
return group;
}

Expand All @@ -45,6 +51,9 @@ +(TightdbGroup *)groupTightdbGroup:(tightdb::Group *)tightdbGroup readOnly:(BOOL
TightdbGroup *group = [[TightdbGroup alloc] init];
group.group = tightdbGroup;
group.readOnly = readOnly;
#ifdef TIGHTDB_DEBUG
++TightdbGroupAllocateCount;
#endif
return group;
}

Expand All @@ -59,12 +68,15 @@ +(TightdbGroup *)groupWithFilename:(NSString *)filename error:(NSError **)error
tightdb::Group* group;
TIGHTDB_EXCEPTION_ERRHANDLER(
group = new tightdb::Group(tightdb::StringData(ObjcStringAccessor(filename)));
, @"com.tightdb.group", nil);
, @"com.tightdb.group", return nil);
TightdbGroup* group2 = [[TightdbGroup alloc] init];
if (group2) {
group2.group = group;
group2.readOnly = NO;
}
#ifdef TIGHTDB_DEBUG
++TightdbGroupAllocateCount;
#endif
return group2;
}

Expand All @@ -78,10 +90,13 @@ +(TightdbGroup *)groupWithBuffer:(const char *)data size:(size_t)size error:(NSE
tightdb::Group* group;
TIGHTDB_EXCEPTION_ERRHANDLER(
group = new tightdb::Group(tightdb::BinaryData(data, size));
, @"com.tightdb.group", nil);
, @"com.tightdb.group", return nil);
TightdbGroup* group2 = [[TightdbGroup alloc] init];
group2.group = group;
group2.readOnly = NO;
#ifdef TIGHTDB_DEBUG
++TightdbGroupAllocateCount;
#endif
return group2;
}

Expand All @@ -94,6 +109,7 @@ -(void)dealloc
{
#ifdef TIGHTDB_DEBUG
NSLog(@"TightdbGroup dealloc");
--TightdbGroupAllocateCount;
#endif
delete _group;
}
Expand All @@ -117,7 +133,7 @@ -(BOOL)write:(NSString *)filePath error:(NSError *__autoreleasing *)error
{
TIGHTDB_EXCEPTION_ERRHANDLER(
_group->write(tightdb::StringData(ObjcStringAccessor(filePath)));
, @"com.tightdb.group", NO);
, @"com.tightdb.group", return NO);
return YES;
}

Expand All @@ -132,7 +148,7 @@ -(const char*)writeToMem:(size_t*)size error:(NSError *__autoreleasing *)error
tightdb::BinaryData buffer = _group->write_to_mem();
*size = buffer.size();
return buffer.data();
, @"com.tightdb.group", nil);
, @"com.tightdb.group", return nil);
}

-(BOOL)hasTable:(NSString *)name
Expand Down Expand Up @@ -161,7 +177,7 @@ -(id)getTable:(NSString *)name error:(NSError *__autoreleasing *)error
if (TIGHTDB_UNLIKELY(!table)) return nil;
TIGHTDB_EXCEPTION_ERRHANDLER(
[table setTable:_group->get_table(ObjcStringAccessor(name))];
, @"com.tightdb.group", nil);
, @"com.tightdb.group", return nil);
[table setParent:self];
[table setReadOnly:_readOnly];
return table;
Expand All @@ -181,7 +197,7 @@ -(id)getTable:(NSString *)name withClass:(__unsafe_unretained Class)classObj err
tightdb::TableRef r = tightdb::LangBindHelper::get_table_ptr(_group, ObjcStringAccessor(name),
was_created)->get_table_ref();
[table setTable:move(r)];
, @"com.tightdb.group", nil);
, @"com.tightdb.group", return nil);
[table setParent:self];
[table setReadOnly:_readOnly];
if (was_created) {
Expand Down
Loading