upb: add a non-void typedef for upb_Message
PiperOrigin-RevId: 592863926
diff --git a/python/BUILD.bazel b/python/BUILD.bazel
index f604bad..7f2b247 100644
--- a/python/BUILD.bazel
+++ b/python/BUILD.bazel
@@ -190,6 +190,7 @@
],
target_compatible_with = select(_message_target_compatible_with),
deps = [
+ "//upb:base",
"//upb:descriptor_upb_proto_reflection",
"//upb:eps_copy_input_stream",
"//upb:hash",
diff --git a/python/descriptor.c b/python/descriptor.c
index ea4c028..c5af6dd 100644
--- a/python/descriptor.c
+++ b/python/descriptor.c
@@ -12,6 +12,7 @@
#include "python/descriptor_pool.h"
#include "python/message.h"
#include "python/protobuf.h"
+#include "upb/base/upcast.h"
#include "upb/reflection/def.h"
#include "upb/util/def_to_proto.h"
@@ -391,7 +392,7 @@
static PyObject* PyUpb_Descriptor_GetOptions(PyObject* _self, PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetOptions(
- &self->options, upb_MessageDef_Options(self->def),
+ &self->options, UPB_UPCAST(upb_MessageDef_Options(self->def)),
&google__protobuf__MessageOptions_msg_init,
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".MessageOptions");
}
@@ -399,7 +400,7 @@
static PyObject* PyUpb_Descriptor_GetFeatures(PyObject* _self, PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetFeatures(
- &self->features, upb_MessageDef_ResolvedFeatures(self->def));
+ &self->features, UPB_UPCAST(upb_MessageDef_ResolvedFeatures(self->def)));
}
static PyObject* PyUpb_Descriptor_CopyToProto(PyObject* _self,
@@ -700,10 +701,10 @@
{0, NULL}};
static PyType_Spec PyUpb_Descriptor_Spec = {
- PYUPB_MODULE_NAME ".Descriptor", // tp_name
- sizeof(PyUpb_DescriptorBase), // tp_basicsize
- 0, // tp_itemsize
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags
+ PYUPB_MODULE_NAME ".Descriptor", // tp_name
+ sizeof(PyUpb_DescriptorBase), // tp_basicsize
+ 0, // tp_itemsize
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags
PyUpb_Descriptor_Slots,
};
@@ -809,7 +810,7 @@
PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetOptions(
- &self->options, upb_EnumDef_Options(self->def),
+ &self->options, UPB_UPCAST(upb_EnumDef_Options(self->def)),
&google__protobuf__EnumOptions_msg_init,
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".EnumOptions");
}
@@ -818,7 +819,7 @@
PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetFeatures(
- &self->features, upb_EnumDef_ResolvedFeatures(self->def));
+ &self->features, UPB_UPCAST(upb_EnumDef_ResolvedFeatures(self->def)));
}
static PyObject* PyUpb_EnumDescriptor_CopyToProto(PyObject* _self,
@@ -908,7 +909,7 @@
PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetOptions(
- &self->options, upb_EnumValueDef_Options(self->def),
+ &self->options, UPB_UPCAST(upb_EnumValueDef_Options(self->def)),
&google__protobuf__EnumValueOptions_msg_init,
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".EnumValueOptions");
}
@@ -917,7 +918,8 @@
PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetFeatures(
- &self->features, upb_EnumValueDef_ResolvedFeatures(self->def));
+ &self->features,
+ UPB_UPCAST(upb_EnumValueDef_ResolvedFeatures(self->def)));
}
static PyGetSetDef PyUpb_EnumValueDescriptor_Getters[] = {
@@ -1121,7 +1123,7 @@
PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetOptions(
- &self->options, upb_FieldDef_Options(self->def),
+ &self->options, UPB_UPCAST(upb_FieldDef_Options(self->def)),
&google__protobuf__FieldOptions_msg_init,
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".FieldOptions");
}
@@ -1130,7 +1132,7 @@
PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetFeatures(
- &self->features, upb_FieldDef_ResolvedFeatures(self->def));
+ &self->features, UPB_UPCAST(upb_FieldDef_ResolvedFeatures(self->def)));
}
static PyGetSetDef PyUpb_FieldDescriptor_Getters[] = {
@@ -1381,7 +1383,7 @@
PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetOptions(
- &self->options, upb_FileDef_Options(self->def),
+ &self->options, UPB_UPCAST(upb_FileDef_Options(self->def)),
&google__protobuf__FileOptions_msg_init,
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".FileOptions");
}
@@ -1390,7 +1392,7 @@
PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetFeatures(
- &self->features, upb_FileDef_ResolvedFeatures(self->def));
+ &self->features, UPB_UPCAST(upb_FileDef_ResolvedFeatures(self->def)));
}
static PyObject* PyUpb_FileDescriptor_CopyToProto(PyObject* _self,
@@ -1515,7 +1517,7 @@
PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetOptions(
- &self->options, upb_MethodDef_Options(self->def),
+ &self->options, UPB_UPCAST(upb_MethodDef_Options(self->def)),
&google__protobuf__MethodOptions_msg_init,
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".MethodOptions");
}
@@ -1524,7 +1526,7 @@
PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetFeatures(
- &self->features, upb_MethodDef_ResolvedFeatures(self->def));
+ &self->features, UPB_UPCAST(upb_MethodDef_ResolvedFeatures(self->def)));
}
static PyObject* PyUpb_MethodDescriptor_CopyToProto(PyObject* _self,
@@ -1632,7 +1634,7 @@
PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetOptions(
- &self->options, upb_OneofDef_Options(self->def),
+ &self->options, UPB_UPCAST(upb_OneofDef_Options(self->def)),
&google__protobuf__OneofOptions_msg_init,
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".OneofOptions");
}
@@ -1641,7 +1643,7 @@
PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetFeatures(
- &self->features, upb_OneofDef_ResolvedFeatures(self->def));
+ &self->features, UPB_UPCAST(upb_OneofDef_ResolvedFeatures(self->def)));
}
static PyGetSetDef PyUpb_OneofDescriptor_Getters[] = {
@@ -1742,7 +1744,7 @@
PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetOptions(
- &self->options, upb_ServiceDef_Options(self->def),
+ &self->options, UPB_UPCAST(upb_ServiceDef_Options(self->def)),
&google__protobuf__ServiceOptions_msg_init,
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".ServiceOptions");
}
@@ -1751,7 +1753,7 @@
PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetFeatures(
- &self->features, upb_ServiceDef_ResolvedFeatures(self->def));
+ &self->features, UPB_UPCAST(upb_ServiceDef_ResolvedFeatures(self->def)));
}
static PyObject* PyUpb_ServiceDescriptor_CopyToProto(PyObject* _self,
diff --git a/python/descriptor_pool.c b/python/descriptor_pool.c
index 09efbda..089d31b 100644
--- a/python/descriptor_pool.c
+++ b/python/descriptor_pool.c
@@ -12,6 +12,7 @@
#include "python/descriptor.h"
#include "python/message.h"
#include "python/protobuf.h"
+#include "upb/base/upcast.h"
#include "upb/reflection/def.h"
#include "upb/util/def_to_proto.h"
@@ -147,8 +148,7 @@
static bool PyUpb_DescriptorPool_LoadDependentFiles(
PyUpb_DescriptorPool* self, google_protobuf_FileDescriptorProto* proto) {
size_t n;
- const upb_StringView* deps =
- google_protobuf_FileDescriptorProto_dependency(proto, &n);
+ const upb_StringView* deps = google_protobuf_FileDescriptorProto_dependency(proto, &n);
for (size_t i = 0; i < n; i++) {
const upb_FileDef* dep = upb_DefPool_FindFileByNameWithSize(
self->symtab, deps[i].data, deps[i].size);
@@ -191,14 +191,13 @@
if (file) {
// If the existing file is equal to the new file, then silently ignore the
// duplicate add.
- google_protobuf_FileDescriptorProto* existing =
- upb_FileDef_ToProto(file, arena);
+ google_protobuf_FileDescriptorProto* existing = upb_FileDef_ToProto(file, arena);
if (!existing) {
PyErr_SetNone(PyExc_MemoryError);
goto done;
}
const upb_MessageDef* m = PyUpb_DescriptorPool_GetFileProtoDef();
- if (upb_Message_IsEqual(proto, existing, m)) {
+ if (upb_Message_IsEqual(UPB_UPCAST(proto), UPB_UPCAST(existing), m)) {
result = PyUpb_FileDescriptor_Get(file);
goto done;
}
diff --git a/python/map.c b/python/map.c
index 4330aae..bbbd636 100644
--- a/python/map.c
+++ b/python/map.c
@@ -184,7 +184,7 @@
map = PyUpb_MapContainer_EnsureReified(_self);
upb_Arena* arena = PyUpb_Arena_Get(self->arena);
if (upb_FieldDef_IsSubMessage(val_f)) {
- const upb_Message* m = upb_FieldDef_MessageSubDef(val_f);
+ const upb_MessageDef* m = upb_FieldDef_MessageSubDef(val_f);
const upb_MiniTable* layout = upb_MessageDef_MiniTable(m);
u_val.msg_val = upb_Message_New(layout, arena);
} else {