Browse Source

Restoring authorship annotation for <olegts@yandex-team.ru>. Commit 1 of 2.

olegts 3 years ago
parent
commit
30983fb258

File diff suppressed because it is too large
+ 977 - 977
contrib/python/cffi/c/_cffi_backend.c


+ 246 - 246
contrib/python/cffi/c/call_python.c

@@ -1,7 +1,7 @@
 #if PY_VERSION_HEX >= 0x03080000
 # define HAVE_PYINTERPSTATE_GETDICT
 #endif
-
+ 
 
 static PyObject *_current_interp_key(void)
 {
@@ -13,25 +13,25 @@ static PyObject *_current_interp_key(void)
 #endif
 }
 
-static PyObject *_get_interpstate_dict(void)
-{
-    /* Hack around to return a dict that is subinterpreter-local.
-       Does not return a new reference.  Returns NULL in case of
-       error, but without setting any exception.  (If called late
-       during shutdown, we *can't* set an exception!)
-    */
-    static PyObject *attr_name = NULL;
-    PyThreadState *tstate;
+static PyObject *_get_interpstate_dict(void) 
+{ 
+    /* Hack around to return a dict that is subinterpreter-local. 
+       Does not return a new reference.  Returns NULL in case of 
+       error, but without setting any exception.  (If called late 
+       during shutdown, we *can't* set an exception!) 
+    */ 
+    static PyObject *attr_name = NULL; 
+    PyThreadState *tstate; 
     PyObject *d, *interpdict;
-    int err;
+    int err; 
     PyInterpreterState *interp;
-
-    tstate = PyThreadState_GET();
-    if (tstate == NULL) {
-        /* no thread state! */
-        return NULL;
-    }
-
+ 
+    tstate = PyThreadState_GET(); 
+    if (tstate == NULL) { 
+        /* no thread state! */ 
+        return NULL; 
+    } 
+ 
     interp = tstate->interp;
 #ifdef HAVE_PYINTERPSTATE_GETDICT
     interpdict = PyInterpreterState_GetDict(interp);   /* shared reference */
@@ -39,164 +39,164 @@ static PyObject *_get_interpstate_dict(void)
     interpdict = interp->builtins;
 #endif
     if (interpdict == NULL) {
-        /* subinterpreter was cleared already, or is being cleared right now,
-           to a point that is too much for us to continue */
-        return NULL;
-    }
-
-    /* from there on, we know the (sub-)interpreter is still valid */
-
-    if (attr_name == NULL) {
-        attr_name = PyText_InternFromString("__cffi_backend_extern_py");
-        if (attr_name == NULL)
-            goto error;
-    }
-
+        /* subinterpreter was cleared already, or is being cleared right now, 
+           to a point that is too much for us to continue */ 
+        return NULL; 
+    } 
+ 
+    /* from there on, we know the (sub-)interpreter is still valid */ 
+ 
+    if (attr_name == NULL) { 
+        attr_name = PyText_InternFromString("__cffi_backend_extern_py"); 
+        if (attr_name == NULL) 
+            goto error; 
+    } 
+ 
     d = PyDict_GetItem(interpdict, attr_name);
-    if (d == NULL) {
-        d = PyDict_New();
-        if (d == NULL)
-            goto error;
+    if (d == NULL) { 
+        d = PyDict_New(); 
+        if (d == NULL) 
+            goto error; 
         err = PyDict_SetItem(interpdict, attr_name, d);
         Py_DECREF(d);   /* if successful, there is one ref left in interpdict */
-        if (err < 0)
-            goto error;
-    }
-    return d;
-
- error:
-    PyErr_Clear();    /* typically a MemoryError */
-    return NULL;
-}
-
-static PyObject *_ffi_def_extern_decorator(PyObject *outer_args, PyObject *fn)
-{
+        if (err < 0) 
+            goto error; 
+    } 
+    return d; 
+ 
+ error: 
+    PyErr_Clear();    /* typically a MemoryError */ 
+    return NULL; 
+} 
+ 
+static PyObject *_ffi_def_extern_decorator(PyObject *outer_args, PyObject *fn) 
+{ 
     const char *s;
-    PyObject *error, *onerror, *infotuple, *old1;
-    int index, err;
-    const struct _cffi_global_s *g;
-    struct _cffi_externpy_s *externpy;
-    CTypeDescrObject *ct;
-    FFIObject *ffi;
-    builder_c_t *types_builder;
-    PyObject *name = NULL;
-    PyObject *interpstate_dict;
-    PyObject *interpstate_key;
-
-    if (!PyArg_ParseTuple(outer_args, "OzOO", &ffi, &s, &error, &onerror))
-        return NULL;
-
-    if (s == NULL) {
-        name = PyObject_GetAttrString(fn, "__name__");
-        if (name == NULL)
-            return NULL;
-        s = PyText_AsUTF8(name);
-        if (s == NULL) {
-            Py_DECREF(name);
-            return NULL;
-        }
-    }
-
-    types_builder = &ffi->types_builder;
-    index = search_in_globals(&types_builder->ctx, s, strlen(s));
-    if (index < 0)
-        goto not_found;
-    g = &types_builder->ctx.globals[index];
-    if (_CFFI_GETOP(g->type_op) != _CFFI_OP_EXTERN_PYTHON)
-        goto not_found;
-    Py_XDECREF(name);
-
-    ct = realize_c_type(types_builder, types_builder->ctx.types,
-                        _CFFI_GETARG(g->type_op));
-    if (ct == NULL)
-        return NULL;
-
-    infotuple = prepare_callback_info_tuple(ct, fn, error, onerror, 0);
-    Py_DECREF(ct);
-    if (infotuple == NULL)
-        return NULL;
-
-    /* don't directly attach infotuple to externpy: in the presence of
-       subinterpreters, each time we switch to a different
-       subinterpreter and call the C function, it will notice the
-       change and look up infotuple from the interpstate_dict.
-    */
-    interpstate_dict = _get_interpstate_dict();
-    if (interpstate_dict == NULL) {
-        Py_DECREF(infotuple);
-        return PyErr_NoMemory();
-    }
-
-    externpy = (struct _cffi_externpy_s *)g->address;
-    interpstate_key = PyLong_FromVoidPtr((void *)externpy);
-    if (interpstate_key == NULL) {
-        Py_DECREF(infotuple);
-        return NULL;
-    }
-
-    err = PyDict_SetItem(interpstate_dict, interpstate_key, infotuple);
-    Py_DECREF(interpstate_key);
-    Py_DECREF(infotuple);    /* interpstate_dict owns the last ref */
-    if (err < 0)
-        return NULL;
-
-    /* force _update_cache_to_call_python() to be called the next time
-       the C function invokes cffi_call_python, to update the cache */
-    old1 = externpy->reserved1;
-    externpy->reserved1 = Py_None;   /* a non-NULL value */
-    Py_INCREF(Py_None);
-    Py_XDECREF(old1);
-
-    /* return the function object unmodified */
-    Py_INCREF(fn);
-    return fn;
-
- not_found:
-    PyErr_Format(FFIError, "ffi.def_extern('%s'): no 'extern \"Python\"' "
-                 "function with this name", s);
-    Py_XDECREF(name);
-    return NULL;
-}
-
-
-static int _update_cache_to_call_python(struct _cffi_externpy_s *externpy)
-{
-    PyObject *interpstate_dict, *interpstate_key, *infotuple, *old1, *new1;
-    PyObject *old2;
-
-    interpstate_dict = _get_interpstate_dict();
-    if (interpstate_dict == NULL)
-        return 4;    /* oops, shutdown issue? */
-
-    interpstate_key = PyLong_FromVoidPtr((void *)externpy);
-    if (interpstate_key == NULL)
-        goto error;
-
-    infotuple = PyDict_GetItem(interpstate_dict, interpstate_key);
-    Py_DECREF(interpstate_key);
-    if (infotuple == NULL)
-        return 3;    /* no ffi.def_extern() from this subinterpreter */
-
+    PyObject *error, *onerror, *infotuple, *old1; 
+    int index, err; 
+    const struct _cffi_global_s *g; 
+    struct _cffi_externpy_s *externpy; 
+    CTypeDescrObject *ct; 
+    FFIObject *ffi; 
+    builder_c_t *types_builder; 
+    PyObject *name = NULL; 
+    PyObject *interpstate_dict; 
+    PyObject *interpstate_key; 
+ 
+    if (!PyArg_ParseTuple(outer_args, "OzOO", &ffi, &s, &error, &onerror)) 
+        return NULL; 
+ 
+    if (s == NULL) { 
+        name = PyObject_GetAttrString(fn, "__name__"); 
+        if (name == NULL) 
+            return NULL; 
+        s = PyText_AsUTF8(name); 
+        if (s == NULL) { 
+            Py_DECREF(name); 
+            return NULL; 
+        } 
+    } 
+ 
+    types_builder = &ffi->types_builder; 
+    index = search_in_globals(&types_builder->ctx, s, strlen(s)); 
+    if (index < 0) 
+        goto not_found; 
+    g = &types_builder->ctx.globals[index]; 
+    if (_CFFI_GETOP(g->type_op) != _CFFI_OP_EXTERN_PYTHON) 
+        goto not_found; 
+    Py_XDECREF(name); 
+ 
+    ct = realize_c_type(types_builder, types_builder->ctx.types, 
+                        _CFFI_GETARG(g->type_op)); 
+    if (ct == NULL) 
+        return NULL; 
+ 
+    infotuple = prepare_callback_info_tuple(ct, fn, error, onerror, 0); 
+    Py_DECREF(ct); 
+    if (infotuple == NULL) 
+        return NULL; 
+ 
+    /* don't directly attach infotuple to externpy: in the presence of 
+       subinterpreters, each time we switch to a different 
+       subinterpreter and call the C function, it will notice the 
+       change and look up infotuple from the interpstate_dict. 
+    */ 
+    interpstate_dict = _get_interpstate_dict(); 
+    if (interpstate_dict == NULL) { 
+        Py_DECREF(infotuple); 
+        return PyErr_NoMemory(); 
+    } 
+ 
+    externpy = (struct _cffi_externpy_s *)g->address; 
+    interpstate_key = PyLong_FromVoidPtr((void *)externpy); 
+    if (interpstate_key == NULL) { 
+        Py_DECREF(infotuple); 
+        return NULL; 
+    } 
+ 
+    err = PyDict_SetItem(interpstate_dict, interpstate_key, infotuple); 
+    Py_DECREF(interpstate_key); 
+    Py_DECREF(infotuple);    /* interpstate_dict owns the last ref */ 
+    if (err < 0) 
+        return NULL; 
+ 
+    /* force _update_cache_to_call_python() to be called the next time 
+       the C function invokes cffi_call_python, to update the cache */ 
+    old1 = externpy->reserved1; 
+    externpy->reserved1 = Py_None;   /* a non-NULL value */ 
+    Py_INCREF(Py_None); 
+    Py_XDECREF(old1); 
+ 
+    /* return the function object unmodified */ 
+    Py_INCREF(fn); 
+    return fn; 
+ 
+ not_found: 
+    PyErr_Format(FFIError, "ffi.def_extern('%s'): no 'extern \"Python\"' " 
+                 "function with this name", s); 
+    Py_XDECREF(name); 
+    return NULL; 
+} 
+ 
+ 
+static int _update_cache_to_call_python(struct _cffi_externpy_s *externpy) 
+{ 
+    PyObject *interpstate_dict, *interpstate_key, *infotuple, *old1, *new1; 
+    PyObject *old2; 
+ 
+    interpstate_dict = _get_interpstate_dict(); 
+    if (interpstate_dict == NULL) 
+        return 4;    /* oops, shutdown issue? */ 
+ 
+    interpstate_key = PyLong_FromVoidPtr((void *)externpy); 
+    if (interpstate_key == NULL) 
+        goto error; 
+ 
+    infotuple = PyDict_GetItem(interpstate_dict, interpstate_key); 
+    Py_DECREF(interpstate_key); 
+    if (infotuple == NULL) 
+        return 3;    /* no ffi.def_extern() from this subinterpreter */ 
+ 
     new1 = _current_interp_key();
-    Py_INCREF(new1);
-    Py_INCREF(infotuple);
-    old1 = (PyObject *)externpy->reserved1;
-    old2 = (PyObject *)externpy->reserved2;
-    externpy->reserved1 = new1;         /* holds a reference        */
-    externpy->reserved2 = infotuple;    /* holds a reference (issue #246) */
-    Py_XDECREF(old1);
-    Py_XDECREF(old2);
-
-    return 0;   /* no error */
-
- error:
-    PyErr_Clear();
-    return 2;   /* out of memory? */
-}
-
-#if (defined(WITH_THREAD) && !defined(_MSC_VER) &&   \
-     !defined(__amd64__) && !defined(__x86_64__) &&   \
-     !defined(__i386__) && !defined(__i386))
+    Py_INCREF(new1); 
+    Py_INCREF(infotuple); 
+    old1 = (PyObject *)externpy->reserved1; 
+    old2 = (PyObject *)externpy->reserved2; 
+    externpy->reserved1 = new1;         /* holds a reference        */ 
+    externpy->reserved2 = infotuple;    /* holds a reference (issue #246) */ 
+    Py_XDECREF(old1); 
+    Py_XDECREF(old2); 
+ 
+    return 0;   /* no error */ 
+ 
+ error: 
+    PyErr_Clear(); 
+    return 2;   /* out of memory? */ 
+} 
+ 
+#if (defined(WITH_THREAD) && !defined(_MSC_VER) &&   \ 
+     !defined(__amd64__) && !defined(__x86_64__) &&   \ 
+     !defined(__i386__) && !defined(__i386)) 
 # if defined(HAVE_SYNC_SYNCHRONIZE)
 #   define read_barrier()  __sync_synchronize()
 # elif defined(_AIX)
@@ -211,82 +211,82 @@ static int _update_cache_to_call_python(struct _cffi_externpy_s *externpy)
 #   warning "no definition for read_barrier(), missing synchronization for\
  multi-thread initialization in embedded mode"
 # endif
