term.c 192 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165
  1. /* Generated by Cython 0.28.4 */
  2. /* BEGIN: Cython Metadata
  3. {
  4. "distutils": {
  5. "depends": [],
  6. "extra_compile_args": [
  7. "-fopenmp"
  8. ],
  9. "extra_link_args": [
  10. "-fopenmp"
  11. ],
  12. "include_dirs": [
  13. "/home/scossu/code/lsup/src/lakesuperior/cy_include",
  14. "/home/scossu/code/lsup/src/ext/include"
  15. ],
  16. "libraries": [
  17. "crypto"
  18. ],
  19. "name": "lakesuperior.store.ldp_rs.term",
  20. "sources": [
  21. "/home/scossu/code/lsup/src/lakesuperior/store/ldp_rs/term.pyx",
  22. "/home/scossu/code/lsup/src/ext/lib/tpl.c",
  23. "/home/scossu/code/lsup/src/ext/lib/mdb.c",
  24. "/home/scossu/code/lsup/src/ext/lib/midl.c"
  25. ]
  26. },
  27. "module_name": "lakesuperior.store.ldp_rs.term"
  28. }
  29. END: Cython Metadata */
  30. #define PY_SSIZE_T_CLEAN
  31. #include "Python.h"
  32. #ifndef Py_PYTHON_H
  33. #error Python headers needed to compile C extensions, please install development version of Python.
  34. #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000)
  35. #error Cython requires Python 2.6+ or Python 3.3+.
  36. #else
  37. #define CYTHON_ABI "0_28_4"
  38. #define CYTHON_FUTURE_DIVISION 1
  39. #include <stddef.h>
  40. #ifndef offsetof
  41. #define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
  42. #endif
  43. #if !defined(WIN32) && !defined(MS_WINDOWS)
  44. #ifndef __stdcall
  45. #define __stdcall
  46. #endif
  47. #ifndef __cdecl
  48. #define __cdecl
  49. #endif
  50. #ifndef __fastcall
  51. #define __fastcall
  52. #endif
  53. #endif
  54. #ifndef DL_IMPORT
  55. #define DL_IMPORT(t) t
  56. #endif
  57. #ifndef DL_EXPORT
  58. #define DL_EXPORT(t) t
  59. #endif
  60. #define __PYX_COMMA ,
  61. #ifndef HAVE_LONG_LONG
  62. #if PY_VERSION_HEX >= 0x02070000
  63. #define HAVE_LONG_LONG
  64. #endif
  65. #endif
  66. #ifndef PY_LONG_LONG
  67. #define PY_LONG_LONG LONG_LONG
  68. #endif
  69. #ifndef Py_HUGE_VAL
  70. #define Py_HUGE_VAL HUGE_VAL
  71. #endif
  72. #ifdef PYPY_VERSION
  73. #define CYTHON_COMPILING_IN_PYPY 1
  74. #define CYTHON_COMPILING_IN_PYSTON 0
  75. #define CYTHON_COMPILING_IN_CPYTHON 0
  76. #undef CYTHON_USE_TYPE_SLOTS
  77. #define CYTHON_USE_TYPE_SLOTS 0
  78. #undef CYTHON_USE_PYTYPE_LOOKUP
  79. #define CYTHON_USE_PYTYPE_LOOKUP 0
  80. #if PY_VERSION_HEX < 0x03050000
  81. #undef CYTHON_USE_ASYNC_SLOTS
  82. #define CYTHON_USE_ASYNC_SLOTS 0
  83. #elif !defined(CYTHON_USE_ASYNC_SLOTS)
  84. #define CYTHON_USE_ASYNC_SLOTS 1
  85. #endif
  86. #undef CYTHON_USE_PYLIST_INTERNALS
  87. #define CYTHON_USE_PYLIST_INTERNALS 0
  88. #undef CYTHON_USE_UNICODE_INTERNALS
  89. #define CYTHON_USE_UNICODE_INTERNALS 0
  90. #undef CYTHON_USE_UNICODE_WRITER
  91. #define CYTHON_USE_UNICODE_WRITER 0
  92. #undef CYTHON_USE_PYLONG_INTERNALS
  93. #define CYTHON_USE_PYLONG_INTERNALS 0
  94. #undef CYTHON_AVOID_BORROWED_REFS
  95. #define CYTHON_AVOID_BORROWED_REFS 1
  96. #undef CYTHON_ASSUME_SAFE_MACROS
  97. #define CYTHON_ASSUME_SAFE_MACROS 0
  98. #undef CYTHON_UNPACK_METHODS
  99. #define CYTHON_UNPACK_METHODS 0
  100. #undef CYTHON_FAST_THREAD_STATE
  101. #define CYTHON_FAST_THREAD_STATE 0
  102. #undef CYTHON_FAST_PYCALL
  103. #define CYTHON_FAST_PYCALL 0
  104. #undef CYTHON_PEP489_MULTI_PHASE_INIT
  105. #define CYTHON_PEP489_MULTI_PHASE_INIT 0
  106. #undef CYTHON_USE_TP_FINALIZE
  107. #define CYTHON_USE_TP_FINALIZE 0
  108. #elif defined(PYSTON_VERSION)
  109. #define CYTHON_COMPILING_IN_PYPY 0
  110. #define CYTHON_COMPILING_IN_PYSTON 1
  111. #define CYTHON_COMPILING_IN_CPYTHON 0
  112. #ifndef CYTHON_USE_TYPE_SLOTS
  113. #define CYTHON_USE_TYPE_SLOTS 1
  114. #endif
  115. #undef CYTHON_USE_PYTYPE_LOOKUP
  116. #define CYTHON_USE_PYTYPE_LOOKUP 0
  117. #undef CYTHON_USE_ASYNC_SLOTS
  118. #define CYTHON_USE_ASYNC_SLOTS 0
  119. #undef CYTHON_USE_PYLIST_INTERNALS
  120. #define CYTHON_USE_PYLIST_INTERNALS 0
  121. #ifndef CYTHON_USE_UNICODE_INTERNALS
  122. #define CYTHON_USE_UNICODE_INTERNALS 1
  123. #endif
  124. #undef CYTHON_USE_UNICODE_WRITER
  125. #define CYTHON_USE_UNICODE_WRITER 0
  126. #undef CYTHON_USE_PYLONG_INTERNALS
  127. #define CYTHON_USE_PYLONG_INTERNALS 0
  128. #ifndef CYTHON_AVOID_BORROWED_REFS
  129. #define CYTHON_AVOID_BORROWED_REFS 0
  130. #endif
  131. #ifndef CYTHON_ASSUME_SAFE_MACROS
  132. #define CYTHON_ASSUME_SAFE_MACROS 1
  133. #endif
  134. #ifndef CYTHON_UNPACK_METHODS
  135. #define CYTHON_UNPACK_METHODS 1
  136. #endif
  137. #undef CYTHON_FAST_THREAD_STATE
  138. #define CYTHON_FAST_THREAD_STATE 0
  139. #undef CYTHON_FAST_PYCALL
  140. #define CYTHON_FAST_PYCALL 0
  141. #undef CYTHON_PEP489_MULTI_PHASE_INIT
  142. #define CYTHON_PEP489_MULTI_PHASE_INIT 0
  143. #undef CYTHON_USE_TP_FINALIZE
  144. #define CYTHON_USE_TP_FINALIZE 0
  145. #else
  146. #define CYTHON_COMPILING_IN_PYPY 0
  147. #define CYTHON_COMPILING_IN_PYSTON 0
  148. #define CYTHON_COMPILING_IN_CPYTHON 1
  149. #ifndef CYTHON_USE_TYPE_SLOTS
  150. #define CYTHON_USE_TYPE_SLOTS 1
  151. #endif
  152. #if PY_VERSION_HEX < 0x02070000
  153. #undef CYTHON_USE_PYTYPE_LOOKUP
  154. #define CYTHON_USE_PYTYPE_LOOKUP 0
  155. #elif !defined(CYTHON_USE_PYTYPE_LOOKUP)
  156. #define CYTHON_USE_PYTYPE_LOOKUP 1
  157. #endif
  158. #if PY_MAJOR_VERSION < 3
  159. #undef CYTHON_USE_ASYNC_SLOTS
  160. #define CYTHON_USE_ASYNC_SLOTS 0
  161. #elif !defined(CYTHON_USE_ASYNC_SLOTS)
  162. #define CYTHON_USE_ASYNC_SLOTS 1
  163. #endif
  164. #if PY_VERSION_HEX < 0x02070000
  165. #undef CYTHON_USE_PYLONG_INTERNALS
  166. #define CYTHON_USE_PYLONG_INTERNALS 0
  167. #elif !defined(CYTHON_USE_PYLONG_INTERNALS)
  168. #define CYTHON_USE_PYLONG_INTERNALS 1
  169. #endif
  170. #ifndef CYTHON_USE_PYLIST_INTERNALS
  171. #define CYTHON_USE_PYLIST_INTERNALS 1
  172. #endif
  173. #ifndef CYTHON_USE_UNICODE_INTERNALS
  174. #define CYTHON_USE_UNICODE_INTERNALS 1
  175. #endif
  176. #if PY_VERSION_HEX < 0x030300F0
  177. #undef CYTHON_USE_UNICODE_WRITER
  178. #define CYTHON_USE_UNICODE_WRITER 0
  179. #elif !defined(CYTHON_USE_UNICODE_WRITER)
  180. #define CYTHON_USE_UNICODE_WRITER 1
  181. #endif
  182. #ifndef CYTHON_AVOID_BORROWED_REFS
  183. #define CYTHON_AVOID_BORROWED_REFS 0
  184. #endif
  185. #ifndef CYTHON_ASSUME_SAFE_MACROS
  186. #define CYTHON_ASSUME_SAFE_MACROS 1
  187. #endif
  188. #ifndef CYTHON_UNPACK_METHODS
  189. #define CYTHON_UNPACK_METHODS 1
  190. #endif
  191. #ifndef CYTHON_FAST_THREAD_STATE
  192. #define CYTHON_FAST_THREAD_STATE 1
  193. #endif
  194. #ifndef CYTHON_FAST_PYCALL
  195. #define CYTHON_FAST_PYCALL 1
  196. #endif
  197. #ifndef CYTHON_PEP489_MULTI_PHASE_INIT
  198. #define CYTHON_PEP489_MULTI_PHASE_INIT (0 && PY_VERSION_HEX >= 0x03050000)
  199. #endif
  200. #ifndef CYTHON_USE_TP_FINALIZE
  201. #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1)
  202. #endif
  203. #endif
  204. #if !defined(CYTHON_FAST_PYCCALL)
  205. #define CYTHON_FAST_PYCCALL (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1)
  206. #endif
  207. #if CYTHON_USE_PYLONG_INTERNALS
  208. #include "longintrepr.h"
  209. #undef SHIFT
  210. #undef BASE
  211. #undef MASK
  212. #endif
  213. #ifndef __has_attribute
  214. #define __has_attribute(x) 0
  215. #endif
  216. #ifndef __has_cpp_attribute
  217. #define __has_cpp_attribute(x) 0
  218. #endif
  219. #ifndef CYTHON_RESTRICT
  220. #if defined(__GNUC__)
  221. #define CYTHON_RESTRICT __restrict__
  222. #elif defined(_MSC_VER) && _MSC_VER >= 1400
  223. #define CYTHON_RESTRICT __restrict
  224. #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  225. #define CYTHON_RESTRICT restrict
  226. #else
  227. #define CYTHON_RESTRICT
  228. #endif
  229. #endif
  230. #ifndef CYTHON_UNUSED
  231. # if defined(__GNUC__)
  232. # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
  233. # define CYTHON_UNUSED __attribute__ ((__unused__))
  234. # else
  235. # define CYTHON_UNUSED
  236. # endif
  237. # elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
  238. # define CYTHON_UNUSED __attribute__ ((__unused__))
  239. # else
  240. # define CYTHON_UNUSED
  241. # endif
  242. #endif
  243. #ifndef CYTHON_MAYBE_UNUSED_VAR
  244. # if defined(__cplusplus)
  245. template<class T> void CYTHON_MAYBE_UNUSED_VAR( const T& ) { }
  246. # else
  247. # define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x)
  248. # endif
  249. #endif
  250. #ifndef CYTHON_NCP_UNUSED
  251. # if CYTHON_COMPILING_IN_CPYTHON
  252. # define CYTHON_NCP_UNUSED
  253. # else
  254. # define CYTHON_NCP_UNUSED CYTHON_UNUSED
  255. # endif
  256. #endif
  257. #define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None)
  258. #ifdef _MSC_VER
  259. #ifndef _MSC_STDINT_H_
  260. #if _MSC_VER < 1300
  261. typedef unsigned char uint8_t;
  262. typedef unsigned int uint32_t;
  263. #else
  264. typedef unsigned __int8 uint8_t;
  265. typedef unsigned __int32 uint32_t;
  266. #endif
  267. #endif
  268. #else
  269. #include <stdint.h>
  270. #endif
  271. #ifndef CYTHON_FALLTHROUGH
  272. #if defined(__cplusplus) && __cplusplus >= 201103L
  273. #if __has_cpp_attribute(fallthrough)
  274. #define CYTHON_FALLTHROUGH [[fallthrough]]
  275. #elif __has_cpp_attribute(clang::fallthrough)
  276. #define CYTHON_FALLTHROUGH [[clang::fallthrough]]
  277. #elif __has_cpp_attribute(gnu::fallthrough)
  278. #define CYTHON_FALLTHROUGH [[gnu::fallthrough]]
  279. #endif
  280. #endif
  281. #ifndef CYTHON_FALLTHROUGH
  282. #if __has_attribute(fallthrough)
  283. #define CYTHON_FALLTHROUGH __attribute__((fallthrough))
  284. #else
  285. #define CYTHON_FALLTHROUGH
  286. #endif
  287. #endif
  288. #if defined(__clang__ ) && defined(__apple_build_version__)
  289. #if __apple_build_version__ < 7000000
  290. #undef CYTHON_FALLTHROUGH
  291. #define CYTHON_FALLTHROUGH
  292. #endif
  293. #endif
  294. #endif
  295. #ifndef CYTHON_INLINE
  296. #if defined(__clang__)
  297. #define CYTHON_INLINE __inline__ __attribute__ ((__unused__))
  298. #elif defined(__GNUC__)
  299. #define CYTHON_INLINE __inline__
  300. #elif defined(_MSC_VER)
  301. #define CYTHON_INLINE __inline
  302. #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  303. #define CYTHON_INLINE inline
  304. #else
  305. #define CYTHON_INLINE
  306. #endif
  307. #endif
  308. #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
  309. #define Py_OptimizeFlag 0
  310. #endif
  311. #define __PYX_BUILD_PY_SSIZE_T "n"
  312. #define CYTHON_FORMAT_SSIZE_T "z"
  313. #if PY_MAJOR_VERSION < 3
  314. #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
  315. #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
  316. PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  317. #define __Pyx_DefaultClassType PyClass_Type
  318. #else
  319. #define __Pyx_BUILTIN_MODULE_NAME "builtins"
  320. #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
  321. PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  322. #define __Pyx_DefaultClassType PyType_Type
  323. #endif
  324. #ifndef Py_TPFLAGS_CHECKTYPES
  325. #define Py_TPFLAGS_CHECKTYPES 0
  326. #endif
  327. #ifndef Py_TPFLAGS_HAVE_INDEX
  328. #define Py_TPFLAGS_HAVE_INDEX 0
  329. #endif
  330. #ifndef Py_TPFLAGS_HAVE_NEWBUFFER
  331. #define Py_TPFLAGS_HAVE_NEWBUFFER 0
  332. #endif
  333. #ifndef Py_TPFLAGS_HAVE_FINALIZE
  334. #define Py_TPFLAGS_HAVE_FINALIZE 0
  335. #endif
  336. #if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL)
  337. #ifndef METH_FASTCALL
  338. #define METH_FASTCALL 0x80
  339. #endif
  340. typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs);
  341. typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args,
  342. Py_ssize_t nargs, PyObject *kwnames);
  343. #else
  344. #define __Pyx_PyCFunctionFast _PyCFunctionFast
  345. #define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords
  346. #endif
  347. #if CYTHON_FAST_PYCCALL
  348. #define __Pyx_PyFastCFunction_Check(func)\
  349. ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS)))))
  350. #else
  351. #define __Pyx_PyFastCFunction_Check(func) 0
  352. #endif
  353. #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc)
  354. #define PyObject_Malloc(s) PyMem_Malloc(s)
  355. #define PyObject_Free(p) PyMem_Free(p)
  356. #define PyObject_Realloc(p) PyMem_Realloc(p)
  357. #endif
  358. #if CYTHON_COMPILING_IN_PYSTON
  359. #define __Pyx_PyCode_HasFreeVars(co) PyCode_HasFreeVars(co)
  360. #define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno)
  361. #else
  362. #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0)
  363. #define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno)
  364. #endif
  365. #if !CYTHON_FAST_THREAD_STATE || PY_VERSION_HEX < 0x02070000
  366. #define __Pyx_PyThreadState_Current PyThreadState_GET()
  367. #elif PY_VERSION_HEX >= 0x03060000
  368. #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet()
  369. #elif PY_VERSION_HEX >= 0x03000000
  370. #define __Pyx_PyThreadState_Current PyThreadState_GET()
  371. #else
  372. #define __Pyx_PyThreadState_Current _PyThreadState_Current
  373. #endif
  374. #if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT)
  375. #include "pythread.h"
  376. #define Py_tss_NEEDS_INIT 0
  377. typedef int Py_tss_t;
  378. static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) {
  379. *key = PyThread_create_key();
  380. return 0; // PyThread_create_key reports success always
  381. }
  382. static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) {
  383. Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t));
  384. *key = Py_tss_NEEDS_INIT;
  385. return key;
  386. }
  387. static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) {
  388. PyObject_Free(key);
  389. }
  390. static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) {
  391. return *key != Py_tss_NEEDS_INIT;
  392. }
  393. static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) {
  394. PyThread_delete_key(*key);
  395. *key = Py_tss_NEEDS_INIT;
  396. }
  397. static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) {
  398. return PyThread_set_key_value(*key, value);
  399. }
  400. static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
  401. return PyThread_get_key_value(*key);
  402. }
  403. #endif // TSS (Thread Specific Storage) API
  404. #if CYTHON_COMPILING_IN_CPYTHON || defined(_PyDict_NewPresized)
  405. #define __Pyx_PyDict_NewPresized(n) ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n))
  406. #else
  407. #define __Pyx_PyDict_NewPresized(n) PyDict_New()
  408. #endif
  409. #if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION
  410. #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y)
  411. #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y)
  412. #else
  413. #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y)
  414. #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y)
  415. #endif
  416. #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && CYTHON_USE_UNICODE_INTERNALS
  417. #define __Pyx_PyDict_GetItemStr(dict, name) _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash)
  418. #else
  419. #define __Pyx_PyDict_GetItemStr(dict, name) PyDict_GetItem(dict, name)
  420. #endif
  421. #if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
  422. #define CYTHON_PEP393_ENABLED 1
  423. #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\
  424. 0 : _PyUnicode_Ready((PyObject *)(op)))
  425. #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u)
  426. #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
  427. #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) PyUnicode_MAX_CHAR_VALUE(u)
  428. #define __Pyx_PyUnicode_KIND(u) PyUnicode_KIND(u)
  429. #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u)
  430. #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i)
  431. #define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, ch)
  432. #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
  433. #else
  434. #define CYTHON_PEP393_ENABLED 0
  435. #define PyUnicode_1BYTE_KIND 1
  436. #define PyUnicode_2BYTE_KIND 2
  437. #define PyUnicode_4BYTE_KIND 4
  438. #define __Pyx_PyUnicode_READY(op) (0)
  439. #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u)
  440. #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
  441. #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111)
  442. #define __Pyx_PyUnicode_KIND(u) (sizeof(Py_UNICODE))
  443. #define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u))
  444. #define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
  445. #define __Pyx_PyUnicode_WRITE(k, d, i, ch) (((void)(k)), ((Py_UNICODE*)d)[i] = ch)
  446. #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_SIZE(u))
  447. #endif
  448. #if CYTHON_COMPILING_IN_PYPY
  449. #define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b)
  450. #define __Pyx_PyUnicode_ConcatSafe(a, b) PyNumber_Add(a, b)
  451. #else
  452. #define __Pyx_PyUnicode_Concat(a, b) PyUnicode_Concat(a, b)
  453. #define __Pyx_PyUnicode_ConcatSafe(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\
  454. PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b))
  455. #endif
  456. #if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains)
  457. #define PyUnicode_Contains(u, s) PySequence_Contains(u, s)
  458. #endif
  459. #if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check)
  460. #define PyByteArray_Check(obj) PyObject_TypeCheck(obj, &PyByteArray_Type)
  461. #endif
  462. #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format)
  463. #define PyObject_Format(obj, fmt) PyObject_CallMethod(obj, "__format__", "O", fmt)
  464. #endif
  465. #define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
  466. #define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
  467. #if PY_MAJOR_VERSION >= 3
  468. #define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b)
  469. #else
  470. #define __Pyx_PyString_Format(a, b) PyString_Format(a, b)
  471. #endif
  472. #if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII)
  473. #define PyObject_ASCII(o) PyObject_Repr(o)
  474. #endif
  475. #if PY_MAJOR_VERSION >= 3
  476. #define PyBaseString_Type PyUnicode_Type
  477. #define PyStringObject PyUnicodeObject
  478. #define PyString_Type PyUnicode_Type
  479. #define PyString_Check PyUnicode_Check
  480. #define PyString_CheckExact PyUnicode_CheckExact
  481. #define PyObject_Unicode PyObject_Str
  482. #endif
  483. #if PY_MAJOR_VERSION >= 3
  484. #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj)
  485. #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj)
  486. #else
  487. #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj))
  488. #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
  489. #endif
  490. #ifndef PySet_CheckExact
  491. #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type)
  492. #endif
  493. #if CYTHON_ASSUME_SAFE_MACROS
  494. #define __Pyx_PySequence_SIZE(seq) Py_SIZE(seq)
  495. #else
  496. #define __Pyx_PySequence_SIZE(seq) PySequence_Size(seq)
  497. #endif
  498. #if PY_MAJOR_VERSION >= 3
  499. #define PyIntObject PyLongObject
  500. #define PyInt_Type PyLong_Type
  501. #define PyInt_Check(op) PyLong_Check(op)
  502. #define PyInt_CheckExact(op) PyLong_CheckExact(op)
  503. #define PyInt_FromString PyLong_FromString
  504. #define PyInt_FromUnicode PyLong_FromUnicode
  505. #define PyInt_FromLong PyLong_FromLong
  506. #define PyInt_FromSize_t PyLong_FromSize_t
  507. #define PyInt_FromSsize_t PyLong_FromSsize_t
  508. #define PyInt_AsLong PyLong_AsLong
  509. #define PyInt_AS_LONG PyLong_AS_LONG
  510. #define PyInt_AsSsize_t PyLong_AsSsize_t
  511. #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask
  512. #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
  513. #define PyNumber_Int PyNumber_Long
  514. #endif
  515. #if PY_MAJOR_VERSION >= 3
  516. #define PyBoolObject PyLongObject
  517. #endif
  518. #if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY
  519. #ifndef PyUnicode_InternFromString
  520. #define PyUnicode_InternFromString(s) PyUnicode_FromString(s)
  521. #endif
  522. #endif
  523. #if PY_VERSION_HEX < 0x030200A4
  524. typedef long Py_hash_t;
  525. #define __Pyx_PyInt_FromHash_t PyInt_FromLong
  526. #define __Pyx_PyInt_AsHash_t PyInt_AsLong
  527. #else
  528. #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
  529. #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t
  530. #endif
  531. #if PY_MAJOR_VERSION >= 3
  532. #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : (Py_INCREF(func), func))
  533. #else
  534. #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
  535. #endif
  536. #if CYTHON_USE_ASYNC_SLOTS
  537. #if PY_VERSION_HEX >= 0x030500B1
  538. #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
  539. #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
  540. #else
  541. #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
  542. #endif
  543. #else
  544. #define __Pyx_PyType_AsAsync(obj) NULL
  545. #endif
  546. #ifndef __Pyx_PyAsyncMethodsStruct
  547. typedef struct {
  548. unaryfunc am_await;
  549. unaryfunc am_aiter;
  550. unaryfunc am_anext;
  551. } __Pyx_PyAsyncMethodsStruct;
  552. #endif
  553. #if defined(WIN32) || defined(MS_WINDOWS)
  554. #define _USE_MATH_DEFINES
  555. #endif
  556. #include <math.h>
  557. #ifdef NAN
  558. #define __PYX_NAN() ((float) NAN)
  559. #else
  560. static CYTHON_INLINE float __PYX_NAN() {
  561. float value;
  562. memset(&value, 0xFF, sizeof(value));
  563. return value;
  564. }
  565. #endif
  566. #if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL)
  567. #define __Pyx_truncl trunc
  568. #else
  569. #define __Pyx_truncl truncl
  570. #endif
  571. #define __PYX_ERR(f_index, lineno, Ln_error) \
  572. { \
  573. __pyx_filename = __pyx_f[f_index]; __pyx_lineno = lineno; __pyx_clineno = __LINE__; goto Ln_error; \
  574. }
  575. #ifndef __PYX_EXTERN_C
  576. #ifdef __cplusplus
  577. #define __PYX_EXTERN_C extern "C"
  578. #else
  579. #define __PYX_EXTERN_C extern
  580. #endif
  581. #endif
  582. #define __PYX_HAVE__lakesuperior__store__ldp_rs__term
  583. #define __PYX_HAVE_API__lakesuperior__store__ldp_rs__term
  584. /* Early includes */
  585. #include <string.h>
  586. #include <stdlib.h>
  587. #include <stdio.h>
  588. #include <stdint.h>
  589. #include "tpl.h"
  590. #ifdef _OPENMP
  591. #include <omp.h>
  592. #endif /* _OPENMP */
  593. #if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS)
  594. #define CYTHON_WITHOUT_ASSERTIONS
  595. #endif
  596. typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding;
  597. const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry;
  598. #define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0
  599. #define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 0
  600. #define __PYX_DEFAULT_STRING_ENCODING ""
  601. #define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString
  602. #define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
  603. #define __Pyx_uchar_cast(c) ((unsigned char)c)
  604. #define __Pyx_long_cast(x) ((long)x)
  605. #define __Pyx_fits_Py_ssize_t(v, type, is_signed) (\
  606. (sizeof(type) < sizeof(Py_ssize_t)) ||\
  607. (sizeof(type) > sizeof(Py_ssize_t) &&\
  608. likely(v < (type)PY_SSIZE_T_MAX ||\
  609. v == (type)PY_SSIZE_T_MAX) &&\
  610. (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\
  611. v == (type)PY_SSIZE_T_MIN))) ||\
  612. (sizeof(type) == sizeof(Py_ssize_t) &&\
  613. (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\
  614. v == (type)PY_SSIZE_T_MAX))) )
  615. #if defined (__cplusplus) && __cplusplus >= 201103L
  616. #include <cstdlib>
  617. #define __Pyx_sst_abs(value) std::abs(value)
  618. #elif SIZEOF_INT >= SIZEOF_SIZE_T
  619. #define __Pyx_sst_abs(value) abs(value)
  620. #elif SIZEOF_LONG >= SIZEOF_SIZE_T
  621. #define __Pyx_sst_abs(value) labs(value)
  622. #elif defined (_MSC_VER)
  623. #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value))
  624. #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  625. #define __Pyx_sst_abs(value) llabs(value)
  626. #elif defined (__GNUC__)
  627. #define __Pyx_sst_abs(value) __builtin_llabs(value)
  628. #else
  629. #define __Pyx_sst_abs(value) ((value<0) ? -value : value)
  630. #endif
  631. static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*);
  632. static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
  633. #define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s))
  634. #define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l)
  635. #define __Pyx_PyBytes_FromString PyBytes_FromString
  636. #define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
  637. static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*);
  638. #if PY_MAJOR_VERSION < 3
  639. #define __Pyx_PyStr_FromString __Pyx_PyBytes_FromString
  640. #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
  641. #else
  642. #define __Pyx_PyStr_FromString __Pyx_PyUnicode_FromString
  643. #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize
  644. #endif
  645. #define __Pyx_PyBytes_AsWritableString(s) ((char*) PyBytes_AS_STRING(s))
  646. #define __Pyx_PyBytes_AsWritableSString(s) ((signed char*) PyBytes_AS_STRING(s))
  647. #define __Pyx_PyBytes_AsWritableUString(s) ((unsigned char*) PyBytes_AS_STRING(s))
  648. #define __Pyx_PyBytes_AsString(s) ((const char*) PyBytes_AS_STRING(s))
  649. #define __Pyx_PyBytes_AsSString(s) ((const signed char*) PyBytes_AS_STRING(s))
  650. #define __Pyx_PyBytes_AsUString(s) ((const unsigned char*) PyBytes_AS_STRING(s))
  651. #define __Pyx_PyObject_AsWritableString(s) ((char*) __Pyx_PyObject_AsString(s))
  652. #define __Pyx_PyObject_AsWritableSString(s) ((signed char*) __Pyx_PyObject_AsString(s))
  653. #define __Pyx_PyObject_AsWritableUString(s) ((unsigned char*) __Pyx_PyObject_AsString(s))
  654. #define __Pyx_PyObject_AsSString(s) ((const signed char*) __Pyx_PyObject_AsString(s))
  655. #define __Pyx_PyObject_AsUString(s) ((const unsigned char*) __Pyx_PyObject_AsString(s))
  656. #define __Pyx_PyObject_FromCString(s) __Pyx_PyObject_FromString((const char*)s)
  657. #define __Pyx_PyBytes_FromCString(s) __Pyx_PyBytes_FromString((const char*)s)
  658. #define __Pyx_PyByteArray_FromCString(s) __Pyx_PyByteArray_FromString((const char*)s)
  659. #define __Pyx_PyStr_FromCString(s) __Pyx_PyStr_FromString((const char*)s)
  660. #define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s)
  661. static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) {
  662. const Py_UNICODE *u_end = u;
  663. while (*u_end++) ;
  664. return (size_t)(u_end - u - 1);
  665. }
  666. #define __Pyx_PyUnicode_FromUnicode(u) PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u))
  667. #define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode
  668. #define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode
  669. #define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)
  670. #define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None)
  671. static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b);
  672. static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
  673. static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x);
  674. #define __Pyx_PySequence_Tuple(obj)\
  675. (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj))
  676. static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
  677. static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
  678. #if CYTHON_ASSUME_SAFE_MACROS
  679. #define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
  680. #else
  681. #define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
  682. #endif
  683. #define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
  684. #if PY_MAJOR_VERSION >= 3
  685. #define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x))
  686. #else
  687. #define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x))
  688. #endif
  689. #define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x))
  690. #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
  691. static int __Pyx_sys_getdefaultencoding_not_ascii;
  692. static int __Pyx_init_sys_getdefaultencoding_params(void) {
  693. PyObject* sys;
  694. PyObject* default_encoding = NULL;
  695. PyObject* ascii_chars_u = NULL;
  696. PyObject* ascii_chars_b = NULL;
  697. const char* default_encoding_c;
  698. sys = PyImport_ImportModule("sys");
  699. if (!sys) goto bad;
  700. default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL);
  701. Py_DECREF(sys);
  702. if (!default_encoding) goto bad;
  703. default_encoding_c = PyBytes_AsString(default_encoding);
  704. if (!default_encoding_c) goto bad;
  705. if (strcmp(default_encoding_c, "ascii") == 0) {
  706. __Pyx_sys_getdefaultencoding_not_ascii = 0;
  707. } else {
  708. char ascii_chars[128];
  709. int c;
  710. for (c = 0; c < 128; c++) {
  711. ascii_chars[c] = c;
  712. }
  713. __Pyx_sys_getdefaultencoding_not_ascii = 1;
  714. ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL);
  715. if (!ascii_chars_u) goto bad;
  716. ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL);
  717. if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) {
  718. PyErr_Format(
  719. PyExc_ValueError,
  720. "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.",
  721. default_encoding_c);
  722. goto bad;
  723. }
  724. Py_DECREF(ascii_chars_u);
  725. Py_DECREF(ascii_chars_b);
  726. }
  727. Py_DECREF(default_encoding);
  728. return 0;
  729. bad:
  730. Py_XDECREF(default_encoding);
  731. Py_XDECREF(ascii_chars_u);
  732. Py_XDECREF(ascii_chars_b);
  733. return -1;
  734. }
  735. #endif
  736. #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3
  737. #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL)
  738. #else
  739. #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL)
  740. #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
  741. static char* __PYX_DEFAULT_STRING_ENCODING;
  742. static int __Pyx_init_sys_getdefaultencoding_params(void) {
  743. PyObject* sys;
  744. PyObject* default_encoding = NULL;
  745. char* default_encoding_c;
  746. sys = PyImport_ImportModule("sys");
  747. if (!sys) goto bad;
  748. default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
  749. Py_DECREF(sys);
  750. if (!default_encoding) goto bad;
  751. default_encoding_c = PyBytes_AsString(default_encoding);
  752. if (!default_encoding_c) goto bad;
  753. __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c));
  754. if (!__PYX_DEFAULT_STRING_ENCODING) goto bad;
  755. strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c);
  756. Py_DECREF(default_encoding);
  757. return 0;
  758. bad:
  759. Py_XDECREF(default_encoding);
  760. return -1;
  761. }
  762. #endif
  763. #endif
  764. /* Test for GCC > 2.95 */
  765. #if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)))
  766. #define likely(x) __builtin_expect(!!(x), 1)
  767. #define unlikely(x) __builtin_expect(!!(x), 0)
  768. #else /* !__GNUC__ or GCC < 2.95 */
  769. #define likely(x) (x)
  770. #define unlikely(x) (x)
  771. #endif /* __GNUC__ */
  772. static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; }
  773. static PyObject *__pyx_m = NULL;
  774. static PyObject *__pyx_d;
  775. static PyObject *__pyx_b;
  776. static PyObject *__pyx_cython_runtime = NULL;
  777. static PyObject *__pyx_empty_tuple;
  778. static PyObject *__pyx_empty_bytes;
  779. static PyObject *__pyx_empty_unicode;
  780. static int __pyx_lineno;
  781. static int __pyx_clineno = 0;
  782. static const char * __pyx_cfilenm= __FILE__;
  783. static const char *__pyx_filename;
  784. static const char *__pyx_f[] = {
  785. "lakesuperior/store/ldp_rs/term.pyx",
  786. "type.pxd",
  787. };
  788. /*--- Type declarations ---*/
  789. struct __pyx_t_12lakesuperior_5store_6ldp_rs_4term_IdentifierTerm;
  790. struct __pyx_t_12lakesuperior_5store_6ldp_rs_4term_LiteralTerm;
  791. /* "lakesuperior/store/ldp_rs/term.pxd":10
  792. * #size_t pack_size
  793. *
  794. * struct IdentifierTerm: # <<<<<<<<<<<<<<
  795. * char type
  796. * unsigned char *data
  797. */
  798. struct __pyx_t_12lakesuperior_5store_6ldp_rs_4term_IdentifierTerm {
  799. char type;
  800. unsigned char *data;
  801. };
  802. /* "lakesuperior/store/ldp_rs/term.pxd":14
  803. * unsigned char *data
  804. *
  805. * struct LiteralTerm: # <<<<<<<<<<<<<<
  806. * char type
  807. * unsigned char *data
  808. */
  809. struct __pyx_t_12lakesuperior_5store_6ldp_rs_4term_LiteralTerm {
  810. char type;
  811. unsigned char *data;
  812. unsigned char *datatype;
  813. unsigned char *lang;
  814. };
  815. /* --- Runtime support code (head) --- */
  816. /* Refnanny.proto */
  817. #ifndef CYTHON_REFNANNY
  818. #define CYTHON_REFNANNY 0
  819. #endif
  820. #if CYTHON_REFNANNY
  821. typedef struct {
  822. void (*INCREF)(void*, PyObject*, int);
  823. void (*DECREF)(void*, PyObject*, int);
  824. void (*GOTREF)(void*, PyObject*, int);
  825. void (*GIVEREF)(void*, PyObject*, int);
  826. void* (*SetupContext)(const char*, int, const char*);
  827. void (*FinishContext)(void**);
  828. } __Pyx_RefNannyAPIStruct;
  829. static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
  830. static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname);
  831. #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
  832. #ifdef WITH_THREAD
  833. #define __Pyx_RefNannySetupContext(name, acquire_gil)\
  834. if (acquire_gil) {\
  835. PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\
  836. __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
  837. PyGILState_Release(__pyx_gilstate_save);\
  838. } else {\
  839. __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
  840. }
  841. #else
  842. #define __Pyx_RefNannySetupContext(name, acquire_gil)\
  843. __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
  844. #endif
  845. #define __Pyx_RefNannyFinishContext()\
  846. __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
  847. #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  848. #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  849. #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  850. #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  851. #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
  852. #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
  853. #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
  854. #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
  855. #else
  856. #define __Pyx_RefNannyDeclarations
  857. #define __Pyx_RefNannySetupContext(name, acquire_gil)
  858. #define __Pyx_RefNannyFinishContext()
  859. #define __Pyx_INCREF(r) Py_INCREF(r)
  860. #define __Pyx_DECREF(r) Py_DECREF(r)
  861. #define __Pyx_GOTREF(r)
  862. #define __Pyx_GIVEREF(r)
  863. #define __Pyx_XINCREF(r) Py_XINCREF(r)
  864. #define __Pyx_XDECREF(r) Py_XDECREF(r)
  865. #define __Pyx_XGOTREF(r)
  866. #define __Pyx_XGIVEREF(r)
  867. #endif
  868. #define __Pyx_XDECREF_SET(r, v) do {\
  869. PyObject *tmp = (PyObject *) r;\
  870. r = v; __Pyx_XDECREF(tmp);\
  871. } while (0)
  872. #define __Pyx_DECREF_SET(r, v) do {\
  873. PyObject *tmp = (PyObject *) r;\
  874. r = v; __Pyx_DECREF(tmp);\
  875. } while (0)
  876. #define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
  877. #define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)
  878. /* PyObjectGetAttrStr.proto */
  879. #if CYTHON_USE_TYPE_SLOTS
  880. static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name);
  881. #else
  882. #define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
  883. #endif
  884. /* GetBuiltinName.proto */
  885. static PyObject *__Pyx_GetBuiltinName(PyObject *name);
  886. /* PyThreadStateGet.proto */
  887. #if CYTHON_FAST_THREAD_STATE
  888. #define __Pyx_PyThreadState_declare PyThreadState *__pyx_tstate;
  889. #define __Pyx_PyThreadState_assign __pyx_tstate = __Pyx_PyThreadState_Current;
  890. #define __Pyx_PyErr_Occurred() __pyx_tstate->curexc_type
  891. #else
  892. #define __Pyx_PyThreadState_declare
  893. #define __Pyx_PyThreadState_assign
  894. #define __Pyx_PyErr_Occurred() PyErr_Occurred()
  895. #endif
  896. /* PyErrFetchRestore.proto */
  897. #if CYTHON_FAST_THREAD_STATE
  898. #define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL)
  899. #define __Pyx_ErrRestoreWithState(type, value, tb) __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb)
  900. #define __Pyx_ErrFetchWithState(type, value, tb) __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb)
  901. #define __Pyx_ErrRestore(type, value, tb) __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb)
  902. #define __Pyx_ErrFetch(type, value, tb) __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb)
  903. static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
  904. static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
  905. #if CYTHON_COMPILING_IN_CPYTHON
  906. #define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL))
  907. #else
  908. #define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
  909. #endif
  910. #else
  911. #define __Pyx_PyErr_Clear() PyErr_Clear()
  912. #define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
  913. #define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb)
  914. #define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb)
  915. #define __Pyx_ErrRestoreInState(tstate, type, value, tb) PyErr_Restore(type, value, tb)
  916. #define __Pyx_ErrFetchInState(tstate, type, value, tb) PyErr_Fetch(type, value, tb)
  917. #define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb)
  918. #define __Pyx_ErrFetch(type, value, tb) PyErr_Fetch(type, value, tb)
  919. #endif
  920. /* Profile.proto */
  921. #ifndef CYTHON_PROFILE
  922. #if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_PYSTON
  923. #define CYTHON_PROFILE 0
  924. #else
  925. #define CYTHON_PROFILE 1
  926. #endif
  927. #endif
  928. #ifndef CYTHON_TRACE_NOGIL
  929. #define CYTHON_TRACE_NOGIL 0
  930. #else
  931. #if CYTHON_TRACE_NOGIL && !defined(CYTHON_TRACE)
  932. #define CYTHON_TRACE 1
  933. #endif
  934. #endif
  935. #ifndef CYTHON_TRACE
  936. #define CYTHON_TRACE 0
  937. #endif
  938. #if CYTHON_TRACE
  939. #undef CYTHON_PROFILE_REUSE_FRAME
  940. #endif
  941. #ifndef CYTHON_PROFILE_REUSE_FRAME
  942. #define CYTHON_PROFILE_REUSE_FRAME 0
  943. #endif
  944. #if CYTHON_PROFILE || CYTHON_TRACE
  945. #include "compile.h"
  946. #include "frameobject.h"
  947. #include "traceback.h"
  948. #if CYTHON_PROFILE_REUSE_FRAME
  949. #define CYTHON_FRAME_MODIFIER static
  950. #define CYTHON_FRAME_DEL(frame)
  951. #else
  952. #define CYTHON_FRAME_MODIFIER
  953. #define CYTHON_FRAME_DEL(frame) Py_CLEAR(frame)
  954. #endif
  955. #define __Pyx_TraceDeclarations\
  956. static PyCodeObject *__pyx_frame_code = NULL;\
  957. CYTHON_FRAME_MODIFIER PyFrameObject *__pyx_frame = NULL;\
  958. int __Pyx_use_tracing = 0;
  959. #define __Pyx_TraceFrameInit(codeobj)\
  960. if (codeobj) __pyx_frame_code = (PyCodeObject*) codeobj;
  961. #ifdef WITH_THREAD
  962. #define __Pyx_TraceCall(funcname, srcfile, firstlineno, nogil, goto_error)\
  963. if (nogil) {\
  964. if (CYTHON_TRACE_NOGIL) {\
  965. PyThreadState *tstate;\
  966. PyGILState_STATE state = PyGILState_Ensure();\
  967. tstate = __Pyx_PyThreadState_Current;\
  968. if (unlikely(tstate->use_tracing) && !tstate->tracing &&\
  969. (tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) {\
  970. __Pyx_use_tracing = __Pyx_TraceSetupAndCall(&__pyx_frame_code, &__pyx_frame, tstate, funcname, srcfile, firstlineno);\
  971. }\
  972. PyGILState_Release(state);\
  973. if (unlikely(__Pyx_use_tracing < 0)) goto_error;\
  974. }\
  975. } else {\
  976. PyThreadState* tstate = PyThreadState_GET();\
  977. if (unlikely(tstate->use_tracing) && !tstate->tracing &&\
  978. (tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) {\
  979. __Pyx_use_tracing = __Pyx_TraceSetupAndCall(&__pyx_frame_code, &__pyx_frame, tstate, funcname, srcfile, firstlineno);\
  980. if (unlikely(__Pyx_use_tracing < 0)) goto_error;\
  981. }\
  982. }
  983. #else
  984. #define __Pyx_TraceCall(funcname, srcfile, firstlineno, nogil, goto_error)\
  985. { PyThreadState* tstate = PyThreadState_GET();\
  986. if (unlikely(tstate->use_tracing) && !tstate->tracing &&\
  987. (tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) {\
  988. __Pyx_use_tracing = __Pyx_TraceSetupAndCall(&__pyx_frame_code, &__pyx_frame, tstate, funcname, srcfile, firstlineno);\
  989. if (unlikely(__Pyx_use_tracing < 0)) goto_error;\
  990. }\
  991. }
  992. #endif
  993. #define __Pyx_TraceException()\
  994. if (likely(!__Pyx_use_tracing)); else {\
  995. PyThreadState* tstate = __Pyx_PyThreadState_Current;\
  996. if (tstate->use_tracing &&\
  997. (tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) {\
  998. tstate->tracing++;\
  999. tstate->use_tracing = 0;\
  1000. PyObject *exc_info = __Pyx_GetExceptionTuple(tstate);\
  1001. if (exc_info) {\
  1002. if (CYTHON_TRACE && tstate->c_tracefunc)\
  1003. tstate->c_tracefunc(\
  1004. tstate->c_traceobj, __pyx_frame, PyTrace_EXCEPTION, exc_info);\
  1005. tstate->c_profilefunc(\
  1006. tstate->c_profileobj, __pyx_frame, PyTrace_EXCEPTION, exc_info);\
  1007. Py_DECREF(exc_info);\
  1008. }\
  1009. tstate->use_tracing = 1;\
  1010. tstate->tracing--;\
  1011. }\
  1012. }
  1013. static void __Pyx_call_return_trace_func(PyThreadState *tstate, PyFrameObject *frame, PyObject *result) {
  1014. PyObject *type, *value, *traceback;
  1015. __Pyx_ErrFetchInState(tstate, &type, &value, &traceback);
  1016. tstate->tracing++;
  1017. tstate->use_tracing = 0;
  1018. if (CYTHON_TRACE && tstate->c_tracefunc)
  1019. tstate->c_tracefunc(tstate->c_traceobj, frame, PyTrace_RETURN, result);
  1020. if (tstate->c_profilefunc)
  1021. tstate->c_profilefunc(tstate->c_profileobj, frame, PyTrace_RETURN, result);
  1022. CYTHON_FRAME_DEL(frame);
  1023. tstate->use_tracing = 1;
  1024. tstate->tracing--;
  1025. __Pyx_ErrRestoreInState(tstate, type, value, traceback);
  1026. }
  1027. #ifdef WITH_THREAD
  1028. #define __Pyx_TraceReturn(result, nogil)\
  1029. if (likely(!__Pyx_use_tracing)); else {\
  1030. if (nogil) {\
  1031. if (CYTHON_TRACE_NOGIL) {\
  1032. PyThreadState *tstate;\
  1033. PyGILState_STATE state = PyGILState_Ensure();\
  1034. tstate = __Pyx_PyThreadState_Current;\
  1035. if (tstate->use_tracing) {\
  1036. __Pyx_call_return_trace_func(tstate, __pyx_frame, (PyObject*)result);\
  1037. }\
  1038. PyGILState_Release(state);\
  1039. }\
  1040. } else {\
  1041. PyThreadState* tstate = __Pyx_PyThreadState_Current;\
  1042. if (tstate->use_tracing) {\
  1043. __Pyx_call_return_trace_func(tstate, __pyx_frame, (PyObject*)result);\
  1044. }\
  1045. }\
  1046. }
  1047. #else
  1048. #define __Pyx_TraceReturn(result, nogil)\
  1049. if (likely(!__Pyx_use_tracing)); else {\
  1050. PyThreadState* tstate = __Pyx_PyThreadState_Current;\
  1051. if (tstate->use_tracing) {\
  1052. __Pyx_call_return_trace_func(tstate, __pyx_frame, (PyObject*)result);\
  1053. }\
  1054. }
  1055. #endif
  1056. static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const char *srcfile, int firstlineno);
  1057. static int __Pyx_TraceSetupAndCall(PyCodeObject** code, PyFrameObject** frame, PyThreadState* tstate, const char *funcname, const char *srcfile, int firstlineno);
  1058. #else
  1059. #define __Pyx_TraceDeclarations
  1060. #define __Pyx_TraceFrameInit(codeobj)
  1061. #define __Pyx_TraceCall(funcname, srcfile, firstlineno, nogil, goto_error) if ((1)); else goto_error;
  1062. #define __Pyx_TraceException()
  1063. #define __Pyx_TraceReturn(result, nogil)
  1064. #endif
  1065. #if CYTHON_TRACE
  1066. static int __Pyx_call_line_trace_func(PyThreadState *tstate, PyFrameObject *frame, int lineno) {
  1067. int ret;
  1068. PyObject *type, *value, *traceback;
  1069. __Pyx_ErrFetchInState(tstate, &type, &value, &traceback);
  1070. __Pyx_PyFrame_SetLineNumber(frame, lineno);
  1071. tstate->tracing++;
  1072. tstate->use_tracing = 0;
  1073. ret = tstate->c_tracefunc(tstate->c_traceobj, frame, PyTrace_LINE, NULL);
  1074. tstate->use_tracing = 1;
  1075. tstate->tracing--;
  1076. if (likely(!ret)) {
  1077. __Pyx_ErrRestoreInState(tstate, type, value, traceback);
  1078. } else {
  1079. Py_XDECREF(type);
  1080. Py_XDECREF(value);
  1081. Py_XDECREF(traceback);
  1082. }
  1083. return ret;
  1084. }
  1085. #ifdef WITH_THREAD
  1086. #define __Pyx_TraceLine(lineno, nogil, goto_error)\
  1087. if (likely(!__Pyx_use_tracing)); else {\
  1088. if (nogil) {\
  1089. if (CYTHON_TRACE_NOGIL) {\
  1090. int ret = 0;\
  1091. PyThreadState *tstate;\
  1092. PyGILState_STATE state = PyGILState_Ensure();\
  1093. tstate = __Pyx_PyThreadState_Current;\
  1094. if (unlikely(tstate->use_tracing && tstate->c_tracefunc && __pyx_frame->f_trace)) {\
  1095. ret = __Pyx_call_line_trace_func(tstate, __pyx_frame, lineno);\
  1096. }\
  1097. PyGILState_Release(state);\
  1098. if (unlikely(ret)) goto_error;\
  1099. }\
  1100. } else {\
  1101. PyThreadState* tstate = __Pyx_PyThreadState_Current;\
  1102. if (unlikely(tstate->use_tracing && tstate->c_tracefunc && __pyx_frame->f_trace)) {\
  1103. int ret = __Pyx_call_line_trace_func(tstate, __pyx_frame, lineno);\
  1104. if (unlikely(ret)) goto_error;\
  1105. }\
  1106. }\
  1107. }
  1108. #else
  1109. #define __Pyx_TraceLine(lineno, nogil, goto_error)\
  1110. if (likely(!__Pyx_use_tracing)); else {\
  1111. PyThreadState* tstate = __Pyx_PyThreadState_Current;\
  1112. if (unlikely(tstate->use_tracing && tstate->c_tracefunc && __pyx_frame->f_trace)) {\
  1113. int ret = __Pyx_call_line_trace_func(tstate, __pyx_frame, lineno);\
  1114. if (unlikely(ret)) goto_error;\
  1115. }\
  1116. }
  1117. #endif
  1118. #else
  1119. #define __Pyx_TraceLine(lineno, nogil, goto_error) if ((1)); else goto_error;
  1120. #endif
  1121. /* PyCFunctionFastCall.proto */
  1122. #if CYTHON_FAST_PYCCALL
  1123. static CYTHON_INLINE PyObject *__Pyx_PyCFunction_FastCall(PyObject *func, PyObject **args, Py_ssize_t nargs);
  1124. #else
  1125. #define __Pyx_PyCFunction_FastCall(func, args, nargs) (assert(0), NULL)
  1126. #endif
  1127. /* PyFunctionFastCall.proto */
  1128. #if CYTHON_FAST_PYCALL
  1129. #define __Pyx_PyFunction_FastCall(func, args, nargs)\
  1130. __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL)
  1131. #if 1 || PY_VERSION_HEX < 0x030600B1
  1132. static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwargs);
  1133. #else
  1134. #define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs)
  1135. #endif
  1136. #endif
  1137. /* PyObjectCall.proto */
  1138. #if CYTHON_COMPILING_IN_CPYTHON
  1139. static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw);
  1140. #else
  1141. #define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw)
  1142. #endif
  1143. /* PyObjectCallMethO.proto */
  1144. #if CYTHON_COMPILING_IN_CPYTHON
  1145. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg);
  1146. #endif
  1147. /* PyObjectCallOneArg.proto */
  1148. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg);
  1149. /* PyObjectCallNoArg.proto */
  1150. #if CYTHON_COMPILING_IN_CPYTHON
  1151. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func);
  1152. #else
  1153. #define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL)
  1154. #endif
  1155. /* GetModuleGlobalName.proto */
  1156. static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name);
  1157. /* GetAttr.proto */
  1158. static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *, PyObject *);
  1159. /* PyObjectFormatSimple.proto */
  1160. #if CYTHON_COMPILING_IN_PYPY
  1161. #define __Pyx_PyObject_FormatSimple(s, f) (\
  1162. likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\
  1163. PyObject_Format(s, f))
  1164. #elif PY_MAJOR_VERSION < 3
  1165. #define __Pyx_PyObject_FormatSimple(s, f) (\
  1166. likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\
  1167. likely(PyString_CheckExact(s)) ? PyUnicode_FromEncodedObject(s, NULL, "strict") :\
  1168. PyObject_Format(s, f))
  1169. #elif CYTHON_USE_TYPE_SLOTS
  1170. #define __Pyx_PyObject_FormatSimple(s, f) (\
  1171. likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\
  1172. likely(PyLong_CheckExact(s)) ? PyLong_Type.tp_str(s) :\
  1173. likely(PyFloat_CheckExact(s)) ? PyFloat_Type.tp_str(s) :\
  1174. PyObject_Format(s, f))
  1175. #else
  1176. #define __Pyx_PyObject_FormatSimple(s, f) (\
  1177. likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\
  1178. PyObject_Format(s, f))
  1179. #endif
  1180. /* RaiseException.proto */
  1181. static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause);
  1182. /* IncludeStringH.proto */
  1183. #include <string.h>
  1184. /* BytesEquals.proto */
  1185. static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals);
  1186. /* decode_c_string_utf16.proto */
  1187. static CYTHON_INLINE PyObject *__Pyx_PyUnicode_DecodeUTF16(const char *s, Py_ssize_t size, const char *errors) {
  1188. int byteorder = 0;
  1189. return PyUnicode_DecodeUTF16(s, size, errors, &byteorder);
  1190. }
  1191. static CYTHON_INLINE PyObject *__Pyx_PyUnicode_DecodeUTF16LE(const char *s, Py_ssize_t size, const char *errors) {
  1192. int byteorder = -1;
  1193. return PyUnicode_DecodeUTF16(s, size, errors, &byteorder);
  1194. }
  1195. static CYTHON_INLINE PyObject *__Pyx_PyUnicode_DecodeUTF16BE(const char *s, Py_ssize_t size, const char *errors) {
  1196. int byteorder = 1;
  1197. return PyUnicode_DecodeUTF16(s, size, errors, &byteorder);
  1198. }
  1199. /* decode_c_string.proto */
  1200. static CYTHON_INLINE PyObject* __Pyx_decode_c_string(
  1201. const char* cstring, Py_ssize_t start, Py_ssize_t stop,
  1202. const char* encoding, const char* errors,
  1203. PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors));
  1204. /* BuildPyUnicode.proto */
  1205. static PyObject* __Pyx_PyUnicode_BuildFromAscii(Py_ssize_t ulength, char* chars, int clength,
  1206. int prepend_sign, char padding_char);
  1207. /* CIntToPyUnicode.proto */
  1208. static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_char(char value, Py_ssize_t width, char padding_char, char format_char);
  1209. /* GetException.proto */
  1210. #if CYTHON_FAST_THREAD_STATE
  1211. #define __Pyx_GetException(type, value, tb) __Pyx__GetException(__pyx_tstate, type, value, tb)
  1212. static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
  1213. #else
  1214. static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb);
  1215. #endif
  1216. /* SwapException.proto */
  1217. #if CYTHON_FAST_THREAD_STATE
  1218. #define __Pyx_ExceptionSwap(type, value, tb) __Pyx__ExceptionSwap(__pyx_tstate, type, value, tb)
  1219. static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
  1220. #else
  1221. static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb);
  1222. #endif
  1223. /* SaveResetException.proto */
  1224. #if CYTHON_FAST_THREAD_STATE
  1225. #define __Pyx_ExceptionSave(type, value, tb) __Pyx__ExceptionSave(__pyx_tstate, type, value, tb)
  1226. static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
  1227. #define __Pyx_ExceptionReset(type, value, tb) __Pyx__ExceptionReset(__pyx_tstate, type, value, tb)
  1228. static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
  1229. #else
  1230. #define __Pyx_ExceptionSave(type, value, tb) PyErr_GetExcInfo(type, value, tb)
  1231. #define __Pyx_ExceptionReset(type, value, tb) PyErr_SetExcInfo(type, value, tb)
  1232. #endif
  1233. /* Import.proto */
  1234. static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level);
  1235. /* ImportFrom.proto */
  1236. static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name);
  1237. /* CLineInTraceback.proto */
  1238. #ifdef CYTHON_CLINE_IN_TRACEBACK
  1239. #define __Pyx_CLineForTraceback(tstate, c_line) (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0)
  1240. #else
  1241. static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line);
  1242. #endif
  1243. /* CodeObjectCache.proto */
  1244. typedef struct {
  1245. PyCodeObject* code_object;
  1246. int code_line;
  1247. } __Pyx_CodeObjectCacheEntry;
  1248. struct __Pyx_CodeObjectCache {
  1249. int count;
  1250. int max_count;
  1251. __Pyx_CodeObjectCacheEntry* entries;
  1252. };
  1253. static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL};
  1254. static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
  1255. static PyCodeObject *__pyx_find_code_object(int code_line);
  1256. static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);
  1257. /* AddTraceback.proto */
  1258. static void __Pyx_AddTraceback(const char *funcname, int c_line,
  1259. int py_line, const char *filename);
  1260. /* CIntToPy.proto */
  1261. static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);
  1262. /* CIntFromPy.proto */
  1263. static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);
  1264. /* CIntFromPy.proto */
  1265. static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);
  1266. /* FastTypeChecks.proto */
  1267. #if CYTHON_COMPILING_IN_CPYTHON
  1268. #define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type)
  1269. static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b);
  1270. static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type);
  1271. static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2);
  1272. #else
  1273. #define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
  1274. #define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type)
  1275. #define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2))
  1276. #endif
  1277. #define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception)
  1278. /* CheckBinaryVersion.proto */
  1279. static int __Pyx_check_binary_version(void);
  1280. /* PyObjectSetAttrStr.proto */
  1281. #if CYTHON_USE_TYPE_SLOTS
  1282. #define __Pyx_PyObject_DelAttrStr(o,n) __Pyx_PyObject_SetAttrStr(o, n, NULL)
  1283. static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value);
  1284. #else
  1285. #define __Pyx_PyObject_DelAttrStr(o,n) PyObject_DelAttr(o,n)
  1286. #define __Pyx_PyObject_SetAttrStr(o,n,v) PyObject_SetAttr(o,n,v)
  1287. #endif
  1288. /* VoidPtrExport.proto */
  1289. static int __Pyx_ExportVoidPtr(PyObject *name, void *p, const char *sig);
  1290. /* FunctionExport.proto */
  1291. static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig);
  1292. /* PyIdentifierFromString.proto */
  1293. #if !defined(__Pyx_PyIdentifier_FromString)
  1294. #if PY_MAJOR_VERSION < 3
  1295. #define __Pyx_PyIdentifier_FromString(s) PyString_FromString(s)
  1296. #else
  1297. #define __Pyx_PyIdentifier_FromString(s) PyUnicode_FromString(s)
  1298. #endif
  1299. #endif
  1300. /* ModuleImport.proto */
  1301. static PyObject *__Pyx_ImportModule(const char *name);
  1302. /* TypeImport.proto */
  1303. static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, size_t size, int strict);
  1304. /* InitStrings.proto */
  1305. static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);
  1306. /* Module declarations from 'libc.string' */
  1307. /* Module declarations from 'libc.stdlib' */
  1308. /* Module declarations from 'lakesuperior.cy_include' */
  1309. /* Module declarations from 'libc.stdio' */
  1310. /* Module declarations from '__builtin__' */
  1311. /* Module declarations from 'cpython.type' */
  1312. static PyTypeObject *__pyx_ptype_7cpython_4type_type = 0;
  1313. /* Module declarations from 'cpython' */
  1314. /* Module declarations from 'cpython.object' */
  1315. /* Module declarations from 'cpython.string' */
  1316. /* Module declarations from 'libc.stdint' */
  1317. /* Module declarations from 'lakesuperior.cy_include.cytpl' */
  1318. /* Module declarations from 'lakesuperior.store.ldp_rs.term' */
  1319. static unsigned char __pyx_v_12lakesuperior_5store_6ldp_rs_4term_term_type;
  1320. static unsigned char *__pyx_v_12lakesuperior_5store_6ldp_rs_4term_pack_fmt;
  1321. static unsigned char *__pyx_v_12lakesuperior_5store_6ldp_rs_4term_term_data;
  1322. static unsigned char *__pyx_v_12lakesuperior_5store_6ldp_rs_4term_term_datatype;
  1323. static unsigned char *__pyx_v_12lakesuperior_5store_6ldp_rs_4term_term_lang;
  1324. #define __Pyx_MODULE_NAME "lakesuperior.store.ldp_rs.term"
  1325. extern int __pyx_module_is_main_lakesuperior__store__ldp_rs__term;
  1326. int __pyx_module_is_main_lakesuperior__store__ldp_rs__term = 0;
  1327. /* Implementation of 'lakesuperior.store.ldp_rs.term' */
  1328. static PyObject *__pyx_builtin_ValueError;
  1329. static PyObject *__pyx_builtin_IOError;
  1330. static const char __pyx_k_[] = "";
  1331. static const char __pyx_k_S_cs[] = "S(cs)";
  1332. static const char __pyx_k_lang[] = "lang";
  1333. static const char __pyx_k_main[] = "__main__";
  1334. static const char __pyx_k_test[] = "__test__";
  1335. static const char __pyx_k_BNode[] = "BNode";
  1336. static const char __pyx_k_S_csss[] = "S(csss)";
  1337. static const char __pyx_k_URIRef[] = "URIRef";
  1338. static const char __pyx_k_encode[] = "encode";
  1339. static const char __pyx_k_import[] = "__import__";
  1340. static const char __pyx_k_rdflib[] = "rdflib";
  1341. static const char __pyx_k_IOError[] = "IOError";
  1342. static const char __pyx_k_Literal[] = "Literal";
  1343. static const char __pyx_k_datatype[] = "datatype";
  1344. static const char __pyx_k_language[] = "language";
  1345. static const char __pyx_k_pack_fmt[] = "pack_fmt";
  1346. static const char __pyx_k_pyx_capi[] = "__pyx_capi__";
  1347. static const char __pyx_k_term_data[] = "term_data";
  1348. static const char __pyx_k_term_lang[] = "term_lang";
  1349. static const char __pyx_k_term_type[] = "term_type";
  1350. static const char __pyx_k_ValueError[] = "ValueError";
  1351. static const char __pyx_k_term_datatype[] = "term_datatype";
  1352. static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback";
  1353. static const char __pyx_k_Unsupported_term_type[] = "Unsupported term type: ";
  1354. static const char __pyx_k_Unknown_term_type_code[] = "Unknown term type code: ";
  1355. static const char __pyx_k_Unknown_structure_pack_format[] = "Unknown structure pack format: ";
  1356. static PyObject *__pyx_kp_u_;
  1357. static PyObject *__pyx_n_s_BNode;
  1358. static PyObject *__pyx_n_s_IOError;
  1359. static PyObject *__pyx_n_s_Literal;
  1360. static PyObject *__pyx_kp_b_S_cs;
  1361. static PyObject *__pyx_kp_b_S_csss;
  1362. static PyObject *__pyx_n_s_URIRef;
  1363. static PyObject *__pyx_kp_u_Unknown_structure_pack_format;
  1364. static PyObject *__pyx_kp_u_Unknown_term_type_code;
  1365. static PyObject *__pyx_kp_u_Unsupported_term_type;
  1366. static PyObject *__pyx_n_s_ValueError;
  1367. static PyObject *__pyx_n_s_cline_in_traceback;
  1368. static PyObject *__pyx_n_s_datatype;
  1369. static PyObject *__pyx_n_u_datatype;
  1370. static PyObject *__pyx_n_s_encode;
  1371. static PyObject *__pyx_n_s_import;
  1372. static PyObject *__pyx_n_s_lang;
  1373. static PyObject *__pyx_n_u_language;
  1374. static PyObject *__pyx_n_s_main;
  1375. static PyObject *__pyx_n_s_pack_fmt;
  1376. static PyObject *__pyx_n_s_pyx_capi;
  1377. static PyObject *__pyx_n_s_rdflib;
  1378. static PyObject *__pyx_n_s_term_data;
  1379. static PyObject *__pyx_n_s_term_datatype;
  1380. static PyObject *__pyx_n_s_term_lang;
  1381. static PyObject *__pyx_n_s_term_type;
  1382. static PyObject *__pyx_n_s_test;
  1383. /* Late includes */
  1384. /* "lakesuperior/store/ldp_rs/term.pyx":16
  1385. *
  1386. *
  1387. * cdef int serialize( # <<<<<<<<<<<<<<
  1388. * term, unsigned char **pack_data, size_t *pack_size) except -1:
  1389. * cdef:
  1390. */
  1391. static int __pyx_f_12lakesuperior_5store_6ldp_rs_4term_serialize(PyObject *__pyx_v_term, unsigned char **__pyx_v_pack_data, size_t *__pyx_v_pack_size) {
  1392. PyObject *__pyx_v_term_data = 0;
  1393. PyObject *__pyx_v_term_datatype = 0;
  1394. PyObject *__pyx_v_term_lang = 0;
  1395. struct __pyx_t_12lakesuperior_5store_6ldp_rs_4term_IdentifierTerm __pyx_v_id_t;
  1396. struct __pyx_t_12lakesuperior_5store_6ldp_rs_4term_LiteralTerm __pyx_v_lit_t;
  1397. int __pyx_r;
  1398. __Pyx_TraceDeclarations
  1399. __Pyx_RefNannyDeclarations
  1400. PyObject *__pyx_t_1 = NULL;
  1401. PyObject *__pyx_t_2 = NULL;
  1402. PyObject *__pyx_t_3 = NULL;
  1403. int __pyx_t_4;
  1404. int __pyx_t_5;
  1405. unsigned char *__pyx_t_6;
  1406. __Pyx_RefNannySetupContext("serialize", 0);
  1407. __Pyx_TraceCall("serialize", __pyx_f[0], 16, 0, __PYX_ERR(0, 16, __pyx_L1_error));
  1408. /* "lakesuperior/store/ldp_rs/term.pyx":19
  1409. * term, unsigned char **pack_data, size_t *pack_size) except -1:
  1410. * cdef:
  1411. * bytes term_data = term.encode() # <<<<<<<<<<<<<<
  1412. * bytes term_datatype
  1413. * bytes term_lang
  1414. */
  1415. __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_term, __pyx_n_s_encode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 19, __pyx_L1_error)
  1416. __Pyx_GOTREF(__pyx_t_2);
  1417. __pyx_t_3 = NULL;
  1418. if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
  1419. __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
  1420. if (likely(__pyx_t_3)) {
  1421. PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
  1422. __Pyx_INCREF(__pyx_t_3);
  1423. __Pyx_INCREF(function);
  1424. __Pyx_DECREF_SET(__pyx_t_2, function);
  1425. }
  1426. }
  1427. if (__pyx_t_3) {
  1428. __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 19, __pyx_L1_error)
  1429. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  1430. } else {
  1431. __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 19, __pyx_L1_error)
  1432. }
  1433. __Pyx_GOTREF(__pyx_t_1);
  1434. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  1435. if (!(likely(PyBytes_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 19, __pyx_L1_error)
  1436. __pyx_v_term_data = ((PyObject*)__pyx_t_1);
  1437. __pyx_t_1 = 0;
  1438. /* "lakesuperior/store/ldp_rs/term.pyx":25
  1439. * LiteralTerm lit_t
  1440. *
  1441. * if isinstance(term, Literal): # <<<<<<<<<<<<<<
  1442. * term_datatype = (getattr(term, 'datatype') or '').encode()
  1443. * term_lang = (getattr(term, 'language') or '').encode()
  1444. */
  1445. __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_Literal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 25, __pyx_L1_error)
  1446. __Pyx_GOTREF(__pyx_t_1);
  1447. __pyx_t_4 = PyObject_IsInstance(__pyx_v_term, __pyx_t_1); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 25, __pyx_L1_error)
  1448. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  1449. __pyx_t_5 = (__pyx_t_4 != 0);
  1450. if (__pyx_t_5) {
  1451. /* "lakesuperior/store/ldp_rs/term.pyx":26
  1452. *
  1453. * if isinstance(term, Literal):
  1454. * term_datatype = (getattr(term, 'datatype') or '').encode() # <<<<<<<<<<<<<<
  1455. * term_lang = (getattr(term, 'language') or '').encode()
  1456. *
  1457. */
  1458. __pyx_t_3 = __Pyx_GetAttr(__pyx_v_term, __pyx_n_u_datatype); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 26, __pyx_L1_error)
  1459. __Pyx_GOTREF(__pyx_t_3);
  1460. __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 26, __pyx_L1_error)
  1461. if (!__pyx_t_5) {
  1462. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  1463. } else {
  1464. __Pyx_INCREF(__pyx_t_3);
  1465. __pyx_t_2 = __pyx_t_3;
  1466. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  1467. goto __pyx_L4_bool_binop_done;
  1468. }
  1469. __Pyx_INCREF(__pyx_kp_u_);
  1470. __pyx_t_2 = __pyx_kp_u_;
  1471. __pyx_L4_bool_binop_done:;
  1472. __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_encode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 26, __pyx_L1_error)
  1473. __Pyx_GOTREF(__pyx_t_3);
  1474. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  1475. __pyx_t_2 = NULL;
  1476. if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
  1477. __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
  1478. if (likely(__pyx_t_2)) {
  1479. PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
  1480. __Pyx_INCREF(__pyx_t_2);
  1481. __Pyx_INCREF(function);
  1482. __Pyx_DECREF_SET(__pyx_t_3, function);
  1483. }
  1484. }
  1485. if (__pyx_t_2) {
  1486. __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 26, __pyx_L1_error)
  1487. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  1488. } else {
  1489. __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 26, __pyx_L1_error)
  1490. }
  1491. __Pyx_GOTREF(__pyx_t_1);
  1492. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  1493. if (!(likely(PyBytes_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 26, __pyx_L1_error)
  1494. __pyx_v_term_datatype = ((PyObject*)__pyx_t_1);
  1495. __pyx_t_1 = 0;
  1496. /* "lakesuperior/store/ldp_rs/term.pyx":27
  1497. * if isinstance(term, Literal):
  1498. * term_datatype = (getattr(term, 'datatype') or '').encode()
  1499. * term_lang = (getattr(term, 'language') or '').encode() # <<<<<<<<<<<<<<
  1500. *
  1501. * lit_t.type = LSUP_TERM_TYPE_LITERAL
  1502. */
  1503. __pyx_t_2 = __Pyx_GetAttr(__pyx_v_term, __pyx_n_u_language); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 27, __pyx_L1_error)
  1504. __Pyx_GOTREF(__pyx_t_2);
  1505. __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 27, __pyx_L1_error)
  1506. if (!__pyx_t_5) {
  1507. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  1508. } else {
  1509. __Pyx_INCREF(__pyx_t_2);
  1510. __pyx_t_3 = __pyx_t_2;
  1511. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  1512. goto __pyx_L6_bool_binop_done;
  1513. }
  1514. __Pyx_INCREF(__pyx_kp_u_);
  1515. __pyx_t_3 = __pyx_kp_u_;
  1516. __pyx_L6_bool_binop_done:;
  1517. __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_encode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 27, __pyx_L1_error)
  1518. __Pyx_GOTREF(__pyx_t_2);
  1519. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  1520. __pyx_t_3 = NULL;
  1521. if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
  1522. __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
  1523. if (likely(__pyx_t_3)) {
  1524. PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
  1525. __Pyx_INCREF(__pyx_t_3);
  1526. __Pyx_INCREF(function);
  1527. __Pyx_DECREF_SET(__pyx_t_2, function);
  1528. }
  1529. }
  1530. if (__pyx_t_3) {
  1531. __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 27, __pyx_L1_error)
  1532. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  1533. } else {
  1534. __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 27, __pyx_L1_error)
  1535. }
  1536. __Pyx_GOTREF(__pyx_t_1);
  1537. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  1538. if (!(likely(PyBytes_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 27, __pyx_L1_error)
  1539. __pyx_v_term_lang = ((PyObject*)__pyx_t_1);
  1540. __pyx_t_1 = 0;
  1541. /* "lakesuperior/store/ldp_rs/term.pyx":29
  1542. * term_lang = (getattr(term, 'language') or '').encode()
  1543. *
  1544. * lit_t.type = LSUP_TERM_TYPE_LITERAL # <<<<<<<<<<<<<<
  1545. * lit_t.data = term_data
  1546. * lit_t.datatype = <unsigned char *>term_datatype
  1547. */
  1548. __pyx_v_lit_t.type = 3;
  1549. /* "lakesuperior/store/ldp_rs/term.pyx":30
  1550. *
  1551. * lit_t.type = LSUP_TERM_TYPE_LITERAL
  1552. * lit_t.data = term_data # <<<<<<<<<<<<<<
  1553. * lit_t.datatype = <unsigned char *>term_datatype
  1554. * lit_t.lang = <unsigned char *>term_lang
  1555. */
  1556. if (unlikely(__pyx_v_term_data == Py_None)) {
  1557. PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found");
  1558. __PYX_ERR(0, 30, __pyx_L1_error)
  1559. }
  1560. __pyx_t_6 = __Pyx_PyBytes_AsWritableUString(__pyx_v_term_data); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(0, 30, __pyx_L1_error)
  1561. __pyx_v_lit_t.data = __pyx_t_6;
  1562. /* "lakesuperior/store/ldp_rs/term.pyx":31
  1563. * lit_t.type = LSUP_TERM_TYPE_LITERAL
  1564. * lit_t.data = term_data
  1565. * lit_t.datatype = <unsigned char *>term_datatype # <<<<<<<<<<<<<<
  1566. * lit_t.lang = <unsigned char *>term_lang
  1567. *
  1568. */
  1569. if (unlikely(__pyx_v_term_datatype == Py_None)) {
  1570. PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found");
  1571. __PYX_ERR(0, 31, __pyx_L1_error)
  1572. }
  1573. __pyx_t_6 = __Pyx_PyBytes_AsWritableUString(__pyx_v_term_datatype); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(0, 31, __pyx_L1_error)
  1574. __pyx_v_lit_t.datatype = ((unsigned char *)__pyx_t_6);
  1575. /* "lakesuperior/store/ldp_rs/term.pyx":32
  1576. * lit_t.data = term_data
  1577. * lit_t.datatype = <unsigned char *>term_datatype
  1578. * lit_t.lang = <unsigned char *>term_lang # <<<<<<<<<<<<<<
  1579. *
  1580. * tpl.tpl_jot(tpl.TPL_MEM, pack_data, pack_size, LSUP_PK_FMT_LIT, &lit_t)
  1581. */
  1582. if (unlikely(__pyx_v_term_lang == Py_None)) {
  1583. PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found");
  1584. __PYX_ERR(0, 32, __pyx_L1_error)
  1585. }
  1586. __pyx_t_6 = __Pyx_PyBytes_AsWritableUString(__pyx_v_term_lang); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(0, 32, __pyx_L1_error)
  1587. __pyx_v_lit_t.lang = ((unsigned char *)__pyx_t_6);
  1588. /* "lakesuperior/store/ldp_rs/term.pyx":34
  1589. * lit_t.lang = <unsigned char *>term_lang
  1590. *
  1591. * tpl.tpl_jot(tpl.TPL_MEM, pack_data, pack_size, LSUP_PK_FMT_LIT, &lit_t) # <<<<<<<<<<<<<<
  1592. * else:
  1593. * if isinstance(term, URIRef):
  1594. */
  1595. (void)(tpl_jot(TPL_MEM, __pyx_v_pack_data, __pyx_v_pack_size, ((char *)"S(csss)"), (&__pyx_v_lit_t)));
  1596. /* "lakesuperior/store/ldp_rs/term.pyx":25
  1597. * LiteralTerm lit_t
  1598. *
  1599. * if isinstance(term, Literal): # <<<<<<<<<<<<<<
  1600. * term_datatype = (getattr(term, 'datatype') or '').encode()
  1601. * term_lang = (getattr(term, 'language') or '').encode()
  1602. */
  1603. goto __pyx_L3;
  1604. }
  1605. /* "lakesuperior/store/ldp_rs/term.pyx":36
  1606. * tpl.tpl_jot(tpl.TPL_MEM, pack_data, pack_size, LSUP_PK_FMT_LIT, &lit_t)
  1607. * else:
  1608. * if isinstance(term, URIRef): # <<<<<<<<<<<<<<
  1609. * id_t.type = LSUP_TERM_TYPE_URIREF
  1610. * elif isinstance(term, BNode):
  1611. */
  1612. /*else*/ {
  1613. __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_URIRef); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 36, __pyx_L1_error)
  1614. __Pyx_GOTREF(__pyx_t_1);
  1615. __pyx_t_5 = PyObject_IsInstance(__pyx_v_term, __pyx_t_1); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(0, 36, __pyx_L1_error)
  1616. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  1617. __pyx_t_4 = (__pyx_t_5 != 0);
  1618. if (__pyx_t_4) {
  1619. /* "lakesuperior/store/ldp_rs/term.pyx":37
  1620. * else:
  1621. * if isinstance(term, URIRef):
  1622. * id_t.type = LSUP_TERM_TYPE_URIREF # <<<<<<<<<<<<<<
  1623. * elif isinstance(term, BNode):
  1624. * id_t.type = LSUP_TERM_TYPE_BNODE
  1625. */
  1626. __pyx_v_id_t.type = 1;
  1627. /* "lakesuperior/store/ldp_rs/term.pyx":36
  1628. * tpl.tpl_jot(tpl.TPL_MEM, pack_data, pack_size, LSUP_PK_FMT_LIT, &lit_t)
  1629. * else:
  1630. * if isinstance(term, URIRef): # <<<<<<<<<<<<<<
  1631. * id_t.type = LSUP_TERM_TYPE_URIREF
  1632. * elif isinstance(term, BNode):
  1633. */
  1634. goto __pyx_L8;
  1635. }
  1636. /* "lakesuperior/store/ldp_rs/term.pyx":38
  1637. * if isinstance(term, URIRef):
  1638. * id_t.type = LSUP_TERM_TYPE_URIREF
  1639. * elif isinstance(term, BNode): # <<<<<<<<<<<<<<
  1640. * id_t.type = LSUP_TERM_TYPE_BNODE
  1641. * else:
  1642. */
  1643. __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_BNode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 38, __pyx_L1_error)
  1644. __Pyx_GOTREF(__pyx_t_1);
  1645. __pyx_t_4 = PyObject_IsInstance(__pyx_v_term, __pyx_t_1); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 38, __pyx_L1_error)
  1646. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  1647. __pyx_t_5 = (__pyx_t_4 != 0);
  1648. if (likely(__pyx_t_5)) {
  1649. /* "lakesuperior/store/ldp_rs/term.pyx":39
  1650. * id_t.type = LSUP_TERM_TYPE_URIREF
  1651. * elif isinstance(term, BNode):
  1652. * id_t.type = LSUP_TERM_TYPE_BNODE # <<<<<<<<<<<<<<
  1653. * else:
  1654. * raise ValueError(f'Unsupported term type: {type(term)}')
  1655. */
  1656. __pyx_v_id_t.type = 2;
  1657. /* "lakesuperior/store/ldp_rs/term.pyx":38
  1658. * if isinstance(term, URIRef):
  1659. * id_t.type = LSUP_TERM_TYPE_URIREF
  1660. * elif isinstance(term, BNode): # <<<<<<<<<<<<<<
  1661. * id_t.type = LSUP_TERM_TYPE_BNODE
  1662. * else:
  1663. */
  1664. goto __pyx_L8;
  1665. }
  1666. /* "lakesuperior/store/ldp_rs/term.pyx":41
  1667. * id_t.type = LSUP_TERM_TYPE_BNODE
  1668. * else:
  1669. * raise ValueError(f'Unsupported term type: {type(term)}') # <<<<<<<<<<<<<<
  1670. * id_t.data = term_data
  1671. * tpl.tpl_jot(tpl.TPL_MEM, pack_data, pack_size, LSUP_PK_FMT_ID, &id_t)
  1672. */
  1673. /*else*/ {
  1674. __pyx_t_1 = __Pyx_PyObject_FormatSimple(((PyObject *)Py_TYPE(__pyx_v_term)), __pyx_empty_unicode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 41, __pyx_L1_error)
  1675. __Pyx_GOTREF(__pyx_t_1);
  1676. __pyx_t_2 = __Pyx_PyUnicode_Concat(__pyx_kp_u_Unsupported_term_type, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 41, __pyx_L1_error)
  1677. __Pyx_GOTREF(__pyx_t_2);
  1678. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  1679. __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 41, __pyx_L1_error)
  1680. __Pyx_GOTREF(__pyx_t_1);
  1681. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  1682. __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  1683. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  1684. __PYX_ERR(0, 41, __pyx_L1_error)
  1685. }
  1686. __pyx_L8:;
  1687. /* "lakesuperior/store/ldp_rs/term.pyx":42
  1688. * else:
  1689. * raise ValueError(f'Unsupported term type: {type(term)}')
  1690. * id_t.data = term_data # <<<<<<<<<<<<<<
  1691. * tpl.tpl_jot(tpl.TPL_MEM, pack_data, pack_size, LSUP_PK_FMT_ID, &id_t)
  1692. *
  1693. */
  1694. if (unlikely(__pyx_v_term_data == Py_None)) {
  1695. PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found");
  1696. __PYX_ERR(0, 42, __pyx_L1_error)
  1697. }
  1698. __pyx_t_6 = __Pyx_PyBytes_AsWritableUString(__pyx_v_term_data); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(0, 42, __pyx_L1_error)
  1699. __pyx_v_id_t.data = __pyx_t_6;
  1700. /* "lakesuperior/store/ldp_rs/term.pyx":43
  1701. * raise ValueError(f'Unsupported term type: {type(term)}')
  1702. * id_t.data = term_data
  1703. * tpl.tpl_jot(tpl.TPL_MEM, pack_data, pack_size, LSUP_PK_FMT_ID, &id_t) # <<<<<<<<<<<<<<
  1704. *
  1705. *
  1706. */
  1707. (void)(tpl_jot(TPL_MEM, __pyx_v_pack_data, __pyx_v_pack_size, ((char *)"S(cs)"), (&__pyx_v_id_t)));
  1708. }
  1709. __pyx_L3:;
  1710. /* "lakesuperior/store/ldp_rs/term.pyx":16
  1711. *
  1712. *
  1713. * cdef int serialize( # <<<<<<<<<<<<<<
  1714. * term, unsigned char **pack_data, size_t *pack_size) except -1:
  1715. * cdef:
  1716. */
  1717. /* function exit code */
  1718. __pyx_r = 0;
  1719. goto __pyx_L0;
  1720. __pyx_L1_error:;
  1721. __Pyx_XDECREF(__pyx_t_1);
  1722. __Pyx_XDECREF(__pyx_t_2);
  1723. __Pyx_XDECREF(__pyx_t_3);
  1724. __Pyx_AddTraceback("lakesuperior.store.ldp_rs.term.serialize", __pyx_clineno, __pyx_lineno, __pyx_filename);
  1725. __pyx_r = -1;
  1726. __pyx_L0:;
  1727. __Pyx_XDECREF(__pyx_v_term_data);
  1728. __Pyx_XDECREF(__pyx_v_term_datatype);
  1729. __Pyx_XDECREF(__pyx_v_term_lang);
  1730. __Pyx_TraceReturn(Py_None, 0);
  1731. __Pyx_RefNannyFinishContext();
  1732. return __pyx_r;
  1733. }
  1734. /* "lakesuperior/store/ldp_rs/term.pyx":46
  1735. *
  1736. *
  1737. * cdef deserialize(const unsigned char *data, const size_t data_size): # <<<<<<<<<<<<<<
  1738. * cdef:
  1739. * char term_type
  1740. */
  1741. static PyObject *__pyx_f_12lakesuperior_5store_6ldp_rs_4term_deserialize(unsigned char const *__pyx_v_data, size_t const __pyx_v_data_size) {
  1742. char __pyx_v_term_type;
  1743. char *__pyx_v_fmt;
  1744. char *__pyx_v__pk;
  1745. unsigned char *__pyx_v_term_data;
  1746. unsigned char *__pyx_v_term_lang;
  1747. unsigned char *__pyx_v_term_datatype;
  1748. PyObject *__pyx_v_datatype = NULL;
  1749. PyObject *__pyx_v_lang = NULL;
  1750. PyObject *__pyx_v_uri = NULL;
  1751. PyObject *__pyx_v_msg = NULL;
  1752. PyObject *__pyx_r = NULL;
  1753. __Pyx_TraceDeclarations
  1754. __Pyx_RefNannyDeclarations
  1755. PyObject *__pyx_t_1 = NULL;
  1756. int __pyx_t_2;
  1757. size_t __pyx_t_3;
  1758. PyObject *__pyx_t_4 = NULL;
  1759. PyObject *__pyx_t_5 = NULL;
  1760. PyObject *__pyx_t_6 = NULL;
  1761. int __pyx_t_7;
  1762. int __pyx_t_8;
  1763. char const *__pyx_t_9;
  1764. PyObject *__pyx_t_10 = NULL;
  1765. PyObject *__pyx_t_11 = NULL;
  1766. PyObject *__pyx_t_12 = NULL;
  1767. PyObject *__pyx_t_13 = NULL;
  1768. PyObject *__pyx_t_14 = NULL;
  1769. PyObject *__pyx_t_15 = NULL;
  1770. __Pyx_RefNannySetupContext("deserialize", 0);
  1771. __Pyx_TraceCall("deserialize", __pyx_f[0], 46, 0, __PYX_ERR(0, 46, __pyx_L1_error));
  1772. /* "lakesuperior/store/ldp_rs/term.pyx":49
  1773. * cdef:
  1774. * char term_type
  1775. * char *fmt = NULL # <<<<<<<<<<<<<<
  1776. * char *_pk = NULL
  1777. * unsigned char *term_data = NULL
  1778. */
  1779. __pyx_v_fmt = NULL;
  1780. /* "lakesuperior/store/ldp_rs/term.pyx":50
  1781. * char term_type
  1782. * char *fmt = NULL
  1783. * char *_pk = NULL # <<<<<<<<<<<<<<
  1784. * unsigned char *term_data = NULL
  1785. * unsigned char *term_lang = NULL
  1786. */
  1787. __pyx_v__pk = NULL;
  1788. /* "lakesuperior/store/ldp_rs/term.pyx":51
  1789. * char *fmt = NULL
  1790. * char *_pk = NULL
  1791. * unsigned char *term_data = NULL # <<<<<<<<<<<<<<
  1792. * unsigned char *term_lang = NULL
  1793. * unsigned char *term_datatype = NULL
  1794. */
  1795. __pyx_v_term_data = NULL;
  1796. /* "lakesuperior/store/ldp_rs/term.pyx":52
  1797. * char *_pk = NULL
  1798. * unsigned char *term_data = NULL
  1799. * unsigned char *term_lang = NULL # <<<<<<<<<<<<<<
  1800. * unsigned char *term_datatype = NULL
  1801. *
  1802. */
  1803. __pyx_v_term_lang = NULL;
  1804. /* "lakesuperior/store/ldp_rs/term.pyx":53
  1805. * unsigned char *term_data = NULL
  1806. * unsigned char *term_lang = NULL
  1807. * unsigned char *term_datatype = NULL # <<<<<<<<<<<<<<
  1808. *
  1809. * datatype = None
  1810. */
  1811. __pyx_v_term_datatype = NULL;
  1812. /* "lakesuperior/store/ldp_rs/term.pyx":55
  1813. * unsigned char *term_datatype = NULL
  1814. *
  1815. * datatype = None # <<<<<<<<<<<<<<
  1816. * lang = None
  1817. *
  1818. */
  1819. __Pyx_INCREF(Py_None);
  1820. __pyx_v_datatype = Py_None;
  1821. /* "lakesuperior/store/ldp_rs/term.pyx":56
  1822. *
  1823. * datatype = None
  1824. * lang = None # <<<<<<<<<<<<<<
  1825. *
  1826. * fmt = tpl.tpl_peek(tpl.TPL_MEM, data, data_size)
  1827. */
  1828. __Pyx_INCREF(Py_None);
  1829. __pyx_v_lang = Py_None;
  1830. /* "lakesuperior/store/ldp_rs/term.pyx":58
  1831. * lang = None
  1832. *
  1833. * fmt = tpl.tpl_peek(tpl.TPL_MEM, data, data_size) # <<<<<<<<<<<<<<
  1834. * try:
  1835. * if fmt == LSUP_PK_FMT_LIT:
  1836. */
  1837. __pyx_v_fmt = tpl_peek(TPL_MEM, __pyx_v_data, __pyx_v_data_size);
  1838. /* "lakesuperior/store/ldp_rs/term.pyx":59
  1839. *
  1840. * fmt = tpl.tpl_peek(tpl.TPL_MEM, data, data_size)
  1841. * try: # <<<<<<<<<<<<<<
  1842. * if fmt == LSUP_PK_FMT_LIT:
  1843. * _pk = tpl.tpl_peek(
  1844. */
  1845. /*try:*/ {
  1846. /* "lakesuperior/store/ldp_rs/term.pyx":60
  1847. * fmt = tpl.tpl_peek(tpl.TPL_MEM, data, data_size)
  1848. * try:
  1849. * if fmt == LSUP_PK_FMT_LIT: # <<<<<<<<<<<<<<
  1850. * _pk = tpl.tpl_peek(
  1851. * tpl.TPL_MEM | tpl.TPL_DATAPEEK, data, data_size, b'csss',
  1852. */
  1853. __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_fmt); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 60, __pyx_L4_error)
  1854. __Pyx_GOTREF(__pyx_t_1);
  1855. __pyx_t_2 = (__Pyx_PyBytes_Equals(__pyx_t_1, __pyx_kp_b_S_csss, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 60, __pyx_L4_error)
  1856. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  1857. if (__pyx_t_2) {
  1858. /* "lakesuperior/store/ldp_rs/term.pyx":61
  1859. * try:
  1860. * if fmt == LSUP_PK_FMT_LIT:
  1861. * _pk = tpl.tpl_peek( # <<<<<<<<<<<<<<
  1862. * tpl.TPL_MEM | tpl.TPL_DATAPEEK, data, data_size, b'csss',
  1863. * &term_type, &term_data, &term_datatype, &term_lang)
  1864. */
  1865. __pyx_v__pk = tpl_peek((TPL_MEM | TPL_DATAPEEK), __pyx_v_data, __pyx_v_data_size, ((char *)"csss"), (&__pyx_v_term_type), (&__pyx_v_term_data), (&__pyx_v_term_datatype), (&__pyx_v_term_lang));
  1866. /* "lakesuperior/store/ldp_rs/term.pyx":64
  1867. * tpl.TPL_MEM | tpl.TPL_DATAPEEK, data, data_size, b'csss',
  1868. * &term_type, &term_data, &term_datatype, &term_lang)
  1869. * if len(term_datatype) > 0: # <<<<<<<<<<<<<<
  1870. * datatype = term_datatype.decode()
  1871. * elif len(term_lang) > 0:
  1872. */
  1873. __pyx_t_3 = strlen(((char const *)__pyx_v_term_datatype));
  1874. __pyx_t_2 = ((__pyx_t_3 > 0) != 0);
  1875. if (__pyx_t_2) {
  1876. /* "lakesuperior/store/ldp_rs/term.pyx":65
  1877. * &term_type, &term_data, &term_datatype, &term_lang)
  1878. * if len(term_datatype) > 0:
  1879. * datatype = term_datatype.decode() # <<<<<<<<<<<<<<
  1880. * elif len(term_lang) > 0:
  1881. * lang = term_lang.decode()
  1882. */
  1883. __pyx_t_1 = __Pyx_decode_c_string(((char const *)__pyx_v_term_datatype), 0, strlen(((char const *)__pyx_v_term_datatype)), NULL, NULL, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 65, __pyx_L4_error)
  1884. __Pyx_GOTREF(__pyx_t_1);
  1885. __Pyx_DECREF_SET(__pyx_v_datatype, __pyx_t_1);
  1886. __pyx_t_1 = 0;
  1887. /* "lakesuperior/store/ldp_rs/term.pyx":64
  1888. * tpl.TPL_MEM | tpl.TPL_DATAPEEK, data, data_size, b'csss',
  1889. * &term_type, &term_data, &term_datatype, &term_lang)
  1890. * if len(term_datatype) > 0: # <<<<<<<<<<<<<<
  1891. * datatype = term_datatype.decode()
  1892. * elif len(term_lang) > 0:
  1893. */
  1894. goto __pyx_L7;
  1895. }
  1896. /* "lakesuperior/store/ldp_rs/term.pyx":66
  1897. * if len(term_datatype) > 0:
  1898. * datatype = term_datatype.decode()
  1899. * elif len(term_lang) > 0: # <<<<<<<<<<<<<<
  1900. * lang = term_lang.decode()
  1901. *
  1902. */
  1903. __pyx_t_3 = strlen(((char const *)__pyx_v_term_lang));
  1904. __pyx_t_2 = ((__pyx_t_3 > 0) != 0);
  1905. if (__pyx_t_2) {
  1906. /* "lakesuperior/store/ldp_rs/term.pyx":67
  1907. * datatype = term_datatype.decode()
  1908. * elif len(term_lang) > 0:
  1909. * lang = term_lang.decode() # <<<<<<<<<<<<<<
  1910. *
  1911. * return Literal(term_data.decode(), datatype=datatype, lang=lang)
  1912. */
  1913. __pyx_t_1 = __Pyx_decode_c_string(((char const *)__pyx_v_term_lang), 0, strlen(((char const *)__pyx_v_term_lang)), NULL, NULL, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 67, __pyx_L4_error)
  1914. __Pyx_GOTREF(__pyx_t_1);
  1915. __Pyx_DECREF_SET(__pyx_v_lang, __pyx_t_1);
  1916. __pyx_t_1 = 0;
  1917. /* "lakesuperior/store/ldp_rs/term.pyx":66
  1918. * if len(term_datatype) > 0:
  1919. * datatype = term_datatype.decode()
  1920. * elif len(term_lang) > 0: # <<<<<<<<<<<<<<
  1921. * lang = term_lang.decode()
  1922. *
  1923. */
  1924. }
  1925. __pyx_L7:;
  1926. /* "lakesuperior/store/ldp_rs/term.pyx":69
  1927. * lang = term_lang.decode()
  1928. *
  1929. * return Literal(term_data.decode(), datatype=datatype, lang=lang) # <<<<<<<<<<<<<<
  1930. *
  1931. * elif fmt == LSUP_PK_FMT_ID:
  1932. */
  1933. __Pyx_XDECREF(__pyx_r);
  1934. __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_Literal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 69, __pyx_L4_error)
  1935. __Pyx_GOTREF(__pyx_t_1);
  1936. __pyx_t_4 = __Pyx_decode_c_string(((char const *)__pyx_v_term_data), 0, strlen(((char const *)__pyx_v_term_data)), NULL, NULL, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 69, __pyx_L4_error)
  1937. __Pyx_GOTREF(__pyx_t_4);
  1938. __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 69, __pyx_L4_error)
  1939. __Pyx_GOTREF(__pyx_t_5);
  1940. __Pyx_GIVEREF(__pyx_t_4);
  1941. PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
  1942. __pyx_t_4 = 0;
  1943. __pyx_t_4 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 69, __pyx_L4_error)
  1944. __Pyx_GOTREF(__pyx_t_4);
  1945. if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_datatype, __pyx_v_datatype) < 0) __PYX_ERR(0, 69, __pyx_L4_error)
  1946. if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_lang, __pyx_v_lang) < 0) __PYX_ERR(0, 69, __pyx_L4_error)
  1947. __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 69, __pyx_L4_error)
  1948. __Pyx_GOTREF(__pyx_t_6);
  1949. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  1950. __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  1951. __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  1952. __pyx_r = __pyx_t_6;
  1953. __pyx_t_6 = 0;
  1954. goto __pyx_L3_return;
  1955. /* "lakesuperior/store/ldp_rs/term.pyx":60
  1956. * fmt = tpl.tpl_peek(tpl.TPL_MEM, data, data_size)
  1957. * try:
  1958. * if fmt == LSUP_PK_FMT_LIT: # <<<<<<<<<<<<<<
  1959. * _pk = tpl.tpl_peek(
  1960. * tpl.TPL_MEM | tpl.TPL_DATAPEEK, data, data_size, b'csss',
  1961. */
  1962. }
  1963. /* "lakesuperior/store/ldp_rs/term.pyx":71
  1964. * return Literal(term_data.decode(), datatype=datatype, lang=lang)
  1965. *
  1966. * elif fmt == LSUP_PK_FMT_ID: # <<<<<<<<<<<<<<
  1967. * _pk = tpl.tpl_peek(
  1968. * tpl.TPL_MEM | tpl.TPL_DATAPEEK, data, data_size, b'cs',
  1969. */
  1970. __pyx_t_6 = __Pyx_PyBytes_FromString(__pyx_v_fmt); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 71, __pyx_L4_error)
  1971. __Pyx_GOTREF(__pyx_t_6);
  1972. __pyx_t_2 = (__Pyx_PyBytes_Equals(__pyx_t_6, __pyx_kp_b_S_cs, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 71, __pyx_L4_error)
  1973. __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  1974. if (likely(__pyx_t_2)) {
  1975. /* "lakesuperior/store/ldp_rs/term.pyx":72
  1976. *
  1977. * elif fmt == LSUP_PK_FMT_ID:
  1978. * _pk = tpl.tpl_peek( # <<<<<<<<<<<<<<
  1979. * tpl.TPL_MEM | tpl.TPL_DATAPEEK, data, data_size, b'cs',
  1980. * &term_type, &term_data)
  1981. */
  1982. __pyx_v__pk = tpl_peek((TPL_MEM | TPL_DATAPEEK), __pyx_v_data, __pyx_v_data_size, ((char *)"cs"), (&__pyx_v_term_type), (&__pyx_v_term_data));
  1983. /* "lakesuperior/store/ldp_rs/term.pyx":75
  1984. * tpl.TPL_MEM | tpl.TPL_DATAPEEK, data, data_size, b'cs',
  1985. * &term_type, &term_data)
  1986. * uri = term_data.decode() # <<<<<<<<<<<<<<
  1987. * if term_type == LSUP_TERM_TYPE_URIREF:
  1988. * return URIRef(uri)
  1989. */
  1990. __pyx_t_6 = __Pyx_decode_c_string(((char const *)__pyx_v_term_data), 0, strlen(((char const *)__pyx_v_term_data)), NULL, NULL, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 75, __pyx_L4_error)
  1991. __Pyx_GOTREF(__pyx_t_6);
  1992. __pyx_v_uri = __pyx_t_6;
  1993. __pyx_t_6 = 0;
  1994. /* "lakesuperior/store/ldp_rs/term.pyx":76
  1995. * &term_type, &term_data)
  1996. * uri = term_data.decode()
  1997. * if term_type == LSUP_TERM_TYPE_URIREF: # <<<<<<<<<<<<<<
  1998. * return URIRef(uri)
  1999. * elif term_type == LSUP_TERM_TYPE_BNODE:
  2000. */
  2001. switch (__pyx_v_term_type) {
  2002. case 1:
  2003. /* "lakesuperior/store/ldp_rs/term.pyx":77
  2004. * uri = term_data.decode()
  2005. * if term_type == LSUP_TERM_TYPE_URIREF:
  2006. * return URIRef(uri) # <<<<<<<<<<<<<<
  2007. * elif term_type == LSUP_TERM_TYPE_BNODE:
  2008. * return BNode(uri)
  2009. */
  2010. __Pyx_XDECREF(__pyx_r);
  2011. __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_URIRef); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 77, __pyx_L4_error)
  2012. __Pyx_GOTREF(__pyx_t_4);
  2013. __pyx_t_5 = NULL;
  2014. if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
  2015. __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
  2016. if (likely(__pyx_t_5)) {
  2017. PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
  2018. __Pyx_INCREF(__pyx_t_5);
  2019. __Pyx_INCREF(function);
  2020. __Pyx_DECREF_SET(__pyx_t_4, function);
  2021. }
  2022. }
  2023. if (!__pyx_t_5) {
  2024. __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_uri); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 77, __pyx_L4_error)
  2025. __Pyx_GOTREF(__pyx_t_6);
  2026. } else {
  2027. #if CYTHON_FAST_PYCALL
  2028. if (PyFunction_Check(__pyx_t_4)) {
  2029. PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_uri};
  2030. __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 77, __pyx_L4_error)
  2031. __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  2032. __Pyx_GOTREF(__pyx_t_6);
  2033. } else
  2034. #endif
  2035. #if CYTHON_FAST_PYCCALL
  2036. if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
  2037. PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_uri};
  2038. __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 77, __pyx_L4_error)
  2039. __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  2040. __Pyx_GOTREF(__pyx_t_6);
  2041. } else
  2042. #endif
  2043. {
  2044. __pyx_t_1 = PyTuple_New(1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 77, __pyx_L4_error)
  2045. __Pyx_GOTREF(__pyx_t_1);
  2046. __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5); __pyx_t_5 = NULL;
  2047. __Pyx_INCREF(__pyx_v_uri);
  2048. __Pyx_GIVEREF(__pyx_v_uri);
  2049. PyTuple_SET_ITEM(__pyx_t_1, 0+1, __pyx_v_uri);
  2050. __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_1, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 77, __pyx_L4_error)
  2051. __Pyx_GOTREF(__pyx_t_6);
  2052. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  2053. }
  2054. }
  2055. __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  2056. __pyx_r = __pyx_t_6;
  2057. __pyx_t_6 = 0;
  2058. goto __pyx_L3_return;
  2059. /* "lakesuperior/store/ldp_rs/term.pyx":76
  2060. * &term_type, &term_data)
  2061. * uri = term_data.decode()
  2062. * if term_type == LSUP_TERM_TYPE_URIREF: # <<<<<<<<<<<<<<
  2063. * return URIRef(uri)
  2064. * elif term_type == LSUP_TERM_TYPE_BNODE:
  2065. */
  2066. break;
  2067. /* "lakesuperior/store/ldp_rs/term.pyx":78
  2068. * if term_type == LSUP_TERM_TYPE_URIREF:
  2069. * return URIRef(uri)
  2070. * elif term_type == LSUP_TERM_TYPE_BNODE: # <<<<<<<<<<<<<<
  2071. * return BNode(uri)
  2072. * else:
  2073. */
  2074. case 2:
  2075. /* "lakesuperior/store/ldp_rs/term.pyx":79
  2076. * return URIRef(uri)
  2077. * elif term_type == LSUP_TERM_TYPE_BNODE:
  2078. * return BNode(uri) # <<<<<<<<<<<<<<
  2079. * else:
  2080. * raise IOError(f'Unknown term type code: {term_type}')
  2081. */
  2082. __Pyx_XDECREF(__pyx_r);
  2083. __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_BNode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 79, __pyx_L4_error)
  2084. __Pyx_GOTREF(__pyx_t_4);
  2085. __pyx_t_1 = NULL;
  2086. if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
  2087. __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4);
  2088. if (likely(__pyx_t_1)) {
  2089. PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
  2090. __Pyx_INCREF(__pyx_t_1);
  2091. __Pyx_INCREF(function);
  2092. __Pyx_DECREF_SET(__pyx_t_4, function);
  2093. }
  2094. }
  2095. if (!__pyx_t_1) {
  2096. __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_uri); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 79, __pyx_L4_error)
  2097. __Pyx_GOTREF(__pyx_t_6);
  2098. } else {
  2099. #if CYTHON_FAST_PYCALL
  2100. if (PyFunction_Check(__pyx_t_4)) {
  2101. PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_v_uri};
  2102. __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 79, __pyx_L4_error)
  2103. __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  2104. __Pyx_GOTREF(__pyx_t_6);
  2105. } else
  2106. #endif
  2107. #if CYTHON_FAST_PYCCALL
  2108. if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
  2109. PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_v_uri};
  2110. __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 79, __pyx_L4_error)
  2111. __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  2112. __Pyx_GOTREF(__pyx_t_6);
  2113. } else
  2114. #endif
  2115. {
  2116. __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 79, __pyx_L4_error)
  2117. __Pyx_GOTREF(__pyx_t_5);
  2118. __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1); __pyx_t_1 = NULL;
  2119. __Pyx_INCREF(__pyx_v_uri);
  2120. __Pyx_GIVEREF(__pyx_v_uri);
  2121. PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_uri);
  2122. __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 79, __pyx_L4_error)
  2123. __Pyx_GOTREF(__pyx_t_6);
  2124. __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  2125. }
  2126. }
  2127. __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  2128. __pyx_r = __pyx_t_6;
  2129. __pyx_t_6 = 0;
  2130. goto __pyx_L3_return;
  2131. /* "lakesuperior/store/ldp_rs/term.pyx":78
  2132. * if term_type == LSUP_TERM_TYPE_URIREF:
  2133. * return URIRef(uri)
  2134. * elif term_type == LSUP_TERM_TYPE_BNODE: # <<<<<<<<<<<<<<
  2135. * return BNode(uri)
  2136. * else:
  2137. */
  2138. break;
  2139. default:
  2140. /* "lakesuperior/store/ldp_rs/term.pyx":81
  2141. * return BNode(uri)
  2142. * else:
  2143. * raise IOError(f'Unknown term type code: {term_type}') # <<<<<<<<<<<<<<
  2144. * else:
  2145. * msg = f'Unknown structure pack format: {fmt}'
  2146. */
  2147. __pyx_t_6 = __Pyx_PyUnicode_From_char(__pyx_v_term_type, 0, ' ', 'd'); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 81, __pyx_L4_error)
  2148. __Pyx_GOTREF(__pyx_t_6);
  2149. __pyx_t_4 = __Pyx_PyUnicode_Concat(__pyx_kp_u_Unknown_term_type_code, __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 81, __pyx_L4_error)
  2150. __Pyx_GOTREF(__pyx_t_4);
  2151. __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  2152. __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 81, __pyx_L4_error)
  2153. __Pyx_GOTREF(__pyx_t_6);
  2154. __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  2155. __Pyx_Raise(__pyx_t_6, 0, 0, 0);
  2156. __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  2157. __PYX_ERR(0, 81, __pyx_L4_error)
  2158. break;
  2159. }
  2160. /* "lakesuperior/store/ldp_rs/term.pyx":71
  2161. * return Literal(term_data.decode(), datatype=datatype, lang=lang)
  2162. *
  2163. * elif fmt == LSUP_PK_FMT_ID: # <<<<<<<<<<<<<<
  2164. * _pk = tpl.tpl_peek(
  2165. * tpl.TPL_MEM | tpl.TPL_DATAPEEK, data, data_size, b'cs',
  2166. */
  2167. }
  2168. /* "lakesuperior/store/ldp_rs/term.pyx":83
  2169. * raise IOError(f'Unknown term type code: {term_type}')
  2170. * else:
  2171. * msg = f'Unknown structure pack format: {fmt}' # <<<<<<<<<<<<<<
  2172. * raise IOError(msg)
  2173. * finally:
  2174. */
  2175. /*else*/ {
  2176. __pyx_t_6 = __Pyx_PyBytes_FromString(__pyx_v_fmt); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 83, __pyx_L4_error)
  2177. __Pyx_GOTREF(__pyx_t_6);
  2178. __pyx_t_4 = __Pyx_PyObject_FormatSimple(__pyx_t_6, __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 83, __pyx_L4_error)
  2179. __Pyx_GOTREF(__pyx_t_4);
  2180. __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  2181. __pyx_t_6 = __Pyx_PyUnicode_Concat(__pyx_kp_u_Unknown_structure_pack_format, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 83, __pyx_L4_error)
  2182. __Pyx_GOTREF(__pyx_t_6);
  2183. __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  2184. __pyx_v_msg = ((PyObject*)__pyx_t_6);
  2185. __pyx_t_6 = 0;
  2186. /* "lakesuperior/store/ldp_rs/term.pyx":84
  2187. * else:
  2188. * msg = f'Unknown structure pack format: {fmt}'
  2189. * raise IOError(msg) # <<<<<<<<<<<<<<
  2190. * finally:
  2191. * free(term_data)
  2192. */
  2193. __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IOError, __pyx_v_msg); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 84, __pyx_L4_error)
  2194. __Pyx_GOTREF(__pyx_t_6);
  2195. __Pyx_Raise(__pyx_t_6, 0, 0, 0);
  2196. __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  2197. __PYX_ERR(0, 84, __pyx_L4_error)
  2198. }
  2199. }
  2200. /* "lakesuperior/store/ldp_rs/term.pyx":86
  2201. * raise IOError(msg)
  2202. * finally:
  2203. * free(term_data) # <<<<<<<<<<<<<<
  2204. * free(term_datatype)
  2205. * free(term_lang)
  2206. */
  2207. /*finally:*/ {
  2208. __pyx_L4_error:;
  2209. /*exception exit:*/{
  2210. __Pyx_PyThreadState_declare
  2211. __Pyx_PyThreadState_assign
  2212. __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0; __pyx_t_15 = 0;
  2213. __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  2214. __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  2215. __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  2216. __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  2217. if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_13, &__pyx_t_14, &__pyx_t_15);
  2218. if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12) < 0)) __Pyx_ErrFetch(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12);
  2219. __Pyx_XGOTREF(__pyx_t_10);
  2220. __Pyx_XGOTREF(__pyx_t_11);
  2221. __Pyx_XGOTREF(__pyx_t_12);
  2222. __Pyx_XGOTREF(__pyx_t_13);
  2223. __Pyx_XGOTREF(__pyx_t_14);
  2224. __Pyx_XGOTREF(__pyx_t_15);
  2225. __pyx_t_7 = __pyx_lineno; __pyx_t_8 = __pyx_clineno; __pyx_t_9 = __pyx_filename;
  2226. {
  2227. free(__pyx_v_term_data);
  2228. /* "lakesuperior/store/ldp_rs/term.pyx":87
  2229. * finally:
  2230. * free(term_data)
  2231. * free(term_datatype) # <<<<<<<<<<<<<<
  2232. * free(term_lang)
  2233. * free(_pk)
  2234. */
  2235. free(__pyx_v_term_datatype);
  2236. /* "lakesuperior/store/ldp_rs/term.pyx":88
  2237. * free(term_data)
  2238. * free(term_datatype)
  2239. * free(term_lang) # <<<<<<<<<<<<<<
  2240. * free(_pk)
  2241. * free(fmt)
  2242. */
  2243. free(__pyx_v_term_lang);
  2244. /* "lakesuperior/store/ldp_rs/term.pyx":89
  2245. * free(term_datatype)
  2246. * free(term_lang)
  2247. * free(_pk) # <<<<<<<<<<<<<<
  2248. * free(fmt)
  2249. */
  2250. free(__pyx_v__pk);
  2251. /* "lakesuperior/store/ldp_rs/term.pyx":90
  2252. * free(term_lang)
  2253. * free(_pk)
  2254. * free(fmt) # <<<<<<<<<<<<<<
  2255. */
  2256. free(__pyx_v_fmt);
  2257. }
  2258. if (PY_MAJOR_VERSION >= 3) {
  2259. __Pyx_XGIVEREF(__pyx_t_13);
  2260. __Pyx_XGIVEREF(__pyx_t_14);
  2261. __Pyx_XGIVEREF(__pyx_t_15);
  2262. __Pyx_ExceptionReset(__pyx_t_13, __pyx_t_14, __pyx_t_15);
  2263. }
  2264. __Pyx_XGIVEREF(__pyx_t_10);
  2265. __Pyx_XGIVEREF(__pyx_t_11);
  2266. __Pyx_XGIVEREF(__pyx_t_12);
  2267. __Pyx_ErrRestore(__pyx_t_10, __pyx_t_11, __pyx_t_12);
  2268. __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0; __pyx_t_15 = 0;
  2269. __pyx_lineno = __pyx_t_7; __pyx_clineno = __pyx_t_8; __pyx_filename = __pyx_t_9;
  2270. goto __pyx_L1_error;
  2271. }
  2272. __pyx_L3_return: {
  2273. __pyx_t_15 = __pyx_r;
  2274. __pyx_r = 0;
  2275. /* "lakesuperior/store/ldp_rs/term.pyx":86
  2276. * raise IOError(msg)
  2277. * finally:
  2278. * free(term_data) # <<<<<<<<<<<<<<
  2279. * free(term_datatype)
  2280. * free(term_lang)
  2281. */
  2282. free(__pyx_v_term_data);
  2283. /* "lakesuperior/store/ldp_rs/term.pyx":87
  2284. * finally:
  2285. * free(term_data)
  2286. * free(term_datatype) # <<<<<<<<<<<<<<
  2287. * free(term_lang)
  2288. * free(_pk)
  2289. */
  2290. free(__pyx_v_term_datatype);
  2291. /* "lakesuperior/store/ldp_rs/term.pyx":88
  2292. * free(term_data)
  2293. * free(term_datatype)
  2294. * free(term_lang) # <<<<<<<<<<<<<<
  2295. * free(_pk)
  2296. * free(fmt)
  2297. */
  2298. free(__pyx_v_term_lang);
  2299. /* "lakesuperior/store/ldp_rs/term.pyx":89
  2300. * free(term_datatype)
  2301. * free(term_lang)
  2302. * free(_pk) # <<<<<<<<<<<<<<
  2303. * free(fmt)
  2304. */
  2305. free(__pyx_v__pk);
  2306. /* "lakesuperior/store/ldp_rs/term.pyx":90
  2307. * free(term_lang)
  2308. * free(_pk)
  2309. * free(fmt) # <<<<<<<<<<<<<<
  2310. */
  2311. free(__pyx_v_fmt);
  2312. __pyx_r = __pyx_t_15;
  2313. __pyx_t_15 = 0;
  2314. goto __pyx_L0;
  2315. }
  2316. }
  2317. /* "lakesuperior/store/ldp_rs/term.pyx":46
  2318. *
  2319. *
  2320. * cdef deserialize(const unsigned char *data, const size_t data_size): # <<<<<<<<<<<<<<
  2321. * cdef:
  2322. * char term_type
  2323. */
  2324. /* function exit code */
  2325. __pyx_L1_error:;
  2326. __Pyx_XDECREF(__pyx_t_1);
  2327. __Pyx_XDECREF(__pyx_t_4);
  2328. __Pyx_XDECREF(__pyx_t_5);
  2329. __Pyx_XDECREF(__pyx_t_6);
  2330. __Pyx_AddTraceback("lakesuperior.store.ldp_rs.term.deserialize", __pyx_clineno, __pyx_lineno, __pyx_filename);
  2331. __pyx_r = 0;
  2332. __pyx_L0:;
  2333. __Pyx_XDECREF(__pyx_v_datatype);
  2334. __Pyx_XDECREF(__pyx_v_lang);
  2335. __Pyx_XDECREF(__pyx_v_uri);
  2336. __Pyx_XDECREF(__pyx_v_msg);
  2337. __Pyx_XGIVEREF(__pyx_r);
  2338. __Pyx_TraceReturn(__pyx_r, 0);
  2339. __Pyx_RefNannyFinishContext();
  2340. return __pyx_r;
  2341. }
  2342. static PyMethodDef __pyx_methods[] = {
  2343. {0, 0, 0, 0}
  2344. };
  2345. #if PY_MAJOR_VERSION >= 3
  2346. #if CYTHON_PEP489_MULTI_PHASE_INIT
  2347. static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/
  2348. static int __pyx_pymod_exec_term(PyObject* module); /*proto*/
  2349. static PyModuleDef_Slot __pyx_moduledef_slots[] = {
  2350. {Py_mod_create, (void*)__pyx_pymod_create},
  2351. {Py_mod_exec, (void*)__pyx_pymod_exec_term},
  2352. {0, NULL}
  2353. };
  2354. #endif
  2355. static struct PyModuleDef __pyx_moduledef = {
  2356. PyModuleDef_HEAD_INIT,
  2357. "term",
  2358. 0, /* m_doc */
  2359. #if CYTHON_PEP489_MULTI_PHASE_INIT
  2360. 0, /* m_size */
  2361. #else
  2362. -1, /* m_size */
  2363. #endif
  2364. __pyx_methods /* m_methods */,
  2365. #if CYTHON_PEP489_MULTI_PHASE_INIT
  2366. __pyx_moduledef_slots, /* m_slots */
  2367. #else
  2368. NULL, /* m_reload */
  2369. #endif
  2370. NULL, /* m_traverse */
  2371. NULL, /* m_clear */
  2372. NULL /* m_free */
  2373. };
  2374. #endif
  2375. static __Pyx_StringTabEntry __pyx_string_tab[] = {
  2376. {&__pyx_kp_u_, __pyx_k_, sizeof(__pyx_k_), 0, 1, 0, 0},
  2377. {&__pyx_n_s_BNode, __pyx_k_BNode, sizeof(__pyx_k_BNode), 0, 0, 1, 1},
  2378. {&__pyx_n_s_IOError, __pyx_k_IOError, sizeof(__pyx_k_IOError), 0, 0, 1, 1},
  2379. {&__pyx_n_s_Literal, __pyx_k_Literal, sizeof(__pyx_k_Literal), 0, 0, 1, 1},
  2380. {&__pyx_kp_b_S_cs, __pyx_k_S_cs, sizeof(__pyx_k_S_cs), 0, 0, 0, 0},
  2381. {&__pyx_kp_b_S_csss, __pyx_k_S_csss, sizeof(__pyx_k_S_csss), 0, 0, 0, 0},
  2382. {&__pyx_n_s_URIRef, __pyx_k_URIRef, sizeof(__pyx_k_URIRef), 0, 0, 1, 1},
  2383. {&__pyx_kp_u_Unknown_structure_pack_format, __pyx_k_Unknown_structure_pack_format, sizeof(__pyx_k_Unknown_structure_pack_format), 0, 1, 0, 0},
  2384. {&__pyx_kp_u_Unknown_term_type_code, __pyx_k_Unknown_term_type_code, sizeof(__pyx_k_Unknown_term_type_code), 0, 1, 0, 0},
  2385. {&__pyx_kp_u_Unsupported_term_type, __pyx_k_Unsupported_term_type, sizeof(__pyx_k_Unsupported_term_type), 0, 1, 0, 0},
  2386. {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1},
  2387. {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1},
  2388. {&__pyx_n_s_datatype, __pyx_k_datatype, sizeof(__pyx_k_datatype), 0, 0, 1, 1},
  2389. {&__pyx_n_u_datatype, __pyx_k_datatype, sizeof(__pyx_k_datatype), 0, 1, 0, 1},
  2390. {&__pyx_n_s_encode, __pyx_k_encode, sizeof(__pyx_k_encode), 0, 0, 1, 1},
  2391. {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
  2392. {&__pyx_n_s_lang, __pyx_k_lang, sizeof(__pyx_k_lang), 0, 0, 1, 1},
  2393. {&__pyx_n_u_language, __pyx_k_language, sizeof(__pyx_k_language), 0, 1, 0, 1},
  2394. {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
  2395. {&__pyx_n_s_pack_fmt, __pyx_k_pack_fmt, sizeof(__pyx_k_pack_fmt), 0, 0, 1, 1},
  2396. {&__pyx_n_s_pyx_capi, __pyx_k_pyx_capi, sizeof(__pyx_k_pyx_capi), 0, 0, 1, 1},
  2397. {&__pyx_n_s_rdflib, __pyx_k_rdflib, sizeof(__pyx_k_rdflib), 0, 0, 1, 1},
  2398. {&__pyx_n_s_term_data, __pyx_k_term_data, sizeof(__pyx_k_term_data), 0, 0, 1, 1},
  2399. {&__pyx_n_s_term_datatype, __pyx_k_term_datatype, sizeof(__pyx_k_term_datatype), 0, 0, 1, 1},
  2400. {&__pyx_n_s_term_lang, __pyx_k_term_lang, sizeof(__pyx_k_term_lang), 0, 0, 1, 1},
  2401. {&__pyx_n_s_term_type, __pyx_k_term_type, sizeof(__pyx_k_term_type), 0, 0, 1, 1},
  2402. {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
  2403. {0, 0, 0, 0, 0, 0, 0}
  2404. };
  2405. static int __Pyx_InitCachedBuiltins(void) {
  2406. __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 41, __pyx_L1_error)
  2407. __pyx_builtin_IOError = __Pyx_GetBuiltinName(__pyx_n_s_IOError); if (!__pyx_builtin_IOError) __PYX_ERR(0, 81, __pyx_L1_error)
  2408. return 0;
  2409. __pyx_L1_error:;
  2410. return -1;
  2411. }
  2412. static int __Pyx_InitCachedConstants(void) {
  2413. __Pyx_RefNannyDeclarations
  2414. __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);
  2415. __Pyx_RefNannyFinishContext();
  2416. return 0;
  2417. }
  2418. static int __Pyx_InitGlobals(void) {
  2419. if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
  2420. return 0;
  2421. __pyx_L1_error:;
  2422. return -1;
  2423. }
  2424. static int __Pyx_modinit_global_init_code(void); /*proto*/
  2425. static int __Pyx_modinit_variable_export_code(void); /*proto*/
  2426. static int __Pyx_modinit_function_export_code(void); /*proto*/
  2427. static int __Pyx_modinit_type_init_code(void); /*proto*/
  2428. static int __Pyx_modinit_type_import_code(void); /*proto*/
  2429. static int __Pyx_modinit_variable_import_code(void); /*proto*/
  2430. static int __Pyx_modinit_function_import_code(void); /*proto*/
  2431. static int __Pyx_modinit_global_init_code(void) {
  2432. __Pyx_RefNannyDeclarations
  2433. __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0);
  2434. /*--- Global init code ---*/
  2435. __Pyx_RefNannyFinishContext();
  2436. return 0;
  2437. }
  2438. static int __Pyx_modinit_variable_export_code(void) {
  2439. __Pyx_RefNannyDeclarations
  2440. __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0);
  2441. /*--- Variable export code ---*/
  2442. if (__Pyx_ExportVoidPtr(__pyx_n_s_term_type, (void *)&__pyx_v_12lakesuperior_5store_6ldp_rs_4term_term_type, "unsigned char") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2443. if (__Pyx_ExportVoidPtr(__pyx_n_s_pack_fmt, (void *)&__pyx_v_12lakesuperior_5store_6ldp_rs_4term_pack_fmt, "unsigned char *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2444. if (__Pyx_ExportVoidPtr(__pyx_n_s_term_data, (void *)&__pyx_v_12lakesuperior_5store_6ldp_rs_4term_term_data, "unsigned char *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2445. if (__Pyx_ExportVoidPtr(__pyx_n_s_term_datatype, (void *)&__pyx_v_12lakesuperior_5store_6ldp_rs_4term_term_datatype, "unsigned char *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2446. if (__Pyx_ExportVoidPtr(__pyx_n_s_term_lang, (void *)&__pyx_v_12lakesuperior_5store_6ldp_rs_4term_term_lang, "unsigned char *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2447. __Pyx_RefNannyFinishContext();
  2448. return 0;
  2449. __pyx_L1_error:;
  2450. __Pyx_RefNannyFinishContext();
  2451. return -1;
  2452. }
  2453. static int __Pyx_modinit_function_export_code(void) {
  2454. __Pyx_RefNannyDeclarations
  2455. __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0);
  2456. /*--- Function export code ---*/
  2457. if (__Pyx_ExportFunction("serialize", (void (*)(void))__pyx_f_12lakesuperior_5store_6ldp_rs_4term_serialize, "int (PyObject *, unsigned char **, size_t *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2458. if (__Pyx_ExportFunction("deserialize", (void (*)(void))__pyx_f_12lakesuperior_5store_6ldp_rs_4term_deserialize, "PyObject *(unsigned char *, size_t)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2459. __Pyx_RefNannyFinishContext();
  2460. return 0;
  2461. __pyx_L1_error:;
  2462. __Pyx_RefNannyFinishContext();
  2463. return -1;
  2464. }
  2465. static int __Pyx_modinit_type_init_code(void) {
  2466. __Pyx_RefNannyDeclarations
  2467. __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0);
  2468. /*--- Type init code ---*/
  2469. __Pyx_RefNannyFinishContext();
  2470. return 0;
  2471. }
  2472. static int __Pyx_modinit_type_import_code(void) {
  2473. __Pyx_RefNannyDeclarations
  2474. __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0);
  2475. /*--- Type import code ---*/
  2476. __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "type",
  2477. #if defined(PYPY_VERSION_NUM) && PYPY_VERSION_NUM < 0x050B0000
  2478. sizeof(PyTypeObject),
  2479. #else
  2480. sizeof(PyHeapTypeObject),
  2481. #endif
  2482. 0); if (unlikely(!__pyx_ptype_7cpython_4type_type)) __PYX_ERR(1, 9, __pyx_L1_error)
  2483. __Pyx_RefNannyFinishContext();
  2484. return 0;
  2485. __pyx_L1_error:;
  2486. __Pyx_RefNannyFinishContext();
  2487. return -1;
  2488. }
  2489. static int __Pyx_modinit_variable_import_code(void) {
  2490. __Pyx_RefNannyDeclarations
  2491. __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0);
  2492. /*--- Variable import code ---*/
  2493. __Pyx_RefNannyFinishContext();
  2494. return 0;
  2495. }
  2496. static int __Pyx_modinit_function_import_code(void) {
  2497. __Pyx_RefNannyDeclarations
  2498. __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0);
  2499. /*--- Function import code ---*/
  2500. __Pyx_RefNannyFinishContext();
  2501. return 0;
  2502. }
  2503. #if PY_MAJOR_VERSION < 3
  2504. #ifdef CYTHON_NO_PYINIT_EXPORT
  2505. #define __Pyx_PyMODINIT_FUNC void
  2506. #else
  2507. #define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
  2508. #endif
  2509. #else
  2510. #ifdef CYTHON_NO_PYINIT_EXPORT
  2511. #define __Pyx_PyMODINIT_FUNC PyObject *
  2512. #else
  2513. #define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
  2514. #endif
  2515. #endif
  2516. #ifndef CYTHON_SMALL_CODE
  2517. #if defined(__clang__)
  2518. #define CYTHON_SMALL_CODE
  2519. #elif defined(__GNUC__) && (!(defined(__cplusplus)) || (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 4)))
  2520. #define CYTHON_SMALL_CODE __attribute__((optimize("Os")))
  2521. #else
  2522. #define CYTHON_SMALL_CODE
  2523. #endif
  2524. #endif
  2525. #if PY_MAJOR_VERSION < 3
  2526. __Pyx_PyMODINIT_FUNC initterm(void) CYTHON_SMALL_CODE; /*proto*/
  2527. __Pyx_PyMODINIT_FUNC initterm(void)
  2528. #else
  2529. __Pyx_PyMODINIT_FUNC PyInit_term(void) CYTHON_SMALL_CODE; /*proto*/
  2530. __Pyx_PyMODINIT_FUNC PyInit_term(void)
  2531. #if CYTHON_PEP489_MULTI_PHASE_INIT
  2532. {
  2533. return PyModuleDef_Init(&__pyx_moduledef);
  2534. }
  2535. static int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name) {
  2536. PyObject *value = PyObject_GetAttrString(spec, from_name);
  2537. int result = 0;
  2538. if (likely(value)) {
  2539. result = PyDict_SetItemString(moddict, to_name, value);
  2540. Py_DECREF(value);
  2541. } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
  2542. PyErr_Clear();
  2543. } else {
  2544. result = -1;
  2545. }
  2546. return result;
  2547. }
  2548. static PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) {
  2549. PyObject *module = NULL, *moddict, *modname;
  2550. if (__pyx_m)
  2551. return __Pyx_NewRef(__pyx_m);
  2552. modname = PyObject_GetAttrString(spec, "name");
  2553. if (unlikely(!modname)) goto bad;
  2554. module = PyModule_NewObject(modname);
  2555. Py_DECREF(modname);
  2556. if (unlikely(!module)) goto bad;
  2557. moddict = PyModule_GetDict(module);
  2558. if (unlikely(!moddict)) goto bad;
  2559. if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__") < 0)) goto bad;
  2560. if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__") < 0)) goto bad;
  2561. if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__") < 0)) goto bad;
  2562. if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__") < 0)) goto bad;
  2563. return module;
  2564. bad:
  2565. Py_XDECREF(module);
  2566. return NULL;
  2567. }
  2568. static int __pyx_pymod_exec_term(PyObject *__pyx_pyinit_module)
  2569. #endif
  2570. #endif
  2571. {
  2572. __Pyx_TraceDeclarations
  2573. PyObject *__pyx_t_1 = NULL;
  2574. PyObject *__pyx_t_2 = NULL;
  2575. __Pyx_RefNannyDeclarations
  2576. #if CYTHON_PEP489_MULTI_PHASE_INIT
  2577. if (__pyx_m && __pyx_m == __pyx_pyinit_module) return 0;
  2578. #elif PY_MAJOR_VERSION >= 3
  2579. if (__pyx_m) return __Pyx_NewRef(__pyx_m);
  2580. #endif
  2581. #if CYTHON_REFNANNY
  2582. __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
  2583. if (!__Pyx_RefNanny) {
  2584. PyErr_Clear();
  2585. __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
  2586. if (!__Pyx_RefNanny)
  2587. Py_FatalError("failed to import 'refnanny' module");
  2588. }
  2589. #endif
  2590. __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_term(void)", 0);
  2591. if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2592. __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error)
  2593. __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error)
  2594. __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error)
  2595. #ifdef __Pyx_CyFunction_USED
  2596. if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2597. #endif
  2598. #ifdef __Pyx_FusedFunction_USED
  2599. if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2600. #endif
  2601. #ifdef __Pyx_Coroutine_USED
  2602. if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2603. #endif
  2604. #ifdef __Pyx_Generator_USED
  2605. if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2606. #endif
  2607. #ifdef __Pyx_AsyncGen_USED
  2608. if (__pyx_AsyncGen_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2609. #endif
  2610. #ifdef __Pyx_StopAsyncIteration_USED
  2611. if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2612. #endif
  2613. /*--- Library function declarations ---*/
  2614. /*--- Threads initialization code ---*/
  2615. #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  2616. #ifdef WITH_THREAD /* Python build with threading support? */
  2617. PyEval_InitThreads();
  2618. #endif
  2619. #endif
  2620. /*--- Module creation code ---*/
  2621. #if CYTHON_PEP489_MULTI_PHASE_INIT
  2622. __pyx_m = __pyx_pyinit_module;
  2623. Py_INCREF(__pyx_m);
  2624. #else
  2625. #if PY_MAJOR_VERSION < 3
  2626. __pyx_m = Py_InitModule4("term", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
  2627. #else
  2628. __pyx_m = PyModule_Create(&__pyx_moduledef);
  2629. #endif
  2630. if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error)
  2631. #endif
  2632. __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error)
  2633. Py_INCREF(__pyx_d);
  2634. __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error)
  2635. __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error)
  2636. #if CYTHON_COMPILING_IN_PYPY
  2637. Py_INCREF(__pyx_b);
  2638. #endif
  2639. if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
  2640. /*--- Initialize various global constants etc. ---*/
  2641. if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2642. #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
  2643. if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2644. #endif
  2645. if (__pyx_module_is_main_lakesuperior__store__ldp_rs__term) {
  2646. if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2647. }
  2648. #if PY_MAJOR_VERSION >= 3
  2649. {
  2650. PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error)
  2651. if (!PyDict_GetItemString(modules, "lakesuperior.store.ldp_rs.term")) {
  2652. if (unlikely(PyDict_SetItemString(modules, "lakesuperior.store.ldp_rs.term", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
  2653. }
  2654. }
  2655. #endif
  2656. /*--- Builtin init code ---*/
  2657. if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2658. /*--- Constants init code ---*/
  2659. if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2660. /*--- Global type/function init code ---*/
  2661. (void)__Pyx_modinit_global_init_code();
  2662. if (unlikely(__Pyx_modinit_variable_export_code() != 0)) goto __pyx_L1_error;
  2663. if (unlikely(__Pyx_modinit_function_export_code() != 0)) goto __pyx_L1_error;
  2664. (void)__Pyx_modinit_type_init_code();
  2665. if (unlikely(__Pyx_modinit_type_import_code() != 0)) goto __pyx_L1_error;
  2666. (void)__Pyx_modinit_variable_import_code();
  2667. (void)__Pyx_modinit_function_import_code();
  2668. /*--- Execution code ---*/
  2669. #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
  2670. if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2671. #endif
  2672. __Pyx_TraceCall("__Pyx_PyMODINIT_FUNC PyInit_term(void)", __pyx_f[0], 1, 0, __PYX_ERR(0, 1, __pyx_L1_error));
  2673. /* "lakesuperior/store/ldp_rs/term.pyx":1
  2674. * from rdflib import URIRef, BNode, Literal # <<<<<<<<<<<<<<
  2675. *
  2676. * #from cpython.mem cimport PyMem_Malloc, PyMem_Free
  2677. */
  2678. __pyx_t_1 = PyList_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  2679. __Pyx_GOTREF(__pyx_t_1);
  2680. __Pyx_INCREF(__pyx_n_s_URIRef);
  2681. __Pyx_GIVEREF(__pyx_n_s_URIRef);
  2682. PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_URIRef);
  2683. __Pyx_INCREF(__pyx_n_s_BNode);
  2684. __Pyx_GIVEREF(__pyx_n_s_BNode);
  2685. PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_BNode);
  2686. __Pyx_INCREF(__pyx_n_s_Literal);
  2687. __Pyx_GIVEREF(__pyx_n_s_Literal);
  2688. PyList_SET_ITEM(__pyx_t_1, 2, __pyx_n_s_Literal);
  2689. __pyx_t_2 = __Pyx_Import(__pyx_n_s_rdflib, __pyx_t_1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error)
  2690. __Pyx_GOTREF(__pyx_t_2);
  2691. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  2692. __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_URIRef); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  2693. __Pyx_GOTREF(__pyx_t_1);
  2694. if (PyDict_SetItem(__pyx_d, __pyx_n_s_URIRef, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2695. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  2696. __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_BNode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  2697. __Pyx_GOTREF(__pyx_t_1);
  2698. if (PyDict_SetItem(__pyx_d, __pyx_n_s_BNode, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2699. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  2700. __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_Literal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  2701. __Pyx_GOTREF(__pyx_t_1);
  2702. if (PyDict_SetItem(__pyx_d, __pyx_n_s_Literal, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2703. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  2704. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  2705. /* "lakesuperior/store/ldp_rs/term.pyx":46
  2706. *
  2707. *
  2708. * cdef deserialize(const unsigned char *data, const size_t data_size): # <<<<<<<<<<<<<<
  2709. * cdef:
  2710. * char term_type
  2711. */
  2712. __pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error)
  2713. __Pyx_GOTREF(__pyx_t_2);
  2714. if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  2715. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  2716. __Pyx_TraceReturn(Py_None, 0);
  2717. /*--- Wrapped vars code ---*/
  2718. goto __pyx_L0;
  2719. __pyx_L1_error:;
  2720. __Pyx_XDECREF(__pyx_t_1);
  2721. __Pyx_XDECREF(__pyx_t_2);
  2722. if (__pyx_m) {
  2723. if (__pyx_d) {
  2724. __Pyx_AddTraceback("init lakesuperior.store.ldp_rs.term", 0, __pyx_lineno, __pyx_filename);
  2725. }
  2726. Py_DECREF(__pyx_m); __pyx_m = 0;
  2727. } else if (!PyErr_Occurred()) {
  2728. PyErr_SetString(PyExc_ImportError, "init lakesuperior.store.ldp_rs.term");
  2729. }
  2730. __pyx_L0:;
  2731. __Pyx_RefNannyFinishContext();
  2732. #if CYTHON_PEP489_MULTI_PHASE_INIT
  2733. return (__pyx_m != NULL) ? 0 : -1;
  2734. #elif PY_MAJOR_VERSION >= 3
  2735. return __pyx_m;
  2736. #else
  2737. return;
  2738. #endif
  2739. }
  2740. /* --- Runtime support code --- */
  2741. /* Refnanny */
  2742. #if CYTHON_REFNANNY
  2743. static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
  2744. PyObject *m = NULL, *p = NULL;
  2745. void *r = NULL;
  2746. m = PyImport_ImportModule((char *)modname);
  2747. if (!m) goto end;
  2748. p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
  2749. if (!p) goto end;
  2750. r = PyLong_AsVoidPtr(p);
  2751. end:
  2752. Py_XDECREF(p);
  2753. Py_XDECREF(m);
  2754. return (__Pyx_RefNannyAPIStruct *)r;
  2755. }
  2756. #endif
  2757. /* PyObjectGetAttrStr */
  2758. #if CYTHON_USE_TYPE_SLOTS
  2759. static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) {
  2760. PyTypeObject* tp = Py_TYPE(obj);
  2761. if (likely(tp->tp_getattro))
  2762. return tp->tp_getattro(obj, attr_name);
  2763. #if PY_MAJOR_VERSION < 3
  2764. if (likely(tp->tp_getattr))
  2765. return tp->tp_getattr(obj, PyString_AS_STRING(attr_name));
  2766. #endif
  2767. return PyObject_GetAttr(obj, attr_name);
  2768. }
  2769. #endif
  2770. /* GetBuiltinName */
  2771. static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
  2772. PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name);
  2773. if (unlikely(!result)) {
  2774. PyErr_Format(PyExc_NameError,
  2775. #if PY_MAJOR_VERSION >= 3
  2776. "name '%U' is not defined", name);
  2777. #else
  2778. "name '%.200s' is not defined", PyString_AS_STRING(name));
  2779. #endif
  2780. }
  2781. return result;
  2782. }
  2783. /* PyErrFetchRestore */
  2784. #if CYTHON_FAST_THREAD_STATE
  2785. static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
  2786. PyObject *tmp_type, *tmp_value, *tmp_tb;
  2787. tmp_type = tstate->curexc_type;
  2788. tmp_value = tstate->curexc_value;
  2789. tmp_tb = tstate->curexc_traceback;
  2790. tstate->curexc_type = type;
  2791. tstate->curexc_value = value;
  2792. tstate->curexc_traceback = tb;
  2793. Py_XDECREF(tmp_type);
  2794. Py_XDECREF(tmp_value);
  2795. Py_XDECREF(tmp_tb);
  2796. }
  2797. static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
  2798. *type = tstate->curexc_type;
  2799. *value = tstate->curexc_value;
  2800. *tb = tstate->curexc_traceback;
  2801. tstate->curexc_type = 0;
  2802. tstate->curexc_value = 0;
  2803. tstate->curexc_traceback = 0;
  2804. }
  2805. #endif
  2806. /* Profile */
  2807. #if CYTHON_PROFILE
  2808. static int __Pyx_TraceSetupAndCall(PyCodeObject** code,
  2809. PyFrameObject** frame,
  2810. PyThreadState* tstate,
  2811. const char *funcname,
  2812. const char *srcfile,
  2813. int firstlineno) {
  2814. PyObject *type, *value, *traceback;
  2815. int retval;
  2816. if (*frame == NULL || !CYTHON_PROFILE_REUSE_FRAME) {
  2817. if (*code == NULL) {
  2818. *code = __Pyx_createFrameCodeObject(funcname, srcfile, firstlineno);
  2819. if (*code == NULL) return 0;
  2820. }
  2821. *frame = PyFrame_New(
  2822. tstate, /*PyThreadState *tstate*/
  2823. *code, /*PyCodeObject *code*/
  2824. __pyx_d, /*PyObject *globals*/
  2825. 0 /*PyObject *locals*/
  2826. );
  2827. if (*frame == NULL) return 0;
  2828. if (CYTHON_TRACE && (*frame)->f_trace == NULL) {
  2829. Py_INCREF(Py_None);
  2830. (*frame)->f_trace = Py_None;
  2831. }
  2832. #if PY_VERSION_HEX < 0x030400B1
  2833. } else {
  2834. (*frame)->f_tstate = tstate;
  2835. #endif
  2836. }
  2837. __Pyx_PyFrame_SetLineNumber(*frame, firstlineno);
  2838. retval = 1;
  2839. tstate->tracing++;
  2840. tstate->use_tracing = 0;
  2841. __Pyx_ErrFetchInState(tstate, &type, &value, &traceback);
  2842. #if CYTHON_TRACE
  2843. if (tstate->c_tracefunc)
  2844. retval = tstate->c_tracefunc(tstate->c_traceobj, *frame, PyTrace_CALL, NULL) == 0;
  2845. if (retval && tstate->c_profilefunc)
  2846. #endif
  2847. retval = tstate->c_profilefunc(tstate->c_profileobj, *frame, PyTrace_CALL, NULL) == 0;
  2848. tstate->use_tracing = (tstate->c_profilefunc ||
  2849. (CYTHON_TRACE && tstate->c_tracefunc));
  2850. tstate->tracing--;
  2851. if (retval) {
  2852. __Pyx_ErrRestoreInState(tstate, type, value, traceback);
  2853. return tstate->use_tracing && retval;
  2854. } else {
  2855. Py_XDECREF(type);
  2856. Py_XDECREF(value);
  2857. Py_XDECREF(traceback);
  2858. return -1;
  2859. }
  2860. }
  2861. static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const char *srcfile, int firstlineno) {
  2862. PyObject *py_srcfile = 0;
  2863. PyObject *py_funcname = 0;
  2864. PyCodeObject *py_code = 0;
  2865. #if PY_MAJOR_VERSION < 3
  2866. py_funcname = PyString_FromString(funcname);
  2867. py_srcfile = PyString_FromString(srcfile);
  2868. #else
  2869. py_funcname = PyUnicode_FromString(funcname);
  2870. py_srcfile = PyUnicode_FromString(srcfile);
  2871. #endif
  2872. if (!py_funcname | !py_srcfile) goto bad;
  2873. py_code = PyCode_New(
  2874. 0,
  2875. #if PY_MAJOR_VERSION >= 3
  2876. 0,
  2877. #endif
  2878. 0,
  2879. 0,
  2880. CO_OPTIMIZED | CO_NEWLOCALS,
  2881. __pyx_empty_bytes, /*PyObject *code,*/
  2882. __pyx_empty_tuple, /*PyObject *consts,*/
  2883. __pyx_empty_tuple, /*PyObject *names,*/
  2884. __pyx_empty_tuple, /*PyObject *varnames,*/
  2885. __pyx_empty_tuple, /*PyObject *freevars,*/
  2886. __pyx_empty_tuple, /*PyObject *cellvars,*/
  2887. py_srcfile, /*PyObject *filename,*/
  2888. py_funcname, /*PyObject *name,*/
  2889. firstlineno,
  2890. __pyx_empty_bytes /*PyObject *lnotab*/
  2891. );
  2892. bad:
  2893. Py_XDECREF(py_srcfile);
  2894. Py_XDECREF(py_funcname);
  2895. return py_code;
  2896. }
  2897. #endif
  2898. /* PyCFunctionFastCall */
  2899. #if CYTHON_FAST_PYCCALL
  2900. static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, PyObject **args, Py_ssize_t nargs) {
  2901. PyCFunctionObject *func = (PyCFunctionObject*)func_obj;
  2902. PyCFunction meth = PyCFunction_GET_FUNCTION(func);
  2903. PyObject *self = PyCFunction_GET_SELF(func);
  2904. int flags = PyCFunction_GET_FLAGS(func);
  2905. assert(PyCFunction_Check(func));
  2906. assert(METH_FASTCALL == (flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS)));
  2907. assert(nargs >= 0);
  2908. assert(nargs == 0 || args != NULL);
  2909. /* _PyCFunction_FastCallDict() must not be called with an exception set,
  2910. because it may clear it (directly or indirectly) and so the
  2911. caller loses its exception */
  2912. assert(!PyErr_Occurred());
  2913. if ((PY_VERSION_HEX < 0x030700A0) || unlikely(flags & METH_KEYWORDS)) {
  2914. return (*((__Pyx_PyCFunctionFastWithKeywords)meth)) (self, args, nargs, NULL);
  2915. } else {
  2916. return (*((__Pyx_PyCFunctionFast)meth)) (self, args, nargs);
  2917. }
  2918. }
  2919. #endif
  2920. /* PyFunctionFastCall */
  2921. #if CYTHON_FAST_PYCALL
  2922. #include "frameobject.h"
  2923. static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na,
  2924. PyObject *globals) {
  2925. PyFrameObject *f;
  2926. PyThreadState *tstate = __Pyx_PyThreadState_Current;
  2927. PyObject **fastlocals;
  2928. Py_ssize_t i;
  2929. PyObject *result;
  2930. assert(globals != NULL);
  2931. /* XXX Perhaps we should create a specialized
  2932. PyFrame_New() that doesn't take locals, but does
  2933. take builtins without sanity checking them.
  2934. */
  2935. assert(tstate != NULL);
  2936. f = PyFrame_New(tstate, co, globals, NULL);
  2937. if (f == NULL) {
  2938. return NULL;
  2939. }
  2940. fastlocals = f->f_localsplus;
  2941. for (i = 0; i < na; i++) {
  2942. Py_INCREF(*args);
  2943. fastlocals[i] = *args++;
  2944. }
  2945. result = PyEval_EvalFrameEx(f,0);
  2946. ++tstate->recursion_depth;
  2947. Py_DECREF(f);
  2948. --tstate->recursion_depth;
  2949. return result;
  2950. }
  2951. #if 1 || PY_VERSION_HEX < 0x030600B1
  2952. static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwargs) {
  2953. PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func);
  2954. PyObject *globals = PyFunction_GET_GLOBALS(func);
  2955. PyObject *argdefs = PyFunction_GET_DEFAULTS(func);
  2956. PyObject *closure;
  2957. #if PY_MAJOR_VERSION >= 3
  2958. PyObject *kwdefs;
  2959. #endif
  2960. PyObject *kwtuple, **k;
  2961. PyObject **d;
  2962. Py_ssize_t nd;
  2963. Py_ssize_t nk;
  2964. PyObject *result;
  2965. assert(kwargs == NULL || PyDict_Check(kwargs));
  2966. nk = kwargs ? PyDict_Size(kwargs) : 0;
  2967. if (Py_EnterRecursiveCall((char*)" while calling a Python object")) {
  2968. return NULL;
  2969. }
  2970. if (
  2971. #if PY_MAJOR_VERSION >= 3
  2972. co->co_kwonlyargcount == 0 &&
  2973. #endif
  2974. likely(kwargs == NULL || nk == 0) &&
  2975. co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) {
  2976. if (argdefs == NULL && co->co_argcount == nargs) {
  2977. result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals);
  2978. goto done;
  2979. }
  2980. else if (nargs == 0 && argdefs != NULL
  2981. && co->co_argcount == Py_SIZE(argdefs)) {
  2982. /* function called with no arguments, but all parameters have
  2983. a default value: use default values as arguments .*/
  2984. args = &PyTuple_GET_ITEM(argdefs, 0);
  2985. result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals);
  2986. goto done;
  2987. }
  2988. }
  2989. if (kwargs != NULL) {
  2990. Py_ssize_t pos, i;
  2991. kwtuple = PyTuple_New(2 * nk);
  2992. if (kwtuple == NULL) {
  2993. result = NULL;
  2994. goto done;
  2995. }
  2996. k = &PyTuple_GET_ITEM(kwtuple, 0);
  2997. pos = i = 0;
  2998. while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) {
  2999. Py_INCREF(k[i]);
  3000. Py_INCREF(k[i+1]);
  3001. i += 2;
  3002. }
  3003. nk = i / 2;
  3004. }
  3005. else {
  3006. kwtuple = NULL;
  3007. k = NULL;
  3008. }
  3009. closure = PyFunction_GET_CLOSURE(func);
  3010. #if PY_MAJOR_VERSION >= 3
  3011. kwdefs = PyFunction_GET_KW_DEFAULTS(func);
  3012. #endif
  3013. if (argdefs != NULL) {
  3014. d = &PyTuple_GET_ITEM(argdefs, 0);
  3015. nd = Py_SIZE(argdefs);
  3016. }
  3017. else {
  3018. d = NULL;
  3019. nd = 0;
  3020. }
  3021. #if PY_MAJOR_VERSION >= 3
  3022. result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL,
  3023. args, nargs,
  3024. k, (int)nk,
  3025. d, (int)nd, kwdefs, closure);
  3026. #else
  3027. result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL,
  3028. args, nargs,
  3029. k, (int)nk,
  3030. d, (int)nd, closure);
  3031. #endif
  3032. Py_XDECREF(kwtuple);
  3033. done:
  3034. Py_LeaveRecursiveCall();
  3035. return result;
  3036. }
  3037. #endif
  3038. #endif
  3039. /* PyObjectCall */
  3040. #if CYTHON_COMPILING_IN_CPYTHON
  3041. static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
  3042. PyObject *result;
  3043. ternaryfunc call = func->ob_type->tp_call;
  3044. if (unlikely(!call))
  3045. return PyObject_Call(func, arg, kw);
  3046. if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
  3047. return NULL;
  3048. result = (*call)(func, arg, kw);
  3049. Py_LeaveRecursiveCall();
  3050. if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
  3051. PyErr_SetString(
  3052. PyExc_SystemError,
  3053. "NULL result without error in PyObject_Call");
  3054. }
  3055. return result;
  3056. }
  3057. #endif
  3058. /* PyObjectCallMethO */
  3059. #if CYTHON_COMPILING_IN_CPYTHON
  3060. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
  3061. PyObject *self, *result;
  3062. PyCFunction cfunc;
  3063. cfunc = PyCFunction_GET_FUNCTION(func);
  3064. self = PyCFunction_GET_SELF(func);
  3065. if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
  3066. return NULL;
  3067. result = cfunc(self, arg);
  3068. Py_LeaveRecursiveCall();
  3069. if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
  3070. PyErr_SetString(
  3071. PyExc_SystemError,
  3072. "NULL result without error in PyObject_Call");
  3073. }
  3074. return result;
  3075. }
  3076. #endif
  3077. /* PyObjectCallOneArg */
  3078. #if CYTHON_COMPILING_IN_CPYTHON
  3079. static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) {
  3080. PyObject *result;
  3081. PyObject *args = PyTuple_New(1);
  3082. if (unlikely(!args)) return NULL;
  3083. Py_INCREF(arg);
  3084. PyTuple_SET_ITEM(args, 0, arg);
  3085. result = __Pyx_PyObject_Call(func, args, NULL);
  3086. Py_DECREF(args);
  3087. return result;
  3088. }
  3089. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
  3090. #if CYTHON_FAST_PYCALL
  3091. if (PyFunction_Check(func)) {
  3092. return __Pyx_PyFunction_FastCall(func, &arg, 1);
  3093. }
  3094. #endif
  3095. if (likely(PyCFunction_Check(func))) {
  3096. if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) {
  3097. return __Pyx_PyObject_CallMethO(func, arg);
  3098. #if CYTHON_FAST_PYCCALL
  3099. } else if (PyCFunction_GET_FLAGS(func) & METH_FASTCALL) {
  3100. return __Pyx_PyCFunction_FastCall(func, &arg, 1);
  3101. #endif
  3102. }
  3103. }
  3104. return __Pyx__PyObject_CallOneArg(func, arg);
  3105. }
  3106. #else
  3107. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
  3108. PyObject *result;
  3109. PyObject *args = PyTuple_Pack(1, arg);
  3110. if (unlikely(!args)) return NULL;
  3111. result = __Pyx_PyObject_Call(func, args, NULL);
  3112. Py_DECREF(args);
  3113. return result;
  3114. }
  3115. #endif
  3116. /* PyObjectCallNoArg */
  3117. #if CYTHON_COMPILING_IN_CPYTHON
  3118. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
  3119. #if CYTHON_FAST_PYCALL
  3120. if (PyFunction_Check(func)) {
  3121. return __Pyx_PyFunction_FastCall(func, NULL, 0);
  3122. }
  3123. #endif
  3124. #ifdef __Pyx_CyFunction_USED
  3125. if (likely(PyCFunction_Check(func) || __Pyx_TypeCheck(func, __pyx_CyFunctionType))) {
  3126. #else
  3127. if (likely(PyCFunction_Check(func))) {
  3128. #endif
  3129. if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) {
  3130. return __Pyx_PyObject_CallMethO(func, NULL);
  3131. }
  3132. }
  3133. return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL);
  3134. }
  3135. #endif
  3136. /* GetModuleGlobalName */
  3137. static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) {
  3138. PyObject *result;
  3139. #if !CYTHON_AVOID_BORROWED_REFS
  3140. #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1
  3141. result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash);
  3142. if (likely(result)) {
  3143. Py_INCREF(result);
  3144. } else if (unlikely(PyErr_Occurred())) {
  3145. result = NULL;
  3146. } else {
  3147. #else
  3148. result = PyDict_GetItem(__pyx_d, name);
  3149. if (likely(result)) {
  3150. Py_INCREF(result);
  3151. } else {
  3152. #endif
  3153. #else
  3154. result = PyObject_GetItem(__pyx_d, name);
  3155. if (!result) {
  3156. PyErr_Clear();
  3157. #endif
  3158. result = __Pyx_GetBuiltinName(name);
  3159. }
  3160. return result;
  3161. }
  3162. /* GetAttr */
  3163. static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *o, PyObject *n) {
  3164. #if CYTHON_USE_TYPE_SLOTS
  3165. #if PY_MAJOR_VERSION >= 3
  3166. if (likely(PyUnicode_Check(n)))
  3167. #else
  3168. if (likely(PyString_Check(n)))
  3169. #endif
  3170. return __Pyx_PyObject_GetAttrStr(o, n);
  3171. #endif
  3172. return PyObject_GetAttr(o, n);
  3173. }
  3174. /* RaiseException */
  3175. #if PY_MAJOR_VERSION < 3
  3176. static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
  3177. CYTHON_UNUSED PyObject *cause) {
  3178. __Pyx_PyThreadState_declare
  3179. Py_XINCREF(type);
  3180. if (!value || value == Py_None)
  3181. value = NULL;
  3182. else
  3183. Py_INCREF(value);
  3184. if (!tb || tb == Py_None)
  3185. tb = NULL;
  3186. else {
  3187. Py_INCREF(tb);
  3188. if (!PyTraceBack_Check(tb)) {
  3189. PyErr_SetString(PyExc_TypeError,
  3190. "raise: arg 3 must be a traceback or None");
  3191. goto raise_error;
  3192. }
  3193. }
  3194. if (PyType_Check(type)) {
  3195. #if CYTHON_COMPILING_IN_PYPY
  3196. if (!value) {
  3197. Py_INCREF(Py_None);
  3198. value = Py_None;
  3199. }
  3200. #endif
  3201. PyErr_NormalizeException(&type, &value, &tb);
  3202. } else {
  3203. if (value) {
  3204. PyErr_SetString(PyExc_TypeError,
  3205. "instance exception may not have a separate value");
  3206. goto raise_error;
  3207. }
  3208. value = type;
  3209. type = (PyObject*) Py_TYPE(type);
  3210. Py_INCREF(type);
  3211. if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
  3212. PyErr_SetString(PyExc_TypeError,
  3213. "raise: exception class must be a subclass of BaseException");
  3214. goto raise_error;
  3215. }
  3216. }
  3217. __Pyx_PyThreadState_assign
  3218. __Pyx_ErrRestore(type, value, tb);
  3219. return;
  3220. raise_error:
  3221. Py_XDECREF(value);
  3222. Py_XDECREF(type);
  3223. Py_XDECREF(tb);
  3224. return;
  3225. }
  3226. #else
  3227. static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
  3228. PyObject* owned_instance = NULL;
  3229. if (tb == Py_None) {
  3230. tb = 0;
  3231. } else if (tb && !PyTraceBack_Check(tb)) {
  3232. PyErr_SetString(PyExc_TypeError,
  3233. "raise: arg 3 must be a traceback or None");
  3234. goto bad;
  3235. }
  3236. if (value == Py_None)
  3237. value = 0;
  3238. if (PyExceptionInstance_Check(type)) {
  3239. if (value) {
  3240. PyErr_SetString(PyExc_TypeError,
  3241. "instance exception may not have a separate value");
  3242. goto bad;
  3243. }
  3244. value = type;
  3245. type = (PyObject*) Py_TYPE(value);
  3246. } else if (PyExceptionClass_Check(type)) {
  3247. PyObject *instance_class = NULL;
  3248. if (value && PyExceptionInstance_Check(value)) {
  3249. instance_class = (PyObject*) Py_TYPE(value);
  3250. if (instance_class != type) {
  3251. int is_subclass = PyObject_IsSubclass(instance_class, type);
  3252. if (!is_subclass) {
  3253. instance_class = NULL;
  3254. } else if (unlikely(is_subclass == -1)) {
  3255. goto bad;
  3256. } else {
  3257. type = instance_class;
  3258. }
  3259. }
  3260. }
  3261. if (!instance_class) {
  3262. PyObject *args;
  3263. if (!value)
  3264. args = PyTuple_New(0);
  3265. else if (PyTuple_Check(value)) {
  3266. Py_INCREF(value);
  3267. args = value;
  3268. } else
  3269. args = PyTuple_Pack(1, value);
  3270. if (!args)
  3271. goto bad;
  3272. owned_instance = PyObject_Call(type, args, NULL);
  3273. Py_DECREF(args);
  3274. if (!owned_instance)
  3275. goto bad;
  3276. value = owned_instance;
  3277. if (!PyExceptionInstance_Check(value)) {
  3278. PyErr_Format(PyExc_TypeError,
  3279. "calling %R should have returned an instance of "
  3280. "BaseException, not %R",
  3281. type, Py_TYPE(value));
  3282. goto bad;
  3283. }
  3284. }
  3285. } else {
  3286. PyErr_SetString(PyExc_TypeError,
  3287. "raise: exception class must be a subclass of BaseException");
  3288. goto bad;
  3289. }
  3290. if (cause) {
  3291. PyObject *fixed_cause;
  3292. if (cause == Py_None) {
  3293. fixed_cause = NULL;
  3294. } else if (PyExceptionClass_Check(cause)) {
  3295. fixed_cause = PyObject_CallObject(cause, NULL);
  3296. if (fixed_cause == NULL)
  3297. goto bad;
  3298. } else if (PyExceptionInstance_Check(cause)) {
  3299. fixed_cause = cause;
  3300. Py_INCREF(fixed_cause);
  3301. } else {
  3302. PyErr_SetString(PyExc_TypeError,
  3303. "exception causes must derive from "
  3304. "BaseException");
  3305. goto bad;
  3306. }
  3307. PyException_SetCause(value, fixed_cause);
  3308. }
  3309. PyErr_SetObject(type, value);
  3310. if (tb) {
  3311. #if CYTHON_COMPILING_IN_PYPY
  3312. PyObject *tmp_type, *tmp_value, *tmp_tb;
  3313. PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb);
  3314. Py_INCREF(tb);
  3315. PyErr_Restore(tmp_type, tmp_value, tb);
  3316. Py_XDECREF(tmp_tb);
  3317. #else
  3318. PyThreadState *tstate = __Pyx_PyThreadState_Current;
  3319. PyObject* tmp_tb = tstate->curexc_traceback;
  3320. if (tb != tmp_tb) {
  3321. Py_INCREF(tb);
  3322. tstate->curexc_traceback = tb;
  3323. Py_XDECREF(tmp_tb);
  3324. }
  3325. #endif
  3326. }
  3327. bad:
  3328. Py_XDECREF(owned_instance);
  3329. return;
  3330. }
  3331. #endif
  3332. /* BytesEquals */
  3333. static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) {
  3334. #if CYTHON_COMPILING_IN_PYPY
  3335. return PyObject_RichCompareBool(s1, s2, equals);
  3336. #else
  3337. if (s1 == s2) {
  3338. return (equals == Py_EQ);
  3339. } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) {
  3340. const char *ps1, *ps2;
  3341. Py_ssize_t length = PyBytes_GET_SIZE(s1);
  3342. if (length != PyBytes_GET_SIZE(s2))
  3343. return (equals == Py_NE);
  3344. ps1 = PyBytes_AS_STRING(s1);
  3345. ps2 = PyBytes_AS_STRING(s2);
  3346. if (ps1[0] != ps2[0]) {
  3347. return (equals == Py_NE);
  3348. } else if (length == 1) {
  3349. return (equals == Py_EQ);
  3350. } else {
  3351. int result;
  3352. #if CYTHON_USE_UNICODE_INTERNALS
  3353. Py_hash_t hash1, hash2;
  3354. hash1 = ((PyBytesObject*)s1)->ob_shash;
  3355. hash2 = ((PyBytesObject*)s2)->ob_shash;
  3356. if (hash1 != hash2 && hash1 != -1 && hash2 != -1) {
  3357. return (equals == Py_NE);
  3358. }
  3359. #endif
  3360. result = memcmp(ps1, ps2, (size_t)length);
  3361. return (equals == Py_EQ) ? (result == 0) : (result != 0);
  3362. }
  3363. } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) {
  3364. return (equals == Py_NE);
  3365. } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) {
  3366. return (equals == Py_NE);
  3367. } else {
  3368. int result;
  3369. PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
  3370. if (!py_result)
  3371. return -1;
  3372. result = __Pyx_PyObject_IsTrue(py_result);
  3373. Py_DECREF(py_result);
  3374. return result;
  3375. }
  3376. #endif
  3377. }
  3378. /* decode_c_string */
  3379. static CYTHON_INLINE PyObject* __Pyx_decode_c_string(
  3380. const char* cstring, Py_ssize_t start, Py_ssize_t stop,
  3381. const char* encoding, const char* errors,
  3382. PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors)) {
  3383. Py_ssize_t length;
  3384. if (unlikely((start < 0) | (stop < 0))) {
  3385. size_t slen = strlen(cstring);
  3386. if (unlikely(slen > (size_t) PY_SSIZE_T_MAX)) {
  3387. PyErr_SetString(PyExc_OverflowError,
  3388. "c-string too long to convert to Python");
  3389. return NULL;
  3390. }
  3391. length = (Py_ssize_t) slen;
  3392. if (start < 0) {
  3393. start += length;
  3394. if (start < 0)
  3395. start = 0;
  3396. }
  3397. if (stop < 0)
  3398. stop += length;
  3399. }
  3400. length = stop - start;
  3401. if (unlikely(length <= 0))
  3402. return PyUnicode_FromUnicode(NULL, 0);
  3403. cstring += start;
  3404. if (decode_func) {
  3405. return decode_func(cstring, length, errors);
  3406. } else {
  3407. return PyUnicode_Decode(cstring, length, encoding, errors);
  3408. }
  3409. }
  3410. /* CIntToDigits */
  3411. static const char DIGIT_PAIRS_10[2*10*10+1] = {
  3412. "00010203040506070809"
  3413. "10111213141516171819"
  3414. "20212223242526272829"
  3415. "30313233343536373839"
  3416. "40414243444546474849"
  3417. "50515253545556575859"
  3418. "60616263646566676869"
  3419. "70717273747576777879"
  3420. "80818283848586878889"
  3421. "90919293949596979899"
  3422. };
  3423. static const char DIGIT_PAIRS_8[2*8*8+1] = {
  3424. "0001020304050607"
  3425. "1011121314151617"
  3426. "2021222324252627"
  3427. "3031323334353637"
  3428. "4041424344454647"
  3429. "5051525354555657"
  3430. "6061626364656667"
  3431. "7071727374757677"
  3432. };
  3433. static const char DIGITS_HEX[2*16+1] = {
  3434. "0123456789abcdef"
  3435. "0123456789ABCDEF"
  3436. };
  3437. /* BuildPyUnicode */
  3438. static PyObject* __Pyx_PyUnicode_BuildFromAscii(Py_ssize_t ulength, char* chars, int clength,
  3439. int prepend_sign, char padding_char) {
  3440. PyObject *uval;
  3441. Py_ssize_t uoffset = ulength - clength;
  3442. #if CYTHON_USE_UNICODE_INTERNALS
  3443. Py_ssize_t i;
  3444. #if CYTHON_PEP393_ENABLED
  3445. void *udata;
  3446. uval = PyUnicode_New(ulength, 127);
  3447. if (unlikely(!uval)) return NULL;
  3448. udata = PyUnicode_DATA(uval);
  3449. #else
  3450. Py_UNICODE *udata;
  3451. uval = PyUnicode_FromUnicode(NULL, ulength);
  3452. if (unlikely(!uval)) return NULL;
  3453. udata = PyUnicode_AS_UNICODE(uval);
  3454. #endif
  3455. if (uoffset > 0) {
  3456. i = 0;
  3457. if (prepend_sign) {
  3458. __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, 0, '-');
  3459. i++;
  3460. }
  3461. for (; i < uoffset; i++) {
  3462. __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, i, padding_char);
  3463. }
  3464. }
  3465. for (i=0; i < clength; i++) {
  3466. __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, uoffset+i, chars[i]);
  3467. }
  3468. #else
  3469. {
  3470. uval = NULL;
  3471. PyObject *sign = NULL, *padding = NULL;
  3472. if (uoffset > 0) {
  3473. prepend_sign = !!prepend_sign;
  3474. if (uoffset > prepend_sign) {
  3475. padding = PyUnicode_FromOrdinal(padding_char);
  3476. if (likely(padding) && uoffset > prepend_sign + 1) {
  3477. PyObject *tmp;
  3478. PyObject *repeat = PyInt_FromSize_t(uoffset - prepend_sign);
  3479. if (unlikely(!repeat)) goto done_or_error;
  3480. tmp = PyNumber_Multiply(padding, repeat);
  3481. Py_DECREF(repeat);
  3482. Py_DECREF(padding);
  3483. padding = tmp;
  3484. }
  3485. if (unlikely(!padding)) goto done_or_error;
  3486. }
  3487. if (prepend_sign) {
  3488. sign = PyUnicode_FromOrdinal('-');
  3489. if (unlikely(!sign)) goto done_or_error;
  3490. }
  3491. }
  3492. uval = PyUnicode_DecodeASCII(chars, clength, NULL);
  3493. if (likely(uval) && padding) {
  3494. PyObject *tmp = PyNumber_Add(padding, uval);
  3495. Py_DECREF(uval);
  3496. uval = tmp;
  3497. }
  3498. if (likely(uval) && sign) {
  3499. PyObject *tmp = PyNumber_Add(sign, uval);
  3500. Py_DECREF(uval);
  3501. uval = tmp;
  3502. }
  3503. done_or_error:
  3504. Py_XDECREF(padding);
  3505. Py_XDECREF(sign);
  3506. }
  3507. #endif
  3508. return uval;
  3509. }
  3510. /* CIntToPyUnicode */
  3511. #ifdef _MSC_VER
  3512. #ifndef _MSC_STDINT_H_
  3513. #if _MSC_VER < 1300
  3514. typedef unsigned short uint16_t;
  3515. #else
  3516. typedef unsigned __int16 uint16_t;
  3517. #endif
  3518. #endif
  3519. #else
  3520. #include <stdint.h>
  3521. #endif
  3522. static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_char(char value, Py_ssize_t width, char padding_char, char format_char) {
  3523. char digits[sizeof(char)*3+2];
  3524. char *dpos, *end = digits + sizeof(char)*3+2;
  3525. const char *hex_digits = DIGITS_HEX;
  3526. Py_ssize_t length, ulength;
  3527. int prepend_sign, last_one_off;
  3528. char remaining;
  3529. const char neg_one = (char) -1, const_zero = (char) 0;
  3530. const int is_unsigned = neg_one > const_zero;
  3531. if (format_char == 'X') {
  3532. hex_digits += 16;
  3533. format_char = 'x';
  3534. }
  3535. remaining = value;
  3536. last_one_off = 0;
  3537. dpos = end;
  3538. do {
  3539. int digit_pos;
  3540. switch (format_char) {
  3541. case 'o':
  3542. digit_pos = abs((int)(remaining % (8*8)));
  3543. remaining = (char) (remaining / (8*8));
  3544. dpos -= 2;
  3545. *(uint16_t*)dpos = ((uint16_t*)DIGIT_PAIRS_8)[digit_pos];
  3546. last_one_off = (digit_pos < 8);
  3547. break;
  3548. case 'd':
  3549. digit_pos = abs((int)(remaining % (10*10)));
  3550. remaining = (char) (remaining / (10*10));
  3551. dpos -= 2;
  3552. *(uint16_t*)dpos = ((uint16_t*)DIGIT_PAIRS_10)[digit_pos];
  3553. last_one_off = (digit_pos < 10);
  3554. break;
  3555. case 'x':
  3556. *(--dpos) = hex_digits[abs((int)(remaining % 16))];
  3557. remaining = (char) (remaining / 16);
  3558. break;
  3559. default:
  3560. assert(0);
  3561. break;
  3562. }
  3563. } while (unlikely(remaining != 0));
  3564. if (last_one_off) {
  3565. assert(*dpos == '0');
  3566. dpos++;
  3567. }
  3568. length = end - dpos;
  3569. ulength = length;
  3570. prepend_sign = 0;
  3571. if (!is_unsigned && value <= neg_one) {
  3572. if (padding_char == ' ' || width <= length + 1) {
  3573. *(--dpos) = '-';
  3574. ++length;
  3575. } else {
  3576. prepend_sign = 1;
  3577. }
  3578. ++ulength;
  3579. }
  3580. if (width > ulength) {
  3581. ulength = width;
  3582. }
  3583. if (ulength == 1) {
  3584. return PyUnicode_FromOrdinal(*dpos);
  3585. }
  3586. return __Pyx_PyUnicode_BuildFromAscii(ulength, dpos, (int) length, prepend_sign, padding_char);
  3587. }
  3588. /* GetException */
  3589. #if CYTHON_FAST_THREAD_STATE
  3590. static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
  3591. #else
  3592. static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) {
  3593. #endif
  3594. PyObject *local_type, *local_value, *local_tb;
  3595. #if CYTHON_FAST_THREAD_STATE
  3596. PyObject *tmp_type, *tmp_value, *tmp_tb;
  3597. local_type = tstate->curexc_type;
  3598. local_value = tstate->curexc_value;
  3599. local_tb = tstate->curexc_traceback;
  3600. tstate->curexc_type = 0;
  3601. tstate->curexc_value = 0;
  3602. tstate->curexc_traceback = 0;
  3603. #else
  3604. PyErr_Fetch(&local_type, &local_value, &local_tb);
  3605. #endif
  3606. PyErr_NormalizeException(&local_type, &local_value, &local_tb);
  3607. #if CYTHON_FAST_THREAD_STATE
  3608. if (unlikely(tstate->curexc_type))
  3609. #else
  3610. if (unlikely(PyErr_Occurred()))
  3611. #endif
  3612. goto bad;
  3613. #if PY_MAJOR_VERSION >= 3
  3614. if (local_tb) {
  3615. if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
  3616. goto bad;
  3617. }
  3618. #endif
  3619. Py_XINCREF(local_tb);
  3620. Py_XINCREF(local_type);
  3621. Py_XINCREF(local_value);
  3622. *type = local_type;
  3623. *value = local_value;
  3624. *tb = local_tb;
  3625. #if CYTHON_FAST_THREAD_STATE
  3626. #if PY_VERSION_HEX >= 0x030700A3
  3627. tmp_type = tstate->exc_state.exc_type;
  3628. tmp_value = tstate->exc_state.exc_value;
  3629. tmp_tb = tstate->exc_state.exc_traceback;
  3630. tstate->exc_state.exc_type = local_type;
  3631. tstate->exc_state.exc_value = local_value;
  3632. tstate->exc_state.exc_traceback = local_tb;
  3633. #else
  3634. tmp_type = tstate->exc_type;
  3635. tmp_value = tstate->exc_value;
  3636. tmp_tb = tstate->exc_traceback;
  3637. tstate->exc_type = local_type;
  3638. tstate->exc_value = local_value;
  3639. tstate->exc_traceback = local_tb;
  3640. #endif
  3641. Py_XDECREF(tmp_type);
  3642. Py_XDECREF(tmp_value);
  3643. Py_XDECREF(tmp_tb);
  3644. #else
  3645. PyErr_SetExcInfo(local_type, local_value, local_tb);
  3646. #endif
  3647. return 0;
  3648. bad:
  3649. *type = 0;
  3650. *value = 0;
  3651. *tb = 0;
  3652. Py_XDECREF(local_type);
  3653. Py_XDECREF(local_value);
  3654. Py_XDECREF(local_tb);
  3655. return -1;
  3656. }
  3657. /* SwapException */
  3658. #if CYTHON_FAST_THREAD_STATE
  3659. static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
  3660. PyObject *tmp_type, *tmp_value, *tmp_tb;
  3661. #if PY_VERSION_HEX >= 0x030700A3
  3662. tmp_type = tstate->exc_state.exc_type;
  3663. tmp_value = tstate->exc_state.exc_value;
  3664. tmp_tb = tstate->exc_state.exc_traceback;
  3665. tstate->exc_state.exc_type = *type;
  3666. tstate->exc_state.exc_value = *value;
  3667. tstate->exc_state.exc_traceback = *tb;
  3668. #else
  3669. tmp_type = tstate->exc_type;
  3670. tmp_value = tstate->exc_value;
  3671. tmp_tb = tstate->exc_traceback;
  3672. tstate->exc_type = *type;
  3673. tstate->exc_value = *value;
  3674. tstate->exc_traceback = *tb;
  3675. #endif
  3676. *type = tmp_type;
  3677. *value = tmp_value;
  3678. *tb = tmp_tb;
  3679. }
  3680. #else
  3681. static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) {
  3682. PyObject *tmp_type, *tmp_value, *tmp_tb;
  3683. PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb);
  3684. PyErr_SetExcInfo(*type, *value, *tb);
  3685. *type = tmp_type;
  3686. *value = tmp_value;
  3687. *tb = tmp_tb;
  3688. }
  3689. #endif
  3690. /* SaveResetException */
  3691. #if CYTHON_FAST_THREAD_STATE
  3692. static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
  3693. #if PY_VERSION_HEX >= 0x030700A3
  3694. *type = tstate->exc_state.exc_type;
  3695. *value = tstate->exc_state.exc_value;
  3696. *tb = tstate->exc_state.exc_traceback;
  3697. #else
  3698. *type = tstate->exc_type;
  3699. *value = tstate->exc_value;
  3700. *tb = tstate->exc_traceback;
  3701. #endif
  3702. Py_XINCREF(*type);
  3703. Py_XINCREF(*value);
  3704. Py_XINCREF(*tb);
  3705. }
  3706. static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
  3707. PyObject *tmp_type, *tmp_value, *tmp_tb;
  3708. #if PY_VERSION_HEX >= 0x030700A3
  3709. tmp_type = tstate->exc_state.exc_type;
  3710. tmp_value = tstate->exc_state.exc_value;
  3711. tmp_tb = tstate->exc_state.exc_traceback;
  3712. tstate->exc_state.exc_type = type;
  3713. tstate->exc_state.exc_value = value;
  3714. tstate->exc_state.exc_traceback = tb;
  3715. #else
  3716. tmp_type = tstate->exc_type;
  3717. tmp_value = tstate->exc_value;
  3718. tmp_tb = tstate->exc_traceback;
  3719. tstate->exc_type = type;
  3720. tstate->exc_value = value;
  3721. tstate->exc_traceback = tb;
  3722. #endif
  3723. Py_XDECREF(tmp_type);
  3724. Py_XDECREF(tmp_value);
  3725. Py_XDECREF(tmp_tb);
  3726. }
  3727. #endif
  3728. /* Import */
  3729. static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
  3730. PyObject *empty_list = 0;
  3731. PyObject *module = 0;
  3732. PyObject *global_dict = 0;
  3733. PyObject *empty_dict = 0;
  3734. PyObject *list;
  3735. #if PY_MAJOR_VERSION < 3
  3736. PyObject *py_import;
  3737. py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import);
  3738. if (!py_import)
  3739. goto bad;
  3740. #endif
  3741. if (from_list)
  3742. list = from_list;
  3743. else {
  3744. empty_list = PyList_New(0);
  3745. if (!empty_list)
  3746. goto bad;
  3747. list = empty_list;
  3748. }
  3749. global_dict = PyModule_GetDict(__pyx_m);
  3750. if (!global_dict)
  3751. goto bad;
  3752. empty_dict = PyDict_New();
  3753. if (!empty_dict)
  3754. goto bad;
  3755. {
  3756. #if PY_MAJOR_VERSION >= 3
  3757. if (level == -1) {
  3758. if (strchr(__Pyx_MODULE_NAME, '.')) {
  3759. module = PyImport_ImportModuleLevelObject(
  3760. name, global_dict, empty_dict, list, 1);
  3761. if (!module) {
  3762. if (!PyErr_ExceptionMatches(PyExc_ImportError))
  3763. goto bad;
  3764. PyErr_Clear();
  3765. }
  3766. }
  3767. level = 0;
  3768. }
  3769. #endif
  3770. if (!module) {
  3771. #if PY_MAJOR_VERSION < 3
  3772. PyObject *py_level = PyInt_FromLong(level);
  3773. if (!py_level)
  3774. goto bad;
  3775. module = PyObject_CallFunctionObjArgs(py_import,
  3776. name, global_dict, empty_dict, list, py_level, NULL);
  3777. Py_DECREF(py_level);
  3778. #else
  3779. module = PyImport_ImportModuleLevelObject(
  3780. name, global_dict, empty_dict, list, level);
  3781. #endif
  3782. }
  3783. }
  3784. bad:
  3785. #if PY_MAJOR_VERSION < 3
  3786. Py_XDECREF(py_import);
  3787. #endif
  3788. Py_XDECREF(empty_list);
  3789. Py_XDECREF(empty_dict);
  3790. return module;
  3791. }
  3792. /* ImportFrom */
  3793. static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) {
  3794. PyObject* value = __Pyx_PyObject_GetAttrStr(module, name);
  3795. if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) {
  3796. PyErr_Format(PyExc_ImportError,
  3797. #if PY_MAJOR_VERSION < 3
  3798. "cannot import name %.230s", PyString_AS_STRING(name));
  3799. #else
  3800. "cannot import name %S", name);
  3801. #endif
  3802. }
  3803. return value;
  3804. }
  3805. /* CLineInTraceback */
  3806. #ifndef CYTHON_CLINE_IN_TRACEBACK
  3807. static int __Pyx_CLineForTraceback(CYTHON_UNUSED PyThreadState *tstate, int c_line) {
  3808. PyObject *use_cline;
  3809. PyObject *ptype, *pvalue, *ptraceback;
  3810. #if CYTHON_COMPILING_IN_CPYTHON
  3811. PyObject **cython_runtime_dict;
  3812. #endif
  3813. if (unlikely(!__pyx_cython_runtime)) {
  3814. return c_line;
  3815. }
  3816. __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback);
  3817. #if CYTHON_COMPILING_IN_CPYTHON
  3818. cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime);
  3819. if (likely(cython_runtime_dict)) {
  3820. use_cline = __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback);
  3821. } else
  3822. #endif
  3823. {
  3824. PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback);
  3825. if (use_cline_obj) {
  3826. use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True;
  3827. Py_DECREF(use_cline_obj);
  3828. } else {
  3829. PyErr_Clear();
  3830. use_cline = NULL;
  3831. }
  3832. }
  3833. if (!use_cline) {
  3834. c_line = 0;
  3835. PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False);
  3836. }
  3837. else if (PyObject_Not(use_cline) != 0) {
  3838. c_line = 0;
  3839. }
  3840. __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback);
  3841. return c_line;
  3842. }
  3843. #endif
  3844. /* CodeObjectCache */
  3845. static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
  3846. int start = 0, mid = 0, end = count - 1;
  3847. if (end >= 0 && code_line > entries[end].code_line) {
  3848. return count;
  3849. }
  3850. while (start < end) {
  3851. mid = start + (end - start) / 2;
  3852. if (code_line < entries[mid].code_line) {
  3853. end = mid;
  3854. } else if (code_line > entries[mid].code_line) {
  3855. start = mid + 1;
  3856. } else {
  3857. return mid;
  3858. }
  3859. }
  3860. if (code_line <= entries[mid].code_line) {
  3861. return mid;
  3862. } else {
  3863. return mid + 1;
  3864. }
  3865. }
  3866. static PyCodeObject *__pyx_find_code_object(int code_line) {
  3867. PyCodeObject* code_object;
  3868. int pos;
  3869. if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
  3870. return NULL;
  3871. }
  3872. pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
  3873. if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
  3874. return NULL;
  3875. }
  3876. code_object = __pyx_code_cache.entries[pos].code_object;
  3877. Py_INCREF(code_object);
  3878. return code_object;
  3879. }
  3880. static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
  3881. int pos, i;
  3882. __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
  3883. if (unlikely(!code_line)) {
  3884. return;
  3885. }
  3886. if (unlikely(!entries)) {
  3887. entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
  3888. if (likely(entries)) {
  3889. __pyx_code_cache.entries = entries;
  3890. __pyx_code_cache.max_count = 64;
  3891. __pyx_code_cache.count = 1;
  3892. entries[0].code_line = code_line;
  3893. entries[0].code_object = code_object;
  3894. Py_INCREF(code_object);
  3895. }
  3896. return;
  3897. }
  3898. pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
  3899. if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
  3900. PyCodeObject* tmp = entries[pos].code_object;
  3901. entries[pos].code_object = code_object;
  3902. Py_DECREF(tmp);
  3903. return;
  3904. }
  3905. if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
  3906. int new_max = __pyx_code_cache.max_count + 64;
  3907. entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
  3908. __pyx_code_cache.entries, (size_t)new_max*sizeof(__Pyx_CodeObjectCacheEntry));
  3909. if (unlikely(!entries)) {
  3910. return;
  3911. }
  3912. __pyx_code_cache.entries = entries;
  3913. __pyx_code_cache.max_count = new_max;
  3914. }
  3915. for (i=__pyx_code_cache.count; i>pos; i--) {
  3916. entries[i] = entries[i-1];
  3917. }
  3918. entries[pos].code_line = code_line;
  3919. entries[pos].code_object = code_object;
  3920. __pyx_code_cache.count++;
  3921. Py_INCREF(code_object);
  3922. }
  3923. /* AddTraceback */
  3924. #include "compile.h"
  3925. #include "frameobject.h"
  3926. #include "traceback.h"
  3927. static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
  3928. const char *funcname, int c_line,
  3929. int py_line, const char *filename) {
  3930. PyCodeObject *py_code = 0;
  3931. PyObject *py_srcfile = 0;
  3932. PyObject *py_funcname = 0;
  3933. #if PY_MAJOR_VERSION < 3
  3934. py_srcfile = PyString_FromString(filename);
  3935. #else
  3936. py_srcfile = PyUnicode_FromString(filename);
  3937. #endif
  3938. if (!py_srcfile) goto bad;
  3939. if (c_line) {
  3940. #if PY_MAJOR_VERSION < 3
  3941. py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
  3942. #else
  3943. py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
  3944. #endif
  3945. }
  3946. else {
  3947. #if PY_MAJOR_VERSION < 3
  3948. py_funcname = PyString_FromString(funcname);
  3949. #else
  3950. py_funcname = PyUnicode_FromString(funcname);
  3951. #endif
  3952. }
  3953. if (!py_funcname) goto bad;
  3954. py_code = __Pyx_PyCode_New(
  3955. 0,
  3956. 0,
  3957. 0,
  3958. 0,
  3959. 0,
  3960. __pyx_empty_bytes, /*PyObject *code,*/
  3961. __pyx_empty_tuple, /*PyObject *consts,*/
  3962. __pyx_empty_tuple, /*PyObject *names,*/
  3963. __pyx_empty_tuple, /*PyObject *varnames,*/
  3964. __pyx_empty_tuple, /*PyObject *freevars,*/
  3965. __pyx_empty_tuple, /*PyObject *cellvars,*/
  3966. py_srcfile, /*PyObject *filename,*/
  3967. py_funcname, /*PyObject *name,*/
  3968. py_line,
  3969. __pyx_empty_bytes /*PyObject *lnotab*/
  3970. );
  3971. Py_DECREF(py_srcfile);
  3972. Py_DECREF(py_funcname);
  3973. return py_code;
  3974. bad:
  3975. Py_XDECREF(py_srcfile);
  3976. Py_XDECREF(py_funcname);
  3977. return NULL;
  3978. }
  3979. static void __Pyx_AddTraceback(const char *funcname, int c_line,
  3980. int py_line, const char *filename) {
  3981. PyCodeObject *py_code = 0;
  3982. PyFrameObject *py_frame = 0;
  3983. PyThreadState *tstate = __Pyx_PyThreadState_Current;
  3984. if (c_line) {
  3985. c_line = __Pyx_CLineForTraceback(tstate, c_line);
  3986. }
  3987. py_code = __pyx_find_code_object(c_line ? -c_line : py_line);
  3988. if (!py_code) {
  3989. py_code = __Pyx_CreateCodeObjectForTraceback(
  3990. funcname, c_line, py_line, filename);
  3991. if (!py_code) goto bad;
  3992. __pyx_insert_code_object(c_line ? -c_line : py_line, py_code);
  3993. }
  3994. py_frame = PyFrame_New(
  3995. tstate, /*PyThreadState *tstate,*/
  3996. py_code, /*PyCodeObject *code,*/
  3997. __pyx_d, /*PyObject *globals,*/
  3998. 0 /*PyObject *locals*/
  3999. );
  4000. if (!py_frame) goto bad;
  4001. __Pyx_PyFrame_SetLineNumber(py_frame, py_line);
  4002. PyTraceBack_Here(py_frame);
  4003. bad:
  4004. Py_XDECREF(py_code);
  4005. Py_XDECREF(py_frame);
  4006. }
  4007. /* CIntToPy */
  4008. static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
  4009. const long neg_one = (long) -1, const_zero = (long) 0;
  4010. const int is_unsigned = neg_one > const_zero;
  4011. if (is_unsigned) {
  4012. if (sizeof(long) < sizeof(long)) {
  4013. return PyInt_FromLong((long) value);
  4014. } else if (sizeof(long) <= sizeof(unsigned long)) {
  4015. return PyLong_FromUnsignedLong((unsigned long) value);
  4016. #ifdef HAVE_LONG_LONG
  4017. } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
  4018. return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
  4019. #endif
  4020. }
  4021. } else {
  4022. if (sizeof(long) <= sizeof(long)) {
  4023. return PyInt_FromLong((long) value);
  4024. #ifdef HAVE_LONG_LONG
  4025. } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
  4026. return PyLong_FromLongLong((PY_LONG_LONG) value);
  4027. #endif
  4028. }
  4029. }
  4030. {
  4031. int one = 1; int little = (int)*(unsigned char *)&one;
  4032. unsigned char *bytes = (unsigned char *)&value;
  4033. return _PyLong_FromByteArray(bytes, sizeof(long),
  4034. little, !is_unsigned);
  4035. }
  4036. }
  4037. /* CIntFromPyVerify */
  4038. #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\
  4039. __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
  4040. #define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\
  4041. __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
  4042. #define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\
  4043. {\
  4044. func_type value = func_value;\
  4045. if (sizeof(target_type) < sizeof(func_type)) {\
  4046. if (unlikely(value != (func_type) (target_type) value)) {\
  4047. func_type zero = 0;\
  4048. if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\
  4049. return (target_type) -1;\
  4050. if (is_unsigned && unlikely(value < zero))\
  4051. goto raise_neg_overflow;\
  4052. else\
  4053. goto raise_overflow;\
  4054. }\
  4055. }\
  4056. return (target_type) value;\
  4057. }
  4058. /* CIntFromPy */
  4059. static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
  4060. const long neg_one = (long) -1, const_zero = (long) 0;
  4061. const int is_unsigned = neg_one > const_zero;
  4062. #if PY_MAJOR_VERSION < 3
  4063. if (likely(PyInt_Check(x))) {
  4064. if (sizeof(long) < sizeof(long)) {
  4065. __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x))
  4066. } else {
  4067. long val = PyInt_AS_LONG(x);
  4068. if (is_unsigned && unlikely(val < 0)) {
  4069. goto raise_neg_overflow;
  4070. }
  4071. return (long) val;
  4072. }
  4073. } else
  4074. #endif
  4075. if (likely(PyLong_Check(x))) {
  4076. if (is_unsigned) {
  4077. #if CYTHON_USE_PYLONG_INTERNALS
  4078. const digit* digits = ((PyLongObject*)x)->ob_digit;
  4079. switch (Py_SIZE(x)) {
  4080. case 0: return (long) 0;
  4081. case 1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0])
  4082. case 2:
  4083. if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
  4084. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  4085. __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  4086. } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) {
  4087. return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
  4088. }
  4089. }
  4090. break;
  4091. case 3:
  4092. if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
  4093. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  4094. __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  4095. } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) {
  4096. return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
  4097. }
  4098. }
  4099. break;
  4100. case 4:
  4101. if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
  4102. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  4103. __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  4104. } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) {
  4105. return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
  4106. }
  4107. }
  4108. break;
  4109. }
  4110. #endif
  4111. #if CYTHON_COMPILING_IN_CPYTHON
  4112. if (unlikely(Py_SIZE(x) < 0)) {
  4113. goto raise_neg_overflow;
  4114. }
  4115. #else
  4116. {
  4117. int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
  4118. if (unlikely(result < 0))
  4119. return (long) -1;
  4120. if (unlikely(result == 1))
  4121. goto raise_neg_overflow;
  4122. }
  4123. #endif
  4124. if (sizeof(long) <= sizeof(unsigned long)) {
  4125. __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
  4126. #ifdef HAVE_LONG_LONG
  4127. } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
  4128. __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
  4129. #endif
  4130. }
  4131. } else {
  4132. #if CYTHON_USE_PYLONG_INTERNALS
  4133. const digit* digits = ((PyLongObject*)x)->ob_digit;
  4134. switch (Py_SIZE(x)) {
  4135. case 0: return (long) 0;
  4136. case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0]))
  4137. case 1: __PYX_VERIFY_RETURN_INT(long, digit, +digits[0])
  4138. case -2:
  4139. if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) {
  4140. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  4141. __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  4142. } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
  4143. return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
  4144. }
  4145. }
  4146. break;
  4147. case 2:
  4148. if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
  4149. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  4150. __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  4151. } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
  4152. return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
  4153. }
  4154. }
  4155. break;
  4156. case -3:
  4157. if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
  4158. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  4159. __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  4160. } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
  4161. return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
  4162. }
  4163. }
  4164. break;
  4165. case 3:
  4166. if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
  4167. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  4168. __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  4169. } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
  4170. return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
  4171. }
  4172. }
  4173. break;
  4174. case -4:
  4175. if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
  4176. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  4177. __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  4178. } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
  4179. return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
  4180. }
  4181. }
  4182. break;
  4183. case 4:
  4184. if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
  4185. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  4186. __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  4187. } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
  4188. return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
  4189. }
  4190. }
  4191. break;
  4192. }
  4193. #endif
  4194. if (sizeof(long) <= sizeof(long)) {
  4195. __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
  4196. #ifdef HAVE_LONG_LONG
  4197. } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
  4198. __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
  4199. #endif
  4200. }
  4201. }
  4202. {
  4203. #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
  4204. PyErr_SetString(PyExc_RuntimeError,
  4205. "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
  4206. #else
  4207. long val;
  4208. PyObject *v = __Pyx_PyNumber_IntOrLong(x);
  4209. #if PY_MAJOR_VERSION < 3
  4210. if (likely(v) && !PyLong_Check(v)) {
  4211. PyObject *tmp = v;
  4212. v = PyNumber_Long(tmp);
  4213. Py_DECREF(tmp);
  4214. }
  4215. #endif
  4216. if (likely(v)) {
  4217. int one = 1; int is_little = (int)*(unsigned char *)&one;
  4218. unsigned char *bytes = (unsigned char *)&val;
  4219. int ret = _PyLong_AsByteArray((PyLongObject *)v,
  4220. bytes, sizeof(val),
  4221. is_little, !is_unsigned);
  4222. Py_DECREF(v);
  4223. if (likely(!ret))
  4224. return val;
  4225. }
  4226. #endif
  4227. return (long) -1;
  4228. }
  4229. } else {
  4230. long val;
  4231. PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
  4232. if (!tmp) return (long) -1;
  4233. val = __Pyx_PyInt_As_long(tmp);
  4234. Py_DECREF(tmp);
  4235. return val;
  4236. }
  4237. raise_overflow:
  4238. PyErr_SetString(PyExc_OverflowError,
  4239. "value too large to convert to long");
  4240. return (long) -1;
  4241. raise_neg_overflow:
  4242. PyErr_SetString(PyExc_OverflowError,
  4243. "can't convert negative value to long");
  4244. return (long) -1;
  4245. }
  4246. /* CIntFromPy */
  4247. static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
  4248. const int neg_one = (int) -1, const_zero = (int) 0;
  4249. const int is_unsigned = neg_one > const_zero;
  4250. #if PY_MAJOR_VERSION < 3
  4251. if (likely(PyInt_Check(x))) {
  4252. if (sizeof(int) < sizeof(long)) {
  4253. __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x))
  4254. } else {
  4255. long val = PyInt_AS_LONG(x);
  4256. if (is_unsigned && unlikely(val < 0)) {
  4257. goto raise_neg_overflow;
  4258. }
  4259. return (int) val;
  4260. }
  4261. } else
  4262. #endif
  4263. if (likely(PyLong_Check(x))) {
  4264. if (is_unsigned) {
  4265. #if CYTHON_USE_PYLONG_INTERNALS
  4266. const digit* digits = ((PyLongObject*)x)->ob_digit;
  4267. switch (Py_SIZE(x)) {
  4268. case 0: return (int) 0;
  4269. case 1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0])
  4270. case 2:
  4271. if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
  4272. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  4273. __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  4274. } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) {
  4275. return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
  4276. }
  4277. }
  4278. break;
  4279. case 3:
  4280. if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
  4281. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  4282. __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  4283. } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) {
  4284. return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
  4285. }
  4286. }
  4287. break;
  4288. case 4:
  4289. if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
  4290. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  4291. __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  4292. } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) {
  4293. return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
  4294. }
  4295. }
  4296. break;
  4297. }
  4298. #endif
  4299. #if CYTHON_COMPILING_IN_CPYTHON
  4300. if (unlikely(Py_SIZE(x) < 0)) {
  4301. goto raise_neg_overflow;
  4302. }
  4303. #else
  4304. {
  4305. int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
  4306. if (unlikely(result < 0))
  4307. return (int) -1;
  4308. if (unlikely(result == 1))
  4309. goto raise_neg_overflow;
  4310. }
  4311. #endif
  4312. if (sizeof(int) <= sizeof(unsigned long)) {
  4313. __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
  4314. #ifdef HAVE_LONG_LONG
  4315. } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
  4316. __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
  4317. #endif
  4318. }
  4319. } else {
  4320. #if CYTHON_USE_PYLONG_INTERNALS
  4321. const digit* digits = ((PyLongObject*)x)->ob_digit;
  4322. switch (Py_SIZE(x)) {
  4323. case 0: return (int) 0;
  4324. case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0]))
  4325. case 1: __PYX_VERIFY_RETURN_INT(int, digit, +digits[0])
  4326. case -2:
  4327. if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) {
  4328. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  4329. __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  4330. } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
  4331. return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
  4332. }
  4333. }
  4334. break;
  4335. case 2:
  4336. if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
  4337. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  4338. __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  4339. } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
  4340. return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
  4341. }
  4342. }
  4343. break;
  4344. case -3:
  4345. if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
  4346. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  4347. __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  4348. } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
  4349. return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
  4350. }
  4351. }
  4352. break;
  4353. case 3:
  4354. if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
  4355. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  4356. __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  4357. } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
  4358. return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
  4359. }
  4360. }
  4361. break;
  4362. case -4:
  4363. if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
  4364. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  4365. __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  4366. } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
  4367. return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
  4368. }
  4369. }
  4370. break;
  4371. case 4:
  4372. if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
  4373. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  4374. __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  4375. } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
  4376. return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
  4377. }
  4378. }
  4379. break;
  4380. }
  4381. #endif
  4382. if (sizeof(int) <= sizeof(long)) {
  4383. __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
  4384. #ifdef HAVE_LONG_LONG
  4385. } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
  4386. __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
  4387. #endif
  4388. }
  4389. }
  4390. {
  4391. #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
  4392. PyErr_SetString(PyExc_RuntimeError,
  4393. "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
  4394. #else
  4395. int val;
  4396. PyObject *v = __Pyx_PyNumber_IntOrLong(x);
  4397. #if PY_MAJOR_VERSION < 3
  4398. if (likely(v) && !PyLong_Check(v)) {
  4399. PyObject *tmp = v;
  4400. v = PyNumber_Long(tmp);
  4401. Py_DECREF(tmp);
  4402. }
  4403. #endif
  4404. if (likely(v)) {
  4405. int one = 1; int is_little = (int)*(unsigned char *)&one;
  4406. unsigned char *bytes = (unsigned char *)&val;
  4407. int ret = _PyLong_AsByteArray((PyLongObject *)v,
  4408. bytes, sizeof(val),
  4409. is_little, !is_unsigned);
  4410. Py_DECREF(v);
  4411. if (likely(!ret))
  4412. return val;
  4413. }
  4414. #endif
  4415. return (int) -1;
  4416. }
  4417. } else {
  4418. int val;
  4419. PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
  4420. if (!tmp) return (int) -1;
  4421. val = __Pyx_PyInt_As_int(tmp);
  4422. Py_DECREF(tmp);
  4423. return val;
  4424. }
  4425. raise_overflow:
  4426. PyErr_SetString(PyExc_OverflowError,
  4427. "value too large to convert to int");
  4428. return (int) -1;
  4429. raise_neg_overflow:
  4430. PyErr_SetString(PyExc_OverflowError,
  4431. "can't convert negative value to int");
  4432. return (int) -1;
  4433. }
  4434. /* FastTypeChecks */
  4435. #if CYTHON_COMPILING_IN_CPYTHON
  4436. static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) {
  4437. while (a) {
  4438. a = a->tp_base;
  4439. if (a == b)
  4440. return 1;
  4441. }
  4442. return b == &PyBaseObject_Type;
  4443. }
  4444. static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) {
  4445. PyObject *mro;
  4446. if (a == b) return 1;
  4447. mro = a->tp_mro;
  4448. if (likely(mro)) {
  4449. Py_ssize_t i, n;
  4450. n = PyTuple_GET_SIZE(mro);
  4451. for (i = 0; i < n; i++) {
  4452. if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b)
  4453. return 1;
  4454. }
  4455. return 0;
  4456. }
  4457. return __Pyx_InBases(a, b);
  4458. }
  4459. #if PY_MAJOR_VERSION == 2
  4460. static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) {
  4461. PyObject *exception, *value, *tb;
  4462. int res;
  4463. __Pyx_PyThreadState_declare
  4464. __Pyx_PyThreadState_assign
  4465. __Pyx_ErrFetch(&exception, &value, &tb);
  4466. res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0;
  4467. if (unlikely(res == -1)) {
  4468. PyErr_WriteUnraisable(err);
  4469. res = 0;
  4470. }
  4471. if (!res) {
  4472. res = PyObject_IsSubclass(err, exc_type2);
  4473. if (unlikely(res == -1)) {
  4474. PyErr_WriteUnraisable(err);
  4475. res = 0;
  4476. }
  4477. }
  4478. __Pyx_ErrRestore(exception, value, tb);
  4479. return res;
  4480. }
  4481. #else
  4482. static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) {
  4483. int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0;
  4484. if (!res) {
  4485. res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2);
  4486. }
  4487. return res;
  4488. }
  4489. #endif
  4490. static int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
  4491. Py_ssize_t i, n;
  4492. assert(PyExceptionClass_Check(exc_type));
  4493. n = PyTuple_GET_SIZE(tuple);
  4494. #if PY_MAJOR_VERSION >= 3
  4495. for (i=0; i<n; i++) {
  4496. if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
  4497. }
  4498. #endif
  4499. for (i=0; i<n; i++) {
  4500. PyObject *t = PyTuple_GET_ITEM(tuple, i);
  4501. #if PY_MAJOR_VERSION < 3
  4502. if (likely(exc_type == t)) return 1;
  4503. #endif
  4504. if (likely(PyExceptionClass_Check(t))) {
  4505. if (__Pyx_inner_PyErr_GivenExceptionMatches2(exc_type, NULL, t)) return 1;
  4506. } else {
  4507. }
  4508. }
  4509. return 0;
  4510. }
  4511. static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject* exc_type) {
  4512. if (likely(err == exc_type)) return 1;
  4513. if (likely(PyExceptionClass_Check(err))) {
  4514. if (likely(PyExceptionClass_Check(exc_type))) {
  4515. return __Pyx_inner_PyErr_GivenExceptionMatches2(err, NULL, exc_type);
  4516. } else if (likely(PyTuple_Check(exc_type))) {
  4517. return __Pyx_PyErr_GivenExceptionMatchesTuple(err, exc_type);
  4518. } else {
  4519. }
  4520. }
  4521. return PyErr_GivenExceptionMatches(err, exc_type);
  4522. }
  4523. static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *exc_type1, PyObject *exc_type2) {
  4524. assert(PyExceptionClass_Check(exc_type1));
  4525. assert(PyExceptionClass_Check(exc_type2));
  4526. if (likely(err == exc_type1 || err == exc_type2)) return 1;
  4527. if (likely(PyExceptionClass_Check(err))) {
  4528. return __Pyx_inner_PyErr_GivenExceptionMatches2(err, exc_type1, exc_type2);
  4529. }
  4530. return (PyErr_GivenExceptionMatches(err, exc_type1) || PyErr_GivenExceptionMatches(err, exc_type2));
  4531. }
  4532. #endif
  4533. /* CheckBinaryVersion */
  4534. static int __Pyx_check_binary_version(void) {
  4535. char ctversion[4], rtversion[4];
  4536. PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
  4537. PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
  4538. if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
  4539. char message[200];
  4540. PyOS_snprintf(message, sizeof(message),
  4541. "compiletime version %s of module '%.100s' "
  4542. "does not match runtime version %s",
  4543. ctversion, __Pyx_MODULE_NAME, rtversion);
  4544. return PyErr_WarnEx(NULL, message, 1);
  4545. }
  4546. return 0;
  4547. }
  4548. /* PyObjectSetAttrStr */
  4549. #if CYTHON_USE_TYPE_SLOTS
  4550. static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value) {
  4551. PyTypeObject* tp = Py_TYPE(obj);
  4552. if (likely(tp->tp_setattro))
  4553. return tp->tp_setattro(obj, attr_name, value);
  4554. #if PY_MAJOR_VERSION < 3
  4555. if (likely(tp->tp_setattr))
  4556. return tp->tp_setattr(obj, PyString_AS_STRING(attr_name), value);
  4557. #endif
  4558. return PyObject_SetAttr(obj, attr_name, value);
  4559. }
  4560. #endif
  4561. /* VoidPtrExport */
  4562. static int __Pyx_ExportVoidPtr(PyObject *name, void *p, const char *sig) {
  4563. PyObject *d;
  4564. PyObject *cobj = 0;
  4565. d = PyDict_GetItem(__pyx_d, __pyx_n_s_pyx_capi);
  4566. Py_XINCREF(d);
  4567. if (!d) {
  4568. d = PyDict_New();
  4569. if (!d)
  4570. goto bad;
  4571. if (__Pyx_PyObject_SetAttrStr(__pyx_m, __pyx_n_s_pyx_capi, d) < 0)
  4572. goto bad;
  4573. }
  4574. #if PY_VERSION_HEX >= 0x02070000
  4575. cobj = PyCapsule_New(p, sig, 0);
  4576. #else
  4577. cobj = PyCObject_FromVoidPtrAndDesc(p, (void *)sig, 0);
  4578. #endif
  4579. if (!cobj)
  4580. goto bad;
  4581. if (PyDict_SetItem(d, name, cobj) < 0)
  4582. goto bad;
  4583. Py_DECREF(cobj);
  4584. Py_DECREF(d);
  4585. return 0;
  4586. bad:
  4587. Py_XDECREF(cobj);
  4588. Py_XDECREF(d);
  4589. return -1;
  4590. }
  4591. /* FunctionExport */
  4592. static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig) {
  4593. PyObject *d = 0;
  4594. PyObject *cobj = 0;
  4595. union {
  4596. void (*fp)(void);
  4597. void *p;
  4598. } tmp;
  4599. d = PyObject_GetAttrString(__pyx_m, (char *)"__pyx_capi__");
  4600. if (!d) {
  4601. PyErr_Clear();
  4602. d = PyDict_New();
  4603. if (!d)
  4604. goto bad;
  4605. Py_INCREF(d);
  4606. if (PyModule_AddObject(__pyx_m, (char *)"__pyx_capi__", d) < 0)
  4607. goto bad;
  4608. }
  4609. tmp.fp = f;
  4610. #if PY_VERSION_HEX >= 0x02070000
  4611. cobj = PyCapsule_New(tmp.p, sig, 0);
  4612. #else
  4613. cobj = PyCObject_FromVoidPtrAndDesc(tmp.p, (void *)sig, 0);
  4614. #endif
  4615. if (!cobj)
  4616. goto bad;
  4617. if (PyDict_SetItemString(d, name, cobj) < 0)
  4618. goto bad;
  4619. Py_DECREF(cobj);
  4620. Py_DECREF(d);
  4621. return 0;
  4622. bad:
  4623. Py_XDECREF(cobj);
  4624. Py_XDECREF(d);
  4625. return -1;
  4626. }
  4627. /* ModuleImport */
  4628. #ifndef __PYX_HAVE_RT_ImportModule
  4629. #define __PYX_HAVE_RT_ImportModule
  4630. static PyObject *__Pyx_ImportModule(const char *name) {
  4631. PyObject *py_name = 0;
  4632. PyObject *py_module = 0;
  4633. py_name = __Pyx_PyIdentifier_FromString(name);
  4634. if (!py_name)
  4635. goto bad;
  4636. py_module = PyImport_Import(py_name);
  4637. Py_DECREF(py_name);
  4638. return py_module;
  4639. bad:
  4640. Py_XDECREF(py_name);
  4641. return 0;
  4642. }
  4643. #endif
  4644. /* TypeImport */
  4645. #ifndef __PYX_HAVE_RT_ImportType
  4646. #define __PYX_HAVE_RT_ImportType
  4647. static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name,
  4648. size_t size, int strict)
  4649. {
  4650. PyObject *py_module = 0;
  4651. PyObject *result = 0;
  4652. PyObject *py_name = 0;
  4653. char warning[200];
  4654. Py_ssize_t basicsize;
  4655. #ifdef Py_LIMITED_API
  4656. PyObject *py_basicsize;
  4657. #endif
  4658. py_module = __Pyx_ImportModule(module_name);
  4659. if (!py_module)
  4660. goto bad;
  4661. py_name = __Pyx_PyIdentifier_FromString(class_name);
  4662. if (!py_name)
  4663. goto bad;
  4664. result = PyObject_GetAttr(py_module, py_name);
  4665. Py_DECREF(py_name);
  4666. py_name = 0;
  4667. Py_DECREF(py_module);
  4668. py_module = 0;
  4669. if (!result)
  4670. goto bad;
  4671. if (!PyType_Check(result)) {
  4672. PyErr_Format(PyExc_TypeError,
  4673. "%.200s.%.200s is not a type object",
  4674. module_name, class_name);
  4675. goto bad;
  4676. }
  4677. #ifndef Py_LIMITED_API
  4678. basicsize = ((PyTypeObject *)result)->tp_basicsize;
  4679. #else
  4680. py_basicsize = PyObject_GetAttrString(result, "__basicsize__");
  4681. if (!py_basicsize)
  4682. goto bad;
  4683. basicsize = PyLong_AsSsize_t(py_basicsize);
  4684. Py_DECREF(py_basicsize);
  4685. py_basicsize = 0;
  4686. if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred())
  4687. goto bad;
  4688. #endif
  4689. if (!strict && (size_t)basicsize > size) {
  4690. PyOS_snprintf(warning, sizeof(warning),
  4691. "%s.%s size changed, may indicate binary incompatibility. Expected %zd, got %zd",
  4692. module_name, class_name, basicsize, size);
  4693. if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
  4694. }
  4695. else if ((size_t)basicsize != size) {
  4696. PyErr_Format(PyExc_ValueError,
  4697. "%.200s.%.200s has the wrong size, try recompiling. Expected %zd, got %zd",
  4698. module_name, class_name, basicsize, size);
  4699. goto bad;
  4700. }
  4701. return (PyTypeObject *)result;
  4702. bad:
  4703. Py_XDECREF(py_module);
  4704. Py_XDECREF(result);
  4705. return NULL;
  4706. }
  4707. #endif
  4708. /* InitStrings */
  4709. static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
  4710. while (t->p) {
  4711. #if PY_MAJOR_VERSION < 3
  4712. if (t->is_unicode) {
  4713. *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
  4714. } else if (t->intern) {
  4715. *t->p = PyString_InternFromString(t->s);
  4716. } else {
  4717. *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
  4718. }
  4719. #else
  4720. if (t->is_unicode | t->is_str) {
  4721. if (t->intern) {
  4722. *t->p = PyUnicode_InternFromString(t->s);
  4723. } else if (t->encoding) {
  4724. *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
  4725. } else {
  4726. *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
  4727. }
  4728. } else {
  4729. *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
  4730. }
  4731. #endif
  4732. if (!*t->p)
  4733. return -1;
  4734. if (PyObject_Hash(*t->p) == -1)
  4735. return -1;
  4736. ++t;
  4737. }
  4738. return 0;
  4739. }
  4740. static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
  4741. return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str));
  4742. }
  4743. static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) {
  4744. Py_ssize_t ignore;
  4745. return __Pyx_PyObject_AsStringAndSize(o, &ignore);
  4746. }
  4747. #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
  4748. #if !CYTHON_PEP393_ENABLED
  4749. static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
  4750. char* defenc_c;
  4751. PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL);
  4752. if (!defenc) return NULL;
  4753. defenc_c = PyBytes_AS_STRING(defenc);
  4754. #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
  4755. {
  4756. char* end = defenc_c + PyBytes_GET_SIZE(defenc);
  4757. char* c;
  4758. for (c = defenc_c; c < end; c++) {
  4759. if ((unsigned char) (*c) >= 128) {
  4760. PyUnicode_AsASCIIString(o);
  4761. return NULL;
  4762. }
  4763. }
  4764. }
  4765. #endif
  4766. *length = PyBytes_GET_SIZE(defenc);
  4767. return defenc_c;
  4768. }
  4769. #else
  4770. static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
  4771. if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL;
  4772. #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
  4773. if (likely(PyUnicode_IS_ASCII(o))) {
  4774. *length = PyUnicode_GET_LENGTH(o);
  4775. return PyUnicode_AsUTF8(o);
  4776. } else {
  4777. PyUnicode_AsASCIIString(o);
  4778. return NULL;
  4779. }
  4780. #else
  4781. return PyUnicode_AsUTF8AndSize(o, length);
  4782. #endif
  4783. }
  4784. #endif
  4785. #endif
  4786. static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
  4787. #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
  4788. if (
  4789. #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
  4790. __Pyx_sys_getdefaultencoding_not_ascii &&
  4791. #endif
  4792. PyUnicode_Check(o)) {
  4793. return __Pyx_PyUnicode_AsStringAndSize(o, length);
  4794. } else
  4795. #endif
  4796. #if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
  4797. if (PyByteArray_Check(o)) {
  4798. *length = PyByteArray_GET_SIZE(o);
  4799. return PyByteArray_AS_STRING(o);
  4800. } else
  4801. #endif
  4802. {
  4803. char* result;
  4804. int r = PyBytes_AsStringAndSize(o, &result, length);
  4805. if (unlikely(r < 0)) {
  4806. return NULL;
  4807. } else {
  4808. return result;
  4809. }
  4810. }
  4811. }
  4812. static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
  4813. int is_true = x == Py_True;
  4814. if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
  4815. else return PyObject_IsTrue(x);
  4816. }
  4817. static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) {
  4818. #if PY_MAJOR_VERSION >= 3
  4819. if (PyLong_Check(result)) {
  4820. if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
  4821. "__int__ returned non-int (type %.200s). "
  4822. "The ability to return an instance of a strict subclass of int "
  4823. "is deprecated, and may be removed in a future version of Python.",
  4824. Py_TYPE(result)->tp_name)) {
  4825. Py_DECREF(result);
  4826. return NULL;
  4827. }
  4828. return result;
  4829. }
  4830. #endif
  4831. PyErr_Format(PyExc_TypeError,
  4832. "__%.4s__ returned non-%.4s (type %.200s)",
  4833. type_name, type_name, Py_TYPE(result)->tp_name);
  4834. Py_DECREF(result);
  4835. return NULL;
  4836. }
  4837. static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) {
  4838. #if CYTHON_USE_TYPE_SLOTS
  4839. PyNumberMethods *m;
  4840. #endif
  4841. const char *name = NULL;
  4842. PyObject *res = NULL;
  4843. #if PY_MAJOR_VERSION < 3
  4844. if (likely(PyInt_Check(x) || PyLong_Check(x)))
  4845. #else
  4846. if (likely(PyLong_Check(x)))
  4847. #endif
  4848. return __Pyx_NewRef(x);
  4849. #if CYTHON_USE_TYPE_SLOTS
  4850. m = Py_TYPE(x)->tp_as_number;
  4851. #if PY_MAJOR_VERSION < 3
  4852. if (m && m->nb_int) {
  4853. name = "int";
  4854. res = m->nb_int(x);
  4855. }
  4856. else if (m && m->nb_long) {
  4857. name = "long";
  4858. res = m->nb_long(x);
  4859. }
  4860. #else
  4861. if (likely(m && m->nb_int)) {
  4862. name = "int";
  4863. res = m->nb_int(x);
  4864. }
  4865. #endif
  4866. #else
  4867. if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) {
  4868. res = PyNumber_Int(x);
  4869. }
  4870. #endif
  4871. if (likely(res)) {
  4872. #if PY_MAJOR_VERSION < 3
  4873. if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) {
  4874. #else
  4875. if (unlikely(!PyLong_CheckExact(res))) {
  4876. #endif
  4877. return __Pyx_PyNumber_IntOrLongWrongResultType(res, name);
  4878. }
  4879. }
  4880. else if (!PyErr_Occurred()) {
  4881. PyErr_SetString(PyExc_TypeError,
  4882. "an integer is required");
  4883. }
  4884. return res;
  4885. }
  4886. static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
  4887. Py_ssize_t ival;
  4888. PyObject *x;
  4889. #if PY_MAJOR_VERSION < 3
  4890. if (likely(PyInt_CheckExact(b))) {
  4891. if (sizeof(Py_ssize_t) >= sizeof(long))
  4892. return PyInt_AS_LONG(b);
  4893. else
  4894. return PyInt_AsSsize_t(x);
  4895. }
  4896. #endif
  4897. if (likely(PyLong_CheckExact(b))) {
  4898. #if CYTHON_USE_PYLONG_INTERNALS
  4899. const digit* digits = ((PyLongObject*)b)->ob_digit;
  4900. const Py_ssize_t size = Py_SIZE(b);
  4901. if (likely(__Pyx_sst_abs(size) <= 1)) {
  4902. ival = likely(size) ? digits[0] : 0;
  4903. if (size == -1) ival = -ival;
  4904. return ival;
  4905. } else {
  4906. switch (size) {
  4907. case 2:
  4908. if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
  4909. return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
  4910. }
  4911. break;
  4912. case -2:
  4913. if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
  4914. return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
  4915. }
  4916. break;
  4917. case 3:
  4918. if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
  4919. return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
  4920. }
  4921. break;
  4922. case -3:
  4923. if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
  4924. return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
  4925. }
  4926. break;
  4927. case 4:
  4928. if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
  4929. return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
  4930. }
  4931. break;
  4932. case -4:
  4933. if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
  4934. return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
  4935. }
  4936. break;
  4937. }
  4938. }
  4939. #endif
  4940. return PyLong_AsSsize_t(b);
  4941. }
  4942. x = PyNumber_Index(b);
  4943. if (!x) return -1;
  4944. ival = PyInt_AsSsize_t(x);
  4945. Py_DECREF(x);
  4946. return ival;
  4947. }
  4948. static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) {
  4949. return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False);
  4950. }
  4951. static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
  4952. return PyInt_FromSize_t(ival);
  4953. }
  4954. #endif /* Py_PYTHON_H */