ObjectHandling.c 76 KB

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