2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
5 Internal utility functions.
8 #include <aros/system.h>
9 #include "alib_intern.h"
11 #ifdef AROS_SLOWSTACKMETHODS
12 #include <intuition/classusr.h>
13 #include <proto/exec.h>
14 /******************************************************************************
24 Builds a message structure with the parameters which are passed on
25 the stack. This function is used on machines which have compilers
26 which don't pass the arguments to a varargs function unlike the
30 MethodID - This is the ID of the message
31 args - This has to be initialized by va_start()
32 firstlocal - The address of the first local function of the
33 function which wants to call GetMsgFromStack()
36 A message which can be passed to any function which expects the
37 structure which is defined for this MethodID or NULL if something
38 failed. This call may fail for different reasons on different
39 systems. On some systems, NULL indicates that there was not enough
40 memory, on others that the MethodID is unknown.
43 This function fails for structures with more than 32 fields.
50 intuition.library/NewObjectA(), intuition.library/SetAttrsA(), intuition.library/GetAttr(),
51 intuition.library/DisposeObject(), DoMethodA(),
52 DoSuperMethodA(), "Basic Object-Oriented Programming System for
53 Intuition" and the "boopsi Class Reference" documentation.
56 HPPA: Allocate a structure which can contain all IPTRs between
57 the first argument of, for example, DoMethod() and its first local
58 variable. This will copy a bit too much memory but in the end, it
59 saves a lot of work, since it's not neccessary to register every
62 ******************************************************************************/
69 if ((msg
= AllocVec (size
* sizeof (IPTR
), MEMF_CLEAR
)))
71 IPTR
* ulptr
= (IPTR
*)msg
;
77 *ulptr
++ = va_arg (args
, IPTR
);
82 } /* GetMsgFromStack */
84 /******************************************************************************
87 void FreeMsgFromStack (
93 Frees the memory occupied by the message which was created by
97 msg - The return value of GetMsgFromStack(). May be NULL.
111 ******************************************************************************/
114 } /* FreeMsgFromStack */
116 #endif /* AROS_SLOWSTACKMETHODS */
118 #ifdef AROS_SLOWSTACKTAGS
120 #include <utility/tagitem.h>
121 #include <exec/memory.h>
122 #include <proto/exec.h>
123 /******************************************************************************
126 struct TagItem
* GetTagsFromStack (
133 Builds a tagitem array with the tags on the stack. This function is
134 used on machines which have compilers which don't pass the
135 arguments to a varargs function unlike the Amiga ones.
138 firstTag - This is the first tag passed to the function
139 args - This has to be initialized by va_start()
142 A TagItem array which can be passed to any function which expects
143 such an array or NULL if something failed. This call may fail for
144 different reasons on different systems. On some systems, NULL
145 indicates that there was not enough memory, on others that the
155 intuition.library/NewObjectA(), intuition.library/SetAttrsA(), intuition.library/GetAttr(),
156 intuition.library/DisposeObject(), DoMethodA(),
157 DoSuperMethodA(), "Basic Object-Oriented Programming System for
158 Intuition" and the "boopsi Class Reference" documentation.
161 Allocate a structure which can contain all tags until the first
162 TAG_END. This takes into account TAG_MORE and the like. The code
163 will break if someone makes assumptions about the way taglists
164 are built in memory, ie. if he looks for the next TAG_MORE and
165 then simply skips it instead of following it.
167 ******************************************************************************/
179 if (tag
== TAG_END
|| tag
== TAG_MORE
)
181 size
++; /* Copy this tag, too */
188 (void) va_arg(args
, IPTR
);
189 size
--; /* Don't copy this tag */
195 skip
= va_arg(args
, IPTR
);
199 (void) va_arg(args
, IPTR
);
200 (void) va_arg(args
, IPTR
);
206 (void) va_arg(args
, IPTR
);
209 tag
= va_arg (args
, IPTR
);
214 if ((ti
= AllocVec (size
*sizeof(struct TagItem
), MEMF_ANY
)))
218 ti
[size
].ti_Tag
= tag
;
222 else if (tag
== TAG_MORE
)
224 ti
[size
].ti_Data
= (IPTR
) va_arg (ap
, struct TagItem
*);
231 (void) va_arg(ap
, IPTR
);
232 size
--; /* Don't copy this tag */
238 skip
= va_arg(ap
, IPTR
);
242 (void) va_arg(ap
, IPTR
);
243 (void) va_arg(ap
, IPTR
);
249 ti
[size
].ti_Data
= va_arg(ap
, IPTR
);
252 tag
= va_arg (ap
, IPTR
);
257 } /* GetTagsFromStack */
259 /******************************************************************************
262 void FreeTagsFromStack (
265 struct TagItem
* tags
)
268 Frees the memory occupied by the tagitems which were created by
272 tags - The return value of GetTagsFromStack(). May be NULL.
286 ******************************************************************************/
289 } /* FreeTagsFromStack */
291 /******************************************************************************
294 APTR
GetParamsFromStack (
300 Builds an array of parameters which are passed on the stack.
301 This function is used on machines which have compilers which
302 don't pass the arguments to a varargs function unlike the
306 args - This has to be initialized by va_start()
309 An array which can be passed to any function which expects the
310 structure or NULL if something failed. This call may fail for
311 different reasons on different systems. On some systems, NULL
312 indicates that there was not enough memory.
315 This function fails for structures with more than 20 fields.
325 HPPA: Allocate a structure which can contain all APTRs between the
326 first variadic parameter of, for example, CallHook() and its first
327 local variable. This will copy a bit too much memory but in the end,
328 it saves a lot of work, since it's not neccessary to register every
331 ******************************************************************************/
338 if ((params
= AllocVec (size
* sizeof (IPTR
), MEMF_CLEAR
)))
340 IPTR
* ulptr
= (IPTR
*) params
;
344 *ulptr
++ = va_arg (args
, IPTR
);
349 } /* GetParamsFromStack */
351 /******************************************************************************
354 void FreeParamsFromStack (
360 Frees the memory occupied by the parameters array which was
361 created by GetParamsFromStack().
364 params - The return value of GetParamsFromStack(). May be NULL.
378 ******************************************************************************/
381 } /* FreeParamsFromStack */
383 #endif /* AROS_SLOWSTACKTAGS */