Skip to content

Commit

Permalink
Format the runtime sources.
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasvl committed Sep 23, 2022
1 parent 5d0b217 commit 189f632
Show file tree
Hide file tree
Showing 14 changed files with 677 additions and 967 deletions.
47 changes: 21 additions & 26 deletions objectivec/GPBArray.m
Original file line number Diff line number Diff line change
Expand Up @@ -2056,19 +2056,15 @@ + (instancetype)arrayWithValidationFunction:(GPBEnumValidationFunc)func {
return [[[self alloc] initWithValidationFunction:func] autorelease];
}

+ (instancetype)arrayWithValidationFunction:(GPBEnumValidationFunc)func
rawValue:(int32_t)value {
return [[[self alloc] initWithValidationFunction:func
rawValues:&value
count:1] autorelease];
+ (instancetype)arrayWithValidationFunction:(GPBEnumValidationFunc)func rawValue:(int32_t)value {
return [[[self alloc] initWithValidationFunction:func rawValues:&value count:1] autorelease];
}

+ (instancetype)arrayWithValueArray:(GPBEnumArray *)array {
return [[(GPBEnumArray*)[self alloc] initWithValueArray:array] autorelease];
return [[(GPBEnumArray *)[self alloc] initWithValueArray:array] autorelease];
}

+ (instancetype)arrayWithValidationFunction:(GPBEnumValidationFunc)func
capacity:(NSUInteger)count {
+ (instancetype)arrayWithValidationFunction:(GPBEnumValidationFunc)func capacity:(NSUInteger)count {
return [[[self alloc] initWithValidationFunction:func capacity:count] autorelease];
}

Expand All @@ -2091,7 +2087,7 @@ - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
}

- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
rawValues:(const int32_t [])values
rawValues:(const int32_t[])values
count:(NSUInteger)count {
self = [self initWithValidationFunction:func];
if (self) {
Expand All @@ -2103,17 +2099,16 @@ - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
_count = count;
} else {
[self release];
[NSException raise:NSMallocException
format:@"Failed to allocate %lu bytes",
(unsigned long)(count * sizeof(int32_t))];
[NSException
raise:NSMallocException
format:@"Failed to allocate %lu bytes", (unsigned long)(count * sizeof(int32_t))];
}
}
}
return self;
}

- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
capacity:(NSUInteger)count {
- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func capacity:(NSUInteger)count {
self = [self initWithValidationFunction:func];
if (self && count) {
[self internalResizeToCapacity:count];
Expand All @@ -2122,10 +2117,9 @@ - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
}

- (instancetype)copyWithZone:(NSZone *)zone {
return [[GPBEnumArray allocWithZone:zone]
initWithValidationFunction:_validationFunc
rawValues:_values
count:_count];
return [[GPBEnumArray allocWithZone:zone] initWithValidationFunction:_validationFunc
rawValues:_values
count:_count];
}

// Disable clang-format for the macros.
Expand Down Expand Up @@ -2197,7 +2191,7 @@ - (void)enumerateRawValuesWithOptions:(NSEnumerationOptions)opts
// clang-format on

- (int32_t)valueAtIndex:(NSUInteger)index {
// clang-format off
// clang-format off
//%PDDM-EXPAND VALIDATE_RANGE(index, _count)
// This block of code is generated, do not edit it directly.

Expand All @@ -2207,7 +2201,7 @@ - (int32_t)valueAtIndex:(NSUInteger)index {
(unsigned long)index, (unsigned long)_count];
}
//%PDDM-EXPAND-END VALIDATE_RANGE(index, _count)
// clang-format on
// clang-format on
int32_t result = _values[index];
if (!_validationFunc(result)) {
result = kGPBUnrecognizedEnumeratorValue;
Expand All @@ -2216,7 +2210,7 @@ - (int32_t)valueAtIndex:(NSUInteger)index {
}

- (int32_t)rawValueAtIndex:(NSUInteger)index {
// clang-format off
// clang-format off
//%PDDM-EXPAND VALIDATE_RANGE(index, _count)
// This block of code is generated, do not edit it directly.

Expand All @@ -2226,16 +2220,18 @@ - (int32_t)rawValueAtIndex:(NSUInteger)index {
(unsigned long)index, (unsigned long)_count];
}
//%PDDM-EXPAND-END VALIDATE_RANGE(index, _count)
// clang-format on
// clang-format on
return _values[index];
}

- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop))block {
- (void)enumerateValuesWithBlock:(void(NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop))
block {
[self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block];
}

- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
usingBlock:(void (NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop))block {
usingBlock:(void(NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop))
block {
// NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok).
BOOL stop = NO;
GPBEnumValidationFunc func = _validationFunc;
Expand Down Expand Up @@ -2472,8 +2468,7 @@ @implementation GPBAutocreatedArray {
}

- (void)dealloc {
NSAssert(!_autocreator,
@"%@: Autocreator must be cleared before release, autocreator: %@",
NSAssert(!_autocreator, @"%@: Autocreator must be cleared before release, autocreator: %@",
[self class], _autocreator);
[_array release];
[super dealloc];
Expand Down
62 changes: 24 additions & 38 deletions objectivec/GPBCodedInputStream.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
#import "GPBUtilities_PackagePrivate.h"
#import "GPBWireFormat.h"

NSString *const GPBCodedInputStreamException =
GPBNSStringifySymbol(GPBCodedInputStreamException);
NSString *const GPBCodedInputStreamException = GPBNSStringifySymbol(GPBCodedInputStreamException);

NSString *const GPBCodedInputStreamUnderlyingErrorKey =
GPBNSStringifySymbol(GPBCodedInputStreamUnderlyingErrorKey);
Expand All @@ -55,16 +54,14 @@
static void RaiseException(NSInteger code, NSString *reason) {
NSDictionary *errorInfo = nil;
if ([reason length]) {
errorInfo = @{ GPBErrorReasonKey: reason };
errorInfo = @{GPBErrorReasonKey : reason};
}
NSError *error = [NSError errorWithDomain:GPBCodedInputStreamErrorDomain
code:code
userInfo:errorInfo];

NSDictionary *exceptionInfo =
@{ GPBCodedInputStreamUnderlyingErrorKey: error };
[[NSException exceptionWithName:GPBCodedInputStreamException
reason:reason
NSDictionary *exceptionInfo = @{GPBCodedInputStreamUnderlyingErrorKey : error};
[[NSException exceptionWithName:GPBCodedInputStreamException reason:reason
userInfo:exceptionInfo] raise];
}

Expand Down Expand Up @@ -105,7 +102,7 @@ static int32_t ReadRawLittleEndian32(GPBCodedInputStreamState *state) {
static int64_t ReadRawLittleEndian64(GPBCodedInputStreamState *state) {
CheckSize(state, sizeof(int64_t));
// Not using OSReadLittleInt64 because it has undocumented dependency
// on reads being aligned.
// on reads being aligned.
int64_t value;
memcpy(&value, state->bytes + state->bufferPos, sizeof(int64_t));
value = OSSwapLittleToHostInt64(value);
Expand Down Expand Up @@ -215,8 +212,7 @@ int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state) {
state->lastTag = ReadRawVarint32(state);
// Tags have to include a valid wireformat.
if (!GPBWireFormatIsValidTag(state->lastTag)) {
RaiseException(GPBCodedInputStreamErrorInvalidTag,
@"Invalid wireformat in tag.");
RaiseException(GPBCodedInputStreamErrorInvalidTag, @"Invalid wireformat in tag.");
}
// Zero is not a valid field number.
if (GPBWireFormatGetTagFieldNumber(state->lastTag) == 0) {
Expand All @@ -226,8 +222,7 @@ int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state) {
return state->lastTag;
}

NSString *GPBCodedInputStreamReadRetainedString(
GPBCodedInputStreamState *state) {
NSString *GPBCodedInputStreamReadRetainedString(GPBCodedInputStreamState *state) {
int32_t size = ReadRawVarint32(state);
NSString *result;
if (size == 0) {
Expand All @@ -254,28 +249,24 @@ int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state) {
int32_t size = ReadRawVarint32(state);
if (size < 0) return nil;
CheckSize(state, size);
NSData *result = [[NSData alloc] initWithBytes:state->bytes + state->bufferPos
length:size];
NSData *result = [[NSData alloc] initWithBytes:state->bytes + state->bufferPos length:size];
state->bufferPos += size;
return result;
}

NSData *GPBCodedInputStreamReadRetainedBytesNoCopy(
GPBCodedInputStreamState *state) {
NSData *GPBCodedInputStreamReadRetainedBytesNoCopy(GPBCodedInputStreamState *state) {
int32_t size = ReadRawVarint32(state);
if (size < 0) return nil;
CheckSize(state, size);
// Cast is safe because freeWhenDone is NO.
NSData *result = [[NSData alloc]
initWithBytesNoCopy:(void *)(state->bytes + state->bufferPos)
length:size
freeWhenDone:NO];
NSData *result = [[NSData alloc] initWithBytesNoCopy:(void *)(state->bytes + state->bufferPos)
length:size
freeWhenDone:NO];
state->bufferPos += size;
return result;
}

size_t GPBCodedInputStreamPushLimit(GPBCodedInputStreamState *state,
size_t byteLimit) {
size_t GPBCodedInputStreamPushLimit(GPBCodedInputStreamState *state, size_t byteLimit) {
byteLimit += state->bufferPos;
size_t oldLimit = state->currentLimit;
if (byteLimit > oldLimit) {
Expand All @@ -285,8 +276,7 @@ size_t GPBCodedInputStreamPushLimit(GPBCodedInputStreamState *state,
return oldLimit;
}

void GPBCodedInputStreamPopLimit(GPBCodedInputStreamState *state,
size_t oldLimit) {
void GPBCodedInputStreamPopLimit(GPBCodedInputStreamState *state, size_t oldLimit) {
state->currentLimit = oldLimit;
}

Expand All @@ -295,12 +285,10 @@ size_t GPBCodedInputStreamBytesUntilLimit(GPBCodedInputStreamState *state) {
}

BOOL GPBCodedInputStreamIsAtEnd(GPBCodedInputStreamState *state) {
return (state->bufferPos == state->bufferSize) ||
(state->bufferPos == state->currentLimit);
return (state->bufferPos == state->bufferSize) || (state->bufferPos == state->currentLimit);
}

void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state,
int32_t value) {
void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state, int32_t value) {
if (state->lastTag != value) {
RaiseException(GPBCodedInputStreamErrorInvalidTag, @"Unexpected tag read");
}
Expand Down Expand Up @@ -360,8 +348,8 @@ - (BOOL)skipField:(int32_t)tag {
case GPBWireFormatStartGroup:
[self skipMessage];
GPBCodedInputStreamCheckLastTagWas(
&state_, GPBWireFormatMakeTag(GPBWireFormatGetTagFieldNumber(tag),
GPBWireFormatEndGroup));
&state_,
GPBWireFormatMakeTag(GPBWireFormatGetTagFieldNumber(tag), GPBWireFormatEndGroup));
return YES;
case GPBWireFormatEndGroup:
return NO;
Expand Down Expand Up @@ -438,18 +426,17 @@ - (void)readGroup:(int32_t)fieldNumber
CheckRecursionLimit(&state_);
++state_.recursionDepth;
[message mergeFromCodedInputStream:self extensionRegistry:extensionRegistry];
GPBCodedInputStreamCheckLastTagWas(
&state_, GPBWireFormatMakeTag(fieldNumber, GPBWireFormatEndGroup));
GPBCodedInputStreamCheckLastTagWas(&state_,
GPBWireFormatMakeTag(fieldNumber, GPBWireFormatEndGroup));
--state_.recursionDepth;
}

- (void)readUnknownGroup:(int32_t)fieldNumber
message:(GPBUnknownFieldSet *)message {
- (void)readUnknownGroup:(int32_t)fieldNumber message:(GPBUnknownFieldSet *)message {
CheckRecursionLimit(&state_);
++state_.recursionDepth;
[message mergeFromCodedInputStream:self];
GPBCodedInputStreamCheckLastTagWas(
&state_, GPBWireFormatMakeTag(fieldNumber, GPBWireFormatEndGroup));
GPBCodedInputStreamCheckLastTagWas(&state_,
GPBWireFormatMakeTag(fieldNumber, GPBWireFormatEndGroup));
--state_.recursionDepth;
}

Expand All @@ -473,8 +460,7 @@ - (void)readMapEntry:(id)mapDictionary
int32_t length = ReadRawVarint32(&state_);
size_t oldLimit = GPBCodedInputStreamPushLimit(&state_, length);
++state_.recursionDepth;
GPBDictionaryReadEntry(mapDictionary, self, extensionRegistry, field,
parentMessage);
GPBDictionaryReadEntry(mapDictionary, self, extensionRegistry, field, parentMessage);
GPBCodedInputStreamCheckLastTagWas(&state_, 0);
--state_.recursionDepth;
GPBCodedInputStreamPopLimit(&state_, oldLimit);
Expand Down
Loading

0 comments on commit 189f632

Please sign in to comment.