@@ -81,22 +81,6 @@ PyType_Spec cthunk_spec = {
81
81
82
82
/**************************************************************/
83
83
84
- static void
85
- PrintError (const char * msg , ...)
86
- {
87
- char buf [512 ];
88
- PyObject * f = PySys_GetObject ("stderr" );
89
- va_list marker ;
90
-
91
- va_start (marker , msg );
92
- PyOS_vsnprintf (buf , sizeof (buf ), msg , marker );
93
- va_end (marker );
94
- if (f != NULL && f != Py_None )
95
- PyFile_WriteString (buf , f );
96
- PyErr_Print ();
97
- }
98
-
99
-
100
84
#ifdef MS_WIN32
101
85
/*
102
86
* We must call AddRef() on non-NULL COM pointers we receive as arguments
@@ -108,26 +92,23 @@ PrintError(const char *msg, ...)
108
92
* after checking for PyObject_IsTrue(), but this would probably be somewhat
109
93
* slower.
110
94
*/
111
- static void
95
+ static int
112
96
TryAddRef (PyObject * cnv , CDataObject * obj )
113
97
{
114
98
IUnknown * punk ;
115
99
PyObject * attrdict = _PyType_GetDict ((PyTypeObject * )cnv );
116
100
if (!attrdict ) {
117
- return ;
101
+ return 0 ;
118
102
}
119
103
int r = PyDict_Contains (attrdict , & _Py_ID (_needs_com_addref_ ));
120
104
if (r <= 0 ) {
121
- if (r < 0 ) {
122
- PrintError ("getting _needs_com_addref_" );
123
- }
124
- return ;
105
+ return r ;
125
106
}
126
107
127
108
punk = * (IUnknown * * )obj -> b_ptr ;
128
109
if (punk )
129
110
punk -> lpVtbl -> AddRef (punk );
130
- return ;
111
+ return 0 ;
131
112
}
132
113
#endif
133
114
@@ -162,14 +143,13 @@ static void _CallPythonObject(ctypes_state *st,
162
143
163
144
StgInfo * info ;
164
145
if (PyStgInfo_FromType (st , cnv , & info ) < 0 ) {
165
- goto Done ;
146
+ goto Error ;
166
147
}
167
148
168
149
if (info && info -> getfunc && !_ctypes_simple_instance (st , cnv )) {
169
150
PyObject * v = info -> getfunc (* pArgs , info -> size );
170
151
if (!v ) {
171
- PrintError ("create argument %zd:\n" , i );
172
- goto Done ;
152
+ goto Error ;
173
153
}
174
154
args [i ] = v ;
175
155
/* XXX XXX XX
@@ -182,33 +162,39 @@ static void _CallPythonObject(ctypes_state *st,
182
162
/* Hm, shouldn't we use PyCData_AtAddress() or something like that instead? */
183
163
CDataObject * obj = (CDataObject * )_PyObject_CallNoArgs (cnv );
184
164
if (!obj ) {
185
- PrintError ("create argument %zd:\n" , i );
186
- goto Done ;
165
+ goto Error ;
187
166
}
188
167
if (!CDataObject_Check (st , obj )) {
168
+ PyErr_Format (PyExc_TypeError ,
169
+ "%R returned unexpected result of type %T" , cnv , obj );
189
170
Py_DECREF (obj );
190
- PrintError ("unexpected result of create argument %zd:\n" , i );
191
- goto Done ;
171
+ goto Error ;
192
172
}
193
173
memcpy (obj -> b_ptr , * pArgs , info -> size );
194
174
args [i ] = (PyObject * )obj ;
195
175
#ifdef MS_WIN32
196
- TryAddRef (cnv , obj );
176
+ if (TryAddRef (cnv , obj ) < 0 ) {
177
+ goto Error ;
178
+ }
197
179
#endif
A3E2
td>198
180
} else {
199
- PyErr_SetString (PyExc_TypeError ,
200
- "cannot build parameter" );
201
- PrintError ("Parsing argument %zd\n" , i );
202
- goto Done ;
181
+ PyErr_Format (PyExc_TypeError ,
182
+ "cannot build parameter of type %R" , cnv );
183
+ goto Error ;
203
184
}
204
185
/* XXX error handling! */
205
186
pArgs ++ ;
206
187
}
207
188
208
189
if (flags & (FUNCFLAG_USE_ERRNO | FUNCFLAG_USE_LASTERROR )) {
209
190
error_object = _ctypes_get_errobj (st , & space );
210
- if (error_object == NULL )
191
+ if (error_object == NULL ) {
192
+ PyErr_FormatUnraisable (
193
+ "Exception ignored while setting error for "
194
+ "ctypes callback function %R" ,
195
+ callable );
211
196
goto Done ;
197
+ }
212
198
if (flags & FUNCFLAG_USE_ERRNO ) {
213
199
int temp = space [0 ];
214
200
space [0 ] = errno ;
@@ -295,6 +281,14 @@ static void _CallPythonObject(ctypes_state *st,
295
281
for (j = 0 ; j < i ; j ++ ) {
296
282
Py_DECREF (args [j ]);
297
283
}
284
+ return ;
285
+
286
+ Error :
287
+ PyErr_FormatUnraisable (
288
+ "Exception ignored while creating argument %zd for "
289
+ "ctypes callback function %R" ,
290
+ i , callable );
291
+ goto Done ;
298
292
}
299
293
300
294
static void closure_fcn (ffi_cif * cif ,
0 commit comments