normalize upb_Message_New()
We had _upb_Message_New(), which created a message from a mini table and was
being used outside of upb even though it is an internal-only function.
We also had upb_Message_New(), which created a message from a message def.
Now there is a single public function, upb_Message_New(), which creates a
message from a mini table and covers all use cases. (The internal version has the same definition and is used for inlining.)
PiperOrigin-RevId: 480169804
diff --git a/python/message.c b/python/message.c
index 1752922..2dae4fd 100644
--- a/python/message.c
+++ b/python/message.c
@@ -251,10 +251,11 @@
static PyObject* PyUpb_Message_New(PyObject* cls, PyObject* unused_args,
PyObject* unused_kwargs) {
const upb_MessageDef* msgdef = PyUpb_MessageMeta_GetMsgdef(cls);
+ const upb_MiniTable* layout = upb_MessageDef_MiniTable(msgdef);
PyUpb_Message* msg = (void*)PyType_GenericAlloc((PyTypeObject*)cls, 0);
msg->def = (uintptr_t)msgdef;
msg->arena = PyUpb_Arena_New();
- msg->ptr.msg = upb_Message_New(msgdef, PyUpb_Arena_Get(msg->arena));
+ msg->ptr.msg = upb_Message_New(layout, PyUpb_Arena_Get(msg->arena));
msg->unset_subobj_map = NULL;
msg->ext_dict = NULL;
msg->version = 0;
@@ -596,8 +597,9 @@
static const upb_FieldDef* PyUpb_Message_InitAsMsg(PyUpb_Message* m,
upb_Arena* arena) {
const upb_FieldDef* f = PyUpb_Message_GetFieldDef(m);
- m->ptr.msg = upb_Message_New(upb_FieldDef_MessageSubDef(f), arena);
- m->def = (uintptr_t)upb_FieldDef_MessageSubDef(f);
+ const upb_MessageDef* m2 = upb_FieldDef_MessageSubDef(f);
+ m->ptr.msg = upb_Message_New(upb_MessageDef_MiniTable(m2), arena);
+ m->def = (uintptr_t)m2;
PyUpb_ObjCache_Add(m->ptr.msg, &m->ob_base);
return f;
}
@@ -671,7 +673,8 @@
assert(f == PyUpb_Message_GetFieldDef(self));
if (!msg) {
const upb_MessageDef* msgdef = PyUpb_Message_GetMsgdef((PyObject*)self);
- msg = upb_Message_New(msgdef, PyUpb_Arena_Get(self->arena));
+ const upb_MiniTable* layout = upb_MessageDef_MiniTable(msgdef);
+ msg = upb_Message_New(layout, PyUpb_Arena_Get(self->arena));
}
PyUpb_ObjCache_Add(msg, &self->ob_base);
Py_DECREF(&self->ptr.parent->ob_base);