-#else
-# define read_barrier()  (void)0
-#endif
-
-static void cffi_call_python(struct _cffi_externpy_s *externpy, char *args)
-{
-    /* Invoked by the helpers generated from extern "Python" in the cdef.
-
-       'externpy' is a static structure that describes which of the
-       extern "Python" functions is called.  It has got fields 'name' and
-       'type_index' describing the function, and more reserved fields
-       that are initially zero.  These reserved fields are set up by
-       ffi.def_extern(), which invokes _ffi_def_extern_decorator() above.
-
-       'args' is a pointer to an array of 8-byte entries.  Each entry
-       contains an argument.  If an argument is less than 8 bytes, only
-       the part at the beginning of the entry is initialized.  If an
-       argument is 'long double' or a struct/union, then it is passed
-       by reference.
-
-       'args' is also used as the place to write the result to
-       (directly, even if more than 8 bytes).  In all cases, 'args' is
-       at least 8 bytes in size.
-    */
-    int err = 0;
-
-    /* This read barrier is needed for _embedding.h.  It is paired
-       with the write_barrier() there.  Without this barrier, we can
-       in theory see the following situation: the Python
-       initialization code already ran (in another thread), and the
-       '_cffi_call_python' function pointer directed execution here;
-       but any number of other data could still be seen as
-       uninitialized below.  For example, 'externpy' would still
-       contain NULLs even though it was correctly set up, or
-       'interpreter_lock' (the GIL inside CPython) would still be seen
-       as NULL, or 'autoInterpreterState' (used by
-       PyGILState_Ensure()) would be NULL or contain bogus fields.
-    */
-    read_barrier();
-
-    save_errno();
-
-    /* We need the infotuple here.  We could always go through
+#else 
+# define read_barrier()  (void)0 
+#endif 
+ 
+static void cffi_call_python(struct _cffi_externpy_s *externpy, char *args) 
+{ 
+    /* Invoked by the helpers generated from extern "Python" in the cdef. 
+ 
+       'externpy' is a static structure that describes which of the 
+       extern "Python" functions is called.  It has got fields 'name' and 
+       'type_index' describing the function, and more reserved fields 
+       that are initially zero.  These reserved fields are set up by 
+       ffi.def_extern(), which invokes _ffi_def_extern_decorator() above. 
+ 
+       'args' is a pointer to an array of 8-byte entries.  Each entry 
+       contains an argument.  If an argument is less than 8 bytes, only 
+       the part at the beginning of the entry is initialized.  If an 
+       argument is 'long double' or a struct/union, then it is passed 
+       by reference. 
+ 
+       'args' is also used as the place to write the result to 
+       (directly, even if more than 8 bytes).  In all cases, 'args' is 
+       at least 8 bytes in size. 
+    */ 
+    int err = 0; 
+ 
+    /* This read barrier is needed for _embedding.h.  It is paired 
+       with the write_barrier() there.  Without this barrier, we can 
+       in theory see the following situation: the Python 
+       initialization code already ran (in another thread), and the 
+       '_cffi_call_python' function pointer directed execution here; 
+       but any number of other data could still be seen as 
+       uninitialized below.  For example, 'externpy' would still 
+       contain NULLs even though it was correctly set up, or 
+       'interpreter_lock' (the GIL inside CPython) would still be seen 
+       as NULL, or 'autoInterpreterState' (used by 
+       PyGILState_Ensure()) would be NULL or contain bogus fields. 
+    */ 
+    read_barrier(); 
+ 
+    save_errno(); 
+ 
+    /* We need the infotuple here.  We could always go through 
        _update_cache_to_call_python(), but to avoid the extra dict
-       lookups, we cache in (reserved1, reserved2) the last seen pair
+       lookups, we cache in (reserved1, reserved2) the last seen pair 
        (interp->modules, infotuple).  The first item in this tuple is
        a random PyObject that identifies the subinterpreter.
-    */
-    if (externpy->reserved1 == NULL) {
-        /* Not initialized!  We didn't call @ffi.def_extern() on this
-           externpy object from any subinterpreter at all. */
-        err = 1;
-    }
-    else {
-        PyGILState_STATE state = gil_ensure();
+    */ 
+    if (externpy->reserved1 == NULL) { 
+        /* Not initialized!  We didn't call @ffi.def_extern() on this 
+           externpy object from any subinterpreter at all. */ 
+        err = 1; 
+    } 
+    else { 
+        PyGILState_STATE state = gil_ensure(); 
         if (externpy->reserved1 != _current_interp_key()) {
-            /* Update the (reserved1, reserved2) cache.  This will fail
-               if we didn't call @ffi.def_extern() in this particular
-               subinterpreter. */
-            err = _update_cache_to_call_python(externpy);
-        }
-        if (!err) {
-            general_invoke_callback(0, args, args, externpy->reserved2);
-        }
-        gil_release(state);
-    }
-    if (err) {
-        static const char *msg[] = {
-            "no code was attached to it yet with @ffi.def_extern()",
-            "got internal exception (out of memory?)",
-            "@ffi.def_extern() was not called in the current subinterpreter",
-            "got internal exception (shutdown issue?)",
-        };
-        fprintf(stderr, "extern \"Python\": function %s() called, "
-                        "but %s.  Returning 0.\n", externpy->name, msg[err-1]);
-        memset(args, 0, externpy->size_of_result);
-    }
-    restore_errno();
-}
+            /* Update the (reserved1, reserved2) cache.  This will fail 
+               if we didn't call @ffi.def_extern() in this particular 
+               subinterpreter. */ 
+            err = _update_cache_to_call_python(externpy); 
+        } 
+        if (!err) { 
+            general_invoke_callback(0, args, args, externpy->reserved2); 
+        } 
+        gil_release(state); 
+    } 
+    if (err) { 
+        static const char *msg[] = { 
+            "no code was attached to it yet with @ffi.def_extern()", 
+            "got internal exception (out of memory?)", 
+            "@ffi.def_extern() was not called in the current subinterpreter", 
+            "got internal exception (shutdown issue?)", 
+        }; 
+        fprintf(stderr, "extern \"Python\": function %s() called, " 
+                        "but %s.  Returning 0.\n", externpy->name, msg[err-1]); 
+        memset(args, 0, externpy->size_of_result); 
+    } 
+    restore_errno(); 
+} 

+ 341 - 341
contrib/python/cffi/c/cdlopen.c

@@ -1,362 +1,362 @@
-/* ffi.dlopen() interface with dlopen()/dlsym()/dlclose() */
-
+/* ffi.dlopen() interface with dlopen()/dlsym()/dlclose() */ 
+ 
 static void *cdlopen_fetch(PyObject *libname, void *libhandle,
                            const char *symbol)
