You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3443 lines
127 KiB

4 years ago
  1. /* Generated by Cython 0.28.5 */
  2. /* BEGIN: Cython Metadata
  3. {
  4. "distutils": {
  5. "depends": [],
  6. "name": "aiohttp._websocket",
  7. "sources": [
  8. "aiohttp/_websocket.pyx"
  9. ]
  10. },
  11. "module_name": "aiohttp._websocket"
  12. }
  13. END: Cython Metadata */
  14. #define PY_SSIZE_T_CLEAN
  15. #include "Python.h"
  16. #ifndef Py_PYTHON_H
  17. #error Python headers needed to compile C extensions, please install development version of Python.
  18. #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000)
  19. #error Cython requires Python 2.6+ or Python 3.3+.
  20. #else
  21. #define CYTHON_ABI "0_28_5"
  22. #define CYTHON_FUTURE_DIVISION 0
  23. #include <stddef.h>
  24. #ifndef offsetof
  25. #define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
  26. #endif
  27. #if !defined(WIN32) && !defined(MS_WINDOWS)
  28. #ifndef __stdcall
  29. #define __stdcall
  30. #endif
  31. #ifndef __cdecl
  32. #define __cdecl
  33. #endif
  34. #ifndef __fastcall
  35. #define __fastcall
  36. #endif
  37. #endif
  38. #ifndef DL_IMPORT
  39. #define DL_IMPORT(t) t
  40. #endif
  41. #ifndef DL_EXPORT
  42. #define DL_EXPORT(t) t
  43. #endif
  44. #define __PYX_COMMA ,
  45. #ifndef HAVE_LONG_LONG
  46. #if PY_VERSION_HEX >= 0x02070000
  47. #define HAVE_LONG_LONG
  48. #endif
  49. #endif
  50. #ifndef PY_LONG_LONG
  51. #define PY_LONG_LONG LONG_LONG
  52. #endif
  53. #ifndef Py_HUGE_VAL
  54. #define Py_HUGE_VAL HUGE_VAL
  55. #endif
  56. #ifdef PYPY_VERSION
  57. #define CYTHON_COMPILING_IN_PYPY 1
  58. #define CYTHON_COMPILING_IN_PYSTON 0
  59. #define CYTHON_COMPILING_IN_CPYTHON 0
  60. #undef CYTHON_USE_TYPE_SLOTS
  61. #define CYTHON_USE_TYPE_SLOTS 0
  62. #undef CYTHON_USE_PYTYPE_LOOKUP
  63. #define CYTHON_USE_PYTYPE_LOOKUP 0
  64. #if PY_VERSION_HEX < 0x03050000
  65. #undef CYTHON_USE_ASYNC_SLOTS
  66. #define CYTHON_USE_ASYNC_SLOTS 0
  67. #elif !defined(CYTHON_USE_ASYNC_SLOTS)
  68. #define CYTHON_USE_ASYNC_SLOTS 1
  69. #endif
  70. #undef CYTHON_USE_PYLIST_INTERNALS
  71. #define CYTHON_USE_PYLIST_INTERNALS 0
  72. #undef CYTHON_USE_UNICODE_INTERNALS
  73. #define CYTHON_USE_UNICODE_INTERNALS 0
  74. #undef CYTHON_USE_UNICODE_WRITER
  75. #define CYTHON_USE_UNICODE_WRITER 0
  76. #undef CYTHON_USE_PYLONG_INTERNALS
  77. #define CYTHON_USE_PYLONG_INTERNALS 0
  78. #undef CYTHON_AVOID_BORROWED_REFS
  79. #define CYTHON_AVOID_BORROWED_REFS 1
  80. #undef CYTHON_ASSUME_SAFE_MACROS
  81. #define CYTHON_ASSUME_SAFE_MACROS 0
  82. #undef CYTHON_UNPACK_METHODS
  83. #define CYTHON_UNPACK_METHODS 0
  84. #undef CYTHON_FAST_THREAD_STATE
  85. #define CYTHON_FAST_THREAD_STATE 0
  86. #undef CYTHON_FAST_PYCALL
  87. #define CYTHON_FAST_PYCALL 0
  88. #undef CYTHON_PEP489_MULTI_PHASE_INIT
  89. #define CYTHON_PEP489_MULTI_PHASE_INIT 0
  90. #undef CYTHON_USE_TP_FINALIZE
  91. #define CYTHON_USE_TP_FINALIZE 0
  92. #elif defined(PYSTON_VERSION)
  93. #define CYTHON_COMPILING_IN_PYPY 0
  94. #define CYTHON_COMPILING_IN_PYSTON 1
  95. #define CYTHON_COMPILING_IN_CPYTHON 0
  96. #ifndef CYTHON_USE_TYPE_SLOTS
  97. #define CYTHON_USE_TYPE_SLOTS 1
  98. #endif
  99. #undef CYTHON_USE_PYTYPE_LOOKUP
  100. #define CYTHON_USE_PYTYPE_LOOKUP 0
  101. #undef CYTHON_USE_ASYNC_SLOTS
  102. #define CYTHON_USE_ASYNC_SLOTS 0
  103. #undef CYTHON_USE_PYLIST_INTERNALS
  104. #define CYTHON_USE_PYLIST_INTERNALS 0
  105. #ifndef CYTHON_USE_UNICODE_INTERNALS
  106. #define CYTHON_USE_UNICODE_INTERNALS 1
  107. #endif
  108. #undef CYTHON_USE_UNICODE_WRITER
  109. #define CYTHON_USE_UNICODE_WRITER 0
  110. #undef CYTHON_USE_PYLONG_INTERNALS
  111. #define CYTHON_USE_PYLONG_INTERNALS 0
  112. #ifndef CYTHON_AVOID_BORROWED_REFS
  113. #define CYTHON_AVOID_BORROWED_REFS 0
  114. #endif
  115. #ifndef CYTHON_ASSUME_SAFE_MACROS
  116. #define CYTHON_ASSUME_SAFE_MACROS 1
  117. #endif
  118. #ifndef CYTHON_UNPACK_METHODS
  119. #define CYTHON_UNPACK_METHODS 1
  120. #endif
  121. #undef CYTHON_FAST_THREAD_STATE
  122. #define CYTHON_FAST_THREAD_STATE 0
  123. #undef CYTHON_FAST_PYCALL
  124. #define CYTHON_FAST_PYCALL 0
  125. #undef CYTHON_PEP489_MULTI_PHASE_INIT
  126. #define CYTHON_PEP489_MULTI_PHASE_INIT 0
  127. #undef CYTHON_USE_TP_FINALIZE
  128. #define CYTHON_USE_TP_FINALIZE 0
  129. #else
  130. #define CYTHON_COMPILING_IN_PYPY 0
  131. #define CYTHON_COMPILING_IN_PYSTON 0
  132. #define CYTHON_COMPILING_IN_CPYTHON 1
  133. #ifndef CYTHON_USE_TYPE_SLOTS
  134. #define CYTHON_USE_TYPE_SLOTS 1
  135. #endif
  136. #if PY_VERSION_HEX < 0x02070000
  137. #undef CYTHON_USE_PYTYPE_LOOKUP
  138. #define CYTHON_USE_PYTYPE_LOOKUP 0
  139. #elif !defined(CYTHON_USE_PYTYPE_LOOKUP)
  140. #define CYTHON_USE_PYTYPE_LOOKUP 1
  141. #endif
  142. #if PY_MAJOR_VERSION < 3
  143. #undef CYTHON_USE_ASYNC_SLOTS
  144. #define CYTHON_USE_ASYNC_SLOTS 0
  145. #elif !defined(CYTHON_USE_ASYNC_SLOTS)
  146. #define CYTHON_USE_ASYNC_SLOTS 1
  147. #endif
  148. #if PY_VERSION_HEX < 0x02070000
  149. #undef CYTHON_USE_PYLONG_INTERNALS
  150. #define CYTHON_USE_PYLONG_INTERNALS 0
  151. #elif !defined(CYTHON_USE_PYLONG_INTERNALS)
  152. #define CYTHON_USE_PYLONG_INTERNALS 1
  153. #endif
  154. #ifndef CYTHON_USE_PYLIST_INTERNALS
  155. #define CYTHON_USE_PYLIST_INTERNALS 1
  156. #endif
  157. #ifndef CYTHON_USE_UNICODE_INTERNALS
  158. #define CYTHON_USE_UNICODE_INTERNALS 1
  159. #endif
  160. #if PY_VERSION_HEX < 0x030300F0
  161. #undef CYTHON_USE_UNICODE_WRITER
  162. #define CYTHON_USE_UNICODE_WRITER 0
  163. #elif !defined(CYTHON_USE_UNICODE_WRITER)
  164. #define CYTHON_USE_UNICODE_WRITER 1
  165. #endif
  166. #ifndef CYTHON_AVOID_BORROWED_REFS
  167. #define CYTHON_AVOID_BORROWED_REFS 0
  168. #endif
  169. #ifndef CYTHON_ASSUME_SAFE_MACROS
  170. #define CYTHON_ASSUME_SAFE_MACROS 1
  171. #endif
  172. #ifndef CYTHON_UNPACK_METHODS
  173. #define CYTHON_UNPACK_METHODS 1
  174. #endif
  175. #ifndef CYTHON_FAST_THREAD_STATE
  176. #define CYTHON_FAST_THREAD_STATE 1
  177. #endif
  178. #ifndef CYTHON_FAST_PYCALL
  179. #define CYTHON_FAST_PYCALL 1
  180. #endif
  181. #ifndef CYTHON_PEP489_MULTI_PHASE_INIT
  182. #define CYTHON_PEP489_MULTI_PHASE_INIT (0 && PY_VERSION_HEX >= 0x03050000)
  183. #endif
  184. #ifndef CYTHON_USE_TP_FINALIZE
  185. #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1)
  186. #endif
  187. #endif
  188. #if !defined(CYTHON_FAST_PYCCALL)
  189. #define CYTHON_FAST_PYCCALL (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1)
  190. #endif
  191. #if CYTHON_USE_PYLONG_INTERNALS
  192. #include "longintrepr.h"
  193. #undef SHIFT
  194. #undef BASE
  195. #undef MASK
  196. #endif
  197. #ifndef __has_attribute
  198. #define __has_attribute(x) 0
  199. #endif
  200. #ifndef __has_cpp_attribute
  201. #define __has_cpp_attribute(x) 0
  202. #endif
  203. #ifndef CYTHON_RESTRICT
  204. #if defined(__GNUC__)
  205. #define CYTHON_RESTRICT __restrict__
  206. #elif defined(_MSC_VER) && _MSC_VER >= 1400
  207. #define CYTHON_RESTRICT __restrict
  208. #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  209. #define CYTHON_RESTRICT restrict
  210. #else
  211. #define CYTHON_RESTRICT
  212. #endif
  213. #endif
  214. #ifndef CYTHON_UNUSED
  215. # if defined(__GNUC__)
  216. # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
  217. # define CYTHON_UNUSED __attribute__ ((__unused__))
  218. # else
  219. # define CYTHON_UNUSED
  220. # endif
  221. # elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
  222. # define CYTHON_UNUSED __attribute__ ((__unused__))
  223. # else
  224. # define CYTHON_UNUSED
  225. # endif
  226. #endif
  227. #ifndef CYTHON_MAYBE_UNUSED_VAR
  228. # if defined(__cplusplus)
  229. template<class T> void CYTHON_MAYBE_UNUSED_VAR( const T& ) { }
  230. # else
  231. # define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x)
  232. # endif
  233. #endif
  234. #ifndef CYTHON_NCP_UNUSED
  235. # if CYTHON_COMPILING_IN_CPYTHON
  236. # define CYTHON_NCP_UNUSED
  237. # else
  238. # define CYTHON_NCP_UNUSED CYTHON_UNUSED
  239. # endif
  240. #endif
  241. #define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None)
  242. #ifdef _MSC_VER
  243. #ifndef _MSC_STDINT_H_
  244. #if _MSC_VER < 1300
  245. typedef unsigned char uint8_t;
  246. typedef unsigned int uint32_t;
  247. #else
  248. typedef unsigned __int8 uint8_t;
  249. typedef unsigned __int32 uint32_t;
  250. #endif
  251. #endif
  252. #else
  253. #include <stdint.h>
  254. #endif
  255. #ifndef CYTHON_FALLTHROUGH
  256. #if defined(__cplusplus) && __cplusplus >= 201103L
  257. #if __has_cpp_attribute(fallthrough)
  258. #define CYTHON_FALLTHROUGH [[fallthrough]]
  259. #elif __has_cpp_attribute(clang::fallthrough)
  260. #define CYTHON_FALLTHROUGH [[clang::fallthrough]]
  261. #elif __has_cpp_attribute(gnu::fallthrough)
  262. #define CYTHON_FALLTHROUGH [[gnu::fallthrough]]
  263. #endif
  264. #endif
  265. #ifndef CYTHON_FALLTHROUGH
  266. #if __has_attribute(fallthrough)
  267. #define CYTHON_FALLTHROUGH __attribute__((fallthrough))
  268. #else
  269. #define CYTHON_FALLTHROUGH
  270. #endif
  271. #endif
  272. #if defined(__clang__ ) && defined(__apple_build_version__)
  273. #if __apple_build_version__ < 7000000
  274. #undef CYTHON_FALLTHROUGH
  275. #define CYTHON_FALLTHROUGH
  276. #endif
  277. #endif
  278. #endif
  279. #ifndef CYTHON_INLINE
  280. #if defined(__clang__)
  281. #define CYTHON_INLINE __inline__ __attribute__ ((__unused__))
  282. #elif defined(__GNUC__)
  283. #define CYTHON_INLINE __inline__
  284. #elif defined(_MSC_VER)
  285. #define CYTHON_INLINE __inline
  286. #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  287. #define CYTHON_INLINE inline
  288. #else
  289. #define CYTHON_INLINE
  290. #endif
  291. #endif
  292. #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
  293. #define Py_OptimizeFlag 0
  294. #endif
  295. #define __PYX_BUILD_PY_SSIZE_T "n"
  296. #define CYTHON_FORMAT_SSIZE_T "z"
  297. #if PY_MAJOR_VERSION < 3
  298. #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
  299. #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
  300. PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  301. #define __Pyx_DefaultClassType PyClass_Type
  302. #else
  303. #define __Pyx_BUILTIN_MODULE_NAME "builtins"
  304. #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
  305. PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  306. #define __Pyx_DefaultClassType PyType_Type
  307. #endif
  308. #ifndef Py_TPFLAGS_CHECKTYPES
  309. #define Py_TPFLAGS_CHECKTYPES 0
  310. #endif
  311. #ifndef Py_TPFLAGS_HAVE_INDEX
  312. #define Py_TPFLAGS_HAVE_INDEX 0
  313. #endif
  314. #ifndef Py_TPFLAGS_HAVE_NEWBUFFER
  315. #define Py_TPFLAGS_HAVE_NEWBUFFER 0
  316. #endif
  317. #ifndef Py_TPFLAGS_HAVE_FINALIZE
  318. #define Py_TPFLAGS_HAVE_FINALIZE 0
  319. #endif
  320. #if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL)
  321. #ifndef METH_FASTCALL
  322. #define METH_FASTCALL 0x80
  323. #endif
  324. typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs);
  325. typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args,
  326. Py_ssize_t nargs, PyObject *kwnames);
  327. #else
  328. #define __Pyx_PyCFunctionFast _PyCFunctionFast
  329. #define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords
  330. #endif
  331. #if CYTHON_FAST_PYCCALL
  332. #define __Pyx_PyFastCFunction_Check(func)\
  333. ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS)))))
  334. #else
  335. #define __Pyx_PyFastCFunction_Check(func) 0
  336. #endif
  337. #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc)
  338. #define PyObject_Malloc(s) PyMem_Malloc(s)
  339. #define PyObject_Free(p) PyMem_Free(p)
  340. #define PyObject_Realloc(p) PyMem_Realloc(p)
  341. #endif
  342. #if CYTHON_COMPILING_IN_PYSTON
  343. #define __Pyx_PyCode_HasFreeVars(co) PyCode_HasFreeVars(co)
  344. #define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno)
  345. #else
  346. #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0)
  347. #define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno)
  348. #endif
  349. #if !CYTHON_FAST_THREAD_STATE || PY_VERSION_HEX < 0x02070000
  350. #define __Pyx_PyThreadState_Current PyThreadState_GET()
  351. #elif PY_VERSION_HEX >= 0x03060000
  352. #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet()
  353. #elif PY_VERSION_HEX >= 0x03000000
  354. #define __Pyx_PyThreadState_Current PyThreadState_GET()
  355. #else
  356. #define __Pyx_PyThreadState_Current _PyThreadState_Current
  357. #endif
  358. #if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT)
  359. #include "pythread.h"
  360. #define Py_tss_NEEDS_INIT 0
  361. typedef int Py_tss_t;
  362. static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) {
  363. *key = PyThread_create_key();
  364. return 0; // PyThread_create_key reports success always
  365. }
  366. static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) {
  367. Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t));
  368. *key = Py_tss_NEEDS_INIT;
  369. return key;
  370. }
  371. static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) {
  372. PyObject_Free(key);
  373. }
  374. static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) {
  375. return *key != Py_tss_NEEDS_INIT;
  376. }
  377. static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) {
  378. PyThread_delete_key(*key);
  379. *key = Py_tss_NEEDS_INIT;
  380. }
  381. static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) {
  382. return PyThread_set_key_value(*key, value);
  383. }
  384. static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
  385. return PyThread_get_key_value(*key);
  386. }
  387. #endif // TSS (Thread Specific Storage) API
  388. #if CYTHON_COMPILING_IN_CPYTHON || defined(_PyDict_NewPresized)
  389. #define __Pyx_PyDict_NewPresized(n) ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n))
  390. #else
  391. #define __Pyx_PyDict_NewPresized(n) PyDict_New()
  392. #endif
  393. #if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION
  394. #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y)
  395. #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y)
  396. #else
  397. #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y)
  398. #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y)
  399. #endif
  400. #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && CYTHON_USE_UNICODE_INTERNALS
  401. #define __Pyx_PyDict_GetItemStr(dict, name) _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash)
  402. #else
  403. #define __Pyx_PyDict_GetItemStr(dict, name) PyDict_GetItem(dict, name)
  404. #endif
  405. #if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
  406. #define CYTHON_PEP393_ENABLED 1
  407. #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\
  408. 0 : _PyUnicode_Ready((PyObject *)(op)))
  409. #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u)
  410. #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
  411. #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) PyUnicode_MAX_CHAR_VALUE(u)
  412. #define __Pyx_PyUnicode_KIND(u) PyUnicode_KIND(u)
  413. #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u)
  414. #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i)
  415. #define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, ch)
  416. #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
  417. #else
  418. #define CYTHON_PEP393_ENABLED 0
  419. #define PyUnicode_1BYTE_KIND 1
  420. #define PyUnicode_2BYTE_KIND 2
  421. #define PyUnicode_4BYTE_KIND 4
  422. #define __Pyx_PyUnicode_READY(op) (0)
  423. #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u)
  424. #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
  425. #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111)
  426. #define __Pyx_PyUnicode_KIND(u) (sizeof(Py_UNICODE))
  427. #define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u))
  428. #define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
  429. #define __Pyx_PyUnicode_WRITE(k, d, i, ch) (((void)(k)), ((Py_UNICODE*)d)[i] = ch)
  430. #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_SIZE(u))
  431. #endif
  432. #if CYTHON_COMPILING_IN_PYPY
  433. #define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b)
  434. #define __Pyx_PyUnicode_ConcatSafe(a, b) PyNumber_Add(a, b)
  435. #else
  436. #define __Pyx_PyUnicode_Concat(a, b) PyUnicode_Concat(a, b)
  437. #define __Pyx_PyUnicode_ConcatSafe(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\
  438. PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b))
  439. #endif
  440. #if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains)
  441. #define PyUnicode_Contains(u, s) PySequence_Contains(u, s)
  442. #endif
  443. #if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check)
  444. #define PyByteArray_Check(obj) PyObject_TypeCheck(obj, &PyByteArray_Type)
  445. #endif
  446. #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format)
  447. #define PyObject_Format(obj, fmt) PyObject_CallMethod(obj, "__format__", "O", fmt)
  448. #endif
  449. #define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
  450. #define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
  451. #if PY_MAJOR_VERSION >= 3
  452. #define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b)
  453. #else
  454. #define __Pyx_PyString_Format(a, b) PyString_Format(a, b)
  455. #endif
  456. #if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII)
  457. #define PyObject_ASCII(o) PyObject_Repr(o)
  458. #endif
  459. #if PY_MAJOR_VERSION >= 3
  460. #define PyBaseString_Type PyUnicode_Type
  461. #define PyStringObject PyUnicodeObject
  462. #define PyString_Type PyUnicode_Type
  463. #define PyString_Check PyUnicode_Check
  464. #define PyString_CheckExact PyUnicode_CheckExact
  465. #define PyObject_Unicode PyObject_Str
  466. #endif
  467. #if PY_MAJOR_VERSION >= 3
  468. #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj)
  469. #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj)
  470. #else
  471. #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj))
  472. #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
  473. #endif
  474. #ifndef PySet_CheckExact
  475. #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type)
  476. #endif
  477. #if CYTHON_ASSUME_SAFE_MACROS
  478. #define __Pyx_PySequence_SIZE(seq) Py_SIZE(seq)
  479. #else
  480. #define __Pyx_PySequence_SIZE(seq) PySequence_Size(seq)
  481. #endif
  482. #if PY_MAJOR_VERSION >= 3
  483. #define PyIntObject PyLongObject
  484. #define PyInt_Type PyLong_Type
  485. #define PyInt_Check(op) PyLong_Check(op)
  486. #define PyInt_CheckExact(op) PyLong_CheckExact(op)
  487. #define PyInt_FromString PyLong_FromString
  488. #define PyInt_FromUnicode PyLong_FromUnicode
  489. #define PyInt_FromLong PyLong_FromLong
  490. #define PyInt_FromSize_t PyLong_FromSize_t
  491. #define PyInt_FromSsize_t PyLong_FromSsize_t
  492. #define PyInt_AsLong PyLong_AsLong
  493. #define PyInt_AS_LONG PyLong_AS_LONG
  494. #define PyInt_AsSsize_t PyLong_AsSsize_t
  495. #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask
  496. #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
  497. #define PyNumber_Int PyNumber_Long
  498. #endif
  499. #if PY_MAJOR_VERSION >= 3
  500. #define PyBoolObject PyLongObject
  501. #endif
  502. #if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY
  503. #ifndef PyUnicode_InternFromString
  504. #define PyUnicode_InternFromString(s) PyUnicode_FromString(s)
  505. #endif
  506. #endif
  507. #if PY_VERSION_HEX < 0x030200A4
  508. typedef long Py_hash_t;
  509. #define __Pyx_PyInt_FromHash_t PyInt_FromLong
  510. #define __Pyx_PyInt_AsHash_t PyInt_AsLong
  511. #else
  512. #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
  513. #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t
  514. #endif
  515. #if PY_MAJOR_VERSION >= 3
  516. #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : (Py_INCREF(func), func))
  517. #else
  518. #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
  519. #endif
  520. #if CYTHON_USE_ASYNC_SLOTS
  521. #if PY_VERSION_HEX >= 0x030500B1
  522. #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
  523. #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
  524. #else
  525. #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
  526. #endif
  527. #else
  528. #define __Pyx_PyType_AsAsync(obj) NULL
  529. #endif
  530. #ifndef __Pyx_PyAsyncMethodsStruct
  531. typedef struct {
  532. unaryfunc am_await;
  533. unaryfunc am_aiter;
  534. unaryfunc am_anext;
  535. } __Pyx_PyAsyncMethodsStruct;
  536. #endif
  537. #if defined(WIN32) || defined(MS_WINDOWS)
  538. #define _USE_MATH_DEFINES
  539. #endif
  540. #include <math.h>
  541. #ifdef NAN
  542. #define __PYX_NAN() ((float) NAN)
  543. #else
  544. static CYTHON_INLINE float __PYX_NAN() {
  545. float value;
  546. memset(&value, 0xFF, sizeof(value));
  547. return value;
  548. }
  549. #endif
  550. #if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL)
  551. #define __Pyx_truncl trunc
  552. #else
  553. #define __Pyx_truncl truncl
  554. #endif
  555. #define __PYX_ERR(f_index, lineno, Ln_error) \
  556. { \
  557. __pyx_filename = __pyx_f[f_index]; __pyx_lineno = lineno; __pyx_clineno = __LINE__; goto Ln_error; \
  558. }
  559. #ifndef __PYX_EXTERN_C
  560. #ifdef __cplusplus
  561. #define __PYX_EXTERN_C extern "C"
  562. #else
  563. #define __PYX_EXTERN_C extern
  564. #endif
  565. #endif
  566. #define __PYX_HAVE__aiohttp___websocket
  567. #define __PYX_HAVE_API__aiohttp___websocket
  568. /* Early includes */
  569. #include <string.h>
  570. #include <stdio.h>
  571. #include "pythread.h"
  572. #include <stdint.h>
  573. #ifdef _OPENMP
  574. #include <omp.h>
  575. #endif /* _OPENMP */
  576. #if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS)
  577. #define CYTHON_WITHOUT_ASSERTIONS
  578. #endif
  579. typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding;
  580. const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry;
  581. #define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0
  582. #define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 0
  583. #define __PYX_DEFAULT_STRING_ENCODING ""
  584. #define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString
  585. #define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
  586. #define __Pyx_uchar_cast(c) ((unsigned char)c)
  587. #define __Pyx_long_cast(x) ((long)x)
  588. #define __Pyx_fits_Py_ssize_t(v, type, is_signed) (\
  589. (sizeof(type) < sizeof(Py_ssize_t)) ||\
  590. (sizeof(type) > sizeof(Py_ssize_t) &&\
  591. likely(v < (type)PY_SSIZE_T_MAX ||\
  592. v == (type)PY_SSIZE_T_MAX) &&\
  593. (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\
  594. v == (type)PY_SSIZE_T_MIN))) ||\
  595. (sizeof(type) == sizeof(Py_ssize_t) &&\
  596. (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\
  597. v == (type)PY_SSIZE_T_MAX))) )
  598. #if defined (__cplusplus) && __cplusplus >= 201103L
  599. #include <cstdlib>
  600. #define __Pyx_sst_abs(value) std::abs(value)
  601. #elif SIZEOF_INT >= SIZEOF_SIZE_T
  602. #define __Pyx_sst_abs(value) abs(value)
  603. #elif SIZEOF_LONG >= SIZEOF_SIZE_T
  604. #define __Pyx_sst_abs(value) labs(value)
  605. #elif defined (_MSC_VER)
  606. #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value))
  607. #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  608. #define __Pyx_sst_abs(value) llabs(value)
  609. #elif defined (__GNUC__)
  610. #define __Pyx_sst_abs(value) __builtin_llabs(value)
  611. #else
  612. #define __Pyx_sst_abs(value) ((value<0) ? -value : value)
  613. #endif
  614. static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*);
  615. static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
  616. #define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s))
  617. #define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l)
  618. #define __Pyx_PyBytes_FromString PyBytes_FromString
  619. #define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
  620. static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*);
  621. #if PY_MAJOR_VERSION < 3
  622. #define __Pyx_PyStr_FromString __Pyx_PyBytes_FromString
  623. #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
  624. #else
  625. #define __Pyx_PyStr_FromString __Pyx_PyUnicode_FromString
  626. #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize
  627. #endif
  628. #define __Pyx_PyBytes_AsWritableString(s) ((char*) PyBytes_AS_STRING(s))
  629. #define __Pyx_PyBytes_AsWritableSString(s) ((signed char*) PyBytes_AS_STRING(s))
  630. #define __Pyx_PyBytes_AsWritableUString(s) ((unsigned char*) PyBytes_AS_STRING(s))
  631. #define __Pyx_PyBytes_AsString(s) ((const char*) PyBytes_AS_STRING(s))
  632. #define __Pyx_PyBytes_AsSString(s) ((const signed char*) PyBytes_AS_STRING(s))
  633. #define __Pyx_PyBytes_AsUString(s) ((const unsigned char*) PyBytes_AS_STRING(s))
  634. #define __Pyx_PyObject_AsWritableString(s) ((char*) __Pyx_PyObject_AsString(s))
  635. #define __Pyx_PyObject_AsWritableSString(s) ((signed char*) __Pyx_PyObject_AsString(s))
  636. #define __Pyx_PyObject_AsWritableUString(s) ((unsigned char*) __Pyx_PyObject_AsString(s))
  637. #define __Pyx_PyObject_AsSString(s) ((const signed char*) __Pyx_PyObject_AsString(s))
  638. #define __Pyx_PyObject_AsUString(s) ((const unsigned char*) __Pyx_PyObject_AsString(s))
  639. #define __Pyx_PyObject_FromCString(s) __Pyx_PyObject_FromString((const char*)s)
  640. #define __Pyx_PyBytes_FromCString(s) __Pyx_PyBytes_FromString((const char*)s)
  641. #define __Pyx_PyByteArray_FromCString(s) __Pyx_PyByteArray_FromString((const char*)s)
  642. #define __Pyx_PyStr_FromCString(s) __Pyx_PyStr_FromString((const char*)s)
  643. #define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s)
  644. static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) {
  645. const Py_UNICODE *u_end = u;
  646. while (*u_end++) ;
  647. return (size_t)(u_end - u - 1);
  648. }
  649. #define __Pyx_PyUnicode_FromUnicode(u) PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u))
  650. #define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode
  651. #define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode
  652. #define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)
  653. #define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None)
  654. static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b);
  655. static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
  656. static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x);
  657. #define __Pyx_PySequence_Tuple(obj)\
  658. (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj))
  659. static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
  660. static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
  661. #if CYTHON_ASSUME_SAFE_MACROS
  662. #define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
  663. #else
  664. #define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
  665. #endif
  666. #define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
  667. #if PY_MAJOR_VERSION >= 3
  668. #define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x))
  669. #else
  670. #define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x))
  671. #endif
  672. #define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x))
  673. #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
  674. static int __Pyx_sys_getdefaultencoding_not_ascii;
  675. static int __Pyx_init_sys_getdefaultencoding_params(void) {
  676. PyObject* sys;
  677. PyObject* default_encoding = NULL;
  678. PyObject* ascii_chars_u = NULL;
  679. PyObject* ascii_chars_b = NULL;
  680. const char* default_encoding_c;
  681. sys = PyImport_ImportModule("sys");
  682. if (!sys) goto bad;
  683. default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL);
  684. Py_DECREF(sys);
  685. if (!default_encoding) goto bad;
  686. default_encoding_c = PyBytes_AsString(default_encoding);
  687. if (!default_encoding_c) goto bad;
  688. if (strcmp(default_encoding_c, "ascii") == 0) {
  689. __Pyx_sys_getdefaultencoding_not_ascii = 0;
  690. } else {
  691. char ascii_chars[128];
  692. int c;
  693. for (c = 0; c < 128; c++) {
  694. ascii_chars[c] = c;
  695. }
  696. __Pyx_sys_getdefaultencoding_not_ascii = 1;
  697. ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL);
  698. if (!ascii_chars_u) goto bad;
  699. ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL);
  700. if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) {
  701. PyErr_Format(
  702. PyExc_ValueError,
  703. "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.",
  704. default_encoding_c);
  705. goto bad;
  706. }
  707. Py_DECREF(ascii_chars_u);
  708. Py_DECREF(ascii_chars_b);
  709. }
  710. Py_DECREF(default_encoding);
  711. return 0;
  712. bad:
  713. Py_XDECREF(default_encoding);
  714. Py_XDECREF(ascii_chars_u);
  715. Py_XDECREF(ascii_chars_b);
  716. return -1;
  717. }
  718. #endif
  719. #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3
  720. #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL)
  721. #else
  722. #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL)
  723. #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
  724. static char* __PYX_DEFAULT_STRING_ENCODING;
  725. static int __Pyx_init_sys_getdefaultencoding_params(void) {
  726. PyObject* sys;
  727. PyObject* default_encoding = NULL;
  728. char* default_encoding_c;
  729. sys = PyImport_ImportModule("sys");
  730. if (!sys) goto bad;
  731. default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
  732. Py_DECREF(sys);
  733. if (!default_encoding) goto bad;
  734. default_encoding_c = PyBytes_AsString(default_encoding);
  735. if (!default_encoding_c) goto bad;
  736. __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c));
  737. if (!__PYX_DEFAULT_STRING_ENCODING) goto bad;
  738. strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c);
  739. Py_DECREF(default_encoding);
  740. return 0;
  741. bad:
  742. Py_XDECREF(default_encoding);
  743. return -1;
  744. }
  745. #endif
  746. #endif
  747. /* Test for GCC > 2.95 */
  748. #if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)))
  749. #define likely(x) __builtin_expect(!!(x), 1)
  750. #define unlikely(x) __builtin_expect(!!(x), 0)
  751. #else /* !__GNUC__ or GCC < 2.95 */
  752. #define likely(x) (x)
  753. #define unlikely(x) (x)
  754. #endif /* __GNUC__ */
  755. static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; }
  756. static PyObject *__pyx_m = NULL;
  757. static PyObject *__pyx_d;
  758. static PyObject *__pyx_b;
  759. static PyObject *__pyx_cython_runtime = NULL;
  760. static PyObject *__pyx_empty_tuple;
  761. static PyObject *__pyx_empty_bytes;
  762. static PyObject *__pyx_empty_unicode;
  763. static int __pyx_lineno;
  764. static int __pyx_clineno = 0;
  765. static const char * __pyx_cfilenm= __FILE__;
  766. static const char *__pyx_filename;
  767. static const char *__pyx_f[] = {
  768. "aiohttp/_websocket.pyx",
  769. "type.pxd",
  770. "bool.pxd",
  771. "complex.pxd",
  772. };
  773. /*--- Type declarations ---*/
  774. /* --- Runtime support code (head) --- */
  775. /* Refnanny.proto */
  776. #ifndef CYTHON_REFNANNY
  777. #define CYTHON_REFNANNY 0
  778. #endif
  779. #if CYTHON_REFNANNY
  780. typedef struct {
  781. void (*INCREF)(void*, PyObject*, int);
  782. void (*DECREF)(void*, PyObject*, int);
  783. void (*GOTREF)(void*, PyObject*, int);
  784. void (*GIVEREF)(void*, PyObject*, int);
  785. void* (*SetupContext)(const char*, int, const char*);
  786. void (*FinishContext)(void**);
  787. } __Pyx_RefNannyAPIStruct;
  788. static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
  789. static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname);
  790. #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
  791. #ifdef WITH_THREAD
  792. #define __Pyx_RefNannySetupContext(name, acquire_gil)\
  793. if (acquire_gil) {\
  794. PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\
  795. __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
  796. PyGILState_Release(__pyx_gilstate_save);\
  797. } else {\
  798. __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
  799. }
  800. #else
  801. #define __Pyx_RefNannySetupContext(name, acquire_gil)\
  802. __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
  803. #endif
  804. #define __Pyx_RefNannyFinishContext()\
  805. __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
  806. #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  807. #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  808. #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  809. #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  810. #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
  811. #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
  812. #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
  813. #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
  814. #else
  815. #define __Pyx_RefNannyDeclarations
  816. #define __Pyx_RefNannySetupContext(name, acquire_gil)
  817. #define __Pyx_RefNannyFinishContext()
  818. #define __Pyx_INCREF(r) Py_INCREF(r)
  819. #define __Pyx_DECREF(r) Py_DECREF(r)
  820. #define __Pyx_GOTREF(r)
  821. #define __Pyx_GIVEREF(r)
  822. #define __Pyx_XINCREF(r) Py_XINCREF(r)
  823. #define __Pyx_XDECREF(r) Py_XDECREF(r)
  824. #define __Pyx_XGOTREF(r)
  825. #define __Pyx_XGIVEREF(r)
  826. #endif
  827. #define __Pyx_XDECREF_SET(r, v) do {\
  828. PyObject *tmp = (PyObject *) r;\
  829. r = v; __Pyx_XDECREF(tmp);\
  830. } while (0)
  831. #define __Pyx_DECREF_SET(r, v) do {\
  832. PyObject *tmp = (PyObject *) r;\
  833. r = v; __Pyx_DECREF(tmp);\
  834. } while (0)
  835. #define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
  836. #define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)
  837. /* PyObjectGetAttrStr.proto */
  838. #if CYTHON_USE_TYPE_SLOTS
  839. static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name);
  840. #else
  841. #define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
  842. #endif
  843. /* GetBuiltinName.proto */
  844. static PyObject *__Pyx_GetBuiltinName(PyObject *name);
  845. /* RaiseArgTupleInvalid.proto */
  846. static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
  847. Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found);
  848. /* RaiseDoubleKeywords.proto */
  849. static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name);
  850. /* ParseKeywords.proto */
  851. static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\
  852. PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\
  853. const char* function_name);
  854. /* PyCFunctionFastCall.proto */
  855. #if CYTHON_FAST_PYCCALL
  856. static CYTHON_INLINE PyObject *__Pyx_PyCFunction_FastCall(PyObject *func, PyObject **args, Py_ssize_t nargs);
  857. #else
  858. #define __Pyx_PyCFunction_FastCall(func, args, nargs) (assert(0), NULL)
  859. #endif
  860. /* PyFunctionFastCall.proto */
  861. #if CYTHON_FAST_PYCALL
  862. #define __Pyx_PyFunction_FastCall(func, args, nargs)\
  863. __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL)
  864. #if 1 || PY_VERSION_HEX < 0x030600B1
  865. static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwargs);
  866. #else
  867. #define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs)
  868. #endif
  869. #endif
  870. /* PyObjectCall.proto */
  871. #if CYTHON_COMPILING_IN_CPYTHON
  872. static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw);
  873. #else
  874. #define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw)
  875. #endif
  876. /* PyObjectCallMethO.proto */
  877. #if CYTHON_COMPILING_IN_CPYTHON
  878. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg);
  879. #endif
  880. /* PyObjectCallOneArg.proto */
  881. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg);
  882. /* PyThreadStateGet.proto */
  883. #if CYTHON_FAST_THREAD_STATE
  884. #define __Pyx_PyThreadState_declare PyThreadState *__pyx_tstate;
  885. #define __Pyx_PyThreadState_assign __pyx_tstate = __Pyx_PyThreadState_Current;
  886. #define __Pyx_PyErr_Occurred() __pyx_tstate->curexc_type
  887. #else
  888. #define __Pyx_PyThreadState_declare
  889. #define __Pyx_PyThreadState_assign
  890. #define __Pyx_PyErr_Occurred() PyErr_Occurred()
  891. #endif
  892. /* PyErrFetchRestore.proto */
  893. #if CYTHON_FAST_THREAD_STATE
  894. #define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL)
  895. #define __Pyx_ErrRestoreWithState(type, value, tb) __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb)
  896. #define __Pyx_ErrFetchWithState(type, value, tb) __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb)
  897. #define __Pyx_ErrRestore(type, value, tb) __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb)
  898. #define __Pyx_ErrFetch(type, value, tb) __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb)
  899. static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
  900. static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
  901. #if CYTHON_COMPILING_IN_CPYTHON
  902. #define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL))
  903. #else
  904. #define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
  905. #endif
  906. #else
  907. #define __Pyx_PyErr_Clear() PyErr_Clear()
  908. #define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
  909. #define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb)
  910. #define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb)
  911. #define __Pyx_ErrRestoreInState(tstate, type, value, tb) PyErr_Restore(type, value, tb)
  912. #define __Pyx_ErrFetchInState(tstate, type, value, tb) PyErr_Fetch(type, value, tb)
  913. #define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb)
  914. #define __Pyx_ErrFetch(type, value, tb) PyErr_Fetch(type, value, tb)
  915. #endif
  916. /* CLineInTraceback.proto */
  917. #ifdef CYTHON_CLINE_IN_TRACEBACK
  918. #define __Pyx_CLineForTraceback(tstate, c_line) (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0)
  919. #else
  920. static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line);
  921. #endif
  922. /* CodeObjectCache.proto */
  923. typedef struct {
  924. PyCodeObject* code_object;
  925. int code_line;
  926. } __Pyx_CodeObjectCacheEntry;
  927. struct __Pyx_CodeObjectCache {
  928. int count;
  929. int max_count;
  930. __Pyx_CodeObjectCacheEntry* entries;
  931. };
  932. static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL};
  933. static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
  934. static PyCodeObject *__pyx_find_code_object(int code_line);
  935. static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);
  936. /* AddTraceback.proto */
  937. static void __Pyx_AddTraceback(const char *funcname, int c_line,
  938. int py_line, const char *filename);
  939. /* CIntToPy.proto */
  940. static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);
  941. /* CIntFromPy.proto */
  942. static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);
  943. /* CIntFromPy.proto */
  944. static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);
  945. /* FastTypeChecks.proto */
  946. #if CYTHON_COMPILING_IN_CPYTHON
  947. #define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type)
  948. static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b);
  949. static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type);
  950. static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2);
  951. #else
  952. #define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
  953. #define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type)
  954. #define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2))
  955. #endif
  956. #define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception)
  957. /* CheckBinaryVersion.proto */
  958. static int __Pyx_check_binary_version(void);
  959. /* PyIdentifierFromString.proto */
  960. #if !defined(__Pyx_PyIdentifier_FromString)
  961. #if PY_MAJOR_VERSION < 3
  962. #define __Pyx_PyIdentifier_FromString(s) PyString_FromString(s)
  963. #else
  964. #define __Pyx_PyIdentifier_FromString(s) PyUnicode_FromString(s)
  965. #endif
  966. #endif
  967. /* ModuleImport.proto */
  968. static PyObject *__Pyx_ImportModule(const char *name);
  969. /* TypeImport.proto */
  970. static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, size_t size, int strict);
  971. /* InitStrings.proto */
  972. static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);
  973. /* Module declarations from 'cpython.version' */
  974. /* Module declarations from '__builtin__' */
  975. /* Module declarations from 'cpython.type' */
  976. static PyTypeObject *__pyx_ptype_7cpython_4type_type = 0;
  977. /* Module declarations from 'libc.string' */
  978. /* Module declarations from 'libc.stdio' */
  979. /* Module declarations from 'cpython.object' */
  980. /* Module declarations from 'cpython.ref' */
  981. /* Module declarations from 'cpython.exc' */
  982. /* Module declarations from 'cpython.module' */
  983. /* Module declarations from 'cpython.mem' */
  984. /* Module declarations from 'cpython.tuple' */
  985. /* Module declarations from 'cpython.list' */
  986. /* Module declarations from 'cpython.sequence' */
  987. /* Module declarations from 'cpython.mapping' */
  988. /* Module declarations from 'cpython.iterator' */
  989. /* Module declarations from 'cpython.number' */
  990. /* Module declarations from 'cpython.int' */
  991. /* Module declarations from '__builtin__' */
  992. /* Module declarations from 'cpython.bool' */
  993. static PyTypeObject *__pyx_ptype_7cpython_4bool_bool = 0;
  994. /* Module declarations from 'cpython.long' */
  995. /* Module declarations from 'cpython.float' */
  996. /* Module declarations from '__builtin__' */
  997. /* Module declarations from 'cpython.complex' */
  998. static PyTypeObject *__pyx_ptype_7cpython_7complex_complex = 0;
  999. /* Module declarations from 'cpython.string' */
  1000. /* Module declarations from 'cpython.unicode' */
  1001. /* Module declarations from 'cpython.dict' */
  1002. /* Module declarations from 'cpython.instance' */
  1003. /* Module declarations from 'cpython.function' */
  1004. /* Module declarations from 'cpython.method' */
  1005. /* Module declarations from 'cpython.weakref' */
  1006. /* Module declarations from 'cpython.getargs' */
  1007. /* Module declarations from 'cpython.pythread' */
  1008. /* Module declarations from 'cpython.pystate' */
  1009. /* Module declarations from 'cpython.cobject' */
  1010. /* Module declarations from 'cpython.oldbuffer' */
  1011. /* Module declarations from 'cpython.set' */
  1012. /* Module declarations from 'cpython.buffer' */
  1013. /* Module declarations from 'cpython.bytes' */
  1014. /* Module declarations from 'cpython.pycapsule' */
  1015. /* Module declarations from 'cpython' */
  1016. /* Module declarations from 'libc.stdint' */
  1017. /* Module declarations from 'aiohttp._websocket' */
  1018. #define __Pyx_MODULE_NAME "aiohttp._websocket"
  1019. extern int __pyx_module_is_main_aiohttp___websocket;
  1020. int __pyx_module_is_main_aiohttp___websocket = 0;
  1021. /* Implementation of 'aiohttp._websocket' */
  1022. static PyObject *__pyx_builtin_range;
  1023. static const char __pyx_k_i[] = "i";
  1024. static const char __pyx_k_data[] = "data";
  1025. static const char __pyx_k_main[] = "__main__";
  1026. static const char __pyx_k_mask[] = "mask";
  1027. static const char __pyx_k_test[] = "__test__";
  1028. static const char __pyx_k_range[] = "range";
  1029. static const char __pyx_k_in_buf[] = "in_buf";
  1030. static const char __pyx_k_data_len[] = "data_len";
  1031. static const char __pyx_k_mask_buf[] = "mask_buf";
  1032. static const char __pyx_k_uint32_msk[] = "uint32_msk";
  1033. static const char __pyx_k_uint64_msk[] = "uint64_msk";
  1034. static const char __pyx_k_aiohttp__websocket[] = "aiohttp._websocket";
  1035. static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback";
  1036. static const char __pyx_k_websocket_mask_cython[] = "_websocket_mask_cython";
  1037. static const char __pyx_k_aiohttp__websocket_pyx[] = "aiohttp/_websocket.pyx";
  1038. static PyObject *__pyx_n_s_aiohttp__websocket;
  1039. static PyObject *__pyx_kp_s_aiohttp__websocket_pyx;
  1040. static PyObject *__pyx_n_s_cline_in_traceback;
  1041. static PyObject *__pyx_n_s_data;
  1042. static PyObject *__pyx_n_s_data_len;
  1043. static PyObject *__pyx_n_s_i;
  1044. static PyObject *__pyx_n_s_in_buf;
  1045. static PyObject *__pyx_n_s_main;
  1046. static PyObject *__pyx_n_s_mask;
  1047. static PyObject *__pyx_n_s_mask_buf;
  1048. static PyObject *__pyx_n_s_range;
  1049. static PyObject *__pyx_n_s_test;
  1050. static PyObject *__pyx_n_s_uint32_msk;
  1051. static PyObject *__pyx_n_s_uint64_msk;
  1052. static PyObject *__pyx_n_s_websocket_mask_cython;
  1053. static PyObject *__pyx_pf_7aiohttp_10_websocket__websocket_mask_cython(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_mask, PyObject *__pyx_v_data); /* proto */
  1054. static PyObject *__pyx_tuple_;
  1055. static PyObject *__pyx_codeobj__2;
  1056. /* Late includes */
  1057. /* "aiohttp/_websocket.pyx":9
  1058. * from libc.stdint cimport uint32_t, uint64_t, uintmax_t
  1059. *
  1060. * def _websocket_mask_cython(object mask, object data): # <<<<<<<<<<<<<<
  1061. * """Note, this function mutates it's `data` argument
  1062. * """
  1063. */
  1064. /* Python wrapper */
  1065. static PyObject *__pyx_pw_7aiohttp_10_websocket_1_websocket_mask_cython(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
  1066. static char __pyx_doc_7aiohttp_10_websocket__websocket_mask_cython[] = "Note, this function mutates it's `data` argument\n ";
  1067. static PyMethodDef __pyx_mdef_7aiohttp_10_websocket_1_websocket_mask_cython = {"_websocket_mask_cython", (PyCFunction)__pyx_pw_7aiohttp_10_websocket_1_websocket_mask_cython, METH_VARARGS|METH_KEYWORDS, __pyx_doc_7aiohttp_10_websocket__websocket_mask_cython};
  1068. static PyObject *__pyx_pw_7aiohttp_10_websocket_1_websocket_mask_cython(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  1069. PyObject *__pyx_v_mask = 0;
  1070. PyObject *__pyx_v_data = 0;
  1071. PyObject *__pyx_r = 0;
  1072. __Pyx_RefNannyDeclarations
  1073. __Pyx_RefNannySetupContext("_websocket_mask_cython (wrapper)", 0);
  1074. {
  1075. static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_mask,&__pyx_n_s_data,0};
  1076. PyObject* values[2] = {0,0};
  1077. if (unlikely(__pyx_kwds)) {
  1078. Py_ssize_t kw_args;
  1079. const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
  1080. switch (pos_args) {
  1081. case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
  1082. CYTHON_FALLTHROUGH;
  1083. case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
  1084. CYTHON_FALLTHROUGH;
  1085. case 0: break;
  1086. default: goto __pyx_L5_argtuple_error;
  1087. }
  1088. kw_args = PyDict_Size(__pyx_kwds);
  1089. switch (pos_args) {
  1090. case 0:
  1091. if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mask)) != 0)) kw_args--;
  1092. else goto __pyx_L5_argtuple_error;
  1093. CYTHON_FALLTHROUGH;
  1094. case 1:
  1095. if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_data)) != 0)) kw_args--;
  1096. else {
  1097. __Pyx_RaiseArgtupleInvalid("_websocket_mask_cython", 1, 2, 2, 1); __PYX_ERR(0, 9, __pyx_L3_error)
  1098. }
  1099. }
  1100. if (unlikely(kw_args > 0)) {
  1101. if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_websocket_mask_cython") < 0)) __PYX_ERR(0, 9, __pyx_L3_error)
  1102. }
  1103. } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
  1104. goto __pyx_L5_argtuple_error;
  1105. } else {
  1106. values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
  1107. values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
  1108. }
  1109. __pyx_v_mask = values[0];
  1110. __pyx_v_data = values[1];
  1111. }
  1112. goto __pyx_L4_argument_unpacking_done;
  1113. __pyx_L5_argtuple_error:;
  1114. __Pyx_RaiseArgtupleInvalid("_websocket_mask_cython", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 9, __pyx_L3_error)
  1115. __pyx_L3_error:;
  1116. __Pyx_AddTraceback("aiohttp._websocket._websocket_mask_cython", __pyx_clineno, __pyx_lineno, __pyx_filename);
  1117. __Pyx_RefNannyFinishContext();
  1118. return NULL;
  1119. __pyx_L4_argument_unpacking_done:;
  1120. __pyx_r = __pyx_pf_7aiohttp_10_websocket__websocket_mask_cython(__pyx_self, __pyx_v_mask, __pyx_v_data);
  1121. /* function exit code */
  1122. __Pyx_RefNannyFinishContext();
  1123. return __pyx_r;
  1124. }
  1125. static PyObject *__pyx_pf_7aiohttp_10_websocket__websocket_mask_cython(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_mask, PyObject *__pyx_v_data) {
  1126. Py_ssize_t __pyx_v_data_len;
  1127. Py_ssize_t __pyx_v_i;
  1128. unsigned char *__pyx_v_in_buf;
  1129. unsigned char const *__pyx_v_mask_buf;
  1130. uint32_t __pyx_v_uint32_msk;
  1131. uint64_t __pyx_v_uint64_msk;
  1132. PyObject *__pyx_r = NULL;
  1133. __Pyx_RefNannyDeclarations
  1134. Py_ssize_t __pyx_t_1;
  1135. int __pyx_t_2;
  1136. int __pyx_t_3;
  1137. PyObject *__pyx_t_4 = NULL;
  1138. char *__pyx_t_5;
  1139. uint64_t *__pyx_t_6;
  1140. long __pyx_t_7;
  1141. uint32_t *__pyx_t_8;
  1142. Py_ssize_t __pyx_t_9;
  1143. Py_ssize_t __pyx_t_10;
  1144. Py_ssize_t __pyx_t_11;
  1145. __Pyx_RefNannySetupContext("_websocket_mask_cython", 0);
  1146. __Pyx_INCREF(__pyx_v_mask);
  1147. __Pyx_INCREF(__pyx_v_data);
  1148. /* "aiohttp/_websocket.pyx":20
  1149. * uint64_t uint64_msk
  1150. *
  1151. * assert len(mask) == 4 # <<<<<<<<<<<<<<
  1152. *
  1153. * if not isinstance(mask, bytes):
  1154. */
  1155. #ifndef CYTHON_WITHOUT_ASSERTIONS
  1156. if (unlikely(!Py_OptimizeFlag)) {
  1157. __pyx_t_1 = PyObject_Length(__pyx_v_mask); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 20, __pyx_L1_error)
  1158. if (unlikely(!((__pyx_t_1 == 4) != 0))) {
  1159. PyErr_SetNone(PyExc_AssertionError);
  1160. __PYX_ERR(0, 20, __pyx_L1_error)
  1161. }
  1162. }
  1163. #endif
  1164. /* "aiohttp/_websocket.pyx":22
  1165. * assert len(mask) == 4
  1166. *
  1167. * if not isinstance(mask, bytes): # <<<<<<<<<<<<<<
  1168. * mask = bytes(mask)
  1169. *
  1170. */
  1171. __pyx_t_2 = PyBytes_Check(__pyx_v_mask);
  1172. __pyx_t_3 = ((!(__pyx_t_2 != 0)) != 0);
  1173. if (__pyx_t_3) {
  1174. /* "aiohttp/_websocket.pyx":23
  1175. *
  1176. * if not isinstance(mask, bytes):
  1177. * mask = bytes(mask) # <<<<<<<<<<<<<<
  1178. *
  1179. * if isinstance(data, bytearray):
  1180. */
  1181. __pyx_t_4 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyBytes_Type)), __pyx_v_mask); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 23, __pyx_L1_error)
  1182. __Pyx_GOTREF(__pyx_t_4);
  1183. __Pyx_DECREF_SET(__pyx_v_mask, __pyx_t_4);
  1184. __pyx_t_4 = 0;
  1185. /* "aiohttp/_websocket.pyx":22
  1186. * assert len(mask) == 4
  1187. *
  1188. * if not isinstance(mask, bytes): # <<<<<<<<<<<<<<
  1189. * mask = bytes(mask)
  1190. *
  1191. */
  1192. }
  1193. /* "aiohttp/_websocket.pyx":25
  1194. * mask = bytes(mask)
  1195. *
  1196. * if isinstance(data, bytearray): # <<<<<<<<<<<<<<
  1197. * data = <bytearray>data
  1198. * else:
  1199. */
  1200. __pyx_t_3 = PyByteArray_Check(__pyx_v_data);
  1201. __pyx_t_2 = (__pyx_t_3 != 0);
  1202. if (__pyx_t_2) {
  1203. /* "aiohttp/_websocket.pyx":26
  1204. *
  1205. * if isinstance(data, bytearray):
  1206. * data = <bytearray>data # <<<<<<<<<<<<<<
  1207. * else:
  1208. * data = bytearray(data)
  1209. */
  1210. __pyx_t_4 = __pyx_v_data;
  1211. __Pyx_INCREF(__pyx_t_4);
  1212. __Pyx_DECREF_SET(__pyx_v_data, __pyx_t_4);
  1213. __pyx_t_4 = 0;
  1214. /* "aiohttp/_websocket.pyx":25
  1215. * mask = bytes(mask)
  1216. *
  1217. * if isinstance(data, bytearray): # <<<<<<<<<<<<<<
  1218. * data = <bytearray>data
  1219. * else:
  1220. */
  1221. goto __pyx_L4;
  1222. }
  1223. /* "aiohttp/_websocket.pyx":28
  1224. * data = <bytearray>data
  1225. * else:
  1226. * data = bytearray(data) # <<<<<<<<<<<<<<
  1227. *
  1228. * data_len = len(data)
  1229. */
  1230. /*else*/ {
  1231. __pyx_t_4 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyByteArray_Type)), __pyx_v_data); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 28, __pyx_L1_error)
  1232. __Pyx_GOTREF(__pyx_t_4);
  1233. __Pyx_DECREF_SET(__pyx_v_data, __pyx_t_4);
  1234. __pyx_t_4 = 0;
  1235. }
  1236. __pyx_L4:;
  1237. /* "aiohttp/_websocket.pyx":30
  1238. * data = bytearray(data)
  1239. *
  1240. * data_len = len(data) # <<<<<<<<<<<<<<
  1241. * in_buf = <unsigned char*>PyByteArray_AsString(data)
  1242. * mask_buf = <const unsigned char*>PyBytes_AsString(mask)
  1243. */
  1244. __pyx_t_1 = PyObject_Length(__pyx_v_data); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 30, __pyx_L1_error)
  1245. __pyx_v_data_len = __pyx_t_1;
  1246. /* "aiohttp/_websocket.pyx":31
  1247. *
  1248. * data_len = len(data)
  1249. * in_buf = <unsigned char*>PyByteArray_AsString(data) # <<<<<<<<<<<<<<
  1250. * mask_buf = <const unsigned char*>PyBytes_AsString(mask)
  1251. * uint32_msk = (<uint32_t*>mask_buf)[0]
  1252. */
  1253. if (!(likely(PyByteArray_CheckExact(__pyx_v_data))||((__pyx_v_data) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytearray", Py_TYPE(__pyx_v_data)->tp_name), 0))) __PYX_ERR(0, 31, __pyx_L1_error)
  1254. __pyx_t_5 = PyByteArray_AsString(((PyObject*)__pyx_v_data)); if (unlikely(__pyx_t_5 == ((char *)NULL))) __PYX_ERR(0, 31, __pyx_L1_error)
  1255. __pyx_v_in_buf = ((unsigned char *)__pyx_t_5);
  1256. /* "aiohttp/_websocket.pyx":32
  1257. * data_len = len(data)
  1258. * in_buf = <unsigned char*>PyByteArray_AsString(data)
  1259. * mask_buf = <const unsigned char*>PyBytes_AsString(mask) # <<<<<<<<<<<<<<
  1260. * uint32_msk = (<uint32_t*>mask_buf)[0]
  1261. *
  1262. */
  1263. __pyx_t_5 = PyBytes_AsString(__pyx_v_mask); if (unlikely(__pyx_t_5 == ((char *)NULL))) __PYX_ERR(0, 32, __pyx_L1_error)
  1264. __pyx_v_mask_buf = ((unsigned char const *)__pyx_t_5);
  1265. /* "aiohttp/_websocket.pyx":33
  1266. * in_buf = <unsigned char*>PyByteArray_AsString(data)
  1267. * mask_buf = <const unsigned char*>PyBytes_AsString(mask)
  1268. * uint32_msk = (<uint32_t*>mask_buf)[0] # <<<<<<<<<<<<<<
  1269. *
  1270. * # TODO: align in_data ptr to achieve even faster speeds
  1271. */
  1272. __pyx_v_uint32_msk = (((uint32_t *)__pyx_v_mask_buf)[0]);
  1273. /* "aiohttp/_websocket.pyx":38
  1274. * # does it need in python ?! malloc() always aligns to sizeof(long) bytes
  1275. *
  1276. * if sizeof(size_t) >= 8: # <<<<<<<<<<<<<<
  1277. * uint64_msk = uint32_msk
  1278. * uint64_msk = (uint64_msk << 32) | uint32_msk
  1279. */
  1280. __pyx_t_2 = (((sizeof(size_t)) >= 8) != 0);
  1281. if (__pyx_t_2) {
  1282. /* "aiohttp/_websocket.pyx":39
  1283. *
  1284. * if sizeof(size_t) >= 8:
  1285. * uint64_msk = uint32_msk # <<<<<<<<<<<<<<
  1286. * uint64_msk = (uint64_msk << 32) | uint32_msk
  1287. *
  1288. */
  1289. __pyx_v_uint64_msk = __pyx_v_uint32_msk;
  1290. /* "aiohttp/_websocket.pyx":40
  1291. * if sizeof(size_t) >= 8:
  1292. * uint64_msk = uint32_msk
  1293. * uint64_msk = (uint64_msk << 32) | uint32_msk # <<<<<<<<<<<<<<
  1294. *
  1295. * while data_len >= 8:
  1296. */
  1297. __pyx_v_uint64_msk = ((__pyx_v_uint64_msk << 32) | __pyx_v_uint32_msk);
  1298. /* "aiohttp/_websocket.pyx":42
  1299. * uint64_msk = (uint64_msk << 32) | uint32_msk
  1300. *
  1301. * while data_len >= 8: # <<<<<<<<<<<<<<
  1302. * (<uint64_t*>in_buf)[0] ^= uint64_msk
  1303. * in_buf += 8
  1304. */
  1305. while (1) {
  1306. __pyx_t_2 = ((__pyx_v_data_len >= 8) != 0);
  1307. if (!__pyx_t_2) break;
  1308. /* "aiohttp/_websocket.pyx":43
  1309. *
  1310. * while data_len >= 8:
  1311. * (<uint64_t*>in_buf)[0] ^= uint64_msk # <<<<<<<<<<<<<<
  1312. * in_buf += 8
  1313. * data_len -= 8
  1314. */
  1315. __pyx_t_6 = ((uint64_t *)__pyx_v_in_buf);
  1316. __pyx_t_7 = 0;
  1317. (__pyx_t_6[__pyx_t_7]) = ((__pyx_t_6[__pyx_t_7]) ^ __pyx_v_uint64_msk);
  1318. /* "aiohttp/_websocket.pyx":44
  1319. * while data_len >= 8:
  1320. * (<uint64_t*>in_buf)[0] ^= uint64_msk
  1321. * in_buf += 8 # <<<<<<<<<<<<<<
  1322. * data_len -= 8
  1323. *
  1324. */
  1325. __pyx_v_in_buf = (__pyx_v_in_buf + 8);
  1326. /* "aiohttp/_websocket.pyx":45
  1327. * (<uint64_t*>in_buf)[0] ^= uint64_msk
  1328. * in_buf += 8
  1329. * data_len -= 8 # <<<<<<<<<<<<<<
  1330. *
  1331. *
  1332. */
  1333. __pyx_v_data_len = (__pyx_v_data_len - 8);
  1334. }
  1335. /* "aiohttp/_websocket.pyx":38
  1336. * # does it need in python ?! malloc() always aligns to sizeof(long) bytes
  1337. *
  1338. * if sizeof(size_t) >= 8: # <<<<<<<<<<<<<<
  1339. * uint64_msk = uint32_msk
  1340. * uint64_msk = (uint64_msk << 32) | uint32_msk
  1341. */
  1342. }
  1343. /* "aiohttp/_websocket.pyx":48
  1344. *
  1345. *
  1346. * while data_len >= 4: # <<<<<<<<<<<<<<
  1347. * (<uint32_t*>in_buf)[0] ^= uint32_msk
  1348. * in_buf += 4
  1349. */
  1350. while (1) {
  1351. __pyx_t_2 = ((__pyx_v_data_len >= 4) != 0);
  1352. if (!__pyx_t_2) break;
  1353. /* "aiohttp/_websocket.pyx":49
  1354. *
  1355. * while data_len >= 4:
  1356. * (<uint32_t*>in_buf)[0] ^= uint32_msk # <<<<<<<<<<<<<<
  1357. * in_buf += 4
  1358. * data_len -= 4
  1359. */
  1360. __pyx_t_8 = ((uint32_t *)__pyx_v_in_buf);
  1361. __pyx_t_7 = 0;
  1362. (__pyx_t_8[__pyx_t_7]) = ((__pyx_t_8[__pyx_t_7]) ^ __pyx_v_uint32_msk);
  1363. /* "aiohttp/_websocket.pyx":50
  1364. * while data_len >= 4:
  1365. * (<uint32_t*>in_buf)[0] ^= uint32_msk
  1366. * in_buf += 4 # <<<<<<<<<<<<<<
  1367. * data_len -= 4
  1368. *
  1369. */
  1370. __pyx_v_in_buf = (__pyx_v_in_buf + 4);
  1371. /* "aiohttp/_websocket.pyx":51
  1372. * (<uint32_t*>in_buf)[0] ^= uint32_msk
  1373. * in_buf += 4
  1374. * data_len -= 4 # <<<<<<<<<<<<<<
  1375. *
  1376. * for i in range(0, data_len):
  1377. */
  1378. __pyx_v_data_len = (__pyx_v_data_len - 4);
  1379. }
  1380. /* "aiohttp/_websocket.pyx":53
  1381. * data_len -= 4
  1382. *
  1383. * for i in range(0, data_len): # <<<<<<<<<<<<<<
  1384. * in_buf[i] ^= mask_buf[i]
  1385. */
  1386. __pyx_t_1 = __pyx_v_data_len;
  1387. __pyx_t_9 = __pyx_t_1;
  1388. for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) {
  1389. __pyx_v_i = __pyx_t_10;
  1390. /* "aiohttp/_websocket.pyx":54
  1391. *
  1392. * for i in range(0, data_len):
  1393. * in_buf[i] ^= mask_buf[i] # <<<<<<<<<<<<<<
  1394. */
  1395. __pyx_t_11 = __pyx_v_i;
  1396. (__pyx_v_in_buf[__pyx_t_11]) = ((__pyx_v_in_buf[__pyx_t_11]) ^ (__pyx_v_mask_buf[__pyx_v_i]));
  1397. }
  1398. /* "aiohttp/_websocket.pyx":9
  1399. * from libc.stdint cimport uint32_t, uint64_t, uintmax_t
  1400. *
  1401. * def _websocket_mask_cython(object mask, object data): # <<<<<<<<<<<<<<
  1402. * """Note, this function mutates it's `data` argument
  1403. * """
  1404. */
  1405. /* function exit code */
  1406. __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  1407. goto __pyx_L0;
  1408. __pyx_L1_error:;
  1409. __Pyx_XDECREF(__pyx_t_4);
  1410. __Pyx_AddTraceback("aiohttp._websocket._websocket_mask_cython", __pyx_clineno, __pyx_lineno, __pyx_filename);
  1411. __pyx_r = NULL;
  1412. __pyx_L0:;
  1413. __Pyx_XDECREF(__pyx_v_mask);
  1414. __Pyx_XDECREF(__pyx_v_data);
  1415. __Pyx_XGIVEREF(__pyx_r);
  1416. __Pyx_RefNannyFinishContext();
  1417. return __pyx_r;
  1418. }
  1419. static PyMethodDef __pyx_methods[] = {
  1420. {0, 0, 0, 0}
  1421. };
  1422. #if PY_MAJOR_VERSION >= 3
  1423. #if CYTHON_PEP489_MULTI_PHASE_INIT
  1424. static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/
  1425. static int __pyx_pymod_exec__websocket(PyObject* module); /*proto*/
  1426. static PyModuleDef_Slot __pyx_moduledef_slots[] = {
  1427. {Py_mod_create, (void*)__pyx_pymod_create},
  1428. {Py_mod_exec, (void*)__pyx_pymod_exec__websocket},
  1429. {0, NULL}
  1430. };
  1431. #endif
  1432. static struct PyModuleDef __pyx_moduledef = {
  1433. PyModuleDef_HEAD_INIT,
  1434. "_websocket",
  1435. 0, /* m_doc */
  1436. #if CYTHON_PEP489_MULTI_PHASE_INIT
  1437. 0, /* m_size */
  1438. #else
  1439. -1, /* m_size */
  1440. #endif
  1441. __pyx_methods /* m_methods */,
  1442. #if CYTHON_PEP489_MULTI_PHASE_INIT
  1443. __pyx_moduledef_slots, /* m_slots */
  1444. #else
  1445. NULL, /* m_reload */
  1446. #endif
  1447. NULL, /* m_traverse */
  1448. NULL, /* m_clear */
  1449. NULL /* m_free */
  1450. };
  1451. #endif
  1452. static __Pyx_StringTabEntry __pyx_string_tab[] = {
  1453. {&__pyx_n_s_aiohttp__websocket, __pyx_k_aiohttp__websocket, sizeof(__pyx_k_aiohttp__websocket), 0, 0, 1, 1},
  1454. {&__pyx_kp_s_aiohttp__websocket_pyx, __pyx_k_aiohttp__websocket_pyx, sizeof(__pyx_k_aiohttp__websocket_pyx), 0, 0, 1, 0},
  1455. {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1},
  1456. {&__pyx_n_s_data, __pyx_k_data, sizeof(__pyx_k_data), 0, 0, 1, 1},
  1457. {&__pyx_n_s_data_len, __pyx_k_data_len, sizeof(__pyx_k_data_len), 0, 0, 1, 1},
  1458. {&__pyx_n_s_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 1, 1},
  1459. {&__pyx_n_s_in_buf, __pyx_k_in_buf, sizeof(__pyx_k_in_buf), 0, 0, 1, 1},
  1460. {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
  1461. {&__pyx_n_s_mask, __pyx_k_mask, sizeof(__pyx_k_mask), 0, 0, 1, 1},
  1462. {&__pyx_n_s_mask_buf, __pyx_k_mask_buf, sizeof(__pyx_k_mask_buf), 0, 0, 1, 1},
  1463. {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1},
  1464. {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
  1465. {&__pyx_n_s_uint32_msk, __pyx_k_uint32_msk, sizeof(__pyx_k_uint32_msk), 0, 0, 1, 1},
  1466. {&__pyx_n_s_uint64_msk, __pyx_k_uint64_msk, sizeof(__pyx_k_uint64_msk), 0, 0, 1, 1},
  1467. {&__pyx_n_s_websocket_mask_cython, __pyx_k_websocket_mask_cython, sizeof(__pyx_k_websocket_mask_cython), 0, 0, 1, 1},
  1468. {0, 0, 0, 0, 0, 0, 0}
  1469. };
  1470. static int __Pyx_InitCachedBuiltins(void) {
  1471. __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 53, __pyx_L1_error)
  1472. return 0;
  1473. __pyx_L1_error:;
  1474. return -1;
  1475. }
  1476. static int __Pyx_InitCachedConstants(void) {
  1477. __Pyx_RefNannyDeclarations
  1478. __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);
  1479. /* "aiohttp/_websocket.pyx":9
  1480. * from libc.stdint cimport uint32_t, uint64_t, uintmax_t
  1481. *
  1482. * def _websocket_mask_cython(object mask, object data): # <<<<<<<<<<<<<<
  1483. * """Note, this function mutates it's `data` argument
  1484. * """
  1485. */
  1486. __pyx_tuple_ = PyTuple_Pack(8, __pyx_n_s_mask, __pyx_n_s_data, __pyx_n_s_data_len, __pyx_n_s_i, __pyx_n_s_in_buf, __pyx_n_s_mask_buf, __pyx_n_s_uint32_msk, __pyx_n_s_uint64_msk); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 9, __pyx_L1_error)
  1487. __Pyx_GOTREF(__pyx_tuple_);
  1488. __Pyx_GIVEREF(__pyx_tuple_);
  1489. __pyx_codeobj__2 = (PyObject*)__Pyx_PyCode_New(2, 0, 8, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple_, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_aiohttp__websocket_pyx, __pyx_n_s_websocket_mask_cython, 9, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__2)) __PYX_ERR(0, 9, __pyx_L1_error)
  1490. __Pyx_RefNannyFinishContext();
  1491. return 0;
  1492. __pyx_L1_error:;
  1493. __Pyx_RefNannyFinishContext();
  1494. return -1;
  1495. }
  1496. static int __Pyx_InitGlobals(void) {
  1497. if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
  1498. return 0;
  1499. __pyx_L1_error:;
  1500. return -1;
  1501. }
  1502. static int __Pyx_modinit_global_init_code(void); /*proto*/
  1503. static int __Pyx_modinit_variable_export_code(void); /*proto*/
  1504. static int __Pyx_modinit_function_export_code(void); /*proto*/
  1505. static int __Pyx_modinit_type_init_code(void); /*proto*/
  1506. static int __Pyx_modinit_type_import_code(void); /*proto*/
  1507. static int __Pyx_modinit_variable_import_code(void); /*proto*/
  1508. static int __Pyx_modinit_function_import_code(void); /*proto*/
  1509. static int __Pyx_modinit_global_init_code(void) {
  1510. __Pyx_RefNannyDeclarations
  1511. __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0);
  1512. /*--- Global init code ---*/
  1513. __Pyx_RefNannyFinishContext();
  1514. return 0;
  1515. }
  1516. static int __Pyx_modinit_variable_export_code(void) {
  1517. __Pyx_RefNannyDeclarations
  1518. __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0);
  1519. /*--- Variable export code ---*/
  1520. __Pyx_RefNannyFinishContext();
  1521. return 0;
  1522. }
  1523. static int __Pyx_modinit_function_export_code(void) {
  1524. __Pyx_RefNannyDeclarations
  1525. __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0);
  1526. /*--- Function export code ---*/
  1527. __Pyx_RefNannyFinishContext();
  1528. return 0;
  1529. }
  1530. static int __Pyx_modinit_type_init_code(void) {
  1531. __Pyx_RefNannyDeclarations
  1532. __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0);
  1533. /*--- Type init code ---*/
  1534. __Pyx_RefNannyFinishContext();
  1535. return 0;
  1536. }
  1537. static int __Pyx_modinit_type_import_code(void) {
  1538. __Pyx_RefNannyDeclarations
  1539. __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0);
  1540. /*--- Type import code ---*/
  1541. __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "type",
  1542. #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000
  1543. sizeof(PyTypeObject),
  1544. #else
  1545. sizeof(PyHeapTypeObject),
  1546. #endif
  1547. 0); if (unlikely(!__pyx_ptype_7cpython_4type_type)) __PYX_ERR(1, 9, __pyx_L1_error)
  1548. __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), 0); if (unlikely(!__pyx_ptype_7cpython_4bool_bool)) __PYX_ERR(2, 8, __pyx_L1_error)
  1549. __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), 0); if (unlikely(!__pyx_ptype_7cpython_7complex_complex)) __PYX_ERR(3, 15, __pyx_L1_error)
  1550. __Pyx_RefNannyFinishContext();
  1551. return 0;
  1552. __pyx_L1_error:;
  1553. __Pyx_RefNannyFinishContext();
  1554. return -1;
  1555. }
  1556. static int __Pyx_modinit_variable_import_code(void) {
  1557. __Pyx_RefNannyDeclarations
  1558. __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0);
  1559. /*--- Variable import code ---*/
  1560. __Pyx_RefNannyFinishContext();
  1561. return 0;
  1562. }
  1563. static int __Pyx_modinit_function_import_code(void) {
  1564. __Pyx_RefNannyDeclarations
  1565. __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0);
  1566. /*--- Function import code ---*/
  1567. __Pyx_RefNannyFinishContext();
  1568. return 0;
  1569. }
  1570. #if PY_MAJOR_VERSION < 3
  1571. #ifdef CYTHON_NO_PYINIT_EXPORT
  1572. #define __Pyx_PyMODINIT_FUNC void
  1573. #else
  1574. #define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
  1575. #endif
  1576. #else
  1577. #ifdef CYTHON_NO_PYINIT_EXPORT
  1578. #define __Pyx_PyMODINIT_FUNC PyObject *
  1579. #else
  1580. #define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
  1581. #endif
  1582. #endif
  1583. #ifndef CYTHON_SMALL_CODE
  1584. #if defined(__clang__)
  1585. #define CYTHON_SMALL_CODE
  1586. #elif defined(__GNUC__) && (!(defined(__cplusplus)) || (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 4)))
  1587. #define CYTHON_SMALL_CODE __attribute__((cold))
  1588. #else
  1589. #define CYTHON_SMALL_CODE
  1590. #endif
  1591. #endif
  1592. #if PY_MAJOR_VERSION < 3
  1593. __Pyx_PyMODINIT_FUNC init_websocket(void) CYTHON_SMALL_CODE; /*proto*/
  1594. __Pyx_PyMODINIT_FUNC init_websocket(void)
  1595. #else
  1596. __Pyx_PyMODINIT_FUNC PyInit__websocket(void) CYTHON_SMALL_CODE; /*proto*/
  1597. __Pyx_PyMODINIT_FUNC PyInit__websocket(void)
  1598. #if CYTHON_PEP489_MULTI_PHASE_INIT
  1599. {
  1600. return PyModuleDef_Init(&__pyx_moduledef);
  1601. }
  1602. static int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name) {
  1603. PyObject *value = PyObject_GetAttrString(spec, from_name);
  1604. int result = 0;
  1605. if (likely(value)) {
  1606. result = PyDict_SetItemString(moddict, to_name, value);
  1607. Py_DECREF(value);
  1608. } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
  1609. PyErr_Clear();
  1610. } else {
  1611. result = -1;
  1612. }
  1613. return result;
  1614. }
  1615. static PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) {
  1616. PyObject *module = NULL, *moddict, *modname;
  1617. if (__pyx_m)
  1618. return __Pyx_NewRef(__pyx_m);
  1619. modname = PyObject_GetAttrString(spec, "name");
  1620. if (unlikely(!modname)) goto bad;
  1621. module = PyModule_NewObject(modname);
  1622. Py_DECREF(modname);
  1623. if (unlikely(!module)) goto bad;
  1624. moddict = PyModule_GetDict(module);
  1625. if (unlikely(!moddict)) goto bad;
  1626. if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__") < 0)) goto bad;
  1627. if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__") < 0)) goto bad;
  1628. if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__") < 0)) goto bad;
  1629. if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__") < 0)) goto bad;
  1630. return module;
  1631. bad:
  1632. Py_XDECREF(module);
  1633. return NULL;
  1634. }
  1635. static int __pyx_pymod_exec__websocket(PyObject *__pyx_pyinit_module)
  1636. #endif
  1637. #endif
  1638. {
  1639. PyObject *__pyx_t_1 = NULL;
  1640. __Pyx_RefNannyDeclarations
  1641. #if CYTHON_PEP489_MULTI_PHASE_INIT
  1642. if (__pyx_m && __pyx_m == __pyx_pyinit_module) return 0;
  1643. #elif PY_MAJOR_VERSION >= 3
  1644. if (__pyx_m) return __Pyx_NewRef(__pyx_m);
  1645. #endif
  1646. #if CYTHON_REFNANNY
  1647. __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
  1648. if (!__Pyx_RefNanny) {
  1649. PyErr_Clear();
  1650. __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
  1651. if (!__Pyx_RefNanny)
  1652. Py_FatalError("failed to import 'refnanny' module");
  1653. }
  1654. #endif
  1655. __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit__websocket(void)", 0);
  1656. if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  1657. __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error)
  1658. __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error)
  1659. __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error)
  1660. #ifdef __Pyx_CyFunction_USED
  1661. if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  1662. #endif
  1663. #ifdef __Pyx_FusedFunction_USED
  1664. if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  1665. #endif
  1666. #ifdef __Pyx_Coroutine_USED
  1667. if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  1668. #endif
  1669. #ifdef __Pyx_Generator_USED
  1670. if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  1671. #endif
  1672. #ifdef __Pyx_AsyncGen_USED
  1673. if (__pyx_AsyncGen_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  1674. #endif
  1675. #ifdef __Pyx_StopAsyncIteration_USED
  1676. if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  1677. #endif
  1678. /*--- Library function declarations ---*/
  1679. /*--- Threads initialization code ---*/
  1680. #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  1681. #ifdef WITH_THREAD /* Python build with threading support? */
  1682. PyEval_InitThreads();
  1683. #endif
  1684. #endif
  1685. /*--- Module creation code ---*/
  1686. #if CYTHON_PEP489_MULTI_PHASE_INIT
  1687. __pyx_m = __pyx_pyinit_module;
  1688. Py_INCREF(__pyx_m);
  1689. #else
  1690. #if PY_MAJOR_VERSION < 3
  1691. __pyx_m = Py_InitModule4("_websocket", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
  1692. #else
  1693. __pyx_m = PyModule_Create(&__pyx_moduledef);
  1694. #endif
  1695. if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error)
  1696. #endif
  1697. __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error)
  1698. Py_INCREF(__pyx_d);
  1699. __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error)
  1700. __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error)
  1701. #if CYTHON_COMPILING_IN_PYPY
  1702. Py_INCREF(__pyx_b);
  1703. #endif
  1704. if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
  1705. /*--- Initialize various global constants etc. ---*/
  1706. if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  1707. #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
  1708. if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  1709. #endif
  1710. if (__pyx_module_is_main_aiohttp___websocket) {
  1711. if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  1712. }
  1713. #if PY_MAJOR_VERSION >= 3
  1714. {
  1715. PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error)
  1716. if (!PyDict_GetItemString(modules, "aiohttp._websocket")) {
  1717. if (unlikely(PyDict_SetItemString(modules, "aiohttp._websocket", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
  1718. }
  1719. }
  1720. #endif
  1721. /*--- Builtin init code ---*/
  1722. if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  1723. /*--- Constants init code ---*/
  1724. if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  1725. /*--- Global type/function init code ---*/
  1726. (void)__Pyx_modinit_global_init_code();
  1727. (void)__Pyx_modinit_variable_export_code();
  1728. (void)__Pyx_modinit_function_export_code();
  1729. (void)__Pyx_modinit_type_init_code();
  1730. if (unlikely(__Pyx_modinit_type_import_code() != 0)) goto __pyx_L1_error;
  1731. (void)__Pyx_modinit_variable_import_code();
  1732. (void)__Pyx_modinit_function_import_code();
  1733. /*--- Execution code ---*/
  1734. #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
  1735. if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  1736. #endif
  1737. /* "aiohttp/_websocket.pyx":9
  1738. * from libc.stdint cimport uint32_t, uint64_t, uintmax_t
  1739. *
  1740. * def _websocket_mask_cython(object mask, object data): # <<<<<<<<<<<<<<
  1741. * """Note, this function mutates it's `data` argument
  1742. * """
  1743. */
  1744. __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_7aiohttp_10_websocket_1_websocket_mask_cython, NULL, __pyx_n_s_aiohttp__websocket); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 9, __pyx_L1_error)
  1745. __Pyx_GOTREF(__pyx_t_1);
  1746. if (PyDict_SetItem(__pyx_d, __pyx_n_s_websocket_mask_cython, __pyx_t_1) < 0) __PYX_ERR(0, 9, __pyx_L1_error)
  1747. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  1748. /* "aiohttp/_websocket.pyx":1
  1749. * from cpython cimport PyBytes_AsString # <<<<<<<<<<<<<<
  1750. *
  1751. * #from cpython cimport PyByteArray_AsString # cython still not exports that
  1752. */
  1753. __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  1754. __Pyx_GOTREF(__pyx_t_1);
  1755. if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  1756. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  1757. /*--- Wrapped vars code ---*/
  1758. goto __pyx_L0;
  1759. __pyx_L1_error:;
  1760. __Pyx_XDECREF(__pyx_t_1);
  1761. if (__pyx_m) {
  1762. if (__pyx_d) {
  1763. __Pyx_AddTraceback("init aiohttp._websocket", 0, __pyx_lineno, __pyx_filename);
  1764. }
  1765. Py_DECREF(__pyx_m); __pyx_m = 0;
  1766. } else if (!PyErr_Occurred()) {
  1767. PyErr_SetString(PyExc_ImportError, "init aiohttp._websocket");
  1768. }
  1769. __pyx_L0:;
  1770. __Pyx_RefNannyFinishContext();
  1771. #if CYTHON_PEP489_MULTI_PHASE_INIT
  1772. return (__pyx_m != NULL) ? 0 : -1;
  1773. #elif PY_MAJOR_VERSION >= 3
  1774. return __pyx_m;
  1775. #else
  1776. return;
  1777. #endif
  1778. }
  1779. /* --- Runtime support code --- */
  1780. /* Refnanny */
  1781. #if CYTHON_REFNANNY
  1782. static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
  1783. PyObject *m = NULL, *p = NULL;
  1784. void *r = NULL;
  1785. m = PyImport_ImportModule((char *)modname);
  1786. if (!m) goto end;
  1787. p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
  1788. if (!p) goto end;
  1789. r = PyLong_AsVoidPtr(p);
  1790. end:
  1791. Py_XDECREF(p);
  1792. Py_XDECREF(m);
  1793. return (__Pyx_RefNannyAPIStruct *)r;
  1794. }
  1795. #endif
  1796. /* PyObjectGetAttrStr */
  1797. #if CYTHON_USE_TYPE_SLOTS
  1798. static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) {
  1799. PyTypeObject* tp = Py_TYPE(obj);
  1800. if (likely(tp->tp_getattro))
  1801. return tp->tp_getattro(obj, attr_name);
  1802. #if PY_MAJOR_VERSION < 3
  1803. if (likely(tp->tp_getattr))
  1804. return tp->tp_getattr(obj, PyString_AS_STRING(attr_name));
  1805. #endif
  1806. return PyObject_GetAttr(obj, attr_name);
  1807. }
  1808. #endif
  1809. /* GetBuiltinName */
  1810. static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
  1811. PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name);
  1812. if (unlikely(!result)) {
  1813. PyErr_Format(PyExc_NameError,
  1814. #if PY_MAJOR_VERSION >= 3
  1815. "name '%U' is not defined", name);
  1816. #else
  1817. "name '%.200s' is not defined", PyString_AS_STRING(name));
  1818. #endif
  1819. }
  1820. return result;
  1821. }
  1822. /* RaiseArgTupleInvalid */
  1823. static void __Pyx_RaiseArgtupleInvalid(
  1824. const char* func_name,
  1825. int exact,
  1826. Py_ssize_t num_min,
  1827. Py_ssize_t num_max,
  1828. Py_ssize_t num_found)
  1829. {
  1830. Py_ssize_t num_expected;
  1831. const char *more_or_less;
  1832. if (num_found < num_min) {
  1833. num_expected = num_min;
  1834. more_or_less = "at least";
  1835. } else {
  1836. num_expected = num_max;
  1837. more_or_less = "at most";
  1838. }
  1839. if (exact) {
  1840. more_or_less = "exactly";
  1841. }
  1842. PyErr_Format(PyExc_TypeError,
  1843. "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)",
  1844. func_name, more_or_less, num_expected,
  1845. (num_expected == 1) ? "" : "s", num_found);
  1846. }
  1847. /* RaiseDoubleKeywords */
  1848. static void __Pyx_RaiseDoubleKeywordsError(
  1849. const char* func_name,
  1850. PyObject* kw_name)
  1851. {
  1852. PyErr_Format(PyExc_TypeError,
  1853. #if PY_MAJOR_VERSION >= 3
  1854. "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
  1855. #else
  1856. "%s() got multiple values for keyword argument '%s'", func_name,
  1857. PyString_AsString(kw_name));
  1858. #endif
  1859. }
  1860. /* ParseKeywords */
  1861. static int __Pyx_ParseOptionalKeywords(
  1862. PyObject *kwds,
  1863. PyObject **argnames[],
  1864. PyObject *kwds2,
  1865. PyObject *values[],
  1866. Py_ssize_t num_pos_args,
  1867. const char* function_name)
  1868. {
  1869. PyObject *key = 0, *value = 0;
  1870. Py_ssize_t pos = 0;
  1871. PyObject*** name;
  1872. PyObject*** first_kw_arg = argnames + num_pos_args;
  1873. while (PyDict_Next(kwds, &pos, &key, &value)) {
  1874. name = first_kw_arg;
  1875. while (*name && (**name != key)) name++;
  1876. if (*name) {
  1877. values[name-argnames] = value;
  1878. continue;
  1879. }
  1880. name = first_kw_arg;
  1881. #if PY_MAJOR_VERSION < 3
  1882. if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) {
  1883. while (*name) {
  1884. if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key))
  1885. && _PyString_Eq(**name, key)) {
  1886. values[name-argnames] = value;
  1887. break;
  1888. }
  1889. name++;
  1890. }
  1891. if (*name) continue;
  1892. else {
  1893. PyObject*** argname = argnames;
  1894. while (argname != first_kw_arg) {
  1895. if ((**argname == key) || (
  1896. (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key))
  1897. && _PyString_Eq(**argname, key))) {
  1898. goto arg_passed_twice;
  1899. }
  1900. argname++;
  1901. }
  1902. }
  1903. } else
  1904. #endif
  1905. if (likely(PyUnicode_Check(key))) {
  1906. while (*name) {
  1907. int cmp = (**name == key) ? 0 :
  1908. #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
  1909. (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 :
  1910. #endif
  1911. PyUnicode_Compare(**name, key);
  1912. if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
  1913. if (cmp == 0) {
  1914. values[name-argnames] = value;
  1915. break;
  1916. }
  1917. name++;
  1918. }
  1919. if (*name) continue;
  1920. else {
  1921. PyObject*** argname = argnames;
  1922. while (argname != first_kw_arg) {
  1923. int cmp = (**argname == key) ? 0 :
  1924. #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
  1925. (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 :
  1926. #endif
  1927. PyUnicode_Compare(**argname, key);
  1928. if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
  1929. if (cmp == 0) goto arg_passed_twice;
  1930. argname++;
  1931. }
  1932. }
  1933. } else
  1934. goto invalid_keyword_type;
  1935. if (kwds2) {
  1936. if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
  1937. } else {
  1938. goto invalid_keyword;
  1939. }
  1940. }
  1941. return 0;
  1942. arg_passed_twice:
  1943. __Pyx_RaiseDoubleKeywordsError(function_name, key);
  1944. goto bad;
  1945. invalid_keyword_type:
  1946. PyErr_Format(PyExc_TypeError,
  1947. "%.200s() keywords must be strings", function_name);
  1948. goto bad;
  1949. invalid_keyword:
  1950. PyErr_Format(PyExc_TypeError,
  1951. #if PY_MAJOR_VERSION < 3
  1952. "%.200s() got an unexpected keyword argument '%.200s'",
  1953. function_name, PyString_AsString(key));
  1954. #else
  1955. "%s() got an unexpected keyword argument '%U'",
  1956. function_name, key);
  1957. #endif
  1958. bad:
  1959. return -1;
  1960. }
  1961. /* PyCFunctionFastCall */
  1962. #if CYTHON_FAST_PYCCALL
  1963. static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, PyObject **args, Py_ssize_t nargs) {
  1964. PyCFunctionObject *func = (PyCFunctionObject*)func_obj;
  1965. PyCFunction meth = PyCFunction_GET_FUNCTION(func);
  1966. PyObject *self = PyCFunction_GET_SELF(func);
  1967. int flags = PyCFunction_GET_FLAGS(func);
  1968. assert(PyCFunction_Check(func));
  1969. assert(METH_FASTCALL == (flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS)));
  1970. assert(nargs >= 0);
  1971. assert(nargs == 0 || args != NULL);
  1972. /* _PyCFunction_FastCallDict() must not be called with an exception set,
  1973. because it may clear it (directly or indirectly) and so the
  1974. caller loses its exception */
  1975. assert(!PyErr_Occurred());
  1976. if ((PY_VERSION_HEX < 0x030700A0) || unlikely(flags & METH_KEYWORDS)) {
  1977. return (*((__Pyx_PyCFunctionFastWithKeywords)meth)) (self, args, nargs, NULL);
  1978. } else {
  1979. return (*((__Pyx_PyCFunctionFast)meth)) (self, args, nargs);
  1980. }
  1981. }
  1982. #endif
  1983. /* PyFunctionFastCall */
  1984. #if CYTHON_FAST_PYCALL
  1985. #include "frameobject.h"
  1986. static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na,
  1987. PyObject *globals) {
  1988. PyFrameObject *f;
  1989. PyThreadState *tstate = __Pyx_PyThreadState_Current;
  1990. PyObject **fastlocals;
  1991. Py_ssize_t i;
  1992. PyObject *result;
  1993. assert(globals != NULL);
  1994. /* XXX Perhaps we should create a specialized
  1995. PyFrame_New() that doesn't take locals, but does
  1996. take builtins without sanity checking them.
  1997. */
  1998. assert(tstate != NULL);
  1999. f = PyFrame_New(tstate, co, globals, NULL);
  2000. if (f == NULL) {
  2001. return NULL;
  2002. }
  2003. fastlocals = f->f_localsplus;
  2004. for (i = 0; i < na; i++) {
  2005. Py_INCREF(*args);
  2006. fastlocals[i] = *args++;
  2007. }
  2008. result = PyEval_EvalFrameEx(f,0);
  2009. ++tstate->recursion_depth;
  2010. Py_DECREF(f);
  2011. --tstate->recursion_depth;
  2012. return result;
  2013. }
  2014. #if 1 || PY_VERSION_HEX < 0x030600B1
  2015. static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwargs) {
  2016. PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func);
  2017. PyObject *globals = PyFunction_GET_GLOBALS(func);
  2018. PyObject *argdefs = PyFunction_GET_DEFAULTS(func);
  2019. PyObject *closure;
  2020. #if PY_MAJOR_VERSION >= 3
  2021. PyObject *kwdefs;
  2022. #endif
  2023. PyObject *kwtuple, **k;
  2024. PyObject **d;
  2025. Py_ssize_t nd;
  2026. Py_ssize_t nk;
  2027. PyObject *result;
  2028. assert(kwargs == NULL || PyDict_Check(kwargs));
  2029. nk = kwargs ? PyDict_Size(kwargs) : 0;
  2030. if (Py_EnterRecursiveCall((char*)" while calling a Python object")) {
  2031. return NULL;
  2032. }
  2033. if (
  2034. #if PY_MAJOR_VERSION >= 3
  2035. co->co_kwonlyargcount == 0 &&
  2036. #endif
  2037. likely(kwargs == NULL || nk == 0) &&
  2038. co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) {
  2039. if (argdefs == NULL && co->co_argcount == nargs) {
  2040. result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals);
  2041. goto done;
  2042. }
  2043. else if (nargs == 0 && argdefs != NULL
  2044. && co->co_argcount == Py_SIZE(argdefs)) {
  2045. /* function called with no arguments, but all parameters have
  2046. a default value: use default values as arguments .*/
  2047. args = &PyTuple_GET_ITEM(argdefs, 0);
  2048. result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals);
  2049. goto done;
  2050. }
  2051. }
  2052. if (kwargs != NULL) {
  2053. Py_ssize_t pos, i;
  2054. kwtuple = PyTuple_New(2 * nk);
  2055. if (kwtuple == NULL) {
  2056. result = NULL;
  2057. goto done;
  2058. }
  2059. k = &PyTuple_GET_ITEM(kwtuple, 0);
  2060. pos = i = 0;
  2061. while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) {
  2062. Py_INCREF(k[i]);
  2063. Py_INCREF(k[i+1]);
  2064. i += 2;
  2065. }
  2066. nk = i / 2;
  2067. }
  2068. else {
  2069. kwtuple = NULL;
  2070. k = NULL;
  2071. }
  2072. closure = PyFunction_GET_CLOSURE(func);
  2073. #if PY_MAJOR_VERSION >= 3
  2074. kwdefs = PyFunction_GET_KW_DEFAULTS(func);
  2075. #endif
  2076. if (argdefs != NULL) {
  2077. d = &PyTuple_GET_ITEM(argdefs, 0);
  2078. nd = Py_SIZE(argdefs);
  2079. }
  2080. else {
  2081. d = NULL;
  2082. nd = 0;
  2083. }
  2084. #if PY_MAJOR_VERSION >= 3
  2085. result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL,
  2086. args, nargs,
  2087. k, (int)nk,
  2088. d, (int)nd, kwdefs, closure);
  2089. #else
  2090. result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL,
  2091. args, nargs,
  2092. k, (int)nk,
  2093. d, (int)nd, closure);
  2094. #endif
  2095. Py_XDECREF(kwtuple);
  2096. done:
  2097. Py_LeaveRecursiveCall();
  2098. return result;
  2099. }
  2100. #endif
  2101. #endif
  2102. /* PyObjectCall */
  2103. #if CYTHON_COMPILING_IN_CPYTHON
  2104. static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
  2105. PyObject *result;
  2106. ternaryfunc call = func->ob_type->tp_call;
  2107. if (unlikely(!call))
  2108. return PyObject_Call(func, arg, kw);
  2109. if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
  2110. return NULL;
  2111. result = (*call)(func, arg, kw);
  2112. Py_LeaveRecursiveCall();
  2113. if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
  2114. PyErr_SetString(
  2115. PyExc_SystemError,
  2116. "NULL result without error in PyObject_Call");
  2117. }
  2118. return result;
  2119. }
  2120. #endif
  2121. /* PyObjectCallMethO */
  2122. #if CYTHON_COMPILING_IN_CPYTHON
  2123. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
  2124. PyObject *self, *result;
  2125. PyCFunction cfunc;
  2126. cfunc = PyCFunction_GET_FUNCTION(func);
  2127. self = PyCFunction_GET_SELF(func);
  2128. if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
  2129. return NULL;
  2130. result = cfunc(self, arg);
  2131. Py_LeaveRecursiveCall();
  2132. if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
  2133. PyErr_SetString(
  2134. PyExc_SystemError,
  2135. "NULL result without error in PyObject_Call");
  2136. }
  2137. return result;
  2138. }
  2139. #endif
  2140. /* PyObjectCallOneArg */
  2141. #if CYTHON_COMPILING_IN_CPYTHON
  2142. static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) {
  2143. PyObject *result;
  2144. PyObject *args = PyTuple_New(1);
  2145. if (unlikely(!args)) return NULL;
  2146. Py_INCREF(arg);
  2147. PyTuple_SET_ITEM(args, 0, arg);
  2148. result = __Pyx_PyObject_Call(func, args, NULL);
  2149. Py_DECREF(args);
  2150. return result;
  2151. }
  2152. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
  2153. #if CYTHON_FAST_PYCALL
  2154. if (PyFunction_Check(func)) {
  2155. return __Pyx_PyFunction_FastCall(func, &arg, 1);
  2156. }
  2157. #endif
  2158. if (likely(PyCFunction_Check(func))) {
  2159. if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) {
  2160. return __Pyx_PyObject_CallMethO(func, arg);
  2161. #if CYTHON_FAST_PYCCALL
  2162. } else if (PyCFunction_GET_FLAGS(func) & METH_FASTCALL) {
  2163. return __Pyx_PyCFunction_FastCall(func, &arg, 1);
  2164. #endif
  2165. }
  2166. }
  2167. return __Pyx__PyObject_CallOneArg(func, arg);
  2168. }
  2169. #else
  2170. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
  2171. PyObject *result;
  2172. PyObject *args = PyTuple_Pack(1, arg);
  2173. if (unlikely(!args)) return NULL;
  2174. result = __Pyx_PyObject_Call(func, args, NULL);
  2175. Py_DECREF(args);
  2176. return result;
  2177. }
  2178. #endif
  2179. /* PyErrFetchRestore */
  2180. #if CYTHON_FAST_THREAD_STATE
  2181. static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
  2182. PyObject *tmp_type, *tmp_value, *tmp_tb;
  2183. tmp_type = tstate->curexc_type;
  2184. tmp_value = tstate->curexc_value;
  2185. tmp_tb = tstate->curexc_traceback;
  2186. tstate->curexc_type = type;
  2187. tstate->curexc_value = value;
  2188. tstate->curexc_traceback = tb;
  2189. Py_XDECREF(tmp_type);
  2190. Py_XDECREF(tmp_value);
  2191. Py_XDECREF(tmp_tb);
  2192. }
  2193. static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
  2194. *type = tstate->curexc_type;
  2195. *value = tstate->curexc_value;
  2196. *tb = tstate->curexc_traceback;
  2197. tstate->curexc_type = 0;
  2198. tstate->curexc_value = 0;
  2199. tstate->curexc_traceback = 0;
  2200. }
  2201. #endif
  2202. /* CLineInTraceback */
  2203. #ifndef CYTHON_CLINE_IN_TRACEBACK
  2204. static int __Pyx_CLineForTraceback(CYTHON_UNUSED PyThreadState *tstate, int c_line) {
  2205. PyObject *use_cline;
  2206. PyObject *ptype, *pvalue, *ptraceback;
  2207. #if CYTHON_COMPILING_IN_CPYTHON
  2208. PyObject **cython_runtime_dict;
  2209. #endif
  2210. if (unlikely(!__pyx_cython_runtime)) {
  2211. return c_line;
  2212. }
  2213. __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback);
  2214. #if CYTHON_COMPILING_IN_CPYTHON
  2215. cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime);
  2216. if (likely(cython_runtime_dict)) {
  2217. use_cline = __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback);
  2218. } else
  2219. #endif
  2220. {
  2221. PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback);
  2222. if (use_cline_obj) {
  2223. use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True;
  2224. Py_DECREF(use_cline_obj);
  2225. } else {
  2226. PyErr_Clear();
  2227. use_cline = NULL;
  2228. }
  2229. }
  2230. if (!use_cline) {
  2231. c_line = 0;
  2232. PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False);
  2233. }
  2234. else if (PyObject_Not(use_cline) != 0) {
  2235. c_line = 0;
  2236. }
  2237. __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback);
  2238. return c_line;
  2239. }
  2240. #endif
  2241. /* CodeObjectCache */
  2242. static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
  2243. int start = 0, mid = 0, end = count - 1;
  2244. if (end >= 0 && code_line > entries[end].code_line) {
  2245. return count;
  2246. }
  2247. while (start < end) {
  2248. mid = start + (end - start) / 2;
  2249. if (code_line < entries[mid].code_line) {
  2250. end = mid;
  2251. } else if (code_line > entries[mid].code_line) {
  2252. start = mid + 1;
  2253. } else {
  2254. return mid;
  2255. }
  2256. }
  2257. if (code_line <= entries[mid].code_line) {
  2258. return mid;
  2259. } else {
  2260. return mid + 1;
  2261. }
  2262. }
  2263. static PyCodeObject *__pyx_find_code_object(int code_line) {
  2264. PyCodeObject* code_object;
  2265. int pos;
  2266. if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
  2267. return NULL;
  2268. }
  2269. pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
  2270. if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
  2271. return NULL;
  2272. }
  2273. code_object = __pyx_code_cache.entries[pos].code_object;
  2274. Py_INCREF(code_object);
  2275. return code_object;
  2276. }
  2277. static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
  2278. int pos, i;
  2279. __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
  2280. if (unlikely(!code_line)) {
  2281. return;
  2282. }
  2283. if (unlikely(!entries)) {
  2284. entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
  2285. if (likely(entries)) {
  2286. __pyx_code_cache.entries = entries;
  2287. __pyx_code_cache.max_count = 64;
  2288. __pyx_code_cache.count = 1;
  2289. entries[0].code_line = code_line;
  2290. entries[0].code_object = code_object;
  2291. Py_INCREF(code_object);
  2292. }
  2293. return;
  2294. }
  2295. pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
  2296. if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
  2297. PyCodeObject* tmp = entries[pos].code_object;
  2298. entries[pos].code_object = code_object;
  2299. Py_DECREF(tmp);
  2300. return;
  2301. }
  2302. if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
  2303. int new_max = __pyx_code_cache.max_count + 64;
  2304. entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
  2305. __pyx_code_cache.entries, (size_t)new_max*sizeof(__Pyx_CodeObjectCacheEntry));
  2306. if (unlikely(!entries)) {
  2307. return;
  2308. }
  2309. __pyx_code_cache.entries = entries;
  2310. __pyx_code_cache.max_count = new_max;
  2311. }
  2312. for (i=__pyx_code_cache.count; i>pos; i--) {
  2313. entries[i] = entries[i-1];
  2314. }
  2315. entries[pos].code_line = code_line;
  2316. entries[pos].code_object = code_object;
  2317. __pyx_code_cache.count++;
  2318. Py_INCREF(code_object);
  2319. }
  2320. /* AddTraceback */
  2321. #include "compile.h"
  2322. #include "frameobject.h"
  2323. #include "traceback.h"
  2324. static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
  2325. const char *funcname, int c_line,
  2326. int py_line, const char *filename) {
  2327. PyCodeObject *py_code = 0;
  2328. PyObject *py_srcfile = 0;
  2329. PyObject *py_funcname = 0;
  2330. #if PY_MAJOR_VERSION < 3
  2331. py_srcfile = PyString_FromString(filename);
  2332. #else
  2333. py_srcfile = PyUnicode_FromString(filename);
  2334. #endif
  2335. if (!py_srcfile) goto bad;
  2336. if (c_line) {
  2337. #if PY_MAJOR_VERSION < 3
  2338. py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
  2339. #else
  2340. py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
  2341. #endif
  2342. }
  2343. else {
  2344. #if PY_MAJOR_VERSION < 3
  2345. py_funcname = PyString_FromString(funcname);
  2346. #else
  2347. py_funcname = PyUnicode_FromString(funcname);
  2348. #endif
  2349. }
  2350. if (!py_funcname) goto bad;
  2351. py_code = __Pyx_PyCode_New(
  2352. 0,
  2353. 0,
  2354. 0,
  2355. 0,
  2356. 0,
  2357. __pyx_empty_bytes, /*PyObject *code,*/
  2358. __pyx_empty_tuple, /*PyObject *consts,*/
  2359. __pyx_empty_tuple, /*PyObject *names,*/
  2360. __pyx_empty_tuple, /*PyObject *varnames,*/
  2361. __pyx_empty_tuple, /*PyObject *freevars,*/
  2362. __pyx_empty_tuple, /*PyObject *cellvars,*/
  2363. py_srcfile, /*PyObject *filename,*/
  2364. py_funcname, /*PyObject *name,*/
  2365. py_line,
  2366. __pyx_empty_bytes /*PyObject *lnotab*/
  2367. );
  2368. Py_DECREF(py_srcfile);
  2369. Py_DECREF(py_funcname);
  2370. return py_code;
  2371. bad:
  2372. Py_XDECREF(py_srcfile);
  2373. Py_XDECREF(py_funcname);
  2374. return NULL;
  2375. }
  2376. static void __Pyx_AddTraceback(const char *funcname, int c_line,
  2377. int py_line, const char *filename) {
  2378. PyCodeObject *py_code = 0;
  2379. PyFrameObject *py_frame = 0;
  2380. PyThreadState *tstate = __Pyx_PyThreadState_Current;
  2381. if (c_line) {
  2382. c_line = __Pyx_CLineForTraceback(tstate, c_line);
  2383. }
  2384. py_code = __pyx_find_code_object(c_line ? -c_line : py_line);
  2385. if (!py_code) {
  2386. py_code = __Pyx_CreateCodeObjectForTraceback(
  2387. funcname, c_line, py_line, filename);
  2388. if (!py_code) goto bad;
  2389. __pyx_insert_code_object(c_line ? -c_line : py_line, py_code);
  2390. }
  2391. py_frame = PyFrame_New(
  2392. tstate, /*PyThreadState *tstate,*/
  2393. py_code, /*PyCodeObject *code,*/
  2394. __pyx_d, /*PyObject *globals,*/
  2395. 0 /*PyObject *locals*/
  2396. );
  2397. if (!py_frame) goto bad;
  2398. __Pyx_PyFrame_SetLineNumber(py_frame, py_line);
  2399. PyTraceBack_Here(py_frame);
  2400. bad:
  2401. Py_XDECREF(py_code);
  2402. Py_XDECREF(py_frame);
  2403. }
  2404. /* CIntToPy */
  2405. static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
  2406. const long neg_one = (long) -1, const_zero = (long) 0;
  2407. const int is_unsigned = neg_one > const_zero;
  2408. if (is_unsigned) {
  2409. if (sizeof(long) < sizeof(long)) {
  2410. return PyInt_FromLong((long) value);
  2411. } else if (sizeof(long) <= sizeof(unsigned long)) {
  2412. return PyLong_FromUnsignedLong((unsigned long) value);
  2413. #ifdef HAVE_LONG_LONG
  2414. } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
  2415. return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
  2416. #endif
  2417. }
  2418. } else {
  2419. if (sizeof(long) <= sizeof(long)) {
  2420. return PyInt_FromLong((long) value);
  2421. #ifdef HAVE_LONG_LONG
  2422. } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
  2423. return PyLong_FromLongLong((PY_LONG_LONG) value);
  2424. #endif
  2425. }
  2426. }
  2427. {
  2428. int one = 1; int little = (int)*(unsigned char *)&one;
  2429. unsigned char *bytes = (unsigned char *)&value;
  2430. return _PyLong_FromByteArray(bytes, sizeof(long),
  2431. little, !is_unsigned);
  2432. }
  2433. }
  2434. /* CIntFromPyVerify */
  2435. #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\
  2436. __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
  2437. #define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\
  2438. __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
  2439. #define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\
  2440. {\
  2441. func_type value = func_value;\
  2442. if (sizeof(target_type) < sizeof(func_type)) {\
  2443. if (unlikely(value != (func_type) (target_type) value)) {\
  2444. func_type zero = 0;\
  2445. if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\
  2446. return (target_type) -1;\
  2447. if (is_unsigned && unlikely(value < zero))\
  2448. goto raise_neg_overflow;\
  2449. else\
  2450. goto raise_overflow;\
  2451. }\
  2452. }\
  2453. return (target_type) value;\
  2454. }
  2455. /* CIntFromPy */
  2456. static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
  2457. const long neg_one = (long) -1, const_zero = (long) 0;
  2458. const int is_unsigned = neg_one > const_zero;
  2459. #if PY_MAJOR_VERSION < 3
  2460. if (likely(PyInt_Check(x))) {
  2461. if (sizeof(long) < sizeof(long)) {
  2462. __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x))
  2463. } else {
  2464. long val = PyInt_AS_LONG(x);
  2465. if (is_unsigned && unlikely(val < 0)) {
  2466. goto raise_neg_overflow;
  2467. }
  2468. return (long) val;
  2469. }
  2470. } else
  2471. #endif
  2472. if (likely(PyLong_Check(x))) {
  2473. if (is_unsigned) {
  2474. #if CYTHON_USE_PYLONG_INTERNALS
  2475. const digit* digits = ((PyLongObject*)x)->ob_digit;
  2476. switch (Py_SIZE(x)) {
  2477. case 0: return (long) 0;
  2478. case 1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0])
  2479. case 2:
  2480. if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
  2481. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  2482. __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  2483. } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) {
  2484. return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
  2485. }
  2486. }
  2487. break;
  2488. case 3:
  2489. if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
  2490. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  2491. __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  2492. } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) {
  2493. return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
  2494. }
  2495. }
  2496. break;
  2497. case 4:
  2498. if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
  2499. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  2500. __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  2501. } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) {
  2502. return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
  2503. }
  2504. }
  2505. break;
  2506. }
  2507. #endif
  2508. #if CYTHON_COMPILING_IN_CPYTHON
  2509. if (unlikely(Py_SIZE(x) < 0)) {
  2510. goto raise_neg_overflow;
  2511. }
  2512. #else
  2513. {
  2514. int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
  2515. if (unlikely(result < 0))
  2516. return (long) -1;
  2517. if (unlikely(result == 1))
  2518. goto raise_neg_overflow;
  2519. }
  2520. #endif
  2521. if (sizeof(long) <= sizeof(unsigned long)) {
  2522. __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
  2523. #ifdef HAVE_LONG_LONG
  2524. } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
  2525. __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
  2526. #endif
  2527. }
  2528. } else {
  2529. #if CYTHON_USE_PYLONG_INTERNALS
  2530. const digit* digits = ((PyLongObject*)x)->ob_digit;
  2531. switch (Py_SIZE(x)) {
  2532. case 0: return (long) 0;
  2533. case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0]))
  2534. case 1: __PYX_VERIFY_RETURN_INT(long, digit, +digits[0])
  2535. case -2:
  2536. if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) {
  2537. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  2538. __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  2539. } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
  2540. return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
  2541. }
  2542. }
  2543. break;
  2544. case 2:
  2545. if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
  2546. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  2547. __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  2548. } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
  2549. return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
  2550. }
  2551. }
  2552. break;
  2553. case -3:
  2554. if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
  2555. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  2556. __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  2557. } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
  2558. return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
  2559. }
  2560. }
  2561. break;
  2562. case 3:
  2563. if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
  2564. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  2565. __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  2566. } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
  2567. return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
  2568. }
  2569. }
  2570. break;
  2571. case -4:
  2572. if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
  2573. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  2574. __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  2575. } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
  2576. return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
  2577. }
  2578. }
  2579. break;
  2580. case 4:
  2581. if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
  2582. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  2583. __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  2584. } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
  2585. return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
  2586. }
  2587. }
  2588. break;
  2589. }
  2590. #endif
  2591. if (sizeof(long) <= sizeof(long)) {
  2592. __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
  2593. #ifdef HAVE_LONG_LONG
  2594. } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
  2595. __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
  2596. #endif
  2597. }
  2598. }
  2599. {
  2600. #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
  2601. PyErr_SetString(PyExc_RuntimeError,
  2602. "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
  2603. #else
  2604. long val;
  2605. PyObject *v = __Pyx_PyNumber_IntOrLong(x);
  2606. #if PY_MAJOR_VERSION < 3
  2607. if (likely(v) && !PyLong_Check(v)) {
  2608. PyObject *tmp = v;
  2609. v = PyNumber_Long(tmp);
  2610. Py_DECREF(tmp);
  2611. }
  2612. #endif
  2613. if (likely(v)) {
  2614. int one = 1; int is_little = (int)*(unsigned char *)&one;
  2615. unsigned char *bytes = (unsigned char *)&val;
  2616. int ret = _PyLong_AsByteArray((PyLongObject *)v,
  2617. bytes, sizeof(val),
  2618. is_little, !is_unsigned);
  2619. Py_DECREF(v);
  2620. if (likely(!ret))
  2621. return val;
  2622. }
  2623. #endif
  2624. return (long) -1;
  2625. }
  2626. } else {
  2627. long val;
  2628. PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
  2629. if (!tmp) return (long) -1;
  2630. val = __Pyx_PyInt_As_long(tmp);
  2631. Py_DECREF(tmp);
  2632. return val;
  2633. }
  2634. raise_overflow:
  2635. PyErr_SetString(PyExc_OverflowError,
  2636. "value too large to convert to long");
  2637. return (long) -1;
  2638. raise_neg_overflow:
  2639. PyErr_SetString(PyExc_OverflowError,
  2640. "can't convert negative value to long");
  2641. return (long) -1;
  2642. }
  2643. /* CIntFromPy */
  2644. static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
  2645. const int neg_one = (int) -1, const_zero = (int) 0;
  2646. const int is_unsigned = neg_one > const_zero;
  2647. #if PY_MAJOR_VERSION < 3
  2648. if (likely(PyInt_Check(x))) {
  2649. if (sizeof(int) < sizeof(long)) {
  2650. __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x))
  2651. } else {
  2652. long val = PyInt_AS_LONG(x);
  2653. if (is_unsigned && unlikely(val < 0)) {
  2654. goto raise_neg_overflow;
  2655. }
  2656. return (int) val;
  2657. }
  2658. } else
  2659. #endif
  2660. if (likely(PyLong_Check(x))) {
  2661. if (is_unsigned) {
  2662. #if CYTHON_USE_PYLONG_INTERNALS
  2663. const digit* digits = ((PyLongObject*)x)->ob_digit;
  2664. switch (Py_SIZE(x)) {
  2665. case 0: return (int) 0;
  2666. case 1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0])
  2667. case 2:
  2668. if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
  2669. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  2670. __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  2671. } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) {
  2672. return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
  2673. }
  2674. }
  2675. break;
  2676. case 3:
  2677. if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
  2678. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  2679. __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  2680. } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) {
  2681. return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
  2682. }
  2683. }
  2684. break;
  2685. case 4:
  2686. if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
  2687. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  2688. __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  2689. } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) {
  2690. return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
  2691. }
  2692. }
  2693. break;
  2694. }
  2695. #endif
  2696. #if CYTHON_COMPILING_IN_CPYTHON
  2697. if (unlikely(Py_SIZE(x) < 0)) {
  2698. goto raise_neg_overflow;
  2699. }
  2700. #else
  2701. {
  2702. int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
  2703. if (unlikely(result < 0))
  2704. return (int) -1;
  2705. if (unlikely(result == 1))
  2706. goto raise_neg_overflow;
  2707. }
  2708. #endif
  2709. if (sizeof(int) <= sizeof(unsigned long)) {
  2710. __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
  2711. #ifdef HAVE_LONG_LONG
  2712. } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
  2713. __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
  2714. #endif
  2715. }
  2716. } else {
  2717. #if CYTHON_USE_PYLONG_INTERNALS
  2718. const digit* digits = ((PyLongObject*)x)->ob_digit;
  2719. switch (Py_SIZE(x)) {
  2720. case 0: return (int) 0;
  2721. case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0]))
  2722. case 1: __PYX_VERIFY_RETURN_INT(int, digit, +digits[0])
  2723. case -2:
  2724. if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) {
  2725. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  2726. __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  2727. } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
  2728. return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
  2729. }
  2730. }
  2731. break;
  2732. case 2:
  2733. if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
  2734. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  2735. __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  2736. } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
  2737. return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
  2738. }
  2739. }
  2740. break;
  2741. case -3:
  2742. if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
  2743. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  2744. __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  2745. } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
  2746. return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
  2747. }
  2748. }
  2749. break;
  2750. case 3:
  2751. if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
  2752. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  2753. __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  2754. } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
  2755. return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
  2756. }
  2757. }
  2758. break;
  2759. case -4:
  2760. if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
  2761. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  2762. __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  2763. } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
  2764. return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
  2765. }
  2766. }
  2767. break;
  2768. case 4:
  2769. if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
  2770. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  2771. __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  2772. } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
  2773. return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
  2774. }
  2775. }
  2776. break;
  2777. }
  2778. #endif
  2779. if (sizeof(int) <= sizeof(long)) {
  2780. __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
  2781. #ifdef HAVE_LONG_LONG
  2782. } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
  2783. __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
  2784. #endif
  2785. }
  2786. }
  2787. {
  2788. #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
  2789. PyErr_SetString(PyExc_RuntimeError,
  2790. "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
  2791. #else
  2792. int val;
  2793. PyObject *v = __Pyx_PyNumber_IntOrLong(x);
  2794. #if PY_MAJOR_VERSION < 3
  2795. if (likely(v) && !PyLong_Check(v)) {
  2796. PyObject *tmp = v;
  2797. v = PyNumber_Long(tmp);
  2798. Py_DECREF(tmp);
  2799. }
  2800. #endif
  2801. if (likely(v)) {
  2802. int one = 1; int is_little = (int)*(unsigned char *)&one;
  2803. unsigned char *bytes = (unsigned char *)&val;
  2804. int ret = _PyLong_AsByteArray((PyLongObject *)v,
  2805. bytes, sizeof(val),
  2806. is_little, !is_unsigned);
  2807. Py_DECREF(v);
  2808. if (likely(!ret))
  2809. return val;
  2810. }
  2811. #endif
  2812. return (int) -1;
  2813. }
  2814. } else {
  2815. int val;
  2816. PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
  2817. if (!tmp) return (int) -1;
  2818. val = __Pyx_PyInt_As_int(tmp);
  2819. Py_DECREF(tmp);
  2820. return val;
  2821. }
  2822. raise_overflow:
  2823. PyErr_SetString(PyExc_OverflowError,
  2824. "value too large to convert to int");
  2825. return (int) -1;
  2826. raise_neg_overflow:
  2827. PyErr_SetString(PyExc_OverflowError,
  2828. "can't convert negative value to int");
  2829. return (int) -1;
  2830. }
  2831. /* FastTypeChecks */
  2832. #if CYTHON_COMPILING_IN_CPYTHON
  2833. static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) {
  2834. while (a) {
  2835. a = a->tp_base;
  2836. if (a == b)
  2837. return 1;
  2838. }
  2839. return b == &PyBaseObject_Type;
  2840. }
  2841. static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) {
  2842. PyObject *mro;
  2843. if (a == b) return 1;
  2844. mro = a->tp_mro;
  2845. if (likely(mro)) {
  2846. Py_ssize_t i, n;
  2847. n = PyTuple_GET_SIZE(mro);
  2848. for (i = 0; i < n; i++) {
  2849. if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b)
  2850. return 1;
  2851. }
  2852. return 0;
  2853. }
  2854. return __Pyx_InBases(a, b);
  2855. }
  2856. #if PY_MAJOR_VERSION == 2
  2857. static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) {
  2858. PyObject *exception, *value, *tb;
  2859. int res;
  2860. __Pyx_PyThreadState_declare
  2861. __Pyx_PyThreadState_assign
  2862. __Pyx_ErrFetch(&exception, &value, &tb);
  2863. res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0;
  2864. if (unlikely(res == -1)) {
  2865. PyErr_WriteUnraisable(err);
  2866. res = 0;
  2867. }
  2868. if (!res) {
  2869. res = PyObject_IsSubclass(err, exc_type2);
  2870. if (unlikely(res == -1)) {
  2871. PyErr_WriteUnraisable(err);
  2872. res = 0;
  2873. }
  2874. }
  2875. __Pyx_ErrRestore(exception, value, tb);
  2876. return res;
  2877. }
  2878. #else
  2879. static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) {
  2880. int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0;
  2881. if (!res) {
  2882. res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2);
  2883. }
  2884. return res;
  2885. }
  2886. #endif
  2887. static int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
  2888. Py_ssize_t i, n;
  2889. assert(PyExceptionClass_Check(exc_type));
  2890. n = PyTuple_GET_SIZE(tuple);
  2891. #if PY_MAJOR_VERSION >= 3
  2892. for (i=0; i<n; i++) {
  2893. if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
  2894. }
  2895. #endif
  2896. for (i=0; i<n; i++) {
  2897. PyObject *t = PyTuple_GET_ITEM(tuple, i);
  2898. #if PY_MAJOR_VERSION < 3
  2899. if (likely(exc_type == t)) return 1;
  2900. #endif
  2901. if (likely(PyExceptionClass_Check(t))) {
  2902. if (__Pyx_inner_PyErr_GivenExceptionMatches2(exc_type, NULL, t)) return 1;
  2903. } else {
  2904. }
  2905. }
  2906. return 0;
  2907. }
  2908. static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject* exc_type) {
  2909. if (likely(err == exc_type)) return 1;
  2910. if (likely(PyExceptionClass_Check(err))) {
  2911. if (likely(PyExceptionClass_Check(exc_type))) {
  2912. return __Pyx_inner_PyErr_GivenExceptionMatches2(err, NULL, exc_type);
  2913. } else if (likely(PyTuple_Check(exc_type))) {
  2914. return __Pyx_PyErr_GivenExceptionMatchesTuple(err, exc_type);
  2915. } else {
  2916. }
  2917. }
  2918. return PyErr_GivenExceptionMatches(err, exc_type);
  2919. }
  2920. static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *exc_type1, PyObject *exc_type2) {
  2921. assert(PyExceptionClass_Check(exc_type1));
  2922. assert(PyExceptionClass_Check(exc_type2));
  2923. if (likely(err == exc_type1 || err == exc_type2)) return 1;
  2924. if (likely(PyExceptionClass_Check(err))) {
  2925. return __Pyx_inner_PyErr_GivenExceptionMatches2(err, exc_type1, exc_type2);
  2926. }
  2927. return (PyErr_GivenExceptionMatches(err, exc_type1) || PyErr_GivenExceptionMatches(err, exc_type2));
  2928. }
  2929. #endif
  2930. /* CheckBinaryVersion */
  2931. static int __Pyx_check_binary_version(void) {
  2932. char ctversion[4], rtversion[4];
  2933. PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
  2934. PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
  2935. if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
  2936. char message[200];
  2937. PyOS_snprintf(message, sizeof(message),
  2938. "compiletime version %s of module '%.100s' "
  2939. "does not match runtime version %s",
  2940. ctversion, __Pyx_MODULE_NAME, rtversion);
  2941. return PyErr_WarnEx(NULL, message, 1);
  2942. }
  2943. return 0;
  2944. }
  2945. /* ModuleImport */
  2946. #ifndef __PYX_HAVE_RT_ImportModule
  2947. #define __PYX_HAVE_RT_ImportModule
  2948. static PyObject *__Pyx_ImportModule(const char *name) {
  2949. PyObject *py_name = 0;
  2950. PyObject *py_module = 0;
  2951. py_name = __Pyx_PyIdentifier_FromString(name);
  2952. if (!py_name)
  2953. goto bad;
  2954. py_module = PyImport_Import(py_name);
  2955. Py_DECREF(py_name);
  2956. return py_module;
  2957. bad:
  2958. Py_XDECREF(py_name);
  2959. return 0;
  2960. }
  2961. #endif
  2962. /* TypeImport */
  2963. #ifndef __PYX_HAVE_RT_ImportType
  2964. #define __PYX_HAVE_RT_ImportType
  2965. static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name,
  2966. size_t size, int strict)
  2967. {
  2968. PyObject *py_module = 0;
  2969. PyObject *result = 0;
  2970. PyObject *py_name = 0;
  2971. char warning[200];
  2972. Py_ssize_t basicsize;
  2973. #ifdef Py_LIMITED_API
  2974. PyObject *py_basicsize;
  2975. #endif
  2976. py_module = __Pyx_ImportModule(module_name);
  2977. if (!py_module)
  2978. goto bad;
  2979. py_name = __Pyx_PyIdentifier_FromString(class_name);
  2980. if (!py_name)
  2981. goto bad;
  2982. result = PyObject_GetAttr(py_module, py_name);
  2983. Py_DECREF(py_name);
  2984. py_name = 0;
  2985. Py_DECREF(py_module);
  2986. py_module = 0;
  2987. if (!result)
  2988. goto bad;
  2989. if (!PyType_Check(result)) {
  2990. PyErr_Format(PyExc_TypeError,
  2991. "%.200s.%.200s is not a type object",
  2992. module_name, class_name);
  2993. goto bad;
  2994. }
  2995. #ifndef Py_LIMITED_API
  2996. basicsize = ((PyTypeObject *)result)->tp_basicsize;
  2997. #else
  2998. py_basicsize = PyObject_GetAttrString(result, "__basicsize__");
  2999. if (!py_basicsize)
  3000. goto bad;
  3001. basicsize = PyLong_AsSsize_t(py_basicsize);
  3002. Py_DECREF(py_basicsize);
  3003. py_basicsize = 0;
  3004. if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred())
  3005. goto bad;
  3006. #endif
  3007. if (!strict && (size_t)basicsize > size) {
  3008. PyOS_snprintf(warning, sizeof(warning),
  3009. "%s.%s size changed, may indicate binary incompatibility. Expected %zd, got %zd",
  3010. module_name, class_name, basicsize, size);
  3011. if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
  3012. }
  3013. else if ((size_t)basicsize != size) {
  3014. PyErr_Format(PyExc_ValueError,
  3015. "%.200s.%.200s has the wrong size, try recompiling. Expected %zd, got %zd",
  3016. module_name, class_name, basicsize, size);
  3017. goto bad;
  3018. }
  3019. return (PyTypeObject *)result;
  3020. bad:
  3021. Py_XDECREF(py_module);
  3022. Py_XDECREF(result);
  3023. return NULL;
  3024. }
  3025. #endif
  3026. /* InitStrings */
  3027. static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
  3028. while (t->p) {
  3029. #if PY_MAJOR_VERSION < 3
  3030. if (t->is_unicode) {
  3031. *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
  3032. } else if (t->intern) {
  3033. *t->p = PyString_InternFromString(t->s);
  3034. } else {
  3035. *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
  3036. }
  3037. #else
  3038. if (t->is_unicode | t->is_str) {
  3039. if (t->intern) {
  3040. *t->p = PyUnicode_InternFromString(t->s);
  3041. } else if (t->encoding) {
  3042. *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
  3043. } else {
  3044. *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
  3045. }
  3046. } else {
  3047. *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
  3048. }
  3049. #endif
  3050. if (!*t->p)
  3051. return -1;
  3052. if (PyObject_Hash(*t->p) == -1)
  3053. return -1;
  3054. ++t;
  3055. }
  3056. return 0;
  3057. }
  3058. static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
  3059. return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str));
  3060. }
  3061. static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) {
  3062. Py_ssize_t ignore;
  3063. return __Pyx_PyObject_AsStringAndSize(o, &ignore);
  3064. }
  3065. #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
  3066. #if !CYTHON_PEP393_ENABLED
  3067. static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
  3068. char* defenc_c;
  3069. PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL);
  3070. if (!defenc) return NULL;
  3071. defenc_c = PyBytes_AS_STRING(defenc);
  3072. #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
  3073. {
  3074. char* end = defenc_c + PyBytes_GET_SIZE(defenc);
  3075. char* c;
  3076. for (c = defenc_c; c < end; c++) {
  3077. if ((unsigned char) (*c) >= 128) {
  3078. PyUnicode_AsASCIIString(o);
  3079. return NULL;
  3080. }
  3081. }
  3082. }
  3083. #endif
  3084. *length = PyBytes_GET_SIZE(defenc);
  3085. return defenc_c;
  3086. }
  3087. #else
  3088. static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
  3089. if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL;
  3090. #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
  3091. if (likely(PyUnicode_IS_ASCII(o))) {
  3092. *length = PyUnicode_GET_LENGTH(o);
  3093. return PyUnicode_AsUTF8(o);
  3094. } else {
  3095. PyUnicode_AsASCIIString(o);
  3096. return NULL;
  3097. }
  3098. #else
  3099. return PyUnicode_AsUTF8AndSize(o, length);
  3100. #endif
  3101. }
  3102. #endif
  3103. #endif
  3104. static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
  3105. #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
  3106. if (
  3107. #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
  3108. __Pyx_sys_getdefaultencoding_not_ascii &&
  3109. #endif
  3110. PyUnicode_Check(o)) {
  3111. return __Pyx_PyUnicode_AsStringAndSize(o, length);
  3112. } else
  3113. #endif
  3114. #if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
  3115. if (PyByteArray_Check(o)) {
  3116. *length = PyByteArray_GET_SIZE(o);
  3117. return PyByteArray_AS_STRING(o);
  3118. } else
  3119. #endif
  3120. {
  3121. char* result;
  3122. int r = PyBytes_AsStringAndSize(o, &result, length);
  3123. if (unlikely(r < 0)) {
  3124. return NULL;
  3125. } else {
  3126. return result;
  3127. }
  3128. }
  3129. }
  3130. static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
  3131. int is_true = x == Py_True;
  3132. if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
  3133. else return PyObject_IsTrue(x);
  3134. }
  3135. static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) {
  3136. #if PY_MAJOR_VERSION >= 3
  3137. if (PyLong_Check(result)) {
  3138. if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
  3139. "__int__ returned non-int (type %.200s). "
  3140. "The ability to return an instance of a strict subclass of int "
  3141. "is deprecated, and may be removed in a future version of Python.",
  3142. Py_TYPE(result)->tp_name)) {
  3143. Py_DECREF(result);
  3144. return NULL;
  3145. }
  3146. return result;
  3147. }
  3148. #endif
  3149. PyErr_Format(PyExc_TypeError,
  3150. "__%.4s__ returned non-%.4s (type %.200s)",
  3151. type_name, type_name, Py_TYPE(result)->tp_name);
  3152. Py_DECREF(result);
  3153. return NULL;
  3154. }
  3155. static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) {
  3156. #if CYTHON_USE_TYPE_SLOTS
  3157. PyNumberMethods *m;
  3158. #endif
  3159. const char *name = NULL;
  3160. PyObject *res = NULL;
  3161. #if PY_MAJOR_VERSION < 3
  3162. if (likely(PyInt_Check(x) || PyLong_Check(x)))
  3163. #else
  3164. if (likely(PyLong_Check(x)))
  3165. #endif
  3166. return __Pyx_NewRef(x);
  3167. #if CYTHON_USE_TYPE_SLOTS
  3168. m = Py_TYPE(x)->tp_as_number;
  3169. #if PY_MAJOR_VERSION < 3
  3170. if (m && m->nb_int) {
  3171. name = "int";
  3172. res = m->nb_int(x);
  3173. }
  3174. else if (m && m->nb_long) {
  3175. name = "long";
  3176. res = m->nb_long(x);
  3177. }
  3178. #else
  3179. if (likely(m && m->nb_int)) {
  3180. name = "int";
  3181. res = m->nb_int(x);
  3182. }
  3183. #endif
  3184. #else
  3185. if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) {
  3186. res = PyNumber_Int(x);
  3187. }
  3188. #endif
  3189. if (likely(res)) {
  3190. #if PY_MAJOR_VERSION < 3
  3191. if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) {
  3192. #else
  3193. if (unlikely(!PyLong_CheckExact(res))) {
  3194. #endif
  3195. return __Pyx_PyNumber_IntOrLongWrongResultType(res, name);
  3196. }
  3197. }
  3198. else if (!PyErr_Occurred()) {
  3199. PyErr_SetString(PyExc_TypeError,
  3200. "an integer is required");
  3201. }
  3202. return res;
  3203. }
  3204. static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
  3205. Py_ssize_t ival;
  3206. PyObject *x;
  3207. #if PY_MAJOR_VERSION < 3
  3208. if (likely(PyInt_CheckExact(b))) {
  3209. if (sizeof(Py_ssize_t) >= sizeof(long))
  3210. return PyInt_AS_LONG(b);
  3211. else
  3212. return PyInt_AsSsize_t(x);
  3213. }
  3214. #endif
  3215. if (likely(PyLong_CheckExact(b))) {
  3216. #if CYTHON_USE_PYLONG_INTERNALS
  3217. const digit* digits = ((PyLongObject*)b)->ob_digit;
  3218. const Py_ssize_t size = Py_SIZE(b);
  3219. if (likely(__Pyx_sst_abs(size) <= 1)) {
  3220. ival = likely(size) ? digits[0] : 0;
  3221. if (size == -1) ival = -ival;
  3222. return ival;
  3223. } else {
  3224. switch (size) {
  3225. case 2:
  3226. if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
  3227. return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
  3228. }
  3229. break;
  3230. case -2:
  3231. if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
  3232. return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
  3233. }
  3234. break;
  3235. case 3:
  3236. if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
  3237. return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
  3238. }
  3239. break;
  3240. case -3:
  3241. if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
  3242. return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
  3243. }
  3244. break;
  3245. case 4:
  3246. if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
  3247. return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
  3248. }
  3249. break;
  3250. case -4:
  3251. if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
  3252. return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
  3253. }
  3254. break;
  3255. }
  3256. }
  3257. #endif
  3258. return PyLong_AsSsize_t(b);
  3259. }
  3260. x = PyNumber_Index(b);
  3261. if (!x) return -1;
  3262. ival = PyInt_AsSsize_t(x);
  3263. Py_DECREF(x);
  3264. return ival;
  3265. }
  3266. static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) {
  3267. return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False);
  3268. }
  3269. static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
  3270. return PyInt_FromSize_t(ival);
  3271. }
  3272. #endif /* Py_PYTHON_H */