ModuleSetupCode.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394
  1. /////////////// CModulePreamble ///////////////
  2. #include <stddef.h> /* For offsetof */
  3. #ifndef offsetof
  4. #define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
  5. #endif
  6. #if !defined(WIN32) && !defined(MS_WINDOWS)
  7. #ifndef __stdcall
  8. #define __stdcall
  9. #endif
  10. #ifndef __cdecl
  11. #define __cdecl
  12. #endif
  13. #ifndef __fastcall
  14. #define __fastcall
  15. #endif
  16. #endif
  17. #ifndef DL_IMPORT
  18. #define DL_IMPORT(t) t
  19. #endif
  20. #ifndef DL_EXPORT
  21. #define DL_EXPORT(t) t
  22. #endif
  23. // For use in DL_IMPORT/DL_EXPORT macros.
  24. #define __PYX_COMMA ,
  25. #ifndef HAVE_LONG_LONG
  26. // CPython has required PY_LONG_LONG support for years, even if HAVE_LONG_LONG is not defined for us
  27. #if PY_VERSION_HEX >= 0x02070000
  28. #define HAVE_LONG_LONG
  29. #endif
  30. #endif
  31. #ifndef PY_LONG_LONG
  32. #define PY_LONG_LONG LONG_LONG
  33. #endif
  34. #ifndef Py_HUGE_VAL
  35. #define Py_HUGE_VAL HUGE_VAL
  36. #endif
  37. #ifdef PYPY_VERSION
  38. #define CYTHON_COMPILING_IN_PYPY 1
  39. #define CYTHON_COMPILING_IN_PYSTON 0
  40. #define CYTHON_COMPILING_IN_CPYTHON 0
  41. #undef CYTHON_USE_TYPE_SLOTS
  42. #define CYTHON_USE_TYPE_SLOTS 0
  43. #undef CYTHON_USE_PYTYPE_LOOKUP
  44. #define CYTHON_USE_PYTYPE_LOOKUP 0
  45. #if PY_VERSION_HEX < 0x03050000
  46. #undef CYTHON_USE_ASYNC_SLOTS
  47. #define CYTHON_USE_ASYNC_SLOTS 0
  48. #elif !defined(CYTHON_USE_ASYNC_SLOTS)
  49. #define CYTHON_USE_ASYNC_SLOTS 1
  50. #endif
  51. #undef CYTHON_USE_PYLIST_INTERNALS
  52. #define CYTHON_USE_PYLIST_INTERNALS 0
  53. #undef CYTHON_USE_UNICODE_INTERNALS
  54. #define CYTHON_USE_UNICODE_INTERNALS 0
  55. #undef CYTHON_USE_UNICODE_WRITER
  56. #define CYTHON_USE_UNICODE_WRITER 0
  57. #undef CYTHON_USE_PYLONG_INTERNALS
  58. #define CYTHON_USE_PYLONG_INTERNALS 0
  59. #undef CYTHON_AVOID_BORROWED_REFS
  60. #define CYTHON_AVOID_BORROWED_REFS 1
  61. #undef CYTHON_ASSUME_SAFE_MACROS
  62. #define CYTHON_ASSUME_SAFE_MACROS 0
  63. #undef CYTHON_UNPACK_METHODS
  64. #define CYTHON_UNPACK_METHODS 0
  65. #undef CYTHON_FAST_THREAD_STATE
  66. #define CYTHON_FAST_THREAD_STATE 0
  67. #undef CYTHON_FAST_PYCALL
  68. #define CYTHON_FAST_PYCALL 0
  69. #undef CYTHON_PEP489_MULTI_PHASE_INIT
  70. #define CYTHON_PEP489_MULTI_PHASE_INIT 0
  71. #undef CYTHON_USE_TP_FINALIZE
  72. #define CYTHON_USE_TP_FINALIZE 0
  73. #elif defined(PYSTON_VERSION)
  74. #define CYTHON_COMPILING_IN_PYPY 0
  75. #define CYTHON_COMPILING_IN_PYSTON 1
  76. #define CYTHON_COMPILING_IN_CPYTHON 0
  77. #ifndef CYTHON_USE_TYPE_SLOTS
  78. #define CYTHON_USE_TYPE_SLOTS 1
  79. #endif
  80. #undef CYTHON_USE_PYTYPE_LOOKUP
  81. #define CYTHON_USE_PYTYPE_LOOKUP 0
  82. #undef CYTHON_USE_ASYNC_SLOTS
  83. #define CYTHON_USE_ASYNC_SLOTS 0
  84. #undef CYTHON_USE_PYLIST_INTERNALS
  85. #define CYTHON_USE_PYLIST_INTERNALS 0
  86. #ifndef CYTHON_USE_UNICODE_INTERNALS
  87. #define CYTHON_USE_UNICODE_INTERNALS 1
  88. #endif
  89. #undef CYTHON_USE_UNICODE_WRITER
  90. #define CYTHON_USE_UNICODE_WRITER 0
  91. #undef CYTHON_USE_PYLONG_INTERNALS
  92. #define CYTHON_USE_PYLONG_INTERNALS 0
  93. #ifndef CYTHON_AVOID_BORROWED_REFS
  94. #define CYTHON_AVOID_BORROWED_REFS 0
  95. #endif
  96. #ifndef CYTHON_ASSUME_SAFE_MACROS
  97. #define CYTHON_ASSUME_SAFE_MACROS 1
  98. #endif
  99. #ifndef CYTHON_UNPACK_METHODS
  100. #define CYTHON_UNPACK_METHODS 1
  101. #endif
  102. #undef CYTHON_FAST_THREAD_STATE
  103. #define CYTHON_FAST_THREAD_STATE 0
  104. #undef CYTHON_FAST_PYCALL
  105. #define CYTHON_FAST_PYCALL 0
  106. #undef CYTHON_PEP489_MULTI_PHASE_INIT
  107. #define CYTHON_PEP489_MULTI_PHASE_INIT 0
  108. #undef CYTHON_USE_TP_FINALIZE
  109. #define CYTHON_USE_TP_FINALIZE 0
  110. #else
  111. #define CYTHON_COMPILING_IN_PYPY 0
  112. #define CYTHON_COMPILING_IN_PYSTON 0
  113. #define CYTHON_COMPILING_IN_CPYTHON 1
  114. #ifndef CYTHON_USE_TYPE_SLOTS
  115. #define CYTHON_USE_TYPE_SLOTS 1
  116. #endif
  117. #if PY_VERSION_HEX < 0x02070000
  118. // looks like calling _PyType_Lookup() isn't safe in Py<=2.6/3.1
  119. #undef CYTHON_USE_PYTYPE_LOOKUP
  120. #define CYTHON_USE_PYTYPE_LOOKUP 0
  121. #elif !defined(CYTHON_USE_PYTYPE_LOOKUP)
  122. #define CYTHON_USE_PYTYPE_LOOKUP 1
  123. #endif
  124. #if PY_MAJOR_VERSION < 3
  125. #undef CYTHON_USE_ASYNC_SLOTS
  126. #define CYTHON_USE_ASYNC_SLOTS 0
  127. #elif !defined(CYTHON_USE_ASYNC_SLOTS)
  128. #define CYTHON_USE_ASYNC_SLOTS 1
  129. #endif
  130. #if PY_VERSION_HEX < 0x02070000
  131. #undef CYTHON_USE_PYLONG_INTERNALS
  132. #define CYTHON_USE_PYLONG_INTERNALS 0
  133. #elif !defined(CYTHON_USE_PYLONG_INTERNALS)
  134. #define CYTHON_USE_PYLONG_INTERNALS 1
  135. #endif
  136. #ifndef CYTHON_USE_PYLIST_INTERNALS
  137. #define CYTHON_USE_PYLIST_INTERNALS 1
  138. #endif
  139. #ifndef CYTHON_USE_UNICODE_INTERNALS
  140. #define CYTHON_USE_UNICODE_INTERNALS 1
  141. #endif
  142. #if PY_VERSION_HEX < 0x030300F0
  143. #undef CYTHON_USE_UNICODE_WRITER
  144. #define CYTHON_USE_UNICODE_WRITER 0
  145. #elif !defined(CYTHON_USE_UNICODE_WRITER)
  146. #define CYTHON_USE_UNICODE_WRITER 1
  147. #endif
  148. #ifndef CYTHON_AVOID_BORROWED_REFS
  149. #define CYTHON_AVOID_BORROWED_REFS 0
  150. #endif
  151. #ifndef CYTHON_ASSUME_SAFE_MACROS
  152. #define CYTHON_ASSUME_SAFE_MACROS 1
  153. #endif
  154. #ifndef CYTHON_UNPACK_METHODS
  155. #define CYTHON_UNPACK_METHODS 1
  156. #endif
  157. #ifndef CYTHON_FAST_THREAD_STATE
  158. #define CYTHON_FAST_THREAD_STATE 1
  159. #endif
  160. #ifndef CYTHON_FAST_PYCALL
  161. #define CYTHON_FAST_PYCALL 1
  162. #endif
  163. #ifndef CYTHON_PEP489_MULTI_PHASE_INIT
  164. // Disabled for now. Most extension modules simply can't deal with it, and Cython isn't ready either.
  165. // See issues listed here: https://docs.python.org/3/c-api/init.html#sub-interpreter-support
  166. #define CYTHON_PEP489_MULTI_PHASE_INIT (0 && PY_VERSION_HEX >= 0x03050000)
  167. #endif
  168. #ifndef CYTHON_USE_TP_FINALIZE
  169. #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1)
  170. #endif
  171. #endif
  172. #if !defined(CYTHON_FAST_PYCCALL)
  173. #define CYTHON_FAST_PYCCALL (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1)
  174. #endif
  175. #if CYTHON_USE_PYLONG_INTERNALS
  176. #include "longintrepr.h"
  177. /* These short defines can easily conflict with other code */
  178. #undef SHIFT
  179. #undef BASE
  180. #undef MASK
  181. #endif
  182. #ifndef __has_attribute
  183. #define __has_attribute(x) 0
  184. #endif
  185. #ifndef __has_cpp_attribute
  186. #define __has_cpp_attribute(x) 0
  187. #endif
  188. // restrict
  189. #ifndef CYTHON_RESTRICT
  190. #if defined(__GNUC__)
  191. #define CYTHON_RESTRICT __restrict__
  192. #elif defined(_MSC_VER) && _MSC_VER >= 1400
  193. #define CYTHON_RESTRICT __restrict
  194. #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  195. #define CYTHON_RESTRICT restrict
  196. #else
  197. #define CYTHON_RESTRICT
  198. #endif
  199. #endif
  200. // unused attribute
  201. #ifndef CYTHON_UNUSED
  202. # if defined(__GNUC__)
  203. # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
  204. # define CYTHON_UNUSED __attribute__ ((__unused__))
  205. # else
  206. # define CYTHON_UNUSED
  207. # endif
  208. # elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
  209. # define CYTHON_UNUSED __attribute__ ((__unused__))
  210. # else
  211. # define CYTHON_UNUSED
  212. # endif
  213. #endif
  214. #ifndef CYTHON_MAYBE_UNUSED_VAR
  215. # if defined(__cplusplus)
  216. template<class T> void CYTHON_MAYBE_UNUSED_VAR( const T& ) { }
  217. # else
  218. # define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x)
  219. # endif
  220. #endif
  221. #ifndef CYTHON_NCP_UNUSED
  222. # if CYTHON_COMPILING_IN_CPYTHON
  223. # define CYTHON_NCP_UNUSED
  224. # else
  225. # define CYTHON_NCP_UNUSED CYTHON_UNUSED
  226. # endif
  227. #endif
  228. #define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None)
  229. #ifdef _MSC_VER
  230. #ifndef _MSC_STDINT_H_
  231. #if _MSC_VER < 1300
  232. typedef unsigned char uint8_t;
  233. typedef unsigned int uint32_t;
  234. #else
  235. typedef unsigned __int8 uint8_t;
  236. typedef unsigned __int32 uint32_t;
  237. #endif
  238. #endif
  239. #else
  240. #include <stdint.h>
  241. #endif
  242. #ifndef CYTHON_FALLTHROUGH
  243. #if defined(__cplusplus) && __cplusplus >= 201103L
  244. #if __has_cpp_attribute(fallthrough)
  245. #define CYTHON_FALLTHROUGH [[fallthrough]]
  246. #elif __has_cpp_attribute(clang::fallthrough)
  247. #define CYTHON_FALLTHROUGH [[clang::fallthrough]]
  248. #elif __has_cpp_attribute(gnu::fallthrough)
  249. #define CYTHON_FALLTHROUGH [[gnu::fallthrough]]
  250. #endif
  251. #endif
  252. #ifndef CYTHON_FALLTHROUGH
  253. #if __has_attribute(fallthrough)
  254. #define CYTHON_FALLTHROUGH __attribute__((fallthrough))
  255. #else
  256. #define CYTHON_FALLTHROUGH
  257. #endif
  258. #endif
  259. #if defined(__clang__ ) && defined(__apple_build_version__)
  260. #if __apple_build_version__ < 7000000 /* Xcode < 7.0 */
  261. #undef CYTHON_FALLTHROUGH
  262. #define CYTHON_FALLTHROUGH
  263. #endif
  264. #endif
  265. #endif
  266. /////////////// CInitCode ///////////////
  267. // inline attribute
  268. #ifndef CYTHON_INLINE
  269. #if defined(__clang__)
  270. #define CYTHON_INLINE __inline__ __attribute__ ((__unused__))
  271. #elif defined(__GNUC__)
  272. #define CYTHON_INLINE __inline__
  273. #elif defined(_MSC_VER)
  274. #define CYTHON_INLINE __inline
  275. #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  276. #define CYTHON_INLINE inline
  277. #else
  278. #define CYTHON_INLINE
  279. #endif
  280. #endif
  281. /////////////// CppInitCode ///////////////
  282. #ifndef __cplusplus
  283. #error "Cython files generated with the C++ option must be compiled with a C++ compiler."
  284. #endif
  285. // inline attribute
  286. #ifndef CYTHON_INLINE
  287. #if defined(__clang__)
  288. #define CYTHON_INLINE __inline__ __attribute__ ((__unused__))
  289. #else
  290. #define CYTHON_INLINE inline
  291. #endif
  292. #endif
  293. // Work around clang bug http://stackoverflow.com/questions/21847816/c-invoke-nested-template-class-destructor
  294. template<typename T>
  295. void __Pyx_call_destructor(T& x) {
  296. x.~T();
  297. }
  298. // Used for temporary variables of "reference" type.
  299. template<typename T>
  300. class __Pyx_FakeReference {
  301. public:
  302. __Pyx_FakeReference() : ptr(NULL) { }
  303. // __Pyx_FakeReference(T& ref) : ptr(&ref) { }
  304. // Const version needed as Cython doesn't know about const overloads (e.g. for stl containers).
  305. __Pyx_FakeReference(const T& ref) : ptr(const_cast<T*>(&ref)) { }
  306. T *operator->() { return ptr; }
  307. T *operator&() { return ptr; }
  308. operator T&() { return *ptr; }
  309. // TODO(robertwb): Delegate all operators (or auto-generate unwrapping code where needed).
  310. template<typename U> bool operator ==(U other) { return *ptr == other; }
  311. template<typename U> bool operator !=(U other) { return *ptr != other; }
  312. private:
  313. T *ptr;
  314. };
  315. /////////////// PythonCompatibility ///////////////
  316. #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
  317. #define Py_OptimizeFlag 0
  318. #endif
  319. #define __PYX_BUILD_PY_SSIZE_T "n"
  320. #define CYTHON_FORMAT_SSIZE_T "z"
  321. #if PY_MAJOR_VERSION < 3
  322. #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
  323. #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \
  324. PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  325. #define __Pyx_DefaultClassType PyClass_Type
  326. #else
  327. #define __Pyx_BUILTIN_MODULE_NAME "builtins"
  328. #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \
  329. PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  330. #define __Pyx_DefaultClassType PyType_Type
  331. #endif
  332. #ifndef Py_TPFLAGS_CHECKTYPES
  333. #define Py_TPFLAGS_CHECKTYPES 0
  334. #endif
  335. #ifndef Py_TPFLAGS_HAVE_INDEX
  336. #define Py_TPFLAGS_HAVE_INDEX 0
  337. #endif
  338. #ifndef Py_TPFLAGS_HAVE_NEWBUFFER
  339. #define Py_TPFLAGS_HAVE_NEWBUFFER 0
  340. #endif
  341. #ifndef Py_TPFLAGS_HAVE_FINALIZE
  342. #define Py_TPFLAGS_HAVE_FINALIZE 0
  343. #endif
  344. #if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL)
  345. // new in CPython 3.6, but changed in 3.7 - see
  346. // positional-only parameters:
  347. // https://bugs.python.org/issue29464
  348. // const args:
  349. // https://bugs.python.org/issue32240
  350. #ifndef METH_FASTCALL
  351. #define METH_FASTCALL 0x80
  352. #endif
  353. typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs);
  354. // new in CPython 3.7, used to be old signature of _PyCFunctionFast() in 3.6
  355. typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args,
  356. Py_ssize_t nargs, PyObject *kwnames);
  357. #else
  358. #define __Pyx_PyCFunctionFast _PyCFunctionFast
  359. #define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords
  360. #endif
  361. #if CYTHON_FAST_PYCCALL
  362. #define __Pyx_PyFastCFunction_Check(func) \
  363. ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS)))))
  364. #else
  365. #define __Pyx_PyFastCFunction_Check(func) 0
  366. #endif
  367. #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc)
  368. #define PyObject_Malloc(s) PyMem_Malloc(s)
  369. #define PyObject_Free(p) PyMem_Free(p)
  370. #define PyObject_Realloc(p) PyMem_Realloc(p)
  371. #endif
  372. #if CYTHON_COMPILING_IN_PYSTON
  373. // special C-API functions only in Pyston
  374. #define __Pyx_PyCode_HasFreeVars(co) PyCode_HasFreeVars(co)
  375. #define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno)
  376. #else
  377. #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0)
  378. #define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno)
  379. #endif
  380. #if !CYTHON_FAST_THREAD_STATE || PY_VERSION_HEX < 0x02070000
  381. #define __Pyx_PyThreadState_Current PyThreadState_GET()
  382. #elif PY_VERSION_HEX >= 0x03060000
  383. //#elif PY_VERSION_HEX >= 0x03050200
  384. // Actually added in 3.5.2, but compiling against that does not guarantee that we get imported there.
  385. #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet()
  386. #elif PY_VERSION_HEX >= 0x03000000
  387. #define __Pyx_PyThreadState_Current PyThreadState_GET()
  388. #else
  389. #define __Pyx_PyThreadState_Current _PyThreadState_Current
  390. #endif
  391. // TSS (Thread Specific Storage) API
  392. #if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT)
  393. #include "pythread.h"
  394. #define Py_tss_NEEDS_INIT 0
  395. typedef int Py_tss_t;
  396. static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) {
  397. *key = PyThread_create_key();
  398. return 0; // PyThread_create_key reports success always
  399. }
  400. static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) {
  401. Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t));
  402. *key = Py_tss_NEEDS_INIT;
  403. return key;
  404. }
  405. static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) {
  406. PyObject_Free(key);
  407. }
  408. static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) {
  409. return *key != Py_tss_NEEDS_INIT;
  410. }
  411. static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) {
  412. PyThread_delete_key(*key);
  413. *key = Py_tss_NEEDS_INIT;
  414. }
  415. static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) {
  416. return PyThread_set_key_value(*key, value);
  417. }
  418. static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
  419. return PyThread_get_key_value(*key);
  420. }
  421. // PyThread_delete_key_value(key) is equalivalent to PyThread_set_key_value(key, NULL)
  422. // PyThread_ReInitTLS() is a no-op
  423. #endif // TSS (Thread Specific Storage) API
  424. #if CYTHON_COMPILING_IN_CPYTHON || defined(_PyDict_NewPresized)
  425. #define __Pyx_PyDict_NewPresized(n) ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n))
  426. #else
  427. #define __Pyx_PyDict_NewPresized(n) PyDict_New()
  428. #endif
  429. #if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION
  430. #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y)
  431. #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y)
  432. #else
  433. #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y)
  434. #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y)
  435. #endif
  436. #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && CYTHON_USE_UNICODE_INTERNALS
  437. #define __Pyx_PyDict_GetItemStr(dict, name) _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash)
  438. #else
  439. #define __Pyx_PyDict_GetItemStr(dict, name) PyDict_GetItem(dict, name)
  440. #endif
  441. /* new Py3.3 unicode type (PEP 393) */
  442. #if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
  443. #define CYTHON_PEP393_ENABLED 1
  444. #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ? \
  445. 0 : _PyUnicode_Ready((PyObject *)(op)))
  446. #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u)
  447. #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
  448. #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) PyUnicode_MAX_CHAR_VALUE(u)
  449. #define __Pyx_PyUnicode_KIND(u) PyUnicode_KIND(u)
  450. #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u)
  451. #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i)
  452. #define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, ch)
  453. #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
  454. #else
  455. #define CYTHON_PEP393_ENABLED 0
  456. #define PyUnicode_1BYTE_KIND 1
  457. #define PyUnicode_2BYTE_KIND 2
  458. #define PyUnicode_4BYTE_KIND 4
  459. #define __Pyx_PyUnicode_READY(op) (0)
  460. #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u)
  461. #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
  462. #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111)
  463. #define __Pyx_PyUnicode_KIND(u) (sizeof(Py_UNICODE))
  464. #define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u))
  465. /* (void)(k) => avoid unused variable warning due to macro: */
  466. #define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
  467. #define __Pyx_PyUnicode_WRITE(k, d, i, ch) (((void)(k)), ((Py_UNICODE*)d)[i] = ch)
  468. #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_SIZE(u))
  469. #endif
  470. #if CYTHON_COMPILING_IN_PYPY
  471. #define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b)
  472. #define __Pyx_PyUnicode_ConcatSafe(a, b) PyNumber_Add(a, b)
  473. #else
  474. #define __Pyx_PyUnicode_Concat(a, b) PyUnicode_Concat(a, b)
  475. #define __Pyx_PyUnicode_ConcatSafe(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ? \
  476. PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b))
  477. #endif
  478. #if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains)
  479. #define PyUnicode_Contains(u, s) PySequence_Contains(u, s)
  480. #endif
  481. #if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check)
  482. #define PyByteArray_Check(obj) PyObject_TypeCheck(obj, &PyByteArray_Type)
  483. #endif
  484. #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format)
  485. #define PyObject_Format(obj, fmt) PyObject_CallMethod(obj, "__format__", "O", fmt)
  486. #endif
  487. #define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
  488. #define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
  489. #if PY_MAJOR_VERSION >= 3
  490. #define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b)
  491. #else
  492. #define __Pyx_PyString_Format(a, b) PyString_Format(a, b)
  493. #endif
  494. #if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII)
  495. #define PyObject_ASCII(o) PyObject_Repr(o)
  496. #endif
  497. #if PY_MAJOR_VERSION >= 3
  498. #define PyBaseString_Type PyUnicode_Type
  499. #define PyStringObject PyUnicodeObject
  500. #define PyString_Type PyUnicode_Type
  501. #define PyString_Check PyUnicode_Check
  502. #define PyString_CheckExact PyUnicode_CheckExact
  503. #endif
  504. #if PY_MAJOR_VERSION >= 3
  505. #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj)
  506. #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj)
  507. #else
  508. #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj))
  509. #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
  510. #endif
  511. #ifndef PySet_CheckExact
  512. #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type)
  513. #endif
  514. #if CYTHON_ASSUME_SAFE_MACROS
  515. #define __Pyx_PySequence_SIZE(seq) Py_SIZE(seq)
  516. #else
  517. // NOTE: might fail with exception => check for -1
  518. #define __Pyx_PySequence_SIZE(seq) PySequence_Size(seq)
  519. #endif
  520. #if PY_MAJOR_VERSION >= 3
  521. #define PyIntObject PyLongObject
  522. #define PyInt_Type PyLong_Type
  523. #define PyInt_Check(op) PyLong_Check(op)
  524. #define PyInt_CheckExact(op) PyLong_CheckExact(op)
  525. #define PyInt_FromString PyLong_FromString
  526. #define PyInt_FromUnicode PyLong_FromUnicode
  527. #define PyInt_FromLong PyLong_FromLong
  528. #define PyInt_FromSize_t PyLong_FromSize_t
  529. #define PyInt_FromSsize_t PyLong_FromSsize_t
  530. #define PyInt_AsLong PyLong_AsLong
  531. #define PyInt_AS_LONG PyLong_AS_LONG
  532. #define PyInt_AsSsize_t PyLong_AsSsize_t
  533. #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask
  534. #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
  535. #define PyNumber_Int PyNumber_Long
  536. #endif
  537. #if PY_MAJOR_VERSION >= 3
  538. #define PyBoolObject PyLongObject
  539. #endif
  540. #if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY
  541. #ifndef PyUnicode_InternFromString
  542. #define PyUnicode_InternFromString(s) PyUnicode_FromString(s)
  543. #endif
  544. #endif
  545. #if PY_VERSION_HEX < 0x030200A4
  546. typedef long Py_hash_t;
  547. #define __Pyx_PyInt_FromHash_t PyInt_FromLong
  548. #define __Pyx_PyInt_AsHash_t PyInt_AsLong
  549. #else
  550. #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
  551. #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t
  552. #endif
  553. #if PY_MAJOR_VERSION >= 3
  554. #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : (Py_INCREF(func), func))
  555. #else
  556. #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
  557. #endif
  558. // backport of PyAsyncMethods from Py3.5 to older Py3.x versions
  559. // (mis-)using the "tp_reserved" type slot which is re-activated as "tp_as_async" in Py3.5
  560. #if CYTHON_USE_ASYNC_SLOTS
  561. #if PY_VERSION_HEX >= 0x030500B1
  562. #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
  563. #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
  564. #else
  565. #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
  566. #endif
  567. #else
  568. #define __Pyx_PyType_AsAsync(obj) NULL
  569. #endif
  570. #ifndef __Pyx_PyAsyncMethodsStruct
  571. typedef struct {
  572. unaryfunc am_await;
  573. unaryfunc am_aiter;
  574. unaryfunc am_anext;
  575. } __Pyx_PyAsyncMethodsStruct;
  576. #endif
  577. /////////////// PyModInitFuncType.proto ///////////////
  578. #if PY_MAJOR_VERSION < 3
  579. #ifdef CYTHON_NO_PYINIT_EXPORT
  580. // define this to void manually because PyMODINIT_FUNC adds __declspec(dllexport) to it's definition.
  581. #define __Pyx_PyMODINIT_FUNC void
  582. #else
  583. #define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
  584. #endif
  585. #else
  586. #ifdef CYTHON_NO_PYINIT_EXPORT
  587. // define this to PyObject * manually because PyMODINIT_FUNC adds __declspec(dllexport) to it's definition.
  588. #define __Pyx_PyMODINIT_FUNC PyObject *
  589. #else
  590. #define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
  591. #endif
  592. #endif
  593. #ifndef CYTHON_SMALL_CODE
  594. #if defined(__clang__)
  595. #define CYTHON_SMALL_CODE
  596. #elif defined(__GNUC__)
  597. #define CYTHON_SMALL_CODE __attribute__((optimize("Os")))
  598. #else
  599. #define CYTHON_SMALL_CODE
  600. #endif
  601. #endif
  602. /////////////// FastTypeChecks.proto ///////////////
  603. #if CYTHON_COMPILING_IN_CPYTHON
  604. #define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type)
  605. static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b);/*proto*/
  606. static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type);/*proto*/
  607. static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2);/*proto*/
  608. #else
  609. #define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
  610. #define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type)
  611. #define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2))
  612. #endif
  613. #define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception)
  614. /////////////// FastTypeChecks ///////////////
  615. //@requires: Exceptions.c::PyThreadStateGet
  616. //@requires: Exceptions.c::PyErrFetchRestore
  617. #if CYTHON_COMPILING_IN_CPYTHON
  618. static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) {
  619. while (a) {
  620. a = a->tp_base;
  621. if (a == b)
  622. return 1;
  623. }
  624. return b == &PyBaseObject_Type;
  625. }
  626. static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) {
  627. PyObject *mro;
  628. if (a == b) return 1;
  629. mro = a->tp_mro;
  630. if (likely(mro)) {
  631. Py_ssize_t i, n;
  632. n = PyTuple_GET_SIZE(mro);
  633. for (i = 0; i < n; i++) {
  634. if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b)
  635. return 1;
  636. }
  637. return 0;
  638. }
  639. // should only get here for incompletely initialised types, i.e. never under normal usage patterns
  640. return __Pyx_InBases(a, b);
  641. }
  642. #if PY_MAJOR_VERSION == 2
  643. static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) {
  644. // PyObject_IsSubclass() can recurse and therefore is not safe
  645. PyObject *exception, *value, *tb;
  646. int res;
  647. __Pyx_PyThreadState_declare
  648. __Pyx_PyThreadState_assign
  649. __Pyx_ErrFetch(&exception, &value, &tb);
  650. res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0;
  651. // This function must not fail, so print the error here (which also clears it)
  652. if (unlikely(res == -1)) {
  653. PyErr_WriteUnraisable(err);
  654. res = 0;
  655. }
  656. if (!res) {
  657. res = PyObject_IsSubclass(err, exc_type2);
  658. // This function must not fail, so print the error here (which also clears it)
  659. if (unlikely(res == -1)) {
  660. PyErr_WriteUnraisable(err);
  661. res = 0;
  662. }
  663. }
  664. __Pyx_ErrRestore(exception, value, tb);
  665. return res;
  666. }
  667. #else
  668. static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) {
  669. int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0;
  670. if (!res) {
  671. res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2);
  672. }
  673. return res;
  674. }
  675. #endif
  676. // so far, we only call PyErr_GivenExceptionMatches() with an exception type (not instance) as first argument
  677. // => optimise for that case
  678. static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject* exc_type) {
  679. if (likely(err == exc_type)) return 1;
  680. if (likely(PyExceptionClass_Check(err))) {
  681. return __Pyx_inner_PyErr_GivenExceptionMatches2(err, NULL, exc_type);
  682. }
  683. return PyErr_GivenExceptionMatches(err, exc_type);
  684. }
  685. static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *exc_type1, PyObject *exc_type2) {
  686. if (likely(err == exc_type1 || err == exc_type2)) return 1;
  687. if (likely(PyExceptionClass_Check(err))) {
  688. return __Pyx_inner_PyErr_GivenExceptionMatches2(err, exc_type1, exc_type2);
  689. }
  690. return (PyErr_GivenExceptionMatches(err, exc_type1) || PyErr_GivenExceptionMatches(err, exc_type2));
  691. }
  692. #endif
  693. /////////////// MathInitCode ///////////////
  694. #if defined(WIN32) || defined(MS_WINDOWS)
  695. #define _USE_MATH_DEFINES
  696. #endif
  697. #include <math.h>
  698. #ifdef NAN
  699. #define __PYX_NAN() ((float) NAN)
  700. #else
  701. static CYTHON_INLINE float __PYX_NAN() {
  702. // Initialize NaN. The sign is irrelevant, an exponent with all bits 1 and
  703. // a nonzero mantissa means NaN. If the first bit in the mantissa is 1, it is
  704. // a quiet NaN.
  705. float value;
  706. memset(&value, 0xFF, sizeof(value));
  707. return value;
  708. }
  709. #endif
  710. #if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL)
  711. #define __Pyx_truncl trunc
  712. #else
  713. #define __Pyx_truncl truncl
  714. #endif
  715. /////////////// UtilityFunctionPredeclarations.proto ///////////////
  716. typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding;
  717. const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; /*proto*/
  718. /////////////// ForceInitThreads.proto ///////////////
  719. //@proto_block: utility_code_proto_before_types
  720. #ifndef __PYX_FORCE_INIT_THREADS
  721. #define __PYX_FORCE_INIT_THREADS 0
  722. #endif
  723. /////////////// InitThreads.init ///////////////
  724. #ifdef WITH_THREAD
  725. PyEval_InitThreads();
  726. #endif
  727. /////////////// ModuleCreationPEP489 ///////////////
  728. //@substitute: naming
  729. //#if CYTHON_PEP489_MULTI_PHASE_INIT
  730. static int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name) {
  731. PyObject *value = PyObject_GetAttrString(spec, from_name);
  732. int result = 0;
  733. if (likely(value)) {
  734. result = PyDict_SetItemString(moddict, to_name, value);
  735. Py_DECREF(value);
  736. } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
  737. PyErr_Clear();
  738. } else {
  739. result = -1;
  740. }
  741. return result;
  742. }
  743. static PyObject* ${pymodule_create_func_cname}(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) {
  744. PyObject *module = NULL, *moddict, *modname;
  745. // For now, we only have exactly one module instance.
  746. if (${module_cname})
  747. return __Pyx_NewRef(${module_cname});
  748. modname = PyObject_GetAttrString(spec, "name");
  749. if (unlikely(!modname)) goto bad;
  750. module = PyModule_NewObject(modname);
  751. Py_DECREF(modname);
  752. if (unlikely(!module)) goto bad;
  753. moddict = PyModule_GetDict(module);
  754. if (unlikely(!moddict)) goto bad;
  755. // moddict is a borrowed reference
  756. if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__") < 0)) goto bad;
  757. if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__") < 0)) goto bad;
  758. if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__") < 0)) goto bad;
  759. if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__") < 0)) goto bad;
  760. return module;
  761. bad:
  762. Py_XDECREF(module);
  763. return NULL;
  764. }
  765. //#endif
  766. /////////////// CodeObjectCache.proto ///////////////
  767. typedef struct {
  768. PyCodeObject* code_object;
  769. int code_line;
  770. } __Pyx_CodeObjectCacheEntry;
  771. struct __Pyx_CodeObjectCache {
  772. int count;
  773. int max_count;
  774. __Pyx_CodeObjectCacheEntry* entries;
  775. };
  776. static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL};
  777. static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
  778. static PyCodeObject *__pyx_find_code_object(int code_line);
  779. static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);
  780. /////////////// CodeObjectCache ///////////////
  781. // Note that errors are simply ignored in the code below.
  782. // This is just a cache, if a lookup or insertion fails - so what?
  783. static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
  784. int start = 0, mid = 0, end = count - 1;
  785. if (end >= 0 && code_line > entries[end].code_line) {
  786. return count;
  787. }
  788. while (start < end) {
  789. mid = start + (end - start) / 2;
  790. if (code_line < entries[mid].code_line) {
  791. end = mid;
  792. } else if (code_line > entries[mid].code_line) {
  793. start = mid + 1;
  794. } else {
  795. return mid;
  796. }
  797. }
  798. if (code_line <= entries[mid].code_line) {
  799. return mid;
  800. } else {
  801. return mid + 1;
  802. }
  803. }
  804. static PyCodeObject *__pyx_find_code_object(int code_line) {
  805. PyCodeObject* code_object;
  806. int pos;
  807. if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
  808. return NULL;
  809. }
  810. pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
  811. if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
  812. return NULL;
  813. }
  814. code_object = __pyx_code_cache.entries[pos].code_object;
  815. Py_INCREF(code_object);
  816. return code_object;
  817. }
  818. static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
  819. int pos, i;
  820. __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
  821. if (unlikely(!code_line)) {
  822. return;
  823. }
  824. if (unlikely(!entries)) {
  825. entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
  826. if (likely(entries)) {
  827. __pyx_code_cache.entries = entries;
  828. __pyx_code_cache.max_count = 64;
  829. __pyx_code_cache.count = 1;
  830. entries[0].code_line = code_line;
  831. entries[0].code_object = code_object;
  832. Py_INCREF(code_object);
  833. }
  834. return;
  835. }
  836. pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
  837. if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
  838. PyCodeObject* tmp = entries[pos].code_object;
  839. entries[pos].code_object = code_object;
  840. Py_DECREF(tmp);
  841. return;
  842. }
  843. if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
  844. int new_max = __pyx_code_cache.max_count + 64;
  845. entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
  846. __pyx_code_cache.entries, (size_t)new_max*sizeof(__Pyx_CodeObjectCacheEntry));
  847. if (unlikely(!entries)) {
  848. return;
  849. }
  850. __pyx_code_cache.entries = entries;
  851. __pyx_code_cache.max_count = new_max;
  852. }
  853. for (i=__pyx_code_cache.count; i>pos; i--) {
  854. entries[i] = entries[i-1];
  855. }
  856. entries[pos].code_line = code_line;
  857. entries[pos].code_object = code_object;
  858. __pyx_code_cache.count++;
  859. Py_INCREF(code_object);
  860. }
  861. /////////////// CodeObjectCache.cleanup ///////////////
  862. if (__pyx_code_cache.entries) {
  863. __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
  864. int i, count = __pyx_code_cache.count;
  865. __pyx_code_cache.count = 0;
  866. __pyx_code_cache.max_count = 0;
  867. __pyx_code_cache.entries = NULL;
  868. for (i=0; i<count; i++) {
  869. Py_DECREF(entries[i].code_object);
  870. }
  871. PyMem_Free(entries);
  872. }
  873. /////////////// CheckBinaryVersion.proto ///////////////
  874. static int __Pyx_check_binary_version(void);
  875. /////////////// CheckBinaryVersion ///////////////
  876. static int __Pyx_check_binary_version(void) {
  877. char ctversion[4], rtversion[4];
  878. PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
  879. PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
  880. if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
  881. char message[200];
  882. PyOS_snprintf(message, sizeof(message),
  883. "compiletime version %s of module '%.100s' "
  884. "does not match runtime version %s",
  885. ctversion, __Pyx_MODULE_NAME, rtversion);
  886. return PyErr_WarnEx(NULL, message, 1);
  887. }
  888. return 0;
  889. }
  890. /////////////// IsLittleEndian.proto ///////////////
  891. static CYTHON_INLINE int __Pyx_Is_Little_Endian(void);
  892. /////////////// IsLittleEndian ///////////////
  893. static CYTHON_INLINE int __Pyx_Is_Little_Endian(void)
  894. {
  895. union {
  896. uint32_t u32;
  897. uint8_t u8[4];
  898. } S;
  899. S.u32 = 0x01020304;
  900. return S.u8[0] == 4;
  901. }
  902. /////////////// Refnanny.proto ///////////////
  903. #ifndef CYTHON_REFNANNY
  904. #define CYTHON_REFNANNY 0
  905. #endif
  906. #if CYTHON_REFNANNY
  907. typedef struct {
  908. void (*INCREF)(void*, PyObject*, int);
  909. void (*DECREF)(void*, PyObject*, int);
  910. void (*GOTREF)(void*, PyObject*, int);
  911. void (*GIVEREF)(void*, PyObject*, int);
  912. void* (*SetupContext)(const char*, int, const char*);
  913. void (*FinishContext)(void**);
  914. } __Pyx_RefNannyAPIStruct;
  915. static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
  916. static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); /*proto*/
  917. #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
  918. #ifdef WITH_THREAD
  919. #define __Pyx_RefNannySetupContext(name, acquire_gil) \
  920. if (acquire_gil) { \
  921. PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); \
  922. __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \
  923. PyGILState_Release(__pyx_gilstate_save); \
  924. } else { \
  925. __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \
  926. }
  927. #else
  928. #define __Pyx_RefNannySetupContext(name, acquire_gil) \
  929. __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
  930. #endif
  931. #define __Pyx_RefNannyFinishContext() \
  932. __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
  933. #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  934. #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  935. #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  936. #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  937. #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
  938. #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
  939. #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
  940. #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
  941. #else
  942. #define __Pyx_RefNannyDeclarations
  943. #define __Pyx_RefNannySetupContext(name, acquire_gil)
  944. #define __Pyx_RefNannyFinishContext()
  945. #define __Pyx_INCREF(r) Py_INCREF(r)
  946. #define __Pyx_DECREF(r) Py_DECREF(r)
  947. #define __Pyx_GOTREF(r)
  948. #define __Pyx_GIVEREF(r)
  949. #define __Pyx_XINCREF(r) Py_XINCREF(r)
  950. #define __Pyx_XDECREF(r) Py_XDECREF(r)
  951. #define __Pyx_XGOTREF(r)
  952. #define __Pyx_XGIVEREF(r)
  953. #endif /* CYTHON_REFNANNY */
  954. #define __Pyx_XDECREF_SET(r, v) do { \
  955. PyObject *tmp = (PyObject *) r; \
  956. r = v; __Pyx_XDECREF(tmp); \
  957. } while (0)
  958. #define __Pyx_DECREF_SET(r, v) do { \
  959. PyObject *tmp = (PyObject *) r; \
  960. r = v; __Pyx_DECREF(tmp); \
  961. } while (0)
  962. #define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
  963. #define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)
  964. /////////////// Refnanny ///////////////
  965. #if CYTHON_REFNANNY
  966. static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
  967. PyObject *m = NULL, *p = NULL;
  968. void *r = NULL;
  969. m = PyImport_ImportModule((char *)modname);
  970. if (!m) goto end;
  971. p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
  972. if (!p) goto end;
  973. r = PyLong_AsVoidPtr(p);
  974. end:
  975. Py_XDECREF(p);
  976. Py_XDECREF(m);
  977. return (__Pyx_RefNannyAPIStruct *)r;
  978. }
  979. #endif /* CYTHON_REFNANNY */
  980. /////////////// ImportRefnannyAPI ///////////////
  981. #if CYTHON_REFNANNY
  982. __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
  983. if (!__Pyx_RefNanny) {
  984. PyErr_Clear();
  985. __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
  986. if (!__Pyx_RefNanny)
  987. Py_FatalError("failed to import 'refnanny' module");
  988. }
  989. #endif
  990. /////////////// RegisterModuleCleanup.proto ///////////////
  991. //@substitute: naming
  992. static void ${cleanup_cname}(PyObject *self); /*proto*/
  993. static int __Pyx_RegisterCleanup(void); /*proto*/
  994. /////////////// RegisterModuleCleanup ///////////////
  995. //@substitute: naming
  996. //@requires: ImportExport.c::ModuleImport
  997. #if PY_MAJOR_VERSION < 3 || CYTHON_COMPILING_IN_PYPY
  998. static PyObject* ${cleanup_cname}_atexit(PyObject *module, CYTHON_UNUSED PyObject *unused) {
  999. ${cleanup_cname}(module);
  1000. Py_INCREF(Py_None); return Py_None;
  1001. }
  1002. static int __Pyx_RegisterCleanup(void) {
  1003. // Don't use Py_AtExit because that has a 32-call limit and is called
  1004. // after python finalization.
  1005. // Also, we try to prepend the cleanup function to "atexit._exithandlers"
  1006. // in Py2 because CPython runs them last-to-first. Being run last allows
  1007. // user exit code to run before us that may depend on the globals
  1008. // and cached objects that we are about to clean up.
  1009. static PyMethodDef cleanup_def = {
  1010. "__cleanup", (PyCFunction)${cleanup_cname}_atexit, METH_NOARGS, 0};
  1011. PyObject *cleanup_func = 0;
  1012. PyObject *atexit = 0;
  1013. PyObject *reg = 0;
  1014. PyObject *args = 0;
  1015. PyObject *res = 0;
  1016. int ret = -1;
  1017. cleanup_func = PyCFunction_New(&cleanup_def, 0);
  1018. if (!cleanup_func)
  1019. goto bad;
  1020. atexit = __Pyx_ImportModule("atexit");
  1021. if (!atexit)
  1022. goto bad;
  1023. reg = PyObject_GetAttrString(atexit, "_exithandlers");
  1024. if (reg && PyList_Check(reg)) {
  1025. PyObject *a, *kw;
  1026. a = PyTuple_New(0);
  1027. kw = PyDict_New();
  1028. if (!a || !kw) {
  1029. Py_XDECREF(a);
  1030. Py_XDECREF(kw);
  1031. goto bad;
  1032. }
  1033. args = PyTuple_Pack(3, cleanup_func, a, kw);
  1034. Py_DECREF(a);
  1035. Py_DECREF(kw);
  1036. if (!args)
  1037. goto bad;
  1038. ret = PyList_Insert(reg, 0, args);
  1039. } else {
  1040. if (!reg)
  1041. PyErr_Clear();
  1042. Py_XDECREF(reg);
  1043. reg = PyObject_GetAttrString(atexit, "register");
  1044. if (!reg)
  1045. goto bad;
  1046. args = PyTuple_Pack(1, cleanup_func);
  1047. if (!args)
  1048. goto bad;
  1049. res = PyObject_CallObject(reg, args);
  1050. if (!res)
  1051. goto bad;
  1052. ret = 0;
  1053. }
  1054. bad:
  1055. Py_XDECREF(cleanup_func);
  1056. Py_XDECREF(atexit);
  1057. Py_XDECREF(reg);
  1058. Py_XDECREF(args);
  1059. Py_XDECREF(res);
  1060. return ret;
  1061. }
  1062. #else
  1063. // fake call purely to work around "unused function" warning for __Pyx_ImportModule()
  1064. static int __Pyx_RegisterCleanup(void) {
  1065. (void)__Pyx_ImportModule; /* unused */
  1066. return 0;
  1067. }
  1068. #endif
  1069. /////////////// FastGil.init ///////////////
  1070. #ifdef WITH_THREAD
  1071. __Pyx_FastGilFuncInit();
  1072. #endif
  1073. /////////////// NoFastGil.proto ///////////////
  1074. //@proto_block: utility_code_proto_before_types
  1075. #define __Pyx_PyGILState_Ensure PyGILState_Ensure
  1076. #define __Pyx_PyGILState_Release PyGILState_Release
  1077. #define __Pyx_FastGIL_Remember()
  1078. #define __Pyx_FastGIL_Forget()
  1079. #define __Pyx_FastGilFuncInit()
  1080. /////////////// FastGil.proto ///////////////
  1081. //@proto_block: utility_code_proto_before_types
  1082. struct __Pyx_FastGilVtab {
  1083. PyGILState_STATE (*Fast_PyGILState_Ensure)(void);
  1084. void (*Fast_PyGILState_Release)(PyGILState_STATE oldstate);
  1085. void (*FastGIL_Remember)(void);
  1086. void (*FastGIL_Forget)(void);
  1087. };
  1088. static void __Pyx_FastGIL_Noop(void) {}
  1089. static struct __Pyx_FastGilVtab __Pyx_FastGilFuncs = {
  1090. PyGILState_Ensure,
  1091. PyGILState_Release,
  1092. __Pyx_FastGIL_Noop,
  1093. __Pyx_FastGIL_Noop
  1094. };
  1095. static void __Pyx_FastGilFuncInit(void);
  1096. #define __Pyx_PyGILState_Ensure __Pyx_FastGilFuncs.Fast_PyGILState_Ensure
  1097. #define __Pyx_PyGILState_Release __Pyx_FastGilFuncs.Fast_PyGILState_Release
  1098. #define __Pyx_FastGIL_Remember __Pyx_FastGilFuncs.FastGIL_Remember
  1099. #define __Pyx_FastGIL_Forget __Pyx_FastGilFuncs.FastGIL_Forget
  1100. #ifdef WITH_THREAD
  1101. #ifndef CYTHON_THREAD_LOCAL
  1102. #if __STDC_VERSION__ >= 201112
  1103. #define CYTHON_THREAD_LOCAL _Thread_local
  1104. #elif defined(__GNUC__)
  1105. #define CYTHON_THREAD_LOCAL __thread
  1106. #elif defined(_MSC_VER)
  1107. #define CYTHON_THREAD_LOCAL __declspec(thread)
  1108. #endif
  1109. #endif
  1110. #endif
  1111. /////////////// FastGil ///////////////
  1112. //@requires: CommonStructures.c::FetchCommonPointer
  1113. // The implementations of PyGILState_Ensure/Release calls PyThread_get_key_value
  1114. // several times which is turns out to be quite slow (slower in fact than
  1115. // acquiring the GIL itself). Simply storing it in a thread local for the
  1116. // common case is much faster.
  1117. // To make optimal use of this thread local, we attempt to share it between
  1118. // modules.
  1119. #define __Pyx_FastGIL_ABI_module "_cython_" CYTHON_ABI
  1120. #define __Pyx_FastGIL_PyCapsuleName "FastGilFuncs"
  1121. #define __Pyx_FastGIL_PyCapsule \
  1122. __Pyx_FastGIL_ABI_module "." __Pyx_FastGIL_PyCapsuleName
  1123. #if PY_VERSION_HEX < 0x02070000
  1124. #undef CYTHON_THREAD_LOCAL
  1125. #endif
  1126. #ifdef CYTHON_THREAD_LOCAL
  1127. #include "pythread.h"
  1128. #include "pystate.h"
  1129. static CYTHON_THREAD_LOCAL PyThreadState *__Pyx_FastGil_tcur = NULL;
  1130. static CYTHON_THREAD_LOCAL int __Pyx_FastGil_tcur_depth = 0;
  1131. static int __Pyx_FastGil_autoTLSkey = -1;
  1132. static CYTHON_INLINE void __Pyx_FastGIL_Remember0(void) {
  1133. ++__Pyx_FastGil_tcur_depth;
  1134. }
  1135. static CYTHON_INLINE void __Pyx_FastGIL_Forget0(void) {
  1136. if (--__Pyx_FastGil_tcur_depth == 0) {
  1137. __Pyx_FastGil_tcur = NULL;
  1138. }
  1139. }
  1140. static CYTHON_INLINE PyThreadState *__Pyx_FastGil_get_tcur(void) {
  1141. PyThreadState *tcur = __Pyx_FastGil_tcur;
  1142. if (tcur == NULL) {
  1143. tcur = __Pyx_FastGil_tcur = (PyThreadState*)PyThread_get_key_value(__Pyx_FastGil_autoTLSkey);
  1144. }
  1145. return tcur;
  1146. }
  1147. static PyGILState_STATE __Pyx_FastGil_PyGILState_Ensure(void) {
  1148. int current;
  1149. __Pyx_FastGIL_Remember0();
  1150. PyThreadState *tcur = __Pyx_FastGil_get_tcur();
  1151. if (tcur == NULL) {
  1152. // Uninitialized, need to initialize now.
  1153. return PyGILState_Ensure();
  1154. }
  1155. current = tcur == __Pyx_PyThreadState_Current;
  1156. if (current == 0) {
  1157. PyEval_RestoreThread(tcur);
  1158. }
  1159. ++tcur->gilstate_counter;
  1160. return current ? PyGILState_LOCKED : PyGILState_UNLOCKED;
  1161. }
  1162. static void __Pyx_FastGil_PyGILState_Release(PyGILState_STATE oldstate) {
  1163. PyThreadState *tcur = __Pyx_FastGil_get_tcur();
  1164. __Pyx_FastGIL_Forget0();
  1165. if (tcur->gilstate_counter == 1) {
  1166. // This is the last lock, do all the cleanup as well.
  1167. PyGILState_Release(oldstate);
  1168. } else {
  1169. --tcur->gilstate_counter;
  1170. if (oldstate == PyGILState_UNLOCKED) {
  1171. PyEval_SaveThread();
  1172. }
  1173. }
  1174. }
  1175. static void __Pyx_FastGilFuncInit0(void) {
  1176. /* Try to detect autoTLSkey. */
  1177. int key;
  1178. void* this_thread_state = (void*) PyGILState_GetThisThreadState();
  1179. for (key = 0; key < 100; key++) {
  1180. if (PyThread_get_key_value(key) == this_thread_state) {
  1181. __Pyx_FastGil_autoTLSkey = key;
  1182. break;
  1183. }
  1184. }
  1185. if (__Pyx_FastGil_autoTLSkey != -1) {
  1186. PyObject* capsule = NULL;
  1187. PyObject* abi_module = NULL;
  1188. __Pyx_PyGILState_Ensure = __Pyx_FastGil_PyGILState_Ensure;
  1189. __Pyx_PyGILState_Release = __Pyx_FastGil_PyGILState_Release;
  1190. __Pyx_FastGIL_Remember = __Pyx_FastGIL_Remember0;
  1191. __Pyx_FastGIL_Forget = __Pyx_FastGIL_Forget0;
  1192. capsule = PyCapsule_New(&__Pyx_FastGilFuncs, __Pyx_FastGIL_PyCapsule, NULL);
  1193. abi_module = PyImport_AddModule(__Pyx_FastGIL_ABI_module);
  1194. if (capsule && abi_module) {
  1195. PyObject_SetAttrString(abi_module, __Pyx_FastGIL_PyCapsuleName, capsule);
  1196. }
  1197. Py_XDECREF(capsule);
  1198. }
  1199. }
  1200. #else
  1201. static void __Pyx_FastGilFuncInit0(void) {
  1202. CYTHON_UNUSED void* force_use = (void*)&__Pyx_FetchCommonPointer;
  1203. }
  1204. #endif
  1205. static void __Pyx_FastGilFuncInit(void) {
  1206. #if PY_VERSION_HEX >= 0x02070000
  1207. struct __Pyx_FastGilVtab* shared = (struct __Pyx_FastGilVtab*)PyCapsule_Import(__Pyx_FastGIL_PyCapsule, 1);
  1208. #else
  1209. struct __Pyx_FastGilVtab* shared = NULL;
  1210. #endif
  1211. if (shared) {
  1212. __Pyx_FastGilFuncs = *shared;
  1213. } else {
  1214. PyErr_Clear();
  1215. __Pyx_FastGilFuncInit0();
  1216. }
  1217. }