@@ -345,7 +345,7 @@ BaseException_args_get_impl(PyBaseExceptionObject *self)
345345 if (self -> args == NULL ) {
346346 Py_RETURN_NONE ;
347347 }
348- return Py_NewRef (self -> args );
348+ return PyRegion_NewRef (self -> args );
349349}
350350
351351/*[clinic input]
@@ -366,7 +366,9 @@ BaseException_args_set_impl(PyBaseExceptionObject *self, PyObject *value)
366366 seq = PySequence_Tuple (value );
367367 if (!seq )
368368 return -1 ;
369- Py_XSETREF (self -> args , seq );
369+ if (PyRegion_XSETREF (self , self -> args , seq )) {
370+ return -1 ;
371+ }
370372 return 0 ;
371373}
372374
@@ -383,7 +385,7 @@ BaseException___traceback___get_impl(PyBaseExceptionObject *self)
383385 if (self -> traceback == NULL ) {
384386 Py_RETURN_NONE ;
385387 }
386- return Py_NewRef (self -> traceback );
388+ return PyRegion_NewRef (self -> traceback );
387389}
388390
389391
@@ -403,10 +405,12 @@ BaseException___traceback___set_impl(PyBaseExceptionObject *self,
403405 return -1 ;
404406 }
405407 if (PyTraceBack_Check (value )) {
406- Py_XSETREF (self -> traceback , Py_NewRef (value ));
408+ if (PyRegion_XSETNEWREF (self , self -> traceback , value )) {
409+ return -1 ;
410+ }
407411 }
408412 else if (value == Py_None ) {
409- Py_CLEAR ( self -> traceback );
413+ PyRegion_CLEAR ( self , self -> traceback );
410414 }
411415 else {
412416 PyErr_SetString (PyExc_TypeError ,
@@ -429,7 +433,7 @@ BaseException___context___get_impl(PyBaseExceptionObject *self)
429433 if (self -> context == NULL ) {
430434 Py_RETURN_NONE ;
431435 }
432- return Py_NewRef (self -> context );
436+ return PyRegion_NewRef (self -> context );
433437}
434438
435439/*[clinic input]
@@ -453,9 +457,18 @@ BaseException___context___set_impl(PyBaseExceptionObject *self,
453457 "or derive from BaseException" );
454458 return -1 ;
455459 } else {
460+ if (PyRegion_AddLocalRef (value )) {
461+ // Regions: This should never happen, since we have a reference to self.
462+ assert (false);
463+ PyRegion_DirtyObjectRegion (value );
464+ return -1 ;
465+ }
456466 Py_INCREF (value );
457467 }
458- Py_XSETREF (self -> context , value );
468+ if (PyRegion_XSETREF (self , self -> context , value )) {
469+ Py_XDECREF (value );
470+ return -1 ;
471+ }
459472 return 0 ;
460473}
461474
@@ -519,7 +532,15 @@ PyException_GetTraceback(PyObject *self)
519532{
520533 PyObject * traceback ;
521534 Py_BEGIN_CRITICAL_SECTION (self );
522- traceback = Py_XNewRef (PyBaseExceptionObject_CAST (self )-> traceback );
535+ traceback = PyBaseExceptionObject_CAST (self )-> traceback ;
536+ if (PyRegion_AddLocalRef (traceback )) {
537+ // Regions: This should never happen, since we have a reference to self.
538+ assert (false);
539+ PyRegion_DirtyObjectRegion (traceback );
540+ traceback = NULL ;
541+ } else {
542+ Py_XINCREF (traceback );
543+ }
523544 Py_END_CRITICAL_SECTION ();
524545 return traceback ;
525546}
@@ -540,7 +561,15 @@ PyException_GetCause(PyObject *self)
540561{
541562 PyObject * cause ;
542563 Py_BEGIN_CRITICAL_SECTION (self );
543- cause = Py_XNewRef (PyBaseExceptionObject_CAST (self )-> cause );
564+ cause = PyBaseExceptionObject_CAST (self )-> cause ;
565+ if (PyRegion_AddLocalRef (cause )) {
566+ // Regions: This should never happen, since we have a reference to self.
567+ assert (false);
568+ PyRegion_DirtyObjectRegion (cause );
569+ cause = NULL ;
570+ } else {
571+ Py_XINCREF (cause );
572+ }
544573 Py_END_CRITICAL_SECTION ();
545574 return cause ;
546575}
@@ -551,8 +580,11 @@ PyException_SetCause(PyObject *self, PyObject *cause)
551580{
552581 Py_BEGIN_CRITICAL_SECTION (self );
553582 PyBaseExceptionObject * base_self = PyBaseExceptionObject_CAST (self );
554- base_self -> suppress_context = 1 ;
555- Py_XSETREF (base_self -> cause , cause );
583+ if (PyRegion_XSETREF (base_self , base_self -> cause , cause )) {
584+ // FIXME(Regions): xFrednet: This function doesn't support failure.
585+ } else {
586+ base_self -> suppress_context = 1 ;
587+ }
556588 Py_END_CRITICAL_SECTION ();
557589}
558590
@@ -561,7 +593,15 @@ PyException_GetContext(PyObject *self)
561593{
562594 PyObject * context ;
563595 Py_BEGIN_CRITICAL_SECTION (self );
564- context = Py_XNewRef (PyBaseExceptionObject_CAST (self )-> context );
596+ context = PyBaseExceptionObject_CAST (self )-> context ;
597+ if (PyRegion_AddLocalRef (context )) {
598+ // Regions: This should never happen, since we have a reference to self.
599+ assert (false);
600+ PyRegion_DirtyObjectRegion (context );
601+ context = NULL ;
602+ } else {
603+ Py_XINCREF (context );
604+ }
565605 Py_END_CRITICAL_SECTION ();
566606 return context ;
567607}
571611PyException_SetContext (PyObject * self , PyObject * context )
572612{
573613 Py_BEGIN_CRITICAL_SECTION (self );
574- Py_XSETREF (PyBaseExceptionObject_CAST (self )-> context , context );
614+ if (PyRegion_XSETREF (self , PyBaseExceptionObject_CAST (self )-> context , context )) {
615+ // FIXME(Regions): xFrednet: This function doesn't support failure.
616+ }
575617 Py_END_CRITICAL_SECTION ();
576618}
577619
@@ -580,17 +622,34 @@ PyException_GetArgs(PyObject *self)
580622{
581623 PyObject * args ;
582624 Py_BEGIN_CRITICAL_SECTION (self );
583- args = Py_NewRef (PyBaseExceptionObject_CAST (self )-> args );
625+ args = PyBaseExceptionObject_CAST (self )-> args ;
626+ if (PyRegion_AddLocalRef (args )) {
627+ // This should never happen, since we have a reference to self.
628+ assert (false);
629+ PyRegion_DirtyObjectRegion (args );
630+ args = NULL ;
631+ } else {
632+ Py_INCREF (args );
633+ }
584634 Py_END_CRITICAL_SECTION ();
585635 return args ;
586636}
587637
588638void
589639PyException_SetArgs (PyObject * self , PyObject * args )
590640{
591- Py_BEGIN_CRITICAL_SECTION (self );
641+ // Regions: This should always succeed, since we have a reference to args
642+ if (PyRegion_AddLocalRef (args )) {
643+ assert (false);
644+ PyRegion_DirtyObjectRegion (args );
645+ return ;
646+ }
592647 Py_INCREF (args );
593- Py_XSETREF (PyBaseExceptionObject_CAST (self )-> args , args );
648+
649+ Py_BEGIN_CRITICAL_SECTION (self );
650+ if (PyRegion_XSETREF (self , PyBaseExceptionObject_CAST (self )-> args , args )) {
651+ // FIXME(Regions): xFrednet: This function doesn't support failure.
652+ }
594653 Py_END_CRITICAL_SECTION ();
595654}
596655
0 commit comments