protobuf/python/google/protobuf/pyext/message_module.cc
Go to the documentation of this file.
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 #define PY_SSIZE_T_CLEAN
32 #include <Python.h>
33 
34 #include <google/protobuf/message_lite.h>
35 #include <google/protobuf/pyext/descriptor.h>
36 #include <google/protobuf/pyext/descriptor_pool.h>
37 #include <google/protobuf/pyext/message.h>
38 #include <google/protobuf/pyext/message_factory.h>
39 #include <google/protobuf/proto_api.h>
40 
41 namespace {
42 
43 // C++ API. Clients get at this via proto_api.h
44 struct ApiImplementation : google::protobuf::python::PyProto_API {
45  const google::protobuf::Message* GetMessagePointer(PyObject* msg) const override {
47  }
48  google::protobuf::Message* GetMutableMessagePointer(PyObject* msg) const override {
50  }
51  const google::protobuf::Descriptor* MessageDescriptor_AsDescriptor(
52  PyObject* desc) const override {
54  }
55  const google::protobuf::EnumDescriptor* EnumDescriptor_AsDescriptor(
56  PyObject* enum_desc) const override {
58  }
59 
62  }
63 
64  google::protobuf::MessageFactory* GetDefaultMessageFactory() const override {
67  }
68  PyObject* NewMessage(const google::protobuf::Descriptor* descriptor,
69  PyObject* py_message_factory) const override {
70  return google::protobuf::python::PyMessage_New(descriptor, py_message_factory);
71  }
72  PyObject* NewMessageOwnedExternally(
73  google::protobuf::Message* msg, PyObject* py_message_factory) const override {
75  msg, py_message_factory);
76  }
77  PyObject* DescriptorPool_FromPool(
78  const google::protobuf::DescriptorPool* pool) const override {
80  }
81 };
82 
83 } // namespace
84 
85 static const char module_docstring[] =
86  "python-proto2 is a module that can be used to enhance proto2 Python API\n"
87  "performance.\n"
88  "\n"
89  "It provides access to the protocol buffers C++ reflection API that\n"
90  "implements the basic protocol buffer functions.";
91 
92 static PyMethodDef ModuleMethods[] = {
93  {"SetAllowOversizeProtos",
95  "Enable/disable oversize proto parsing."},
96  // DO NOT USE: For migration and testing only.
97  {NULL, NULL}};
98 
99 static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT,
100  "_message",
102  -1,
103  ModuleMethods, /* m_methods */
104  NULL,
105  NULL,
106  NULL,
107  NULL};
108 
109 PyMODINIT_FUNC PyInit__message() {
110  PyObject* m;
111  m = PyModule_Create(&_module);
112  if (m == NULL) {
113  return NULL;
114  }
115 
117  Py_DECREF(m);
118  return NULL;
119  }
120 
121  // Adds the C++ API
122  if (PyObject* api = PyCapsule_New(
123  new ApiImplementation(), google::protobuf::python::PyProtoAPICapsuleName(),
124  [](PyObject* o) {
125  delete (ApiImplementation*)PyCapsule_GetPointer(
127  })) {
128  PyModule_AddObject(m, "proto_API", api);
129  } else {
130  return NULL;
131  }
132 
133  return m;
134 }
google::protobuf::python::GetDefaultDescriptorPool
PyDescriptorPool * GetDefaultDescriptorPool()
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor_pool.cc:751
_module
static struct PyModuleDef _module
Definition: protobuf/python/google/protobuf/pyext/message_module.cc:99
google::protobuf::python::PyMessage_New
PyObject * PyMessage_New(const Descriptor *descriptor, PyObject *py_message_factory)
Definition: protobuf/python/google/protobuf/pyext/message.cc:2852
google::protobuf::python::PyDescriptorPool_FromPool
PyObject * PyDescriptorPool_FromPool(const DescriptorPool *pool)
Definition: protobuf/python/google/protobuf/pyext/descriptor_pool.cc:783
module_docstring
static const char module_docstring[]
Definition: protobuf/python/google/protobuf/pyext/message_module.cc:85
google::protobuf::MessageFactory
Definition: bloaty/third_party/protobuf/src/google/protobuf/message.h:1066
o
UnboundConversion o
Definition: third_party/abseil-cpp/absl/strings/internal/str_format/parser_test.cc:97
google::protobuf::python::PyMessageDescriptor_AsDescriptor
const Descriptor * PyMessageDescriptor_AsDescriptor(PyObject *obj)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor.cc:728
google::protobuf::python::PyProto_API
Definition: bloaty/third_party/protobuf/python/google/protobuf/proto_api.h:63
PyInit__message
PyMODINIT_FUNC PyInit__message()
Definition: protobuf/python/google/protobuf/pyext/message_module.cc:109
google::protobuf::python::PyProtoAPICapsuleName
const char * PyProtoAPICapsuleName()
Definition: bloaty/third_party/protobuf/python/google/protobuf/proto_api.h:87
google::protobuf::python::PyDescriptorPool::py_message_factory
PyMessageFactory * py_message_factory
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor_pool.h:77
google::protobuf::DescriptorPool
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:1539
google::protobuf::python::cmessage::SetAllowOversizeProtos
PyObject * SetAllowOversizeProtos(PyObject *m, PyObject *arg)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:1914
ModuleMethods
static PyMethodDef ModuleMethods[]
Definition: protobuf/python/google/protobuf/pyext/message_module.cc:92
msg
std::string msg
Definition: client_interceptors_end2end_test.cc:372
google::protobuf::Message
Definition: bloaty/third_party/protobuf/src/google/protobuf/message.h:205
google::protobuf::python::PyEnumDescriptor_AsDescriptor
const EnumDescriptor * PyEnumDescriptor_AsDescriptor(PyObject *obj)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor.cc:1198
google::protobuf::python::PyDescriptorPool::pool
PyObject_HEAD DescriptorPool * pool
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor_pool.h:60
google::protobuf::Descriptor
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:231
desc
#define desc
Definition: bloaty/third_party/protobuf/src/google/protobuf/extension_set.h:338
pool
InternalDescriptorPool * pool
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:807
google::protobuf::python::InitProto2MessageModule
bool InitProto2MessageModule(PyObject *m)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:2943
google::protobuf::python::PyMessage_NewMessageOwnedExternally
PyObject * PyMessage_NewMessageOwnedExternally(Message *message, PyObject *message_factory)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:2904
regress.m
m
Definition: regress/regress.py:25
google::protobuf::EnumDescriptor
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:918
google::protobuf::python::PyMessageFactory::message_factory
PyObject_HEAD MessageFactory * message_factory
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message_factory.h:58
descriptor
static const char descriptor[1336]
Definition: certs.upbdefs.c:16
google::protobuf::python::PyMessage_GetMessagePointer
const Message * PyMessage_GetMessagePointer(PyObject *msg)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:2872
google::protobuf::python::PyMessage_GetMutableMessagePointer
Message * PyMessage_GetMutableMessagePointer(PyObject *msg)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message.cc:2881


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:26