scripts: prepare new configuration for x86_64 on vault13 server using pre build cross...
[AROS.git] / compiler / alib / alib_util.c
blob2bf4ff4017d886de88ef810bb7c16945f5b630d7
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 Internal utility functions.
6 */
8 #include <aros/debug.h>
9 #include <aros/system.h>
10 #include "alib_intern.h"
12 #ifdef AROS_SLOWSTACKMETHODS
13 #include <intuition/classusr.h>
14 #include <proto/exec.h>
15 /******************************************************************************
17 NAME */
18 Msg GetMsgFromStack (
20 /* SYNOPSIS */
21 IPTR MethodID,
22 va_list args)
24 /* FUNCTION
25 Builds a message structure with the parameters which are passed on
26 the stack. This function is used on machines which have compilers
27 which don't pass the arguments to a varargs function unlike the
28 Amiga ones.
30 INPUTS
31 MethodID - This is the ID of the message
32 args - This has to be initialized by va_start()
33 firstlocal - The address of the first local function of the
34 function which wants to call GetMsgFromStack()
36 RESULT
37 A message which can be passed to any function which expects the
38 structure which is defined for this MethodID or NULL if something
39 failed. This call may fail for different reasons on different
40 systems. On some systems, NULL indicates that there was not enough
41 memory, on others that the MethodID is unknown.
43 NOTES
44 This function fails for structures with more than 32 fields.
46 EXAMPLE
48 BUGS
50 SEE ALSO
51 intuition.library/NewObjectA(), intuition.library/SetAttrsA(), intuition.library/GetAttr(),
52 intuition.library/DisposeObject(), DoMethodA(),
53 DoSuperMethodA(), "Basic Object-Oriented Programming System for
54 Intuition" and the "boopsi Class Reference" documentation.
56 INTERNALS
57 HPPA: Allocate a structure which can contain all IPTRs between
58 the first argument of, for example, DoMethod() and its first local
59 variable. This will copy a bit too much memory but in the end, it
60 saves a lot of work, since it's not neccessary to register every
61 structure.
63 ******************************************************************************/
65 ULONG size;
66 Msg msg;
68 size = 33;
70 if ((msg = AllocVec (size * sizeof (IPTR), MEMF_CLEAR)))
72 IPTR * ulptr = (IPTR *)msg;
74 *ulptr ++ = MethodID;
76 while (-- size)
78 *ulptr ++ = va_arg (args, IPTR);
82 return msg;
83 } /* GetMsgFromStack */
85 /******************************************************************************
87 NAME */
88 void FreeMsgFromStack (
90 /* SYNOPSIS */
91 Msg msg)
93 /* FUNCTION
94 Frees the memory occupied by the message which was created by
95 GetMsgFromStack().
97 INPUTS
98 msg - The return value of GetMsgFromStack(). May be NULL.
100 RESULT
101 None.
103 NOTES
105 EXAMPLE
107 BUGS
109 SEE ALSO
110 GetMsgFromStack()
112 ******************************************************************************/
114 FreeVec(msg);
115 } /* FreeMsgFromStack */
117 #endif /* AROS_SLOWSTACKMETHODS */
119 #ifdef AROS_SLOWSTACKTAGS
120 #include <stdarg.h>
121 #include <utility/tagitem.h>
122 #include <exec/memory.h>
123 #include <proto/exec.h>
124 /******************************************************************************
126 NAME */
127 struct TagItem * GetTagsFromStack (
129 /* SYNOPSIS */
130 IPTR firstTag,
131 va_list args)
133 /* FUNCTION
134 Builds a tagitem array with the tags on the stack. This function is
135 used on machines which have compilers which don't pass the
136 arguments to a varargs function unlike the Amiga ones.
138 INPUTS
139 firstTag - This is the first tag passed to the function
140 args - This has to be initialized by va_start()
142 RESULT
143 A TagItem array which can be passed to any function which expects
144 such an array or NULL if something failed. This call may fail for
145 different reasons on different systems. On some systems, NULL
146 indicates that there was not enough memory, on others that the
147 MethodID is unknown.
149 NOTES
151 EXAMPLE
153 BUGS
155 SEE ALSO
156 intuition.library/NewObjectA(), intuition.library/SetAttrsA(), intuition.library/GetAttr(),
157 intuition.library/DisposeObject(), DoMethodA(),
158 DoSuperMethodA(), "Basic Object-Oriented Programming System for
159 Intuition" and the "boopsi Class Reference" documentation.
161 INTERNALS
162 Allocate a structure which can contain all tags until the first
163 TAG_END. This takes into account TAG_MORE and the like. The code
164 will break if someone makes assumptions about the way taglists
165 are built in memory, ie. if he looks for the next TAG_MORE and
166 then simply skips it instead of following it.
168 ******************************************************************************/
170 struct TagItem * ti;
171 IPTR tag;
172 ULONG size;
173 va_list ap;
175 va_copy(ap, args);
176 tag = firstTag;
178 for (size=0;;size++)
180 if (tag == TAG_END || tag == TAG_MORE)
182 size ++; /* Copy this tag, too */
183 break;
186 switch (tag)
188 case TAG_IGNORE:
189 (void) va_arg(args, IPTR);
190 size --; /* Don't copy this tag */
191 break;
193 case TAG_SKIP: {
194 ULONG skip;
196 skip = va_arg(args, IPTR);
198 while (skip --)
200 (void) va_arg(args, IPTR);
201 (void) va_arg(args, IPTR);
204 break; }
206 default:
207 (void) va_arg(args, IPTR);
210 tag = va_arg (args, IPTR);
213 tag = firstTag;
215 if ((ti = AllocVec (size*sizeof(struct TagItem), MEMF_ANY)))
217 for (size=0;;size++)
219 ti[size].ti_Tag = tag;
221 if (tag == TAG_END)
222 break;
223 else if (tag == TAG_MORE)
225 ti[size].ti_Data = (IPTR) va_arg (ap, struct TagItem *);
226 break;
229 switch (tag)
231 case TAG_IGNORE:
232 (void) va_arg(ap, IPTR);
233 size --; /* Don't copy this tag */
234 break;
236 case TAG_SKIP: {
237 ULONG skip;
239 skip = va_arg(ap, IPTR);
241 while (skip --)
243 (void) va_arg(ap, IPTR);
244 (void) va_arg(ap, IPTR);
247 break; }
249 default:
250 ti[size].ti_Data = va_arg(ap, IPTR);
253 tag = va_arg (ap, IPTR);
256 va_end(ap);
257 return ti;
258 } /* GetTagsFromStack */
260 /******************************************************************************
262 NAME */
263 void FreeTagsFromStack (
265 /* SYNOPSIS */
266 struct TagItem * tags)
268 /* FUNCTION
269 Frees the memory occupied by the tagitems which were created by
270 GetTagsFromStack().
272 INPUTS
273 tags - The return value of GetTagsFromStack(). May be NULL.
275 RESULT
276 None.
278 NOTES
280 EXAMPLE
282 BUGS
284 SEE ALSO
285 GetTagsFromStack()
287 ******************************************************************************/
289 FreeVec(tags);
290 } /* FreeTagsFromStack */
292 /******************************************************************************
294 NAME */
295 APTR GetParamsFromStack (
297 /* SYNOPSIS */
298 va_list args)
300 /* FUNCTION
301 Builds an array of parameters which are passed on the stack.
302 This function is used on machines which have compilers which
303 don't pass the arguments to a varargs function unlike the
304 Amiga ones.
306 INPUTS
307 args - This has to be initialized by va_start()
309 RESULT
310 An array which can be passed to any function which expects the
311 structure or NULL if something failed. This call may fail for
312 different reasons on different systems. On some systems, NULL
313 indicates that there was not enough memory.
315 NOTES
316 This function fails for structures with more than 20 fields.
318 EXAMPLE
320 BUGS
322 SEE ALSO
323 CallHook()
325 INTERNALS
326 HPPA: Allocate a structure which can contain all APTRs between the
327 first variadic parameter of, for example, CallHook() and its first
328 local variable. This will copy a bit too much memory but in the end,
329 it saves a lot of work, since it's not neccessary to register every
330 structure.
332 ******************************************************************************/
334 ULONG size;
335 APTR params;
337 size = 21;
339 if ((params = AllocVec (size * sizeof (IPTR), MEMF_CLEAR)))
341 IPTR * ulptr = (IPTR *) params;
343 while (-- size)
345 *ulptr ++ = va_arg (args, IPTR);
349 return params;
350 } /* GetParamsFromStack */
352 /******************************************************************************
354 NAME */
355 void FreeParamsFromStack (
357 /* SYNOPSIS */
358 APTR params)
360 /* FUNCTION
361 Frees the memory occupied by the parameters array which was
362 created by GetParamsFromStack().
364 INPUTS
365 params - The return value of GetParamsFromStack(). May be NULL.
367 RESULT
368 None.
370 NOTES
372 EXAMPLE
374 BUGS
376 SEE ALSO
377 GetParamsFromStack()
379 ******************************************************************************/
381 FreeVec(params);
382 } /* FreeParamsFromStack */
383 #endif /* AROS_SLOWSTACKTAGS */