-{
-    void *address;
-
-    if (libhandle == NULL) {
-        PyErr_Format(FFIError, "library '%s' has been closed",
-                     PyText_AS_UTF8(libname));
-        return NULL;
-    }
-
-    dlerror();   /* clear error condition */
-    address = dlsym(libhandle, symbol);
-    if (address == NULL) {
-        const char *error = dlerror();
-        PyErr_Format(FFIError, "symbol '%s' not found in library '%s': %s",
-                     symbol, PyText_AS_UTF8(libname), error);
-    }
-    return address;
-}
-
-static void cdlopen_close_ignore_errors(void *libhandle)
-{
-    if (libhandle != NULL)
-        dlclose(libhandle);
-}
-
-static int cdlopen_close(PyObject *libname, void *libhandle)
-{
-    if (libhandle != NULL && dlclose(libhandle) != 0) {
-        const char *error = dlerror();
-        PyErr_Format(FFIError, "closing library '%s': %s",
-                     PyText_AS_UTF8(libname), error);
-        return -1;
-    }
-    return 0;
-}
-
-static PyObject *ffi_dlopen(PyObject *self, PyObject *args)
-{
+{ 
+    void *address; 
+ 
+    if (libhandle == NULL) { 
+        PyErr_Format(FFIError, "library '%s' has been closed", 
+                     PyText_AS_UTF8(libname)); 
+        return NULL; 
+    } 
+ 
+    dlerror();   /* clear error condition */ 
+    address = dlsym(libhandle, symbol); 
+    if (address == NULL) { 
+        const char *error = dlerror(); 
+        PyErr_Format(FFIError, "symbol '%s' not found in library '%s': %s", 
+                     symbol, PyText_AS_UTF8(libname), error); 
+    } 
+    return address; 
+} 
+ 
+static void cdlopen_close_ignore_errors(void *libhandle) 
+{ 
+    if (libhandle != NULL) 
+        dlclose(libhandle); 
+} 
+ 
+static int cdlopen_close(PyObject *libname, void *libhandle) 
+{ 
+    if (libhandle != NULL && dlclose(libhandle) != 0) { 
+        const char *error = dlerror(); 
+        PyErr_Format(FFIError, "closing library '%s': %s", 
+                     PyText_AS_UTF8(libname), error); 
+        return -1; 
+    } 
+    return 0; 
+} 
+ 
+static PyObject *ffi_dlopen(PyObject *self, PyObject *args) 
+{ 
     const char *modname;
     PyObject *temp, *result = NULL;
-    void *handle;
+    void *handle; 
     int auto_close;
-
+ 
     handle = b_do_dlopen(args, &modname, &temp, &auto_close);
     if (handle != NULL)
     {
         result = (PyObject *)lib_internal_new((FFIObject *)self,
                                               modname, handle, auto_close);
-    }
+    } 
     Py_XDECREF(temp);
     return result;
-}
-
-static PyObject *ffi_dlclose(PyObject *self, PyObject *args)
-{
-    LibObject *lib;
-    void *libhandle;
-    if (!PyArg_ParseTuple(args, "O!", &Lib_Type, &lib))
-        return NULL;
-
-    libhandle = lib->l_libhandle;
+} 
+ 
+static PyObject *ffi_dlclose(PyObject *self, PyObject *args) 
+{ 
+    LibObject *lib; 
+    void *libhandle; 
+    if (!PyArg_ParseTuple(args, "O!", &Lib_Type, &lib)) 
+        return NULL; 
+ 
+    libhandle = lib->l_libhandle; 
     if (libhandle != NULL)
     {
         lib->l_libhandle = NULL;
-
+ 
         /* Clear the dict to force further accesses to do cdlopen_fetch()
            again, and fail because the library was closed. */
         PyDict_Clear(lib->l_dict);
 
         if (cdlopen_close(lib->l_libname, libhandle) < 0)
             return NULL;
-    }
-    Py_INCREF(Py_None);
-    return Py_None;
-}
-
-
-static Py_ssize_t cdl_4bytes(char *src)
-{
-    /* read 4 bytes in little-endian order; return it as a signed integer */
-    signed char *ssrc = (signed char *)src;
-    unsigned char *usrc = (unsigned char *)src;
-    return (ssrc[0] << 24) | (usrc[1] << 16) | (usrc[2] << 8) | usrc[3];
-}
-
-static _cffi_opcode_t cdl_opcode(char *src)
-{
-    return (_cffi_opcode_t)cdl_4bytes(src);
-}
-
-typedef struct {
-    unsigned long long value;
-    int neg;
-} cdl_intconst_t;
-
-static int _cdl_realize_global_int(struct _cffi_getconst_s *gc)
-{
-    /* The 'address' field of 'struct _cffi_global_s' is set to point
-       to this function in case ffiobj_init() sees constant integers.
-       This fishes around after the 'ctx->globals' array, which is
-       initialized to contain another array, this time of
-       'cdl_intconst_t' structures.  We get the nth one and it tells
-       us what to return.
-    */
-    cdl_intconst_t *ic;
-    ic = (cdl_intconst_t *)(gc->ctx->globals + gc->ctx->num_globals);
-    ic += gc->gindex;
-    gc->value = ic->value;
-    return ic->neg;
-}
-
-static int ffiobj_init(PyObject *self, PyObject *args, PyObject *kwds)
-{
-    FFIObject *ffi;
-    static char *keywords[] = {"module_name", "_version", "_types",
-                               "_globals", "_struct_unions", "_enums",
-                               "_typenames", "_includes", NULL};
-    char *ffiname = "?", *types = NULL, *building = NULL;
-    Py_ssize_t version = -1;
-    Py_ssize_t types_len = 0;
-    PyObject *globals = NULL, *struct_unions = NULL, *enums = NULL;
-    PyObject *typenames = NULL, *includes = NULL;
-
-    if (!PyArg_ParseTupleAndKeywords(args, kwds,
-                                     "|sns#O!O!O!O!O!:FFI", keywords,
-                                     &ffiname, &version, &types, &types_len,
-                                     &PyTuple_Type, &globals,
-                                     &PyTuple_Type, &struct_unions,
-                                     &PyTuple_Type, &enums,
-                                     &PyTuple_Type, &typenames,
-                                     &PyTuple_Type, &includes))
-        return -1;
-
-    ffi = (FFIObject *)self;
-    if (ffi->ctx_is_nonempty) {
-        PyErr_SetString(PyExc_ValueError,
-                        "cannot call FFI.__init__() more than once");
-        return -1;
-    }
-    ffi->ctx_is_nonempty = 1;
-
-    if (version == -1 && types_len == 0)
-        return 0;
-    if (version < CFFI_VERSION_MIN || version > CFFI_VERSION_MAX) {
-        PyErr_Format(PyExc_ImportError,
-                     "cffi out-of-line Python module '%s' has unknown "
-                     "version %p", ffiname, (void *)version);
-        return -1;
-    }
-
-    if (types_len > 0) {
-        /* unpack a string of 4-byte entries into an array of _cffi_opcode_t */
-        _cffi_opcode_t *ntypes;
-        Py_ssize_t i, n = types_len / 4;
-
-        building = PyMem_Malloc(n * sizeof(_cffi_opcode_t));
-        if (building == NULL)
-            goto error;
-        ntypes = (_cffi_opcode_t *)building;
-
-        for (i = 0; i < n; i++) {
-            ntypes[i] = cdl_opcode(types);
-            types += 4;
-        }
-        ffi->types_builder.ctx.types = ntypes;
-        ffi->types_builder.ctx.num_types = n;
-        building = NULL;
-    }
-
-    if (globals != NULL) {
-        /* unpack a tuple alternating strings and ints, each two together
-           describing one global_s entry with no specified address or size.
-           The int is only used with integer constants. */
-        struct _cffi_global_s *nglobs;
-        cdl_intconst_t *nintconsts;
-        Py_ssize_t i, n = PyTuple_GET_SIZE(globals) / 2;
-
-        i = n * (sizeof(struct _cffi_global_s) + sizeof(cdl_intconst_t));
-        building = PyMem_Malloc(i);
-        if (building == NULL)
-            goto error;
-        memset(building, 0, i);
-        nglobs = (struct _cffi_global_s *)building;
-        nintconsts = (cdl_intconst_t *)(nglobs + n);
-
-        for (i = 0; i < n; i++) {
-            char *g = PyBytes_AS_STRING(PyTuple_GET_ITEM(globals, i * 2));
-            nglobs[i].type_op = cdl_opcode(g); g += 4;
-            nglobs[i].name = g;
-            if (_CFFI_GETOP(nglobs[i].type_op) == _CFFI_OP_CONSTANT_INT ||
-                _CFFI_GETOP(nglobs[i].type_op) == _CFFI_OP_ENUM) {
-                PyObject *o = PyTuple_GET_ITEM(globals, i * 2 + 1);
-                nglobs[i].address = &_cdl_realize_global_int;
-#if PY_MAJOR_VERSION < 3
-                if (PyInt_Check(o)) {
-                    nintconsts[i].neg = PyInt_AS_LONG(o) <= 0;
-                    nintconsts[i].value = (long long)PyInt_AS_LONG(o);
-                }
-                else
-#endif
-                {
-                    nintconsts[i].neg = PyObject_RichCompareBool(o, Py_False,
-                                                                 Py_LE);
-                    nintconsts[i].value = PyLong_AsUnsignedLongLongMask(o);
-                    if (PyErr_Occurred())
-                        goto error;
-                }
-            }
-        }
-        ffi->types_builder.ctx.globals = nglobs;
-        ffi->types_builder.ctx.num_globals = n;
-        building = NULL;
-    }
-
-    if (struct_unions != NULL) {
-        /* unpack a tuple of struct/unions, each described as a sub-tuple;
-           the item 0 of each sub-tuple describes the struct/union, and
-           the items 1..N-1 describe the fields, if any */
-        struct _cffi_struct_union_s *nstructs;
-        struct _cffi_field_s *nfields;
-        Py_ssize_t i, n = PyTuple_GET_SIZE(struct_unions);
-        Py_ssize_t nf = 0;   /* total number of fields */
-
-        for (i = 0; i < n; i++) {
-            nf += PyTuple_GET_SIZE(PyTuple_GET_ITEM(struct_unions, i)) - 1;
-        }
-        i = (n * sizeof(struct _cffi_struct_union_s) +
-             nf * sizeof(struct _cffi_field_s));
-        building = PyMem_Malloc(i);
-        if (building == NULL)
-            goto error;
-        memset(building, 0, i);
-        nstructs = (struct _cffi_struct_union_s *)building;
-        nfields = (struct _cffi_field_s *)(nstructs + n);
-        nf = 0;
-
-        for (i = 0; i < n; i++) {
-            /* 'desc' is the tuple of strings (desc_struct, desc_field_1, ..) */
-            PyObject *desc = PyTuple_GET_ITEM(struct_unions, i);
-            Py_ssize_t j, nf1 = PyTuple_GET_SIZE(desc) - 1;
-            char *s = PyBytes_AS_STRING(PyTuple_GET_ITEM(desc, 0));
-            /* 's' is the first string, describing the struct/union */
-            nstructs[i].type_index = cdl_4bytes(s); s += 4;
-            nstructs[i].flags = cdl_4bytes(s); s += 4;
-            nstructs[i].name = s;
-            if (nstructs[i].flags & (_CFFI_F_OPAQUE | _CFFI_F_EXTERNAL)) {
-                nstructs[i].size = (size_t)-1;
-                nstructs[i].alignment = -1;
-                nstructs[i].first_field_index = -1;
-                nstructs[i].num_fields = 0;
-                assert(nf1 == 0);
-            }
-            else {
-                nstructs[i].size = (size_t)-2;
-                nstructs[i].alignment = -2;
-                nstructs[i].first_field_index = nf;
-                nstructs[i].num_fields = nf1;
-            }
-            for (j = 0; j < nf1; j++) {
-                char *f = PyBytes_AS_STRING(PyTuple_GET_ITEM(desc, j + 1));
-                /* 'f' is one of the other strings beyond the first one,
-                   describing one field each */
-                nfields[nf].field_type_op = cdl_opcode(f); f += 4;
-                nfields[nf].field_offset = (size_t)-1;
-                if (_CFFI_GETOP(nfields[nf].field_type_op) != _CFFI_OP_NOOP) {
-                    nfields[nf].field_size = cdl_4bytes(f); f += 4;
-                }
-                else {
-                    nfields[nf].field_size = (size_t)-1;
-                }
-                nfields[nf].name = f;
-                nf++;
-            }
-        }
-        ffi->types_builder.ctx.struct_unions = nstructs;
-        ffi->types_builder.ctx.fields = nfields;
-        ffi->types_builder.ctx.num_struct_unions = n;
-        building = NULL;
-    }
-
-    if (enums != NULL) {
-        /* unpack a tuple of strings, each of which describes one enum_s
-           entry */
-        struct _cffi_enum_s *nenums;
-        Py_ssize_t i, n = PyTuple_GET_SIZE(enums);
-
-        i = n * sizeof(struct _cffi_enum_s);
-        building = PyMem_Malloc(i);
-        if (building == NULL)
-            goto error;
-        memset(building, 0, i);
-        nenums = (struct _cffi_enum_s *)building;
-
-        for (i = 0; i < n; i++) {
-            char *e = PyBytes_AS_STRING(PyTuple_GET_ITEM(enums, i));
-            /* 'e' is a string describing the enum */
-            nenums[i].type_index = cdl_4bytes(e); e += 4;
-            nenums[i].type_prim = cdl_4bytes(e); e += 4;
-            nenums[i].name = e; e += strlen(e) + 1;
-            nenums[i].enumerators = e;
-        }
-        ffi->types_builder.ctx.enums = nenums;
-        ffi->types_builder.ctx.num_enums = n;
-        building = NULL;
-    }
-
-    if (typenames != NULL) {
-        /* unpack a tuple of strings, each of which describes one typename_s
-           entry */
-        struct _cffi_typename_s *ntypenames;
-        Py_ssize_t i, n = PyTuple_GET_SIZE(typenames);
-
-        i = n * sizeof(struct _cffi_typename_s);
-        building = PyMem_Malloc(i);
-        if (building == NULL)
-            goto error;
-        memset(building, 0, i);
-        ntypenames = (struct _cffi_typename_s *)building;
-
-        for (i = 0; i < n; i++) {
-            char *t = PyBytes_AS_STRING(PyTuple_GET_ITEM(typenames, i));
-            /* 't' is a string describing the typename */
-            ntypenames[i].type_index = cdl_4bytes(t); t += 4;
-            ntypenames[i].name = t;
-        }
-        ffi->types_builder.ctx.typenames = ntypenames;
-        ffi->types_builder.ctx.num_typenames = n;
-        building = NULL;
-    }
-
-    if (includes != NULL) {
-        PyObject *included_libs;
-
-        included_libs = PyTuple_New(PyTuple_GET_SIZE(includes));
-        if (included_libs == NULL)
-            return -1;
-
-        Py_INCREF(includes);
-        ffi->types_builder.included_ffis = includes;
-        ffi->types_builder.included_libs = included_libs;
-    }
-
-    /* Above, we took directly some "char *" strings out of the strings,
-       typically from somewhere inside tuples.  Keep them alive by
-       incref'ing the whole input arguments. */
-    Py_INCREF(args);
-    Py_XINCREF(kwds);
-    ffi->types_builder._keepalive1 = args;
-    ffi->types_builder._keepalive2 = kwds;
-    return 0;
-
- error:
-    if (building != NULL)
-        PyMem_Free(building);
-    if (!PyErr_Occurred())
-        PyErr_NoMemory();
-    return -1;
-}
+    } 
+    Py_INCREF(Py_None); 
+    return Py_None; 
+} 
+ 
+ 
+static Py_ssize_t cdl_4bytes(char *src) 
+{ 
+    /* read 4 bytes in little-endian order; return it as a signed integer */ 
+    signed char *ssrc = (signed char *)src; 
+    unsigned char *usrc = (unsigned char *)src; 
+    return (ssrc[0] << 24) | (usrc[1] << 16) | (usrc[2] << 8) | usrc[3]; 
+} 
+ 
+static _cffi_opcode_t cdl_opcode(char *src) 
+{ 
+    return (_cffi_opcode_t)cdl_4bytes(src); 
+} 
+ 
+typedef struct { 
+    unsigned long long value; 
+    int neg; 
+} cdl_intconst_t; 
+ 
+static int _cdl_realize_global_int(struct _cffi_getconst_s *gc) 
+{ 
+    /* The 'address' field of 'struct _cffi_global_s' is set to point 
+       to this function in case ffiobj_init() sees constant integers. 
+       This fishes around after the 'ctx->globals' array, which is 
+       initialized to contain another array, this time of 
+       'cdl_intconst_t' structures.  We get the nth one and it tells 
+       us what to return. 
+    */ 
+    cdl_intconst_t *ic; 
+    ic = (cdl_intconst_t *)(gc->ctx->globals + gc->ctx->num_globals); 
+    ic += gc->gindex; 
+    gc->value = ic->value; 
+    return ic->neg; 
+} 
+ 
+static int ffiobj_init(PyObject *self, PyObject *args, PyObject *kwds) 
+{ 
+    FFIObject *ffi; 
+    static char *keywords[] = {"module_name", "_version", "_types", 
+                               "_globals", "_struct_unions", "_enums", 
+                               "_typenames", "_includes", NULL}; 
+    char *ffiname = "?", *types = NULL, *building = NULL; 
+    Py_ssize_t version = -1; 
+    Py_ssize_t types_len = 0; 
+    PyObject *globals = NULL, *struct_unions = NULL, *enums = NULL; 
+    PyObject *typenames = NULL, *includes = NULL; 
+ 
+    if (!PyArg_ParseTupleAndKeywords(args, kwds, 
+                                     "|sns#O!O!O!O!O!:FFI", keywords, 
+                                     &ffiname, &version, &types, &types_len, 
+                                     &PyTuple_Type, &globals, 
+                                     &PyTuple_Type, &struct_unions, 
+                                     &PyTuple_Type, &enums, 
+                                     &PyTuple_Type, &typenames, 
+                                     &PyTuple_Type, &includes)) 
+        return -1; 
+ 
+    ffi = (FFIObject *)self; 
+    if (ffi->ctx_is_nonempty) { 
+        PyErr_SetString(PyExc_ValueError, 
+                        "cannot call FFI.__init__() more than once"); 
+        return -1; 
+    } 
+    ffi->ctx_is_nonempty = 1; 
+ 
+    if (version == -1 && types_len == 0) 
+        return 0; 
+    if (version < CFFI_VERSION_MIN || version > CFFI_VERSION_MAX) { 
+        PyErr_Format(PyExc_ImportError, 
+                     "cffi out-of-line Python module '%s' has unknown " 
+                     "version %p", ffiname, (void *)version); 
+        return -1; 
+    } 
+ 
+    if (types_len > 0) { 
+        /* unpack a string of 4-byte entries into an array of _cffi_opcode_t */ 
+        _cffi_opcode_t *ntypes; 
+        Py_ssize_t i, n = types_len / 4; 
+ 
+        building = PyMem_Malloc(n * sizeof(_cffi_opcode_t)); 
+        if (building == NULL) 
+            goto error; 
+        ntypes = (_cffi_opcode_t *)building; 
+ 
+        for (i = 0; i < n; i++) { 
+            ntypes[i] = cdl_opcode(types); 
+            types += 4; 
+        } 
+        ffi->types_builder.ctx.types = ntypes; 
+        ffi->types_builder.ctx.num_types = n; 
+        building = NULL; 
+    } 
+ 
+    if (globals != NULL) { 
+        /* unpack a tuple alternating strings and ints, each two together 
+           describing one global_s entry with no specified address or size. 
+           The int is only used with integer constants. */ 
+        struct _cffi_global_s *nglobs; 
+        cdl_intconst_t *nintconsts; 
+        Py_ssize_t i, n = PyTuple_GET_SIZE(globals) / 2; 
+ 
+        i = n * (sizeof(struct _cffi_global_s) + sizeof(cdl_intconst_t)); 
+        building = PyMem_Malloc(i); 
+        if (building == NULL) 
+            goto error; 
+        memset(building, 0, i); 
+        nglobs = (struct _cffi_global_s *)building; 
+        nintconsts = (cdl_intconst_t *)(nglobs + n); 
+ 
+        for (i = 0; i < n; i++) { 
+            char *g = PyBytes_AS_STRING(PyTuple_GET_ITEM(globals, i * 2)); 
+            nglobs[i].type_op = cdl_opcode(g); g += 4; 
+            nglobs[i].name = g; 
+            if (_CFFI_GETOP(nglobs[i].type_op) == _CFFI_OP_CONSTANT_INT || 
+                _CFFI_GETOP(nglobs[i].type_op) == _CFFI_OP_ENUM) { 
+                PyObject *o = PyTuple_GET_ITEM(globals, i * 2 + 1); 
+                nglobs[i].address = &_cdl_realize_global_int; 
+#if PY_MAJOR_VERSION < 3 
+                if (PyInt_Check(o)) { 
+                    nintconsts[i].neg = PyInt_AS_LONG(o) <= 0; 
+                    nintconsts[i].value = (long long)PyInt_AS_LONG(o); 
+                } 
+                else 
+#endif 
+                { 
+                    nintconsts[i].neg = PyObject_RichCompareBool(o, Py_False, 
+                                                                 Py_LE); 
+                    nintconsts[i].value = PyLong_AsUnsignedLongLongMask(o); 
+                    if (PyErr_Occurred()) 
+                        goto error; 
+                } 
+            } 
+        } 
+        ffi->types_builder.ctx.globals = nglobs; 
+        ffi->types_builder.ctx.num_globals = n; 
+        building = NULL; 
+    } 
+ 
+    if (struct_unions != NULL) { 
+        /* unpack a tuple of struct/unions, each described as a sub-tuple; 
+           the item 0 of each sub-tuple describes the struct/union, and 
+           the items 1..N-1 describe the fields, if any */ 
+        struct _cffi_struct_union_s *nstructs; 
+        struct _cffi_field_s *nfields; 
+        Py_ssize_t i, n = PyTuple_GET_SIZE(struct_unions); 
+        Py_ssize_t nf = 0;   /* total number of fields */ 
+ 
+        for (i = 0; i < n; i++) { 
+            nf += PyTuple_GET_SIZE(PyTuple_GET_ITEM(struct_unions, i)) - 1; 
+        } 
+        i = (n * sizeof(struct _cffi_struct_union_s) + 
+             nf * sizeof(struct _cffi_field_s)); 
+        building = PyMem_Malloc(i); 
+        if (building == NULL) 
+            goto error; 
+        memset(building, 0, i); 
+        nstructs = (struct _cffi_struct_union_s *)building; 
+        nfields = (struct _cffi_field_s *)(nstructs + n); 
+        nf = 0; 
+ 
+        for (i = 0; i < n; i++) { 
+            /* 'desc' is the tuple of strings (desc_struct, desc_field_1, ..) */ 
+            PyObject *desc = PyTuple_GET_ITEM(struct_unions, i); 
+            Py_ssize_t j, nf1 = PyTuple_GET_SIZE(desc) - 1; 
+            char *s = PyBytes_AS_STRING(PyTuple_GET_ITEM(desc, 0)); 
+            /* 's' is the first string, describing the struct/union */ 
+            nstructs[i].type_index = cdl_4bytes(s); s += 4; 
+            nstructs[i].flags = cdl_4bytes(s); s += 4; 
+            nstructs[i].name = s; 
+            if (nstructs[i].flags & (_CFFI_F_OPAQUE | _CFFI_F_EXTERNAL)) { 
+                nstructs[i].size = (size_t)-1; 
+                nstructs[i].alignment = -1; 
+                nstructs[i].first_field_index = -1; 
+                nstructs[i].num_fields = 0; 
+                assert(nf1 == 0); 
+            } 
+            else { 
+                nstructs[i].size = (size_t)-2; 
+                nstructs[i].alignment = -2; 
+                nstructs[i].first_field_index = nf; 
+                nstructs[i].num_fields = nf1; 
+            } 
+            for (j = 0; j < nf1; j++) { 
+                char *f = PyBytes_AS_STRING(PyTuple_GET_ITEM(desc, j + 1)); 
+                /* 'f' is one of the other strings beyond the first one, 
+                   describing one field each */ 
+                nfields[nf].field_type_op = cdl_opcode(f); f += 4; 
+                nfields[nf].field_offset = (size_t)-1; 
+                if (_CFFI_GETOP(nfields[nf].field_type_op) != _CFFI_OP_NOOP) { 
+                    nfields[nf].field_size = cdl_4bytes(f); f += 4; 
+                } 
+                else { 
+                    nfields[nf].field_size = (size_t)-1; 
+                } 
+                nfields[nf].name = f; 
+                nf++; 
+            } 
+        } 
+        ffi->types_builder.ctx.struct_unions = nstructs; 
+        ffi->types_builder.ctx.fields = nfields; 
+        ffi->types_builder.ctx.num_struct_unions = n; 
+        building = NULL; 
+    } 
+ 
+    if (enums != NULL) { 
+        /* unpack a tuple of strings, each of which describes one enum_s 
+           entry */ 
+        struct _cffi_enum_s *nenums; 
+        Py_ssize_t i, n = PyTuple_GET_SIZE(enums); 
+ 
+        i = n * sizeof(struct _cffi_enum_s); 
+        building = PyMem_Malloc(i); 
+        if (building == NULL) 
+            goto error; 
+        memset(building, 0, i); 
+        nenums = (struct _cffi_enum_s *)building; 
+ 
+        for (i = 0; i < n; i++) { 
+            char *e = PyBytes_AS_STRING(PyTuple_GET_ITEM(enums, i)); 
+            /* 'e' is a string describing the enum */ 
+            nenums[i].type_index = cdl_4bytes(e); e += 4; 
+            nenums[i].type_prim = cdl_4bytes(e); e += 4; 
+            nenums[i].name = e; e += strlen(e) + 1; 
+            nenums[i].enumerators = e; 
+        } 
+        ffi->types_builder.ctx.enums = nenums; 
+        ffi->types_builder.ctx.num_enums = n; 
+        building = NULL; 
+    } 
+ 
+    if (typenames != NULL) { 
+        /* unpack a tuple of strings, each of which describes one typename_s 
+           entry */ 
+        struct _cffi_typename_s *ntypenames; 
+        Py_ssize_t i, n = PyTuple_GET_SIZE(typenames); 
+ 
+        i = n * sizeof(struct _cffi_typename_s); 
+        building = PyMem_Malloc(i); 
+        if (building == NULL) 
+            goto error; 
+        memset(building, 0, i); 
+        ntypenames = (struct _cffi_typename_s *)building; 
+ 
+        for (i = 0; i < n; i++) { 
+            char *t = PyBytes_AS_STRING(PyTuple_GET_ITEM(typenames, i)); 
+            /* 't' is a string describing the typename */ 
+            ntypenames[i].type_index = cdl_4bytes(t); t += 4; 
+            ntypenames[i].name = t; 
+        } 
+        ffi->types_builder.ctx.typenames = ntypenames; 
+        ffi->types_builder.ctx.num_typenames = n; 
+        building = NULL; 
+    } 
+ 
+    if (includes != NULL) { 
+        PyObject *included_libs; 
+ 
+        included_libs = PyTuple_New(PyTuple_GET_SIZE(includes)); 
+        if (included_libs == NULL) 
+            return -1; 
+ 
+        Py_INCREF(includes); 
+        ffi->types_builder.included_ffis = includes; 
+        ffi->types_builder.included_libs = included_libs; 
+    } 
+ 
+    /* Above, we took directly some "char *" strings out of the strings, 
+       typically from somewhere inside tuples.  Keep them alive by 
+       incref'ing the whole input arguments. */ 
+    Py_INCREF(args); 
+    Py_XINCREF(kwds); 
+    ffi->types_builder._keepalive1 = args; 
+    ffi->types_builder._keepalive2 = kwds; 
+    return 0; 
+ 
+ error: 
+    if (building != NULL) 
+        PyMem_Free(building); 
+    if (!PyErr_Occurred()) 
+        PyErr_NoMemory(); 
+    return -1; 
+} 

+ 207 - 207
contrib/python/cffi/c/cffi1_module.c

@@ -1,216 +1,216 @@
-
-#include "parse_c_type.c"
-#include "realize_c_type.c"
-
+ 
+#include "parse_c_type.c" 
+#include "realize_c_type.c" 
+ 
 #define CFFI_VERSION_MIN            0x2601
 #define CFFI_VERSION_CHAR16CHAR32   0x2801
 #define CFFI_VERSION_MAX            0x28FF
