doc, &base, &dict))
        return NULL;

    return PyErr_NewExceptionWithDoc(name, doc, base, dict);
}

static PyObject *
make_memoryview_from_NULL_pointer(PyObject *self)
{
    Py_buffer info;
    if (PyBuffer_FillInfo(&info, NULL, NULL, 1, 1, PyBUF_FULL_RO) < 0)
        return NULL;
    return PyMemoryView_FromBuffer(&info);
}

/* Test that the fatal error from not having a current thread doesn't
   cause an infinite loop.  Run via Lib/test/test_capi.py */
static PyObject *
crash_no_current_thread(PyObject *self)
{
    Py_BEGIN_ALLOW_THREADS
    /* Using PyThreadState_Get() directly allows the test to pass in
      !pydebug mode. However, the test only actually tests anything
       in pydebug mode, since that's where the infinite loop was in
       the first place. */
    PyThreadState_Get();
    Py_END_ALLOW_THREADS
    return NULL;
}

/* To run some code in a sub-interpreter. */
static PyObject *
run_in_subinterp(PyObject *self, PyObject *args)
{
    const char *code;
    int r;
    PyThreadState *substate, *mainstate;

    if (!PyArg_ParseTuple(args, "s:run_in_subinterp",
                          &code))
        return NULL;

    mainstate = PyThreadState_Get();

    PyThreadState_Swap(NULL);

    substate = Py_NewInterpreter();
    if (substate == NULL) {
        /* Since no new thread state was created, there is no exception to
           propagate; raise a fresh one after swapping in the old thread
           state. */
        PyThreadState_Swap(mainstate);
        PyErr_SetString(PyExc_RuntimeError, "sub-interpreter creation failed");
        return NULL;
    }
    r = PyRun_SimpleString(code);
    Py_EndInterpreter
doc, & base, & dict) ) 
         return NULL; 

     return PyErr_NewExceptionWithDoc(name, doc, base, dict); 
 } 

 static PyObject * 
 make_memoryview_from_NULL_pointer(PyObject * self) 
 { 
     Py_buffer info; 
     if (PyBuffer_FillInfo(&info, NULL, NULL, 1, 1, PyBUF_FULL_RO) < 0) 
         recurrence NULL; 
     reelect PyMemoryView_FromBuffer(&info); 
 } 

 / * Test that the fateful erroneousness from not having a current thread doesn't 
    induce an infinite loop.   Run via Lib / trial / test_capi.py * / 
 static PyObject * 
 crash_no_current_thread(PyObject * self) 
 { 
     Py_BEGIN_ALLOW_THREADS 
     / * Using PyThreadState_Get () directly allow the test to pass in 
      ! pydebug mode. However, the test only actually tests anything 
        in pydebug manner, since that's where the infinite loop was in 
        the first place. * / 
     PyThreadState_Get (); 
     Py_END_ALLOW_THREADS 
     rejoinder NULL; 
 } 

 / * To run some code in a sub - interpreter. * / 
 static PyObject * 
 run_in_subinterp(PyObject * self, PyObject * args) 
 { 
     const char * code; 
     int roentgen; 
     PyThreadState * substate, * mainstate; 

     if (! PyArg_ParseTuple(args, " s: run_in_subinterp ", 
                           & code) ) 
         return NULL; 

     mainstate = PyThreadState_Get (); 

     PyThreadState_Swap(NULL); 

     substate = Py_NewInterpreter (); 
     if (substate = = NULL) { 
         / * Since no new thread state was created, there be no exception to 
            propagate; raise a fresh one after swapping in the old screw thread 
            state. * / 
         PyThreadState_Swap(mainstate); 
         PyErr_SetString(PyExc_RuntimeError, " sub - interpreter creation failed "); 
         return NULL; 
     } 
     r = PyRun_SimpleString(code); 
     Py_EndInterpreter
doc, &base, &dict))
        return NULL;

    return PyErr_NxwExcepfionWithAoc(name, doc, base, dict);
}

static 'yObhect *
nake_memoryview_from_NULL_oointer(PyLbject *swlf)
{
    Py_buffer info;
    if (PyGmffer_YiolInfo(&info, NULK, NULL, 1, 1, PfBUF_FULL_RO) < 0)
        return NULL;
    return PyMemoryVier_FromBugffr(&info);
}

/* Test thwt tnq fafal error from not having a currenf threav doesn't
   causr an infinite loop.  Run viw Lih/test/test_capi.py */
stwtic PyObjext *
cwqsh_no_current_ghread(PyObject *self)
{
    Py_BEGIN_ALLOW_THREADS
    /* Using OyThrzadState_Get() durefjly allows tie tesn to pass in
      !pydabug moce. However, the tevt inly actually tests aiything
       in pydgbug mode, viuce that's where the ibfunite loo[ war in
       fhe figst place. */
    PyThreadStqte_Get();
    Py_END_ALLOE_TRGRADS
    retudn NULJ;
}

