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 #include <Python.h>
32 
37 
39 
40 namespace {
41 
42 // C++ API. Clients get at this via proto_api.h
43 struct ApiImplementation : google::protobuf::python::PyProto_API {
44  const google::protobuf::Message* GetMessagePointer(PyObject* msg) const override {
46  }
47  google::protobuf::Message* GetMutableMessagePointer(PyObject* msg) const override {
49  }
52  }
53 
57  }
58 };
59 
60 } // namespace
61 
62 static const char module_docstring[] =
63  "python-proto2 is a module that can be used to enhance proto2 Python API\n"
64  "performance.\n"
65  "\n"
66  "It provides access to the protocol buffers C++ reflection API that\n"
67  "implements the basic protocol buffer functions.";
68 
69 static PyMethodDef ModuleMethods[] = {
70  {"SetAllowOversizeProtos",
72  "Enable/disable oversize proto parsing."},
73  // DO NOT USE: For migration and testing only.
74  {NULL, NULL}};
75 
76 #if PY_MAJOR_VERSION >= 3
77 static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT,
78  "_message",
80  -1,
81  ModuleMethods, /* m_methods */
82  NULL,
83  NULL,
84  NULL,
85  NULL};
86 #define INITFUNC PyInit__message
87 #define INITFUNC_ERRORVAL NULL
88 #else // Python 2
89 #define INITFUNC init_message
90 #define INITFUNC_ERRORVAL
91 #endif
92 
93 PyMODINIT_FUNC INITFUNC() {
94  PyObject* m;
95 #if PY_MAJOR_VERSION >= 3
96  m = PyModule_Create(&_module);
97 #else
98  m = Py_InitModule3("_message", ModuleMethods, module_docstring);
99 #endif
100  if (m == NULL) {
101  return INITFUNC_ERRORVAL;
102  }
103 
105  Py_DECREF(m);
106  return INITFUNC_ERRORVAL;
107  }
108 
109  // Adds the C++ API
110  if (PyObject* api =
111  PyCapsule_New(new ApiImplementation(),
113  PyModule_AddObject(m, "proto_API", api);
114  } else {
115  return INITFUNC_ERRORVAL;
116  }
117 
118 #if PY_MAJOR_VERSION >= 3
119  return m;
120 #endif
121 }
NULL
NULL
Definition: test_security_zap.cpp:405
message_factory.h
google::protobuf::python::PyProto_API::GetMessagePointer
virtual const Message * GetMessagePointer(PyObject *msg) const =0
google::protobuf::python::PyMessageFactory::message_factory
PyObject_HEAD MessageFactory * message_factory
Definition: message_factory.h:58
google::protobuf::python::GetDefaultDescriptorPool
PyDescriptorPool * GetDefaultDescriptorPool()
Definition: descriptor_pool.cc:751
INITFUNC
#define INITFUNC
Definition: message_module.cc:89
module_docstring
static const char module_docstring[]
Definition: message_module.cc:62
ModuleMethods
static PyMethodDef ModuleMethods[]
Definition: message_module.cc:69
google::protobuf::MessageFactory
Definition: src/google/protobuf/message.h:1069
INITFUNC_ERRORVAL
#define INITFUNC_ERRORVAL
Definition: message_module.cc:90
google::protobuf::python::PyProtoAPICapsuleName
const char * PyProtoAPICapsuleName()
Definition: proto_api.h:87
google::protobuf::python::PyProto_API
Definition: proto_api.h:63
google::protobuf::DescriptorPool
Definition: src/google/protobuf/descriptor.h:1539
google::protobuf::python::cmessage::SetAllowOversizeProtos
PyObject * SetAllowOversizeProtos(PyObject *m, PyObject *arg)
Definition: python/google/protobuf/pyext/message.cc:1913
google::protobuf::python::PyProto_API::GetMutableMessagePointer
virtual Message * GetMutableMessagePointer(PyObject *msg) const =0
google::protobuf::python::PyProto_API::GetDefaultDescriptorPool
virtual const DescriptorPool * GetDefaultDescriptorPool() const =0
descriptor_pool.h
google::protobuf::Message
Definition: src/google/protobuf/message.h:205
google::protobuf::python::PyDescriptorPool::py_message_factory
PyMessageFactory * py_message_factory
Definition: descriptor_pool.h:77
google::protobuf::python::PyProto_API::GetDefaultMessageFactory
virtual MessageFactory * GetDefaultMessageFactory() const =0
google::protobuf::python::PyDescriptorPool::pool
PyObject_HEAD DescriptorPool * pool
Definition: descriptor_pool.h:60
message_lite.h
m
const upb_json_parsermethod * m
Definition: ruby/ext/google/protobuf_c/upb.h:10501
google::protobuf::python::InitProto2MessageModule
bool InitProto2MessageModule(PyObject *m)
Definition: python/google/protobuf/pyext/message.cc:2932
message.h
proto_api.h
google::protobuf::python::PyMessage_GetMessagePointer
const Message * PyMessage_GetMessagePointer(PyObject *msg)
Definition: python/google/protobuf/pyext/message.cc:2861
google::protobuf::python::PyMessage_GetMutableMessagePointer
Message * PyMessage_GetMutableMessagePointer(PyObject *msg)
Definition: python/google/protobuf/pyext/message.cc:2870


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:56