summaryrefslogtreecommitdiff
path: root/src/upb_context.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/upb_context.h')
-rw-r--r--src/upb_context.h96
1 files changed, 37 insertions, 59 deletions
diff --git a/src/upb_context.h b/src/upb_context.h
index b20f169..177b42e 100644
--- a/src/upb_context.h
+++ b/src/upb_context.h
@@ -24,26 +24,18 @@ extern "C" {
/* Definitions. ***************************************************************/
-struct upb_symtab_entry {
- struct upb_strtable_entry e;
- struct upb_def *def; /* We own one ref. */
-};
-
struct upb_context {
upb_atomic_refcount_t refcount;
- upb_rwlock_t lock;
- struct upb_strtable symtab; /* The context's symbol table. */
- struct upb_strtable psymtab; /* Private symbols, for internal use. */
- struct upb_msgdef *fds_msgdef; /* In psymtab, ptr here for convenience. */
-
- /* A list of the FileDescriptorProtos we own (from having parsed them
- * ourselves) and must free on destruction. */
- size_t fds_size, fds_len;
- struct google_protobuf_FileDescriptorSet **fds;
+ upb_rwlock_t lock; // Protects all members except the refcount.
+ struct upb_msgdef *fds_msgdef; // In psymtab, ptr here for convenience.
+
+ // Our symbol tables; we own refs to the defs therein.
+ struct upb_strtable symtab; // The context's symbol table.
+ struct upb_strtable psymtab; // Private symbols, for internal use.
};
-/* Initializes a upb_context. Contexts are not freed explicitly, but unref'd
- * when the caller is done with them. */
+// Initializes a upb_context. Contexts are not freed explicitly, but unref'd
+// when the caller is done with them.
struct upb_context *upb_context_new(void);
INLINE void upb_context_ref(struct upb_context *c) {
upb_atomic_ref(&c->refcount);
@@ -52,55 +44,41 @@ void upb_context_unref(struct upb_context *c);
/* Looking up symbols. ********************************************************/
-/* Resolves the given symbol using the rules described in descriptor.proto,
- * namely:
- *
- * If the name starts with a '.', it is fully-qualified. Otherwise, C++-like
- * scoping rules are used to find the type (i.e. first the nested types
- * within this message are searched, then within the parent, on up to the
- * root namespace).
- *
- * Returns NULL if the symbol has not been defined. */
-bool upb_context_resolve(struct upb_context *c, struct upb_string *base,
- struct upb_string *symbol,
- struct upb_symtab_entry *out_entry);
-
-/* Find an entry in the symbol table with this exact name. Returns NULL if no
- * such symbol name exists. */
-bool upb_context_lookup(struct upb_context *c, struct upb_string *symbol,
- struct upb_symtab_entry *out_entry);
-
-/* For enumerating over the entries in the symbol table. The enumerator
- * callback will be called once for every symtab entry.
- *
- * The callback *must not* block or take any significant amount of time, since
- * the upb_context's lock is held while it is being called! */
-typedef void (*upb_context_enumerator_t)(
- void *udata, struct upb_symtab_entry *entry);
-void upb_context_enumerate(struct upb_context *c, upb_context_enumerator_t,
- void *udata);
+// Resolves the given symbol using the rules described in descriptor.proto,
+// namely:
+//
+// If the name starts with a '.', it is fully-qualified. Otherwise, C++-like
+// scoping rules are used to find the type (i.e. first the nested types
+// within this message are searched, then within the parent, on up to the
+// root namespace).
+//
+// Returns NULL if no such symbol has been defined.
+struct upb_def *upb_context_resolve(struct upb_context *c,
+ struct upb_string *base,
+ struct upb_string *symbol);
+
+// Find an entry in the symbol table with this exact name. Returns NULL if no
+// such symbol name has been defined.
+struct upb_def *upb_context_lookup(struct upb_context *c,
+ struct upb_string *sym);
+
+// Gets an array of pointers to all currently active defs in this context. The
+// caller owns the returned array (which is of length *count) as well as a ref
+// to each symbol inside.
+struct upb_def **upb_context_getandref_defs(struct upb_context *c, int *count);
/* Adding symbols. ************************************************************/
-/* Adds the definitions in the given file descriptor to this context. All
- * types that are referenced from fd must have previously been defined (or be
- * defined in fd). fd may not attempt to define any names that are already
- * defined in this context.
- *
- * Caller retains ownership of fd, but the context will contain references to
- * it, so it must outlive the context.
- *
- * upb_context_addfd only returns true or false; it does not give any hint
- * about what happened in the case of failure. This is because the descriptor
- * is expected to have been validated at the time it was parsed/generated. */
-void upb_context_addfds(struct upb_context *c,
- struct google_protobuf_FileDescriptorSet *fds,
- struct upb_status *status);
-
+// Adds the definitions in the given file descriptor to this context. All
+// types that are referenced from fd must have previously been defined (or be
+// defined in fd). fd may not attempt to define any names that are already
+// defined in this context. Caller retains ownership of fd. status indicates
+// whether the operation was successful or not, and the error message (if any).
+struct google_protobuf_FileDescriptorSet;
void upb_context_addfds(struct upb_context *c,
struct google_protobuf_FileDescriptorSet *fds,
struct upb_status *status);
-
+// Like the above, but also parses the FileDescriptorSet from fds.
void upb_context_parsefds(struct upb_context *c, struct upb_string *fds,
struct upb_status *status);
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback