Skip to content

Commit 4b56158

Browse files
Auto-generate files after cl/718469089
1 parent 1f42fcb commit 4b56158

File tree

4 files changed

+30
-24
lines changed

4 files changed

+30
-24
lines changed

php/ext/google/protobuf/php-upb.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5282,7 +5282,7 @@ typedef struct {
52825282
typedef struct {
52835283
upb_OneOfLayoutItem* data;
52845284
size_t size;
5285-
size_t capacity;
5285+
size_t buf_capacity_bytes;
52865286
} upb_OneOfLayoutItemVector;
52875287

52885288
typedef struct {
@@ -5485,11 +5485,13 @@ static void upb_MtDecoder_PushOneof(upb_MtDecoder* d,
54855485
if (item.field_index == kUpb_OneOfLayoutItem_IndexSentinel) {
54865486
upb_MdDecoder_ErrorJmp(&d->base, "Empty oneof");
54875487
}
5488-
if (d->oneofs.size == d->oneofs.capacity) {
5489-
size_t new_cap = UPB_MAX(8, d->oneofs.size * 2);
5490-
d->oneofs.data = realloc(d->oneofs.data, new_cap * sizeof(*d->oneofs.data));
5488+
if ((d->oneofs.size + 1) * sizeof(*d->oneofs.data) >
5489+
d->oneofs.buf_capacity_bytes) {
5490+
size_t new_cap = UPB_MAX(8, d->oneofs.size * 2) * sizeof(*d->oneofs.data);
5491+
d->oneofs.data =
5492+
upb_grealloc(d->oneofs.data, d->oneofs.buf_capacity_bytes, new_cap);
54915493
upb_MdDecoder_CheckOutOfMemory(&d->base, d->oneofs.data);
5492-
d->oneofs.capacity = new_cap;
5494+
d->oneofs.buf_capacity_bytes = new_cap;
54935495
}
54945496
item.field_index -= kOneofBase;
54955497

@@ -5960,7 +5962,7 @@ static upb_MiniTable* upb_MtDecoder_DoBuildMiniTableWithBuf(
59605962

59615963
done:
59625964
*buf = decoder->oneofs.data;
5963-
*buf_size = decoder->oneofs.capacity * sizeof(*decoder->oneofs.data);
5965+
*buf_size = decoder->oneofs.buf_capacity_bytes;
59645966
return decoder->table;
59655967
}
59665968

@@ -5969,7 +5971,7 @@ static upb_MiniTable* upb_MtDecoder_BuildMiniTableWithBuf(
59695971
void** const buf, size_t* const buf_size) {
59705972
if (UPB_SETJMP(decoder->base.err) != 0) {
59715973
*buf = decoder->oneofs.data;
5972-
*buf_size = decoder->oneofs.capacity * sizeof(*decoder->oneofs.data);
5974+
*buf_size = decoder->oneofs.buf_capacity_bytes;
59735975
return NULL;
59745976
}
59755977

@@ -5988,7 +5990,7 @@ upb_MiniTable* upb_MiniTable_BuildWithBuf(const char* data, size_t len,
59885990
.oneofs =
59895991
{
59905992
.data = *buf,
5991-
.capacity = *buf_size / sizeof(*decoder.oneofs.data),
5993+
.buf_capacity_bytes = *buf_size,
59925994
.size = 0,
59935995
},
59945996
.arena = arena,
@@ -6086,7 +6088,7 @@ upb_MiniTable* _upb_MiniTable_Build(const char* data, size_t len,
60866088
size_t size = 0;
60876089
upb_MiniTable* ret = upb_MiniTable_BuildWithBuf(data, len, platform, arena,
60886090
&buf, &size, status);
6089-
free(buf);
6091+
upb_gfree(buf);
60906092
return ret;
60916093
}
60926094

php/ext/google/protobuf/php-upb.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5296,10 +5296,11 @@ UPB_API_INLINE upb_MiniTableExtension* upb_MiniTableExtension_BuildEnum(
52965296
}
52975297

52985298
// Like upb_MiniTable_Build(), but the user provides a buffer of layout data so
5299-
// it can be reused from call to call, avoiding repeated realloc()/free().
5299+
// it can be reused from call to call, avoiding repeated
5300+
// upb_grealloc()/upb_gfree().
53005301
//
5301-
// The caller owns `*buf` both before and after the call, and must free() it
5302-
// when it is no longer in use. The function will realloc() `*buf` as
5302+
// The caller owns `*buf` both before and after the call, and must upb_gfree()
5303+
// it when it is no longer in use. The function will upb_grealloc() `*buf` as
53035304
// necessary, updating `*size` accordingly.
53045305
upb_MiniTable* upb_MiniTable_BuildWithBuf(const char* data, size_t len,
53055306
upb_MiniTablePlatform platform,

ruby/ext/google/protobuf_c/ruby-upb.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5282,7 +5282,7 @@ typedef struct {
52825282
typedef struct {
52835283
upb_OneOfLayoutItem* data;
52845284
size_t size;
5285-
size_t capacity;
5285+
size_t buf_capacity_bytes;
52865286
} upb_OneOfLayoutItemVector;
52875287

52885288
typedef struct {
@@ -5485,11 +5485,13 @@ static void upb_MtDecoder_PushOneof(upb_MtDecoder* d,
54855485
if (item.field_index == kUpb_OneOfLayoutItem_IndexSentinel) {
54865486
upb_MdDecoder_ErrorJmp(&d->base, "Empty oneof");
54875487
}
5488-
if (d->oneofs.size == d->oneofs.capacity) {
5489-
size_t new_cap = UPB_MAX(8, d->oneofs.size * 2);
5490-
d->oneofs.data = realloc(d->oneofs.data, new_cap * sizeof(*d->oneofs.data));
5488+
if ((d->oneofs.size + 1) * sizeof(*d->oneofs.data) >
5489+
d->oneofs.buf_capacity_bytes) {
5490+
size_t new_cap = UPB_MAX(8, d->oneofs.size * 2) * sizeof(*d->oneofs.data);
5491+
d->oneofs.data =
5492+
upb_grealloc(d->oneofs.data, d->oneofs.buf_capacity_bytes, new_cap);
54915493
upb_MdDecoder_CheckOutOfMemory(&d->base, d->oneofs.data);
5492-
d->oneofs.capacity = new_cap;
5494+
d->oneofs.buf_capacity_bytes = new_cap;
54935495
}
54945496
item.field_index -= kOneofBase;
54955497

@@ -5960,7 +5962,7 @@ static upb_MiniTable* upb_MtDecoder_DoBuildMiniTableWithBuf(
59605962

59615963
done:
59625964
*buf = decoder->oneofs.data;
5963-
*buf_size = decoder->oneofs.capacity * sizeof(*decoder->oneofs.data);
5965+
*buf_size = decoder->oneofs.buf_capacity_bytes;
59645966
return decoder->table;
59655967
}
59665968

@@ -5969,7 +5971,7 @@ static upb_MiniTable* upb_MtDecoder_BuildMiniTableWithBuf(
59695971
void** const buf, size_t* const buf_size) {
59705972
if (UPB_SETJMP(decoder->base.err) != 0) {
59715973
*buf = decoder->oneofs.data;
5972-
*buf_size = decoder->oneofs.capacity * sizeof(*decoder->oneofs.data);
5974+
*buf_size = decoder->oneofs.buf_capacity_bytes;
59735975
return NULL;
59745976
}
59755977

@@ -5988,7 +5990,7 @@ upb_MiniTable* upb_MiniTable_BuildWithBuf(const char* data, size_t len,
59885990
.oneofs =
59895991
{
59905992
.data = *buf,
5991-
.capacity = *buf_size / sizeof(*decoder.oneofs.data),
5993+
.buf_capacity_bytes = *buf_size,
59925994
.size = 0,
59935995
},
59945996
.arena = arena,
@@ -6086,7 +6088,7 @@ upb_MiniTable* _upb_MiniTable_Build(const char* data, size_t len,
60866088
size_t size = 0;
60876089
upb_MiniTable* ret = upb_MiniTable_BuildWithBuf(data, len, platform, arena,
60886090
&buf, &size, status);
6089-
free(buf);
6091+
upb_gfree(buf);
60906092
return ret;
60916093
}
60926094

ruby/ext/google/protobuf_c/ruby-upb.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5298,10 +5298,11 @@ UPB_API_INLINE upb_MiniTableExtension* upb_MiniTableExtension_BuildEnum(
52985298
}
52995299

53005300
// Like upb_MiniTable_Build(), but the user provides a buffer of layout data so
5301-
// it can be reused from call to call, avoiding repeated realloc()/free().
5301+
// it can be reused from call to call, avoiding repeated
5302+
// upb_grealloc()/upb_gfree().
53025303
//
5303-
// The caller owns `*buf` both before and after the call, and must free() it
5304-
// when it is no longer in use. The function will realloc() `*buf` as
5304+
// The caller owns `*buf` both before and after the call, and must upb_gfree()
5305+
// it when it is no longer in use. The function will upb_grealloc() `*buf` as
53055306
// necessary, updating `*size` accordingly.
53065307
upb_MiniTable* upb_MiniTable_BuildWithBuf(const char* data, size_t len,
53075308
upb_MiniTablePlatform platform,

0 commit comments

Comments
 (0)