split out the internal arena defs from internal/upb.h

PiperOrigin-RevId: 456584853
pull/13171/head
Protobuf Team Bot 2 years ago committed by Copybara-Service
parent 7b05f25b98
commit b174d9d5a0
  1. 4
      BUILD
  2. 2
      upb/arena.c
  3. 1
      upb/decode.h
  4. 71
      upb/internal/arena.h
  5. 2
      upb/internal/decode.h
  6. 34
      upb/internal/upb.h

@ -106,6 +106,7 @@ cc_library(
"upb/arena.c", "upb/arena.c",
"upb/decode.c", "upb/decode.c",
"upb/encode.c", "upb/encode.c",
"upb/internal/arena.h",
"upb/internal/decode.h", "upb/internal/decode.h",
"upb/internal/table.h", "upb/internal/table.h",
"upb/internal/upb.h", "upb/internal/upb.h",
@ -269,8 +270,8 @@ cc_library(
"upb/decode.h", "upb/decode.h",
"upb/decode_fast.c", "upb/decode_fast.c",
"upb/decode_fast.h", "upb/decode_fast.h",
"upb/internal/arena.h",
"upb/internal/decode.h", "upb/internal/decode.h",
"upb/internal/upb.h",
"upb/msg.h", "upb/msg.h",
"upb/msg_internal.h", "upb/msg_internal.h",
], ],
@ -406,6 +407,7 @@ cc_library(
cc_library( cc_library(
name = "json", name = "json",
srcs = [ srcs = [
"upb/internal/arena.h",
"upb/internal/upb.h", "upb/internal/upb.h",
"upb/json_decode.c", "upb/json_decode.c",
"upb/json_encode.c", "upb/json_encode.c",

@ -28,7 +28,7 @@
#include "upb/arena.h" #include "upb/arena.h"
#include "upb/alloc.h" #include "upb/alloc.h"
#include "upb/internal/upb.h" #include "upb/internal/arena.h"
// Must be last. // Must be last.
#include "upb/port_def.inc" #include "upb/port_def.inc"

@ -32,6 +32,7 @@
#ifndef UPB_DECODE_H_ #ifndef UPB_DECODE_H_
#define UPB_DECODE_H_ #define UPB_DECODE_H_
#include "upb/arena.h"
#include "upb/extension_registry.h" #include "upb/extension_registry.h"
#include "upb/msg.h" #include "upb/msg.h"

@ -0,0 +1,71 @@
/*
* Copyright (c) 2009-2021, Google LLC
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Google LLC nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef UPB_INTERNAL_ARENA_H_
#define UPB_INTERNAL_ARENA_H_
#include "upb/arena.h"
// Must be last.
#include "upb/port_def.inc"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct mem_block mem_block;
struct upb_Arena {
_upb_ArenaHead head;
/* Stores cleanup metadata for this arena.
* - a pointer to the current cleanup counter.
* - a boolean indicating if there is an unowned initial block. */
uintptr_t cleanup_metadata;
/* Allocator to allocate arena blocks. We are responsible for freeing these
* when we are destroyed. */
upb_alloc* block_alloc;
uint32_t last_size;
/* 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. */
uint32_t refcount; /* Only used when a->parent == a */
struct upb_Arena* parent;
/* Linked list of blocks to free/cleanup. */
mem_block *freelist, *freelist_tail;
};
#ifdef __cplusplus
} /* extern "C" */
#endif
#include "upb/port_undef.inc"
#endif /* UPB_INTERNAL_ARENA_H_ */

@ -36,7 +36,7 @@
#include <setjmp.h> #include <setjmp.h>
#include "upb/decode.h" #include "upb/decode.h"
#include "upb/internal/upb.h" #include "upb/internal/arena.h"
#include "upb/msg_internal.h" #include "upb/msg_internal.h"
#include "third_party/utf8_range/utf8_range.h" #include "third_party/utf8_range/utf8_range.h"

@ -30,30 +30,12 @@
#include "upb/upb.h" #include "upb/upb.h"
struct mem_block; // Must be last.
typedef struct mem_block mem_block; #include "upb/port_def.inc"
struct upb_Arena { #ifdef __cplusplus
_upb_ArenaHead head; extern "C" {
/* Stores cleanup metadata for this arena. #endif
* - a pointer to the current cleanup counter.
* - a boolean indicating if there is an unowned initial block. */
uintptr_t cleanup_metadata;
/* Allocator to allocate arena blocks. We are responsible for freeing these
* when we are destroyed. */
upb_alloc* block_alloc;
uint32_t last_size;
/* 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. */
uint32_t refcount; /* Only used when a->parent == a */
struct upb_Arena* parent;
/* Linked list of blocks to free/cleanup. */
mem_block *freelist, *freelist_tail;
};
// Encodes a float or double that is round-trippable, but as short as possible. // Encodes a float or double that is round-trippable, but as short as possible.
// These routines are not fully optimal (not guaranteed to be shortest), but are // These routines are not fully optimal (not guaranteed to be shortest), but are
@ -65,4 +47,10 @@ enum { kUpb_RoundTripBufferSize = 32 };
void _upb_EncodeRoundTripDouble(double val, char* buf, size_t size); void _upb_EncodeRoundTripDouble(double val, char* buf, size_t size);
void _upb_EncodeRoundTripFloat(float val, char* buf, size_t size); void _upb_EncodeRoundTripFloat(float val, char* buf, size_t size);
#ifdef __cplusplus
} /* extern "C" */
#endif
#include "upb/port_undef.inc"
#endif /* UPB_INTERNAL_UPB_H_ */ #endif /* UPB_INTERNAL_UPB_H_ */

Loading…
Cancel
Save