2 Copyright © 1995-2003, 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 boopsi.library/NewObject(), boopsi.library/SetAttrs(), boopsi.library/GetAttr(),
51 boopsi.library/DisposeObject(), DoMethodA(),
52 DoSuperMethodA(), "Basic Object-Oriented Programming System for
53 Intuition" and the "boopsi Class Reference" Dokument.
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
63 22.11.96 digulla created
65 ******************************************************************************/
72 if ((msg
= AllocVec (size
* sizeof (IPTR
), MEMF_CLEAR
)))
74 IPTR
* ulptr
= (IPTR
*)msg
;
80 *ulptr
++ = va_arg (args
, IPTR
);
85 } /* GetMsgFromStack */
87 /******************************************************************************
90 void FreeMsgFromStack (
96 Frees the memory occupied by the message which was created by
100 msg - The return value of GetMsgFromStack(). May be NULL.
115 22.11.96 digulla created
117 ******************************************************************************/
121 } /* FreeMsgFromStack */
123 #endif /* AROS_SLOWSTACKMETHODS */
125 #ifdef AROS_SLOWSTACKTAGS
127 #include <utility/tagitem.h>
128 #include <exec/memory.h>
129 #include <proto/exec.h>
130 /******************************************************************************
133 struct TagItem
* GetTagsFromStack (
140 Builds a tagitem array with the tags on the stack. This function is
141 used on machines which have compilers which don't pass the
142 arguments to a varargs function unlike the Amiga ones.
145 firstTag - This is the first tag passed to the function
146 args - This has to be initialized by va_start()
149 A TagItem array which can be passed to any function which expects
150 such an array or NULL if something failed. This call may fail for
151 different reasons on different systems. On some systems, NULL
152 indicates that there was not enough memory, on others that the
162 boopsi.library/NewObject(), boopsi.library/SetAttrs(), boopsi.library/GetAttr(),
163 boopsi.library/DisposeObject(), DoMethodA(),
164 DoSuperMethodA(), "Basic Object-Oriented Programming System for
165 Intuition" and the "boopsi Class Reference" Dokument.
168 Allocate a structure which can contain all tags until the first
169 TAG_END. This takes into account TAG_MORE and the like. The code
170 will break if someone makes assumptions about the way taglists
171 are built in memory, ie. if he looks for the next TAG_MORE and
172 then simply skips it instead of following it.
175 22.11.96 digulla created
177 ******************************************************************************/
189 if (tag
== TAG_END
|| tag
== TAG_MORE
)
191 size
++; /* Copy this tag, too */
198 (void) va_arg(args
, IPTR
);
199 size
--; /* Don't copy this tag */
205 skip
= va_arg(args
, IPTR
);
209 (void) va_arg(args
, IPTR
);
210 (void) va_arg(args
, IPTR
);
216 (void) va_arg(args
, IPTR
);
219 tag
= va_arg (args
, IPTR
);
224 if ((ti
= AllocVec (size
*sizeof(struct TagItem
), MEMF_ANY
)))
228 ti
[size
].ti_Tag
= tag
;
232 else if (tag
== TAG_MORE
)
234 ti
[size
].ti_Data
= (IPTR
) va_arg (ap
, struct TagItem
*);
241 (void) va_arg(ap
, IPTR
);
242 size
--; /* Don't copy this tag */
248 skip
= va_arg(ap
, IPTR
);
252 (void) va_arg(ap
, IPTR
);
253 (void) va_arg(ap
, IPTR
);
259 ti
[size
].ti_Data
= va_arg(ap
, IPTR
);
262 tag
= va_arg (ap
, IPTR
);
267 } /* GetTagsFromStack */
269 /******************************************************************************
272 void FreeTagsFromStack (
275 struct TagItem
* tags
)
278 Frees the memory occupied by the tagitems which were created by
282 tags - The return value of GetTagsFromStack(). May be NULL.
297 22.11.96 digulla created
299 ******************************************************************************/
303 } /* FreeTagsFromStack */
305 /******************************************************************************
308 APTR
GetParamsFromStack (
314 Builds an array of parameters which are passed on the stack.
315 This function is used on machines which have compilers which
316 don't pass the arguments to a varargs function unlike the
320 args - This has to be initialized by va_start()
323 An array which can be passed to any function which expects the
324 structure or NULL if something failed. This call may fail for
325 different reasons on different systems. On some systems, NULL
326 indicates that there was not enough memory.
329 This function fails for structures with more than 20 fields.
339 HPPA: Allocate a structure which can contain all APTRs between the
340 first variadic parameter of, for example, CallHook() and its first
341 local variable. This will copy a bit too much memory but in the end,
342 it saves a lot of work, since it's not neccessary to register every
346 25.04.08 sszymczy adapted from GetMsgFromStack()
348 ******************************************************************************/
355 if ((params
= AllocVec (size
* sizeof (IPTR
), MEMF_CLEAR
)))
357 IPTR
* ulptr
= (IPTR
*) params
;
361 *ulptr
++ = va_arg (args
, IPTR
);
366 } /* GetParamsFromStack */
368 /******************************************************************************
371 void FreeParamsFromStack (
377 Frees the memory occupied by the parameters array which was
378 created by GetParamsFromStack().
381 params - The return value of GetParamsFromStack(). May be NULL.
396 25.04.08 sszymczy adapted from FreeMsgFromStack()
398 ******************************************************************************/
402 } /* FreeParamsFromStack */
404 #endif /* AROS_SLOWSTACKTAGS */