13
13
#import " GPBUtilities_PackagePrivate.h"
14
14
#import " GPBWireFormat.h"
15
15
16
+ // TODO: Consider using on other functions to reduce bloat when
17
+ // some compiler optimizations are enabled.
18
+ #define GPB_NOINLINE __attribute__ ((noinline))
19
+
16
20
NSString *const GPBCodedInputStreamException = GPBNSStringifySymbol(GPBCodedInputStreamException);
17
21
18
22
NSString *const GPBCodedInputStreamUnderlyingErrorKey =
28
32
// int CodedInputStream::default_recursion_limit_ = 100;
29
33
static const NSUInteger kDefaultRecursionLimit = 100 ;
30
34
31
- static void RaiseException (NSInteger code, NSString *reason) {
35
+ GPB_NOINLINE
36
+ void GPBRaiseStreamError (NSInteger code, NSString *reason) {
32
37
NSDictionary *errorInfo = nil ;
33
38
if ([reason length ]) {
34
39
errorInfo = @{GPBErrorReasonKey : reason};
@@ -44,7 +49,7 @@ static void RaiseException(NSInteger code, NSString *reason) {
44
49
45
50
GPB_INLINE void CheckRecursionLimit (GPBCodedInputStreamState *state) {
46
51
if (state->recursionDepth >= kDefaultRecursionLimit ) {
47
- RaiseException (GPBCodedInputStreamErrorRecursionDepthExceeded, nil );
52
+ GPBRaiseStreamError (GPBCodedInputStreamErrorRecursionDepthExceeded, nil );
48
53
}
49
54
}
50
55
@@ -56,19 +61,19 @@ GPB_INLINE void CheckFieldSize(uint64_t size) {
56
61
if (size > 0x7fffffff ) {
57
62
// TODO: Maybe a different error code for this, but adding one is a breaking
58
63
// change so reuse an existing one.
59
- RaiseException (GPBCodedInputStreamErrorInvalidSize, nil );
64
+ GPBRaiseStreamError (GPBCodedInputStreamErrorInvalidSize, nil );
60
65
}
61
66
}
62
67
63
68
static void CheckSize (GPBCodedInputStreamState *state, size_t size) {
64
69
size_t newSize = state->bufferPos + size;
65
70
if (newSize > state->bufferSize ) {
66
- RaiseException (GPBCodedInputStreamErrorInvalidSize, nil );
71
+ GPBRaiseStreamError (GPBCodedInputStreamErrorInvalidSize, nil );
67
72
}
68
73
if (newSize > state->currentLimit ) {
69
74
// Fast forward to end of currentLimit;
70
75
state->bufferPos = state->currentLimit ;
71
- RaiseException (GPBCodedInputStreamErrorSubsectionLimitReached, nil );
76
+ GPBRaiseStreamError (GPBCodedInputStreamErrorSubsectionLimitReached, nil );
72
77
}
73
78
}
74
79
@@ -110,7 +115,7 @@ static int64_t ReadRawVarint64(GPBCodedInputStreamState *state) {
110
115
}
111
116
shift += 7 ;
112
117
}
113
- RaiseException (GPBCodedInputStreamErrorInvalidVarInt, @" Invalid VarInt64" );
118
+ GPBRaiseStreamError (GPBCodedInputStreamErrorInvalidVarInt, @" Invalid VarInt64" );
114
119
return 0 ;
115
120
}
116
121
@@ -201,12 +206,12 @@ int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state) {
201
206
state->lastTag = ReadRawVarint32 (state);
202
207
// Tags have to include a valid wireformat.
203
208
if (!GPBWireFormatIsValidTag (state->lastTag )) {
204
- RaiseException (GPBCodedInputStreamErrorInvalidTag, @" Invalid wireformat in tag." );
209
+ GPBRaiseStreamError (GPBCodedInputStreamErrorInvalidTag, @" Invalid wireformat in tag." );
205
210
}
206
211
// Zero is not a valid field number.
207
212
if (GPBWireFormatGetTagFieldNumber (state->lastTag ) == 0 ) {
208
- RaiseException (GPBCodedInputStreamErrorInvalidTag,
209
- @" A zero field number on the wire is invalid." );
213
+ GPBRaiseStreamError (GPBCodedInputStreamErrorInvalidTag,
214
+ @" A zero field number on the wire is invalid." );
210
215
}
211
216
return state->lastTag ;
212
217
}
@@ -231,7 +236,7 @@ int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state) {
231
236
NSLog (@" UTF-8 failure, is some field type 'string' when it should be "
232
237
@" 'bytes'?" );
233
238
#endif
234
- RaiseException (GPBCodedInputStreamErrorInvalidUTF8, nil );
239
+ GPBRaiseStreamError (GPBCodedInputStreamErrorInvalidUTF8, nil );
235
240
}
236
241
}
237
242
return result;
@@ -266,7 +271,7 @@ size_t GPBCodedInputStreamPushLimit(GPBCodedInputStreamState *state, size_t byte
266
271
byteLimit += state->bufferPos ;
267
272
size_t oldLimit = state->currentLimit ;
268
273
if (byteLimit > oldLimit) {
269
- RaiseException (GPBCodedInputStreamErrorInvalidSubsectionLimit, nil );
274
+ GPBRaiseStreamError (GPBCodedInputStreamErrorInvalidSubsectionLimit, nil );
270
275
}
271
276
state->currentLimit = byteLimit;
272
277
return oldLimit;
@@ -286,7 +291,7 @@ BOOL GPBCodedInputStreamIsAtEnd(GPBCodedInputStreamState *state) {
286
291
287
292
void GPBCodedInputStreamCheckLastTagWas (GPBCodedInputStreamState *state, int32_t value) {
288
293
if (state->lastTag != value) {
289
- RaiseException (GPBCodedInputStreamErrorInvalidTag, @" Unexpected tag read" );
294
+ GPBRaiseStreamError (GPBCodedInputStreamErrorInvalidTag, @" Unexpected tag read" );
290
295
}
291
296
}
292
297
0 commit comments