-
-typedef struct FFIObject_s FFIObject;
-typedef struct LibObject_s LibObject;
-
-static PyTypeObject FFI_Type;   /* forward */
-static PyTypeObject Lib_Type;   /* forward */
-
-#include "ffi_obj.c"
-#include "cglob.c"
-#include "lib_obj.c"
-#include "cdlopen.c"
-#include "commontypes.c"
-#include "call_python.c"
-
-
-static int init_ffi_lib(PyObject *m)
-{
-    PyObject *x;
-    int i, res;
-    static char init_done = 0;
-
-    if (!init_done) {
-        if (init_global_types_dict(FFI_Type.tp_dict) < 0)
-            return -1;
-
-        FFIError = PyErr_NewException("ffi.error", NULL, NULL);
-        if (FFIError == NULL)
-            return -1;
-        if (PyDict_SetItemString(FFI_Type.tp_dict, "error", FFIError) < 0)
-            return -1;
-        if (PyDict_SetItemString(FFI_Type.tp_dict, "CType",
-                                 (PyObject *)&CTypeDescr_Type) < 0)
-            return -1;
-        if (PyDict_SetItemString(FFI_Type.tp_dict, "CData",
-                                 (PyObject *)&CData_Type) < 0)
-            return -1;
+ 
+typedef struct FFIObject_s FFIObject; 
+typedef struct LibObject_s LibObject; 
+ 
+static PyTypeObject FFI_Type;   /* forward */ 
+static PyTypeObject Lib_Type;   /* forward */ 
+ 
+#include "ffi_obj.c" 
+#include "cglob.c" 
+#include "lib_obj.c" 
+#include "cdlopen.c" 
+#include "commontypes.c" 
+#include "call_python.c" 
+ 
+ 
+static int init_ffi_lib(PyObject *m) 
+{ 
+    PyObject *x; 
+    int i, res; 
+    static char init_done = 0; 
+ 
+    if (!init_done) { 
+        if (init_global_types_dict(FFI_Type.tp_dict) < 0) 
+            return -1; 
+ 
+        FFIError = PyErr_NewException("ffi.error", NULL, NULL); 
+        if (FFIError == NULL) 
+            return -1; 
+        if (PyDict_SetItemString(FFI_Type.tp_dict, "error", FFIError) < 0) 
+            return -1; 
+        if (PyDict_SetItemString(FFI_Type.tp_dict, "CType", 
+                                 (PyObject *)&CTypeDescr_Type) < 0) 
+            return -1; 
+        if (PyDict_SetItemString(FFI_Type.tp_dict, "CData", 
+                                 (PyObject *)&CData_Type) < 0) 
+            return -1; 
         if (PyDict_SetItemString(FFI_Type.tp_dict, "buffer",
                                  (PyObject *)&MiniBuffer_Type) < 0)
             return -1;
-
-        for (i = 0; all_dlopen_flags[i].name != NULL; i++) {
-            x = PyInt_FromLong(all_dlopen_flags[i].value);
-            if (x == NULL)
-                return -1;
-            res = PyDict_SetItemString(FFI_Type.tp_dict,
-                                       all_dlopen_flags[i].name, x);
-            Py_DECREF(x);
-            if (res < 0)
-                return -1;
-        }
-        init_done = 1;
-    }
-    return 0;
-}
-
-static int make_included_tuples(char *module_name,
-                                const char *const *ctx_includes,
-                                PyObject **included_ffis,
-                                PyObject **included_libs)
-{
-    Py_ssize_t num = 0;
-    const char *const *p_include;
-
-    if (ctx_includes == NULL)
-        return 0;
-
-    for (p_include = ctx_includes; *p_include; p_include++) {
-        num++;
-    }
-    *included_ffis = PyTuple_New(num);
-    *included_libs = PyTuple_New(num);
-    if (*included_ffis == NULL || *included_libs == NULL)
-        goto error;
-
-    num = 0;
-    for (p_include = ctx_includes; *p_include; p_include++) {
-        PyObject *included_ffi, *included_lib;
-        PyObject *m = PyImport_ImportModule(*p_include);
-        if (m == NULL)
-            goto import_error;
-
-        included_ffi = PyObject_GetAttrString(m, "ffi");
-        PyTuple_SET_ITEM(*included_ffis, num, included_ffi);
-
-        included_lib = (included_ffi == NULL) ? NULL :
-                       PyObject_GetAttrString(m, "lib");
-        PyTuple_SET_ITEM(*included_libs, num, included_lib);
-
-        Py_DECREF(m);
-        if (included_lib == NULL)
-            goto import_error;
-
-        if (!FFIObject_Check(included_ffi) ||
-            !LibObject_Check(included_lib))
-            goto import_error;
-        num++;
-    }
-    return 0;
-
- import_error:
-    PyErr_Format(PyExc_ImportError,
-                 "while loading %.200s: failed to import ffi, lib from %.200s",
-                 module_name, *p_include);
- error:
-    Py_XDECREF(*included_ffis); *included_ffis = NULL;
-    Py_XDECREF(*included_libs); *included_libs = NULL;
-    return -1;
-}
-
-static PyObject *_my_Py_InitModule(char *module_name)
-{
-#if PY_MAJOR_VERSION >= 3
-    struct PyModuleDef *module_def, local_module_def = {
-        PyModuleDef_HEAD_INIT,
-        module_name,
-        NULL,
-        -1,
-        NULL, NULL, NULL, NULL, NULL
-    };
-    /* note: the 'module_def' is allocated dynamically and leaks,
-       but anyway the C extension module can never be unloaded */
-    module_def = PyMem_Malloc(sizeof(struct PyModuleDef));
-    if (module_def == NULL)
-        return PyErr_NoMemory();
-    *module_def = local_module_def;
-    return PyModule_Create(module_def);
-#else
-    return Py_InitModule(module_name, NULL);
-#endif
-}
-
-static PyObject *b_init_cffi_1_0_external_module(PyObject *self, PyObject *arg)
-{
-    PyObject *m, *modules_dict;
-    FFIObject *ffi;
-    LibObject *lib;
-    Py_ssize_t version, num_exports;
-    char *module_name, *exports, *module_name_with_lib;
-    void **raw;
-    const struct _cffi_type_context_s *ctx;
-
-    raw = (void **)PyLong_AsVoidPtr(arg);
-    if (raw == NULL)
-        return NULL;
-
-    module_name = (char *)raw[0];
-    version = (Py_ssize_t)raw[1];
-    exports = (char *)raw[2];
-    ctx = (const struct _cffi_type_context_s *)raw[3];
-
-    if (version < CFFI_VERSION_MIN || version > CFFI_VERSION_MAX) {
-        if (!PyErr_Occurred())
-            PyErr_Format(PyExc_ImportError,
-                "cffi extension module '%s' uses an unknown version tag %p. "
-                "This module might need a more recent version of cffi "
-                "than the one currently installed, which is %s",
-                module_name, (void *)version, CFFI_VERSION);
-        return NULL;
-    }
-
-    /* initialize the exports array */
-    num_exports = 25;
-    if (ctx->flags & 1)    /* set to mean that 'extern "Python"' is used */
-        num_exports = 26;
+ 
+        for (i = 0; all_dlopen_flags[i].name != NULL; i++) { 
+            x = PyInt_FromLong(all_dlopen_flags[i].value); 
+            if (x == NULL) 
+                return -1; 
+            res = PyDict_SetItemString(FFI_Type.tp_dict, 
+                                       all_dlopen_flags[i].name, x); 
+            Py_DECREF(x); 
+            if (res < 0) 
+                return -1; 
+        } 
+        init_done = 1; 
+    } 
+    return 0; 
+} 
+ 
+static int make_included_tuples(char *module_name, 
+                                const char *const *ctx_includes, 
+                                PyObject **included_ffis, 
+                                PyObject **included_libs) 
+{ 
+    Py_ssize_t num = 0; 
+    const char *const *p_include; 
+ 
+    if (ctx_includes == NULL) 
+        return 0; 
+ 
+    for (p_include = ctx_includes; *p_include; p_include++) { 
+        num++; 
+    } 
+    *included_ffis = PyTuple_New(num); 
+    *included_libs = PyTuple_New(num); 
+    if (*included_ffis == NULL || *included_libs == NULL) 
+        goto error; 
+ 
+    num = 0; 
+    for (p_include = ctx_includes; *p_include; p_include++) { 
+        PyObject *included_ffi, *included_lib; 
+        PyObject *m = PyImport_ImportModule(*p_include); 
+        if (m == NULL) 
+            goto import_error; 
+ 
+        included_ffi = PyObject_GetAttrString(m, "ffi"); 
+        PyTuple_SET_ITEM(*included_ffis, num, included_ffi); 
+ 
+        included_lib = (included_ffi == NULL) ? NULL : 
+                       PyObject_GetAttrString(m, "lib"); 
+        PyTuple_SET_ITEM(*included_libs, num, included_lib); 
+ 
+        Py_DECREF(m); 
+        if (included_lib == NULL) 
+            goto import_error; 
+ 
+        if (!FFIObject_Check(included_ffi) || 
+            !LibObject_Check(included_lib)) 
+            goto import_error; 
+        num++; 
+    } 
+    return 0; 
+ 
+ import_error: 
+    PyErr_Format(PyExc_ImportError, 
+                 "while loading %.200s: failed to import ffi, lib from %.200s", 
+                 module_name, *p_include); 
+ error: 
+    Py_XDECREF(*included_ffis); *included_ffis = NULL; 
+    Py_XDECREF(*included_libs); *included_libs = NULL; 
+    return -1; 
+} 
+ 
+static PyObject *_my_Py_InitModule(char *module_name) 
+{ 
+#if PY_MAJOR_VERSION >= 3 
+    struct PyModuleDef *module_def, local_module_def = { 
+        PyModuleDef_HEAD_INIT, 
+        module_name, 
+        NULL, 
+        -1, 
+        NULL, NULL, NULL, NULL, NULL 
+    }; 
+    /* note: the 'module_def' is allocated dynamically and leaks, 
+       but anyway the C extension module can never be unloaded */ 
+    module_def = PyMem_Malloc(sizeof(struct PyModuleDef)); 
+    if (module_def == NULL) 
+        return PyErr_NoMemory(); 
+    *module_def = local_module_def; 
+    return PyModule_Create(module_def); 
+#else 
+    return Py_InitModule(module_name, NULL); 
+#endif 
+} 
+ 
+static PyObject *b_init_cffi_1_0_external_module(PyObject *self, PyObject *arg) 
+{ 
+    PyObject *m, *modules_dict; 
+    FFIObject *ffi; 
+    LibObject *lib; 
+    Py_ssize_t version, num_exports; 
+    char *module_name, *exports, *module_name_with_lib; 
+    void **raw; 
+    const struct _cffi_type_context_s *ctx; 
+ 
+    raw = (void **)PyLong_AsVoidPtr(arg); 
+    if (raw == NULL) 
+        return NULL; 
+ 
+    module_name = (char *)raw[0]; 
+    version = (Py_ssize_t)raw[1]; 
+    exports = (char *)raw[2]; 
+    ctx = (const struct _cffi_type_context_s *)raw[3]; 
+ 
+    if (version < CFFI_VERSION_MIN || version > CFFI_VERSION_MAX) { 
+        if (!PyErr_Occurred()) 
+            PyErr_Format(PyExc_ImportError, 
+                "cffi extension module '%s' uses an unknown version tag %p. " 
+                "This module might need a more recent version of cffi " 
+                "than the one currently installed, which is %s", 
+                module_name, (void *)version, CFFI_VERSION); 
+        return NULL; 
+    } 
+ 
+    /* initialize the exports array */ 
+    num_exports = 25; 
+    if (ctx->flags & 1)    /* set to mean that 'extern "Python"' is used */ 
+        num_exports = 26; 
     if (version >= CFFI_VERSION_CHAR16CHAR32)
         num_exports = 28;
-    memcpy(exports, (char *)cffi_exports, num_exports * sizeof(void *));
-
-    /* make the module object */
-    m = _my_Py_InitModule(module_name);
-    if (m == NULL)
-        return NULL;
-
-    /* build the FFI and Lib object inside this new module */
-    ffi = ffi_internal_new(&FFI_Type, ctx);
-    Py_XINCREF(ffi);    /* make the ffi object really immortal */
-    if (ffi == NULL || PyModule_AddObject(m, "ffi", (PyObject *)ffi) < 0)
-        return NULL;
-
+    memcpy(exports, (char *)cffi_exports, num_exports * sizeof(void *)); 
+ 
+    /* make the module object */ 
+    m = _my_Py_InitModule(module_name); 
+    if (m == NULL) 
+        return NULL; 
+ 
+    /* build the FFI and Lib object inside this new module */ 
+    ffi = ffi_internal_new(&FFI_Type, ctx); 
+    Py_XINCREF(ffi);    /* make the ffi object really immortal */ 
+    if (ffi == NULL || PyModule_AddObject(m, "ffi", (PyObject *)ffi) < 0) 
+        return NULL; 
+ 
     lib = lib_internal_new(ffi, module_name, NULL, 0);
-    if (lib == NULL || PyModule_AddObject(m, "lib", (PyObject *)lib) < 0)
-        return NULL;
-
-    if (make_included_tuples(module_name, ctx->includes,
-                             &ffi->types_builder.included_ffis,
-                             &lib->l_types_builder->included_libs) < 0)
-        return NULL;
-
-    /* add manually 'module_name.lib' in sys.modules:
-       see test_import_from_lib */
-    modules_dict = PySys_GetObject("modules");
-    if (!modules_dict)
-        return NULL;
-    module_name_with_lib = alloca(strlen(module_name) + 5);
-    strcpy(module_name_with_lib, module_name);
-    strcat(module_name_with_lib, ".lib");
-    if (PyDict_SetItemString(modules_dict, module_name_with_lib,
-                             (PyObject *)lib) < 0)
-        return NULL;
-
-#if PY_MAJOR_VERSION >= 3
-    /* add manually 'module_name' in sys.modules: it seems that 
-       Py_InitModule() is not enough to do that */
-    if (PyDict_SetItemString(modules_dict, module_name, m) < 0)
-        return NULL;
-#endif
-
-    return m;
-}
+    if (lib == NULL || PyModule_AddObject(m, "lib", (PyObject *)lib) < 0) 
+        return NULL; 
+ 
+    if (make_included_tuples(module_name, ctx->includes, 
+                             &ffi->types_builder.included_ffis, 
+                             &lib->l_types_builder->included_libs) < 0) 
+        return NULL; 
+ 
+    /* add manually 'module_name.lib' in sys.modules: 
+       see test_import_from_lib */ 
+    modules_dict = PySys_GetObject("modules"); 
+    if (!modules_dict) 
+        return NULL; 
+    module_name_with_lib = alloca(strlen(module_name) + 5); 
+    strcpy(module_name_with_lib, module_name); 
+    strcat(module_name_with_lib, ".lib"); 
+    if (PyDict_SetItemString(modules_dict, module_name_with_lib, 
+                             (PyObject *)lib) < 0) 
+        return NULL; 
+ 
+#if PY_MAJOR_VERSION >= 3 
+    /* add manually 'module_name' in sys.modules: it seems that  
+       Py_InitModule() is not enough to do that */ 
+    if (PyDict_SetItemString(modules_dict, module_name, m) < 0) 
+        return NULL; 
+#endif 
+ 
+    return m; 
+} 

+ 112 - 112
contrib/python/cffi/c/cglob.c

