Merge pull request #534 from haberman/google3-names

Factored out name differences into C macros
pull/13171/head
Joshua Haberman 3 years ago committed by GitHub
commit bc2018744f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 33
      python/descriptor.c
  2. 3
      python/descriptor_pool.c
  3. 7
      python/message.c
  4. 4
      python/protobuf.c
  5. 12
      python/protobuf.h

@ -107,7 +107,7 @@ static PyObject* PyUpb_DescriptorBase_GetOptions(PyUpb_DescriptorBase* self,
if (!self->options) {
// Load descriptors protos if they are not loaded already. We have to do
// this lazily, otherwise, it would lead to circular imports.
PyObject* mod = PyImport_ImportModule("google.protobuf.descriptor_pb2");
PyObject* mod = PyImport_ImportModule(PYUPB_DESCRIPTOR_MODULE);
Py_DECREF(mod);
// Find the correct options message.
@ -323,7 +323,7 @@ static PyObject* PyUpb_Descriptor_GetOptions(PyObject* _self, PyObject* args) {
return PyUpb_DescriptorBase_GetOptions(
self, upb_MessageDef_Options(self->def),
&google_protobuf_MessageOptions_msginit,
"google.protobuf.MessageOptions");
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".MessageOptions");
}
static PyObject* PyUpb_Descriptor_CopyToProto(PyObject* _self,
@ -331,7 +331,7 @@ static PyObject* PyUpb_Descriptor_CopyToProto(PyObject* _self,
return PyUpb_DescriptorBase_CopyToProto(
_self, (PyUpb_ToProto_Func*)&upb_MessageDef_ToProto,
&google_protobuf_DescriptorProto_msginit,
"google.protobuf.DescriptorProto", py_proto);
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".DescriptorProto", py_proto);
}
static PyObject* PyUpb_Descriptor_EnumValueName(PyObject* _self,
@ -733,7 +733,8 @@ static PyObject* PyUpb_EnumDescriptor_GetOptions(PyObject* _self,
PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetOptions(self, upb_EnumDef_Options(self->def),
&google_protobuf_EnumOptions_msginit,
"google.protobuf.EnumOptions");
PYUPB_DESCRIPTOR_PROTO_PACKAGE
".EnumOptions");
}
static PyObject* PyUpb_EnumDescriptor_CopyToProto(PyObject* _self,
@ -741,7 +742,7 @@ static PyObject* PyUpb_EnumDescriptor_CopyToProto(PyObject* _self,
return PyUpb_DescriptorBase_CopyToProto(
_self, (PyUpb_ToProto_Func*)&upb_EnumDef_ToProto,
&google_protobuf_EnumDescriptorProto_msginit,
"google.protobuf.EnumDescriptorProto", py_proto);
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".EnumDescriptorProto", py_proto);
}
static PyGetSetDef PyUpb_EnumDescriptor_Getters[] = {
@ -822,7 +823,7 @@ static PyObject* PyUpb_EnumValueDescriptor_GetOptions(PyObject* _self,
return PyUpb_DescriptorBase_GetOptions(
self, upb_EnumValueDef_Options(self->def),
&google_protobuf_EnumValueOptions_msginit,
"google.protobuf.EnumValueOptions");
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".EnumValueOptions");
}
static PyGetSetDef PyUpb_EnumValueDescriptor_Getters[] = {
@ -1015,7 +1016,8 @@ static PyObject* PyUpb_FieldDescriptor_GetOptions(PyObject* _self,
PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetOptions(self, upb_FieldDef_Options(self->def),
&google_protobuf_FieldOptions_msginit,
"google.protobuf.FieldOptions");
PYUPB_DESCRIPTOR_PROTO_PACKAGE
".FieldOptions");
}
static PyGetSetDef PyUpb_FieldDescriptor_Getters[] = {
@ -1254,7 +1256,8 @@ static PyObject* PyUpb_FileDescriptor_GetOptions(PyObject* _self,
PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetOptions(self, upb_FileDef_Options(self->def),
&google_protobuf_FileOptions_msginit,
"google.protobuf.FileOptions");
PYUPB_DESCRIPTOR_PROTO_PACKAGE
".FileOptions");
}
static PyObject* PyUpb_FileDescriptor_CopyToProto(PyObject* _self,
@ -1262,7 +1265,7 @@ static PyObject* PyUpb_FileDescriptor_CopyToProto(PyObject* _self,
return PyUpb_DescriptorBase_CopyToProto(
_self, (PyUpb_ToProto_Func*)&upb_FileDef_ToProto,
&google_protobuf_FileDescriptorProto_msginit,
"google.protobuf.FileDescriptorProto", py_proto);
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".FileDescriptorProto", py_proto);
}
static PyGetSetDef PyUpb_FileDescriptor_Getters[] = {
@ -1361,7 +1364,8 @@ static PyObject* PyUpb_MethodDescriptor_GetOptions(PyObject* _self,
PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetOptions(self, upb_MethodDef_Options(self->def),
&google_protobuf_MethodOptions_msginit,
"google.protobuf.MethodOptions");
PYUPB_DESCRIPTOR_PROTO_PACKAGE
".MethodOptions");
}
static PyObject* PyUpb_MethodDescriptor_CopyToProto(PyObject* _self,
@ -1369,7 +1373,7 @@ static PyObject* PyUpb_MethodDescriptor_CopyToProto(PyObject* _self,
return PyUpb_DescriptorBase_CopyToProto(
_self, (PyUpb_ToProto_Func*)&upb_MethodDef_ToProto,
&google_protobuf_MethodDescriptorProto_msginit,
"google.protobuf.MethodDescriptorProto", py_proto);
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".MethodDescriptorProto", py_proto);
}
static PyGetSetDef PyUpb_MethodDescriptor_Getters[] = {
@ -1466,7 +1470,8 @@ static PyObject* PyUpb_OneofDescriptor_GetOptions(PyObject* _self,
PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetOptions(self, upb_OneofDef_Options(self->def),
&google_protobuf_OneofOptions_msginit,
"google.protobuf.OneofOptions");
PYUPB_DESCRIPTOR_PROTO_PACKAGE
".OneofOptions");
}
static PyGetSetDef PyUpb_OneofDescriptor_Getters[] = {
@ -1567,7 +1572,7 @@ static PyObject* PyUpb_ServiceDescriptor_GetOptions(PyObject* _self,
return PyUpb_DescriptorBase_GetOptions(
self, upb_ServiceDef_Options(self->def),
&google_protobuf_ServiceOptions_msginit,
"google.protobuf.ServiceOptions");
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".ServiceOptions");
}
static PyObject* PyUpb_ServiceDescriptor_CopyToProto(PyObject* _self,
@ -1575,7 +1580,7 @@ static PyObject* PyUpb_ServiceDescriptor_CopyToProto(PyObject* _self,
return PyUpb_DescriptorBase_CopyToProto(
_self, (PyUpb_ToProto_Func*)&upb_ServiceDef_ToProto,
&google_protobuf_ServiceDescriptorProto_msginit,
"google.protobuf.ServiceDescriptorProto", py_proto);
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".ServiceDescriptorProto", py_proto);
}
static PyObject* PyUpb_ServiceDescriptor_FindMethodByName(PyObject* _self,

@ -251,7 +251,8 @@ static PyObject* PyUpb_DescriptorPool_DoAdd(PyObject* _self,
PyObject* file_desc) {
if (!PyUpb_CMessage_Verify(file_desc)) return NULL;
const upb_MessageDef* m = PyUpb_CMessage_GetMsgdef(file_desc);
const char* file_proto_name = "google.protobuf.FileDescriptorProto";
const char* file_proto_name =
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".FileDescriptorProto";
if (strcmp(upb_MessageDef_FullName(m), file_proto_name) != 0) {
return PyErr_Format(PyExc_TypeError, "Can only add FileDescriptorProto");
}

@ -1832,7 +1832,8 @@ bool PyUpb_InitMessage(PyObject* m) {
state->listfields_item_key = PyObject_GetAttrString(
(PyObject*)state->cmessage_type, "_ListFieldsItemKey");
PyObject* mod = PyImport_ImportModule("google.protobuf.message");
PyObject* mod =
PyImport_ImportModule(PYUPB_PROTOBUF_PUBLIC_PACKAGE ".message");
if (mod == NULL) return false;
state->encode_error_class = PyObject_GetAttrString(mod, "EncodeError");
@ -1840,8 +1841,8 @@ bool PyUpb_InitMessage(PyObject* m) {
state->message_class = PyObject_GetAttrString(mod, "Message");
Py_DECREF(mod);
PyObject* enum_type_wrapper =
PyImport_ImportModule("google.protobuf.internal.enum_type_wrapper");
PyObject* enum_type_wrapper = PyImport_ImportModule(
PYUPB_PROTOBUF_INTERNAL_PACKAGE ".enum_type_wrapper");
if (enum_type_wrapper == NULL) return false;
state->enum_type_wrapper_class =

@ -94,8 +94,8 @@ PyUpb_ModuleState* PyUpb_ModuleState_Get(void) {
PyObject* PyUpb_GetWktBases(PyUpb_ModuleState* state) {
if (!state->wkt_bases) {
PyObject* wkt_module =
PyImport_ImportModule("google.protobuf.internal.well_known_types");
PyObject* wkt_module = PyImport_ImportModule(PYUPB_PROTOBUF_INTERNAL_PACKAGE
".well_known_types");
if (wkt_module == NULL) {
return false;

@ -34,7 +34,19 @@
#include "python/python.h"
#include "upb/table_internal.h"
// copybara:strip_for_google3_begin
#define PYUPB_PROTOBUF_PUBLIC_PACKAGE "google.protobuf"
#define PYUPB_PROTOBUF_INTERNAL_PACKAGE "google.protobuf.internal"
#define PYUPB_DESCRIPTOR_PROTO_PACKAGE "google.protobuf"
#define PYUPB_DESCRIPTOR_MODULE "google.protobuf.descriptor_pb2"
#define PYUPB_MODULE_NAME "google.protobuf.pyext._message"
// copybara:replace_for_google3_begin
// #define PYUPB_PROTOBUF_PUBLIC_PACKAGE "google3.net.proto2.python.public"
// #define PYUPB_PROTOBUF_INTERNAL_PACKAGE "google3.net.proto2.python.internal"
// #define PYUPB_DESCRIPTOR_PROTO_PACKAGE "proto2"
// #define PYUPB_DESCRIPTOR_MODULE "google3.net.proto2.proto.descriptor_pb2"
// #define PYUPB_MODULE_NAME "google3.third_party.upb.python._message"
// copybara:replace_for_google3_end
#define PYUPB_RETURN_OOM return PyErr_SetNone(PyExc_MemoryError), NULL

Loading…
Cancel
Save