gevent._semaphore.c 355 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807
  1. /* Generated by Cython 0.25.2 */
  2. #define PY_SSIZE_T_CLEAN
  3. #include "Python.h"
  4. #ifndef Py_PYTHON_H
  5. #error Python headers needed to compile C extensions, please install development version of Python.
  6. #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03020000)
  7. #error Cython requires Python 2.6+ or Python 3.2+.
  8. #else
  9. #define CYTHON_ABI "0_25_2"
  10. #include <stddef.h>
  11. #ifndef offsetof
  12. #define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
  13. #endif
  14. #if !defined(WIN32) && !defined(MS_WINDOWS)
  15. #ifndef __stdcall
  16. #define __stdcall
  17. #endif
  18. #ifndef __cdecl
  19. #define __cdecl
  20. #endif
  21. #ifndef __fastcall
  22. #define __fastcall
  23. #endif
  24. #endif
  25. #ifndef DL_IMPORT
  26. #define DL_IMPORT(t) t
  27. #endif
  28. #ifndef DL_EXPORT
  29. #define DL_EXPORT(t) t
  30. #endif
  31. #ifndef HAVE_LONG_LONG
  32. #if PY_VERSION_HEX >= 0x03030000 || (PY_MAJOR_VERSION == 2 && PY_VERSION_HEX >= 0x02070000)
  33. #define HAVE_LONG_LONG
  34. #endif
  35. #endif
  36. #ifndef PY_LONG_LONG
  37. #define PY_LONG_LONG LONG_LONG
  38. #endif
  39. #ifndef Py_HUGE_VAL
  40. #define Py_HUGE_VAL HUGE_VAL
  41. #endif
  42. #ifdef PYPY_VERSION
  43. #define CYTHON_COMPILING_IN_PYPY 1
  44. #define CYTHON_COMPILING_IN_PYSTON 0
  45. #define CYTHON_COMPILING_IN_CPYTHON 0
  46. #undef CYTHON_USE_TYPE_SLOTS
  47. #define CYTHON_USE_TYPE_SLOTS 0
  48. #undef CYTHON_USE_ASYNC_SLOTS
  49. #define CYTHON_USE_ASYNC_SLOTS 0
  50. #undef CYTHON_USE_PYLIST_INTERNALS
  51. #define CYTHON_USE_PYLIST_INTERNALS 0
  52. #undef CYTHON_USE_UNICODE_INTERNALS
  53. #define CYTHON_USE_UNICODE_INTERNALS 0
  54. #undef CYTHON_USE_UNICODE_WRITER
  55. #define CYTHON_USE_UNICODE_WRITER 0
  56. #undef CYTHON_USE_PYLONG_INTERNALS
  57. #define CYTHON_USE_PYLONG_INTERNALS 0
  58. #undef CYTHON_AVOID_BORROWED_REFS
  59. #define CYTHON_AVOID_BORROWED_REFS 1
  60. #undef CYTHON_ASSUME_SAFE_MACROS
  61. #define CYTHON_ASSUME_SAFE_MACROS 0
  62. #undef CYTHON_UNPACK_METHODS
  63. #define CYTHON_UNPACK_METHODS 0
  64. #undef CYTHON_FAST_THREAD_STATE
  65. #define CYTHON_FAST_THREAD_STATE 0
  66. #undef CYTHON_FAST_PYCALL
  67. #define CYTHON_FAST_PYCALL 0
  68. #elif defined(PYSTON_VERSION)
  69. #define CYTHON_COMPILING_IN_PYPY 0
  70. #define CYTHON_COMPILING_IN_PYSTON 1
  71. #define CYTHON_COMPILING_IN_CPYTHON 0
  72. #ifndef CYTHON_USE_TYPE_SLOTS
  73. #define CYTHON_USE_TYPE_SLOTS 1
  74. #endif
  75. #undef CYTHON_USE_ASYNC_SLOTS
  76. #define CYTHON_USE_ASYNC_SLOTS 0
  77. #undef CYTHON_USE_PYLIST_INTERNALS
  78. #define CYTHON_USE_PYLIST_INTERNALS 0
  79. #ifndef CYTHON_USE_UNICODE_INTERNALS
  80. #define CYTHON_USE_UNICODE_INTERNALS 1
  81. #endif
  82. #undef CYTHON_USE_UNICODE_WRITER
  83. #define CYTHON_USE_UNICODE_WRITER 0
  84. #undef CYTHON_USE_PYLONG_INTERNALS
  85. #define CYTHON_USE_PYLONG_INTERNALS 0
  86. #ifndef CYTHON_AVOID_BORROWED_REFS
  87. #define CYTHON_AVOID_BORROWED_REFS 0
  88. #endif
  89. #ifndef CYTHON_ASSUME_SAFE_MACROS
  90. #define CYTHON_ASSUME_SAFE_MACROS 1
  91. #endif
  92. #ifndef CYTHON_UNPACK_METHODS
  93. #define CYTHON_UNPACK_METHODS 1
  94. #endif
  95. #undef CYTHON_FAST_THREAD_STATE
  96. #define CYTHON_FAST_THREAD_STATE 0
  97. #undef CYTHON_FAST_PYCALL
  98. #define CYTHON_FAST_PYCALL 0
  99. #else
  100. #define CYTHON_COMPILING_IN_PYPY 0
  101. #define CYTHON_COMPILING_IN_PYSTON 0
  102. #define CYTHON_COMPILING_IN_CPYTHON 1
  103. #ifndef CYTHON_USE_TYPE_SLOTS
  104. #define CYTHON_USE_TYPE_SLOTS 1
  105. #endif
  106. #if PY_MAJOR_VERSION < 3
  107. #undef CYTHON_USE_ASYNC_SLOTS
  108. #define CYTHON_USE_ASYNC_SLOTS 0
  109. #elif !defined(CYTHON_USE_ASYNC_SLOTS)
  110. #define CYTHON_USE_ASYNC_SLOTS 1
  111. #endif
  112. #if PY_VERSION_HEX < 0x02070000
  113. #undef CYTHON_USE_PYLONG_INTERNALS
  114. #define CYTHON_USE_PYLONG_INTERNALS 0
  115. #elif !defined(CYTHON_USE_PYLONG_INTERNALS)
  116. #define CYTHON_USE_PYLONG_INTERNALS 1
  117. #endif
  118. #ifndef CYTHON_USE_PYLIST_INTERNALS
  119. #define CYTHON_USE_PYLIST_INTERNALS 1
  120. #endif
  121. #ifndef CYTHON_USE_UNICODE_INTERNALS
  122. #define CYTHON_USE_UNICODE_INTERNALS 1
  123. #endif
  124. #if PY_VERSION_HEX < 0x030300F0
  125. #undef CYTHON_USE_UNICODE_WRITER
  126. #define CYTHON_USE_UNICODE_WRITER 0
  127. #elif !defined(CYTHON_USE_UNICODE_WRITER)
  128. #define CYTHON_USE_UNICODE_WRITER 1
  129. #endif
  130. #ifndef CYTHON_AVOID_BORROWED_REFS
  131. #define CYTHON_AVOID_BORROWED_REFS 0
  132. #endif
  133. #ifndef CYTHON_ASSUME_SAFE_MACROS
  134. #define CYTHON_ASSUME_SAFE_MACROS 1
  135. #endif
  136. #ifndef CYTHON_UNPACK_METHODS
  137. #define CYTHON_UNPACK_METHODS 1
  138. #endif
  139. #ifndef CYTHON_FAST_THREAD_STATE
  140. #define CYTHON_FAST_THREAD_STATE 1
  141. #endif
  142. #ifndef CYTHON_FAST_PYCALL
  143. #define CYTHON_FAST_PYCALL 1
  144. #endif
  145. #endif
  146. #if !defined(CYTHON_FAST_PYCCALL)
  147. #define CYTHON_FAST_PYCCALL (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1)
  148. #endif
  149. #if CYTHON_USE_PYLONG_INTERNALS
  150. #include "longintrepr.h"
  151. #undef SHIFT
  152. #undef BASE
  153. #undef MASK
  154. #endif
  155. #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
  156. #define Py_OptimizeFlag 0
  157. #endif
  158. #define __PYX_BUILD_PY_SSIZE_T "n"
  159. #define CYTHON_FORMAT_SSIZE_T "z"
  160. #if PY_MAJOR_VERSION < 3
  161. #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
  162. #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
  163. PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  164. #define __Pyx_DefaultClassType PyClass_Type
  165. #else
  166. #define __Pyx_BUILTIN_MODULE_NAME "builtins"
  167. #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
  168. PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  169. #define __Pyx_DefaultClassType PyType_Type
  170. #endif
  171. #ifndef Py_TPFLAGS_CHECKTYPES
  172. #define Py_TPFLAGS_CHECKTYPES 0
  173. #endif
  174. #ifndef Py_TPFLAGS_HAVE_INDEX
  175. #define Py_TPFLAGS_HAVE_INDEX 0
  176. #endif
  177. #ifndef Py_TPFLAGS_HAVE_NEWBUFFER
  178. #define Py_TPFLAGS_HAVE_NEWBUFFER 0
  179. #endif
  180. #ifndef Py_TPFLAGS_HAVE_FINALIZE
  181. #define Py_TPFLAGS_HAVE_FINALIZE 0
  182. #endif
  183. #ifndef METH_FASTCALL
  184. #define METH_FASTCALL 0x80
  185. typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject **args,
  186. Py_ssize_t nargs, PyObject *kwnames);
  187. #else
  188. #define __Pyx_PyCFunctionFast _PyCFunctionFast
  189. #endif
  190. #if CYTHON_FAST_PYCCALL
  191. #define __Pyx_PyFastCFunction_Check(func)\
  192. ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST)))))
  193. #else
  194. #define __Pyx_PyFastCFunction_Check(func) 0
  195. #endif
  196. #if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
  197. #define CYTHON_PEP393_ENABLED 1
  198. #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\
  199. 0 : _PyUnicode_Ready((PyObject *)(op)))
  200. #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u)
  201. #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
  202. #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) PyUnicode_MAX_CHAR_VALUE(u)
  203. #define __Pyx_PyUnicode_KIND(u) PyUnicode_KIND(u)
  204. #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u)
  205. #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i)
  206. #define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, ch)
  207. #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
  208. #else
  209. #define CYTHON_PEP393_ENABLED 0
  210. #define PyUnicode_1BYTE_KIND 1
  211. #define PyUnicode_2BYTE_KIND 2
  212. #define PyUnicode_4BYTE_KIND 4
  213. #define __Pyx_PyUnicode_READY(op) (0)
  214. #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u)
  215. #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
  216. #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111)
  217. #define __Pyx_PyUnicode_KIND(u) (sizeof(Py_UNICODE))
  218. #define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u))
  219. #define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
  220. #define __Pyx_PyUnicode_WRITE(k, d, i, ch) (((void)(k)), ((Py_UNICODE*)d)[i] = ch)
  221. #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_SIZE(u))
  222. #endif
  223. #if CYTHON_COMPILING_IN_PYPY
  224. #define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b)
  225. #define __Pyx_PyUnicode_ConcatSafe(a, b) PyNumber_Add(a, b)
  226. #else
  227. #define __Pyx_PyUnicode_Concat(a, b) PyUnicode_Concat(a, b)
  228. #define __Pyx_PyUnicode_ConcatSafe(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\
  229. PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b))
  230. #endif
  231. #if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains)
  232. #define PyUnicode_Contains(u, s) PySequence_Contains(u, s)
  233. #endif
  234. #if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check)
  235. #define PyByteArray_Check(obj) PyObject_TypeCheck(obj, &PyByteArray_Type)
  236. #endif
  237. #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format)
  238. #define PyObject_Format(obj, fmt) PyObject_CallMethod(obj, "__format__", "O", fmt)
  239. #endif
  240. #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc)
  241. #define PyObject_Malloc(s) PyMem_Malloc(s)
  242. #define PyObject_Free(p) PyMem_Free(p)
  243. #define PyObject_Realloc(p) PyMem_Realloc(p)
  244. #endif
  245. #if CYTHON_COMPILING_IN_PYSTON
  246. #define __Pyx_PyCode_HasFreeVars(co) PyCode_HasFreeVars(co)
  247. #define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno)
  248. #else
  249. #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0)
  250. #define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno)
  251. #endif
  252. #define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
  253. #define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
  254. #if PY_MAJOR_VERSION >= 3
  255. #define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b)
  256. #else
  257. #define __Pyx_PyString_Format(a, b) PyString_Format(a, b)
  258. #endif
  259. #if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII)
  260. #define PyObject_ASCII(o) PyObject_Repr(o)
  261. #endif
  262. #if PY_MAJOR_VERSION >= 3
  263. #define PyBaseString_Type PyUnicode_Type
  264. #define PyStringObject PyUnicodeObject
  265. #define PyString_Type PyUnicode_Type
  266. #define PyString_Check PyUnicode_Check
  267. #define PyString_CheckExact PyUnicode_CheckExact
  268. #endif
  269. #if PY_MAJOR_VERSION >= 3
  270. #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj)
  271. #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj)
  272. #else
  273. #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj))
  274. #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
  275. #endif
  276. #ifndef PySet_CheckExact
  277. #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type)
  278. #endif
  279. #define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
  280. #define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception)
  281. #if PY_MAJOR_VERSION >= 3
  282. #define PyIntObject PyLongObject
  283. #define PyInt_Type PyLong_Type
  284. #define PyInt_Check(op) PyLong_Check(op)
  285. #define PyInt_CheckExact(op) PyLong_CheckExact(op)
  286. #define PyInt_FromString PyLong_FromString
  287. #define PyInt_FromUnicode PyLong_FromUnicode
  288. #define PyInt_FromLong PyLong_FromLong
  289. #define PyInt_FromSize_t PyLong_FromSize_t
  290. #define PyInt_FromSsize_t PyLong_FromSsize_t
  291. #define PyInt_AsLong PyLong_AsLong
  292. #define PyInt_AS_LONG PyLong_AS_LONG
  293. #define PyInt_AsSsize_t PyLong_AsSsize_t
  294. #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask
  295. #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
  296. #define PyNumber_Int PyNumber_Long
  297. #endif
  298. #if PY_MAJOR_VERSION >= 3
  299. #define PyBoolObject PyLongObject
  300. #endif
  301. #if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY
  302. #ifndef PyUnicode_InternFromString
  303. #define PyUnicode_InternFromString(s) PyUnicode_FromString(s)
  304. #endif
  305. #endif
  306. #if PY_VERSION_HEX < 0x030200A4
  307. typedef long Py_hash_t;
  308. #define __Pyx_PyInt_FromHash_t PyInt_FromLong
  309. #define __Pyx_PyInt_AsHash_t PyInt_AsLong
  310. #else
  311. #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
  312. #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t
  313. #endif
  314. #if PY_MAJOR_VERSION >= 3
  315. #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
  316. #else
  317. #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
  318. #endif
  319. #if CYTHON_USE_ASYNC_SLOTS
  320. #if PY_VERSION_HEX >= 0x030500B1
  321. #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
  322. #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
  323. #else
  324. typedef struct {
  325. unaryfunc am_await;
  326. unaryfunc am_aiter;
  327. unaryfunc am_anext;
  328. } __Pyx_PyAsyncMethodsStruct;
  329. #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
  330. #endif
  331. #else
  332. #define __Pyx_PyType_AsAsync(obj) NULL
  333. #endif
  334. #ifndef CYTHON_RESTRICT
  335. #if defined(__GNUC__)
  336. #define CYTHON_RESTRICT __restrict__
  337. #elif defined(_MSC_VER) && _MSC_VER >= 1400
  338. #define CYTHON_RESTRICT __restrict
  339. #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  340. #define CYTHON_RESTRICT restrict
  341. #else
  342. #define CYTHON_RESTRICT
  343. #endif
  344. #endif
  345. #ifndef CYTHON_UNUSED
  346. # if defined(__GNUC__)
  347. # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
  348. # define CYTHON_UNUSED __attribute__ ((__unused__))
  349. # else
  350. # define CYTHON_UNUSED
  351. # endif
  352. # elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
  353. # define CYTHON_UNUSED __attribute__ ((__unused__))
  354. # else
  355. # define CYTHON_UNUSED
  356. # endif
  357. #endif
  358. #ifndef CYTHON_MAYBE_UNUSED_VAR
  359. # if defined(__cplusplus)
  360. template<class T> void CYTHON_MAYBE_UNUSED_VAR( const T& ) { }
  361. # else
  362. # define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x)
  363. # endif
  364. #endif
  365. #ifndef CYTHON_NCP_UNUSED
  366. # if CYTHON_COMPILING_IN_CPYTHON
  367. # define CYTHON_NCP_UNUSED
  368. # else
  369. # define CYTHON_NCP_UNUSED CYTHON_UNUSED
  370. # endif
  371. #endif
  372. #define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None)
  373. #ifndef CYTHON_INLINE
  374. #if defined(__clang__)
  375. #define CYTHON_INLINE __inline__ __attribute__ ((__unused__))
  376. #elif defined(__GNUC__)
  377. #define CYTHON_INLINE __inline__
  378. #elif defined(_MSC_VER)
  379. #define CYTHON_INLINE __inline
  380. #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  381. #define CYTHON_INLINE inline
  382. #else
  383. #define CYTHON_INLINE
  384. #endif
  385. #endif
  386. #if defined(WIN32) || defined(MS_WINDOWS)
  387. #define _USE_MATH_DEFINES
  388. #endif
  389. #include <math.h>
  390. #ifdef NAN
  391. #define __PYX_NAN() ((float) NAN)
  392. #else
  393. static CYTHON_INLINE float __PYX_NAN() {
  394. float value;
  395. memset(&value, 0xFF, sizeof(value));
  396. return value;
  397. }
  398. #endif
  399. #if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL)
  400. #define __Pyx_truncl trunc
  401. #else
  402. #define __Pyx_truncl truncl
  403. #endif
  404. #define __PYX_ERR(f_index, lineno, Ln_error) \
  405. { \
  406. __pyx_filename = __pyx_f[f_index]; __pyx_lineno = lineno; __pyx_clineno = __LINE__; goto Ln_error; \
  407. }
  408. #if PY_MAJOR_VERSION >= 3
  409. #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y)
  410. #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y)
  411. #else
  412. #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y)
  413. #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y)
  414. #endif
  415. #ifndef __PYX_EXTERN_C
  416. #ifdef __cplusplus
  417. #define __PYX_EXTERN_C extern "C"
  418. #else
  419. #define __PYX_EXTERN_C extern
  420. #endif
  421. #endif
  422. #define __PYX_HAVE__gevent___semaphore
  423. #define __PYX_HAVE_API__gevent___semaphore
  424. #ifdef _OPENMP
  425. #include <omp.h>
  426. #endif /* _OPENMP */
  427. #ifdef PYREX_WITHOUT_ASSERTIONS
  428. #define CYTHON_WITHOUT_ASSERTIONS
  429. #endif
  430. typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding;
  431. const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry;
  432. #define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0
  433. #define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 0
  434. #define __PYX_DEFAULT_STRING_ENCODING ""
  435. #define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString
  436. #define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
  437. #define __Pyx_uchar_cast(c) ((unsigned char)c)
  438. #define __Pyx_long_cast(x) ((long)x)
  439. #define __Pyx_fits_Py_ssize_t(v, type, is_signed) (\
  440. (sizeof(type) < sizeof(Py_ssize_t)) ||\
  441. (sizeof(type) > sizeof(Py_ssize_t) &&\
  442. likely(v < (type)PY_SSIZE_T_MAX ||\
  443. v == (type)PY_SSIZE_T_MAX) &&\
  444. (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\
  445. v == (type)PY_SSIZE_T_MIN))) ||\
  446. (sizeof(type) == sizeof(Py_ssize_t) &&\
  447. (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\
  448. v == (type)PY_SSIZE_T_MAX))) )
  449. #if defined (__cplusplus) && __cplusplus >= 201103L
  450. #include <cstdlib>
  451. #define __Pyx_sst_abs(value) std::abs(value)
  452. #elif SIZEOF_INT >= SIZEOF_SIZE_T
  453. #define __Pyx_sst_abs(value) abs(value)
  454. #elif SIZEOF_LONG >= SIZEOF_SIZE_T
  455. #define __Pyx_sst_abs(value) labs(value)
  456. #elif defined (_MSC_VER) && defined (_M_X64)
  457. #define __Pyx_sst_abs(value) _abs64(value)
  458. #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
  459. #define __Pyx_sst_abs(value) llabs(value)
  460. #elif defined (__GNUC__)
  461. #define __Pyx_sst_abs(value) __builtin_llabs(value)
  462. #else
  463. #define __Pyx_sst_abs(value) ((value<0) ? -value : value)
  464. #endif
  465. static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject*);
  466. static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
  467. #define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s))
  468. #define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l)
  469. #define __Pyx_PyBytes_FromString PyBytes_FromString
  470. #define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
  471. static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*);
  472. #if PY_MAJOR_VERSION < 3
  473. #define __Pyx_PyStr_FromString __Pyx_PyBytes_FromString
  474. #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
  475. #else
  476. #define __Pyx_PyStr_FromString __Pyx_PyUnicode_FromString
  477. #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize
  478. #endif
  479. #define __Pyx_PyObject_AsSString(s) ((signed char*) __Pyx_PyObject_AsString(s))
  480. #define __Pyx_PyObject_AsUString(s) ((unsigned char*) __Pyx_PyObject_AsString(s))
  481. #define __Pyx_PyObject_FromCString(s) __Pyx_PyObject_FromString((const char*)s)
  482. #define __Pyx_PyBytes_FromCString(s) __Pyx_PyBytes_FromString((const char*)s)
  483. #define __Pyx_PyByteArray_FromCString(s) __Pyx_PyByteArray_FromString((const char*)s)
  484. #define __Pyx_PyStr_FromCString(s) __Pyx_PyStr_FromString((const char*)s)
  485. #define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s)
  486. #if PY_MAJOR_VERSION < 3
  487. static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u)
  488. {
  489. const Py_UNICODE *u_end = u;
  490. while (*u_end++) ;
  491. return (size_t)(u_end - u - 1);
  492. }
  493. #else
  494. #define __Pyx_Py_UNICODE_strlen Py_UNICODE_strlen
  495. #endif
  496. #define __Pyx_PyUnicode_FromUnicode(u) PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u))
  497. #define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode
  498. #define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode
  499. #define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)
  500. #define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None)
  501. #define __Pyx_PyBool_FromLong(b) ((b) ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False))
  502. static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
  503. static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x);
  504. static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
  505. static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
  506. #if CYTHON_ASSUME_SAFE_MACROS
  507. #define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
  508. #else
  509. #define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
  510. #endif
  511. #define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
  512. #if PY_MAJOR_VERSION >= 3
  513. #define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x))
  514. #else
  515. #define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x))
  516. #endif
  517. #define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x))
  518. #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
  519. static int __Pyx_sys_getdefaultencoding_not_ascii;
  520. static int __Pyx_init_sys_getdefaultencoding_params(void) {
  521. PyObject* sys;
  522. PyObject* default_encoding = NULL;
  523. PyObject* ascii_chars_u = NULL;
  524. PyObject* ascii_chars_b = NULL;
  525. const char* default_encoding_c;
  526. sys = PyImport_ImportModule("sys");
  527. if (!sys) goto bad;
  528. default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL);
  529. Py_DECREF(sys);
  530. if (!default_encoding) goto bad;
  531. default_encoding_c = PyBytes_AsString(default_encoding);
  532. if (!default_encoding_c) goto bad;
  533. if (strcmp(default_encoding_c, "ascii") == 0) {
  534. __Pyx_sys_getdefaultencoding_not_ascii = 0;
  535. } else {
  536. char ascii_chars[128];
  537. int c;
  538. for (c = 0; c < 128; c++) {
  539. ascii_chars[c] = c;
  540. }
  541. __Pyx_sys_getdefaultencoding_not_ascii = 1;
  542. ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL);
  543. if (!ascii_chars_u) goto bad;
  544. ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL);
  545. if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) {
  546. PyErr_Format(
  547. PyExc_ValueError,
  548. "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.",
  549. default_encoding_c);
  550. goto bad;
  551. }
  552. Py_DECREF(ascii_chars_u);
  553. Py_DECREF(ascii_chars_b);
  554. }
  555. Py_DECREF(default_encoding);
  556. return 0;
  557. bad:
  558. Py_XDECREF(default_encoding);
  559. Py_XDECREF(ascii_chars_u);
  560. Py_XDECREF(ascii_chars_b);
  561. return -1;
  562. }
  563. #endif
  564. #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3
  565. #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL)
  566. #else
  567. #define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL)
  568. #if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
  569. static char* __PYX_DEFAULT_STRING_ENCODING;
  570. static int __Pyx_init_sys_getdefaultencoding_params(void) {
  571. PyObject* sys;
  572. PyObject* default_encoding = NULL;
  573. char* default_encoding_c;
  574. sys = PyImport_ImportModule("sys");
  575. if (!sys) goto bad;
  576. default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
  577. Py_DECREF(sys);
  578. if (!default_encoding) goto bad;
  579. default_encoding_c = PyBytes_AsString(default_encoding);
  580. if (!default_encoding_c) goto bad;
  581. __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c));
  582. if (!__PYX_DEFAULT_STRING_ENCODING) goto bad;
  583. strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c);
  584. Py_DECREF(default_encoding);
  585. return 0;
  586. bad:
  587. Py_XDECREF(default_encoding);
  588. return -1;
  589. }
  590. #endif
  591. #endif
  592. /* Test for GCC > 2.95 */
  593. #if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)))
  594. #define likely(x) __builtin_expect(!!(x), 1)
  595. #define unlikely(x) __builtin_expect(!!(x), 0)
  596. #else /* !__GNUC__ or GCC < 2.95 */
  597. #define likely(x) (x)
  598. #define unlikely(x) (x)
  599. #endif /* __GNUC__ */
  600. static PyObject *__pyx_m;
  601. static PyObject *__pyx_d;
  602. static PyObject *__pyx_b;
  603. static PyObject *__pyx_empty_tuple;
  604. static PyObject *__pyx_empty_bytes;
  605. static PyObject *__pyx_empty_unicode;
  606. static int __pyx_lineno;
  607. static int __pyx_clineno = 0;
  608. static const char * __pyx_cfilenm= __FILE__;
  609. static const char *__pyx_filename;
  610. static const char *__pyx_f[] = {
  611. "src\\gevent\\_semaphore.py",
  612. "src\\gevent\\_semaphore.pxd",
  613. };
  614. /*--- Type declarations ---*/
  615. struct __pyx_obj_6gevent_10_semaphore_Semaphore;
  616. struct __pyx_obj_6gevent_10_semaphore_BoundedSemaphore;
  617. struct __pyx_opt_args_6gevent_10_semaphore_9Semaphore_wait;
  618. struct __pyx_opt_args_6gevent_10_semaphore_9Semaphore_acquire;
  619. /* "gevent/_semaphore.pxd":15
  620. * cpdef _notify_links(self)
  621. * cdef _do_wait(self, object timeout)
  622. * cpdef int wait(self, object timeout=*) except -1000 # <<<<<<<<<<<<<<
  623. * cpdef bint acquire(self, int blocking=*, object timeout=*) except -1000
  624. * cpdef __enter__(self)
  625. */
  626. struct __pyx_opt_args_6gevent_10_semaphore_9Semaphore_wait {
  627. int __pyx_n;
  628. PyObject *timeout;
  629. };
  630. /* "gevent/_semaphore.pxd":16
  631. * cdef _do_wait(self, object timeout)
  632. * cpdef int wait(self, object timeout=*) except -1000
  633. * cpdef bint acquire(self, int blocking=*, object timeout=*) except -1000 # <<<<<<<<<<<<<<
  634. * cpdef __enter__(self)
  635. * cpdef __exit__(self, object t, object v, object tb)
  636. */
  637. struct __pyx_opt_args_6gevent_10_semaphore_9Semaphore_acquire {
  638. int __pyx_n;
  639. int blocking;
  640. PyObject *timeout;
  641. };
  642. /* "gevent/_semaphore.pxd":1
  643. * cdef class Semaphore: # <<<<<<<<<<<<<<
  644. * cdef public int counter
  645. * cdef readonly object _links
  646. */
  647. struct __pyx_obj_6gevent_10_semaphore_Semaphore {
  648. PyObject_HEAD
  649. struct __pyx_vtabstruct_6gevent_10_semaphore_Semaphore *__pyx_vtab;
  650. int counter;
  651. PyObject *_links;
  652. PyObject *_notifier;
  653. int _dirty;
  654. PyObject *__weakref__;
  655. };
  656. /* "gevent/_semaphore.pxd":20
  657. * cpdef __exit__(self, object t, object v, object tb)
  658. *
  659. * cdef class BoundedSemaphore(Semaphore): # <<<<<<<<<<<<<<
  660. * cdef readonly int _initial_value
  661. *
  662. */
  663. struct __pyx_obj_6gevent_10_semaphore_BoundedSemaphore {
  664. struct __pyx_obj_6gevent_10_semaphore_Semaphore __pyx_base;
  665. int _initial_value;
  666. };
  667. /* "gevent/_semaphore.py":9
  668. *
  669. *
  670. * class Semaphore(object): # <<<<<<<<<<<<<<
  671. * """
  672. * Semaphore(value=1) -> Semaphore
  673. */
  674. struct __pyx_vtabstruct_6gevent_10_semaphore_Semaphore {
  675. int (*locked)(struct __pyx_obj_6gevent_10_semaphore_Semaphore *, int __pyx_skip_dispatch);
  676. int (*release)(struct __pyx_obj_6gevent_10_semaphore_Semaphore *, int __pyx_skip_dispatch);
  677. PyObject *(*rawlink)(struct __pyx_obj_6gevent_10_semaphore_Semaphore *, PyObject *, int __pyx_skip_dispatch);
  678. PyObject *(*unlink)(struct __pyx_obj_6gevent_10_semaphore_Semaphore *, PyObject *, int __pyx_skip_dispatch);
  679. PyObject *(*_start_notify)(struct __pyx_obj_6gevent_10_semaphore_Semaphore *, int __pyx_skip_dispatch);
  680. PyObject *(*_notify_links)(struct __pyx_obj_6gevent_10_semaphore_Semaphore *, int __pyx_skip_dispatch);
  681. PyObject *(*_do_wait)(struct __pyx_obj_6gevent_10_semaphore_Semaphore *, PyObject *);
  682. int (*wait)(struct __pyx_obj_6gevent_10_semaphore_Semaphore *, int __pyx_skip_dispatch, struct __pyx_opt_args_6gevent_10_semaphore_9Semaphore_wait *__pyx_optional_args);
  683. int (*acquire)(struct __pyx_obj_6gevent_10_semaphore_Semaphore *, int __pyx_skip_dispatch, struct __pyx_opt_args_6gevent_10_semaphore_9Semaphore_acquire *__pyx_optional_args);
  684. PyObject *(*__pyx___enter__)(struct __pyx_obj_6gevent_10_semaphore_Semaphore *, int __pyx_skip_dispatch);
  685. PyObject *(*__pyx___exit__)(struct __pyx_obj_6gevent_10_semaphore_Semaphore *, PyObject *, PyObject *, PyObject *, int __pyx_skip_dispatch);
  686. };
  687. static struct __pyx_vtabstruct_6gevent_10_semaphore_Semaphore *__pyx_vtabptr_6gevent_10_semaphore_Semaphore;
  688. /* "gevent/_semaphore.py":246
  689. *
  690. *
  691. * class BoundedSemaphore(Semaphore): # <<<<<<<<<<<<<<
  692. * """
  693. * BoundedSemaphore(value=1) -> BoundedSemaphore
  694. */
  695. struct __pyx_vtabstruct_6gevent_10_semaphore_BoundedSemaphore {
  696. struct __pyx_vtabstruct_6gevent_10_semaphore_Semaphore __pyx_base;
  697. };
  698. static struct __pyx_vtabstruct_6gevent_10_semaphore_BoundedSemaphore *__pyx_vtabptr_6gevent_10_semaphore_BoundedSemaphore;
  699. /* --- Runtime support code (head) --- */
  700. /* Refnanny.proto */
  701. #ifndef CYTHON_REFNANNY
  702. #define CYTHON_REFNANNY 0
  703. #endif
  704. #if CYTHON_REFNANNY
  705. typedef struct {
  706. void (*INCREF)(void*, PyObject*, int);
  707. void (*DECREF)(void*, PyObject*, int);
  708. void (*GOTREF)(void*, PyObject*, int);
  709. void (*GIVEREF)(void*, PyObject*, int);
  710. void* (*SetupContext)(const char*, int, const char*);
  711. void (*FinishContext)(void**);
  712. } __Pyx_RefNannyAPIStruct;
  713. static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
  714. static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname);
  715. #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
  716. #ifdef WITH_THREAD
  717. #define __Pyx_RefNannySetupContext(name, acquire_gil)\
  718. if (acquire_gil) {\
  719. PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\
  720. __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
  721. PyGILState_Release(__pyx_gilstate_save);\
  722. } else {\
  723. __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
  724. }
  725. #else
  726. #define __Pyx_RefNannySetupContext(name, acquire_gil)\
  727. __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
  728. #endif
  729. #define __Pyx_RefNannyFinishContext()\
  730. __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
  731. #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  732. #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  733. #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  734. #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  735. #define __Pyx_XINCREF(r) do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
  736. #define __Pyx_XDECREF(r) do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
  737. #define __Pyx_XGOTREF(r) do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
  738. #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
  739. #else
  740. #define __Pyx_RefNannyDeclarations
  741. #define __Pyx_RefNannySetupContext(name, acquire_gil)
  742. #define __Pyx_RefNannyFinishContext()
  743. #define __Pyx_INCREF(r) Py_INCREF(r)
  744. #define __Pyx_DECREF(r) Py_DECREF(r)
  745. #define __Pyx_GOTREF(r)
  746. #define __Pyx_GIVEREF(r)
  747. #define __Pyx_XINCREF(r) Py_XINCREF(r)
  748. #define __Pyx_XDECREF(r) Py_XDECREF(r)
  749. #define __Pyx_XGOTREF(r)
  750. #define __Pyx_XGIVEREF(r)
  751. #endif
  752. #define __Pyx_XDECREF_SET(r, v) do {\
  753. PyObject *tmp = (PyObject *) r;\
  754. r = v; __Pyx_XDECREF(tmp);\
  755. } while (0)
  756. #define __Pyx_DECREF_SET(r, v) do {\
  757. PyObject *tmp = (PyObject *) r;\
  758. r = v; __Pyx_DECREF(tmp);\
  759. } while (0)
  760. #define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
  761. #define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)
  762. /* PyObjectGetAttrStr.proto */
  763. #if CYTHON_USE_TYPE_SLOTS
  764. static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) {
  765. PyTypeObject* tp = Py_TYPE(obj);
  766. if (likely(tp->tp_getattro))
  767. return tp->tp_getattro(obj, attr_name);
  768. #if PY_MAJOR_VERSION < 3
  769. if (likely(tp->tp_getattr))
  770. return tp->tp_getattr(obj, PyString_AS_STRING(attr_name));
  771. #endif
  772. return PyObject_GetAttr(obj, attr_name);
  773. }
  774. #else
  775. #define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
  776. #endif
  777. /* GetBuiltinName.proto */
  778. static PyObject *__Pyx_GetBuiltinName(PyObject *name);
  779. /* RaiseDoubleKeywords.proto */
  780. static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name);
  781. /* ParseKeywords.proto */
  782. static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\
  783. PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\
  784. const char* function_name);
  785. /* RaiseArgTupleInvalid.proto */
  786. static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
  787. Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found);
  788. /* PyObjectCall.proto */
  789. #if CYTHON_COMPILING_IN_CPYTHON
  790. static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw);
  791. #else
  792. #define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw)
  793. #endif
  794. /* PyThreadStateGet.proto */
  795. #if CYTHON_FAST_THREAD_STATE
  796. #define __Pyx_PyThreadState_declare PyThreadState *__pyx_tstate;
  797. #define __Pyx_PyThreadState_assign __pyx_tstate = PyThreadState_GET();
  798. #else
  799. #define __Pyx_PyThreadState_declare
  800. #define __Pyx_PyThreadState_assign
  801. #endif
  802. /* PyErrFetchRestore.proto */
  803. #if CYTHON_FAST_THREAD_STATE
  804. #define __Pyx_ErrRestoreWithState(type, value, tb) __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb)
  805. #define __Pyx_ErrFetchWithState(type, value, tb) __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb)
  806. #define __Pyx_ErrRestore(type, value, tb) __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb)
  807. #define __Pyx_ErrFetch(type, value, tb) __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb)
  808. static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
  809. static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
  810. #else
  811. #define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb)
  812. #define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb)
  813. #define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb)
  814. #define __Pyx_ErrFetch(type, value, tb) PyErr_Fetch(type, value, tb)
  815. #endif
  816. /* RaiseException.proto */
  817. static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause);
  818. /* PyCFunctionFastCall.proto */
  819. #if CYTHON_FAST_PYCCALL
  820. static CYTHON_INLINE PyObject *__Pyx_PyCFunction_FastCall(PyObject *func, PyObject **args, Py_ssize_t nargs);
  821. #else
  822. #define __Pyx_PyCFunction_FastCall(func, args, nargs) (assert(0), NULL)
  823. #endif
  824. /* PyFunctionFastCall.proto */
  825. #if CYTHON_FAST_PYCALL
  826. #define __Pyx_PyFunction_FastCall(func, args, nargs)\
  827. __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL)
  828. #if 1 || PY_VERSION_HEX < 0x030600B1
  829. static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwargs);
  830. #else
  831. #define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs)
  832. #endif
  833. #endif
  834. /* PyObjectCallMethO.proto */
  835. #if CYTHON_COMPILING_IN_CPYTHON
  836. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg);
  837. #endif
  838. /* PyObjectCallOneArg.proto */
  839. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg);
  840. /* PyObjectCallNoArg.proto */
  841. #if CYTHON_COMPILING_IN_CPYTHON
  842. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func);
  843. #else
  844. #define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL)
  845. #endif
  846. /* WriteUnraisableException.proto */
  847. static void __Pyx_WriteUnraisable(const char *name, int clineno,
  848. int lineno, const char *filename,
  849. int full_traceback, int nogil);
  850. /* GetModuleGlobalName.proto */
  851. static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name);
  852. /* SaveResetException.proto */
  853. #if CYTHON_FAST_THREAD_STATE
  854. #define __Pyx_ExceptionSave(type, value, tb) __Pyx__ExceptionSave(__pyx_tstate, type, value, tb)
  855. static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
  856. #define __Pyx_ExceptionReset(type, value, tb) __Pyx__ExceptionReset(__pyx_tstate, type, value, tb)
  857. static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
  858. #else
  859. #define __Pyx_ExceptionSave(type, value, tb) PyErr_GetExcInfo(type, value, tb)
  860. #define __Pyx_ExceptionReset(type, value, tb) PyErr_SetExcInfo(type, value, tb)
  861. #endif
  862. /* GetException.proto */
  863. #if CYTHON_FAST_THREAD_STATE
  864. #define __Pyx_GetException(type, value, tb) __Pyx__GetException(__pyx_tstate, type, value, tb)
  865. static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
  866. #else
  867. static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb);
  868. #endif
  869. /* SwapException.proto */
  870. #if CYTHON_FAST_THREAD_STATE
  871. #define __Pyx_ExceptionSwap(type, value, tb) __Pyx__ExceptionSwap(__pyx_tstate, type, value, tb)
  872. static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
  873. #else
  874. static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb);
  875. #endif
  876. /* CallableCheck.proto */
  877. #if CYTHON_USE_TYPE_SLOTS && PY_MAJOR_VERSION >= 3
  878. #define __Pyx_PyCallable_Check(obj) ((obj)->ob_type->tp_call != NULL)
  879. #else
  880. #define __Pyx_PyCallable_Check(obj) PyCallable_Check(obj)
  881. #endif
  882. /* ListAppend.proto */
  883. #if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS
  884. static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) {
  885. PyListObject* L = (PyListObject*) list;
  886. Py_ssize_t len = Py_SIZE(list);
  887. if (likely(L->allocated > len) & likely(len > (L->allocated >> 1))) {
  888. Py_INCREF(x);
  889. PyList_SET_ITEM(list, len, x);
  890. Py_SIZE(list) = len+1;
  891. return 0;
  892. }
  893. return PyList_Append(list, x);
  894. }
  895. #else
  896. #define __Pyx_PyList_Append(L,x) PyList_Append(L,x)
  897. #endif
  898. /* PyObjectCallMethod1.proto */
  899. static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg);
  900. /* append.proto */
  901. static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x);
  902. /* PyErrExceptionMatches.proto */
  903. #if CYTHON_FAST_THREAD_STATE
  904. #define __Pyx_PyErr_ExceptionMatches(err) __Pyx_PyErr_ExceptionMatchesInState(__pyx_tstate, err)
  905. static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err);
  906. #else
  907. #define __Pyx_PyErr_ExceptionMatches(err) PyErr_ExceptionMatches(err)
  908. #endif
  909. /* KeywordStringCheck.proto */
  910. static CYTHON_INLINE int __Pyx_CheckKeywordStrings(PyObject *kwdict, const char* function_name, int kw_allowed);
  911. /* SetVTable.proto */
  912. static int __Pyx_SetVtable(PyObject *dict, void *vtable);
  913. /* Import.proto */
  914. static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level);
  915. /* ImportFrom.proto */
  916. static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name);
  917. /* FetchCommonType.proto */
  918. static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type);
  919. /* CythonFunction.proto */
  920. #define __Pyx_CyFunction_USED 1
  921. #include <structmember.h>
  922. #define __Pyx_CYFUNCTION_STATICMETHOD 0x01
  923. #define __Pyx_CYFUNCTION_CLASSMETHOD 0x02
  924. #define __Pyx_CYFUNCTION_CCLASS 0x04
  925. #define __Pyx_CyFunction_GetClosure(f)\
  926. (((__pyx_CyFunctionObject *) (f))->func_closure)
  927. #define __Pyx_CyFunction_GetClassObj(f)\
  928. (((__pyx_CyFunctionObject *) (f))->func_classobj)
  929. #define __Pyx_CyFunction_Defaults(type, f)\
  930. ((type *)(((__pyx_CyFunctionObject *) (f))->defaults))
  931. #define __Pyx_CyFunction_SetDefaultsGetter(f, g)\
  932. ((__pyx_CyFunctionObject *) (f))->defaults_getter = (g)
  933. typedef struct {
  934. PyCFunctionObject func;
  935. #if PY_VERSION_HEX < 0x030500A0
  936. PyObject *func_weakreflist;
  937. #endif
  938. PyObject *func_dict;
  939. PyObject *func_name;
  940. PyObject *func_qualname;
  941. PyObject *func_doc;
  942. PyObject *func_globals;
  943. PyObject *func_code;
  944. PyObject *func_closure;
  945. PyObject *func_classobj;
  946. void *defaults;
  947. int defaults_pyobjects;
  948. int flags;
  949. PyObject *defaults_tuple;
  950. PyObject *defaults_kwdict;
  951. PyObject *(*defaults_getter)(PyObject *);
  952. PyObject *func_annotations;
  953. } __pyx_CyFunctionObject;
  954. static PyTypeObject *__pyx_CyFunctionType = 0;
  955. #define __Pyx_CyFunction_NewEx(ml, flags, qualname, self, module, globals, code)\
  956. __Pyx_CyFunction_New(__pyx_CyFunctionType, ml, flags, qualname, self, module, globals, code)
  957. static PyObject *__Pyx_CyFunction_New(PyTypeObject *, PyMethodDef *ml,
  958. int flags, PyObject* qualname,
  959. PyObject *self,
  960. PyObject *module, PyObject *globals,
  961. PyObject* code);
  962. static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *m,
  963. size_t size,
  964. int pyobjects);
  965. static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *m,
  966. PyObject *tuple);
  967. static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *m,
  968. PyObject *dict);
  969. static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *m,
  970. PyObject *dict);
  971. static int __pyx_CyFunction_init(void);
  972. /* GetNameInClass.proto */
  973. static PyObject *__Pyx_GetNameInClass(PyObject *nmspace, PyObject *name);
  974. /* CodeObjectCache.proto */
  975. typedef struct {
  976. PyCodeObject* code_object;
  977. int code_line;
  978. } __Pyx_CodeObjectCacheEntry;
  979. struct __Pyx_CodeObjectCache {
  980. int count;
  981. int max_count;
  982. __Pyx_CodeObjectCacheEntry* entries;
  983. };
  984. static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL};
  985. static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
  986. static PyCodeObject *__pyx_find_code_object(int code_line);
  987. static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);
  988. /* AddTraceback.proto */
  989. static void __Pyx_AddTraceback(const char *funcname, int c_line,
  990. int py_line, const char *filename);
  991. /* CIntToPy.proto */
  992. static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value);
  993. /* CIntFromPy.proto */
  994. static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);
  995. /* CIntToPy.proto */
  996. static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);
  997. /* CIntFromPy.proto */
  998. static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);
  999. /* CheckBinaryVersion.proto */
  1000. static int __Pyx_check_binary_version(void);
  1001. /* InitStrings.proto */
  1002. static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);
  1003. static int __pyx_f_6gevent_10_semaphore_9Semaphore_locked(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, int __pyx_skip_dispatch); /* proto*/
  1004. static int __pyx_f_6gevent_10_semaphore_9Semaphore_release(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, int __pyx_skip_dispatch); /* proto*/
  1005. static PyObject *__pyx_f_6gevent_10_semaphore_9Semaphore__start_notify(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, int __pyx_skip_dispatch); /* proto*/
  1006. static PyObject *__pyx_f_6gevent_10_semaphore_9Semaphore__notify_links(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, int __pyx_skip_dispatch); /* proto*/
  1007. static PyObject *__pyx_f_6gevent_10_semaphore_9Semaphore_rawlink(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, PyObject *__pyx_v_callback, int __pyx_skip_dispatch); /* proto*/
  1008. static PyObject *__pyx_f_6gevent_10_semaphore_9Semaphore_unlink(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, PyObject *__pyx_v_callback, int __pyx_skip_dispatch); /* proto*/
  1009. static PyObject *__pyx_f_6gevent_10_semaphore_9Semaphore__do_wait(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, PyObject *__pyx_v_timeout); /* proto*/
  1010. static int __pyx_f_6gevent_10_semaphore_9Semaphore_wait(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, int __pyx_skip_dispatch, struct __pyx_opt_args_6gevent_10_semaphore_9Semaphore_wait *__pyx_optional_args); /* proto*/
  1011. static int __pyx_f_6gevent_10_semaphore_9Semaphore_acquire(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, int __pyx_skip_dispatch, struct __pyx_opt_args_6gevent_10_semaphore_9Semaphore_acquire *__pyx_optional_args); /* proto*/
  1012. static PyObject *__pyx_f_6gevent_10_semaphore_9Semaphore___enter__(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, int __pyx_skip_dispatch); /* proto*/
  1013. static PyObject *__pyx_f_6gevent_10_semaphore_9Semaphore___exit__(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_t, CYTHON_UNUSED PyObject *__pyx_v_v, CYTHON_UNUSED PyObject *__pyx_v_tb, int __pyx_skip_dispatch); /* proto*/
  1014. static int __pyx_f_6gevent_10_semaphore_16BoundedSemaphore_release(struct __pyx_obj_6gevent_10_semaphore_BoundedSemaphore *__pyx_v_self, int __pyx_skip_dispatch); /* proto*/
  1015. /* Module declarations from 'gevent._semaphore' */
  1016. static PyTypeObject *__pyx_ptype_6gevent_10_semaphore_Semaphore = 0;
  1017. static PyTypeObject *__pyx_ptype_6gevent_10_semaphore_BoundedSemaphore = 0;
  1018. #define __Pyx_MODULE_NAME "gevent._semaphore"
  1019. int __pyx_module_is_main_gevent___semaphore = 0;
  1020. /* Implementation of 'gevent._semaphore' */
  1021. static PyObject *__pyx_builtin_ValueError;
  1022. static PyObject *__pyx_builtin_TypeError;
  1023. static PyObject *__pyx_builtin_AttributeError;
  1024. static const char __pyx_k_t[] = "t";
  1025. static const char __pyx_k_v[] = "v";
  1026. static const char __pyx_k_tb[] = "tb";
  1027. static const char __pyx_k_all[] = "__all__";
  1028. static const char __pyx_k_sys[] = "sys";
  1029. static const char __pyx_k_exit[] = "__exit__";
  1030. static const char __pyx_k_init[] = "__init__";
  1031. static const char __pyx_k_loop[] = "loop";
  1032. static const char __pyx_k_main[] = "__main__";
  1033. static const char __pyx_k_name[] = "__name__";
  1034. static const char __pyx_k_self[] = "self";
  1035. static const char __pyx_k_test[] = "__test__";
  1036. static const char __pyx_k_wait[] = "wait";
  1037. static const char __pyx_k_class[] = "__class__";
  1038. static const char __pyx_k_enter[] = "__enter__";
  1039. static const char __pyx_k_value[] = "value";
  1040. static const char __pyx_k_append[] = "append";
  1041. static const char __pyx_k_cancel[] = "cancel";
  1042. static const char __pyx_k_import[] = "__import__";
  1043. static const char __pyx_k_locked[] = "locked";
  1044. static const char __pyx_k_remove[] = "remove";
  1045. static const char __pyx_k_switch[] = "switch";
  1046. static const char __pyx_k_unlink[] = "unlink";
  1047. static const char __pyx_k_Timeout[] = "Timeout";
  1048. static const char __pyx_k_acquire[] = "acquire";
  1049. static const char __pyx_k_get_hub[] = "get_hub";
  1050. static const char __pyx_k_rawlink[] = "rawlink";
  1051. static const char __pyx_k_release[] = "release";
  1052. static const char __pyx_k_timeout[] = "timeout";
  1053. static const char __pyx_k_blocking[] = "blocking";
  1054. static const char __pyx_k_callback[] = "callback";
  1055. static const char __pyx_k_exc_info[] = "exc_info";
  1056. static const char __pyx_k_Semaphore[] = "Semaphore";
  1057. static const char __pyx_k_TypeError[] = "TypeError";
  1058. static const char __pyx_k_ValueError[] = "ValueError";
  1059. static const char __pyx_k_getcurrent[] = "getcurrent";
  1060. static const char __pyx_k_gevent_hub[] = "gevent.hub";
  1061. static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__";
  1062. static const char __pyx_k_handle_error[] = "handle_error";
  1063. static const char __pyx_k_notify_links[] = "_notify_links";
  1064. static const char __pyx_k_py3k_acquire[] = "_py3k_acquire";
  1065. static const char __pyx_k_run_callback[] = "run_callback";
  1066. static const char __pyx_k_start_notify[] = "_start_notify";
  1067. static const char __pyx_k_AttributeError[] = "AttributeError";
  1068. static const char __pyx_k_Semaphore_wait[] = "Semaphore.wait";
  1069. static const char __pyx_k_gevent_timeout[] = "gevent.timeout";
  1070. static const char __pyx_k_BoundedSemaphore[] = "BoundedSemaphore";
  1071. static const char __pyx_k_Semaphore___exit[] = "Semaphore.__exit__";
  1072. static const char __pyx_k_Semaphore_locked[] = "Semaphore.locked";
  1073. static const char __pyx_k_Semaphore_unlink[] = "Semaphore.unlink";
  1074. static const char __pyx_k_Expected_callable[] = "Expected callable:";
  1075. static const char __pyx_k_Semaphore___enter[] = "Semaphore.__enter__";
  1076. static const char __pyx_k_Semaphore_acquire[] = "Semaphore.acquire";
  1077. static const char __pyx_k_Semaphore_rawlink[] = "Semaphore.rawlink";
  1078. static const char __pyx_k_Semaphore_release[] = "Semaphore.release";
  1079. static const char __pyx_k_gevent__semaphore[] = "gevent._semaphore";
  1080. static const char __pyx_k_OVER_RELEASE_ERROR[] = "_OVER_RELEASE_ERROR";
  1081. static const char __pyx_k_start_new_or_dummy[] = "_start_new_or_dummy";
  1082. static const char __pyx_k_s_counter_s__links_s[] = "<%s counter=%s _links[%s]>";
  1083. static const char __pyx_k_Semaphore__notify_links[] = "Semaphore._notify_links";
  1084. static const char __pyx_k_Semaphore__start_notify[] = "Semaphore._start_notify";
  1085. static const char __pyx_k_BoundedSemaphore_release[] = "BoundedSemaphore.release";
  1086. static const char __pyx_k_semaphore_initial_value_must_be[] = "semaphore initial value must be >= 0";
  1087. static const char __pyx_k_C_projects_gevent_src_gevent__se[] = "C:\\projects\\gevent\\src\\gevent\\_semaphore.py";
  1088. static const char __pyx_k_Invalid_switch_into_Semaphore_wa[] = "Invalid switch into Semaphore.wait/acquire(): %r";
  1089. static const char __pyx_k_Semaphore_released_too_many_time[] = "Semaphore released too many times";
  1090. static PyObject *__pyx_n_s_AttributeError;
  1091. static PyObject *__pyx_n_s_BoundedSemaphore;
  1092. static PyObject *__pyx_n_s_BoundedSemaphore_release;
  1093. static PyObject *__pyx_kp_s_C_projects_gevent_src_gevent__se;
  1094. static PyObject *__pyx_kp_s_Expected_callable;
  1095. static PyObject *__pyx_kp_s_Invalid_switch_into_Semaphore_wa;
  1096. static PyObject *__pyx_n_s_OVER_RELEASE_ERROR;
  1097. static PyObject *__pyx_n_s_Semaphore;
  1098. static PyObject *__pyx_n_s_Semaphore___enter;
  1099. static PyObject *__pyx_n_s_Semaphore___exit;
  1100. static PyObject *__pyx_n_s_Semaphore__notify_links;
  1101. static PyObject *__pyx_n_s_Semaphore__start_notify;
  1102. static PyObject *__pyx_n_s_Semaphore_acquire;
  1103. static PyObject *__pyx_n_s_Semaphore_locked;
  1104. static PyObject *__pyx_n_s_Semaphore_rawlink;
  1105. static PyObject *__pyx_n_s_Semaphore_release;
  1106. static PyObject *__pyx_kp_s_Semaphore_released_too_many_time;
  1107. static PyObject *__pyx_n_s_Semaphore_unlink;
  1108. static PyObject *__pyx_n_s_Semaphore_wait;
  1109. static PyObject *__pyx_n_s_Timeout;
  1110. static PyObject *__pyx_n_s_TypeError;
  1111. static PyObject *__pyx_n_s_ValueError;
  1112. static PyObject *__pyx_n_s_acquire;
  1113. static PyObject *__pyx_n_s_all;
  1114. static PyObject *__pyx_n_s_append;
  1115. static PyObject *__pyx_n_s_blocking;
  1116. static PyObject *__pyx_n_s_callback;
  1117. static PyObject *__pyx_n_s_cancel;
  1118. static PyObject *__pyx_n_s_class;
  1119. static PyObject *__pyx_n_s_enter;
  1120. static PyObject *__pyx_n_s_exc_info;
  1121. static PyObject *__pyx_n_s_exit;
  1122. static PyObject *__pyx_n_s_get_hub;
  1123. static PyObject *__pyx_n_s_getcurrent;
  1124. static PyObject *__pyx_n_s_gevent__semaphore;
  1125. static PyObject *__pyx_n_s_gevent_hub;
  1126. static PyObject *__pyx_n_s_gevent_timeout;
  1127. static PyObject *__pyx_n_s_handle_error;
  1128. static PyObject *__pyx_n_s_import;
  1129. static PyObject *__pyx_n_s_init;
  1130. static PyObject *__pyx_n_s_locked;
  1131. static PyObject *__pyx_n_s_loop;
  1132. static PyObject *__pyx_n_s_main;
  1133. static PyObject *__pyx_n_s_name;
  1134. static PyObject *__pyx_n_s_notify_links;
  1135. static PyObject *__pyx_n_s_py3k_acquire;
  1136. static PyObject *__pyx_n_s_pyx_vtable;
  1137. static PyObject *__pyx_n_s_rawlink;
  1138. static PyObject *__pyx_n_s_release;
  1139. static PyObject *__pyx_n_s_remove;
  1140. static PyObject *__pyx_n_s_run_callback;
  1141. static PyObject *__pyx_kp_s_s_counter_s__links_s;
  1142. static PyObject *__pyx_n_s_self;
  1143. static PyObject *__pyx_kp_s_semaphore_initial_value_must_be;
  1144. static PyObject *__pyx_n_s_start_new_or_dummy;
  1145. static PyObject *__pyx_n_s_start_notify;
  1146. static PyObject *__pyx_n_s_switch;
  1147. static PyObject *__pyx_n_s_sys;
  1148. static PyObject *__pyx_n_s_t;
  1149. static PyObject *__pyx_n_s_tb;
  1150. static PyObject *__pyx_n_s_test;
  1151. static PyObject *__pyx_n_s_timeout;
  1152. static PyObject *__pyx_n_s_unlink;
  1153. static PyObject *__pyx_n_s_v;
  1154. static PyObject *__pyx_n_s_value;
  1155. static PyObject *__pyx_n_s_wait;
  1156. static int __pyx_pf_6gevent_10_semaphore_9Semaphore___init__(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, PyObject *__pyx_v_value); /* proto */
  1157. static PyObject *__pyx_pf_6gevent_10_semaphore_9Semaphore_2__str__(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self); /* proto */
  1158. static PyObject *__pyx_pf_6gevent_10_semaphore_9Semaphore_4locked(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self); /* proto */
  1159. static PyObject *__pyx_pf_6gevent_10_semaphore_9Semaphore_6release(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self); /* proto */
  1160. static PyObject *__pyx_pf_6gevent_10_semaphore_9Semaphore_8_start_notify(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self); /* proto */
  1161. static PyObject *__pyx_pf_6gevent_10_semaphore_9Semaphore_10_notify_links(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self); /* proto */
  1162. static PyObject *__pyx_pf_6gevent_10_semaphore_9Semaphore_12rawlink(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, PyObject *__pyx_v_callback); /* proto */
  1163. static PyObject *__pyx_pf_6gevent_10_semaphore_9Semaphore_14unlink(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, PyObject *__pyx_v_callback); /* proto */
  1164. static PyObject *__pyx_pf_6gevent_10_semaphore_9Semaphore_16wait(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, PyObject *__pyx_v_timeout); /* proto */
  1165. static PyObject *__pyx_pf_6gevent_10_semaphore_9Semaphore_18acquire(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, int __pyx_v_blocking, PyObject *__pyx_v_timeout); /* proto */
  1166. static PyObject *__pyx_pf_6gevent_10_semaphore_9Semaphore_20__enter__(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self); /* proto */
  1167. static PyObject *__pyx_pf_6gevent_10_semaphore_9Semaphore_22__exit__(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, PyObject *__pyx_v_t, PyObject *__pyx_v_v, PyObject *__pyx_v_tb); /* proto */
  1168. static PyObject *__pyx_pf_6gevent_10_semaphore_9Semaphore_7counter___get__(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self); /* proto */
  1169. static int __pyx_pf_6gevent_10_semaphore_9Semaphore_7counter_2__set__(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, PyObject *__pyx_v_value); /* proto */
  1170. static PyObject *__pyx_pf_6gevent_10_semaphore_9Semaphore_6_links___get__(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self); /* proto */
  1171. static PyObject *__pyx_pf_6gevent_10_semaphore_9Semaphore_9_notifier___get__(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self); /* proto */
  1172. static PyObject *__pyx_pf_6gevent_10_semaphore_9Semaphore_6_dirty___get__(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self); /* proto */
  1173. static int __pyx_pf_6gevent_10_semaphore_9Semaphore_6_dirty_2__set__(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, PyObject *__pyx_v_value); /* proto */
  1174. static int __pyx_pf_6gevent_10_semaphore_16BoundedSemaphore___init__(struct __pyx_obj_6gevent_10_semaphore_BoundedSemaphore *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
  1175. static PyObject *__pyx_pf_6gevent_10_semaphore_16BoundedSemaphore_2release(struct __pyx_obj_6gevent_10_semaphore_BoundedSemaphore *__pyx_v_self); /* proto */
  1176. static PyObject *__pyx_pf_6gevent_10_semaphore_16BoundedSemaphore_14_initial_value___get__(struct __pyx_obj_6gevent_10_semaphore_BoundedSemaphore *__pyx_v_self); /* proto */
  1177. static PyObject *__pyx_tp_new_6gevent_10_semaphore_Semaphore(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
  1178. static PyObject *__pyx_tp_new_6gevent_10_semaphore_BoundedSemaphore(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
  1179. static PyObject *__pyx_int_0;
  1180. static PyObject *__pyx_int_1;
  1181. static PyObject *__pyx_tuple_;
  1182. static PyObject *__pyx_tuple__2;
  1183. static PyObject *__pyx_tuple__3;
  1184. static PyObject *__pyx_tuple__5;
  1185. static PyObject *__pyx_tuple__7;
  1186. static PyObject *__pyx_tuple__9;
  1187. static PyObject *__pyx_tuple__11;
  1188. static PyObject *__pyx_tuple__13;
  1189. static PyObject *__pyx_tuple__15;
  1190. static PyObject *__pyx_tuple__17;
  1191. static PyObject *__pyx_tuple__19;
  1192. static PyObject *__pyx_tuple__21;
  1193. static PyObject *__pyx_tuple__23;
  1194. static PyObject *__pyx_codeobj__4;
  1195. static PyObject *__pyx_codeobj__6;
  1196. static PyObject *__pyx_codeobj__8;
  1197. static PyObject *__pyx_codeobj__10;
  1198. static PyObject *__pyx_codeobj__12;
  1199. static PyObject *__pyx_codeobj__14;
  1200. static PyObject *__pyx_codeobj__16;
  1201. static PyObject *__pyx_codeobj__18;
  1202. static PyObject *__pyx_codeobj__20;
  1203. static PyObject *__pyx_codeobj__22;
  1204. static PyObject *__pyx_codeobj__24;
  1205. /* "gevent/_semaphore.py":29
  1206. * """
  1207. *
  1208. * def __init__(self, value=1): # <<<<<<<<<<<<<<
  1209. * if value < 0:
  1210. * raise ValueError("semaphore initial value must be >= 0")
  1211. */
  1212. /* Python wrapper */
  1213. static int __pyx_pw_6gevent_10_semaphore_9Semaphore_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
  1214. static int __pyx_pw_6gevent_10_semaphore_9Semaphore_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  1215. PyObject *__pyx_v_value = 0;
  1216. int __pyx_r;
  1217. __Pyx_RefNannyDeclarations
  1218. __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  1219. {
  1220. static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_value,0};
  1221. PyObject* values[1] = {0};
  1222. values[0] = ((PyObject *)__pyx_int_1);
  1223. if (unlikely(__pyx_kwds)) {
  1224. Py_ssize_t kw_args;
  1225. const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
  1226. switch (pos_args) {
  1227. case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
  1228. case 0: break;
  1229. default: goto __pyx_L5_argtuple_error;
  1230. }
  1231. kw_args = PyDict_Size(__pyx_kwds);
  1232. switch (pos_args) {
  1233. case 0:
  1234. if (kw_args > 0) {
  1235. PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_value);
  1236. if (value) { values[0] = value; kw_args--; }
  1237. }
  1238. }
  1239. if (unlikely(kw_args > 0)) {
  1240. if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 29, __pyx_L3_error)
  1241. }
  1242. } else {
  1243. switch (PyTuple_GET_SIZE(__pyx_args)) {
  1244. case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
  1245. case 0: break;
  1246. default: goto __pyx_L5_argtuple_error;
  1247. }
  1248. }
  1249. __pyx_v_value = values[0];
  1250. }
  1251. goto __pyx_L4_argument_unpacking_done;
  1252. __pyx_L5_argtuple_error:;
  1253. __Pyx_RaiseArgtupleInvalid("__init__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 29, __pyx_L3_error)
  1254. __pyx_L3_error:;
  1255. __Pyx_AddTraceback("gevent._semaphore.Semaphore.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  1256. __Pyx_RefNannyFinishContext();
  1257. return -1;
  1258. __pyx_L4_argument_unpacking_done:;
  1259. __pyx_r = __pyx_pf_6gevent_10_semaphore_9Semaphore___init__(((struct __pyx_obj_6gevent_10_semaphore_Semaphore *)__pyx_v_self), __pyx_v_value);
  1260. /* function exit code */
  1261. __Pyx_RefNannyFinishContext();
  1262. return __pyx_r;
  1263. }
  1264. static int __pyx_pf_6gevent_10_semaphore_9Semaphore___init__(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, PyObject *__pyx_v_value) {
  1265. int __pyx_r;
  1266. __Pyx_RefNannyDeclarations
  1267. PyObject *__pyx_t_1 = NULL;
  1268. int __pyx_t_2;
  1269. int __pyx_t_3;
  1270. __Pyx_RefNannySetupContext("__init__", 0);
  1271. /* "gevent/_semaphore.py":30
  1272. *
  1273. * def __init__(self, value=1):
  1274. * if value < 0: # <<<<<<<<<<<<<<
  1275. * raise ValueError("semaphore initial value must be >= 0")
  1276. * self.counter = value
  1277. */
  1278. __pyx_t_1 = PyObject_RichCompare(__pyx_v_value, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 30, __pyx_L1_error)
  1279. __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 30, __pyx_L1_error)
  1280. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  1281. if (__pyx_t_2) {
  1282. /* "gevent/_semaphore.py":31
  1283. * def __init__(self, value=1):
  1284. * if value < 0:
  1285. * raise ValueError("semaphore initial value must be >= 0") # <<<<<<<<<<<<<<
  1286. * self.counter = value
  1287. * self._dirty = False
  1288. */
  1289. __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 31, __pyx_L1_error)
  1290. __Pyx_GOTREF(__pyx_t_1);
  1291. __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  1292. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  1293. __PYX_ERR(0, 31, __pyx_L1_error)
  1294. /* "gevent/_semaphore.py":30
  1295. *
  1296. * def __init__(self, value=1):
  1297. * if value < 0: # <<<<<<<<<<<<<<
  1298. * raise ValueError("semaphore initial value must be >= 0")
  1299. * self.counter = value
  1300. */
  1301. }
  1302. /* "gevent/_semaphore.py":32
  1303. * if value < 0:
  1304. * raise ValueError("semaphore initial value must be >= 0")
  1305. * self.counter = value # <<<<<<<<<<<<<<
  1306. * self._dirty = False
  1307. * # In PyPy 2.6.1 with Cython 0.23, `cdef public` or `cdef
  1308. */
  1309. __pyx_t_3 = __Pyx_PyInt_As_int(__pyx_v_value); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 32, __pyx_L1_error)
  1310. __pyx_v_self->counter = __pyx_t_3;
  1311. /* "gevent/_semaphore.py":33
  1312. * raise ValueError("semaphore initial value must be >= 0")
  1313. * self.counter = value
  1314. * self._dirty = False # <<<<<<<<<<<<<<
  1315. * # In PyPy 2.6.1 with Cython 0.23, `cdef public` or `cdef
  1316. * # readonly` or simply `cdef` attributes of type `object` can appear to leak if
  1317. */
  1318. __pyx_v_self->_dirty = 0;
  1319. /* "gevent/_semaphore.py":47
  1320. * # CPython ("No attribute...")
  1321. * # See https://github.com/gevent/gevent/issues/660
  1322. * self._links = None # <<<<<<<<<<<<<<
  1323. * self._notifier = None
  1324. * # we don't want to do get_hub() here to allow defining module-level locks
  1325. */
  1326. __Pyx_INCREF(Py_None);
  1327. __Pyx_GIVEREF(Py_None);
  1328. __Pyx_GOTREF(__pyx_v_self->_links);
  1329. __Pyx_DECREF(__pyx_v_self->_links);
  1330. __pyx_v_self->_links = Py_None;
  1331. /* "gevent/_semaphore.py":48
  1332. * # See https://github.com/gevent/gevent/issues/660
  1333. * self._links = None
  1334. * self._notifier = None # <<<<<<<<<<<<<<
  1335. * # we don't want to do get_hub() here to allow defining module-level locks
  1336. * # without initializing the hub
  1337. */
  1338. __Pyx_INCREF(Py_None);
  1339. __Pyx_GIVEREF(Py_None);
  1340. __Pyx_GOTREF(__pyx_v_self->_notifier);
  1341. __Pyx_DECREF(__pyx_v_self->_notifier);
  1342. __pyx_v_self->_notifier = Py_None;
  1343. /* "gevent/_semaphore.py":29
  1344. * """
  1345. *
  1346. * def __init__(self, value=1): # <<<<<<<<<<<<<<
  1347. * if value < 0:
  1348. * raise ValueError("semaphore initial value must be >= 0")
  1349. */
  1350. /* function exit code */
  1351. __pyx_r = 0;
  1352. goto __pyx_L0;
  1353. __pyx_L1_error:;
  1354. __Pyx_XDECREF(__pyx_t_1);
  1355. __Pyx_AddTraceback("gevent._semaphore.Semaphore.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  1356. __pyx_r = -1;
  1357. __pyx_L0:;
  1358. __Pyx_RefNannyFinishContext();
  1359. return __pyx_r;
  1360. }
  1361. /* "gevent/_semaphore.py":52
  1362. * # without initializing the hub
  1363. *
  1364. * def __str__(self): # <<<<<<<<<<<<<<
  1365. * params = (self.__class__.__name__, self.counter, len(self._links) if self._links else 0)
  1366. * return '<%s counter=%s _links[%s]>' % params
  1367. */
  1368. /* Python wrapper */
  1369. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_3__str__(PyObject *__pyx_v_self); /*proto*/
  1370. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_3__str__(PyObject *__pyx_v_self) {
  1371. PyObject *__pyx_r = 0;
  1372. __Pyx_RefNannyDeclarations
  1373. __Pyx_RefNannySetupContext("__str__ (wrapper)", 0);
  1374. __pyx_r = __pyx_pf_6gevent_10_semaphore_9Semaphore_2__str__(((struct __pyx_obj_6gevent_10_semaphore_Semaphore *)__pyx_v_self));
  1375. /* function exit code */
  1376. __Pyx_RefNannyFinishContext();
  1377. return __pyx_r;
  1378. }
  1379. static PyObject *__pyx_pf_6gevent_10_semaphore_9Semaphore_2__str__(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self) {
  1380. PyObject *__pyx_v_params = NULL;
  1381. PyObject *__pyx_r = NULL;
  1382. __Pyx_RefNannyDeclarations
  1383. PyObject *__pyx_t_1 = NULL;
  1384. PyObject *__pyx_t_2 = NULL;
  1385. PyObject *__pyx_t_3 = NULL;
  1386. int __pyx_t_4;
  1387. PyObject *__pyx_t_5 = NULL;
  1388. Py_ssize_t __pyx_t_6;
  1389. __Pyx_RefNannySetupContext("__str__", 0);
  1390. /* "gevent/_semaphore.py":53
  1391. *
  1392. * def __str__(self):
  1393. * params = (self.__class__.__name__, self.counter, len(self._links) if self._links else 0) # <<<<<<<<<<<<<<
  1394. * return '<%s counter=%s _links[%s]>' % params
  1395. *
  1396. */
  1397. __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_class); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 53, __pyx_L1_error)
  1398. __Pyx_GOTREF(__pyx_t_1);
  1399. __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 53, __pyx_L1_error)
  1400. __Pyx_GOTREF(__pyx_t_2);
  1401. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  1402. __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->counter); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 53, __pyx_L1_error)
  1403. __Pyx_GOTREF(__pyx_t_1);
  1404. __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_self->_links); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 53, __pyx_L1_error)
  1405. if (__pyx_t_4) {
  1406. __pyx_t_5 = __pyx_v_self->_links;
  1407. __Pyx_INCREF(__pyx_t_5);
  1408. __pyx_t_6 = PyObject_Length(__pyx_t_5); if (unlikely(__pyx_t_6 == -1)) __PYX_ERR(0, 53, __pyx_L1_error)
  1409. __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  1410. __pyx_t_5 = PyInt_FromSsize_t(__pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 53, __pyx_L1_error)
  1411. __Pyx_GOTREF(__pyx_t_5);
  1412. __pyx_t_3 = __pyx_t_5;
  1413. __pyx_t_5 = 0;
  1414. } else {
  1415. __Pyx_INCREF(__pyx_int_0);
  1416. __pyx_t_3 = __pyx_int_0;
  1417. }
  1418. __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 53, __pyx_L1_error)
  1419. __Pyx_GOTREF(__pyx_t_5);
  1420. __Pyx_GIVEREF(__pyx_t_2);
  1421. PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
  1422. __Pyx_GIVEREF(__pyx_t_1);
  1423. PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);
  1424. __Pyx_GIVEREF(__pyx_t_3);
  1425. PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_3);
  1426. __pyx_t_2 = 0;
  1427. __pyx_t_1 = 0;
  1428. __pyx_t_3 = 0;
  1429. __pyx_v_params = ((PyObject*)__pyx_t_5);
  1430. __pyx_t_5 = 0;
  1431. /* "gevent/_semaphore.py":54
  1432. * def __str__(self):
  1433. * params = (self.__class__.__name__, self.counter, len(self._links) if self._links else 0)
  1434. * return '<%s counter=%s _links[%s]>' % params # <<<<<<<<<<<<<<
  1435. *
  1436. * def locked(self):
  1437. */
  1438. __Pyx_XDECREF(__pyx_r);
  1439. __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_s_counter_s__links_s, __pyx_v_params); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 54, __pyx_L1_error)
  1440. __Pyx_GOTREF(__pyx_t_5);
  1441. __pyx_r = __pyx_t_5;
  1442. __pyx_t_5 = 0;
  1443. goto __pyx_L0;
  1444. /* "gevent/_semaphore.py":52
  1445. * # without initializing the hub
  1446. *
  1447. * def __str__(self): # <<<<<<<<<<<<<<
  1448. * params = (self.__class__.__name__, self.counter, len(self._links) if self._links else 0)
  1449. * return '<%s counter=%s _links[%s]>' % params
  1450. */
  1451. /* function exit code */
  1452. __pyx_L1_error:;
  1453. __Pyx_XDECREF(__pyx_t_1);
  1454. __Pyx_XDECREF(__pyx_t_2);
  1455. __Pyx_XDECREF(__pyx_t_3);
  1456. __Pyx_XDECREF(__pyx_t_5);
  1457. __Pyx_AddTraceback("gevent._semaphore.Semaphore.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  1458. __pyx_r = NULL;
  1459. __pyx_L0:;
  1460. __Pyx_XDECREF(__pyx_v_params);
  1461. __Pyx_XGIVEREF(__pyx_r);
  1462. __Pyx_RefNannyFinishContext();
  1463. return __pyx_r;
  1464. }
  1465. /* "gevent/_semaphore.py":56
  1466. * return '<%s counter=%s _links[%s]>' % params
  1467. *
  1468. * def locked(self): # <<<<<<<<<<<<<<
  1469. * """Return a boolean indicating whether the semaphore can be acquired.
  1470. * Most useful with binary semaphores."""
  1471. */
  1472. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_5locked(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
  1473. static int __pyx_f_6gevent_10_semaphore_9Semaphore_locked(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, int __pyx_skip_dispatch) {
  1474. int __pyx_r;
  1475. __Pyx_RefNannyDeclarations
  1476. PyObject *__pyx_t_1 = NULL;
  1477. PyObject *__pyx_t_2 = NULL;
  1478. PyObject *__pyx_t_3 = NULL;
  1479. PyObject *__pyx_t_4 = NULL;
  1480. int __pyx_t_5;
  1481. __Pyx_RefNannySetupContext("locked", 0);
  1482. /* Check if called by wrapper */
  1483. if (unlikely(__pyx_skip_dispatch)) ;
  1484. /* Check if overridden in Python */
  1485. else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
  1486. __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_locked); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 56, __pyx_L1_error)
  1487. __Pyx_GOTREF(__pyx_t_1);
  1488. if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_6gevent_10_semaphore_9Semaphore_5locked)) {
  1489. __Pyx_INCREF(__pyx_t_1);
  1490. __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
  1491. if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
  1492. __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
  1493. if (likely(__pyx_t_4)) {
  1494. PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
  1495. __Pyx_INCREF(__pyx_t_4);
  1496. __Pyx_INCREF(function);
  1497. __Pyx_DECREF_SET(__pyx_t_3, function);
  1498. }
  1499. }
  1500. if (__pyx_t_4) {
  1501. __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 56, __pyx_L1_error)
  1502. __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  1503. } else {
  1504. __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 56, __pyx_L1_error)
  1505. }
  1506. __Pyx_GOTREF(__pyx_t_2);
  1507. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  1508. __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 56, __pyx_L1_error)
  1509. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  1510. __pyx_r = __pyx_t_5;
  1511. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  1512. goto __pyx_L0;
  1513. }
  1514. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  1515. }
  1516. /* "gevent/_semaphore.py":59
  1517. * """Return a boolean indicating whether the semaphore can be acquired.
  1518. * Most useful with binary semaphores."""
  1519. * return self.counter <= 0 # <<<<<<<<<<<<<<
  1520. *
  1521. * def release(self):
  1522. */
  1523. __pyx_r = (__pyx_v_self->counter <= 0);
  1524. goto __pyx_L0;
  1525. /* "gevent/_semaphore.py":56
  1526. * return '<%s counter=%s _links[%s]>' % params
  1527. *
  1528. * def locked(self): # <<<<<<<<<<<<<<
  1529. * """Return a boolean indicating whether the semaphore can be acquired.
  1530. * Most useful with binary semaphores."""
  1531. */
  1532. /* function exit code */
  1533. __pyx_L1_error:;
  1534. __Pyx_XDECREF(__pyx_t_1);
  1535. __Pyx_XDECREF(__pyx_t_2);
  1536. __Pyx_XDECREF(__pyx_t_3);
  1537. __Pyx_XDECREF(__pyx_t_4);
  1538. __Pyx_WriteUnraisable("gevent._semaphore.Semaphore.locked", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  1539. __pyx_r = 0;
  1540. __pyx_L0:;
  1541. __Pyx_RefNannyFinishContext();
  1542. return __pyx_r;
  1543. }
  1544. /* Python wrapper */
  1545. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_5locked(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
  1546. static char __pyx_doc_6gevent_10_semaphore_9Semaphore_4locked[] = "Return a boolean indicating whether the semaphore can be acquired.\n Most useful with binary semaphores.";
  1547. static PyMethodDef __pyx_mdef_6gevent_10_semaphore_9Semaphore_5locked = {"locked", (PyCFunction)__pyx_pw_6gevent_10_semaphore_9Semaphore_5locked, METH_NOARGS, __pyx_doc_6gevent_10_semaphore_9Semaphore_4locked};
  1548. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_5locked(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  1549. PyObject *__pyx_r = 0;
  1550. __Pyx_RefNannyDeclarations
  1551. __Pyx_RefNannySetupContext("locked (wrapper)", 0);
  1552. __pyx_r = __pyx_pf_6gevent_10_semaphore_9Semaphore_4locked(((struct __pyx_obj_6gevent_10_semaphore_Semaphore *)__pyx_v_self));
  1553. /* function exit code */
  1554. __Pyx_RefNannyFinishContext();
  1555. return __pyx_r;
  1556. }
  1557. static PyObject *__pyx_pf_6gevent_10_semaphore_9Semaphore_4locked(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self) {
  1558. PyObject *__pyx_r = NULL;
  1559. __Pyx_RefNannyDeclarations
  1560. PyObject *__pyx_t_1 = NULL;
  1561. __Pyx_RefNannySetupContext("locked", 0);
  1562. __Pyx_XDECREF(__pyx_r);
  1563. __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_f_6gevent_10_semaphore_9Semaphore_locked(__pyx_v_self, 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 56, __pyx_L1_error)
  1564. __Pyx_GOTREF(__pyx_t_1);
  1565. __pyx_r = __pyx_t_1;
  1566. __pyx_t_1 = 0;
  1567. goto __pyx_L0;
  1568. /* function exit code */
  1569. __pyx_L1_error:;
  1570. __Pyx_XDECREF(__pyx_t_1);
  1571. __Pyx_AddTraceback("gevent._semaphore.Semaphore.locked", __pyx_clineno, __pyx_lineno, __pyx_filename);
  1572. __pyx_r = NULL;
  1573. __pyx_L0:;
  1574. __Pyx_XGIVEREF(__pyx_r);
  1575. __Pyx_RefNannyFinishContext();
  1576. return __pyx_r;
  1577. }
  1578. /* "gevent/_semaphore.py":61
  1579. * return self.counter <= 0
  1580. *
  1581. * def release(self): # <<<<<<<<<<<<<<
  1582. * """
  1583. * Release the semaphore, notifying any waiters if needed.
  1584. */
  1585. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_7release(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
  1586. static int __pyx_f_6gevent_10_semaphore_9Semaphore_release(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, int __pyx_skip_dispatch) {
  1587. int __pyx_r;
  1588. __Pyx_RefNannyDeclarations
  1589. PyObject *__pyx_t_1 = NULL;
  1590. PyObject *__pyx_t_2 = NULL;
  1591. PyObject *__pyx_t_3 = NULL;
  1592. PyObject *__pyx_t_4 = NULL;
  1593. int __pyx_t_5;
  1594. __Pyx_RefNannySetupContext("release", 0);
  1595. /* Check if called by wrapper */
  1596. if (unlikely(__pyx_skip_dispatch)) ;
  1597. /* Check if overridden in Python */
  1598. else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
  1599. __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_release); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 61, __pyx_L1_error)
  1600. __Pyx_GOTREF(__pyx_t_1);
  1601. if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_6gevent_10_semaphore_9Semaphore_7release)) {
  1602. __Pyx_INCREF(__pyx_t_1);
  1603. __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
  1604. if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
  1605. __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
  1606. if (likely(__pyx_t_4)) {
  1607. PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
  1608. __Pyx_INCREF(__pyx_t_4);
  1609. __Pyx_INCREF(function);
  1610. __Pyx_DECREF_SET(__pyx_t_3, function);
  1611. }
  1612. }
  1613. if (__pyx_t_4) {
  1614. __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 61, __pyx_L1_error)
  1615. __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  1616. } else {
  1617. __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 61, __pyx_L1_error)
  1618. }
  1619. __Pyx_GOTREF(__pyx_t_2);
  1620. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  1621. __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 61, __pyx_L1_error)
  1622. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  1623. __pyx_r = __pyx_t_5;
  1624. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  1625. goto __pyx_L0;
  1626. }
  1627. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  1628. }
  1629. /* "gevent/_semaphore.py":65
  1630. * Release the semaphore, notifying any waiters if needed.
  1631. * """
  1632. * self.counter += 1 # <<<<<<<<<<<<<<
  1633. * self._start_notify()
  1634. * return self.counter
  1635. */
  1636. __pyx_v_self->counter = (__pyx_v_self->counter + 1);
  1637. /* "gevent/_semaphore.py":66
  1638. * """
  1639. * self.counter += 1
  1640. * self._start_notify() # <<<<<<<<<<<<<<
  1641. * return self.counter
  1642. *
  1643. */
  1644. __pyx_t_1 = ((struct __pyx_vtabstruct_6gevent_10_semaphore_Semaphore *)__pyx_v_self->__pyx_vtab)->_start_notify(__pyx_v_self, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 66, __pyx_L1_error)
  1645. __Pyx_GOTREF(__pyx_t_1);
  1646. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  1647. /* "gevent/_semaphore.py":67
  1648. * self.counter += 1
  1649. * self._start_notify()
  1650. * return self.counter # <<<<<<<<<<<<<<
  1651. *
  1652. * def _start_notify(self):
  1653. */
  1654. __pyx_r = __pyx_v_self->counter;
  1655. goto __pyx_L0;
  1656. /* "gevent/_semaphore.py":61
  1657. * return self.counter <= 0
  1658. *
  1659. * def release(self): # <<<<<<<<<<<<<<
  1660. * """
  1661. * Release the semaphore, notifying any waiters if needed.
  1662. */
  1663. /* function exit code */
  1664. __pyx_L1_error:;
  1665. __Pyx_XDECREF(__pyx_t_1);
  1666. __Pyx_XDECREF(__pyx_t_2);
  1667. __Pyx_XDECREF(__pyx_t_3);
  1668. __Pyx_XDECREF(__pyx_t_4);
  1669. __Pyx_AddTraceback("gevent._semaphore.Semaphore.release", __pyx_clineno, __pyx_lineno, __pyx_filename);
  1670. __pyx_r = -1000;
  1671. __pyx_L0:;
  1672. __Pyx_RefNannyFinishContext();
  1673. return __pyx_r;
  1674. }
  1675. /* Python wrapper */
  1676. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_7release(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
  1677. static char __pyx_doc_6gevent_10_semaphore_9Semaphore_6release[] = "\n Release the semaphore, notifying any waiters if needed.\n ";
  1678. static PyMethodDef __pyx_mdef_6gevent_10_semaphore_9Semaphore_7release = {"release", (PyCFunction)__pyx_pw_6gevent_10_semaphore_9Semaphore_7release, METH_NOARGS, __pyx_doc_6gevent_10_semaphore_9Semaphore_6release};
  1679. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_7release(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  1680. PyObject *__pyx_r = 0;
  1681. __Pyx_RefNannyDeclarations
  1682. __Pyx_RefNannySetupContext("release (wrapper)", 0);
  1683. __pyx_r = __pyx_pf_6gevent_10_semaphore_9Semaphore_6release(((struct __pyx_obj_6gevent_10_semaphore_Semaphore *)__pyx_v_self));
  1684. /* function exit code */
  1685. __Pyx_RefNannyFinishContext();
  1686. return __pyx_r;
  1687. }
  1688. static PyObject *__pyx_pf_6gevent_10_semaphore_9Semaphore_6release(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self) {
  1689. PyObject *__pyx_r = NULL;
  1690. __Pyx_RefNannyDeclarations
  1691. int __pyx_t_1;
  1692. PyObject *__pyx_t_2 = NULL;
  1693. __Pyx_RefNannySetupContext("release", 0);
  1694. __Pyx_XDECREF(__pyx_r);
  1695. __pyx_t_1 = __pyx_f_6gevent_10_semaphore_9Semaphore_release(__pyx_v_self, 1); if (unlikely(__pyx_t_1 == -1000)) __PYX_ERR(0, 61, __pyx_L1_error)
  1696. __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 61, __pyx_L1_error)
  1697. __Pyx_GOTREF(__pyx_t_2);
  1698. __pyx_r = __pyx_t_2;
  1699. __pyx_t_2 = 0;
  1700. goto __pyx_L0;
  1701. /* function exit code */
  1702. __pyx_L1_error:;
  1703. __Pyx_XDECREF(__pyx_t_2);
  1704. __Pyx_AddTraceback("gevent._semaphore.Semaphore.release", __pyx_clineno, __pyx_lineno, __pyx_filename);
  1705. __pyx_r = NULL;
  1706. __pyx_L0:;
  1707. __Pyx_XGIVEREF(__pyx_r);
  1708. __Pyx_RefNannyFinishContext();
  1709. return __pyx_r;
  1710. }
  1711. /* "gevent/_semaphore.py":69
  1712. * return self.counter
  1713. *
  1714. * def _start_notify(self): # <<<<<<<<<<<<<<
  1715. * if self._links and self.counter > 0 and not self._notifier:
  1716. * # We create a new self._notifier each time through the loop,
  1717. */
  1718. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_9_start_notify(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
  1719. static PyObject *__pyx_f_6gevent_10_semaphore_9Semaphore__start_notify(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, int __pyx_skip_dispatch) {
  1720. PyObject *__pyx_r = NULL;
  1721. __Pyx_RefNannyDeclarations
  1722. PyObject *__pyx_t_1 = NULL;
  1723. PyObject *__pyx_t_2 = NULL;
  1724. PyObject *__pyx_t_3 = NULL;
  1725. PyObject *__pyx_t_4 = NULL;
  1726. int __pyx_t_5;
  1727. int __pyx_t_6;
  1728. int __pyx_t_7;
  1729. PyObject *__pyx_t_8 = NULL;
  1730. __Pyx_RefNannySetupContext("_start_notify", 0);
  1731. /* Check if called by wrapper */
  1732. if (unlikely(__pyx_skip_dispatch)) ;
  1733. /* Check if overridden in Python */
  1734. else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
  1735. __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_start_notify); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 69, __pyx_L1_error)
  1736. __Pyx_GOTREF(__pyx_t_1);
  1737. if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_6gevent_10_semaphore_9Semaphore_9_start_notify)) {
  1738. __Pyx_XDECREF(__pyx_r);
  1739. __Pyx_INCREF(__pyx_t_1);
  1740. __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
  1741. if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
  1742. __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
  1743. if (likely(__pyx_t_4)) {
  1744. PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
  1745. __Pyx_INCREF(__pyx_t_4);
  1746. __Pyx_INCREF(function);
  1747. __Pyx_DECREF_SET(__pyx_t_3, function);
  1748. }
  1749. }
  1750. if (__pyx_t_4) {
  1751. __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 69, __pyx_L1_error)
  1752. __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  1753. } else {
  1754. __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 69, __pyx_L1_error)
  1755. }
  1756. __Pyx_GOTREF(__pyx_t_2);
  1757. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  1758. __pyx_r = __pyx_t_2;
  1759. __pyx_t_2 = 0;
  1760. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  1761. goto __pyx_L0;
  1762. }
  1763. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  1764. }
  1765. /* "gevent/_semaphore.py":70
  1766. *
  1767. * def _start_notify(self):
  1768. * if self._links and self.counter > 0 and not self._notifier: # <<<<<<<<<<<<<<
  1769. * # We create a new self._notifier each time through the loop,
  1770. * # if needed. (it has a __bool__ method that tells whether it has
  1771. */
  1772. __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_self->_links); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 70, __pyx_L1_error)
  1773. if (__pyx_t_6) {
  1774. } else {
  1775. __pyx_t_5 = __pyx_t_6;
  1776. goto __pyx_L4_bool_binop_done;
  1777. }
  1778. __pyx_t_6 = ((__pyx_v_self->counter > 0) != 0);
  1779. if (__pyx_t_6) {
  1780. } else {
  1781. __pyx_t_5 = __pyx_t_6;
  1782. goto __pyx_L4_bool_binop_done;
  1783. }
  1784. __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_self->_notifier); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 70, __pyx_L1_error)
  1785. __pyx_t_7 = ((!__pyx_t_6) != 0);
  1786. __pyx_t_5 = __pyx_t_7;
  1787. __pyx_L4_bool_binop_done:;
  1788. if (__pyx_t_5) {
  1789. /* "gevent/_semaphore.py":78
  1790. * # with Cython <= 0.23.3. You must use >= 0.23.4.
  1791. * # See https://bitbucket.org/pypy/pypy/issues/2149/memory-leak-for-python-subclass-of-cpyext#comment-22371546
  1792. * self._notifier = get_hub().loop.run_callback(self._notify_links) # <<<<<<<<<<<<<<
  1793. *
  1794. * def _notify_links(self):
  1795. */
  1796. __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_get_hub); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 78, __pyx_L1_error)
  1797. __Pyx_GOTREF(__pyx_t_3);
  1798. __pyx_t_4 = NULL;
  1799. if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
  1800. __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
  1801. if (likely(__pyx_t_4)) {
  1802. PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
  1803. __Pyx_INCREF(__pyx_t_4);
  1804. __Pyx_INCREF(function);
  1805. __Pyx_DECREF_SET(__pyx_t_3, function);
  1806. }
  1807. }
  1808. if (__pyx_t_4) {
  1809. __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 78, __pyx_L1_error)
  1810. __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  1811. } else {
  1812. __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 78, __pyx_L1_error)
  1813. }
  1814. __Pyx_GOTREF(__pyx_t_2);
  1815. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  1816. __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_loop); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 78, __pyx_L1_error)
  1817. __Pyx_GOTREF(__pyx_t_3);
  1818. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  1819. __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_run_callback); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 78, __pyx_L1_error)
  1820. __Pyx_GOTREF(__pyx_t_2);
  1821. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  1822. __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_notify_links); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 78, __pyx_L1_error)
  1823. __Pyx_GOTREF(__pyx_t_3);
  1824. __pyx_t_4 = NULL;
  1825. if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
  1826. __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
  1827. if (likely(__pyx_t_4)) {
  1828. PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
  1829. __Pyx_INCREF(__pyx_t_4);
  1830. __Pyx_INCREF(function);
  1831. __Pyx_DECREF_SET(__pyx_t_2, function);
  1832. }
  1833. }
  1834. if (!__pyx_t_4) {
  1835. __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 78, __pyx_L1_error)
  1836. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  1837. __Pyx_GOTREF(__pyx_t_1);
  1838. } else {
  1839. #if CYTHON_FAST_PYCALL
  1840. if (PyFunction_Check(__pyx_t_2)) {
  1841. PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_3};
  1842. __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 78, __pyx_L1_error)
  1843. __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  1844. __Pyx_GOTREF(__pyx_t_1);
  1845. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  1846. } else
  1847. #endif
  1848. #if CYTHON_FAST_PYCCALL
  1849. if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
  1850. PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_3};
  1851. __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 78, __pyx_L1_error)
  1852. __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  1853. __Pyx_GOTREF(__pyx_t_1);
  1854. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  1855. } else
  1856. #endif
  1857. {
  1858. __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 78, __pyx_L1_error)
  1859. __Pyx_GOTREF(__pyx_t_8);
  1860. __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_4); __pyx_t_4 = NULL;
  1861. __Pyx_GIVEREF(__pyx_t_3);
  1862. PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_t_3);
  1863. __pyx_t_3 = 0;
  1864. __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 78, __pyx_L1_error)
  1865. __Pyx_GOTREF(__pyx_t_1);
  1866. __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  1867. }
  1868. }
  1869. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  1870. __Pyx_GIVEREF(__pyx_t_1);
  1871. __Pyx_GOTREF(__pyx_v_self->_notifier);
  1872. __Pyx_DECREF(__pyx_v_self->_notifier);
  1873. __pyx_v_self->_notifier = __pyx_t_1;
  1874. __pyx_t_1 = 0;
  1875. /* "gevent/_semaphore.py":70
  1876. *
  1877. * def _start_notify(self):
  1878. * if self._links and self.counter > 0 and not self._notifier: # <<<<<<<<<<<<<<
  1879. * # We create a new self._notifier each time through the loop,
  1880. * # if needed. (it has a __bool__ method that tells whether it has
  1881. */
  1882. }
  1883. /* "gevent/_semaphore.py":69
  1884. * return self.counter
  1885. *
  1886. * def _start_notify(self): # <<<<<<<<<<<<<<
  1887. * if self._links and self.counter > 0 and not self._notifier:
  1888. * # We create a new self._notifier each time through the loop,
  1889. */
  1890. /* function exit code */
  1891. __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  1892. goto __pyx_L0;
  1893. __pyx_L1_error:;
  1894. __Pyx_XDECREF(__pyx_t_1);
  1895. __Pyx_XDECREF(__pyx_t_2);
  1896. __Pyx_XDECREF(__pyx_t_3);
  1897. __Pyx_XDECREF(__pyx_t_4);
  1898. __Pyx_XDECREF(__pyx_t_8);
  1899. __Pyx_AddTraceback("gevent._semaphore.Semaphore._start_notify", __pyx_clineno, __pyx_lineno, __pyx_filename);
  1900. __pyx_r = 0;
  1901. __pyx_L0:;
  1902. __Pyx_XGIVEREF(__pyx_r);
  1903. __Pyx_RefNannyFinishContext();
  1904. return __pyx_r;
  1905. }
  1906. /* Python wrapper */
  1907. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_9_start_notify(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
  1908. static PyMethodDef __pyx_mdef_6gevent_10_semaphore_9Semaphore_9_start_notify = {"_start_notify", (PyCFunction)__pyx_pw_6gevent_10_semaphore_9Semaphore_9_start_notify, METH_NOARGS, 0};
  1909. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_9_start_notify(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  1910. PyObject *__pyx_r = 0;
  1911. __Pyx_RefNannyDeclarations
  1912. __Pyx_RefNannySetupContext("_start_notify (wrapper)", 0);
  1913. __pyx_r = __pyx_pf_6gevent_10_semaphore_9Semaphore_8_start_notify(((struct __pyx_obj_6gevent_10_semaphore_Semaphore *)__pyx_v_self));
  1914. /* function exit code */
  1915. __Pyx_RefNannyFinishContext();
  1916. return __pyx_r;
  1917. }
  1918. static PyObject *__pyx_pf_6gevent_10_semaphore_9Semaphore_8_start_notify(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self) {
  1919. PyObject *__pyx_r = NULL;
  1920. __Pyx_RefNannyDeclarations
  1921. PyObject *__pyx_t_1 = NULL;
  1922. __Pyx_RefNannySetupContext("_start_notify", 0);
  1923. __Pyx_XDECREF(__pyx_r);
  1924. __pyx_t_1 = __pyx_f_6gevent_10_semaphore_9Semaphore__start_notify(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 69, __pyx_L1_error)
  1925. __Pyx_GOTREF(__pyx_t_1);
  1926. __pyx_r = __pyx_t_1;
  1927. __pyx_t_1 = 0;
  1928. goto __pyx_L0;
  1929. /* function exit code */
  1930. __pyx_L1_error:;
  1931. __Pyx_XDECREF(__pyx_t_1);
  1932. __Pyx_AddTraceback("gevent._semaphore.Semaphore._start_notify", __pyx_clineno, __pyx_lineno, __pyx_filename);
  1933. __pyx_r = NULL;
  1934. __pyx_L0:;
  1935. __Pyx_XGIVEREF(__pyx_r);
  1936. __Pyx_RefNannyFinishContext();
  1937. return __pyx_r;
  1938. }
  1939. /* "gevent/_semaphore.py":80
  1940. * self._notifier = get_hub().loop.run_callback(self._notify_links)
  1941. *
  1942. * def _notify_links(self): # <<<<<<<<<<<<<<
  1943. * # Subclasses CANNOT override. This is a cdef method.
  1944. *
  1945. */
  1946. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_11_notify_links(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
  1947. static PyObject *__pyx_f_6gevent_10_semaphore_9Semaphore__notify_links(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, int __pyx_skip_dispatch) {
  1948. PyObject *__pyx_v_notifier = NULL;
  1949. PyObject *__pyx_v_link = NULL;
  1950. PyObject *__pyx_r = NULL;
  1951. __Pyx_RefNannyDeclarations
  1952. PyObject *__pyx_t_1 = NULL;
  1953. PyObject *__pyx_t_2 = NULL;
  1954. PyObject *__pyx_t_3 = NULL;
  1955. PyObject *__pyx_t_4 = NULL;
  1956. int __pyx_t_5;
  1957. int __pyx_t_6;
  1958. Py_ssize_t __pyx_t_7;
  1959. PyObject *(*__pyx_t_8)(PyObject *);
  1960. PyObject *__pyx_t_9 = NULL;
  1961. PyObject *__pyx_t_10 = NULL;
  1962. PyObject *__pyx_t_11 = NULL;
  1963. PyObject *__pyx_t_12 = NULL;
  1964. PyObject *__pyx_t_13 = NULL;
  1965. PyObject *__pyx_t_14 = NULL;
  1966. PyObject *__pyx_t_15 = NULL;
  1967. PyObject *__pyx_t_16 = NULL;
  1968. int __pyx_t_17;
  1969. int __pyx_t_18;
  1970. char const *__pyx_t_19;
  1971. PyObject *__pyx_t_20 = NULL;
  1972. PyObject *__pyx_t_21 = NULL;
  1973. PyObject *__pyx_t_22 = NULL;
  1974. __Pyx_RefNannySetupContext("_notify_links", 0);
  1975. /* Check if called by wrapper */
  1976. if (unlikely(__pyx_skip_dispatch)) ;
  1977. /* Check if overridden in Python */
  1978. else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
  1979. __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_notify_links); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 80, __pyx_L1_error)
  1980. __Pyx_GOTREF(__pyx_t_1);
  1981. if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_6gevent_10_semaphore_9Semaphore_11_notify_links)) {
  1982. __Pyx_XDECREF(__pyx_r);
  1983. __Pyx_INCREF(__pyx_t_1);
  1984. __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
  1985. if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
  1986. __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
  1987. if (likely(__pyx_t_4)) {
  1988. PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
  1989. __Pyx_INCREF(__pyx_t_4);
  1990. __Pyx_INCREF(function);
  1991. __Pyx_DECREF_SET(__pyx_t_3, function);
  1992. }
  1993. }
  1994. if (__pyx_t_4) {
  1995. __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 80, __pyx_L1_error)
  1996. __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  1997. } else {
  1998. __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 80, __pyx_L1_error)
  1999. }
  2000. __Pyx_GOTREF(__pyx_t_2);
  2001. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  2002. __pyx_r = __pyx_t_2;
  2003. __pyx_t_2 = 0;
  2004. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  2005. goto __pyx_L0;
  2006. }
  2007. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  2008. }
  2009. /* "gevent/_semaphore.py":89
  2010. * # no need to keep it around until that point (making it potentially climb
  2011. * # into older GC generations, notably on PyPy)
  2012. * notifier = self._notifier # <<<<<<<<<<<<<<
  2013. * try:
  2014. * while True:
  2015. */
  2016. __pyx_t_1 = __pyx_v_self->_notifier;
  2017. __Pyx_INCREF(__pyx_t_1);
  2018. __pyx_v_notifier = __pyx_t_1;
  2019. __pyx_t_1 = 0;
  2020. /* "gevent/_semaphore.py":90
  2021. * # into older GC generations, notably on PyPy)
  2022. * notifier = self._notifier
  2023. * try: # <<<<<<<<<<<<<<
  2024. * while True:
  2025. * self._dirty = False
  2026. */
  2027. /*try:*/ {
  2028. /* "gevent/_semaphore.py":91
  2029. * notifier = self._notifier
  2030. * try:
  2031. * while True: # <<<<<<<<<<<<<<
  2032. * self._dirty = False
  2033. * if not self._links:
  2034. */
  2035. while (1) {
  2036. /* "gevent/_semaphore.py":92
  2037. * try:
  2038. * while True:
  2039. * self._dirty = False # <<<<<<<<<<<<<<
  2040. * if not self._links:
  2041. * # In case we were manually unlinked before
  2042. */
  2043. __pyx_v_self->_dirty = 0;
  2044. /* "gevent/_semaphore.py":93
  2045. * while True:
  2046. * self._dirty = False
  2047. * if not self._links: # <<<<<<<<<<<<<<
  2048. * # In case we were manually unlinked before
  2049. * # the callback. Which shouldn't happen
  2050. */
  2051. __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_self->_links); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 93, __pyx_L4_error)
  2052. __pyx_t_6 = ((!__pyx_t_5) != 0);
  2053. if (__pyx_t_6) {
  2054. /* "gevent/_semaphore.py":96
  2055. * # In case we were manually unlinked before
  2056. * # the callback. Which shouldn't happen
  2057. * return # <<<<<<<<<<<<<<
  2058. * for link in self._links:
  2059. * if self.counter <= 0:
  2060. */
  2061. __Pyx_XDECREF(__pyx_r);
  2062. __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  2063. goto __pyx_L3_return;
  2064. /* "gevent/_semaphore.py":93
  2065. * while True:
  2066. * self._dirty = False
  2067. * if not self._links: # <<<<<<<<<<<<<<
  2068. * # In case we were manually unlinked before
  2069. * # the callback. Which shouldn't happen
  2070. */
  2071. }
  2072. /* "gevent/_semaphore.py":97
  2073. * # the callback. Which shouldn't happen
  2074. * return
  2075. * for link in self._links: # <<<<<<<<<<<<<<
  2076. * if self.counter <= 0:
  2077. * return
  2078. */
  2079. if (likely(PyList_CheckExact(__pyx_v_self->_links)) || PyTuple_CheckExact(__pyx_v_self->_links)) {
  2080. __pyx_t_1 = __pyx_v_self->_links; __Pyx_INCREF(__pyx_t_1); __pyx_t_7 = 0;
  2081. __pyx_t_8 = NULL;
  2082. } else {
  2083. __pyx_t_7 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_self->_links); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 97, __pyx_L4_error)
  2084. __Pyx_GOTREF(__pyx_t_1);
  2085. __pyx_t_8 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 97, __pyx_L4_error)
  2086. }
  2087. for (;;) {
  2088. if (likely(!__pyx_t_8)) {
  2089. if (likely(PyList_CheckExact(__pyx_t_1))) {
  2090. if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_1)) break;
  2091. #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
  2092. __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_7); __Pyx_INCREF(__pyx_t_2); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 97, __pyx_L4_error)
  2093. #else
  2094. __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 97, __pyx_L4_error)
  2095. __Pyx_GOTREF(__pyx_t_2);
  2096. #endif
  2097. } else {
  2098. if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
  2099. #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
  2100. __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_7); __Pyx_INCREF(__pyx_t_2); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 97, __pyx_L4_error)
  2101. #else
  2102. __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 97, __pyx_L4_error)
  2103. __Pyx_GOTREF(__pyx_t_2);
  2104. #endif
  2105. }
  2106. } else {
  2107. __pyx_t_2 = __pyx_t_8(__pyx_t_1);
  2108. if (unlikely(!__pyx_t_2)) {
  2109. PyObject* exc_type = PyErr_Occurred();
  2110. if (exc_type) {
  2111. if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
  2112. else __PYX_ERR(0, 97, __pyx_L4_error)
  2113. }
  2114. break;
  2115. }
  2116. __Pyx_GOTREF(__pyx_t_2);
  2117. }
  2118. __Pyx_XDECREF_SET(__pyx_v_link, __pyx_t_2);
  2119. __pyx_t_2 = 0;
  2120. /* "gevent/_semaphore.py":98
  2121. * return
  2122. * for link in self._links:
  2123. * if self.counter <= 0: # <<<<<<<<<<<<<<
  2124. * return
  2125. * try:
  2126. */
  2127. __pyx_t_6 = ((__pyx_v_self->counter <= 0) != 0);
  2128. if (__pyx_t_6) {
  2129. /* "gevent/_semaphore.py":99
  2130. * for link in self._links:
  2131. * if self.counter <= 0:
  2132. * return # <<<<<<<<<<<<<<
  2133. * try:
  2134. * link(self) # Must use Cython >= 0.23.4 on PyPy else this leaks memory
  2135. */
  2136. __Pyx_XDECREF(__pyx_r);
  2137. __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  2138. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  2139. goto __pyx_L3_return;
  2140. /* "gevent/_semaphore.py":98
  2141. * return
  2142. * for link in self._links:
  2143. * if self.counter <= 0: # <<<<<<<<<<<<<<
  2144. * return
  2145. * try:
  2146. */
  2147. }
  2148. /* "gevent/_semaphore.py":100
  2149. * if self.counter <= 0:
  2150. * return
  2151. * try: # <<<<<<<<<<<<<<
  2152. * link(self) # Must use Cython >= 0.23.4 on PyPy else this leaks memory
  2153. * except: # pylint:disable=bare-except
  2154. */
  2155. {
  2156. __Pyx_PyThreadState_declare
  2157. __Pyx_PyThreadState_assign
  2158. __Pyx_ExceptionSave(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
  2159. __Pyx_XGOTREF(__pyx_t_9);
  2160. __Pyx_XGOTREF(__pyx_t_10);
  2161. __Pyx_XGOTREF(__pyx_t_11);
  2162. /*try:*/ {
  2163. /* "gevent/_semaphore.py":101
  2164. * return
  2165. * try:
  2166. * link(self) # Must use Cython >= 0.23.4 on PyPy else this leaks memory # <<<<<<<<<<<<<<
  2167. * except: # pylint:disable=bare-except
  2168. * getcurrent().handle_error((link, self), *sys.exc_info())
  2169. */
  2170. __Pyx_INCREF(__pyx_v_link);
  2171. __pyx_t_3 = __pyx_v_link; __pyx_t_4 = NULL;
  2172. if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
  2173. __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
  2174. if (likely(__pyx_t_4)) {
  2175. PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
  2176. __Pyx_INCREF(__pyx_t_4);
  2177. __Pyx_INCREF(function);
  2178. __Pyx_DECREF_SET(__pyx_t_3, function);
  2179. }
  2180. }
  2181. if (!__pyx_t_4) {
  2182. __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, ((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 101, __pyx_L12_error)
  2183. __Pyx_GOTREF(__pyx_t_2);
  2184. } else {
  2185. #if CYTHON_FAST_PYCALL
  2186. if (PyFunction_Check(__pyx_t_3)) {
  2187. PyObject *__pyx_temp[2] = {__pyx_t_4, ((PyObject *)__pyx_v_self)};
  2188. __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 101, __pyx_L12_error)
  2189. __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  2190. __Pyx_GOTREF(__pyx_t_2);
  2191. } else
  2192. #endif
  2193. #if CYTHON_FAST_PYCCALL
  2194. if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
  2195. PyObject *__pyx_temp[2] = {__pyx_t_4, ((PyObject *)__pyx_v_self)};
  2196. __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 101, __pyx_L12_error)
  2197. __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  2198. __Pyx_GOTREF(__pyx_t_2);
  2199. } else
  2200. #endif
  2201. {
  2202. __pyx_t_12 = PyTuple_New(1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 101, __pyx_L12_error)
  2203. __Pyx_GOTREF(__pyx_t_12);
  2204. __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_4); __pyx_t_4 = NULL;
  2205. __Pyx_INCREF(((PyObject *)__pyx_v_self));
  2206. __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  2207. PyTuple_SET_ITEM(__pyx_t_12, 0+1, ((PyObject *)__pyx_v_self));
  2208. __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_12, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 101, __pyx_L12_error)
  2209. __Pyx_GOTREF(__pyx_t_2);
  2210. __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  2211. }
  2212. }
  2213. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  2214. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  2215. /* "gevent/_semaphore.py":100
  2216. * if self.counter <= 0:
  2217. * return
  2218. * try: # <<<<<<<<<<<<<<
  2219. * link(self) # Must use Cython >= 0.23.4 on PyPy else this leaks memory
  2220. * except: # pylint:disable=bare-except
  2221. */
  2222. }
  2223. __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
  2224. __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
  2225. __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
  2226. goto __pyx_L19_try_end;
  2227. __pyx_L12_error:;
  2228. __Pyx_PyThreadState_assign
  2229. __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  2230. __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
  2231. __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  2232. __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  2233. /* "gevent/_semaphore.py":102
  2234. * try:
  2235. * link(self) # Must use Cython >= 0.23.4 on PyPy else this leaks memory
  2236. * except: # pylint:disable=bare-except # <<<<<<<<<<<<<<
  2237. * getcurrent().handle_error((link, self), *sys.exc_info())
  2238. * if self._dirty:
  2239. */
  2240. /*except:*/ {
  2241. __Pyx_AddTraceback("gevent._semaphore.Semaphore._notify_links", __pyx_clineno, __pyx_lineno, __pyx_filename);
  2242. if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_3, &__pyx_t_12) < 0) __PYX_ERR(0, 102, __pyx_L14_except_error)
  2243. __Pyx_GOTREF(__pyx_t_2);
  2244. __Pyx_GOTREF(__pyx_t_3);
  2245. __Pyx_GOTREF(__pyx_t_12);
  2246. /* "gevent/_semaphore.py":103
  2247. * link(self) # Must use Cython >= 0.23.4 on PyPy else this leaks memory
  2248. * except: # pylint:disable=bare-except
  2249. * getcurrent().handle_error((link, self), *sys.exc_info()) # <<<<<<<<<<<<<<
  2250. * if self._dirty:
  2251. * # We mutated self._links so we need to start over
  2252. */
  2253. __pyx_t_13 = __Pyx_GetModuleGlobalName(__pyx_n_s_getcurrent); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 103, __pyx_L14_except_error)
  2254. __Pyx_GOTREF(__pyx_t_13);
  2255. __pyx_t_14 = NULL;
  2256. if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_13))) {
  2257. __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_13);
  2258. if (likely(__pyx_t_14)) {
  2259. PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
  2260. __Pyx_INCREF(__pyx_t_14);
  2261. __Pyx_INCREF(function);
  2262. __Pyx_DECREF_SET(__pyx_t_13, function);
  2263. }
  2264. }
  2265. if (__pyx_t_14) {
  2266. __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_14); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 103, __pyx_L14_except_error)
  2267. __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  2268. } else {
  2269. __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_t_13); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 103, __pyx_L14_except_error)
  2270. }
  2271. __Pyx_GOTREF(__pyx_t_4);
  2272. __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  2273. __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_handle_error); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 103, __pyx_L14_except_error)
  2274. __Pyx_GOTREF(__pyx_t_13);
  2275. __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  2276. __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 103, __pyx_L14_except_error)
  2277. __Pyx_GOTREF(__pyx_t_4);
  2278. __Pyx_INCREF(__pyx_v_link);
  2279. __Pyx_GIVEREF(__pyx_v_link);
  2280. PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_link);
  2281. __Pyx_INCREF(((PyObject *)__pyx_v_self));
  2282. __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  2283. PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_v_self));
  2284. __pyx_t_14 = PyTuple_New(1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 103, __pyx_L14_except_error)
  2285. __Pyx_GOTREF(__pyx_t_14);
  2286. __Pyx_GIVEREF(__pyx_t_4);
  2287. PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_4);
  2288. __pyx_t_4 = 0;
  2289. __pyx_t_15 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 103, __pyx_L14_except_error)
  2290. __Pyx_GOTREF(__pyx_t_15);
  2291. __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_exc_info); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 103, __pyx_L14_except_error)
  2292. __Pyx_GOTREF(__pyx_t_16);
  2293. __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  2294. __pyx_t_15 = NULL;
  2295. if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_16))) {
  2296. __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_16);
  2297. if (likely(__pyx_t_15)) {
  2298. PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16);
  2299. __Pyx_INCREF(__pyx_t_15);
  2300. __Pyx_INCREF(function);
  2301. __Pyx_DECREF_SET(__pyx_t_16, function);
  2302. }
  2303. }
  2304. if (__pyx_t_15) {
  2305. __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_16, __pyx_t_15); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 103, __pyx_L14_except_error)
  2306. __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  2307. } else {
  2308. __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_t_16); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 103, __pyx_L14_except_error)
  2309. }
  2310. __Pyx_GOTREF(__pyx_t_4);
  2311. __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  2312. __pyx_t_16 = PySequence_Tuple(__pyx_t_4); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 103, __pyx_L14_except_error)
  2313. __Pyx_GOTREF(__pyx_t_16);
  2314. __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  2315. __pyx_t_4 = PyNumber_Add(__pyx_t_14, __pyx_t_16); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 103, __pyx_L14_except_error)
  2316. __Pyx_GOTREF(__pyx_t_4);
  2317. __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  2318. __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  2319. __pyx_t_16 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_4, NULL); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 103, __pyx_L14_except_error)
  2320. __Pyx_GOTREF(__pyx_t_16);
  2321. __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  2322. __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  2323. __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
  2324. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  2325. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  2326. __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  2327. goto __pyx_L13_exception_handled;
  2328. }
  2329. __pyx_L14_except_error:;
  2330. /* "gevent/_semaphore.py":100
  2331. * if self.counter <= 0:
  2332. * return
  2333. * try: # <<<<<<<<<<<<<<
  2334. * link(self) # Must use Cython >= 0.23.4 on PyPy else this leaks memory
  2335. * except: # pylint:disable=bare-except
  2336. */
  2337. __Pyx_PyThreadState_assign
  2338. __Pyx_XGIVEREF(__pyx_t_9);
  2339. __Pyx_XGIVEREF(__pyx_t_10);
  2340. __Pyx_XGIVEREF(__pyx_t_11);
  2341. __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11);
  2342. goto __pyx_L4_error;
  2343. __pyx_L13_exception_handled:;
  2344. __Pyx_PyThreadState_assign
  2345. __Pyx_XGIVEREF(__pyx_t_9);
  2346. __Pyx_XGIVEREF(__pyx_t_10);
  2347. __Pyx_XGIVEREF(__pyx_t_11);
  2348. __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11);
  2349. __pyx_L19_try_end:;
  2350. }
  2351. /* "gevent/_semaphore.py":104
  2352. * except: # pylint:disable=bare-except
  2353. * getcurrent().handle_error((link, self), *sys.exc_info())
  2354. * if self._dirty: # <<<<<<<<<<<<<<
  2355. * # We mutated self._links so we need to start over
  2356. * break
  2357. */
  2358. __pyx_t_6 = (__pyx_v_self->_dirty != 0);
  2359. if (__pyx_t_6) {
  2360. /* "gevent/_semaphore.py":106
  2361. * if self._dirty:
  2362. * # We mutated self._links so we need to start over
  2363. * break # <<<<<<<<<<<<<<
  2364. * if not self._dirty:
  2365. * return
  2366. */
  2367. goto __pyx_L10_break;
  2368. /* "gevent/_semaphore.py":104
  2369. * except: # pylint:disable=bare-except
  2370. * getcurrent().handle_error((link, self), *sys.exc_info())
  2371. * if self._dirty: # <<<<<<<<<<<<<<
  2372. * # We mutated self._links so we need to start over
  2373. * break
  2374. */
  2375. }
  2376. /* "gevent/_semaphore.py":97
  2377. * # the callback. Which shouldn't happen
  2378. * return
  2379. * for link in self._links: # <<<<<<<<<<<<<<
  2380. * if self.counter <= 0:
  2381. * return
  2382. */
  2383. }
  2384. __pyx_L10_break:;
  2385. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  2386. /* "gevent/_semaphore.py":107
  2387. * # We mutated self._links so we need to start over
  2388. * break
  2389. * if not self._dirty: # <<<<<<<<<<<<<<
  2390. * return
  2391. * finally:
  2392. */
  2393. __pyx_t_6 = ((!(__pyx_v_self->_dirty != 0)) != 0);
  2394. if (__pyx_t_6) {
  2395. /* "gevent/_semaphore.py":108
  2396. * break
  2397. * if not self._dirty:
  2398. * return # <<<<<<<<<<<<<<
  2399. * finally:
  2400. * # We should not have created a new notifier even if callbacks
  2401. */
  2402. __Pyx_XDECREF(__pyx_r);
  2403. __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  2404. goto __pyx_L3_return;
  2405. /* "gevent/_semaphore.py":107
  2406. * # We mutated self._links so we need to start over
  2407. * break
  2408. * if not self._dirty: # <<<<<<<<<<<<<<
  2409. * return
  2410. * finally:
  2411. */
  2412. }
  2413. }
  2414. }
  2415. /* "gevent/_semaphore.py":113
  2416. * # released us because we loop through *all* of our links on the
  2417. * # same callback while self._notifier is still true.
  2418. * assert self._notifier is notifier # <<<<<<<<<<<<<<
  2419. * self._notifier = None
  2420. *
  2421. */
  2422. /*finally:*/ {
  2423. /*normal exit:*/{
  2424. #ifndef CYTHON_WITHOUT_ASSERTIONS
  2425. if (unlikely(!Py_OptimizeFlag)) {
  2426. __pyx_t_6 = (__pyx_v_self->_notifier == __pyx_v_notifier);
  2427. if (unlikely(!(__pyx_t_6 != 0))) {
  2428. PyErr_SetNone(PyExc_AssertionError);
  2429. __PYX_ERR(0, 113, __pyx_L1_error)
  2430. }
  2431. }
  2432. #endif
  2433. /* "gevent/_semaphore.py":114
  2434. * # same callback while self._notifier is still true.
  2435. * assert self._notifier is notifier
  2436. * self._notifier = None # <<<<<<<<<<<<<<
  2437. *
  2438. * def rawlink(self, callback):
  2439. */
  2440. __Pyx_INCREF(Py_None);
  2441. __Pyx_GIVEREF(Py_None);
  2442. __Pyx_GOTREF(__pyx_v_self->_notifier);
  2443. __Pyx_DECREF(__pyx_v_self->_notifier);
  2444. __pyx_v_self->_notifier = Py_None;
  2445. goto __pyx_L5;
  2446. }
  2447. /*exception exit:*/{
  2448. __Pyx_PyThreadState_declare
  2449. __pyx_L4_error:;
  2450. __pyx_t_11 = 0; __pyx_t_10 = 0; __pyx_t_9 = 0; __pyx_t_20 = 0; __pyx_t_21 = 0; __pyx_t_22 = 0;
  2451. __Pyx_PyThreadState_assign
  2452. __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
  2453. __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
  2454. __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
  2455. __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  2456. __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
  2457. __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  2458. __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  2459. __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
  2460. __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  2461. if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_20, &__pyx_t_21, &__pyx_t_22);
  2462. if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_11, &__pyx_t_10, &__pyx_t_9) < 0)) __Pyx_ErrFetch(&__pyx_t_11, &__pyx_t_10, &__pyx_t_9);
  2463. __Pyx_XGOTREF(__pyx_t_11);
  2464. __Pyx_XGOTREF(__pyx_t_10);
  2465. __Pyx_XGOTREF(__pyx_t_9);
  2466. __Pyx_XGOTREF(__pyx_t_20);
  2467. __Pyx_XGOTREF(__pyx_t_21);
  2468. __Pyx_XGOTREF(__pyx_t_22);
  2469. __pyx_t_17 = __pyx_lineno; __pyx_t_18 = __pyx_clineno; __pyx_t_19 = __pyx_filename;
  2470. {
  2471. /* "gevent/_semaphore.py":113
  2472. * # released us because we loop through *all* of our links on the
  2473. * # same callback while self._notifier is still true.
  2474. * assert self._notifier is notifier # <<<<<<<<<<<<<<
  2475. * self._notifier = None
  2476. *
  2477. */
  2478. #ifndef CYTHON_WITHOUT_ASSERTIONS
  2479. if (unlikely(!Py_OptimizeFlag)) {
  2480. __pyx_t_6 = (__pyx_v_self->_notifier == __pyx_v_notifier);
  2481. if (unlikely(!(__pyx_t_6 != 0))) {
  2482. PyErr_SetNone(PyExc_AssertionError);
  2483. __PYX_ERR(0, 113, __pyx_L25_error)
  2484. }
  2485. }
  2486. #endif
  2487. /* "gevent/_semaphore.py":114
  2488. * # same callback while self._notifier is still true.
  2489. * assert self._notifier is notifier
  2490. * self._notifier = None # <<<<<<<<<<<<<<
  2491. *
  2492. * def rawlink(self, callback):
  2493. */
  2494. __Pyx_INCREF(Py_None);
  2495. __Pyx_GIVEREF(Py_None);
  2496. __Pyx_GOTREF(__pyx_v_self->_notifier);
  2497. __Pyx_DECREF(__pyx_v_self->_notifier);
  2498. __pyx_v_self->_notifier = Py_None;
  2499. }
  2500. __Pyx_PyThreadState_assign
  2501. if (PY_MAJOR_VERSION >= 3) {
  2502. __Pyx_XGIVEREF(__pyx_t_20);
  2503. __Pyx_XGIVEREF(__pyx_t_21);
  2504. __Pyx_XGIVEREF(__pyx_t_22);
  2505. __Pyx_ExceptionReset(__pyx_t_20, __pyx_t_21, __pyx_t_22);
  2506. }
  2507. __Pyx_XGIVEREF(__pyx_t_11);
  2508. __Pyx_XGIVEREF(__pyx_t_10);
  2509. __Pyx_XGIVEREF(__pyx_t_9);
  2510. __Pyx_ErrRestore(__pyx_t_11, __pyx_t_10, __pyx_t_9);
  2511. __pyx_t_11 = 0; __pyx_t_10 = 0; __pyx_t_9 = 0; __pyx_t_20 = 0; __pyx_t_21 = 0; __pyx_t_22 = 0;
  2512. __pyx_lineno = __pyx_t_17; __pyx_clineno = __pyx_t_18; __pyx_filename = __pyx_t_19;
  2513. goto __pyx_L1_error;
  2514. __pyx_L25_error:;
  2515. __Pyx_PyThreadState_assign
  2516. if (PY_MAJOR_VERSION >= 3) {
  2517. __Pyx_XGIVEREF(__pyx_t_20);
  2518. __Pyx_XGIVEREF(__pyx_t_21);
  2519. __Pyx_XGIVEREF(__pyx_t_22);
  2520. __Pyx_ExceptionReset(__pyx_t_20, __pyx_t_21, __pyx_t_22);
  2521. }
  2522. __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
  2523. __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
  2524. __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
  2525. __pyx_t_20 = 0; __pyx_t_21 = 0; __pyx_t_22 = 0;
  2526. goto __pyx_L1_error;
  2527. }
  2528. __pyx_L3_return: {
  2529. __pyx_t_22 = __pyx_r;
  2530. __pyx_r = 0;
  2531. /* "gevent/_semaphore.py":113
  2532. * # released us because we loop through *all* of our links on the
  2533. * # same callback while self._notifier is still true.
  2534. * assert self._notifier is notifier # <<<<<<<<<<<<<<
  2535. * self._notifier = None
  2536. *
  2537. */
  2538. #ifndef CYTHON_WITHOUT_ASSERTIONS
  2539. if (unlikely(!Py_OptimizeFlag)) {
  2540. __pyx_t_6 = (__pyx_v_self->_notifier == __pyx_v_notifier);
  2541. if (unlikely(!(__pyx_t_6 != 0))) {
  2542. PyErr_SetNone(PyExc_AssertionError);
  2543. __PYX_ERR(0, 113, __pyx_L1_error)
  2544. }
  2545. }
  2546. #endif
  2547. /* "gevent/_semaphore.py":114
  2548. * # same callback while self._notifier is still true.
  2549. * assert self._notifier is notifier
  2550. * self._notifier = None # <<<<<<<<<<<<<<
  2551. *
  2552. * def rawlink(self, callback):
  2553. */
  2554. __Pyx_INCREF(Py_None);
  2555. __Pyx_GIVEREF(Py_None);
  2556. __Pyx_GOTREF(__pyx_v_self->_notifier);
  2557. __Pyx_DECREF(__pyx_v_self->_notifier);
  2558. __pyx_v_self->_notifier = Py_None;
  2559. __pyx_r = __pyx_t_22;
  2560. __pyx_t_22 = 0;
  2561. goto __pyx_L0;
  2562. }
  2563. __pyx_L5:;
  2564. }
  2565. /* "gevent/_semaphore.py":80
  2566. * self._notifier = get_hub().loop.run_callback(self._notify_links)
  2567. *
  2568. * def _notify_links(self): # <<<<<<<<<<<<<<
  2569. * # Subclasses CANNOT override. This is a cdef method.
  2570. *
  2571. */
  2572. /* function exit code */
  2573. __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  2574. goto __pyx_L0;
  2575. __pyx_L1_error:;
  2576. __Pyx_XDECREF(__pyx_t_1);
  2577. __Pyx_XDECREF(__pyx_t_2);
  2578. __Pyx_XDECREF(__pyx_t_3);
  2579. __Pyx_XDECREF(__pyx_t_4);
  2580. __Pyx_XDECREF(__pyx_t_12);
  2581. __Pyx_XDECREF(__pyx_t_13);
  2582. __Pyx_XDECREF(__pyx_t_14);
  2583. __Pyx_XDECREF(__pyx_t_15);
  2584. __Pyx_XDECREF(__pyx_t_16);
  2585. __Pyx_AddTraceback("gevent._semaphore.Semaphore._notify_links", __pyx_clineno, __pyx_lineno, __pyx_filename);
  2586. __pyx_r = 0;
  2587. __pyx_L0:;
  2588. __Pyx_XDECREF(__pyx_v_notifier);
  2589. __Pyx_XDECREF(__pyx_v_link);
  2590. __Pyx_XGIVEREF(__pyx_r);
  2591. __Pyx_RefNannyFinishContext();
  2592. return __pyx_r;
  2593. }
  2594. /* Python wrapper */
  2595. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_11_notify_links(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
  2596. static PyMethodDef __pyx_mdef_6gevent_10_semaphore_9Semaphore_11_notify_links = {"_notify_links", (PyCFunction)__pyx_pw_6gevent_10_semaphore_9Semaphore_11_notify_links, METH_NOARGS, 0};
  2597. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_11_notify_links(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  2598. PyObject *__pyx_r = 0;
  2599. __Pyx_RefNannyDeclarations
  2600. __Pyx_RefNannySetupContext("_notify_links (wrapper)", 0);
  2601. __pyx_r = __pyx_pf_6gevent_10_semaphore_9Semaphore_10_notify_links(((struct __pyx_obj_6gevent_10_semaphore_Semaphore *)__pyx_v_self));
  2602. /* function exit code */
  2603. __Pyx_RefNannyFinishContext();
  2604. return __pyx_r;
  2605. }
  2606. static PyObject *__pyx_pf_6gevent_10_semaphore_9Semaphore_10_notify_links(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self) {
  2607. PyObject *__pyx_r = NULL;
  2608. __Pyx_RefNannyDeclarations
  2609. PyObject *__pyx_t_1 = NULL;
  2610. __Pyx_RefNannySetupContext("_notify_links", 0);
  2611. __Pyx_XDECREF(__pyx_r);
  2612. __pyx_t_1 = __pyx_f_6gevent_10_semaphore_9Semaphore__notify_links(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 80, __pyx_L1_error)
  2613. __Pyx_GOTREF(__pyx_t_1);
  2614. __pyx_r = __pyx_t_1;
  2615. __pyx_t_1 = 0;
  2616. goto __pyx_L0;
  2617. /* function exit code */
  2618. __pyx_L1_error:;
  2619. __Pyx_XDECREF(__pyx_t_1);
  2620. __Pyx_AddTraceback("gevent._semaphore.Semaphore._notify_links", __pyx_clineno, __pyx_lineno, __pyx_filename);
  2621. __pyx_r = NULL;
  2622. __pyx_L0:;
  2623. __Pyx_XGIVEREF(__pyx_r);
  2624. __Pyx_RefNannyFinishContext();
  2625. return __pyx_r;
  2626. }
  2627. /* "gevent/_semaphore.py":116
  2628. * self._notifier = None
  2629. *
  2630. * def rawlink(self, callback): # <<<<<<<<<<<<<<
  2631. * """
  2632. * rawlink(callback) -> None
  2633. */
  2634. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_13rawlink(PyObject *__pyx_v_self, PyObject *__pyx_v_callback); /*proto*/
  2635. static PyObject *__pyx_f_6gevent_10_semaphore_9Semaphore_rawlink(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, PyObject *__pyx_v_callback, int __pyx_skip_dispatch) {
  2636. PyObject *__pyx_r = NULL;
  2637. __Pyx_RefNannyDeclarations
  2638. PyObject *__pyx_t_1 = NULL;
  2639. PyObject *__pyx_t_2 = NULL;
  2640. PyObject *__pyx_t_3 = NULL;
  2641. PyObject *__pyx_t_4 = NULL;
  2642. PyObject *__pyx_t_5 = NULL;
  2643. int __pyx_t_6;
  2644. int __pyx_t_7;
  2645. int __pyx_t_8;
  2646. __Pyx_RefNannySetupContext("rawlink", 0);
  2647. /* Check if called by wrapper */
  2648. if (unlikely(__pyx_skip_dispatch)) ;
  2649. /* Check if overridden in Python */
  2650. else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
  2651. __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_rawlink); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 116, __pyx_L1_error)
  2652. __Pyx_GOTREF(__pyx_t_1);
  2653. if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_6gevent_10_semaphore_9Semaphore_13rawlink)) {
  2654. __Pyx_XDECREF(__pyx_r);
  2655. __Pyx_INCREF(__pyx_t_1);
  2656. __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
  2657. if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
  2658. __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
  2659. if (likely(__pyx_t_4)) {
  2660. PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
  2661. __Pyx_INCREF(__pyx_t_4);
  2662. __Pyx_INCREF(function);
  2663. __Pyx_DECREF_SET(__pyx_t_3, function);
  2664. }
  2665. }
  2666. if (!__pyx_t_4) {
  2667. __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_callback); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 116, __pyx_L1_error)
  2668. __Pyx_GOTREF(__pyx_t_2);
  2669. } else {
  2670. #if CYTHON_FAST_PYCALL
  2671. if (PyFunction_Check(__pyx_t_3)) {
  2672. PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_callback};
  2673. __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 116, __pyx_L1_error)
  2674. __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  2675. __Pyx_GOTREF(__pyx_t_2);
  2676. } else
  2677. #endif
  2678. #if CYTHON_FAST_PYCCALL
  2679. if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
  2680. PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_callback};
  2681. __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 116, __pyx_L1_error)
  2682. __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  2683. __Pyx_GOTREF(__pyx_t_2);
  2684. } else
  2685. #endif
  2686. {
  2687. __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 116, __pyx_L1_error)
  2688. __Pyx_GOTREF(__pyx_t_5);
  2689. __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
  2690. __Pyx_INCREF(__pyx_v_callback);
  2691. __Pyx_GIVEREF(__pyx_v_callback);
  2692. PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_callback);
  2693. __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 116, __pyx_L1_error)
  2694. __Pyx_GOTREF(__pyx_t_2);
  2695. __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  2696. }
  2697. }
  2698. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  2699. __pyx_r = __pyx_t_2;
  2700. __pyx_t_2 = 0;
  2701. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  2702. goto __pyx_L0;
  2703. }
  2704. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  2705. }
  2706. /* "gevent/_semaphore.py":128
  2707. * will not need to use it.
  2708. * """
  2709. * if not callable(callback): # <<<<<<<<<<<<<<
  2710. * raise TypeError('Expected callable:', callback)
  2711. * if self._links is None:
  2712. */
  2713. __pyx_t_6 = __Pyx_PyCallable_Check(__pyx_v_callback); if (unlikely(__pyx_t_6 == -1)) __PYX_ERR(0, 128, __pyx_L1_error)
  2714. __pyx_t_7 = ((!(__pyx_t_6 != 0)) != 0);
  2715. if (__pyx_t_7) {
  2716. /* "gevent/_semaphore.py":129
  2717. * """
  2718. * if not callable(callback):
  2719. * raise TypeError('Expected callable:', callback) # <<<<<<<<<<<<<<
  2720. * if self._links is None:
  2721. * self._links = [callback]
  2722. */
  2723. __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 129, __pyx_L1_error)
  2724. __Pyx_GOTREF(__pyx_t_1);
  2725. __Pyx_INCREF(__pyx_kp_s_Expected_callable);
  2726. __Pyx_GIVEREF(__pyx_kp_s_Expected_callable);
  2727. PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_s_Expected_callable);
  2728. __Pyx_INCREF(__pyx_v_callback);
  2729. __Pyx_GIVEREF(__pyx_v_callback);
  2730. PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_callback);
  2731. __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 129, __pyx_L1_error)
  2732. __Pyx_GOTREF(__pyx_t_2);
  2733. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  2734. __Pyx_Raise(__pyx_t_2, 0, 0, 0);
  2735. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  2736. __PYX_ERR(0, 129, __pyx_L1_error)
  2737. /* "gevent/_semaphore.py":128
  2738. * will not need to use it.
  2739. * """
  2740. * if not callable(callback): # <<<<<<<<<<<<<<
  2741. * raise TypeError('Expected callable:', callback)
  2742. * if self._links is None:
  2743. */
  2744. }
  2745. /* "gevent/_semaphore.py":130
  2746. * if not callable(callback):
  2747. * raise TypeError('Expected callable:', callback)
  2748. * if self._links is None: # <<<<<<<<<<<<<<
  2749. * self._links = [callback]
  2750. * else:
  2751. */
  2752. __pyx_t_7 = (__pyx_v_self->_links == Py_None);
  2753. __pyx_t_6 = (__pyx_t_7 != 0);
  2754. if (__pyx_t_6) {
  2755. /* "gevent/_semaphore.py":131
  2756. * raise TypeError('Expected callable:', callback)
  2757. * if self._links is None:
  2758. * self._links = [callback] # <<<<<<<<<<<<<<
  2759. * else:
  2760. * self._links.append(callback)
  2761. */
  2762. __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 131, __pyx_L1_error)
  2763. __Pyx_GOTREF(__pyx_t_2);
  2764. __Pyx_INCREF(__pyx_v_callback);
  2765. __Pyx_GIVEREF(__pyx_v_callback);
  2766. PyList_SET_ITEM(__pyx_t_2, 0, __pyx_v_callback);
  2767. __Pyx_GIVEREF(__pyx_t_2);
  2768. __Pyx_GOTREF(__pyx_v_self->_links);
  2769. __Pyx_DECREF(__pyx_v_self->_links);
  2770. __pyx_v_self->_links = __pyx_t_2;
  2771. __pyx_t_2 = 0;
  2772. /* "gevent/_semaphore.py":130
  2773. * if not callable(callback):
  2774. * raise TypeError('Expected callable:', callback)
  2775. * if self._links is None: # <<<<<<<<<<<<<<
  2776. * self._links = [callback]
  2777. * else:
  2778. */
  2779. goto __pyx_L4;
  2780. }
  2781. /* "gevent/_semaphore.py":133
  2782. * self._links = [callback]
  2783. * else:
  2784. * self._links.append(callback) # <<<<<<<<<<<<<<
  2785. * self._dirty = True
  2786. *
  2787. */
  2788. /*else*/ {
  2789. __pyx_t_8 = __Pyx_PyObject_Append(__pyx_v_self->_links, __pyx_v_callback); if (unlikely(__pyx_t_8 == -1)) __PYX_ERR(0, 133, __pyx_L1_error)
  2790. }
  2791. __pyx_L4:;
  2792. /* "gevent/_semaphore.py":134
  2793. * else:
  2794. * self._links.append(callback)
  2795. * self._dirty = True # <<<<<<<<<<<<<<
  2796. *
  2797. * def unlink(self, callback):
  2798. */
  2799. __pyx_v_self->_dirty = 1;
  2800. /* "gevent/_semaphore.py":116
  2801. * self._notifier = None
  2802. *
  2803. * def rawlink(self, callback): # <<<<<<<<<<<<<<
  2804. * """
  2805. * rawlink(callback) -> None
  2806. */
  2807. /* function exit code */
  2808. __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  2809. goto __pyx_L0;
  2810. __pyx_L1_error:;
  2811. __Pyx_XDECREF(__pyx_t_1);
  2812. __Pyx_XDECREF(__pyx_t_2);
  2813. __Pyx_XDECREF(__pyx_t_3);
  2814. __Pyx_XDECREF(__pyx_t_4);
  2815. __Pyx_XDECREF(__pyx_t_5);
  2816. __Pyx_AddTraceback("gevent._semaphore.Semaphore.rawlink", __pyx_clineno, __pyx_lineno, __pyx_filename);
  2817. __pyx_r = 0;
  2818. __pyx_L0:;
  2819. __Pyx_XGIVEREF(__pyx_r);
  2820. __Pyx_RefNannyFinishContext();
  2821. return __pyx_r;
  2822. }
  2823. /* Python wrapper */
  2824. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_13rawlink(PyObject *__pyx_v_self, PyObject *__pyx_v_callback); /*proto*/
  2825. static char __pyx_doc_6gevent_10_semaphore_9Semaphore_12rawlink[] = "\n rawlink(callback) -> None\n\n Register a callback to call when a counter is more than zero.\n\n *callback* will be called in the :class:`Hub <gevent.hub.Hub>`, so it must not use blocking gevent API.\n *callback* will be passed one argument: this instance.\n\n This method is normally called automatically by :meth:`acquire` and :meth:`wait`; most code\n will not need to use it.\n ";
  2826. static PyMethodDef __pyx_mdef_6gevent_10_semaphore_9Semaphore_13rawlink = {"rawlink", (PyCFunction)__pyx_pw_6gevent_10_semaphore_9Semaphore_13rawlink, METH_O, __pyx_doc_6gevent_10_semaphore_9Semaphore_12rawlink};
  2827. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_13rawlink(PyObject *__pyx_v_self, PyObject *__pyx_v_callback) {
  2828. PyObject *__pyx_r = 0;
  2829. __Pyx_RefNannyDeclarations
  2830. __Pyx_RefNannySetupContext("rawlink (wrapper)", 0);
  2831. __pyx_r = __pyx_pf_6gevent_10_semaphore_9Semaphore_12rawlink(((struct __pyx_obj_6gevent_10_semaphore_Semaphore *)__pyx_v_self), ((PyObject *)__pyx_v_callback));
  2832. /* function exit code */
  2833. __Pyx_RefNannyFinishContext();
  2834. return __pyx_r;
  2835. }
  2836. static PyObject *__pyx_pf_6gevent_10_semaphore_9Semaphore_12rawlink(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, PyObject *__pyx_v_callback) {
  2837. PyObject *__pyx_r = NULL;
  2838. __Pyx_RefNannyDeclarations
  2839. PyObject *__pyx_t_1 = NULL;
  2840. __Pyx_RefNannySetupContext("rawlink", 0);
  2841. __Pyx_XDECREF(__pyx_r);
  2842. __pyx_t_1 = __pyx_f_6gevent_10_semaphore_9Semaphore_rawlink(__pyx_v_self, __pyx_v_callback, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 116, __pyx_L1_error)
  2843. __Pyx_GOTREF(__pyx_t_1);
  2844. __pyx_r = __pyx_t_1;
  2845. __pyx_t_1 = 0;
  2846. goto __pyx_L0;
  2847. /* function exit code */
  2848. __pyx_L1_error:;
  2849. __Pyx_XDECREF(__pyx_t_1);
  2850. __Pyx_AddTraceback("gevent._semaphore.Semaphore.rawlink", __pyx_clineno, __pyx_lineno, __pyx_filename);
  2851. __pyx_r = NULL;
  2852. __pyx_L0:;
  2853. __Pyx_XGIVEREF(__pyx_r);
  2854. __Pyx_RefNannyFinishContext();
  2855. return __pyx_r;
  2856. }
  2857. /* "gevent/_semaphore.py":136
  2858. * self._dirty = True
  2859. *
  2860. * def unlink(self, callback): # <<<<<<<<<<<<<<
  2861. * """
  2862. * unlink(callback) -> None
  2863. */
  2864. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_15unlink(PyObject *__pyx_v_self, PyObject *__pyx_v_callback); /*proto*/
  2865. static PyObject *__pyx_f_6gevent_10_semaphore_9Semaphore_unlink(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, PyObject *__pyx_v_callback, int __pyx_skip_dispatch) {
  2866. PyObject *__pyx_r = NULL;
  2867. __Pyx_RefNannyDeclarations
  2868. PyObject *__pyx_t_1 = NULL;
  2869. PyObject *__pyx_t_2 = NULL;
  2870. PyObject *__pyx_t_3 = NULL;
  2871. PyObject *__pyx_t_4 = NULL;
  2872. PyObject *__pyx_t_5 = NULL;
  2873. PyObject *__pyx_t_6 = NULL;
  2874. PyObject *__pyx_t_7 = NULL;
  2875. PyObject *__pyx_t_8 = NULL;
  2876. int __pyx_t_9;
  2877. int __pyx_t_10;
  2878. int __pyx_t_11;
  2879. __Pyx_RefNannySetupContext("unlink", 0);
  2880. /* Check if called by wrapper */
  2881. if (unlikely(__pyx_skip_dispatch)) ;
  2882. /* Check if overridden in Python */
  2883. else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
  2884. __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_unlink); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 136, __pyx_L1_error)
  2885. __Pyx_GOTREF(__pyx_t_1);
  2886. if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_6gevent_10_semaphore_9Semaphore_15unlink)) {
  2887. __Pyx_XDECREF(__pyx_r);
  2888. __Pyx_INCREF(__pyx_t_1);
  2889. __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
  2890. if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
  2891. __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
  2892. if (likely(__pyx_t_4)) {
  2893. PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
  2894. __Pyx_INCREF(__pyx_t_4);
  2895. __Pyx_INCREF(function);
  2896. __Pyx_DECREF_SET(__pyx_t_3, function);
  2897. }
  2898. }
  2899. if (!__pyx_t_4) {
  2900. __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_callback); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 136, __pyx_L1_error)
  2901. __Pyx_GOTREF(__pyx_t_2);
  2902. } else {
  2903. #if CYTHON_FAST_PYCALL
  2904. if (PyFunction_Check(__pyx_t_3)) {
  2905. PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_callback};
  2906. __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 136, __pyx_L1_error)
  2907. __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  2908. __Pyx_GOTREF(__pyx_t_2);
  2909. } else
  2910. #endif
  2911. #if CYTHON_FAST_PYCCALL
  2912. if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
  2913. PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_callback};
  2914. __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 136, __pyx_L1_error)
  2915. __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  2916. __Pyx_GOTREF(__pyx_t_2);
  2917. } else
  2918. #endif
  2919. {
  2920. __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 136, __pyx_L1_error)
  2921. __Pyx_GOTREF(__pyx_t_5);
  2922. __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
  2923. __Pyx_INCREF(__pyx_v_callback);
  2924. __Pyx_GIVEREF(__pyx_v_callback);
  2925. PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_callback);
  2926. __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 136, __pyx_L1_error)
  2927. __Pyx_GOTREF(__pyx_t_2);
  2928. __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  2929. }
  2930. }
  2931. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  2932. __pyx_r = __pyx_t_2;
  2933. __pyx_t_2 = 0;
  2934. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  2935. goto __pyx_L0;
  2936. }
  2937. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  2938. }
  2939. /* "gevent/_semaphore.py":145
  2940. * code will not need to use it.
  2941. * """
  2942. * try: # <<<<<<<<<<<<<<
  2943. * self._links.remove(callback)
  2944. * self._dirty = True
  2945. */
  2946. {
  2947. __Pyx_PyThreadState_declare
  2948. __Pyx_PyThreadState_assign
  2949. __Pyx_ExceptionSave(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8);
  2950. __Pyx_XGOTREF(__pyx_t_6);
  2951. __Pyx_XGOTREF(__pyx_t_7);
  2952. __Pyx_XGOTREF(__pyx_t_8);
  2953. /*try:*/ {
  2954. /* "gevent/_semaphore.py":146
  2955. * """
  2956. * try:
  2957. * self._links.remove(callback) # <<<<<<<<<<<<<<
  2958. * self._dirty = True
  2959. * except (ValueError, AttributeError):
  2960. */
  2961. __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->_links, __pyx_n_s_remove); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 146, __pyx_L3_error)
  2962. __Pyx_GOTREF(__pyx_t_2);
  2963. __pyx_t_3 = NULL;
  2964. if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
  2965. __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
  2966. if (likely(__pyx_t_3)) {
  2967. PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
  2968. __Pyx_INCREF(__pyx_t_3);
  2969. __Pyx_INCREF(function);
  2970. __Pyx_DECREF_SET(__pyx_t_2, function);
  2971. }
  2972. }
  2973. if (!__pyx_t_3) {
  2974. __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_callback); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 146, __pyx_L3_error)
  2975. __Pyx_GOTREF(__pyx_t_1);
  2976. } else {
  2977. #if CYTHON_FAST_PYCALL
  2978. if (PyFunction_Check(__pyx_t_2)) {
  2979. PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_callback};
  2980. __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 146, __pyx_L3_error)
  2981. __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  2982. __Pyx_GOTREF(__pyx_t_1);
  2983. } else
  2984. #endif
  2985. #if CYTHON_FAST_PYCCALL
  2986. if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
  2987. PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_callback};
  2988. __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 146, __pyx_L3_error)
  2989. __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  2990. __Pyx_GOTREF(__pyx_t_1);
  2991. } else
  2992. #endif
  2993. {
  2994. __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 146, __pyx_L3_error)
  2995. __Pyx_GOTREF(__pyx_t_5);
  2996. __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL;
  2997. __Pyx_INCREF(__pyx_v_callback);
  2998. __Pyx_GIVEREF(__pyx_v_callback);
  2999. PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_callback);
  3000. __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 146, __pyx_L3_error)
  3001. __Pyx_GOTREF(__pyx_t_1);
  3002. __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  3003. }
  3004. }
  3005. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  3006. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  3007. /* "gevent/_semaphore.py":147
  3008. * try:
  3009. * self._links.remove(callback)
  3010. * self._dirty = True # <<<<<<<<<<<<<<
  3011. * except (ValueError, AttributeError):
  3012. * pass
  3013. */
  3014. __pyx_v_self->_dirty = 1;
  3015. /* "gevent/_semaphore.py":145
  3016. * code will not need to use it.
  3017. * """
  3018. * try: # <<<<<<<<<<<<<<
  3019. * self._links.remove(callback)
  3020. * self._dirty = True
  3021. */
  3022. }
  3023. __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  3024. __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
  3025. __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
  3026. goto __pyx_L10_try_end;
  3027. __pyx_L3_error:;
  3028. __Pyx_PyThreadState_assign
  3029. __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  3030. __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  3031. __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  3032. __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  3033. __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  3034. /* "gevent/_semaphore.py":148
  3035. * self._links.remove(callback)
  3036. * self._dirty = True
  3037. * except (ValueError, AttributeError): # <<<<<<<<<<<<<<
  3038. * pass
  3039. * if not self._links:
  3040. */
  3041. __pyx_t_9 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError) || __Pyx_PyErr_ExceptionMatches(__pyx_builtin_AttributeError);
  3042. if (__pyx_t_9) {
  3043. __Pyx_ErrRestore(0,0,0);
  3044. goto __pyx_L4_exception_handled;
  3045. }
  3046. goto __pyx_L5_except_error;
  3047. __pyx_L5_except_error:;
  3048. /* "gevent/_semaphore.py":145
  3049. * code will not need to use it.
  3050. * """
  3051. * try: # <<<<<<<<<<<<<<
  3052. * self._links.remove(callback)
  3053. * self._dirty = True
  3054. */
  3055. __Pyx_PyThreadState_assign
  3056. __Pyx_XGIVEREF(__pyx_t_6);
  3057. __Pyx_XGIVEREF(__pyx_t_7);
  3058. __Pyx_XGIVEREF(__pyx_t_8);
  3059. __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8);
  3060. goto __pyx_L1_error;
  3061. __pyx_L4_exception_handled:;
  3062. __Pyx_PyThreadState_assign
  3063. __Pyx_XGIVEREF(__pyx_t_6);
  3064. __Pyx_XGIVEREF(__pyx_t_7);
  3065. __Pyx_XGIVEREF(__pyx_t_8);
  3066. __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8);
  3067. __pyx_L10_try_end:;
  3068. }
  3069. /* "gevent/_semaphore.py":150
  3070. * except (ValueError, AttributeError):
  3071. * pass
  3072. * if not self._links: # <<<<<<<<<<<<<<
  3073. * self._links = None
  3074. * # TODO: Cancel a notifier if there are no links?
  3075. */
  3076. __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_self->_links); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 150, __pyx_L1_error)
  3077. __pyx_t_11 = ((!__pyx_t_10) != 0);
  3078. if (__pyx_t_11) {
  3079. /* "gevent/_semaphore.py":151
  3080. * pass
  3081. * if not self._links:
  3082. * self._links = None # <<<<<<<<<<<<<<
  3083. * # TODO: Cancel a notifier if there are no links?
  3084. *
  3085. */
  3086. __Pyx_INCREF(Py_None);
  3087. __Pyx_GIVEREF(Py_None);
  3088. __Pyx_GOTREF(__pyx_v_self->_links);
  3089. __Pyx_DECREF(__pyx_v_self->_links);
  3090. __pyx_v_self->_links = Py_None;
  3091. /* "gevent/_semaphore.py":150
  3092. * except (ValueError, AttributeError):
  3093. * pass
  3094. * if not self._links: # <<<<<<<<<<<<<<
  3095. * self._links = None
  3096. * # TODO: Cancel a notifier if there are no links?
  3097. */
  3098. }
  3099. /* "gevent/_semaphore.py":136
  3100. * self._dirty = True
  3101. *
  3102. * def unlink(self, callback): # <<<<<<<<<<<<<<
  3103. * """
  3104. * unlink(callback) -> None
  3105. */
  3106. /* function exit code */
  3107. __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  3108. goto __pyx_L0;
  3109. __pyx_L1_error:;
  3110. __Pyx_XDECREF(__pyx_t_1);
  3111. __Pyx_XDECREF(__pyx_t_2);
  3112. __Pyx_XDECREF(__pyx_t_3);
  3113. __Pyx_XDECREF(__pyx_t_4);
  3114. __Pyx_XDECREF(__pyx_t_5);
  3115. __Pyx_AddTraceback("gevent._semaphore.Semaphore.unlink", __pyx_clineno, __pyx_lineno, __pyx_filename);
  3116. __pyx_r = 0;
  3117. __pyx_L0:;
  3118. __Pyx_XGIVEREF(__pyx_r);
  3119. __Pyx_RefNannyFinishContext();
  3120. return __pyx_r;
  3121. }
  3122. /* Python wrapper */
  3123. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_15unlink(PyObject *__pyx_v_self, PyObject *__pyx_v_callback); /*proto*/
  3124. static char __pyx_doc_6gevent_10_semaphore_9Semaphore_14unlink[] = "\n unlink(callback) -> None\n\n Remove the callback set by :meth:`rawlink`.\n\n This method is normally called automatically by :meth:`acquire` and :meth:`wait`; most\n code will not need to use it.\n ";
  3125. static PyMethodDef __pyx_mdef_6gevent_10_semaphore_9Semaphore_15unlink = {"unlink", (PyCFunction)__pyx_pw_6gevent_10_semaphore_9Semaphore_15unlink, METH_O, __pyx_doc_6gevent_10_semaphore_9Semaphore_14unlink};
  3126. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_15unlink(PyObject *__pyx_v_self, PyObject *__pyx_v_callback) {
  3127. PyObject *__pyx_r = 0;
  3128. __Pyx_RefNannyDeclarations
  3129. __Pyx_RefNannySetupContext("unlink (wrapper)", 0);
  3130. __pyx_r = __pyx_pf_6gevent_10_semaphore_9Semaphore_14unlink(((struct __pyx_obj_6gevent_10_semaphore_Semaphore *)__pyx_v_self), ((PyObject *)__pyx_v_callback));
  3131. /* function exit code */
  3132. __Pyx_RefNannyFinishContext();
  3133. return __pyx_r;
  3134. }
  3135. static PyObject *__pyx_pf_6gevent_10_semaphore_9Semaphore_14unlink(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, PyObject *__pyx_v_callback) {
  3136. PyObject *__pyx_r = NULL;
  3137. __Pyx_RefNannyDeclarations
  3138. PyObject *__pyx_t_1 = NULL;
  3139. __Pyx_RefNannySetupContext("unlink", 0);
  3140. __Pyx_XDECREF(__pyx_r);
  3141. __pyx_t_1 = __pyx_f_6gevent_10_semaphore_9Semaphore_unlink(__pyx_v_self, __pyx_v_callback, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 136, __pyx_L1_error)
  3142. __Pyx_GOTREF(__pyx_t_1);
  3143. __pyx_r = __pyx_t_1;
  3144. __pyx_t_1 = 0;
  3145. goto __pyx_L0;
  3146. /* function exit code */
  3147. __pyx_L1_error:;
  3148. __Pyx_XDECREF(__pyx_t_1);
  3149. __Pyx_AddTraceback("gevent._semaphore.Semaphore.unlink", __pyx_clineno, __pyx_lineno, __pyx_filename);
  3150. __pyx_r = NULL;
  3151. __pyx_L0:;
  3152. __Pyx_XGIVEREF(__pyx_r);
  3153. __Pyx_RefNannyFinishContext();
  3154. return __pyx_r;
  3155. }
  3156. /* "gevent/_semaphore.py":154
  3157. * # TODO: Cancel a notifier if there are no links?
  3158. *
  3159. * def _do_wait(self, timeout): # <<<<<<<<<<<<<<
  3160. * """
  3161. * Wait for up to *timeout* seconds to expire. If timeout
  3162. */
  3163. static PyObject *__pyx_f_6gevent_10_semaphore_9Semaphore__do_wait(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, PyObject *__pyx_v_timeout) {
  3164. PyObject *__pyx_v_switch = NULL;
  3165. PyObject *__pyx_v_timer = NULL;
  3166. PyObject *__pyx_v_result = NULL;
  3167. PyObject *__pyx_v_ex = NULL;
  3168. PyObject *__pyx_r = NULL;
  3169. __Pyx_RefNannyDeclarations
  3170. PyObject *__pyx_t_1 = NULL;
  3171. PyObject *__pyx_t_2 = NULL;
  3172. PyObject *__pyx_t_3 = NULL;
  3173. PyObject *__pyx_t_4 = NULL;
  3174. PyObject *__pyx_t_5 = NULL;
  3175. PyObject *__pyx_t_6 = NULL;
  3176. PyObject *__pyx_t_7 = NULL;
  3177. int __pyx_t_8;
  3178. int __pyx_t_9;
  3179. int __pyx_t_10;
  3180. int __pyx_t_11;
  3181. char const *__pyx_t_12;
  3182. PyObject *__pyx_t_13 = NULL;
  3183. PyObject *__pyx_t_14 = NULL;
  3184. PyObject *__pyx_t_15 = NULL;
  3185. char const *__pyx_t_16;
  3186. __Pyx_RefNannySetupContext("_do_wait", 0);
  3187. /* "gevent/_semaphore.py":160
  3188. * Raises timeout if a different timer expires.
  3189. * """
  3190. * switch = getcurrent().switch # <<<<<<<<<<<<<<
  3191. * self.rawlink(switch)
  3192. * try:
  3193. */
  3194. __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_getcurrent); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 160, __pyx_L1_error)
  3195. __Pyx_GOTREF(__pyx_t_2);
  3196. __pyx_t_3 = NULL;
  3197. if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
  3198. __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
  3199. if (likely(__pyx_t_3)) {
  3200. PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
  3201. __Pyx_INCREF(__pyx_t_3);
  3202. __Pyx_INCREF(function);
  3203. __Pyx_DECREF_SET(__pyx_t_2, function);
  3204. }
  3205. }
  3206. if (__pyx_t_3) {
  3207. __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 160, __pyx_L1_error)
  3208. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  3209. } else {
  3210. __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 160, __pyx_L1_error)
  3211. }
  3212. __Pyx_GOTREF(__pyx_t_1);
  3213. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  3214. __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_switch); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 160, __pyx_L1_error)
  3215. __Pyx_GOTREF(__pyx_t_2);
  3216. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  3217. __pyx_v_switch = __pyx_t_2;
  3218. __pyx_t_2 = 0;
  3219. /* "gevent/_semaphore.py":161
  3220. * """
  3221. * switch = getcurrent().switch
  3222. * self.rawlink(switch) # <<<<<<<<<<<<<<
  3223. * try:
  3224. * timer = Timeout._start_new_or_dummy(timeout)
  3225. */
  3226. __pyx_t_2 = ((struct __pyx_vtabstruct_6gevent_10_semaphore_Semaphore *)__pyx_v_self->__pyx_vtab)->rawlink(__pyx_v_self, __pyx_v_switch, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 161, __pyx_L1_error)
  3227. __Pyx_GOTREF(__pyx_t_2);
  3228. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  3229. /* "gevent/_semaphore.py":162
  3230. * switch = getcurrent().switch
  3231. * self.rawlink(switch)
  3232. * try: # <<<<<<<<<<<<<<
  3233. * timer = Timeout._start_new_or_dummy(timeout)
  3234. * try:
  3235. */
  3236. /*try:*/ {
  3237. /* "gevent/_semaphore.py":163
  3238. * self.rawlink(switch)
  3239. * try:
  3240. * timer = Timeout._start_new_or_dummy(timeout) # <<<<<<<<<<<<<<
  3241. * try:
  3242. * try:
  3243. */
  3244. __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_Timeout); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 163, __pyx_L4_error)
  3245. __Pyx_GOTREF(__pyx_t_1);
  3246. __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_start_new_or_dummy); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 163, __pyx_L4_error)
  3247. __Pyx_GOTREF(__pyx_t_3);
  3248. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  3249. __pyx_t_1 = NULL;
  3250. if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
  3251. __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3);
  3252. if (likely(__pyx_t_1)) {
  3253. PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
  3254. __Pyx_INCREF(__pyx_t_1);
  3255. __Pyx_INCREF(function);
  3256. __Pyx_DECREF_SET(__pyx_t_3, function);
  3257. }
  3258. }
  3259. if (!__pyx_t_1) {
  3260. __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_timeout); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 163, __pyx_L4_error)
  3261. __Pyx_GOTREF(__pyx_t_2);
  3262. } else {
  3263. #if CYTHON_FAST_PYCALL
  3264. if (PyFunction_Check(__pyx_t_3)) {
  3265. PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_v_timeout};
  3266. __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 163, __pyx_L4_error)
  3267. __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  3268. __Pyx_GOTREF(__pyx_t_2);
  3269. } else
  3270. #endif
  3271. #if CYTHON_FAST_PYCCALL
  3272. if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
  3273. PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_v_timeout};
  3274. __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 163, __pyx_L4_error)
  3275. __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  3276. __Pyx_GOTREF(__pyx_t_2);
  3277. } else
  3278. #endif
  3279. {
  3280. __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 163, __pyx_L4_error)
  3281. __Pyx_GOTREF(__pyx_t_4);
  3282. __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __pyx_t_1 = NULL;
  3283. __Pyx_INCREF(__pyx_v_timeout);
  3284. __Pyx_GIVEREF(__pyx_v_timeout);
  3285. PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_timeout);
  3286. __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 163, __pyx_L4_error)
  3287. __Pyx_GOTREF(__pyx_t_2);
  3288. __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  3289. }
  3290. }
  3291. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  3292. __pyx_v_timer = __pyx_t_2;
  3293. __pyx_t_2 = 0;
  3294. /* "gevent/_semaphore.py":164
  3295. * try:
  3296. * timer = Timeout._start_new_or_dummy(timeout)
  3297. * try: # <<<<<<<<<<<<<<
  3298. * try:
  3299. * result = get_hub().switch()
  3300. */
  3301. /*try:*/ {
  3302. /* "gevent/_semaphore.py":165
  3303. * timer = Timeout._start_new_or_dummy(timeout)
  3304. * try:
  3305. * try: # <<<<<<<<<<<<<<
  3306. * result = get_hub().switch()
  3307. * assert result is self, 'Invalid switch into Semaphore.wait/acquire(): %r' % (result, )
  3308. */
  3309. {
  3310. __Pyx_PyThreadState_declare
  3311. __Pyx_PyThreadState_assign
  3312. __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7);
  3313. __Pyx_XGOTREF(__pyx_t_5);
  3314. __Pyx_XGOTREF(__pyx_t_6);
  3315. __Pyx_XGOTREF(__pyx_t_7);
  3316. /*try:*/ {
  3317. /* "gevent/_semaphore.py":166
  3318. * try:
  3319. * try:
  3320. * result = get_hub().switch() # <<<<<<<<<<<<<<
  3321. * assert result is self, 'Invalid switch into Semaphore.wait/acquire(): %r' % (result, )
  3322. * except Timeout as ex:
  3323. */
  3324. __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_get_hub); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 166, __pyx_L9_error)
  3325. __Pyx_GOTREF(__pyx_t_4);
  3326. __pyx_t_1 = NULL;
  3327. if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
  3328. __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4);
  3329. if (likely(__pyx_t_1)) {
  3330. PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
  3331. __Pyx_INCREF(__pyx_t_1);
  3332. __Pyx_INCREF(function);
  3333. __Pyx_DECREF_SET(__pyx_t_4, function);
  3334. }
  3335. }
  3336. if (__pyx_t_1) {
  3337. __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 166, __pyx_L9_error)
  3338. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  3339. } else {
  3340. __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 166, __pyx_L9_error)
  3341. }
  3342. __Pyx_GOTREF(__pyx_t_3);
  3343. __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  3344. __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_switch); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 166, __pyx_L9_error)
  3345. __Pyx_GOTREF(__pyx_t_4);
  3346. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  3347. __pyx_t_3 = NULL;
  3348. if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
  3349. __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
  3350. if (likely(__pyx_t_3)) {
  3351. PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
  3352. __Pyx_INCREF(__pyx_t_3);
  3353. __Pyx_INCREF(function);
  3354. __Pyx_DECREF_SET(__pyx_t_4, function);
  3355. }
  3356. }
  3357. if (__pyx_t_3) {
  3358. __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 166, __pyx_L9_error)
  3359. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  3360. } else {
  3361. __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 166, __pyx_L9_error)
  3362. }
  3363. __Pyx_GOTREF(__pyx_t_2);
  3364. __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  3365. __pyx_v_result = __pyx_t_2;
  3366. __pyx_t_2 = 0;
  3367. /* "gevent/_semaphore.py":167
  3368. * try:
  3369. * result = get_hub().switch()
  3370. * assert result is self, 'Invalid switch into Semaphore.wait/acquire(): %r' % (result, ) # <<<<<<<<<<<<<<
  3371. * except Timeout as ex:
  3372. * if ex is not timer:
  3373. */
  3374. #ifndef CYTHON_WITHOUT_ASSERTIONS
  3375. if (unlikely(!Py_OptimizeFlag)) {
  3376. __pyx_t_8 = (__pyx_v_result == ((PyObject *)__pyx_v_self));
  3377. if (unlikely(!(__pyx_t_8 != 0))) {
  3378. __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 167, __pyx_L9_error)
  3379. __Pyx_GOTREF(__pyx_t_2);
  3380. __Pyx_INCREF(__pyx_v_result);
  3381. __Pyx_GIVEREF(__pyx_v_result);
  3382. PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_result);
  3383. __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Invalid_switch_into_Semaphore_wa, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 167, __pyx_L9_error)
  3384. __Pyx_GOTREF(__pyx_t_4);
  3385. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  3386. PyErr_SetObject(PyExc_AssertionError, __pyx_t_4);
  3387. __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  3388. __PYX_ERR(0, 167, __pyx_L9_error)
  3389. }
  3390. }
  3391. #endif
  3392. /* "gevent/_semaphore.py":165
  3393. * timer = Timeout._start_new_or_dummy(timeout)
  3394. * try:
  3395. * try: # <<<<<<<<<<<<<<
  3396. * result = get_hub().switch()
  3397. * assert result is self, 'Invalid switch into Semaphore.wait/acquire(): %r' % (result, )
  3398. */
  3399. }
  3400. __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  3401. __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  3402. __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
  3403. goto __pyx_L16_try_end;
  3404. __pyx_L9_error:;
  3405. __Pyx_PyThreadState_assign
  3406. __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  3407. __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  3408. __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  3409. __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  3410. /* "gevent/_semaphore.py":168
  3411. * result = get_hub().switch()
  3412. * assert result is self, 'Invalid switch into Semaphore.wait/acquire(): %r' % (result, )
  3413. * except Timeout as ex: # <<<<<<<<<<<<<<
  3414. * if ex is not timer:
  3415. * raise
  3416. */
  3417. __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_Timeout); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 168, __pyx_L11_except_error)
  3418. __Pyx_GOTREF(__pyx_t_4);
  3419. __pyx_t_9 = __Pyx_PyErr_ExceptionMatches(__pyx_t_4);
  3420. __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  3421. if (__pyx_t_9) {
  3422. __Pyx_AddTraceback("gevent._semaphore.Semaphore._do_wait", __pyx_clineno, __pyx_lineno, __pyx_filename);
  3423. if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_2, &__pyx_t_3) < 0) __PYX_ERR(0, 168, __pyx_L11_except_error)
  3424. __Pyx_GOTREF(__pyx_t_4);
  3425. __Pyx_GOTREF(__pyx_t_2);
  3426. __Pyx_GOTREF(__pyx_t_3);
  3427. __Pyx_INCREF(__pyx_t_2);
  3428. __pyx_v_ex = __pyx_t_2;
  3429. /* "gevent/_semaphore.py":169
  3430. * assert result is self, 'Invalid switch into Semaphore.wait/acquire(): %r' % (result, )
  3431. * except Timeout as ex:
  3432. * if ex is not timer: # <<<<<<<<<<<<<<
  3433. * raise
  3434. * return ex
  3435. */
  3436. __pyx_t_8 = (__pyx_v_ex != __pyx_v_timer);
  3437. __pyx_t_10 = (__pyx_t_8 != 0);
  3438. if (__pyx_t_10) {
  3439. /* "gevent/_semaphore.py":170
  3440. * except Timeout as ex:
  3441. * if ex is not timer:
  3442. * raise # <<<<<<<<<<<<<<
  3443. * return ex
  3444. * finally:
  3445. */
  3446. __Pyx_GIVEREF(__pyx_t_4);
  3447. __Pyx_GIVEREF(__pyx_t_2);
  3448. __Pyx_XGIVEREF(__pyx_t_3);
  3449. __Pyx_ErrRestoreWithState(__pyx_t_4, __pyx_t_2, __pyx_t_3);
  3450. __pyx_t_4 = 0; __pyx_t_2 = 0; __pyx_t_3 = 0;
  3451. __PYX_ERR(0, 170, __pyx_L11_except_error)
  3452. /* "gevent/_semaphore.py":169
  3453. * assert result is self, 'Invalid switch into Semaphore.wait/acquire(): %r' % (result, )
  3454. * except Timeout as ex:
  3455. * if ex is not timer: # <<<<<<<<<<<<<<
  3456. * raise
  3457. * return ex
  3458. */
  3459. }
  3460. /* "gevent/_semaphore.py":171
  3461. * if ex is not timer:
  3462. * raise
  3463. * return ex # <<<<<<<<<<<<<<
  3464. * finally:
  3465. * timer.cancel()
  3466. */
  3467. __Pyx_XDECREF(__pyx_r);
  3468. __Pyx_INCREF(__pyx_v_ex);
  3469. __pyx_r = __pyx_v_ex;
  3470. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  3471. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  3472. __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  3473. goto __pyx_L12_except_return;
  3474. }
  3475. goto __pyx_L11_except_error;
  3476. __pyx_L11_except_error:;
  3477. /* "gevent/_semaphore.py":165
  3478. * timer = Timeout._start_new_or_dummy(timeout)
  3479. * try:
  3480. * try: # <<<<<<<<<<<<<<
  3481. * result = get_hub().switch()
  3482. * assert result is self, 'Invalid switch into Semaphore.wait/acquire(): %r' % (result, )
  3483. */
  3484. __Pyx_PyThreadState_assign
  3485. __Pyx_XGIVEREF(__pyx_t_5);
  3486. __Pyx_XGIVEREF(__pyx_t_6);
  3487. __Pyx_XGIVEREF(__pyx_t_7);
  3488. __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7);
  3489. goto __pyx_L7_error;
  3490. __pyx_L12_except_return:;
  3491. __Pyx_PyThreadState_assign
  3492. __Pyx_XGIVEREF(__pyx_t_5);
  3493. __Pyx_XGIVEREF(__pyx_t_6);
  3494. __Pyx_XGIVEREF(__pyx_t_7);
  3495. __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7);
  3496. goto __pyx_L6_return;
  3497. __pyx_L16_try_end:;
  3498. }
  3499. }
  3500. /* "gevent/_semaphore.py":173
  3501. * return ex
  3502. * finally:
  3503. * timer.cancel() # <<<<<<<<<<<<<<
  3504. * finally:
  3505. * self.unlink(switch)
  3506. */
  3507. /*finally:*/ {
  3508. /*normal exit:*/{
  3509. __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_timer, __pyx_n_s_cancel); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 173, __pyx_L4_error)
  3510. __Pyx_GOTREF(__pyx_t_2);
  3511. __pyx_t_4 = NULL;
  3512. if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
  3513. __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
  3514. if (likely(__pyx_t_4)) {
  3515. PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
  3516. __Pyx_INCREF(__pyx_t_4);
  3517. __Pyx_INCREF(function);
  3518. __Pyx_DECREF_SET(__pyx_t_2, function);
  3519. }
  3520. }
  3521. if (__pyx_t_4) {
  3522. __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 173, __pyx_L4_error)
  3523. __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  3524. } else {
  3525. __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 173, __pyx_L4_error)
  3526. }
  3527. __Pyx_GOTREF(__pyx_t_3);
  3528. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  3529. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  3530. goto __pyx_L8;
  3531. }
  3532. /*exception exit:*/{
  3533. __Pyx_PyThreadState_declare
  3534. __pyx_L7_error:;
  3535. __pyx_t_7 = 0; __pyx_t_6 = 0; __pyx_t_5 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0; __pyx_t_15 = 0;
  3536. __Pyx_PyThreadState_assign
  3537. __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  3538. __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  3539. __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  3540. __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  3541. if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_13, &__pyx_t_14, &__pyx_t_15);
  3542. if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_7, &__pyx_t_6, &__pyx_t_5) < 0)) __Pyx_ErrFetch(&__pyx_t_7, &__pyx_t_6, &__pyx_t_5);
  3543. __Pyx_XGOTREF(__pyx_t_7);
  3544. __Pyx_XGOTREF(__pyx_t_6);
  3545. __Pyx_XGOTREF(__pyx_t_5);
  3546. __Pyx_XGOTREF(__pyx_t_13);
  3547. __Pyx_XGOTREF(__pyx_t_14);
  3548. __Pyx_XGOTREF(__pyx_t_15);
  3549. __pyx_t_9 = __pyx_lineno; __pyx_t_11 = __pyx_clineno; __pyx_t_12 = __pyx_filename;
  3550. {
  3551. __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_timer, __pyx_n_s_cancel); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 173, __pyx_L21_error)
  3552. __Pyx_GOTREF(__pyx_t_2);
  3553. __pyx_t_4 = NULL;
  3554. if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
  3555. __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
  3556. if (likely(__pyx_t_4)) {
  3557. PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
  3558. __Pyx_INCREF(__pyx_t_4);
  3559. __Pyx_INCREF(function);
  3560. __Pyx_DECREF_SET(__pyx_t_2, function);
  3561. }
  3562. }
  3563. if (__pyx_t_4) {
  3564. __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 173, __pyx_L21_error)
  3565. __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  3566. } else {
  3567. __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 173, __pyx_L21_error)
  3568. }
  3569. __Pyx_GOTREF(__pyx_t_3);
  3570. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  3571. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  3572. }
  3573. __Pyx_PyThreadState_assign
  3574. if (PY_MAJOR_VERSION >= 3) {
  3575. __Pyx_XGIVEREF(__pyx_t_13);
  3576. __Pyx_XGIVEREF(__pyx_t_14);
  3577. __Pyx_XGIVEREF(__pyx_t_15);
  3578. __Pyx_ExceptionReset(__pyx_t_13, __pyx_t_14, __pyx_t_15);
  3579. }
  3580. __Pyx_XGIVEREF(__pyx_t_7);
  3581. __Pyx_XGIVEREF(__pyx_t_6);
  3582. __Pyx_XGIVEREF(__pyx_t_5);
  3583. __Pyx_ErrRestore(__pyx_t_7, __pyx_t_6, __pyx_t_5);
  3584. __pyx_t_7 = 0; __pyx_t_6 = 0; __pyx_t_5 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0; __pyx_t_15 = 0;
  3585. __pyx_lineno = __pyx_t_9; __pyx_clineno = __pyx_t_11; __pyx_filename = __pyx_t_12;
  3586. goto __pyx_L4_error;
  3587. __pyx_L21_error:;
  3588. __Pyx_PyThreadState_assign
  3589. if (PY_MAJOR_VERSION >= 3) {
  3590. __Pyx_XGIVEREF(__pyx_t_13);
  3591. __Pyx_XGIVEREF(__pyx_t_14);
  3592. __Pyx_XGIVEREF(__pyx_t_15);
  3593. __Pyx_ExceptionReset(__pyx_t_13, __pyx_t_14, __pyx_t_15);
  3594. }
  3595. __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
  3596. __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  3597. __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  3598. __pyx_t_13 = 0; __pyx_t_14 = 0; __pyx_t_15 = 0;
  3599. goto __pyx_L4_error;
  3600. }
  3601. __pyx_L6_return: {
  3602. __pyx_t_15 = __pyx_r;
  3603. __pyx_r = 0;
  3604. __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_timer, __pyx_n_s_cancel); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 173, __pyx_L4_error)
  3605. __Pyx_GOTREF(__pyx_t_2);
  3606. __pyx_t_4 = NULL;
  3607. if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
  3608. __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
  3609. if (likely(__pyx_t_4)) {
  3610. PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
  3611. __Pyx_INCREF(__pyx_t_4);
  3612. __Pyx_INCREF(function);
  3613. __Pyx_DECREF_SET(__pyx_t_2, function);
  3614. }
  3615. }
  3616. if (__pyx_t_4) {
  3617. __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 173, __pyx_L4_error)
  3618. __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  3619. } else {
  3620. __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 173, __pyx_L4_error)
  3621. }
  3622. __Pyx_GOTREF(__pyx_t_3);
  3623. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  3624. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  3625. __pyx_r = __pyx_t_15;
  3626. __pyx_t_15 = 0;
  3627. goto __pyx_L3_return;
  3628. }
  3629. __pyx_L8:;
  3630. }
  3631. }
  3632. /* "gevent/_semaphore.py":175
  3633. * timer.cancel()
  3634. * finally:
  3635. * self.unlink(switch) # <<<<<<<<<<<<<<
  3636. *
  3637. * def wait(self, timeout=None):
  3638. */
  3639. /*finally:*/ {
  3640. /*normal exit:*/{
  3641. __pyx_t_3 = ((struct __pyx_vtabstruct_6gevent_10_semaphore_Semaphore *)__pyx_v_self->__pyx_vtab)->unlink(__pyx_v_self, __pyx_v_switch, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 175, __pyx_L1_error)
  3642. __Pyx_GOTREF(__pyx_t_3);
  3643. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  3644. goto __pyx_L5;
  3645. }
  3646. /*exception exit:*/{
  3647. __Pyx_PyThreadState_declare
  3648. __pyx_L4_error:;
  3649. __pyx_t_15 = 0; __pyx_t_14 = 0; __pyx_t_13 = 0; __pyx_t_5 = 0; __pyx_t_6 = 0; __pyx_t_7 = 0;
  3650. __Pyx_PyThreadState_assign
  3651. __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  3652. __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  3653. __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  3654. __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  3655. if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7);
  3656. if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_15, &__pyx_t_14, &__pyx_t_13) < 0)) __Pyx_ErrFetch(&__pyx_t_15, &__pyx_t_14, &__pyx_t_13);
  3657. __Pyx_XGOTREF(__pyx_t_15);
  3658. __Pyx_XGOTREF(__pyx_t_14);
  3659. __Pyx_XGOTREF(__pyx_t_13);
  3660. __Pyx_XGOTREF(__pyx_t_5);
  3661. __Pyx_XGOTREF(__pyx_t_6);
  3662. __Pyx_XGOTREF(__pyx_t_7);
  3663. __pyx_t_11 = __pyx_lineno; __pyx_t_9 = __pyx_clineno; __pyx_t_16 = __pyx_filename;
  3664. {
  3665. __pyx_t_3 = ((struct __pyx_vtabstruct_6gevent_10_semaphore_Semaphore *)__pyx_v_self->__pyx_vtab)->unlink(__pyx_v_self, __pyx_v_switch, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 175, __pyx_L23_error)
  3666. __Pyx_GOTREF(__pyx_t_3);
  3667. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  3668. }
  3669. __Pyx_PyThreadState_assign
  3670. if (PY_MAJOR_VERSION >= 3) {
  3671. __Pyx_XGIVEREF(__pyx_t_5);
  3672. __Pyx_XGIVEREF(__pyx_t_6);
  3673. __Pyx_XGIVEREF(__pyx_t_7);
  3674. __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7);
  3675. }
  3676. __Pyx_XGIVEREF(__pyx_t_15);
  3677. __Pyx_XGIVEREF(__pyx_t_14);
  3678. __Pyx_XGIVEREF(__pyx_t_13);
  3679. __Pyx_ErrRestore(__pyx_t_15, __pyx_t_14, __pyx_t_13);
  3680. __pyx_t_15 = 0; __pyx_t_14 = 0; __pyx_t_13 = 0; __pyx_t_5 = 0; __pyx_t_6 = 0; __pyx_t_7 = 0;
  3681. __pyx_lineno = __pyx_t_11; __pyx_clineno = __pyx_t_9; __pyx_filename = __pyx_t_16;
  3682. goto __pyx_L1_error;
  3683. __pyx_L23_error:;
  3684. __Pyx_PyThreadState_assign
  3685. if (PY_MAJOR_VERSION >= 3) {
  3686. __Pyx_XGIVEREF(__pyx_t_5);
  3687. __Pyx_XGIVEREF(__pyx_t_6);
  3688. __Pyx_XGIVEREF(__pyx_t_7);
  3689. __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7);
  3690. }
  3691. __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
  3692. __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
  3693. __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
  3694. __pyx_t_5 = 0; __pyx_t_6 = 0; __pyx_t_7 = 0;
  3695. goto __pyx_L1_error;
  3696. }
  3697. __pyx_L3_return: {
  3698. __pyx_t_7 = __pyx_r;
  3699. __pyx_r = 0;
  3700. __pyx_t_3 = ((struct __pyx_vtabstruct_6gevent_10_semaphore_Semaphore *)__pyx_v_self->__pyx_vtab)->unlink(__pyx_v_self, __pyx_v_switch, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 175, __pyx_L1_error)
  3701. __Pyx_GOTREF(__pyx_t_3);
  3702. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  3703. __pyx_r = __pyx_t_7;
  3704. __pyx_t_7 = 0;
  3705. goto __pyx_L0;
  3706. }
  3707. __pyx_L5:;
  3708. }
  3709. /* "gevent/_semaphore.py":154
  3710. * # TODO: Cancel a notifier if there are no links?
  3711. *
  3712. * def _do_wait(self, timeout): # <<<<<<<<<<<<<<
  3713. * """
  3714. * Wait for up to *timeout* seconds to expire. If timeout
  3715. */
  3716. /* function exit code */
  3717. __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  3718. goto __pyx_L0;
  3719. __pyx_L1_error:;
  3720. __Pyx_XDECREF(__pyx_t_1);
  3721. __Pyx_XDECREF(__pyx_t_2);
  3722. __Pyx_XDECREF(__pyx_t_3);
  3723. __Pyx_XDECREF(__pyx_t_4);
  3724. __Pyx_AddTraceback("gevent._semaphore.Semaphore._do_wait", __pyx_clineno, __pyx_lineno, __pyx_filename);
  3725. __pyx_r = 0;
  3726. __pyx_L0:;
  3727. __Pyx_XDECREF(__pyx_v_switch);
  3728. __Pyx_XDECREF(__pyx_v_timer);
  3729. __Pyx_XDECREF(__pyx_v_result);
  3730. __Pyx_XDECREF(__pyx_v_ex);
  3731. __Pyx_XGIVEREF(__pyx_r);
  3732. __Pyx_RefNannyFinishContext();
  3733. return __pyx_r;
  3734. }
  3735. /* "gevent/_semaphore.py":177
  3736. * self.unlink(switch)
  3737. *
  3738. * def wait(self, timeout=None): # <<<<<<<<<<<<<<
  3739. * """
  3740. * wait(timeout=None) -> int
  3741. */
  3742. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_17wait(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
  3743. static int __pyx_f_6gevent_10_semaphore_9Semaphore_wait(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, int __pyx_skip_dispatch, struct __pyx_opt_args_6gevent_10_semaphore_9Semaphore_wait *__pyx_optional_args) {
  3744. PyObject *__pyx_v_timeout = ((PyObject *)Py_None);
  3745. int __pyx_r;
  3746. __Pyx_RefNannyDeclarations
  3747. PyObject *__pyx_t_1 = NULL;
  3748. PyObject *__pyx_t_2 = NULL;
  3749. PyObject *__pyx_t_3 = NULL;
  3750. PyObject *__pyx_t_4 = NULL;
  3751. PyObject *__pyx_t_5 = NULL;
  3752. int __pyx_t_6;
  3753. int __pyx_t_7;
  3754. __Pyx_RefNannySetupContext("wait", 0);
  3755. if (__pyx_optional_args) {
  3756. if (__pyx_optional_args->__pyx_n > 0) {
  3757. __pyx_v_timeout = __pyx_optional_args->timeout;
  3758. }
  3759. }
  3760. /* Check if called by wrapper */
  3761. if (unlikely(__pyx_skip_dispatch)) ;
  3762. /* Check if overridden in Python */
  3763. else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
  3764. __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_wait); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 177, __pyx_L1_error)
  3765. __Pyx_GOTREF(__pyx_t_1);
  3766. if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_6gevent_10_semaphore_9Semaphore_17wait)) {
  3767. __Pyx_INCREF(__pyx_t_1);
  3768. __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
  3769. if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
  3770. __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
  3771. if (likely(__pyx_t_4)) {
  3772. PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
  3773. __Pyx_INCREF(__pyx_t_4);
  3774. __Pyx_INCREF(function);
  3775. __Pyx_DECREF_SET(__pyx_t_3, function);
  3776. }
  3777. }
  3778. if (!__pyx_t_4) {
  3779. __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_timeout); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 177, __pyx_L1_error)
  3780. __Pyx_GOTREF(__pyx_t_2);
  3781. } else {
  3782. #if CYTHON_FAST_PYCALL
  3783. if (PyFunction_Check(__pyx_t_3)) {
  3784. PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_timeout};
  3785. __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 177, __pyx_L1_error)
  3786. __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  3787. __Pyx_GOTREF(__pyx_t_2);
  3788. } else
  3789. #endif
  3790. #if CYTHON_FAST_PYCCALL
  3791. if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
  3792. PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_timeout};
  3793. __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 177, __pyx_L1_error)
  3794. __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  3795. __Pyx_GOTREF(__pyx_t_2);
  3796. } else
  3797. #endif
  3798. {
  3799. __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 177, __pyx_L1_error)
  3800. __Pyx_GOTREF(__pyx_t_5);
  3801. __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
  3802. __Pyx_INCREF(__pyx_v_timeout);
  3803. __Pyx_GIVEREF(__pyx_v_timeout);
  3804. PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_timeout);
  3805. __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 177, __pyx_L1_error)
  3806. __Pyx_GOTREF(__pyx_t_2);
  3807. __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  3808. }
  3809. }
  3810. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  3811. __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 177, __pyx_L1_error)
  3812. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  3813. __pyx_r = __pyx_t_6;
  3814. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  3815. goto __pyx_L0;
  3816. }
  3817. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  3818. }
  3819. /* "gevent/_semaphore.py":192
  3820. * before blocking.
  3821. * """
  3822. * if self.counter > 0: # <<<<<<<<<<<<<<
  3823. * return self.counter
  3824. *
  3825. */
  3826. __pyx_t_7 = ((__pyx_v_self->counter > 0) != 0);
  3827. if (__pyx_t_7) {
  3828. /* "gevent/_semaphore.py":193
  3829. * """
  3830. * if self.counter > 0:
  3831. * return self.counter # <<<<<<<<<<<<<<
  3832. *
  3833. * self._do_wait(timeout) # return value irrelevant, whether we got it or got a timeout
  3834. */
  3835. __pyx_r = __pyx_v_self->counter;
  3836. goto __pyx_L0;
  3837. /* "gevent/_semaphore.py":192
  3838. * before blocking.
  3839. * """
  3840. * if self.counter > 0: # <<<<<<<<<<<<<<
  3841. * return self.counter
  3842. *
  3843. */
  3844. }
  3845. /* "gevent/_semaphore.py":195
  3846. * return self.counter
  3847. *
  3848. * self._do_wait(timeout) # return value irrelevant, whether we got it or got a timeout # <<<<<<<<<<<<<<
  3849. * return self.counter
  3850. *
  3851. */
  3852. __pyx_t_1 = ((struct __pyx_vtabstruct_6gevent_10_semaphore_Semaphore *)__pyx_v_self->__pyx_vtab)->_do_wait(__pyx_v_self, __pyx_v_timeout); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 195, __pyx_L1_error)
  3853. __Pyx_GOTREF(__pyx_t_1);
  3854. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  3855. /* "gevent/_semaphore.py":196
  3856. *
  3857. * self._do_wait(timeout) # return value irrelevant, whether we got it or got a timeout
  3858. * return self.counter # <<<<<<<<<<<<<<
  3859. *
  3860. * def acquire(self, blocking=True, timeout=None):
  3861. */
  3862. __pyx_r = __pyx_v_self->counter;
  3863. goto __pyx_L0;
  3864. /* "gevent/_semaphore.py":177
  3865. * self.unlink(switch)
  3866. *
  3867. * def wait(self, timeout=None): # <<<<<<<<<<<<<<
  3868. * """
  3869. * wait(timeout=None) -> int
  3870. */
  3871. /* function exit code */
  3872. __pyx_L1_error:;
  3873. __Pyx_XDECREF(__pyx_t_1);
  3874. __Pyx_XDECREF(__pyx_t_2);
  3875. __Pyx_XDECREF(__pyx_t_3);
  3876. __Pyx_XDECREF(__pyx_t_4);
  3877. __Pyx_XDECREF(__pyx_t_5);
  3878. __Pyx_AddTraceback("gevent._semaphore.Semaphore.wait", __pyx_clineno, __pyx_lineno, __pyx_filename);
  3879. __pyx_r = -1000;
  3880. __pyx_L0:;
  3881. __Pyx_RefNannyFinishContext();
  3882. return __pyx_r;
  3883. }
  3884. /* Python wrapper */
  3885. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_17wait(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
  3886. static char __pyx_doc_6gevent_10_semaphore_9Semaphore_16wait[] = "\n wait(timeout=None) -> int\n\n Wait until it is possible to acquire this semaphore, or until the optional\n *timeout* elapses.\n\n .. caution:: If this semaphore was initialized with a size of 0,\n this method will block forever if no timeout is given.\n\n :keyword float timeout: If given, specifies the maximum amount of seconds\n this method will block.\n :return: A number indicating how many times the semaphore can be acquired\n before blocking.\n ";
  3887. static PyMethodDef __pyx_mdef_6gevent_10_semaphore_9Semaphore_17wait = {"wait", (PyCFunction)__pyx_pw_6gevent_10_semaphore_9Semaphore_17wait, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6gevent_10_semaphore_9Semaphore_16wait};
  3888. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_17wait(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  3889. PyObject *__pyx_v_timeout = 0;
  3890. PyObject *__pyx_r = 0;
  3891. __Pyx_RefNannyDeclarations
  3892. __Pyx_RefNannySetupContext("wait (wrapper)", 0);
  3893. {
  3894. static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_timeout,0};
  3895. PyObject* values[1] = {0};
  3896. values[0] = ((PyObject *)Py_None);
  3897. if (unlikely(__pyx_kwds)) {
  3898. Py_ssize_t kw_args;
  3899. const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
  3900. switch (pos_args) {
  3901. case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
  3902. case 0: break;
  3903. default: goto __pyx_L5_argtuple_error;
  3904. }
  3905. kw_args = PyDict_Size(__pyx_kwds);
  3906. switch (pos_args) {
  3907. case 0:
  3908. if (kw_args > 0) {
  3909. PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_timeout);
  3910. if (value) { values[0] = value; kw_args--; }
  3911. }
  3912. }
  3913. if (unlikely(kw_args > 0)) {
  3914. if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "wait") < 0)) __PYX_ERR(0, 177, __pyx_L3_error)
  3915. }
  3916. } else {
  3917. switch (PyTuple_GET_SIZE(__pyx_args)) {
  3918. case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
  3919. case 0: break;
  3920. default: goto __pyx_L5_argtuple_error;
  3921. }
  3922. }
  3923. __pyx_v_timeout = values[0];
  3924. }
  3925. goto __pyx_L4_argument_unpacking_done;
  3926. __pyx_L5_argtuple_error:;
  3927. __Pyx_RaiseArgtupleInvalid("wait", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 177, __pyx_L3_error)
  3928. __pyx_L3_error:;
  3929. __Pyx_AddTraceback("gevent._semaphore.Semaphore.wait", __pyx_clineno, __pyx_lineno, __pyx_filename);
  3930. __Pyx_RefNannyFinishContext();
  3931. return NULL;
  3932. __pyx_L4_argument_unpacking_done:;
  3933. __pyx_r = __pyx_pf_6gevent_10_semaphore_9Semaphore_16wait(((struct __pyx_obj_6gevent_10_semaphore_Semaphore *)__pyx_v_self), __pyx_v_timeout);
  3934. /* function exit code */
  3935. __Pyx_RefNannyFinishContext();
  3936. return __pyx_r;
  3937. }
  3938. static PyObject *__pyx_pf_6gevent_10_semaphore_9Semaphore_16wait(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, PyObject *__pyx_v_timeout) {
  3939. PyObject *__pyx_r = NULL;
  3940. __Pyx_RefNannyDeclarations
  3941. int __pyx_t_1;
  3942. struct __pyx_opt_args_6gevent_10_semaphore_9Semaphore_wait __pyx_t_2;
  3943. PyObject *__pyx_t_3 = NULL;
  3944. __Pyx_RefNannySetupContext("wait", 0);
  3945. __Pyx_XDECREF(__pyx_r);
  3946. __pyx_t_2.__pyx_n = 1;
  3947. __pyx_t_2.timeout = __pyx_v_timeout;
  3948. __pyx_t_1 = __pyx_vtabptr_6gevent_10_semaphore_Semaphore->wait(__pyx_v_self, 1, &__pyx_t_2); if (unlikely(__pyx_t_1 == -1000)) __PYX_ERR(0, 177, __pyx_L1_error)
  3949. __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 177, __pyx_L1_error)
  3950. __Pyx_GOTREF(__pyx_t_3);
  3951. __pyx_r = __pyx_t_3;
  3952. __pyx_t_3 = 0;
  3953. goto __pyx_L0;
  3954. /* function exit code */
  3955. __pyx_L1_error:;
  3956. __Pyx_XDECREF(__pyx_t_3);
  3957. __Pyx_AddTraceback("gevent._semaphore.Semaphore.wait", __pyx_clineno, __pyx_lineno, __pyx_filename);
  3958. __pyx_r = NULL;
  3959. __pyx_L0:;
  3960. __Pyx_XGIVEREF(__pyx_r);
  3961. __Pyx_RefNannyFinishContext();
  3962. return __pyx_r;
  3963. }
  3964. /* "gevent/_semaphore.py":198
  3965. * return self.counter
  3966. *
  3967. * def acquire(self, blocking=True, timeout=None): # <<<<<<<<<<<<<<
  3968. * """
  3969. * acquire(blocking=True, timeout=None) -> bool
  3970. */
  3971. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_19acquire(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
  3972. static int __pyx_f_6gevent_10_semaphore_9Semaphore_acquire(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, int __pyx_skip_dispatch, struct __pyx_opt_args_6gevent_10_semaphore_9Semaphore_acquire *__pyx_optional_args) {
  3973. int __pyx_v_blocking = ((int)1);
  3974. PyObject *__pyx_v_timeout = ((PyObject *)Py_None);
  3975. int __pyx_r;
  3976. __Pyx_RefNannyDeclarations
  3977. PyObject *__pyx_t_1 = NULL;
  3978. PyObject *__pyx_t_2 = NULL;
  3979. PyObject *__pyx_t_3 = NULL;
  3980. PyObject *__pyx_t_4 = NULL;
  3981. PyObject *__pyx_t_5 = NULL;
  3982. int __pyx_t_6;
  3983. PyObject *__pyx_t_7 = NULL;
  3984. int __pyx_t_8;
  3985. int __pyx_t_9;
  3986. __Pyx_RefNannySetupContext("acquire", 0);
  3987. if (__pyx_optional_args) {
  3988. if (__pyx_optional_args->__pyx_n > 0) {
  3989. __pyx_v_blocking = __pyx_optional_args->blocking;
  3990. if (__pyx_optional_args->__pyx_n > 1) {
  3991. __pyx_v_timeout = __pyx_optional_args->timeout;
  3992. }
  3993. }
  3994. }
  3995. __Pyx_INCREF(__pyx_v_timeout);
  3996. /* Check if called by wrapper */
  3997. if (unlikely(__pyx_skip_dispatch)) ;
  3998. /* Check if overridden in Python */
  3999. else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
  4000. __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_acquire); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 198, __pyx_L1_error)
  4001. __Pyx_GOTREF(__pyx_t_1);
  4002. if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_6gevent_10_semaphore_9Semaphore_19acquire)) {
  4003. __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_blocking); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 198, __pyx_L1_error)
  4004. __Pyx_GOTREF(__pyx_t_3);
  4005. __Pyx_INCREF(__pyx_t_1);
  4006. __pyx_t_4 = __pyx_t_1; __pyx_t_5 = NULL;
  4007. __pyx_t_6 = 0;
  4008. if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
  4009. __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
  4010. if (likely(__pyx_t_5)) {
  4011. PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
  4012. __Pyx_INCREF(__pyx_t_5);
  4013. __Pyx_INCREF(function);
  4014. __Pyx_DECREF_SET(__pyx_t_4, function);
  4015. __pyx_t_6 = 1;
  4016. }
  4017. }
  4018. #if CYTHON_FAST_PYCALL
  4019. if (PyFunction_Check(__pyx_t_4)) {
  4020. PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_3, __pyx_v_timeout};
  4021. __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 198, __pyx_L1_error)
  4022. __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  4023. __Pyx_GOTREF(__pyx_t_2);
  4024. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  4025. } else
  4026. #endif
  4027. #if CYTHON_FAST_PYCCALL
  4028. if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
  4029. PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_t_3, __pyx_v_timeout};
  4030. __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 198, __pyx_L1_error)
  4031. __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  4032. __Pyx_GOTREF(__pyx_t_2);
  4033. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  4034. } else
  4035. #endif
  4036. {
  4037. __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 198, __pyx_L1_error)
  4038. __Pyx_GOTREF(__pyx_t_7);
  4039. if (__pyx_t_5) {
  4040. __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL;
  4041. }
  4042. __Pyx_GIVEREF(__pyx_t_3);
  4043. PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_t_3);
  4044. __Pyx_INCREF(__pyx_v_timeout);
  4045. __Pyx_GIVEREF(__pyx_v_timeout);
  4046. PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_v_timeout);
  4047. __pyx_t_3 = 0;
  4048. __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 198, __pyx_L1_error)
  4049. __Pyx_GOTREF(__pyx_t_2);
  4050. __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  4051. }
  4052. __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  4053. __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 198, __pyx_L1_error)
  4054. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  4055. __pyx_r = __pyx_t_8;
  4056. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  4057. goto __pyx_L0;
  4058. }
  4059. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  4060. }
  4061. /* "gevent/_semaphore.py":219
  4062. * raise a ``Timeout`` exception, if some other caller had already started a timer.)
  4063. * """
  4064. * if self.counter > 0: # <<<<<<<<<<<<<<
  4065. * self.counter -= 1
  4066. * return True
  4067. */
  4068. __pyx_t_8 = ((__pyx_v_self->counter > 0) != 0);
  4069. if (__pyx_t_8) {
  4070. /* "gevent/_semaphore.py":220
  4071. * """
  4072. * if self.counter > 0:
  4073. * self.counter -= 1 # <<<<<<<<<<<<<<
  4074. * return True
  4075. *
  4076. */
  4077. __pyx_v_self->counter = (__pyx_v_self->counter - 1);
  4078. /* "gevent/_semaphore.py":221
  4079. * if self.counter > 0:
  4080. * self.counter -= 1
  4081. * return True # <<<<<<<<<<<<<<
  4082. *
  4083. * if not blocking:
  4084. */
  4085. __pyx_r = 1;
  4086. goto __pyx_L0;
  4087. /* "gevent/_semaphore.py":219
  4088. * raise a ``Timeout`` exception, if some other caller had already started a timer.)
  4089. * """
  4090. * if self.counter > 0: # <<<<<<<<<<<<<<
  4091. * self.counter -= 1
  4092. * return True
  4093. */
  4094. }
  4095. /* "gevent/_semaphore.py":223
  4096. * return True
  4097. *
  4098. * if not blocking: # <<<<<<<<<<<<<<
  4099. * return False
  4100. *
  4101. */
  4102. __pyx_t_8 = ((!(__pyx_v_blocking != 0)) != 0);
  4103. if (__pyx_t_8) {
  4104. /* "gevent/_semaphore.py":224
  4105. *
  4106. * if not blocking:
  4107. * return False # <<<<<<<<<<<<<<
  4108. *
  4109. * timeout = self._do_wait(timeout)
  4110. */
  4111. __pyx_r = 0;
  4112. goto __pyx_L0;
  4113. /* "gevent/_semaphore.py":223
  4114. * return True
  4115. *
  4116. * if not blocking: # <<<<<<<<<<<<<<
  4117. * return False
  4118. *
  4119. */
  4120. }
  4121. /* "gevent/_semaphore.py":226
  4122. * return False
  4123. *
  4124. * timeout = self._do_wait(timeout) # <<<<<<<<<<<<<<
  4125. * if timeout is not None:
  4126. * # Our timer expired.
  4127. */
  4128. __pyx_t_1 = ((struct __pyx_vtabstruct_6gevent_10_semaphore_Semaphore *)__pyx_v_self->__pyx_vtab)->_do_wait(__pyx_v_self, __pyx_v_timeout); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 226, __pyx_L1_error)
  4129. __Pyx_GOTREF(__pyx_t_1);
  4130. __Pyx_DECREF_SET(__pyx_v_timeout, __pyx_t_1);
  4131. __pyx_t_1 = 0;
  4132. /* "gevent/_semaphore.py":227
  4133. *
  4134. * timeout = self._do_wait(timeout)
  4135. * if timeout is not None: # <<<<<<<<<<<<<<
  4136. * # Our timer expired.
  4137. * return False
  4138. */
  4139. __pyx_t_8 = (__pyx_v_timeout != Py_None);
  4140. __pyx_t_9 = (__pyx_t_8 != 0);
  4141. if (__pyx_t_9) {
  4142. /* "gevent/_semaphore.py":229
  4143. * if timeout is not None:
  4144. * # Our timer expired.
  4145. * return False # <<<<<<<<<<<<<<
  4146. *
  4147. * # Neither our timer no another one expired, so we blocked until
  4148. */
  4149. __pyx_r = 0;
  4150. goto __pyx_L0;
  4151. /* "gevent/_semaphore.py":227
  4152. *
  4153. * timeout = self._do_wait(timeout)
  4154. * if timeout is not None: # <<<<<<<<<<<<<<
  4155. * # Our timer expired.
  4156. * return False
  4157. */
  4158. }
  4159. /* "gevent/_semaphore.py":233
  4160. * # Neither our timer no another one expired, so we blocked until
  4161. * # awoke. Therefore, the counter is ours
  4162. * self.counter -= 1 # <<<<<<<<<<<<<<
  4163. * assert self.counter >= 0
  4164. * return True
  4165. */
  4166. __pyx_v_self->counter = (__pyx_v_self->counter - 1);
  4167. /* "gevent/_semaphore.py":234
  4168. * # awoke. Therefore, the counter is ours
  4169. * self.counter -= 1
  4170. * assert self.counter >= 0 # <<<<<<<<<<<<<<
  4171. * return True
  4172. *
  4173. */
  4174. #ifndef CYTHON_WITHOUT_ASSERTIONS
  4175. if (unlikely(!Py_OptimizeFlag)) {
  4176. if (unlikely(!((__pyx_v_self->counter >= 0) != 0))) {
  4177. PyErr_SetNone(PyExc_AssertionError);
  4178. __PYX_ERR(0, 234, __pyx_L1_error)
  4179. }
  4180. }
  4181. #endif
  4182. /* "gevent/_semaphore.py":235
  4183. * self.counter -= 1
  4184. * assert self.counter >= 0
  4185. * return True # <<<<<<<<<<<<<<
  4186. *
  4187. * _py3k_acquire = acquire # PyPy needs this; it must be static for Cython
  4188. */
  4189. __pyx_r = 1;
  4190. goto __pyx_L0;
  4191. /* "gevent/_semaphore.py":198
  4192. * return self.counter
  4193. *
  4194. * def acquire(self, blocking=True, timeout=None): # <<<<<<<<<<<<<<
  4195. * """
  4196. * acquire(blocking=True, timeout=None) -> bool
  4197. */
  4198. /* function exit code */
  4199. __pyx_L1_error:;
  4200. __Pyx_XDECREF(__pyx_t_1);
  4201. __Pyx_XDECREF(__pyx_t_2);
  4202. __Pyx_XDECREF(__pyx_t_3);
  4203. __Pyx_XDECREF(__pyx_t_4);
  4204. __Pyx_XDECREF(__pyx_t_5);
  4205. __Pyx_XDECREF(__pyx_t_7);
  4206. __Pyx_AddTraceback("gevent._semaphore.Semaphore.acquire", __pyx_clineno, __pyx_lineno, __pyx_filename);
  4207. __pyx_r = -1000;
  4208. __pyx_L0:;
  4209. __Pyx_XDECREF(__pyx_v_timeout);
  4210. __Pyx_RefNannyFinishContext();
  4211. return __pyx_r;
  4212. }
  4213. /* Python wrapper */
  4214. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_19acquire(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
  4215. static char __pyx_doc_6gevent_10_semaphore_9Semaphore_18acquire[] = "\n acquire(blocking=True, timeout=None) -> bool\n\n Acquire the semaphore.\n\n .. caution:: If this semaphore was initialized with a size of 0,\n this method will block forever (unless a timeout is given or blocking is\n set to false).\n\n :keyword bool blocking: If True (the default), this function will block\n until the semaphore is acquired.\n :keyword float timeout: If given, specifies the maximum amount of seconds\n this method will block.\n :return: A boolean indicating whether the semaphore was acquired.\n If ``blocking`` is True and ``timeout`` is None (the default), then\n (so long as this semaphore was initialized with a size greater than 0)\n this will always return True. If a timeout was given, and it expired before\n the semaphore was acquired, False will be returned. (Note that this can still\n raise a ``Timeout`` exception, if some other caller had already started a timer.)\n ";
  4216. static PyMethodDef __pyx_mdef_6gevent_10_semaphore_9Semaphore_19acquire = {"acquire", (PyCFunction)__pyx_pw_6gevent_10_semaphore_9Semaphore_19acquire, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6gevent_10_semaphore_9Semaphore_18acquire};
  4217. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_19acquire(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  4218. int __pyx_v_blocking;
  4219. PyObject *__pyx_v_timeout = 0;
  4220. PyObject *__pyx_r = 0;
  4221. __Pyx_RefNannyDeclarations
  4222. __Pyx_RefNannySetupContext("acquire (wrapper)", 0);
  4223. {
  4224. static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_blocking,&__pyx_n_s_timeout,0};
  4225. PyObject* values[2] = {0,0};
  4226. values[1] = ((PyObject *)Py_None);
  4227. if (unlikely(__pyx_kwds)) {
  4228. Py_ssize_t kw_args;
  4229. const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
  4230. switch (pos_args) {
  4231. case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
  4232. case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
  4233. case 0: break;
  4234. default: goto __pyx_L5_argtuple_error;
  4235. }
  4236. kw_args = PyDict_Size(__pyx_kwds);
  4237. switch (pos_args) {
  4238. case 0:
  4239. if (kw_args > 0) {
  4240. PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_blocking);
  4241. if (value) { values[0] = value; kw_args--; }
  4242. }
  4243. case 1:
  4244. if (kw_args > 0) {
  4245. PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_timeout);
  4246. if (value) { values[1] = value; kw_args--; }
  4247. }
  4248. }
  4249. if (unlikely(kw_args > 0)) {
  4250. if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "acquire") < 0)) __PYX_ERR(0, 198, __pyx_L3_error)
  4251. }
  4252. } else {
  4253. switch (PyTuple_GET_SIZE(__pyx_args)) {
  4254. case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
  4255. case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
  4256. case 0: break;
  4257. default: goto __pyx_L5_argtuple_error;
  4258. }
  4259. }
  4260. if (values[0]) {
  4261. __pyx_v_blocking = __Pyx_PyInt_As_int(values[0]); if (unlikely((__pyx_v_blocking == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 198, __pyx_L3_error)
  4262. } else {
  4263. __pyx_v_blocking = ((int)1);
  4264. }
  4265. __pyx_v_timeout = values[1];
  4266. }
  4267. goto __pyx_L4_argument_unpacking_done;
  4268. __pyx_L5_argtuple_error:;
  4269. __Pyx_RaiseArgtupleInvalid("acquire", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 198, __pyx_L3_error)
  4270. __pyx_L3_error:;
  4271. __Pyx_AddTraceback("gevent._semaphore.Semaphore.acquire", __pyx_clineno, __pyx_lineno, __pyx_filename);
  4272. __Pyx_RefNannyFinishContext();
  4273. return NULL;
  4274. __pyx_L4_argument_unpacking_done:;
  4275. __pyx_r = __pyx_pf_6gevent_10_semaphore_9Semaphore_18acquire(((struct __pyx_obj_6gevent_10_semaphore_Semaphore *)__pyx_v_self), __pyx_v_blocking, __pyx_v_timeout);
  4276. /* function exit code */
  4277. __Pyx_RefNannyFinishContext();
  4278. return __pyx_r;
  4279. }
  4280. static PyObject *__pyx_pf_6gevent_10_semaphore_9Semaphore_18acquire(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, int __pyx_v_blocking, PyObject *__pyx_v_timeout) {
  4281. PyObject *__pyx_r = NULL;
  4282. __Pyx_RefNannyDeclarations
  4283. int __pyx_t_1;
  4284. struct __pyx_opt_args_6gevent_10_semaphore_9Semaphore_acquire __pyx_t_2;
  4285. PyObject *__pyx_t_3 = NULL;
  4286. __Pyx_RefNannySetupContext("acquire", 0);
  4287. __Pyx_XDECREF(__pyx_r);
  4288. __pyx_t_2.__pyx_n = 2;
  4289. __pyx_t_2.blocking = __pyx_v_blocking;
  4290. __pyx_t_2.timeout = __pyx_v_timeout;
  4291. __pyx_t_1 = __pyx_vtabptr_6gevent_10_semaphore_Semaphore->acquire(__pyx_v_self, 1, &__pyx_t_2); if (unlikely(__pyx_t_1 == -1000)) __PYX_ERR(0, 198, __pyx_L1_error)
  4292. __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 198, __pyx_L1_error)
  4293. __Pyx_GOTREF(__pyx_t_3);
  4294. __pyx_r = __pyx_t_3;
  4295. __pyx_t_3 = 0;
  4296. goto __pyx_L0;
  4297. /* function exit code */
  4298. __pyx_L1_error:;
  4299. __Pyx_XDECREF(__pyx_t_3);
  4300. __Pyx_AddTraceback("gevent._semaphore.Semaphore.acquire", __pyx_clineno, __pyx_lineno, __pyx_filename);
  4301. __pyx_r = NULL;
  4302. __pyx_L0:;
  4303. __Pyx_XGIVEREF(__pyx_r);
  4304. __Pyx_RefNannyFinishContext();
  4305. return __pyx_r;
  4306. }
  4307. /* "gevent/_semaphore.py":239
  4308. * _py3k_acquire = acquire # PyPy needs this; it must be static for Cython
  4309. *
  4310. * def __enter__(self): # <<<<<<<<<<<<<<
  4311. * self.acquire()
  4312. *
  4313. */
  4314. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_21__enter__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
  4315. static PyObject *__pyx_f_6gevent_10_semaphore_9Semaphore___enter__(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, int __pyx_skip_dispatch) {
  4316. PyObject *__pyx_r = NULL;
  4317. __Pyx_RefNannyDeclarations
  4318. PyObject *__pyx_t_1 = NULL;
  4319. PyObject *__pyx_t_2 = NULL;
  4320. PyObject *__pyx_t_3 = NULL;
  4321. PyObject *__pyx_t_4 = NULL;
  4322. int __pyx_t_5;
  4323. __Pyx_RefNannySetupContext("__enter__", 0);
  4324. /* Check if called by wrapper */
  4325. if (unlikely(__pyx_skip_dispatch)) ;
  4326. /* Check if overridden in Python */
  4327. else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
  4328. __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_enter); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 239, __pyx_L1_error)
  4329. __Pyx_GOTREF(__pyx_t_1);
  4330. if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_6gevent_10_semaphore_9Semaphore_21__enter__)) {
  4331. __Pyx_XDECREF(__pyx_r);
  4332. __Pyx_INCREF(__pyx_t_1);
  4333. __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
  4334. if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
  4335. __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
  4336. if (likely(__pyx_t_4)) {
  4337. PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
  4338. __Pyx_INCREF(__pyx_t_4);
  4339. __Pyx_INCREF(function);
  4340. __Pyx_DECREF_SET(__pyx_t_3, function);
  4341. }
  4342. }
  4343. if (__pyx_t_4) {
  4344. __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 239, __pyx_L1_error)
  4345. __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  4346. } else {
  4347. __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 239, __pyx_L1_error)
  4348. }
  4349. __Pyx_GOTREF(__pyx_t_2);
  4350. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  4351. __pyx_r = __pyx_t_2;
  4352. __pyx_t_2 = 0;
  4353. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  4354. goto __pyx_L0;
  4355. }
  4356. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  4357. }
  4358. /* "gevent/_semaphore.py":240
  4359. *
  4360. * def __enter__(self):
  4361. * self.acquire() # <<<<<<<<<<<<<<
  4362. *
  4363. * def __exit__(self, t, v, tb):
  4364. */
  4365. __pyx_t_5 = ((struct __pyx_vtabstruct_6gevent_10_semaphore_Semaphore *)__pyx_v_self->__pyx_vtab)->acquire(__pyx_v_self, 0, NULL); if (unlikely(__pyx_t_5 == -1000)) __PYX_ERR(0, 240, __pyx_L1_error)
  4366. /* "gevent/_semaphore.py":239
  4367. * _py3k_acquire = acquire # PyPy needs this; it must be static for Cython
  4368. *
  4369. * def __enter__(self): # <<<<<<<<<<<<<<
  4370. * self.acquire()
  4371. *
  4372. */
  4373. /* function exit code */
  4374. __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  4375. goto __pyx_L0;
  4376. __pyx_L1_error:;
  4377. __Pyx_XDECREF(__pyx_t_1);
  4378. __Pyx_XDECREF(__pyx_t_2);
  4379. __Pyx_XDECREF(__pyx_t_3);
  4380. __Pyx_XDECREF(__pyx_t_4);
  4381. __Pyx_AddTraceback("gevent._semaphore.Semaphore.__enter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  4382. __pyx_r = 0;
  4383. __pyx_L0:;
  4384. __Pyx_XGIVEREF(__pyx_r);
  4385. __Pyx_RefNannyFinishContext();
  4386. return __pyx_r;
  4387. }
  4388. /* Python wrapper */
  4389. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_21__enter__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
  4390. static PyMethodDef __pyx_mdef_6gevent_10_semaphore_9Semaphore_21__enter__ = {"__enter__", (PyCFunction)__pyx_pw_6gevent_10_semaphore_9Semaphore_21__enter__, METH_NOARGS, 0};
  4391. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_21__enter__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  4392. PyObject *__pyx_r = 0;
  4393. __Pyx_RefNannyDeclarations
  4394. __Pyx_RefNannySetupContext("__enter__ (wrapper)", 0);
  4395. __pyx_r = __pyx_pf_6gevent_10_semaphore_9Semaphore_20__enter__(((struct __pyx_obj_6gevent_10_semaphore_Semaphore *)__pyx_v_self));
  4396. /* function exit code */
  4397. __Pyx_RefNannyFinishContext();
  4398. return __pyx_r;
  4399. }
  4400. static PyObject *__pyx_pf_6gevent_10_semaphore_9Semaphore_20__enter__(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self) {
  4401. PyObject *__pyx_r = NULL;
  4402. __Pyx_RefNannyDeclarations
  4403. PyObject *__pyx_t_1 = NULL;
  4404. __Pyx_RefNannySetupContext("__enter__", 0);
  4405. __Pyx_XDECREF(__pyx_r);
  4406. __pyx_t_1 = __pyx_f_6gevent_10_semaphore_9Semaphore___enter__(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 239, __pyx_L1_error)
  4407. __Pyx_GOTREF(__pyx_t_1);
  4408. __pyx_r = __pyx_t_1;
  4409. __pyx_t_1 = 0;
  4410. goto __pyx_L0;
  4411. /* function exit code */
  4412. __pyx_L1_error:;
  4413. __Pyx_XDECREF(__pyx_t_1);
  4414. __Pyx_AddTraceback("gevent._semaphore.Semaphore.__enter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  4415. __pyx_r = NULL;
  4416. __pyx_L0:;
  4417. __Pyx_XGIVEREF(__pyx_r);
  4418. __Pyx_RefNannyFinishContext();
  4419. return __pyx_r;
  4420. }
  4421. /* "gevent/_semaphore.py":242
  4422. * self.acquire()
  4423. *
  4424. * def __exit__(self, t, v, tb): # <<<<<<<<<<<<<<
  4425. * self.release()
  4426. *
  4427. */
  4428. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_23__exit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
  4429. static PyObject *__pyx_f_6gevent_10_semaphore_9Semaphore___exit__(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_t, CYTHON_UNUSED PyObject *__pyx_v_v, CYTHON_UNUSED PyObject *__pyx_v_tb, int __pyx_skip_dispatch) {
  4430. PyObject *__pyx_r = NULL;
  4431. __Pyx_RefNannyDeclarations
  4432. PyObject *__pyx_t_1 = NULL;
  4433. PyObject *__pyx_t_2 = NULL;
  4434. PyObject *__pyx_t_3 = NULL;
  4435. PyObject *__pyx_t_4 = NULL;
  4436. int __pyx_t_5;
  4437. PyObject *__pyx_t_6 = NULL;
  4438. __Pyx_RefNannySetupContext("__exit__", 0);
  4439. /* Check if called by wrapper */
  4440. if (unlikely(__pyx_skip_dispatch)) ;
  4441. /* Check if overridden in Python */
  4442. else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
  4443. __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_exit); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 242, __pyx_L1_error)
  4444. __Pyx_GOTREF(__pyx_t_1);
  4445. if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_6gevent_10_semaphore_9Semaphore_23__exit__)) {
  4446. __Pyx_XDECREF(__pyx_r);
  4447. __Pyx_INCREF(__pyx_t_1);
  4448. __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
  4449. __pyx_t_5 = 0;
  4450. if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
  4451. __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
  4452. if (likely(__pyx_t_4)) {
  4453. PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
  4454. __Pyx_INCREF(__pyx_t_4);
  4455. __Pyx_INCREF(function);
  4456. __Pyx_DECREF_SET(__pyx_t_3, function);
  4457. __pyx_t_5 = 1;
  4458. }
  4459. }
  4460. #if CYTHON_FAST_PYCALL
  4461. if (PyFunction_Check(__pyx_t_3)) {
  4462. PyObject *__pyx_temp[4] = {__pyx_t_4, __pyx_v_t, __pyx_v_v, __pyx_v_tb};
  4463. __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 3+__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 242, __pyx_L1_error)
  4464. __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  4465. __Pyx_GOTREF(__pyx_t_2);
  4466. } else
  4467. #endif
  4468. #if CYTHON_FAST_PYCCALL
  4469. if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
  4470. PyObject *__pyx_temp[4] = {__pyx_t_4, __pyx_v_t, __pyx_v_v, __pyx_v_tb};
  4471. __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 3+__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 242, __pyx_L1_error)
  4472. __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  4473. __Pyx_GOTREF(__pyx_t_2);
  4474. } else
  4475. #endif
  4476. {
  4477. __pyx_t_6 = PyTuple_New(3+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 242, __pyx_L1_error)
  4478. __Pyx_GOTREF(__pyx_t_6);
  4479. if (__pyx_t_4) {
  4480. __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __pyx_t_4 = NULL;
  4481. }
  4482. __Pyx_INCREF(__pyx_v_t);
  4483. __Pyx_GIVEREF(__pyx_v_t);
  4484. PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_v_t);
  4485. __Pyx_INCREF(__pyx_v_v);
  4486. __Pyx_GIVEREF(__pyx_v_v);
  4487. PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_v_v);
  4488. __Pyx_INCREF(__pyx_v_tb);
  4489. __Pyx_GIVEREF(__pyx_v_tb);
  4490. PyTuple_SET_ITEM(__pyx_t_6, 2+__pyx_t_5, __pyx_v_tb);
  4491. __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 242, __pyx_L1_error)
  4492. __Pyx_GOTREF(__pyx_t_2);
  4493. __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  4494. }
  4495. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  4496. __pyx_r = __pyx_t_2;
  4497. __pyx_t_2 = 0;
  4498. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  4499. goto __pyx_L0;
  4500. }
  4501. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  4502. }
  4503. /* "gevent/_semaphore.py":243
  4504. *
  4505. * def __exit__(self, t, v, tb):
  4506. * self.release() # <<<<<<<<<<<<<<
  4507. *
  4508. *
  4509. */
  4510. __pyx_t_5 = ((struct __pyx_vtabstruct_6gevent_10_semaphore_Semaphore *)__pyx_v_self->__pyx_vtab)->release(__pyx_v_self, 0); if (unlikely(__pyx_t_5 == -1000)) __PYX_ERR(0, 243, __pyx_L1_error)
  4511. /* "gevent/_semaphore.py":242
  4512. * self.acquire()
  4513. *
  4514. * def __exit__(self, t, v, tb): # <<<<<<<<<<<<<<
  4515. * self.release()
  4516. *
  4517. */
  4518. /* function exit code */
  4519. __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  4520. goto __pyx_L0;
  4521. __pyx_L1_error:;
  4522. __Pyx_XDECREF(__pyx_t_1);
  4523. __Pyx_XDECREF(__pyx_t_2);
  4524. __Pyx_XDECREF(__pyx_t_3);
  4525. __Pyx_XDECREF(__pyx_t_4);
  4526. __Pyx_XDECREF(__pyx_t_6);
  4527. __Pyx_AddTraceback("gevent._semaphore.Semaphore.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  4528. __pyx_r = 0;
  4529. __pyx_L0:;
  4530. __Pyx_XGIVEREF(__pyx_r);
  4531. __Pyx_RefNannyFinishContext();
  4532. return __pyx_r;
  4533. }
  4534. /* Python wrapper */
  4535. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_23__exit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
  4536. static PyMethodDef __pyx_mdef_6gevent_10_semaphore_9Semaphore_23__exit__ = {"__exit__", (PyCFunction)__pyx_pw_6gevent_10_semaphore_9Semaphore_23__exit__, METH_VARARGS|METH_KEYWORDS, 0};
  4537. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_23__exit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  4538. PyObject *__pyx_v_t = 0;
  4539. PyObject *__pyx_v_v = 0;
  4540. PyObject *__pyx_v_tb = 0;
  4541. PyObject *__pyx_r = 0;
  4542. __Pyx_RefNannyDeclarations
  4543. __Pyx_RefNannySetupContext("__exit__ (wrapper)", 0);
  4544. {
  4545. static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_t,&__pyx_n_s_v,&__pyx_n_s_tb,0};
  4546. PyObject* values[3] = {0,0,0};
  4547. if (unlikely(__pyx_kwds)) {
  4548. Py_ssize_t kw_args;
  4549. const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
  4550. switch (pos_args) {
  4551. case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
  4552. case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
  4553. case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
  4554. case 0: break;
  4555. default: goto __pyx_L5_argtuple_error;
  4556. }
  4557. kw_args = PyDict_Size(__pyx_kwds);
  4558. switch (pos_args) {
  4559. case 0:
  4560. if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_t)) != 0)) kw_args--;
  4561. else goto __pyx_L5_argtuple_error;
  4562. case 1:
  4563. if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_v)) != 0)) kw_args--;
  4564. else {
  4565. __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 1); __PYX_ERR(0, 242, __pyx_L3_error)
  4566. }
  4567. case 2:
  4568. if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tb)) != 0)) kw_args--;
  4569. else {
  4570. __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 2); __PYX_ERR(0, 242, __pyx_L3_error)
  4571. }
  4572. }
  4573. if (unlikely(kw_args > 0)) {
  4574. if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__exit__") < 0)) __PYX_ERR(0, 242, __pyx_L3_error)
  4575. }
  4576. } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
  4577. goto __pyx_L5_argtuple_error;
  4578. } else {
  4579. values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
  4580. values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
  4581. values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
  4582. }
  4583. __pyx_v_t = values[0];
  4584. __pyx_v_v = values[1];
  4585. __pyx_v_tb = values[2];
  4586. }
  4587. goto __pyx_L4_argument_unpacking_done;
  4588. __pyx_L5_argtuple_error:;
  4589. __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 242, __pyx_L3_error)
  4590. __pyx_L3_error:;
  4591. __Pyx_AddTraceback("gevent._semaphore.Semaphore.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  4592. __Pyx_RefNannyFinishContext();
  4593. return NULL;
  4594. __pyx_L4_argument_unpacking_done:;
  4595. __pyx_r = __pyx_pf_6gevent_10_semaphore_9Semaphore_22__exit__(((struct __pyx_obj_6gevent_10_semaphore_Semaphore *)__pyx_v_self), __pyx_v_t, __pyx_v_v, __pyx_v_tb);
  4596. /* function exit code */
  4597. __Pyx_RefNannyFinishContext();
  4598. return __pyx_r;
  4599. }
  4600. static PyObject *__pyx_pf_6gevent_10_semaphore_9Semaphore_22__exit__(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, PyObject *__pyx_v_t, PyObject *__pyx_v_v, PyObject *__pyx_v_tb) {
  4601. PyObject *__pyx_r = NULL;
  4602. __Pyx_RefNannyDeclarations
  4603. PyObject *__pyx_t_1 = NULL;
  4604. __Pyx_RefNannySetupContext("__exit__", 0);
  4605. __Pyx_XDECREF(__pyx_r);
  4606. __pyx_t_1 = __pyx_f_6gevent_10_semaphore_9Semaphore___exit__(__pyx_v_self, __pyx_v_t, __pyx_v_v, __pyx_v_tb, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 242, __pyx_L1_error)
  4607. __Pyx_GOTREF(__pyx_t_1);
  4608. __pyx_r = __pyx_t_1;
  4609. __pyx_t_1 = 0;
  4610. goto __pyx_L0;
  4611. /* function exit code */
  4612. __pyx_L1_error:;
  4613. __Pyx_XDECREF(__pyx_t_1);
  4614. __Pyx_AddTraceback("gevent._semaphore.Semaphore.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  4615. __pyx_r = NULL;
  4616. __pyx_L0:;
  4617. __Pyx_XGIVEREF(__pyx_r);
  4618. __Pyx_RefNannyFinishContext();
  4619. return __pyx_r;
  4620. }
  4621. /* "gevent/_semaphore.pxd":2
  4622. * cdef class Semaphore:
  4623. * cdef public int counter # <<<<<<<<<<<<<<
  4624. * cdef readonly object _links
  4625. * cdef readonly object _notifier
  4626. */
  4627. /* Python wrapper */
  4628. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_7counter_1__get__(PyObject *__pyx_v_self); /*proto*/
  4629. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_7counter_1__get__(PyObject *__pyx_v_self) {
  4630. PyObject *__pyx_r = 0;
  4631. __Pyx_RefNannyDeclarations
  4632. __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  4633. __pyx_r = __pyx_pf_6gevent_10_semaphore_9Semaphore_7counter___get__(((struct __pyx_obj_6gevent_10_semaphore_Semaphore *)__pyx_v_self));
  4634. /* function exit code */
  4635. __Pyx_RefNannyFinishContext();
  4636. return __pyx_r;
  4637. }
  4638. static PyObject *__pyx_pf_6gevent_10_semaphore_9Semaphore_7counter___get__(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self) {
  4639. PyObject *__pyx_r = NULL;
  4640. __Pyx_RefNannyDeclarations
  4641. PyObject *__pyx_t_1 = NULL;
  4642. __Pyx_RefNannySetupContext("__get__", 0);
  4643. __Pyx_XDECREF(__pyx_r);
  4644. __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->counter); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error)
  4645. __Pyx_GOTREF(__pyx_t_1);
  4646. __pyx_r = __pyx_t_1;
  4647. __pyx_t_1 = 0;
  4648. goto __pyx_L0;
  4649. /* function exit code */
  4650. __pyx_L1_error:;
  4651. __Pyx_XDECREF(__pyx_t_1);
  4652. __Pyx_AddTraceback("gevent._semaphore.Semaphore.counter.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  4653. __pyx_r = NULL;
  4654. __pyx_L0:;
  4655. __Pyx_XGIVEREF(__pyx_r);
  4656. __Pyx_RefNannyFinishContext();
  4657. return __pyx_r;
  4658. }
  4659. /* Python wrapper */
  4660. static int __pyx_pw_6gevent_10_semaphore_9Semaphore_7counter_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
  4661. static int __pyx_pw_6gevent_10_semaphore_9Semaphore_7counter_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
  4662. int __pyx_r;
  4663. __Pyx_RefNannyDeclarations
  4664. __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  4665. __pyx_r = __pyx_pf_6gevent_10_semaphore_9Semaphore_7counter_2__set__(((struct __pyx_obj_6gevent_10_semaphore_Semaphore *)__pyx_v_self), ((PyObject *)__pyx_v_value));
  4666. /* function exit code */
  4667. __Pyx_RefNannyFinishContext();
  4668. return __pyx_r;
  4669. }
  4670. static int __pyx_pf_6gevent_10_semaphore_9Semaphore_7counter_2__set__(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, PyObject *__pyx_v_value) {
  4671. int __pyx_r;
  4672. __Pyx_RefNannyDeclarations
  4673. int __pyx_t_1;
  4674. __Pyx_RefNannySetupContext("__set__", 0);
  4675. __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 2, __pyx_L1_error)
  4676. __pyx_v_self->counter = __pyx_t_1;
  4677. /* function exit code */
  4678. __pyx_r = 0;
  4679. goto __pyx_L0;
  4680. __pyx_L1_error:;
  4681. __Pyx_AddTraceback("gevent._semaphore.Semaphore.counter.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  4682. __pyx_r = -1;
  4683. __pyx_L0:;
  4684. __Pyx_RefNannyFinishContext();
  4685. return __pyx_r;
  4686. }
  4687. /* "gevent/_semaphore.pxd":3
  4688. * cdef class Semaphore:
  4689. * cdef public int counter
  4690. * cdef readonly object _links # <<<<<<<<<<<<<<
  4691. * cdef readonly object _notifier
  4692. * cdef public int _dirty
  4693. */
  4694. /* Python wrapper */
  4695. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_6_links_1__get__(PyObject *__pyx_v_self); /*proto*/
  4696. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_6_links_1__get__(PyObject *__pyx_v_self) {
  4697. PyObject *__pyx_r = 0;
  4698. __Pyx_RefNannyDeclarations
  4699. __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  4700. __pyx_r = __pyx_pf_6gevent_10_semaphore_9Semaphore_6_links___get__(((struct __pyx_obj_6gevent_10_semaphore_Semaphore *)__pyx_v_self));
  4701. /* function exit code */
  4702. __Pyx_RefNannyFinishContext();
  4703. return __pyx_r;
  4704. }
  4705. static PyObject *__pyx_pf_6gevent_10_semaphore_9Semaphore_6_links___get__(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self) {
  4706. PyObject *__pyx_r = NULL;
  4707. __Pyx_RefNannyDeclarations
  4708. __Pyx_RefNannySetupContext("__get__", 0);
  4709. __Pyx_XDECREF(__pyx_r);
  4710. __Pyx_INCREF(__pyx_v_self->_links);
  4711. __pyx_r = __pyx_v_self->_links;
  4712. goto __pyx_L0;
  4713. /* function exit code */
  4714. __pyx_L0:;
  4715. __Pyx_XGIVEREF(__pyx_r);
  4716. __Pyx_RefNannyFinishContext();
  4717. return __pyx_r;
  4718. }
  4719. /* "gevent/_semaphore.pxd":4
  4720. * cdef public int counter
  4721. * cdef readonly object _links
  4722. * cdef readonly object _notifier # <<<<<<<<<<<<<<
  4723. * cdef public int _dirty
  4724. * cdef object __weakref__
  4725. */
  4726. /* Python wrapper */
  4727. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_9_notifier_1__get__(PyObject *__pyx_v_self); /*proto*/
  4728. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_9_notifier_1__get__(PyObject *__pyx_v_self) {
  4729. PyObject *__pyx_r = 0;
  4730. __Pyx_RefNannyDeclarations
  4731. __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  4732. __pyx_r = __pyx_pf_6gevent_10_semaphore_9Semaphore_9_notifier___get__(((struct __pyx_obj_6gevent_10_semaphore_Semaphore *)__pyx_v_self));
  4733. /* function exit code */
  4734. __Pyx_RefNannyFinishContext();
  4735. return __pyx_r;
  4736. }
  4737. static PyObject *__pyx_pf_6gevent_10_semaphore_9Semaphore_9_notifier___get__(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self) {
  4738. PyObject *__pyx_r = NULL;
  4739. __Pyx_RefNannyDeclarations
  4740. __Pyx_RefNannySetupContext("__get__", 0);
  4741. __Pyx_XDECREF(__pyx_r);
  4742. __Pyx_INCREF(__pyx_v_self->_notifier);
  4743. __pyx_r = __pyx_v_self->_notifier;
  4744. goto __pyx_L0;
  4745. /* function exit code */
  4746. __pyx_L0:;
  4747. __Pyx_XGIVEREF(__pyx_r);
  4748. __Pyx_RefNannyFinishContext();
  4749. return __pyx_r;
  4750. }
  4751. /* "gevent/_semaphore.pxd":5
  4752. * cdef readonly object _links
  4753. * cdef readonly object _notifier
  4754. * cdef public int _dirty # <<<<<<<<<<<<<<
  4755. * cdef object __weakref__
  4756. *
  4757. */
  4758. /* Python wrapper */
  4759. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_6_dirty_1__get__(PyObject *__pyx_v_self); /*proto*/
  4760. static PyObject *__pyx_pw_6gevent_10_semaphore_9Semaphore_6_dirty_1__get__(PyObject *__pyx_v_self) {
  4761. PyObject *__pyx_r = 0;
  4762. __Pyx_RefNannyDeclarations
  4763. __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  4764. __pyx_r = __pyx_pf_6gevent_10_semaphore_9Semaphore_6_dirty___get__(((struct __pyx_obj_6gevent_10_semaphore_Semaphore *)__pyx_v_self));
  4765. /* function exit code */
  4766. __Pyx_RefNannyFinishContext();
  4767. return __pyx_r;
  4768. }
  4769. static PyObject *__pyx_pf_6gevent_10_semaphore_9Semaphore_6_dirty___get__(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self) {
  4770. PyObject *__pyx_r = NULL;
  4771. __Pyx_RefNannyDeclarations
  4772. PyObject *__pyx_t_1 = NULL;
  4773. __Pyx_RefNannySetupContext("__get__", 0);
  4774. __Pyx_XDECREF(__pyx_r);
  4775. __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_dirty); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error)
  4776. __Pyx_GOTREF(__pyx_t_1);
  4777. __pyx_r = __pyx_t_1;
  4778. __pyx_t_1 = 0;
  4779. goto __pyx_L0;
  4780. /* function exit code */
  4781. __pyx_L1_error:;
  4782. __Pyx_XDECREF(__pyx_t_1);
  4783. __Pyx_AddTraceback("gevent._semaphore.Semaphore._dirty.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  4784. __pyx_r = NULL;
  4785. __pyx_L0:;
  4786. __Pyx_XGIVEREF(__pyx_r);
  4787. __Pyx_RefNannyFinishContext();
  4788. return __pyx_r;
  4789. }
  4790. /* Python wrapper */
  4791. static int __pyx_pw_6gevent_10_semaphore_9Semaphore_6_dirty_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/
  4792. static int __pyx_pw_6gevent_10_semaphore_9Semaphore_6_dirty_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) {
  4793. int __pyx_r;
  4794. __Pyx_RefNannyDeclarations
  4795. __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  4796. __pyx_r = __pyx_pf_6gevent_10_semaphore_9Semaphore_6_dirty_2__set__(((struct __pyx_obj_6gevent_10_semaphore_Semaphore *)__pyx_v_self), ((PyObject *)__pyx_v_value));
  4797. /* function exit code */
  4798. __Pyx_RefNannyFinishContext();
  4799. return __pyx_r;
  4800. }
  4801. static int __pyx_pf_6gevent_10_semaphore_9Semaphore_6_dirty_2__set__(struct __pyx_obj_6gevent_10_semaphore_Semaphore *__pyx_v_self, PyObject *__pyx_v_value) {
  4802. int __pyx_r;
  4803. __Pyx_RefNannyDeclarations
  4804. int __pyx_t_1;
  4805. __Pyx_RefNannySetupContext("__set__", 0);
  4806. __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_value); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 5, __pyx_L1_error)
  4807. __pyx_v_self->_dirty = __pyx_t_1;
  4808. /* function exit code */
  4809. __pyx_r = 0;
  4810. goto __pyx_L0;
  4811. __pyx_L1_error:;
  4812. __Pyx_AddTraceback("gevent._semaphore.Semaphore._dirty.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  4813. __pyx_r = -1;
  4814. __pyx_L0:;
  4815. __Pyx_RefNannyFinishContext();
  4816. return __pyx_r;
  4817. }
  4818. /* "gevent/_semaphore.py":262
  4819. * _OVER_RELEASE_ERROR = ValueError
  4820. *
  4821. * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<<
  4822. * Semaphore.__init__(self, *args, **kwargs)
  4823. * self._initial_value = self.counter
  4824. */
  4825. /* Python wrapper */
  4826. static int __pyx_pw_6gevent_10_semaphore_16BoundedSemaphore_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
  4827. static int __pyx_pw_6gevent_10_semaphore_16BoundedSemaphore_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  4828. PyObject *__pyx_v_args = 0;
  4829. PyObject *__pyx_v_kwargs = 0;
  4830. int __pyx_r;
  4831. __Pyx_RefNannyDeclarations
  4832. __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  4833. if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 1))) return -1;
  4834. if (unlikely(__pyx_kwds)) {
  4835. __pyx_v_kwargs = PyDict_Copy(__pyx_kwds); if (unlikely(!__pyx_v_kwargs)) return -1;
  4836. __Pyx_GOTREF(__pyx_v_kwargs);
  4837. } else {
  4838. __pyx_v_kwargs = NULL;
  4839. }
  4840. __Pyx_INCREF(__pyx_args);
  4841. __pyx_v_args = __pyx_args;
  4842. __pyx_r = __pyx_pf_6gevent_10_semaphore_16BoundedSemaphore___init__(((struct __pyx_obj_6gevent_10_semaphore_BoundedSemaphore *)__pyx_v_self), __pyx_v_args, __pyx_v_kwargs);
  4843. /* function exit code */
  4844. __Pyx_XDECREF(__pyx_v_args);
  4845. __Pyx_XDECREF(__pyx_v_kwargs);
  4846. __Pyx_RefNannyFinishContext();
  4847. return __pyx_r;
  4848. }
  4849. static int __pyx_pf_6gevent_10_semaphore_16BoundedSemaphore___init__(struct __pyx_obj_6gevent_10_semaphore_BoundedSemaphore *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  4850. int __pyx_r;
  4851. __Pyx_RefNannyDeclarations
  4852. PyObject *__pyx_t_1 = NULL;
  4853. PyObject *__pyx_t_2 = NULL;
  4854. PyObject *__pyx_t_3 = NULL;
  4855. int __pyx_t_4;
  4856. __Pyx_RefNannySetupContext("__init__", 0);
  4857. /* "gevent/_semaphore.py":263
  4858. *
  4859. * def __init__(self, *args, **kwargs):
  4860. * Semaphore.__init__(self, *args, **kwargs) # <<<<<<<<<<<<<<
  4861. * self._initial_value = self.counter
  4862. *
  4863. */
  4864. __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_6gevent_10_semaphore_Semaphore), __pyx_n_s_init); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 263, __pyx_L1_error)
  4865. __Pyx_GOTREF(__pyx_t_1);
  4866. __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 263, __pyx_L1_error)
  4867. __Pyx_GOTREF(__pyx_t_2);
  4868. __Pyx_INCREF(((PyObject *)__pyx_v_self));
  4869. __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  4870. PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self));
  4871. __pyx_t_3 = PyNumber_Add(__pyx_t_2, __pyx_v_args); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 263, __pyx_L1_error)
  4872. __Pyx_GOTREF(__pyx_t_3);
  4873. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  4874. __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, __pyx_v_kwargs); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 263, __pyx_L1_error)
  4875. __Pyx_GOTREF(__pyx_t_2);
  4876. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  4877. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  4878. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  4879. /* "gevent/_semaphore.py":264
  4880. * def __init__(self, *args, **kwargs):
  4881. * Semaphore.__init__(self, *args, **kwargs)
  4882. * self._initial_value = self.counter # <<<<<<<<<<<<<<
  4883. *
  4884. * def release(self):
  4885. */
  4886. __pyx_t_4 = __pyx_v_self->__pyx_base.counter;
  4887. __pyx_v_self->_initial_value = __pyx_t_4;
  4888. /* "gevent/_semaphore.py":262
  4889. * _OVER_RELEASE_ERROR = ValueError
  4890. *
  4891. * def __init__(self, *args, **kwargs): # <<<<<<<<<<<<<<
  4892. * Semaphore.__init__(self, *args, **kwargs)
  4893. * self._initial_value = self.counter
  4894. */
  4895. /* function exit code */
  4896. __pyx_r = 0;
  4897. goto __pyx_L0;
  4898. __pyx_L1_error:;
  4899. __Pyx_XDECREF(__pyx_t_1);
  4900. __Pyx_XDECREF(__pyx_t_2);
  4901. __Pyx_XDECREF(__pyx_t_3);
  4902. __Pyx_AddTraceback("gevent._semaphore.BoundedSemaphore.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  4903. __pyx_r = -1;
  4904. __pyx_L0:;
  4905. __Pyx_RefNannyFinishContext();
  4906. return __pyx_r;
  4907. }
  4908. /* "gevent/_semaphore.py":266
  4909. * self._initial_value = self.counter
  4910. *
  4911. * def release(self): # <<<<<<<<<<<<<<
  4912. * if self.counter >= self._initial_value:
  4913. * raise self._OVER_RELEASE_ERROR("Semaphore released too many times")
  4914. */
  4915. static PyObject *__pyx_pw_6gevent_10_semaphore_16BoundedSemaphore_3release(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
  4916. static int __pyx_f_6gevent_10_semaphore_16BoundedSemaphore_release(struct __pyx_obj_6gevent_10_semaphore_BoundedSemaphore *__pyx_v_self, int __pyx_skip_dispatch) {
  4917. int __pyx_r;
  4918. __Pyx_RefNannyDeclarations
  4919. PyObject *__pyx_t_1 = NULL;
  4920. PyObject *__pyx_t_2 = NULL;
  4921. PyObject *__pyx_t_3 = NULL;
  4922. PyObject *__pyx_t_4 = NULL;
  4923. int __pyx_t_5;
  4924. int __pyx_t_6;
  4925. __Pyx_RefNannySetupContext("release", 0);
  4926. /* Check if called by wrapper */
  4927. if (unlikely(__pyx_skip_dispatch)) ;
  4928. /* Check if overridden in Python */
  4929. else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
  4930. __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_release); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 266, __pyx_L1_error)
  4931. __Pyx_GOTREF(__pyx_t_1);
  4932. if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_6gevent_10_semaphore_16BoundedSemaphore_3release)) {
  4933. __Pyx_INCREF(__pyx_t_1);
  4934. __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
  4935. if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
  4936. __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
  4937. if (likely(__pyx_t_4)) {
  4938. PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
  4939. __Pyx_INCREF(__pyx_t_4);
  4940. __Pyx_INCREF(function);
  4941. __Pyx_DECREF_SET(__pyx_t_3, function);
  4942. }
  4943. }
  4944. if (__pyx_t_4) {
  4945. __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 266, __pyx_L1_error)
  4946. __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  4947. } else {
  4948. __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 266, __pyx_L1_error)
  4949. }
  4950. __Pyx_GOTREF(__pyx_t_2);
  4951. __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  4952. __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 266, __pyx_L1_error)
  4953. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  4954. __pyx_r = __pyx_t_5;
  4955. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  4956. goto __pyx_L0;
  4957. }
  4958. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  4959. }
  4960. /* "gevent/_semaphore.py":267
  4961. *
  4962. * def release(self):
  4963. * if self.counter >= self._initial_value: # <<<<<<<<<<<<<<
  4964. * raise self._OVER_RELEASE_ERROR("Semaphore released too many times")
  4965. * return Semaphore.release(self)
  4966. */
  4967. __pyx_t_6 = ((__pyx_v_self->__pyx_base.counter >= __pyx_v_self->_initial_value) != 0);
  4968. if (__pyx_t_6) {
  4969. /* "gevent/_semaphore.py":268
  4970. * def release(self):
  4971. * if self.counter >= self._initial_value:
  4972. * raise self._OVER_RELEASE_ERROR("Semaphore released too many times") # <<<<<<<<<<<<<<
  4973. * return Semaphore.release(self)
  4974. */
  4975. __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_OVER_RELEASE_ERROR); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 268, __pyx_L1_error)
  4976. __Pyx_GOTREF(__pyx_t_1);
  4977. __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 268, __pyx_L1_error)
  4978. __Pyx_GOTREF(__pyx_t_2);
  4979. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  4980. __Pyx_Raise(__pyx_t_2, 0, 0, 0);
  4981. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  4982. __PYX_ERR(0, 268, __pyx_L1_error)
  4983. /* "gevent/_semaphore.py":267
  4984. *
  4985. * def release(self):
  4986. * if self.counter >= self._initial_value: # <<<<<<<<<<<<<<
  4987. * raise self._OVER_RELEASE_ERROR("Semaphore released too many times")
  4988. * return Semaphore.release(self)
  4989. */
  4990. }
  4991. /* "gevent/_semaphore.py":269
  4992. * if self.counter >= self._initial_value:
  4993. * raise self._OVER_RELEASE_ERROR("Semaphore released too many times")
  4994. * return Semaphore.release(self) # <<<<<<<<<<<<<<
  4995. */
  4996. __pyx_t_5 = __pyx_f_6gevent_10_semaphore_9Semaphore_release(((struct __pyx_obj_6gevent_10_semaphore_Semaphore *)__pyx_v_self), 1); if (unlikely(__pyx_t_5 == -1000)) __PYX_ERR(0, 269, __pyx_L1_error)
  4997. __pyx_r = __pyx_t_5;
  4998. goto __pyx_L0;
  4999. /* "gevent/_semaphore.py":266
  5000. * self._initial_value = self.counter
  5001. *
  5002. * def release(self): # <<<<<<<<<<<<<<
  5003. * if self.counter >= self._initial_value:
  5004. * raise self._OVER_RELEASE_ERROR("Semaphore released too many times")
  5005. */
  5006. /* function exit code */
  5007. __pyx_L1_error:;
  5008. __Pyx_XDECREF(__pyx_t_1);
  5009. __Pyx_XDECREF(__pyx_t_2);
  5010. __Pyx_XDECREF(__pyx_t_3);
  5011. __Pyx_XDECREF(__pyx_t_4);
  5012. __Pyx_AddTraceback("gevent._semaphore.BoundedSemaphore.release", __pyx_clineno, __pyx_lineno, __pyx_filename);
  5013. __pyx_r = -1000;
  5014. __pyx_L0:;
  5015. __Pyx_RefNannyFinishContext();
  5016. return __pyx_r;
  5017. }
  5018. /* Python wrapper */
  5019. static PyObject *__pyx_pw_6gevent_10_semaphore_16BoundedSemaphore_3release(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
  5020. static PyMethodDef __pyx_mdef_6gevent_10_semaphore_16BoundedSemaphore_3release = {"release", (PyCFunction)__pyx_pw_6gevent_10_semaphore_16BoundedSemaphore_3release, METH_NOARGS, 0};
  5021. static PyObject *__pyx_pw_6gevent_10_semaphore_16BoundedSemaphore_3release(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  5022. PyObject *__pyx_r = 0;
  5023. __Pyx_RefNannyDeclarations
  5024. __Pyx_RefNannySetupContext("release (wrapper)", 0);
  5025. __pyx_r = __pyx_pf_6gevent_10_semaphore_16BoundedSemaphore_2release(((struct __pyx_obj_6gevent_10_semaphore_BoundedSemaphore *)__pyx_v_self));
  5026. /* function exit code */
  5027. __Pyx_RefNannyFinishContext();
  5028. return __pyx_r;
  5029. }
  5030. static PyObject *__pyx_pf_6gevent_10_semaphore_16BoundedSemaphore_2release(struct __pyx_obj_6gevent_10_semaphore_BoundedSemaphore *__pyx_v_self) {
  5031. PyObject *__pyx_r = NULL;
  5032. __Pyx_RefNannyDeclarations
  5033. int __pyx_t_1;
  5034. PyObject *__pyx_t_2 = NULL;
  5035. __Pyx_RefNannySetupContext("release", 0);
  5036. __Pyx_XDECREF(__pyx_r);
  5037. __pyx_t_1 = __pyx_f_6gevent_10_semaphore_16BoundedSemaphore_release(__pyx_v_self, 1); if (unlikely(__pyx_t_1 == -1000)) __PYX_ERR(0, 266, __pyx_L1_error)
  5038. __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 266, __pyx_L1_error)
  5039. __Pyx_GOTREF(__pyx_t_2);
  5040. __pyx_r = __pyx_t_2;
  5041. __pyx_t_2 = 0;
  5042. goto __pyx_L0;
  5043. /* function exit code */
  5044. __pyx_L1_error:;
  5045. __Pyx_XDECREF(__pyx_t_2);
  5046. __Pyx_AddTraceback("gevent._semaphore.BoundedSemaphore.release", __pyx_clineno, __pyx_lineno, __pyx_filename);
  5047. __pyx_r = NULL;
  5048. __pyx_L0:;
  5049. __Pyx_XGIVEREF(__pyx_r);
  5050. __Pyx_RefNannyFinishContext();
  5051. return __pyx_r;
  5052. }
  5053. /* "gevent/_semaphore.pxd":21
  5054. *
  5055. * cdef class BoundedSemaphore(Semaphore):
  5056. * cdef readonly int _initial_value # <<<<<<<<<<<<<<
  5057. *
  5058. * cpdef int release(self) except -1000
  5059. */
  5060. /* Python wrapper */
  5061. static PyObject *__pyx_pw_6gevent_10_semaphore_16BoundedSemaphore_14_initial_value_1__get__(PyObject *__pyx_v_self); /*proto*/
  5062. static PyObject *__pyx_pw_6gevent_10_semaphore_16BoundedSemaphore_14_initial_value_1__get__(PyObject *__pyx_v_self) {
  5063. PyObject *__pyx_r = 0;
  5064. __Pyx_RefNannyDeclarations
  5065. __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  5066. __pyx_r = __pyx_pf_6gevent_10_semaphore_16BoundedSemaphore_14_initial_value___get__(((struct __pyx_obj_6gevent_10_semaphore_BoundedSemaphore *)__pyx_v_self));
  5067. /* function exit code */
  5068. __Pyx_RefNannyFinishContext();
  5069. return __pyx_r;
  5070. }
  5071. static PyObject *__pyx_pf_6gevent_10_semaphore_16BoundedSemaphore_14_initial_value___get__(struct __pyx_obj_6gevent_10_semaphore_BoundedSemaphore *__pyx_v_self) {
  5072. PyObject *__pyx_r = NULL;
  5073. __Pyx_RefNannyDeclarations
  5074. PyObject *__pyx_t_1 = NULL;
  5075. __Pyx_RefNannySetupContext("__get__", 0);
  5076. __Pyx_XDECREF(__pyx_r);
  5077. __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_initial_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 21, __pyx_L1_error)
  5078. __Pyx_GOTREF(__pyx_t_1);
  5079. __pyx_r = __pyx_t_1;
  5080. __pyx_t_1 = 0;
  5081. goto __pyx_L0;
  5082. /* function exit code */
  5083. __pyx_L1_error:;
  5084. __Pyx_XDECREF(__pyx_t_1);
  5085. __Pyx_AddTraceback("gevent._semaphore.BoundedSemaphore._initial_value.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  5086. __pyx_r = NULL;
  5087. __pyx_L0:;
  5088. __Pyx_XGIVEREF(__pyx_r);
  5089. __Pyx_RefNannyFinishContext();
  5090. return __pyx_r;
  5091. }
  5092. static struct __pyx_vtabstruct_6gevent_10_semaphore_Semaphore __pyx_vtable_6gevent_10_semaphore_Semaphore;
  5093. static PyObject *__pyx_tp_new_6gevent_10_semaphore_Semaphore(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  5094. struct __pyx_obj_6gevent_10_semaphore_Semaphore *p;
  5095. PyObject *o;
  5096. if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
  5097. o = (*t->tp_alloc)(t, 0);
  5098. } else {
  5099. o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  5100. }
  5101. if (unlikely(!o)) return 0;
  5102. p = ((struct __pyx_obj_6gevent_10_semaphore_Semaphore *)o);
  5103. p->__pyx_vtab = __pyx_vtabptr_6gevent_10_semaphore_Semaphore;
  5104. p->_links = Py_None; Py_INCREF(Py_None);
  5105. p->_notifier = Py_None; Py_INCREF(Py_None);
  5106. return o;
  5107. }
  5108. static void __pyx_tp_dealloc_6gevent_10_semaphore_Semaphore(PyObject *o) {
  5109. struct __pyx_obj_6gevent_10_semaphore_Semaphore *p = (struct __pyx_obj_6gevent_10_semaphore_Semaphore *)o;
  5110. #if PY_VERSION_HEX >= 0x030400a1
  5111. if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
  5112. if (PyObject_CallFinalizerFromDealloc(o)) return;
  5113. }
  5114. #endif
  5115. PyObject_GC_UnTrack(o);
  5116. if (p->__weakref__) PyObject_ClearWeakRefs(o);
  5117. Py_CLEAR(p->_links);
  5118. Py_CLEAR(p->_notifier);
  5119. (*Py_TYPE(o)->tp_free)(o);
  5120. }
  5121. static int __pyx_tp_traverse_6gevent_10_semaphore_Semaphore(PyObject *o, visitproc v, void *a) {
  5122. int e;
  5123. struct __pyx_obj_6gevent_10_semaphore_Semaphore *p = (struct __pyx_obj_6gevent_10_semaphore_Semaphore *)o;
  5124. if (p->_links) {
  5125. e = (*v)(p->_links, a); if (e) return e;
  5126. }
  5127. if (p->_notifier) {
  5128. e = (*v)(p->_notifier, a); if (e) return e;
  5129. }
  5130. return 0;
  5131. }
  5132. static int __pyx_tp_clear_6gevent_10_semaphore_Semaphore(PyObject *o) {
  5133. PyObject* tmp;
  5134. struct __pyx_obj_6gevent_10_semaphore_Semaphore *p = (struct __pyx_obj_6gevent_10_semaphore_Semaphore *)o;
  5135. tmp = ((PyObject*)p->_links);
  5136. p->_links = Py_None; Py_INCREF(Py_None);
  5137. Py_XDECREF(tmp);
  5138. tmp = ((PyObject*)p->_notifier);
  5139. p->_notifier = Py_None; Py_INCREF(Py_None);
  5140. Py_XDECREF(tmp);
  5141. return 0;
  5142. }
  5143. static PyObject *__pyx_getprop_6gevent_10_semaphore_9Semaphore_counter(PyObject *o, CYTHON_UNUSED void *x) {
  5144. return __pyx_pw_6gevent_10_semaphore_9Semaphore_7counter_1__get__(o);
  5145. }
  5146. static int __pyx_setprop_6gevent_10_semaphore_9Semaphore_counter(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  5147. if (v) {
  5148. return __pyx_pw_6gevent_10_semaphore_9Semaphore_7counter_3__set__(o, v);
  5149. }
  5150. else {
  5151. PyErr_SetString(PyExc_NotImplementedError, "__del__");
  5152. return -1;
  5153. }
  5154. }
  5155. static PyObject *__pyx_getprop_6gevent_10_semaphore_9Semaphore__links(PyObject *o, CYTHON_UNUSED void *x) {
  5156. return __pyx_pw_6gevent_10_semaphore_9Semaphore_6_links_1__get__(o);
  5157. }
  5158. static PyObject *__pyx_getprop_6gevent_10_semaphore_9Semaphore__notifier(PyObject *o, CYTHON_UNUSED void *x) {
  5159. return __pyx_pw_6gevent_10_semaphore_9Semaphore_9_notifier_1__get__(o);
  5160. }
  5161. static PyObject *__pyx_getprop_6gevent_10_semaphore_9Semaphore__dirty(PyObject *o, CYTHON_UNUSED void *x) {
  5162. return __pyx_pw_6gevent_10_semaphore_9Semaphore_6_dirty_1__get__(o);
  5163. }
  5164. static int __pyx_setprop_6gevent_10_semaphore_9Semaphore__dirty(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  5165. if (v) {
  5166. return __pyx_pw_6gevent_10_semaphore_9Semaphore_6_dirty_3__set__(o, v);
  5167. }
  5168. else {
  5169. PyErr_SetString(PyExc_NotImplementedError, "__del__");
  5170. return -1;
  5171. }
  5172. }
  5173. static PyMethodDef __pyx_methods_6gevent_10_semaphore_Semaphore[] = {
  5174. {0, 0, 0, 0}
  5175. };
  5176. static struct PyGetSetDef __pyx_getsets_6gevent_10_semaphore_Semaphore[] = {
  5177. {(char *)"counter", __pyx_getprop_6gevent_10_semaphore_9Semaphore_counter, __pyx_setprop_6gevent_10_semaphore_9Semaphore_counter, (char *)0, 0},
  5178. {(char *)"_links", __pyx_getprop_6gevent_10_semaphore_9Semaphore__links, 0, (char *)0, 0},
  5179. {(char *)"_notifier", __pyx_getprop_6gevent_10_semaphore_9Semaphore__notifier, 0, (char *)0, 0},
  5180. {(char *)"_dirty", __pyx_getprop_6gevent_10_semaphore_9Semaphore__dirty, __pyx_setprop_6gevent_10_semaphore_9Semaphore__dirty, (char *)0, 0},
  5181. {0, 0, 0, 0, 0}
  5182. };
  5183. static PyTypeObject __pyx_type_6gevent_10_semaphore_Semaphore = {
  5184. PyVarObject_HEAD_INIT(0, 0)
  5185. "gevent._semaphore.Semaphore", /*tp_name*/
  5186. sizeof(struct __pyx_obj_6gevent_10_semaphore_Semaphore), /*tp_basicsize*/
  5187. 0, /*tp_itemsize*/
  5188. __pyx_tp_dealloc_6gevent_10_semaphore_Semaphore, /*tp_dealloc*/
  5189. 0, /*tp_print*/
  5190. 0, /*tp_getattr*/
  5191. 0, /*tp_setattr*/
  5192. #if PY_MAJOR_VERSION < 3
  5193. 0, /*tp_compare*/
  5194. #endif
  5195. #if PY_MAJOR_VERSION >= 3
  5196. 0, /*tp_as_async*/
  5197. #endif
  5198. 0, /*tp_repr*/
  5199. 0, /*tp_as_number*/
  5200. 0, /*tp_as_sequence*/
  5201. 0, /*tp_as_mapping*/
  5202. 0, /*tp_hash*/
  5203. 0, /*tp_call*/
  5204. __pyx_pw_6gevent_10_semaphore_9Semaphore_3__str__, /*tp_str*/
  5205. 0, /*tp_getattro*/
  5206. 0, /*tp_setattro*/
  5207. 0, /*tp_as_buffer*/
  5208. Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  5209. "\n Semaphore(value=1) -> Semaphore\n\n A semaphore manages a counter representing the number of release()\n calls minus the number of acquire() calls, plus an initial value.\n The acquire() method blocks if necessary until it can return\n without making the counter negative.\n\n If not given, ``value`` defaults to 1.\n\n The semaphore is a context manager and can be used in ``with`` statements.\n\n This Semaphore's ``__exit__`` method does not call the trace function\n on CPython, but does under PyPy.\n\n .. seealso:: :class:`BoundedSemaphore` for a safer version that prevents\n some classes of bugs.\n ", /*tp_doc*/
  5210. __pyx_tp_traverse_6gevent_10_semaphore_Semaphore, /*tp_traverse*/
  5211. __pyx_tp_clear_6gevent_10_semaphore_Semaphore, /*tp_clear*/
  5212. 0, /*tp_richcompare*/
  5213. 0, /*tp_weaklistoffset*/
  5214. 0, /*tp_iter*/
  5215. 0, /*tp_iternext*/
  5216. __pyx_methods_6gevent_10_semaphore_Semaphore, /*tp_methods*/
  5217. 0, /*tp_members*/
  5218. __pyx_getsets_6gevent_10_semaphore_Semaphore, /*tp_getset*/
  5219. 0, /*tp_base*/
  5220. 0, /*tp_dict*/
  5221. 0, /*tp_descr_get*/
  5222. 0, /*tp_descr_set*/
  5223. 0, /*tp_dictoffset*/
  5224. __pyx_pw_6gevent_10_semaphore_9Semaphore_1__init__, /*tp_init*/
  5225. 0, /*tp_alloc*/
  5226. __pyx_tp_new_6gevent_10_semaphore_Semaphore, /*tp_new*/
  5227. 0, /*tp_free*/
  5228. 0, /*tp_is_gc*/
  5229. 0, /*tp_bases*/
  5230. 0, /*tp_mro*/
  5231. 0, /*tp_cache*/
  5232. 0, /*tp_subclasses*/
  5233. 0, /*tp_weaklist*/
  5234. 0, /*tp_del*/
  5235. 0, /*tp_version_tag*/
  5236. #if PY_VERSION_HEX >= 0x030400a1
  5237. 0, /*tp_finalize*/
  5238. #endif
  5239. };
  5240. static struct __pyx_vtabstruct_6gevent_10_semaphore_BoundedSemaphore __pyx_vtable_6gevent_10_semaphore_BoundedSemaphore;
  5241. static PyObject *__pyx_tp_new_6gevent_10_semaphore_BoundedSemaphore(PyTypeObject *t, PyObject *a, PyObject *k) {
  5242. struct __pyx_obj_6gevent_10_semaphore_BoundedSemaphore *p;
  5243. PyObject *o = __pyx_tp_new_6gevent_10_semaphore_Semaphore(t, a, k);
  5244. if (unlikely(!o)) return 0;
  5245. p = ((struct __pyx_obj_6gevent_10_semaphore_BoundedSemaphore *)o);
  5246. p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_6gevent_10_semaphore_Semaphore*)__pyx_vtabptr_6gevent_10_semaphore_BoundedSemaphore;
  5247. return o;
  5248. }
  5249. static PyObject *__pyx_getprop_6gevent_10_semaphore_16BoundedSemaphore__initial_value(PyObject *o, CYTHON_UNUSED void *x) {
  5250. return __pyx_pw_6gevent_10_semaphore_16BoundedSemaphore_14_initial_value_1__get__(o);
  5251. }
  5252. static PyMethodDef __pyx_methods_6gevent_10_semaphore_BoundedSemaphore[] = {
  5253. {0, 0, 0, 0}
  5254. };
  5255. static struct PyGetSetDef __pyx_getsets_6gevent_10_semaphore_BoundedSemaphore[] = {
  5256. {(char *)"_initial_value", __pyx_getprop_6gevent_10_semaphore_16BoundedSemaphore__initial_value, 0, (char *)0, 0},
  5257. {0, 0, 0, 0, 0}
  5258. };
  5259. static PyTypeObject __pyx_type_6gevent_10_semaphore_BoundedSemaphore = {
  5260. PyVarObject_HEAD_INIT(0, 0)
  5261. "gevent._semaphore.BoundedSemaphore", /*tp_name*/
  5262. sizeof(struct __pyx_obj_6gevent_10_semaphore_BoundedSemaphore), /*tp_basicsize*/
  5263. 0, /*tp_itemsize*/
  5264. __pyx_tp_dealloc_6gevent_10_semaphore_Semaphore, /*tp_dealloc*/
  5265. 0, /*tp_print*/
  5266. 0, /*tp_getattr*/
  5267. 0, /*tp_setattr*/
  5268. #if PY_MAJOR_VERSION < 3
  5269. 0, /*tp_compare*/
  5270. #endif
  5271. #if PY_MAJOR_VERSION >= 3
  5272. 0, /*tp_as_async*/
  5273. #endif
  5274. 0, /*tp_repr*/
  5275. 0, /*tp_as_number*/
  5276. 0, /*tp_as_sequence*/
  5277. 0, /*tp_as_mapping*/
  5278. 0, /*tp_hash*/
  5279. 0, /*tp_call*/
  5280. #if CYTHON_COMPILING_IN_PYPY
  5281. __pyx_pw_6gevent_10_semaphore_9Semaphore_3__str__, /*tp_str*/
  5282. #else
  5283. 0, /*tp_str*/
  5284. #endif
  5285. 0, /*tp_getattro*/
  5286. 0, /*tp_setattro*/
  5287. 0, /*tp_as_buffer*/
  5288. Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  5289. "\n BoundedSemaphore(value=1) -> BoundedSemaphore\n\n A bounded semaphore checks to make sure its current value doesn't\n exceed its initial value. If it does, :class:`ValueError` is\n raised. In most situations semaphores are used to guard resources\n with limited capacity. If the semaphore is released too many times\n it's a sign of a bug.\n\n If not given, *value* defaults to 1.\n ", /*tp_doc*/
  5290. __pyx_tp_traverse_6gevent_10_semaphore_Semaphore, /*tp_traverse*/
  5291. __pyx_tp_clear_6gevent_10_semaphore_Semaphore, /*tp_clear*/
  5292. 0, /*tp_richcompare*/
  5293. 0, /*tp_weaklistoffset*/
  5294. 0, /*tp_iter*/
  5295. 0, /*tp_iternext*/
  5296. __pyx_methods_6gevent_10_semaphore_BoundedSemaphore, /*tp_methods*/
  5297. 0, /*tp_members*/
  5298. __pyx_getsets_6gevent_10_semaphore_BoundedSemaphore, /*tp_getset*/
  5299. 0, /*tp_base*/
  5300. 0, /*tp_dict*/
  5301. 0, /*tp_descr_get*/
  5302. 0, /*tp_descr_set*/
  5303. 0, /*tp_dictoffset*/
  5304. __pyx_pw_6gevent_10_semaphore_16BoundedSemaphore_1__init__, /*tp_init*/
  5305. 0, /*tp_alloc*/
  5306. __pyx_tp_new_6gevent_10_semaphore_BoundedSemaphore, /*tp_new*/
  5307. 0, /*tp_free*/
  5308. 0, /*tp_is_gc*/
  5309. 0, /*tp_bases*/
  5310. 0, /*tp_mro*/
  5311. 0, /*tp_cache*/
  5312. 0, /*tp_subclasses*/
  5313. 0, /*tp_weaklist*/
  5314. 0, /*tp_del*/
  5315. 0, /*tp_version_tag*/
  5316. #if PY_VERSION_HEX >= 0x030400a1
  5317. 0, /*tp_finalize*/
  5318. #endif
  5319. };
  5320. static PyMethodDef __pyx_methods[] = {
  5321. {0, 0, 0, 0}
  5322. };
  5323. #if PY_MAJOR_VERSION >= 3
  5324. static struct PyModuleDef __pyx_moduledef = {
  5325. #if PY_VERSION_HEX < 0x03020000
  5326. { PyObject_HEAD_INIT(NULL) NULL, 0, NULL },
  5327. #else
  5328. PyModuleDef_HEAD_INIT,
  5329. #endif
  5330. "_semaphore",
  5331. 0, /* m_doc */
  5332. -1, /* m_size */
  5333. __pyx_methods /* m_methods */,
  5334. NULL, /* m_reload */
  5335. NULL, /* m_traverse */
  5336. NULL, /* m_clear */
  5337. NULL /* m_free */
  5338. };
  5339. #endif
  5340. static __Pyx_StringTabEntry __pyx_string_tab[] = {
  5341. {&__pyx_n_s_AttributeError, __pyx_k_AttributeError, sizeof(__pyx_k_AttributeError), 0, 0, 1, 1},
  5342. {&__pyx_n_s_BoundedSemaphore, __pyx_k_BoundedSemaphore, sizeof(__pyx_k_BoundedSemaphore), 0, 0, 1, 1},
  5343. {&__pyx_n_s_BoundedSemaphore_release, __pyx_k_BoundedSemaphore_release, sizeof(__pyx_k_BoundedSemaphore_release), 0, 0, 1, 1},
  5344. {&__pyx_kp_s_C_projects_gevent_src_gevent__se, __pyx_k_C_projects_gevent_src_gevent__se, sizeof(__pyx_k_C_projects_gevent_src_gevent__se), 0, 0, 1, 0},
  5345. {&__pyx_kp_s_Expected_callable, __pyx_k_Expected_callable, sizeof(__pyx_k_Expected_callable), 0, 0, 1, 0},
  5346. {&__pyx_kp_s_Invalid_switch_into_Semaphore_wa, __pyx_k_Invalid_switch_into_Semaphore_wa, sizeof(__pyx_k_Invalid_switch_into_Semaphore_wa), 0, 0, 1, 0},
  5347. {&__pyx_n_s_OVER_RELEASE_ERROR, __pyx_k_OVER_RELEASE_ERROR, sizeof(__pyx_k_OVER_RELEASE_ERROR), 0, 0, 1, 1},
  5348. {&__pyx_n_s_Semaphore, __pyx_k_Semaphore, sizeof(__pyx_k_Semaphore), 0, 0, 1, 1},
  5349. {&__pyx_n_s_Semaphore___enter, __pyx_k_Semaphore___enter, sizeof(__pyx_k_Semaphore___enter), 0, 0, 1, 1},
  5350. {&__pyx_n_s_Semaphore___exit, __pyx_k_Semaphore___exit, sizeof(__pyx_k_Semaphore___exit), 0, 0, 1, 1},
  5351. {&__pyx_n_s_Semaphore__notify_links, __pyx_k_Semaphore__notify_links, sizeof(__pyx_k_Semaphore__notify_links), 0, 0, 1, 1},
  5352. {&__pyx_n_s_Semaphore__start_notify, __pyx_k_Semaphore__start_notify, sizeof(__pyx_k_Semaphore__start_notify), 0, 0, 1, 1},
  5353. {&__pyx_n_s_Semaphore_acquire, __pyx_k_Semaphore_acquire, sizeof(__pyx_k_Semaphore_acquire), 0, 0, 1, 1},
  5354. {&__pyx_n_s_Semaphore_locked, __pyx_k_Semaphore_locked, sizeof(__pyx_k_Semaphore_locked), 0, 0, 1, 1},
  5355. {&__pyx_n_s_Semaphore_rawlink, __pyx_k_Semaphore_rawlink, sizeof(__pyx_k_Semaphore_rawlink), 0, 0, 1, 1},
  5356. {&__pyx_n_s_Semaphore_release, __pyx_k_Semaphore_release, sizeof(__pyx_k_Semaphore_release), 0, 0, 1, 1},
  5357. {&__pyx_kp_s_Semaphore_released_too_many_time, __pyx_k_Semaphore_released_too_many_time, sizeof(__pyx_k_Semaphore_released_too_many_time), 0, 0, 1, 0},
  5358. {&__pyx_n_s_Semaphore_unlink, __pyx_k_Semaphore_unlink, sizeof(__pyx_k_Semaphore_unlink), 0, 0, 1, 1},
  5359. {&__pyx_n_s_Semaphore_wait, __pyx_k_Semaphore_wait, sizeof(__pyx_k_Semaphore_wait), 0, 0, 1, 1},
  5360. {&__pyx_n_s_Timeout, __pyx_k_Timeout, sizeof(__pyx_k_Timeout), 0, 0, 1, 1},
  5361. {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1},
  5362. {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1},
  5363. {&__pyx_n_s_acquire, __pyx_k_acquire, sizeof(__pyx_k_acquire), 0, 0, 1, 1},
  5364. {&__pyx_n_s_all, __pyx_k_all, sizeof(__pyx_k_all), 0, 0, 1, 1},
  5365. {&__pyx_n_s_append, __pyx_k_append, sizeof(__pyx_k_append), 0, 0, 1, 1},
  5366. {&__pyx_n_s_blocking, __pyx_k_blocking, sizeof(__pyx_k_blocking), 0, 0, 1, 1},
  5367. {&__pyx_n_s_callback, __pyx_k_callback, sizeof(__pyx_k_callback), 0, 0, 1, 1},
  5368. {&__pyx_n_s_cancel, __pyx_k_cancel, sizeof(__pyx_k_cancel), 0, 0, 1, 1},
  5369. {&__pyx_n_s_class, __pyx_k_class, sizeof(__pyx_k_class), 0, 0, 1, 1},
  5370. {&__pyx_n_s_enter, __pyx_k_enter, sizeof(__pyx_k_enter), 0, 0, 1, 1},
  5371. {&__pyx_n_s_exc_info, __pyx_k_exc_info, sizeof(__pyx_k_exc_info), 0, 0, 1, 1},
  5372. {&__pyx_n_s_exit, __pyx_k_exit, sizeof(__pyx_k_exit), 0, 0, 1, 1},
  5373. {&__pyx_n_s_get_hub, __pyx_k_get_hub, sizeof(__pyx_k_get_hub), 0, 0, 1, 1},
  5374. {&__pyx_n_s_getcurrent, __pyx_k_getcurrent, sizeof(__pyx_k_getcurrent), 0, 0, 1, 1},
  5375. {&__pyx_n_s_gevent__semaphore, __pyx_k_gevent__semaphore, sizeof(__pyx_k_gevent__semaphore), 0, 0, 1, 1},
  5376. {&__pyx_n_s_gevent_hub, __pyx_k_gevent_hub, sizeof(__pyx_k_gevent_hub), 0, 0, 1, 1},
  5377. {&__pyx_n_s_gevent_timeout, __pyx_k_gevent_timeout, sizeof(__pyx_k_gevent_timeout), 0, 0, 1, 1},
  5378. {&__pyx_n_s_handle_error, __pyx_k_handle_error, sizeof(__pyx_k_handle_error), 0, 0, 1, 1},
  5379. {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
  5380. {&__pyx_n_s_init, __pyx_k_init, sizeof(__pyx_k_init), 0, 0, 1, 1},
  5381. {&__pyx_n_s_locked, __pyx_k_locked, sizeof(__pyx_k_locked), 0, 0, 1, 1},
  5382. {&__pyx_n_s_loop, __pyx_k_loop, sizeof(__pyx_k_loop), 0, 0, 1, 1},
  5383. {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
  5384. {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1},
  5385. {&__pyx_n_s_notify_links, __pyx_k_notify_links, sizeof(__pyx_k_notify_links), 0, 0, 1, 1},
  5386. {&__pyx_n_s_py3k_acquire, __pyx_k_py3k_acquire, sizeof(__pyx_k_py3k_acquire), 0, 0, 1, 1},
  5387. {&__pyx_n_s_pyx_vtable, __pyx_k_pyx_vtable, sizeof(__pyx_k_pyx_vtable), 0, 0, 1, 1},
  5388. {&__pyx_n_s_rawlink, __pyx_k_rawlink, sizeof(__pyx_k_rawlink), 0, 0, 1, 1},
  5389. {&__pyx_n_s_release, __pyx_k_release, sizeof(__pyx_k_release), 0, 0, 1, 1},
  5390. {&__pyx_n_s_remove, __pyx_k_remove, sizeof(__pyx_k_remove), 0, 0, 1, 1},
  5391. {&__pyx_n_s_run_callback, __pyx_k_run_callback, sizeof(__pyx_k_run_callback), 0, 0, 1, 1},
  5392. {&__pyx_kp_s_s_counter_s__links_s, __pyx_k_s_counter_s__links_s, sizeof(__pyx_k_s_counter_s__links_s), 0, 0, 1, 0},
  5393. {&__pyx_n_s_self, __pyx_k_self, sizeof(__pyx_k_self), 0, 0, 1, 1},
  5394. {&__pyx_kp_s_semaphore_initial_value_must_be, __pyx_k_semaphore_initial_value_must_be, sizeof(__pyx_k_semaphore_initial_value_must_be), 0, 0, 1, 0},
  5395. {&__pyx_n_s_start_new_or_dummy, __pyx_k_start_new_or_dummy, sizeof(__pyx_k_start_new_or_dummy), 0, 0, 1, 1},
  5396. {&__pyx_n_s_start_notify, __pyx_k_start_notify, sizeof(__pyx_k_start_notify), 0, 0, 1, 1},
  5397. {&__pyx_n_s_switch, __pyx_k_switch, sizeof(__pyx_k_switch), 0, 0, 1, 1},
  5398. {&__pyx_n_s_sys, __pyx_k_sys, sizeof(__pyx_k_sys), 0, 0, 1, 1},
  5399. {&__pyx_n_s_t, __pyx_k_t, sizeof(__pyx_k_t), 0, 0, 1, 1},
  5400. {&__pyx_n_s_tb, __pyx_k_tb, sizeof(__pyx_k_tb), 0, 0, 1, 1},
  5401. {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
  5402. {&__pyx_n_s_timeout, __pyx_k_timeout, sizeof(__pyx_k_timeout), 0, 0, 1, 1},
  5403. {&__pyx_n_s_unlink, __pyx_k_unlink, sizeof(__pyx_k_unlink), 0, 0, 1, 1},
  5404. {&__pyx_n_s_v, __pyx_k_v, sizeof(__pyx_k_v), 0, 0, 1, 1},
  5405. {&__pyx_n_s_value, __pyx_k_value, sizeof(__pyx_k_value), 0, 0, 1, 1},
  5406. {&__pyx_n_s_wait, __pyx_k_wait, sizeof(__pyx_k_wait), 0, 0, 1, 1},
  5407. {0, 0, 0, 0, 0, 0, 0}
  5408. };
  5409. static int __Pyx_InitCachedBuiltins(void) {
  5410. __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 260, __pyx_L1_error)
  5411. __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(0, 129, __pyx_L1_error)
  5412. __pyx_builtin_AttributeError = __Pyx_GetBuiltinName(__pyx_n_s_AttributeError); if (!__pyx_builtin_AttributeError) __PYX_ERR(0, 148, __pyx_L1_error)
  5413. return 0;
  5414. __pyx_L1_error:;
  5415. return -1;
  5416. }
  5417. static int __Pyx_InitCachedConstants(void) {
  5418. __Pyx_RefNannyDeclarations
  5419. __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);
  5420. /* "gevent/_semaphore.py":31
  5421. * def __init__(self, value=1):
  5422. * if value < 0:
  5423. * raise ValueError("semaphore initial value must be >= 0") # <<<<<<<<<<<<<<
  5424. * self.counter = value
  5425. * self._dirty = False
  5426. */
  5427. __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_s_semaphore_initial_value_must_be); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 31, __pyx_L1_error)
  5428. __Pyx_GOTREF(__pyx_tuple_);
  5429. __Pyx_GIVEREF(__pyx_tuple_);
  5430. /* "gevent/_semaphore.py":268
  5431. * def release(self):
  5432. * if self.counter >= self._initial_value:
  5433. * raise self._OVER_RELEASE_ERROR("Semaphore released too many times") # <<<<<<<<<<<<<<
  5434. * return Semaphore.release(self)
  5435. */
  5436. __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_s_Semaphore_released_too_many_time); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 268, __pyx_L1_error)
  5437. __Pyx_GOTREF(__pyx_tuple__2);
  5438. __Pyx_GIVEREF(__pyx_tuple__2);
  5439. /* "gevent/_semaphore.py":56
  5440. * return '<%s counter=%s _links[%s]>' % params
  5441. *
  5442. * def locked(self): # <<<<<<<<<<<<<<
  5443. * """Return a boolean indicating whether the semaphore can be acquired.
  5444. * Most useful with binary semaphores."""
  5445. */
  5446. __pyx_tuple__3 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 56, __pyx_L1_error)
  5447. __Pyx_GOTREF(__pyx_tuple__3);
  5448. __Pyx_GIVEREF(__pyx_tuple__3);
  5449. __pyx_codeobj__4 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__3, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_C_projects_gevent_src_gevent__se, __pyx_n_s_locked, 56, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__4)) __PYX_ERR(0, 56, __pyx_L1_error)
  5450. /* "gevent/_semaphore.py":61
  5451. * return self.counter <= 0
  5452. *
  5453. * def release(self): # <<<<<<<<<<<<<<
  5454. * """
  5455. * Release the semaphore, notifying any waiters if needed.
  5456. */
  5457. __pyx_tuple__5 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 61, __pyx_L1_error)
  5458. __Pyx_GOTREF(__pyx_tuple__5);
  5459. __Pyx_GIVEREF(__pyx_tuple__5);
  5460. __pyx_codeobj__6 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__5, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_C_projects_gevent_src_gevent__se, __pyx_n_s_release, 61, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__6)) __PYX_ERR(0, 61, __pyx_L1_error)
  5461. /* "gevent/_semaphore.py":69
  5462. * return self.counter
  5463. *
  5464. * def _start_notify(self): # <<<<<<<<<<<<<<
  5465. * if self._links and self.counter > 0 and not self._notifier:
  5466. * # We create a new self._notifier each time through the loop,
  5467. */
  5468. __pyx_tuple__7 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 69, __pyx_L1_error)
  5469. __Pyx_GOTREF(__pyx_tuple__7);
  5470. __Pyx_GIVEREF(__pyx_tuple__7);
  5471. __pyx_codeobj__8 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__7, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_C_projects_gevent_src_gevent__se, __pyx_n_s_start_notify, 69, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__8)) __PYX_ERR(0, 69, __pyx_L1_error)
  5472. /* "gevent/_semaphore.py":80
  5473. * self._notifier = get_hub().loop.run_callback(self._notify_links)
  5474. *
  5475. * def _notify_links(self): # <<<<<<<<<<<<<<
  5476. * # Subclasses CANNOT override. This is a cdef method.
  5477. *
  5478. */
  5479. __pyx_tuple__9 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(0, 80, __pyx_L1_error)
  5480. __Pyx_GOTREF(__pyx_tuple__9);
  5481. __Pyx_GIVEREF(__pyx_tuple__9);
  5482. __pyx_codeobj__10 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__9, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_C_projects_gevent_src_gevent__se, __pyx_n_s_notify_links, 80, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__10)) __PYX_ERR(0, 80, __pyx_L1_error)
  5483. /* "gevent/_semaphore.py":116
  5484. * self._notifier = None
  5485. *
  5486. * def rawlink(self, callback): # <<<<<<<<<<<<<<
  5487. * """
  5488. * rawlink(callback) -> None
  5489. */
  5490. __pyx_tuple__11 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_callback); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(0, 116, __pyx_L1_error)
  5491. __Pyx_GOTREF(__pyx_tuple__11);
  5492. __Pyx_GIVEREF(__pyx_tuple__11);
  5493. __pyx_codeobj__12 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__11, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_C_projects_gevent_src_gevent__se, __pyx_n_s_rawlink, 116, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__12)) __PYX_ERR(0, 116, __pyx_L1_error)
  5494. /* "gevent/_semaphore.py":136
  5495. * self._dirty = True
  5496. *
  5497. * def unlink(self, callback): # <<<<<<<<<<<<<<
  5498. * """
  5499. * unlink(callback) -> None
  5500. */
  5501. __pyx_tuple__13 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_callback); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(0, 136, __pyx_L1_error)
  5502. __Pyx_GOTREF(__pyx_tuple__13);
  5503. __Pyx_GIVEREF(__pyx_tuple__13);
  5504. __pyx_codeobj__14 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__13, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_C_projects_gevent_src_gevent__se, __pyx_n_s_unlink, 136, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__14)) __PYX_ERR(0, 136, __pyx_L1_error)
  5505. /* "gevent/_semaphore.py":177
  5506. * self.unlink(switch)
  5507. *
  5508. * def wait(self, timeout=None): # <<<<<<<<<<<<<<
  5509. * """
  5510. * wait(timeout=None) -> int
  5511. */
  5512. __pyx_tuple__15 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_timeout); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(0, 177, __pyx_L1_error)
  5513. __Pyx_GOTREF(__pyx_tuple__15);
  5514. __Pyx_GIVEREF(__pyx_tuple__15);
  5515. __pyx_codeobj__16 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__15, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_C_projects_gevent_src_gevent__se, __pyx_n_s_wait, 177, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__16)) __PYX_ERR(0, 177, __pyx_L1_error)
  5516. /* "gevent/_semaphore.py":198
  5517. * return self.counter
  5518. *
  5519. * def acquire(self, blocking=True, timeout=None): # <<<<<<<<<<<<<<
  5520. * """
  5521. * acquire(blocking=True, timeout=None) -> bool
  5522. */
  5523. __pyx_tuple__17 = PyTuple_Pack(3, __pyx_n_s_self, __pyx_n_s_blocking, __pyx_n_s_timeout); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(0, 198, __pyx_L1_error)
  5524. __Pyx_GOTREF(__pyx_tuple__17);
  5525. __Pyx_GIVEREF(__pyx_tuple__17);
  5526. __pyx_codeobj__18 = (PyObject*)__Pyx_PyCode_New(3, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__17, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_C_projects_gevent_src_gevent__se, __pyx_n_s_acquire, 198, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__18)) __PYX_ERR(0, 198, __pyx_L1_error)
  5527. /* "gevent/_semaphore.py":239
  5528. * _py3k_acquire = acquire # PyPy needs this; it must be static for Cython
  5529. *
  5530. * def __enter__(self): # <<<<<<<<<<<<<<
  5531. * self.acquire()
  5532. *
  5533. */
  5534. __pyx_tuple__19 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(0, 239, __pyx_L1_error)
  5535. __Pyx_GOTREF(__pyx_tuple__19);
  5536. __Pyx_GIVEREF(__pyx_tuple__19);
  5537. __pyx_codeobj__20 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__19, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_C_projects_gevent_src_gevent__se, __pyx_n_s_enter, 239, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__20)) __PYX_ERR(0, 239, __pyx_L1_error)
  5538. /* "gevent/_semaphore.py":242
  5539. * self.acquire()
  5540. *
  5541. * def __exit__(self, t, v, tb): # <<<<<<<<<<<<<<
  5542. * self.release()
  5543. *
  5544. */
  5545. __pyx_tuple__21 = PyTuple_Pack(4, __pyx_n_s_self, __pyx_n_s_t, __pyx_n_s_v, __pyx_n_s_tb); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(0, 242, __pyx_L1_error)
  5546. __Pyx_GOTREF(__pyx_tuple__21);
  5547. __Pyx_GIVEREF(__pyx_tuple__21);
  5548. __pyx_codeobj__22 = (PyObject*)__Pyx_PyCode_New(4, 0, 4, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__21, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_C_projects_gevent_src_gevent__se, __pyx_n_s_exit, 242, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__22)) __PYX_ERR(0, 242, __pyx_L1_error)
  5549. /* "gevent/_semaphore.py":266
  5550. * self._initial_value = self.counter
  5551. *
  5552. * def release(self): # <<<<<<<<<<<<<<
  5553. * if self.counter >= self._initial_value:
  5554. * raise self._OVER_RELEASE_ERROR("Semaphore released too many times")
  5555. */
  5556. __pyx_tuple__23 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(0, 266, __pyx_L1_error)
  5557. __Pyx_GOTREF(__pyx_tuple__23);
  5558. __Pyx_GIVEREF(__pyx_tuple__23);
  5559. __pyx_codeobj__24 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__23, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_C_projects_gevent_src_gevent__se, __pyx_n_s_release, 266, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__24)) __PYX_ERR(0, 266, __pyx_L1_error)
  5560. __Pyx_RefNannyFinishContext();
  5561. return 0;
  5562. __pyx_L1_error:;
  5563. __Pyx_RefNannyFinishContext();
  5564. return -1;
  5565. }
  5566. static int __Pyx_InitGlobals(void) {
  5567. if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
  5568. __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error)
  5569. __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  5570. return 0;
  5571. __pyx_L1_error:;
  5572. return -1;
  5573. }
  5574. #if PY_MAJOR_VERSION < 3
  5575. PyMODINIT_FUNC init_semaphore(void); /*proto*/
  5576. PyMODINIT_FUNC init_semaphore(void)
  5577. #else
  5578. PyMODINIT_FUNC PyInit__semaphore(void); /*proto*/
  5579. PyMODINIT_FUNC PyInit__semaphore(void)
  5580. #endif
  5581. {
  5582. PyObject *__pyx_t_1 = NULL;
  5583. PyObject *__pyx_t_2 = NULL;
  5584. __Pyx_RefNannyDeclarations
  5585. #if CYTHON_REFNANNY
  5586. __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
  5587. if (!__Pyx_RefNanny) {
  5588. PyErr_Clear();
  5589. __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
  5590. if (!__Pyx_RefNanny)
  5591. Py_FatalError("failed to import 'refnanny' module");
  5592. }
  5593. #endif
  5594. __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit__semaphore(void)", 0);
  5595. if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  5596. __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error)
  5597. __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error)
  5598. __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error)
  5599. #ifdef __Pyx_CyFunction_USED
  5600. if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  5601. #endif
  5602. #ifdef __Pyx_FusedFunction_USED
  5603. if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  5604. #endif
  5605. #ifdef __Pyx_Coroutine_USED
  5606. if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  5607. #endif
  5608. #ifdef __Pyx_Generator_USED
  5609. if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  5610. #endif
  5611. #ifdef __Pyx_StopAsyncIteration_USED
  5612. if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  5613. #endif
  5614. /*--- Library function declarations ---*/
  5615. /*--- Threads initialization code ---*/
  5616. #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  5617. #ifdef WITH_THREAD /* Python build with threading support? */
  5618. PyEval_InitThreads();
  5619. #endif
  5620. #endif
  5621. /*--- Module creation code ---*/
  5622. #if PY_MAJOR_VERSION < 3
  5623. __pyx_m = Py_InitModule4("_semaphore", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
  5624. #else
  5625. __pyx_m = PyModule_Create(&__pyx_moduledef);
  5626. #endif
  5627. if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error)
  5628. __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error)
  5629. Py_INCREF(__pyx_d);
  5630. __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error)
  5631. #if CYTHON_COMPILING_IN_PYPY
  5632. Py_INCREF(__pyx_b);
  5633. #endif
  5634. if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
  5635. /*--- Initialize various global constants etc. ---*/
  5636. if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  5637. #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
  5638. if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  5639. #endif
  5640. if (__pyx_module_is_main_gevent___semaphore) {
  5641. if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  5642. }
  5643. #if PY_MAJOR_VERSION >= 3
  5644. {
  5645. PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error)
  5646. if (!PyDict_GetItemString(modules, "gevent._semaphore")) {
  5647. if (unlikely(PyDict_SetItemString(modules, "gevent._semaphore", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
  5648. }
  5649. }
  5650. #endif
  5651. /*--- Builtin init code ---*/
  5652. if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  5653. /*--- Constants init code ---*/
  5654. if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  5655. /*--- Global init code ---*/
  5656. /*--- Variable export code ---*/
  5657. /*--- Function export code ---*/
  5658. /*--- Type init code ---*/
  5659. __pyx_vtabptr_6gevent_10_semaphore_Semaphore = &__pyx_vtable_6gevent_10_semaphore_Semaphore;
  5660. __pyx_vtable_6gevent_10_semaphore_Semaphore.locked = (int (*)(struct __pyx_obj_6gevent_10_semaphore_Semaphore *, int __pyx_skip_dispatch))__pyx_f_6gevent_10_semaphore_9Semaphore_locked;
  5661. __pyx_vtable_6gevent_10_semaphore_Semaphore.release = (int (*)(struct __pyx_obj_6gevent_10_semaphore_Semaphore *, int __pyx_skip_dispatch))__pyx_f_6gevent_10_semaphore_9Semaphore_release;
  5662. __pyx_vtable_6gevent_10_semaphore_Semaphore.rawlink = (PyObject *(*)(struct __pyx_obj_6gevent_10_semaphore_Semaphore *, PyObject *, int __pyx_skip_dispatch))__pyx_f_6gevent_10_semaphore_9Semaphore_rawlink;
  5663. __pyx_vtable_6gevent_10_semaphore_Semaphore.unlink = (PyObject *(*)(struct __pyx_obj_6gevent_10_semaphore_Semaphore *, PyObject *, int __pyx_skip_dispatch))__pyx_f_6gevent_10_semaphore_9Semaphore_unlink;
  5664. __pyx_vtable_6gevent_10_semaphore_Semaphore._start_notify = (PyObject *(*)(struct __pyx_obj_6gevent_10_semaphore_Semaphore *, int __pyx_skip_dispatch))__pyx_f_6gevent_10_semaphore_9Semaphore__start_notify;
  5665. __pyx_vtable_6gevent_10_semaphore_Semaphore._notify_links = (PyObject *(*)(struct __pyx_obj_6gevent_10_semaphore_Semaphore *, int __pyx_skip_dispatch))__pyx_f_6gevent_10_semaphore_9Semaphore__notify_links;
  5666. __pyx_vtable_6gevent_10_semaphore_Semaphore._do_wait = (PyObject *(*)(struct __pyx_obj_6gevent_10_semaphore_Semaphore *, PyObject *))__pyx_f_6gevent_10_semaphore_9Semaphore__do_wait;
  5667. __pyx_vtable_6gevent_10_semaphore_Semaphore.wait = (int (*)(struct __pyx_obj_6gevent_10_semaphore_Semaphore *, int __pyx_skip_dispatch, struct __pyx_opt_args_6gevent_10_semaphore_9Semaphore_wait *__pyx_optional_args))__pyx_f_6gevent_10_semaphore_9Semaphore_wait;
  5668. __pyx_vtable_6gevent_10_semaphore_Semaphore.acquire = (int (*)(struct __pyx_obj_6gevent_10_semaphore_Semaphore *, int __pyx_skip_dispatch, struct __pyx_opt_args_6gevent_10_semaphore_9Semaphore_acquire *__pyx_optional_args))__pyx_f_6gevent_10_semaphore_9Semaphore_acquire;
  5669. __pyx_vtable_6gevent_10_semaphore_Semaphore.__pyx___enter__ = (PyObject *(*)(struct __pyx_obj_6gevent_10_semaphore_Semaphore *, int __pyx_skip_dispatch))__pyx_f_6gevent_10_semaphore_9Semaphore___enter__;
  5670. __pyx_vtable_6gevent_10_semaphore_Semaphore.__pyx___exit__ = (PyObject *(*)(struct __pyx_obj_6gevent_10_semaphore_Semaphore *, PyObject *, PyObject *, PyObject *, int __pyx_skip_dispatch))__pyx_f_6gevent_10_semaphore_9Semaphore___exit__;
  5671. if (PyType_Ready(&__pyx_type_6gevent_10_semaphore_Semaphore) < 0) __PYX_ERR(0, 9, __pyx_L1_error)
  5672. __pyx_type_6gevent_10_semaphore_Semaphore.tp_print = 0;
  5673. if (__Pyx_SetVtable(__pyx_type_6gevent_10_semaphore_Semaphore.tp_dict, __pyx_vtabptr_6gevent_10_semaphore_Semaphore) < 0) __PYX_ERR(0, 9, __pyx_L1_error)
  5674. if (PyObject_SetAttrString(__pyx_m, "Semaphore", (PyObject *)&__pyx_type_6gevent_10_semaphore_Semaphore) < 0) __PYX_ERR(0, 9, __pyx_L1_error)
  5675. if (__pyx_type_6gevent_10_semaphore_Semaphore.tp_weaklistoffset == 0) __pyx_type_6gevent_10_semaphore_Semaphore.tp_weaklistoffset = offsetof(struct __pyx_obj_6gevent_10_semaphore_Semaphore, __weakref__);
  5676. __pyx_ptype_6gevent_10_semaphore_Semaphore = &__pyx_type_6gevent_10_semaphore_Semaphore;
  5677. __pyx_vtabptr_6gevent_10_semaphore_BoundedSemaphore = &__pyx_vtable_6gevent_10_semaphore_BoundedSemaphore;
  5678. __pyx_vtable_6gevent_10_semaphore_BoundedSemaphore.__pyx_base = *__pyx_vtabptr_6gevent_10_semaphore_Semaphore;
  5679. __pyx_vtable_6gevent_10_semaphore_BoundedSemaphore.__pyx_base.release = (int (*)(struct __pyx_obj_6gevent_10_semaphore_Semaphore *, int __pyx_skip_dispatch))__pyx_f_6gevent_10_semaphore_16BoundedSemaphore_release;
  5680. __pyx_type_6gevent_10_semaphore_BoundedSemaphore.tp_base = __pyx_ptype_6gevent_10_semaphore_Semaphore;
  5681. if (PyType_Ready(&__pyx_type_6gevent_10_semaphore_BoundedSemaphore) < 0) __PYX_ERR(0, 246, __pyx_L1_error)
  5682. __pyx_type_6gevent_10_semaphore_BoundedSemaphore.tp_print = 0;
  5683. if (__Pyx_SetVtable(__pyx_type_6gevent_10_semaphore_BoundedSemaphore.tp_dict, __pyx_vtabptr_6gevent_10_semaphore_BoundedSemaphore) < 0) __PYX_ERR(0, 246, __pyx_L1_error)
  5684. if (PyObject_SetAttrString(__pyx_m, "BoundedSemaphore", (PyObject *)&__pyx_type_6gevent_10_semaphore_BoundedSemaphore) < 0) __PYX_ERR(0, 246, __pyx_L1_error)
  5685. if (__pyx_type_6gevent_10_semaphore_BoundedSemaphore.tp_weaklistoffset == 0) __pyx_type_6gevent_10_semaphore_BoundedSemaphore.tp_weaklistoffset = offsetof(struct __pyx_obj_6gevent_10_semaphore_BoundedSemaphore, __pyx_base.__weakref__);
  5686. __pyx_ptype_6gevent_10_semaphore_BoundedSemaphore = &__pyx_type_6gevent_10_semaphore_BoundedSemaphore;
  5687. /*--- Type import code ---*/
  5688. /*--- Variable import code ---*/
  5689. /*--- Function import code ---*/
  5690. /*--- Execution code ---*/
  5691. #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
  5692. if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  5693. #endif
  5694. /* "gevent/_semaphore.py":1
  5695. * import sys # <<<<<<<<<<<<<<
  5696. * from gevent.hub import get_hub, getcurrent
  5697. * from gevent.timeout import Timeout
  5698. */
  5699. __pyx_t_1 = __Pyx_Import(__pyx_n_s_sys, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  5700. __Pyx_GOTREF(__pyx_t_1);
  5701. if (PyDict_SetItem(__pyx_d, __pyx_n_s_sys, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  5702. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  5703. /* "gevent/_semaphore.py":2
  5704. * import sys
  5705. * from gevent.hub import get_hub, getcurrent # <<<<<<<<<<<<<<
  5706. * from gevent.timeout import Timeout
  5707. *
  5708. */
  5709. __pyx_t_1 = PyList_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2, __pyx_L1_error)
  5710. __Pyx_GOTREF(__pyx_t_1);
  5711. __Pyx_INCREF(__pyx_n_s_get_hub);
  5712. __Pyx_GIVEREF(__pyx_n_s_get_hub);
  5713. PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_get_hub);
  5714. __Pyx_INCREF(__pyx_n_s_getcurrent);
  5715. __Pyx_GIVEREF(__pyx_n_s_getcurrent);
  5716. PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_getcurrent);
  5717. __pyx_t_2 = __Pyx_Import(__pyx_n_s_gevent_hub, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2, __pyx_L1_error)
  5718. __Pyx_GOTREF(__pyx_t_2);
  5719. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  5720. __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_get_hub); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2, __pyx_L1_error)
  5721. __Pyx_GOTREF(__pyx_t_1);
  5722. if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_hub, __pyx_t_1) < 0) __PYX_ERR(0, 2, __pyx_L1_error)
  5723. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  5724. __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_getcurrent); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2, __pyx_L1_error)
  5725. __Pyx_GOTREF(__pyx_t_1);
  5726. if (PyDict_SetItem(__pyx_d, __pyx_n_s_getcurrent, __pyx_t_1) < 0) __PYX_ERR(0, 2, __pyx_L1_error)
  5727. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  5728. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  5729. /* "gevent/_semaphore.py":3
  5730. * import sys
  5731. * from gevent.hub import get_hub, getcurrent
  5732. * from gevent.timeout import Timeout # <<<<<<<<<<<<<<
  5733. *
  5734. *
  5735. */
  5736. __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3, __pyx_L1_error)
  5737. __Pyx_GOTREF(__pyx_t_2);
  5738. __Pyx_INCREF(__pyx_n_s_Timeout);
  5739. __Pyx_GIVEREF(__pyx_n_s_Timeout);
  5740. PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_Timeout);
  5741. __pyx_t_1 = __Pyx_Import(__pyx_n_s_gevent_timeout, __pyx_t_2, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3, __pyx_L1_error)
  5742. __Pyx_GOTREF(__pyx_t_1);
  5743. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  5744. __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_Timeout); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3, __pyx_L1_error)
  5745. __Pyx_GOTREF(__pyx_t_2);
  5746. if (PyDict_SetItem(__pyx_d, __pyx_n_s_Timeout, __pyx_t_2) < 0) __PYX_ERR(0, 3, __pyx_L1_error)
  5747. __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  5748. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  5749. /* "gevent/_semaphore.py":6
  5750. *
  5751. *
  5752. * __all__ = ['Semaphore', 'BoundedSemaphore'] # <<<<<<<<<<<<<<
  5753. *
  5754. *
  5755. */
  5756. __pyx_t_1 = PyList_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6, __pyx_L1_error)
  5757. __Pyx_GOTREF(__pyx_t_1);
  5758. __Pyx_INCREF(__pyx_n_s_Semaphore);
  5759. __Pyx_GIVEREF(__pyx_n_s_Semaphore);
  5760. PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_Semaphore);
  5761. __Pyx_INCREF(__pyx_n_s_BoundedSemaphore);
  5762. __Pyx_GIVEREF(__pyx_n_s_BoundedSemaphore);
  5763. PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_BoundedSemaphore);
  5764. if (PyDict_SetItem(__pyx_d, __pyx_n_s_all, __pyx_t_1) < 0) __PYX_ERR(0, 6, __pyx_L1_error)
  5765. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  5766. /* "gevent/_semaphore.py":56
  5767. * return '<%s counter=%s _links[%s]>' % params
  5768. *
  5769. * def locked(self): # <<<<<<<<<<<<<<
  5770. * """Return a boolean indicating whether the semaphore can be acquired.
  5771. * Most useful with binary semaphores."""
  5772. */
  5773. __pyx_t_1 = __Pyx_CyFunction_NewEx(&__pyx_mdef_6gevent_10_semaphore_9Semaphore_5locked, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Semaphore_locked, NULL, __pyx_n_s_gevent__semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__4)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 56, __pyx_L1_error)
  5774. __Pyx_GOTREF(__pyx_t_1);
  5775. if (PyDict_SetItem((PyObject *)__pyx_ptype_6gevent_10_semaphore_Semaphore->tp_dict, __pyx_n_s_locked, __pyx_t_1) < 0) __PYX_ERR(0, 56, __pyx_L1_error)
  5776. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  5777. PyType_Modified(__pyx_ptype_6gevent_10_semaphore_Semaphore);
  5778. /* "gevent/_semaphore.py":61
  5779. * return self.counter <= 0
  5780. *
  5781. * def release(self): # <<<<<<<<<<<<<<
  5782. * """
  5783. * Release the semaphore, notifying any waiters if needed.
  5784. */
  5785. __pyx_t_1 = __Pyx_CyFunction_NewEx(&__pyx_mdef_6gevent_10_semaphore_9Semaphore_7release, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Semaphore_release, NULL, __pyx_n_s_gevent__semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__6)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 61, __pyx_L1_error)
  5786. __Pyx_GOTREF(__pyx_t_1);
  5787. if (PyDict_SetItem((PyObject *)__pyx_ptype_6gevent_10_semaphore_Semaphore->tp_dict, __pyx_n_s_release, __pyx_t_1) < 0) __PYX_ERR(0, 61, __pyx_L1_error)
  5788. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  5789. PyType_Modified(__pyx_ptype_6gevent_10_semaphore_Semaphore);
  5790. /* "gevent/_semaphore.py":69
  5791. * return self.counter
  5792. *
  5793. * def _start_notify(self): # <<<<<<<<<<<<<<
  5794. * if self._links and self.counter > 0 and not self._notifier:
  5795. * # We create a new self._notifier each time through the loop,
  5796. */
  5797. __pyx_t_1 = __Pyx_CyFunction_NewEx(&__pyx_mdef_6gevent_10_semaphore_9Semaphore_9_start_notify, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Semaphore__start_notify, NULL, __pyx_n_s_gevent__semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__8)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 69, __pyx_L1_error)
  5798. __Pyx_GOTREF(__pyx_t_1);
  5799. if (PyDict_SetItem((PyObject *)__pyx_ptype_6gevent_10_semaphore_Semaphore->tp_dict, __pyx_n_s_start_notify, __pyx_t_1) < 0) __PYX_ERR(0, 69, __pyx_L1_error)
  5800. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  5801. PyType_Modified(__pyx_ptype_6gevent_10_semaphore_Semaphore);
  5802. /* "gevent/_semaphore.py":80
  5803. * self._notifier = get_hub().loop.run_callback(self._notify_links)
  5804. *
  5805. * def _notify_links(self): # <<<<<<<<<<<<<<
  5806. * # Subclasses CANNOT override. This is a cdef method.
  5807. *
  5808. */
  5809. __pyx_t_1 = __Pyx_CyFunction_NewEx(&__pyx_mdef_6gevent_10_semaphore_9Semaphore_11_notify_links, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Semaphore__notify_links, NULL, __pyx_n_s_gevent__semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__10)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 80, __pyx_L1_error)
  5810. __Pyx_GOTREF(__pyx_t_1);
  5811. if (PyDict_SetItem((PyObject *)__pyx_ptype_6gevent_10_semaphore_Semaphore->tp_dict, __pyx_n_s_notify_links, __pyx_t_1) < 0) __PYX_ERR(0, 80, __pyx_L1_error)
  5812. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  5813. PyType_Modified(__pyx_ptype_6gevent_10_semaphore_Semaphore);
  5814. /* "gevent/_semaphore.py":116
  5815. * self._notifier = None
  5816. *
  5817. * def rawlink(self, callback): # <<<<<<<<<<<<<<
  5818. * """
  5819. * rawlink(callback) -> None
  5820. */
  5821. __pyx_t_1 = __Pyx_CyFunction_NewEx(&__pyx_mdef_6gevent_10_semaphore_9Semaphore_13rawlink, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Semaphore_rawlink, NULL, __pyx_n_s_gevent__semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__12)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 116, __pyx_L1_error)
  5822. __Pyx_GOTREF(__pyx_t_1);
  5823. if (PyDict_SetItem((PyObject *)__pyx_ptype_6gevent_10_semaphore_Semaphore->tp_dict, __pyx_n_s_rawlink, __pyx_t_1) < 0) __PYX_ERR(0, 116, __pyx_L1_error)
  5824. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  5825. PyType_Modified(__pyx_ptype_6gevent_10_semaphore_Semaphore);
  5826. /* "gevent/_semaphore.py":136
  5827. * self._dirty = True
  5828. *
  5829. * def unlink(self, callback): # <<<<<<<<<<<<<<
  5830. * """
  5831. * unlink(callback) -> None
  5832. */
  5833. __pyx_t_1 = __Pyx_CyFunction_NewEx(&__pyx_mdef_6gevent_10_semaphore_9Semaphore_15unlink, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Semaphore_unlink, NULL, __pyx_n_s_gevent__semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__14)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 136, __pyx_L1_error)
  5834. __Pyx_GOTREF(__pyx_t_1);
  5835. if (PyDict_SetItem((PyObject *)__pyx_ptype_6gevent_10_semaphore_Semaphore->tp_dict, __pyx_n_s_unlink, __pyx_t_1) < 0) __PYX_ERR(0, 136, __pyx_L1_error)
  5836. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  5837. PyType_Modified(__pyx_ptype_6gevent_10_semaphore_Semaphore);
  5838. /* "gevent/_semaphore.py":177
  5839. * self.unlink(switch)
  5840. *
  5841. * def wait(self, timeout=None): # <<<<<<<<<<<<<<
  5842. * """
  5843. * wait(timeout=None) -> int
  5844. */
  5845. __pyx_t_1 = __Pyx_CyFunction_NewEx(&__pyx_mdef_6gevent_10_semaphore_9Semaphore_17wait, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Semaphore_wait, NULL, __pyx_n_s_gevent__semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__16)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 177, __pyx_L1_error)
  5846. __Pyx_GOTREF(__pyx_t_1);
  5847. if (PyDict_SetItem((PyObject *)__pyx_ptype_6gevent_10_semaphore_Semaphore->tp_dict, __pyx_n_s_wait, __pyx_t_1) < 0) __PYX_ERR(0, 177, __pyx_L1_error)
  5848. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  5849. PyType_Modified(__pyx_ptype_6gevent_10_semaphore_Semaphore);
  5850. /* "gevent/_semaphore.py":198
  5851. * return self.counter
  5852. *
  5853. * def acquire(self, blocking=True, timeout=None): # <<<<<<<<<<<<<<
  5854. * """
  5855. * acquire(blocking=True, timeout=None) -> bool
  5856. */
  5857. __pyx_t_1 = __Pyx_CyFunction_NewEx(&__pyx_mdef_6gevent_10_semaphore_9Semaphore_19acquire, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Semaphore_acquire, NULL, __pyx_n_s_gevent__semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__18)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 198, __pyx_L1_error)
  5858. __Pyx_GOTREF(__pyx_t_1);
  5859. if (PyDict_SetItem((PyObject *)__pyx_ptype_6gevent_10_semaphore_Semaphore->tp_dict, __pyx_n_s_acquire, __pyx_t_1) < 0) __PYX_ERR(0, 198, __pyx_L1_error)
  5860. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  5861. PyType_Modified(__pyx_ptype_6gevent_10_semaphore_Semaphore);
  5862. /* "gevent/_semaphore.py":237
  5863. * return True
  5864. *
  5865. * _py3k_acquire = acquire # PyPy needs this; it must be static for Cython # <<<<<<<<<<<<<<
  5866. *
  5867. * def __enter__(self):
  5868. */
  5869. __pyx_t_1 = __Pyx_GetNameInClass((PyObject *)__pyx_ptype_6gevent_10_semaphore_Semaphore, __pyx_n_s_acquire); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 237, __pyx_L1_error)
  5870. __Pyx_GOTREF(__pyx_t_1);
  5871. if (PyDict_SetItem((PyObject *)__pyx_ptype_6gevent_10_semaphore_Semaphore->tp_dict, __pyx_n_s_py3k_acquire, __pyx_t_1) < 0) __PYX_ERR(0, 237, __pyx_L1_error)
  5872. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  5873. PyType_Modified(__pyx_ptype_6gevent_10_semaphore_Semaphore);
  5874. /* "gevent/_semaphore.py":239
  5875. * _py3k_acquire = acquire # PyPy needs this; it must be static for Cython
  5876. *
  5877. * def __enter__(self): # <<<<<<<<<<<<<<
  5878. * self.acquire()
  5879. *
  5880. */
  5881. __pyx_t_1 = __Pyx_CyFunction_NewEx(&__pyx_mdef_6gevent_10_semaphore_9Semaphore_21__enter__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Semaphore___enter, NULL, __pyx_n_s_gevent__semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__20)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 239, __pyx_L1_error)
  5882. __Pyx_GOTREF(__pyx_t_1);
  5883. if (PyDict_SetItem((PyObject *)__pyx_ptype_6gevent_10_semaphore_Semaphore->tp_dict, __pyx_n_s_enter, __pyx_t_1) < 0) __PYX_ERR(0, 239, __pyx_L1_error)
  5884. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  5885. PyType_Modified(__pyx_ptype_6gevent_10_semaphore_Semaphore);
  5886. /* "gevent/_semaphore.py":242
  5887. * self.acquire()
  5888. *
  5889. * def __exit__(self, t, v, tb): # <<<<<<<<<<<<<<
  5890. * self.release()
  5891. *
  5892. */
  5893. __pyx_t_1 = __Pyx_CyFunction_NewEx(&__pyx_mdef_6gevent_10_semaphore_9Semaphore_23__exit__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Semaphore___exit, NULL, __pyx_n_s_gevent__semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__22)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 242, __pyx_L1_error)
  5894. __Pyx_GOTREF(__pyx_t_1);
  5895. if (PyDict_SetItem((PyObject *)__pyx_ptype_6gevent_10_semaphore_Semaphore->tp_dict, __pyx_n_s_exit, __pyx_t_1) < 0) __PYX_ERR(0, 242, __pyx_L1_error)
  5896. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  5897. PyType_Modified(__pyx_ptype_6gevent_10_semaphore_Semaphore);
  5898. /* "gevent/_semaphore.py":260
  5899. *
  5900. * #: For monkey-patching, allow changing the class of error we raise
  5901. * _OVER_RELEASE_ERROR = ValueError # <<<<<<<<<<<<<<
  5902. *
  5903. * def __init__(self, *args, **kwargs):
  5904. */
  5905. if (PyDict_SetItem((PyObject *)__pyx_ptype_6gevent_10_semaphore_BoundedSemaphore->tp_dict, __pyx_n_s_OVER_RELEASE_ERROR, __pyx_builtin_ValueError) < 0) __PYX_ERR(0, 260, __pyx_L1_error)
  5906. PyType_Modified(__pyx_ptype_6gevent_10_semaphore_BoundedSemaphore);
  5907. /* "gevent/_semaphore.py":266
  5908. * self._initial_value = self.counter
  5909. *
  5910. * def release(self): # <<<<<<<<<<<<<<
  5911. * if self.counter >= self._initial_value:
  5912. * raise self._OVER_RELEASE_ERROR("Semaphore released too many times")
  5913. */
  5914. __pyx_t_1 = __Pyx_CyFunction_NewEx(&__pyx_mdef_6gevent_10_semaphore_16BoundedSemaphore_3release, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_BoundedSemaphore_release, NULL, __pyx_n_s_gevent__semaphore, __pyx_d, ((PyObject *)__pyx_codeobj__24)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 266, __pyx_L1_error)
  5915. __Pyx_GOTREF(__pyx_t_1);
  5916. if (PyDict_SetItem((PyObject *)__pyx_ptype_6gevent_10_semaphore_BoundedSemaphore->tp_dict, __pyx_n_s_release, __pyx_t_1) < 0) __PYX_ERR(0, 266, __pyx_L1_error)
  5917. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  5918. PyType_Modified(__pyx_ptype_6gevent_10_semaphore_BoundedSemaphore);
  5919. /* "gevent/_semaphore.py":1
  5920. * import sys # <<<<<<<<<<<<<<
  5921. * from gevent.hub import get_hub, getcurrent
  5922. * from gevent.timeout import Timeout
  5923. */
  5924. __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  5925. __Pyx_GOTREF(__pyx_t_1);
  5926. if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  5927. __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  5928. /*--- Wrapped vars code ---*/
  5929. goto __pyx_L0;
  5930. __pyx_L1_error:;
  5931. __Pyx_XDECREF(__pyx_t_1);
  5932. __Pyx_XDECREF(__pyx_t_2);
  5933. if (__pyx_m) {
  5934. if (__pyx_d) {
  5935. __Pyx_AddTraceback("init gevent._semaphore", __pyx_clineno, __pyx_lineno, __pyx_filename);
  5936. }
  5937. Py_DECREF(__pyx_m); __pyx_m = 0;
  5938. } else if (!PyErr_Occurred()) {
  5939. PyErr_SetString(PyExc_ImportError, "init gevent._semaphore");
  5940. }
  5941. __pyx_L0:;
  5942. __Pyx_RefNannyFinishContext();
  5943. #if PY_MAJOR_VERSION < 3
  5944. return;
  5945. #else
  5946. return __pyx_m;
  5947. #endif
  5948. }
  5949. /* --- Runtime support code --- */
  5950. /* Refnanny */
  5951. #if CYTHON_REFNANNY
  5952. static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
  5953. PyObject *m = NULL, *p = NULL;
  5954. void *r = NULL;
  5955. m = PyImport_ImportModule((char *)modname);
  5956. if (!m) goto end;
  5957. p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
  5958. if (!p) goto end;
  5959. r = PyLong_AsVoidPtr(p);
  5960. end:
  5961. Py_XDECREF(p);
  5962. Py_XDECREF(m);
  5963. return (__Pyx_RefNannyAPIStruct *)r;
  5964. }
  5965. #endif
  5966. /* GetBuiltinName */
  5967. static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
  5968. PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name);
  5969. if (unlikely(!result)) {
  5970. PyErr_Format(PyExc_NameError,
  5971. #if PY_MAJOR_VERSION >= 3
  5972. "name '%U' is not defined", name);
  5973. #else
  5974. "name '%.200s' is not defined", PyString_AS_STRING(name));
  5975. #endif
  5976. }
  5977. return result;
  5978. }
  5979. /* RaiseDoubleKeywords */
  5980. static void __Pyx_RaiseDoubleKeywordsError(
  5981. const char* func_name,
  5982. PyObject* kw_name)
  5983. {
  5984. PyErr_Format(PyExc_TypeError,
  5985. #if PY_MAJOR_VERSION >= 3
  5986. "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
  5987. #else
  5988. "%s() got multiple values for keyword argument '%s'", func_name,
  5989. PyString_AsString(kw_name));
  5990. #endif
  5991. }
  5992. /* ParseKeywords */
  5993. static int __Pyx_ParseOptionalKeywords(
  5994. PyObject *kwds,
  5995. PyObject **argnames[],
  5996. PyObject *kwds2,
  5997. PyObject *values[],
  5998. Py_ssize_t num_pos_args,
  5999. const char* function_name)
  6000. {
  6001. PyObject *key = 0, *value = 0;
  6002. Py_ssize_t pos = 0;
  6003. PyObject*** name;
  6004. PyObject*** first_kw_arg = argnames + num_pos_args;
  6005. while (PyDict_Next(kwds, &pos, &key, &value)) {
  6006. name = first_kw_arg;
  6007. while (*name && (**name != key)) name++;
  6008. if (*name) {
  6009. values[name-argnames] = value;
  6010. continue;
  6011. }
  6012. name = first_kw_arg;
  6013. #if PY_MAJOR_VERSION < 3
  6014. if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) {
  6015. while (*name) {
  6016. if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key))
  6017. && _PyString_Eq(**name, key)) {
  6018. values[name-argnames] = value;
  6019. break;
  6020. }
  6021. name++;
  6022. }
  6023. if (*name) continue;
  6024. else {
  6025. PyObject*** argname = argnames;
  6026. while (argname != first_kw_arg) {
  6027. if ((**argname == key) || (
  6028. (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key))
  6029. && _PyString_Eq(**argname, key))) {
  6030. goto arg_passed_twice;
  6031. }
  6032. argname++;
  6033. }
  6034. }
  6035. } else
  6036. #endif
  6037. if (likely(PyUnicode_Check(key))) {
  6038. while (*name) {
  6039. int cmp = (**name == key) ? 0 :
  6040. #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
  6041. (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 :
  6042. #endif
  6043. PyUnicode_Compare(**name, key);
  6044. if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
  6045. if (cmp == 0) {
  6046. values[name-argnames] = value;
  6047. break;
  6048. }
  6049. name++;
  6050. }
  6051. if (*name) continue;
  6052. else {
  6053. PyObject*** argname = argnames;
  6054. while (argname != first_kw_arg) {
  6055. int cmp = (**argname == key) ? 0 :
  6056. #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
  6057. (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 :
  6058. #endif
  6059. PyUnicode_Compare(**argname, key);
  6060. if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
  6061. if (cmp == 0) goto arg_passed_twice;
  6062. argname++;
  6063. }
  6064. }
  6065. } else
  6066. goto invalid_keyword_type;
  6067. if (kwds2) {
  6068. if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
  6069. } else {
  6070. goto invalid_keyword;
  6071. }
  6072. }
  6073. return 0;
  6074. arg_passed_twice:
  6075. __Pyx_RaiseDoubleKeywordsError(function_name, key);
  6076. goto bad;
  6077. invalid_keyword_type:
  6078. PyErr_Format(PyExc_TypeError,
  6079. "%.200s() keywords must be strings", function_name);
  6080. goto bad;
  6081. invalid_keyword:
  6082. PyErr_Format(PyExc_TypeError,
  6083. #if PY_MAJOR_VERSION < 3
  6084. "%.200s() got an unexpected keyword argument '%.200s'",
  6085. function_name, PyString_AsString(key));
  6086. #else
  6087. "%s() got an unexpected keyword argument '%U'",
  6088. function_name, key);
  6089. #endif
  6090. bad:
  6091. return -1;
  6092. }
  6093. /* RaiseArgTupleInvalid */
  6094. static void __Pyx_RaiseArgtupleInvalid(
  6095. const char* func_name,
  6096. int exact,
  6097. Py_ssize_t num_min,
  6098. Py_ssize_t num_max,
  6099. Py_ssize_t num_found)
  6100. {
  6101. Py_ssize_t num_expected;
  6102. const char *more_or_less;
  6103. if (num_found < num_min) {
  6104. num_expected = num_min;
  6105. more_or_less = "at least";
  6106. } else {
  6107. num_expected = num_max;
  6108. more_or_less = "at most";
  6109. }
  6110. if (exact) {
  6111. more_or_less = "exactly";
  6112. }
  6113. PyErr_Format(PyExc_TypeError,
  6114. "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)",
  6115. func_name, more_or_less, num_expected,
  6116. (num_expected == 1) ? "" : "s", num_found);
  6117. }
  6118. /* PyObjectCall */
  6119. #if CYTHON_COMPILING_IN_CPYTHON
  6120. static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
  6121. PyObject *result;
  6122. ternaryfunc call = func->ob_type->tp_call;
  6123. if (unlikely(!call))
  6124. return PyObject_Call(func, arg, kw);
  6125. if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
  6126. return NULL;
  6127. result = (*call)(func, arg, kw);
  6128. Py_LeaveRecursiveCall();
  6129. if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
  6130. PyErr_SetString(
  6131. PyExc_SystemError,
  6132. "NULL result without error in PyObject_Call");
  6133. }
  6134. return result;
  6135. }
  6136. #endif
  6137. /* PyErrFetchRestore */
  6138. #if CYTHON_FAST_THREAD_STATE
  6139. static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
  6140. PyObject *tmp_type, *tmp_value, *tmp_tb;
  6141. tmp_type = tstate->curexc_type;
  6142. tmp_value = tstate->curexc_value;
  6143. tmp_tb = tstate->curexc_traceback;
  6144. tstate->curexc_type = type;
  6145. tstate->curexc_value = value;
  6146. tstate->curexc_traceback = tb;
  6147. Py_XDECREF(tmp_type);
  6148. Py_XDECREF(tmp_value);
  6149. Py_XDECREF(tmp_tb);
  6150. }
  6151. static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
  6152. *type = tstate->curexc_type;
  6153. *value = tstate->curexc_value;
  6154. *tb = tstate->curexc_traceback;
  6155. tstate->curexc_type = 0;
  6156. tstate->curexc_value = 0;
  6157. tstate->curexc_traceback = 0;
  6158. }
  6159. #endif
  6160. /* RaiseException */
  6161. #if PY_MAJOR_VERSION < 3
  6162. static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
  6163. CYTHON_UNUSED PyObject *cause) {
  6164. __Pyx_PyThreadState_declare
  6165. Py_XINCREF(type);
  6166. if (!value || value == Py_None)
  6167. value = NULL;
  6168. else
  6169. Py_INCREF(value);
  6170. if (!tb || tb == Py_None)
  6171. tb = NULL;
  6172. else {
  6173. Py_INCREF(tb);
  6174. if (!PyTraceBack_Check(tb)) {
  6175. PyErr_SetString(PyExc_TypeError,
  6176. "raise: arg 3 must be a traceback or None");
  6177. goto raise_error;
  6178. }
  6179. }
  6180. if (PyType_Check(type)) {
  6181. #if CYTHON_COMPILING_IN_PYPY
  6182. if (!value) {
  6183. Py_INCREF(Py_None);
  6184. value = Py_None;
  6185. }
  6186. #endif
  6187. PyErr_NormalizeException(&type, &value, &tb);
  6188. } else {
  6189. if (value) {
  6190. PyErr_SetString(PyExc_TypeError,
  6191. "instance exception may not have a separate value");
  6192. goto raise_error;
  6193. }
  6194. value = type;
  6195. type = (PyObject*) Py_TYPE(type);
  6196. Py_INCREF(type);
  6197. if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
  6198. PyErr_SetString(PyExc_TypeError,
  6199. "raise: exception class must be a subclass of BaseException");
  6200. goto raise_error;
  6201. }
  6202. }
  6203. __Pyx_PyThreadState_assign
  6204. __Pyx_ErrRestore(type, value, tb);
  6205. return;
  6206. raise_error:
  6207. Py_XDECREF(value);
  6208. Py_XDECREF(type);
  6209. Py_XDECREF(tb);
  6210. return;
  6211. }
  6212. #else
  6213. static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
  6214. PyObject* owned_instance = NULL;
  6215. if (tb == Py_None) {
  6216. tb = 0;
  6217. } else if (tb && !PyTraceBack_Check(tb)) {
  6218. PyErr_SetString(PyExc_TypeError,
  6219. "raise: arg 3 must be a traceback or None");
  6220. goto bad;
  6221. }
  6222. if (value == Py_None)
  6223. value = 0;
  6224. if (PyExceptionInstance_Check(type)) {
  6225. if (value) {
  6226. PyErr_SetString(PyExc_TypeError,
  6227. "instance exception may not have a separate value");
  6228. goto bad;
  6229. }
  6230. value = type;
  6231. type = (PyObject*) Py_TYPE(value);
  6232. } else if (PyExceptionClass_Check(type)) {
  6233. PyObject *instance_class = NULL;
  6234. if (value && PyExceptionInstance_Check(value)) {
  6235. instance_class = (PyObject*) Py_TYPE(value);
  6236. if (instance_class != type) {
  6237. int is_subclass = PyObject_IsSubclass(instance_class, type);
  6238. if (!is_subclass) {
  6239. instance_class = NULL;
  6240. } else if (unlikely(is_subclass == -1)) {
  6241. goto bad;
  6242. } else {
  6243. type = instance_class;
  6244. }
  6245. }
  6246. }
  6247. if (!instance_class) {
  6248. PyObject *args;
  6249. if (!value)
  6250. args = PyTuple_New(0);
  6251. else if (PyTuple_Check(value)) {
  6252. Py_INCREF(value);
  6253. args = value;
  6254. } else
  6255. args = PyTuple_Pack(1, value);
  6256. if (!args)
  6257. goto bad;
  6258. owned_instance = PyObject_Call(type, args, NULL);
  6259. Py_DECREF(args);
  6260. if (!owned_instance)
  6261. goto bad;
  6262. value = owned_instance;
  6263. if (!PyExceptionInstance_Check(value)) {
  6264. PyErr_Format(PyExc_TypeError,
  6265. "calling %R should have returned an instance of "
  6266. "BaseException, not %R",
  6267. type, Py_TYPE(value));
  6268. goto bad;
  6269. }
  6270. }
  6271. } else {
  6272. PyErr_SetString(PyExc_TypeError,
  6273. "raise: exception class must be a subclass of BaseException");
  6274. goto bad;
  6275. }
  6276. #if PY_VERSION_HEX >= 0x03030000
  6277. if (cause) {
  6278. #else
  6279. if (cause && cause != Py_None) {
  6280. #endif
  6281. PyObject *fixed_cause;
  6282. if (cause == Py_None) {
  6283. fixed_cause = NULL;
  6284. } else if (PyExceptionClass_Check(cause)) {
  6285. fixed_cause = PyObject_CallObject(cause, NULL);
  6286. if (fixed_cause == NULL)
  6287. goto bad;
  6288. } else if (PyExceptionInstance_Check(cause)) {
  6289. fixed_cause = cause;
  6290. Py_INCREF(fixed_cause);
  6291. } else {
  6292. PyErr_SetString(PyExc_TypeError,
  6293. "exception causes must derive from "
  6294. "BaseException");
  6295. goto bad;
  6296. }
  6297. PyException_SetCause(value, fixed_cause);
  6298. }
  6299. PyErr_SetObject(type, value);
  6300. if (tb) {
  6301. #if CYTHON_COMPILING_IN_PYPY
  6302. PyObject *tmp_type, *tmp_value, *tmp_tb;
  6303. PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb);
  6304. Py_INCREF(tb);
  6305. PyErr_Restore(tmp_type, tmp_value, tb);
  6306. Py_XDECREF(tmp_tb);
  6307. #else
  6308. PyThreadState *tstate = PyThreadState_GET();
  6309. PyObject* tmp_tb = tstate->curexc_traceback;
  6310. if (tb != tmp_tb) {
  6311. Py_INCREF(tb);
  6312. tstate->curexc_traceback = tb;
  6313. Py_XDECREF(tmp_tb);
  6314. }
  6315. #endif
  6316. }
  6317. bad:
  6318. Py_XDECREF(owned_instance);
  6319. return;
  6320. }
  6321. #endif
  6322. /* PyCFunctionFastCall */
  6323. #if CYTHON_FAST_PYCCALL
  6324. static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, PyObject **args, Py_ssize_t nargs) {
  6325. PyCFunctionObject *func = (PyCFunctionObject*)func_obj;
  6326. PyCFunction meth = PyCFunction_GET_FUNCTION(func);
  6327. PyObject *self = PyCFunction_GET_SELF(func);
  6328. assert(PyCFunction_Check(func));
  6329. assert(METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST)));
  6330. assert(nargs >= 0);
  6331. assert(nargs == 0 || args != NULL);
  6332. /* _PyCFunction_FastCallDict() must not be called with an exception set,
  6333. because it may clear it (directly or indirectly) and so the
  6334. caller loses its exception */
  6335. assert(!PyErr_Occurred());
  6336. return (*((__Pyx_PyCFunctionFast)meth)) (self, args, nargs, NULL);
  6337. }
  6338. #endif // CYTHON_FAST_PYCCALL
  6339. /* PyFunctionFastCall */
  6340. #if CYTHON_FAST_PYCALL
  6341. #include "frameobject.h"
  6342. static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na,
  6343. PyObject *globals) {
  6344. PyFrameObject *f;
  6345. PyThreadState *tstate = PyThreadState_GET();
  6346. PyObject **fastlocals;
  6347. Py_ssize_t i;
  6348. PyObject *result;
  6349. assert(globals != NULL);
  6350. /* XXX Perhaps we should create a specialized
  6351. PyFrame_New() that doesn't take locals, but does
  6352. take builtins without sanity checking them.
  6353. */
  6354. assert(tstate != NULL);
  6355. f = PyFrame_New(tstate, co, globals, NULL);
  6356. if (f == NULL) {
  6357. return NULL;
  6358. }
  6359. fastlocals = f->f_localsplus;
  6360. for (i = 0; i < na; i++) {
  6361. Py_INCREF(*args);
  6362. fastlocals[i] = *args++;
  6363. }
  6364. result = PyEval_EvalFrameEx(f,0);
  6365. ++tstate->recursion_depth;
  6366. Py_DECREF(f);
  6367. --tstate->recursion_depth;
  6368. return result;
  6369. }
  6370. #if 1 || PY_VERSION_HEX < 0x030600B1
  6371. static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwargs) {
  6372. PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func);
  6373. PyObject *globals = PyFunction_GET_GLOBALS(func);
  6374. PyObject *argdefs = PyFunction_GET_DEFAULTS(func);
  6375. PyObject *closure;
  6376. #if PY_MAJOR_VERSION >= 3
  6377. PyObject *kwdefs;
  6378. #endif
  6379. PyObject *kwtuple, **k;
  6380. PyObject **d;
  6381. Py_ssize_t nd;
  6382. Py_ssize_t nk;
  6383. PyObject *result;
  6384. assert(kwargs == NULL || PyDict_Check(kwargs));
  6385. nk = kwargs ? PyDict_Size(kwargs) : 0;
  6386. if (Py_EnterRecursiveCall((char*)" while calling a Python object")) {
  6387. return NULL;
  6388. }
  6389. if (
  6390. #if PY_MAJOR_VERSION >= 3
  6391. co->co_kwonlyargcount == 0 &&
  6392. #endif
  6393. likely(kwargs == NULL || nk == 0) &&
  6394. co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) {
  6395. if (argdefs == NULL && co->co_argcount == nargs) {
  6396. result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals);
  6397. goto done;
  6398. }
  6399. else if (nargs == 0 && argdefs != NULL
  6400. && co->co_argcount == Py_SIZE(argdefs)) {
  6401. /* function called with no arguments, but all parameters have
  6402. a default value: use default values as arguments .*/
  6403. args = &PyTuple_GET_ITEM(argdefs, 0);
  6404. result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals);
  6405. goto done;
  6406. }
  6407. }
  6408. if (kwargs != NULL) {
  6409. Py_ssize_t pos, i;
  6410. kwtuple = PyTuple_New(2 * nk);
  6411. if (kwtuple == NULL) {
  6412. result = NULL;
  6413. goto done;
  6414. }
  6415. k = &PyTuple_GET_ITEM(kwtuple, 0);
  6416. pos = i = 0;
  6417. while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) {
  6418. Py_INCREF(k[i]);
  6419. Py_INCREF(k[i+1]);
  6420. i += 2;
  6421. }
  6422. nk = i / 2;
  6423. }
  6424. else {
  6425. kwtuple = NULL;
  6426. k = NULL;
  6427. }
  6428. closure = PyFunction_GET_CLOSURE(func);
  6429. #if PY_MAJOR_VERSION >= 3
  6430. kwdefs = PyFunction_GET_KW_DEFAULTS(func);
  6431. #endif
  6432. if (argdefs != NULL) {
  6433. d = &PyTuple_GET_ITEM(argdefs, 0);
  6434. nd = Py_SIZE(argdefs);
  6435. }
  6436. else {
  6437. d = NULL;
  6438. nd = 0;
  6439. }
  6440. #if PY_MAJOR_VERSION >= 3
  6441. result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL,
  6442. args, nargs,
  6443. k, (int)nk,
  6444. d, (int)nd, kwdefs, closure);
  6445. #else
  6446. result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL,
  6447. args, nargs,
  6448. k, (int)nk,
  6449. d, (int)nd, closure);
  6450. #endif
  6451. Py_XDECREF(kwtuple);
  6452. done:
  6453. Py_LeaveRecursiveCall();
  6454. return result;
  6455. }
  6456. #endif // CPython < 3.6
  6457. #endif // CYTHON_FAST_PYCALL
  6458. /* PyObjectCallMethO */
  6459. #if CYTHON_COMPILING_IN_CPYTHON
  6460. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
  6461. PyObject *self, *result;
  6462. PyCFunction cfunc;
  6463. cfunc = PyCFunction_GET_FUNCTION(func);
  6464. self = PyCFunction_GET_SELF(func);
  6465. if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
  6466. return NULL;
  6467. result = cfunc(self, arg);
  6468. Py_LeaveRecursiveCall();
  6469. if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
  6470. PyErr_SetString(
  6471. PyExc_SystemError,
  6472. "NULL result without error in PyObject_Call");
  6473. }
  6474. return result;
  6475. }
  6476. #endif
  6477. /* PyObjectCallOneArg */
  6478. #if CYTHON_COMPILING_IN_CPYTHON
  6479. static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) {
  6480. PyObject *result;
  6481. PyObject *args = PyTuple_New(1);
  6482. if (unlikely(!args)) return NULL;
  6483. Py_INCREF(arg);
  6484. PyTuple_SET_ITEM(args, 0, arg);
  6485. result = __Pyx_PyObject_Call(func, args, NULL);
  6486. Py_DECREF(args);
  6487. return result;
  6488. }
  6489. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
  6490. #if CYTHON_FAST_PYCALL
  6491. if (PyFunction_Check(func)) {
  6492. return __Pyx_PyFunction_FastCall(func, &arg, 1);
  6493. }
  6494. #endif
  6495. #ifdef __Pyx_CyFunction_USED
  6496. if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) {
  6497. #else
  6498. if (likely(PyCFunction_Check(func))) {
  6499. #endif
  6500. if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) {
  6501. return __Pyx_PyObject_CallMethO(func, arg);
  6502. #if CYTHON_FAST_PYCCALL
  6503. } else if (PyCFunction_GET_FLAGS(func) & METH_FASTCALL) {
  6504. return __Pyx_PyCFunction_FastCall(func, &arg, 1);
  6505. #endif
  6506. }
  6507. }
  6508. return __Pyx__PyObject_CallOneArg(func, arg);
  6509. }
  6510. #else
  6511. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
  6512. PyObject *result;
  6513. PyObject *args = PyTuple_Pack(1, arg);
  6514. if (unlikely(!args)) return NULL;
  6515. result = __Pyx_PyObject_Call(func, args, NULL);
  6516. Py_DECREF(args);
  6517. return result;
  6518. }
  6519. #endif
  6520. /* PyObjectCallNoArg */
  6521. #if CYTHON_COMPILING_IN_CPYTHON
  6522. static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
  6523. #if CYTHON_FAST_PYCALL
  6524. if (PyFunction_Check(func)) {
  6525. return __Pyx_PyFunction_FastCall(func, NULL, 0);
  6526. }
  6527. #endif
  6528. #ifdef __Pyx_CyFunction_USED
  6529. if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) {
  6530. #else
  6531. if (likely(PyCFunction_Check(func))) {
  6532. #endif
  6533. if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) {
  6534. return __Pyx_PyObject_CallMethO(func, NULL);
  6535. }
  6536. }
  6537. return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL);
  6538. }
  6539. #endif
  6540. /* WriteUnraisableException */
  6541. static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno,
  6542. CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename,
  6543. int full_traceback, CYTHON_UNUSED int nogil) {
  6544. PyObject *old_exc, *old_val, *old_tb;
  6545. PyObject *ctx;
  6546. __Pyx_PyThreadState_declare
  6547. #ifdef WITH_THREAD
  6548. PyGILState_STATE state;
  6549. if (nogil)
  6550. state = PyGILState_Ensure();
  6551. #ifdef _MSC_VER
  6552. else state = (PyGILState_STATE)-1;
  6553. #endif
  6554. #endif
  6555. __Pyx_PyThreadState_assign
  6556. __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
  6557. if (full_traceback) {
  6558. Py_XINCREF(old_exc);
  6559. Py_XINCREF(old_val);
  6560. Py_XINCREF(old_tb);
  6561. __Pyx_ErrRestore(old_exc, old_val, old_tb);
  6562. PyErr_PrintEx(1);
  6563. }
  6564. #if PY_MAJOR_VERSION < 3
  6565. ctx = PyString_FromString(name);
  6566. #else
  6567. ctx = PyUnicode_FromString(name);
  6568. #endif
  6569. __Pyx_ErrRestore(old_exc, old_val, old_tb);
  6570. if (!ctx) {
  6571. PyErr_WriteUnraisable(Py_None);
  6572. } else {
  6573. PyErr_WriteUnraisable(ctx);
  6574. Py_DECREF(ctx);
  6575. }
  6576. #ifdef WITH_THREAD
  6577. if (nogil)
  6578. PyGILState_Release(state);
  6579. #endif
  6580. }
  6581. /* GetModuleGlobalName */
  6582. static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) {
  6583. PyObject *result;
  6584. #if !CYTHON_AVOID_BORROWED_REFS
  6585. result = PyDict_GetItem(__pyx_d, name);
  6586. if (likely(result)) {
  6587. Py_INCREF(result);
  6588. } else {
  6589. #else
  6590. result = PyObject_GetItem(__pyx_d, name);
  6591. if (!result) {
  6592. PyErr_Clear();
  6593. #endif
  6594. result = __Pyx_GetBuiltinName(name);
  6595. }
  6596. return result;
  6597. }
  6598. /* SaveResetException */
  6599. #if CYTHON_FAST_THREAD_STATE
  6600. static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
  6601. *type = tstate->exc_type;
  6602. *value = tstate->exc_value;
  6603. *tb = tstate->exc_traceback;
  6604. Py_XINCREF(*type);
  6605. Py_XINCREF(*value);
  6606. Py_XINCREF(*tb);
  6607. }
  6608. static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
  6609. PyObject *tmp_type, *tmp_value, *tmp_tb;
  6610. tmp_type = tstate->exc_type;
  6611. tmp_value = tstate->exc_value;
  6612. tmp_tb = tstate->exc_traceback;
  6613. tstate->exc_type = type;
  6614. tstate->exc_value = value;
  6615. tstate->exc_traceback = tb;
  6616. Py_XDECREF(tmp_type);
  6617. Py_XDECREF(tmp_value);
  6618. Py_XDECREF(tmp_tb);
  6619. }
  6620. #endif
  6621. /* GetException */
  6622. #if CYTHON_FAST_THREAD_STATE
  6623. static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
  6624. #else
  6625. static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) {
  6626. #endif
  6627. PyObject *local_type, *local_value, *local_tb;
  6628. #if CYTHON_FAST_THREAD_STATE
  6629. PyObject *tmp_type, *tmp_value, *tmp_tb;
  6630. local_type = tstate->curexc_type;
  6631. local_value = tstate->curexc_value;
  6632. local_tb = tstate->curexc_traceback;
  6633. tstate->curexc_type = 0;
  6634. tstate->curexc_value = 0;
  6635. tstate->curexc_traceback = 0;
  6636. #else
  6637. PyErr_Fetch(&local_type, &local_value, &local_tb);
  6638. #endif
  6639. PyErr_NormalizeException(&local_type, &local_value, &local_tb);
  6640. #if CYTHON_FAST_THREAD_STATE
  6641. if (unlikely(tstate->curexc_type))
  6642. #else
  6643. if (unlikely(PyErr_Occurred()))
  6644. #endif
  6645. goto bad;
  6646. #if PY_MAJOR_VERSION >= 3
  6647. if (local_tb) {
  6648. if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
  6649. goto bad;
  6650. }
  6651. #endif
  6652. Py_XINCREF(local_tb);
  6653. Py_XINCREF(local_type);
  6654. Py_XINCREF(local_value);
  6655. *type = local_type;
  6656. *value = local_value;
  6657. *tb = local_tb;
  6658. #if CYTHON_FAST_THREAD_STATE
  6659. tmp_type = tstate->exc_type;
  6660. tmp_value = tstate->exc_value;
  6661. tmp_tb = tstate->exc_traceback;
  6662. tstate->exc_type = local_type;
  6663. tstate->exc_value = local_value;
  6664. tstate->exc_traceback = local_tb;
  6665. Py_XDECREF(tmp_type);
  6666. Py_XDECREF(tmp_value);
  6667. Py_XDECREF(tmp_tb);
  6668. #else
  6669. PyErr_SetExcInfo(local_type, local_value, local_tb);
  6670. #endif
  6671. return 0;
  6672. bad:
  6673. *type = 0;
  6674. *value = 0;
  6675. *tb = 0;
  6676. Py_XDECREF(local_type);
  6677. Py_XDECREF(local_value);
  6678. Py_XDECREF(local_tb);
  6679. return -1;
  6680. }
  6681. /* SwapException */
  6682. #if CYTHON_FAST_THREAD_STATE
  6683. static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
  6684. PyObject *tmp_type, *tmp_value, *tmp_tb;
  6685. tmp_type = tstate->exc_type;
  6686. tmp_value = tstate->exc_value;
  6687. tmp_tb = tstate->exc_traceback;
  6688. tstate->exc_type = *type;
  6689. tstate->exc_value = *value;
  6690. tstate->exc_traceback = *tb;
  6691. *type = tmp_type;
  6692. *value = tmp_value;
  6693. *tb = tmp_tb;
  6694. }
  6695. #else
  6696. static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) {
  6697. PyObject *tmp_type, *tmp_value, *tmp_tb;
  6698. PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb);
  6699. PyErr_SetExcInfo(*type, *value, *tb);
  6700. *type = tmp_type;
  6701. *value = tmp_value;
  6702. *tb = tmp_tb;
  6703. }
  6704. #endif
  6705. /* PyObjectCallMethod1 */
  6706. static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) {
  6707. PyObject *method, *result = NULL;
  6708. method = __Pyx_PyObject_GetAttrStr(obj, method_name);
  6709. if (unlikely(!method)) goto done;
  6710. #if CYTHON_UNPACK_METHODS
  6711. if (likely(PyMethod_Check(method))) {
  6712. PyObject *self = PyMethod_GET_SELF(method);
  6713. if (likely(self)) {
  6714. PyObject *args;
  6715. PyObject *function = PyMethod_GET_FUNCTION(method);
  6716. #if CYTHON_FAST_PYCALL
  6717. if (PyFunction_Check(function)) {
  6718. PyObject *args[2] = {self, arg};
  6719. result = __Pyx_PyFunction_FastCall(function, args, 2);
  6720. goto done;
  6721. }
  6722. #endif
  6723. #if CYTHON_FAST_PYCCALL
  6724. if (__Pyx_PyFastCFunction_Check(function)) {
  6725. PyObject *args[2] = {self, arg};
  6726. result = __Pyx_PyCFunction_FastCall(function, args, 2);
  6727. goto done;
  6728. }
  6729. #endif
  6730. args = PyTuple_New(2);
  6731. if (unlikely(!args)) goto done;
  6732. Py_INCREF(self);
  6733. PyTuple_SET_ITEM(args, 0, self);
  6734. Py_INCREF(arg);
  6735. PyTuple_SET_ITEM(args, 1, arg);
  6736. Py_INCREF(function);
  6737. Py_DECREF(method); method = NULL;
  6738. result = __Pyx_PyObject_Call(function, args, NULL);
  6739. Py_DECREF(args);
  6740. Py_DECREF(function);
  6741. return result;
  6742. }
  6743. }
  6744. #endif
  6745. result = __Pyx_PyObject_CallOneArg(method, arg);
  6746. done:
  6747. Py_XDECREF(method);
  6748. return result;
  6749. }
  6750. /* append */
  6751. static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x) {
  6752. if (likely(PyList_CheckExact(L))) {
  6753. if (unlikely(__Pyx_PyList_Append(L, x) < 0)) return -1;
  6754. } else {
  6755. PyObject* retval = __Pyx_PyObject_CallMethod1(L, __pyx_n_s_append, x);
  6756. if (unlikely(!retval))
  6757. return -1;
  6758. Py_DECREF(retval);
  6759. }
  6760. return 0;
  6761. }
  6762. /* PyErrExceptionMatches */
  6763. #if CYTHON_FAST_THREAD_STATE
  6764. static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err) {
  6765. PyObject *exc_type = tstate->curexc_type;
  6766. if (exc_type == err) return 1;
  6767. if (unlikely(!exc_type)) return 0;
  6768. return PyErr_GivenExceptionMatches(exc_type, err);
  6769. }
  6770. #endif
  6771. /* KeywordStringCheck */
  6772. static CYTHON_INLINE int __Pyx_CheckKeywordStrings(
  6773. PyObject *kwdict,
  6774. const char* function_name,
  6775. int kw_allowed)
  6776. {
  6777. PyObject* key = 0;
  6778. Py_ssize_t pos = 0;
  6779. #if CYTHON_COMPILING_IN_PYPY
  6780. if (!kw_allowed && PyDict_Next(kwdict, &pos, &key, 0))
  6781. goto invalid_keyword;
  6782. return 1;
  6783. #else
  6784. while (PyDict_Next(kwdict, &pos, &key, 0)) {
  6785. #if PY_MAJOR_VERSION < 3
  6786. if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key)))
  6787. #endif
  6788. if (unlikely(!PyUnicode_Check(key)))
  6789. goto invalid_keyword_type;
  6790. }
  6791. if ((!kw_allowed) && unlikely(key))
  6792. goto invalid_keyword;
  6793. return 1;
  6794. invalid_keyword_type:
  6795. PyErr_Format(PyExc_TypeError,
  6796. "%.200s() keywords must be strings", function_name);
  6797. return 0;
  6798. #endif
  6799. invalid_keyword:
  6800. PyErr_Format(PyExc_TypeError,
  6801. #if PY_MAJOR_VERSION < 3
  6802. "%.200s() got an unexpected keyword argument '%.200s'",
  6803. function_name, PyString_AsString(key));
  6804. #else
  6805. "%s() got an unexpected keyword argument '%U'",
  6806. function_name, key);
  6807. #endif
  6808. return 0;
  6809. }
  6810. /* SetVTable */
  6811. static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
  6812. #if PY_VERSION_HEX >= 0x02070000
  6813. PyObject *ob = PyCapsule_New(vtable, 0, 0);
  6814. #else
  6815. PyObject *ob = PyCObject_FromVoidPtr(vtable, 0);
  6816. #endif
  6817. if (!ob)
  6818. goto bad;
  6819. if (PyDict_SetItem(dict, __pyx_n_s_pyx_vtable, ob) < 0)
  6820. goto bad;
  6821. Py_DECREF(ob);
  6822. return 0;
  6823. bad:
  6824. Py_XDECREF(ob);
  6825. return -1;
  6826. }
  6827. /* Import */
  6828. static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
  6829. PyObject *empty_list = 0;
  6830. PyObject *module = 0;
  6831. PyObject *global_dict = 0;
  6832. PyObject *empty_dict = 0;
  6833. PyObject *list;
  6834. #if PY_VERSION_HEX < 0x03030000
  6835. PyObject *py_import;
  6836. py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import);
  6837. if (!py_import)
  6838. goto bad;
  6839. #endif
  6840. if (from_list)
  6841. list = from_list;
  6842. else {
  6843. empty_list = PyList_New(0);
  6844. if (!empty_list)
  6845. goto bad;
  6846. list = empty_list;
  6847. }
  6848. global_dict = PyModule_GetDict(__pyx_m);
  6849. if (!global_dict)
  6850. goto bad;
  6851. empty_dict = PyDict_New();
  6852. if (!empty_dict)
  6853. goto bad;
  6854. {
  6855. #if PY_MAJOR_VERSION >= 3
  6856. if (level == -1) {
  6857. if (strchr(__Pyx_MODULE_NAME, '.')) {
  6858. #if PY_VERSION_HEX < 0x03030000
  6859. PyObject *py_level = PyInt_FromLong(1);
  6860. if (!py_level)
  6861. goto bad;
  6862. module = PyObject_CallFunctionObjArgs(py_import,
  6863. name, global_dict, empty_dict, list, py_level, NULL);
  6864. Py_DECREF(py_level);
  6865. #else
  6866. module = PyImport_ImportModuleLevelObject(
  6867. name, global_dict, empty_dict, list, 1);
  6868. #endif
  6869. if (!module) {
  6870. if (!PyErr_ExceptionMatches(PyExc_ImportError))
  6871. goto bad;
  6872. PyErr_Clear();
  6873. }
  6874. }
  6875. level = 0;
  6876. }
  6877. #endif
  6878. if (!module) {
  6879. #if PY_VERSION_HEX < 0x03030000
  6880. PyObject *py_level = PyInt_FromLong(level);
  6881. if (!py_level)
  6882. goto bad;
  6883. module = PyObject_CallFunctionObjArgs(py_import,
  6884. name, global_dict, empty_dict, list, py_level, NULL);
  6885. Py_DECREF(py_level);
  6886. #else
  6887. module = PyImport_ImportModuleLevelObject(
  6888. name, global_dict, empty_dict, list, level);
  6889. #endif
  6890. }
  6891. }
  6892. bad:
  6893. #if PY_VERSION_HEX < 0x03030000
  6894. Py_XDECREF(py_import);
  6895. #endif
  6896. Py_XDECREF(empty_list);
  6897. Py_XDECREF(empty_dict);
  6898. return module;
  6899. }
  6900. /* ImportFrom */
  6901. static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) {
  6902. PyObject* value = __Pyx_PyObject_GetAttrStr(module, name);
  6903. if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) {
  6904. PyErr_Format(PyExc_ImportError,
  6905. #if PY_MAJOR_VERSION < 3
  6906. "cannot import name %.230s", PyString_AS_STRING(name));
  6907. #else
  6908. "cannot import name %S", name);
  6909. #endif
  6910. }
  6911. return value;
  6912. }
  6913. /* FetchCommonType */
  6914. static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type) {
  6915. PyObject* fake_module;
  6916. PyTypeObject* cached_type = NULL;
  6917. fake_module = PyImport_AddModule((char*) "_cython_" CYTHON_ABI);
  6918. if (!fake_module) return NULL;
  6919. Py_INCREF(fake_module);
  6920. cached_type = (PyTypeObject*) PyObject_GetAttrString(fake_module, type->tp_name);
  6921. if (cached_type) {
  6922. if (!PyType_Check((PyObject*)cached_type)) {
  6923. PyErr_Format(PyExc_TypeError,
  6924. "Shared Cython type %.200s is not a type object",
  6925. type->tp_name);
  6926. goto bad;
  6927. }
  6928. if (cached_type->tp_basicsize != type->tp_basicsize) {
  6929. PyErr_Format(PyExc_TypeError,
  6930. "Shared Cython type %.200s has the wrong size, try recompiling",
  6931. type->tp_name);
  6932. goto bad;
  6933. }
  6934. } else {
  6935. if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad;
  6936. PyErr_Clear();
  6937. if (PyType_Ready(type) < 0) goto bad;
  6938. if (PyObject_SetAttrString(fake_module, type->tp_name, (PyObject*) type) < 0)
  6939. goto bad;
  6940. Py_INCREF(type);
  6941. cached_type = type;
  6942. }
  6943. done:
  6944. Py_DECREF(fake_module);
  6945. return cached_type;
  6946. bad:
  6947. Py_XDECREF(cached_type);
  6948. cached_type = NULL;
  6949. goto done;
  6950. }
  6951. /* CythonFunction */
  6952. static PyObject *
  6953. __Pyx_CyFunction_get_doc(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *closure)
  6954. {
  6955. if (unlikely(op->func_doc == NULL)) {
  6956. if (op->func.m_ml->ml_doc) {
  6957. #if PY_MAJOR_VERSION >= 3
  6958. op->func_doc = PyUnicode_FromString(op->func.m_ml->ml_doc);
  6959. #else
  6960. op->func_doc = PyString_FromString(op->func.m_ml->ml_doc);
  6961. #endif
  6962. if (unlikely(op->func_doc == NULL))
  6963. return NULL;
  6964. } else {
  6965. Py_INCREF(Py_None);
  6966. return Py_None;
  6967. }
  6968. }
  6969. Py_INCREF(op->func_doc);
  6970. return op->func_doc;
  6971. }
  6972. static int
  6973. __Pyx_CyFunction_set_doc(__pyx_CyFunctionObject *op, PyObject *value)
  6974. {
  6975. PyObject *tmp = op->func_doc;
  6976. if (value == NULL) {
  6977. value = Py_None;
  6978. }
  6979. Py_INCREF(value);
  6980. op->func_doc = value;
  6981. Py_XDECREF(tmp);
  6982. return 0;
  6983. }
  6984. static PyObject *
  6985. __Pyx_CyFunction_get_name(__pyx_CyFunctionObject *op)
  6986. {
  6987. if (unlikely(op->func_name == NULL)) {
  6988. #if PY_MAJOR_VERSION >= 3
  6989. op->func_name = PyUnicode_InternFromString(op->func.m_ml->ml_name);
  6990. #else
  6991. op->func_name = PyString_InternFromString(op->func.m_ml->ml_name);
  6992. #endif
  6993. if (unlikely(op->func_name == NULL))
  6994. return NULL;
  6995. }
  6996. Py_INCREF(op->func_name);
  6997. return op->func_name;
  6998. }
  6999. static int
  7000. __Pyx_CyFunction_set_name(__pyx_CyFunctionObject *op, PyObject *value)
  7001. {
  7002. PyObject *tmp;
  7003. #if PY_MAJOR_VERSION >= 3
  7004. if (unlikely(value == NULL || !PyUnicode_Check(value))) {
  7005. #else
  7006. if (unlikely(value == NULL || !PyString_Check(value))) {
  7007. #endif
  7008. PyErr_SetString(PyExc_TypeError,
  7009. "__name__ must be set to a string object");
  7010. return -1;
  7011. }
  7012. tmp = op->func_name;
  7013. Py_INCREF(value);
  7014. op->func_name = value;
  7015. Py_XDECREF(tmp);
  7016. return 0;
  7017. }
  7018. static PyObject *
  7019. __Pyx_CyFunction_get_qualname(__pyx_CyFunctionObject *op)
  7020. {
  7021. Py_INCREF(op->func_qualname);
  7022. return op->func_qualname;
  7023. }
  7024. static int
  7025. __Pyx_CyFunction_set_qualname(__pyx_CyFunctionObject *op, PyObject *value)
  7026. {
  7027. PyObject *tmp;
  7028. #if PY_MAJOR_VERSION >= 3
  7029. if (unlikely(value == NULL || !PyUnicode_Check(value))) {
  7030. #else
  7031. if (unlikely(value == NULL || !PyString_Check(value))) {
  7032. #endif
  7033. PyErr_SetString(PyExc_TypeError,
  7034. "__qualname__ must be set to a string object");
  7035. return -1;
  7036. }
  7037. tmp = op->func_qualname;
  7038. Py_INCREF(value);
  7039. op->func_qualname = value;
  7040. Py_XDECREF(tmp);
  7041. return 0;
  7042. }
  7043. static PyObject *
  7044. __Pyx_CyFunction_get_self(__pyx_CyFunctionObject *m, CYTHON_UNUSED void *closure)
  7045. {
  7046. PyObject *self;
  7047. self = m->func_closure;
  7048. if (self == NULL)
  7049. self = Py_None;
  7050. Py_INCREF(self);
  7051. return self;
  7052. }
  7053. static PyObject *
  7054. __Pyx_CyFunction_get_dict(__pyx_CyFunctionObject *op)
  7055. {
  7056. if (unlikely(op->func_dict == NULL)) {
  7057. op->func_dict = PyDict_New();
  7058. if (unlikely(op->func_dict == NULL))
  7059. return NULL;
  7060. }
  7061. Py_INCREF(op->func_dict);
  7062. return op->func_dict;
  7063. }
  7064. static int
  7065. __Pyx_CyFunction_set_dict(__pyx_CyFunctionObject *op, PyObject *value)
  7066. {
  7067. PyObject *tmp;
  7068. if (unlikely(value == NULL)) {
  7069. PyErr_SetString(PyExc_TypeError,
  7070. "function's dictionary may not be deleted");
  7071. return -1;
  7072. }
  7073. if (unlikely(!PyDict_Check(value))) {
  7074. PyErr_SetString(PyExc_TypeError,
  7075. "setting function's dictionary to a non-dict");
  7076. return -1;
  7077. }
  7078. tmp = op->func_dict;
  7079. Py_INCREF(value);
  7080. op->func_dict = value;
  7081. Py_XDECREF(tmp);
  7082. return 0;
  7083. }
  7084. static PyObject *
  7085. __Pyx_CyFunction_get_globals(__pyx_CyFunctionObject *op)
  7086. {
  7087. Py_INCREF(op->func_globals);
  7088. return op->func_globals;
  7089. }
  7090. static PyObject *
  7091. __Pyx_CyFunction_get_closure(CYTHON_UNUSED __pyx_CyFunctionObject *op)
  7092. {
  7093. Py_INCREF(Py_None);
  7094. return Py_None;
  7095. }
  7096. static PyObject *
  7097. __Pyx_CyFunction_get_code(__pyx_CyFunctionObject *op)
  7098. {
  7099. PyObject* result = (op->func_code) ? op->func_code : Py_None;
  7100. Py_INCREF(result);
  7101. return result;
  7102. }
  7103. static int
  7104. __Pyx_CyFunction_init_defaults(__pyx_CyFunctionObject *op) {
  7105. int result = 0;
  7106. PyObject *res = op->defaults_getter((PyObject *) op);
  7107. if (unlikely(!res))
  7108. return -1;
  7109. #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
  7110. op->defaults_tuple = PyTuple_GET_ITEM(res, 0);
  7111. Py_INCREF(op->defaults_tuple);
  7112. op->defaults_kwdict = PyTuple_GET_ITEM(res, 1);
  7113. Py_INCREF(op->defaults_kwdict);
  7114. #else
  7115. op->defaults_tuple = PySequence_ITEM(res, 0);
  7116. if (unlikely(!op->defaults_tuple)) result = -1;
  7117. else {
  7118. op->defaults_kwdict = PySequence_ITEM(res, 1);
  7119. if (unlikely(!op->defaults_kwdict)) result = -1;
  7120. }
  7121. #endif
  7122. Py_DECREF(res);
  7123. return result;
  7124. }
  7125. static int
  7126. __Pyx_CyFunction_set_defaults(__pyx_CyFunctionObject *op, PyObject* value) {
  7127. PyObject* tmp;
  7128. if (!value) {
  7129. value = Py_None;
  7130. } else if (value != Py_None && !PyTuple_Check(value)) {
  7131. PyErr_SetString(PyExc_TypeError,
  7132. "__defaults__ must be set to a tuple object");
  7133. return -1;
  7134. }
  7135. Py_INCREF(value);
  7136. tmp = op->defaults_tuple;
  7137. op->defaults_tuple = value;
  7138. Py_XDECREF(tmp);
  7139. return 0;
  7140. }
  7141. static PyObject *
  7142. __Pyx_CyFunction_get_defaults(__pyx_CyFunctionObject *op) {
  7143. PyObject* result = op->defaults_tuple;
  7144. if (unlikely(!result)) {
  7145. if (op->defaults_getter) {
  7146. if (__Pyx_CyFunction_init_defaults(op) < 0) return NULL;
  7147. result = op->defaults_tuple;
  7148. } else {
  7149. result = Py_None;
  7150. }
  7151. }
  7152. Py_INCREF(result);
  7153. return result;
  7154. }
  7155. static int
  7156. __Pyx_CyFunction_set_kwdefaults(__pyx_CyFunctionObject *op, PyObject* value) {
  7157. PyObject* tmp;
  7158. if (!value) {
  7159. value = Py_None;
  7160. } else if (value != Py_None && !PyDict_Check(value)) {
  7161. PyErr_SetString(PyExc_TypeError,
  7162. "__kwdefaults__ must be set to a dict object");
  7163. return -1;
  7164. }
  7165. Py_INCREF(value);
  7166. tmp = op->defaults_kwdict;
  7167. op->defaults_kwdict = value;
  7168. Py_XDECREF(tmp);
  7169. return 0;
  7170. }
  7171. static PyObject *
  7172. __Pyx_CyFunction_get_kwdefaults(__pyx_CyFunctionObject *op) {
  7173. PyObject* result = op->defaults_kwdict;
  7174. if (unlikely(!result)) {
  7175. if (op->defaults_getter) {
  7176. if (__Pyx_CyFunction_init_defaults(op) < 0) return NULL;
  7177. result = op->defaults_kwdict;
  7178. } else {
  7179. result = Py_None;
  7180. }
  7181. }
  7182. Py_INCREF(result);
  7183. return result;
  7184. }
  7185. static int
  7186. __Pyx_CyFunction_set_annotations(__pyx_CyFunctionObject *op, PyObject* value) {
  7187. PyObject* tmp;
  7188. if (!value || value == Py_None) {
  7189. value = NULL;
  7190. } else if (!PyDict_Check(value)) {
  7191. PyErr_SetString(PyExc_TypeError,
  7192. "__annotations__ must be set to a dict object");
  7193. return -1;
  7194. }
  7195. Py_XINCREF(value);
  7196. tmp = op->func_annotations;
  7197. op->func_annotations = value;
  7198. Py_XDECREF(tmp);
  7199. return 0;
  7200. }
  7201. static PyObject *
  7202. __Pyx_CyFunction_get_annotations(__pyx_CyFunctionObject *op) {
  7203. PyObject* result = op->func_annotations;
  7204. if (unlikely(!result)) {
  7205. result = PyDict_New();
  7206. if (unlikely(!result)) return NULL;
  7207. op->func_annotations = result;
  7208. }
  7209. Py_INCREF(result);
  7210. return result;
  7211. }
  7212. static PyGetSetDef __pyx_CyFunction_getsets[] = {
  7213. {(char *) "func_doc", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0},
  7214. {(char *) "__doc__", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0},
  7215. {(char *) "func_name", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0},
  7216. {(char *) "__name__", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0},
  7217. {(char *) "__qualname__", (getter)__Pyx_CyFunction_get_qualname, (setter)__Pyx_CyFunction_set_qualname, 0, 0},
  7218. {(char *) "__self__", (getter)__Pyx_CyFunction_get_self, 0, 0, 0},
  7219. {(char *) "func_dict", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0},
  7220. {(char *) "__dict__", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0},
  7221. {(char *) "func_globals", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0},
  7222. {(char *) "__globals__", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0},
  7223. {(char *) "func_closure", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0},
  7224. {(char *) "__closure__", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0},
  7225. {(char *) "func_code", (getter)__Pyx_CyFunction_get_code, 0, 0, 0},
  7226. {(char *) "__code__", (getter)__Pyx_CyFunction_get_code, 0, 0, 0},
  7227. {(char *) "func_defaults", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0},
  7228. {(char *) "__defaults__", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0},
  7229. {(char *) "__kwdefaults__", (getter)__Pyx_CyFunction_get_kwdefaults, (setter)__Pyx_CyFunction_set_kwdefaults, 0, 0},
  7230. {(char *) "__annotations__", (getter)__Pyx_CyFunction_get_annotations, (setter)__Pyx_CyFunction_set_annotations, 0, 0},
  7231. {0, 0, 0, 0, 0}
  7232. };
  7233. static PyMemberDef __pyx_CyFunction_members[] = {
  7234. {(char *) "__module__", T_OBJECT, offsetof(__pyx_CyFunctionObject, func.m_module), PY_WRITE_RESTRICTED, 0},
  7235. {0, 0, 0, 0, 0}
  7236. };
  7237. static PyObject *
  7238. __Pyx_CyFunction_reduce(__pyx_CyFunctionObject *m, CYTHON_UNUSED PyObject *args)
  7239. {
  7240. #if PY_MAJOR_VERSION >= 3
  7241. return PyUnicode_FromString(m->func.m_ml->ml_name);
  7242. #else
  7243. return PyString_FromString(m->func.m_ml->ml_name);
  7244. #endif
  7245. }
  7246. static PyMethodDef __pyx_CyFunction_methods[] = {
  7247. {"__reduce__", (PyCFunction)__Pyx_CyFunction_reduce, METH_VARARGS, 0},
  7248. {0, 0, 0, 0}
  7249. };
  7250. #if PY_VERSION_HEX < 0x030500A0
  7251. #define __Pyx_CyFunction_weakreflist(cyfunc) ((cyfunc)->func_weakreflist)
  7252. #else
  7253. #define __Pyx_CyFunction_weakreflist(cyfunc) ((cyfunc)->func.m_weakreflist)
  7254. #endif
  7255. static PyObject *__Pyx_CyFunction_New(PyTypeObject *type, PyMethodDef *ml, int flags, PyObject* qualname,
  7256. PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) {
  7257. __pyx_CyFunctionObject *op = PyObject_GC_New(__pyx_CyFunctionObject, type);
  7258. if (op == NULL)
  7259. return NULL;
  7260. op->flags = flags;
  7261. __Pyx_CyFunction_weakreflist(op) = NULL;
  7262. op->func.m_ml = ml;
  7263. op->func.m_self = (PyObject *) op;
  7264. Py_XINCREF(closure);
  7265. op->func_closure = closure;
  7266. Py_XINCREF(module);
  7267. op->func.m_module = module;
  7268. op->func_dict = NULL;
  7269. op->func_name = NULL;
  7270. Py_INCREF(qualname);
  7271. op->func_qualname = qualname;
  7272. op->func_doc = NULL;
  7273. op->func_classobj = NULL;
  7274. op->func_globals = globals;
  7275. Py_INCREF(op->func_globals);
  7276. Py_XINCREF(code);
  7277. op->func_code = code;
  7278. op->defaults_pyobjects = 0;
  7279. op->defaults = NULL;
  7280. op->defaults_tuple = NULL;
  7281. op->defaults_kwdict = NULL;
  7282. op->defaults_getter = NULL;
  7283. op->func_annotations = NULL;
  7284. PyObject_GC_Track(op);
  7285. return (PyObject *) op;
  7286. }
  7287. static int
  7288. __Pyx_CyFunction_clear(__pyx_CyFunctionObject *m)
  7289. {
  7290. Py_CLEAR(m->func_closure);
  7291. Py_CLEAR(m->func.m_module);
  7292. Py_CLEAR(m->func_dict);
  7293. Py_CLEAR(m->func_name);
  7294. Py_CLEAR(m->func_qualname);
  7295. Py_CLEAR(m->func_doc);
  7296. Py_CLEAR(m->func_globals);
  7297. Py_CLEAR(m->func_code);
  7298. Py_CLEAR(m->func_classobj);
  7299. Py_CLEAR(m->defaults_tuple);
  7300. Py_CLEAR(m->defaults_kwdict);
  7301. Py_CLEAR(m->func_annotations);
  7302. if (m->defaults) {
  7303. PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m);
  7304. int i;
  7305. for (i = 0; i < m->defaults_pyobjects; i++)
  7306. Py_XDECREF(pydefaults[i]);
  7307. PyObject_Free(m->defaults);
  7308. m->defaults = NULL;
  7309. }
  7310. return 0;
  7311. }
  7312. static void __Pyx_CyFunction_dealloc(__pyx_CyFunctionObject *m)
  7313. {
  7314. PyObject_GC_UnTrack(m);
  7315. if (__Pyx_CyFunction_weakreflist(m) != NULL)
  7316. PyObject_ClearWeakRefs((PyObject *) m);
  7317. __Pyx_CyFunction_clear(m);
  7318. PyObject_GC_Del(m);
  7319. }
  7320. static int __Pyx_CyFunction_traverse(__pyx_CyFunctionObject *m, visitproc visit, void *arg)
  7321. {
  7322. Py_VISIT(m->func_closure);
  7323. Py_VISIT(m->func.m_module);
  7324. Py_VISIT(m->func_dict);
  7325. Py_VISIT(m->func_name);
  7326. Py_VISIT(m->func_qualname);
  7327. Py_VISIT(m->func_doc);
  7328. Py_VISIT(m->func_globals);
  7329. Py_VISIT(m->func_code);
  7330. Py_VISIT(m->func_classobj);
  7331. Py_VISIT(m->defaults_tuple);
  7332. Py_VISIT(m->defaults_kwdict);
  7333. if (m->defaults) {
  7334. PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m);
  7335. int i;
  7336. for (i = 0; i < m->defaults_pyobjects; i++)
  7337. Py_VISIT(pydefaults[i]);
  7338. }
  7339. return 0;
  7340. }
  7341. static PyObject *__Pyx_CyFunction_descr_get(PyObject *func, PyObject *obj, PyObject *type)
  7342. {
  7343. __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
  7344. if (m->flags & __Pyx_CYFUNCTION_STATICMETHOD) {
  7345. Py_INCREF(func);
  7346. return func;
  7347. }
  7348. if (m->flags & __Pyx_CYFUNCTION_CLASSMETHOD) {
  7349. if (type == NULL)
  7350. type = (PyObject *)(Py_TYPE(obj));
  7351. return __Pyx_PyMethod_New(func, type, (PyObject *)(Py_TYPE(type)));
  7352. }
  7353. if (obj == Py_None)
  7354. obj = NULL;
  7355. return __Pyx_PyMethod_New(func, obj, type);
  7356. }
  7357. static PyObject*
  7358. __Pyx_CyFunction_repr(__pyx_CyFunctionObject *op)
  7359. {
  7360. #if PY_MAJOR_VERSION >= 3
  7361. return PyUnicode_FromFormat("<cyfunction %U at %p>",
  7362. op->func_qualname, (void *)op);
  7363. #else
  7364. return PyString_FromFormat("<cyfunction %s at %p>",
  7365. PyString_AsString(op->func_qualname), (void *)op);
  7366. #endif
  7367. }
  7368. static PyObject * __Pyx_CyFunction_CallMethod(PyObject *func, PyObject *self, PyObject *arg, PyObject *kw) {
  7369. PyCFunctionObject* f = (PyCFunctionObject*)func;
  7370. PyCFunction meth = f->m_ml->ml_meth;
  7371. Py_ssize_t size;
  7372. switch (f->m_ml->ml_flags & (METH_VARARGS | METH_KEYWORDS | METH_NOARGS | METH_O)) {
  7373. case METH_VARARGS:
  7374. if (likely(kw == NULL || PyDict_Size(kw) == 0))
  7375. return (*meth)(self, arg);
  7376. break;
  7377. case METH_VARARGS | METH_KEYWORDS:
  7378. return (*(PyCFunctionWithKeywords)meth)(self, arg, kw);
  7379. case METH_NOARGS:
  7380. if (likely(kw == NULL || PyDict_Size(kw) == 0)) {
  7381. size = PyTuple_GET_SIZE(arg);
  7382. if (likely(size == 0))
  7383. return (*meth)(self, NULL);
  7384. PyErr_Format(PyExc_TypeError,
  7385. "%.200s() takes no arguments (%" CYTHON_FORMAT_SSIZE_T "d given)",
  7386. f->m_ml->ml_name, size);
  7387. return NULL;
  7388. }
  7389. break;
  7390. case METH_O:
  7391. if (likely(kw == NULL || PyDict_Size(kw) == 0)) {
  7392. size = PyTuple_GET_SIZE(arg);
  7393. if (likely(size == 1)) {
  7394. PyObject *result, *arg0 = PySequence_ITEM(arg, 0);
  7395. if (unlikely(!arg0)) return NULL;
  7396. result = (*meth)(self, arg0);
  7397. Py_DECREF(arg0);
  7398. return result;
  7399. }
  7400. PyErr_Format(PyExc_TypeError,
  7401. "%.200s() takes exactly one argument (%" CYTHON_FORMAT_SSIZE_T "d given)",
  7402. f->m_ml->ml_name, size);
  7403. return NULL;
  7404. }
  7405. break;
  7406. default:
  7407. PyErr_SetString(PyExc_SystemError, "Bad call flags in "
  7408. "__Pyx_CyFunction_Call. METH_OLDARGS is no "
  7409. "longer supported!");
  7410. return NULL;
  7411. }
  7412. PyErr_Format(PyExc_TypeError, "%.200s() takes no keyword arguments",
  7413. f->m_ml->ml_name);
  7414. return NULL;
  7415. }
  7416. static CYTHON_INLINE PyObject *__Pyx_CyFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) {
  7417. return __Pyx_CyFunction_CallMethod(func, ((PyCFunctionObject*)func)->m_self, arg, kw);
  7418. }
  7419. static PyObject *__Pyx_CyFunction_CallAsMethod(PyObject *func, PyObject *args, PyObject *kw) {
  7420. PyObject *result;
  7421. __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *) func;
  7422. if ((cyfunc->flags & __Pyx_CYFUNCTION_CCLASS) && !(cyfunc->flags & __Pyx_CYFUNCTION_STATICMETHOD)) {
  7423. Py_ssize_t argc;
  7424. PyObject *new_args;
  7425. PyObject *self;
  7426. argc = PyTuple_GET_SIZE(args);
  7427. new_args = PyTuple_GetSlice(args, 1, argc);
  7428. if (unlikely(!new_args))
  7429. return NULL;
  7430. self = PyTuple_GetItem(args, 0);
  7431. if (unlikely(!self)) {
  7432. Py_DECREF(new_args);
  7433. return NULL;
  7434. }
  7435. result = __Pyx_CyFunction_CallMethod(func, self, new_args, kw);
  7436. Py_DECREF(new_args);
  7437. } else {
  7438. result = __Pyx_CyFunction_Call(func, args, kw);
  7439. }
  7440. return result;
  7441. }
  7442. static PyTypeObject __pyx_CyFunctionType_type = {
  7443. PyVarObject_HEAD_INIT(0, 0)
  7444. "cython_function_or_method",
  7445. sizeof(__pyx_CyFunctionObject),
  7446. 0,
  7447. (destructor) __Pyx_CyFunction_dealloc,
  7448. 0,
  7449. 0,
  7450. 0,
  7451. #if PY_MAJOR_VERSION < 3
  7452. 0,
  7453. #else
  7454. 0,
  7455. #endif
  7456. (reprfunc) __Pyx_CyFunction_repr,
  7457. 0,
  7458. 0,
  7459. 0,
  7460. 0,
  7461. __Pyx_CyFunction_CallAsMethod,
  7462. 0,
  7463. 0,
  7464. 0,
  7465. 0,
  7466. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
  7467. 0,
  7468. (traverseproc) __Pyx_CyFunction_traverse,
  7469. (inquiry) __Pyx_CyFunction_clear,
  7470. 0,
  7471. #if PY_VERSION_HEX < 0x030500A0
  7472. offsetof(__pyx_CyFunctionObject, func_weakreflist),
  7473. #else
  7474. offsetof(PyCFunctionObject, m_weakreflist),
  7475. #endif
  7476. 0,
  7477. 0,
  7478. __pyx_CyFunction_methods,
  7479. __pyx_CyFunction_members,
  7480. __pyx_CyFunction_getsets,
  7481. 0,
  7482. 0,
  7483. __Pyx_CyFunction_descr_get,
  7484. 0,
  7485. offsetof(__pyx_CyFunctionObject, func_dict),
  7486. 0,
  7487. 0,
  7488. 0,
  7489. 0,
  7490. 0,
  7491. 0,
  7492. 0,
  7493. 0,
  7494. 0,
  7495. 0,
  7496. 0,
  7497. 0,
  7498. #if PY_VERSION_HEX >= 0x030400a1
  7499. 0,
  7500. #endif
  7501. };
  7502. static int __pyx_CyFunction_init(void) {
  7503. __pyx_CyFunctionType = __Pyx_FetchCommonType(&__pyx_CyFunctionType_type);
  7504. if (__pyx_CyFunctionType == NULL) {
  7505. return -1;
  7506. }
  7507. return 0;
  7508. }
  7509. static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *func, size_t size, int pyobjects) {
  7510. __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
  7511. m->defaults = PyObject_Malloc(size);
  7512. if (!m->defaults)
  7513. return PyErr_NoMemory();
  7514. memset(m->defaults, 0, size);
  7515. m->defaults_pyobjects = pyobjects;
  7516. return m->defaults;
  7517. }
  7518. static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *func, PyObject *tuple) {
  7519. __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
  7520. m->defaults_tuple = tuple;
  7521. Py_INCREF(tuple);
  7522. }
  7523. static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *func, PyObject *dict) {
  7524. __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
  7525. m->defaults_kwdict = dict;
  7526. Py_INCREF(dict);
  7527. }
  7528. static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *func, PyObject *dict) {
  7529. __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
  7530. m->func_annotations = dict;
  7531. Py_INCREF(dict);
  7532. }
  7533. /* GetNameInClass */
  7534. static PyObject *__Pyx_GetNameInClass(PyObject *nmspace, PyObject *name) {
  7535. PyObject *result;
  7536. result = __Pyx_PyObject_GetAttrStr(nmspace, name);
  7537. if (!result)
  7538. result = __Pyx_GetModuleGlobalName(name);
  7539. return result;
  7540. }
  7541. /* CodeObjectCache */
  7542. static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
  7543. int start = 0, mid = 0, end = count - 1;
  7544. if (end >= 0 && code_line > entries[end].code_line) {
  7545. return count;
  7546. }
  7547. while (start < end) {
  7548. mid = start + (end - start) / 2;
  7549. if (code_line < entries[mid].code_line) {
  7550. end = mid;
  7551. } else if (code_line > entries[mid].code_line) {
  7552. start = mid + 1;
  7553. } else {
  7554. return mid;
  7555. }
  7556. }
  7557. if (code_line <= entries[mid].code_line) {
  7558. return mid;
  7559. } else {
  7560. return mid + 1;
  7561. }
  7562. }
  7563. static PyCodeObject *__pyx_find_code_object(int code_line) {
  7564. PyCodeObject* code_object;
  7565. int pos;
  7566. if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
  7567. return NULL;
  7568. }
  7569. pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
  7570. if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
  7571. return NULL;
  7572. }
  7573. code_object = __pyx_code_cache.entries[pos].code_object;
  7574. Py_INCREF(code_object);
  7575. return code_object;
  7576. }
  7577. static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
  7578. int pos, i;
  7579. __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
  7580. if (unlikely(!code_line)) {
  7581. return;
  7582. }
  7583. if (unlikely(!entries)) {
  7584. entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
  7585. if (likely(entries)) {
  7586. __pyx_code_cache.entries = entries;
  7587. __pyx_code_cache.max_count = 64;
  7588. __pyx_code_cache.count = 1;
  7589. entries[0].code_line = code_line;
  7590. entries[0].code_object = code_object;
  7591. Py_INCREF(code_object);
  7592. }
  7593. return;
  7594. }
  7595. pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
  7596. if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
  7597. PyCodeObject* tmp = entries[pos].code_object;
  7598. entries[pos].code_object = code_object;
  7599. Py_DECREF(tmp);
  7600. return;
  7601. }
  7602. if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
  7603. int new_max = __pyx_code_cache.max_count + 64;
  7604. entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
  7605. __pyx_code_cache.entries, (size_t)new_max*sizeof(__Pyx_CodeObjectCacheEntry));
  7606. if (unlikely(!entries)) {
  7607. return;
  7608. }
  7609. __pyx_code_cache.entries = entries;
  7610. __pyx_code_cache.max_count = new_max;
  7611. }
  7612. for (i=__pyx_code_cache.count; i>pos; i--) {
  7613. entries[i] = entries[i-1];
  7614. }
  7615. entries[pos].code_line = code_line;
  7616. entries[pos].code_object = code_object;
  7617. __pyx_code_cache.count++;
  7618. Py_INCREF(code_object);
  7619. }
  7620. /* AddTraceback */
  7621. #include "compile.h"
  7622. #include "frameobject.h"
  7623. #include "traceback.h"
  7624. static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
  7625. const char *funcname, int c_line,
  7626. int py_line, const char *filename) {
  7627. PyCodeObject *py_code = 0;
  7628. PyObject *py_srcfile = 0;
  7629. PyObject *py_funcname = 0;
  7630. #if PY_MAJOR_VERSION < 3
  7631. py_srcfile = PyString_FromString(filename);
  7632. #else
  7633. py_srcfile = PyUnicode_FromString(filename);
  7634. #endif
  7635. if (!py_srcfile) goto bad;
  7636. if (c_line) {
  7637. #if PY_MAJOR_VERSION < 3
  7638. py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
  7639. #else
  7640. py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
  7641. #endif
  7642. }
  7643. else {
  7644. #if PY_MAJOR_VERSION < 3
  7645. py_funcname = PyString_FromString(funcname);
  7646. #else
  7647. py_funcname = PyUnicode_FromString(funcname);
  7648. #endif
  7649. }
  7650. if (!py_funcname) goto bad;
  7651. py_code = __Pyx_PyCode_New(
  7652. 0,
  7653. 0,
  7654. 0,
  7655. 0,
  7656. 0,
  7657. __pyx_empty_bytes, /*PyObject *code,*/
  7658. __pyx_empty_tuple, /*PyObject *consts,*/
  7659. __pyx_empty_tuple, /*PyObject *names,*/
  7660. __pyx_empty_tuple, /*PyObject *varnames,*/
  7661. __pyx_empty_tuple, /*PyObject *freevars,*/
  7662. __pyx_empty_tuple, /*PyObject *cellvars,*/
  7663. py_srcfile, /*PyObject *filename,*/
  7664. py_funcname, /*PyObject *name,*/
  7665. py_line,
  7666. __pyx_empty_bytes /*PyObject *lnotab*/
  7667. );
  7668. Py_DECREF(py_srcfile);
  7669. Py_DECREF(py_funcname);
  7670. return py_code;
  7671. bad:
  7672. Py_XDECREF(py_srcfile);
  7673. Py_XDECREF(py_funcname);
  7674. return NULL;
  7675. }
  7676. static void __Pyx_AddTraceback(const char *funcname, int c_line,
  7677. int py_line, const char *filename) {
  7678. PyCodeObject *py_code = 0;
  7679. PyFrameObject *py_frame = 0;
  7680. py_code = __pyx_find_code_object(c_line ? c_line : py_line);
  7681. if (!py_code) {
  7682. py_code = __Pyx_CreateCodeObjectForTraceback(
  7683. funcname, c_line, py_line, filename);
  7684. if (!py_code) goto bad;
  7685. __pyx_insert_code_object(c_line ? c_line : py_line, py_code);
  7686. }
  7687. py_frame = PyFrame_New(
  7688. PyThreadState_GET(), /*PyThreadState *tstate,*/
  7689. py_code, /*PyCodeObject *code,*/
  7690. __pyx_d, /*PyObject *globals,*/
  7691. 0 /*PyObject *locals*/
  7692. );
  7693. if (!py_frame) goto bad;
  7694. __Pyx_PyFrame_SetLineNumber(py_frame, py_line);
  7695. PyTraceBack_Here(py_frame);
  7696. bad:
  7697. Py_XDECREF(py_code);
  7698. Py_XDECREF(py_frame);
  7699. }
  7700. /* CIntFromPyVerify */
  7701. #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\
  7702. __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
  7703. #define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\
  7704. __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
  7705. #define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\
  7706. {\
  7707. func_type value = func_value;\
  7708. if (sizeof(target_type) < sizeof(func_type)) {\
  7709. if (unlikely(value != (func_type) (target_type) value)) {\
  7710. func_type zero = 0;\
  7711. if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\
  7712. return (target_type) -1;\
  7713. if (is_unsigned && unlikely(value < zero))\
  7714. goto raise_neg_overflow;\
  7715. else\
  7716. goto raise_overflow;\
  7717. }\
  7718. }\
  7719. return (target_type) value;\
  7720. }
  7721. /* CIntToPy */
  7722. static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
  7723. const int neg_one = (int) -1, const_zero = (int) 0;
  7724. const int is_unsigned = neg_one > const_zero;
  7725. if (is_unsigned) {
  7726. if (sizeof(int) < sizeof(long)) {
  7727. return PyInt_FromLong((long) value);
  7728. } else if (sizeof(int) <= sizeof(unsigned long)) {
  7729. return PyLong_FromUnsignedLong((unsigned long) value);
  7730. #ifdef HAVE_LONG_LONG
  7731. } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
  7732. return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
  7733. #endif
  7734. }
  7735. } else {
  7736. if (sizeof(int) <= sizeof(long)) {
  7737. return PyInt_FromLong((long) value);
  7738. #ifdef HAVE_LONG_LONG
  7739. } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
  7740. return PyLong_FromLongLong((PY_LONG_LONG) value);
  7741. #endif
  7742. }
  7743. }
  7744. {
  7745. int one = 1; int little = (int)*(unsigned char *)&one;
  7746. unsigned char *bytes = (unsigned char *)&value;
  7747. return _PyLong_FromByteArray(bytes, sizeof(int),
  7748. little, !is_unsigned);
  7749. }
  7750. }
  7751. /* CIntFromPy */
  7752. static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
  7753. const int neg_one = (int) -1, const_zero = (int) 0;
  7754. const int is_unsigned = neg_one > const_zero;
  7755. #if PY_MAJOR_VERSION < 3
  7756. if (likely(PyInt_Check(x))) {
  7757. if (sizeof(int) < sizeof(long)) {
  7758. __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x))
  7759. } else {
  7760. long val = PyInt_AS_LONG(x);
  7761. if (is_unsigned && unlikely(val < 0)) {
  7762. goto raise_neg_overflow;
  7763. }
  7764. return (int) val;
  7765. }
  7766. } else
  7767. #endif
  7768. if (likely(PyLong_Check(x))) {
  7769. if (is_unsigned) {
  7770. #if CYTHON_USE_PYLONG_INTERNALS
  7771. const digit* digits = ((PyLongObject*)x)->ob_digit;
  7772. switch (Py_SIZE(x)) {
  7773. case 0: return (int) 0;
  7774. case 1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0])
  7775. case 2:
  7776. if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
  7777. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  7778. __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  7779. } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) {
  7780. return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
  7781. }
  7782. }
  7783. break;
  7784. case 3:
  7785. if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
  7786. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  7787. __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  7788. } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) {
  7789. return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
  7790. }
  7791. }
  7792. break;
  7793. case 4:
  7794. if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
  7795. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  7796. __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])))
  7797. } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) {
  7798. return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
  7799. }
  7800. }
  7801. break;
  7802. }
  7803. #endif
  7804. #if CYTHON_COMPILING_IN_CPYTHON
  7805. if (unlikely(Py_SIZE(x) < 0)) {
  7806. goto raise_neg_overflow;
  7807. }
  7808. #else
  7809. {
  7810. int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
  7811. if (unlikely(result < 0))
  7812. return (int) -1;
  7813. if (unlikely(result == 1))
  7814. goto raise_neg_overflow;
  7815. }
  7816. #endif
  7817. if (sizeof(int) <= sizeof(unsigned long)) {
  7818. __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
  7819. #ifdef HAVE_LONG_LONG
  7820. } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
  7821. __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
  7822. #endif
  7823. }
  7824. } else {
  7825. #if CYTHON_USE_PYLONG_INTERNALS
  7826. const digit* digits = ((PyLongObject*)x)->ob_digit;
  7827. switch (Py_SIZE(x)) {
  7828. case 0: return (int) 0;
  7829. case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0]))
  7830. case 1: __PYX_VERIFY_RETURN_INT(int, digit, +digits[0])
  7831. case -2:
  7832. if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) {
  7833. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  7834. __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  7835. } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
  7836. return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
  7837. }
  7838. }
  7839. break;
  7840. case 2:
  7841. if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
  7842. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  7843. __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  7844. } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
  7845. return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
  7846. }
  7847. }
  7848. break;
  7849. case -3:
  7850. if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
  7851. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  7852. __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  7853. } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
  7854. return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
  7855. }
  7856. }
  7857. break;
  7858. case 3:
  7859. if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
  7860. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  7861. __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  7862. } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
  7863. return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
  7864. }
  7865. }
  7866. break;
  7867. case -4:
  7868. if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
  7869. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  7870. __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])))
  7871. } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
  7872. return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
  7873. }
  7874. }
  7875. break;
  7876. case 4:
  7877. if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
  7878. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  7879. __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])))
  7880. } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
  7881. return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
  7882. }
  7883. }
  7884. break;
  7885. }
  7886. #endif
  7887. if (sizeof(int) <= sizeof(long)) {
  7888. __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
  7889. #ifdef HAVE_LONG_LONG
  7890. } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
  7891. __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
  7892. #endif
  7893. }
  7894. }
  7895. {
  7896. #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
  7897. PyErr_SetString(PyExc_RuntimeError,
  7898. "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
  7899. #else
  7900. int val;
  7901. PyObject *v = __Pyx_PyNumber_IntOrLong(x);
  7902. #if PY_MAJOR_VERSION < 3
  7903. if (likely(v) && !PyLong_Check(v)) {
  7904. PyObject *tmp = v;
  7905. v = PyNumber_Long(tmp);
  7906. Py_DECREF(tmp);
  7907. }
  7908. #endif
  7909. if (likely(v)) {
  7910. int one = 1; int is_little = (int)*(unsigned char *)&one;
  7911. unsigned char *bytes = (unsigned char *)&val;
  7912. int ret = _PyLong_AsByteArray((PyLongObject *)v,
  7913. bytes, sizeof(val),
  7914. is_little, !is_unsigned);
  7915. Py_DECREF(v);
  7916. if (likely(!ret))
  7917. return val;
  7918. }
  7919. #endif
  7920. return (int) -1;
  7921. }
  7922. } else {
  7923. int val;
  7924. PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
  7925. if (!tmp) return (int) -1;
  7926. val = __Pyx_PyInt_As_int(tmp);
  7927. Py_DECREF(tmp);
  7928. return val;
  7929. }
  7930. raise_overflow:
  7931. PyErr_SetString(PyExc_OverflowError,
  7932. "value too large to convert to int");
  7933. return (int) -1;
  7934. raise_neg_overflow:
  7935. PyErr_SetString(PyExc_OverflowError,
  7936. "can't convert negative value to int");
  7937. return (int) -1;
  7938. }
  7939. /* CIntToPy */
  7940. static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
  7941. const long neg_one = (long) -1, const_zero = (long) 0;
  7942. const int is_unsigned = neg_one > const_zero;
  7943. if (is_unsigned) {
  7944. if (sizeof(long) < sizeof(long)) {
  7945. return PyInt_FromLong((long) value);
  7946. } else if (sizeof(long) <= sizeof(unsigned long)) {
  7947. return PyLong_FromUnsignedLong((unsigned long) value);
  7948. #ifdef HAVE_LONG_LONG
  7949. } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
  7950. return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
  7951. #endif
  7952. }
  7953. } else {
  7954. if (sizeof(long) <= sizeof(long)) {
  7955. return PyInt_FromLong((long) value);
  7956. #ifdef HAVE_LONG_LONG
  7957. } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
  7958. return PyLong_FromLongLong((PY_LONG_LONG) value);
  7959. #endif
  7960. }
  7961. }
  7962. {
  7963. int one = 1; int little = (int)*(unsigned char *)&one;
  7964. unsigned char *bytes = (unsigned char *)&value;
  7965. return _PyLong_FromByteArray(bytes, sizeof(long),
  7966. little, !is_unsigned);
  7967. }
  7968. }
  7969. /* CIntFromPy */
  7970. static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
  7971. const long neg_one = (long) -1, const_zero = (long) 0;
  7972. const int is_unsigned = neg_one > const_zero;
  7973. #if PY_MAJOR_VERSION < 3
  7974. if (likely(PyInt_Check(x))) {
  7975. if (sizeof(long) < sizeof(long)) {
  7976. __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x))
  7977. } else {
  7978. long val = PyInt_AS_LONG(x);
  7979. if (is_unsigned && unlikely(val < 0)) {
  7980. goto raise_neg_overflow;
  7981. }
  7982. return (long) val;
  7983. }
  7984. } else
  7985. #endif
  7986. if (likely(PyLong_Check(x))) {
  7987. if (is_unsigned) {
  7988. #if CYTHON_USE_PYLONG_INTERNALS
  7989. const digit* digits = ((PyLongObject*)x)->ob_digit;
  7990. switch (Py_SIZE(x)) {
  7991. case 0: return (long) 0;
  7992. case 1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0])
  7993. case 2:
  7994. if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
  7995. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  7996. __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  7997. } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) {
  7998. return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
  7999. }
  8000. }
  8001. break;
  8002. case 3:
  8003. if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
  8004. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  8005. __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  8006. } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) {
  8007. return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
  8008. }
  8009. }
  8010. break;
  8011. case 4:
  8012. if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
  8013. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  8014. __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])))
  8015. } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) {
  8016. return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
  8017. }
  8018. }
  8019. break;
  8020. }
  8021. #endif
  8022. #if CYTHON_COMPILING_IN_CPYTHON
  8023. if (unlikely(Py_SIZE(x) < 0)) {
  8024. goto raise_neg_overflow;
  8025. }
  8026. #else
  8027. {
  8028. int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
  8029. if (unlikely(result < 0))
  8030. return (long) -1;
  8031. if (unlikely(result == 1))
  8032. goto raise_neg_overflow;
  8033. }
  8034. #endif
  8035. if (sizeof(long) <= sizeof(unsigned long)) {
  8036. __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
  8037. #ifdef HAVE_LONG_LONG
  8038. } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
  8039. __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
  8040. #endif
  8041. }
  8042. } else {
  8043. #if CYTHON_USE_PYLONG_INTERNALS
  8044. const digit* digits = ((PyLongObject*)x)->ob_digit;
  8045. switch (Py_SIZE(x)) {
  8046. case 0: return (long) 0;
  8047. case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0]))
  8048. case 1: __PYX_VERIFY_RETURN_INT(long, digit, +digits[0])
  8049. case -2:
  8050. if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) {
  8051. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  8052. __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  8053. } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
  8054. return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
  8055. }
  8056. }
  8057. break;
  8058. case 2:
  8059. if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
  8060. if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
  8061. __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  8062. } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
  8063. return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
  8064. }
  8065. }
  8066. break;
  8067. case -3:
  8068. if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
  8069. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  8070. __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  8071. } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
  8072. return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
  8073. }
  8074. }
  8075. break;
  8076. case 3:
  8077. if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
  8078. if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
  8079. __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
  8080. } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
  8081. return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
  8082. }
  8083. }
  8084. break;
  8085. case -4:
  8086. if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
  8087. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  8088. __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])))
  8089. } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
  8090. return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
  8091. }
  8092. }
  8093. break;
  8094. case 4:
  8095. if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
  8096. if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
  8097. __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])))
  8098. } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
  8099. return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
  8100. }
  8101. }
  8102. break;
  8103. }
  8104. #endif
  8105. if (sizeof(long) <= sizeof(long)) {
  8106. __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
  8107. #ifdef HAVE_LONG_LONG
  8108. } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
  8109. __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
  8110. #endif
  8111. }
  8112. }
  8113. {
  8114. #if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
  8115. PyErr_SetString(PyExc_RuntimeError,
  8116. "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
  8117. #else
  8118. long val;
  8119. PyObject *v = __Pyx_PyNumber_IntOrLong(x);
  8120. #if PY_MAJOR_VERSION < 3
  8121. if (likely(v) && !PyLong_Check(v)) {
  8122. PyObject *tmp = v;
  8123. v = PyNumber_Long(tmp);
  8124. Py_DECREF(tmp);
  8125. }
  8126. #endif
  8127. if (likely(v)) {
  8128. int one = 1; int is_little = (int)*(unsigned char *)&one;
  8129. unsigned char *bytes = (unsigned char *)&val;
  8130. int ret = _PyLong_AsByteArray((PyLongObject *)v,
  8131. bytes, sizeof(val),
  8132. is_little, !is_unsigned);
  8133. Py_DECREF(v);
  8134. if (likely(!ret))
  8135. return val;
  8136. }
  8137. #endif
  8138. return (long) -1;
  8139. }
  8140. } else {
  8141. long val;
  8142. PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
  8143. if (!tmp) return (long) -1;
  8144. val = __Pyx_PyInt_As_long(tmp);
  8145. Py_DECREF(tmp);
  8146. return val;
  8147. }
  8148. raise_overflow:
  8149. PyErr_SetString(PyExc_OverflowError,
  8150. "value too large to convert to long");
  8151. return (long) -1;
  8152. raise_neg_overflow:
  8153. PyErr_SetString(PyExc_OverflowError,
  8154. "can't convert negative value to long");
  8155. return (long) -1;
  8156. }
  8157. /* CheckBinaryVersion */
  8158. static int __Pyx_check_binary_version(void) {
  8159. char ctversion[4], rtversion[4];
  8160. PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
  8161. PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
  8162. if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
  8163. char message[200];
  8164. PyOS_snprintf(message, sizeof(message),
  8165. "compiletime version %s of module '%.100s' "
  8166. "does not match runtime version %s",
  8167. ctversion, __Pyx_MODULE_NAME, rtversion);
  8168. return PyErr_WarnEx(NULL, message, 1);
  8169. }
  8170. return 0;
  8171. }
  8172. /* InitStrings */
  8173. static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
  8174. while (t->p) {
  8175. #if PY_MAJOR_VERSION < 3
  8176. if (t->is_unicode) {
  8177. *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
  8178. } else if (t->intern) {
  8179. *t->p = PyString_InternFromString(t->s);
  8180. } else {
  8181. *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
  8182. }
  8183. #else
  8184. if (t->is_unicode | t->is_str) {
  8185. if (t->intern) {
  8186. *t->p = PyUnicode_InternFromString(t->s);
  8187. } else if (t->encoding) {
  8188. *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
  8189. } else {
  8190. *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
  8191. }
  8192. } else {
  8193. *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
  8194. }
  8195. #endif
  8196. if (!*t->p)
  8197. return -1;
  8198. ++t;
  8199. }
  8200. return 0;
  8201. }
  8202. static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
  8203. return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str));
  8204. }
  8205. static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject* o) {
  8206. Py_ssize_t ignore;
  8207. return __Pyx_PyObject_AsStringAndSize(o, &ignore);
  8208. }
  8209. static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
  8210. #if CYTHON_COMPILING_IN_CPYTHON && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
  8211. if (
  8212. #if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
  8213. __Pyx_sys_getdefaultencoding_not_ascii &&
  8214. #endif
  8215. PyUnicode_Check(o)) {
  8216. #if PY_VERSION_HEX < 0x03030000
  8217. char* defenc_c;
  8218. PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL);
  8219. if (!defenc) return NULL;
  8220. defenc_c = PyBytes_AS_STRING(defenc);
  8221. #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
  8222. {
  8223. char* end = defenc_c + PyBytes_GET_SIZE(defenc);
  8224. char* c;
  8225. for (c = defenc_c; c < end; c++) {
  8226. if ((unsigned char) (*c) >= 128) {
  8227. PyUnicode_AsASCIIString(o);
  8228. return NULL;
  8229. }
  8230. }
  8231. }
  8232. #endif
  8233. *length = PyBytes_GET_SIZE(defenc);
  8234. return defenc_c;
  8235. #else
  8236. if (__Pyx_PyUnicode_READY(o) == -1) return NULL;
  8237. #if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
  8238. if (PyUnicode_IS_ASCII(o)) {
  8239. *length = PyUnicode_GET_LENGTH(o);
  8240. return PyUnicode_AsUTF8(o);
  8241. } else {
  8242. PyUnicode_AsASCIIString(o);
  8243. return NULL;
  8244. }
  8245. #else
  8246. return PyUnicode_AsUTF8AndSize(o, length);
  8247. #endif
  8248. #endif
  8249. } else
  8250. #endif
  8251. #if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
  8252. if (PyByteArray_Check(o)) {
  8253. *length = PyByteArray_GET_SIZE(o);
  8254. return PyByteArray_AS_STRING(o);
  8255. } else
  8256. #endif
  8257. {
  8258. char* result;
  8259. int r = PyBytes_AsStringAndSize(o, &result, length);
  8260. if (unlikely(r < 0)) {
  8261. return NULL;
  8262. } else {
  8263. return result;
  8264. }
  8265. }
  8266. }
  8267. static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
  8268. int is_true = x == Py_True;
  8269. if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
  8270. else return PyObject_IsTrue(x);
  8271. }
  8272. static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) {
  8273. #if CYTHON_USE_TYPE_SLOTS
  8274. PyNumberMethods *m;
  8275. #endif
  8276. const char *name = NULL;
  8277. PyObject *res = NULL;
  8278. #if PY_MAJOR_VERSION < 3
  8279. if (PyInt_Check(x) || PyLong_Check(x))
  8280. #else
  8281. if (PyLong_Check(x))
  8282. #endif
  8283. return __Pyx_NewRef(x);
  8284. #if CYTHON_USE_TYPE_SLOTS
  8285. m = Py_TYPE(x)->tp_as_number;
  8286. #if PY_MAJOR_VERSION < 3
  8287. if (m && m->nb_int) {
  8288. name = "int";
  8289. res = PyNumber_Int(x);
  8290. }
  8291. else if (m && m->nb_long) {
  8292. name = "long";
  8293. res = PyNumber_Long(x);
  8294. }
  8295. #else
  8296. if (m && m->nb_int) {
  8297. name = "int";
  8298. res = PyNumber_Long(x);
  8299. }
  8300. #endif
  8301. #else
  8302. res = PyNumber_Int(x);
  8303. #endif
  8304. if (res) {
  8305. #if PY_MAJOR_VERSION < 3
  8306. if (!PyInt_Check(res) && !PyLong_Check(res)) {
  8307. #else
  8308. if (!PyLong_Check(res)) {
  8309. #endif
  8310. PyErr_Format(PyExc_TypeError,
  8311. "__%.4s__ returned non-%.4s (type %.200s)",
  8312. name, name, Py_TYPE(res)->tp_name);
  8313. Py_DECREF(res);
  8314. return NULL;
  8315. }
  8316. }
  8317. else if (!PyErr_Occurred()) {
  8318. PyErr_SetString(PyExc_TypeError,
  8319. "an integer is required");
  8320. }
  8321. return res;
  8322. }
  8323. static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
  8324. Py_ssize_t ival;
  8325. PyObject *x;
  8326. #if PY_MAJOR_VERSION < 3
  8327. if (likely(PyInt_CheckExact(b))) {
  8328. if (sizeof(Py_ssize_t) >= sizeof(long))
  8329. return PyInt_AS_LONG(b);
  8330. else
  8331. return PyInt_AsSsize_t(x);
  8332. }
  8333. #endif
  8334. if (likely(PyLong_CheckExact(b))) {
  8335. #if CYTHON_USE_PYLONG_INTERNALS
  8336. const digit* digits = ((PyLongObject*)b)->ob_digit;
  8337. const Py_ssize_t size = Py_SIZE(b);
  8338. if (likely(__Pyx_sst_abs(size) <= 1)) {
  8339. ival = likely(size) ? digits[0] : 0;
  8340. if (size == -1) ival = -ival;
  8341. return ival;
  8342. } else {
  8343. switch (size) {
  8344. case 2:
  8345. if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
  8346. return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
  8347. }
  8348. break;
  8349. case -2:
  8350. if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
  8351. return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
  8352. }
  8353. break;
  8354. case 3:
  8355. if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
  8356. return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
  8357. }
  8358. break;
  8359. case -3:
  8360. if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
  8361. return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
  8362. }
  8363. break;
  8364. case 4:
  8365. if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
  8366. 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]));
  8367. }
  8368. break;
  8369. case -4:
  8370. if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
  8371. 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]));
  8372. }
  8373. break;
  8374. }
  8375. }
  8376. #endif
  8377. return PyLong_AsSsize_t(b);
  8378. }
  8379. x = PyNumber_Index(b);
  8380. if (!x) return -1;
  8381. ival = PyInt_AsSsize_t(x);
  8382. Py_DECREF(x);
  8383. return ival;
  8384. }
  8385. static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
  8386. return PyInt_FromSize_t(ival);
  8387. }
  8388. #endif /* Py_PYTHON_H */