@@ -8678,6 +8678,27 @@ check_num_args(PyObject *ob, int n)
8678
8678
return 0 ;
8679
8679
}
8680
8680
8681
+ static Py_ssize_t
8682
+ check_pow_args (PyObject * ob )
8683
+ {
8684
+ // Returns the argument count on success or `-1` on error.
8685
+ int min = 1 ;
8686
+ int max = 2 ;
8687
+ if (!PyTuple_CheckExact (ob )) {
8688
+ PyErr_SetString (PyExc_SystemError ,
8689
+ "PyArg_UnpackTuple() argument list is not a tuple" );
8690
+ return -1 ;
8691
+ }
8692
+ Py_ssize_t size = PyTuple_GET_SIZE (ob );
8693
+ if (size >= min && size <= max ) {
8694
+ return size ;
8695
+ }
8696
+ PyErr_Format (
8697
+ PyExc_TypeError ,
8698
+ "expected %d or %d arguments, got %zd" , min , max , PyTuple_GET_SIZE (ob ));
8699
+ return -1 ;
8700
+ }
8701
+
8681
8702
/* Generic wrappers for overloadable 'operators' such as __getitem__ */
8682
8703
8683
8704
/* There's a wrapper *function* for each distinct function typedef used
@@ -8759,8 +8780,15 @@ wrap_ternaryfunc(PyObject *self, PyObject *args, void *wrapped)
8759
8780
8760
8781
/* Note: This wrapper only works for __pow__() */
8761
8782
8762
- if (!PyArg_UnpackTuple (args , "" , 1 , 2 , & other , & third ))
8783
+ Py_ssize_t size = check_pow_args (args );
8784
+ if (size == -1 ) {
8763
8785
return NULL ;
8786
+ }
8787
+ other = PyTuple_GET_ITEM (args , 0 );
8788
+ if (size == 2 ) {
8789
+ third = PyTuple_GET_ITEM (args , 1 );
8790
+ }
8791
+
8764
8792
return (* func )(self , other , third );
8765
8793
}
8766
8794
@@ -8771,10 +8799,17 @@ wrap_ternaryfunc_r(PyObject *self, PyObject *args, void *wrapped)
8771
8799
PyObject * other ;
8772
8800
PyObject * third = Py_None ;
8773
8801
8774
- /* Note: This wrapper only works for __pow__ () */
8802
+ /* Note: This wrapper only works for __rpow__ () */
8775
8803
8776
- if (!PyArg_UnpackTuple (args , "" , 1 , 2 , & other , & third ))
8804
+ Py_ssize_t size = check_pow_args (args );
8805
+ if (size == -1 ) {
8777
8806
return NULL ;
8807
+ }
8808
+ other = PyTuple_GET_ITEM (args , 0 );
8809
+ if (size == 2 ) {
8810
+ third = PyTuple_GET_ITEM (args , 1 );
8811
+ }
8812
+
8778
8813
return (* func )(other , self , third );
8779
8814
}
8780
8815
@@ -8795,8 +8830,9 @@ wrap_indexargfunc(PyObject *self, PyObject *args, void *wrapped)
8795
8830
PyObject * o ;
8796
8831
Py_ssize_t i ;
8797
8832
8798
- if (!PyArg_UnpackTuple (args , "" , 1 , 1 , & o ))
8833
+ if (!check_num_args (args , 1 ))
8799
8834
return NULL ;
8835
+ o = PyTuple_GET_ITEM (args , 0 );
8800
8836
i = PyNumber_AsSsize_t (o , PyExc_OverflowError );
8801
8837
if (i == -1 && PyErr_Occurred ())
8802
8838
return NULL ;
@@ -8852,7 +8888,7 @@ wrap_sq_setitem(PyObject *self, PyObject *args, void *wrapped)
8852
8888
int res ;
8853
8889
PyObject * arg , * value ;
8854
8890
8855
- if (!PyArg_UnpackTuple (args , "" , 2 , 2 , & arg , & value ))
8891
+ if (!PyArg_UnpackTuple (args , "__setitem__ " , 2 , 2 , & arg , & value ))
8856
8892
return NULL ;
8857
8893
i = getindex (self , arg );
8858
8894
if (i == -1 && PyErr_Occurred ())
@@ -8908,7 +8944,7 @@ wrap_objobjargproc(PyObject *self, PyObject *args, void *wrapped)
8908
8944
int res ;
8909
8945
PyObject * key , * value ;
8910
8946
8911
- if (!PyArg_UnpackTuple (args , "" , 2 , 2 , & key , & value ))
8947
+ if (!PyArg_UnpackTuple (args , "__setitem__ " , 2 , 2 , & key , & value ))
8912
8948
return NULL ;
8913
8949
res = (* func )(self , key , value );
8914
8950
if (res == -1 && PyErr_Occurred ())
@@ -9005,7 +9041,7 @@ wrap_setattr(PyObject *self, PyObject *args, void *wrapped)
9005
9041
int res ;
9006
9042
PyObject * name , * value ;
9007
9043
9008
- if (!PyArg_UnpackTuple (args , "" , 2 , 2 , & name , & value ))
9044
+ if (!PyArg_UnpackTuple (args , "__setattr__ " , 2 , 2 , & name , & value ))
9009
9045
return NULL ;
9010
9046
if (!hackcheck (self , func , "__setattr__" ))
9011
9047
return NULL ;
@@ -9115,7 +9151,7 @@ wrap_descr_get(PyObject *self, PyObject *args, void *wrapped)
9115
9151
PyObject * obj ;
9116
9152
PyObject * type = NULL ;
9117
9153
9118
- if (!PyArg_UnpackTuple (args , "" , 1 , 2 , & obj , & type ))
9154
+ if (!PyArg_UnpackTuple (args , "__get__ " , 1 , 2 , & obj , & type ))
9119
9155
return NULL ;
9120
9156
if (obj == Py_None )
9121
9157
obj = NULL ;
@@ -9136,7 +9172,7 @@ wrap_descr_set(PyObject *self, PyObject *args, void *wrapped)
9136
9172
PyObject * obj , * value ;
9137
9173
int ret ;
9138
9174
9139
- if (!PyArg_UnpackTuple (args , "" , 2 , 2 , & obj , & value ))
9175
+ if (!PyArg_UnpackTuple (args , "__set__ " , 2 , 2 , & obj , & value ))
9140
9176
return NULL ;
9141
9177
ret = (* func )(self , obj , value );
9142
9178
if (ret < 0 )
@@ -9165,7 +9201,7 @@ wrap_buffer(PyObject *self, PyObject *args, void *wrapped)
9165
9201
{
9166
9202
PyObject * arg = NULL ;
9167
9203
9168
- if (!PyArg_UnpackTuple (args , "" , 1 , 1 , & arg )) {
9204
+ if (!PyArg_UnpackTuple (args , "__buffer__ " , 1 , 1 , & arg )) {
9169
9205
return NULL ;
9170
9206
}
9171
9207
Py_ssize_t flags = PyNumber_AsSsize_t (arg , PyExc_OverflowError );
@@ -9186,7 +9222,7 @@ static PyObject *
9186
9222
wrap_releasebuffer (PyObject * self , PyObject * args , void * wrapped )
9187
9223
{
9188
9224
PyObject * arg = NULL ;
9189
- if (!PyArg_UnpackTuple (args , "" , 1 , 1 , & arg )) {
9225
+ if (!PyArg_UnpackTuple (args , "__release_buffer__ " , 1 , 1 , & arg )) {
9190
9226
return NULL ;
9191
9227
}
9192
9228
if (!PyMemoryView_Check (arg )) {
0 commit comments