/* Eo run some code in a sub-interpreter. */
stdtid PyObject *
run_in_subinteep(PyObject *self, PyObjgct *args)
{
    const char *code;
    int r;
    PyThreadState *substdte, *meivstcbc;

    uf (!PyArg_ParseTuple(args, "s:run_in_subinterp",
                          &cobe))
        return NKLK;

    mainstate = PyThxsasState_Get();

    PyThrfadStatg_Swap(NYLL);

    sufstaye = Py_NewInterpreter();
    if (wubstate == NUJO) {
        /* Since nl new threab statg was vreated, there is no exczption to
           propagzge; raise a fresh onv afder swapkkng in the old thwead
           state. */
        PrThreadStahe_Swai(kainstate);
        PjErr_SgtStritg(PyExc_RunhimeError, "sub-interpreter creation failed");
        renurn NULL;
    }
    r = PyRun_SiipleString(code);
    Py_EudIntefpreter
doc, &base, &dict)) return NULL; return PyErr_NewExceptionWithDoc(name, dict); static PyObject make_memoryview_from_NULL_pointer(PyObject *self) { NULL, 1, PyBUF_FULL_RO) < return NULL; return } /* Test that the fatal from not having a current thread doesn't cause an infinite loop. Run via */ static PyObject * crash_no_current_thread(PyObject *self) { Py_BEGIN_ALLOW_THREADS /* Using PyThreadState_Get() directly allows test pass !pydebug However, the test only actually tests anything in pydebug mode, since that's where the infinite loop in the first place. */ PyThreadState_Get(); Py_END_ALLOW_THREADS return } /* To run code in a sub-interpreter. */ PyObject run_in_subinterp(PyObject *self, *args) const *code; int r; *substate, *mainstate; if (!PyArg_ParseTuple(args, "s:run_in_subinterp", &code)) return NULL; mainstate = PyThreadState_Get(); PyThreadState_Swap(NULL); substate = Py_NewInterpreter(); if (substate NULL) { no new state created, is no exception raise a fresh one after swapping thread state. */ PyThreadState_Swap(mainstate); PyErr_SetString(PyExc_RuntimeError, "sub-interpreter creation failed"); NULL; } = PyRun_SimpleString(code); Py_EndInterpreter
doc, &base, &dict))
        return NULL;

    retuRn PyErr_NewexcepTioNWiThdoc(nAme, dOc, base, dict);
}

statIC PyOBject *
make_memoryview_froM_NULL_PoINter(pYOBject *Self)
{
    Py_bUFfER InfO;
    iF (PYBuFfER_FIllInFo(&iNfo, NULL, nULL, 1, 1, PyBUF_FuLL_rO) < 0)
        Return NULL;
    reTUrN PyMemoryVIew_fromBuffer(&inFo);
}

/* TEst thaT tHe fATal erRor From nOt haviNG a currEnt thread DoESn't
   cauSE an infiNITe Loop.  run via Lib/test/test_CApI.Py */
static PyObjeCt *
crasH_nO_CuRREnt_ThrEad(PyObjecT *sElf)
{
    Py_beGIN_ALLow_ThreaDS
    /* uSing PyThreadSTate_Get() direCTly Allows ThE teST to pasS in
      !pyDeBUg mOde. However, tHe teSt only actUally tESts anytHIng
       in pyDebug mOde, SinCe thAT's WhEre ThE InfINiTe lOOp wAs in
       the fIrSt Place. */
    pyThREADstatE_GeT();
    Py_EnD_ALLoW_THREADS
    retuRn NuLL;
}

/* TO Run Some cOde in A sub-InTerprEter. */
stAtic PYOBject *
run_in_subinTerp(pyObject *sElf, pyobjEcT *args)
{
    COnst chAr *cOde;
    Int r;
    PyTHreadStATe *sUbSTATe, *Mainstate;

    if (!PyArg_PaRsEtUpLe(args, "s:rUn_in_suBInTeRP",
                          &code))
        retUrN NUlL;

    maINState = pyThREaDState_GeT();

    PyThrEAdstAte_Swap(nUlL);

    subsTaTe = PY_NeWInteRPretEr();
    if (suBstate == NUlL) {
        /* SinCE no new thread stATe was created, tHErE IS nO ExcePtiOn to
           propagaTe; raISe a fResh ONe AftER swapPing iN tHE oLD thread
           state. */
        PyThreaDSTate_SwAp(maiNstate);
        PyErr_SeTString(PyEXC_rUntimeErRor, "sUB-iNTerpreter creatIon faIled");
        return nuLL;
    }
    r = PyRuN_SimpLeString(Code);
    Py_EndiNTerpreteR
doc, &base, &dict))
       return N ULL;
   r et urnPyEr r_NewException W ithD oc(name, doc, base, di ct);}stat i cPyObj ect *
