_version.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (c) 2016 Jonathan Underwood
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * 3. Neither the name of Steeve Morin nor the names of its contributors may be
  16. * used to endorse or promote products derived from this software without
  17. * specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  23. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29. * POSSIBILITY OF SUCH DAMAGE.
  30. */
  31. #include <Python.h>
  32. #include <stdlib.h>
  33. #include <lz4.h>
  34. #include <lz4hc.h>
  35. static PyObject *
  36. library_version_number (PyObject * Py_UNUSED (self), PyObject * Py_UNUSED (args))
  37. {
  38. return Py_BuildValue ("i", LZ4_versionNumber ());
  39. }
  40. static PyObject *
  41. library_version_string (PyObject * Py_UNUSED (self), PyObject * Py_UNUSED (args))
  42. {
  43. return Py_BuildValue ("s", LZ4_versionString ());
  44. }
  45. PyDoc_STRVAR
  46. (
  47. library_version_number__doc,
  48. "library_version_number()\n\n" \
  49. "Returns the version number of the LZ4 library.\n" \
  50. "\n" \
  51. "Args:\n" \
  52. " None\n" \
  53. "\n" \
  54. "Returns:\n" \
  55. " int: version number eg. 10705"
  56. );
  57. PyDoc_STRVAR
  58. (
  59. library_version_string__doc,
  60. "library_version_string()\n\n" \
  61. "Returns the version number of the LZ4 library as a string\n" \
  62. "containing the semantic version.\n" \
  63. "\n" \
  64. "Args:\n" \
  65. " None\n" \
  66. "\n" \
  67. "Returns:\n" \
  68. " str: version number eg. \"1.7.5\""
  69. );
  70. static PyMethodDef module_methods[] = {
  71. {
  72. "library_version_number",
  73. (PyCFunction) library_version_number,
  74. METH_VARARGS,
  75. library_version_number__doc
  76. },
  77. {
  78. "library_version_string",
  79. (PyCFunction) library_version_string,
  80. METH_VARARGS,
  81. library_version_string__doc
  82. },
  83. {
  84. /* Sentinel */
  85. NULL,
  86. NULL,
  87. 0,
  88. NULL
  89. }
  90. };
  91. static struct PyModuleDef moduledef =
  92. {
  93. PyModuleDef_HEAD_INIT,
  94. "_version",
  95. NULL,
  96. -1,
  97. module_methods
  98. };
  99. PyMODINIT_FUNC
  100. PyInit__version(void)
  101. {
  102. PyObject *module = PyModule_Create (&moduledef);
  103. if (module == NULL)
  104. return NULL;
  105. return module;
  106. }