ModuleSetupCode.c 58 KB

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