@@ -1,113 +1,113 @@
-
-typedef void *(*gs_fetch_addr_fn)(void);
-
-typedef struct {
-    PyObject_HEAD
-
-    PyObject         *gs_name;
-    CTypeDescrObject *gs_type;
-    char             *gs_data;
-    gs_fetch_addr_fn  gs_fetch_addr;
-
-} GlobSupportObject;
-
-static void glob_support_dealloc(GlobSupportObject *gs)
-{
-    Py_DECREF(gs->gs_name);
-    Py_DECREF(gs->gs_type);
-    PyObject_Del(gs);
-}
-
-static PyTypeObject GlobSupport_Type = {
-    PyVarObject_HEAD_INIT(NULL, 0)
+ 
+typedef void *(*gs_fetch_addr_fn)(void); 
+ 
+typedef struct { 
+    PyObject_HEAD 
+ 
+    PyObject         *gs_name; 
+    CTypeDescrObject *gs_type; 
+    char             *gs_data; 
+    gs_fetch_addr_fn  gs_fetch_addr; 
+ 
+} GlobSupportObject; 
+ 
+static void glob_support_dealloc(GlobSupportObject *gs) 
+{ 
+    Py_DECREF(gs->gs_name); 
+    Py_DECREF(gs->gs_type); 
+    PyObject_Del(gs); 
+} 
+ 
+static PyTypeObject GlobSupport_Type = { 
+    PyVarObject_HEAD_INIT(NULL, 0) 
     "_cffi_backend.__FFIGlobSupport",
-    sizeof(GlobSupportObject),
-    0,
-    (destructor)glob_support_dealloc,           /* tp_dealloc */
-    0,                                          /* tp_print */
-    0,                                          /* tp_getattr */
-    0,                                          /* tp_setattr */
-    0,                                          /* tp_compare */
-    0,                                          /* tp_repr */
-    0,                                          /* tp_as_number */
-    0,                                          /* tp_as_sequence */
-    0,                                          /* tp_as_mapping */
-    0,                                          /* tp_hash */
-    0,                                          /* tp_call */
-    0,                                          /* tp_str */
-    PyObject_GenericGetAttr,                    /* tp_getattro */
-    0,                                          /* tp_setattro */
-    0,                                          /* tp_as_buffer */
-    Py_TPFLAGS_DEFAULT,                         /* tp_flags */
-};
-
-#define GlobSupport_Check(ob)  (Py_TYPE(ob) == &GlobSupport_Type)
-
-static PyObject *make_global_var(PyObject *name, CTypeDescrObject *type,
-                                 char *addr, gs_fetch_addr_fn fetch_addr)
-{
-    GlobSupportObject *gs = PyObject_New(GlobSupportObject, &GlobSupport_Type);
-    if (gs == NULL)
-        return NULL;
-
-    Py_INCREF(name);
-    Py_INCREF(type);
-    gs->gs_name = name;
-    gs->gs_type = type;
-    gs->gs_data = addr;
-    gs->gs_fetch_addr = fetch_addr;
-    return (PyObject *)gs;
-}
-
-static void *fetch_global_var_addr(GlobSupportObject *gs)
-{
-    void *data;
-    if (gs->gs_data != NULL) {
-        data = gs->gs_data;
-    }
-    else {
-        Py_BEGIN_ALLOW_THREADS
-        restore_errno();
-        data = gs->gs_fetch_addr();
-        save_errno();
-        Py_END_ALLOW_THREADS
-    }
-    if (data == NULL) {
-        PyErr_Format(FFIError, "global variable '%s' is at address NULL",
-                     PyText_AS_UTF8(gs->gs_name));
-        return NULL;
-    }
-    return data;
-}
-
-static PyObject *read_global_var(GlobSupportObject *gs)
-{
-    void *data = fetch_global_var_addr(gs);
-    if (data == NULL)
-        return NULL;
-    return convert_to_object(data, gs->gs_type);
-}
-
-static int write_global_var(GlobSupportObject *gs, PyObject *obj)
-{
-    void *data = fetch_global_var_addr(gs);
-    if (data == NULL)
-        return -1;
-    return convert_from_object(data, gs->gs_type, obj);
-}
-
-static PyObject *cg_addressof_global_var(GlobSupportObject *gs)
-{
-    void *data;
-    PyObject *x, *ptrtype = new_pointer_type(gs->gs_type);
-    if (ptrtype == NULL)
-        return NULL;
-
-    data = fetch_global_var_addr(gs);
-    if (data != NULL)
-        x = new_simple_cdata(data, (CTypeDescrObject *)ptrtype);
-    else
-        x = NULL;
-    Py_DECREF(ptrtype);
-    return x;
-}
+    sizeof(GlobSupportObject), 
+    0, 
+    (destructor)glob_support_dealloc,           /* tp_dealloc */ 
+    0,                                          /* tp_print */ 
+    0,                                          /* tp_getattr */ 
+    0,                                          /* tp_setattr */ 
+    0,                                          /* tp_compare */ 
+    0,                                          /* tp_repr */ 
+    0,                                          /* tp_as_number */ 
+    0,                                          /* tp_as_sequence */ 
+    0,                                          /* tp_as_mapping */ 
+    0,                                          /* tp_hash */ 
+    0,                                          /* tp_call */ 
+    0,                                          /* tp_str */ 
+    PyObject_GenericGetAttr,                    /* tp_getattro */ 
+    0,                                          /* tp_setattro */ 
+    0,                                          /* tp_as_buffer */ 
+    Py_TPFLAGS_DEFAULT,                         /* tp_flags */ 
+}; 
+ 
+#define GlobSupport_Check(ob)  (Py_TYPE(ob) == &GlobSupport_Type) 
+ 
+static PyObject *make_global_var(PyObject *name, CTypeDescrObject *type, 
+                                 char *addr, gs_fetch_addr_fn fetch_addr) 
+{ 
+    GlobSupportObject *gs = PyObject_New(GlobSupportObject, &GlobSupport_Type); 
+    if (gs == NULL) 
+        return NULL; 
+ 
+    Py_INCREF(name); 
+    Py_INCREF(type); 
+    gs->gs_name = name; 
+    gs->gs_type = type; 
+    gs->gs_data = addr; 
+    gs->gs_fetch_addr = fetch_addr; 
+    return (PyObject *)gs; 
+} 
+ 
+static void *fetch_global_var_addr(GlobSupportObject *gs) 
+{ 
+    void *data; 
+    if (gs->gs_data != NULL) { 
+        data = gs->gs_data; 
+    } 
+    else { 
+        Py_BEGIN_ALLOW_THREADS 
+        restore_errno(); 
+        data = gs->gs_fetch_addr(); 
+        save_errno(); 
+        Py_END_ALLOW_THREADS 
+    } 
+    if (data == NULL) { 
+        PyErr_Format(FFIError, "global variable '%s' is at address NULL", 
+                     PyText_AS_UTF8(gs->gs_name)); 
+        return NULL; 
+    } 
+    return data; 
+} 
+ 
+static PyObject *read_global_var(GlobSupportObject *gs) 
+{ 
+    void *data = fetch_global_var_addr(gs); 
+    if (data == NULL) 
+        return NULL; 
+    return convert_to_object(data, gs->gs_type); 
+} 
+ 
+static int write_global_var(GlobSupportObject *gs, PyObject *obj) 
+{ 
+    void *data = fetch_global_var_addr(gs); 
+    if (data == NULL) 
+        return -1; 
+    return convert_from_object(data, gs->gs_type, obj); 
+} 
+ 
+static PyObject *cg_addressof_global_var(GlobSupportObject *gs) 
+{ 
+    void *data; 
+    PyObject *x, *ptrtype = new_pointer_type(gs->gs_type); 
+    if (ptrtype == NULL) 
+        return NULL; 
+ 
+    data = fetch_global_var_addr(gs); 
+    if (data != NULL) 
+        x = new_simple_cdata(data, (CTypeDescrObject *)ptrtype); 
+    else 
+        x = NULL; 
+    Py_DECREF(ptrtype); 
+    return x; 
+} 

+ 216 - 216
contrib/python/cffi/c/commontypes.c

