upb_Encode() now returns a status value

PiperOrigin-RevId: 454740100
diff --git a/python/descriptor.c b/python/descriptor.c
index 8ef6da4..b30b348 100644
--- a/python/descriptor.c
+++ b/python/descriptor.c
@@ -123,14 +123,16 @@
     size_t size;
     PyObject* py_arena = PyUpb_Arena_New();
     upb_Arena* arena = PyUpb_Arena_Get(py_arena);
-    char* pb = upb_Encode(opts, layout, 0, arena, &size);
+    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);
     assert(opts2);
-    bool ok = upb_Decode(pb, size, opts2, upb_MessageDef_MiniTable(m),
-                         upb_DefPool_ExtensionRegistry(symtab), 0,
-                         arena) == kUpb_DecodeStatus_Ok;
-    (void)ok;
-    assert(ok);
+    upb_DecodeStatus ds =
+        upb_Decode(pb, size, opts2, upb_MessageDef_MiniTable(m),
+                   upb_DefPool_ExtensionRegistry(symtab), 0, arena);
+    (void)ds;
+    assert(ds == kUpb_DecodeStatus_Ok);
 
     self->options = PyUpb_Message_Get(opts2, m, py_arena);
     Py_DECREF(py_arena);
@@ -150,8 +152,9 @@
   upb_Message* proto = func(self->def, arena);
   if (!proto) goto oom;
   size_t size;
-  char* pb = upb_Encode(proto, layout, 0, arena, &size);
-  if (!pb) goto oom;
+  char* pb;
+  upb_EncodeStatus status = upb_Encode(proto, layout, 0, arena, &pb, &size);
+  if (status) goto oom;  // TODO(b/235839510) non-oom errors are possible here
   PyObject* str = PyBytes_FromStringAndSize(pb, size);
   upb_Arena_Free(arena);
   return str;
diff --git a/python/message.c b/python/message.c
index 24d45cf..68efb19 100644
--- a/python/message.c
+++ b/python/message.c
@@ -1487,12 +1487,14 @@
   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 |= kUpb_Encode_CheckRequired;
-  if (deterministic) options |= kUpb_Encode_Deterministic;
-  char* pb = upb_Encode(self->ptr.msg, layout, options, arena, &size);
+  if (check_required) options |= kUpb_EncodeOption_CheckRequired;
+  if (deterministic) options |= kUpb_EncodeOption_Deterministic;
+  char* pb;
+  upb_EncodeStatus status =
+      upb_Encode(self->ptr.msg, layout, options, arena, &pb, &size);
   PyObject* ret = NULL;
 
-  if (!pb) {
+  if (status != kUpb_EncodeStatus_Ok) {
     PyUpb_ModuleState* state = PyUpb_ModuleState_Get();
     PyObject* errors = PyUpb_Message_FindInitializationErrors(_self, NULL);
     if (PyList_Size(errors) != 0) {