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/convert.c b/python/convert.c
index 3ad5b1b..d1229b3 100644
--- a/python/convert.c
+++ b/python/convert.c
@@ -13,11 +13,11 @@
* 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
+ * 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
@@ -32,26 +32,27 @@
#include "upb/reflection.h"
#include "upb/util/compare.h"
-PyObject* PyUpb_UpbToPy(upb_msgval val, const upb_fielddef *f, PyObject *arena) {
- switch (upb_fielddef_type(f)) {
- case UPB_TYPE_ENUM:
- case UPB_TYPE_INT32:
+PyObject* PyUpb_UpbToPy(upb_MessageValue val, const upb_FieldDef* f,
+ PyObject* arena) {
+ switch (upb_FieldDef_CType(f)) {
+ case kUpb_CType_Enum:
+ case kUpb_CType_Int32:
return PyLong_FromLong(val.int32_val);
- case UPB_TYPE_INT64:
+ case kUpb_CType_Int64:
return PyLong_FromLongLong(val.int64_val);
- case UPB_TYPE_UINT32:
+ case kUpb_CType_UInt32:
return PyLong_FromSize_t(val.uint32_val);
- case UPB_TYPE_UINT64:
+ case kUpb_CType_UInt64:
return PyLong_FromUnsignedLongLong(val.uint64_val);
- case UPB_TYPE_FLOAT:
+ case kUpb_CType_Float:
return PyFloat_FromDouble(val.float_val);
- case UPB_TYPE_DOUBLE:
+ case kUpb_CType_Double:
return PyFloat_FromDouble(val.double_val);
- case UPB_TYPE_BOOL:
+ case kUpb_CType_Bool:
return PyBool_FromLong(val.bool_val);
- case UPB_TYPE_BYTES:
+ case kUpb_CType_Bytes:
return PyBytes_FromStringAndSize(val.str_val.data, val.str_val.size);
- case UPB_TYPE_STRING: {
+ case kUpb_CType_String: {
PyObject* ret =
PyUnicode_DecodeUTF8(val.str_val.data, val.str_val.size, NULL);
// If the string can't be decoded in UTF-8, just return a bytes object
@@ -64,18 +65,18 @@
}
return ret;
}
- case UPB_TYPE_MESSAGE:
+ case kUpb_CType_Message:
return PyUpb_CMessage_Get((upb_msg*)val.msg_val,
- upb_fielddef_msgsubdef(f), arena);
+ upb_FieldDef_MessageSubDef(f), arena);
default:
PyErr_Format(PyExc_SystemError,
"Getting a value from a field of unknown type %d",
- upb_fielddef_type(f));
+ upb_FieldDef_CType(f));
return NULL;
}
}
-static bool PyUpb_GetInt64(PyObject *obj, int64_t *val) {
+static bool PyUpb_GetInt64(PyObject* obj, int64_t* val) {
// We require that the value is either an integer or has an __index__
// conversion.
if (!PyIndex_Check(obj)) {
@@ -95,7 +96,7 @@
return false;
}
-static bool PyUpb_GetUint64(PyObject *obj, uint64_t *val) {
+static bool PyUpb_GetUint64(PyObject* obj, uint64_t* val) {
// We require that the value is either an integer or has an __index__
// conversion.
if (!PyIndex_Check(obj)) {
@@ -119,7 +120,7 @@
return false;
}
-static bool PyUpb_GetInt32(PyObject *obj, int32_t *val) {
+static bool PyUpb_GetInt32(PyObject* obj, int32_t* val) {
int64_t i64;
if (!PyUpb_GetInt64(obj, &i64)) return false;
if (i64 < INT32_MIN || i64 > INT32_MAX) {
@@ -130,7 +131,7 @@
return true;
}
-static bool PyUpb_GetUint32(PyObject *obj, uint32_t *val) {
+static bool PyUpb_GetUint32(PyObject* obj, uint32_t* val) {
uint64_t u64;
if (!PyUpb_GetUint64(obj, &u64)) return false;
if (u64 > UINT32_MAX) {
@@ -143,12 +144,12 @@
// If `arena` is specified, copies the string data into the given arena.
// Otherwise aliases the given data.
-static upb_msgval PyUpb_MaybeCopyString(const char *ptr, size_t size,
- upb_arena *arena) {
- upb_msgval ret;
+static upb_MessageValue PyUpb_MaybeCopyString(const char* ptr, size_t size,
+ upb_Arena* arena) {
+ upb_MessageValue ret;
ret.str_val.size = size;
if (arena) {
- char *buf = upb_arena_malloc(arena, size);
+ char* buf = upb_Arena_Malloc(arena, size);
memcpy(buf, ptr, size);
ret.str_val.data = buf;
} else {
@@ -157,23 +158,24 @@
return ret;
}
-static bool PyUpb_PyToUpbEnum(PyObject *obj, const upb_enumdef *e,
- upb_msgval *val) {
+static bool PyUpb_PyToUpbEnum(PyObject* obj, const upb_EnumDef* e,
+ upb_MessageValue* val) {
if (PyUnicode_Check(obj)) {
Py_ssize_t size;
- const char *name = PyUnicode_AsUTF8AndSize(obj, &size);
- const upb_enumvaldef *ev = upb_enumdef_lookupname(e, name, size);
+ const char* name = PyUnicode_AsUTF8AndSize(obj, &size);
+ const upb_EnumValueDef* ev =
+ upb_EnumDef_FindValueByNameWithSize(e, name, size);
if (!ev) {
PyErr_Format(PyExc_ValueError, "unknown enum label \"%s\"", name);
return false;
}
- val->int32_val = upb_enumvaldef_number(ev);
+ val->int32_val = upb_EnumValueDef_Number(ev);
return true;
} else {
int32_t i32;
if (!PyUpb_GetInt32(obj, &i32)) return false;
- if (upb_filedef_syntax(upb_enumdef_file(e)) == UPB_SYNTAX_PROTO2 &&
- !upb_enumdef_checknum(e, i32)) {
+ if (upb_FileDef_Syntax(upb_EnumDef_File(e)) == kUpb_Syntax_Proto2 &&
+ !upb_EnumDef_CheckNumber(e, i32)) {
PyErr_Format(PyExc_ValueError, "invalid enumerator %d", (int)i32);
return false;
}
@@ -182,39 +184,39 @@
}
}
-bool PyUpb_PyToUpb(PyObject *obj, const upb_fielddef *f, upb_msgval *val,
- upb_arena *arena) {
- switch (upb_fielddef_type(f)) {
- case UPB_TYPE_ENUM:
- return PyUpb_PyToUpbEnum(obj, upb_fielddef_enumsubdef(f), val);
- case UPB_TYPE_INT32:
+bool PyUpb_PyToUpb(PyObject* obj, const upb_FieldDef* f, upb_MessageValue* val,
+ upb_Arena* arena) {
+ switch (upb_FieldDef_CType(f)) {
+ case kUpb_CType_Enum:
+ return PyUpb_PyToUpbEnum(obj, upb_FieldDef_EnumSubDef(f), val);
+ case kUpb_CType_Int32:
return PyUpb_GetInt32(obj, &val->int32_val);
- case UPB_TYPE_INT64:
+ case kUpb_CType_Int64:
return PyUpb_GetInt64(obj, &val->int64_val);
- case UPB_TYPE_UINT32:
+ case kUpb_CType_UInt32:
return PyUpb_GetUint32(obj, &val->uint32_val);
- case UPB_TYPE_UINT64:
+ case kUpb_CType_UInt64:
return PyUpb_GetUint64(obj, &val->uint64_val);
- case UPB_TYPE_FLOAT:
+ case kUpb_CType_Float:
val->float_val = PyFloat_AsDouble(obj);
return !PyErr_Occurred();
- case UPB_TYPE_DOUBLE:
+ case kUpb_CType_Double:
val->double_val = PyFloat_AsDouble(obj);
return !PyErr_Occurred();
- case UPB_TYPE_BOOL:
+ case kUpb_CType_Bool:
val->bool_val = PyLong_AsLong(obj);
return !PyErr_Occurred();
- case UPB_TYPE_BYTES: {
- char *ptr;
+ case kUpb_CType_Bytes: {
+ char* ptr;
Py_ssize_t size;
if (PyBytes_AsStringAndSize(obj, &ptr, &size) < 0) return false;
*val = PyUpb_MaybeCopyString(ptr, size, arena);
return true;
}
- case UPB_TYPE_STRING: {
+ case kUpb_CType_String: {
Py_ssize_t size;
- const char *ptr;
- PyObject *unicode = NULL;
+ const char* ptr;
+ PyObject* unicode = NULL;
if (PyBytes_Check(obj)) {
unicode = obj = PyUnicode_FromEncodedObject(obj, "utf-8", NULL);
if (!obj) return false;
@@ -228,95 +230,96 @@
Py_XDECREF(unicode);
return true;
}
- case UPB_TYPE_MESSAGE:
- PyErr_Format(
- PyExc_ValueError, "Message objects may not be assigned",
- upb_fielddef_type(f));
+ case kUpb_CType_Message:
+ PyErr_Format(PyExc_ValueError, "Message objects may not be assigned",
+ upb_FieldDef_CType(f));
return false;
default:
- PyErr_Format(
- PyExc_SystemError, "Getting a value from a field of unknown type %d",
- upb_fielddef_type(f));
+ PyErr_Format(PyExc_SystemError,
+ "Getting a value from a field of unknown type %d",
+ upb_FieldDef_CType(f));
return false;
}
}
-bool PyUpb_Message_IsEqual(const upb_msg *msg1, const upb_msg *msg2,
- const upb_msgdef *m);
+bool PyUpb_Message_IsEqual(const upb_msg* msg1, const upb_msg* msg2,
+ const upb_MessageDef* m);
// -----------------------------------------------------------------------------
// Equal
// -----------------------------------------------------------------------------
-bool PyUpb_ValueEq(upb_msgval val1, upb_msgval val2, const upb_fielddef *f) {
- switch (upb_fielddef_type(f)) {
- case UPB_TYPE_BOOL:
+bool PyUpb_ValueEq(upb_MessageValue val1, upb_MessageValue val2,
+ const upb_FieldDef* f) {
+ switch (upb_FieldDef_CType(f)) {
+ case kUpb_CType_Bool:
return val1.bool_val == val2.bool_val;
- case UPB_TYPE_INT32:
- case UPB_TYPE_UINT32:
- case UPB_TYPE_ENUM:
+ case kUpb_CType_Int32:
+ case kUpb_CType_UInt32:
+ case kUpb_CType_Enum:
return val1.int32_val == val2.int32_val;
- case UPB_TYPE_INT64:
- case UPB_TYPE_UINT64:
+ case kUpb_CType_Int64:
+ case kUpb_CType_UInt64:
return val1.int64_val == val2.int64_val;
- case UPB_TYPE_FLOAT:
+ case kUpb_CType_Float:
return val1.float_val == val2.float_val;
- case UPB_TYPE_DOUBLE:
+ case kUpb_CType_Double:
return val1.double_val == val2.double_val;
- case UPB_TYPE_STRING:
- case UPB_TYPE_BYTES:
+ case kUpb_CType_String:
+ case kUpb_CType_Bytes:
return val1.str_val.size == val2.str_val.size &&
- memcmp(val1.str_val.data, val2.str_val.data, val1.str_val.size) == 0;
- case UPB_TYPE_MESSAGE:
+ memcmp(val1.str_val.data, val2.str_val.data, val1.str_val.size) ==
+ 0;
+ case kUpb_CType_Message:
return PyUpb_Message_IsEqual(val1.msg_val, val2.msg_val,
- upb_fielddef_msgsubdef(f));
+ upb_FieldDef_MessageSubDef(f));
default:
return false;
}
}
-bool PyUpb_Map_IsEqual(const upb_map *map1, const upb_map *map2,
- const upb_fielddef *f) {
- assert(upb_fielddef_ismap(f));
+bool PyUpb_Map_IsEqual(const upb_Map* map1, const upb_Map* map2,
+ const upb_FieldDef* f) {
+ assert(upb_FieldDef_IsMap(f));
if (map1 == map2) return true;
- size_t size1 = map1 ? upb_map_size(map1) : 0;
- size_t size2 = map2 ? upb_map_size(map2) : 0;
+ size_t size1 = map1 ? upb_Map_Size(map1) : 0;
+ size_t size2 = map2 ? upb_Map_Size(map2) : 0;
if (size1 != size2) return false;
if (size1 == 0) return true;
- const upb_msgdef *entry_m = upb_fielddef_msgsubdef(f);
- const upb_fielddef *val_f = upb_msgdef_field(entry_m, 1);
- size_t iter = UPB_MAP_BEGIN;
+ const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(f);
+ const upb_FieldDef* val_f = upb_MessageDef_Field(entry_m, 1);
+ size_t iter = kUpb_Map_Begin;
- while (upb_mapiter_next(map1, &iter)) {
- upb_msgval key = upb_mapiter_key(map1, iter);
- upb_msgval val1 = upb_mapiter_value(map1, iter);
- upb_msgval val2;
- if (!upb_map_get(map2, key, &val2)) return false;
+ while (upb_MapIterator_Next(map1, &iter)) {
+ upb_MessageValue key = upb_MapIterator_Key(map1, iter);
+ upb_MessageValue val1 = upb_MapIterator_Value(map1, iter);
+ upb_MessageValue val2;
+ if (!upb_Map_Get(map2, key, &val2)) return false;
if (!PyUpb_ValueEq(val1, val2, val_f)) return false;
}
return true;
}
-static bool PyUpb_ArrayElem_IsEqual(const upb_array *arr1,
- const upb_array *arr2, size_t i,
- const upb_fielddef *f) {
- assert(i < upb_array_size(arr1));
- assert(i < upb_array_size(arr2));
- upb_msgval val1 = upb_array_get(arr1, i);
- upb_msgval val2 = upb_array_get(arr2, i);
+static bool PyUpb_ArrayElem_IsEqual(const upb_Array* arr1,
+ const upb_Array* arr2, size_t i,
+ const upb_FieldDef* f) {
+ assert(i < upb_Array_Size(arr1));
+ assert(i < upb_Array_Size(arr2));
+ upb_MessageValue val1 = upb_Array_Get(arr1, i);
+ upb_MessageValue val2 = upb_Array_Get(arr2, i);
return PyUpb_ValueEq(val1, val2, f);
}
-bool PyUpb_Array_IsEqual(const upb_array *arr1, const upb_array *arr2,
- const upb_fielddef *f) {
- assert(upb_fielddef_isseq(f) && !upb_fielddef_ismap(f));
+bool PyUpb_Array_IsEqual(const upb_Array* arr1, const upb_Array* arr2,
+ const upb_FieldDef* f) {
+ assert(upb_FieldDef_IsRepeated(f) && !upb_FieldDef_IsMap(f));
if (arr1 == arr2) return true;
- size_t n1 = arr1 ? upb_array_size(arr1) : 0;
- size_t n2 = arr2 ? upb_array_size(arr2) : 0;
+ size_t n1 = arr1 ? upb_Array_Size(arr1) : 0;
+ size_t n2 = arr2 ? upb_Array_Size(arr2) : 0;
if (n1 != n2) return false;
// Half the length rounded down. Important: the empty list rounds to 0.
@@ -338,8 +341,8 @@
return true;
}
-bool PyUpb_Message_IsEqual(const upb_msg *msg1, const upb_msg *msg2,
- const upb_msgdef *m) {
+bool PyUpb_Message_IsEqual(const upb_msg* msg1, const upb_msg* msg2,
+ const upb_MessageDef* m) {
if (msg1 == msg2) return true;
if (upb_msg_extcount(msg1) != upb_msg_extcount(msg2)) return false;
@@ -349,34 +352,35 @@
// So we use the following strategy:
// 1. Iterate over all msg1 fields (including extensions).
// 2. For non-extension fields, we find the corresponding field by simply
- // using upb_msg_next(msg2). If the two messages have the same set of
- // fields, this will yield the same field.
+ // using upb_Message_Next(msg2). If the two messages have the same set
+ // of fields, this will yield the same field.
// 3. For extension fields, we have to actually search for the corresponding
- // field, which we do with upb_msg_get(msg2, ext_f1).
- // 4. Once iteration over msg1 is complete, we call upb_msg_next(msg2) one
+ // field, which we do with upb_Message_Get(msg2, ext_f1).
+ // 4. Once iteration over msg1 is complete, we call upb_Message_Next(msg2)
+ // one
// final time to verify that we have visited all of msg2's regular fields
// (we pass NULL for ext_dict so that iteration will *not* return
// extensions).
//
// We don't need to visit all of msg2's extensions, because we verified up
// front that both messages have the same number of extensions.
- const upb_symtab* symtab = upb_filedef_symtab(upb_msgdef_file(m));
- const upb_fielddef *f1, *f2;
- upb_msgval val1, val2;
- size_t iter1 = UPB_MSG_BEGIN;
- size_t iter2 = UPB_MSG_BEGIN;
- while (upb_msg_next(msg1, m, symtab, &f1, &val1, &iter1)) {
- if (upb_fielddef_isextension(f1)) {
- val2 = upb_msg_get(msg2, f1);
+ const upb_DefPool* symtab = upb_FileDef_Pool(upb_MessageDef_File(m));
+ const upb_FieldDef *f1, *f2;
+ upb_MessageValue val1, val2;
+ size_t iter1 = kUpb_Message_Begin;
+ size_t iter2 = kUpb_Message_Begin;
+ while (upb_Message_Next(msg1, m, symtab, &f1, &val1, &iter1)) {
+ if (upb_FieldDef_IsExtension(f1)) {
+ val2 = upb_Message_Get(msg2, f1);
} else {
- if (!upb_msg_next(msg2, m, NULL, &f2, &val2, &iter2) || f1 != f2) {
+ if (!upb_Message_Next(msg2, m, NULL, &f2, &val2, &iter2) || f1 != f2) {
return false;
}
}
- if (upb_fielddef_ismap(f1)) {
+ if (upb_FieldDef_IsMap(f1)) {
if (!PyUpb_Map_IsEqual(val1.map_val, val2.map_val, f1)) return false;
- } else if (upb_fielddef_isseq(f1)) {
+ } else if (upb_FieldDef_IsRepeated(f1)) {
if (!PyUpb_Array_IsEqual(val1.array_val, val2.array_val, f1)) {
return false;
}
@@ -385,11 +389,11 @@
}
}
- if (upb_msg_next(msg2, m, NULL, &f2, &val2, &iter2)) return false;
+ if (upb_Message_Next(msg2, m, NULL, &f2, &val2, &iter2)) return false;
size_t usize1, usize2;
- const char *uf1 = upb_msg_getunknown(msg1, &usize1);
- const char *uf2 = upb_msg_getunknown(msg2, &usize2);
+ const char* uf1 = upb_Message_Getunknown(msg1, &usize1);
+ const char* uf2 = upb_Message_Getunknown(msg2, &usize2);
// 100 is arbitrary, we're trying to prevent stack overflow but it's not
// obvious how deep we should allow here.
return upb_Message_UnknownFieldsAreEqual(uf1, usize1, uf2, usize2, 100) ==
diff --git a/python/convert.h b/python/convert.h
index 2512b65..9188cbb 100644
--- a/python/convert.h
+++ b/python/convert.h
@@ -13,11 +13,11 @@
* 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
+ * 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
@@ -28,35 +28,36 @@
#ifndef PYUPB_CONVERT_H__
#define PYUPB_CONVERT_H__
+#include "protobuf.h"
#include "upb/def.h"
#include "upb/reflection.h"
-#include "protobuf.h"
-
// Converts `val` to a Python object according to the type information in `f`.
// Any newly-created Python objects that reference non-primitive data from `val`
// will take a reference on `arena`; the caller must ensure that `val` belongs
// to `arena`. If the conversion cannot be performed, returns NULL and sets a
// Python error.
-PyObject *PyUpb_UpbToPy(upb_msgval val, const upb_fielddef *f, PyObject *arena);
+PyObject* PyUpb_UpbToPy(upb_MessageValue val, const upb_FieldDef* f,
+ PyObject* arena);
-// Converts `obj` to a upb_msgval `*val` according to the type information in
-// `f`. If `arena` is provided, any string data will be copied into `arena`,
+// Converts `obj` to a upb_MessageValue `*val` according to the type information
+// in `f`. If `arena` is provided, any string data will be copied into `arena`,
// otherwise the returned value will alias the Python-owned data (this can be
-// useful for an ephemeral upb_msgval). If the conversion cannot be performed,
-// returns false.
-bool PyUpb_PyToUpb(PyObject *obj, const upb_fielddef *f, upb_msgval *val,
- upb_arena *arena);
+// useful for an ephemeral upb_MessageValue). If the conversion cannot be
+// performed, returns false.
+bool PyUpb_PyToUpb(PyObject* obj, const upb_FieldDef* f, upb_MessageValue* val,
+ upb_Arena* arena);
// Returns true if the given values (of type `f`) are equal.
-bool PyUpb_ValueEq(upb_msgval val1, upb_msgval val2, const upb_fielddef *f);
+bool PyUpb_ValueEq(upb_MessageValue val1, upb_MessageValue val2,
+ const upb_FieldDef* f);
// Returns true if the given messages (of type `m`) are equal.
-bool PyUpb_Message_IsEqual(const upb_msg *msg1, const upb_msg *msg2,
- const upb_msgdef *m);
+bool PyUpb_Message_IsEqual(const upb_msg* msg1, const upb_msg* msg2,
+ const upb_MessageDef* m);
// Returns true if the two arrays (with element type `f`) are equal.
-bool PyUpb_Array_IsEqual(const upb_array *arr1, const upb_array *arr2,
- const upb_fielddef *f);
+bool PyUpb_Array_IsEqual(const upb_Array* arr1, const upb_Array* arr2,
+ const upb_FieldDef* f);
#endif // PYUPB_CONVERT_H__
diff --git a/python/descriptor.c b/python/descriptor.c
index 51aa8c6..34fdddb 100644
--- a/python/descriptor.c
+++ b/python/descriptor.c
@@ -42,8 +42,8 @@
// This representation is used by all concrete descriptors.
typedef struct {
- PyObject_HEAD
- PyObject* pool; // We own a ref.
+ PyObject_HEAD;
+ PyObject* pool; // We own a ref.
const void* def; // Type depends on the class. Kept alive by "pool".
PyObject* options; // NULL if not present or not cached.
} PyUpb_DescriptorBase;
@@ -59,13 +59,13 @@
}
static PyUpb_DescriptorBase* PyUpb_DescriptorBase_DoCreate(
- PyUpb_DescriptorType type, const void* def, const upb_filedef* file) {
+ PyUpb_DescriptorType type, const void* def, const upb_FileDef* file) {
PyUpb_ModuleState* state = PyUpb_ModuleState_Get();
PyTypeObject* type_obj = state->descriptor_types[type];
assert(def);
PyUpb_DescriptorBase* base = (void*)PyType_GenericAlloc(type_obj, 0);
- base->pool = PyUpb_DescriptorPool_Get(upb_filedef_symtab(file));
+ base->pool = PyUpb_DescriptorPool_Get(upb_FileDef_Pool(file));
base->def = def;
base->options = NULL;
@@ -78,7 +78,7 @@
// new wrapper.
static PyObject* PyUpb_DescriptorBase_Get(PyUpb_DescriptorType type,
const void* def,
- const upb_filedef* file) {
+ const upb_FileDef* file) {
PyUpb_DescriptorBase* base = (PyUpb_DescriptorBase*)PyUpb_ObjCache_Get(def);
if (!base) {
@@ -102,7 +102,7 @@
static PyObject* PyUpb_DescriptorBase_GetOptions(PyUpb_DescriptorBase* self,
const upb_msg* opts,
- const upb_msglayout* layout,
+ const upb_MiniTable* layout,
const char* msg_name) {
if (!self->options) {
// Load descriptors protos if they are not loaded already. We have to do
@@ -112,8 +112,8 @@
// Find the correct options message.
PyObject* default_pool = PyUpb_DescriptorPool_GetDefaultPool();
- const upb_symtab* symtab = PyUpb_DescriptorPool_GetSymtab(default_pool);
- const upb_msgdef* m = upb_symtab_lookupmsg(symtab, msg_name);
+ const upb_DefPool* symtab = PyUpb_DescriptorPool_GetSymtab(default_pool);
+ const upb_MessageDef* m = upb_DefPool_FindMessageByName(symtab, msg_name);
assert(m);
// Copy the options message from C to Python using serialize+parse.
@@ -122,12 +122,12 @@
// layout as the C types that were compiled in.
size_t size;
PyObject* py_arena = PyUpb_Arena_New();
- upb_arena* arena = PyUpb_Arena_Get(py_arena);
- char* pb = upb_encode(opts, layout, arena, &size);
- upb_msg* opts2 = upb_msg_new(m, arena);
+ upb_Arena* arena = PyUpb_Arena_Get(py_arena);
+ char* pb = upb_Encode(opts, layout, arena, &size);
+ upb_msg* opts2 = upb_Message_New(m, arena);
assert(opts2);
- bool ok = _upb_decode(pb, size, opts2, upb_msgdef_layout(m),
- upb_symtab_extreg(symtab), 0,
+ bool ok = _upb_decode(pb, size, opts2, upb_MessageDef_MiniTable(m),
+ upb_DefPool_ExtensionRegistry(symtab), 0,
arena) == kUpb_DecodeStatus_Ok;
(void)ok;
assert(ok);
@@ -140,31 +140,31 @@
return self->options;
}
-typedef void* PyUpb_ToProto_Func(const void* def, upb_arena* arena);
+typedef void* PyUpb_ToProto_Func(const void* def, upb_Arena* arena);
static PyObject* PyUpb_DescriptorBase_GetSerializedProto(
- PyObject* _self, PyUpb_ToProto_Func* func, const upb_msglayout* layout) {
+ PyObject* _self, PyUpb_ToProto_Func* func, const upb_MiniTable* layout) {
PyUpb_DescriptorBase* self = (void*)_self;
- upb_arena* arena = upb_arena_new();
+ upb_Arena* arena = upb_Arena_New();
if (!arena) PYUPB_RETURN_OOM;
upb_msg* proto = func(self->def, arena);
if (!proto) goto oom;
size_t size;
- char* pb = upb_encode(proto, layout, arena, &size);
+ char* pb = upb_Encode(proto, layout, arena, &size);
if (!pb) goto oom;
PyObject* str = PyBytes_FromStringAndSize(pb, size);
- upb_arena_free(arena);
+ upb_Arena_Free(arena);
return str;
oom:
- upb_arena_free(arena);
+ upb_Arena_Free(arena);
PyErr_SetNone(PyExc_MemoryError);
return NULL;
}
static PyObject* PyUpb_DescriptorBase_CopyToProto(PyObject* _self,
PyUpb_ToProto_Func* func,
- const upb_msglayout* layout,
+ const upb_MiniTable* layout,
PyObject* py_proto) {
PyObject* serialized =
PyUpb_DescriptorBase_GetSerializedProto(_self, func, layout);
@@ -180,21 +180,22 @@
}
#define DESCRIPTOR_BASE_SLOTS \
- {Py_tp_new, (void*)&PyUpb_Forbidden_New}, \
- {Py_tp_dealloc, (void*)&PyUpb_DescriptorBase_Dealloc}
+ {Py_tp_new, (void*)&PyUpb_Forbidden_New}, { \
+ Py_tp_dealloc, (void*)&PyUpb_DescriptorBase_Dealloc \
+ }
// -----------------------------------------------------------------------------
// Descriptor
// -----------------------------------------------------------------------------
-PyObject* PyUpb_Descriptor_Get(const upb_msgdef* m) {
+PyObject* PyUpb_Descriptor_Get(const upb_MessageDef* m) {
assert(m);
- const upb_filedef* file = upb_msgdef_file(m);
+ const upb_FileDef* file = upb_MessageDef_File(m);
return PyUpb_DescriptorBase_Get(kPyUpb_Descriptor, m, file);
}
-PyObject* PyUpb_Descriptor_GetClass(const upb_msgdef* m) {
- PyObject* ret = PyUpb_ObjCache_Get(upb_msgdef_layout(m));
+PyObject* PyUpb_Descriptor_GetClass(const upb_MessageDef* m) {
+ PyObject* ret = PyUpb_ObjCache_Get(upb_MessageDef_MiniTable(m));
assert(ret);
return ret;
}
@@ -203,37 +204,40 @@
// a message. This uses the symtab's table, which requires that the symtab is
// not being mutated concurrently. We can guarantee this for Python-owned
// symtabs, but upb cannot guarantee it in general for an arbitrary
-// `const upb_msgdef*`.
+// `const upb_MessageDef*`.
-static const void* PyUpb_Descriptor_LookupNestedMessage(const upb_msgdef* m,
+static const void* PyUpb_Descriptor_LookupNestedMessage(const upb_MessageDef* m,
const char* name) {
- const upb_filedef* filedef = upb_msgdef_file(m);
- const upb_symtab* symtab = upb_filedef_symtab(filedef);
- PyObject* qname = PyUnicode_FromFormat("%s.%s", upb_msgdef_fullname(m), name);
- const upb_msgdef* ret =
- upb_symtab_lookupmsg(symtab, PyUnicode_AsUTF8AndSize(qname, NULL));
+ const upb_FileDef* filedef = upb_MessageDef_File(m);
+ const upb_DefPool* symtab = upb_FileDef_Pool(filedef);
+ PyObject* qname =
+ PyUnicode_FromFormat("%s.%s", upb_MessageDef_FullName(m), name);
+ const upb_MessageDef* ret = upb_DefPool_FindMessageByName(
+ symtab, PyUnicode_AsUTF8AndSize(qname, NULL));
Py_DECREF(qname);
return ret;
}
-static const void* PyUpb_Descriptor_LookupNestedEnum(const upb_msgdef* m,
+static const void* PyUpb_Descriptor_LookupNestedEnum(const upb_MessageDef* m,
const char* name) {
- const upb_filedef* filedef = upb_msgdef_file(m);
- const upb_symtab* symtab = upb_filedef_symtab(filedef);
- PyObject* qname = PyUnicode_FromFormat("%s.%s", upb_msgdef_fullname(m), name);
- const upb_enumdef* ret =
- upb_symtab_lookupenum(symtab, PyUnicode_AsUTF8AndSize(qname, NULL));
+ const upb_FileDef* filedef = upb_MessageDef_File(m);
+ const upb_DefPool* symtab = upb_FileDef_Pool(filedef);
+ PyObject* qname =
+ PyUnicode_FromFormat("%s.%s", upb_MessageDef_FullName(m), name);
+ const upb_EnumDef* ret =
+ upb_DefPool_FindEnumByName(symtab, PyUnicode_AsUTF8AndSize(qname, NULL));
Py_DECREF(qname);
return ret;
}
-static const void* PyUpb_Descriptor_LookupNestedExtension(const upb_msgdef* m,
- const char* name) {
- const upb_filedef* filedef = upb_msgdef_file(m);
- const upb_symtab* symtab = upb_filedef_symtab(filedef);
- PyObject* qname = PyUnicode_FromFormat("%s.%s", upb_msgdef_fullname(m), name);
- const upb_fielddef* ret =
- upb_symtab_lookupext(symtab, PyUnicode_AsUTF8AndSize(qname, NULL));
+static const void* PyUpb_Descriptor_LookupNestedExtension(
+ const upb_MessageDef* m, const char* name) {
+ const upb_FileDef* filedef = upb_MessageDef_File(m);
+ const upb_DefPool* symtab = upb_FileDef_Pool(filedef);
+ PyObject* qname =
+ PyUnicode_FromFormat("%s.%s", upb_MessageDef_FullName(m), name);
+ const upb_FieldDef* ret = upb_DefPool_FindExtensionByName(
+ symtab, PyUnicode_AsUTF8AndSize(qname, NULL));
Py_DECREF(qname);
return ret;
}
@@ -241,13 +245,14 @@
static PyObject* PyUpb_Descriptor_GetExtensionRanges(PyObject* _self,
void* closure) {
PyUpb_DescriptorBase* self = (PyUpb_DescriptorBase*)_self;
- int n = upb_msgdef_extrangecount(self->def);
+ int n = upb_MessageDef_ExtensionRangeCount(self->def);
PyObject* range_list = PyList_New(n);
for (int i = 0; i < n; i++) {
- const upb_extrange* range = upb_msgdef_extrange(self->def, i);
- PyObject* start = PyLong_FromLong(upb_extrange_start(range));
- PyObject* end = PyLong_FromLong(upb_extrange_end(range));
+ const upb_ExtensionRange* range =
+ upb_MessageDef_ExtensionRange(self->def, i);
+ PyObject* start = PyLong_FromLong(upb_ExtensionRange_Start(range));
+ PyObject* end = PyLong_FromLong(upb_ExtensionRange_End(range));
PyList_SetItem(range_list, i, PyTuple_Pack(2, start, end));
}
@@ -258,8 +263,8 @@
void* closure) {
PyUpb_DescriptorBase* self = (void*)_self;
static PyUpb_GenericSequence_Funcs funcs = {
- (void*)&upb_msgdef_nestedextcount,
- (void*)&upb_msgdef_nestedext,
+ (void*)&upb_MessageDef_NestedExtensionCount,
+ (void*)&upb_MessageDef_NestedExtension,
(void*)&PyUpb_FieldDescriptor_Get,
};
return PyUpb_GenericSequence_New(&funcs, self->def, self->pool);
@@ -270,12 +275,12 @@
PyUpb_DescriptorBase* self = (void*)_self;
static PyUpb_ByNameMap_Funcs funcs = {
{
- (void*)&upb_msgdef_nestedextcount,
- (void*)&upb_msgdef_nestedext,
+ (void*)&upb_MessageDef_NestedExtensionCount,
+ (void*)&upb_MessageDef_NestedExtension,
(void*)&PyUpb_FieldDescriptor_Get,
},
(void*)&PyUpb_Descriptor_LookupNestedExtension,
- (void*)&upb_fielddef_name,
+ (void*)&upb_FieldDef_Name,
};
return PyUpb_ByNameMap_New(&funcs, self->def, self->pool);
}
@@ -283,8 +288,8 @@
static PyObject* PyUpb_Descriptor_GetEnumTypes(PyObject* _self, void* closure) {
PyUpb_DescriptorBase* self = (void*)_self;
static PyUpb_GenericSequence_Funcs funcs = {
- (void*)&upb_msgdef_nestedenumcount,
- (void*)&upb_msgdef_nestedenum,
+ (void*)&upb_MessageDef_NestedEnumCount,
+ (void*)&upb_MessageDef_NestedEnum,
(void*)&PyUpb_EnumDescriptor_Get,
};
return PyUpb_GenericSequence_New(&funcs, self->def, self->pool);
@@ -293,8 +298,8 @@
static PyObject* PyUpb_Descriptor_GetOneofs(PyObject* _self, void* closure) {
PyUpb_DescriptorBase* self = (void*)_self;
static PyUpb_GenericSequence_Funcs funcs = {
- (void*)&upb_msgdef_oneofcount,
- (void*)&upb_msgdef_oneof,
+ (void*)&upb_MessageDef_OneofCount,
+ (void*)&upb_MessageDef_Oneof,
(void*)&PyUpb_OneofDescriptor_Get,
};
return PyUpb_GenericSequence_New(&funcs, self->def, self->pool);
@@ -303,7 +308,7 @@
static PyObject* PyUpb_Descriptor_GetOptions(PyObject* _self, PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetOptions(
- self, upb_msgdef_options(self->def),
+ self, upb_MessageDef_Options(self->def),
&google_protobuf_MessageOptions_msginit,
"google.protobuf.MessageOptions");
}
@@ -321,18 +326,18 @@
const char* enum_name;
int number;
if (!PyArg_ParseTuple(args, "si", &enum_name, &number)) return NULL;
- const upb_enumdef* e =
+ const upb_EnumDef* e =
PyUpb_Descriptor_LookupNestedEnum(self->def, enum_name);
if (!e) {
PyErr_SetString(PyExc_KeyError, enum_name);
return NULL;
}
- const upb_enumvaldef* ev = upb_enumdef_lookupnum(e, number);
+ const upb_EnumValueDef* ev = upb_EnumDef_FindValueByNumber(e, number);
if (!ev) {
PyErr_Format(PyExc_KeyError, "%d", number);
return NULL;
}
- return PyUnicode_FromString(upb_enumvaldef_name(ev));
+ return PyUnicode_FromString(upb_EnumValueDef_Name(ev));
}
static PyObject* PyUpb_Descriptor_GetFieldsByName(PyObject* _self,
@@ -340,12 +345,12 @@
PyUpb_DescriptorBase* self = (void*)_self;
static PyUpb_ByNameMap_Funcs funcs = {
{
- (void*)&upb_msgdef_fieldcount,
- (void*)&upb_msgdef_field,
+ (void*)&upb_MessageDef_FieldCount,
+ (void*)&upb_MessageDef_Field,
(void*)&PyUpb_FieldDescriptor_Get,
},
- (void*)&upb_msgdef_ntofz,
- (void*)&upb_fielddef_name,
+ (void*)&upb_MessageDef_FindFieldByName,
+ (void*)&upb_FieldDef_Name,
};
return PyUpb_ByNameMap_New(&funcs, self->def, self->pool);
}
@@ -355,12 +360,12 @@
PyUpb_DescriptorBase* self = (void*)_self;
static PyUpb_ByNameMap_Funcs funcs = {
{
- (void*)&upb_msgdef_fieldcount,
- (void*)&upb_msgdef_field,
+ (void*)&upb_MessageDef_FieldCount,
+ (void*)&upb_MessageDef_Field,
(void*)&PyUpb_FieldDescriptor_Get,
},
- (void*)&upb_msgdef_lookupjsonnamez,
- (void*)&upb_fielddef_jsonname,
+ (void*)&upb_MessageDef_FindByJsonName,
+ (void*)&upb_FieldDef_JsonName,
};
return PyUpb_ByNameMap_New(&funcs, self->def, self->pool);
}
@@ -369,12 +374,12 @@
void* closure) {
static PyUpb_ByNumberMap_Funcs funcs = {
{
- (void*)&upb_msgdef_fieldcount,
- (void*)&upb_msgdef_field,
+ (void*)&upb_MessageDef_FieldCount,
+ (void*)&upb_MessageDef_Field,
(void*)&PyUpb_FieldDescriptor_Get,
},
- (void*)&upb_msgdef_itof,
- (void*)&upb_fielddef_number,
+ (void*)&upb_MessageDef_FindFieldByNumberWithSize,
+ (void*)&upb_FieldDef_Number,
};
PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_ByNumberMap_New(&funcs, self->def, self->pool);
@@ -384,8 +389,8 @@
void* closure) {
PyUpb_DescriptorBase* self = (void*)_self;
static PyUpb_GenericSequence_Funcs funcs = {
- (void*)&upb_msgdef_nestedmsgcount,
- (void*)&upb_msgdef_nestedmsg,
+ (void*)&upb_MessageDef_NestedMessageCount,
+ (void*)&upb_MessageDef_NestedMessage,
(void*)&PyUpb_Descriptor_Get,
};
return PyUpb_GenericSequence_New(&funcs, self->def, self->pool);
@@ -396,12 +401,12 @@
PyUpb_DescriptorBase* self = (void*)_self;
static PyUpb_ByNameMap_Funcs funcs = {
{
- (void*)&upb_msgdef_nestedmsgcount,
- (void*)&upb_msgdef_nestedmsg,
+ (void*)&upb_MessageDef_NestedMessageCount,
+ (void*)&upb_MessageDef_NestedMessage,
(void*)&PyUpb_Descriptor_Get,
},
(void*)&PyUpb_Descriptor_LookupNestedMessage,
- (void*)&upb_msgdef_name,
+ (void*)&upb_MessageDef_Name,
};
return PyUpb_ByNameMap_New(&funcs, self->def, self->pool);
}
@@ -411,14 +416,14 @@
// upb does not natively store the lexical parent of a message type, but we
// can derive it with some string manipulation and a lookup.
PyUpb_DescriptorBase* self = (void*)_self;
- const upb_msgdef* m = self->def;
- const upb_filedef* file = upb_msgdef_file(m);
- const upb_symtab* symtab = upb_filedef_symtab(file);
- const char* full_name = upb_msgdef_fullname(m);
+ const upb_MessageDef* m = self->def;
+ const upb_FileDef* file = upb_MessageDef_File(m);
+ const upb_DefPool* symtab = upb_FileDef_Pool(file);
+ const char* full_name = upb_MessageDef_FullName(m);
const char* last_dot = strrchr(full_name, '.');
if (!last_dot) Py_RETURN_NONE;
- const upb_msgdef* parent =
- upb_symtab_lookupmsg2(symtab, full_name, last_dot - full_name);
+ const upb_MessageDef* parent = upb_DefPool_FindMessageByNameWithSize(
+ symtab, full_name, last_dot - full_name);
if (!parent) Py_RETURN_NONE;
return PyUpb_Descriptor_Get(parent);
}
@@ -428,12 +433,12 @@
PyUpb_DescriptorBase* self = (void*)_self;
static PyUpb_ByNameMap_Funcs funcs = {
{
- (void*)&upb_msgdef_nestedenumcount,
- (void*)&upb_msgdef_nestedenum,
+ (void*)&upb_MessageDef_NestedEnumCount,
+ (void*)&upb_MessageDef_NestedEnum,
(void*)&PyUpb_EnumDescriptor_Get,
},
(void*)&PyUpb_Descriptor_LookupNestedEnum,
- (void*)&upb_enumdef_name,
+ (void*)&upb_EnumDef_Name,
};
return PyUpb_ByNameMap_New(&funcs, self->def, self->pool);
}
@@ -441,7 +446,7 @@
static PyObject* PyUpb_Descriptor_GetIsExtendable(PyObject* _self,
void* closure) {
PyUpb_DescriptorBase* self = (void*)_self;
- if (upb_msgdef_extrangecount(self->def) > 0) {
+ if (upb_MessageDef_ExtensionRangeCount(self->def) > 0) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
@@ -449,26 +454,26 @@
}
static PyObject* PyUpb_Descriptor_GetFullName(PyObject* self, void* closure) {
- const upb_msgdef* msgdef = PyUpb_Descriptor_GetDef(self);
- return PyUnicode_FromString(upb_msgdef_fullname(msgdef));
+ const upb_MessageDef* msgdef = PyUpb_Descriptor_GetDef(self);
+ return PyUnicode_FromString(upb_MessageDef_FullName(msgdef));
}
static PyObject* PyUpb_Descriptor_GetConcreteClass(PyObject* self,
void* closure) {
- const upb_msgdef* msgdef = PyUpb_Descriptor_GetDef(self);
+ const upb_MessageDef* msgdef = PyUpb_Descriptor_GetDef(self);
return PyUpb_Descriptor_GetClass(msgdef);
}
static PyObject* PyUpb_Descriptor_GetFile(PyObject* self, void* closure) {
- const upb_msgdef* msgdef = PyUpb_Descriptor_GetDef(self);
- return PyUpb_FileDescriptor_Get(upb_msgdef_file(msgdef));
+ const upb_MessageDef* msgdef = PyUpb_Descriptor_GetDef(self);
+ return PyUpb_FileDescriptor_Get(upb_MessageDef_File(msgdef));
}
static PyObject* PyUpb_Descriptor_GetFields(PyObject* _self, void* closure) {
PyUpb_DescriptorBase* self = (void*)_self;
static PyUpb_GenericSequence_Funcs funcs = {
- (void*)&upb_msgdef_fieldcount,
- (void*)&upb_msgdef_field,
+ (void*)&upb_MessageDef_FieldCount,
+ (void*)&upb_MessageDef_Field,
(void*)&PyUpb_FieldDescriptor_Get,
};
return PyUpb_GenericSequence_New(&funcs, self->def, self->pool);
@@ -477,12 +482,12 @@
static PyObject* PyUpb_Descriptor_GetHasOptions(PyObject* _self,
void* closure) {
PyUpb_DescriptorBase* self = (void*)_self;
- return PyBool_FromLong(upb_msgdef_hasoptions(self->def));
+ return PyBool_FromLong(upb_MessageDef_HasOptions(self->def));
}
static PyObject* PyUpb_Descriptor_GetName(PyObject* self, void* closure) {
- const upb_msgdef* msgdef = PyUpb_Descriptor_GetDef(self);
- return PyUnicode_FromString(upb_msgdef_name(msgdef));
+ const upb_MessageDef* msgdef = PyUpb_Descriptor_GetDef(self);
+ return PyUnicode_FromString(upb_MessageDef_Name(msgdef));
}
static PyObject* PyUpb_Descriptor_GetEnumValuesByName(PyObject* _self,
@@ -509,10 +514,10 @@
PyUpb_DescriptorBase* self = (void*)_self;
PyObject* ret = PyDict_New();
if (!ret) return NULL;
- int enum_count = upb_msgdef_nestedenumcount(self->def);
+ int enum_count = upb_MessageDef_NestedEnumCount(self->def);
for (int i = 0; i < enum_count; i++) {
- const upb_enumdef* e = upb_msgdef_nestedenum(self->def, i);
- int value_count = upb_enumdef_valuecount(e);
+ const upb_EnumDef* e = upb_MessageDef_NestedEnum(self->def, i);
+ int value_count = upb_EnumDef_ValueCount(e);
for (int j = 0; j < value_count; j++) {
// Collisions should be impossible here, as uniqueness is checked by
// protoc (this is an invariant of the protobuf language). However this
@@ -524,9 +529,9 @@
// constraint proactively, but upb is always checking a subset of the full
// validation performed by C++, and we have to pick and choose the biggest
// bang for the buck.
- const upb_enumvaldef* ev = upb_enumdef_value(e, j);
- const char* name = upb_enumvaldef_name(ev);
- PyObject* val = PyLong_FromLong(upb_enumvaldef_number(ev));
+ const upb_EnumValueDef* ev = upb_EnumDef_Value(e, j);
+ const char* name = upb_EnumValueDef_Name(ev);
+ PyObject* val = PyLong_FromLong(upb_EnumValueDef_Number(ev));
if (!val || PyDict_SetItemString(ret, name, val) < 0) {
Py_XDECREF(val);
Py_DECREF(ret);
@@ -543,20 +548,20 @@
PyUpb_DescriptorBase* self = (void*)_self;
static PyUpb_ByNameMap_Funcs funcs = {
{
- (void*)&upb_msgdef_oneofcount,
- (void*)&upb_msgdef_oneof,
+ (void*)&upb_MessageDef_OneofCount,
+ (void*)&upb_MessageDef_Oneof,
(void*)&PyUpb_OneofDescriptor_Get,
},
- (void*)&upb_msgdef_ntooz,
- (void*)&upb_oneofdef_name,
+ (void*)&upb_MessageDef_FindOneofByName,
+ (void*)&upb_OneofDef_Name,
};
return PyUpb_ByNameMap_New(&funcs, self->def, self->pool);
}
static PyObject* PyUpb_Descriptor_GetSyntax(PyObject* self, void* closure) {
- const upb_msgdef* msgdef = PyUpb_Descriptor_GetDef(self);
+ const upb_MessageDef* msgdef = PyUpb_Descriptor_GetDef(self);
const char* syntax =
- upb_msgdef_syntax(msgdef) == UPB_SYNTAX_PROTO2 ? "proto2" : "proto3";
+ upb_MessageDef_Syntax(msgdef) == kUpb_Syntax_Proto2 ? "proto2" : "proto3";
return PyUnicode_InternFromString(syntax);
}
@@ -617,7 +622,7 @@
PyUpb_Descriptor_Slots,
};
-const upb_msgdef* PyUpb_Descriptor_GetDef(PyObject* _self) {
+const upb_MessageDef* PyUpb_Descriptor_GetDef(PyObject* _self) {
PyUpb_DescriptorBase* self =
PyUpb_DescriptorBase_Check(_self, kPyUpb_Descriptor);
return self ? self->def : NULL;
@@ -627,12 +632,12 @@
// EnumDescriptor
// -----------------------------------------------------------------------------
-PyObject* PyUpb_EnumDescriptor_Get(const upb_enumdef* enumdef) {
- const upb_filedef* file = upb_enumdef_file(enumdef);
+PyObject* PyUpb_EnumDescriptor_Get(const upb_EnumDef* enumdef) {
+ const upb_FileDef* file = upb_EnumDef_File(enumdef);
return PyUpb_DescriptorBase_Get(kPyUpb_EnumDescriptor, enumdef, file);
}
-const upb_enumdef* PyUpb_EnumDescriptor_GetDef(PyObject* _self) {
+const upb_EnumDef* PyUpb_EnumDescriptor_GetDef(PyObject* _self) {
PyUpb_DescriptorBase* self =
PyUpb_DescriptorBase_Check(_self, kPyUpb_EnumDescriptor);
return self ? self->def : NULL;
@@ -640,26 +645,26 @@
static PyObject* PyUpb_EnumDescriptor_GetFullName(PyObject* self,
void* closure) {
- const upb_enumdef* enumdef = PyUpb_EnumDescriptor_GetDef(self);
- return PyUnicode_FromString(upb_enumdef_fullname(enumdef));
+ const upb_EnumDef* enumdef = PyUpb_EnumDescriptor_GetDef(self);
+ return PyUnicode_FromString(upb_EnumDef_FullName(enumdef));
}
static PyObject* PyUpb_EnumDescriptor_GetName(PyObject* self, void* closure) {
- const upb_enumdef* enumdef = PyUpb_EnumDescriptor_GetDef(self);
- return PyUnicode_FromString(upb_enumdef_name(enumdef));
+ const upb_EnumDef* enumdef = PyUpb_EnumDescriptor_GetDef(self);
+ return PyUnicode_FromString(upb_EnumDef_Name(enumdef));
}
static PyObject* PyUpb_EnumDescriptor_GetFile(PyObject* self, void* closure) {
- const upb_enumdef* enumdef = PyUpb_EnumDescriptor_GetDef(self);
- return PyUpb_FileDescriptor_Get(upb_enumdef_file(enumdef));
+ const upb_EnumDef* enumdef = PyUpb_EnumDescriptor_GetDef(self);
+ return PyUpb_FileDescriptor_Get(upb_EnumDef_File(enumdef));
}
static PyObject* PyUpb_EnumDescriptor_GetValues(PyObject* _self,
void* closure) {
PyUpb_DescriptorBase* self = (void*)_self;
static PyUpb_GenericSequence_Funcs funcs = {
- (void*)&upb_enumdef_valuecount,
- (void*)&upb_enumdef_value,
+ (void*)&upb_EnumDef_ValueCount,
+ (void*)&upb_EnumDef_Value,
(void*)&PyUpb_EnumValueDescriptor_Get,
};
return PyUpb_GenericSequence_New(&funcs, self->def, self->pool);
@@ -669,12 +674,12 @@
void* closure) {
static PyUpb_ByNameMap_Funcs funcs = {
{
- (void*)&upb_enumdef_valuecount,
- (void*)&upb_enumdef_value,
+ (void*)&upb_EnumDef_ValueCount,
+ (void*)&upb_EnumDef_Value,
(void*)&PyUpb_EnumValueDescriptor_Get,
},
- (void*)&upb_enumdef_lookupnamez,
- (void*)&upb_enumvaldef_name,
+ (void*)&upb_EnumDef_FindValueByName,
+ (void*)&upb_EnumValueDef_Name,
};
PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_ByNameMap_New(&funcs, self->def, self->pool);
@@ -684,12 +689,12 @@
void* closure) {
static PyUpb_ByNumberMap_Funcs funcs = {
{
- (void*)&upb_enumdef_valuecount,
- (void*)&upb_enumdef_value,
+ (void*)&upb_EnumDef_ValueCount,
+ (void*)&upb_EnumDef_Value,
(void*)&PyUpb_EnumValueDescriptor_Get,
},
- (void*)&upb_enumdef_lookupnum,
- (void*)&upb_enumvaldef_number,
+ (void*)&upb_EnumDef_FindValueByNumber,
+ (void*)&upb_EnumValueDef_Number,
};
PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_ByNumberMap_New(&funcs, self->def, self->pool);
@@ -698,7 +703,7 @@
static PyObject* PyUpb_EnumDescriptor_GetContainingType(PyObject* _self,
void* closure) {
PyUpb_DescriptorBase* self = (void*)_self;
- const upb_msgdef* m = upb_enumdef_containingtype(self->def);
+ const upb_MessageDef* m = upb_EnumDef_ContainingType(self->def);
if (!m) Py_RETURN_NONE;
return PyUpb_Descriptor_Get(m);
}
@@ -706,13 +711,13 @@
static PyObject* PyUpb_EnumDescriptor_GetHasOptions(PyObject* _self,
void* closure) {
PyUpb_DescriptorBase* self = (void*)_self;
- return PyBool_FromLong(upb_enumdef_hasoptions(self->def));
+ return PyBool_FromLong(upb_EnumDef_HasOptions(self->def));
}
static PyObject* PyUpb_EnumDescriptor_GetOptions(PyObject* _self,
PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self;
- return PyUpb_DescriptorBase_GetOptions(self, upb_enumdef_options(self->def),
+ return PyUpb_DescriptorBase_GetOptions(self, upb_EnumDef_Options(self->def),
&google_protobuf_EnumOptions_msginit,
"google.protobuf.EnumOptions");
}
@@ -761,46 +766,46 @@
// EnumValueDescriptor
// -----------------------------------------------------------------------------
-PyObject* PyUpb_EnumValueDescriptor_Get(const upb_enumvaldef* ev) {
- const upb_filedef* file = upb_enumdef_file(upb_enumvaldef_enum(ev));
+PyObject* PyUpb_EnumValueDescriptor_Get(const upb_EnumValueDef* ev) {
+ const upb_FileDef* file = upb_EnumDef_File(upb_EnumValueDef_Enum(ev));
return PyUpb_DescriptorBase_Get(kPyUpb_EnumValueDescriptor, ev, file);
}
static PyObject* PyUpb_EnumValueDescriptor_GetName(PyObject* self,
void* closure) {
PyUpb_DescriptorBase* base = (PyUpb_DescriptorBase*)self;
- return PyUnicode_FromString(upb_enumvaldef_name(base->def));
+ return PyUnicode_FromString(upb_EnumValueDef_Name(base->def));
}
static PyObject* PyUpb_EnumValueDescriptor_GetNumber(PyObject* self,
void* closure) {
PyUpb_DescriptorBase* base = (PyUpb_DescriptorBase*)self;
- return PyLong_FromLong(upb_enumvaldef_number(base->def));
+ return PyLong_FromLong(upb_EnumValueDef_Number(base->def));
}
static PyObject* PyUpb_EnumValueDescriptor_GetIndex(PyObject* self,
void* closure) {
PyUpb_DescriptorBase* base = (PyUpb_DescriptorBase*)self;
- return PyLong_FromLong(upb_enumvaldef_index(base->def));
+ return PyLong_FromLong(upb_EnumValueDef_Index(base->def));
}
static PyObject* PyUpb_EnumValueDescriptor_GetType(PyObject* self,
void* closure) {
PyUpb_DescriptorBase* base = (PyUpb_DescriptorBase*)self;
- return PyUpb_EnumDescriptor_Get(upb_enumvaldef_enum(base->def));
+ return PyUpb_EnumDescriptor_Get(upb_EnumValueDef_Enum(base->def));
}
static PyObject* PyUpb_EnumValueDescriptor_GetHasOptions(PyObject* _self,
void* closure) {
PyUpb_DescriptorBase* self = (void*)_self;
- return PyBool_FromLong(upb_enumvaldef_hasoptions(self->def));
+ return PyBool_FromLong(upb_EnumValueDef_HasOptions(self->def));
}
static PyObject* PyUpb_EnumValueDescriptor_GetOptions(PyObject* _self,
PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetOptions(
- self, upb_enumvaldef_options(self->def),
+ self, upb_EnumValueDef_Options(self->def),
&google_protobuf_EnumValueOptions_msginit,
"google.protobuf.EnumValueOptions");
}
@@ -840,48 +845,48 @@
// FieldDescriptor
// -----------------------------------------------------------------------------
-const upb_fielddef* PyUpb_FieldDescriptor_GetDef(PyObject* _self) {
+const upb_FieldDef* PyUpb_FieldDescriptor_GetDef(PyObject* _self) {
PyUpb_DescriptorBase* self =
PyUpb_DescriptorBase_Check(_self, kPyUpb_FieldDescriptor);
return self ? self->def : NULL;
}
-PyObject* PyUpb_FieldDescriptor_Get(const upb_fielddef* field) {
- const upb_filedef* file = upb_fielddef_file(field);
+PyObject* PyUpb_FieldDescriptor_Get(const upb_FieldDef* field) {
+ const upb_FileDef* file = upb_FieldDef_File(field);
return PyUpb_DescriptorBase_Get(kPyUpb_FieldDescriptor, field, file);
}
static PyObject* PyUpb_FieldDescriptor_GetFullName(PyUpb_DescriptorBase* self,
void* closure) {
- return PyUnicode_FromString(upb_fielddef_fullname(self->def));
+ return PyUnicode_FromString(upb_FieldDef_FullName(self->def));
}
static PyObject* PyUpb_FieldDescriptor_GetName(PyUpb_DescriptorBase* self,
void* closure) {
- return PyUnicode_FromString(upb_fielddef_name(self->def));
+ return PyUnicode_FromString(upb_FieldDef_Name(self->def));
}
static PyObject* PyUpb_FieldDescriptor_GetCamelCaseName(
PyUpb_DescriptorBase* self, void* closure) {
// TODO: Ok to use jsonname here?
- return PyUnicode_FromString(upb_fielddef_jsonname(self->def));
+ return PyUnicode_FromString(upb_FieldDef_JsonName(self->def));
}
static PyObject* PyUpb_FieldDescriptor_GetJsonName(PyUpb_DescriptorBase* self,
void* closure) {
- return PyUnicode_FromString(upb_fielddef_jsonname(self->def));
+ return PyUnicode_FromString(upb_FieldDef_JsonName(self->def));
}
static PyObject* PyUpb_FieldDescriptor_GetFile(PyUpb_DescriptorBase* self,
void* closure) {
- const upb_filedef* file = upb_fielddef_file(self->def);
+ const upb_FileDef* file = upb_FieldDef_File(self->def);
if (!file) Py_RETURN_NONE;
return PyUpb_FileDescriptor_Get(file);
}
static PyObject* PyUpb_FieldDescriptor_GetType(PyUpb_DescriptorBase* self,
void* closure) {
- return PyLong_FromLong(upb_fielddef_descriptortype(self->def));
+ return PyLong_FromLong(upb_FieldDef_Type(self->def));
}
static PyObject* PyUpb_FieldDescriptor_GetCppType(PyUpb_DescriptorBase* self,
@@ -900,86 +905,86 @@
CPPTYPE_MESSAGE = 10, // TYPE_MESSAGE, TYPE_GROUP
};
static const uint8_t cpp_types[] = {
- -1,
- [UPB_TYPE_INT32] = CPPTYPE_INT32,
- [UPB_TYPE_INT64] = CPPTYPE_INT64,
- [UPB_TYPE_UINT32] = CPPTYPE_UINT32,
- [UPB_TYPE_UINT64] = CPPTYPE_UINT64,
- [UPB_TYPE_DOUBLE] = CPPTYPE_DOUBLE,
- [UPB_TYPE_FLOAT] = CPPTYPE_FLOAT,
- [UPB_TYPE_BOOL] = CPPTYPE_BOOL,
- [UPB_TYPE_ENUM] = CPPTYPE_ENUM,
- [UPB_TYPE_STRING] = CPPTYPE_STRING,
- [UPB_TYPE_BYTES] = CPPTYPE_STRING,
- [UPB_TYPE_MESSAGE] = CPPTYPE_MESSAGE,
+ -1,
+ [kUpb_CType_Int32] = CPPTYPE_INT32,
+ [kUpb_CType_Int64] = CPPTYPE_INT64,
+ [kUpb_CType_UInt32] = CPPTYPE_UINT32,
+ [kUpb_CType_UInt64] = CPPTYPE_UINT64,
+ [kUpb_CType_Double] = CPPTYPE_DOUBLE,
+ [kUpb_CType_Float] = CPPTYPE_FLOAT,
+ [kUpb_CType_Bool] = CPPTYPE_BOOL,
+ [kUpb_CType_Enum] = CPPTYPE_ENUM,
+ [kUpb_CType_String] = CPPTYPE_STRING,
+ [kUpb_CType_Bytes] = CPPTYPE_STRING,
+ [kUpb_CType_Message] = CPPTYPE_MESSAGE,
};
- return PyLong_FromLong(cpp_types[upb_fielddef_type(self->def)]);
+ return PyLong_FromLong(cpp_types[upb_FieldDef_CType(self->def)]);
}
static PyObject* PyUpb_FieldDescriptor_GetLabel(PyUpb_DescriptorBase* self,
void* closure) {
- return PyLong_FromLong(upb_fielddef_label(self->def));
+ return PyLong_FromLong(upb_FieldDef_Label(self->def));
}
static PyObject* PyUpb_FieldDescriptor_GetIsExtension(
PyUpb_DescriptorBase* self, void* closure) {
- return PyBool_FromLong(upb_fielddef_isextension(self->def));
+ return PyBool_FromLong(upb_FieldDef_IsExtension(self->def));
}
static PyObject* PyUpb_FieldDescriptor_GetNumber(PyUpb_DescriptorBase* self,
void* closure) {
- return PyLong_FromLong(upb_fielddef_number(self->def));
+ return PyLong_FromLong(upb_FieldDef_Number(self->def));
}
static PyObject* PyUpb_FieldDescriptor_GetIndex(PyUpb_DescriptorBase* self,
void* closure) {
- return PyLong_FromLong(upb_fielddef_index(self->def));
+ return PyLong_FromLong(upb_FieldDef_Index(self->def));
}
static PyObject* PyUpb_FieldDescriptor_GetMessageType(
PyUpb_DescriptorBase* self, void* closure) {
- const upb_msgdef* subdef = upb_fielddef_msgsubdef(self->def);
+ const upb_MessageDef* subdef = upb_FieldDef_MessageSubDef(self->def);
if (!subdef) Py_RETURN_NONE;
return PyUpb_Descriptor_Get(subdef);
}
static PyObject* PyUpb_FieldDescriptor_GetEnumType(PyUpb_DescriptorBase* self,
void* closure) {
- const upb_enumdef* enumdef = upb_fielddef_enumsubdef(self->def);
+ const upb_EnumDef* enumdef = upb_FieldDef_EnumSubDef(self->def);
if (!enumdef) Py_RETURN_NONE;
return PyUpb_EnumDescriptor_Get(enumdef);
}
static PyObject* PyUpb_FieldDescriptor_GetContainingType(
PyUpb_DescriptorBase* self, void* closure) {
- const upb_msgdef* m = upb_fielddef_containingtype(self->def);
+ const upb_MessageDef* m = upb_FieldDef_ContainingType(self->def);
if (!m) Py_RETURN_NONE;
return PyUpb_Descriptor_Get(m);
}
static PyObject* PyUpb_FieldDescriptor_GetExtensionScope(
PyUpb_DescriptorBase* self, void* closure) {
- const upb_msgdef* m = upb_fielddef_extensionscope(self->def);
+ const upb_MessageDef* m = upb_FieldDef_ExtensionScope(self->def);
if (!m) Py_RETURN_NONE;
return PyUpb_Descriptor_Get(m);
}
static PyObject* PyUpb_FieldDescriptor_HasDefaultValue(
PyUpb_DescriptorBase* self, void* closure) {
- return PyBool_FromLong(upb_fielddef_hasdefault(self->def));
+ return PyBool_FromLong(upb_FieldDef_HasDefault(self->def));
}
static PyObject* PyUpb_FieldDescriptor_GetDefaultValue(
PyUpb_DescriptorBase* self, void* closure) {
- const upb_fielddef* f = self->def;
- if (upb_fielddef_isseq(f)) return PyList_New(0);
- if (upb_fielddef_issubmsg(f)) Py_RETURN_NONE;
- return PyUpb_UpbToPy(upb_fielddef_default(self->def), self->def, NULL);
+ const upb_FieldDef* f = self->def;
+ if (upb_FieldDef_IsRepeated(f)) return PyList_New(0);
+ if (upb_FieldDef_IsSubMessage(f)) Py_RETURN_NONE;
+ return PyUpb_UpbToPy(upb_FieldDef_Default(self->def), self->def, NULL);
}
static PyObject* PyUpb_FieldDescriptor_GetContainingOneof(
PyUpb_DescriptorBase* self, void* closure) {
- const upb_oneofdef* oneof = upb_fielddef_containingoneof(self->def);
+ const upb_OneofDef* oneof = upb_FieldDef_ContainingOneof(self->def);
if (!oneof) Py_RETURN_NONE;
return PyUpb_OneofDescriptor_Get(oneof);
}
@@ -987,13 +992,13 @@
static PyObject* PyUpb_FieldDescriptor_GetHasOptions(
PyUpb_DescriptorBase* _self, void* closure) {
PyUpb_DescriptorBase* self = (void*)_self;
- return PyBool_FromLong(upb_fielddef_hasoptions(self->def));
+ return PyBool_FromLong(upb_FieldDef_HasOptions(self->def));
}
static PyObject* PyUpb_FieldDescriptor_GetOptions(PyObject* _self,
PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self;
- return PyUpb_DescriptorBase_GetOptions(self, upb_fielddef_options(self->def),
+ return PyUpb_DescriptorBase_GetOptions(self, upb_FieldDef_Options(self->def),
&google_protobuf_FieldOptions_msginit,
"google.protobuf.FieldOptions");
}
@@ -1059,22 +1064,22 @@
// FileDescriptor
// -----------------------------------------------------------------------------
-PyObject* PyUpb_FileDescriptor_Get(const upb_filedef* file) {
+PyObject* PyUpb_FileDescriptor_Get(const upb_FileDef* file) {
return PyUpb_DescriptorBase_Get(kPyUpb_FileDescriptor, file, file);
}
-// These are not provided on upb_filedef because they use the underlying
+// These are not provided on upb_FileDef because they use the underlying
// symtab's hash table. This works for Python because everything happens under
// the GIL, but in general the caller has to guarantee that the symtab is not
// being mutated concurrently.
-typedef const void* PyUpb_FileDescriptor_LookupFunc(const upb_symtab*,
+typedef const void* PyUpb_FileDescriptor_LookupFunc(const upb_DefPool*,
const char*);
static const void* PyUpb_FileDescriptor_NestedLookup(
- const upb_filedef* filedef, const char* name,
+ const upb_FileDef* filedef, const char* name,
PyUpb_FileDescriptor_LookupFunc* func) {
- const upb_symtab* symtab = upb_filedef_symtab(filedef);
- const char* package = upb_filedef_package(filedef);
+ const upb_DefPool* symtab = upb_FileDef_Pool(filedef);
+ const char* package = upb_FileDef_Package(filedef);
if (package) {
PyObject* qname = PyUnicode_FromFormat("%s.%s", package, name);
const void* ret = func(symtab, PyUnicode_AsUTF8AndSize(qname, NULL));
@@ -1086,32 +1091,32 @@
}
static const void* PyUpb_FileDescriptor_LookupMessage(
- const upb_filedef* filedef, const char* name) {
- return PyUpb_FileDescriptor_NestedLookup(filedef, name,
- (void*)&upb_symtab_lookupmsg);
+ const upb_FileDef* filedef, const char* name) {
+ return PyUpb_FileDescriptor_NestedLookup(
+ filedef, name, (void*)&upb_DefPool_FindMessageByName);
}
-static const void* PyUpb_FileDescriptor_LookupEnum(const upb_filedef* filedef,
+static const void* PyUpb_FileDescriptor_LookupEnum(const upb_FileDef* filedef,
const char* name) {
return PyUpb_FileDescriptor_NestedLookup(filedef, name,
- (void*)&upb_symtab_lookupenum);
+ (void*)&upb_DefPool_FindEnumByName);
}
static const void* PyUpb_FileDescriptor_LookupExtension(
- const upb_filedef* filedef, const char* name) {
- return PyUpb_FileDescriptor_NestedLookup(filedef, name,
- (void*)&upb_symtab_lookupext);
+ const upb_FileDef* filedef, const char* name) {
+ return PyUpb_FileDescriptor_NestedLookup(
+ filedef, name, (void*)&upb_DefPool_FindExtensionByName);
}
static const void* PyUpb_FileDescriptor_LookupService(
- const upb_filedef* filedef, const char* name) {
- return PyUpb_FileDescriptor_NestedLookup(filedef, name,
- (void*)&upb_symtab_lookupservice);
+ const upb_FileDef* filedef, const char* name) {
+ return PyUpb_FileDescriptor_NestedLookup(
+ filedef, name, (void*)&upb_DefPool_FindServiceByName);
}
static PyObject* PyUpb_FileDescriptor_GetName(PyUpb_DescriptorBase* self,
void* closure) {
- return PyUnicode_FromString(upb_filedef_name(self->def));
+ return PyUnicode_FromString(upb_FileDef_Name(self->def));
}
static PyObject* PyUpb_FileDescriptor_GetPool(PyObject* _self, void* closure) {
@@ -1123,7 +1128,7 @@
static PyObject* PyUpb_FileDescriptor_GetPackage(PyObject* _self,
void* closure) {
PyUpb_DescriptorBase* self = (PyUpb_DescriptorBase*)_self;
- return PyUnicode_FromString(upb_filedef_package(self->def));
+ return PyUnicode_FromString(upb_FileDef_Package(self->def));
}
static PyObject* PyUpb_FileDescriptor_GetSerializedPb(PyObject* self,
@@ -1137,12 +1142,12 @@
void* closure) {
static PyUpb_ByNameMap_Funcs funcs = {
{
- (void*)&upb_filedef_toplvlmsgcount,
- (void*)&upb_filedef_toplvlmsg,
+ (void*)&upb_FileDef_TopLevelMessageCount,
+ (void*)&upb_FileDef_TopLevelMessage,
(void*)&PyUpb_Descriptor_Get,
},
(void*)&PyUpb_FileDescriptor_LookupMessage,
- (void*)&upb_msgdef_name,
+ (void*)&upb_MessageDef_Name,
};
PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_ByNameMap_New(&funcs, self->def, self->pool);
@@ -1152,12 +1157,12 @@
void* closure) {
static PyUpb_ByNameMap_Funcs funcs = {
{
- (void*)&upb_filedef_toplvlenumcount,
- (void*)&upb_filedef_toplvlenum,
+ (void*)&upb_FileDef_TopLevelEnumCount,
+ (void*)&upb_FileDef_TopLevelEnum,
(void*)&PyUpb_EnumDescriptor_Get,
},
(void*)&PyUpb_FileDescriptor_LookupEnum,
- (void*)&upb_enumdef_name,
+ (void*)&upb_EnumDef_Name,
};
PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_ByNameMap_New(&funcs, self->def, self->pool);
@@ -1167,12 +1172,12 @@
void* closure) {
static PyUpb_ByNameMap_Funcs funcs = {
{
- (void*)&upb_filedef_toplvlextcount,
- (void*)&upb_filedef_toplvlext,
+ (void*)&upb_FileDef_TopLevelExtensionCount,
+ (void*)&upb_FileDef_TopLevelExtension,
(void*)&PyUpb_FieldDescriptor_Get,
},
(void*)&PyUpb_FileDescriptor_LookupExtension,
- (void*)&upb_fielddef_name,
+ (void*)&upb_FieldDef_Name,
};
PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_ByNameMap_New(&funcs, self->def, self->pool);
@@ -1182,12 +1187,12 @@
void* closure) {
static PyUpb_ByNameMap_Funcs funcs = {
{
- (void*)&upb_filedef_servicecount,
- (void*)&upb_filedef_service,
+ (void*)&upb_FileDef_ServiceCount,
+ (void*)&upb_FileDef_Service,
(void*)&PyUpb_ServiceDescriptor_Get,
},
(void*)&PyUpb_FileDescriptor_LookupService,
- (void*)&upb_servicedef_name,
+ (void*)&upb_ServiceDef_Name,
};
PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_ByNameMap_New(&funcs, self->def, self->pool);
@@ -1197,8 +1202,8 @@
void* closure) {
PyUpb_DescriptorBase* self = (void*)_self;
static PyUpb_GenericSequence_Funcs funcs = {
- (void*)&upb_filedef_depcount,
- (void*)&upb_filedef_dep,
+ (void*)&upb_FileDef_DependencyCount,
+ (void*)&upb_FileDef_Dependency,
(void*)&PyUpb_FileDescriptor_Get,
};
return PyUpb_GenericSequence_New(&funcs, self->def, self->pool);
@@ -1208,8 +1213,8 @@
void* closure) {
PyUpb_DescriptorBase* self = (void*)_self;
static PyUpb_GenericSequence_Funcs funcs = {
- (void*)&upb_filedef_publicdepcount,
- (void*)&upb_filedef_publicdep,
+ (void*)&upb_FileDef_PublicDependencyCount,
+ (void*)&upb_FileDef_PublicDependency,
(void*)&PyUpb_FileDescriptor_Get,
};
return PyUpb_GenericSequence_New(&funcs, self->def, self->pool);
@@ -1219,20 +1224,20 @@
void* closure) {
PyUpb_DescriptorBase* self = (void*)_self;
const char* syntax =
- upb_filedef_syntax(self->def) == UPB_SYNTAX_PROTO2 ? "proto2" : "proto3";
+ upb_FileDef_Syntax(self->def) == kUpb_Syntax_Proto2 ? "proto2" : "proto3";
return PyUnicode_FromString(syntax);
}
static PyObject* PyUpb_FileDescriptor_GetHasOptions(PyObject* _self,
void* closure) {
PyUpb_DescriptorBase* self = (void*)_self;
- return PyBool_FromLong(upb_filedef_hasoptions(self->def));
+ return PyBool_FromLong(upb_FileDef_HasOptions(self->def));
}
static PyObject* PyUpb_FileDescriptor_GetOptions(PyObject* _self,
PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self;
- return PyUpb_DescriptorBase_GetOptions(self, upb_filedef_options(self->def),
+ return PyUpb_DescriptorBase_GetOptions(self, upb_FileDef_Options(self->def),
&google_protobuf_FileOptions_msginit,
"google.protobuf.FileOptions");
}
@@ -1285,7 +1290,7 @@
PyUpb_FileDescriptor_Slots,
};
-const upb_filedef* PyUpb_FileDescriptor_GetDef(PyObject* _self) {
+const upb_FileDef* PyUpb_FileDescriptor_GetDef(PyObject* _self) {
PyUpb_DescriptorBase* self =
PyUpb_DescriptorBase_Check(_self, kPyUpb_FileDescriptor);
return self ? self->def : NULL;
@@ -1295,50 +1300,50 @@
// MethodDescriptor
// -----------------------------------------------------------------------------
-const upb_methoddef* PyUpb_MethodDescriptor_GetDef(PyObject* _self) {
+const upb_MethodDef* PyUpb_MethodDescriptor_GetDef(PyObject* _self) {
PyUpb_DescriptorBase* self =
PyUpb_DescriptorBase_Check(_self, kPyUpb_MethodDescriptor);
return self ? self->def : NULL;
}
-PyObject* PyUpb_MethodDescriptor_Get(const upb_methoddef* m) {
- const upb_filedef* file = upb_servicedef_file(upb_methoddef_service(m));
+PyObject* PyUpb_MethodDescriptor_Get(const upb_MethodDef* m) {
+ const upb_FileDef* file = upb_ServiceDef_File(upb_MethodDef_Service(m));
return PyUpb_DescriptorBase_Get(kPyUpb_MethodDescriptor, m, file);
}
static PyObject* PyUpb_MethodDescriptor_GetName(PyObject* self, void* closure) {
- const upb_methoddef* m = PyUpb_MethodDescriptor_GetDef(self);
- return PyUnicode_FromString(upb_methoddef_name(m));
+ const upb_MethodDef* m = PyUpb_MethodDescriptor_GetDef(self);
+ return PyUnicode_FromString(upb_MethodDef_Name(m));
}
static PyObject* PyUpb_MethodDescriptor_GetFullName(PyObject* self,
void* closure) {
- const upb_methoddef* m = PyUpb_MethodDescriptor_GetDef(self);
- return PyUnicode_FromString(upb_methoddef_fullname(m));
+ const upb_MethodDef* m = PyUpb_MethodDescriptor_GetDef(self);
+ return PyUnicode_FromString(upb_MethodDef_FullName(m));
}
static PyObject* PyUpb_MethodDescriptor_GetContainingService(PyObject* self,
void* closure) {
- const upb_methoddef* m = PyUpb_MethodDescriptor_GetDef(self);
- return PyUpb_ServiceDescriptor_Get(upb_methoddef_service(m));
+ const upb_MethodDef* m = PyUpb_MethodDescriptor_GetDef(self);
+ return PyUpb_ServiceDescriptor_Get(upb_MethodDef_Service(m));
}
static PyObject* PyUpb_MethodDescriptor_GetInputType(PyObject* self,
void* closure) {
- const upb_methoddef* m = PyUpb_MethodDescriptor_GetDef(self);
- return PyUpb_Descriptor_Get(upb_methoddef_inputtype(m));
+ const upb_MethodDef* m = PyUpb_MethodDescriptor_GetDef(self);
+ return PyUpb_Descriptor_Get(upb_MethodDef_InputType(m));
}
static PyObject* PyUpb_MethodDescriptor_GetOutputType(PyObject* self,
void* closure) {
- const upb_methoddef* m = PyUpb_MethodDescriptor_GetDef(self);
- return PyUpb_Descriptor_Get(upb_methoddef_outputtype(m));
+ const upb_MethodDef* m = PyUpb_MethodDescriptor_GetDef(self);
+ return PyUpb_Descriptor_Get(upb_MethodDef_OutputType(m));
}
static PyObject* PyUpb_MethodDescriptor_GetOptions(PyObject* _self,
PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self;
- return PyUpb_DescriptorBase_GetOptions(self, upb_methoddef_options(self->def),
+ return PyUpb_DescriptorBase_GetOptions(self, upb_MethodDef_Options(self->def),
&google_protobuf_MethodOptions_msginit,
"google.protobuf.MethodOptions");
}
@@ -1386,53 +1391,54 @@
// OneofDescriptor
// -----------------------------------------------------------------------------
-const upb_oneofdef* PyUpb_OneofDescriptor_GetDef(PyObject* _self) {
+const upb_OneofDef* PyUpb_OneofDescriptor_GetDef(PyObject* _self) {
PyUpb_DescriptorBase* self =
PyUpb_DescriptorBase_Check(_self, kPyUpb_OneofDescriptor);
return self ? self->def : NULL;
}
-PyObject* PyUpb_OneofDescriptor_Get(const upb_oneofdef* oneof) {
- const upb_filedef* file = upb_msgdef_file(upb_oneofdef_containingtype(oneof));
+PyObject* PyUpb_OneofDescriptor_Get(const upb_OneofDef* oneof) {
+ const upb_FileDef* file =
+ upb_MessageDef_File(upb_OneofDef_ContainingType(oneof));
return PyUpb_DescriptorBase_Get(kPyUpb_OneofDescriptor, oneof, file);
}
static PyObject* PyUpb_OneofDescriptor_GetName(PyObject* self, void* closure) {
- const upb_oneofdef* oneof = PyUpb_OneofDescriptor_GetDef(self);
- return PyUnicode_FromString(upb_oneofdef_name(oneof));
+ const upb_OneofDef* oneof = PyUpb_OneofDescriptor_GetDef(self);
+ return PyUnicode_FromString(upb_OneofDef_Name(oneof));
}
static PyObject* PyUpb_OneofDescriptor_GetFullName(PyObject* self,
void* closure) {
- const upb_oneofdef* oneof = PyUpb_OneofDescriptor_GetDef(self);
+ const upb_OneofDef* oneof = PyUpb_OneofDescriptor_GetDef(self);
return PyUnicode_FromFormat(
- "%s.%s", upb_msgdef_fullname(upb_oneofdef_containingtype(oneof)),
- upb_oneofdef_name(oneof));
+ "%s.%s", upb_MessageDef_FullName(upb_OneofDef_ContainingType(oneof)),
+ upb_OneofDef_Name(oneof));
}
static PyObject* PyUpb_OneofDescriptor_GetIndex(PyObject* self, void* closure) {
- const upb_oneofdef* oneof = PyUpb_OneofDescriptor_GetDef(self);
- return PyLong_FromLong(upb_oneofdef_index(oneof));
+ const upb_OneofDef* oneof = PyUpb_OneofDescriptor_GetDef(self);
+ return PyLong_FromLong(upb_OneofDef_Index(oneof));
}
static PyObject* PyUpb_OneofDescriptor_GetContainingType(PyObject* self,
void* closure) {
- const upb_oneofdef* oneof = PyUpb_OneofDescriptor_GetDef(self);
- return PyUpb_Descriptor_Get(upb_oneofdef_containingtype(oneof));
+ const upb_OneofDef* oneof = PyUpb_OneofDescriptor_GetDef(self);
+ return PyUpb_Descriptor_Get(upb_OneofDef_ContainingType(oneof));
}
static PyObject* PyUpb_OneofDescriptor_GetHasOptions(PyObject* _self,
void* closure) {
PyUpb_DescriptorBase* self = (void*)_self;
- return PyBool_FromLong(upb_oneofdef_hasoptions(self->def));
+ return PyBool_FromLong(upb_OneofDef_HasOptions(self->def));
}
static PyObject* PyUpb_OneofDescriptor_GetFields(PyObject* _self,
void* closure) {
PyUpb_DescriptorBase* self = (void*)_self;
static PyUpb_GenericSequence_Funcs funcs = {
- (void*)&upb_oneofdef_fieldcount,
- (void*)&upb_oneofdef_field,
+ (void*)&upb_OneofDef_FieldCount,
+ (void*)&upb_OneofDef_Field,
(void*)&PyUpb_FieldDescriptor_Get,
};
return PyUpb_GenericSequence_New(&funcs, self->def, self->pool);
@@ -1441,7 +1447,7 @@
static PyObject* PyUpb_OneofDescriptor_GetOptions(PyObject* _self,
PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self;
- return PyUpb_DescriptorBase_GetOptions(self, upb_oneofdef_options(self->def),
+ return PyUpb_DescriptorBase_GetOptions(self, upb_OneofDef_Options(self->def),
&google_protobuf_OneofOptions_msginit,
"google.protobuf.OneofOptions");
}
@@ -1477,47 +1483,47 @@
// ServiceDescriptor
// -----------------------------------------------------------------------------
-const upb_servicedef* PyUpb_ServiceDescriptor_GetDef(PyObject* _self) {
+const upb_ServiceDef* PyUpb_ServiceDescriptor_GetDef(PyObject* _self) {
PyUpb_DescriptorBase* self =
PyUpb_DescriptorBase_Check(_self, kPyUpb_ServiceDescriptor);
return self ? self->def : NULL;
}
-PyObject* PyUpb_ServiceDescriptor_Get(const upb_servicedef* s) {
- const upb_filedef* file = upb_servicedef_file(s);
+PyObject* PyUpb_ServiceDescriptor_Get(const upb_ServiceDef* s) {
+ const upb_FileDef* file = upb_ServiceDef_File(s);
return PyUpb_DescriptorBase_Get(kPyUpb_ServiceDescriptor, s, file);
}
static PyObject* PyUpb_ServiceDescriptor_GetFullName(PyObject* self,
void* closure) {
- const upb_servicedef* s = PyUpb_ServiceDescriptor_GetDef(self);
- return PyUnicode_FromString(upb_servicedef_fullname(s));
+ const upb_ServiceDef* s = PyUpb_ServiceDescriptor_GetDef(self);
+ return PyUnicode_FromString(upb_ServiceDef_FullName(s));
}
static PyObject* PyUpb_ServiceDescriptor_GetName(PyObject* self,
void* closure) {
- const upb_servicedef* s = PyUpb_ServiceDescriptor_GetDef(self);
- return PyUnicode_FromString(upb_servicedef_name(s));
+ const upb_ServiceDef* s = PyUpb_ServiceDescriptor_GetDef(self);
+ return PyUnicode_FromString(upb_ServiceDef_Name(s));
}
static PyObject* PyUpb_ServiceDescriptor_GetFile(PyObject* self,
void* closure) {
- const upb_servicedef* s = PyUpb_ServiceDescriptor_GetDef(self);
- return PyUpb_FileDescriptor_Get(upb_servicedef_file(s));
+ const upb_ServiceDef* s = PyUpb_ServiceDescriptor_GetDef(self);
+ return PyUpb_FileDescriptor_Get(upb_ServiceDef_File(s));
}
static PyObject* PyUpb_ServiceDescriptor_GetIndex(PyObject* self,
void* closure) {
- const upb_servicedef* s = PyUpb_ServiceDescriptor_GetDef(self);
- return PyLong_FromLong(upb_servicedef_index(s));
+ const upb_ServiceDef* s = PyUpb_ServiceDescriptor_GetDef(self);
+ return PyLong_FromLong(upb_ServiceDef_Index(s));
}
static PyObject* PyUpb_ServiceDescriptor_GetMethods(PyObject* _self,
void* closure) {
PyUpb_DescriptorBase* self = (void*)_self;
static PyUpb_GenericSequence_Funcs funcs = {
- (void*)&upb_servicedef_methodcount,
- (void*)&upb_servicedef_method,
+ (void*)&upb_ServiceDef_MethodCount,
+ (void*)&upb_ServiceDef_Method,
(void*)&PyUpb_MethodDescriptor_Get,
};
return PyUpb_GenericSequence_New(&funcs, self->def, self->pool);
@@ -1527,12 +1533,12 @@
void* closure) {
static PyUpb_ByNameMap_Funcs funcs = {
{
- (void*)&upb_servicedef_methodcount,
- (void*)&upb_servicedef_method,
+ (void*)&upb_ServiceDef_MethodCount,
+ (void*)&upb_ServiceDef_Method,
(void*)&PyUpb_MethodDescriptor_Get,
},
- (void*)&upb_servicedef_lookupmethod,
- (void*)&upb_methoddef_name,
+ (void*)&upb_ServiceDef_FindMethodByName,
+ (void*)&upb_MethodDef_Name,
};
PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_ByNameMap_New(&funcs, self->def, self->pool);
@@ -1542,7 +1548,7 @@
PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetOptions(
- self, upb_servicedef_options(self->def),
+ self, upb_ServiceDef_Options(self->def),
&google_protobuf_ServiceOptions_msginit,
"google.protobuf.ServiceOptions");
}
@@ -1559,7 +1565,8 @@
PyUpb_DescriptorBase* self = (void*)_self;
const char* name = PyUnicode_AsUTF8AndSize(py_name, NULL);
if (!name) return NULL;
- const upb_methoddef* method = upb_servicedef_lookupmethod(self->def, name);
+ const upb_MethodDef* method =
+ upb_ServiceDef_FindMethodByName(self->def, name);
if (method == NULL) {
return PyErr_Format(PyExc_KeyError, "Couldn't find method %.200s", name);
}
diff --git a/python/descriptor.h b/python/descriptor.h
index 58ac0df..0b29cd8 100644
--- a/python/descriptor.h
+++ b/python/descriptor.h
@@ -47,33 +47,33 @@
// Given a descriptor object |desc|, returns a Python message class object for
// the msgdef |m|, which must be from the same pool.
-PyObject* PyUpb_Descriptor_GetClass(const upb_msgdef* m);
+PyObject* PyUpb_Descriptor_GetClass(const upb_MessageDef* m);
// Returns a Python wrapper object for the given def. This will return an
// existing object if one already exists, otherwise a new object will be
// created. The caller always owns a ref on the returned object.
-PyObject* PyUpb_Descriptor_Get(const upb_msgdef* msgdef);
-PyObject* PyUpb_EnumDescriptor_Get(const upb_enumdef* enumdef);
-PyObject* PyUpb_FieldDescriptor_Get(const upb_fielddef* field);
-PyObject* PyUpb_FileDescriptor_Get(const upb_filedef* file);
-PyObject* PyUpb_OneofDescriptor_Get(const upb_oneofdef* oneof);
-PyObject* PyUpb_EnumValueDescriptor_Get(const upb_enumvaldef* enumval);
-PyObject* PyUpb_Descriptor_GetOrCreateWrapper(const upb_msgdef* msg);
-PyObject* PyUpb_ServiceDescriptor_Get(const upb_servicedef* s);
+PyObject* PyUpb_Descriptor_Get(const upb_MessageDef* msgdef);
+PyObject* PyUpb_EnumDescriptor_Get(const upb_EnumDef* enumdef);
+PyObject* PyUpb_FieldDescriptor_Get(const upb_FieldDef* field);
+PyObject* PyUpb_FileDescriptor_Get(const upb_FileDef* file);
+PyObject* PyUpb_OneofDescriptor_Get(const upb_OneofDef* oneof);
+PyObject* PyUpb_EnumValueDescriptor_Get(const upb_EnumValueDef* enumval);
+PyObject* PyUpb_Descriptor_GetOrCreateWrapper(const upb_MessageDef* msg);
+PyObject* PyUpb_ServiceDescriptor_Get(const upb_ServiceDef* s);
// Returns the underlying |def| for a given wrapper object. The caller must
// have already verified that the given Python object is of the expected type.
-const upb_filedef* PyUpb_FileDescriptor_GetDef(PyObject* file);
-const upb_fielddef* PyUpb_FieldDescriptor_GetDef(PyObject* file);
-const upb_msgdef* PyUpb_Descriptor_GetDef(PyObject* _self);
+const upb_FileDef* PyUpb_FileDescriptor_GetDef(PyObject* file);
+const upb_FieldDef* PyUpb_FieldDescriptor_GetDef(PyObject* file);
+const upb_MessageDef* PyUpb_Descriptor_GetDef(PyObject* _self);
const void* PyUpb_AnyDescriptor_GetDef(PyObject* _self);
// Returns the underlying |def| for a given wrapper object. The caller must
// have already verified that the given Python object is of the expected type.
-const upb_filedef* PyUpb_FileDescriptor_GetDef(PyObject* file);
+const upb_FileDef* PyUpb_FileDescriptor_GetDef(PyObject* file);
const void* PyUpb_AnyDescriptor_GetDef(PyObject* _self);
// Module-level init.
bool PyUpb_InitDescriptor(PyObject* m);
-#endif // PYUPB_DESCRIPTOR_H__
+#endif // PYUPB_DESCRIPTOR_H__
diff --git a/python/descriptor_containers.c b/python/descriptor_containers.c
index 95d2da1..ac71585 100644
--- a/python/descriptor_containers.c
+++ b/python/descriptor_containers.c
@@ -13,11 +13,11 @@
* 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
+ * 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
@@ -27,40 +27,39 @@
#include "descriptor_containers.h"
-#include "upb/def.h"
-
-#include "protobuf.h"
#include "descriptor.h"
+#include "protobuf.h"
+#include "upb/def.h"
// -----------------------------------------------------------------------------
// DescriptorIterator
// -----------------------------------------------------------------------------
typedef struct {
- PyObject_HEAD
- const PyUpb_GenericSequence_Funcs *funcs;
- const void *parent; // upb_msgdef*, upb_symtab*, etc.
- PyObject *parent_obj; // Python object that keeps parent alive, we own a ref.
+ PyObject_HEAD;
+ const PyUpb_GenericSequence_Funcs* funcs;
+ const void* parent; // upb_MessageDef*, upb_DefPool*, etc.
+ PyObject* parent_obj; // Python object that keeps parent alive, we own a ref.
int index; // Current iterator index.
} PyUpb_DescriptorIterator;
-PyUpb_DescriptorIterator *PyUpb_DescriptorIterator_Self(PyObject *obj) {
+PyUpb_DescriptorIterator* PyUpb_DescriptorIterator_Self(PyObject* obj) {
assert(Py_TYPE(obj) == PyUpb_ModuleState_Get()->descriptor_iterator_type);
return (PyUpb_DescriptorIterator*)obj;
}
-static void PyUpb_DescriptorIterator_Dealloc(PyObject *_self) {
- PyUpb_DescriptorIterator *self = PyUpb_DescriptorIterator_Self(_self);
+static void PyUpb_DescriptorIterator_Dealloc(PyObject* _self) {
+ PyUpb_DescriptorIterator* self = PyUpb_DescriptorIterator_Self(_self);
Py_DECREF(self->parent_obj);
PyUpb_Dealloc(self);
}
-PyObject *PyUpb_DescriptorIterator_New(const PyUpb_GenericSequence_Funcs *funcs,
- const void *parent,
- PyObject *parent_obj) {
- PyUpb_ModuleState *s = PyUpb_ModuleState_Get();
- PyUpb_DescriptorIterator *iter =
- (void *)PyType_GenericAlloc(s->descriptor_iterator_type, 0);
+PyObject* PyUpb_DescriptorIterator_New(const PyUpb_GenericSequence_Funcs* funcs,
+ const void* parent,
+ PyObject* parent_obj) {
+ PyUpb_ModuleState* s = PyUpb_ModuleState_Get();
+ PyUpb_DescriptorIterator* iter =
+ (void*)PyType_GenericAlloc(s->descriptor_iterator_type, 0);
iter->funcs = funcs;
iter->parent = parent;
iter->parent_obj = parent_obj;
@@ -70,27 +69,26 @@
}
PyObject* PyUpb_DescriptorIterator_IterNext(PyObject* _self) {
- PyUpb_DescriptorIterator *self = PyUpb_DescriptorIterator_Self(_self);
+ PyUpb_DescriptorIterator* self = PyUpb_DescriptorIterator_Self(_self);
int size = self->funcs->get_elem_count(self->parent);
if (self->index >= size) return NULL;
- const void *elem = self->funcs->index(self->parent, self->index);
+ const void* elem = self->funcs->index(self->parent, self->index);
self->index++;
return self->funcs->get_elem_wrapper(elem);
}
static PyType_Slot PyUpb_DescriptorIterator_Slots[] = {
- {Py_tp_dealloc, PyUpb_DescriptorIterator_Dealloc},
- {Py_tp_iter, PyObject_SelfIter},
- {Py_tp_iternext, PyUpb_DescriptorIterator_IterNext},
- {0, NULL}
-};
+ {Py_tp_dealloc, PyUpb_DescriptorIterator_Dealloc},
+ {Py_tp_iter, PyObject_SelfIter},
+ {Py_tp_iternext, PyUpb_DescriptorIterator_IterNext},
+ {0, NULL}};
static PyType_Spec PyUpb_DescriptorIterator_Spec = {
- PYUPB_MODULE_NAME ".DescriptorIterator", // tp_name
- sizeof(PyUpb_DescriptorIterator), // tp_basicsize
- 0, // tp_itemsize
- Py_TPFLAGS_DEFAULT, // tp_flags
- PyUpb_DescriptorIterator_Slots,
+ PYUPB_MODULE_NAME ".DescriptorIterator", // tp_name
+ sizeof(PyUpb_DescriptorIterator), // tp_basicsize
+ 0, // tp_itemsize
+ Py_TPFLAGS_DEFAULT, // tp_flags
+ PyUpb_DescriptorIterator_Slots,
};
// -----------------------------------------------------------------------------
@@ -98,29 +96,28 @@
// -----------------------------------------------------------------------------
typedef struct {
- PyObject_HEAD
- const PyUpb_GenericSequence_Funcs *funcs;
- const void *parent; // upb_msgdef*, upb_symtab*, etc.
- PyObject *parent_obj; // Python object that keeps parent alive, we own a ref.
+ PyObject_HEAD;
+ const PyUpb_GenericSequence_Funcs* funcs;
+ const void* parent; // upb_MessageDef*, upb_DefPool*, etc.
+ PyObject* parent_obj; // Python object that keeps parent alive, we own a ref.
} PyUpb_GenericSequence;
-PyUpb_GenericSequence *PyUpb_GenericSequence_Self(PyObject *obj) {
+PyUpb_GenericSequence* PyUpb_GenericSequence_Self(PyObject* obj) {
assert(Py_TYPE(obj) == PyUpb_ModuleState_Get()->generic_sequence_type);
return (PyUpb_GenericSequence*)obj;
}
-static void PyUpb_GenericSequence_Dealloc(PyObject *_self) {
- PyUpb_GenericSequence *self = PyUpb_GenericSequence_Self(_self);
+static void PyUpb_GenericSequence_Dealloc(PyObject* _self) {
+ PyUpb_GenericSequence* self = PyUpb_GenericSequence_Self(_self);
Py_CLEAR(self->parent_obj);
PyUpb_Dealloc(self);
}
-PyObject *PyUpb_GenericSequence_New(
- const PyUpb_GenericSequence_Funcs *funcs, const void *parent,
- PyObject *parent_obj) {
- PyUpb_ModuleState *s = PyUpb_ModuleState_Get();
- PyUpb_GenericSequence *seq =
- (PyUpb_GenericSequence *)PyType_GenericAlloc(s->generic_sequence_type, 0);
+PyObject* PyUpb_GenericSequence_New(const PyUpb_GenericSequence_Funcs* funcs,
+ const void* parent, PyObject* parent_obj) {
+ PyUpb_ModuleState* s = PyUpb_ModuleState_Get();
+ PyUpb_GenericSequence* seq =
+ (PyUpb_GenericSequence*)PyType_GenericAlloc(s->generic_sequence_type, 0);
seq->funcs = funcs;
seq->parent = parent;
seq->parent_obj = parent_obj;
@@ -129,30 +126,30 @@
}
static Py_ssize_t PyUpb_GenericSequence_Length(PyObject* _self) {
- PyUpb_GenericSequence *self = PyUpb_GenericSequence_Self(_self);
+ PyUpb_GenericSequence* self = PyUpb_GenericSequence_Self(_self);
return self->funcs->get_elem_count(self->parent);
}
-static PyObject *PyUpb_GenericSequence_GetItem(PyObject *_self,
+static PyObject* PyUpb_GenericSequence_GetItem(PyObject* _self,
Py_ssize_t index) {
- PyUpb_GenericSequence *self = PyUpb_GenericSequence_Self(_self);
+ PyUpb_GenericSequence* self = PyUpb_GenericSequence_Self(_self);
Py_ssize_t size = self->funcs->get_elem_count(self->parent);
if (index < 0 || index >= size) {
PyErr_Format(PyExc_IndexError, "list index (%zd) out of range", index);
return NULL;
}
- const void *elem = self->funcs->index(self->parent, index);
+ const void* elem = self->funcs->index(self->parent, index);
return self->funcs->get_elem_wrapper(elem);
}
// A sequence container can only be equal to another sequence container, or (for
// backward compatibility) to a list containing the same items.
// Returns 1 if equal, 0 if unequal, -1 on error.
-static int PyUpb_GenericSequence_IsEqual(PyUpb_GenericSequence *self,
- PyObject *other) {
+static int PyUpb_GenericSequence_IsEqual(PyUpb_GenericSequence* self,
+ PyObject* other) {
// Check the identity of C++ pointers.
if (PyObject_TypeCheck(other, Py_TYPE(self))) {
- PyUpb_GenericSequence *other_seq = (void *)other;
+ PyUpb_GenericSequence* other_seq = (void*)other;
return self->parent == other_seq->parent && self->funcs == other_seq->funcs;
}
@@ -166,7 +163,7 @@
return false;
}
- PyObject *item1;
+ PyObject* item1;
for (int i = 0; i < n; i++) {
item1 = PyUpb_GenericSequence_GetItem((PyObject*)self, i);
PyObject* item2 = PyList_GetItem(other, i);
@@ -183,9 +180,9 @@
return -1;
}
-static PyObject *PyUpb_GenericSequence_RichCompare(PyObject *_self,
- PyObject *other, int opid) {
- PyUpb_GenericSequence *self = PyUpb_GenericSequence_Self(_self);
+static PyObject* PyUpb_GenericSequence_RichCompare(PyObject* _self,
+ PyObject* other, int opid) {
+ PyUpb_GenericSequence* self = PyUpb_GenericSequence_Self(_self);
if (opid != Py_EQ && opid != Py_NE) {
Py_RETURN_NOTIMPLEMENTED;
}
@@ -196,9 +193,9 @@
// Linear search. Could optimize this in some cases (defs that have index),
// but not all (FileDescriptor.dependencies).
-static int PyUpb_GenericSequence_Find(PyObject *_self, PyObject *item) {
- PyUpb_GenericSequence *self = PyUpb_GenericSequence_Self(_self);
- const void *item_ptr = PyUpb_AnyDescriptor_GetDef(item);
+static int PyUpb_GenericSequence_Find(PyObject* _self, PyObject* item) {
+ PyUpb_GenericSequence* self = PyUpb_GenericSequence_Self(_self);
+ const void* item_ptr = PyUpb_AnyDescriptor_GetDef(item);
int count = self->funcs->get_elem_count(self->parent);
for (int i = 0; i < count; i++) {
if (self->funcs->index(self->parent, i) == item_ptr) {
@@ -218,9 +215,9 @@
}
}
-static PyObject *PyUpb_GenericSequence_Count(PyObject *_self, PyObject *item) {
- PyUpb_GenericSequence *self = PyUpb_GenericSequence_Self(_self);
- const void *item_ptr = PyUpb_AnyDescriptor_GetDef(item);
+static PyObject* PyUpb_GenericSequence_Count(PyObject* _self, PyObject* item) {
+ PyUpb_GenericSequence* self = PyUpb_GenericSequence_Self(_self);
+ const void* item_ptr = PyUpb_AnyDescriptor_GetDef(item);
int n = self->funcs->get_elem_count(self->parent);
int count = 0;
for (int i = 0; i < n; i++) {
@@ -231,7 +228,7 @@
return PyLong_FromLong(count);
}
-static PyObject *PyUpb_GenericSequence_Append(PyObject *self, PyObject *args) {
+static PyObject* PyUpb_GenericSequence_Append(PyObject* self, PyObject* args) {
PyErr_Format(PyExc_TypeError, "'%R' is not a mutable sequence", self);
return NULL;
}
@@ -245,25 +242,25 @@
{NULL}};
static PyType_Slot PyUpb_GenericSequence_Slots[] = {
- {Py_tp_dealloc, &PyUpb_GenericSequence_Dealloc},
- {Py_tp_methods, &PyUpb_GenericSequence_Methods},
- {Py_sq_length, PyUpb_GenericSequence_Length},
- {Py_sq_item, PyUpb_GenericSequence_GetItem},
- {Py_tp_richcompare, &PyUpb_GenericSequence_RichCompare},
- // These were implemented for Python/C++ but so far have not been required.
- // {Py_tp_repr, &PyUpb_GenericSequence_Repr},
- // {Py_sq_contains, PyUpb_GenericSequence_Contains},
- // {Py_mp_subscript, PyUpb_GenericSequence_Subscript},
- // {Py_mp_ass_subscript, PyUpb_GenericSequence_AssignSubscript},
- {0, NULL},
+ {Py_tp_dealloc, &PyUpb_GenericSequence_Dealloc},
+ {Py_tp_methods, &PyUpb_GenericSequence_Methods},
+ {Py_sq_length, PyUpb_GenericSequence_Length},
+ {Py_sq_item, PyUpb_GenericSequence_GetItem},
+ {Py_tp_richcompare, &PyUpb_GenericSequence_RichCompare},
+ // These were implemented for Python/C++ but so far have not been required.
+ // {Py_tp_repr, &PyUpb_GenericSequence_Repr},
+ // {Py_sq_contains, PyUpb_GenericSequence_Contains},
+ // {Py_mp_subscript, PyUpb_GenericSequence_Subscript},
+ // {Py_mp_ass_subscript, PyUpb_GenericSequence_AssignSubscript},
+ {0, NULL},
};
static PyType_Spec PyUpb_GenericSequence_Spec = {
- PYUPB_MODULE_NAME "._GenericSequence", // tp_name
- sizeof(PyUpb_GenericSequence), // tp_basicsize
- 0, // tp_itemsize
- Py_TPFLAGS_DEFAULT, // tp_flags
- PyUpb_GenericSequence_Slots,
+ PYUPB_MODULE_NAME "._GenericSequence", // tp_name
+ sizeof(PyUpb_GenericSequence), // tp_basicsize
+ 0, // tp_itemsize
+ Py_TPFLAGS_DEFAULT, // tp_flags
+ PyUpb_GenericSequence_Slots,
};
// -----------------------------------------------------------------------------
@@ -271,27 +268,27 @@
// -----------------------------------------------------------------------------
typedef struct {
- PyObject_HEAD
- const PyUpb_ByNameMap_Funcs *funcs;
- const void *parent; // upb_msgdef*, upb_symtab*, etc.
- PyObject *parent_obj; // Python object that keeps parent alive, we own a ref.
+ PyObject_HEAD;
+ const PyUpb_ByNameMap_Funcs* funcs;
+ const void* parent; // upb_MessageDef*, upb_DefPool*, etc.
+ PyObject* parent_obj; // Python object that keeps parent alive, we own a ref.
} PyUpb_ByNameMap;
-PyUpb_ByNameMap *PyUpb_ByNameMap_Self(PyObject *obj) {
+PyUpb_ByNameMap* PyUpb_ByNameMap_Self(PyObject* obj) {
assert(Py_TYPE(obj) == PyUpb_ModuleState_Get()->by_name_map_type);
return (PyUpb_ByNameMap*)obj;
}
-static void PyUpb_ByNameMap_Dealloc(PyObject *_self) {
- PyUpb_ByNameMap *self = PyUpb_ByNameMap_Self(_self);
+static void PyUpb_ByNameMap_Dealloc(PyObject* _self) {
+ PyUpb_ByNameMap* self = PyUpb_ByNameMap_Self(_self);
Py_DECREF(self->parent_obj);
PyUpb_Dealloc(self);
}
-PyObject *PyUpb_ByNameMap_New(const PyUpb_ByNameMap_Funcs *funcs,
- const void *parent, PyObject *parent_obj) {
- PyUpb_ModuleState *s = PyUpb_ModuleState_Get();
- PyUpb_ByNameMap *map = (void*)PyType_GenericAlloc(s->by_name_map_type, 0);
+PyObject* PyUpb_ByNameMap_New(const PyUpb_ByNameMap_Funcs* funcs,
+ const void* parent, PyObject* parent_obj) {
+ PyUpb_ModuleState* s = PyUpb_ModuleState_Get();
+ PyUpb_ByNameMap* map = (void*)PyType_GenericAlloc(s->by_name_map_type, 0);
map->funcs = funcs;
map->parent = parent;
map->parent_obj = parent_obj;
@@ -300,14 +297,14 @@
}
static Py_ssize_t PyUpb_ByNameMap_Length(PyObject* _self) {
- PyUpb_ByNameMap *self = PyUpb_ByNameMap_Self(_self);
+ PyUpb_ByNameMap* self = PyUpb_ByNameMap_Self(_self);
return self->funcs->base.get_elem_count(self->parent);
}
-static PyObject *PyUpb_ByNameMap_Subscript(PyObject *_self, PyObject *key) {
- PyUpb_ByNameMap *self = PyUpb_ByNameMap_Self(_self);
- const char *name = PyUpb_GetStrData(key);
- const void *elem = name ? self->funcs->lookup(self->parent, name) : NULL;
+static PyObject* PyUpb_ByNameMap_Subscript(PyObject* _self, PyObject* key) {
+ PyUpb_ByNameMap* self = PyUpb_ByNameMap_Self(_self);
+ const char* name = PyUpb_GetStrData(key);
+ const void* elem = name ? self->funcs->lookup(self->parent, name) : NULL;
if (elem) {
return self->funcs->base.get_elem_wrapper(elem);
@@ -317,30 +314,30 @@
}
}
-static int PyUpb_ByNameMap_AssignSubscript(PyObject *self, PyObject *key,
- PyObject *value) {
+static int PyUpb_ByNameMap_AssignSubscript(PyObject* self, PyObject* key,
+ PyObject* value) {
PyErr_Format(PyExc_TypeError, PYUPB_MODULE_NAME
".ByNameMap' object does not support item assignment");
return -1;
}
-static int PyUpb_ByNameMap_Contains(PyObject *_self, PyObject *key) {
- PyUpb_ByNameMap *self = PyUpb_ByNameMap_Self(_self);
- const char *name = PyUpb_GetStrData(key);
- const void *elem = name ? self->funcs->lookup(self->parent, name) : NULL;
+static int PyUpb_ByNameMap_Contains(PyObject* _self, PyObject* key) {
+ PyUpb_ByNameMap* self = PyUpb_ByNameMap_Self(_self);
+ const char* name = PyUpb_GetStrData(key);
+ const void* elem = name ? self->funcs->lookup(self->parent, name) : NULL;
return elem ? 1 : 0;
}
-static PyObject *PyUpb_ByNameMap_Get(PyObject *_self, PyObject *args) {
- PyUpb_ByNameMap *self = PyUpb_ByNameMap_Self(_self);
+static PyObject* PyUpb_ByNameMap_Get(PyObject* _self, PyObject* args) {
+ PyUpb_ByNameMap* self = PyUpb_ByNameMap_Self(_self);
PyObject* key;
PyObject* default_value = Py_None;
if (!PyArg_UnpackTuple(args, "get", 1, 2, &key, &default_value)) {
return NULL;
}
- const char *name = PyUpb_GetStrData(key);
- const void *elem = name ? self->funcs->lookup(self->parent, name) : NULL;
+ const char* name = PyUpb_GetStrData(key);
+ const void* elem = name ? self->funcs->lookup(self->parent, name) : NULL;
if (elem) {
return self->funcs->base.get_elem_wrapper(elem);
@@ -350,20 +347,20 @@
}
}
-static PyObject *PyUpb_ByNameMap_GetIter(PyObject *_self) {
- PyUpb_ByNameMap *self = PyUpb_ByNameMap_Self(_self);
+static PyObject* PyUpb_ByNameMap_GetIter(PyObject* _self) {
+ PyUpb_ByNameMap* self = PyUpb_ByNameMap_Self(_self);
return PyUpb_DescriptorIterator_New(&self->funcs->base, self->parent,
self->parent_obj);
}
-static PyObject *PyUpb_ByNameMap_Keys(PyObject *_self, PyObject *args) {
- PyUpb_ByNameMap *self = PyUpb_ByNameMap_Self(_self);
+static PyObject* PyUpb_ByNameMap_Keys(PyObject* _self, PyObject* args) {
+ PyUpb_ByNameMap* self = PyUpb_ByNameMap_Self(_self);
int n = self->funcs->base.get_elem_count(self->parent);
- PyObject *ret = PyList_New(n);
+ PyObject* ret = PyList_New(n);
if (!ret) return NULL;
for (int i = 0; i < n; i++) {
- const void *elem = self->funcs->base.index(self->parent, i);
- PyObject *key = PyUnicode_FromString(self->funcs->get_elem_name(elem));
+ const void* elem = self->funcs->base.index(self->parent, i);
+ PyObject* key = PyUnicode_FromString(self->funcs->get_elem_name(elem));
if (!key) goto error;
PyList_SetItem(ret, i, key);
}
@@ -374,14 +371,14 @@
return NULL;
}
-static PyObject *PyUpb_ByNameMap_Values(PyObject *_self, PyObject *args) {
- PyUpb_ByNameMap *self = PyUpb_ByNameMap_Self(_self);
+static PyObject* PyUpb_ByNameMap_Values(PyObject* _self, PyObject* args) {
+ PyUpb_ByNameMap* self = PyUpb_ByNameMap_Self(_self);
int n = self->funcs->base.get_elem_count(self->parent);
- PyObject *ret = PyList_New(n);
+ PyObject* ret = PyList_New(n);
if (!ret) return NULL;
for (int i = 0; i < n; i++) {
- const void *elem = self->funcs->base.index(self->parent, i);
- PyObject *py_elem = self->funcs->base.get_elem_wrapper(elem);
+ const void* elem = self->funcs->base.index(self->parent, i);
+ PyObject* py_elem = self->funcs->base.get_elem_wrapper(elem);
if (!py_elem) goto error;
PyList_SetItem(ret, i, py_elem);
}
@@ -392,15 +389,15 @@
return NULL;
}
-static PyObject *PyUpb_ByNameMap_Items(PyObject *_self, PyObject *args) {
- PyUpb_ByNameMap *self = (PyUpb_ByNameMap *)_self;
+static PyObject* PyUpb_ByNameMap_Items(PyObject* _self, PyObject* args) {
+ PyUpb_ByNameMap* self = (PyUpb_ByNameMap*)_self;
int n = self->funcs->base.get_elem_count(self->parent);
- PyObject *ret = PyList_New(n);
- PyObject *item;
- PyObject *py_elem;
+ PyObject* ret = PyList_New(n);
+ PyObject* item;
+ PyObject* py_elem;
if (!ret) return NULL;
for (int i = 0; i < n; i++) {
- const void *elem = self->funcs->base.index(self->parent, i);
+ const void* elem = self->funcs->base.index(self->parent, i);
item = PyTuple_New(2);
py_elem = self->funcs->base.get_elem_wrapper(elem);
if (!item || !py_elem) goto error;
@@ -424,22 +421,22 @@
static int PyUpb_ByNameMap_IsEqual(PyUpb_ByNameMap* self, PyObject* other) {
// Check the identity of C++ pointers.
if (PyObject_TypeCheck(other, Py_TYPE(self))) {
- PyUpb_ByNameMap *other_map = (void *)other;
+ PyUpb_ByNameMap* other_map = (void*)other;
return self->parent == other_map->parent && self->funcs == other_map->funcs;
}
if (!PyDict_Check(other)) return 0;
- PyObject *self_dict = PyDict_New();
+ PyObject* self_dict = PyDict_New();
PyDict_Merge(self_dict, (PyObject*)self, 0);
int eq = PyObject_RichCompareBool(self_dict, other, Py_EQ);
Py_DECREF(self_dict);
return eq;
}
-static PyObject *PyUpb_ByNameMap_RichCompare(PyObject *_self, PyObject *other,
+static PyObject* PyUpb_ByNameMap_RichCompare(PyObject* _self, PyObject* other,
int opid) {
- PyUpb_ByNameMap *self = PyUpb_ByNameMap_Self(_self);
+ PyUpb_ByNameMap* self = PyUpb_ByNameMap_Self(_self);
if (opid != Py_EQ && opid != Py_NE) {
Py_RETURN_NOTIMPLEMENTED;
}
@@ -468,11 +465,11 @@
};
static PyType_Spec PyUpb_ByNameMap_Spec = {
- PYUPB_MODULE_NAME "._ByNameMap", // tp_name
- sizeof(PyUpb_ByNameMap), // tp_basicsize
- 0, // tp_itemsize
- Py_TPFLAGS_DEFAULT, // tp_flags
- PyUpb_ByNameMap_Slots,
+ PYUPB_MODULE_NAME "._ByNameMap", // tp_name
+ sizeof(PyUpb_ByNameMap), // tp_basicsize
+ 0, // tp_itemsize
+ Py_TPFLAGS_DEFAULT, // tp_flags
+ PyUpb_ByNameMap_Slots,
};
// -----------------------------------------------------------------------------
@@ -480,21 +477,21 @@
// -----------------------------------------------------------------------------
typedef struct {
- PyObject_HEAD
- const PyUpb_ByNumberMap_Funcs *funcs;
- const void *parent; // upb_msgdef*, upb_symtab*, etc.
- PyObject *parent_obj; // Python object that keeps parent alive, we own a ref.
+ PyObject_HEAD;
+ const PyUpb_ByNumberMap_Funcs* funcs;
+ const void* parent; // upb_MessageDef*, upb_DefPool*, etc.
+ PyObject* parent_obj; // Python object that keeps parent alive, we own a ref.
} PyUpb_ByNumberMap;
-PyUpb_ByNumberMap *PyUpb_ByNumberMap_Self(PyObject *obj) {
+PyUpb_ByNumberMap* PyUpb_ByNumberMap_Self(PyObject* obj) {
assert(Py_TYPE(obj) == PyUpb_ModuleState_Get()->by_number_map_type);
return (PyUpb_ByNumberMap*)obj;
}
-PyObject *PyUpb_ByNumberMap_New(const PyUpb_ByNumberMap_Funcs *funcs,
- const void *parent, PyObject *parent_obj) {
- PyUpb_ModuleState *s = PyUpb_ModuleState_Get();
- PyUpb_ByNumberMap *map = (void*)PyType_GenericAlloc(s->by_number_map_type, 0);
+PyObject* PyUpb_ByNumberMap_New(const PyUpb_ByNumberMap_Funcs* funcs,
+ const void* parent, PyObject* parent_obj) {
+ PyUpb_ModuleState* s = PyUpb_ModuleState_Get();
+ PyUpb_ByNumberMap* map = (void*)PyType_GenericAlloc(s->by_number_map_type, 0);
map->funcs = funcs;
map->parent = parent;
map->parent_obj = parent_obj;
@@ -502,19 +499,19 @@
return &map->ob_base;
}
-static void PyUpb_ByNumberMap_Dealloc(PyObject *_self) {
- PyUpb_ByNumberMap *self = PyUpb_ByNumberMap_Self(_self);
+static void PyUpb_ByNumberMap_Dealloc(PyObject* _self) {
+ PyUpb_ByNumberMap* self = PyUpb_ByNumberMap_Self(_self);
Py_DECREF(self->parent_obj);
PyUpb_Dealloc(self);
}
static Py_ssize_t PyUpb_ByNumberMap_Length(PyObject* _self) {
- PyUpb_ByNumberMap *self = PyUpb_ByNumberMap_Self(_self);
+ PyUpb_ByNumberMap* self = PyUpb_ByNumberMap_Self(_self);
return self->funcs->base.get_elem_count(self->parent);
}
-static const void *PyUpb_ByNumberMap_LookupHelper(PyUpb_ByNumberMap *self,
- PyObject *key) {
+static const void* PyUpb_ByNumberMap_LookupHelper(PyUpb_ByNumberMap* self,
+ PyObject* key) {
long num = PyLong_AsLong(key);
if (num == -1 && PyErr_Occurred()) {
PyErr_Clear();
@@ -524,9 +521,9 @@
}
}
-static PyObject *PyUpb_ByNumberMap_Subscript(PyObject *_self, PyObject *key) {
- PyUpb_ByNumberMap *self = PyUpb_ByNumberMap_Self(_self);
- const void *elem = PyUpb_ByNumberMap_LookupHelper(self, key);
+static PyObject* PyUpb_ByNumberMap_Subscript(PyObject* _self, PyObject* key) {
+ PyUpb_ByNumberMap* self = PyUpb_ByNumberMap_Self(_self);
+ const void* elem = PyUpb_ByNumberMap_LookupHelper(self, key);
if (elem) {
return self->funcs->base.get_elem_wrapper(elem);
} else {
@@ -535,22 +532,22 @@
}
}
-static int PyUpb_ByNumberMap_AssignSubscript(PyObject *self, PyObject *key,
- PyObject *value) {
+static int PyUpb_ByNumberMap_AssignSubscript(PyObject* self, PyObject* key,
+ PyObject* value) {
PyErr_Format(PyExc_TypeError, PYUPB_MODULE_NAME
".ByNumberMap' object does not support item assignment");
return -1;
}
-static PyObject *PyUpb_ByNumberMap_Get(PyObject *_self, PyObject *args) {
- PyUpb_ByNumberMap *self = PyUpb_ByNumberMap_Self(_self);
+static PyObject* PyUpb_ByNumberMap_Get(PyObject* _self, PyObject* args) {
+ PyUpb_ByNumberMap* self = PyUpb_ByNumberMap_Self(_self);
PyObject* key;
PyObject* default_value = Py_None;
if (!PyArg_UnpackTuple(args, "get", 1, 2, &key, &default_value)) {
return NULL;
}
- const void *elem = PyUpb_ByNumberMap_LookupHelper(self, key);
+ const void* elem = PyUpb_ByNumberMap_LookupHelper(self, key);
if (elem) {
return self->funcs->base.get_elem_wrapper(elem);
} else {
@@ -558,20 +555,20 @@
}
}
-static PyObject *PyUpb_ByNumberMap_GetIter(PyObject *_self) {
- PyUpb_ByNumberMap *self = PyUpb_ByNumberMap_Self(_self);
+static PyObject* PyUpb_ByNumberMap_GetIter(PyObject* _self) {
+ PyUpb_ByNumberMap* self = PyUpb_ByNumberMap_Self(_self);
return PyUpb_DescriptorIterator_New(&self->funcs->base, self->parent,
self->parent_obj);
}
-static PyObject *PyUpb_ByNumberMap_Keys(PyObject *_self, PyObject *args) {
- PyUpb_ByNumberMap *self = PyUpb_ByNumberMap_Self(_self);
+static PyObject* PyUpb_ByNumberMap_Keys(PyObject* _self, PyObject* args) {
+ PyUpb_ByNumberMap* self = PyUpb_ByNumberMap_Self(_self);
int n = self->funcs->base.get_elem_count(self->parent);
- PyObject *ret = PyList_New(n);
+ PyObject* ret = PyList_New(n);
if (!ret) return NULL;
for (int i = 0; i < n; i++) {
- const void *elem = self->funcs->base.index(self->parent, i);
- PyObject *key = PyLong_FromLong(self->funcs->get_elem_num(elem));
+ const void* elem = self->funcs->base.index(self->parent, i);
+ PyObject* key = PyLong_FromLong(self->funcs->get_elem_num(elem));
if (!key) goto error;
PyList_SetItem(ret, i, key);
}
@@ -582,14 +579,14 @@
return NULL;
}
-static PyObject *PyUpb_ByNumberMap_Values(PyObject *_self, PyObject *args) {
- PyUpb_ByNumberMap *self = PyUpb_ByNumberMap_Self(_self);
+static PyObject* PyUpb_ByNumberMap_Values(PyObject* _self, PyObject* args) {
+ PyUpb_ByNumberMap* self = PyUpb_ByNumberMap_Self(_self);
int n = self->funcs->base.get_elem_count(self->parent);
- PyObject *ret = PyList_New(n);
+ PyObject* ret = PyList_New(n);
if (!ret) return NULL;
for (int i = 0; i < n; i++) {
- const void *elem = self->funcs->base.index(self->parent, i);
- PyObject *py_elem = self->funcs->base.get_elem_wrapper(elem);
+ const void* elem = self->funcs->base.index(self->parent, i);
+ PyObject* py_elem = self->funcs->base.get_elem_wrapper(elem);
if (!py_elem) goto error;
PyList_SetItem(ret, i, py_elem);
}
@@ -600,19 +597,19 @@
return NULL;
}
-static PyObject *PyUpb_ByNumberMap_Items(PyObject *_self, PyObject *args) {
- PyUpb_ByNumberMap *self = PyUpb_ByNumberMap_Self(_self);
+static PyObject* PyUpb_ByNumberMap_Items(PyObject* _self, PyObject* args) {
+ PyUpb_ByNumberMap* self = PyUpb_ByNumberMap_Self(_self);
int n = self->funcs->base.get_elem_count(self->parent);
- PyObject *ret = PyList_New(n);
- PyObject *item;
- PyObject *py_elem;
+ PyObject* ret = PyList_New(n);
+ PyObject* item;
+ PyObject* py_elem;
if (!ret) return NULL;
for (int i = 0; i < n; i++) {
- const void *elem = self->funcs->base.index(self->parent, i);
+ const void* elem = self->funcs->base.index(self->parent, i);
int number = self->funcs->get_elem_num(elem);
item = PyTuple_New(2);
py_elem = self->funcs->base.get_elem_wrapper(elem);
- if (!item || ! py_elem) goto error;
+ if (!item || !py_elem) goto error;
PyTuple_SetItem(item, 0, PyLong_FromLong(number));
PyTuple_SetItem(item, 1, py_elem);
PyList_SetItem(ret, i, item);
@@ -626,9 +623,9 @@
return NULL;
}
-static int PyUpb_ByNumberMap_Contains(PyObject *_self, PyObject *key) {
- PyUpb_ByNumberMap *self = PyUpb_ByNumberMap_Self(_self);
- const void *elem = PyUpb_ByNumberMap_LookupHelper(self, key);
+static int PyUpb_ByNumberMap_Contains(PyObject* _self, PyObject* key) {
+ PyUpb_ByNumberMap* self = PyUpb_ByNumberMap_Self(_self);
+ const void* elem = PyUpb_ByNumberMap_LookupHelper(self, key);
return elem ? 1 : 0;
}
@@ -638,22 +635,22 @@
static int PyUpb_ByNumberMap_IsEqual(PyUpb_ByNumberMap* self, PyObject* other) {
// Check the identity of C++ pointers.
if (PyObject_TypeCheck(other, Py_TYPE(self))) {
- PyUpb_ByNumberMap *other_map = (void *)other;
+ PyUpb_ByNumberMap* other_map = (void*)other;
return self->parent == other_map->parent && self->funcs == other_map->funcs;
}
if (!PyDict_Check(other)) return 0;
- PyObject *self_dict = PyDict_New();
+ PyObject* self_dict = PyDict_New();
PyDict_Merge(self_dict, (PyObject*)self, 0);
int eq = PyObject_RichCompareBool(self_dict, other, Py_EQ);
Py_DECREF(self_dict);
return eq;
}
-static PyObject *PyUpb_ByNumberMap_RichCompare(PyObject *_self, PyObject *other,
+static PyObject* PyUpb_ByNumberMap_RichCompare(PyObject* _self, PyObject* other,
int opid) {
- PyUpb_ByNumberMap *self = PyUpb_ByNumberMap_Self(_self);
+ PyUpb_ByNumberMap* self = PyUpb_ByNumberMap_Self(_self);
if (opid != Py_EQ && opid != Py_NE) {
Py_RETURN_NOTIMPLEMENTED;
}
@@ -682,11 +679,11 @@
};
static PyType_Spec PyUpb_ByNumberMap_Spec = {
- PYUPB_MODULE_NAME "._ByNumberMap", // tp_name
- sizeof(PyUpb_ByNumberMap), // tp_basicsize
- 0, // tp_itemsize
- Py_TPFLAGS_DEFAULT, // tp_flags
- PyUpb_ByNumberMap_Slots,
+ PYUPB_MODULE_NAME "._ByNumberMap", // tp_name
+ sizeof(PyUpb_ByNumberMap), // tp_basicsize
+ 0, // tp_itemsize
+ Py_TPFLAGS_DEFAULT, // tp_flags
+ PyUpb_ByNumberMap_Slots,
};
// -----------------------------------------------------------------------------
@@ -694,14 +691,13 @@
// -----------------------------------------------------------------------------
bool PyUpb_InitDescriptorContainers(PyObject* m) {
- PyUpb_ModuleState *s = PyUpb_ModuleState_GetFromModule(m);
+ PyUpb_ModuleState* s = PyUpb_ModuleState_GetFromModule(m);
s->by_name_map_type = PyUpb_AddClass(m, &PyUpb_ByNameMap_Spec);
s->by_number_map_type = PyUpb_AddClass(m, &PyUpb_ByNumberMap_Spec);
s->descriptor_iterator_type =
PyUpb_AddClass(m, &PyUpb_DescriptorIterator_Spec);
- s->generic_sequence_type =
- PyUpb_AddClass(m, &PyUpb_GenericSequence_Spec);
+ s->generic_sequence_type = PyUpb_AddClass(m, &PyUpb_GenericSequence_Spec);
return s->by_name_map_type && s->by_number_map_type &&
s->descriptor_iterator_type && s->generic_sequence_type;
diff --git a/python/descriptor_containers.h b/python/descriptor_containers.h
index 6991b2c..8c6b0d9 100644
--- a/python/descriptor_containers.h
+++ b/python/descriptor_containers.h
@@ -13,11 +13,11 @@
* 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
+ * 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
@@ -42,9 +42,8 @@
#include <stdbool.h>
-#include "upb/def.h"
-
#include "protobuf.h"
+#include "upb/def.h"
// -----------------------------------------------------------------------------
// PyUpb_GenericSequence
@@ -54,19 +53,19 @@
typedef struct {
// Returns the number of elements in the map.
- int (*get_elem_count)(const void *parent);
+ int (*get_elem_count)(const void* parent);
// Returns an element by index.
- const void *(*index)(const void *parent, int idx);
+ const void* (*index)(const void* parent, int idx);
// Returns a Python object wrapping this element, caller owns a ref.
- PyObject *(*get_elem_wrapper)(const void *elem);
+ PyObject* (*get_elem_wrapper)(const void* elem);
} PyUpb_GenericSequence_Funcs;
// Returns a new GenericSequence. The vtable `funcs` must outlive this object
// (generally it should be static). The GenericSequence will take a ref on
// `parent_obj`, which must be sufficient to keep `parent` alive. The object
// `parent` will be passed as an argument to the functions in `funcs`.
-PyObject *PyUpb_GenericSequence_New(const PyUpb_GenericSequence_Funcs *funcs,
- const void *parent, PyObject *parent_obj);
+PyObject* PyUpb_GenericSequence_New(const PyUpb_GenericSequence_Funcs* funcs,
+ const void* parent, PyObject* parent_obj);
// -----------------------------------------------------------------------------
// PyUpb_ByNameMap
@@ -77,17 +76,17 @@
typedef struct {
PyUpb_GenericSequence_Funcs base;
// Looks up by name and returns either a pointer to the element or NULL.
- const void *(*lookup)(const void *parent, const char *key);
+ const void* (*lookup)(const void* parent, const char* key);
// Returns the name associated with this element.
- const char *(*get_elem_name)(const void *elem);
+ const char* (*get_elem_name)(const void* elem);
} PyUpb_ByNameMap_Funcs;
// Returns a new ByNameMap. The vtable `funcs` must outlive this object
// (generally it should be static). The ByNameMap will take a ref on
// `parent_obj`, which must be sufficient to keep `parent` alive. The object
// `parent` will be passed as an argument to the functions in `funcs`.
-PyObject *PyUpb_ByNameMap_New(const PyUpb_ByNameMap_Funcs *funcs,
- const void *parent, PyObject *parent_obj);
+PyObject* PyUpb_ByNameMap_New(const PyUpb_ByNameMap_Funcs* funcs,
+ const void* parent, PyObject* parent_obj);
// -----------------------------------------------------------------------------
// PyUpb_ByNumberMap
@@ -98,18 +97,18 @@
typedef struct {
PyUpb_GenericSequence_Funcs base;
// Looks up by name and returns either a pointer to the element or NULL.
- const void *(*lookup)(const void *parent, int num);
+ const void* (*lookup)(const void* parent, int num);
// Returns the name associated with this element.
- int (*get_elem_num)(const void *elem);
+ int (*get_elem_num)(const void* elem);
} PyUpb_ByNumberMap_Funcs;
// Returns a new ByNumberMap. The vtable `funcs` must outlive this object
// (generally it should be static). The ByNumberMap will take a ref on
// `parent_obj`, which must be sufficient to keep `parent` alive. The object
// `parent` will be passed as an argument to the functions in `funcs`.
-PyObject *PyUpb_ByNumberMap_New(const PyUpb_ByNumberMap_Funcs *funcs,
- const void *parent, PyObject *parent_obj);
+PyObject* PyUpb_ByNumberMap_New(const PyUpb_ByNumberMap_Funcs* funcs,
+ const void* parent, PyObject* parent_obj);
bool PyUpb_InitDescriptorContainers(PyObject* m);
-#endif // PYUPB_DESCRIPTOR_CONTAINERS_H__
+#endif // PYUPB_DESCRIPTOR_CONTAINERS_H__
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]);
diff --git a/python/descriptor_pool.h b/python/descriptor_pool.h
index 0bda5b1..41b7c3e 100644
--- a/python/descriptor_pool.h
+++ b/python/descriptor_pool.h
@@ -34,10 +34,10 @@
// Returns a Python wrapper object for the given symtab. The symtab must have
// been created from a Python DescriptorPool originally.
-PyObject* PyUpb_DescriptorPool_Get(const upb_symtab* symtab);
+PyObject* PyUpb_DescriptorPool_Get(const upb_DefPool* symtab);
// Given a Python DescriptorPool, returns the underlying symtab.
-upb_symtab* PyUpb_DescriptorPool_GetSymtab(PyObject* pool);
+upb_DefPool* PyUpb_DescriptorPool_GetSymtab(PyObject* pool);
// Returns the default DescriptorPool (a global singleton).
PyObject* PyUpb_DescriptorPool_GetDefaultPool(void);
diff --git a/python/extension_dict.c b/python/extension_dict.c
index 0d3da1e..277da0e 100644
--- a/python/extension_dict.c
+++ b/python/extension_dict.c
@@ -35,7 +35,7 @@
// -----------------------------------------------------------------------------
typedef struct {
- PyObject_HEAD
+ PyObject_HEAD;
PyObject* msg; // Owning ref to our parent pessage.
} PyUpb_ExtensionDict;
@@ -52,10 +52,10 @@
PyObject* key) {
PyUpb_ExtensionDict* self = (PyUpb_ExtensionDict*)_self;
const char* name = PyUpb_GetStrData(key);
- const upb_msgdef* m = PyUpb_CMessage_GetMsgdef(self->msg);
- const upb_filedef* file = upb_msgdef_file(m);
- const upb_symtab* symtab = upb_filedef_symtab(file);
- const upb_fielddef* ext = upb_symtab_lookupext(symtab, name);
+ const upb_MessageDef* m = PyUpb_CMessage_GetMsgdef(self->msg);
+ const upb_FileDef* file = upb_MessageDef_File(m);
+ const upb_DefPool* symtab = upb_FileDef_Pool(file);
+ const upb_FieldDef* ext = upb_DefPool_FindExtensionByName(symtab, name);
if (ext) {
return PyUpb_FieldDescriptor_Get(ext);
} else {
@@ -66,16 +66,16 @@
static PyObject* PyUpb_ExtensionDict_FindExtensionByNumber(PyObject* _self,
PyObject* arg) {
PyUpb_ExtensionDict* self = (PyUpb_ExtensionDict*)_self;
- const upb_msgdef* m = PyUpb_CMessage_GetMsgdef(self->msg);
- const upb_msglayout* l = upb_msgdef_layout(m);
- const upb_filedef* file = upb_msgdef_file(m);
- const upb_symtab* symtab = upb_filedef_symtab(file);
- const upb_extreg* reg = upb_symtab_extreg(symtab);
+ const upb_MessageDef* m = PyUpb_CMessage_GetMsgdef(self->msg);
+ const upb_MiniTable* l = upb_MessageDef_MiniTable(m);
+ const upb_FileDef* file = upb_MessageDef_File(m);
+ const upb_DefPool* symtab = upb_FileDef_Pool(file);
+ const upb_extreg* reg = upb_DefPool_ExtensionRegistry(symtab);
int64_t number = PyLong_AsLong(arg);
- const upb_msglayout_ext* ext =
- (upb_msglayout_ext*)_upb_extreg_get(reg, l, number);
+ const upb_MiniTable_Extension* ext =
+ (upb_MiniTable_Extension*)_upb_extreg_get(reg, l, number);
if (ext) {
- const upb_fielddef* f = _upb_symtab_lookupextfield(symtab, ext);
+ const upb_FieldDef* f = _upb_DefPool_FindExtensionByMiniTable(symtab, ext);
return PyUpb_FieldDescriptor_Get(f);
} else {
Py_RETURN_NONE;
@@ -90,15 +90,15 @@
static int PyUpb_ExtensionDict_Contains(PyObject* _self, PyObject* key) {
PyUpb_ExtensionDict* self = (PyUpb_ExtensionDict*)_self;
- const upb_fielddef* f = PyUpb_CMessage_GetExtensionDef(self->msg, key);
+ const upb_FieldDef* f = PyUpb_CMessage_GetExtensionDef(self->msg, key);
if (!f) return -1;
upb_msg* msg = PyUpb_CMessage_GetIfReified(self->msg);
if (!msg) return 0;
- if (upb_fielddef_isseq(f)) {
- upb_msgval val = upb_msg_get(msg, f);
- return upb_array_size(val.array_val) > 0;
+ if (upb_FieldDef_IsRepeated(f)) {
+ upb_MessageValue val = upb_Message_Get(msg, f);
+ return upb_Array_Size(val.array_val) > 0;
} else {
- return upb_msg_has(msg, f);
+ return upb_Message_Has(msg, f);
}
}
@@ -110,7 +110,7 @@
static PyObject* PyUpb_ExtensionDict_Subscript(PyObject* _self, PyObject* key) {
PyUpb_ExtensionDict* self = (PyUpb_ExtensionDict*)_self;
- const upb_fielddef* f = PyUpb_CMessage_GetExtensionDef(self->msg, key);
+ const upb_FieldDef* f = PyUpb_CMessage_GetExtensionDef(self->msg, key);
if (!f) return NULL;
return PyUpb_CMessage_GetFieldValue(self->msg, f);
}
@@ -118,7 +118,7 @@
static int PyUpb_ExtensionDict_AssignSubscript(PyObject* _self, PyObject* key,
PyObject* val) {
PyUpb_ExtensionDict* self = (PyUpb_ExtensionDict*)_self;
- const upb_fielddef* f = PyUpb_CMessage_GetExtensionDef(self->msg, key);
+ const upb_FieldDef* f = PyUpb_CMessage_GetExtensionDef(self->msg, key);
if (!f) return -1;
if (val) {
return PyUpb_CMessage_SetFieldValue(self->msg, f, val, PyExc_TypeError);
@@ -165,7 +165,7 @@
// -----------------------------------------------------------------------------
typedef struct {
- PyObject_HEAD
+ PyObject_HEAD;
PyObject* msg;
size_t iter;
} PyUpb_ExtensionIterator;
@@ -177,7 +177,7 @@
(void*)PyType_GenericAlloc(state->extension_iterator_type, 0);
if (!iter) return NULL;
iter->msg = ext_dict->msg;
- iter->iter = UPB_MSG_BEGIN;
+ iter->iter = kUpb_Message_Begin;
Py_INCREF(iter->msg);
return &iter->ob_base;
}
@@ -192,13 +192,13 @@
PyUpb_ExtensionIterator* self = (PyUpb_ExtensionIterator*)_self;
upb_msg* msg = PyUpb_CMessage_GetIfReified(self->msg);
if (!msg) return NULL;
- const upb_msgdef* m = PyUpb_CMessage_GetMsgdef(self->msg);
- const upb_symtab* symtab = upb_filedef_symtab(upb_msgdef_file(m));
+ const upb_MessageDef* m = PyUpb_CMessage_GetMsgdef(self->msg);
+ const upb_DefPool* symtab = upb_FileDef_Pool(upb_MessageDef_File(m));
while (true) {
- const upb_fielddef* f;
- upb_msgval val;
- if (!upb_msg_next(msg, m, symtab, &f, &val, &self->iter)) return NULL;
- if (upb_fielddef_isextension(f)) return PyUpb_FieldDescriptor_Get(f);
+ const upb_FieldDef* f;
+ upb_MessageValue val;
+ if (!upb_Message_Next(msg, m, symtab, &f, &val, &self->iter)) return NULL;
+ if (upb_FieldDef_IsExtension(f)) return PyUpb_FieldDescriptor_Get(f);
}
}
diff --git a/python/map.c b/python/map.c
index 5f233b5..35d3d32 100644
--- a/python/map.c
+++ b/python/map.c
@@ -36,16 +36,16 @@
// -----------------------------------------------------------------------------
typedef struct {
- PyObject_HEAD
+ PyObject_HEAD;
PyObject* arena;
- // The field descriptor (upb_fielddef*).
+ // The field descriptor (upb_FieldDef*).
// The low bit indicates whether the container is reified (see ptr below).
// - low bit set: repeated field is a stub (empty map, no underlying data).
- // - low bit clear: repeated field is reified (points to upb_array).
+ // - low bit clear: repeated field is reified (points to upb_Array).
uintptr_t field;
union {
PyObject* parent; // stub: owning pointer to parent message.
- upb_map* map; // reified: the data for this array.
+ upb_Map* map; // reified: the data for this array.
} ptr;
int version;
} PyUpb_MapContainer;
@@ -58,13 +58,13 @@
// If the map is reified, returns it. Otherwise, returns NULL.
// If NULL is returned, the object is empty and has no underlying data.
-static upb_map* PyUpb_MapContainer_GetIfReified(PyUpb_MapContainer* self) {
+static upb_Map* PyUpb_MapContainer_GetIfReified(PyUpb_MapContainer* self) {
return PyUpb_MapContainer_IsStub(self) ? NULL : self->ptr.map;
}
-static const upb_fielddef* PyUpb_MapContainer_GetField(
+static const upb_FieldDef* PyUpb_MapContainer_GetField(
PyUpb_MapContainer* self) {
- return (const upb_fielddef*)(self->field & ~(uintptr_t)1);
+ return (const upb_FieldDef*)(self->field & ~(uintptr_t)1);
}
static void PyUpb_MapContainer_Dealloc(void* _self) {
@@ -80,14 +80,14 @@
PyUpb_Dealloc(_self);
}
-PyTypeObject* PyUpb_MapContainer_GetClass(const upb_fielddef* f) {
- assert(upb_fielddef_ismap(f));
+PyTypeObject* PyUpb_MapContainer_GetClass(const upb_FieldDef* f) {
+ assert(upb_FieldDef_IsMap(f));
PyUpb_ModuleState* state = PyUpb_ModuleState_Get();
- return upb_fielddef_issubmsg(f) ? state->message_map_container_type
- : state->scalar_map_container_type;
+ return upb_FieldDef_IsSubMessage(f) ? state->message_map_container_type
+ : state->scalar_map_container_type;
}
-PyObject* PyUpb_MapContainer_NewStub(PyObject* parent, const upb_fielddef* f,
+PyObject* PyUpb_MapContainer_NewStub(PyObject* parent, const upb_FieldDef* f,
PyObject* arena) {
// We only create stubs when the parent is reified, by convention. However
// this is not an invariant: the parent could become reified at any time.
@@ -103,15 +103,16 @@
return &map->ob_base;
}
-void PyUpb_MapContainer_Reify(PyObject* _self, upb_map* map) {
+void PyUpb_MapContainer_Reify(PyObject* _self, upb_Map* map) {
PyUpb_MapContainer* self = (PyUpb_MapContainer*)_self;
if (!map) {
- const upb_fielddef* f = PyUpb_MapContainer_GetField(self);
- upb_arena* arena = PyUpb_Arena_Get(self->arena);
- const upb_msgdef* entry_m = upb_fielddef_msgsubdef(f);
- const upb_fielddef* key_f = upb_msgdef_field(entry_m, 0);
- const upb_fielddef* val_f = upb_msgdef_field(entry_m, 1);
- map = upb_map_new(arena, upb_fielddef_type(key_f), upb_fielddef_type(val_f));
+ const upb_FieldDef* f = PyUpb_MapContainer_GetField(self);
+ upb_Arena* arena = PyUpb_Arena_Get(self->arena);
+ const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(f);
+ const upb_FieldDef* key_f = upb_MessageDef_Field(entry_m, 0);
+ const upb_FieldDef* val_f = upb_MessageDef_Field(entry_m, 1);
+ map = upb_Map_New(arena, upb_FieldDef_CType(key_f),
+ upb_FieldDef_CType(val_f));
}
PyUpb_ObjCache_Add(map, &self->ob_base);
Py_DECREF(self->ptr.parent);
@@ -125,19 +126,20 @@
self->version++;
}
-upb_map* PyUpb_MapContainer_EnsureReified(PyObject* _self) {
+upb_Map* PyUpb_MapContainer_EnsureReified(PyObject* _self) {
PyUpb_MapContainer* self = (PyUpb_MapContainer*)_self;
self->version++;
- upb_map* map = PyUpb_MapContainer_GetIfReified(self);
+ upb_Map* map = PyUpb_MapContainer_GetIfReified(self);
if (map) return map; // Already writable.
- const upb_fielddef* f = PyUpb_MapContainer_GetField(self);
- upb_arena* arena = PyUpb_Arena_Get(self->arena);
- const upb_msgdef* entry_m = upb_fielddef_msgsubdef(f);
- const upb_fielddef* key_f = upb_msgdef_field(entry_m, 0);
- const upb_fielddef* val_f = upb_msgdef_field(entry_m, 1);
- map = upb_map_new(arena, upb_fielddef_type(key_f), upb_fielddef_type(val_f));
- upb_msgval msgval = {.map_val = map};
+ const upb_FieldDef* f = PyUpb_MapContainer_GetField(self);
+ upb_Arena* arena = PyUpb_Arena_Get(self->arena);
+ const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(f);
+ const upb_FieldDef* key_f = upb_MessageDef_Field(entry_m, 0);
+ const upb_FieldDef* val_f = upb_MessageDef_Field(entry_m, 1);
+ map =
+ upb_Map_New(arena, upb_FieldDef_CType(key_f), upb_FieldDef_CType(val_f));
+ upb_MessageValue msgval = {.map_val = map};
PyUpb_CMessage_SetConcreteSubobj(self->ptr.parent, f, msgval);
PyUpb_MapContainer_Reify((PyObject*)self, map);
return map;
@@ -146,20 +148,20 @@
int PyUpb_MapContainer_AssignSubscript(PyObject* _self, PyObject* key,
PyObject* val) {
PyUpb_MapContainer* self = (PyUpb_MapContainer*)_self;
- upb_map* map = PyUpb_MapContainer_EnsureReified(_self);
- const upb_fielddef* f = PyUpb_MapContainer_GetField(self);
- const upb_msgdef* entry_m = upb_fielddef_msgsubdef(f);
- const upb_fielddef* key_f = upb_msgdef_field(entry_m, 0);
- const upb_fielddef* val_f = upb_msgdef_field(entry_m, 1);
- upb_arena* arena = PyUpb_Arena_Get(self->arena);
- upb_msgval u_key, u_val;
+ upb_Map* map = PyUpb_MapContainer_EnsureReified(_self);
+ const upb_FieldDef* f = PyUpb_MapContainer_GetField(self);
+ const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(f);
+ const upb_FieldDef* key_f = upb_MessageDef_Field(entry_m, 0);
+ const upb_FieldDef* val_f = upb_MessageDef_Field(entry_m, 1);
+ upb_Arena* arena = PyUpb_Arena_Get(self->arena);
+ upb_MessageValue u_key, u_val;
if (!PyUpb_PyToUpb(key, key_f, &u_key, arena)) return -1;
if (val) {
if (!PyUpb_PyToUpb(val, val_f, &u_val, arena)) return -1;
- upb_map_set(map, u_key, u_val, arena);
+ upb_Map_Set(map, u_key, u_val, arena);
} else {
- if (!upb_map_delete(map, u_key)) {
+ if (!upb_Map_Delete(map, u_key)) {
PyErr_Format(PyExc_KeyError, "Key not present in map");
return -1;
}
@@ -169,37 +171,37 @@
PyObject* PyUpb_MapContainer_Subscript(PyObject* _self, PyObject* key) {
PyUpb_MapContainer* self = (PyUpb_MapContainer*)_self;
- upb_map* map = PyUpb_MapContainer_GetIfReified(self);
- const upb_fielddef* f = PyUpb_MapContainer_GetField(self);
- const upb_msgdef* entry_m = upb_fielddef_msgsubdef(f);
- const upb_fielddef* key_f = upb_msgdef_field(entry_m, 0);
- const upb_fielddef* val_f = upb_msgdef_field(entry_m, 1);
- upb_arena* arena = PyUpb_Arena_Get(self->arena);
- upb_msgval u_key, u_val;
+ upb_Map* map = PyUpb_MapContainer_GetIfReified(self);
+ const upb_FieldDef* f = PyUpb_MapContainer_GetField(self);
+ const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(f);
+ const upb_FieldDef* key_f = upb_MessageDef_Field(entry_m, 0);
+ const upb_FieldDef* val_f = upb_MessageDef_Field(entry_m, 1);
+ upb_Arena* arena = PyUpb_Arena_Get(self->arena);
+ upb_MessageValue u_key, u_val;
if (!PyUpb_PyToUpb(key, key_f, &u_key, arena)) return NULL;
- if (!map || !upb_map_get(map, u_key, &u_val)) {
+ if (!map || !upb_Map_Get(map, u_key, &u_val)) {
map = PyUpb_MapContainer_EnsureReified(_self);
- upb_arena* arena = PyUpb_Arena_Get(self->arena);
- if (upb_fielddef_issubmsg(val_f)) {
- u_val.msg_val = upb_msg_new(upb_fielddef_msgsubdef(val_f), arena);
+ upb_Arena* arena = PyUpb_Arena_Get(self->arena);
+ if (upb_FieldDef_IsSubMessage(val_f)) {
+ u_val.msg_val = upb_Message_New(upb_FieldDef_MessageSubDef(val_f), arena);
} else {
memset(&u_val, 0, sizeof(u_val));
}
- upb_map_set(map, u_key, u_val, arena);
+ upb_Map_Set(map, u_key, u_val, arena);
}
return PyUpb_UpbToPy(u_val, val_f, self->arena);
}
PyObject* PyUpb_MapContainer_Contains(PyObject* _self, PyObject* key) {
PyUpb_MapContainer* self = (PyUpb_MapContainer*)_self;
- upb_map* map = PyUpb_MapContainer_GetIfReified(self);
+ upb_Map* map = PyUpb_MapContainer_GetIfReified(self);
if (!map) Py_RETURN_FALSE;
- const upb_fielddef* f = PyUpb_MapContainer_GetField(self);
- const upb_msgdef* entry_m = upb_fielddef_msgsubdef(f);
- const upb_fielddef* key_f = upb_msgdef_field(entry_m, 0);
- upb_msgval u_key;
+ const upb_FieldDef* f = PyUpb_MapContainer_GetField(self);
+ const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(f);
+ const upb_FieldDef* key_f = upb_MessageDef_Field(entry_m, 0);
+ upb_MessageValue u_key;
if (!PyUpb_PyToUpb(key, key_f, &u_key, NULL)) return NULL;
- if (upb_map_get(map, u_key, NULL)) {
+ if (upb_Map_Get(map, u_key, NULL)) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
@@ -207,8 +209,8 @@
}
PyObject* PyUpb_MapContainer_Clear(PyObject* _self, PyObject* key) {
- upb_map* map = PyUpb_MapContainer_EnsureReified(_self);
- upb_map_clear(map);
+ upb_Map* map = PyUpb_MapContainer_EnsureReified(_self);
+ upb_Map_Clear(map);
Py_RETURN_NONE;
}
@@ -218,20 +220,20 @@
static const char* kwlist[] = {"key", "default", NULL};
PyObject* key;
PyObject* default_value = NULL;
- upb_map* map = PyUpb_MapContainer_GetIfReified(self);
+ upb_Map* map = PyUpb_MapContainer_GetIfReified(self);
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O", (char**)kwlist, &key,
&default_value)) {
return NULL;
}
- const upb_fielddef* f = PyUpb_MapContainer_GetField(self);
- const upb_msgdef* entry_m = upb_fielddef_msgsubdef(f);
- const upb_fielddef* key_f = upb_msgdef_field(entry_m, 0);
- const upb_fielddef* val_f = upb_msgdef_field(entry_m, 1);
- upb_arena* arena = PyUpb_Arena_Get(self->arena);
- upb_msgval u_key, u_val;
+ const upb_FieldDef* f = PyUpb_MapContainer_GetField(self);
+ const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(f);
+ const upb_FieldDef* key_f = upb_MessageDef_Field(entry_m, 0);
+ const upb_FieldDef* val_f = upb_MessageDef_Field(entry_m, 1);
+ upb_Arena* arena = PyUpb_Arena_Get(self->arena);
+ upb_MessageValue u_key, u_val;
if (!PyUpb_PyToUpb(key, key_f, &u_key, arena)) return NULL;
- if (map && upb_map_get(map, u_key, &u_val)) {
+ if (map && upb_Map_Get(map, u_key, &u_val)) {
return PyUpb_UpbToPy(u_val, val_f, self->arena);
}
if (default_value) {
@@ -244,15 +246,15 @@
static PyObject* PyUpb_MapContainer_GetEntryClass(PyObject* _self,
PyObject* arg) {
PyUpb_MapContainer* self = (PyUpb_MapContainer*)_self;
- const upb_fielddef* f = PyUpb_MapContainer_GetField(self);
- const upb_msgdef* entry_m = upb_fielddef_msgsubdef(f);
+ const upb_FieldDef* f = PyUpb_MapContainer_GetField(self);
+ const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(f);
return PyUpb_Descriptor_GetClass(entry_m);
}
Py_ssize_t PyUpb_MapContainer_Length(PyObject* _self) {
PyUpb_MapContainer* self = (PyUpb_MapContainer*)_self;
- upb_map* map = PyUpb_MapContainer_GetIfReified(self);
- return map ? upb_map_size(map) : 0;
+ upb_Map* map = PyUpb_MapContainer_GetIfReified(self);
+ return map ? upb_Map_Size(map) : 0;
}
PyUpb_MapContainer* PyUpb_MapContainer_Check(PyObject* _self) {
@@ -266,11 +268,11 @@
}
int PyUpb_CMessage_InitMapAttributes(PyObject* map, PyObject* value,
- const upb_fielddef* f);
+ const upb_FieldDef* f);
static PyObject* PyUpb_MapContainer_MergeFrom(PyObject* _self, PyObject* _arg) {
PyUpb_MapContainer* self = (PyUpb_MapContainer*)_self;
- const upb_fielddef* f = PyUpb_MapContainer_GetField(self);
+ const upb_FieldDef* f = PyUpb_MapContainer_GetField(self);
if (PyDict_Check(_arg)) {
return PyErr_Format(PyExc_AttributeError, "Merging of dict is not allowed");
@@ -285,19 +287,19 @@
static PyObject* PyUpb_MapContainer_Repr(PyObject* _self) {
PyUpb_MapContainer* self = (PyUpb_MapContainer*)_self;
- upb_map* map = PyUpb_MapContainer_GetIfReified(self);
+ upb_Map* map = PyUpb_MapContainer_GetIfReified(self);
PyObject* dict = PyDict_New();
if (map) {
- const upb_fielddef* f = PyUpb_MapContainer_GetField(self);
- const upb_msgdef* entry_m = upb_fielddef_msgsubdef(f);
- const upb_fielddef* key_f = upb_msgdef_field(entry_m, 0);
- const upb_fielddef* val_f = upb_msgdef_field(entry_m, 1);
- size_t iter = UPB_MAP_BEGIN;
- while (upb_mapiter_next(map, &iter)) {
+ const upb_FieldDef* f = PyUpb_MapContainer_GetField(self);
+ const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(f);
+ const upb_FieldDef* key_f = upb_MessageDef_Field(entry_m, 0);
+ const upb_FieldDef* val_f = upb_MessageDef_Field(entry_m, 1);
+ size_t iter = kUpb_Map_Begin;
+ while (upb_MapIterator_Next(map, &iter)) {
PyObject* key =
- PyUpb_UpbToPy(upb_mapiter_key(map, iter), key_f, self->arena);
+ PyUpb_UpbToPy(upb_MapIterator_Key(map, iter), key_f, self->arena);
PyObject* val =
- PyUpb_UpbToPy(upb_mapiter_value(map, iter), val_f, self->arena);
+ PyUpb_UpbToPy(upb_MapIterator_Value(map, iter), val_f, self->arena);
if (!key || !val) {
Py_XDECREF(key);
Py_XDECREF(val);
@@ -314,8 +316,8 @@
return repr;
}
-PyObject* PyUpb_MapContainer_GetOrCreateWrapper(upb_map* map,
- const upb_fielddef* f,
+PyObject* PyUpb_MapContainer_GetOrCreateWrapper(upb_Map* map,
+ const upb_FieldDef* f,
PyObject* arena) {
PyUpb_MapContainer* ret = (void*)PyUpb_ObjCache_Get(map);
if (ret) return &ret->ob_base;
@@ -421,7 +423,7 @@
// -----------------------------------------------------------------------------
typedef struct {
- PyObject_HEAD
+ PyObject_HEAD;
PyUpb_MapContainer* map; // We own a reference.
size_t iter;
int version;
@@ -432,7 +434,7 @@
PyUpb_MapIterator* iter =
(void*)PyType_GenericAlloc(state->map_iterator_type, 0);
iter->map = map;
- iter->iter = UPB_MAP_BEGIN;
+ iter->iter = kUpb_Map_Begin;
iter->version = map->version;
Py_INCREF(map);
return &iter->ob_base;
@@ -449,13 +451,13 @@
if (self->version != self->map->version) {
return PyErr_Format(PyExc_RuntimeError, "Map modified during iteration.");
}
- upb_map* map = PyUpb_MapContainer_GetIfReified(self->map);
+ upb_Map* map = PyUpb_MapContainer_GetIfReified(self->map);
if (!map) return NULL;
- if (!upb_mapiter_next(map, &self->iter)) return NULL;
- upb_msgval key = upb_mapiter_key(map, self->iter);
- const upb_fielddef* f = PyUpb_MapContainer_GetField(self->map);
- const upb_msgdef* entry_m = upb_fielddef_msgsubdef(f);
- const upb_fielddef* key_f = upb_msgdef_field(entry_m, 0);
+ if (!upb_MapIterator_Next(map, &self->iter)) return NULL;
+ upb_MessageValue key = upb_MapIterator_Key(map, self->iter);
+ const upb_FieldDef* f = PyUpb_MapContainer_GetField(self->map);
+ const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(f);
+ const upb_FieldDef* key_f = upb_MessageDef_Field(entry_m, 0);
return PyUpb_UpbToPy(key, key_f, self->map->arena);
}
diff --git a/python/map.h b/python/map.h
index 9f6f969..0c03ed0 100644
--- a/python/map.h
+++ b/python/map.h
@@ -35,23 +35,23 @@
// Creates a new repeated field stub for field `f` of message object `parent`.
// Precondition: `parent` must be a stub.
-PyObject* PyUpb_MapContainer_NewStub(PyObject* parent, const upb_fielddef* f,
+PyObject* PyUpb_MapContainer_NewStub(PyObject* parent, const upb_FieldDef* f,
PyObject* arena);
// Returns a map object wrapping `map`, of field type `f`, which must be on
// `arena`. If an existing wrapper object exists, it will be returned,
// otherwise a new object will be created. The caller always owns a ref on the
// returned value.
-PyObject* PyUpb_MapContainer_GetOrCreateWrapper(upb_map* map,
- const upb_fielddef* f,
+PyObject* PyUpb_MapContainer_GetOrCreateWrapper(upb_Map* map,
+ const upb_FieldDef* f,
PyObject* arena);
// Reifies a map stub to point to the concrete data in `map`.
// If `map` is NULL, an appropriate empty map will be constructed.
-void PyUpb_MapContainer_Reify(PyObject* self, upb_map* map);
+void PyUpb_MapContainer_Reify(PyObject* self, upb_Map* map);
// Reifies this map object if it is not already reified.
-upb_map* PyUpb_MapContainer_EnsureReified(PyObject* self);
+upb_Map* PyUpb_MapContainer_EnsureReified(PyObject* self);
// Assigns `self[key] = val` for the map `self`.
int PyUpb_MapContainer_AssignSubscript(PyObject* self, PyObject* key,
diff --git a/python/message.c b/python/message.c
index 08cba55..7ef2f92 100644
--- a/python/message.c
+++ b/python/message.c
@@ -37,7 +37,7 @@
#include "upb/text_encode.h"
#include "upb/util/required_fields.h"
-static const upb_msgdef* PyUpb_MessageMeta_GetMsgdef(PyObject* cls);
+static const upb_MessageDef* PyUpb_MessageMeta_GetMsgdef(PyObject* cls);
static PyObject* PyUpb_MessageMeta_GetAttr(PyObject* self, PyObject* name);
// -----------------------------------------------------------------------------
@@ -63,7 +63,7 @@
// the version of Python we were compiled against, which may be different
// than the version we are dynamically linked against. Here we want the
// version that is actually running in this process.
- long python_version_hex; // PY_VERSION_HEX
+ long python_version_hex; // PY_VERSION_HEX
} PyUpb_CPythonBits;
// A global containing the values for this process.
@@ -151,9 +151,9 @@
// The parent may also be non-present, in which case a mutation will trigger a
// chain reaction.
typedef struct PyUpb_CMessage {
- PyObject_HEAD
+ PyObject_HEAD;
PyObject* arena;
- uintptr_t def; // Tagged, low bit 1 == upb_fielddef*, else upb_msgdef*
+ uintptr_t def; // Tagged, low bit 1 == upb_FieldDef*, else upb_MessageDef*
union {
// when def is msgdef, the data for this msg.
upb_msg* msg;
@@ -170,18 +170,18 @@
bool PyUpb_CMessage_IsStub(PyUpb_CMessage* msg) { return msg->def & 1; }
-const upb_fielddef* PyUpb_CMessage_GetFieldDef(PyUpb_CMessage* msg) {
+const upb_FieldDef* PyUpb_CMessage_GetFieldDef(PyUpb_CMessage* msg) {
assert(PyUpb_CMessage_IsStub(msg));
return (void*)(msg->def & ~(uintptr_t)1);
}
-static const upb_msgdef* _PyUpb_CMessage_GetMsgdef(PyUpb_CMessage* msg) {
+static const upb_MessageDef* _PyUpb_CMessage_GetMsgdef(PyUpb_CMessage* msg) {
return PyUpb_CMessage_IsStub(msg)
- ? upb_fielddef_msgsubdef(PyUpb_CMessage_GetFieldDef(msg))
+ ? upb_FieldDef_MessageSubDef(PyUpb_CMessage_GetFieldDef(msg))
: (void*)msg->def;
}
-const upb_msgdef* PyUpb_CMessage_GetMsgdef(PyObject* self) {
+const upb_MessageDef* PyUpb_CMessage_GetMsgdef(PyObject* self) {
return _PyUpb_CMessage_GetMsgdef((PyUpb_CMessage*)self);
}
@@ -214,11 +214,11 @@
static PyObject* PyUpb_CMessage_New(PyObject* cls, PyObject* unused_args,
PyObject* unused_kwargs) {
- const upb_msgdef* msgdef = PyUpb_MessageMeta_GetMsgdef(cls);
+ const upb_MessageDef* msgdef = PyUpb_MessageMeta_GetMsgdef(cls);
PyUpb_CMessage* msg = (void*)PyType_GenericAlloc((PyTypeObject*)cls, 0);
msg->def = (uintptr_t)msgdef;
msg->arena = PyUpb_Arena_New();
- msg->ptr.msg = upb_msg_new(msgdef, PyUpb_Arena_Get(msg->arena));
+ msg->ptr.msg = upb_Message_New(msgdef, PyUpb_Arena_Get(msg->arena));
msg->unset_subobj_map = NULL;
msg->ext_dict = NULL;
msg->version = 0;
@@ -238,8 +238,8 @@
* and sets an exception of type `exc_type` if provided.
*/
static bool PyUpb_CMessage_LookupName(PyUpb_CMessage* self, PyObject* py_name,
- const upb_fielddef** f,
- const upb_oneofdef** o,
+ const upb_FieldDef** f,
+ const upb_OneofDef** o,
PyObject* exc_type) {
assert(f || o);
Py_ssize_t size;
@@ -250,13 +250,12 @@
PyBytes_AsStringAndSize(py_name, (char**)&name, &size);
}
if (!name) return NULL;
- const upb_msgdef* msgdef = _PyUpb_CMessage_GetMsgdef(self);
+ const upb_MessageDef* msgdef = _PyUpb_CMessage_GetMsgdef(self);
- if (!upb_msgdef_lookupname(msgdef, name, size, f, o)) {
+ if (!upb_MessageDef_FindByNameWithSize(msgdef, name, size, f, o)) {
if (exc_type) {
- PyErr_Format(exc_type,
- "Protocol message %s has no \"%s\" field.",
- upb_msgdef_name(msgdef), name);
+ PyErr_Format(exc_type, "Protocol message %s has no \"%s\" field.",
+ upb_MessageDef_Name(msgdef), name);
}
return false;
}
@@ -296,17 +295,17 @@
}
int PyUpb_CMessage_InitMapAttributes(PyObject* map, PyObject* value,
- const upb_fielddef* f) {
- const upb_msgdef* entry_m = upb_fielddef_msgsubdef(f);
- const upb_fielddef* val_f = upb_msgdef_field(entry_m, 1);
+ const upb_FieldDef* f) {
+ const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(f);
+ const upb_FieldDef* val_f = upb_MessageDef_Field(entry_m, 1);
PyObject* it = NULL;
PyObject* tmp = NULL;
int ret = -1;
- if (upb_fielddef_issubmsg(val_f)) {
+ if (upb_FieldDef_IsSubMessage(val_f)) {
it = PyObject_GetIter(value);
if (it == NULL) {
PyErr_Format(PyExc_TypeError, "Argument for field %s is not iterable",
- upb_fielddef_fullname(f));
+ upb_FieldDef_FullName(f));
goto err;
}
PyObject* e;
@@ -334,7 +333,7 @@
void PyUpb_CMessage_EnsureReified(PyUpb_CMessage* self);
static bool PyUpb_CMessage_InitMapAttribute(PyObject* _self, PyObject* name,
- const upb_fielddef* f,
+ const upb_FieldDef* f,
PyObject* value) {
PyObject* map = PyUpb_CMessage_GetAttr(_self, name);
int ok = PyUpb_CMessage_InitMapAttributes(map, value, f);
@@ -366,9 +365,9 @@
assert(!PyErr_Occurred());
ok = PyUpb_CMessage_InitAttributes(submsg, NULL, value) >= 0;
} else {
- const upb_msgdef* m = PyUpb_CMessage_GetMsgdef(_self);
+ const upb_MessageDef* m = PyUpb_CMessage_GetMsgdef(_self);
PyErr_Format(PyExc_TypeError, "Message must be initialized with a dict: %s",
- upb_msgdef_fullname(m));
+ upb_MessageDef_FullName(m));
ok = false;
}
Py_DECREF(submsg);
@@ -376,13 +375,13 @@
}
static bool PyUpb_CMessage_InitScalarAttribute(upb_msg* msg,
- const upb_fielddef* f,
+ const upb_FieldDef* f,
PyObject* value,
- upb_arena* arena) {
- upb_msgval msgval;
+ upb_Arena* arena) {
+ upb_MessageValue msgval;
assert(!PyErr_Occurred());
if (!PyUpb_PyToUpb(value, f, &msgval, arena)) return false;
- upb_msg_set(msg, f, msgval, arena);
+ upb_Message_Set(msg, f, msgval, arena);
return true;
}
@@ -403,11 +402,11 @@
PyObject* value;
PyUpb_CMessage_EnsureReified(self);
upb_msg* msg = PyUpb_CMessage_GetMsg(self);
- upb_arena* arena = PyUpb_Arena_Get(self->arena);
+ upb_Arena* arena = PyUpb_Arena_Get(self->arena);
while (PyDict_Next(kwargs, &pos, &name, &value)) {
assert(!PyErr_Occurred());
- const upb_fielddef* f;
+ const upb_FieldDef* f;
assert(!PyErr_Occurred());
if (!PyUpb_CMessage_LookupName(self, name, &f, NULL, PyExc_ValueError)) {
return -1;
@@ -417,11 +416,11 @@
assert(!PyErr_Occurred());
- if (upb_fielddef_ismap(f)) {
+ if (upb_FieldDef_IsMap(f)) {
if (!PyUpb_CMessage_InitMapAttribute(_self, name, f, value)) return -1;
- } else if (upb_fielddef_isseq(f)) {
+ } else if (upb_FieldDef_IsRepeated(f)) {
if (!PyUpb_CMessage_InitRepeatedAttribute(_self, name, value)) return -1;
- } else if (upb_fielddef_issubmsg(f)) {
+ } else if (upb_FieldDef_IsSubMessage(f)) {
if (!PyUpb_CMessage_InitMessageAttribute(_self, name, value)) return -1;
} else {
if (!PyUpb_CMessage_InitScalarAttribute(msg, f, value, arena)) return -1;
@@ -443,9 +442,9 @@
return PyUpb_CMessage_InitAttributes(_self, args, kwargs);
}
-static PyObject* PyUpb_CMessage_NewStub(PyObject* parent, const upb_fielddef* f,
+static PyObject* PyUpb_CMessage_NewStub(PyObject* parent, const upb_FieldDef* f,
PyObject* arena) {
- const upb_msgdef* sub_m = upb_fielddef_msgsubdef(f);
+ const upb_MessageDef* sub_m = upb_FieldDef_MessageSubDef(f);
PyObject* cls = PyUpb_Descriptor_GetClass(sub_m);
PyUpb_CMessage* msg = (void*)PyType_GenericAlloc((PyTypeObject*)cls, 0);
@@ -468,9 +467,9 @@
if (!PyObject_TypeCheck(_m2, m1->ob_base.ob_type)) {
return false;
}
- const upb_msgdef* m1_msgdef = _PyUpb_CMessage_GetMsgdef(m1);
+ const upb_MessageDef* m1_msgdef = _PyUpb_CMessage_GetMsgdef(m1);
#ifndef NDEBUG
- const upb_msgdef* m2_msgdef = _PyUpb_CMessage_GetMsgdef(m2);
+ const upb_MessageDef* m2_msgdef = _PyUpb_CMessage_GetMsgdef(m2);
assert(m1_msgdef == m2_msgdef);
#endif
const upb_msg* m1_msg = PyUpb_CMessage_GetIfReified((PyObject*)m1);
@@ -478,20 +477,20 @@
return PyUpb_Message_IsEqual(m1_msg, m2_msg, m1_msgdef);
}
-static const upb_fielddef* PyUpb_CMessage_InitAsMsg(PyUpb_CMessage* m,
- upb_arena* arena) {
- const upb_fielddef* f = PyUpb_CMessage_GetFieldDef(m);
- m->ptr.msg = upb_msg_new(upb_fielddef_msgsubdef(f), arena);
- m->def = (uintptr_t)upb_fielddef_msgsubdef(f);
+static const upb_FieldDef* PyUpb_CMessage_InitAsMsg(PyUpb_CMessage* m,
+ upb_Arena* arena) {
+ const upb_FieldDef* f = PyUpb_CMessage_GetFieldDef(m);
+ m->ptr.msg = upb_Message_New(upb_FieldDef_MessageSubDef(f), arena);
+ m->def = (uintptr_t)upb_FieldDef_MessageSubDef(f);
PyUpb_ObjCache_Add(m->ptr.msg, &m->ob_base);
return f;
}
static void PyUpb_CMessage_SetField(PyUpb_CMessage* parent,
- const upb_fielddef* f,
- PyUpb_CMessage* child, upb_arena* arena) {
- upb_msgval msgval = {.msg_val = PyUpb_CMessage_GetMsg(child)};
- upb_msg_set(PyUpb_CMessage_GetMsg(parent), f, msgval, arena);
+ const upb_FieldDef* f,
+ PyUpb_CMessage* child, upb_Arena* arena) {
+ upb_MessageValue msgval = {.msg_val = PyUpb_CMessage_GetMsg(child)};
+ upb_Message_Set(PyUpb_CMessage_GetMsg(parent), f, msgval, arena);
PyUpb_WeakMap_Delete(parent->unset_subobj_map, f);
// Releases a ref previously owned by child->ptr.parent of our child.
Py_DECREF(child);
@@ -517,18 +516,18 @@
*/
void PyUpb_CMessage_EnsureReified(PyUpb_CMessage* self) {
if (!PyUpb_CMessage_IsStub(self)) return;
- upb_arena* arena = PyUpb_Arena_Get(self->arena);
+ upb_Arena* arena = PyUpb_Arena_Get(self->arena);
// This is a non-present message. We need to create a real upb_msg for this
// object and every parent until we reach a present message.
PyUpb_CMessage* child = self;
PyUpb_CMessage* parent = self->ptr.parent;
- const upb_fielddef* child_f = PyUpb_CMessage_InitAsMsg(child, arena);
+ const upb_FieldDef* child_f = PyUpb_CMessage_InitAsMsg(child, arena);
Py_INCREF(child); // To avoid a special-case in PyUpb_CMessage_SetField().
do {
PyUpb_CMessage* next_parent = parent->ptr.parent;
- const upb_fielddef* parent_f = NULL;
+ const upb_FieldDef* parent_f = NULL;
if (PyUpb_CMessage_IsStub(parent)) {
parent_f = PyUpb_CMessage_InitAsMsg(parent, arena);
}
@@ -549,20 +548,20 @@
* PyUpb_CMessage_Reify()
*
* The message equivalent of PyUpb_*Container_Reify(), this transitions
- * the wrapper from the unset state (owning a reference on self->ptr.parent) to the
- * set state (having a non-owning pointer to self->ptr.msg).
+ * the wrapper from the unset state (owning a reference on self->ptr.parent) to
+ * the set state (having a non-owning pointer to self->ptr.msg).
*/
-static void PyUpb_CMessage_Reify(PyUpb_CMessage* self, const upb_fielddef* f,
+static void PyUpb_CMessage_Reify(PyUpb_CMessage* self, const upb_FieldDef* f,
upb_msg* msg) {
assert(f == PyUpb_CMessage_GetFieldDef(self));
if (!msg) {
- const upb_msgdef* msgdef = PyUpb_CMessage_GetMsgdef((PyObject*)self);
- msg = upb_msg_new(msgdef, PyUpb_Arena_Get(self->arena));
+ const upb_MessageDef* msgdef = PyUpb_CMessage_GetMsgdef((PyObject*)self);
+ msg = upb_Message_New(msgdef, PyUpb_Arena_Get(self->arena));
}
PyUpb_ObjCache_Add(msg, &self->ob_base);
Py_DECREF(&self->ptr.parent->ob_base);
self->ptr.msg = msg; // Overwrites self->ptr.parent
- self->def = (uintptr_t)upb_fielddef_msgsubdef(f);
+ self->def = (uintptr_t)upb_FieldDef_MessageSubDef(f);
PyUpb_CMessage_SyncSubobjs(self);
}
@@ -580,7 +579,7 @@
* # SyncSubobjs() is required to connect our existing 'sub' wrapper to the
* # newly created foo.submsg data in C.
* foo.MergeFrom(FooMessage(submsg={}))
- *
+ *
* This requires that all of the new sub-objects that have appeared are owned
* by `self`'s arena.
*/
@@ -601,16 +600,16 @@
Py_INCREF(&self->ob_base);
while (PyUpb_WeakMap_Next(subobj_map, &key, &obj, &iter)) {
- const upb_fielddef* f = key;
- if (upb_fielddef_haspresence(f) && !upb_msg_has(msg, f)) continue;
- upb_msgval msgval = upb_msg_get(msg, f);
+ const upb_FieldDef* f = key;
+ if (upb_FieldDef_HasPresence(f) && !upb_Message_Has(msg, f)) continue;
+ upb_MessageValue msgval = upb_Message_Get(msg, f);
PyUpb_WeakMap_DeleteIter(subobj_map, &iter);
- if (upb_fielddef_ismap(f)) {
+ if (upb_FieldDef_IsMap(f)) {
if (!msgval.map_val) continue;
- PyUpb_MapContainer_Reify(obj, (upb_map*)msgval.map_val);
- } else if (upb_fielddef_isseq(f)) {
+ PyUpb_MapContainer_Reify(obj, (upb_Map*)msgval.map_val);
+ } else if (upb_FieldDef_IsRepeated(f)) {
if (!msgval.array_val) continue;
- PyUpb_RepeatedContainer_Reify(obj, (upb_array*)msgval.array_val);
+ PyUpb_RepeatedContainer_Reify(obj, (upb_Array*)msgval.array_val);
} else {
PyUpb_CMessage* sub = (void*)obj;
assert(self == sub->ptr.parent);
@@ -629,8 +628,8 @@
return PyUnicode_FromStringAndSize(NULL, 0);
}
upb_msg* msg = PyUpb_CMessage_GetMsg(self);
- const upb_msgdef* msgdef = _PyUpb_CMessage_GetMsgdef(self);
- const upb_symtab* symtab = upb_filedef_symtab(upb_msgdef_file(msgdef));
+ const upb_MessageDef* msgdef = _PyUpb_CMessage_GetMsgdef(self);
+ const upb_DefPool* symtab = upb_FileDef_Pool(upb_MessageDef_File(msgdef));
char buf[1024];
int options = UPB_TXTENC_SKIPUNKNOWN;
size_t size = upb_text_encode(msg, msgdef, symtab, options, buf, sizeof(buf));
@@ -659,17 +658,17 @@
return PyBool_FromLong(ret);
}
-void PyUpb_CMessage_CacheDelete(PyObject* _self, const upb_fielddef* f) {
+void PyUpb_CMessage_CacheDelete(PyObject* _self, const upb_FieldDef* f) {
PyUpb_CMessage* self = (void*)_self;
PyUpb_WeakMap_Delete(self->unset_subobj_map, f);
}
-void PyUpb_CMessage_SetConcreteSubobj(PyObject* _self, const upb_fielddef* f,
- upb_msgval subobj) {
+void PyUpb_CMessage_SetConcreteSubobj(PyObject* _self, const upb_FieldDef* f,
+ upb_MessageValue subobj) {
PyUpb_CMessage* self = (void*)_self;
PyUpb_CMessage_EnsureReified(self);
PyUpb_CMessage_CacheDelete(_self, f);
- upb_msg_set(self->ptr.msg, f, subobj, PyUpb_Arena_Get(self->arena));
+ upb_Message_Set(self->ptr.msg, f, subobj, PyUpb_Arena_Get(self->arena));
}
static void PyUpb_CMessage_Dealloc(PyObject* _self) {
@@ -702,7 +701,7 @@
}
}
-PyObject* PyUpb_CMessage_Get(upb_msg* u_msg, const upb_msgdef* m,
+PyObject* PyUpb_CMessage_Get(upb_msg* u_msg, const upb_MessageDef* m,
PyObject* arena) {
PyObject* ret = PyUpb_ObjCache_Get(u_msg);
if (ret) return ret;
@@ -728,15 +727,15 @@
*
* Non-present messages return "stub" objects that point to their parent, but
* will materialize into real upb objects if they are mutated.
- *
+ *
* Note: we do *not* create stubs for repeated/map fields unless the parent
* is a stub:
- *
+ *
* msg = TestMessage()
* msg.submessage # (A) Creates a stub
* msg.repeated_foo # (B) Does *not* create a stub
* msg.submessage.repeated_bar # (C) Creates a stub
- *
+ *
* In case (B) we have some freedom: we could either create a stub, or create
* a reified object with underlying data. It appears that either could work
* equally well, with no observable change to users. There isn't a clear
@@ -746,7 +745,7 @@
* within the realm of possibility.
*/
PyObject* PyUpb_CMessage_GetStub(PyUpb_CMessage* self,
- const upb_fielddef* field) {
+ const upb_FieldDef* field) {
PyObject* _self = (void*)self;
if (!self->unset_subobj_map) {
self->unset_subobj_map = PyUpb_WeakMap_New();
@@ -755,9 +754,9 @@
if (subobj) return subobj;
- if (upb_fielddef_ismap(field)) {
+ if (upb_FieldDef_IsMap(field)) {
subobj = PyUpb_MapContainer_NewStub(_self, field, self->arena);
- } else if (upb_fielddef_isseq(field)) {
+ } else if (upb_FieldDef_IsRepeated(field)) {
subobj = PyUpb_RepeatedContainer_NewStub(_self, field, self->arena);
} else {
subobj = PyUpb_CMessage_NewStub(&self->ob_base, field, self->arena);
@@ -769,11 +768,11 @@
}
PyObject* PyUpb_CMessage_GetPresentWrapper(PyUpb_CMessage* self,
- const upb_fielddef* field) {
+ const upb_FieldDef* field) {
assert(!PyUpb_CMessage_IsStub(self));
- upb_mutmsgval mutval =
- upb_msg_mutable(self->ptr.msg, field, PyUpb_Arena_Get(self->arena));
- if (upb_fielddef_ismap(field)) {
+ upb_MutableMessageValue mutval =
+ upb_Message_Mutable(self->ptr.msg, field, PyUpb_Arena_Get(self->arena));
+ if (upb_FieldDef_IsMap(field)) {
return PyUpb_MapContainer_GetOrCreateWrapper(mutval.map, field,
self->arena);
} else {
@@ -783,13 +782,13 @@
}
PyObject* PyUpb_CMessage_GetScalarValue(PyUpb_CMessage* self,
- const upb_fielddef* field) {
- upb_msgval val;
+ const upb_FieldDef* field) {
+ upb_MessageValue val;
if (PyUpb_CMessage_IsStub(self)) {
// Unset message always returns default values.
- val = upb_fielddef_default(field);
+ val = upb_FieldDef_Default(field);
} else {
- val = upb_msg_get(self->ptr.msg, field);
+ val = upb_Message_Get(self->ptr.msg, field);
}
return PyUpb_UpbToPy(val, field, self->arena);
}
@@ -798,7 +797,7 @@
* PyUpb_CMessage_GetFieldValue()
*
* Implements the equivalent of getattr(msg, field), once `field` has
- * already been resolved to a `upb_fielddef*`.
+ * already been resolved to a `upb_FieldDef*`.
*
* This may involve constructing a wrapper object for the given field, or
* returning one that was previously constructed. If the field is not actually
@@ -806,14 +805,14 @@
* connected to any C data.
*/
PyObject* PyUpb_CMessage_GetFieldValue(PyObject* _self,
- const upb_fielddef* field) {
+ const upb_FieldDef* field) {
PyUpb_CMessage* self = (void*)_self;
- assert(upb_fielddef_containingtype(field) == PyUpb_CMessage_GetMsgdef(_self));
- bool submsg = upb_fielddef_issubmsg(field);
- bool seq = upb_fielddef_isseq(field);
+ assert(upb_FieldDef_ContainingType(field) == PyUpb_CMessage_GetMsgdef(_self));
+ bool submsg = upb_FieldDef_IsSubMessage(field);
+ bool seq = upb_FieldDef_IsRepeated(field);
if ((PyUpb_CMessage_IsStub(self) && (submsg || seq)) ||
- (submsg && !seq && !upb_msg_has(self->ptr.msg, field))) {
+ (submsg && !seq && !upb_Message_Has(self->ptr.msg, field))) {
return PyUpb_CMessage_GetStub(self, field);
} else if (seq) {
return PyUpb_CMessage_GetPresentWrapper(self, field);
@@ -822,28 +821,28 @@
}
}
-int PyUpb_CMessage_SetFieldValue(PyObject* _self, const upb_fielddef* field,
+int PyUpb_CMessage_SetFieldValue(PyObject* _self, const upb_FieldDef* field,
PyObject* value, PyObject* exc) {
PyUpb_CMessage* self = (void*)_self;
assert(value);
- if (upb_fielddef_issubmsg(field) || upb_fielddef_isseq(field)) {
+ if (upb_FieldDef_IsSubMessage(field) || upb_FieldDef_IsRepeated(field)) {
PyErr_Format(exc,
"Assignment not allowed to message, map, or repeated "
"field \"%s\" in protocol message object.",
- upb_fielddef_name(field));
+ upb_FieldDef_Name(field));
return -1;
}
PyUpb_CMessage_EnsureReified(self);
- upb_msgval val;
- upb_arena* arena = PyUpb_Arena_Get(self->arena);
+ upb_MessageValue val;
+ upb_Arena* arena = PyUpb_Arena_Get(self->arena);
if (!PyUpb_PyToUpb(value, field, &val, arena)) {
return -1;
}
- upb_msg_set(self->ptr.msg, field, val, arena);
+ upb_Message_Set(self->ptr.msg, field, val, arena);
return 0;
}
@@ -866,7 +865,7 @@
PyUpb_CMessage* self = (void*)_self;
// Lookup field by name.
- const upb_fielddef* field;
+ const upb_FieldDef* field;
if (PyUpb_CMessage_LookupName(self, attr, &field, NULL, NULL)) {
return PyUpb_CMessage_GetFieldValue(_self, field);
}
@@ -898,34 +897,36 @@
static int PyUpb_CMessage_SetAttr(PyObject* _self, PyObject* attr,
PyObject* value) {
PyUpb_CMessage* self = (void*)_self;
- const upb_fielddef* field;
+ const upb_FieldDef* field;
if (!PyUpb_CMessage_LookupName(self, attr, &field, NULL,
PyExc_AttributeError)) {
return -1;
}
- return PyUpb_CMessage_SetFieldValue(_self, field, value, PyExc_AttributeError);
+ return PyUpb_CMessage_SetFieldValue(_self, field, value,
+ PyExc_AttributeError);
}
static PyObject* PyUpb_CMessage_HasField(PyObject* _self, PyObject* arg) {
PyUpb_CMessage* self = (void*)_self;
- const upb_fielddef* field;
- const upb_oneofdef* oneof;
+ const upb_FieldDef* field;
+ const upb_OneofDef* oneof;
if (!PyUpb_CMessage_LookupName(self, arg, &field, &oneof, PyExc_ValueError)) {
return NULL;
}
- if (field && !upb_fielddef_haspresence(field)) {
+ if (field && !upb_FieldDef_HasPresence(field)) {
PyErr_Format(PyExc_ValueError, "Field %s does not have presence.",
- upb_fielddef_fullname(field));
+ upb_FieldDef_FullName(field));
return NULL;
}
if (PyUpb_CMessage_IsStub(self)) Py_RETURN_FALSE;
- return PyBool_FromLong(field ? upb_msg_has(self->ptr.msg, field)
- : upb_msg_whichoneof(self->ptr.msg, oneof) != NULL);
+ return PyBool_FromLong(field ? upb_Message_Has(self->ptr.msg, field)
+ : upb_Message_WhichOneof(self->ptr.msg, oneof) !=
+ NULL);
}
static PyObject* PyUpb_CMessage_FindInitializationErrors(PyObject* _self,
@@ -963,8 +964,8 @@
} else {
// We just need to return a boolean "true" or "false" for whether all
// required fields are set.
- const upb_msgdef* m = PyUpb_CMessage_GetMsgdef(_self);
- const upb_symtab* symtab = upb_filedef_symtab(upb_msgdef_file(m));
+ const upb_MessageDef* m = PyUpb_CMessage_GetMsgdef(_self);
+ const upb_DefPool* symtab = upb_FileDef_Pool(upb_MessageDef_File(m));
bool initialized = !upb_util_HasUnsetRequired(msg, m, symtab, NULL);
return PyBool_FromLong(initialized);
}
@@ -974,8 +975,8 @@
PyObject* val) {
assert(PyTuple_Check(val));
PyObject* field = PyTuple_GetItem(val, 0);
- const upb_fielddef* f = PyUpb_FieldDescriptor_GetDef(field);
- return PyLong_FromLong(upb_fielddef_number(f));
+ const upb_FieldDef* f = PyUpb_FieldDescriptor_GetDef(field);
+ return PyLong_FromLong(upb_FieldDef_Number(f));
}
static bool PyUpb_CMessage_SortFieldList(PyObject* list) {
@@ -993,7 +994,7 @@
if (!call_result) goto err;
ok = true;
- err:
+err:
Py_XDECREF(method);
Py_XDECREF(args);
Py_XDECREF(kwargs);
@@ -1006,18 +1007,18 @@
upb_msg* msg = PyUpb_CMessage_GetIfReified(_self);
if (!msg) return list;
- size_t iter1 = UPB_MSG_BEGIN;
- const upb_msgdef* m = PyUpb_CMessage_GetMsgdef(_self);
- const upb_symtab* symtab = upb_filedef_symtab(upb_msgdef_file(m));
- const upb_fielddef* f;
+ size_t iter1 = kUpb_Message_Begin;
+ const upb_MessageDef* m = PyUpb_CMessage_GetMsgdef(_self);
+ const upb_DefPool* symtab = upb_FileDef_Pool(upb_MessageDef_File(m));
+ const upb_FieldDef* f;
PyObject* field_desc = NULL;
PyObject* py_val = NULL;
PyObject* tuple = NULL;
- upb_msgval val;
+ upb_MessageValue val;
uint32_t last_field = 0;
bool in_order = true;
- while (upb_msg_next(msg, m, symtab, &f, &val, &iter1)) {
- const uint32_t field_number = upb_fielddef_number(f);
+ while (upb_Message_Next(msg, m, symtab, &f, &val, &iter1)) {
+ const uint32_t field_number = upb_FieldDef_Number(f);
if (field_number < last_field) in_order = false;
last_field = field_number;
PyObject* field_desc = PyUpb_FieldDescriptor_Get(f);
@@ -1094,11 +1095,12 @@
}
PyUpb_CMessage_EnsureReified(self);
- const upb_msgdef* msgdef = _PyUpb_CMessage_GetMsgdef(self);
- const upb_filedef* file = upb_msgdef_file(msgdef);
- const upb_extreg* extreg = upb_symtab_extreg(upb_filedef_symtab(file));
- const upb_msglayout* layout = upb_msgdef_layout(msgdef);
- upb_arena* arena = PyUpb_Arena_Get(self->arena);
+ const upb_MessageDef* msgdef = _PyUpb_CMessage_GetMsgdef(self);
+ const upb_FileDef* file = upb_MessageDef_File(msgdef);
+ const upb_extreg* extreg =
+ upb_DefPool_ExtensionRegistry(upb_FileDef_Pool(file));
+ const upb_MiniTable* layout = upb_MessageDef_MiniTable(msgdef);
+ upb_Arena* arena = PyUpb_Arena_Get(self->arena);
PyUpb_ModuleState* state = PyUpb_ModuleState_Get();
int options =
UPB_DECODE_MAXDEPTH(state->allow_oversize_protos ? UINT32_MAX : 100);
@@ -1136,7 +1138,7 @@
static PyObject* PyUpb_CMessage_Clear(PyUpb_CMessage* self, PyObject* args) {
PyUpb_CMessage_EnsureReified(self);
- const upb_msgdef* msgdef = _PyUpb_CMessage_GetMsgdef(self);
+ const upb_MessageDef* msgdef = _PyUpb_CMessage_GetMsgdef(self);
PyUpb_WeakMap* subobj_map = self->unset_subobj_map;
if (subobj_map) {
@@ -1146,16 +1148,16 @@
PyObject* obj;
while (PyUpb_WeakMap_Next(subobj_map, &key, &obj, &iter)) {
- const upb_fielddef* f = key;
+ const upb_FieldDef* f = key;
PyUpb_WeakMap_DeleteIter(subobj_map, &iter);
- if (upb_fielddef_ismap(f)) {
- assert(upb_msg_get(msg, f).map_val == NULL);
+ if (upb_FieldDef_IsMap(f)) {
+ assert(upb_Message_Get(msg, f).map_val == NULL);
PyUpb_MapContainer_Reify(obj, NULL);
- } else if (upb_fielddef_isseq(f)) {
- assert(upb_msg_get(msg, f).array_val == NULL);
+ } else if (upb_FieldDef_IsRepeated(f)) {
+ assert(upb_Message_Get(msg, f).array_val == NULL);
PyUpb_RepeatedContainer_Reify(obj, NULL);
} else {
- assert(!upb_msg_has(msg, f));
+ assert(!upb_Message_Has(msg, f));
PyUpb_CMessage* sub = (void*)obj;
assert(self == sub->ptr.parent);
PyUpb_CMessage_Reify(sub, f, NULL);
@@ -1163,11 +1165,11 @@
}
}
- upb_msg_clear(self->ptr.msg, msgdef);
+ upb_Message_Clear(self->ptr.msg, msgdef);
Py_RETURN_NONE;
}
-void PyUpb_CMessage_DoClearField(PyObject* _self, const upb_fielddef* f) {
+void PyUpb_CMessage_DoClearField(PyObject* _self, const upb_FieldDef* f) {
PyUpb_CMessage* self = (void*)_self;
PyUpb_CMessage_EnsureReified((PyUpb_CMessage*)self);
@@ -1177,7 +1179,7 @@
? PyUpb_WeakMap_Get(self->unset_subobj_map, f)
: NULL;
- if (upb_fielddef_ismap(f)) {
+ if (upb_FieldDef_IsMap(f)) {
// For maps we additionally have to invalidate any iterators. So we need
// to get an object even if it's reified.
if (!sub) {
@@ -1185,24 +1187,24 @@
}
PyUpb_MapContainer_EnsureReified(sub);
PyUpb_MapContainer_Invalidate(sub);
- } else if (upb_fielddef_isseq(f)) {
+ } else if (upb_FieldDef_IsRepeated(f)) {
if (sub) {
PyUpb_RepeatedContainer_EnsureReified(sub);
}
- } else if (upb_fielddef_issubmsg(f)) {
+ } else if (upb_FieldDef_IsSubMessage(f)) {
if (sub) {
PyUpb_CMessage_EnsureReified((PyUpb_CMessage*)sub);
}
}
Py_XDECREF(sub);
- upb_msg_clearfield(self->ptr.msg, f);
+ upb_Message_ClearField(self->ptr.msg, f);
}
static PyObject* PyUpb_CMessage_ClearExtension(PyObject* _self, PyObject* arg) {
PyUpb_CMessage* self = (void*)_self;
PyUpb_CMessage_EnsureReified(self);
- const upb_fielddef* f = PyUpb_CMessage_GetExtensionDef(_self, arg);
+ const upb_FieldDef* f = PyUpb_CMessage_GetExtensionDef(_self, arg);
if (!f) return NULL;
PyUpb_CMessage_DoClearField(_self, f);
Py_RETURN_NONE;
@@ -1218,13 +1220,13 @@
// assert msg.HasField("foo")
PyUpb_CMessage_EnsureReified(self);
- const upb_fielddef* f;
- const upb_oneofdef* o;
+ const upb_FieldDef* f;
+ const upb_OneofDef* o;
if (!PyUpb_CMessage_LookupName(self, arg, &f, &o, PyExc_ValueError)) {
return NULL;
}
- if (o) f = upb_msg_whichoneof(self->ptr.msg, o);
+ if (o) f = upb_Message_WhichOneof(self->ptr.msg, o);
PyUpb_CMessage_DoClearField(_self, f);
Py_RETURN_NONE;
}
@@ -1232,8 +1234,8 @@
static PyObject* PyUpb_CMessage_DiscardUnknownFields(PyUpb_CMessage* self,
PyObject* arg) {
PyUpb_CMessage_EnsureReified(self);
- const upb_msgdef* msgdef = _PyUpb_CMessage_GetMsgdef(self);
- upb_msg_discardunknown(self->ptr.msg, msgdef, 64);
+ const upb_MessageDef* msgdef = _PyUpb_CMessage_GetMsgdef(self);
+ upb_Message_DiscardUnknown(self->ptr.msg, msgdef, 64);
Py_RETURN_NONE;
}
@@ -1241,8 +1243,8 @@
PyObject* arg) {
PyUpb_CMessage* self = (void*)_self;
upb_msg* msg = PyUpb_CMessage_GetIfReified(_self);
- const upb_msgdef* msgdef = _PyUpb_CMessage_GetMsgdef(self);
- const upb_symtab* ext_pool = upb_filedef_symtab(upb_msgdef_file(msgdef));
+ const upb_MessageDef* msgdef = _PyUpb_CMessage_GetMsgdef(self);
+ const upb_DefPool* ext_pool = upb_FileDef_Pool(upb_MessageDef_File(msgdef));
upb_FieldPathEntry* fields;
PyObject* ret = PyList_New(0);
if (upb_util_HasUnsetRequired(msg, msgdef, ext_pool, &fields)) {
@@ -1287,43 +1289,43 @@
goto done;
}
-const upb_fielddef* PyUpb_CMessage_GetExtensionDef(PyObject* _self, PyObject* key) {
- const upb_fielddef* f = PyUpb_FieldDescriptor_GetDef(key);
+const upb_FieldDef* PyUpb_CMessage_GetExtensionDef(PyObject* _self,
+ PyObject* key) {
+ const upb_FieldDef* f = PyUpb_FieldDescriptor_GetDef(key);
if (!f) {
PyErr_Clear();
PyErr_Format(PyExc_KeyError, "Object %R is not a field descriptor\n", key);
return NULL;
}
- if (!upb_fielddef_isextension(f)) {
+ if (!upb_FieldDef_IsExtension(f)) {
PyErr_Format(PyExc_KeyError, "Field %s is not an extension\n",
- upb_fielddef_fullname(f));
+ upb_FieldDef_FullName(f));
return NULL;
}
- const upb_msgdef* msgdef = PyUpb_CMessage_GetMsgdef(_self);
- if (upb_fielddef_containingtype(f) != msgdef) {
+ const upb_MessageDef* msgdef = PyUpb_CMessage_GetMsgdef(_self);
+ if (upb_FieldDef_ContainingType(f) != msgdef) {
PyErr_Format(PyExc_KeyError, "Extension doesn't match (%s vs %s)",
- upb_msgdef_fullname(msgdef), upb_fielddef_fullname(f));
+ upb_MessageDef_FullName(msgdef), upb_FieldDef_FullName(f));
return NULL;
}
return f;
}
-
static PyObject* PyUpb_CMessage_HasExtension(PyObject* _self,
PyObject* ext_desc) {
upb_msg* msg = PyUpb_CMessage_GetIfReified(_self);
- const upb_fielddef* f = PyUpb_CMessage_GetExtensionDef(_self, ext_desc);
+ const upb_FieldDef* f = PyUpb_CMessage_GetExtensionDef(_self, ext_desc);
if (!f) return NULL;
- if (upb_fielddef_isseq(f)) {
+ if (upb_FieldDef_IsRepeated(f)) {
PyErr_SetString(PyExc_KeyError,
"Field is repeated. A singular method is required.");
return NULL;
}
if (!msg) Py_RETURN_FALSE;
- return PyBool_FromLong(upb_msg_has(msg, f));
+ return PyBool_FromLong(upb_Message_Has(msg, f));
}
-void PyUpb_CMessage_ReportInitializationErrors(const upb_msgdef* msgdef,
+void PyUpb_CMessage_ReportInitializationErrors(const upb_MessageDef* msgdef,
PyObject* errors,
PyObject* exc) {
PyObject* comma = PyUnicode_FromString(",");
@@ -1332,7 +1334,7 @@
missing_fields = PyUnicode_Join(comma, errors);
if (!missing_fields) goto done;
PyErr_Format(exc, "Message %s is missing required fields: %U",
- upb_msgdef_fullname(msgdef), missing_fields);
+ upb_MessageDef_FullName(msgdef), missing_fields);
done:
Py_XDECREF(comma);
Py_XDECREF(missing_fields);
@@ -1351,7 +1353,7 @@
return NULL;
}
- const upb_msgdef* msgdef = _PyUpb_CMessage_GetMsgdef(self);
+ const upb_MessageDef* msgdef = _PyUpb_CMessage_GetMsgdef(self);
if (PyUpb_CMessage_IsStub(self)) {
// Nothing to serialize, but we do have to check whether the message is
// initialized.
@@ -1367,14 +1369,14 @@
return NULL;
}
- upb_arena* arena = upb_arena_new();
- const upb_msglayout* layout = upb_msgdef_layout(msgdef);
+ upb_Arena* arena = upb_Arena_New();
+ const upb_MiniTable* layout = upb_MessageDef_MiniTable(msgdef);
size_t size = 0;
// Python does not currently have any effective limit on serialization depth.
int options = UPB_ENCODE_MAXDEPTH(UINT32_MAX);
- if (check_required) options |= UPB_ENCODE_CHECKREQUIRED;
- if (deterministic) options |= UPB_ENCODE_DETERMINISTIC;
- char* pb = upb_encode_ex(self->ptr.msg, layout, options, arena, &size);
+ if (check_required) options |= kUpb_Encode_CheckRequired;
+ if (deterministic) options |= kUpb_Encode_Deterministic;
+ char* pb = upb_EncodeEx(self->ptr.msg, layout, options, arena, &size);
PyObject* ret = NULL;
if (!pb) {
@@ -1392,7 +1394,7 @@
ret = PyBytes_FromStringAndSize(pb, size);
done:
- upb_arena_free(arena);
+ upb_Arena_Free(arena);
return ret;
}
@@ -1409,15 +1411,15 @@
static PyObject* PyUpb_CMessage_WhichOneof(PyObject* _self, PyObject* name) {
PyUpb_CMessage* self = (void*)_self;
- const upb_oneofdef* o;
+ const upb_OneofDef* o;
if (!PyUpb_CMessage_LookupName(self, name, NULL, &o, PyExc_ValueError)) {
return NULL;
}
upb_msg* msg = PyUpb_CMessage_GetIfReified(_self);
if (!msg) Py_RETURN_NONE;
- const upb_fielddef* f = upb_msg_whichoneof(msg, o);
+ const upb_FieldDef* f = upb_Message_WhichOneof(msg, o);
if (!f) Py_RETURN_NONE;
- return PyUnicode_FromString(upb_fielddef_name(f));
+ return PyUnicode_FromString(upb_FieldDef_Name(f));
}
void PyUpb_CMessage_ClearExtensionDict(PyObject* _self) {
@@ -1433,8 +1435,8 @@
return self->ext_dict;
}
- const upb_msgdef* m = _PyUpb_CMessage_GetMsgdef(self);
- if (upb_msgdef_extrangecount(m) == 0) {
+ const upb_MessageDef* m = _PyUpb_CMessage_GetMsgdef(self);
+ if (upb_MessageDef_ExtensionRangeCount(m) == 0) {
PyErr_SetNone(PyExc_AttributeError);
return NULL;
}
@@ -1544,7 +1546,7 @@
// to simplify this, so that the illustration above is indeed accurate).
typedef struct {
- const upb_msglayout* layout;
+ const upb_MiniTable* layout;
PyObject* py_message_descriptor;
} PyUpb_MessageMeta;
@@ -1559,7 +1561,7 @@
return (PyUpb_MessageMeta*)((char*)cls + cpython_bits.type_basicsize);
}
-static const upb_msgdef* PyUpb_MessageMeta_GetMsgdef(PyObject* cls) {
+static const upb_MessageDef* PyUpb_MessageMeta_GetMsgdef(PyObject* cls) {
PyUpb_MessageMeta* self = PyUpb_GetMessageMeta(cls);
return PyUpb_Descriptor_GetDef(self->py_message_descriptor);
}
@@ -1572,9 +1574,9 @@
return PyErr_Format(PyExc_TypeError, "Expected a message Descriptor");
}
- const upb_msgdef* msgdef = PyUpb_Descriptor_GetDef(py_descriptor);
+ const upb_MessageDef* msgdef = PyUpb_Descriptor_GetDef(py_descriptor);
assert(msgdef);
- assert(!PyUpb_ObjCache_Get(upb_msgdef_layout(msgdef)));
+ assert(!PyUpb_ObjCache_Get(upb_MessageDef_MiniTable(msgdef)));
PyObject* slots = PyTuple_New(0);
if (PyDict_SetItemString(dict, "__slots__", slots) < 0) {
@@ -1586,7 +1588,7 @@
// (CMessage, Message, WktBase) # For well-known types
PyObject* wkt_bases = PyUpb_GetWktBases(state);
PyObject* wkt_base =
- PyDict_GetItemString(wkt_bases, upb_msgdef_fullname(msgdef));
+ PyDict_GetItemString(wkt_bases, upb_MessageDef_FullName(msgdef));
PyObject* args;
if (wkt_base == NULL) {
args = Py_BuildValue("s(OO)O", name, state->cmessage_type,
@@ -1602,10 +1604,10 @@
PyUpb_MessageMeta* meta = PyUpb_GetMessageMeta(ret);
meta->py_message_descriptor = py_descriptor;
- meta->layout = upb_msgdef_layout(msgdef);
+ meta->layout = upb_MessageDef_MiniTable(msgdef);
Py_INCREF(meta->py_message_descriptor);
- PyUpb_ObjCache_Add(upb_msgdef_layout(msgdef), ret);
+ PyUpb_ObjCache_Add(upb_MessageDef_MiniTable(msgdef), ret);
return ret;
}
@@ -1641,8 +1643,8 @@
return NULL;
}
- const upb_msgdef* m = PyUpb_Descriptor_GetDef(py_descriptor);
- PyObject* ret = PyUpb_ObjCache_Get(upb_msgdef_layout(m));
+ const upb_MessageDef* m = PyUpb_Descriptor_GetDef(py_descriptor);
+ PyObject* ret = PyUpb_ObjCache_Get(upb_MessageDef_MiniTable(m));
if (ret) return ret;
return PyUpb_MessageMeta_DoCreateClass(py_descriptor, name, dict);
}
@@ -1654,11 +1656,11 @@
PyUpb_Dealloc(self);
}
-void PyUpb_MessageMeta_AddFieldNumber(PyObject* self, const upb_fielddef* f) {
+void PyUpb_MessageMeta_AddFieldNumber(PyObject* self, const upb_FieldDef* f) {
PyObject* name =
- PyUnicode_FromFormat("%s_FIELD_NUMBER", upb_fielddef_name(f));
+ PyUnicode_FromFormat("%s_FIELD_NUMBER", upb_FieldDef_Name(f));
PyObject* upper = PyObject_CallMethod(name, "upper", "");
- PyObject_SetAttr(self, upper, PyLong_FromLong(upb_fielddef_number(f)));
+ PyObject_SetAttr(self, upper, PyLong_FromLong(upb_FieldDef_Number(f)));
Py_DECREF(name);
Py_DECREF(upper);
}
@@ -1666,48 +1668,49 @@
static PyObject* PyUpb_MessageMeta_GetDynamicAttr(PyObject* self,
PyObject* name) {
const char* name_buf = PyUpb_GetStrData(name);
- const upb_msgdef* msgdef = PyUpb_MessageMeta_GetMsgdef(self);
- const upb_filedef* filedef = upb_msgdef_file(msgdef);
- const upb_symtab* symtab = upb_filedef_symtab(filedef);
+ const upb_MessageDef* msgdef = PyUpb_MessageMeta_GetMsgdef(self);
+ const upb_FileDef* filedef = upb_MessageDef_File(msgdef);
+ const upb_DefPool* symtab = upb_FileDef_Pool(filedef);
PyObject* py_key =
- PyBytes_FromFormat("%s.%s", upb_msgdef_fullname(msgdef), name_buf);
+ PyBytes_FromFormat("%s.%s", upb_MessageDef_FullName(msgdef), name_buf);
const char* key = PyUpb_GetStrData(py_key);
PyObject* ret = NULL;
- const upb_msgdef* nested = upb_symtab_lookupmsg(symtab, key);
- const upb_enumdef* enumdef;
- const upb_enumvaldef* enumval;
- const upb_fielddef* ext;
+ const upb_MessageDef* nested = upb_DefPool_FindMessageByName(symtab, key);
+ const upb_EnumDef* enumdef;
+ const upb_EnumValueDef* enumval;
+ const upb_FieldDef* ext;
if (nested) {
ret = PyUpb_Descriptor_GetClass(nested);
- } else if ((enumdef = upb_symtab_lookupenum(symtab, key))) {
+ } else if ((enumdef = upb_DefPool_FindEnumByName(symtab, key))) {
PyUpb_ModuleState* state = PyUpb_ModuleState_Get();
PyObject* klass = state->enum_type_wrapper_class;
ret = PyUpb_EnumDescriptor_Get(enumdef);
ret = PyObject_CallFunctionObjArgs(klass, ret, NULL);
- } else if ((enumval = upb_symtab_lookupenumval(symtab, key))) {
- ret = PyLong_FromLong(upb_enumvaldef_number(enumval));
- } else if ((ext = upb_symtab_lookupext(symtab, key))) {
+ } else if ((enumval = upb_DefPool_FindEnumByNameval(symtab, key))) {
+ ret = PyLong_FromLong(upb_EnumValueDef_Number(enumval));
+ } else if ((ext = upb_DefPool_FindExtensionByName(symtab, key))) {
ret = PyUpb_FieldDescriptor_Get(ext);
}
Py_DECREF(py_key);
- const char* suffix = "_FIELD_NUMBER";
+ const char* suffix = "_FIELD_NUMBER";
size_t n = strlen(name_buf);
size_t suffix_n = strlen(suffix);
if (n > suffix_n && memcmp(suffix, name_buf + n - suffix_n, suffix_n) == 0) {
// We can't look up field names dynamically, because the <NAME>_FIELD_NUMBER
// naming scheme upper-cases the field name and is therefore non-reversible.
// So we just add all field numbers.
- int n = upb_msgdef_fieldcount(msgdef);
+ int n = upb_MessageDef_FieldCount(msgdef);
for (int i = 0; i < n; i++) {
- PyUpb_MessageMeta_AddFieldNumber(self, upb_msgdef_field(msgdef, i));
+ PyUpb_MessageMeta_AddFieldNumber(self, upb_MessageDef_Field(msgdef, i));
}
- n = upb_msgdef_nestedextcount(msgdef);
+ n = upb_MessageDef_NestedExtensionCount(msgdef);
for (int i = 0; i < n; i++) {
- PyUpb_MessageMeta_AddFieldNumber(self, upb_msgdef_nestedext(msgdef, i));
+ PyUpb_MessageMeta_AddFieldNumber(
+ self, upb_MessageDef_NestedExtension(msgdef, i));
}
ret = PyObject_GenericGetAttr(self, name);
}
@@ -1772,8 +1775,8 @@
if (!state->cmessage_type || !state->message_meta_type) return false;
if (PyModule_AddObject(m, "MessageMeta", message_meta_type)) return false;
- state->listfields_item_key =
- PyObject_GetAttrString((PyObject*)state->cmessage_type, "_ListFieldsItemKey");
+ state->listfields_item_key = PyObject_GetAttrString(
+ (PyObject*)state->cmessage_type, "_ListFieldsItemKey");
PyObject* mod = PyImport_ImportModule("google.protobuf.message");
if (mod == NULL) return false;
diff --git a/python/message.h b/python/message.h
index 1f88b8d..6049726 100644
--- a/python/message.h
+++ b/python/message.h
@@ -34,18 +34,18 @@
#include "upb/reflection.h"
// Removes the wrapper object for this field from the unset subobject cache.
-void PyUpb_CMessage_CacheDelete(PyObject* _self, const upb_fielddef* f);
+void PyUpb_CMessage_CacheDelete(PyObject* _self, const upb_FieldDef* f);
// Sets the field value for `f` to `subobj`, evicting the wrapper object from
// the "unset subobject" cache now that real data exists for it. The caller
// must also update the wrapper associated with `f` to point to `subobj` also.
-void PyUpb_CMessage_SetConcreteSubobj(PyObject* _self, const upb_fielddef* f,
- upb_msgval subobj);
+void PyUpb_CMessage_SetConcreteSubobj(PyObject* _self, const upb_FieldDef* f,
+ upb_MessageValue subobj);
// Gets a Python wrapper object for message `u_msg` of type `m`, returning a
// cached wrapper if one was previously created. If a new object is created,
// it will reference `arena`, which must own `u_msg`.
-PyObject* PyUpb_CMessage_Get(upb_msg* u_msg, const upb_msgdef* m,
+PyObject* PyUpb_CMessage_Get(upb_msg* u_msg, const upb_MessageDef* m,
PyObject* arena);
// Verifies that a Python object is a message. Sets a TypeError exception and
@@ -56,8 +56,8 @@
// Otherwise returns NULL.
upb_msg* PyUpb_CMessage_GetIfReified(PyObject* _self);
-// Returns the `upb_msgdef` for a given CMessage.
-const upb_msgdef* PyUpb_CMessage_GetMsgdef(PyObject* self);
+// Returns the `upb_MessageDef` for a given CMessage.
+const upb_MessageDef* PyUpb_CMessage_GetMsgdef(PyObject* self);
// Functions that match the corresponding methods on the message object.
PyObject* PyUpb_CMessage_MergeFrom(PyObject* self, PyObject* arg);
@@ -71,24 +71,24 @@
// Checks that `key` is a field descriptor for an extension type, and that the
// extendee is this message. Otherwise returns NULL and sets a KeyError.
-const upb_fielddef* PyUpb_CMessage_GetExtensionDef(PyObject* _self,
+const upb_FieldDef* PyUpb_CMessage_GetExtensionDef(PyObject* _self,
PyObject* key);
// Clears the given field in this message.
-void PyUpb_CMessage_DoClearField(PyObject* _self, const upb_fielddef* f);
+void PyUpb_CMessage_DoClearField(PyObject* _self, const upb_FieldDef* f);
// Clears the ExtensionDict from the message. The message must have an
// ExtensionDict set.
void PyUpb_CMessage_ClearExtensionDict(PyObject* _self);
// Implements the equivalent of getattr(msg, field), once `field` has
-// already been resolved to a `upb_fielddef*`.
+// already been resolved to a `upb_FieldDef*`.
PyObject* PyUpb_CMessage_GetFieldValue(PyObject* _self,
- const upb_fielddef* field);
+ const upb_FieldDef* field);
// Implements the equivalent of setattr(msg, field, value), once `field` has
-// already been resolved to a `upb_fielddef*`.
-int PyUpb_CMessage_SetFieldValue(PyObject* _self, const upb_fielddef* field,
+// already been resolved to a `upb_FieldDef*`.
+int PyUpb_CMessage_SetFieldValue(PyObject* _self, const upb_FieldDef* field,
PyObject* value, PyObject* exc);
// Returns the version associated with this message. The version will be
diff --git a/python/protobuf.c b/python/protobuf.c
index 0e3fb7f..af0777e 100644
--- a/python/protobuf.c
+++ b/python/protobuf.c
@@ -35,11 +35,11 @@
#include "python/message.h"
#include "python/repeated.h"
-static void PyUpb_ModuleDealloc(void *module) {
- PyUpb_ModuleState *s = PyModule_GetState(module);
+static void PyUpb_ModuleDealloc(void* module) {
+ PyUpb_ModuleState* s = PyModule_GetState(module);
PyUpb_WeakMap_Free(s->obj_cache);
if (s->c_descriptor_symtab) {
- upb_symtab_free(s->c_descriptor_symtab);
+ upb_DefPool_Free(s->c_descriptor_symtab);
}
}
@@ -65,9 +65,9 @@
"Protobuf Module",
sizeof(PyUpb_ModuleState),
PyUpb_ModuleMethods, // m_methods
- NULL, // m_slots
- NULL, // m_traverse
- NULL, // m_clear
+ NULL, // m_slots
+ NULL, // m_traverse
+ NULL, // m_clear
PyUpb_ModuleDealloc};
// -----------------------------------------------------------------------------
@@ -79,22 +79,22 @@
return module ? PyModule_GetState(module) : NULL;
}
-PyUpb_ModuleState *PyUpb_ModuleState_GetFromModule(PyObject *module) {
- PyUpb_ModuleState *state = PyModule_GetState(module);
+PyUpb_ModuleState* PyUpb_ModuleState_GetFromModule(PyObject* module) {
+ PyUpb_ModuleState* state = PyModule_GetState(module);
assert(state);
assert(PyModule_GetDef(module) == &module_def);
return state;
}
-PyUpb_ModuleState *PyUpb_ModuleState_Get(void) {
- PyObject *module = PyState_FindModule(&module_def);
+PyUpb_ModuleState* PyUpb_ModuleState_Get(void) {
+ PyObject* module = PyState_FindModule(&module_def);
assert(module);
return PyUpb_ModuleState_GetFromModule(module);
}
-PyObject *PyUpb_GetWktBases(PyUpb_ModuleState *state) {
+PyObject* PyUpb_GetWktBases(PyUpb_ModuleState* state) {
if (!state->wkt_bases) {
- PyObject *wkt_module =
+ PyObject* wkt_module =
PyImport_ImportModule("google.protobuf.internal.well_known_types");
if (wkt_module == NULL) {
@@ -102,7 +102,7 @@
}
state->wkt_bases = PyObject_GetAttrString(wkt_module, "WKTBASES");
- PyObject *m = PyState_FindModule(&module_def);
+ PyObject* m = PyState_FindModule(&module_def);
// Reparent ownership to m.
PyModule_AddObject(m, "__internal_wktbases", state->wkt_bases);
Py_DECREF(wkt_module);
@@ -117,33 +117,31 @@
struct PyUpb_WeakMap {
upb_inttable table;
- upb_arena *arena;
+ upb_Arena* arena;
};
-PyUpb_WeakMap *PyUpb_WeakMap_New(void) {
- upb_arena *arena = upb_arena_new();
- PyUpb_WeakMap *map = upb_arena_malloc(arena, sizeof(*map));
+PyUpb_WeakMap* PyUpb_WeakMap_New(void) {
+ upb_Arena* arena = upb_Arena_New();
+ PyUpb_WeakMap* map = upb_Arena_Malloc(arena, sizeof(*map));
map->arena = arena;
upb_inttable_init(&map->table, map->arena);
return map;
}
-void PyUpb_WeakMap_Free(PyUpb_WeakMap *map) {
- upb_arena_free(map->arena);
-}
+void PyUpb_WeakMap_Free(PyUpb_WeakMap* map) { upb_Arena_Free(map->arena); }
-uintptr_t PyUpb_WeakMap_GetKey(const void *key) {
+uintptr_t PyUpb_WeakMap_GetKey(const void* key) {
uintptr_t n = (uintptr_t)key;
assert((n & 7) == 0);
return n >> 3;
}
-void PyUpb_WeakMap_Add(PyUpb_WeakMap *map, const void *key, PyObject *py_obj) {
+void PyUpb_WeakMap_Add(PyUpb_WeakMap* map, const void* key, PyObject* py_obj) {
upb_inttable_insert(&map->table, PyUpb_WeakMap_GetKey(key),
upb_value_ptr(py_obj), map->arena);
}
-void PyUpb_WeakMap_Delete(PyUpb_WeakMap *map, const void *key) {
+void PyUpb_WeakMap_Delete(PyUpb_WeakMap* map, const void* key) {
upb_value val;
bool removed =
upb_inttable_remove(&map->table, PyUpb_WeakMap_GetKey(key), &val);
@@ -151,14 +149,14 @@
assert(removed);
}
-void PyUpb_WeakMap_TryDelete(PyUpb_WeakMap *map, const void *key) {
+void PyUpb_WeakMap_TryDelete(PyUpb_WeakMap* map, const void* key) {
upb_inttable_remove(&map->table, PyUpb_WeakMap_GetKey(key), NULL);
}
-PyObject *PyUpb_WeakMap_Get(PyUpb_WeakMap *map, const void *key) {
+PyObject* PyUpb_WeakMap_Get(PyUpb_WeakMap* map, const void* key) {
upb_value val;
if (upb_inttable_lookup(&map->table, PyUpb_WeakMap_GetKey(key), &val)) {
- PyObject *ret = upb_value_getptr(val);
+ PyObject* ret = upb_value_getptr(val);
Py_INCREF(ret);
return ret;
} else {
@@ -166,17 +164,17 @@
}
}
-bool PyUpb_WeakMap_Next(PyUpb_WeakMap *map, const void **key, PyObject **obj,
- intptr_t *iter) {
+bool PyUpb_WeakMap_Next(PyUpb_WeakMap* map, const void** key, PyObject** obj,
+ intptr_t* iter) {
uintptr_t u_key;
upb_value val;
if (!upb_inttable_next2(&map->table, &u_key, &val, iter)) return false;
- *key = (void *)(u_key << 3);
+ *key = (void*)(u_key << 3);
*obj = upb_value_getptr(val);
return true;
}
-void PyUpb_WeakMap_DeleteIter(PyUpb_WeakMap *map, intptr_t *iter) {
+void PyUpb_WeakMap_DeleteIter(PyUpb_WeakMap* map, intptr_t* iter) {
upb_inttable_removeiter(&map->table, iter);
}
@@ -184,17 +182,17 @@
// ObjCache
// -----------------------------------------------------------------------------
-PyUpb_WeakMap *PyUpb_ObjCache_Instance(void) {
- PyUpb_ModuleState *state = PyUpb_ModuleState_Get();
+PyUpb_WeakMap* PyUpb_ObjCache_Instance(void) {
+ PyUpb_ModuleState* state = PyUpb_ModuleState_Get();
return state->obj_cache;
}
-void PyUpb_ObjCache_Add(const void *key, PyObject *py_obj) {
+void PyUpb_ObjCache_Add(const void* key, PyObject* py_obj) {
PyUpb_WeakMap_Add(PyUpb_ObjCache_Instance(), key, py_obj);
}
-void PyUpb_ObjCache_Delete(const void *key) {
- PyUpb_ModuleState *state = PyUpb_ModuleState_MaybeGet();
+void PyUpb_ObjCache_Delete(const void* key) {
+ PyUpb_ModuleState* state = PyUpb_ModuleState_MaybeGet();
if (!state) {
// During the shutdown sequence, our object's Dealloc() methods can be
// called *after* our module Dealloc() method has been called. At that
@@ -205,7 +203,7 @@
PyUpb_WeakMap_Delete(state->obj_cache, key);
}
-PyObject *PyUpb_ObjCache_Get(const void *key) {
+PyObject* PyUpb_ObjCache_Get(const void* key) {
return PyUpb_WeakMap_Get(PyUpb_ObjCache_Instance(), key);
}
@@ -214,23 +212,23 @@
// -----------------------------------------------------------------------------
typedef struct {
- PyObject_HEAD
- upb_arena* arena;
+ PyObject_HEAD;
+ upb_Arena* arena;
} PyUpb_Arena;
PyObject* PyUpb_Arena_New(void) {
PyUpb_ModuleState* state = PyUpb_ModuleState_Get();
PyUpb_Arena* arena = (void*)PyType_GenericAlloc(state->arena_type, 0);
- arena->arena = upb_arena_new();
+ arena->arena = upb_Arena_New();
return &arena->ob_base;
}
static void PyUpb_Arena_Dealloc(PyObject* self) {
- upb_arena_free(PyUpb_Arena_Get(self));
+ upb_Arena_Free(PyUpb_Arena_Get(self));
PyUpb_Dealloc(self);
}
-upb_arena* PyUpb_Arena_Get(PyObject* arena) {
+upb_Arena* PyUpb_Arena_Get(PyObject* arena) {
return ((PyUpb_Arena*)arena)->arena;
}
@@ -257,25 +255,25 @@
// Utilities
// -----------------------------------------------------------------------------
-PyTypeObject *AddObject(PyObject *m, const char *name, PyType_Spec *spec) {
- PyObject *type = PyType_FromSpec(spec);
- return type && PyModule_AddObject(m, name, type) == 0 ? (PyTypeObject *)type
+PyTypeObject* AddObject(PyObject* m, const char* name, PyType_Spec* spec) {
+ PyObject* type = PyType_FromSpec(spec);
+ return type && PyModule_AddObject(m, name, type) == 0 ? (PyTypeObject*)type
: NULL;
}
-static const char *PyUpb_GetClassName(PyType_Spec *spec) {
+static const char* PyUpb_GetClassName(PyType_Spec* spec) {
// spec->name contains a fully-qualified name, like:
// google.protobuf.pyext._message.FooBar
//
// Find the rightmost '.' to get "FooBar".
- const char *name = strrchr(spec->name, '.');
+ const char* name = strrchr(spec->name, '.');
assert(name);
return name + 1;
}
-PyTypeObject *PyUpb_AddClass(PyObject *m, PyType_Spec *spec) {
- PyObject *type = PyType_FromSpec(spec);
- const char *name = PyUpb_GetClassName(spec);
+PyTypeObject* PyUpb_AddClass(PyObject* m, PyType_Spec* spec) {
+ PyObject* type = PyType_FromSpec(spec);
+ const char* name = PyUpb_GetClassName(spec);
if (PyModule_AddObject(m, name, type) < 0) {
Py_XDECREF(type);
return NULL;
@@ -294,7 +292,7 @@
return (PyTypeObject*)type;
}
-const char *PyUpb_GetStrData(PyObject *obj) {
+const char* PyUpb_GetStrData(PyObject* obj) {
if (PyUnicode_Check(obj)) {
return PyUnicode_AsUTF8AndSize(obj, NULL);
} else if (PyBytes_Check(obj)) {
@@ -304,8 +302,8 @@
}
}
-PyObject *PyUpb_Forbidden_New(PyObject *cls, PyObject *args, PyObject *kwds) {
- PyObject *name = PyObject_GetAttrString(cls, "__name__");
+PyObject* PyUpb_Forbidden_New(PyObject* cls, PyObject* args, PyObject* kwds) {
+ PyObject* name = PyObject_GetAttrString(cls, "__name__");
PyErr_Format(PyExc_RuntimeError,
"Objects of type %U may not be created directly.", name);
Py_XDECREF(name);
@@ -317,10 +315,10 @@
// -----------------------------------------------------------------------------
PyMODINIT_FUNC PyInit__message(void) {
- PyObject *m = PyModule_Create(&module_def);
+ PyObject* m = PyModule_Create(&module_def);
if (!m) return NULL;
- PyUpb_ModuleState *state = PyUpb_ModuleState_GetFromModule(m);
+ PyUpb_ModuleState* state = PyUpb_ModuleState_GetFromModule(m);
state->allow_oversize_protos = false;
state->wkt_bases = NULL;
diff --git a/python/protobuf.h b/python/protobuf.h
index b5156d8..312a877 100644
--- a/python/protobuf.h
+++ b/python/protobuf.h
@@ -50,20 +50,20 @@
typedef struct {
// From descriptor.c
- PyTypeObject *descriptor_types[kPyUpb_Descriptor_Count];
+ PyTypeObject* descriptor_types[kPyUpb_Descriptor_Count];
// From descriptor_containers.c
- PyTypeObject *by_name_map_type;
- PyTypeObject *by_number_map_type;
- PyTypeObject *descriptor_iterator_type;
- PyTypeObject *generic_sequence_type;
+ PyTypeObject* by_name_map_type;
+ PyTypeObject* by_number_map_type;
+ PyTypeObject* descriptor_iterator_type;
+ PyTypeObject* generic_sequence_type;
// From descriptor_pool.c
- PyObject *default_pool;
+ PyObject* default_pool;
// From descriptor_pool.c
- PyTypeObject *descriptor_pool_type;
- upb_symtab* c_descriptor_symtab;
+ PyTypeObject* descriptor_pool_type;
+ upb_DefPool* c_descriptor_symtab;
// From extension_dict.c
PyTypeObject* extension_dict_type;
@@ -75,20 +75,20 @@
PyTypeObject* scalar_map_container_type;
// From message.c
- PyObject *decode_error_class;
+ PyObject* decode_error_class;
PyObject* descriptor_string;
- PyObject *encode_error_class;
- PyObject *enum_type_wrapper_class;
- PyObject *message_class;
- PyTypeObject *cmessage_type;
- PyTypeObject *message_meta_type;
+ PyObject* encode_error_class;
+ PyObject* enum_type_wrapper_class;
+ PyObject* message_class;
+ PyTypeObject* cmessage_type;
+ PyTypeObject* message_meta_type;
PyObject* listfields_item_key;
// From protobuf.c
bool allow_oversize_protos;
- PyObject *wkt_bases;
- PyTypeObject *arena_type;
- PyUpb_WeakMap *obj_cache;
+ PyObject* wkt_bases;
+ PyTypeObject* arena_type;
+ PyUpb_WeakMap* obj_cache;
// From repeated.c
PyTypeObject* repeated_composite_container_type;
@@ -97,8 +97,8 @@
// Returns the global state object from the current interpreter. The current
// interpreter is looked up from thread-local state.
-PyUpb_ModuleState *PyUpb_ModuleState_Get(void);
-PyUpb_ModuleState *PyUpb_ModuleState_GetFromModule(PyObject *module);
+PyUpb_ModuleState* PyUpb_ModuleState_Get(void);
+PyUpb_ModuleState* PyUpb_ModuleState_GetFromModule(PyObject* module);
// Returns NULL if module state is not yet available (during startup).
// Any use of the module state during startup needs to be passed explicitly.
@@ -109,7 +109,7 @@
//
// This has to be imported lazily rather than at module load time, because
// otherwise it would cause a circular import.
-PyObject *PyUpb_GetWktBases(PyUpb_ModuleState *state);
+PyObject* PyUpb_GetWktBases(PyUpb_ModuleState* state);
// -----------------------------------------------------------------------------
// WeakMap
@@ -123,18 +123,18 @@
// remove itself from the map when it is destroyed. The map is weak so it does
// not take references to the cached objects.
-PyUpb_WeakMap *PyUpb_WeakMap_New(void);
-void PyUpb_WeakMap_Free(PyUpb_WeakMap *map);
+PyUpb_WeakMap* PyUpb_WeakMap_New(void);
+void PyUpb_WeakMap_Free(PyUpb_WeakMap* map);
// Adds the given object to the map, indexed by the given key.
-void PyUpb_WeakMap_Add(PyUpb_WeakMap *map, const void *key, PyObject *py_obj);
+void PyUpb_WeakMap_Add(PyUpb_WeakMap* map, const void* key, PyObject* py_obj);
// Removes the given key from the cache. It must exist in the cache currently.
-void PyUpb_WeakMap_Delete(PyUpb_WeakMap *map, const void *key);
-void PyUpb_WeakMap_TryDelete(PyUpb_WeakMap *map, const void *key);
+void PyUpb_WeakMap_Delete(PyUpb_WeakMap* map, const void* key);
+void PyUpb_WeakMap_TryDelete(PyUpb_WeakMap* map, const void* key);
// Returns a new reference to an object if it exists, otherwise returns NULL.
-PyObject *PyUpb_WeakMap_Get(PyUpb_WeakMap *map, const void *key);
+PyObject* PyUpb_WeakMap_Get(PyUpb_WeakMap* map, const void* key);
#define PYUPB_WEAKMAP_BEGIN UPB_INTTABLE_BEGIN
@@ -146,9 +146,9 @@
// }
//
// Note that the callee does not own a ref on the returned `obj`.
-bool PyUpb_WeakMap_Next(PyUpb_WeakMap *map, const void **key, PyObject **obj,
- intptr_t *iter);
-void PyUpb_WeakMap_DeleteIter(PyUpb_WeakMap *map, intptr_t *iter);
+bool PyUpb_WeakMap_Next(PyUpb_WeakMap* map, const void** key, PyObject** obj,
+ intptr_t* iter);
+void PyUpb_WeakMap_DeleteIter(PyUpb_WeakMap* map, intptr_t* iter);
// -----------------------------------------------------------------------------
// ObjCache
@@ -156,26 +156,26 @@
// The object cache is a global WeakMap for mapping upb objects to the
// corresponding wrapper.
-void PyUpb_ObjCache_Add(const void *key, PyObject *py_obj);
-void PyUpb_ObjCache_Delete(const void *key);
-PyObject *PyUpb_ObjCache_Get(const void *key); // returns NULL if not present.
-PyUpb_WeakMap *PyUpb_ObjCache_Instance(void);
+void PyUpb_ObjCache_Add(const void* key, PyObject* py_obj);
+void PyUpb_ObjCache_Delete(const void* key);
+PyObject* PyUpb_ObjCache_Get(const void* key); // returns NULL if not present.
+PyUpb_WeakMap* PyUpb_ObjCache_Instance(void);
// -----------------------------------------------------------------------------
// Arena
// -----------------------------------------------------------------------------
-PyObject *PyUpb_Arena_New(void);
-upb_arena *PyUpb_Arena_Get(PyObject *arena);
+PyObject* PyUpb_Arena_New(void);
+upb_Arena* PyUpb_Arena_Get(PyObject* arena);
// -----------------------------------------------------------------------------
// Utilities
// -----------------------------------------------------------------------------
-PyTypeObject *AddObject(PyObject *m, const char *name, PyType_Spec *spec);
+PyTypeObject* AddObject(PyObject* m, const char* name, PyType_Spec* spec);
// Creates a Python type from `spec` and adds it to the given module `m`.
-PyTypeObject *PyUpb_AddClass(PyObject *m, PyType_Spec *spec);
+PyTypeObject* PyUpb_AddClass(PyObject* m, PyType_Spec* spec);
// Like PyUpb_AddClass(), but allows you to specify a tuple of base classes
// in `bases`.
@@ -184,14 +184,14 @@
// A function that implements the tp_new slot for types that we do not allow
// users to create directly. This will immediately fail with an error message.
-PyObject *PyUpb_Forbidden_New(PyObject *cls, PyObject *args, PyObject *kwds);
+PyObject* PyUpb_Forbidden_New(PyObject* cls, PyObject* args, PyObject* kwds);
// Our standard dealloc func. It follows the guidance defined in:
// https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_dealloc
// However it tests Py_TPFLAGS_HEAPTYPE dynamically so that a single dealloc
// function can work for any type.
-static inline void PyUpb_Dealloc(void *self) {
- PyTypeObject *tp = Py_TYPE(self);
+static inline void PyUpb_Dealloc(void* self) {
+ PyTypeObject* tp = Py_TYPE(self);
freefunc tp_free = PyType_GetSlot(tp, Py_tp_free);
tp_free(self);
if (PyType_GetFlags(tp) & Py_TPFLAGS_HEAPTYPE) {
@@ -202,11 +202,11 @@
// Equivalent to the Py_NewRef() function introduced in Python 3.10. If/when we
// drop support for Python <3.10, we can remove this function and replace all
// callers with Py_NewRef().
-static inline PyObject *PyUpb_NewRef(PyObject *obj) {
+static inline PyObject* PyUpb_NewRef(PyObject* obj) {
Py_INCREF(obj);
return obj;
}
-const char *PyUpb_GetStrData(PyObject *obj);
+const char* PyUpb_GetStrData(PyObject* obj);
#endif // PYUPB_PROTOBUF_H__
diff --git a/python/python.h b/python/python.h
index a26cc2f..7eef3e5 100644
--- a/python/python.h
+++ b/python/python.h
@@ -36,7 +36,7 @@
// This function was not officially added to the limited API until Python 3.10.
// But in practice it has been stable since Python 3.1. See:
// https://bugs.python.org/issue41784
-PyAPI_FUNC(const char *)
- PyUnicode_AsUTF8AndSize(PyObject *unicode, Py_ssize_t *size);
+PyAPI_FUNC(const char*)
+ PyUnicode_AsUTF8AndSize(PyObject* unicode, Py_ssize_t* size);
#endif // PYUPB_PYTHON_H__
diff --git a/python/repeated.c b/python/repeated.c
index 4794fc1..7faa888 100644
--- a/python/repeated.c
+++ b/python/repeated.c
@@ -71,16 +71,16 @@
// Wrapper for a repeated field.
typedef struct {
- PyObject_HEAD
+ PyObject_HEAD;
PyObject* arena;
// The field descriptor (PyObject*).
// The low bit indicates whether the container is reified (see ptr below).
// - low bit set: repeated field is a stub (no underlying data).
- // - low bit clear: repeated field is reified (points to upb_array).
+ // - low bit clear: repeated field is reified (points to upb_Array).
uintptr_t field;
union {
PyObject* parent; // stub: owning pointer to parent message.
- upb_array* arr; // reified: the data for this array.
+ upb_Array* arr; // reified: the data for this array.
} ptr;
} PyUpb_RepeatedContainer;
@@ -93,7 +93,7 @@
return (PyObject*)(self->field & ~(uintptr_t)1);
}
-static const upb_fielddef* PyUpb_RepeatedContainer_GetField(
+static const upb_FieldDef* PyUpb_RepeatedContainer_GetField(
PyUpb_RepeatedContainer* self) {
return PyUpb_FieldDescriptor_GetDef(
PyUpb_RepeatedContainer_GetFieldDescriptor(self));
@@ -101,18 +101,18 @@
// If the repeated field is reified, returns it. Otherwise, returns NULL.
// If NULL is returned, the object is empty and has no underlying data.
-static upb_array* PyUpb_RepeatedContainer_GetIfReified(
+static upb_Array* PyUpb_RepeatedContainer_GetIfReified(
PyUpb_RepeatedContainer* self) {
return PyUpb_RepeatedContainer_IsStub(self) ? NULL : self->ptr.arr;
}
-void PyUpb_RepeatedContainer_Reify(PyObject* _self, upb_array* arr) {
+void PyUpb_RepeatedContainer_Reify(PyObject* _self, upb_Array* arr) {
PyUpb_RepeatedContainer* self = (PyUpb_RepeatedContainer*)_self;
assert(PyUpb_RepeatedContainer_IsStub(self));
if (!arr) {
- const upb_fielddef* f = PyUpb_RepeatedContainer_GetField(self);
- upb_arena* arena = PyUpb_Arena_Get(self->arena);
- arr = upb_array_new(arena, upb_fielddef_type(f));
+ const upb_FieldDef* f = PyUpb_RepeatedContainer_GetField(self);
+ upb_Arena* arena = PyUpb_Arena_Get(self->arena);
+ arr = upb_Array_New(arena, upb_FieldDef_CType(f));
}
PyUpb_ObjCache_Add(arr, &self->ob_base);
Py_DECREF(self->ptr.parent);
@@ -121,16 +121,16 @@
assert(!PyUpb_RepeatedContainer_IsStub(self));
}
-upb_array* PyUpb_RepeatedContainer_EnsureReified(PyObject* _self) {
+upb_Array* PyUpb_RepeatedContainer_EnsureReified(PyObject* _self) {
PyUpb_RepeatedContainer* self = (PyUpb_RepeatedContainer*)_self;
- upb_array* arr = PyUpb_RepeatedContainer_GetIfReified(self);
+ upb_Array* arr = PyUpb_RepeatedContainer_GetIfReified(self);
if (arr) return arr; // Already writable.
- const upb_fielddef* f = PyUpb_RepeatedContainer_GetField(self);
- upb_arena* arena = PyUpb_Arena_Get(self->arena);
- arr = upb_array_new(arena, upb_fielddef_type(f));
+ const upb_FieldDef* f = PyUpb_RepeatedContainer_GetField(self);
+ upb_Arena* arena = PyUpb_Arena_Get(self->arena);
+ arr = upb_Array_New(arena, upb_FieldDef_CType(f));
PyUpb_CMessage_SetConcreteSubobj(self->ptr.parent, f,
- (upb_msgval){.array_val = arr});
+ (upb_MessageValue){.array_val = arr});
PyUpb_RepeatedContainer_Reify((PyObject*)self, arr);
return arr;
}
@@ -149,21 +149,21 @@
PyUpb_Dealloc(self);
}
-static PyTypeObject* PyUpb_RepeatedContainer_GetClass(const upb_fielddef* f) {
- assert(upb_fielddef_isseq(f) && !upb_fielddef_ismap(f));
+static PyTypeObject* PyUpb_RepeatedContainer_GetClass(const upb_FieldDef* f) {
+ assert(upb_FieldDef_IsRepeated(f) && !upb_FieldDef_IsMap(f));
PyUpb_ModuleState* state = PyUpb_ModuleState_Get();
- return upb_fielddef_issubmsg(f) ? state->repeated_composite_container_type
- : state->repeated_scalar_container_type;
+ return upb_FieldDef_IsSubMessage(f) ? state->repeated_composite_container_type
+ : state->repeated_scalar_container_type;
}
static Py_ssize_t PyUpb_RepeatedContainer_Length(PyObject* self) {
- upb_array* arr =
+ upb_Array* arr =
PyUpb_RepeatedContainer_GetIfReified((PyUpb_RepeatedContainer*)self);
- return arr ? upb_array_size(arr) : 0;
+ return arr ? upb_Array_Size(arr) : 0;
}
PyObject* PyUpb_RepeatedContainer_NewStub(PyObject* parent,
- const upb_fielddef* f,
+ const upb_FieldDef* f,
PyObject* arena) {
// We only create stubs when the parent is reified, by convention. However
// this is not an invariant: the parent could become reified at any time.
@@ -178,8 +178,8 @@
return &repeated->ob_base;
}
-PyObject* PyUpb_RepeatedContainer_GetOrCreateWrapper(upb_array* arr,
- const upb_fielddef* f,
+PyObject* PyUpb_RepeatedContainer_GetOrCreateWrapper(upb_Array* arr,
+ const upb_FieldDef* f,
PyObject* arena) {
PyObject* ret = PyUpb_ObjCache_Get(arr);
if (ret) return ret;
@@ -200,33 +200,34 @@
PyObject* PyUpb_RepeatedContainer_DeepCopy(PyObject* _self, PyObject* value) {
PyUpb_RepeatedContainer* self = (PyUpb_RepeatedContainer*)_self;
- PyUpb_RepeatedContainer* clone = (void*)PyType_GenericAlloc(Py_TYPE(_self), 0);
+ PyUpb_RepeatedContainer* clone =
+ (void*)PyType_GenericAlloc(Py_TYPE(_self), 0);
if (clone == NULL) return NULL;
- const upb_fielddef* f = PyUpb_RepeatedContainer_GetField(self);
+ const upb_FieldDef* f = PyUpb_RepeatedContainer_GetField(self);
clone->arena = PyUpb_Arena_New();
clone->field = (uintptr_t)PyUpb_FieldDescriptor_Get(f);
clone->ptr.arr =
- upb_array_new(PyUpb_Arena_Get(clone->arena), upb_fielddef_type(f));
+ upb_Array_New(PyUpb_Arena_Get(clone->arena), upb_FieldDef_CType(f));
PyUpb_ObjCache_Add(clone->ptr.arr, (PyObject*)clone);
if (!PyUpb_RepeatedContainer_MergeFrom((PyObject*)clone, _self)) {
Py_DECREF(clone);
return NULL;
- }
+ }
return (PyObject*)clone;
}
PyObject* PyUpb_RepeatedContainer_Extend(PyObject* _self, PyObject* value) {
PyUpb_RepeatedContainer* self = (PyUpb_RepeatedContainer*)_self;
- upb_array* arr = PyUpb_RepeatedContainer_EnsureReified(_self);
- size_t start_size = upb_array_size(arr);
+ upb_Array* arr = PyUpb_RepeatedContainer_EnsureReified(_self);
+ size_t start_size = upb_Array_Size(arr);
PyObject* it = PyObject_GetIter(value);
if (!it) {
PyErr_SetString(PyExc_TypeError, "Value must be iterable");
return NULL;
}
- const upb_fielddef* f = PyUpb_RepeatedContainer_GetField(self);
- bool submsg = upb_fielddef_issubmsg(f);
+ const upb_FieldDef* f = PyUpb_RepeatedContainer_GetField(self);
+ bool submsg = upb_FieldDef_IsSubMessage(f);
PyObject* e;
while ((e = PyIter_Next(it))) {
@@ -243,7 +244,7 @@
Py_DECREF(it);
if (PyErr_Occurred()) {
- upb_array_resize(arr, start_size, NULL);
+ upb_Array_Resize(arr, start_size, NULL);
return NULL;
}
@@ -253,26 +254,26 @@
static PyObject* PyUpb_RepeatedContainer_Item(PyObject* _self,
Py_ssize_t index) {
PyUpb_RepeatedContainer* self = (PyUpb_RepeatedContainer*)_self;
- upb_array* arr = PyUpb_RepeatedContainer_GetIfReified(self);
- Py_ssize_t size = arr ? upb_array_size(arr) : 0;
+ upb_Array* arr = PyUpb_RepeatedContainer_GetIfReified(self);
+ Py_ssize_t size = arr ? upb_Array_Size(arr) : 0;
if (index < 0 || index >= size) {
PyErr_Format(PyExc_IndexError, "list index (%zd) out of range", index);
return NULL;
}
- const upb_fielddef* f = PyUpb_RepeatedContainer_GetField(self);
- return PyUpb_UpbToPy(upb_array_get(arr, index), f, self->arena);
+ const upb_FieldDef* f = PyUpb_RepeatedContainer_GetField(self);
+ return PyUpb_UpbToPy(upb_Array_Get(arr, index), f, self->arena);
}
PyObject* PyUpb_RepeatedContainer_ToList(PyObject* _self) {
PyUpb_RepeatedContainer* self = (PyUpb_RepeatedContainer*)_self;
- upb_array* arr = PyUpb_RepeatedContainer_GetIfReified(self);
+ upb_Array* arr = PyUpb_RepeatedContainer_GetIfReified(self);
if (!arr) return PyList_New(0);
- const upb_fielddef* f = PyUpb_RepeatedContainer_GetField(self);
- size_t n = upb_array_size(arr);
+ const upb_FieldDef* f = PyUpb_RepeatedContainer_GetField(self);
+ size_t n = upb_Array_Size(arr);
PyObject* list = PyList_New(n);
for (size_t i = 0; i < n; i++) {
- PyObject* val = PyUpb_UpbToPy(upb_array_get(arr, i), f, self->arena);
+ PyObject* val = PyUpb_UpbToPy(upb_Array_Get(arr, i), f, self->arena);
if (!val) {
Py_DECREF(list);
return NULL;
@@ -313,17 +314,17 @@
static PyObject* PyUpb_RepeatedContainer_Subscript(PyObject* _self,
PyObject* key) {
PyUpb_RepeatedContainer* self = (PyUpb_RepeatedContainer*)_self;
- upb_array* arr = PyUpb_RepeatedContainer_GetIfReified(self);
- Py_ssize_t size = arr ? upb_array_size(arr) : 0;
+ upb_Array* arr = PyUpb_RepeatedContainer_GetIfReified(self);
+ Py_ssize_t size = arr ? upb_Array_Size(arr) : 0;
Py_ssize_t idx, count, step;
if (!IndexToRange(key, size, &idx, &count, &step)) return NULL;
- const upb_fielddef* f = PyUpb_RepeatedContainer_GetField(self);
+ const upb_FieldDef* f = PyUpb_RepeatedContainer_GetField(self);
if (step == 0) {
- return PyUpb_UpbToPy(upb_array_get(arr, idx), f, self->arena);
+ return PyUpb_UpbToPy(upb_Array_Get(arr, idx), f, self->arena);
} else {
PyObject* list = PyList_New(count);
for (Py_ssize_t i = 0; i < count; i++, idx += step) {
- upb_msgval msgval = upb_array_get(self->ptr.arr, idx);
+ upb_MessageValue msgval = upb_Array_Get(self->ptr.arr, idx);
PyObject* item = PyUpb_UpbToPy(msgval, f, self->arena);
if (!item) {
Py_DECREF(list);
@@ -336,19 +337,19 @@
}
static int PyUpb_RepeatedContainer_SetSubscript(
- PyUpb_RepeatedContainer* self, upb_array* arr, const upb_fielddef* f,
+ PyUpb_RepeatedContainer* self, upb_Array* arr, const upb_FieldDef* f,
Py_ssize_t idx, Py_ssize_t count, Py_ssize_t step, PyObject* value) {
- upb_arena* arena = PyUpb_Arena_Get(self->arena);
- if (upb_fielddef_issubmsg(f)) {
+ upb_Arena* arena = PyUpb_Arena_Get(self->arena);
+ if (upb_FieldDef_IsSubMessage(f)) {
PyErr_SetString(PyExc_TypeError, "does not support assignment");
return -1;
}
if (step == 0) {
// Set single value.
- upb_msgval msgval;
+ upb_MessageValue msgval;
if (!PyUpb_PyToUpb(value, f, &msgval, arena)) return -1;
- upb_array_set(arr, idx, msgval);
+ upb_Array_Set(arr, idx, msgval);
return 0;
}
@@ -362,9 +363,9 @@
if (seq_size != count) {
if (step == 1) {
// We must shift the tail elements (either right or left).
- size_t tail = upb_array_size(arr) - (idx + count);
- upb_array_resize(arr, idx + seq_size + tail, arena);
- upb_array_move(arr, idx + seq_size, idx + count, tail);
+ size_t tail = upb_Array_Size(arr) - (idx + count);
+ upb_Array_Resize(arr, idx + seq_size + tail, arena);
+ upb_Array_Move(arr, idx + seq_size, idx + count, tail);
count = seq_size;
} else {
PyErr_Format(PyExc_ValueError,
@@ -375,14 +376,14 @@
}
}
for (Py_ssize_t i = 0; i < count; i++, idx += step) {
- upb_msgval msgval;
+ upb_MessageValue msgval;
item = PySequence_GetItem(seq, i);
if (!item) goto err;
// XXX: if this fails we can leave the list partially mutated.
if (!PyUpb_PyToUpb(item, f, &msgval, arena)) goto err;
Py_DECREF(item);
item = NULL;
- upb_array_set(arr, idx, msgval);
+ upb_Array_Set(arr, idx, msgval);
}
ret = 0;
@@ -392,7 +393,7 @@
return ret;
}
-static int PyUpb_RepeatedContainer_DeleteSubscript(upb_array* arr,
+static int PyUpb_RepeatedContainer_DeleteSubscript(upb_Array* arr,
Py_ssize_t idx,
Py_ssize_t count,
Py_ssize_t step) {
@@ -416,18 +417,18 @@
// dst <-------- tail -------------->
src = start + 1;
for (Py_ssize_t i = 1; i < count; i++, dst += step - 1, src += step) {
- upb_array_move(arr, dst, src, step);
+ upb_Array_Move(arr, dst, src, step);
}
} else {
src = start + count;
}
// Move tail.
- size_t tail = upb_array_size(arr) - src;
+ size_t tail = upb_Array_Size(arr) - src;
size_t new_size = dst + tail;
- assert(new_size == upb_array_size(arr) - count);
- upb_array_move(arr, dst, src, tail);
- upb_array_resize(arr, new_size, NULL);
+ assert(new_size == upb_Array_Size(arr) - count);
+ upb_Array_Move(arr, dst, src, tail);
+ upb_Array_Resize(arr, new_size, NULL);
return 0;
}
@@ -435,9 +436,9 @@
PyObject* key,
PyObject* value) {
PyUpb_RepeatedContainer* self = (PyUpb_RepeatedContainer*)_self;
- const upb_fielddef* f = PyUpb_RepeatedContainer_GetField(self);
- upb_array* arr = PyUpb_RepeatedContainer_GetIfReified(self);
- Py_ssize_t size = arr ? upb_array_size(arr) : 0;
+ const upb_FieldDef* f = PyUpb_RepeatedContainer_GetField(self);
+ upb_Array* arr = PyUpb_RepeatedContainer_GetIfReified(self);
+ Py_ssize_t size = arr ? upb_Array_Size(arr) : 0;
Py_ssize_t idx, count, step;
if (!IndexToRange(key, size, &idx, &count, &step)) return -1;
if (value) {
@@ -452,19 +453,19 @@
PyUpb_RepeatedContainer* self = (PyUpb_RepeatedContainer*)_self;
Py_ssize_t index = -1;
if (!PyArg_ParseTuple(args, "|n", &index)) return NULL;
- upb_array* arr = PyUpb_RepeatedContainer_EnsureReified(_self);
- size_t size = upb_array_size(arr);
+ upb_Array* arr = PyUpb_RepeatedContainer_EnsureReified(_self);
+ size_t size = upb_Array_Size(arr);
if (index < 0) index += size;
if (index >= size) index = size - 1;
PyObject* ret = PyUpb_RepeatedContainer_Item(_self, index);
if (!ret) return NULL;
- upb_array_delete(self->ptr.arr, index, 1);
+ upb_Array_Delete(self->ptr.arr, index, 1);
return ret;
}
static PyObject* PyUpb_RepeatedContainer_Remove(PyObject* _self,
PyObject* value) {
- upb_array* arr = PyUpb_RepeatedContainer_EnsureReified(_self);
+ upb_Array* arr = PyUpb_RepeatedContainer_EnsureReified(_self);
Py_ssize_t match_index = -1;
Py_ssize_t n = PyUpb_RepeatedContainer_Length(_self);
for (Py_ssize_t i = 0; i < n; ++i) {
@@ -490,21 +491,21 @@
// A helper function used only for Sort().
static bool PyUpb_RepeatedContainer_Assign(PyObject* _self, PyObject* list) {
PyUpb_RepeatedContainer* self = (PyUpb_RepeatedContainer*)_self;
- const upb_fielddef* f = PyUpb_RepeatedContainer_GetField(self);
- upb_array* arr = PyUpb_RepeatedContainer_EnsureReified(_self);
+ const upb_FieldDef* f = PyUpb_RepeatedContainer_GetField(self);
+ upb_Array* arr = PyUpb_RepeatedContainer_EnsureReified(_self);
Py_ssize_t size = PyList_Size(list);
- bool submsg = upb_fielddef_issubmsg(f);
- upb_arena* arena = PyUpb_Arena_Get(self->arena);
+ bool submsg = upb_FieldDef_IsSubMessage(f);
+ upb_Arena* arena = PyUpb_Arena_Get(self->arena);
for (Py_ssize_t i = 0; i < size; ++i) {
PyObject* obj = PyList_GetItem(list, i);
- upb_msgval msgval;
+ upb_MessageValue msgval;
if (submsg) {
msgval.msg_val = PyUpb_CMessage_GetIfReified(obj);
assert(msgval.msg_val);
} else {
if (!PyUpb_PyToUpb(obj, f, &msgval, arena)) return false;
}
- upb_array_set(arr, i, msgval);
+ upb_Array_Set(arr, i, msgval);
}
return true;
}
@@ -545,15 +546,15 @@
}
static PyObject* PyUpb_RepeatedContainer_Reverse(PyObject* _self) {
- upb_array* arr = PyUpb_RepeatedContainer_EnsureReified(_self);
- size_t n = upb_array_size(arr);
+ upb_Array* arr = PyUpb_RepeatedContainer_EnsureReified(_self);
+ size_t n = upb_Array_Size(arr);
size_t half = n / 2; // Rounds down.
for (size_t i = 0; i < half; i++) {
size_t i2 = n - i - 1;
- upb_msgval val1 = upb_array_get(arr, i);
- upb_msgval val2 = upb_array_get(arr, i2);
- upb_array_set(arr, i, val2);
- upb_array_set(arr, i2, val1);
+ upb_MessageValue val1 = upb_Array_Get(arr, i);
+ upb_MessageValue val2 = upb_Array_Get(arr, i2);
+ upb_Array_Set(arr, i, val2);
+ upb_Array_Set(arr, i2, val1);
}
Py_RETURN_NONE;
}
@@ -569,14 +570,14 @@
static PyObject* PyUpb_RepeatedCompositeContainer_AppendNew(PyObject* _self) {
PyUpb_RepeatedContainer* self = (PyUpb_RepeatedContainer*)_self;
- upb_array* arr = PyUpb_RepeatedContainer_EnsureReified(_self);
+ upb_Array* arr = PyUpb_RepeatedContainer_EnsureReified(_self);
if (!arr) return NULL;
- const upb_fielddef* f = PyUpb_RepeatedContainer_GetField(self);
- upb_arena* arena = PyUpb_Arena_Get(self->arena);
- const upb_msgdef* m = upb_fielddef_msgsubdef(f);
- upb_msg* msg = upb_msg_new(m, arena);
- upb_msgval msgval = {.msg_val = msg};
- upb_array_append(arr, msgval, arena);
+ const upb_FieldDef* f = PyUpb_RepeatedContainer_GetField(self);
+ upb_Arena* arena = PyUpb_Arena_Get(self->arena);
+ const upb_MessageDef* m = upb_FieldDef_MessageSubDef(f);
+ upb_msg* msg = upb_Message_New(m, arena);
+ upb_MessageValue msgval = {.msg_val = msg};
+ upb_Array_Append(arr, msgval, arena);
return PyUpb_CMessage_Get(msg, m, self->arena);
}
@@ -587,7 +588,7 @@
if (!py_msg) return NULL;
if (PyUpb_CMessage_InitAttributes(py_msg, args, kwargs) < 0) {
Py_DECREF(py_msg);
- upb_array_delete(self->ptr.arr, upb_array_size(self->ptr.arr) - 1, 1);
+ upb_Array_Delete(self->ptr.arr, upb_Array_Size(self->ptr.arr) - 1, 1);
return NULL;
}
return py_msg;
@@ -613,22 +614,22 @@
Py_ssize_t index;
PyObject* value;
if (!PyArg_ParseTuple(args, "nO", &index, &value)) return NULL;
- upb_array* arr = PyUpb_RepeatedContainer_EnsureReified(_self);
+ upb_Array* arr = PyUpb_RepeatedContainer_EnsureReified(_self);
if (!arr) return NULL;
// Normalize index.
- Py_ssize_t size = upb_array_size(arr);
+ Py_ssize_t size = upb_Array_Size(arr);
if (index < 0) index += size;
if (index < 0) index = 0;
if (index > size) index = size;
- const upb_fielddef* f = PyUpb_RepeatedContainer_GetField(self);
- upb_msgval msgval;
- upb_arena* arena = PyUpb_Arena_Get(self->arena);
- if (upb_fielddef_issubmsg(f)) {
+ const upb_FieldDef* f = PyUpb_RepeatedContainer_GetField(self);
+ upb_MessageValue msgval;
+ upb_Arena* arena = PyUpb_Arena_Get(self->arena);
+ if (upb_FieldDef_IsSubMessage(f)) {
// Create message.
- const upb_msgdef* m = upb_fielddef_msgsubdef(f);
- upb_msg* msg = upb_msg_new(m, arena);
+ const upb_MessageDef* m = upb_FieldDef_MessageSubDef(f);
+ upb_msg* msg = upb_Message_New(m, arena);
PyObject* py_msg = PyUpb_CMessage_Get(msg, m, self->arena);
PyObject* ret = PyUpb_CMessage_MergeFrom(py_msg, value);
Py_DECREF(py_msg);
@@ -639,8 +640,8 @@
if (!PyUpb_PyToUpb(value, f, &msgval, arena)) return NULL;
}
- upb_array_insert(arr, index, 1, arena);
- upb_array_set(arr, index, msgval);
+ upb_Array_Insert(arr, index, 1, arena);
+ upb_Array_Set(arr, index, msgval);
Py_RETURN_NONE;
}
@@ -697,14 +698,14 @@
static PyObject* PyUpb_RepeatedScalarContainer_Append(PyObject* _self,
PyObject* value) {
PyUpb_RepeatedContainer* self = (PyUpb_RepeatedContainer*)_self;
- upb_array* arr = PyUpb_RepeatedContainer_EnsureReified(_self);
- upb_arena* arena = PyUpb_Arena_Get(self->arena);
- const upb_fielddef* f = PyUpb_RepeatedContainer_GetField(self);
- upb_msgval msgval;
+ upb_Array* arr = PyUpb_RepeatedContainer_EnsureReified(_self);
+ upb_Arena* arena = PyUpb_Arena_Get(self->arena);
+ const upb_FieldDef* f = PyUpb_RepeatedContainer_GetField(self);
+ upb_MessageValue msgval;
if (!PyUpb_PyToUpb(value, f, &msgval, arena)) {
return NULL;
}
- upb_array_append(arr, msgval, arena);
+ upb_Array_Append(arr, msgval, arena);
Py_RETURN_NONE;
}
@@ -712,19 +713,19 @@
Py_ssize_t index,
PyObject* item) {
PyUpb_RepeatedContainer* self = (PyUpb_RepeatedContainer*)_self;
- upb_array* arr = PyUpb_RepeatedContainer_GetIfReified(self);
- Py_ssize_t size = arr ? upb_array_size(arr) : 0;
+ upb_Array* arr = PyUpb_RepeatedContainer_GetIfReified(self);
+ Py_ssize_t size = arr ? upb_Array_Size(arr) : 0;
if (index < 0 || index >= size) {
PyErr_Format(PyExc_IndexError, "list index (%zd) out of range", index);
return -1;
}
- const upb_fielddef* f = PyUpb_RepeatedContainer_GetField(self);
- upb_msgval msgval;
- upb_arena* arena = PyUpb_Arena_Get(self->arena);
+ const upb_FieldDef* f = PyUpb_RepeatedContainer_GetField(self);
+ upb_MessageValue msgval;
+ upb_Arena* arena = PyUpb_Arena_Get(self->arena);
if (!PyUpb_PyToUpb(item, f, &msgval, arena)) {
return -1;
}
- upb_array_set(self->ptr.arr, index, msgval);
+ upb_Array_Set(self->ptr.arr, index, msgval);
return 0;
}
diff --git a/python/repeated.h b/python/repeated.h
index de81b2b..9cde3ea 100644
--- a/python/repeated.h
+++ b/python/repeated.h
@@ -36,23 +36,23 @@
// Creates a new repeated field stub for field `f` of message object `parent`.
// Precondition: `parent` must be a stub.
PyObject* PyUpb_RepeatedContainer_NewStub(PyObject* parent,
- const upb_fielddef* f,
+ const upb_FieldDef* f,
PyObject* arena);
// Returns a repeated field object wrapping `arr`, of field type `f`, which
// must be on `arena`. If an existing wrapper object exists, it will be
// returned, otherwise a new object will be created. The caller always owns a
// ref on the returned value.
-PyObject* PyUpb_RepeatedContainer_GetOrCreateWrapper(upb_array* arr,
- const upb_fielddef* f,
+PyObject* PyUpb_RepeatedContainer_GetOrCreateWrapper(upb_Array* arr,
+ const upb_FieldDef* f,
PyObject* arena);
// Reifies a repeated field stub to point to the concrete data in `arr`.
// If `arr` is NULL, an appropriate empty array will be constructed.
-void PyUpb_RepeatedContainer_Reify(PyObject* self, upb_array* arr);
+void PyUpb_RepeatedContainer_Reify(PyObject* self, upb_Array* arr);
// Reifies this repeated object if it is not already reified.
-upb_array* PyUpb_RepeatedContainer_EnsureReified(PyObject* self);
+upb_Array* PyUpb_RepeatedContainer_EnsureReified(PyObject* self);
// Implements repeated_field.extend(iterable). `_self` must be a repeated
// field (either repeated composite or repeated scalar).