123456789101112131415161718192021222324252627282930313233343536373839typet=intletleaked=-1letzero=0letone=1letppf=function|-1->Fmt.pff"rc=%a"Fmt.(styled`Redstring)"LEAKED"|0->Fmt.pff"rc=%a"Fmt.(styled`Redint)0|t->Fmt.pff"rc=%d"tletsum~pp:pp_objtd=ift>0then(lett'=t+dinift'<0then(ifd>0thenFmt.failwith"Ref-count %a + %d would wrap!"pptdpp_objelseFmt.failwith"Ref-count %a - %d would go negative!"ppt(-d)pp_obj);t')elseifd>=0then(Fmt.failwith"Attempt to change ref-count (to %a+%d) on freed resource %t"pptdpp_obj)else(Fmt.failwith"Attempt to change ref-count (to %a%d) on freed resource %t"pptdpp_obj)letsucc~ppt=sum~ppt1letpred~ppt=sum~ppt(-1)letis_zero=function|0->true|_->falseletcheck~ppt=ift<1thenDebug.invariant_broken(funf->Fmt.pff"Already unref'd! %t"pp)letto_intt=ift>=0thenSometelseNone