| OLD | NEW |
| (Empty) |
| 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 <google/protobuf/pyext/message.h> | |
| 32 | |
| 33 static const char module_docstring[] = | |
| 34 "python-proto2 is a module that can be used to enhance proto2 Python API\n" | |
| 35 "performance.\n" | |
| 36 "\n" | |
| 37 "It provides access to the protocol buffers C++ reflection API that\n" | |
| 38 "implements the basic protocol buffer functions."; | |
| 39 | |
| 40 static PyMethodDef ModuleMethods[] = { | |
| 41 {"SetAllowOversizeProtos", | |
| 42 (PyCFunction)google::protobuf::python::cmessage::SetAllowOversizeProtos, | |
| 43 METH_O, "Enable/disable oversize proto parsing."}, | |
| 44 { NULL, NULL} | |
| 45 }; | |
| 46 | |
| 47 #if PY_MAJOR_VERSION >= 3 | |
| 48 static struct PyModuleDef _module = { | |
| 49 PyModuleDef_HEAD_INIT, | |
| 50 "_message", | |
| 51 module_docstring, | |
| 52 -1, | |
| 53 ModuleMethods, /* m_methods */ | |
| 54 NULL, | |
| 55 NULL, | |
| 56 NULL, | |
| 57 NULL | |
| 58 }; | |
| 59 #define INITFUNC PyInit__message | |
| 60 #define INITFUNC_ERRORVAL NULL | |
| 61 #else // Python 2 | |
| 62 #define INITFUNC init_message | |
| 63 #define INITFUNC_ERRORVAL | |
| 64 #endif | |
| 65 | |
| 66 extern "C" { | |
| 67 PyMODINIT_FUNC INITFUNC(void) { | |
| 68 PyObject* m; | |
| 69 #if PY_MAJOR_VERSION >= 3 | |
| 70 m = PyModule_Create(&_module); | |
| 71 #else | |
| 72 m = Py_InitModule3("_message", ModuleMethods, | |
| 73 module_docstring); | |
| 74 #endif | |
| 75 if (m == NULL) { | |
| 76 return INITFUNC_ERRORVAL; | |
| 77 } | |
| 78 | |
| 79 if (!google::protobuf::python::InitProto2MessageModule(m)) { | |
| 80 Py_DECREF(m); | |
| 81 return INITFUNC_ERRORVAL; | |
| 82 } | |
| 83 | |
| 84 #if PY_MAJOR_VERSION >= 3 | |
| 85 return m; | |
| 86 #endif | |
| 87 } | |
| 88 } | |
| OLD | NEW |