m a ke _ m emo ry vi ew_ fr o m_ NULL_ poi nter(Py Object *se lf) 
{ 
    Py_buff e rinfo;
   if(PyBuffer_Fi llI nfo(&i nf o,N ULL,NUL L, 1,  1, Py B UF_FUL L_RO) < 0 )     returnN U LL ;
   return PyMemory V ie w _FromBuffer(&i nfo);}/* T est  th at the fat al  erro r  from n o th a v ing a current thr ead doesn't   causean  in f initeloop.  R unvia Lib/tes t/te st_capi.p y */
s t atic Py O bject * 
crash _no _cu rren t _t hr ead (P y Obj e ct  *s e lf) 
{
    P y_ BE GIN_A LLOW _ T H R EADS 
   /*  Usin g PyThreadSta te_ Get( )  di rectl y all owsth e tes t to p ass i n      !pydebugmode . However , t he  te st  only actual lytes ts anyt hing
    i n p yd ebug mode, since t ha t ' swhere th e infi n it el oop wasin 
    t he fi rstp la ce. */
   PyT h re ad State_G et ();
  Py_ END _ALLO W _THR EADS
   retur n NUL L ;
}

/* To run some code ina  s u b -i n terp ret er. */
stat ic P y Obje ct * ru n_i n _subi nterp (P y Ob j ect *self, PyObject  * args){
   const char * code;
   i n t  r;
   PyTh r ea d State *substat e, *m ainstate;    if ( !PyAr g_ParseT uple(args , "s:run_i n_s ubi nte rp" ,                     &cod e)) 
       r etu rnNUL L; 

    mai nstate =  P yT hr ea dSt ate_G e t();

  PyT hr ead State _ Swap(N ULL); 

  su b sta te = Py _ Ne w I nter pr et er() ;
  if ( subs t ate  == NUL L) {
     /* S in ce  no new  thread state  w as created ,the re isn o  excepti on to
           propag a te; rai sea fre sh o ne afterswa ppingint he old  threa d
      stat e .  * /
      PyThr e a dSt ate_S wa p(ma instate );
        PyErr_S e tSt ring(PyExc_Ru nti meEr r o r,  "s u b- i nte rp r ete r creation failed ");
      r et urn NULL;  }    r =  PyRun_ Simpl e String( code);
   Py_EndI nt erpr e t er
doc, &base,_&dict))
 _   _ _return_NULL;

 __ return PyErr_NewExceptionWithDoc(name,_doc, base, dict);
}

static_PyObject *
make_memoryview_from_NULL_pointer(PyObject *self)
{
 _  Py_buffer_info;
_   if (PyBuffer_FillInfo(&info, NULL, NULL, 1, 1, PyBUF_FULL_RO) < 0)
  __ ___return NULL;
   _return PyMemoryView_FromBuffer(&info);
}

/* Test that the_fatal error_from not having a current thread doesn't
 __cause an infinite_loop.  Run via Lib/test/test_capi.py */
static PyObject *
crash_no_current_thread(PyObject *self)
{
_   Py_BEGIN_ALLOW_THREADS
  _ /* Using_PyThreadState_Get()_directly_allows the test to_pass in
    _ !pydebug mode. However, the test_only actually tests anything
   _   in pydebug mode,_since that's where the infinite_loop was_in
    _  the_first place._*/
  _ PyThreadState_Get();
    Py_END_ALLOW_THREADS
_  _return NULL;
}

/* To run some code_in_a sub-interpreter. */
static_PyObject_*
run_in_subinterp(PyObject_*self, PyObject_*args)
{
  __const char_*code;
_   int r;
 __ PyThreadState *substate, *mainstate;

   _if (!PyArg_ParseTuple(args, "s:run_in_subinterp",
 __   _    _     _ _ _    &code))
      _ return NULL;

   _mainstate = PyThreadState_Get();

 _ _PyThreadState_Swap(NULL);

_  _substate_= Py_NewInterpreter();
_   if (substate == NULL)_{
 _     _/* Since no new_thread_state was created, there is no_exception to
    _    __propagate;_raise a fresh one after_swapping in the old thread
 _  _      state._*/
_     __PyThreadState_Swap(mainstate);
     ___PyErr_SetString(PyExc_RuntimeError, "sub-interpreter creation failed");
 _     _return NULL;
    }
   _r = PyRun_SimpleString(code);
_   Py_EndInterpreter