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/descriptor.c b/python/descriptor.c
index 5e3a5fd..f721175 100644
--- a/python/descriptor.c
+++ b/python/descriptor.c
@@ -126,10 +126,11 @@
     char* pb;
     // TODO(b/235839510): Need to correctly handle failed return codes.
     (void)upb_Encode(opts, layout, 0, arena, &pb, &size);
-    upb_Message* opts2 = upb_Message_New(m, arena);
+    const upb_MiniTable* opts2_layout = upb_MessageDef_MiniTable(m);
+    upb_Message* opts2 = upb_Message_New(opts2_layout, arena);
     assert(opts2);
     upb_DecodeStatus ds =
-        upb_Decode(pb, size, opts2, upb_MessageDef_MiniTable(m),
+        upb_Decode(pb, size, opts2, opts2_layout,
                    upb_DefPool_ExtensionRegistry(symtab), 0, arena);
     (void)ds;
     assert(ds == kUpb_DecodeStatus_Ok);
diff --git a/python/map.c b/python/map.c
index dfadf41..bdfb34d 100644
--- a/python/map.c
+++ b/python/map.c
@@ -204,7 +204,9 @@
     map = PyUpb_MapContainer_EnsureReified(_self);
     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);
+      const upb_Message* m = upb_FieldDef_MessageSubDef(val_f);
+      const upb_MiniTable* layout = upb_MessageDef_MiniTable(m);
+      u_val.msg_val = upb_Message_New(layout, arena);
     } else {
       memset(&u_val, 0, sizeof(u_val));
     }
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);
diff --git a/python/repeated.c b/python/repeated.c
index 1c2378f..2c09f7c 100644
--- a/python/repeated.c
+++ b/python/repeated.c
@@ -577,7 +577,8 @@
   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_Message* msg = upb_Message_New(m, arena);
+  const upb_MiniTable* layout = upb_MessageDef_MiniTable(m);
+  upb_Message* msg = upb_Message_New(layout, arena);
   upb_MessageValue msgval = {.msg_val = msg};
   upb_Array_Append(arr, msgval, arena);
   return PyUpb_Message_Get(msg, m, self->arena);
@@ -631,7 +632,8 @@
   if (upb_FieldDef_IsSubMessage(f)) {
     // Create message.
     const upb_MessageDef* m = upb_FieldDef_MessageSubDef(f);
-    upb_Message* msg = upb_Message_New(m, arena);
+    const upb_MiniTable* layout = upb_MessageDef_MiniTable(m);
+    upb_Message* msg = upb_Message_New(layout, arena);
     PyObject* py_msg = PyUpb_Message_Get(msg, m, self->arena);
     PyObject* ret = PyUpb_Message_MergeFrom(py_msg, value);
     Py_DECREF(py_msg);