@@ -1,216 +1,216 @@
-/* This file must be kept in alphabetical order.  See test_commontypes.py */
-
-#define EQ(key, value)    key "\0" value   /* string concatenation */
-#ifdef _WIN64
-#  define W32_64(X,Y)  Y
-# else
-#  define W32_64(X,Y)  X
-# endif
-
-
-static const char *common_simple_types[] = {
-
-#ifdef MS_WIN32   /* Windows types */
-    EQ("ATOM", "WORD"),
-    EQ("BOOL", "int"),
-    EQ("BOOLEAN", "BYTE"),
-    EQ("BYTE", "unsigned char"),
-    EQ("CCHAR", "char"),
-    EQ("CHAR", "char"),
-    EQ("COLORREF", "DWORD"),
-    EQ("DWORD", "unsigned long"),
-    EQ("DWORD32", "unsigned int"),
-    EQ("DWORD64", "unsigned long long"),
-    EQ("DWORDLONG", "ULONGLONG"),
-    EQ("DWORD_PTR", "ULONG_PTR"),
-#endif
-
-    EQ("FILE", "struct _IO_FILE"),
-
-#ifdef MS_WIN32   /* more Windows types */
-    EQ("FLOAT", "float"),
-    EQ("HACCEL", "HANDLE"),
-    EQ("HALF_PTR", W32_64("short","int")),
-    EQ("HANDLE", "PVOID"),
-    EQ("HBITMAP", "HANDLE"),
-    EQ("HBRUSH", "HANDLE"),
-    EQ("HCOLORSPACE", "HANDLE"),
-    EQ("HCONV", "HANDLE"),
-    EQ("HCONVLIST", "HANDLE"),
-    EQ("HCURSOR", "HICON"),
-    EQ("HDC", "HANDLE"),
-    EQ("HDDEDATA", "HANDLE"),
-    EQ("HDESK", "HANDLE"),
-    EQ("HDROP", "HANDLE"),
-    EQ("HDWP", "HANDLE"),
-    EQ("HENHMETAFILE", "HANDLE"),
-    EQ("HFILE", "int"),
-    EQ("HFONT", "HANDLE"),
-    EQ("HGDIOBJ", "HANDLE"),
-    EQ("HGLOBAL", "HANDLE"),
-    EQ("HHOOK", "HANDLE"),
-    EQ("HICON", "HANDLE"),
-    EQ("HINSTANCE", "HANDLE"),
-    EQ("HKEY", "HANDLE"),
-    EQ("HKL", "HANDLE"),
-    EQ("HLOCAL", "HANDLE"),
-    EQ("HMENU", "HANDLE"),
-    EQ("HMETAFILE", "HANDLE"),
-    EQ("HMODULE", "HINSTANCE"),
-    EQ("HMONITOR", "HANDLE"),
-    EQ("HPALETTE", "HANDLE"),
-    EQ("HPEN", "HANDLE"),
-    EQ("HRESULT", "LONG"),
-    EQ("HRGN", "HANDLE"),
-    EQ("HRSRC", "HANDLE"),
-    EQ("HSZ", "HANDLE"),
-    EQ("HWND", "HANDLE"),
-    EQ("INT", "int"),
-    EQ("INT16", "short"),
-    EQ("INT32", "int"),
-    EQ("INT64", "long long"),
-    EQ("INT8", "signed char"),
-    EQ("INT_PTR", W32_64("int","long long")),
-    EQ("LANGID", "WORD"),
-    EQ("LCID", "DWORD"),
-    EQ("LCTYPE", "DWORD"),
-    EQ("LGRPID", "DWORD"),
-    EQ("LONG", "long"),
-    EQ("LONG32", "int"),
-    EQ("LONG64", "long long"),
-    EQ("LONGLONG", "long long"),
-    EQ("LONG_PTR", W32_64("long","long long")),
-    EQ("LPARAM", "LONG_PTR"),
-    EQ("LPBOOL", "BOOL *"),
-    EQ("LPBYTE", "BYTE *"),
-    EQ("LPCOLORREF", "DWORD *"),
-    EQ("LPCSTR", "const char *"),
-    EQ("LPCVOID", "const void *"),
-    EQ("LPCWSTR", "const WCHAR *"),
-    EQ("LPDWORD", "DWORD *"),
-    EQ("LPHANDLE", "HANDLE *"),
-    EQ("LPINT", "int *"),
-    EQ("LPLONG", "long *"),
-    EQ("LPSTR", "CHAR *"),
-    EQ("LPVOID", "void *"),
-    EQ("LPWORD", "WORD *"),
-    EQ("LPWSTR", "WCHAR *"),
-    EQ("LRESULT", "LONG_PTR"),
-    EQ("PBOOL", "BOOL *"),
-    EQ("PBOOLEAN", "BOOLEAN *"),
-    EQ("PBYTE", "BYTE *"),
-    EQ("PCHAR", "CHAR *"),
-    EQ("PCSTR", "const CHAR *"),
-    EQ("PCWSTR", "const WCHAR *"),
-    EQ("PDWORD", "DWORD *"),
-    EQ("PDWORD32", "DWORD32 *"),
-    EQ("PDWORD64", "DWORD64 *"),
-    EQ("PDWORDLONG", "DWORDLONG *"),
-    EQ("PDWORD_PTR", "DWORD_PTR *"),
-    EQ("PFLOAT", "FLOAT *"),
-    EQ("PHALF_PTR", "HALF_PTR *"),
-    EQ("PHANDLE", "HANDLE *"),
-    EQ("PHKEY", "HKEY *"),
-    EQ("PINT", "int *"),
-    EQ("PINT16", "INT16 *"),
-    EQ("PINT32", "INT32 *"),
-    EQ("PINT64", "INT64 *"),
-    EQ("PINT8", "INT8 *"),
-    EQ("PINT_PTR", "INT_PTR *"),
-    EQ("PLCID", "PDWORD"),
-    EQ("PLONG", "LONG *"),
-    EQ("PLONG32", "LONG32 *"),
-    EQ("PLONG64", "LONG64 *"),
-    EQ("PLONGLONG", "LONGLONG *"),
-    EQ("PLONG_PTR", "LONG_PTR *"),
-    EQ("PSHORT", "SHORT *"),
-    EQ("PSIZE_T", "SIZE_T *"),
-    EQ("PSSIZE_T", "SSIZE_T *"),
-    EQ("PSTR", "CHAR *"),
-    EQ("PUCHAR", "UCHAR *"),
-    EQ("PUHALF_PTR", "UHALF_PTR *"),
-    EQ("PUINT", "UINT *"),
-    EQ("PUINT16", "UINT16 *"),
-    EQ("PUINT32", "UINT32 *"),
-    EQ("PUINT64", "UINT64 *"),
-    EQ("PUINT8", "UINT8 *"),
-    EQ("PUINT_PTR", "UINT_PTR *"),
-    EQ("PULONG", "ULONG *"),
-    EQ("PULONG32", "ULONG32 *"),
-    EQ("PULONG64", "ULONG64 *"),
-    EQ("PULONGLONG", "ULONGLONG *"),
-    EQ("PULONG_PTR", "ULONG_PTR *"),
-    EQ("PUSHORT", "USHORT *"),
-    EQ("PVOID", "void *"),
-    EQ("PWCHAR", "WCHAR *"),
-    EQ("PWORD", "WORD *"),
-    EQ("PWSTR", "WCHAR *"),
-    EQ("QWORD", "unsigned long long"),
-    EQ("SC_HANDLE", "HANDLE"),
-    EQ("SC_LOCK", "LPVOID"),
-    EQ("SERVICE_STATUS_HANDLE", "HANDLE"),
-    EQ("SHORT", "short"),
-    EQ("SIZE_T", "ULONG_PTR"),
-    EQ("SSIZE_T", "LONG_PTR"),
-    EQ("UCHAR", "unsigned char"),
-    EQ("UHALF_PTR", W32_64("unsigned short","unsigned int")),
-    EQ("UINT", "unsigned int"),
-    EQ("UINT16", "unsigned short"),
-    EQ("UINT32", "unsigned int"),
-    EQ("UINT64", "unsigned long long"),
-    EQ("UINT8", "unsigned char"),
-    EQ("UINT_PTR", W32_64("unsigned int","unsigned long long")),
-    EQ("ULONG", "unsigned long"),
-    EQ("ULONG32", "unsigned int"),
-    EQ("ULONG64", "unsigned long long"),
-    EQ("ULONGLONG", "unsigned long long"),
-    EQ("ULONG_PTR", W32_64("unsigned long","unsigned long long")),
-    EQ("USHORT", "unsigned short"),
-    EQ("USN", "LONGLONG"),
-    EQ("VOID", "void"),
-    EQ("WCHAR", "wchar_t"),
-    EQ("WINSTA", "HANDLE"),
-    EQ("WORD", "unsigned short"),
-    EQ("WPARAM", "UINT_PTR"),
-#endif
-
-    EQ("bool", "_Bool"),
-};
-
-
-#undef EQ
-#undef W32_64
-
-#define num_common_simple_types    \
-    (sizeof(common_simple_types) / sizeof(common_simple_types[0]))
-
-
-static const char *get_common_type(const char *search, size_t search_len)
-{
-    const char *entry;
-    int index = search_sorted(common_simple_types, sizeof(const char *),
-                              num_common_simple_types, search, search_len);
-    if (index < 0)
-        return NULL;
-
-    entry = common_simple_types[index];
-    return entry + strlen(entry) + 1;
-}
-
-static PyObject *b__get_common_types(PyObject *self, PyObject *arg)
-{
-    int err;
-    size_t i;
-    for (i = 0; i < num_common_simple_types; i++) {
-        const char *s = common_simple_types[i];
-        PyObject *o = PyText_FromString(s + strlen(s) + 1);
-        if (o == NULL)
-            return NULL;
-        err = PyDict_SetItemString(arg, s, o);
-        Py_DECREF(o);
-        if (err < 0)
-            return NULL;
-    }
-    Py_INCREF(Py_None);
-    return Py_None;
-}
+/* This file must be kept in alphabetical order.  See test_commontypes.py */ 
+ 
+#define EQ(key, value)    key "\0" value   /* string concatenation */ 
+#ifdef _WIN64 
+#  define W32_64(X,Y)  Y 
+# else 
+#  define W32_64(X,Y)  X 
+# endif 
+ 
+ 
+static const char *common_simple_types[] = { 
+ 
+#ifdef MS_WIN32   /* Windows types */ 
+    EQ("ATOM", "WORD"), 
+    EQ("BOOL", "int"), 
+    EQ("BOOLEAN", "BYTE"), 
+    EQ("BYTE", "unsigned char"), 
+    EQ("CCHAR", "char"), 
+    EQ("CHAR", "char"), 
+    EQ("COLORREF", "DWORD"), 
+    EQ("DWORD", "unsigned long"), 
+    EQ("DWORD32", "unsigned int"), 
+    EQ("DWORD64", "unsigned long long"), 
+    EQ("DWORDLONG", "ULONGLONG"), 
+    EQ("DWORD_PTR", "ULONG_PTR"), 
+#endif 
+ 
+    EQ("FILE", "struct _IO_FILE"), 
+ 
+#ifdef MS_WIN32   /* more Windows types */ 
+    EQ("FLOAT", "float"), 
+    EQ("HACCEL", "HANDLE"), 
+    EQ("HALF_PTR", W32_64("short","int")), 
+    EQ("HANDLE", "PVOID"), 
+    EQ("HBITMAP", "HANDLE"), 
+    EQ("HBRUSH", "HANDLE"), 
+    EQ("HCOLORSPACE", "HANDLE"), 
+    EQ("HCONV", "HANDLE"), 
+    EQ("HCONVLIST", "HANDLE"), 
+    EQ("HCURSOR", "HICON"), 
+    EQ("HDC", "HANDLE"), 
+    EQ("HDDEDATA", "HANDLE"), 
+    EQ("HDESK", "HANDLE"), 
+    EQ("HDROP", "HANDLE"), 
+    EQ("HDWP", "HANDLE"), 
+    EQ("HENHMETAFILE", "HANDLE"), 
+    EQ("HFILE", "int"), 
+    EQ("HFONT", "HANDLE"), 
+    EQ("HGDIOBJ", "HANDLE"), 
+    EQ("HGLOBAL", "HANDLE"), 
+    EQ("HHOOK", "HANDLE"), 
+    EQ("HICON", "HANDLE"), 
+    EQ("HINSTANCE", "HANDLE"), 
+    EQ("HKEY", "HANDLE"), 
+    EQ("HKL", "HANDLE"), 
+    EQ("HLOCAL", "HANDLE"), 
+    EQ("HMENU", "HANDLE"), 
+    EQ("HMETAFILE", "HANDLE"), 
+    EQ("HMODULE", "HINSTANCE"), 
+    EQ("HMONITOR", "HANDLE"), 
+    EQ("HPALETTE", "HANDLE"), 
+    EQ("HPEN", "HANDLE"), 
+    EQ("HRESULT", "LONG"), 
+    EQ("HRGN", "HANDLE"), 
+    EQ("HRSRC", "HANDLE"), 
+    EQ("HSZ", "HANDLE"), 
+    EQ("HWND", "HANDLE"), 
+    EQ("INT", "int"), 
+    EQ("INT16", "short"), 
+    EQ("INT32", "int"), 
+    EQ("INT64", "long long"), 
+    EQ("INT8", "signed char"), 
+    EQ("INT_PTR", W32_64("int","long long")), 
+    EQ("LANGID", "WORD"), 
+    EQ("LCID", "DWORD"), 
+    EQ("LCTYPE", "DWORD"), 
+    EQ("LGRPID", "DWORD"), 
+    EQ("LONG", "long"), 
+    EQ("LONG32", "int"), 
+    EQ("LONG64", "long long"), 
+    EQ("LONGLONG", "long long"), 
+    EQ("LONG_PTR", W32_64("long","long long")), 
+    EQ("LPARAM", "LONG_PTR"), 
+    EQ("LPBOOL", "BOOL *"), 
+    EQ("LPBYTE", "BYTE *"), 
+    EQ("LPCOLORREF", "DWORD *"), 
+    EQ("LPCSTR", "const char *"), 
+    EQ("LPCVOID", "const void *"), 
+    EQ("LPCWSTR", "const WCHAR *"), 
+    EQ("LPDWORD", "DWORD *"), 
+    EQ("LPHANDLE", "HANDLE *"), 
+    EQ("LPINT", "int *"), 
+    EQ("LPLONG", "long *"), 
+    EQ("LPSTR", "CHAR *"), 
+    EQ("LPVOID", "void *"), 
+    EQ("LPWORD", "WORD *"), 
+    EQ("LPWSTR", "WCHAR *"), 
+    EQ("LRESULT", "LONG_PTR"), 
+    EQ("PBOOL", "BOOL *"), 
+    EQ("PBOOLEAN", "BOOLEAN *"), 
+    EQ("PBYTE", "BYTE *"), 
+    EQ("PCHAR", "CHAR *"), 
+    EQ("PCSTR", "const CHAR *"), 
+    EQ("PCWSTR", "const WCHAR *"), 
+    EQ("PDWORD", "DWORD *"), 
+    EQ("PDWORD32", "DWORD32 *"), 
+    EQ("PDWORD64", "DWORD64 *"), 
+    EQ("PDWORDLONG", "DWORDLONG *"), 
+    EQ("PDWORD_PTR", "DWORD_PTR *"), 
+    EQ("PFLOAT", "FLOAT *"), 
+    EQ("PHALF_PTR", "HALF_PTR *"), 
+    EQ("PHANDLE", "HANDLE *"), 
+    EQ("PHKEY", "HKEY *"), 
+    EQ("PINT", "int *"), 
+    EQ("PINT16", "INT16 *"), 
+    EQ("PINT32", "INT32 *"), 
+    EQ("PINT64", "INT64 *"), 
+    EQ("PINT8", "INT8 *"), 
+    EQ("PINT_PTR", "INT_PTR *"), 
+    EQ("PLCID", "PDWORD"), 
+    EQ("PLONG", "LONG *"), 
+    EQ("PLONG32", "LONG32 *"), 
+    EQ("PLONG64", "LONG64 *"), 
+    EQ("PLONGLONG", "LONGLONG *"), 
+    EQ("PLONG_PTR", "LONG_PTR *"), 
+    EQ("PSHORT", "SHORT *"), 
+    EQ("PSIZE_T", "SIZE_T *"), 
+    EQ("PSSIZE_T", "SSIZE_T *"), 
+    EQ("PSTR", "CHAR *"), 
+    EQ("PUCHAR", "UCHAR *"), 
+    EQ("PUHALF_PTR", "UHALF_PTR *"), 
+    EQ("PUINT", "UINT *"), 
+    EQ("PUINT16", "UINT16 *"), 
+    EQ("PUINT32", "UINT32 *"), 
+    EQ("PUINT64", "UINT64 *"), 
+    EQ("PUINT8", "UINT8 *"), 
+    EQ("PUINT_PTR", "UINT_PTR *"), 
+    EQ("PULONG", "ULONG *"), 
+    EQ("PULONG32", "ULONG32 *"), 
+    EQ("PULONG64", "ULONG64 *"), 
+    EQ("PULONGLONG", "ULONGLONG *"), 
+    EQ("PULONG_PTR", "ULONG_PTR *"), 
+    EQ("PUSHORT", "USHORT *"), 
+    EQ("PVOID", "void *"), 
+    EQ("PWCHAR", "WCHAR *"), 
+    EQ("PWORD", "WORD *"), 
+    EQ("PWSTR", "WCHAR *"), 
+    EQ("QWORD", "unsigned long long"), 
+    EQ("SC_HANDLE", "HANDLE"), 
+    EQ("SC_LOCK", "LPVOID"), 
+    EQ("SERVICE_STATUS_HANDLE", "HANDLE"), 
+    EQ("SHORT", "short"), 
+    EQ("SIZE_T", "ULONG_PTR"), 
+    EQ("SSIZE_T", "LONG_PTR"), 
+    EQ("UCHAR", "unsigned char"), 
+    EQ("UHALF_PTR", W32_64("unsigned short","unsigned int")), 
+    EQ("UINT", "unsigned int"), 
+    EQ("UINT16", "unsigned short"), 
+    EQ("UINT32", "unsigned int"), 
+    EQ("UINT64", "unsigned long long"), 
+    EQ("UINT8", "unsigned char"), 
+    EQ("UINT_PTR", W32_64("unsigned int","unsigned long long")), 
+    EQ("ULONG", "unsigned long"), 
+    EQ("ULONG32", "unsigned int"), 
+    EQ("ULONG64", "unsigned long long"), 
+    EQ("ULONGLONG", "unsigned long long"), 
+    EQ("ULONG_PTR", W32_64("unsigned long","unsigned long long")), 
+    EQ("USHORT", "unsigned short"), 
+    EQ("USN", "LONGLONG"), 
+    EQ("VOID", "void"), 
+    EQ("WCHAR", "wchar_t"), 
+    EQ("WINSTA", "HANDLE"), 
+    EQ("WORD", "unsigned short"), 
+    EQ("WPARAM", "UINT_PTR"), 
+#endif 
+ 
+    EQ("bool", "_Bool"), 
+}; 
+ 
+ 
+#undef EQ 
+#undef W32_64 
+ 
+#define num_common_simple_types    \ 
+    (sizeof(common_simple_types) / sizeof(common_simple_types[0])) 
+ 
+ 
+static const char *get_common_type(const char *search, size_t search_len) 
+{ 
+    const char *entry; 
+    int index = search_sorted(common_simple_types, sizeof(const char *), 
+                              num_common_simple_types, search, search_len); 
+    if (index < 0) 
+        return NULL; 
+ 
+    entry = common_simple_types[index]; 
+    return entry + strlen(entry) + 1; 
+} 
+ 
+static PyObject *b__get_common_types(PyObject *self, PyObject *arg) 
+{ 
+    int err; 
+    size_t i; 
+    for (i = 0; i < num_common_simple_types; i++) { 
+        const char *s = common_simple_types[i]; 
+        PyObject *o = PyText_FromString(s + strlen(s) + 1); 
+        if (o == NULL) 
+            return NULL; 
+        err = PyDict_SetItemString(arg, s, o); 
+        Py_DECREF(o); 
+        if (err < 0) 
+            return NULL; 
+    } 
+    Py_INCREF(Py_None); 
+    return Py_None; 
+} 

File diff suppressed because it is too large
+ 697 - 697
contrib/python/cffi/c/ffi_obj.c


+ 92 - 92
contrib/python/cffi/c/file_emulator.h

@@ -1,93 +1,93 @@
-
-/* Emulation of PyFile_Check() and PyFile_AsFile() for Python 3. */
-
-static PyObject *PyIOBase_TypeObj;
-
-static int init_file_emulator(void)
-{
-    if (PyIOBase_TypeObj == NULL) {
-        PyObject *io = PyImport_ImportModule("_io");
-        if (io == NULL)
-            return -1;
-        PyIOBase_TypeObj = PyObject_GetAttrString(io, "_IOBase");
-        if (PyIOBase_TypeObj == NULL)
-            return -1;
-    }
-    return 0;
-}
-
-
-#define PyFile_Check(p)  PyObject_IsInstance(p, PyIOBase_TypeObj)
-
-
-static void _close_file_capsule(PyObject *ob_capsule)
-{
-    FILE *f = (FILE *)PyCapsule_GetPointer(ob_capsule, "FILE");
-    if (f != NULL)
-        fclose(f);
-}
-
-
-static FILE *PyFile_AsFile(PyObject *ob_file)
-{
-    PyObject *ob, *ob_capsule = NULL, *ob_mode = NULL;
-    FILE *f;
-    int fd;
+ 
+/* Emulation of PyFile_Check() and PyFile_AsFile() for Python 3. */ 
+ 
+static PyObject *PyIOBase_TypeObj; 
+ 
+static int init_file_emulator(void) 
+{ 
+    if (PyIOBase_TypeObj == NULL) { 
+        PyObject *io = PyImport_ImportModule("_io"); 
+        if (io == NULL) 
+            return -1; 
+        PyIOBase_TypeObj = PyObject_GetAttrString(io, "_IOBase"); 
+        if (PyIOBase_TypeObj == NULL) 
+            return -1; 
+    } 
+    return 0; 
+} 
+ 
+ 
+#define PyFile_Check(p)  PyObject_IsInstance(p, PyIOBase_TypeObj) 
+ 
+ 
+static void _close_file_capsule(PyObject *ob_capsule) 
+{ 
+    FILE *f = (FILE *)PyCapsule_GetPointer(ob_capsule, "FILE"); 
+    if (f != NULL) 
+        fclose(f); 
+} 
+ 
+ 
+static FILE *PyFile_AsFile(PyObject *ob_file) 
+{ 
+    PyObject *ob, *ob_capsule = NULL, *ob_mode = NULL; 
+    FILE *f; 
+    int fd; 
     const char *mode;
-
-    ob = PyObject_CallMethod(ob_file, "flush", NULL);
-    if (ob == NULL)
-        goto fail;
-    Py_DECREF(ob);
-
-    ob_capsule = PyObject_GetAttrString(ob_file, "__cffi_FILE");
-    if (ob_capsule == NULL) {
-        PyErr_Clear();
-
-        fd = PyObject_AsFileDescriptor(ob_file);
-        if (fd < 0)
-            goto fail;
-
-        ob_mode = PyObject_GetAttrString(ob_file, "mode");
-        if (ob_mode == NULL)
-            goto fail;
-        mode = PyText_AsUTF8(ob_mode);
-        if (mode == NULL)
-            goto fail;
-
-        fd = dup(fd);
-        if (fd < 0) {
-            PyErr_SetFromErrno(PyExc_OSError);
-            goto fail;
-        }
-
-        f = fdopen(fd, mode);
-        if (f == NULL) {
-            close(fd);
-            PyErr_SetFromErrno(PyExc_OSError);
-            goto fail;
-        }
-        setbuf(f, NULL);    /* non-buffered */
-        Py_DECREF(ob_mode);
-        ob_mode = NULL;
-
-        ob_capsule = PyCapsule_New(f, "FILE", _close_file_capsule);
-        if (ob_capsule == NULL) {
-            fclose(f);
-            goto fail;
-        }
-
-        if (PyObject_SetAttrString(ob_file, "__cffi_FILE", ob_capsule) < 0)
-            goto fail;
-    }
-    else {
-        f = PyCapsule_GetPointer(ob_capsule, "FILE");
-    }
-    Py_DECREF(ob_capsule);   /* assumes still at least one reference */
-    return f;
-
- fail:
-    Py_XDECREF(ob_mode);
-    Py_XDECREF(ob_capsule);
-    return NULL;
-}
+ 
+    ob = PyObject_CallMethod(ob_file, "flush", NULL); 
+    if (ob == NULL) 
+        goto fail; 
+    Py_DECREF(ob); 
+ 
+    ob_capsule = PyObject_GetAttrString(ob_file, "__cffi_FILE"); 
+    if (ob_capsule == NULL) { 
+        PyErr_Clear(); 
+ 
+        fd = PyObject_AsFileDescriptor(ob_file); 
+        if (fd < 0) 
+            goto fail; 
+ 
+        ob_mode = PyObject_GetAttrString(ob_file, "mode"); 
+        if (ob_mode == NULL) 
+            goto fail; 
+        mode = PyText_AsUTF8(ob_mode); 
+        if (mode == NULL) 
+            goto fail; 
+ 
+        fd = dup(fd); 
+        if (fd < 0) { 
+            PyErr_SetFromErrno(PyExc_OSError); 
+            goto fail; 
+        } 
+ 
+        f = fdopen(fd, mode); 
+        if (f == NULL) { 
+            close(fd); 
+            PyErr_SetFromErrno(PyExc_OSError); 
+            goto fail; 
+        } 
+        setbuf(f, NULL);    /* non-buffered */ 
+        Py_DECREF(ob_mode); 
+        ob_mode = NULL; 
+ 
+        ob_capsule = PyCapsule_New(f, "FILE", _close_file_capsule); 
+        if (ob_capsule == NULL) { 
+            fclose(f); 
+            goto fail; 
+        } 
+ 
+        if (PyObject_SetAttrString(ob_file, "__cffi_FILE", ob_capsule) < 0) 
+            goto fail; 
+    } 
+    else { 
+        f = PyCapsule_GetPointer(ob_capsule, "FILE"); 
+    } 
+    Py_DECREF(ob_capsule);   /* assumes still at least one reference */ 
+    return f; 
+ 
+ fail: 
+    Py_XDECREF(ob_mode); 
+    Py_XDECREF(ob_capsule); 
+    return NULL; 
+} 

