Mass API rename and clang-reformat (#485)
* Wave 1: upb_fielddef.
* upb_fielddef itself.
* upb_oneofdef.
* upb_msgdef.
* ExtensionRange.
* upb_enumdef
* upb_enumvaldef
* upb_filedef
* upb_methoddef
* upb_servicedef
* upb_symtab
* upb_defpool_init
* upb_wellknown and upb_syntax_t
* Some constants.
* upb_status
* upb_strview
* upb_arena
* upb.h constants
* reflection
* encode
* JSON decode.
* json encode.
* msg_internal.
* Formatted with clang-format.
* Some naming fixups and comment reformatting.
* More refinements.
* A few more stragglers.
* Fixed PyObject_HEAD with semicolon. Removed TODO entries.
diff --git a/python/descriptor_pool.c b/python/descriptor_pool.c
index 7a39403..95e14fe 100644
--- a/python/descriptor_pool.c
+++ b/python/descriptor_pool.c
@@ -27,21 +27,21 @@
#include "python/descriptor_pool.h"
+#include "google/protobuf/descriptor.upbdefs.h"
#include "python/convert.h"
#include "python/descriptor.h"
#include "python/message.h"
#include "python/protobuf.h"
#include "upb/def.h"
#include "upb/util/def_to_proto.h"
-#include "google/protobuf/descriptor.upbdefs.h"
// -----------------------------------------------------------------------------
// DescriptorPool
// -----------------------------------------------------------------------------
typedef struct {
- PyObject_HEAD
- upb_symtab* symtab;
+ PyObject_HEAD;
+ upb_DefPool* symtab;
PyObject* db; // The DescriptorDatabase underlying this pool. May be NULL.
} PyUpb_DescriptorPool;
@@ -50,10 +50,10 @@
return s->default_pool;
}
-const upb_msgdef* PyUpb_DescriptorPool_GetFileProtoDef(void) {
+const upb_MessageDef* PyUpb_DescriptorPool_GetFileProtoDef(void) {
PyUpb_ModuleState* s = PyUpb_ModuleState_Get();
if (!s->c_descriptor_symtab) {
- s->c_descriptor_symtab = upb_symtab_new();
+ s->c_descriptor_symtab = upb_DefPool_New();
}
return google_protobuf_FileDescriptorProto_getmsgdef(s->c_descriptor_symtab);
}
@@ -61,7 +61,7 @@
static PyObject* PyUpb_DescriptorPool_DoCreateWithCache(
PyTypeObject* type, PyObject* db, PyUpb_WeakMap* obj_cache) {
PyUpb_DescriptorPool* pool = (void*)PyType_GenericAlloc(type, 0);
- pool->symtab = upb_symtab_new();
+ pool->symtab = upb_DefPool_New();
pool->db = db;
Py_XINCREF(pool->db);
PyUpb_WeakMap_Add(obj_cache, pool->symtab, &pool->ob_base);
@@ -74,7 +74,7 @@
PyUpb_ObjCache_Instance());
}
-upb_symtab* PyUpb_DescriptorPool_GetSymtab(PyObject* pool) {
+upb_DefPool* PyUpb_DescriptorPool_GetSymtab(PyObject* pool) {
return ((PyUpb_DescriptorPool*)pool)->symtab;
}
@@ -89,7 +89,7 @@
return 0;
}
-PyObject* PyUpb_DescriptorPool_Get(const upb_symtab* symtab) {
+PyObject* PyUpb_DescriptorPool_Get(const upb_DefPool* symtab) {
PyObject* pool = PyUpb_ObjCache_Get(symtab);
assert(pool);
return pool;
@@ -97,7 +97,7 @@
static void PyUpb_DescriptorPool_Dealloc(PyUpb_DescriptorPool* self) {
PyUpb_DescriptorPool_Clear(self);
- upb_symtab_free(self->symtab);
+ upb_DefPool_Free(self->symtab);
PyUpb_ObjCache_Delete(self->symtab);
PyUpb_Dealloc(self);
}
@@ -158,18 +158,16 @@
return ret;
}
-bool PyUpb_DescriptorPool_CheckNoDatabase(PyObject* _self) {
- return true;
-}
+bool PyUpb_DescriptorPool_CheckNoDatabase(PyObject* _self) { return true; }
static bool PyUpb_DescriptorPool_LoadDependentFiles(
PyUpb_DescriptorPool* self, google_protobuf_FileDescriptorProto* proto) {
size_t n;
- const upb_strview* deps =
+ const upb_StringView* deps =
google_protobuf_FileDescriptorProto_dependency(proto, &n);
for (size_t i = 0; i < n; i++) {
- const upb_filedef* dep =
- upb_symtab_lookupfile2(self->symtab, deps[i].data, deps[i].size);
+ const upb_FileDef* dep = upb_DefPool_FindFileByNameWithSize(
+ self->symtab, deps[i].data, deps[i].size);
if (!dep) {
PyObject* filename =
PyUnicode_FromStringAndSize(deps[i].data, deps[i].size);
@@ -185,7 +183,7 @@
static PyObject* PyUpb_DescriptorPool_DoAddSerializedFile(
PyObject* _self, PyObject* serialized_pb) {
PyUpb_DescriptorPool* self = (PyUpb_DescriptorPool*)_self;
- upb_arena* arena = upb_arena_new();
+ upb_Arena* arena = upb_Arena_New();
if (!arena) PYUPB_RETURN_OOM;
PyObject* result = NULL;
@@ -202,9 +200,9 @@
goto done;
}
- upb_strview name = google_protobuf_FileDescriptorProto_name(proto);
- const upb_filedef* file =
- upb_symtab_lookupfile2(self->symtab, name.data, name.size);
+ upb_StringView name = google_protobuf_FileDescriptorProto_name(proto);
+ const upb_FileDef* file =
+ upb_DefPool_FindFileByNameWithSize(self->symtab, name.data, name.size);
if (file) {
// If the existing file is equal to the new file, then silently ignore the
@@ -215,7 +213,7 @@
PyErr_SetNone(PyExc_MemoryError);
goto done;
}
- const upb_msgdef* m = PyUpb_DescriptorPool_GetFileProtoDef();
+ const upb_MessageDef* m = PyUpb_DescriptorPool_GetFileProtoDef();
if (PyUpb_Message_IsEqual(proto, existing, m)) {
Py_INCREF(Py_None);
result = Py_None;
@@ -227,21 +225,22 @@
if (!PyUpb_DescriptorPool_LoadDependentFiles(self, proto)) goto done;
}
- upb_status status;
- upb_status_clear(&status);
+ upb_Status status;
+ upb_Status_Clear(&status);
- const upb_filedef* filedef = upb_symtab_addfile(self->symtab, proto, &status);
+ const upb_FileDef* filedef =
+ upb_DefPool_AddFile(self->symtab, proto, &status);
if (!filedef) {
PyErr_Format(PyExc_TypeError,
"Couldn't build proto file into descriptor pool: %s",
- upb_status_errmsg(&status));
+ upb_Status_ErrorMessage(&status));
goto done;
}
result = PyUpb_FileDescriptor_Get(filedef);
done:
- upb_arena_free(arena);
+ upb_Arena_Free(arena);
return result;
}
@@ -249,9 +248,9 @@
PyObject* file_desc) {
PyObject* subargs = PyTuple_New(0);
if (!PyUpb_CMessage_Check(file_desc)) return NULL;
- const upb_msgdef* m = PyUpb_CMessage_GetMsgdef(file_desc);
+ const upb_MessageDef* m = PyUpb_CMessage_GetMsgdef(file_desc);
const char* file_proto_name = "google.protobuf.FileDescriptorProto";
- if (strcmp(upb_msgdef_fullname(m), file_proto_name) != 0) {
+ if (strcmp(upb_MessageDef_FullName(m), file_proto_name) != 0) {
return PyErr_Format(PyExc_TypeError, "Can only add FileDescriptorProto");
}
PyObject* serialized =
@@ -272,7 +271,7 @@
* Adds the given serialized FileDescriptorProto to the pool.
*/
static PyObject* PyUpb_DescriptorPool_AddSerializedFile(
- PyObject * _self, PyObject * serialized_pb) {
+ PyObject* _self, PyObject* serialized_pb) {
PyUpb_DescriptorPool* self = (PyUpb_DescriptorPool*)_self;
if (self->db) {
PyErr_SetString(
@@ -310,10 +309,10 @@
const char* name = PyUpb_GetStrData(arg);
if (!name) return NULL;
- const upb_filedef* file = upb_symtab_lookupfile(self->symtab, name);
+ const upb_FileDef* file = upb_DefPool_FindFileByName(self->symtab, name);
if (file == NULL && self->db) {
if (!PyUpb_DescriptorPool_TryLoadFilename(self, arg)) return NULL;
- file = upb_symtab_lookupfile(self->symtab, name);
+ file = upb_DefPool_FindFileByName(self->symtab, name);
}
if (file == NULL) {
return PyErr_Format(PyExc_KeyError, "Couldn't find file %.200s", name);
@@ -335,10 +334,11 @@
const char* name = PyUpb_GetStrData(arg);
if (!name) return NULL;
- const upb_fielddef* field = upb_symtab_lookupext(self->symtab, name);
+ const upb_FieldDef* field =
+ upb_DefPool_FindExtensionByName(self->symtab, name);
if (field == NULL && self->db) {
if (!PyUpb_DescriptorPool_TryLoadSymbol(self, arg)) return NULL;
- field = upb_symtab_lookupext(self->symtab, name);
+ field = upb_DefPool_FindExtensionByName(self->symtab, name);
}
if (field == NULL) {
return PyErr_Format(PyExc_KeyError, "Couldn't find extension %.200s", name);
@@ -360,10 +360,10 @@
const char* name = PyUpb_GetStrData(arg);
if (!name) return NULL;
- const upb_msgdef* m = upb_symtab_lookupmsg(self->symtab, name);
+ const upb_MessageDef* m = upb_DefPool_FindMessageByName(self->symtab, name);
if (m == NULL && self->db) {
if (!PyUpb_DescriptorPool_TryLoadSymbol(self, arg)) return NULL;
- m = upb_symtab_lookupmsg(self->symtab, name);
+ m = upb_DefPool_FindMessageByName(self->symtab, name);
}
if (m == NULL) {
return PyErr_Format(PyExc_KeyError, "Couldn't find message %.200s", name);
@@ -397,14 +397,13 @@
if (!name) return NULL;
size_t parent_size;
- const char* child =
- PyUpb_DescriptorPool_SplitSymbolName(name, &parent_size);
- const upb_fielddef* f = NULL;
+ const char* child = PyUpb_DescriptorPool_SplitSymbolName(name, &parent_size);
+ const upb_FieldDef* f = NULL;
if (child) {
- const upb_msgdef* parent =
- upb_symtab_lookupmsg2(self->symtab, name, parent_size);
+ const upb_MessageDef* parent =
+ upb_DefPool_FindMessageByNameWithSize(self->symtab, name, parent_size);
if (parent) {
- f = upb_msgdef_ntofz(parent, child);
+ f = upb_MessageDef_FindFieldByName(parent, child);
}
}
@@ -428,10 +427,10 @@
const char* name = PyUpb_GetStrData(arg);
if (!name) return NULL;
- const upb_enumdef* e = upb_symtab_lookupenum(self->symtab, name);
+ const upb_EnumDef* e = upb_DefPool_FindEnumByName(self->symtab, name);
if (e == NULL && self->db) {
if (!PyUpb_DescriptorPool_TryLoadSymbol(self, arg)) return NULL;
- e = upb_symtab_lookupenum(self->symtab, name);
+ e = upb_DefPool_FindEnumByName(self->symtab, name);
}
if (e == NULL) {
return PyErr_Format(PyExc_KeyError, "Couldn't find enum %.200s", name);
@@ -457,14 +456,15 @@
const char* child = PyUpb_DescriptorPool_SplitSymbolName(name, &parent_size);
if (child) {
- const upb_msgdef* parent =
- upb_symtab_lookupmsg2(self->symtab, name, parent_size);
+ const upb_MessageDef* parent =
+ upb_DefPool_FindMessageByNameWithSize(self->symtab, name, parent_size);
if (parent == NULL && self->db) {
if (!PyUpb_DescriptorPool_TryLoadSymbol(self, arg)) return NULL;
- parent = upb_symtab_lookupmsg2(self->symtab, name, parent_size);
+ parent = upb_DefPool_FindMessageByNameWithSize(self->symtab, name,
+ parent_size);
}
if (parent) {
- const upb_oneofdef* o = upb_msgdef_ntooz(parent, child);
+ const upb_OneofDef* o = upb_MessageDef_FindOneofByName(parent, child);
return PyUpb_OneofDescriptor_Get(o);
}
}
@@ -479,7 +479,7 @@
const char* name = PyUpb_GetStrData(arg);
if (!name) return NULL;
- const upb_servicedef* s = upb_symtab_lookupservice(self->symtab, name);
+ const upb_ServiceDef* s = upb_DefPool_FindServiceByName(self->symtab, name);
if (s == NULL) {
return PyErr_Format(PyExc_KeyError, "Couldn't find enum %.200s", name);
}
@@ -494,10 +494,10 @@
const char* name = PyUpb_GetStrData(arg);
if (!name) return NULL;
- const upb_filedef* f = upb_symtab_lookupfileforsym(self->symtab, name);
+ const upb_FileDef* f = upb_DefPool_FindFileByNameforsym(self->symtab, name);
if (f == NULL && self->db) {
if (!PyUpb_DescriptorPool_TryLoadSymbol(self, arg)) return NULL;
- f = upb_symtab_lookupfileforsym(self->symtab, name);
+ f = upb_DefPool_FindFileByNameforsym(self->symtab, name);
}
if (f == NULL) {
return PyErr_Format(PyExc_KeyError, "Couldn't find symbol %.200s", name);
@@ -515,7 +515,7 @@
return NULL;
}
- const upb_fielddef* f = upb_symtab_lookupextbynum(
+ const upb_FieldDef* f = upb_DefPool_FindExtensionByNumber(
self->symtab, PyUpb_Descriptor_GetDef(message_descriptor), number);
if (f == NULL) {
return PyErr_Format(PyExc_KeyError, "Couldn't find Extension %d", number);
@@ -527,9 +527,9 @@
static PyObject* PyUpb_DescriptorPool_FindAllExtensions(PyObject* _self,
PyObject* msg_desc) {
PyUpb_DescriptorPool* self = (PyUpb_DescriptorPool*)_self;
- const upb_msgdef* m = PyUpb_Descriptor_GetDef(msg_desc);
+ const upb_MessageDef* m = PyUpb_Descriptor_GetDef(msg_desc);
size_t n;
- const upb_fielddef** ext = upb_symtab_getallexts(self->symtab, m, &n);
+ const upb_FieldDef** ext = upb_DefPool_GetAllExtensions(self->symtab, m, &n);
PyObject* ret = PyList_New(n);
for (size_t i = 0; i < n; i++) {
PyObject* field = PyUpb_FieldDescriptor_Get(ext[i]);