2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
5 Internal utility functions.
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 /******************************************************************************
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
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()
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.
44 This function fails for structures with more than 32 fields.
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.
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
63 ******************************************************************************/
70 if ((msg
= AllocVec (size
* sizeof (IPTR
), MEMF_CLEAR
)))
72 IPTR
* ulptr
= (IPTR
*)msg
;
78 *ulptr
++ = va_arg (args
, IPTR
);
83 } /* GetMsgFromStack */
85 /******************************************************************************
88 void FreeMsgFromStack (
94 Frees the memory occupied by the message which was created by
98 msg - The return value of GetMsgFromStack(). May be NULL.
112 ******************************************************************************/
115 } /* FreeMsgFromStack */
117 #endif /* AROS_SLOWSTACKMETHODS */
119 #ifdef AROS_SLOWSTACKTAGS
121 #include <utility/tagitem.h>
122 #include <exec/memory.h>
123 #include <proto/exec.h>
124 /******************************************************************************
127 struct TagItem
* GetTagsFromStack (
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.
139 firstTag - This is the first tag passed to the function
140 args - This has to be initialized by va_start()
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
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.
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 ******************************************************************************/
180 if (tag
== TAG_END
|| tag
== TAG_MORE
)
182 size
++; /* Copy this tag, too */
189 (void) va_arg(args
, IPTR
);
190 size
--; /* Don't copy this tag */
196 skip
= va_arg(args
, IPTR
);
200 (void) va_arg(args
, IPTR
);
201 (void) va_arg(args
, IPTR
);
207 (void) va_arg(args
, IPTR
);
210 tag
= va_arg (args
, IPTR
);
215 if ((ti
= AllocVec (size
*sizeof(struct TagItem
), MEMF_ANY
)))
219 ti
[size
].ti_Tag
= tag
;
223 else if (tag
== TAG_MORE
)
225 ti
[size
].ti_Data
= (IPTR
) va_arg (ap
, struct TagItem
*);
232 (void) va_arg(ap
, IPTR
);
233 size
--; /* Don't copy this tag */
239 skip
= va_arg(ap
, IPTR
);
243 (void) va_arg(ap
, IPTR
);
244 (void) va_arg(ap
, IPTR
);
250 ti
[size
].ti_Data
= va_arg(ap
, IPTR
);
253 tag
= va_arg (ap
, IPTR
);
258 } /* GetTagsFromStack */
260 /******************************************************************************
263 void FreeTagsFromStack (
266 struct TagItem
* tags
)
269 Frees the memory occupied by the tagitems which were created by
273 tags - The return value of GetTagsFromStack(). May be NULL.
287 ******************************************************************************/
290 } /* FreeTagsFromStack */
292 /******************************************************************************
295 APTR
GetParamsFromStack (
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
307 args - This has to be initialized by va_start()
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.
316 This function fails for structures with more than 20 fields.
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
332 ******************************************************************************/
339 if ((params
= AllocVec (size
* sizeof (IPTR
), MEMF_CLEAR
)))
341 IPTR
* ulptr
= (IPTR
*) params
;
345 *ulptr
++ = va_arg (args
, IPTR
);
350 } /* GetParamsFromStack */
352 /******************************************************************************
355 void FreeParamsFromStack (
361 Frees the memory occupied by the parameters array which was
362 created by GetParamsFromStack().
365 params - The return value of GetParamsFromStack(). May be NULL.
379 ******************************************************************************/
382 } /* FreeParamsFromStack */
383 #endif /* AROS_SLOWSTACKTAGS */