Firstly, I’d just like to explain what the ‘Twitpocalpyse’ is to all those who don’t know:
On Friday evening, the number of tweets exceeded 2,147,483,6471. While that doesn’t seem like a round number, it’s the largest number that can be stored as the data type known as a “signed integer.” Once that number was exceeded, some versions of some Twitter client apps could break in a fashion similar to what was expected during the Y2K “millennium bug” era.
As I am using the MGTwitterEngine, I thought I’d like to post up how to fix the bug, with thanks to someone named kleinman.
http://gist.github.com/111435
add in MGTWitterYAJLParser.m
-------
int process_yajl_number(void *ctx, const char *numberVal, int size)
{
id self = ctx;
if (currentKey) {
// We alloc a proper buffer and copy the chars in it along with a null
char *zeroTerminatedBuf = calloc(1, size+1);
memcpy(zeroTerminatedBuf, numberVal, size);
// Then we put everything in an NSString so we can initialize our NSNumber with the corresponding long long
NSString *rawValue = [NSString stringWithCString:zeroTerminatedBuf];
NSNumber *longLongValue = [NSNumber numberWithLongLong:[rawValue longLongValue]];
[self addValue:longLongValue forKey:currentKey];
free(zeroTerminatedBuf);
[currentKey release];
currentKey = nil;
}
return 1;
}
static yajl_callbacks callbacks = {
process_yajl_null,
process_yajl_boolean,
process_yajl_integer,
process_yajl_double,
// Put number callback so we can properly handle a long long value
// Martin Dufort - WhereCloud Inc
process_yajl_number,
//
process_yajl_string,
process_yajl_start_map,
process_yajl_map_key,
process_yajl_end_map,
process_yajl_start_array,
process_yajl_end_array
};
