summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Haberman <joshua@reverberate.org>2009-07-03 11:50:13 -0700
committerJoshua Haberman <joshua@reverberate.org>2009-07-03 11:50:13 -0700
commitaecbfe42243ccd06425f021df6fe8d8d65974db7 (patch)
treece93d0c7d342895b1603693309ec44b8fe7d80a8
parent62be5969a14b36e4f3ca336ec57c4627f541a69c (diff)
Moved upb_enum to a proper C file, updated upb_inlinedefs.
-rw-r--r--Makefile2
-rw-r--r--tests.c1
-rw-r--r--upb.h2
-rw-r--r--upb_context.h6
-rw-r--r--upb_enum.c31
-rw-r--r--upb_enum.h25
-rw-r--r--upb_inlinedefs.c11
7 files changed, 52 insertions, 26 deletions
diff --git a/Makefile b/Makefile
index ced605c..08c56cf 100644
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@ CC=gcc
CXX=g++
CFLAGS=-std=c99
CPPFLAGS=-O0 -Wall -Wextra -pedantic -g -DUPB_UNALIGNED_READS_OK -fomit-frame-pointer
-OBJ=upb_parse.o upb_table.o upb_msg.o upb_context.o descriptor.o
+OBJ=upb_parse.o upb_table.o upb_msg.o upb_enum.o upb_context.o descriptor.o
all: $(OBJ) test_table tests
clean:
rm -f *.o test_table tests
diff --git a/tests.c b/tests.c
index c42ebd9..7bc5dde 100644
--- a/tests.c
+++ b/tests.c
@@ -3,6 +3,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "descriptor.c"
+#include "upb_enum.c"
#include "upb_parse.c"
#include "upb_context.c"
#include "upb_msg.c"
diff --git a/upb.h b/upb.h
index d62fba6..d76ba75 100644
--- a/upb.h
+++ b/upb.h
@@ -26,7 +26,9 @@ extern "C" {
#endif
/* inline if possible, emit standalone code if required. */
+#ifndef INLINE
#define INLINE static inline
+#endif
/* The maximum that any submessages can be nested. Matches proto2's limit. */
#define UPB_MAX_NESTING 64
diff --git a/upb_context.h b/upb_context.h
index d96ee39..8229ae4 100644
--- a/upb_context.h
+++ b/upb_context.h
@@ -16,6 +16,8 @@
#include "upb.h"
#include "upb_table.h"
+struct google_protobuf_FileDescriptorProto;
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -34,7 +36,7 @@ struct upb_context {
/* A list of the FileDescriptorProtos we own (from having parsed them
* ourselves) and must free on destruction. */
size_t fd_size, fd_len;
- google_protobuf_FileDescriptorProto **fd;
+ struct google_protobuf_FileDescriptorProto **fd;
};
/* Initializes and frees a upb_context, respectively. Newly initialized
@@ -89,7 +91,7 @@ INLINE struct upb_symtab_entry *upb_context_symnext(
* 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. */
bool upb_context_addfd(struct upb_context *c,
- google_protobuf_FileDescriptorProto *fd);
+ struct google_protobuf_FileDescriptorProto *fd);
/* Like the previous, but takes a serialized FileDescriptorProto and parses
* it before adding to the context. */
diff --git a/upb_enum.c b/upb_enum.c
new file mode 100644
index 0000000..b599c9b
--- /dev/null
+++ b/upb_enum.c
@@ -0,0 +1,31 @@
+/*
+ * upb - a minimalist implementation of protocol buffers.
+ *
+ * Copyright (c) 2009 Joshua Haberman. See LICENSE for details.
+ */
+
+#include "descriptor.h"
+#include "upb_enum.h"
+
+void upb_enum_init(struct upb_enum *e,
+ struct google_protobuf_EnumDescriptorProto *ed) {
+ int num_values = ed->set_flags.has.value ? ed->value->len : 0;
+ e->descriptor = ed;
+ upb_strtable_init(&e->nametoint, num_values, sizeof(struct upb_enum_ntoi_entry));
+ upb_inttable_init(&e->inttoname, num_values, sizeof(struct upb_enum_iton_entry));
+
+ for(int i = 0; i < num_values; i++) {
+ google_protobuf_EnumValueDescriptorProto *value = ed->value->elements[i];
+ struct upb_enum_ntoi_entry ntoi_entry = {.e = {.key = *value->name},
+ .value = value->number};
+ struct upb_enum_iton_entry iton_entry = {.e = {.key = value->number},
+ .string = value->name};
+ upb_strtable_insert(&e->nametoint, &ntoi_entry.e);
+ upb_inttable_insert(&e->inttoname, &iton_entry.e);
+ }
+}
+
+void upb_enum_free(struct upb_enum *e) {
+ upb_strtable_free(&e->nametoint);
+ upb_inttable_free(&e->inttoname);
+}
diff --git a/upb_enum.h b/upb_enum.h
index 2c4010b..9fea3a4 100644
--- a/upb_enum.h
+++ b/upb_enum.h
@@ -34,27 +34,8 @@ struct upb_enum_iton_entry {
/* Initializes and frees an enum, respectively. Caller retains ownership of
* ed, but it must outlive e. */
-INLINE void upb_enum_init(struct upb_enum *e,
- struct google_protobuf_EnumDescriptorProto *ed) {
- int num_values = ed->set_flags.has.value ? ed->value->len : 0;
- e->descriptor = ed;
- upb_strtable_init(&e->nametoint, num_values, sizeof(struct upb_enum_ntoi_entry));
- upb_inttable_init(&e->inttoname, num_values, sizeof(struct upb_enum_iton_entry));
-
- for(int i = 0; i < num_values; i++) {
- google_protobuf_EnumValueDescriptorProto *value = ed->value->elements[i];
- struct upb_enum_ntoi_entry ntoi_entry = {.e = {.key = *value->name},
- .value = value->number};
- struct upb_enum_iton_entry iton_entry = {.e = {.key = value->number},
- .string = value->name};
- upb_strtable_insert(&e->nametoint, &ntoi_entry.e);
- upb_inttable_insert(&e->inttoname, &iton_entry.e);
- }
-}
-
-INLINE void upb_enum_free(struct upb_enum *e) {
- upb_strtable_free(&e->nametoint);
- upb_inttable_free(&e->inttoname);
-}
+void upb_enum_init(struct upb_enum *e,
+ struct google_protobuf_EnumDescriptorProto *ed);
+void upb_enum_free(struct upb_enum *e);
#endif /* UPB_ENUM_H_ */
diff --git a/upb_inlinedefs.c b/upb_inlinedefs.c
index 8f9514a..60863c4 100644
--- a/upb_inlinedefs.c
+++ b/upb_inlinedefs.c
@@ -1,10 +1,19 @@
/*
* upb - a minimalist implementation of protocol buffers.
*
+ * This file, if compiled, will contain standalone (non-inlined) versions of
+ * all inline functions defined in header files. We don't generally use this
+ * file since we use "static inline" for inline functions (which will put a
+ * standalone version of the function in any .o file that needs it, but
+ * compiling this file and dumping the object file will let us inspect how
+ * inline functions are compiled, so we keep it around.
+ *
* Copyright (c) 2009 Joshua Haberman. See LICENSE for details.
*/
#define INLINE
-#include "upb_parse.h"
+#include "upb_context.h"
+#include "upb_enum.h"
#include "upb_msg.h"
+#include "upb_parse.h"
#include "upb_table.h"
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback