Skip to content

Commit

Permalink
I have a feeling there might be a race condition lurking around here…
Browse files Browse the repository at this point in the history
  • Loading branch information
dmoagx committed Jun 15, 2015
1 parent 7335464 commit 0a2f79c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Source/SPDataStorage.m
Expand Up @@ -31,6 +31,7 @@
#import "SPDataStorage.h"
#import "SPObjectAdditions.h"
#import <SPMySQL/SPMySQLStreamingResultStore.h>
#include <stdlib.h>

@interface SPDataStorage (Private_API)

Expand Down Expand Up @@ -80,7 +81,7 @@ - (void) setDataStorage:(SPMySQLStreamingResultStore *)newDataStorage updatingEx
[self resultStoreDidFinishLoadingData:dataStorage];
}

unloadedColumns = malloc(numberOfColumns * sizeof(BOOL));
unloadedColumns = calloc(numberOfColumns, sizeof(BOOL));
for (i = 0; i < numberOfColumns; i++) {
unloadedColumns[i] = NO;
}
Expand Down Expand Up @@ -110,6 +111,7 @@ - (NSMutableArray *) rowContentsAtIndex:(NSUInteger)anIndex

// Modify unloaded cells as appropriate
for (NSUInteger i = 0; i < numberOfColumns; i++) {
NSAssert(unloadedColumns != NULL, @"unloadedColumns not loaded!");
if (unloadedColumns[i]) {
CFArraySetValueAtIndex((CFMutableArrayRef)dataArray, i, [SPNotLoaded notLoaded]);
}
Expand Down Expand Up @@ -138,6 +140,7 @@ - (id) cellDataAtRow:(NSUInteger)rowIndex column:(NSUInteger)columnIndex
}

// If the specified column is not loaded, return a SPNotLoaded reference
NSAssert(unloadedColumns != NULL, @"unloadedColumns not loaded!");
if (unloadedColumns[columnIndex]) {
return [SPNotLoaded notLoaded];
}
Expand Down Expand Up @@ -172,6 +175,7 @@ - (id) cellPreviewAtRow:(NSUInteger)rowIndex column:(NSUInteger)columnIndex prev
}

// If the specified column is not loaded, return a SPNotLoaded reference
NSAssert(unloadedColumns != NULL, @"unloadedColumns not loaded!");
if (unloadedColumns[columnIndex]) {
return [SPNotLoaded notLoaded];
}
Expand Down Expand Up @@ -199,6 +203,7 @@ - (BOOL) cellIsNullOrUnloadedAtRow:(NSUInteger)rowIndex column:(NSUInteger)colum
[NSException raise:NSRangeException format:@"Requested storage column (col %llu) beyond bounds (%llu)", (unsigned long long)columnIndex, (unsigned long long)numberOfColumns];
}

NSAssert(unloadedColumns != NULL, @"unloadedColumns not loaded!");
if (unloadedColumns[columnIndex]) {
return YES;
}
Expand Down Expand Up @@ -232,6 +237,7 @@ - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state object

// Modify unloaded cells as appropriate
for (NSUInteger i = 0; i < numberOfColumns; i++) {
NSAssert(unloadedColumns != NULL, @"unloadedColumns not loaded!");
if (unloadedColumns[i]) {
CFArraySetValueAtIndex((CFMutableArrayRef)targetRow, i, [SPNotLoaded notLoaded]);
}
Expand Down Expand Up @@ -391,6 +397,7 @@ - (void) setColumnAsUnloaded:(NSUInteger)columnIndex
if (columnIndex >= numberOfColumns) {
[NSException raise:NSRangeException format:@"Invalid column set as unloaded; requested column index (%llu) beyond bounds (%llu)", (unsigned long long)columnIndex, (unsigned long long)numberOfColumns];
}
NSAssert(unloadedColumns != NULL, @"unloadedColumns not loaded!");
unloadedColumns[columnIndex] = YES;
}

Expand Down

0 comments on commit 0a2f79c

Please sign in to comment.