From cbacdf152a04abc7e849b68ba6c4eaeb3c3669e3 Mon Sep 17 00:00:00 2001 From: Jie Luo Date: Mon, 12 Jun 2023 00:33:50 -0700 Subject: [PATCH] Remove RegisterExtension in message class PiperOrigin-RevId: 539568063 --- python/extension_dict.c | 5 +++++ python/message.c | 4 ---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/python/extension_dict.c b/python/extension_dict.c index aa714a34d1..48bb2de799 100644 --- a/python/extension_dict.c +++ b/python/extension_dict.c @@ -53,6 +53,10 @@ static PyObject* PyUpb_ExtensionDict_FindExtensionByName(PyObject* _self, PyObject* key) { PyUpb_ExtensionDict* self = (PyUpb_ExtensionDict*)_self; const char* name = PyUpb_GetStrData(key); + if (!name) { + PyErr_Format(PyExc_TypeError, "_FindExtensionByName expect a str"); + return NULL; + } const upb_MessageDef* m = PyUpb_Message_GetMsgdef(self->msg); const upb_FileDef* file = upb_MessageDef_File(m); const upb_DefPool* symtab = upb_FileDef_Pool(file); @@ -73,6 +77,7 @@ static PyObject* PyUpb_ExtensionDict_FindExtensionByNumber(PyObject* _self, const upb_DefPool* symtab = upb_FileDef_Pool(file); const upb_ExtensionRegistry* reg = upb_DefPool_ExtensionRegistry(symtab); int64_t number = PyLong_AsLong(arg); + if (number == -1 && PyErr_Occurred()) return NULL; const upb_MiniTableExtension* ext = (upb_MiniTableExtension*)upb_ExtensionRegistry_Lookup(reg, l, number); if (ext) { diff --git a/python/message.c b/python/message.c index 0e42a9884c..a01ce166fd 100644 --- a/python/message.c +++ b/python/message.c @@ -1677,10 +1677,6 @@ static PyMethodDef PyUpb_Message_Methods[] = { "Merges a serialized message into the current message."}, {"ParseFromString", PyUpb_Message_ParseFromString, METH_O, "Parses a serialized message into the current message."}, - // TODO(https://github.com/protocolbuffers/upb/issues/459) - //{ "RegisterExtension", (PyCFunction)RegisterExtension, METH_O | - // METH_CLASS, - // "Registers an extension with the current message." }, {"SerializePartialToString", (PyCFunction)PyUpb_Message_SerializePartialToString, METH_VARARGS | METH_KEYWORDS,