Skip to content

Commit

Permalink
Auto-generate files after cl/702483612
Browse files Browse the repository at this point in the history
  • Loading branch information
protobuf-team-bot committed Dec 3, 2024
1 parent be11a95 commit bedda1d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
16 changes: 16 additions & 0 deletions php/ext/google/protobuf/php-upb.c
Original file line number Diff line number Diff line change
Expand Up @@ -2891,6 +2891,10 @@ typedef struct upb_ArenaInternal {
// block.
uintptr_t block_alloc;

// The cleanup for the allocator. This is called after all the blocks are
// freed in an arena.
upb_AllocCleanupFunc* upb_alloc_cleanup;

// When multiple arenas are fused together, each arena points to a parent
// arena (root points to itself). The root tracks how many live arenas
// reference it.
Expand Down Expand Up @@ -3158,6 +3162,7 @@ static upb_Arena* _upb_Arena_InitSlow(upb_alloc* alloc) {
upb_Atomic_Init(&a->body.next, NULL);
upb_Atomic_Init(&a->body.tail, &a->body);
upb_Atomic_Init(&a->body.blocks, NULL);
a->body.upb_alloc_cleanup = NULL;

_upb_Arena_AddBlock(&a->head, mem, n);

Expand Down Expand Up @@ -3196,6 +3201,7 @@ upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc) {
upb_Atomic_Init(&a->body.next, NULL);
upb_Atomic_Init(&a->body.tail, &a->body);
upb_Atomic_Init(&a->body.blocks, NULL);
a->body.upb_alloc_cleanup = NULL;

a->body.block_alloc = _upb_Arena_MakeBlockAlloc(alloc, 1);
a->head.UPB_PRIVATE(ptr) = mem;
Expand All @@ -3214,13 +3220,17 @@ static void _upb_Arena_DoFree(upb_ArenaInternal* ai) {
(upb_ArenaInternal*)upb_Atomic_Load(&ai->next, memory_order_acquire);
upb_alloc* block_alloc = _upb_ArenaInternal_BlockAlloc(ai);
upb_MemBlock* block = upb_Atomic_Load(&ai->blocks, memory_order_acquire);
upb_AllocCleanupFunc* alloc_cleanup = *ai->upb_alloc_cleanup;
while (block != NULL) {
// Load first since we are deleting block.
upb_MemBlock* next_block =
upb_Atomic_Load(&block->next, memory_order_acquire);
upb_free(block_alloc, block);
block = next_block;
}
if (alloc_cleanup != NULL) {
alloc_cleanup(block_alloc);
}
ai = next_arena;
}
}
Expand Down Expand Up @@ -3285,6 +3295,12 @@ static void _upb_Arena_DoFuseArenaLists(upb_ArenaInternal* const parent,
upb_Atomic_Store(&parent->tail, parent_tail, memory_order_relaxed);
}

void upb_Arena_SetAllocCleanup(upb_Arena* a, upb_AllocCleanupFunc* func) {
upb_ArenaInternal* ai = upb_Arena_Internal(a);
UPB_ASSERT(ai->upb_alloc_cleanup == NULL);
ai->upb_alloc_cleanup = func;
}

static upb_ArenaInternal* _upb_Arena_DoFuse(const upb_Arena* a1,
const upb_Arena* a2,
uintptr_t* ref_delta) {
Expand Down
9 changes: 8 additions & 1 deletion php/ext/google/protobuf/php-upb.h
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ UPB_INLINE void upb_gfree(void* ptr) { upb_free(&upb_alloc_global, ptr); }
//
// We need this because the decoder inlines a upb_Arena for performance but
// the full struct is not visible outside of arena.c. Yes, I know, it's awful.
#define UPB_ARENA_SIZE_HACK 7
#define UPB_ARENA_SIZE_HACK 8

// LINT.IfChange(upb_Arena)

Expand Down Expand Up @@ -696,6 +696,8 @@ UPB_API_INLINE void upb_Arena_ShrinkLast(struct upb_Arena* a, void* ptr,

typedef struct upb_Arena upb_Arena;

typedef void upb_AllocCleanupFunc(upb_alloc* alloc);

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -706,6 +708,11 @@ extern "C" {
UPB_API upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc);

UPB_API void upb_Arena_Free(upb_Arena* a);
// Sets the cleanup function for the upb_alloc used by the arena. Only one
// cleanup function can be set, which will be called after all blocks are
// freed.
UPB_API void upb_Arena_SetAllocCleanup(upb_Arena* a,
upb_AllocCleanupFunc* func);
UPB_API bool upb_Arena_Fuse(const upb_Arena* a, const upb_Arena* b);
UPB_API bool upb_Arena_IsFused(const upb_Arena* a, const upb_Arena* b);

Expand Down
16 changes: 16 additions & 0 deletions ruby/ext/google/protobuf_c/ruby-upb.c
Original file line number Diff line number Diff line change
Expand Up @@ -2891,6 +2891,10 @@ typedef struct upb_ArenaInternal {
// block.
uintptr_t block_alloc;

// The cleanup for the allocator. This is called after all the blocks are
// freed in an arena.
upb_AllocCleanupFunc* upb_alloc_cleanup;

// When multiple arenas are fused together, each arena points to a parent
// arena (root points to itself). The root tracks how many live arenas
// reference it.
Expand Down Expand Up @@ -3158,6 +3162,7 @@ static upb_Arena* _upb_Arena_InitSlow(upb_alloc* alloc) {
upb_Atomic_Init(&a->body.next, NULL);
upb_Atomic_Init(&a->body.tail, &a->body);
upb_Atomic_Init(&a->body.blocks, NULL);
a->body.upb_alloc_cleanup = NULL;

_upb_Arena_AddBlock(&a->head, mem, n);

Expand Down Expand Up @@ -3196,6 +3201,7 @@ upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc) {
upb_Atomic_Init(&a->body.next, NULL);
upb_Atomic_Init(&a->body.tail, &a->body);
upb_Atomic_Init(&a->body.blocks, NULL);
a->body.upb_alloc_cleanup = NULL;

a->body.block_alloc = _upb_Arena_MakeBlockAlloc(alloc, 1);
a->head.UPB_PRIVATE(ptr) = mem;
Expand All @@ -3214,13 +3220,17 @@ static void _upb_Arena_DoFree(upb_ArenaInternal* ai) {
(upb_ArenaInternal*)upb_Atomic_Load(&ai->next, memory_order_acquire);
upb_alloc* block_alloc = _upb_ArenaInternal_BlockAlloc(ai);
upb_MemBlock* block = upb_Atomic_Load(&ai->blocks, memory_order_acquire);
upb_AllocCleanupFunc* alloc_cleanup = *ai->upb_alloc_cleanup;
while (block != NULL) {
// Load first since we are deleting block.
upb_MemBlock* next_block =
upb_Atomic_Load(&block->next, memory_order_acquire);
upb_free(block_alloc, block);
block = next_block;
}
if (alloc_cleanup != NULL) {
alloc_cleanup(block_alloc);
}
ai = next_arena;
}
}
Expand Down Expand Up @@ -3285,6 +3295,12 @@ static void _upb_Arena_DoFuseArenaLists(upb_ArenaInternal* const parent,
upb_Atomic_Store(&parent->tail, parent_tail, memory_order_relaxed);
}

void upb_Arena_SetAllocCleanup(upb_Arena* a, upb_AllocCleanupFunc* func) {
upb_ArenaInternal* ai = upb_Arena_Internal(a);
UPB_ASSERT(ai->upb_alloc_cleanup == NULL);
ai->upb_alloc_cleanup = func;
}

static upb_ArenaInternal* _upb_Arena_DoFuse(const upb_Arena* a1,
const upb_Arena* a2,
uintptr_t* ref_delta) {
Expand Down
9 changes: 8 additions & 1 deletion ruby/ext/google/protobuf_c/ruby-upb.h
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ UPB_INLINE void upb_gfree(void* ptr) { upb_free(&upb_alloc_global, ptr); }
//
// We need this because the decoder inlines a upb_Arena for performance but
// the full struct is not visible outside of arena.c. Yes, I know, it's awful.
#define UPB_ARENA_SIZE_HACK 7
#define UPB_ARENA_SIZE_HACK 8

// LINT.IfChange(upb_Arena)

Expand Down Expand Up @@ -698,6 +698,8 @@ UPB_API_INLINE void upb_Arena_ShrinkLast(struct upb_Arena* a, void* ptr,

typedef struct upb_Arena upb_Arena;

typedef void upb_AllocCleanupFunc(upb_alloc* alloc);

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -708,6 +710,11 @@ extern "C" {
UPB_API upb_Arena* upb_Arena_Init(void* mem, size_t n, upb_alloc* alloc);

UPB_API void upb_Arena_Free(upb_Arena* a);
// Sets the cleanup function for the upb_alloc used by the arena. Only one
// cleanup function can be set, which will be called after all blocks are
// freed.
UPB_API void upb_Arena_SetAllocCleanup(upb_Arena* a,
upb_AllocCleanupFunc* func);
UPB_API bool upb_Arena_Fuse(const upb_Arena* a, const upb_Arena* b);
UPB_API bool upb_Arena_IsFused(const upb_Arena* a, const upb_Arena* b);

Expand Down

0 comments on commit bedda1d

Please sign in to comment.