ObjectHandling.c 87 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506
  1. /*
  2. * General object operations and protocol implementations,
  3. * including their specialisations for certain builtins.
  4. *
  5. * Optional optimisations for builtins are in Optimize.c.
  6. *
  7. * Required replacements of builtins are in Builtins.c.
  8. */
  9. /////////////// RaiseNoneIterError.proto ///////////////
  10. static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void);
  11. /////////////// RaiseNoneIterError ///////////////
  12. static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) {
  13. PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
  14. }
  15. /////////////// RaiseTooManyValuesToUnpack.proto ///////////////
  16. static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);
  17. /////////////// RaiseTooManyValuesToUnpack ///////////////
  18. static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
  19. PyErr_Format(PyExc_ValueError,
  20. "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected);
  21. }
  22. /////////////// RaiseNeedMoreValuesToUnpack.proto ///////////////
  23. static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);
  24. /////////////// RaiseNeedMoreValuesToUnpack ///////////////
  25. static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
  26. PyErr_Format(PyExc_ValueError,
  27. "need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack",
  28. index, (index == 1) ? "" : "s");
  29. }
  30. /////////////// UnpackTupleError.proto ///////////////
  31. static void __Pyx_UnpackTupleError(PyObject *, Py_ssize_t index); /*proto*/
  32. /////////////// UnpackTupleError ///////////////
  33. //@requires: RaiseNoneIterError
  34. //@requires: RaiseNeedMoreValuesToUnpack
  35. //@requires: RaiseTooManyValuesToUnpack
  36. static void __Pyx_UnpackTupleError(PyObject *t, Py_ssize_t index) {
  37. if (t == Py_None) {
  38. __Pyx_RaiseNoneNotIterableError();
  39. } else if (PyTuple_GET_SIZE(t) < index) {
  40. __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(t));
  41. } else {
  42. __Pyx_RaiseTooManyValuesError(index);
  43. }
  44. }
  45. /////////////// UnpackItemEndCheck.proto ///////////////
  46. static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); /*proto*/
  47. /////////////// UnpackItemEndCheck ///////////////
  48. //@requires: RaiseTooManyValuesToUnpack
  49. //@requires: IterFinish
  50. static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) {
  51. if (unlikely(retval)) {
  52. Py_DECREF(retval);
  53. __Pyx_RaiseTooManyValuesError(expected);
  54. return -1;
  55. }
  56. return __Pyx_IterFinish();
  57. }
  58. /////////////// UnpackTuple2.proto ///////////////
  59. #define __Pyx_unpack_tuple2(tuple, value1, value2, is_tuple, has_known_size, decref_tuple) \
  60. (likely(is_tuple || PyTuple_Check(tuple)) ? \
  61. (likely(has_known_size || PyTuple_GET_SIZE(tuple) == 2) ? \
  62. __Pyx_unpack_tuple2_exact(tuple, value1, value2, decref_tuple) : \
  63. (__Pyx_UnpackTupleError(tuple, 2), -1)) : \
  64. __Pyx_unpack_tuple2_generic(tuple, value1, value2, has_known_size, decref_tuple))
  65. static CYTHON_INLINE int __Pyx_unpack_tuple2_exact(
  66. PyObject* tuple, PyObject** value1, PyObject** value2, int decref_tuple);
  67. static int __Pyx_unpack_tuple2_generic(
  68. PyObject* tuple, PyObject** value1, PyObject** value2, int has_known_size, int decref_tuple);
  69. /////////////// UnpackTuple2 ///////////////
  70. //@requires: UnpackItemEndCheck
  71. //@requires: UnpackTupleError
  72. //@requires: RaiseNeedMoreValuesToUnpack
  73. static CYTHON_INLINE int __Pyx_unpack_tuple2_exact(
  74. PyObject* tuple, PyObject** pvalue1, PyObject** pvalue2, int decref_tuple) {
  75. PyObject *value1 = NULL, *value2 = NULL;
  76. #if CYTHON_COMPILING_IN_PYPY
  77. value1 = PySequence_ITEM(tuple, 0); if (unlikely(!value1)) goto bad;
  78. value2 = PySequence_ITEM(tuple, 1); if (unlikely(!value2)) goto bad;
  79. #else
  80. value1 = PyTuple_GET_ITEM(tuple, 0); Py_INCREF(value1);
  81. value2 = PyTuple_GET_ITEM(tuple, 1); Py_INCREF(value2);
  82. #endif
  83. if (decref_tuple) {
  84. Py_DECREF(tuple);
  85. }
  86. *pvalue1 = value1;
  87. *pvalue2 = value2;
  88. return 0;
  89. #if CYTHON_COMPILING_IN_PYPY
  90. bad:
  91. Py_XDECREF(value1);
  92. Py_XDECREF(value2);
  93. if (decref_tuple) { Py_XDECREF(tuple); }
  94. return -1;
  95. #endif
  96. }
  97. static int __Pyx_unpack_tuple2_generic(PyObject* tuple, PyObject** pvalue1, PyObject** pvalue2,
  98. int has_known_size, int decref_tuple) {
  99. Py_ssize_t index;
  100. PyObject *value1 = NULL, *value2 = NULL, *iter = NULL;
  101. iternextfunc iternext;
  102. iter = PyObject_GetIter(tuple);
  103. if (unlikely(!iter)) goto bad;
  104. if (decref_tuple) { Py_DECREF(tuple); tuple = NULL; }
  105. iternext = Py_TYPE(iter)->tp_iternext;
  106. value1 = iternext(iter); if (unlikely(!value1)) { index = 0; goto unpacking_failed; }
  107. value2 = iternext(iter); if (unlikely(!value2)) { index = 1; goto unpacking_failed; }
  108. if (!has_known_size && unlikely(__Pyx_IternextUnpackEndCheck(iternext(iter), 2))) goto bad;
  109. Py_DECREF(iter);
  110. *pvalue1 = value1;
  111. *pvalue2 = value2;
  112. return 0;
  113. unpacking_failed:
  114. if (!has_known_size && __Pyx_IterFinish() == 0)
  115. __Pyx_RaiseNeedMoreValuesError(index);
  116. bad:
  117. Py_XDECREF(iter);
  118. Py_XDECREF(value1);
  119. Py_XDECREF(value2);
  120. if (decref_tuple) { Py_XDECREF(tuple); }
  121. return -1;
  122. }
  123. /////////////// IterNext.proto ///////////////
  124. #define __Pyx_PyIter_Next(obj) __Pyx_PyIter_Next2(obj, NULL)
  125. static CYTHON_INLINE PyObject *__Pyx_PyIter_Next2(PyObject *, PyObject *); /*proto*/
  126. /////////////// IterNext ///////////////
  127. //@requires: Exceptions.c::PyThreadStateGet
  128. //@requires: Exceptions.c::PyErrFetchRestore
  129. static PyObject *__Pyx_PyIter_Next2Default(PyObject* defval) {
  130. PyObject* exc_type;
  131. __Pyx_PyThreadState_declare
  132. __Pyx_PyThreadState_assign
  133. exc_type = __Pyx_PyErr_Occurred();
  134. if (unlikely(exc_type)) {
  135. if (!defval || unlikely(!__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))
  136. return NULL;
  137. __Pyx_PyErr_Clear();
  138. Py_INCREF(defval);
  139. return defval;
  140. }
  141. if (defval) {
  142. Py_INCREF(defval);
  143. return defval;
  144. }
  145. __Pyx_PyErr_SetNone(PyExc_StopIteration);
  146. return NULL;
  147. }
  148. static void __Pyx_PyIter_Next_ErrorNoIterator(PyObject *iterator) {
  149. PyErr_Format(PyExc_TypeError,
  150. "%.200s object is not an iterator", Py_TYPE(iterator)->tp_name);
  151. }
  152. // originally copied from Py3's builtin_next()
  153. static CYTHON_INLINE PyObject *__Pyx_PyIter_Next2(PyObject* iterator, PyObject* defval) {
  154. PyObject* next;
  155. // We always do a quick slot check because calling PyIter_Check() is so wasteful.
  156. iternextfunc iternext = Py_TYPE(iterator)->tp_iternext;
  157. if (likely(iternext)) {
  158. #if CYTHON_USE_TYPE_SLOTS || CYTHON_COMPILING_IN_PYPY
  159. next = iternext(iterator);
  160. if (likely(next))
  161. return next;
  162. #if PY_VERSION_HEX >= 0x02070000 && CYTHON_COMPILING_IN_CPYTHON
  163. if (unlikely(iternext == &_PyObject_NextNotImplemented))
  164. return NULL;
  165. #endif
  166. #else
  167. // Since the slot was set, assume that PyIter_Next() will likely succeed, and properly fail otherwise.
  168. // Note: PyIter_Next() crashes in CPython if "tp_iternext" is NULL.
  169. next = PyIter_Next(iterator);
  170. if (likely(next))
  171. return next;
  172. #endif
  173. } else if (CYTHON_USE_TYPE_SLOTS || unlikely(!PyIter_Check(iterator))) {
  174. // If CYTHON_USE_TYPE_SLOTS, then the slot was not set and we don't have an iterable.
  175. // Otherwise, don't trust "tp_iternext" and rely on PyIter_Check().
  176. __Pyx_PyIter_Next_ErrorNoIterator(iterator);
  177. return NULL;
  178. }
  179. #if !CYTHON_USE_TYPE_SLOTS
  180. else {
  181. // We have an iterator with an empty "tp_iternext", but didn't call next() on it yet.
  182. next = PyIter_Next(iterator);
  183. if (likely(next))
  184. return next;
  185. }
  186. #endif
  187. return __Pyx_PyIter_Next2Default(defval);
  188. }
  189. /////////////// IterFinish.proto ///////////////
  190. static CYTHON_INLINE int __Pyx_IterFinish(void); /*proto*/
  191. /////////////// IterFinish ///////////////
  192. // When PyIter_Next(iter) has returned NULL in order to signal termination,
  193. // this function does the right cleanup and returns 0 on success. If it
  194. // detects an error that occurred in the iterator, it returns -1.
  195. static CYTHON_INLINE int __Pyx_IterFinish(void) {
  196. #if CYTHON_FAST_THREAD_STATE
  197. PyThreadState *tstate = __Pyx_PyThreadState_Current;
  198. PyObject* exc_type = tstate->curexc_type;
  199. if (unlikely(exc_type)) {
  200. if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) {
  201. PyObject *exc_value, *exc_tb;
  202. exc_value = tstate->curexc_value;
  203. exc_tb = tstate->curexc_traceback;
  204. tstate->curexc_type = 0;
  205. tstate->curexc_value = 0;
  206. tstate->curexc_traceback = 0;
  207. Py_DECREF(exc_type);
  208. Py_XDECREF(exc_value);
  209. Py_XDECREF(exc_tb);
  210. return 0;
  211. } else {
  212. return -1;
  213. }
  214. }
  215. return 0;
  216. #else
  217. if (unlikely(PyErr_Occurred())) {
  218. if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) {
  219. PyErr_Clear();
  220. return 0;
  221. } else {
  222. return -1;
  223. }
  224. }
  225. return 0;
  226. #endif
  227. }
  228. /////////////// ObjectGetItem.proto ///////////////
  229. #if CYTHON_USE_TYPE_SLOTS
  230. static CYTHON_INLINE PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key);/*proto*/
  231. #else
  232. #define __Pyx_PyObject_GetItem(obj, key) PyObject_GetItem(obj, key)
  233. #endif
  234. /////////////// ObjectGetItem ///////////////
  235. // //@requires: GetItemInt - added in IndexNode as it uses templating.
  236. #if CYTHON_USE_TYPE_SLOTS
  237. static PyObject *__Pyx_PyObject_GetIndex(PyObject *obj, PyObject* index) {
  238. PyObject *runerr = NULL;
  239. Py_ssize_t key_value;
  240. PySequenceMethods *m = Py_TYPE(obj)->tp_as_sequence;
  241. if (unlikely(!(m && m->sq_item))) {
  242. PyErr_Format(PyExc_TypeError, "'%.200s' object is not subscriptable", Py_TYPE(obj)->tp_name);
  243. return NULL;
  244. }
  245. key_value = __Pyx_PyIndex_AsSsize_t(index);
  246. if (likely(key_value != -1 || !(runerr = PyErr_Occurred()))) {
  247. return __Pyx_GetItemInt_Fast(obj, key_value, 0, 1, 1);
  248. }
  249. // Error handling code -- only manage OverflowError differently.
  250. if (PyErr_GivenExceptionMatches(runerr, PyExc_OverflowError)) {
  251. PyErr_Clear();
  252. PyErr_Format(PyExc_IndexError, "cannot fit '%.200s' into an index-sized integer", Py_TYPE(index)->tp_name);
  253. }
  254. return NULL;
  255. }
  256. static PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key) {
  257. PyMappingMethods *m = Py_TYPE(obj)->tp_as_mapping;
  258. if (likely(m && m->mp_subscript)) {
  259. return m->mp_subscript(obj, key);
  260. }
  261. return __Pyx_PyObject_GetIndex(obj, key);
  262. }
  263. #endif
  264. /////////////// DictGetItem.proto ///////////////
  265. #if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY
  266. static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key);/*proto*/
  267. #define __Pyx_PyObject_Dict_GetItem(obj, name) \
  268. (likely(PyDict_CheckExact(obj)) ? \
  269. __Pyx_PyDict_GetItem(obj, name) : PyObject_GetItem(obj, name))
  270. #else
  271. #define __Pyx_PyDict_GetItem(d, key) PyObject_GetItem(d, key)
  272. #define __Pyx_PyObject_Dict_GetItem(obj, name) PyObject_GetItem(obj, name)
  273. #endif
  274. /////////////// DictGetItem ///////////////
  275. #if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY
  276. static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) {
  277. PyObject *value;
  278. value = PyDict_GetItemWithError(d, key);
  279. if (unlikely(!value)) {
  280. if (!PyErr_Occurred()) {
  281. if (unlikely(PyTuple_Check(key))) {
  282. // CPython interprets tuples as separate arguments => must wrap them in another tuple.
  283. PyObject* args = PyTuple_Pack(1, key);
  284. if (likely(args)) {
  285. PyErr_SetObject(PyExc_KeyError, args);
  286. Py_DECREF(args);
  287. }
  288. } else {
  289. // Avoid tuple packing if possible.
  290. PyErr_SetObject(PyExc_KeyError, key);
  291. }
  292. }
  293. return NULL;
  294. }
  295. Py_INCREF(value);
  296. return value;
  297. }
  298. #endif
  299. /////////////// GetItemInt.proto ///////////////
  300. #define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \
  301. (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
  302. __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) : \
  303. (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) : \
  304. __Pyx_GetItemInt_Generic(o, to_py_func(i))))
  305. {{for type in ['List', 'Tuple']}}
  306. #define __Pyx_GetItemInt_{{type}}(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \
  307. (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
  308. __Pyx_GetItemInt_{{type}}_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) : \
  309. (PyErr_SetString(PyExc_IndexError, "{{ type.lower() }} index out of range"), (PyObject*)NULL))
  310. static CYTHON_INLINE PyObject *__Pyx_GetItemInt_{{type}}_Fast(PyObject *o, Py_ssize_t i,
  311. int wraparound, int boundscheck);
  312. {{endfor}}
  313. static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j);
  314. static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i,
  315. int is_list, int wraparound, int boundscheck);
  316. /////////////// GetItemInt ///////////////
  317. static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
  318. PyObject *r;
  319. if (!j) return NULL;
  320. r = PyObject_GetItem(o, j);
  321. Py_DECREF(j);
  322. return r;
  323. }
  324. {{for type in ['List', 'Tuple']}}
  325. static CYTHON_INLINE PyObject *__Pyx_GetItemInt_{{type}}_Fast(PyObject *o, Py_ssize_t i,
  326. CYTHON_NCP_UNUSED int wraparound,
  327. CYTHON_NCP_UNUSED int boundscheck) {
  328. #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
  329. Py_ssize_t wrapped_i = i;
  330. if (wraparound & unlikely(i < 0)) {
  331. wrapped_i += Py{{type}}_GET_SIZE(o);
  332. }
  333. if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, Py{{type}}_GET_SIZE(o)))) {
  334. PyObject *r = Py{{type}}_GET_ITEM(o, wrapped_i);
  335. Py_INCREF(r);
  336. return r;
  337. }
  338. return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
  339. #else
  340. return PySequence_GetItem(o, i);
  341. #endif
  342. }
  343. {{endfor}}
  344. static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list,
  345. CYTHON_NCP_UNUSED int wraparound,
  346. CYTHON_NCP_UNUSED int boundscheck) {
  347. #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS
  348. if (is_list || PyList_CheckExact(o)) {
  349. Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
  350. if ((!boundscheck) || (likely(__Pyx_is_valid_index(n, PyList_GET_SIZE(o))))) {
  351. PyObject *r = PyList_GET_ITEM(o, n);
  352. Py_INCREF(r);
  353. return r;
  354. }
  355. }
  356. else if (PyTuple_CheckExact(o)) {
  357. Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
  358. if ((!boundscheck) || likely(__Pyx_is_valid_index(n, PyTuple_GET_SIZE(o)))) {
  359. PyObject *r = PyTuple_GET_ITEM(o, n);
  360. Py_INCREF(r);
  361. return r;
  362. }
  363. } else {
  364. // inlined PySequence_GetItem() + special cased length overflow
  365. PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
  366. if (likely(m && m->sq_item)) {
  367. if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
  368. Py_ssize_t l = m->sq_length(o);
  369. if (likely(l >= 0)) {
  370. i += l;
  371. } else {
  372. // if length > max(Py_ssize_t), maybe the object can wrap around itself?
  373. if (!PyErr_ExceptionMatches(PyExc_OverflowError))
  374. return NULL;
  375. PyErr_Clear();
  376. }
  377. }
  378. return m->sq_item(o, i);
  379. }
  380. }
  381. #else
  382. if (is_list || PySequence_Check(o)) {
  383. return PySequence_GetItem(o, i);
  384. }
  385. #endif
  386. return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
  387. }
  388. /////////////// SetItemInt.proto ///////////////
  389. #define __Pyx_SetItemInt(o, i, v, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \
  390. (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
  391. __Pyx_SetItemInt_Fast(o, (Py_ssize_t)i, v, is_list, wraparound, boundscheck) : \
  392. (is_list ? (PyErr_SetString(PyExc_IndexError, "list assignment index out of range"), -1) : \
  393. __Pyx_SetItemInt_Generic(o, to_py_func(i), v)))
  394. static int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v);
  395. static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v,
  396. int is_list, int wraparound, int boundscheck);
  397. /////////////// SetItemInt ///////////////
  398. static int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v) {
  399. int r;
  400. if (!j) return -1;
  401. r = PyObject_SetItem(o, j, v);
  402. Py_DECREF(j);
  403. return r;
  404. }
  405. static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v, int is_list,
  406. CYTHON_NCP_UNUSED int wraparound, CYTHON_NCP_UNUSED int boundscheck) {
  407. #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS
  408. if (is_list || PyList_CheckExact(o)) {
  409. Py_ssize_t n = (!wraparound) ? i : ((likely(i >= 0)) ? i : i + PyList_GET_SIZE(o));
  410. if ((!boundscheck) || likely(__Pyx_is_valid_index(n, PyList_GET_SIZE(o)))) {
  411. PyObject* old = PyList_GET_ITEM(o, n);
  412. Py_INCREF(v);
  413. PyList_SET_ITEM(o, n, v);
  414. Py_DECREF(old);
  415. return 1;
  416. }
  417. } else {
  418. // inlined PySequence_SetItem() + special cased length overflow
  419. PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
  420. if (likely(m && m->sq_ass_item)) {
  421. if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
  422. Py_ssize_t l = m->sq_length(o);
  423. if (likely(l >= 0)) {
  424. i += l;
  425. } else {
  426. // if length > max(Py_ssize_t), maybe the object can wrap around itself?
  427. if (!PyErr_ExceptionMatches(PyExc_OverflowError))
  428. return -1;
  429. PyErr_Clear();
  430. }
  431. }
  432. return m->sq_ass_item(o, i, v);
  433. }
  434. }
  435. #else
  436. #if CYTHON_COMPILING_IN_PYPY
  437. if (is_list || (PySequence_Check(o) && !PyDict_Check(o)))
  438. #else
  439. if (is_list || PySequence_Check(o))
  440. #endif
  441. {
  442. return PySequence_SetItem(o, i, v);
  443. }
  444. #endif
  445. return __Pyx_SetItemInt_Generic(o, PyInt_FromSsize_t(i), v);
  446. }
  447. /////////////// DelItemInt.proto ///////////////
  448. #define __Pyx_DelItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck) \
  449. (__Pyx_fits_Py_ssize_t(i, type, is_signed) ? \
  450. __Pyx_DelItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound) : \
  451. (is_list ? (PyErr_SetString(PyExc_IndexError, "list assignment index out of range"), -1) : \
  452. __Pyx_DelItem_Generic(o, to_py_func(i))))
  453. static int __Pyx_DelItem_Generic(PyObject *o, PyObject *j);
  454. static CYTHON_INLINE int __Pyx_DelItemInt_Fast(PyObject *o, Py_ssize_t i,
  455. int is_list, int wraparound);
  456. /////////////// DelItemInt ///////////////
  457. static int __Pyx_DelItem_Generic(PyObject *o, PyObject *j) {
  458. int r;
  459. if (!j) return -1;
  460. r = PyObject_DelItem(o, j);
  461. Py_DECREF(j);
  462. return r;
  463. }
  464. static CYTHON_INLINE int __Pyx_DelItemInt_Fast(PyObject *o, Py_ssize_t i,
  465. CYTHON_UNUSED int is_list, CYTHON_NCP_UNUSED int wraparound) {
  466. #if !CYTHON_USE_TYPE_SLOTS
  467. if (is_list || PySequence_Check(o)) {
  468. return PySequence_DelItem(o, i);
  469. }
  470. #else
  471. // inlined PySequence_DelItem() + special cased length overflow
  472. PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
  473. if (likely(m && m->sq_ass_item)) {
  474. if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
  475. Py_ssize_t l = m->sq_length(o);
  476. if (likely(l >= 0)) {
  477. i += l;
  478. } else {
  479. // if length > max(Py_ssize_t), maybe the object can wrap around itself?
  480. if (!PyErr_ExceptionMatches(PyExc_OverflowError))
  481. return -1;
  482. PyErr_Clear();
  483. }
  484. }
  485. return m->sq_ass_item(o, i, (PyObject *)NULL);
  486. }
  487. #endif
  488. return __Pyx_DelItem_Generic(o, PyInt_FromSsize_t(i));
  489. }
  490. /////////////// SliceObject.proto ///////////////
  491. // we pass pointer addresses to show the C compiler what is NULL and what isn't
  492. {{if access == 'Get'}}
  493. static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(
  494. PyObject* obj, Py_ssize_t cstart, Py_ssize_t cstop,
  495. PyObject** py_start, PyObject** py_stop, PyObject** py_slice,
  496. int has_cstart, int has_cstop, int wraparound);
  497. {{else}}
  498. #define __Pyx_PyObject_DelSlice(obj, cstart, cstop, py_start, py_stop, py_slice, has_cstart, has_cstop, wraparound) \
  499. __Pyx_PyObject_SetSlice(obj, (PyObject*)NULL, cstart, cstop, py_start, py_stop, py_slice, has_cstart, has_cstop, wraparound)
  500. // we pass pointer addresses to show the C compiler what is NULL and what isn't
  501. static CYTHON_INLINE int __Pyx_PyObject_SetSlice(
  502. PyObject* obj, PyObject* value, Py_ssize_t cstart, Py_ssize_t cstop,
  503. PyObject** py_start, PyObject** py_stop, PyObject** py_slice,
  504. int has_cstart, int has_cstop, int wraparound);
  505. {{endif}}
  506. /////////////// SliceObject ///////////////
  507. {{if access == 'Get'}}
  508. static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(PyObject* obj,
  509. {{else}}
  510. static CYTHON_INLINE int __Pyx_PyObject_SetSlice(PyObject* obj, PyObject* value,
  511. {{endif}}
  512. Py_ssize_t cstart, Py_ssize_t cstop,
  513. PyObject** _py_start, PyObject** _py_stop, PyObject** _py_slice,
  514. int has_cstart, int has_cstop, CYTHON_UNUSED int wraparound) {
  515. #if CYTHON_USE_TYPE_SLOTS
  516. PyMappingMethods* mp;
  517. #if PY_MAJOR_VERSION < 3
  518. PySequenceMethods* ms = Py_TYPE(obj)->tp_as_sequence;
  519. if (likely(ms && ms->sq_{{if access == 'Set'}}ass_{{endif}}slice)) {
  520. if (!has_cstart) {
  521. if (_py_start && (*_py_start != Py_None)) {
  522. cstart = __Pyx_PyIndex_AsSsize_t(*_py_start);
  523. if ((cstart == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
  524. } else
  525. cstart = 0;
  526. }
  527. if (!has_cstop) {
  528. if (_py_stop && (*_py_stop != Py_None)) {
  529. cstop = __Pyx_PyIndex_AsSsize_t(*_py_stop);
  530. if ((cstop == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
  531. } else
  532. cstop = PY_SSIZE_T_MAX;
  533. }
  534. if (wraparound && unlikely((cstart < 0) | (cstop < 0)) && likely(ms->sq_length)) {
  535. Py_ssize_t l = ms->sq_length(obj);
  536. if (likely(l >= 0)) {
  537. if (cstop < 0) {
  538. cstop += l;
  539. if (cstop < 0) cstop = 0;
  540. }
  541. if (cstart < 0) {
  542. cstart += l;
  543. if (cstart < 0) cstart = 0;
  544. }
  545. } else {
  546. // if length > max(Py_ssize_t), maybe the object can wrap around itself?
  547. if (!PyErr_ExceptionMatches(PyExc_OverflowError))
  548. goto bad;
  549. PyErr_Clear();
  550. }
  551. }
  552. {{if access == 'Get'}}
  553. return ms->sq_slice(obj, cstart, cstop);
  554. {{else}}
  555. return ms->sq_ass_slice(obj, cstart, cstop, value);
  556. {{endif}}
  557. }
  558. #endif
  559. mp = Py_TYPE(obj)->tp_as_mapping;
  560. {{if access == 'Get'}}
  561. if (likely(mp && mp->mp_subscript))
  562. {{else}}
  563. if (likely(mp && mp->mp_ass_subscript))
  564. {{endif}}
  565. #endif
  566. {
  567. {{if access == 'Get'}}PyObject*{{else}}int{{endif}} result;
  568. PyObject *py_slice, *py_start, *py_stop;
  569. if (_py_slice) {
  570. py_slice = *_py_slice;
  571. } else {
  572. PyObject* owned_start = NULL;
  573. PyObject* owned_stop = NULL;
  574. if (_py_start) {
  575. py_start = *_py_start;
  576. } else {
  577. if (has_cstart) {
  578. owned_start = py_start = PyInt_FromSsize_t(cstart);
  579. if (unlikely(!py_start)) goto bad;
  580. } else
  581. py_start = Py_None;
  582. }
  583. if (_py_stop) {
  584. py_stop = *_py_stop;
  585. } else {
  586. if (has_cstop) {
  587. owned_stop = py_stop = PyInt_FromSsize_t(cstop);
  588. if (unlikely(!py_stop)) {
  589. Py_XDECREF(owned_start);
  590. goto bad;
  591. }
  592. } else
  593. py_stop = Py_None;
  594. }
  595. py_slice = PySlice_New(py_start, py_stop, Py_None);
  596. Py_XDECREF(owned_start);
  597. Py_XDECREF(owned_stop);
  598. if (unlikely(!py_slice)) goto bad;
  599. }
  600. #if CYTHON_USE_TYPE_SLOTS
  601. {{if access == 'Get'}}
  602. result = mp->mp_subscript(obj, py_slice);
  603. #else
  604. result = PyObject_GetItem(obj, py_slice);
  605. {{else}}
  606. result = mp->mp_ass_subscript(obj, py_slice, value);
  607. #else
  608. result = value ? PyObject_SetItem(obj, py_slice, value) : PyObject_DelItem(obj, py_slice);
  609. {{endif}}
  610. #endif
  611. if (!_py_slice) {
  612. Py_DECREF(py_slice);
  613. }
  614. return result;
  615. }
  616. PyErr_Format(PyExc_TypeError,
  617. {{if access == 'Get'}}
  618. "'%.200s' object is unsliceable", Py_TYPE(obj)->tp_name);
  619. {{else}}
  620. "'%.200s' object does not support slice %.10s",
  621. Py_TYPE(obj)->tp_name, value ? "assignment" : "deletion");
  622. {{endif}}
  623. bad:
  624. return {{if access == 'Get'}}NULL{{else}}-1{{endif}};
  625. }
  626. /////////////// SliceTupleAndList.proto ///////////////
  627. #if CYTHON_COMPILING_IN_CPYTHON
  628. static CYTHON_INLINE PyObject* __Pyx_PyList_GetSlice(PyObject* src, Py_ssize_t start, Py_ssize_t stop);
  629. static CYTHON_INLINE PyObject* __Pyx_PyTuple_GetSlice(PyObject* src, Py_ssize_t start, Py_ssize_t stop);
  630. #else
  631. #define __Pyx_PyList_GetSlice(seq, start, stop) PySequence_GetSlice(seq, start, stop)
  632. #define __Pyx_PyTuple_GetSlice(seq, start, stop) PySequence_GetSlice(seq, start, stop)
  633. #endif
  634. /////////////// SliceTupleAndList ///////////////
  635. #if CYTHON_COMPILING_IN_CPYTHON
  636. static CYTHON_INLINE void __Pyx_crop_slice(Py_ssize_t* _start, Py_ssize_t* _stop, Py_ssize_t* _length) {
  637. Py_ssize_t start = *_start, stop = *_stop, length = *_length;
  638. if (start < 0) {
  639. start += length;
  640. if (start < 0)
  641. start = 0;
  642. }
  643. if (stop < 0)
  644. stop += length;
  645. else if (stop > length)
  646. stop = length;
  647. *_length = stop - start;
  648. *_start = start;
  649. *_stop = stop;
  650. }
  651. static CYTHON_INLINE void __Pyx_copy_object_array(PyObject** CYTHON_RESTRICT src, PyObject** CYTHON_RESTRICT dest, Py_ssize_t length) {
  652. PyObject *v;
  653. Py_ssize_t i;
  654. for (i = 0; i < length; i++) {
  655. v = dest[i] = src[i];
  656. Py_INCREF(v);
  657. }
  658. }
  659. {{for type in ['List', 'Tuple']}}
  660. static CYTHON_INLINE PyObject* __Pyx_Py{{type}}_GetSlice(
  661. PyObject* src, Py_ssize_t start, Py_ssize_t stop) {
  662. PyObject* dest;
  663. Py_ssize_t length = Py{{type}}_GET_SIZE(src);
  664. __Pyx_crop_slice(&start, &stop, &length);
  665. if (unlikely(length <= 0))
  666. return Py{{type}}_New(0);
  667. dest = Py{{type}}_New(length);
  668. if (unlikely(!dest))
  669. return NULL;
  670. __Pyx_copy_object_array(
  671. ((Py{{type}}Object*)src)->ob_item + start,
  672. ((Py{{type}}Object*)dest)->ob_item,
  673. length);
  674. return dest;
  675. }
  676. {{endfor}}
  677. #endif
  678. /////////////// CalculateMetaclass.proto ///////////////
  679. static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases);
  680. /////////////// CalculateMetaclass ///////////////
  681. static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases) {
  682. Py_ssize_t i, nbases = PyTuple_GET_SIZE(bases);
  683. for (i=0; i < nbases; i++) {
  684. PyTypeObject *tmptype;
  685. PyObject *tmp = PyTuple_GET_ITEM(bases, i);
  686. tmptype = Py_TYPE(tmp);
  687. #if PY_MAJOR_VERSION < 3
  688. if (tmptype == &PyClass_Type)
  689. continue;
  690. #endif
  691. if (!metaclass) {
  692. metaclass = tmptype;
  693. continue;
  694. }
  695. if (PyType_IsSubtype(metaclass, tmptype))
  696. continue;
  697. if (PyType_IsSubtype(tmptype, metaclass)) {
  698. metaclass = tmptype;
  699. continue;
  700. }
  701. // else:
  702. PyErr_SetString(PyExc_TypeError,
  703. "metaclass conflict: "
  704. "the metaclass of a derived class "
  705. "must be a (non-strict) subclass "
  706. "of the metaclasses of all its bases");
  707. return NULL;
  708. }
  709. if (!metaclass) {
  710. #if PY_MAJOR_VERSION < 3
  711. metaclass = &PyClass_Type;
  712. #else
  713. metaclass = &PyType_Type;
  714. #endif
  715. }
  716. // make owned reference
  717. Py_INCREF((PyObject*) metaclass);
  718. return (PyObject*) metaclass;
  719. }
  720. /////////////// FindInheritedMetaclass.proto ///////////////
  721. static PyObject *__Pyx_FindInheritedMetaclass(PyObject *bases); /*proto*/
  722. /////////////// FindInheritedMetaclass ///////////////
  723. //@requires: PyObjectGetAttrStr
  724. //@requires: CalculateMetaclass
  725. static PyObject *__Pyx_FindInheritedMetaclass(PyObject *bases) {
  726. PyObject *metaclass;
  727. if (PyTuple_Check(bases) && PyTuple_GET_SIZE(bases) > 0) {
  728. PyTypeObject *metatype;
  729. #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
  730. PyObject *base = PyTuple_GET_ITEM(bases, 0);
  731. #else
  732. PyObject *base = PySequence_ITEM(bases, 0);
  733. #endif
  734. #if PY_MAJOR_VERSION < 3
  735. PyObject* basetype = __Pyx_PyObject_GetAttrStr(base, PYIDENT("__class__"));
  736. if (basetype) {
  737. metatype = (PyType_Check(basetype)) ? ((PyTypeObject*) basetype) : NULL;
  738. } else {
  739. PyErr_Clear();
  740. metatype = Py_TYPE(base);
  741. basetype = (PyObject*) metatype;
  742. Py_INCREF(basetype);
  743. }
  744. #else
  745. metatype = Py_TYPE(base);
  746. #endif
  747. metaclass = __Pyx_CalculateMetaclass(metatype, bases);
  748. #if !(CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS)
  749. Py_DECREF(base);
  750. #endif
  751. #if PY_MAJOR_VERSION < 3
  752. Py_DECREF(basetype);
  753. #endif
  754. } else {
  755. // no bases => use default metaclass
  756. #if PY_MAJOR_VERSION < 3
  757. metaclass = (PyObject *) &PyClass_Type;
  758. #else
  759. metaclass = (PyObject *) &PyType_Type;
  760. #endif
  761. Py_INCREF(metaclass);
  762. }
  763. return metaclass;
  764. }
  765. /////////////// Py3MetaclassGet.proto ///////////////
  766. static PyObject *__Pyx_Py3MetaclassGet(PyObject *bases, PyObject *mkw); /*proto*/
  767. /////////////// Py3MetaclassGet ///////////////
  768. //@requires: FindInheritedMetaclass
  769. //@requires: CalculateMetaclass
  770. static PyObject *__Pyx_Py3MetaclassGet(PyObject *bases, PyObject *mkw) {
  771. PyObject *metaclass = mkw ? __Pyx_PyDict_GetItemStr(mkw, PYIDENT("metaclass")) : NULL;
  772. if (metaclass) {
  773. Py_INCREF(metaclass);
  774. if (PyDict_DelItem(mkw, PYIDENT("metaclass")) < 0) {
  775. Py_DECREF(metaclass);
  776. return NULL;
  777. }
  778. if (PyType_Check(metaclass)) {
  779. PyObject* orig = metaclass;
  780. metaclass = __Pyx_CalculateMetaclass((PyTypeObject*) metaclass, bases);
  781. Py_DECREF(orig);
  782. }
  783. return metaclass;
  784. }
  785. return __Pyx_FindInheritedMetaclass(bases);
  786. }
  787. /////////////// CreateClass.proto ///////////////
  788. static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name,
  789. PyObject *qualname, PyObject *modname); /*proto*/
  790. /////////////// CreateClass ///////////////
  791. //@requires: FindInheritedMetaclass
  792. //@requires: CalculateMetaclass
  793. static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name,
  794. PyObject *qualname, PyObject *modname) {
  795. PyObject *result;
  796. PyObject *metaclass;
  797. if (PyDict_SetItem(dict, PYIDENT("__module__"), modname) < 0)
  798. return NULL;
  799. if (PyDict_SetItem(dict, PYIDENT("__qualname__"), qualname) < 0)
  800. return NULL;
  801. /* Python2 __metaclass__ */
  802. metaclass = __Pyx_PyDict_GetItemStr(dict, PYIDENT("__metaclass__"));
  803. if (metaclass) {
  804. Py_INCREF(metaclass);
  805. if (PyType_Check(metaclass)) {
  806. PyObject* orig = metaclass;
  807. metaclass = __Pyx_CalculateMetaclass((PyTypeObject*) metaclass, bases);
  808. Py_DECREF(orig);
  809. }
  810. } else {
  811. metaclass = __Pyx_FindInheritedMetaclass(bases);
  812. }
  813. if (unlikely(!metaclass))
  814. return NULL;
  815. result = PyObject_CallFunctionObjArgs(metaclass, name, bases, dict, NULL);
  816. Py_DECREF(metaclass);
  817. return result;
  818. }
  819. /////////////// Py3ClassCreate.proto ///////////////
  820. static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name, PyObject *qualname,
  821. PyObject *mkw, PyObject *modname, PyObject *doc); /*proto*/
  822. static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases, PyObject *dict,
  823. PyObject *mkw, int calculate_metaclass, int allow_py2_metaclass); /*proto*/
  824. /////////////// Py3ClassCreate ///////////////
  825. //@requires: PyObjectGetAttrStr
  826. //@requires: CalculateMetaclass
  827. static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name,
  828. PyObject *qualname, PyObject *mkw, PyObject *modname, PyObject *doc) {
  829. PyObject *ns;
  830. if (metaclass) {
  831. PyObject *prep = __Pyx_PyObject_GetAttrStr(metaclass, PYIDENT("__prepare__"));
  832. if (prep) {
  833. PyObject *pargs = PyTuple_Pack(2, name, bases);
  834. if (unlikely(!pargs)) {
  835. Py_DECREF(prep);
  836. return NULL;
  837. }
  838. ns = PyObject_Call(prep, pargs, mkw);
  839. Py_DECREF(prep);
  840. Py_DECREF(pargs);
  841. } else {
  842. if (unlikely(!PyErr_ExceptionMatches(PyExc_AttributeError)))
  843. return NULL;
  844. PyErr_Clear();
  845. ns = PyDict_New();
  846. }
  847. } else {
  848. ns = PyDict_New();
  849. }
  850. if (unlikely(!ns))
  851. return NULL;
  852. /* Required here to emulate assignment order */
  853. if (unlikely(PyObject_SetItem(ns, PYIDENT("__module__"), modname) < 0)) goto bad;
  854. if (unlikely(PyObject_SetItem(ns, PYIDENT("__qualname__"), qualname) < 0)) goto bad;
  855. if (unlikely(doc && PyObject_SetItem(ns, PYIDENT("__doc__"), doc) < 0)) goto bad;
  856. return ns;
  857. bad:
  858. Py_DECREF(ns);
  859. return NULL;
  860. }
  861. static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases,
  862. PyObject *dict, PyObject *mkw,
  863. int calculate_metaclass, int allow_py2_metaclass) {
  864. PyObject *result, *margs;
  865. PyObject *owned_metaclass = NULL;
  866. if (allow_py2_metaclass) {
  867. /* honour Python2 __metaclass__ for backward compatibility */
  868. owned_metaclass = PyObject_GetItem(dict, PYIDENT("__metaclass__"));
  869. if (owned_metaclass) {
  870. metaclass = owned_metaclass;
  871. } else if (likely(PyErr_ExceptionMatches(PyExc_KeyError))) {
  872. PyErr_Clear();
  873. } else {
  874. return NULL;
  875. }
  876. }
  877. if (calculate_metaclass && (!metaclass || PyType_Check(metaclass))) {
  878. metaclass = __Pyx_CalculateMetaclass((PyTypeObject*) metaclass, bases);
  879. Py_XDECREF(owned_metaclass);
  880. if (unlikely(!metaclass))
  881. return NULL;
  882. owned_metaclass = metaclass;
  883. }
  884. margs = PyTuple_Pack(3, name, bases, dict);
  885. if (unlikely(!margs)) {
  886. result = NULL;
  887. } else {
  888. result = PyObject_Call(metaclass, margs, mkw);
  889. Py_DECREF(margs);
  890. }
  891. Py_XDECREF(owned_metaclass);
  892. return result;
  893. }
  894. /////////////// ExtTypeTest.proto ///////////////
  895. static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/
  896. /////////////// ExtTypeTest ///////////////
  897. static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
  898. if (unlikely(!type)) {
  899. PyErr_SetString(PyExc_SystemError, "Missing type object");
  900. return 0;
  901. }
  902. if (likely(__Pyx_TypeCheck(obj, type)))
  903. return 1;
  904. PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s",
  905. Py_TYPE(obj)->tp_name, type->tp_name);
  906. return 0;
  907. }
  908. /////////////// CallableCheck.proto ///////////////
  909. #if CYTHON_USE_TYPE_SLOTS && PY_MAJOR_VERSION >= 3
  910. #define __Pyx_PyCallable_Check(obj) (Py_TYPE(obj)->tp_call != NULL)
  911. #else
  912. #define __Pyx_PyCallable_Check(obj) PyCallable_Check(obj)
  913. #endif
  914. /////////////// PyDictContains.proto ///////////////
  915. static CYTHON_INLINE int __Pyx_PyDict_ContainsTF(PyObject* item, PyObject* dict, int eq) {
  916. int result = PyDict_Contains(dict, item);
  917. return unlikely(result < 0) ? result : (result == (eq == Py_EQ));
  918. }
  919. /////////////// PySetContains.proto ///////////////
  920. static CYTHON_INLINE int __Pyx_PySet_ContainsTF(PyObject* key, PyObject* set, int eq); /* proto */
  921. /////////////// PySetContains ///////////////
  922. //@requires: Builtins.c::pyfrozenset_new
  923. static int __Pyx_PySet_ContainsUnhashable(PyObject *set, PyObject *key) {
  924. int result = -1;
  925. if (PySet_Check(key) && PyErr_ExceptionMatches(PyExc_TypeError)) {
  926. /* Convert key to frozenset */
  927. PyObject *tmpkey;
  928. PyErr_Clear();
  929. tmpkey = __Pyx_PyFrozenSet_New(key);
  930. if (tmpkey != NULL) {
  931. result = PySet_Contains(set, tmpkey);
  932. Py_DECREF(tmpkey);
  933. }
  934. }
  935. return result;
  936. }
  937. static CYTHON_INLINE int __Pyx_PySet_ContainsTF(PyObject* key, PyObject* set, int eq) {
  938. int result = PySet_Contains(set, key);
  939. if (unlikely(result < 0)) {
  940. result = __Pyx_PySet_ContainsUnhashable(set, key);
  941. }
  942. return unlikely(result < 0) ? result : (result == (eq == Py_EQ));
  943. }
  944. /////////////// PySequenceContains.proto ///////////////
  945. static CYTHON_INLINE int __Pyx_PySequence_ContainsTF(PyObject* item, PyObject* seq, int eq) {
  946. int result = PySequence_Contains(seq, item);
  947. return unlikely(result < 0) ? result : (result == (eq == Py_EQ));
  948. }
  949. /////////////// PyBoolOrNullFromLong.proto ///////////////
  950. static CYTHON_INLINE PyObject* __Pyx_PyBoolOrNull_FromLong(long b) {
  951. return unlikely(b < 0) ? NULL : __Pyx_PyBool_FromLong(b);
  952. }
  953. /////////////// GetBuiltinName.proto ///////////////
  954. static PyObject *__Pyx_GetBuiltinName(PyObject *name); /*proto*/
  955. /////////////// GetBuiltinName ///////////////
  956. //@requires: PyObjectGetAttrStr
  957. //@substitute: naming
  958. static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
  959. PyObject* result = __Pyx_PyObject_GetAttrStr($builtins_cname, name);
  960. if (unlikely(!result)) {
  961. PyErr_Format(PyExc_NameError,
  962. #if PY_MAJOR_VERSION >= 3
  963. "name '%U' is not defined", name);
  964. #else
  965. "name '%.200s' is not defined", PyString_AS_STRING(name));
  966. #endif
  967. }
  968. return result;
  969. }
  970. /////////////// GetNameInClass.proto ///////////////
  971. #define __Pyx_GetNameInClass(var, nmspace, name) (var) = __Pyx__GetNameInClass(nmspace, name)
  972. static PyObject *__Pyx__GetNameInClass(PyObject *nmspace, PyObject *name); /*proto*/
  973. /////////////// GetNameInClass ///////////////
  974. //@requires: PyObjectGetAttrStr
  975. //@requires: GetModuleGlobalName
  976. //@requires: Exceptions.c::PyThreadStateGet
  977. //@requires: Exceptions.c::PyErrFetchRestore
  978. //@requires: Exceptions.c::PyErrExceptionMatches
  979. static PyObject *__Pyx_GetGlobalNameAfterAttributeLookup(PyObject *name) {
  980. PyObject *result;
  981. __Pyx_PyThreadState_declare
  982. __Pyx_PyThreadState_assign
  983. if (unlikely(!__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError)))
  984. return NULL;
  985. __Pyx_PyErr_Clear();
  986. __Pyx_GetModuleGlobalNameUncached(result, name);
  987. return result;
  988. }
  989. static PyObject *__Pyx__GetNameInClass(PyObject *nmspace, PyObject *name) {
  990. PyObject *result;
  991. result = __Pyx_PyObject_GetAttrStr(nmspace, name);
  992. if (!result) {
  993. result = __Pyx_GetGlobalNameAfterAttributeLookup(name);
  994. }
  995. return result;
  996. }
  997. /////////////// SetNameInClass.proto ///////////////
  998. #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1
  999. // Identifier names are always interned and have a pre-calculated hash value.
  1000. #define __Pyx_SetNameInClass(ns, name, value) \
  1001. (likely(PyDict_CheckExact(ns)) ? _PyDict_SetItem_KnownHash(ns, name, value, ((PyASCIIObject *) name)->hash) : PyObject_SetItem(ns, name, value))
  1002. #elif CYTHON_COMPILING_IN_CPYTHON
  1003. #define __Pyx_SetNameInClass(ns, name, value) \
  1004. (likely(PyDict_CheckExact(ns)) ? PyDict_SetItem(ns, name, value) : PyObject_SetItem(ns, name, value))
  1005. #else
  1006. #define __Pyx_SetNameInClass(ns, name, value) PyObject_SetItem(ns, name, value)
  1007. #endif
  1008. /////////////// GetModuleGlobalName.proto ///////////////
  1009. //@requires: PyDictVersioning
  1010. //@substitute: naming
  1011. #if CYTHON_USE_DICT_VERSIONS
  1012. #define __Pyx_GetModuleGlobalName(var, name) do { \
  1013. static PY_UINT64_T __pyx_dict_version = 0; \
  1014. static PyObject *__pyx_dict_cached_value = NULL; \
  1015. (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION($moddict_cname))) ? \
  1016. (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) : \
  1017. __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value); \
  1018. } while(0)
  1019. #define __Pyx_GetModuleGlobalNameUncached(var, name) do { \
  1020. PY_UINT64_T __pyx_dict_version; \
  1021. PyObject *__pyx_dict_cached_value; \
  1022. (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value); \
  1023. } while(0)
  1024. static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value); /*proto*/
  1025. #else
  1026. #define __Pyx_GetModuleGlobalName(var, name) (var) = __Pyx__GetModuleGlobalName(name)
  1027. #define __Pyx_GetModuleGlobalNameUncached(var, name) (var) = __Pyx__GetModuleGlobalName(name)
  1028. static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name); /*proto*/
  1029. #endif
  1030. /////////////// GetModuleGlobalName ///////////////
  1031. //@requires: GetBuiltinName
  1032. //@substitute: naming
  1033. #if CYTHON_USE_DICT_VERSIONS
  1034. static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value)
  1035. #else
  1036. static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name)
  1037. #endif
  1038. {
  1039. PyObject *result;
  1040. #if !CYTHON_AVOID_BORROWED_REFS
  1041. #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1
  1042. // Identifier names are always interned and have a pre-calculated hash value.
  1043. result = _PyDict_GetItem_KnownHash($moddict_cname, name, ((PyASCIIObject *) name)->hash);
  1044. __PYX_UPDATE_DICT_CACHE($moddict_cname, result, *dict_cached_value, *dict_version)
  1045. if (likely(result)) {
  1046. return __Pyx_NewRef(result);
  1047. } else if (unlikely(PyErr_Occurred())) {
  1048. return NULL;
  1049. }
  1050. #else
  1051. result = PyDict_GetItem($moddict_cname, name);
  1052. __PYX_UPDATE_DICT_CACHE($moddict_cname, result, *dict_cached_value, *dict_version)
  1053. if (likely(result)) {
  1054. return __Pyx_NewRef(result);
  1055. }
  1056. #endif
  1057. #else
  1058. result = PyObject_GetItem($moddict_cname, name);
  1059. __PYX_UPDATE_DICT_CACHE($moddict_cname, result, *dict_cached_value, *dict_version)
  1060. if (likely(result)) {
  1061. return __Pyx_NewRef(result);
  1062. }
  1063. PyErr_Clear();
  1064. #endif
  1065. return __Pyx_GetBuiltinName(name);
  1066. }
  1067. //////////////////// GetAttr.proto ////////////////////
  1068. static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *, PyObject *); /*proto*/
  1069. //////////////////// GetAttr ////////////////////
  1070. //@requires: PyObjectGetAttrStr
  1071. static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *o, PyObject *n) {
  1072. #if CYTHON_USE_TYPE_SLOTS
  1073. #if PY_MAJOR_VERSION >= 3
  1074. if (likely(PyUnicode_Check(n)))
  1075. #else
  1076. if (likely(PyString_Check(n)))
  1077. #endif
  1078. return __Pyx_PyObject_GetAttrStr(o, n);
  1079. #endif
  1080. return PyObject_GetAttr(o, n);
  1081. }
  1082. /////////////// PyObjectLookupSpecial.proto ///////////////
  1083. //@requires: PyObjectGetAttrStr
  1084. #if CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
  1085. static CYTHON_INLINE PyObject* __Pyx_PyObject_LookupSpecial(PyObject* obj, PyObject* attr_name) {
  1086. PyObject *res;
  1087. PyTypeObject *tp = Py_TYPE(obj);
  1088. #if PY_MAJOR_VERSION < 3
  1089. if (unlikely(PyInstance_Check(obj)))
  1090. return __Pyx_PyObject_GetAttrStr(obj, attr_name);
  1091. #endif
  1092. // adapted from CPython's special_lookup() in ceval.c
  1093. res = _PyType_Lookup(tp, attr_name);
  1094. if (likely(res)) {
  1095. descrgetfunc f = Py_TYPE(res)->tp_descr_get;
  1096. if (!f) {
  1097. Py_INCREF(res);
  1098. } else {
  1099. res = f(res, obj, (PyObject *)tp);
  1100. }
  1101. } else {
  1102. PyErr_SetObject(PyExc_AttributeError, attr_name);
  1103. }
  1104. return res;
  1105. }
  1106. #else
  1107. #define __Pyx_PyObject_LookupSpecial(o,n) __Pyx_PyObject_GetAttrStr(o,n)
  1108. #endif
  1109. /////////////// PyObject_GenericGetAttrNoDict.proto ///////////////
  1110. // Setting "tp_getattro" to anything but "PyObject_GenericGetAttr" disables fast method calls in Py3.7.
  1111. #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
  1112. static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name);
  1113. #else
  1114. // No-args macro to allow function pointer assignment.
  1115. #define __Pyx_PyObject_GenericGetAttrNoDict PyObject_GenericGetAttr
  1116. #endif
  1117. /////////////// PyObject_GenericGetAttrNoDict ///////////////
  1118. #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
  1119. static PyObject *__Pyx_RaiseGenericGetAttributeError(PyTypeObject *tp, PyObject *attr_name) {
  1120. PyErr_Format(PyExc_AttributeError,
  1121. #if PY_MAJOR_VERSION >= 3
  1122. "'%.50s' object has no attribute '%U'",
  1123. tp->tp_name, attr_name);
  1124. #else
  1125. "'%.50s' object has no attribute '%.400s'",
  1126. tp->tp_name, PyString_AS_STRING(attr_name));
  1127. #endif
  1128. return NULL;
  1129. }
  1130. static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name) {
  1131. // Copied and adapted from _PyObject_GenericGetAttrWithDict() in CPython 2.6/3.7.
  1132. // To be used in the "tp_getattro" slot of extension types that have no instance dict and cannot be subclassed.
  1133. PyObject *descr;
  1134. PyTypeObject *tp = Py_TYPE(obj);
  1135. if (unlikely(!PyString_Check(attr_name))) {
  1136. return PyObject_GenericGetAttr(obj, attr_name);
  1137. }
  1138. assert(!tp->tp_dictoffset);
  1139. descr = _PyType_Lookup(tp, attr_name);
  1140. if (unlikely(!descr)) {
  1141. return __Pyx_RaiseGenericGetAttributeError(tp, attr_name);
  1142. }
  1143. Py_INCREF(descr);
  1144. #if PY_MAJOR_VERSION < 3
  1145. if (likely(PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_HAVE_CLASS)))
  1146. #endif
  1147. {
  1148. descrgetfunc f = Py_TYPE(descr)->tp_descr_get;
  1149. // Optimise for the non-descriptor case because it is faster.
  1150. if (unlikely(f)) {
  1151. PyObject *res = f(descr, obj, (PyObject *)tp);
  1152. Py_DECREF(descr);
  1153. return res;
  1154. }
  1155. }
  1156. return descr;
  1157. }
  1158. #endif
  1159. /////////////// PyObject_GenericGetAttr.proto ///////////////
  1160. // Setting "tp_getattro" to anything but "PyObject_GenericGetAttr" disables fast method calls in Py3.7.
  1161. #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
  1162. static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name);
  1163. #else
  1164. // No-args macro to allow function pointer assignment.
  1165. #define __Pyx_PyObject_GenericGetAttr PyObject_GenericGetAttr
  1166. #endif
  1167. /////////////// PyObject_GenericGetAttr ///////////////
  1168. //@requires: PyObject_GenericGetAttrNoDict
  1169. #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000
  1170. static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name) {
  1171. if (unlikely(Py_TYPE(obj)->tp_dictoffset)) {
  1172. return PyObject_GenericGetAttr(obj, attr_name);
  1173. }
  1174. return __Pyx_PyObject_GenericGetAttrNoDict(obj, attr_name);
  1175. }
  1176. #endif
  1177. /////////////// PyObjectGetAttrStrNoError.proto ///////////////
  1178. static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name);/*proto*/
  1179. /////////////// PyObjectGetAttrStrNoError ///////////////
  1180. //@requires: PyObjectGetAttrStr
  1181. //@requires: Exceptions.c::PyThreadStateGet
  1182. //@requires: Exceptions.c::PyErrFetchRestore
  1183. //@requires: Exceptions.c::PyErrExceptionMatches
  1184. static void __Pyx_PyObject_GetAttrStr_ClearAttributeError(void) {
  1185. __Pyx_PyThreadState_declare
  1186. __Pyx_PyThreadState_assign
  1187. if (likely(__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError)))
  1188. __Pyx_PyErr_Clear();
  1189. }
  1190. static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name) {
  1191. PyObject *result;
  1192. #if CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_TYPE_SLOTS && PY_VERSION_HEX >= 0x030700B1
  1193. // _PyObject_GenericGetAttrWithDict() in CPython 3.7+ can avoid raising the AttributeError.
  1194. // See https://bugs.python.org/issue32544
  1195. PyTypeObject* tp = Py_TYPE(obj);
  1196. if (likely(tp->tp_getattro == PyObject_GenericGetAttr)) {
  1197. return _PyObject_GenericGetAttrWithDict(obj, attr_name, NULL, 1);
  1198. }
  1199. #endif
  1200. result = __Pyx_PyObject_GetAttrStr(obj, attr_name);
  1201. if (unlikely(!result)) {
  1202. __Pyx_PyObject_GetAttrStr_ClearAttributeError();
  1203. }
  1204. return result;
  1205. }
  1206. /////////////// PyObjectGetAttrStr.proto ///////////////
  1207. #if CYTHON_USE_TYPE_SLOTS
  1208. static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name);/*proto*/
  1209. #else
  1210. #define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
  1211. #endif
  1212. /////////////// PyObjectGetAttrStr ///////////////
  1213. #if CYTHON_USE_TYPE_SLOTS
  1214. static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) {
  1215. PyTypeObject* tp = Py_TYPE(obj);
  1216. if (likely(tp->tp_getattro))
  1217. return tp->tp_getattro(obj, attr_name);
  1218. #if PY_MAJOR_VERSION < 3
  1219. if (likely(tp->tp_getattr))
  1220. return tp->tp_getattr(obj, PyString_AS_STRING(attr_name));
  1221. #endif
  1222. return PyObject_GetAttr(obj, attr_name);
  1223. }
  1224. #endif
  1225. /////////////// PyObjectSetAttrStr.proto ///////////////
  1226. #if CYTHON_USE_TYPE_SLOTS
  1227. #define __Pyx_PyObject_DelAttrStr(o,n) __Pyx_PyObject_SetAttrStr(o, n, NULL)
  1228. static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value);/*proto*/
  1229. #else
  1230. #define __Pyx_PyObject_DelAttrStr(o,n) PyObject_DelAttr(o,n)
  1231. #define __Pyx_PyObject_SetAttrStr(o,n,v) PyObject_SetAttr(o,n,v)
  1232. #endif
  1233. /////////////// PyObjectSetAttrStr ///////////////
  1234. #if CYTHON_USE_TYPE_SLOTS
  1235. static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value) {
  1236. PyTypeObject* tp = Py_TYPE(obj);
  1237. if (likely(tp->tp_setattro))
  1238. return tp->tp_setattro(obj, attr_name, value);
  1239. #if PY_MAJOR_VERSION < 3
  1240. if (likely(tp->tp_setattr))
  1241. return tp->tp_setattr(obj, PyString_AS_STRING(attr_name), value);
  1242. #endif
  1243. return PyObject_SetAttr(obj, attr_name, value);
  1244. }
  1245. #endif
  1246. /////////////// PyObjectGetMethod.proto ///////////////
  1247. static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method);/*proto*/
  1248. /////////////// PyObjectGetMethod ///////////////
  1249. //@requires: PyObjectGetAttrStr
  1250. static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method) {
  1251. PyObject *attr;
  1252. #if CYTHON_UNPACK_METHODS && CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_PYTYPE_LOOKUP
  1253. // Copied from _PyObject_GetMethod() in CPython 3.7
  1254. PyTypeObject *tp = Py_TYPE(obj);
  1255. PyObject *descr;
  1256. descrgetfunc f = NULL;
  1257. PyObject **dictptr, *dict;
  1258. int meth_found = 0;
  1259. assert (*method == NULL);
  1260. if (unlikely(tp->tp_getattro != PyObject_GenericGetAttr)) {
  1261. attr = __Pyx_PyObject_GetAttrStr(obj, name);
  1262. goto try_unpack;
  1263. }
  1264. if (unlikely(tp->tp_dict == NULL) && unlikely(PyType_Ready(tp) < 0)) {
  1265. return 0;
  1266. }
  1267. descr = _PyType_Lookup(tp, name);
  1268. if (likely(descr != NULL)) {
  1269. Py_INCREF(descr);
  1270. // Repeating the condition below accommodates for MSVC's inability to test macros inside of macro expansions.
  1271. #if PY_MAJOR_VERSION >= 3
  1272. #ifdef __Pyx_CyFunction_USED
  1273. if (likely(PyFunction_Check(descr) || (Py_TYPE(descr) == &PyMethodDescr_Type) || __Pyx_CyFunction_Check(descr)))
  1274. #else
  1275. if (likely(PyFunction_Check(descr) || (Py_TYPE(descr) == &PyMethodDescr_Type)))
  1276. #endif
  1277. #else
  1278. // "PyMethodDescr_Type" is not part of the C-API in Py2.
  1279. #ifdef __Pyx_CyFunction_USED
  1280. if (likely(PyFunction_Check(descr) || __Pyx_CyFunction_Check(descr)))
  1281. #else
  1282. if (likely(PyFunction_Check(descr)))
  1283. #endif
  1284. #endif
  1285. {
  1286. meth_found = 1;
  1287. } else {
  1288. f = Py_TYPE(descr)->tp_descr_get;
  1289. if (f != NULL && PyDescr_IsData(descr)) {
  1290. attr = f(descr, obj, (PyObject *)Py_TYPE(obj));
  1291. Py_DECREF(descr);
  1292. goto try_unpack;
  1293. }
  1294. }
  1295. }
  1296. dictptr = _PyObject_GetDictPtr(obj);
  1297. if (dictptr != NULL && (dict = *dictptr) != NULL) {
  1298. Py_INCREF(dict);
  1299. attr = __Pyx_PyDict_GetItemStr(dict, name);
  1300. if (attr != NULL) {
  1301. Py_INCREF(attr);
  1302. Py_DECREF(dict);
  1303. Py_XDECREF(descr);
  1304. goto try_unpack;
  1305. }
  1306. Py_DECREF(dict);
  1307. }
  1308. if (meth_found) {
  1309. *method = descr;
  1310. return 1;
  1311. }
  1312. if (f != NULL) {
  1313. attr = f(descr, obj, (PyObject *)Py_TYPE(obj));
  1314. Py_DECREF(descr);
  1315. goto try_unpack;
  1316. }
  1317. if (descr != NULL) {
  1318. *method = descr;
  1319. return 0;
  1320. }
  1321. PyErr_Format(PyExc_AttributeError,
  1322. #if PY_MAJOR_VERSION >= 3
  1323. "'%.50s' object has no attribute '%U'",
  1324. tp->tp_name, name);
  1325. #else
  1326. "'%.50s' object has no attribute '%.400s'",
  1327. tp->tp_name, PyString_AS_STRING(name));
  1328. #endif
  1329. return 0;
  1330. // Generic fallback implementation using normal attribute lookup.
  1331. #else
  1332. attr = __Pyx_PyObject_GetAttrStr(obj, name);
  1333. goto try_unpack;
  1334. #endif
  1335. try_unpack:
  1336. #if CYTHON_UNPACK_METHODS
  1337. // Even if we failed to avoid creating a bound method object, it's still worth unpacking it now, if possible.
  1338. if (likely(attr) && PyMethod_Check(attr) && likely(PyMethod_GET_SELF(attr) == obj)) {
  1339. PyObject *function = PyMethod_GET_FUNCTION(attr);
  1340. Py_INCREF(function);
  1341. Py_DECREF(attr);
  1342. *method = function;
  1343. return 1;
  1344. }
  1345. #endif
  1346. *method = attr;
  1347. return 0;
  1348. }
  1349. /////////////// UnpackUnboundCMethod.proto ///////////////
  1350. typedef struct {
  1351. PyObject *type;
  1352. PyObject **method_name;
  1353. // "func" is set on first access (direct C function pointer)
  1354. PyCFunction func;
  1355. // "method" is set on first access (fallback)
  1356. PyObject *method;
  1357. int flag;
  1358. } __Pyx_CachedCFunction;
  1359. /////////////// UnpackUnboundCMethod ///////////////
  1360. //@requires: PyObjectGetAttrStr
  1361. static int __Pyx_TryUnpackUnboundCMethod(__Pyx_CachedCFunction* target) {
  1362. PyObject *method;
  1363. method = __Pyx_PyObject_GetAttrStr(target->type, *target->method_name);
  1364. if (unlikely(!method))
  1365. return -1;
  1366. target->method = method;
  1367. #if CYTHON_COMPILING_IN_CPYTHON
  1368. #if PY_MAJOR_VERSION >= 3
  1369. // method dscriptor type isn't exported in Py2.x, cannot easily check the type there
  1370. if (likely(__Pyx_TypeCheck(method, &PyMethodDescr_Type)))
  1371. #endif
  1372. {
  1373. PyMethodDescrObject *descr = (PyMethodDescrObject*) method;
  1374. target->func = descr->d_method->ml_meth;
  1375. target->flag = descr->d_method->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_STACKLESS);
  1376. }
  1377. #endif
  1378. return 0;
  1379. }
  1380. /////////////// CallUnboundCMethod0.proto ///////////////
  1381. //@substitute: naming
  1382. static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self); /*proto*/
  1383. #if CYTHON_COMPILING_IN_CPYTHON
  1384. // FASTCALL methods receive "&empty_tuple" as simple "PyObject[0]*"
  1385. #define __Pyx_CallUnboundCMethod0(cfunc, self) \
  1386. (likely((cfunc)->func) ? \
  1387. (likely((cfunc)->flag == METH_NOARGS) ? (*((cfunc)->func))(self, NULL) : \
  1388. (PY_VERSION_HEX >= 0x030600B1 && likely((cfunc)->flag == METH_FASTCALL) ? \
  1389. (PY_VERSION_HEX >= 0x030700A0 ? \
  1390. (*(__Pyx_PyCFunctionFast)(void*)(PyCFunction)(cfunc)->func)(self, &$empty_tuple, 0) : \
  1391. (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)(cfunc)->func)(self, &$empty_tuple, 0, NULL)) : \
  1392. (PY_VERSION_HEX >= 0x030700A0 && (cfunc)->flag == (METH_FASTCALL | METH_KEYWORDS) ? \
  1393. (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)(cfunc)->func)(self, &$empty_tuple, 0, NULL) : \
  1394. (likely((cfunc)->flag == (METH_VARARGS | METH_KEYWORDS)) ? ((*(PyCFunctionWithKeywords)(void*)(PyCFunction)(cfunc)->func)(self, $empty_tuple, NULL)) : \
  1395. ((cfunc)->flag == METH_VARARGS ? (*((cfunc)->func))(self, $empty_tuple) : \
  1396. __Pyx__CallUnboundCMethod0(cfunc, self)))))) : \
  1397. __Pyx__CallUnboundCMethod0(cfunc, self))
  1398. #else
  1399. #define __Pyx_CallUnboundCMethod0(cfunc, self) __Pyx__CallUnboundCMethod0(cfunc, self)
  1400. #endif
  1401. /////////////// CallUnboundCMethod0 ///////////////
  1402. //@requires: UnpackUnboundCMethod
  1403. //@requires: PyObjectCall
  1404. static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self) {
  1405. PyObject *args, *result = NULL;
  1406. if (unlikely(!cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL;
  1407. #if CYTHON_ASSUME_SAFE_MACROS
  1408. args = PyTuple_New(1);
  1409. if (unlikely(!args)) goto bad;
  1410. Py_INCREF(self);
  1411. PyTuple_SET_ITEM(args, 0, self);
  1412. #else
  1413. args = PyTuple_Pack(1, self);
  1414. if (unlikely(!args)) goto bad;
  1415. #endif
  1416. result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
  1417. Py_DECREF(args);
  1418. bad:
  1419. return result;
  1420. }
  1421. /////////////// CallUnboundCMethod1.proto ///////////////
  1422. static PyObject* __Pyx__CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg);/*proto*/
  1423. #if CYTHON_COMPILING_IN_CPYTHON
  1424. static CYTHON_INLINE PyObject* __Pyx_CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg);/*proto*/
  1425. #else
  1426. #define __Pyx_CallUnboundCMethod1(cfunc, self, arg) __Pyx__CallUnboundCMethod1(cfunc, self, arg)
  1427. #endif
  1428. /////////////// CallUnboundCMethod1 ///////////////
  1429. //@requires: UnpackUnboundCMethod
  1430. //@requires: PyObjectCall
  1431. #if CYTHON_COMPILING_IN_CPYTHON
  1432. static CYTHON_INLINE PyObject* __Pyx_CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg) {
  1433. if (likely(cfunc->func)) {
  1434. int flag = cfunc->flag;
  1435. // Not using #ifdefs for PY_VERSION_HEX to avoid C compiler warnings about unused functions.
  1436. if (flag == METH_O) {
  1437. return (*(cfunc->func))(self, arg);
  1438. } else if (PY_VERSION_HEX >= 0x030600B1 && flag == METH_FASTCALL) {
  1439. #if PY_VERSION_HEX >= 0x030700A0
  1440. return (*(__Pyx_PyCFunctionFast)(void*)(PyCFunction)cfunc->func)(self, &arg, 1);
  1441. #else
  1442. return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, &arg, 1, NULL);
  1443. #endif
  1444. } else if (PY_VERSION_HEX >= 0x030700A0 && flag == (METH_FASTCALL | METH_KEYWORDS)) {
  1445. return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, &arg, 1, NULL);
  1446. }
  1447. }
  1448. return __Pyx__CallUnboundCMethod1(cfunc, self, arg);
  1449. }
  1450. #endif
  1451. static PyObject* __Pyx__CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg){
  1452. PyObject *args, *result = NULL;
  1453. if (unlikely(!cfunc->func && !cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL;
  1454. #if CYTHON_COMPILING_IN_CPYTHON
  1455. if (cfunc->func && (cfunc->flag & METH_VARARGS)) {
  1456. args = PyTuple_New(1);
  1457. if (unlikely(!args)) goto bad;
  1458. Py_INCREF(arg);
  1459. PyTuple_SET_ITEM(args, 0, arg);
  1460. if (cfunc->flag & METH_KEYWORDS)
  1461. result = (*(PyCFunctionWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, NULL);
  1462. else
  1463. result = (*cfunc->func)(self, args);
  1464. } else {
  1465. args = PyTuple_New(2);
  1466. if (unlikely(!args)) goto bad;
  1467. Py_INCREF(self);
  1468. PyTuple_SET_ITEM(args, 0, self);
  1469. Py_INCREF(arg);
  1470. PyTuple_SET_ITEM(args, 1, arg);
  1471. result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
  1472. }
  1473. #else
  1474. args = PyTuple_Pack(2, self, arg);
  1475. if (unlikely(!args)) goto bad;
  1476. result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
  1477. #endif
  1478. bad:
  1479. Py_XDECREF(args);
  1480. return result;
  1481. }
  1482. /////////////// CallUnboundCMethod2.proto ///////////////
  1483. static PyObject* __Pyx__CallUnboundCMethod2(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg1, PyObject* arg2); /*proto*/
  1484. #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030600B1
  1485. static CYTHON_INLINE PyObject *__Pyx_CallUnboundCMethod2(__Pyx_CachedCFunction *cfunc, PyObject *self, PyObject *arg1, PyObject *arg2); /*proto*/
  1486. #else
  1487. #define __Pyx_CallUnboundCMethod2(cfunc, self, arg1, arg2) __Pyx__CallUnboundCMethod2(cfunc, self, arg1, arg2)
  1488. #endif
  1489. /////////////// CallUnboundCMethod2 ///////////////
  1490. //@requires: UnpackUnboundCMethod
  1491. //@requires: PyObjectCall
  1492. #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030600B1
  1493. static CYTHON_INLINE PyObject *__Pyx_CallUnboundCMethod2(__Pyx_CachedCFunction *cfunc, PyObject *self, PyObject *arg1, PyObject *arg2) {
  1494. if (likely(cfunc->func)) {
  1495. PyObject *args[2] = {arg1, arg2};
  1496. if (cfunc->flag == METH_FASTCALL) {
  1497. #if PY_VERSION_HEX >= 0x030700A0
  1498. return (*(__Pyx_PyCFunctionFast)(void*)(PyCFunction)cfunc->func)(self, args, 2);
  1499. #else
  1500. return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, 2, NULL);
  1501. #endif
  1502. }
  1503. #if PY_VERSION_HEX >= 0x030700A0
  1504. if (cfunc->flag == (METH_FASTCALL | METH_KEYWORDS))
  1505. return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, 2, NULL);
  1506. #endif
  1507. }
  1508. return __Pyx__CallUnboundCMethod2(cfunc, self, arg1, arg2);
  1509. }
  1510. #endif
  1511. static PyObject* __Pyx__CallUnboundCMethod2(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg1, PyObject* arg2){
  1512. PyObject *args, *result = NULL;
  1513. if (unlikely(!cfunc->func && !cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL;
  1514. #if CYTHON_COMPILING_IN_CPYTHON
  1515. if (cfunc->func && (cfunc->flag & METH_VARARGS)) {
  1516. args = PyTuple_New(2);
  1517. if (unlikely(!args)) goto bad;
  1518. Py_INCREF(arg1);
  1519. PyTuple_SET_ITEM(args, 0, arg1);
  1520. Py_INCREF(arg2);
  1521. PyTuple_SET_ITEM(args, 1, arg2);
  1522. if (cfunc->flag & METH_KEYWORDS)
  1523. result = (*(PyCFunctionWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, NULL);
  1524. else
  1525. result = (*cfunc->func)(self, args);
  1526. } else {
  1527. args = PyTuple_New(3);
  1528. if (unlikely(!args)) goto bad;
  1529. Py_INCREF(self);
  1530. PyTuple_SET_ITEM(args, 0, self);
  1531. Py_INCREF(arg1);
  1532. PyTuple_SET_ITEM(args, 1, arg1);
  1533. Py_INCREF(arg2);
  1534. PyTuple_SET_ITEM(args, 2, arg2);
  1535. result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
  1536. }
  1537. #else
  1538. args = PyTuple_Pack(3, self, arg1, arg2);
  1539. if (unlikely(!args)) goto bad;
  1540. result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
  1541. #endif
  1542. bad:
  1543. Py_XDECREF(args);
  1544. return result;
  1545. }
  1546. /////////////// PyObjectCallMethod0.proto ///////////////
  1547. static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name); /*proto*/
  1548. /////////////// PyObjectCallMethod0 ///////////////
  1549. //@requires: PyObjectGetMethod
  1550. //@requires: PyObjectCallOneArg
  1551. //@requires: PyObjectCallNoArg
  1552. static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name) {
  1553. PyObject *method = NULL, *result = NULL;
  1554. int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method);
  1555. if (likely(is_method)) {
  1556. result = __Pyx_PyObject_CallOneArg(method, obj);
  1557. Py_DECREF(method);
  1558. return result;
  1559. }
  1560. if (unlikely(!method)) goto bad;
  1561. result = __Pyx_PyObject_CallNoArg(method);
  1562. Py_DECREF(method);
  1563. bad:
  1564. return result;
  1565. }
  1566. /////////////// PyObjectCallMethod1.proto ///////////////
  1567. static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg); /*proto*/
  1568. /////////////// PyObjectCallMethod1 ///////////////
  1569. //@requires: PyObjectGetMethod
  1570. //@requires: PyObjectCallOneArg
  1571. //@requires: PyObjectCall2Args
  1572. static PyObject* __Pyx__PyObject_CallMethod1(PyObject* method, PyObject* arg) {
  1573. // Separate function to avoid excessive inlining.
  1574. PyObject *result = __Pyx_PyObject_CallOneArg(method, arg);
  1575. Py_DECREF(method);
  1576. return result;
  1577. }
  1578. static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) {
  1579. PyObject *method = NULL, *result;
  1580. int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method);
  1581. if (likely(is_method)) {
  1582. result = __Pyx_PyObject_Call2Args(method, obj, arg);
  1583. Py_DECREF(method);
  1584. return result;
  1585. }
  1586. if (unlikely(!method)) return NULL;
  1587. return __Pyx__PyObject_CallMethod1(method, arg);
  1588. }
  1589. /////////////// PyObjectCallMethod2.proto ///////////////
  1590. static PyObject* __Pyx_PyObject_CallMethod2(PyObject* obj, PyObject* method_name, PyObject* arg1, PyObject* arg2); /*proto*/
  1591. /////////////// PyObjectCallMethod2 ///////////////
  1592. //@requires: PyObjectCall
  1593. //@requires: PyFunctionFastCall
  1594. //@requires: PyCFunctionFastCall
  1595. //@requires: PyObjectCall2Args
  1596. static PyObject* __Pyx_PyObject_Call3Args(PyObject* function, PyObject* arg1, PyObject* arg2, PyObject* arg3) {
  1597. #if CYTHON_FAST_PYCALL
  1598. if (PyFunction_Check(function)) {
  1599. PyObject *args[3] = {arg1, arg2, arg3};
  1600. return __Pyx_PyFunction_FastCall(function, args, 3);
  1601. }
  1602. #endif
  1603. #if CYTHON_FAST_PYCCALL
  1604. if (__Pyx_PyFastCFunction_Check(function)) {
  1605. PyObject *args[3] = {arg1, arg2, arg3};
  1606. return __Pyx_PyFunction_FastCall(function, args, 3);
  1607. }
  1608. #endif
  1609. args = PyTuple_New(3);
  1610. if (unlikely(!args)) goto done;
  1611. Py_INCREF(arg1);
  1612. PyTuple_SET_ITEM(args, 0, arg1);
  1613. Py_INCREF(arg2);
  1614. PyTuple_SET_ITEM(args, 1, arg2);
  1615. Py_INCREF(arg3);
  1616. PyTuple_SET_ITEM(args, 2, arg3);
  1617. result = __Pyx_PyObject_Call(function, args, NULL);
  1618. Py_DECREF(args);
  1619. return result;
  1620. }
  1621. static PyObject* __Pyx_PyObject_CallMethod2(PyObject* obj, PyObject* method_name, PyObject* arg1, PyObject* arg2) {
  1622. PyObject *args, *method = NULL, *result = NULL;
  1623. int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method);
  1624. if (likely(is_method)) {
  1625. result = __Pyx_PyObject_Call3Args(method, obj, arg1, arg2);
  1626. Py_DECREF(method);
  1627. return result;
  1628. }
  1629. if (unlikely(!method)) return NULL;
  1630. result = __Pyx_PyObject_Call2Args(method, arg1, arg2);
  1631. Py_DECREF(method);
  1632. return result;
  1633. }
  1634. /////////////// tp_new.proto ///////////////
  1635. #define __Pyx_tp_new(type_obj, args) __Pyx_tp_new_kwargs(type_obj, args, NULL)
  1636. static CYTHON_INLINE PyObject* __Pyx_tp_new_kwargs(PyObject* type_obj, PyObject* args, PyObject* kwargs) {
  1637. return (PyObject*) (((PyTypeObject*)type_obj)->tp_new((PyTypeObject*)type_obj, args, kwargs));
  1638. }
  1639. /////////////// PyObjectCall.proto ///////////////
  1640. #if CYTHON_COMPILING_IN_CPYTHON
  1641. static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw); /*proto*/
  1642. #else
  1643. #define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw)
  1644. #endif
  1645. /////////////// PyObjectCall ///////////////
  1646. #if CYTHON_COMPILING_IN_CPYTHON
  1647. static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
  1648. PyObject *result;
  1649. ternaryfunc call = Py_TYPE(func)->tp_call;
  1650. if (unlikely(!call))
  1651. return PyObject_Call(func, arg, kw);
  1652. if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
  1653. return NULL;
  1654. result = (*call)(func, arg, kw);
  1655. Py_LeaveRecursiveCall();
  1656. if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
  1657. PyErr_SetString(
  1658. PyExc_SystemError,
  1659. "NULL result without error in PyObject_Call");
  1660. }
  1661. return result;
  1662. }
  1663. #endif
  1664. /////////////// PyObjectCallMethO.proto ///////////////
  1665. #if CYTHON_COMPILING_IN_CPYTHON
  1666. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg); /*proto*/
  1667. #endif
  1668. /////////////// PyObjectCallMethO ///////////////
  1669. #if CYTHON_COMPILING_IN_CPYTHON
  1670. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
  1671. PyObject *self, *result;
  1672. PyCFunction cfunc;
  1673. cfunc = PyCFunction_GET_FUNCTION(func);
  1674. self = PyCFunction_GET_SELF(func);
  1675. if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
  1676. return NULL;
  1677. result = cfunc(self, arg);
  1678. Py_LeaveRecursiveCall();
  1679. if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
  1680. PyErr_SetString(
  1681. PyExc_SystemError,
  1682. "NULL result without error in PyObject_Call");
  1683. }
  1684. return result;
  1685. }
  1686. #endif
  1687. /////////////// PyFunctionFastCall.proto ///////////////
  1688. #if CYTHON_FAST_PYCALL
  1689. #define __Pyx_PyFunction_FastCall(func, args, nargs) \
  1690. __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL)
  1691. // let's assume that the non-public C-API function might still change during the 3.6 beta phase
  1692. #if 1 || PY_VERSION_HEX < 0x030600B1
  1693. static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs);
  1694. #else
  1695. #define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs)
  1696. #endif
  1697. // Backport from Python 3
  1698. // Assert a build-time dependency, as an expression.
  1699. // Your compile will fail if the condition isn't true, or can't be evaluated
  1700. // by the compiler. This can be used in an expression: its value is 0.
  1701. // Example:
  1702. // #define foo_to_char(foo) \
  1703. // ((char *)(foo) \
  1704. // + Py_BUILD_ASSERT_EXPR(offsetof(struct foo, string) == 0))
  1705. //
  1706. // Written by Rusty Russell, public domain, http://ccodearchive.net/
  1707. #define __Pyx_BUILD_ASSERT_EXPR(cond) \
  1708. (sizeof(char [1 - 2*!(cond)]) - 1)
  1709. #ifndef Py_MEMBER_SIZE
  1710. // Get the size of a structure member in bytes
  1711. #define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member)
  1712. #endif
  1713. #if CYTHON_FAST_PYCALL
  1714. // Initialised by module init code.
  1715. static size_t __pyx_pyframe_localsplus_offset = 0;
  1716. #include "frameobject.h"
  1717. #if PY_VERSION_HEX >= 0x030b00a6
  1718. #ifndef Py_BUILD_CORE
  1719. #define Py_BUILD_CORE 1
  1720. #endif
  1721. #include "internal/pycore_frame.h"
  1722. #endif
  1723. // This is the long runtime version of
  1724. // #define __Pyx_PyFrame_GetLocalsplus(frame) ((frame)->f_localsplus)
  1725. // offsetof(PyFrameObject, f_localsplus) differs between regular C-Python and Stackless Python.
  1726. // Therefore the offset is computed at run time from PyFrame_type.tp_basicsize. That is feasible,
  1727. // because f_localsplus is the last field of PyFrameObject (checked by Py_BUILD_ASSERT_EXPR below).
  1728. #define __Pxy_PyFrame_Initialize_Offsets() \
  1729. ((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)), \
  1730. (void)(__pyx_pyframe_localsplus_offset = ((size_t)PyFrame_Type.tp_basicsize) - Py_MEMBER_SIZE(PyFrameObject, f_localsplus)))
  1731. #define __Pyx_PyFrame_GetLocalsplus(frame) \
  1732. (assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset))
  1733. #endif // CYTHON_FAST_PYCALL
  1734. #endif
  1735. /////////////// PyFunctionFastCall ///////////////
  1736. // copied from CPython 3.6 ceval.c
  1737. #if CYTHON_FAST_PYCALL
  1738. static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na,
  1739. PyObject *globals) {
  1740. PyFrameObject *f;
  1741. PyThreadState *tstate = __Pyx_PyThreadState_Current;
  1742. PyObject **fastlocals;
  1743. Py_ssize_t i;
  1744. PyObject *result;
  1745. assert(globals != NULL);
  1746. /* XXX Perhaps we should create a specialized
  1747. PyFrame_New() that doesn't take locals, but does
  1748. take builtins without sanity checking them.
  1749. */
  1750. assert(tstate != NULL);
  1751. f = PyFrame_New(tstate, co, globals, NULL);
  1752. if (f == NULL) {
  1753. return NULL;
  1754. }
  1755. fastlocals = __Pyx_PyFrame_GetLocalsplus(f);
  1756. for (i = 0; i < na; i++) {
  1757. Py_INCREF(*args);
  1758. fastlocals[i] = *args++;
  1759. }
  1760. result = PyEval_EvalFrameEx(f,0);
  1761. ++tstate->recursion_depth;
  1762. Py_DECREF(f);
  1763. --tstate->recursion_depth;
  1764. return result;
  1765. }
  1766. #if 1 || PY_VERSION_HEX < 0x030600B1
  1767. static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs) {
  1768. PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func);
  1769. PyObject *globals = PyFunction_GET_GLOBALS(func);
  1770. PyObject *argdefs = PyFunction_GET_DEFAULTS(func);
  1771. PyObject *closure;
  1772. #if PY_MAJOR_VERSION >= 3
  1773. PyObject *kwdefs;
  1774. //#if PY_VERSION_HEX >= 0x03050000
  1775. //PyObject *name, *qualname;
  1776. //#endif
  1777. #endif
  1778. PyObject *kwtuple, **k;
  1779. PyObject **d;
  1780. Py_ssize_t nd;
  1781. Py_ssize_t nk;
  1782. PyObject *result;
  1783. assert(kwargs == NULL || PyDict_Check(kwargs));
  1784. nk = kwargs ? PyDict_Size(kwargs) : 0;
  1785. if (Py_EnterRecursiveCall((char*)" while calling a Python object")) {
  1786. return NULL;
  1787. }
  1788. if (
  1789. #if PY_MAJOR_VERSION >= 3
  1790. co->co_kwonlyargcount == 0 &&
  1791. #endif
  1792. likely(kwargs == NULL || nk == 0) &&
  1793. co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) {
  1794. /* Fast paths */
  1795. if (argdefs == NULL && co->co_argcount == nargs) {
  1796. result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals);
  1797. goto done;
  1798. }
  1799. else if (nargs == 0 && argdefs != NULL
  1800. && co->co_argcount == Py_SIZE(argdefs)) {
  1801. /* function called with no arguments, but all parameters have
  1802. a default value: use default values as arguments .*/
  1803. args = &PyTuple_GET_ITEM(argdefs, 0);
  1804. result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals);
  1805. goto done;
  1806. }
  1807. }
  1808. if (kwargs != NULL) {
  1809. Py_ssize_t pos, i;
  1810. kwtuple = PyTuple_New(2 * nk);
  1811. if (kwtuple == NULL) {
  1812. result = NULL;
  1813. goto done;
  1814. }
  1815. k = &PyTuple_GET_ITEM(kwtuple, 0);
  1816. pos = i = 0;
  1817. while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) {
  1818. Py_INCREF(k[i]);
  1819. Py_INCREF(k[i+1]);
  1820. i += 2;
  1821. }
  1822. nk = i / 2;
  1823. }
  1824. else {
  1825. kwtuple = NULL;
  1826. k = NULL;
  1827. }
  1828. closure = PyFunction_GET_CLOSURE(func);
  1829. #if PY_MAJOR_VERSION >= 3
  1830. kwdefs = PyFunction_GET_KW_DEFAULTS(func);
  1831. //#if PY_VERSION_HEX >= 0x03050000
  1832. //name = ((PyFunctionObject *)func) -> func_name;
  1833. //qualname = ((PyFunctionObject *)func) -> func_qualname;
  1834. //#endif
  1835. #endif
  1836. if (argdefs != NULL) {
  1837. d = &PyTuple_GET_ITEM(argdefs, 0);
  1838. nd = Py_SIZE(argdefs);
  1839. }
  1840. else {
  1841. d = NULL;
  1842. nd = 0;
  1843. }
  1844. //#if PY_VERSION_HEX >= 0x03050000
  1845. //return _PyEval_EvalCodeWithName((PyObject*)co, globals, (PyObject *)NULL,
  1846. // args, nargs,
  1847. // NULL, 0,
  1848. // d, nd, kwdefs,
  1849. // closure, name, qualname);
  1850. //#elif PY_MAJOR_VERSION >= 3
  1851. #if PY_MAJOR_VERSION >= 3
  1852. result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL,
  1853. args, (int)nargs,
  1854. k, (int)nk,
  1855. d, (int)nd, kwdefs, closure);
  1856. #else
  1857. result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL,
  1858. args, (int)nargs,
  1859. k, (int)nk,
  1860. d, (int)nd, closure);
  1861. #endif
  1862. Py_XDECREF(kwtuple);
  1863. done:
  1864. Py_LeaveRecursiveCall();
  1865. return result;
  1866. }
  1867. #endif /* CPython < 3.6 */
  1868. #endif /* CYTHON_FAST_PYCALL */
  1869. /////////////// PyCFunctionFastCall.proto ///////////////
  1870. #if CYTHON_FAST_PYCCALL
  1871. static CYTHON_INLINE PyObject *__Pyx_PyCFunction_FastCall(PyObject *func, PyObject **args, Py_ssize_t nargs);
  1872. #else
  1873. #define __Pyx_PyCFunction_FastCall(func, args, nargs) (assert(0), NULL)
  1874. #endif
  1875. /////////////// PyCFunctionFastCall ///////////////
  1876. #if CYTHON_FAST_PYCCALL
  1877. static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, PyObject **args, Py_ssize_t nargs) {
  1878. PyCFunctionObject *func = (PyCFunctionObject*)func_obj;
  1879. PyCFunction meth = PyCFunction_GET_FUNCTION(func);
  1880. PyObject *self = PyCFunction_GET_SELF(func);
  1881. int flags = PyCFunction_GET_FLAGS(func);
  1882. assert(PyCFunction_Check(func));
  1883. assert(METH_FASTCALL == (flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS)));
  1884. assert(nargs >= 0);
  1885. assert(nargs == 0 || args != NULL);
  1886. /* _PyCFunction_FastCallDict() must not be called with an exception set,
  1887. because it may clear it (directly or indirectly) and so the
  1888. caller loses its exception */
  1889. assert(!PyErr_Occurred());
  1890. if ((PY_VERSION_HEX < 0x030700A0) || unlikely(flags & METH_KEYWORDS)) {
  1891. return (*((__Pyx_PyCFunctionFastWithKeywords)(void*)meth)) (self, args, nargs, NULL);
  1892. } else {
  1893. return (*((__Pyx_PyCFunctionFast)(void*)meth)) (self, args, nargs);
  1894. }
  1895. }
  1896. #endif /* CYTHON_FAST_PYCCALL */
  1897. /////////////// PyObjectCall2Args.proto ///////////////
  1898. static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2); /*proto*/
  1899. /////////////// PyObjectCall2Args ///////////////
  1900. //@requires: PyObjectCall
  1901. //@requires: PyFunctionFastCall
  1902. //@requires: PyCFunctionFastCall
  1903. static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2) {
  1904. PyObject *args, *result = NULL;
  1905. #if CYTHON_FAST_PYCALL
  1906. if (PyFunction_Check(function)) {
  1907. PyObject *args[2] = {arg1, arg2};
  1908. return __Pyx_PyFunction_FastCall(function, args, 2);
  1909. }
  1910. #endif
  1911. #if CYTHON_FAST_PYCCALL
  1912. if (__Pyx_PyFastCFunction_Check(function)) {
  1913. PyObject *args[2] = {arg1, arg2};
  1914. return __Pyx_PyCFunction_FastCall(function, args, 2);
  1915. }
  1916. #endif
  1917. args = PyTuple_New(2);
  1918. if (unlikely(!args)) goto done;
  1919. Py_INCREF(arg1);
  1920. PyTuple_SET_ITEM(args, 0, arg1);
  1921. Py_INCREF(arg2);
  1922. PyTuple_SET_ITEM(args, 1, arg2);
  1923. Py_INCREF(function);
  1924. result = __Pyx_PyObject_Call(function, args, NULL);
  1925. Py_DECREF(args);
  1926. Py_DECREF(function);
  1927. done:
  1928. return result;
  1929. }
  1930. /////////////// PyObjectCallOneArg.proto ///////////////
  1931. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg); /*proto*/
  1932. /////////////// PyObjectCallOneArg ///////////////
  1933. //@requires: PyObjectCallMethO
  1934. //@requires: PyObjectCall
  1935. //@requires: PyFunctionFastCall
  1936. //@requires: PyCFunctionFastCall
  1937. #if CYTHON_COMPILING_IN_CPYTHON
  1938. static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) {
  1939. PyObject *result;
  1940. PyObject *args = PyTuple_New(1);
  1941. if (unlikely(!args)) return NULL;
  1942. Py_INCREF(arg);
  1943. PyTuple_SET_ITEM(args, 0, arg);
  1944. result = __Pyx_PyObject_Call(func, args, NULL);
  1945. Py_DECREF(args);
  1946. return result;
  1947. }
  1948. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
  1949. #if CYTHON_FAST_PYCALL
  1950. if (PyFunction_Check(func)) {
  1951. return __Pyx_PyFunction_FastCall(func, &arg, 1);
  1952. }
  1953. #endif
  1954. if (likely(PyCFunction_Check(func))) {
  1955. if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) {
  1956. // fast and simple case that we are optimising for
  1957. return __Pyx_PyObject_CallMethO(func, arg);
  1958. #if CYTHON_FAST_PYCCALL
  1959. } else if (__Pyx_PyFastCFunction_Check(func)) {
  1960. return __Pyx_PyCFunction_FastCall(func, &arg, 1);
  1961. #endif
  1962. }
  1963. }
  1964. return __Pyx__PyObject_CallOneArg(func, arg);
  1965. }
  1966. #else
  1967. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
  1968. PyObject *result;
  1969. PyObject *args = PyTuple_Pack(1, arg);
  1970. if (unlikely(!args)) return NULL;
  1971. result = __Pyx_PyObject_Call(func, args, NULL);
  1972. Py_DECREF(args);
  1973. return result;
  1974. }
  1975. #endif
  1976. /////////////// PyObjectCallNoArg.proto ///////////////
  1977. //@requires: PyObjectCall
  1978. //@substitute: naming
  1979. #if CYTHON_COMPILING_IN_CPYTHON
  1980. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func); /*proto*/
  1981. #else
  1982. #define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, $empty_tuple, NULL)
  1983. #endif
  1984. /////////////// PyObjectCallNoArg ///////////////
  1985. //@requires: PyObjectCallMethO
  1986. //@requires: PyObjectCall
  1987. //@requires: PyFunctionFastCall
  1988. //@substitute: naming
  1989. #if CYTHON_COMPILING_IN_CPYTHON
  1990. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
  1991. #if CYTHON_FAST_PYCALL
  1992. if (PyFunction_Check(func)) {
  1993. return __Pyx_PyFunction_FastCall(func, NULL, 0);
  1994. }
  1995. #endif
  1996. #if defined(__Pyx_CyFunction_USED) && defined(NDEBUG)
  1997. // TODO PyCFunction_GET_FLAGS has a type-check assert that breaks with a CyFunction
  1998. // in debug mode. There is likely to be a better way of avoiding tripping this
  1999. // check that doesn't involve disabling the optimized path.
  2000. if (likely(PyCFunction_Check(func) || __Pyx_CyFunction_Check(func)))
  2001. #else
  2002. if (likely(PyCFunction_Check(func)))
  2003. #endif
  2004. {
  2005. if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) {
  2006. // fast and simple case that we are optimising for
  2007. return __Pyx_PyObject_CallMethO(func, NULL);
  2008. }
  2009. }
  2010. return __Pyx_PyObject_Call(func, $empty_tuple, NULL);
  2011. }
  2012. #endif
  2013. /////////////// MatrixMultiply.proto ///////////////
  2014. #if PY_VERSION_HEX >= 0x03050000
  2015. #define __Pyx_PyNumber_MatrixMultiply(x,y) PyNumber_MatrixMultiply(x,y)
  2016. #define __Pyx_PyNumber_InPlaceMatrixMultiply(x,y) PyNumber_InPlaceMatrixMultiply(x,y)
  2017. #else
  2018. #define __Pyx_PyNumber_MatrixMultiply(x,y) __Pyx__PyNumber_MatrixMultiply(x, y, "@")
  2019. static PyObject* __Pyx__PyNumber_MatrixMultiply(PyObject* x, PyObject* y, const char* op_name);
  2020. static PyObject* __Pyx_PyNumber_InPlaceMatrixMultiply(PyObject* x, PyObject* y);
  2021. #endif
  2022. /////////////// MatrixMultiply ///////////////
  2023. //@requires: PyObjectGetAttrStr
  2024. //@requires: PyObjectCallOneArg
  2025. //@requires: PyFunctionFastCall
  2026. //@requires: PyCFunctionFastCall
  2027. #if PY_VERSION_HEX < 0x03050000
  2028. static PyObject* __Pyx_PyObject_CallMatrixMethod(PyObject* method, PyObject* arg) {
  2029. // NOTE: eats the method reference
  2030. PyObject *result = NULL;
  2031. #if CYTHON_UNPACK_METHODS
  2032. if (likely(PyMethod_Check(method))) {
  2033. PyObject *self = PyMethod_GET_SELF(method);
  2034. if (likely(self)) {
  2035. PyObject *args;
  2036. PyObject *function = PyMethod_GET_FUNCTION(method);
  2037. #if CYTHON_FAST_PYCALL
  2038. if (PyFunction_Check(function)) {
  2039. PyObject *args[2] = {self, arg};
  2040. result = __Pyx_PyFunction_FastCall(function, args, 2);
  2041. goto done;
  2042. }
  2043. #endif
  2044. #if CYTHON_FAST_PYCCALL
  2045. if (__Pyx_PyFastCFunction_Check(function)) {
  2046. PyObject *args[2] = {self, arg};
  2047. result = __Pyx_PyCFunction_FastCall(function, args, 2);
  2048. goto done;
  2049. }
  2050. #endif
  2051. args = PyTuple_New(2);
  2052. if (unlikely(!args)) goto done;
  2053. Py_INCREF(self);
  2054. PyTuple_SET_ITEM(args, 0, self);
  2055. Py_INCREF(arg);
  2056. PyTuple_SET_ITEM(args, 1, arg);
  2057. Py_INCREF(function);
  2058. Py_DECREF(method); method = NULL;
  2059. result = __Pyx_PyObject_Call(function, args, NULL);
  2060. Py_DECREF(args);
  2061. Py_DECREF(function);
  2062. return result;
  2063. }
  2064. }
  2065. #endif
  2066. result = __Pyx_PyObject_CallOneArg(method, arg);
  2067. done:
  2068. Py_DECREF(method);
  2069. return result;
  2070. }
  2071. #define __Pyx_TryMatrixMethod(x, y, py_method_name) { \
  2072. PyObject *func = __Pyx_PyObject_GetAttrStr(x, py_method_name); \
  2073. if (func) { \
  2074. PyObject *result = __Pyx_PyObject_CallMatrixMethod(func, y); \
  2075. if (result != Py_NotImplemented) \
  2076. return result; \
  2077. Py_DECREF(result); \
  2078. } else { \
  2079. if (!PyErr_ExceptionMatches(PyExc_AttributeError)) \
  2080. return NULL; \
  2081. PyErr_Clear(); \
  2082. } \
  2083. }
  2084. static PyObject* __Pyx__PyNumber_MatrixMultiply(PyObject* x, PyObject* y, const char* op_name) {
  2085. int right_is_subtype = PyObject_IsSubclass((PyObject*)Py_TYPE(y), (PyObject*)Py_TYPE(x));
  2086. if (unlikely(right_is_subtype == -1))
  2087. return NULL;
  2088. if (right_is_subtype) {
  2089. // to allow subtypes to override parent behaviour, try reversed operation first
  2090. // see note at https://docs.python.org/3/reference/datamodel.html#emulating-numeric-types
  2091. __Pyx_TryMatrixMethod(y, x, PYIDENT("__rmatmul__"))
  2092. }
  2093. __Pyx_TryMatrixMethod(x, y, PYIDENT("__matmul__"))
  2094. if (!right_is_subtype) {
  2095. __Pyx_TryMatrixMethod(y, x, PYIDENT("__rmatmul__"))
  2096. }
  2097. PyErr_Format(PyExc_TypeError,
  2098. "unsupported operand type(s) for %.2s: '%.100s' and '%.100s'",
  2099. op_name,
  2100. Py_TYPE(x)->tp_name,
  2101. Py_TYPE(y)->tp_name);
  2102. return NULL;
  2103. }
  2104. static PyObject* __Pyx_PyNumber_InPlaceMatrixMultiply(PyObject* x, PyObject* y) {
  2105. __Pyx_TryMatrixMethod(x, y, PYIDENT("__imatmul__"))
  2106. return __Pyx__PyNumber_MatrixMultiply(x, y, "@=");
  2107. }
  2108. #undef __Pyx_TryMatrixMethod
  2109. #endif
  2110. /////////////// PyDictVersioning.proto ///////////////
  2111. #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS
  2112. #define __PYX_DICT_VERSION_INIT ((PY_UINT64_T) -1)
  2113. #define __PYX_GET_DICT_VERSION(dict) (((PyDictObject*)(dict))->ma_version_tag)
  2114. #define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var) \
  2115. (version_var) = __PYX_GET_DICT_VERSION(dict); \
  2116. (cache_var) = (value);
  2117. #define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) { \
  2118. static PY_UINT64_T __pyx_dict_version = 0; \
  2119. static PyObject *__pyx_dict_cached_value = NULL; \
  2120. if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) { \
  2121. (VAR) = __pyx_dict_cached_value; \
  2122. } else { \
  2123. (VAR) = __pyx_dict_cached_value = (LOOKUP); \
  2124. __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT); \
  2125. } \
  2126. }
  2127. static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj); /*proto*/
  2128. static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj); /*proto*/
  2129. static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version); /*proto*/
  2130. #else
  2131. #define __PYX_GET_DICT_VERSION(dict) (0)
  2132. #define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)
  2133. #define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) (VAR) = (LOOKUP);
  2134. #endif
  2135. /////////////// PyDictVersioning ///////////////
  2136. #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS
  2137. static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) {
  2138. PyObject *dict = Py_TYPE(obj)->tp_dict;
  2139. return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0;
  2140. }
  2141. static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) {
  2142. PyObject **dictptr = NULL;
  2143. Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset;
  2144. if (offset) {
  2145. #if CYTHON_COMPILING_IN_CPYTHON
  2146. dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj);
  2147. #else
  2148. dictptr = _PyObject_GetDictPtr(obj);
  2149. #endif
  2150. }
  2151. return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0;
  2152. }
  2153. static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) {
  2154. PyObject *dict = Py_TYPE(obj)->tp_dict;
  2155. if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict)))
  2156. return 0;
  2157. return obj_dict_version == __Pyx_get_object_dict_version(obj);
  2158. }
  2159. #endif