summaryrefslogtreecommitdiff
path: root/upb/pb
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2019-01-09 22:40:50 -0800
committerJoshua Haberman <jhaberman@gmail.com>2019-01-09 22:40:50 -0800
commit0553eff64a87eceff0de3b6260b4f2d45b61703a (patch)
tree5b051740c041786655d1794a5034ccf20928e8ee /upb/pb
parent31e0997c1abaa531505d28e36473f1c972ca0849 (diff)
upb_refcounted is gone! Some tests still to fix.
Diffstat (limited to 'upb/pb')
-rw-r--r--upb/pb/compile_decoder.c176
-rw-r--r--upb/pb/decoder.h128
-rw-r--r--upb/pb/decoder.int.h63
-rw-r--r--upb/pb/encoder.c5
-rw-r--r--upb/pb/encoder.h12
-rw-r--r--upb/pb/textprinter.c5
-rw-r--r--upb/pb/textprinter.h11
7 files changed, 133 insertions, 267 deletions
diff --git a/upb/pb/compile_decoder.c b/upb/pb/compile_decoder.c
index d147edf..02f5179 100644
--- a/upb/pb/compile_decoder.c
+++ b/upb/pb/compile_decoder.c
@@ -23,80 +23,23 @@
#define MAXLABEL 5
#define EMPTYLABEL -1
-/* mgroup *********************************************************************/
-
-static void freegroup(upb_refcounted *r) {
- mgroup *g = (mgroup*)r;
- upb_inttable_uninit(&g->methods);
-#ifdef UPB_USE_JIT_X64
- upb_pbdecoder_freejit(g);
-#endif
- upb_gfree(g->bytecode);
- upb_gfree(g);
-}
-
-static void visitgroup(const upb_refcounted *r, upb_refcounted_visit *visit,
- void *closure) {
- const mgroup *g = (const mgroup*)r;
- upb_inttable_iter i;
- upb_inttable_begin(&i, &g->methods);
- for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
- upb_pbdecodermethod *method = upb_value_getptr(upb_inttable_iter_value(&i));
- visit(r, upb_pbdecodermethod_upcast(method), closure);
- }
-}
-
-mgroup *newgroup(const void *owner) {
- mgroup *g = upb_gmalloc(sizeof(*g));
- static const struct upb_refcounted_vtbl vtbl = {visitgroup, freegroup};
- upb_refcounted_init(mgroup_upcast_mutable(g), &vtbl, owner);
- upb_inttable_init(&g->methods, UPB_CTYPE_PTR);
- g->bytecode = NULL;
- g->bytecode_end = NULL;
- return g;
-}
-
-
/* upb_pbdecodermethod ********************************************************/
-static void freemethod(upb_refcounted *r) {
- upb_pbdecodermethod *method = (upb_pbdecodermethod*)r;
-
- if (method->dest_handlers_) {
- upb_handlers_unref(method->dest_handlers_, method);
- }
-
+static void freemethod(upb_pbdecodermethod *method) {
upb_inttable_uninit(&method->dispatch);
upb_gfree(method);
}
-static void visitmethod(const upb_refcounted *r, upb_refcounted_visit *visit,
- void *closure) {
- const upb_pbdecodermethod *m = (const upb_pbdecodermethod*)r;
- visit(r, m->group, closure);
-}
-
static upb_pbdecodermethod *newmethod(const upb_handlers *dest_handlers,
mgroup *group) {
- static const struct upb_refcounted_vtbl vtbl = {visitmethod, freemethod};
upb_pbdecodermethod *ret = upb_gmalloc(sizeof(*ret));
- upb_refcounted_init(upb_pbdecodermethod_upcast_mutable(ret), &vtbl, &ret);
upb_byteshandler_init(&ret->input_handler_);
- /* The method references the group and vice-versa, in a circular reference. */
- upb_ref2(ret, group);
- upb_ref2(group, ret);
- upb_inttable_insertptr(&group->methods, dest_handlers, upb_value_ptr(ret));
- upb_pbdecodermethod_unref(ret, &ret);
-
- ret->group = mgroup_upcast_mutable(group);
+ ret->group = group;
ret->dest_handlers_ = dest_handlers;
ret->is_native_ = false; /* If we JIT, it will update this later. */
upb_inttable_init(&ret->dispatch, UPB_CTYPE_UINT64);
- if (ret->dest_handlers_) {
- upb_handlers_ref(ret->dest_handlers_, ret);
- }
return ret;
}
@@ -114,16 +57,31 @@ bool upb_pbdecodermethod_isnative(const upb_pbdecodermethod *m) {
return m->is_native_;
}
-const upb_pbdecodermethod *upb_pbdecodermethod_new(
- const upb_pbdecodermethodopts *opts, const void *owner) {
- const upb_pbdecodermethod *ret;
- upb_pbcodecache cache;
- upb_pbcodecache_init(&cache);
- ret = upb_pbcodecache_getdecodermethod(&cache, opts);
- upb_pbdecodermethod_ref(ret, owner);
- upb_pbcodecache_uninit(&cache);
- return ret;
+/* mgroup *********************************************************************/
+
+static void freegroup(mgroup *g) {
+ upb_inttable_iter i;
+
+ upb_inttable_begin(&i, &g->methods);
+ for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
+ freemethod(upb_value_getptr(upb_inttable_iter_value(&i)));
+ }
+
+ upb_inttable_uninit(&g->methods);
+#ifdef UPB_USE_JIT_X64
+ upb_pbdecoder_freejit(g);
+#endif
+ upb_gfree(g->bytecode);
+ upb_gfree(g);
+}
+
+mgroup *newgroup() {
+ mgroup *g = upb_gmalloc(sizeof(*g));
+ upb_inttable_init(&g->methods, UPB_CTYPE_PTR);
+ g->bytecode = NULL;
+ g->bytecode_end = NULL;
+ return g;
}
@@ -814,10 +772,13 @@ static void find_methods(compiler *c, const upb_handlers *h) {
upb_value v;
upb_msg_field_iter i;
const upb_msgdef *md;
+ upb_pbdecodermethod *method;
if (upb_inttable_lookupptr(&c->group->methods, h, &v))
return;
- newmethod(h, c->group);
+
+ method = newmethod(h, c->group);
+ upb_inttable_insertptr(&c->group->methods, h, upb_value_ptr(method));
/* Find submethods. */
md = upb_handlers_msgdef(h);
@@ -893,15 +854,13 @@ static void sethandlers(mgroup *g, bool allowjit) {
/* TODO(haberman): allow this to be constructed for an arbitrary set of dest
* handlers and other mgroups (but verify we have a transitive closure). */
-const mgroup *mgroup_new(const upb_handlers *dest, bool allowjit, bool lazy,
- const void *owner) {
+const mgroup *mgroup_new(const upb_handlers *dest, bool allowjit, bool lazy) {
mgroup *g;
compiler *c;
UPB_UNUSED(allowjit);
- UPB_ASSERT(upb_handlers_isfrozen(dest));
- g = newgroup(owner);
+ g = newgroup();
c = newcompiler(g, lazy);
find_methods(c, dest);
@@ -939,56 +898,63 @@ const mgroup *mgroup_new(const upb_handlers *dest, bool allowjit, bool lazy,
/* upb_pbcodecache ************************************************************/
-void upb_pbcodecache_init(upb_pbcodecache *c) {
- upb_inttable_init(&c->groups, UPB_CTYPE_CONSTPTR);
- c->allow_jit_ = true;
+upb_pbcodecache *upb_pbcodecache_new(upb_handlercache *dest) {
+ upb_pbcodecache *c = upb_gmalloc(sizeof(*c));
+
+ if (!c) return NULL;
+
+ c->dest = dest;
+ c->allow_jit = true;
+ c->lazy = false;
+
+ upb_arena_init(&c->arena);
+ if (!upb_inttable_init(&c->groups, UPB_CTYPE_CONSTPTR)) return NULL;
+
+ return c;
}
-void upb_pbcodecache_uninit(upb_pbcodecache *c) {
- upb_inttable_iter i;
- upb_inttable_begin(&i, &c->groups);
- for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
- const mgroup *group = upb_value_getconstptr(upb_inttable_iter_value(&i));
- mgroup_unref(group, c);
+void upb_pbcodecache_free(upb_pbcodecache *c) {
+ size_t i;
+
+ for (i = 0; i < upb_inttable_count(&c->groups); i++) {
+ upb_value v;
+ bool ok = upb_inttable_lookup(&c->groups, i, &v);
+ UPB_ASSERT(ok);
+ freegroup((void*)upb_value_getconstptr(v));
}
+
upb_inttable_uninit(&c->groups);
+ upb_gfree(c);
}
bool upb_pbcodecache_allowjit(const upb_pbcodecache *c) {
- return c->allow_jit_;
+ return c->allow_jit;
}
-bool upb_pbcodecache_setallowjit(upb_pbcodecache *c, bool allow) {
- if (upb_inttable_count(&c->groups) > 0)
- return false;
- c->allow_jit_ = allow;
- return true;
+void upb_pbcodecache_setallowjit(upb_pbcodecache *c, bool allow) {
+ UPB_ASSERT(upb_inttable_count(&c->groups) == 0);
+ c->allow_jit = allow;
}
-const upb_pbdecodermethod *upb_pbcodecache_getdecodermethod(
- upb_pbcodecache *c, const upb_pbdecodermethodopts *opts) {
+void upb_pbdecodermethodopts_setlazy(upb_pbcodecache *c, bool lazy) {
+ UPB_ASSERT(upb_inttable_count(&c->groups) == 0);
+ c->lazy = lazy;
+}
+
+const upb_pbdecodermethod *upb_pbcodecache_get(upb_pbcodecache *c,
+ const upb_msgdef *md) {
upb_value v;
bool ok;
+ const upb_handlers *h;
+ const mgroup *g;
/* Right now we build a new DecoderMethod every time.
* TODO(haberman): properly cache methods by their true key. */
- const mgroup *g = mgroup_new(opts->handlers, c->allow_jit_, opts->lazy, c);
+ h = upb_handlercache_get(c->dest, md);
+ g = mgroup_new(h, c->allow_jit, c->lazy);
upb_inttable_push(&c->groups, upb_value_constptr(g));
- ok = upb_inttable_lookupptr(&g->methods, opts->handlers, &v);
+ ok = upb_inttable_lookupptr(&g->methods, h, &v);
UPB_ASSERT(ok);
return upb_value_getptr(v);
}
-
-
-/* upb_pbdecodermethodopts ****************************************************/
-
-void upb_pbdecodermethodopts_init(upb_pbdecodermethodopts *opts,
- const upb_handlers *h) {
- opts->handlers = h;
- opts->lazy = false;
-}
-
-void upb_pbdecodermethodopts_setlazy(upb_pbdecodermethodopts *opts, bool lazy) {
- opts->lazy = lazy;
-}
diff --git a/upb/pb/decoder.h b/upb/pb/decoder.h
index 7c1877a..1a00801 100644
--- a/upb/pb/decoder.h
+++ b/upb/pb/decoder.h
@@ -30,10 +30,7 @@ class DecoderMethodOptions;
UPB_DECLARE_TYPE(upb::pb::CodeCache, upb_pbcodecache)
UPB_DECLARE_TYPE(upb::pb::Decoder, upb_pbdecoder)
-UPB_DECLARE_TYPE(upb::pb::DecoderMethodOptions, upb_pbdecodermethodopts)
-
-UPB_DECLARE_DERIVED_TYPE(upb::pb::DecoderMethod, upb::RefCounted,
- upb_pbdecodermethod, upb_refcounted)
+UPB_DECLARE_TYPE(upb::pb::DecoderMethod, upb_pbdecodermethod)
/* The maximum number of bytes we are required to buffer internally between
* calls to the decoder. The value is 14: a 5 byte unknown tag plus ten-byte
@@ -44,35 +41,10 @@ UPB_DECLARE_DERIVED_TYPE(upb::pb::DecoderMethod, upb::RefCounted,
#ifdef __cplusplus
-/* The parameters one uses to construct a DecoderMethod.
- * TODO(haberman): move allowjit here? Seems more convenient for users.
- * TODO(haberman): move this to be heap allocated for ABI stability. */
-class upb::pb::DecoderMethodOptions {
- public:
- /* Parameter represents the destination handlers that this method will push
- * to. */
- explicit DecoderMethodOptions(const Handlers* dest_handlers);
-
- /* Should the decoder push submessages to lazy handlers for fields that have
- * them? The caller should set this iff the lazy handlers expect data that is
- * in protobuf binary format and the caller wishes to lazy parse it. */
- void set_lazy(bool lazy);
-#else
-struct upb_pbdecodermethodopts {
-#endif
- const upb_handlers *handlers;
- bool lazy;
-};
-
-#ifdef __cplusplus
-
/* Represents the code to parse a protobuf according to a destination
* Handlers. */
class upb::pb::DecoderMethod {
public:
- /* Include base methods from upb::ReferenceCounted. */
- UPB_REFCOUNTED_CPPMETHODS
-
/* The destination handlers that are statically bound to this method.
* This method is only capable of outputting to a sink that uses these
* handlers. */
@@ -84,10 +56,6 @@ class upb::pb::DecoderMethod {
/* Whether this method is native. */
bool is_native() const;
- /* Convenience method for generating a DecoderMethod without explicitly
- * creating a CodeCache. */
- static reffed_ptr<const DecoderMethod> New(const DecoderMethodOptions& opts);
-
private:
UPB_DISALLOW_POD_OPS(DecoderMethod, upb::pb::DecoderMethod)
};
@@ -147,20 +115,14 @@ class upb::pb::Decoder {
UPB_DISALLOW_POD_OPS(Decoder, upb::pb::Decoder)
};
-#endif /* __cplusplus */
-
-#ifdef __cplusplus
-
/* A class for caching protobuf processing code, whether bytecode for the
* interpreted decoder or machine code for the JIT.
*
- * This class is not thread-safe.
- *
- * TODO(haberman): move this to be heap allocated for ABI stability. */
+ * This class is not thread-safe. */
class upb::pb::CodeCache {
public:
- CodeCache();
- ~CodeCache();
+ static CodeCache* New(HandlerCache* dest);
+ static void Free(CodeCache* cache);
/* Whether the cache is allowed to generate machine code. Defaults to true.
* There is no real reason to turn it off except for testing or if you are
@@ -172,33 +134,24 @@ class upb::pb::CodeCache {
bool allow_jit() const;
/* This may only be called when the object is first constructed, and prior to
- * any code generation, otherwise returns false and does nothing. */
- bool set_allow_jit(bool allow);
+ * any code generation. */
+ void set_allow_jit(bool allow);
- /* Returns a DecoderMethod that can push data to the given handlers.
- * If a suitable method already exists, it will be returned from the cache.
- *
- * Specifying the destination handlers here allows the DecoderMethod to be
- * statically bound to the destination handlers if possible, which can allow
- * more efficient decoding. However the returned method may or may not
- * actually be statically bound. But in all cases, the returned method can
- * push data to the given handlers. */
- const DecoderMethod *GetDecoderMethod(const DecoderMethodOptions& opts);
+ /* Should the decoder push submessages to lazy handlers for fields that have
+ * them? The caller should set this iff the lazy handlers expect data that is
+ * in protobuf binary format and the caller wishes to lazy parse it. */
+ void set_lazy(bool lazy);
- /* If/when someone needs to explicitly create a dynamically-bound
- * DecoderMethod*, we can add a method to get it here. */
+ /* Returns a DecoderMethod that can push data to the given handlers.
+ * If a suitable method already exists, it will be returned from the cache. */
+ const DecoderMethod *Get(const MessageDef* md);
private:
- UPB_DISALLOW_COPY_AND_ASSIGN(CodeCache)
-#else
-struct upb_pbcodecache {
-#endif
- bool allow_jit_;
-
- /* Array of mgroups. */
- upb_inttable groups;
+ UPB_DISALLOW_POD_OPS(CodeCache, upb::pb::CodeCache)
};
+#endif
+
UPB_BEGIN_EXTERN_C
upb_pbdecoder *upb_pbdecoder_create(upb_env *e,
@@ -211,28 +164,21 @@ size_t upb_pbdecoder_maxnesting(const upb_pbdecoder *d);
bool upb_pbdecoder_setmaxnesting(upb_pbdecoder *d, size_t max);
void upb_pbdecoder_reset(upb_pbdecoder *d);
-void upb_pbdecodermethodopts_init(upb_pbdecodermethodopts *opts,
- const upb_handlers *h);
-void upb_pbdecodermethodopts_setlazy(upb_pbdecodermethodopts *opts, bool lazy);
-/* Include refcounted methods like upb_pbdecodermethod_ref(). */
-UPB_REFCOUNTED_CMETHODS(upb_pbdecodermethod, upb_pbdecodermethod_upcast)
-
const upb_handlers *upb_pbdecodermethod_desthandlers(
const upb_pbdecodermethod *m);
const upb_byteshandler *upb_pbdecodermethod_inputhandler(
const upb_pbdecodermethod *m);
bool upb_pbdecodermethod_isnative(const upb_pbdecodermethod *m);
-const upb_pbdecodermethod *upb_pbdecodermethod_new(
- const upb_pbdecodermethodopts *opts, const void *owner);
-void upb_pbcodecache_init(upb_pbcodecache *c);
-void upb_pbcodecache_uninit(upb_pbcodecache *c);
+upb_pbcodecache *upb_pbcodecache_new(upb_handlercache *dest);
+void upb_pbcodecache_free(upb_pbcodecache *c);
bool upb_pbcodecache_allowjit(const upb_pbcodecache *c);
-bool upb_pbcodecache_setallowjit(upb_pbcodecache *c, bool allow);
-const upb_pbdecodermethod *upb_pbcodecache_getdecodermethod(
- upb_pbcodecache *c, const upb_pbdecodermethodopts *opts);
+void upb_pbcodecache_setallowjit(upb_pbcodecache *c, bool allow);
+void upb_pbcodecache_setlazy(upb_pbcodecache *c, bool lazy);
+const upb_pbdecodermethod *upb_pbcodecache_get(upb_pbcodecache *c,
+ const upb_msgdef *md);
UPB_END_EXTERN_C
@@ -264,13 +210,6 @@ inline bool Decoder::set_max_nesting(size_t max) {
}
inline void Decoder::Reset() { upb_pbdecoder_reset(this); }
-inline DecoderMethodOptions::DecoderMethodOptions(const Handlers* h) {
- upb_pbdecodermethodopts_init(this, h);
-}
-inline void DecoderMethodOptions::set_lazy(bool lazy) {
- upb_pbdecodermethodopts_setlazy(this, lazy);
-}
-
inline const Handlers* DecoderMethod::dest_handlers() const {
return upb_pbdecodermethod_desthandlers(this);
}
@@ -280,28 +219,21 @@ inline const BytesHandler* DecoderMethod::input_handler() const {
inline bool DecoderMethod::is_native() const {
return upb_pbdecodermethod_isnative(this);
}
-/* static */
-inline reffed_ptr<const DecoderMethod> DecoderMethod::New(
- const DecoderMethodOptions &opts) {
- const upb_pbdecodermethod *m = upb_pbdecodermethod_new(&opts, &m);
- return reffed_ptr<const DecoderMethod>(m, &m);
-}
-inline CodeCache::CodeCache() {
- upb_pbcodecache_init(this);
+inline CodeCache* CodeCache::New(HandlerCache* dest) {
+ return upb_pbcodecache_new(dest);
}
-inline CodeCache::~CodeCache() {
- upb_pbcodecache_uninit(this);
+inline void CodeCache::Free(CodeCache* cache) {
+ upb_pbcodecache_free(cache);
}
inline bool CodeCache::allow_jit() const {
return upb_pbcodecache_allowjit(this);
}
-inline bool CodeCache::set_allow_jit(bool allow) {
- return upb_pbcodecache_setallowjit(this, allow);
+inline void CodeCache::set_allow_jit(bool allow) {
+ upb_pbcodecache_setallowjit(this, allow);
}
-inline const DecoderMethod *CodeCache::GetDecoderMethod(
- const DecoderMethodOptions& opts) {
- return upb_pbcodecache_getdecodermethod(this, &opts);
+inline const DecoderMethod *CodeCache::Get(const MessageDef *md) {
+ return upb_pbcodecache_get(this, md);
}
} /* namespace pb */
diff --git a/upb/pb/decoder.int.h b/upb/pb/decoder.int.h
index f02bdd5..8d464fa 100644
--- a/upb/pb/decoder.int.h
+++ b/upb/pb/decoder.int.h
@@ -11,17 +11,6 @@
#include "upb/sink.h"
#include "upb/table.int.h"
-/* C++ names are not actually used since this type isn't exposed to users. */
-#ifdef __cplusplus
-namespace upb {
-namespace pb {
-class MessageGroup;
-} /* namespace pb */
-} /* namespace upb */
-#endif
-UPB_DECLARE_DERIVED_TYPE(upb::pb::MessageGroup, upb::RefCounted,
- mgroup, upb_refcounted)
-
/* Opcode definitions. The canonical meaning of each opcode is its
* implementation in the interpreter (the JIT is written to match this).
*
@@ -83,30 +72,25 @@ typedef enum {
UPB_INLINE opcode getop(uint32_t instr) { return instr & 0xff; }
+struct upb_pbcodecache {
+ upb_arena arena;
+ upb_handlercache *dest;
+ bool allow_jit;
+ bool lazy;
+
+ /* Array of mgroups. */
+ upb_inttable groups;
+};
+
/* Method group; represents a set of decoder methods that had their code
- * emitted together, and must therefore be freed together. Immutable once
- * created. It is possible we may want to expose this to users at some point.
- *
- * Overall ownership of Decoder objects looks like this:
- *
- * +----------+
- * | | <---> DecoderMethod
- * | method |
- * CodeCache ---> | group | <---> DecoderMethod
- * | |
- * | (mgroup) | <---> DecoderMethod
- * +----------+
- */
-struct mgroup {
- upb_refcounted base;
-
- /* Maps upb_msgdef/upb_handlers -> upb_pbdecodermethod. We own refs on the
- * methods. */
+ * emitted together. Immutable once created. */
+typedef struct {
+ /* Maps upb_msgdef/upb_handlers -> upb_pbdecodermethod. Owned by us.
+ *
+ * Ideally this would be on pbcodecache (if we were actually caching code).
+ * Right now we don't actually cache anything, which is wasteful. */
upb_inttable methods;
- /* When we add the ability to link to previously existing mgroups, we'll
- * need an array of mgroups we reference here, and own refs on them. */
-
/* The bytecode for our methods, if any exists. Owned by us. */
uint32_t *bytecode;
uint32_t *bytecode_end;
@@ -119,7 +103,7 @@ struct mgroup {
char *debug_info;
void *dl;
#endif
-};
+} mgroup;
/* The maximum that any submessages can be nested. Matches proto2's limit.
* This specifies the size of the decoder's statically-sized array and therefore
@@ -159,8 +143,6 @@ typedef struct {
} upb_pbdecoder_frame;
struct upb_pbdecodermethod {
- upb_refcounted base;
-
/* While compiling, the base is relative in "ofs", after compiling it is
* absolute in "ptr". */
union {
@@ -168,14 +150,8 @@ struct upb_pbdecodermethod {
void *ptr; /* Pointer to bytecode or machine code for this method. */
} code_base;
- /* The decoder method group to which this method belongs. We own a ref.
- * Owning a ref on the entire group is more coarse-grained than is strictly
- * necessary; all we truly require is that methods we directly reference
- * outlive us, while the group could contain many other messages we don't
- * require. But the group represents the messages that were
- * allocated+compiled together, so it makes the most sense to free them
- * together also. */
- const upb_refcounted *group;
+ /* The decoder method group to which this method belongs. */
+ const mgroup *group;
/* Whether this method is native code or bytecode. */
bool is_native_;
@@ -276,7 +252,6 @@ const char *upb_pbdecoder_getopname(unsigned int op);
/* JIT codegen entry point. */
void upb_pbdecoder_jit(mgroup *group);
void upb_pbdecoder_freejit(mgroup *group);
-UPB_REFCOUNTED_CMETHODS(mgroup, mgroup_upcast)
/* A special label that means "do field dispatch for this message and branch to
* wherever that takes you." */
diff --git a/upb/pb/encoder.c b/upb/pb/encoder.c
index 839ede0..ca3ca5c 100644
--- a/upb/pb/encoder.c
+++ b/upb/pb/encoder.c
@@ -526,9 +526,8 @@ void upb_pb_encoder_reset(upb_pb_encoder *e) {
/* public API *****************************************************************/
-const upb_handlers *upb_pb_encoder_newhandlers(const upb_msgdef *m,
- const void *owner) {
- return upb_handlers_newfrozen(m, owner, newhandlers_callback, NULL);
+upb_handlercache *upb_pb_encoder_newcache() {
+ return upb_handlercache_new(newhandlers_callback, NULL);
}
upb_pb_encoder *upb_pb_encoder_create(upb_env *env, const upb_handlers *h,
diff --git a/upb/pb/encoder.h b/upb/pb/encoder.h
index 41b7e7b..eefa385 100644
--- a/upb/pb/encoder.h
+++ b/upb/pb/encoder.h
@@ -47,7 +47,7 @@ class upb::pb::Encoder {
Sink* input();
/* Creates a new set of handlers for this MessageDef. */
- static reffed_ptr<const Handlers> NewHandlers(const MessageDef* msg);
+ static upb_handlercache* NewCache();
static const size_t kSize = UPB_PB_ENCODER_SIZE;
@@ -59,12 +59,12 @@ class upb::pb::Encoder {
UPB_BEGIN_EXTERN_C
-const upb_handlers *upb_pb_encoder_newhandlers(const upb_msgdef *m,
- const void *owner);
upb_sink *upb_pb_encoder_input(upb_pb_encoder *p);
upb_pb_encoder* upb_pb_encoder_create(upb_env* e, const upb_handlers* h,
upb_bytessink* output);
+upb_handlercache *upb_pb_encoder_newcache();
+
UPB_END_EXTERN_C
#ifdef __cplusplus
@@ -78,10 +78,8 @@ inline Encoder* Encoder::Create(Environment* env, const Handlers* handlers,
inline Sink* Encoder::input() {
return upb_pb_encoder_input(this);
}
-inline reffed_ptr<const Handlers> Encoder::NewHandlers(
- const upb::MessageDef *md) {
- const Handlers* h = upb_pb_encoder_newhandlers(md, &h);
- return reffed_ptr<const Handlers>(h, &h);
+inline upb_handlercache* Encoder::NewCache() {
+ return upb_pb_encoder_newcache();
}
} /* namespace pb */
} /* namespace upb */
diff --git a/upb/pb/textprinter.c b/upb/pb/textprinter.c
index e8033f8..b6f8024 100644
--- a/upb/pb/textprinter.c
+++ b/upb/pb/textprinter.c
@@ -327,9 +327,8 @@ upb_textprinter *upb_textprinter_create(upb_env *env, const upb_handlers *h,
return p;
}
-const upb_handlers *upb_textprinter_newhandlers(const upb_msgdef *m,
- const void *owner) {
- return upb_handlers_newfrozen(m, owner, &onmreg, NULL);
+upb_handlercache *upb_textprinter_newcache() {
+ return upb_handlercache_new(&onmreg, NULL);
}
upb_sink *upb_textprinter_input(upb_textprinter *p) { return &p->input_; }
diff --git a/upb/pb/textprinter.h b/upb/pb/textprinter.h
index 2f40ed8..06ff7d5 100644
--- a/upb/pb/textprinter.h
+++ b/upb/pb/textprinter.h
@@ -34,7 +34,7 @@ class upb::pb::TextPrinter {
/* If handler caching becomes a requirement we can add a code cache as in
* decoder.h */
- static reffed_ptr<const Handlers> NewHandlers(const MessageDef* md);
+ static HandlerCache* NewCache();
};
#endif
@@ -47,8 +47,7 @@ upb_textprinter *upb_textprinter_create(upb_env *env, const upb_handlers *h,
void upb_textprinter_setsingleline(upb_textprinter *p, bool single_line);
upb_sink *upb_textprinter_input(upb_textprinter *p);
-const upb_handlers *upb_textprinter_newhandlers(const upb_msgdef *m,
- const void *owner);
+upb_handlercache *upb_textprinter_newcache();
UPB_END_EXTERN_C
@@ -67,10 +66,8 @@ inline void TextPrinter::SetSingleLineMode(bool single_line) {
inline Sink* TextPrinter::input() {
return upb_textprinter_input(this);
}
-inline reffed_ptr<const Handlers> TextPrinter::NewHandlers(
- const MessageDef *md) {
- const Handlers* h = upb_textprinter_newhandlers(md, &h);
- return reffed_ptr<const Handlers>(h, &h);
+inline HandlerCache* TextPrinter::NewCache() {
+ return upb_textprinter_newcache();
}
} /* namespace pb */
} /* namespace upb */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback