processing.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #ifndef PROCESSING_H
  2. #define PROCESSING_H
  3. #define PY_SSIZE_T_CLEAN
  4. #include "Python.h"
  5. #include "structmember.h"
  6. #include "pythread.h"
  7. /*
  8. * Platform includes and definitions
  9. */
  10. #ifdef MS_WINDOWS
  11. # define WIN32_LEAN_AND_MEAN
  12. # include <windows.h>
  13. # include <winsock2.h>
  14. # include <process.h>
  15. # define SEM_HANDLE HANDLE
  16. HANDLE duplicate_handle(HANDLE h);
  17. #else
  18. # include <unistd.h>
  19. # include <sys/socket.h>
  20. # include <arpa/inet.h>
  21. # if HAVE_SEM_OPEN
  22. # include <semaphore.h>
  23. # include <fcntl.h>
  24. typedef sem_t *SEM_HANDLE;
  25. # endif
  26. # define HANDLE int
  27. # define SOCKET int
  28. # define BOOL int
  29. # define UINT32 uint32_t
  30. # define INT32 int32_t
  31. # define TRUE 1
  32. # define FALSE 0
  33. # define INVALID_HANDLE_VALUE (-1)
  34. #endif
  35. /*
  36. * Make sure Py_ssize_t available
  37. */
  38. #if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
  39. typedef int Py_ssize_t;
  40. # define PY_SSIZE_T_MAX INT_MAX
  41. # define PY_SSIZE_T_MIN INT_MIN
  42. # define F_PY_SSIZE_T "i"
  43. # define PY_FORMAT_SIZE_T ""
  44. # define PyInt_FromSsize_t(n) PyInt_FromLong((long)n)
  45. #else
  46. # define F_PY_SSIZE_T "n"
  47. #endif
  48. /*
  49. * Format codes
  50. */
  51. #if SIZEOF_VOID_P == SIZEOF_LONG
  52. # define F_POINTER "k"
  53. # define T_POINTER T_ULONG
  54. #elif defined(HAVE_LONG_LONG) && (SIZEOF_VOID_P == SIZEOF_LONG_LONG)
  55. # define F_POINTER "K"
  56. # define T_POINTER T_ULONGLONG
  57. #else
  58. # error "can't find format code for unsigned integer of same size as void*"
  59. #endif
  60. #ifdef MS_WINDOWS
  61. # define F_HANDLE F_POINTER
  62. # define T_HANDLE T_POINTER
  63. # define F_SEM_HANDLE F_HANDLE
  64. # define T_SEM_HANDLE T_HANDLE
  65. # define F_DWORD "k"
  66. # define T_DWORD T_ULONG
  67. #else
  68. # define F_HANDLE "i"
  69. # define T_HANDLE T_INT
  70. # define F_SEM_HANDLE F_POINTER
  71. # define T_SEM_HANDLE T_POINTER
  72. #endif
  73. /*
  74. * Message length limited to 2**31-1
  75. */
  76. #define TOO_LONG(n) ((UINT32)n >= 0x7fffffff)
  77. /*
  78. * Error codes which can be returned by functions called without GIL
  79. */
  80. #define SUCCESS (0)
  81. #define STANDARD_ERROR (-1)
  82. #define MEMORY_ERROR (-1001)
  83. #define END_OF_FILE (-1002)
  84. #define EARLY_END_OF_FILE (-1003)
  85. #define BAD_MESSAGE_LENGTH (-1004)
  86. #define WSA_ERROR (-1005)
  87. #define EXCEPTION_HAS_BEEN_SET (-1006)
  88. PyObject *SetException(PyObject *Type, int num);
  89. /*
  90. * Externs
  91. */
  92. extern PyObject *dumpsFunction;
  93. extern PyObject *loadsFunction;
  94. extern PyObject *protocol;
  95. extern PyObject *BufferTooShort;
  96. extern PyTypeObject SemLockType;
  97. extern PyTypeObject ConnectionType;
  98. #ifdef MS_WINDOWS
  99. extern PyTypeObject PipeConnectionType;
  100. extern HANDLE hInterruptEvent;
  101. extern long main_thread;
  102. #endif
  103. #endif /* PROCESSING_H */