PageRenderTime 36ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Lib/python/pyhead.swg

#
Unknown | 214 lines | 188 code | 26 blank | 0 comment | 0 complexity | e4fa19964040688934998689bad86c82 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* Compatibility macros for Python 3 */
  2. #if PY_VERSION_HEX >= 0x03000000
  3. #define PyClass_Check(obj) PyObject_IsInstance(obj, (PyObject *)&PyType_Type)
  4. #define PyInt_Check(x) PyLong_Check(x)
  5. #define PyInt_AsLong(x) PyLong_AsLong(x)
  6. #define PyInt_AsUnsignedLongMask(x) PyLong_AsUnsignedLongMask(x)
  7. #define PyInt_FromLong(x) PyLong_FromLong(x)
  8. #define PyString_Check(name) PyBytes_Check(name)
  9. #define PyString_FromString(x) PyUnicode_FromString(x)
  10. #define PyString_Format(fmt, args) PyUnicode_Format(fmt, args)
  11. #define PyString_AsString(str) PyBytes_AsString(str)
  12. #define PyString_Size(str) PyBytes_Size(str)
  13. #define PyString_InternFromString(key) PyUnicode_InternFromString(key)
  14. #define Py_TPFLAGS_HAVE_CLASS Py_TPFLAGS_BASETYPE
  15. #define PyString_AS_STRING(x) PyUnicode_AS_STRING(x)
  16. #define _PyLong_FromSsize_t(x) PyLong_FromSsize_t(x)
  17. #endif
  18. #ifndef Py_TYPE
  19. # define Py_TYPE(op) ((op)->ob_type)
  20. #endif
  21. /* SWIG APIs for compatibility of both Python 2 & 3 */
  22. #if PY_VERSION_HEX >= 0x03000000
  23. # define SWIG_Python_str_FromFormat PyUnicode_FromFormat
  24. #else
  25. # define SWIG_Python_str_FromFormat PyString_FromFormat
  26. #endif
  27. /* Warning: This function will allocate a new string in Python 3,
  28. * so please call SWIG_Python_str_DelForPy3(x) to free the space.
  29. */
  30. SWIGINTERN char*
  31. SWIG_Python_str_AsChar(PyObject *str)
  32. {
  33. #if PY_VERSION_HEX >= 0x03000000
  34. char *cstr;
  35. char *newstr;
  36. Py_ssize_t len;
  37. str = PyUnicode_AsUTF8String(str);
  38. PyBytes_AsStringAndSize(str, &cstr, &len);
  39. newstr = (char *) malloc(len+1);
  40. memcpy(newstr, cstr, len+1);
  41. Py_XDECREF(str);
  42. return newstr;
  43. #else
  44. return PyString_AsString(str);
  45. #endif
  46. }
  47. #if PY_VERSION_HEX >= 0x03000000
  48. # define SWIG_Python_str_DelForPy3(x) free( (void*) (x) )
  49. #else
  50. # define SWIG_Python_str_DelForPy3(x)
  51. #endif
  52. SWIGINTERN PyObject*
  53. SWIG_Python_str_FromChar(const char *c)
  54. {
  55. #if PY_VERSION_HEX >= 0x03000000
  56. return PyUnicode_FromString(c);
  57. #else
  58. return PyString_FromString(c);
  59. #endif
  60. }
  61. /* Add PyOS_snprintf for old Pythons */
  62. #if PY_VERSION_HEX < 0x02020000
  63. # if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM)
  64. # define PyOS_snprintf _snprintf
  65. # else
  66. # define PyOS_snprintf snprintf
  67. # endif
  68. #endif
  69. /* A crude PyString_FromFormat implementation for old Pythons */
  70. #if PY_VERSION_HEX < 0x02020000
  71. #ifndef SWIG_PYBUFFER_SIZE
  72. # define SWIG_PYBUFFER_SIZE 1024
  73. #endif
  74. static PyObject *
  75. PyString_FromFormat(const char *fmt, ...) {
  76. va_list ap;
  77. char buf[SWIG_PYBUFFER_SIZE * 2];
  78. int res;
  79. va_start(ap, fmt);
  80. res = vsnprintf(buf, sizeof(buf), fmt, ap);
  81. va_end(ap);
  82. return (res < 0 || res >= (int)sizeof(buf)) ? 0 : PyString_FromString(buf);
  83. }
  84. #endif
  85. /* Add PyObject_Del for old Pythons */
  86. #if PY_VERSION_HEX < 0x01060000
  87. # define PyObject_Del(op) PyMem_DEL((op))
  88. #endif
  89. #ifndef PyObject_DEL
  90. # define PyObject_DEL PyObject_Del
  91. #endif
  92. /* A crude PyExc_StopIteration exception for old Pythons */
  93. #if PY_VERSION_HEX < 0x02020000
  94. # ifndef PyExc_StopIteration
  95. # define PyExc_StopIteration PyExc_RuntimeError
  96. # endif
  97. # ifndef PyObject_GenericGetAttr
  98. # define PyObject_GenericGetAttr 0
  99. # endif
  100. #endif
  101. /* Py_NotImplemented is defined in 2.1 and up. */
  102. #if PY_VERSION_HEX < 0x02010000
  103. # ifndef Py_NotImplemented
  104. # define Py_NotImplemented PyExc_RuntimeError
  105. # endif
  106. #endif
  107. /* A crude PyString_AsStringAndSize implementation for old Pythons */
  108. #if PY_VERSION_HEX < 0x02010000
  109. # ifndef PyString_AsStringAndSize
  110. # define PyString_AsStringAndSize(obj, s, len) {*s = PyString_AsString(obj); *len = *s ? strlen(*s) : 0;}
  111. # endif
  112. #endif
  113. /* PySequence_Size for old Pythons */
  114. #if PY_VERSION_HEX < 0x02000000
  115. # ifndef PySequence_Size
  116. # define PySequence_Size PySequence_Length
  117. # endif
  118. #endif
  119. /* PyBool_FromLong for old Pythons */
  120. #if PY_VERSION_HEX < 0x02030000
  121. static
  122. PyObject *PyBool_FromLong(long ok)
  123. {
  124. PyObject *result = ok ? Py_True : Py_False;
  125. Py_INCREF(result);
  126. return result;
  127. }
  128. #endif
  129. /* Py_ssize_t for old Pythons */
  130. /* This code is as recommended by: */
  131. /* http://www.python.org/dev/peps/pep-0353/#conversion-guidelines */
  132. #if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
  133. typedef int Py_ssize_t;
  134. # define PY_SSIZE_T_MAX INT_MAX
  135. # define PY_SSIZE_T_MIN INT_MIN
  136. typedef inquiry lenfunc;
  137. typedef intargfunc ssizeargfunc;
  138. typedef intintargfunc ssizessizeargfunc;
  139. typedef intobjargproc ssizeobjargproc;
  140. typedef intintobjargproc ssizessizeobjargproc;
  141. typedef getreadbufferproc readbufferproc;
  142. typedef getwritebufferproc writebufferproc;
  143. typedef getsegcountproc segcountproc;
  144. typedef getcharbufferproc charbufferproc;
  145. static long PyNumber_AsSsize_t (PyObject *x, void *SWIGUNUSEDPARM(exc))
  146. {
  147. long result = 0;
  148. PyObject *i = PyNumber_Int(x);
  149. if (i) {
  150. result = PyInt_AsLong(i);
  151. Py_DECREF(i);
  152. }
  153. return result;
  154. }
  155. #endif
  156. #if PY_VERSION_HEX < 0x02040000
  157. #define Py_VISIT(op) \
  158. do { \
  159. if (op) { \
  160. int vret = visit((op), arg); \
  161. if (vret) \
  162. return vret; \
  163. } \
  164. } while (0)
  165. #endif
  166. #if PY_VERSION_HEX < 0x02030000
  167. typedef struct {
  168. PyTypeObject type;
  169. PyNumberMethods as_number;
  170. PyMappingMethods as_mapping;
  171. PySequenceMethods as_sequence;
  172. PyBufferProcs as_buffer;
  173. PyObject *name, *slots;
  174. } PyHeapTypeObject;
  175. #endif
  176. #if PY_VERSION_HEX < 0x02030000
  177. typedef destructor freefunc;
  178. #endif
  179. #if ((PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION > 6) || \
  180. (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION > 0) || \
  181. (PY_MAJOR_VERSION > 3))
  182. # define SWIGPY_USE_CAPSULE
  183. # define SWIGPY_CAPSULE_NAME ((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION ".type_pointer_capsule" SWIG_TYPE_TABLE_NAME)
  184. #endif
  185. #if PY_VERSION_HEX < 0x03020000
  186. #define PyDescr_TYPE(x) (((PyDescrObject *)(x))->d_type)
  187. #define PyDescr_NAME(x) (((PyDescrObject *)(x))->d_name)
  188. #endif