home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / compiler / alib / alib_util.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-09  |  7.4 KB  |  353 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: alib_util.c,v 1.3 1996/11/28 10:40:28 aros Exp $
  4.  
  5.     Desc: internal utility functions for amiga.lib
  6.     Lang: english
  7. */
  8. #include <aros/system.h>
  9. #include "alib_intern.h"
  10.  
  11. #undef CallHookPkt
  12. /******************************************************************************
  13.  
  14.     NAME */
  15.     ULONG CallHookPkt (
  16.  
  17. /*  SYNOPSIS */
  18.     struct Hook * hook,
  19.     APTR          object,
  20.     APTR          paramPacket)
  21.  
  22. /*  FUNCTION
  23.     Calls a hook with the specified object and parameters.
  24.  
  25.     INPUTS
  26.     hook - Call this hook.
  27.     object - This is the object which is passed to the hook. The valid
  28.         values for this parameter depends on the definition of the called
  29.         hook.
  30.     paramPacket - This are the parameters which is passed to the hook.
  31.         The valid values for this parameter depends on the definition
  32.         of the called hook.
  33.  
  34.     RESULT
  35.     The return value depends on the definition of the hook.
  36.  
  37.     NOTES
  38.  
  39.     EXAMPLE
  40.  
  41.     BUGS
  42.  
  43.     SEE ALSO
  44.     NewObject(), SetAttrs(), GetAttr(), DisposeObject(), DoMethod(),
  45.     DoSuperMethod(), "Basic Object-Oriented Programming System for
  46.     Intuition" and the "boopsi Class Reference" Dokument.
  47.  
  48.     HISTORY
  49.     22.11.96 digulla documented
  50.  
  51. ******************************************************************************/
  52. {
  53.     return AROS_UFC3(IPTR, hook->h_Entry,
  54.     AROS_UFHA(struct Hook *, hook,        A0),
  55.     AROS_UFHA(APTR,          object,      A2),
  56.     AROS_UFHA(APTR,          paramPacket, A1)
  57.     );
  58. }
  59.  
  60. #ifdef AROS_SLOWSTACKMETHODS
  61. /******************************************************************************
  62.  
  63.     NAME */
  64.     Msg GetMsgFromStack (
  65.  
  66. /*  SYNOPSIS */
  67.     ULONG    MethodID,
  68.     va_list args)
  69.  
  70. /*  FUNCTION
  71.     Builds a message structure with the parameters which are passed on
  72.     the stack. This function is used on machines which have compilers
  73.     which don't pass the arguments to a varargs function unlike the
  74.     Amiga ones.
  75.  
  76.     INPUTS
  77.     MethodID - This is the ID of the message
  78.     args - This has to be initialized by va_start()
  79.     firstlocal - The address of the first local function of the
  80.         function which wants to call GetMsgFromStack()
  81.  
  82.     RESULT
  83.     A message which can be passed to any function which expects the
  84.     structure which is defined for this MethodID or NULL if something
  85.     failed. This call may fail for different reasons on different
  86.     systems. On some systems, NULL indicates that there was not enough
  87.     memory, on others that the MethodID is unknown.
  88.  
  89.     NOTES
  90.     This function fails for structures with more than 20 fields.
  91.  
  92.     EXAMPLE
  93.  
  94.     BUGS
  95.  
  96.     SEE ALSO
  97.     NewObject(), SetAttrs(), GetAttr(), DisposeObject(), DoMethod(),
  98.     DoSuperMethod(), "Basic Object-Oriented Programming System for
  99.     Intuition" and the "boopsi Class Reference" Dokument.
  100.  
  101.     INTERNALS
  102.     HPPA: Allocate a structure which can contain all ULONGs between
  103.     the first argument of, for example, DoMethod() and its first local
  104.     variable. This will copy a bit too much memory but in the end, it
  105.     saves a lot of work, since it's not neccessary to register every
  106.     structure.
  107.  
  108.     HISTORY
  109.     22.11.96 digulla created
  110.  
  111. ******************************************************************************/
  112. {
  113. #if !AROS_STACK_GROWS_DOWNWARDS
  114.     ULONG size;
  115.     Msg   msg;
  116.  
  117.     size = 21;
  118.  
  119.     if ((msg = AllocVec (size * sizeof (ULONG), MEMF_CLEAR))
  120.     {
  121.     ULONG * ulptr = (ULONG * msg);
  122.  
  123.     *ulptr ++ = MethodID;
  124.  
  125.     while (-- size)
  126.     {
  127.         *ulptr = va_arg (args, ULONG);
  128.     }
  129.     }
  130.  
  131.     return msg;
  132. #else
  133.     return NULL;
  134. #endif
  135. } /* GetMsgFromStack */
  136.  
  137. /******************************************************************************
  138.  
  139.     NAME */
  140.     void FreeMsgFromStack (
  141.  
  142. /*  SYNOPSIS */
  143.     Msg msg)
  144.  
  145. /*  FUNCTION
  146.     Frees the memory occupied by the message which was created by
  147.     GetMsgFromStack().
  148.  
  149.     INPUTS
  150.     msg - The return value of GetMsgFromStack(). May be NULL.
  151.  
  152.     RESULT
  153.     None.
  154.  
  155.     NOTES
  156.  
  157.     EXAMPLE
  158.  
  159.     BUGS
  160.  
  161.     SEE ALSO
  162.     GetMsgFromStack()
  163.  
  164.     HISTORY
  165.     22.11.96 digulla created
  166.  
  167. ******************************************************************************/
  168. {
  169.     if (msg)
  170.     FreeVec (msg);
  171. } /* FreeMsgFromStack */
  172.  
  173. #endif /* AROS_SLOWSTACKMETHODS */
  174.  
  175. #ifdef AROS_SLOWSTACKTAGS
  176. /******************************************************************************
  177.  
  178.     NAME */
  179.     struct TagItem * GetTagsFromStack (
  180.  
  181. /*  SYNOPSIS */
  182.     ULONG    firstTag,
  183.     va_list args)
  184.  
  185. /*  FUNCTION
  186.     Builds a tagitem array with the tags on the stack. This function is
  187.     used on machines which have compilers which don't pass the
  188.     arguments to a varargs function unlike the Amiga ones.
  189.  
  190.     INPUTS
  191.     firstTag - This is the first tag passed to the function
  192.     args - This has to be initialized by va_start()
  193.  
  194.     RESULT
  195.     A TagItem array which can be passed to any function which expects
  196.     such an array or NULL if something failed. This call may fail for
  197.     different reasons on different systems. On some systems, NULL
  198.     indicates that there was not enough memory, on others that the
  199.     MethodID is unknown.
  200.  
  201.     NOTES
  202.  
  203.     EXAMPLE
  204.  
  205.     BUGS
  206.  
  207.     SEE ALSO
  208.     NewObject(), SetAttrs(), GetAttr(), DisposeObject(), DoMethod(),
  209.     DoSuperMethod(), "Basic Object-Oriented Programming System for
  210.     Intuition" and the "boopsi Class Reference" Dokument.
  211.  
  212.     INTERNALS
  213.     Allocate a structure which can contain all tags until the first
  214.     TAG_END. This takes into account TAG_MORE and the like. The code
  215.     will break if someone makes assumptions about the way taglists
  216.     are built in memory, ie. if he looks for the next TAG_MORE and
  217.     then simply skips it instead of following it.
  218.  
  219.     HISTORY
  220.     22.11.96 digulla created
  221.  
  222. ******************************************************************************/
  223. {
  224.     struct TagItem * ti;
  225.     ULONG         tag;
  226.     ULONG         size;
  227.     va_list         ap;
  228.  
  229.     ap    = args;
  230.     tag = firstTag;
  231.  
  232.     for (size=0;;size++)
  233.     {
  234.     if (tag == TAG_END || tag == TAG_MORE)
  235.     {
  236.         size ++; /* Copy this tag, too */
  237.         break;
  238.     }
  239.  
  240.     switch (tag)
  241.     {
  242.     case TAG_IGNORE:
  243.         size --; /* Don't copy this tag */
  244.         break;
  245.  
  246.     case TAG_SKIP: {
  247.         ULONG skip;
  248.  
  249.         skip = va_arg(args, IPTR);
  250.  
  251.         while (skip --)
  252.         {
  253.         (void) va_arg(args, ULONG);
  254.         (void) va_arg(args, IPTR);
  255.         }
  256.  
  257.         break; }
  258.  
  259.     default:
  260.         (void) va_arg(args, IPTR);
  261.     }
  262.  
  263.     tag = va_arg (args, ULONG);
  264.     }
  265.  
  266.     args = ap;
  267.     tag  = firstTag;
  268.  
  269.     if ((msg = AllocVec (size*sizeof(TagItem), MEMF_ANY))
  270.     {
  271.     for (size=0;;size++)
  272.     {
  273.         ti[size].ti_Tag = tag;
  274.  
  275.         if (tag == TAG_END)
  276.         break;
  277.         else if (tag == TAG_MORE)
  278.         {
  279.         ti[size].ti_Data = (IPTR) va_arg (args, struct TagItem *);
  280.         break;
  281.         }
  282.  
  283.         switch (tag)
  284.         {
  285.         case TAG_IGNORE:
  286.         size --; /* Don't copy this tag */
  287.         break;
  288.  
  289.         case TAG_SKIP: {
  290.         ULONG skip;
  291.  
  292.         skip = va_arg(args, IPTR);
  293.  
  294.         while (skip --)
  295.         {
  296.             (void) va_arg(args, ULONG);
  297.             (void) va_arg(args, IPTR);
  298.         }
  299.  
  300.         break; }
  301.  
  302.         default:
  303.         ti[size].ti_Data = va_arg(args, IPTR);
  304.         }
  305.  
  306.         tag = va_arg (args, ULONG);
  307.     }
  308.     }
  309.  
  310.     return msg;
  311. } /* GetTagsFromStack */
  312.  
  313. /******************************************************************************
  314.  
  315.     NAME */
  316.     void FreeTagsFromStack (
  317.  
  318. /*  SYNOPSIS */
  319.     struct TagItem * tags)
  320.  
  321. /*  FUNCTION
  322.     Frees the memory occupied by the tagitems which were created by
  323.     GetTagsFromStack().
  324.  
  325.     INPUTS
  326.     tags - The return value of GetTagsFromStack(). May be NULL.
  327.  
  328.     RESULT
  329.     None.
  330.  
  331.     NOTES
  332.  
  333.     EXAMPLE
  334.  
  335.     BUGS
  336.  
  337.     SEE ALSO
  338.     GetTagsFromStack()
  339.  
  340.     HISTORY
  341.     22.11.96 digulla created
  342.  
  343. ******************************************************************************/
  344. {
  345.     if (tags)
  346.     FreeVec (tags);
  347. } /* FreeTagsFromStack */
  348.  
  349. #endif /* AROS_SLOWSTACKTAGS */
  350.  
  351.  
  352.  
  353.