Skip to content

Commit 595a18e

Browse files
habermancopybara-github
authored andcommitted
Marked functions private in EpsCopyInputStream.
I marked as many functions as possible private, to reduce the public API surface. This is in anticipation of adding better testing of all public API surfaces. PiperOrigin-RevId: 826291245
1 parent f027f1f commit 595a18e

File tree

11 files changed

+131
-122
lines changed

11 files changed

+131
-122
lines changed

upb/wire/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ cc_test(
212212
deps = [
213213
":eps_copy_input_stream",
214214
"//upb/mem",
215+
"//upb/port",
215216
"@googletest//:gtest",
216217
"@googletest//:gtest_main",
217218
],

upb/wire/decode.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,8 @@ const char* _upb_Decoder_DecodeFixedPacked(upb_Decoder* d, const char* ptr,
385385
// Note: if/when the decoder supports multi-buffer input, we will need to
386386
// handle buffer seams here.
387387
if (upb_IsLittleEndian()) {
388-
ptr = upb_EpsCopyInputStream_Copy(&d->input, ptr, mem, val->size);
388+
ptr = UPB_PRIVATE(upb_EpsCopyInputStream_Copy)(&d->input, ptr, mem,
389+
val->size);
389390
} else {
390391
int delta = upb_EpsCopyInputStream_PushLimit(&d->input, ptr, val->size);
391392
char* dst = mem;

upb/wire/decode_fast/cardinality.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,9 @@ bool upb_DecodeFast_DoNextRepeated(upb_Decoder* d, const char** ptr,
361361
upb_DecodeFast_Cardinality card,
362362
upb_DecodeFast_TagSize tagsize) {
363363
int overrun;
364-
if (UPB_UNLIKELY(
365-
upb_EpsCopyInputStream_IsDoneStatus(&d->input, *ptr, &overrun) !=
366-
kUpb_IsDoneStatus_NotDone)) {
364+
if (UPB_UNLIKELY(UPB_PRIVATE(upb_EpsCopyInputStream_IsDoneStatus)(
365+
&d->input, *ptr, &overrun) !=
366+
kUpb_IsDoneStatus_NotDone)) {
367367
return UPB_DECODEFAST_EXIT(kUpb_DecodeFastNext_MessageIsDoneFallback, next);
368368
}
369369

upb/wire/decode_fast/dispatch.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
UPB_NOINLINE UPB_PRESERVE_NONE const char* upb_DecodeFast_MessageIsDoneFallback(
2020
UPB_PARSE_PARAMS) {
2121
int overrun;
22-
switch (upb_EpsCopyInputStream_IsDoneStatus(&d->input, ptr, &overrun)) {
22+
switch (UPB_PRIVATE(upb_EpsCopyInputStream_IsDoneStatus)(&d->input, ptr,
23+
&overrun)) {
2324
case kUpb_IsDoneStatus_Done: {
2425
// We've reach end-of-message. Sync hasbits and maybe check required
2526
// fields.
@@ -32,7 +33,7 @@ UPB_NOINLINE UPB_PRESERVE_NONE const char* upb_DecodeFast_MessageIsDoneFallback(
3233
}
3334
case kUpb_IsDoneStatus_NeedFallback:
3435
// We've reached end-of-buffer. Refresh the buffer.
35-
ptr = _upb_EpsCopyInputStream_IsDoneFallbackInline(
36+
ptr = UPB_PRIVATE(upb_EpsCopyInputStream_IsDoneFallbackInline)(
3637
&d->input, ptr, overrun, _upb_Decoder_BufferFlipCallback);
3738

3839
// We successfully refreshed the buffer (otherwise the function above

upb/wire/decode_fast/dispatch.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ UPB_NOINLINE UPB_PRESERVE_NONE const char* upb_DecodeFast_MessageIsDoneFallback(
7171
UPB_FORCEINLINE UPB_PRESERVE_NONE const char* upb_DecodeFast_Dispatch(
7272
UPB_PARSE_PARAMS) {
7373
int overrun;
74-
upb_IsDoneStatus status =
75-
upb_EpsCopyInputStream_IsDoneStatus(&d->input, ptr, &overrun);
74+
upb_IsDoneStatus status = UPB_PRIVATE(upb_EpsCopyInputStream_IsDoneStatus)(
75+
&d->input, ptr, &overrun);
7676

7777
if (UPB_UNLIKELY(status != kUpb_IsDoneStatus_NotDone)) {
7878
// End-of-message or end-of-buffer.

upb/wire/decode_fast/field_string.c

Lines changed: 74 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, int copy,
112112
bool validate_utf8 = type == kUpb_DecodeFast_String; \
113113
int tagbytes = upb_DecodeFast_TagSizeBytes(tagsize); \
114114
\
115-
UPB_ASSERT(!upb_EpsCopyInputStream_AliasingAvailable(&d->input, ptr, 0)); \
115+
UPB_ASSERT(!UPB_PRIVATE(upb_EpsCopyInputStream_AliasingAvailable)(&d->input, \
116+
ptr, 0)); \
116117
UPB_ASSERT(fastdecode_checktag(data, tagbytes)); \
117118
\
118119
dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \
@@ -129,8 +130,9 @@ void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, int copy,
129130
\
130131
buf = d->arena.UPB_PRIVATE(ptr); \
131132
arena_has = UPB_PRIVATE(_upb_ArenaHas)(&d->arena); \
132-
common_has = UPB_MIN(arena_has, \
133-
upb_EpsCopyInputStream_BytesAvailable(&d->input, ptr)); \
133+
common_has = UPB_MIN( \
134+
arena_has, \
135+
UPB_PRIVATE(upb_EpsCopyInputStream_BytesAvailable)(&d->input, ptr)); \
134136
\
135137
if (UPB_LIKELY(size <= 15 - tagbytes)) { \
136138
if (arena_has < 16) goto longstr; \
@@ -190,75 +192,75 @@ void fastdecode_docopy(upb_Decoder* d, const char* ptr, uint32_t size, int copy,
190192
hasbits, (uint64_t)dst); \
191193
}
192194

193-
#define FASTDECODE_STRING(d, ptr, msg, table, hasbits, data, type, card, \
194-
tagsize, copyfunc) \
195-
upb_StringView* dst; \
196-
fastdecode_arr farr; \
197-
int64_t size; \
198-
bool validate_utf8 = type == kUpb_DecodeFast_String; \
199-
int tagbytes = upb_DecodeFast_TagSizeBytes(tagsize); \
200-
\
201-
if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) { \
202-
RETURN_GENERIC("string field tag mismatch\n"); \
203-
} \
204-
\
205-
if (UPB_UNLIKELY( \
206-
!upb_EpsCopyInputStream_AliasingAvailable(&d->input, ptr, 0))) { \
207-
UPB_MUSTTAIL return copyfunc(UPB_PARSE_ARGS); \
208-
} \
209-
\
210-
dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \
211-
sizeof(upb_StringView), card); \
212-
\
213-
again: \
214-
if (card == kUpb_DecodeFast_Repeated) { \
215-
dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_StringView)); \
216-
} \
217-
\
218-
size = (int8_t)ptr[tagbytes]; \
219-
ptr += tagbytes + 1; \
220-
\
221-
if (UPB_UNLIKELY( \
222-
!upb_EpsCopyInputStream_AliasingAvailable(&d->input, ptr, size))) { \
223-
ptr--; \
224-
if (validate_utf8) { \
225-
return fastdecode_longstring_utf8(d, ptr, msg, table, hasbits, \
226-
(uint64_t)dst); \
227-
} else { \
228-
return fastdecode_longstring_noutf8(d, ptr, msg, table, hasbits, \
229-
(uint64_t)dst); \
230-
} \
231-
} \
232-
\
233-
dst->data = ptr; \
234-
dst->size = size; \
235-
ptr = upb_EpsCopyInputStream_ReadStringAliased(&d->input, &dst->data, \
236-
dst->size); \
237-
\
238-
if (card == kUpb_DecodeFast_Repeated) { \
239-
if (validate_utf8 && \
240-
!_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { \
241-
_upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); \
242-
} \
243-
fastdecode_nextret ret = fastdecode_nextrepeated( \
244-
d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_StringView)); \
245-
switch (ret.next) { \
246-
case FD_NEXT_SAMEFIELD: \
247-
dst = ret.dst; \
248-
goto again; \
249-
case FD_NEXT_OTHERFIELD: \
250-
data = ret.tag; \
251-
UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \
252-
case FD_NEXT_ATLIMIT: \
253-
return ptr; \
254-
} \
255-
} \
256-
\
257-
if (card != kUpb_DecodeFast_Repeated && validate_utf8) { \
258-
data = (uint64_t)dst; \
259-
UPB_MUSTTAIL return fastdecode_verifyutf8(UPB_PARSE_ARGS); \
260-
} \
261-
\
195+
#define FASTDECODE_STRING(d, ptr, msg, table, hasbits, data, type, card, \
196+
tagsize, copyfunc) \
197+
upb_StringView* dst; \
198+
fastdecode_arr farr; \
199+
int64_t size; \
200+
bool validate_utf8 = type == kUpb_DecodeFast_String; \
201+
int tagbytes = upb_DecodeFast_TagSizeBytes(tagsize); \
202+
\
203+
if (UPB_UNLIKELY(!fastdecode_checktag(data, tagbytes))) { \
204+
RETURN_GENERIC("string field tag mismatch\n"); \
205+
} \
206+
\
207+
if (UPB_UNLIKELY(!UPB_PRIVATE(upb_EpsCopyInputStream_AliasingAvailable)( \
208+
&d->input, ptr, 0))) { \
209+
UPB_MUSTTAIL return copyfunc(UPB_PARSE_ARGS); \
210+
} \
211+
\
212+
dst = fastdecode_getfield(d, ptr, msg, &data, &hasbits, &farr, \
213+
sizeof(upb_StringView), card); \
214+
\
215+
again: \
216+
if (card == kUpb_DecodeFast_Repeated) { \
217+
dst = fastdecode_resizearr(d, dst, &farr, sizeof(upb_StringView)); \
218+
} \
219+
\
220+
size = (int8_t)ptr[tagbytes]; \
221+
ptr += tagbytes + 1; \
222+
\
223+
if (UPB_UNLIKELY(!UPB_PRIVATE(upb_EpsCopyInputStream_AliasingAvailable)( \
224+
&d->input, ptr, size))) { \
225+
ptr--; \
226+
if (validate_utf8) { \
227+
return fastdecode_longstring_utf8(d, ptr, msg, table, hasbits, \
228+
(uint64_t)dst); \
229+
} else { \
230+
return fastdecode_longstring_noutf8(d, ptr, msg, table, hasbits, \
231+
(uint64_t)dst); \
232+
} \
233+
} \
234+
\
235+
dst->data = ptr; \
236+
dst->size = size; \
237+
ptr = upb_EpsCopyInputStream_ReadStringAliased(&d->input, &dst->data, \
238+
dst->size); \
239+
\
240+
if (card == kUpb_DecodeFast_Repeated) { \
241+
if (validate_utf8 && \
242+
!_upb_Decoder_VerifyUtf8Inline(dst->data, dst->size)) { \
243+
_upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_BadUtf8); \
244+
} \
245+
fastdecode_nextret ret = fastdecode_nextrepeated( \
246+
d, dst, &ptr, &farr, data, tagbytes, sizeof(upb_StringView)); \
247+
switch (ret.next) { \
248+
case FD_NEXT_SAMEFIELD: \
249+
dst = ret.dst; \
250+
goto again; \
251+
case FD_NEXT_OTHERFIELD: \
252+
data = ret.tag; \
253+
UPB_MUSTTAIL return _upb_FastDecoder_TagDispatch(UPB_PARSE_ARGS); \
254+
case FD_NEXT_ATLIMIT: \
255+
return ptr; \
256+
} \
257+
} \
258+
\
259+
if (card != kUpb_DecodeFast_Repeated && validate_utf8) { \
260+
data = (uint64_t)dst; \
261+
UPB_MUSTTAIL return fastdecode_verifyutf8(UPB_PARSE_ARGS); \
262+
} \
263+
\
262264
UPB_MUSTTAIL return upb_DecodeFast_Dispatch(UPB_PARSE_ARGS);
263265

264266
/* Generate all combinations:

upb/wire/eps_copy_input_stream.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77

88
#include "upb/wire/eps_copy_input_stream.h"
99

10+
// Must be last.
11+
#include "upb/port/def.inc"
12+
1013
static const char* _upb_EpsCopyInputStream_NoOpCallback(
1114
upb_EpsCopyInputStream* e, const char* old_end, const char* new_start) {
1215
return new_start;
1316
}
1417

15-
const char* _upb_EpsCopyInputStream_IsDoneFallbackNoCallback(
18+
const char* UPB_PRIVATE(upb_EpsCopyInputStream_IsDoneFallbackNoCallback)(
1619
upb_EpsCopyInputStream* e, const char* ptr, int overrun) {
17-
return _upb_EpsCopyInputStream_IsDoneFallbackInline(
20+
return UPB_PRIVATE(upb_EpsCopyInputStream_IsDoneFallbackInline)(
1821
e, ptr, overrun, _upb_EpsCopyInputStream_NoOpCallback);
1922
}

0 commit comments

Comments
 (0)