protobuf/python/google/protobuf/internal/api_implementation.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 namespace google {
35 namespace protobuf {
36 namespace python {
37 
38 // Version constant.
39 // This is either 0 for python, 1 for CPP V1, 2 for CPP V2.
40 //
41 // 0 is default and is equivalent to
42 // PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
43 //
44 // 1 is set with -DPYTHON_PROTO2_CPP_IMPL_V1 and is equivalent to
45 // PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp
46 // and
47 // PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION_VERSION=1
48 //
49 // 2 is set with -DPYTHON_PROTO2_CPP_IMPL_V2 and is equivalent to
50 // PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp
51 // and
52 // PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION_VERSION=2
53 #ifdef PYTHON_PROTO2_CPP_IMPL_V1
54 #error "PYTHON_PROTO2_CPP_IMPL_V1 is no longer supported."
55 #else
56 #ifdef PYTHON_PROTO2_CPP_IMPL_V2
57 static int kImplVersion = 2;
58 #else
59 #ifdef PYTHON_PROTO2_PYTHON_IMPL
60 static int kImplVersion = 0;
61 #else
62 
63 static int kImplVersion = -1; // -1 means "Unspecified by compiler flags".
64 
65 #endif // PYTHON_PROTO2_PYTHON_IMPL
66 #endif // PYTHON_PROTO2_CPP_IMPL_V2
67 #endif // PYTHON_PROTO2_CPP_IMPL_V1
68 
69 static const char* kImplVersionName = "api_version";
70 
71 static const char* kModuleName = "_api_implementation";
72 static const char kModuleDocstring[] =
73  "_api_implementation is a module that exposes compile-time constants that\n"
74  "determine the default API implementation to use for Python proto2.\n"
75  "\n"
76  "It complements api_implementation.py by setting defaults using "
77  "compile-time\n"
78  "constants defined in C, such that one can set defaults at compilation\n"
79  "(e.g. with blaze flag --copt=-DPYTHON_PROTO2_CPP_IMPL_V2).";
80 
81 static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT,
84  -1,
85  NULL,
86  NULL,
87  NULL,
88  NULL,
89  NULL};
90 
91 extern "C" {
92 PyMODINIT_FUNC PyInit__api_implementation() {
93  PyObject* module = PyModule_Create(&_module);
94  if (module == NULL) {
95  return NULL;
96  }
97 
98  // Adds the module variable "api_version".
99  if (PyModule_AddIntConstant(module, const_cast<char*>(kImplVersionName),
100  kImplVersion)) {
101  Py_DECREF(module);
102  return NULL;
103  }
104 
105  return module;
106 }
107 }
108 
109 } // namespace python
110 } // namespace protobuf
111 } // namespace google
google::protobuf::python::kImplVersionName
static const char * kImplVersionName
Definition: bloaty/third_party/protobuf/python/google/protobuf/internal/api_implementation.cc:68
google::protobuf::python::kModuleDocstring
static const char kModuleDocstring[]
Definition: bloaty/third_party/protobuf/python/google/protobuf/internal/api_implementation.cc:71
google::protobuf::python::kModuleName
static const char * kModuleName
Definition: bloaty/third_party/protobuf/python/google/protobuf/internal/api_implementation.cc:70
google::protobuf::python::PyInit__api_implementation
PyMODINIT_FUNC PyInit__api_implementation()
Definition: protobuf/python/google/protobuf/internal/api_implementation.cc:92
google::protobuf
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:12
google::protobuf::python::_module
static struct PyModuleDef _module
Definition: protobuf/python/google/protobuf/internal/api_implementation.cc:81
google::protobuf::python::kImplVersion
static int kImplVersion
Definition: bloaty/third_party/protobuf/python/google/protobuf/internal/api_implementation.cc:62
descriptor_database_test_wrapper.module
module
Definition: descriptor_database_test_wrapper.py:30
google
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:11


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:31