@@ -760,7 +760,7 @@ array_richcompare_lock_held(PyObject *v, PyObject *w, int op)
760760 res = Py_False ;
761761 else
762762 res = Py_True ;
763- return res ;
763+ return Py_NewRef ( res ) ;
764764 }
765765
766766 if (va -> ob_descr == wa -> ob_descr && va -> ob_descr -> compareitems != NULL ) {
@@ -783,7 +783,7 @@ array_richcompare_lock_held(PyObject *v, PyObject *w, int op)
783783 default : return NULL ; /* cannot happen */
784784 }
785785 PyObject * res = cmp ? Py_True : Py_False ;
786- return res ;
786+ return Py_NewRef ( res ) ;
787787 }
788788
789789
@@ -829,15 +829,15 @@ array_richcompare_lock_held(PyObject *v, PyObject *w, int op)
829829 res = Py_True ;
830830 else
831831 res = Py_False ;
832- return res ;
832+ return Py_NewRef ( res ) ;
833833 }
834834
835835 /* We have an item that differs. First, shortcuts for EQ/NE */
836836 if (op == Py_EQ ) {
837- res = Py_False ;
837+ res = Py_NewRef ( Py_False ) ;
838838 }
839839 else if (op == Py_NE ) {
840- res = Py_True ;
840+ res = Py_NewRef ( Py_True ) ;
841841 }
842842 else {
843843 /* Compare the final item again using the proper operator */
@@ -2817,15 +2817,14 @@ static const void *emptybuf = "";
28172817
28182818
28192819static int
2820- array_buffer_getbuf (arrayobject * self , Py_buffer * view , int flags )
2820+ array_buffer_getbuf_lock_held (arrayobject * self , Py_buffer * view , int flags )
28212821{
28222822 if (view == NULL ) {
28232823 PyErr_SetString (PyExc_BufferError ,
28242824 "array_buffer_getbuf: view==NULL argument is obsolete" );
28252825 return -1 ;
28262826 }
28272827
2828- Py_BEGIN_CRITICAL_SECTION (self );
28292828 view -> buf = (void * )self -> ob_item ;
28302829 view -> obj = Py_NewRef (self );
28312830 if (view -> buf == NULL )
@@ -2854,14 +2853,27 @@ array_buffer_getbuf(arrayobject *self, Py_buffer *view, int flags)
28542853 }
28552854
28562855 self -> ob_exports ++ ;
2857- Py_END_CRITICAL_SECTION ();
28582856 return 0 ;
28592857}
28602858
2859+ static int
2860+ array_buffer_getbuf (arrayobject * self , Py_buffer * view , int flags )
2861+ {
2862+ int ret ;
2863+ Py_BEGIN_CRITICAL_SECTION (self );
2864+ ret = array_buffer_getbuf_lock_held (self , view , flags );
2865+ Py_END_CRITICAL_SECTION ();
2866+ return ret ;
2867+ }
2868+
28612869static void
28622870array_buffer_relbuf (arrayobject * self , Py_buffer * view )
28632871{
2872+ #ifdef Py_GIL_DISABLED
28642873 _Py_atomic_add_ssize (& self -> ob_exports , -1 );
2874+ #else
2875+ self -> ob_exports -- ;
2876+ #endif
28652877}
28662878
28672879static PyObject *
0 commit comments