Rebase
[platform/upstream/libffi.git] / patches / win64-struct-args
1 Index: libffi/doc/libffi.texi
2 ===================================================================
3 --- libffi.orig/doc/libffi.texi
4 +++ libffi/doc/libffi.texi
5 @@ -171,7 +171,9 @@ discarded.
6  @var{avalues} is a vector of @code{void *} pointers that point to the
7  memory locations holding the argument values for a call.  If @var{cif}
8  declares that the function has no arguments (i.e., @var{nargs} was 0),
9 -then @var{avalues} is ignored.
10 +then @var{avalues} is ignored.  Note that argument values may be
11 +modified by the callee (for instance, structs passed by value); the
12 +burden of copying pass-by-value arguments is placed on the caller.
13  @end defun
14  
15  
16 Index: libffi/src/x86/ffi.c
17 ===================================================================
18 --- libffi.orig/src/x86/ffi.c
19 +++ libffi/src/x86/ffi.c
20 @@ -291,27 +291,8 @@ void ffi_call(ffi_cif *cif, void (*fn)(v
21      {
22  #ifdef X86_WIN64
23      case FFI_WIN64:
24 -      {
25 -        /* Make copies of all struct arguments
26 -           NOTE: not sure if responsibility should be here or in caller */
27 -        unsigned int i;
28 -        for (i=0; i < cif->nargs;i++) {
29 -          size_t size = cif->arg_types[i]->size;
30 -          if ((cif->arg_types[i]->type == FFI_TYPE_STRUCT
31 -               && (size != 1 && size != 2 && size != 4 && size != 8))
32 -#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
33 -              || cif->arg_types[i]->type == FFI_TYPE_LONGDOUBLE
34 -#endif
35 -              )
36 -            {
37 -              void *local = alloca(size);
38 -              memcpy(local, avalue[i], size);
39 -              avalue[i] = local;
40 -            }
41 -        }
42 -        ffi_call_win64(ffi_prep_args, &ecif, cif->bytes,
43 -                       cif->flags, ecif.rvalue, fn);
44 -      }
45 +      ffi_call_win64(ffi_prep_args, &ecif, cif->bytes,
46 +                     cif->flags, ecif.rvalue, fn);
47        break;
48  #elif defined(X86_WIN32)
49      case FFI_SYSV:
50 Index: libffi/ChangeLog
51 ===================================================================
52 --- libffi.orig/ChangeLog
53 +++ libffi/ChangeLog
54 @@ -102,6 +102,14 @@
55         * fficonfig.h.in: Regenerate.
56         * src/x86/sysv.S (.eh_frame): Use .ascii, .string or error.
57  
58 +2010-05-11  Dan Witte  <dwitte@mozilla.com>
59 +
60 +       * doc/libffi.tex: Document previous change.
61 +
62 +2010-05-11  Makoto Kato <m_kato@ga2.so-net.ne.jp>
63 +
64 +       * src/x86/ffi.c (ffi_call): Don't copy structs passed by value.
65 +
66  2010-05-05  Michael Kohler <michaelkohler@live.com>
67  
68         * src/dlmalloc.c (dlfree): Fix spelling.
69 Index: libffi/doc/libffi.info
70 ===================================================================
71 --- libffi.orig/doc/libffi.info
72 +++ libffi/doc/libffi.info
73 @@ -1,10 +1,10 @@
74 -This is doc/libffi.info, produced by makeinfo version 4.12 from
75 -./doc/libffi.texi.
76 +This is ../libffi/doc/libffi.info, produced by makeinfo version 4.13
77 +from ../libffi/doc/libffi.texi.
78  
79  This manual is for Libffi, a portable foreign-function interface
80  library.
81  
82 -   Copyright (C) 2008 Red Hat, Inc.
83 +   Copyright (C) 2008, 2010 Red Hat, Inc.
84  
85       Permission is granted to copy, distribute and/or modify this
86       document under the terms of the GNU General Public License as
87 @@ -13,7 +13,7 @@ library.
88       included in the section entitled "GNU General Public License".
89  
90  
91 -INFO-DIR-SECTION
92 +INFO-DIR-SECTION Development
93  START-INFO-DIR-ENTRY
94  * libffi: (libffi).             Portable foreign-function interface library.
95  END-INFO-DIR-ENTRY
96 @@ -27,7 +27,7 @@ libffi
97  This manual is for Libffi, a portable foreign-function interface
98  library.
99  
100 -   Copyright (C) 2008 Red Hat, Inc.
101 +   Copyright (C) 2008, 2010 Red Hat, Inc.
102  
103       Permission is granted to copy, distribute and/or modify this
104       document under the terms of the GNU General Public License as
105 @@ -89,6 +89,7 @@ File: libffi.info,  Node: Using libffi, 
106  * Types::                       libffi type descriptions.
107  * Multiple ABIs::               Different passing styles on one platform.
108  * The Closure API::             Writing a generic function.
109 +* Closure Example::             A closure example.
110  
111  \1f
112  File: libffi.info,  Node: The Basics,  Next: Simple Example,  Up: Using libffi
113 @@ -146,7 +147,9 @@ To prepare a call interface object, use 
114       AVALUES is a vector of `void *' pointers that point to the memory
115       locations holding the argument values for a call.  If CIF declares
116       that the function has no arguments (i.e., NARGS was 0), then
117 -     AVALUES is ignored.
118 +     AVALUES is ignored.  Note that argument values may be modified by
119 +     the callee (for instance, structs passed by value); the burden of
120 +     copying pass-by-value arguments is placed on the caller.
121  
122  \1f
123  File: libffi.info,  Node: Simple Example,  Next: Types,  Prev: The Basics,  Up: Using libffi
124 @@ -368,7 +371,7 @@ instance, the x86 platform has both `std
125  necessarily platform-specific.
126  
127  \1f
128 -File: libffi.info,  Node: The Closure API,  Prev: Multiple ABIs,  Up: Using libffi
129 +File: libffi.info,  Node: The Closure API,  Next: Closure Example,  Prev: Multiple ABIs,  Up: Using libffi
130  
131  2.5 The Closure API
132  ===================
133 @@ -444,6 +447,62 @@ is deprecated, as it cannot handle the n
134  executable addresses.
135  
136  \1f
137 +File: libffi.info,  Node: Closure Example,  Prev: The Closure API,  Up: Using libffi
138 +
139 +2.6 Closure Example
140 +===================
141 +
142 +A trivial example that creates a new `puts' by binding `fputs' with
143 +`stdin'.
144 +
145 +     #include <stdio.h>
146 +     #include <ffi.h>
147 +
148 +     /* Acts like puts with the file given at time of enclosure. */
149 +     void puts_binding(ffi_cif *cif, unsigned int *ret, void* args[],
150 +                       FILE *stream)
151 +     {
152 +       *ret = fputs(*(char **)args[0], stream);
153 +     }
154 +
155 +     int main()
156 +     {
157 +       ffi_cif cif;
158 +       ffi_type *args[1];
159 +       ffi_closure *closure;
160 +
161 +       int (*bound_puts)(char *);
162 +       int rc;
163 +
164 +       /* Allocate closure and bound_puts */
165 +       closure = ffi_closure_alloc(sizeof(ffi_closure), &bound_puts);
166 +
167 +       if (closure)
168 +         {
169 +           /* Initialize the argument info vectors */
170 +           args[0] = &ffi_type_pointer;
171 +
172 +           /* Initialize the cif */
173 +           if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
174 +                            &ffi_type_uint, args) == FFI_OK)
175 +             {
176 +               /* Initialize the closure, setting stream to stdout */
177 +               if (ffi_prep_closure_loc(closure, &cif, puts_binding,
178 +                                        stdout, bound_puts) == FFI_OK)
179 +                 {
180 +                   rc = bound_puts("Hello World!");
181 +                   /* rc now holds the result of the call to fputs */
182 +                 }
183 +             }
184 +         }
185 +
186 +       /* Deallocate both closure, and bound_puts */
187 +       ffi_closure_free(closure);
188 +
189 +       return 0;
190 +     }
191 +
192 +\1f
193  File: libffi.info,  Node: Missing Features,  Next: Index,  Prev: Using libffi,  Up: Top
194  
195  3 Missing Features
196 @@ -480,7 +539,7 @@ Index
197  * closures:                              The Closure API.      (line 13)
198  * FFI:                                   Introduction.         (line 31)
199  * ffi_call:                              The Basics.           (line 41)
200 -* ffi_closure_alloca:                    The Closure API.      (line 19)
201 +* ffi_closure_alloc:                     The Closure API.      (line 19)
202  * ffi_closure_free:                      The Closure API.      (line 26)
203  * FFI_CLOSURES:                          The Closure API.      (line 13)
204  * ffi_prep_cif:                          The Basics.           (line 16)
205 @@ -516,18 +575,19 @@ Index
206  
207  \1f
208  Tag Table:
209 -Node: Top\7f670
210 -Node: Introduction\7f1406
211 -Node: Using libffi\7f3042
212 -Node: The Basics\7f3477
213 -Node: Simple Example\7f6084
214 -Node: Types\7f7111
215 -Node: Primitive Types\7f7394
216 -Node: Structures\7f9214
217 -Node: Type Example\7f10074
218 -Node: Multiple ABIs\7f11297
219 -Node: The Closure API\7f11668
220 -Node: Missing Features\7f14588
221 -Node: Index\7f15081
222 +Node: Top\7f706
223 +Node: Introduction\7f1448
224 +Node: Using libffi\7f3084
225 +Node: The Basics\7f3570
226 +Node: Simple Example\7f6356
227 +Node: Types\7f7383
228 +Node: Primitive Types\7f7666
229 +Node: Structures\7f9486
230 +Node: Type Example\7f10346
231 +Node: Multiple ABIs\7f11569
232 +Node: The Closure API\7f11940
233 +Node: Closure Example\7f14884
234 +Node: Missing Features\7f16443
235 +Node: Index\7f16936
236  \1f
237  End Tag Table