~pythonregexp2.7/python/issue2636-12

« back to all changes in this revision

Viewing changes to Modules/_ctypes/callbacks.c

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-06-09 14:52:42 UTC
  • mfrom: (39033.1.3 Regexp-2.6)
  • Revision ID: darklord@timehorse.com-20080609145242-9m268zc6u87rp1vp
Merged in changes from the core Regexp branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
189
189
                              SETFUNC setfunc,
190
190
                              PyObject *callable,
191
191
                              PyObject *converters,
 
192
                              int flags,
192
193
                              void **pArgs)
193
194
{
194
195
        Py_ssize_t i;
195
196
        PyObject *result;
196
197
        PyObject *arglist = NULL;
197
198
        Py_ssize_t nArgs;
 
199
        PyObject *error_object = NULL;
 
200
        int *space;
198
201
#ifdef WITH_THREAD
199
202
        PyGILState_STATE state = PyGILState_Ensure();
200
203
#endif
271
274
#define CHECK(what, x) \
272
275
if (x == NULL) _AddTraceback(what, "_ctypes/callbacks.c", __LINE__ - 1), PyErr_Print()
273
276
 
 
277
        if (flags & (FUNCFLAG_USE_ERRNO | FUNCFLAG_USE_LASTERROR)) {
 
278
                error_object = get_error_object(&space);
 
279
                if (error_object == NULL)
 
280
                        goto Done;
 
281
                if (flags & FUNCFLAG_USE_ERRNO) {
 
282
                        int temp = space[0];
 
283
                        space[0] = errno;
 
284
                        errno = temp;
 
285
                }
 
286
#ifdef MS_WIN32
 
287
                if (flags & FUNCFLAG_USE_LASTERROR) {
 
288
                        int temp = space[1];
 
289
                        space[1] = GetLastError();
 
290
                        SetLastError(temp);
 
291
                }
 
292
#endif
 
293
        }
 
294
 
274
295
        result = PyObject_CallObject(callable, arglist);
275
296
        CHECK("'calling callback function'", result);
 
297
 
 
298
#ifdef MS_WIN32
 
299
        if (flags & FUNCFLAG_USE_LASTERROR) {
 
300
                int temp = space[1];
 
301
                space[1] = GetLastError();
 
302
                SetLastError(temp);
 
303
        }
 
304
#endif
 
305
        if (flags & FUNCFLAG_USE_ERRNO) {
 
306
                int temp = space[0];
 
307
                space[0] = errno;
 
308
                errno = temp;
 
309
        }
 
310
        Py_XDECREF(error_object);
 
311
 
276
312
        if ((restype != &ffi_type_void) && result) {
277
313
                PyObject *keep;
278
314
                assert(setfunc);
322
358
                          p->setfunc,
323
359
                          p->callable,
324
360
                          p->converters,
 
361
                          p->flags,
325
362
                          args);
326
363
}
327
364
 
351
388
CThunkObject *AllocFunctionCallback(PyObject *callable,
352
389
                                    PyObject *converters,
353
390
                                    PyObject *restype,
354
 
                                    int is_cdecl)
 
391
                                    int flags)
355
392
{
356
393
        int result;
357
394
        CThunkObject *p;
371
408
                goto error;
372
409
        }
373
410
 
 
411
        p->flags = flags;
374
412
        for (i = 0; i < nArgs; ++i) {
375
413
                PyObject *cnv = PySequence_GetItem(converters, i);
376
414
                if (cnv == NULL)
398
436
 
399
437
        cc = FFI_DEFAULT_ABI;
400
438
#if defined(MS_WIN32) && !defined(_WIN32_WCE) && !defined(MS_WIN64)
401
 
        if (is_cdecl == 0)
 
439
        if ((flags & FUNCFLAG_CDECL) == 0)
402
440
                cc = FFI_STDCALL;
403
441
#endif
404
442
        result = ffi_prep_cif(&p->cif, cc,