File diff suppressed because it is too large
+ 516 - 516
contrib/python/cffi/c/lib_obj.c


+ 464 - 464
contrib/python/cffi/c/libffi_msvc/ffi.c

@@ -1,495 +1,495 @@
-/* -----------------------------------------------------------------------
-   ffi.c - Copyright (c) 1996, 1998, 1999, 2001  Red Hat, Inc.
-           Copyright (c) 2002  Ranjit Mathew
-           Copyright (c) 2002  Bo Thorsen
-           Copyright (c) 2002  Roger Sayle
-   
-   x86 Foreign Function Interface 
-
-   Permission is hereby granted, free of charge, to any person obtaining
-   a copy of this software and associated documentation files (the
-   ``Software''), to deal in the Software without restriction, including
-   without limitation the rights to use, copy, modify, merge, publish,
-   distribute, sublicense, and/or sell copies of the Software, and to
-   permit persons to whom the Software is furnished to do so, subject to
-   the following conditions:
-
-   The above copyright notice and this permission notice shall be included
-   in all copies or substantial portions of the Software.
-
-   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
-   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-   OTHER DEALINGS IN THE SOFTWARE.
-   ----------------------------------------------------------------------- */
-
-#include <ffi.h>
-#include <ffi_common.h>
-
-#include <stdlib.h>
-
-/* ffi_prep_args is called by the assembly routine once stack space
-   has been allocated for the function's arguments */
-
-extern void Py_FatalError(const char *msg);
-
-/*@-exportheader@*/
-void ffi_prep_args(char *stack, extended_cif *ecif)
-/*@=exportheader@*/
-{
+/* ----------------------------------------------------------------------- 
+   ffi.c - Copyright (c) 1996, 1998, 1999, 2001  Red Hat, Inc. 
+           Copyright (c) 2002  Ranjit Mathew 
+           Copyright (c) 2002  Bo Thorsen 
+           Copyright (c) 2002  Roger Sayle 
+    
+   x86 Foreign Function Interface  
+ 
+   Permission is hereby granted, free of charge, to any person obtaining 
+   a copy of this software and associated documentation files (the 
+   ``Software''), to deal in the Software without restriction, including 
+   without limitation the rights to use, copy, modify, merge, publish, 
+   distribute, sublicense, and/or sell copies of the Software, and to 
+   permit persons to whom the Software is furnished to do so, subject to 
+   the following conditions: 
+ 
+   The above copyright notice and this permission notice shall be included 
+   in all copies or substantial portions of the Software. 
+ 
+   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS 
+   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
+   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
+   IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR 
+   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
+   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 
+   OTHER DEALINGS IN THE SOFTWARE. 
+   ----------------------------------------------------------------------- */ 
+ 
+#include <ffi.h> 
+#include <ffi_common.h> 
+ 
+#include <stdlib.h> 
+ 
+/* ffi_prep_args is called by the assembly routine once stack space 
+   has been allocated for the function's arguments */ 
+ 
+extern void Py_FatalError(const char *msg); 
+ 
+/*@-exportheader@*/ 
+void ffi_prep_args(char *stack, extended_cif *ecif) 
+/*@=exportheader@*/ 
+{ 
   unsigned int i;
   void **p_argv;
   char *argp;
   ffi_type **p_arg;
-
-  argp = stack;
-  if (ecif->cif->flags == FFI_TYPE_STRUCT)
-    {
-      *(void **) argp = ecif->rvalue;
-      argp += sizeof(void *);
-    }
-
-  p_argv = ecif->avalue;
-
-  for (i = ecif->cif->nargs, p_arg = ecif->cif->arg_types;
-       i != 0;
-       i--, p_arg++)
-    {
-      size_t z;
-
-      /* Align if necessary */
-      if ((sizeof(void *) - 1) & (size_t) argp)
-	argp = (char *) ALIGN(argp, sizeof(void *));
-
-      z = (*p_arg)->size;
-      if (z < sizeof(int))
-	{
-	  z = sizeof(int);
-	  switch ((*p_arg)->type)
-	    {
-	    case FFI_TYPE_SINT8:
-	      *(signed int *) argp = (signed int)*(SINT8 *)(* p_argv);
-	      break;
-
-	    case FFI_TYPE_UINT8:
-	      *(unsigned int *) argp = (unsigned int)*(UINT8 *)(* p_argv);
-	      break;
-
-	    case FFI_TYPE_SINT16:
-	      *(signed int *) argp = (signed int)*(SINT16 *)(* p_argv);
-	      break;
-
-	    case FFI_TYPE_UINT16:
-	      *(unsigned int *) argp = (unsigned int)*(UINT16 *)(* p_argv);
-	      break;
-
-	    case FFI_TYPE_SINT32:
-	      *(signed int *) argp = (signed int)*(SINT32 *)(* p_argv);
-	      break;
-
-	    case FFI_TYPE_UINT32:
-	      *(unsigned int *) argp = (unsigned int)*(UINT32 *)(* p_argv);
-	      break;
-
-	    case FFI_TYPE_STRUCT:
-	      *(unsigned int *) argp = (unsigned int)*(UINT32 *)(* p_argv);
-	      break;
-
-	    default:
-	      FFI_ASSERT(0);
-	    }
-	}
-#ifdef _WIN64
+ 
+  argp = stack; 
+  if (ecif->cif->flags == FFI_TYPE_STRUCT) 
+    { 
+      *(void **) argp = ecif->rvalue; 
+      argp += sizeof(void *); 
+    } 
+ 
+  p_argv = ecif->avalue; 
+ 
+  for (i = ecif->cif->nargs, p_arg = ecif->cif->arg_types; 
+       i != 0; 
+       i--, p_arg++) 
+    { 
+      size_t z; 
+ 
+      /* Align if necessary */ 
+      if ((sizeof(void *) - 1) & (size_t) argp) 
+	argp = (char *) ALIGN(argp, sizeof(void *)); 
+ 
+      z = (*p_arg)->size; 
+      if (z < sizeof(int)) 
+	{ 
+	  z = sizeof(int); 
+	  switch ((*p_arg)->type) 
+	    { 
+	    case FFI_TYPE_SINT8: 
+	      *(signed int *) argp = (signed int)*(SINT8 *)(* p_argv); 
+	      break; 
+ 
+	    case FFI_TYPE_UINT8: 
+	      *(unsigned int *) argp = (unsigned int)*(UINT8 *)(* p_argv); 
+	      break; 
+ 
+	    case FFI_TYPE_SINT16: 
+	      *(signed int *) argp = (signed int)*(SINT16 *)(* p_argv); 
+	      break; 
+ 
+	    case FFI_TYPE_UINT16: 
+	      *(unsigned int *) argp = (unsigned int)*(UINT16 *)(* p_argv); 
+	      break; 
+ 
+	    case FFI_TYPE_SINT32: 
+	      *(signed int *) argp = (signed int)*(SINT32 *)(* p_argv); 
+	      break; 
+ 
+	    case FFI_TYPE_UINT32: 
+	      *(unsigned int *) argp = (unsigned int)*(UINT32 *)(* p_argv); 
+	      break; 
+ 
+	    case FFI_TYPE_STRUCT: 
+	      *(unsigned int *) argp = (unsigned int)*(UINT32 *)(* p_argv); 
+	      break; 
+ 
+	    default: 
+	      FFI_ASSERT(0); 
+	    } 
+	} 
+#ifdef _WIN64 
       else if (z != 1 && z != 2 && z != 4 && z != 8)
-        {
-          /* On Win64, if a single argument takes more than 8 bytes,
-             then it is always passed by reference. */
-          *(void **)argp = *p_argv;
-          z = 8;
-        }
-#endif
-      else
-	{
-	  memcpy(argp, *p_argv, z);
-	}
-      p_argv++;
-      argp += z;
-    }
-
-  if (argp - stack > (long)ecif->cif->bytes)
-    {
-      Py_FatalError("FFI BUG: not enough stack space for arguments");
-    }
-  return;
-}
-
-/* Perform machine dependent cif processing */
-ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
-{
-  /* Set the return type flag */
-  switch (cif->rtype->type)
-    {
-    case FFI_TYPE_VOID:
-    case FFI_TYPE_SINT64:
-    case FFI_TYPE_FLOAT:
-    case FFI_TYPE_DOUBLE:
-    case FFI_TYPE_LONGDOUBLE:
-      cif->flags = (unsigned) cif->rtype->type;
-      break;
-
-    case FFI_TYPE_STRUCT:
-      /* MSVC returns small structures in registers.  Put in cif->flags
-         the value FFI_TYPE_STRUCT only if the structure is big enough;
-         otherwise, put the 4- or 8-bytes integer type. */
+        { 
+          /* On Win64, if a single argument takes more than 8 bytes, 
+             then it is always passed by reference. */ 
+          *(void **)argp = *p_argv; 
+          z = 8; 
+        } 
+#endif 
+      else 
+	{ 
+	  memcpy(argp, *p_argv, z); 
+	} 
+      p_argv++; 
+      argp += z; 
+    } 
+ 
+  if (argp - stack > (long)ecif->cif->bytes) 
+    { 
+      Py_FatalError("FFI BUG: not enough stack space for arguments"); 
+    } 
+  return; 
+} 
+ 
+/* Perform machine dependent cif processing */ 
+ffi_status ffi_prep_cif_machdep(ffi_cif *cif) 
+{ 
+  /* Set the return type flag */ 
+  switch (cif->rtype->type) 
+    { 
+    case FFI_TYPE_VOID: 
+    case FFI_TYPE_SINT64: 
+    case FFI_TYPE_FLOAT: 
+    case FFI_TYPE_DOUBLE: 
+    case FFI_TYPE_LONGDOUBLE: 
+      cif->flags = (unsigned) cif->rtype->type; 
+      break; 
+ 
+    case FFI_TYPE_STRUCT: 
+      /* MSVC returns small structures in registers.  Put in cif->flags 
+         the value FFI_TYPE_STRUCT only if the structure is big enough; 
+         otherwise, put the 4- or 8-bytes integer type. */ 
       if (cif->rtype->size == 1 ||
           cif->rtype->size == 2 ||
           cif->rtype->size == 4)
-        cif->flags = FFI_TYPE_INT;
+        cif->flags = FFI_TYPE_INT; 
       else if (cif->rtype->size == 8)
-        cif->flags = FFI_TYPE_SINT64;
-      else
-        cif->flags = FFI_TYPE_STRUCT;
-      break;
-
-    case FFI_TYPE_UINT64:
-#ifdef _WIN64
-    case FFI_TYPE_POINTER:
-#endif
-      cif->flags = FFI_TYPE_SINT64;
-      break;
-
-    default:
-      cif->flags = FFI_TYPE_INT;
-      break;
-    }
-
-  return FFI_OK;
-}
-
-#ifdef _WIN32
-extern int
-ffi_call_x86(void (*)(char *, extended_cif *), 
-	     /*@out@*/ extended_cif *, 
-	     unsigned, unsigned, 
-	     /*@out@*/ unsigned *, 
-	     void (*fn)());
-#endif
-
-#ifdef _WIN64
-extern int
-ffi_call_AMD64(void (*)(char *, extended_cif *),
-		 /*@out@*/ extended_cif *,
-		 unsigned, unsigned,
-		 /*@out@*/ unsigned *,
-		 void (*fn)());
-#endif
-
-int
-ffi_call(/*@dependent@*/ ffi_cif *cif, 
-	 void (*fn)(), 
-	 /*@out@*/ void *rvalue, 
-	 /*@dependent@*/ void **avalue)
-{
-  extended_cif ecif;
-
-  ecif.cif = cif;
-  ecif.avalue = avalue;
-  
-  /* If the return value is a struct and we don't have a return	*/
-  /* value address then we need to make one		        */
-
-  if ((rvalue == NULL) && 
-      (cif->flags == FFI_TYPE_STRUCT))
-    {
-      /*@-sysunrecog@*/
-      ecif.rvalue = alloca(cif->rtype->size);
-      /*@=sysunrecog@*/
-    }
-  else
-    ecif.rvalue = rvalue;
-    
-  
-  switch (cif->abi) 
-    {
-#if !defined(_WIN64)
-    case FFI_SYSV:
-    case FFI_STDCALL:
-      return ffi_call_x86(ffi_prep_args, &ecif, cif->bytes, 
-			  cif->flags, ecif.rvalue, fn);
-      break;
-#else
-    case FFI_SYSV:
-      /*@-usedef@*/
-      return ffi_call_AMD64(ffi_prep_args, &ecif, cif->bytes,
-			   cif->flags, ecif.rvalue, fn);
-      /*@=usedef@*/
-      break;
-#endif
-
-    default:
-      FFI_ASSERT(0);
-      break;
-    }
-  return -1; /* theller: Hrm. */
-}
-
-
-/** private members **/
-
-static void ffi_prep_incoming_args_SYSV (char *stack, void **ret,
-					  void** args, ffi_cif* cif);
-/* This function is jumped to by the trampoline */
-
-#ifdef _WIN64
-void *
-#else
-static void __fastcall
-#endif
-ffi_closure_SYSV (ffi_closure *closure, char *argp)
-{
-  // this is our return value storage
-  long double    res;
-
-  // our various things...
-  ffi_cif       *cif;
-  void         **arg_area;
-  unsigned short rtype;
-  void          *resp = (void*)&res;
-  void *args = argp + sizeof(void *);
-
-  cif         = closure->cif;
-  arg_area    = (void**) alloca (cif->nargs * sizeof (void*));  
-
-  /* this call will initialize ARG_AREA, such that each
-   * element in that array points to the corresponding 
-   * value on the stack; and if the function returns
-   * a structure, it will re-set RESP to point to the
-   * structure return address.  */
-
-  ffi_prep_incoming_args_SYSV(args, (void**)&resp, arg_area, cif);
-  
-  (closure->fun) (cif, resp, arg_area, closure->user_data);
-
-  rtype = cif->flags;
-
-#if defined(_WIN32) && !defined(_WIN64)
-#ifdef _MSC_VER
-  /* now, do a generic return based on the value of rtype */
-  if (rtype == FFI_TYPE_INT)
-    {
-	    _asm mov eax, resp ;
-	    _asm mov eax, [eax] ;
-    }
-  else if (rtype == FFI_TYPE_FLOAT)
-    {
-	    _asm mov eax, resp ;
-	    _asm fld DWORD PTR [eax] ;
-//      asm ("flds (%0)" : : "r" (resp) : "st" );
-    }
+        cif->flags = FFI_TYPE_SINT64; 
+      else 
+        cif->flags = FFI_TYPE_STRUCT; 
+      break; 
+ 
+    case FFI_TYPE_UINT64: 
+#ifdef _WIN64 
+    case FFI_TYPE_POINTER: 
+#endif 
+      cif->flags = FFI_TYPE_SINT64; 
+      break; 
+ 
+    default: 
+      cif->flags = FFI_TYPE_INT; 
+      break; 
+    } 
+ 
+  return FFI_OK; 
+} 
+ 
+#ifdef _WIN32 
+extern int 
+ffi_call_x86(void (*)(char *, extended_cif *),  
+	     /*@out@*/ extended_cif *,  
+	     unsigned, unsigned,  
+	     /*@out@*/ unsigned *,  
+	     void (*fn)()); 
+#endif 
+ 
+#ifdef _WIN64 
+extern int 
+ffi_call_AMD64(void (*)(char *, extended_cif *), 
+		 /*@out@*/ extended_cif *, 
+		 unsigned, unsigned, 
+		 /*@out@*/ unsigned *, 
+		 void (*fn)()); 
+#endif 
+ 
+int 
+ffi_call(/*@dependent@*/ ffi_cif *cif,  
+	 void (*fn)(),  
+	 /*@out@*/ void *rvalue,  
+	 /*@dependent@*/ void **avalue) 
+{ 
+  extended_cif ecif; 
+ 
+  ecif.cif = cif; 
+  ecif.avalue = avalue; 
+   
+  /* If the return value is a struct and we don't have a return	*/ 
+  /* value address then we need to make one		        */ 
+ 
+  if ((rvalue == NULL) &&  
+      (cif->flags == FFI_TYPE_STRUCT)) 
+    { 
+      /*@-sysunrecog@*/ 
+      ecif.rvalue = alloca(cif->rtype->size); 
+      /*@=sysunrecog@*/ 
+    } 
+  else 
+    ecif.rvalue = rvalue; 
+     
+   
+  switch (cif->abi)  
+    { 
+#if !defined(_WIN64) 
+    case FFI_SYSV: 
+    case FFI_STDCALL: 
+      return ffi_call_x86(ffi_prep_args, &ecif, cif->bytes,  
+			  cif->flags, ecif.rvalue, fn); 
+      break; 
+#else 
+    case FFI_SYSV: 
+      /*@-usedef@*/ 
+      return ffi_call_AMD64(ffi_prep_args, &ecif, cif->bytes, 
+			   cif->flags, ecif.rvalue, fn); 
+      /*@=usedef@*/ 
+      break; 
+#endif 
+ 
+    default: 
+      FFI_ASSERT(0); 
+      break; 
+    } 
+  return -1; /* theller: Hrm. */ 
+} 
+ 
+ 
+/** private members **/ 
+ 
+static void ffi_prep_incoming_args_SYSV (char *stack, void **ret, 
+					  void** args, ffi_cif* cif); 
+/* This function is jumped to by the trampoline */ 
+ 
+#ifdef _WIN64 
+void * 
+#else 
+static void __fastcall 
+#endif 
+ffi_closure_SYSV (ffi_closure *closure, char *argp) 
+{ 
+  // this is our return value storage 
+  long double    res; 
+ 
+  // our various things... 
+  ffi_cif       *cif; 
+  void         **arg_area; 
+  unsigned short rtype; 
+  void          *resp = (void*)&res; 
+  void *args = argp + sizeof(void *); 
+ 
+  cif         = closure->cif; 
+  arg_area    = (void**) alloca (cif->nargs * sizeof (void*));   
+ 
+  /* this call will initialize ARG_AREA, such that each 
+   * element in that array points to the corresponding  
+   * value on the stack; and if the function returns 
+   * a structure, it will re-set RESP to point to the 
+   * structure return address.  */ 
+ 
+  ffi_prep_incoming_args_SYSV(args, (void**)&resp, arg_area, cif); 
+   
+  (closure->fun) (cif, resp, arg_area, closure->user_data); 
+ 
+  rtype = cif->flags; 
+ 
+#if defined(_WIN32) && !defined(_WIN64) 
+#ifdef _MSC_VER 
+  /* now, do a generic return based on the value of rtype */ 
+  if (rtype == FFI_TYPE_INT) 
+    { 
+	    _asm mov eax, resp ; 
+	    _asm mov eax, [eax] ; 
+    } 
+  else if (rtype == FFI_TYPE_FLOAT) 
+    { 
+	    _asm mov eax, resp ; 
+	    _asm fld DWORD PTR [eax] ; 
+//      asm ("flds (%0)" : : "r" (resp) : "st" ); 
+    } 
   else if (rtype == FFI_TYPE_DOUBLE || rtype == FFI_TYPE_LONGDOUBLE)
-    {
-	    _asm mov eax, resp ;
-	    _asm fld QWORD PTR [eax] ;
-//      asm ("fldl (%0)" : : "r" (resp) : "st", "st(1)" );
-    }
-  else if (rtype == FFI_TYPE_SINT64)
-    {
-	    _asm mov edx, resp ;
-	    _asm mov eax, [edx] ;
-	    _asm mov edx, [edx + 4] ;
-//      asm ("movl 0(%0),%%eax;"
-//	   "movl 4(%0),%%edx" 
-//	   : : "r"(resp)
-//	   : "eax", "edx");
-    }
+    { 
+	    _asm mov eax, resp ; 
+	    _asm fld QWORD PTR [eax] ; 
+//      asm ("fldl (%0)" : : "r" (resp) : "st", "st(1)" ); 
+    } 
+  else if (rtype == FFI_TYPE_SINT64) 
+    { 
+	    _asm mov edx, resp ; 
+	    _asm mov eax, [edx] ; 
+	    _asm mov edx, [edx + 4] ; 
+//      asm ("movl 0(%0),%%eax;" 
+//	   "movl 4(%0),%%edx"  
+//	   : : "r"(resp) 
+//	   : "eax", "edx"); 
+    } 
   else if (rtype == FFI_TYPE_STRUCT)
     {
 	    _asm mov eax, resp ;
     }
-#else
-  /* now, do a generic return based on the value of rtype */
-  if (rtype == FFI_TYPE_INT)
-    {
-      asm ("movl (%0),%%eax" : : "r" (resp) : "eax");
-    }
-  else if (rtype == FFI_TYPE_FLOAT)
-    {
-      asm ("flds (%0)" : : "r" (resp) : "st" );
-    }
+#else 
+  /* now, do a generic return based on the value of rtype */ 
+  if (rtype == FFI_TYPE_INT) 
+    { 
+      asm ("movl (%0),%%eax" : : "r" (resp) : "eax"); 
+    } 
+  else if (rtype == FFI_TYPE_FLOAT) 
+    { 
+      asm ("flds (%0)" : : "r" (resp) : "st" ); 
+    } 
   else if (rtype == FFI_TYPE_DOUBLE || rtype == FFI_TYPE_LONGDOUBLE)
-    {
-      asm ("fldl (%0)" : : "r" (resp) : "st", "st(1)" );
-    }
-  else if (rtype == FFI_TYPE_SINT64)
-    {
-      asm ("movl 0(%0),%%eax;"
-	   "movl 4(%0),%%edx" 
-	   : : "r"(resp)
-	   : "eax", "edx");
-    }
+    { 
+      asm ("fldl (%0)" : : "r" (resp) : "st", "st(1)" ); 
+    } 
+  else if (rtype == FFI_TYPE_SINT64) 
+    { 
+      asm ("movl 0(%0),%%eax;" 
+	   "movl 4(%0),%%edx"  
+	   : : "r"(resp) 
+	   : "eax", "edx"); 
+    } 
   else if (rtype == FFI_TYPE_STRUCT)
     {
       asm ("movl %0,%%eax" : : "r" (resp) : "eax");
     }
-#endif
-#endif
-
-#ifdef _WIN64
-  /* The result is returned in rax.  This does the right thing for
-     result types except for floats; we have to 'mov xmm0, rax' in the
-     caller to correct this.
-  */
+#endif 
+#endif 
+ 
+#ifdef _WIN64 
+  /* The result is returned in rax.  This does the right thing for 
+     result types except for floats; we have to 'mov xmm0, rax' in the 
+     caller to correct this. 
+  */ 
   if (rtype == FFI_TYPE_STRUCT)
       return resp;
-  return *(void **)resp;
-#endif
-}
-
-/*@-exportheader@*/
-static void 
-ffi_prep_incoming_args_SYSV(char *stack, void **rvalue,
-			    void **avalue, ffi_cif *cif)
-/*@=exportheader@*/
-{
+  return *(void **)resp; 
+#endif 
+} 
+ 
+/*@-exportheader@*/ 
+static void  
+ffi_prep_incoming_args_SYSV(char *stack, void **rvalue, 
+			    void **avalue, ffi_cif *cif) 
+/*@=exportheader@*/ 
+{ 
   unsigned int i;
   void **p_argv;
   char *argp;
   ffi_type **p_arg;
-
-  argp = stack;
-
-  if ( cif->flags == FFI_TYPE_STRUCT ) {
-    *rvalue = *(void **) argp;
-    argp += 4;
-  }
-
-  p_argv = avalue;
-
-  for (i = cif->nargs, p_arg = cif->arg_types; (i != 0); i--, p_arg++)
-    {
-      size_t z;
-
-      /* Align if necessary */
-      if ((sizeof(char *) - 1) & (size_t) argp) {
-	argp = (char *) ALIGN(argp, sizeof(char*));
-      }
-
-      z = (*p_arg)->size;
-
-      /* because we're little endian, this is what it turns into.   */
-
-#ifdef _WIN64
+ 
+  argp = stack; 
+ 
+  if ( cif->flags == FFI_TYPE_STRUCT ) { 
+    *rvalue = *(void **) argp; 
+    argp += 4; 
+  } 
+ 
+  p_argv = avalue; 
+ 
+  for (i = cif->nargs, p_arg = cif->arg_types; (i != 0); i--, p_arg++) 
+    { 
+      size_t z; 
+ 
+      /* Align if necessary */ 
+      if ((sizeof(char *) - 1) & (size_t) argp) { 
+	argp = (char *) ALIGN(argp, sizeof(char*)); 
+      } 
+ 
+      z = (*p_arg)->size; 
+ 
+      /* because we're little endian, this is what it turns into.   */ 
+ 
+#ifdef _WIN64 
       if (z != 1 && z != 2 && z != 4 && z != 8)
-        {
-          /* On Win64, if a single argument takes more than 8 bytes,
-             then it is always passed by reference. */
-          *p_argv = *((void**) argp);
-          z = 8;
-        }
-      else
-#endif
-      *p_argv = (void*) argp;
-
-      p_argv++;
-      argp += z;
-    }
-  
-  return;
-}
-
-/* the cif must already be prep'ed */
-extern void ffi_closure_OUTER();
-
-ffi_status
-ffi_prep_closure_loc (ffi_closure* closure,
-					  ffi_cif* cif,
-					  void (*fun)(ffi_cif*,void*,void**,void*),
-					  void *user_data,
-					  void *codeloc)
-{
-  short bytes;
-  char *tramp;
-#ifdef _WIN64
-  int mask = 0;
-#endif
-  FFI_ASSERT (cif->abi == FFI_SYSV);
-  
-  if (cif->abi == FFI_SYSV)
-    bytes = 0;
-#if !defined(_WIN64)
-  else if (cif->abi == FFI_STDCALL)
-    bytes = cif->bytes;
-#endif
-  else
-    return FFI_BAD_ABI;
-
-  tramp = &closure->tramp[0];
-
-#define BYTES(text) memcpy(tramp, text, sizeof(text)), tramp += sizeof(text)-1
-#define POINTER(x) *(void**)tramp = (void*)(x), tramp += sizeof(void*)
-#define SHORT(x) *(short*)tramp = x, tramp += sizeof(short)
-#define INT(x) *(int*)tramp = x, tramp += sizeof(int)
-
-#ifdef _WIN64
-  if (cif->nargs >= 1 &&
-      (cif->arg_types[0]->type == FFI_TYPE_FLOAT
-       || cif->arg_types[0]->type == FFI_TYPE_DOUBLE))
-    mask |= 1;
-  if (cif->nargs >= 2 &&
-      (cif->arg_types[1]->type == FFI_TYPE_FLOAT
-       || cif->arg_types[1]->type == FFI_TYPE_DOUBLE))
-    mask |= 2;
-  if (cif->nargs >= 3 &&
-      (cif->arg_types[2]->type == FFI_TYPE_FLOAT
-       || cif->arg_types[2]->type == FFI_TYPE_DOUBLE))
-    mask |= 4;
-  if (cif->nargs >= 4 &&
-      (cif->arg_types[3]->type == FFI_TYPE_FLOAT
-       || cif->arg_types[3]->type == FFI_TYPE_DOUBLE))
-    mask |= 8;
-
+        { 
+          /* On Win64, if a single argument takes more than 8 bytes, 
+             then it is always passed by reference. */ 
+          *p_argv = *((void**) argp); 
+          z = 8; 
+        } 
+      else 
+#endif 
+      *p_argv = (void*) argp; 
+ 
+      p_argv++; 
+      argp += z; 
+    } 
+   
+  return; 
+} 
+ 
+/* the cif must already be prep'ed */ 
+extern void ffi_closure_OUTER(); 
+ 
+ffi_status 
+ffi_prep_closure_loc (ffi_closure* closure, 
+					  ffi_cif* cif, 
+					  void (*fun)(ffi_cif*,void*,void**,void*), 
+					  void *user_data, 
+					  void *codeloc) 
+{ 
+  short bytes; 
+  char *tramp; 
+#ifdef _WIN64 
+  int mask = 0; 
+#endif 
+  FFI_ASSERT (cif->abi == FFI_SYSV); 
+   
+  if (cif->abi == FFI_SYSV) 
+    bytes = 0; 
+#if !defined(_WIN64) 
+  else if (cif->abi == FFI_STDCALL) 
+    bytes = cif->bytes; 
+#endif 
+  else 
+    return FFI_BAD_ABI; 
+ 
+  tramp = &closure->tramp[0]; 
+ 
+#define BYTES(text) memcpy(tramp, text, sizeof(text)), tramp += sizeof(text)-1 
+#define POINTER(x) *(void**)tramp = (void*)(x), tramp += sizeof(void*) 
+#define SHORT(x) *(short*)tramp = x, tramp += sizeof(short) 
+#define INT(x) *(int*)tramp = x, tramp += sizeof(int) 
+ 
+#ifdef _WIN64 
+  if (cif->nargs >= 1 && 
+      (cif->arg_types[0]->type == FFI_TYPE_FLOAT 
+       || cif->arg_types[0]->type == FFI_TYPE_DOUBLE)) 
+    mask |= 1; 
+  if (cif->nargs >= 2 && 
+      (cif->arg_types[1]->type == FFI_TYPE_FLOAT 
+       || cif->arg_types[1]->type == FFI_TYPE_DOUBLE)) 
+    mask |= 2; 
+  if (cif->nargs >= 3 && 
+      (cif->arg_types[2]->type == FFI_TYPE_FLOAT 
+       || cif->arg_types[2]->type == FFI_TYPE_DOUBLE)) 
+    mask |= 4; 
+  if (cif->nargs >= 4 && 
+      (cif->arg_types[3]->type == FFI_TYPE_FLOAT 
+       || cif->arg_types[3]->type == FFI_TYPE_DOUBLE)) 
+    mask |= 8; 
+ 
   /* if we return a non-small struct, then the first argument is a pointer
    * to the return area, and all real arguments are shifted by one */
   if (cif->flags == FFI_TYPE_STRUCT)
     mask = (mask & ~8) << 1;
 
-  /* 41 BB ----         mov         r11d,mask */
-  BYTES("\x41\xBB"); INT(mask);
-
-  /* 48 B8 --------     mov         rax, closure			*/
-  BYTES("\x48\xB8"); POINTER(closure);
-
-  /* 49 BA --------     mov         r10, ffi_closure_OUTER */
-  BYTES("\x49\xBA"); POINTER(ffi_closure_OUTER);
-
-  /* 41 FF E2           jmp         r10 */
-  BYTES("\x41\xFF\xE2");
-
-#else
-
-  /* mov ecx, closure */
-  BYTES("\xb9"); POINTER(closure);
-
-  /* mov edx, esp */
-  BYTES("\x8b\xd4");
-
-  /* call ffi_closure_SYSV */
-  BYTES("\xe8"); POINTER((char*)&ffi_closure_SYSV - (tramp + 4));
-
-  /* ret bytes */
-  BYTES("\xc2");
-  SHORT(bytes);
-  
-#endif
-
-  if (tramp - &closure->tramp[0] > FFI_TRAMPOLINE_SIZE)
-    Py_FatalError("FFI_TRAMPOLINE_SIZE too small in " __FILE__);
-
-  closure->cif  = cif;
-  closure->user_data = user_data;
-  closure->fun  = fun;
-  return FFI_OK;
-}
+  /* 41 BB ----         mov         r11d,mask */ 
+  BYTES("\x41\xBB"); INT(mask); 
+ 
+  /* 48 B8 --------     mov         rax, closure			*/ 
+  BYTES("\x48\xB8"); POINTER(closure); 
+ 
+  /* 49 BA --------     mov         r10, ffi_closure_OUTER */ 
+  BYTES("\x49\xBA"); POINTER(ffi_closure_OUTER); 
+ 
+  /* 41 FF E2           jmp         r10 */ 
+  BYTES("\x41\xFF\xE2"); 
+ 
+#else 
+ 
+  /* mov ecx, closure */ 
+  BYTES("\xb9"); POINTER(closure); 
+ 
+  /* mov edx, esp */ 
+  BYTES("\x8b\xd4"); 
+ 
+  /* call ffi_closure_SYSV */ 
+  BYTES("\xe8"); POINTER((char*)&ffi_closure_SYSV - (tramp + 4)); 
+ 
+  /* ret bytes */ 
+  BYTES("\xc2"); 
+  SHORT(bytes); 
+   
+#endif 
+ 
+  if (tramp - &closure->tramp[0] > FFI_TRAMPOLINE_SIZE) 
+    Py_FatalError("FFI_TRAMPOLINE_SIZE too small in " __FILE__); 
+ 
+  closure->cif  = cif; 
+  closure->user_data = user_data; 
+  closure->fun  = fun; 
+  return FFI_OK; 
+} 

Some files were not shown because too many files changed in this diff