message_module.cc 2.9 KB

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