@@ -1847,6 +1847,42 @@ static PyMethodDef c_void_p_method = { "from_param", c_void_p_from_param, METH_O
1847
1847
static PyMethodDef c_char_p_method = { "from_param" , c_char_p_from_param , METH_O };
1848
1848
static PyMethodDef c_wchar_p_method = { "from_param" , c_wchar_p_from_param , METH_O };
1849
1849
1850
+ // Complete arguments passed to PyCSimpleType_init() and CreateSwappedType()
1851
+ static PyObject *
1852
+ CreateSwappedType_ready (PyObject * self , PyObject * args )
1853
+ {
1854
+ PyObject * dict ;
1855
+ if (!PyTuple_CheckExact (args ) || PyTuple_GET_SIZE (args ) < 3 ) {
1856
+ dict = PyDict_New ();
1857
+ }
1858
+ else {
1859
+ dict = PyDict_Copy (PyTuple_GET_ITEM (args , 2 ));
1860
+ }
1861
+ if (!dict ) {
1862
+ return NULL ;
1863
+ }
1864
+ if (PyDict_Update (dict , ((PyTypeObject * )self )-> tp_dict ) < 0 ) {
1865
+ Py_DECREF (dict );
1866
+ return NULL ;
1867
+ }
1868
+ if (PyDict_DelItem (dict , & _Py_ID (__dict__ ))) {
1869
+ PyErr_Clear ();
1870
+ }
1871
+ if (PyDict_DelItem (dict , & _Py_ID (__weakref__ ))) {
1872
+ PyErr_Clear ();
1873
+ }
1874
+
1875
+ PyObject * safe_args = PyTuple_New (3 );
1876
+ if (!safe_args ) {
1877
+ Py_DECREF (dict );
1878
+ return NULL ;
1879
+ }
1880
+ PyTuple_SET_ITEM (safe_args , 0 , PyType_GetName ((PyTypeObject * )self ));
1881
+ PyTuple_SET_ITEM (safe_args , 1 , Py_NewRef (((PyTypeObject * )self )-> tp_bases ));
1882
+ PyTuple_SET_ITEM (safe_args , 2 , dict );
1883
+ return safe_args ;
1884
+ }
1885
+
1850
1886
static PyObject * CreateSwappedType (PyTypeObject * type , PyObject * args , PyObject * kwds ,
1851
1887
PyObject * proto , struct fielddesc * fmt )
1852
1888
{
@@ -2088,8 +2124,13 @@ PyCSimpleType_init(PyObject *self, PyObject *args, PyObject *kwds)
2088
2124
&& fmt -> setfunc_swapped
2089
2125
&& fmt -> getfunc_swapped )
2090
2126
{
2091
- PyObject * swapped = CreateSwappedType (type , args , kwds ,
2127
+ PyObject * safe_args = CreateSwappedType_ready (self , args );
2128
+ if (!safe_args ) {
2129
+ return -1 ;
2130
+ }
2131
+ PyObject * swapped = CreateSwappedType (type , safe_args , kwds ,
2092
2132
proto , fmt );
2133
+ Py_DECREF (safe_args );
2093
2134
StgDictObject * sw_dict ;
2094
2135
if (swapped == NULL ) {
2095
2136
return -1 ;
0 commit comments