Artifact c82abb12fcfaa6685652d8f2898c6f1c0597a27e:


0000: 2f 2a 20 76 61 63 61 6c 6c 20 66 75 6e 63 74 69  /* vacall functi
0010: 6f 6e 20 66 6f 72 20 63 6f 6e 76 65 78 20 43 50  on for convex CP
0020: 55 20 2a 2f 0a 0a 2f 2a 0a 20 2a 20 43 6f 70 79  U */../*. * Copy
0030: 72 69 67 68 74 20 31 39 39 35 2d 32 30 30 34 20  right 1995-2004 
0040: 42 72 75 6e 6f 20 48 61 69 62 6c 65 2c 20 3c 62  Bruno Haible, <b
0050: 72 75 6e 6f 40 63 6c 69 73 70 2e 6f 72 67 3e 0a  runo@clisp.org>.
0060: 20 2a 0a 20 2a 20 54 68 69 73 20 69 73 20 66 72   *. * This is fr
0070: 65 65 20 73 6f 66 74 77 61 72 65 20 64 69 73 74  ee software dist
0080: 72 69 62 75 74 65 64 20 75 6e 64 65 72 20 74 68  ributed under th
0090: 65 20 47 4e 55 20 47 65 6e 65 72 61 6c 20 50 75  e GNU General Pu
00a0: 62 6c 69 63 20 4c 69 63 65 6e 63 65 0a 20 2a 20  blic Licence. * 
00b0: 64 65 73 63 72 69 62 65 64 20 69 6e 20 74 68 65  described in the
00c0: 20 66 69 6c 65 20 43 4f 50 59 49 4e 47 2e 20 43   file COPYING. C
00d0: 6f 6e 74 61 63 74 20 74 68 65 20 61 75 74 68 6f  ontact the autho
00e0: 72 20 69 66 20 79 6f 75 20 64 6f 6e 27 74 20 68  r if you don't h
00f0: 61 76 65 20 74 68 69 73 0a 20 2a 20 6f 72 20 63  ave this. * or c
0100: 61 6e 27 74 20 6c 69 76 65 20 77 69 74 68 20 69  an't live with i
0110: 74 2e 20 54 68 65 72 65 20 69 73 20 41 42 53 4f  t. There is ABSO
0120: 4c 55 54 45 4c 59 20 4e 4f 20 57 41 52 52 41 4e  LUTELY NO WARRAN
0130: 54 59 2c 20 65 78 70 6c 69 63 69 74 20 6f 72 20  TY, explicit or 
0140: 69 6d 70 6c 69 65 64 2c 0a 20 2a 20 6f 6e 20 74  implied,. * on t
0150: 68 69 73 20 73 6f 66 74 77 61 72 65 2e 0a 20 2a  his software.. *
0160: 2f 0a 0a 23 69 66 6e 64 65 66 20 52 45 45 4e 54  /..#ifndef REENT
0170: 52 41 4e 54 0a 23 69 6e 63 6c 75 64 65 20 22 76  RANT.#include "v
0180: 61 63 61 6c 6c 2e 68 2e 69 6e 22 0a 23 65 6c 73  acall.h.in".#els
0190: 65 20 2f 2a 20 52 45 45 4e 54 52 41 4e 54 20 2a  e /* REENTRANT *
01a0: 2f 0a 23 69 6e 63 6c 75 64 65 20 22 76 61 63 61  /.#include "vaca
01b0: 6c 6c 5f 72 2e 68 2e 69 6e 22 0a 23 65 6e 64 69  ll_r.h.in".#endi
01c0: 66 0a 0a 23 69 66 64 65 66 20 52 45 45 4e 54 52  f..#ifdef REENTR
01d0: 41 4e 54 0a 23 64 65 66 69 6e 65 20 5f 5f 76 61  ANT.#define __va
01e0: 63 61 6c 6c 20 5f 5f 76 61 63 61 6c 6c 5f 72 0a  call __vacall_r.
01f0: 72 65 67 69 73 74 65 72 20 73 74 72 75 63 74 20  register struct 
0200: 7b 20 76 6f 69 64 20 28 2a 76 61 63 61 6c 6c 5f  { void (*vacall_
0210: 66 75 6e 63 74 69 6f 6e 29 20 28 76 6f 69 64 2a  function) (void*
0220: 2c 76 61 5f 61 6c 69 73 74 29 3b 20 76 6f 69 64  ,va_alist); void
0230: 2a 20 61 72 67 3b 20 7d 0a 20 20 20 20 20 20 20  * arg; }.       
0240: 20 20 2a 09 09 65 6e 76 09 5f 5f 61 73 6d 5f 5f    *..env.__asm__
0250: 28 22 73 30 22 29 3b 0a 23 65 6e 64 69 66 0a 72  ("s0");.#endif.r
0260: 65 67 69 73 74 65 72 20 69 6e 74 09 09 69 72 65  egister int..ire
0270: 74 09 5f 5f 61 73 6d 5f 5f 28 22 73 30 22 29 3b  t.__asm__("s0");
0280: 0a 72 65 67 69 73 74 65 72 20 6c 6f 6e 67 20 6c  .register long l
0290: 6f 6e 67 09 6c 6c 72 65 74 09 5f 5f 61 73 6d 5f  ong.llret.__asm_
02a0: 5f 28 22 73 30 22 29 3b 0a 72 65 67 69 73 74 65  _("s0");.registe
02b0: 72 20 66 6c 6f 61 74 09 09 66 72 65 74 09 5f 5f  r float..fret.__
02c0: 61 73 6d 5f 5f 28 22 73 30 22 29 3b 0a 72 65 67  asm__("s0");.reg
02d0: 69 73 74 65 72 20 64 6f 75 62 6c 65 09 09 64 72  ister double..dr
02e0: 65 74 09 5f 5f 61 73 6d 5f 5f 28 22 73 30 22 29  et.__asm__("s0")
02f0: 3b 0a 0a 76 6f 69 64 20 2f 2a 20 74 68 65 20 72  ;..void /* the r
0300: 65 74 75 72 6e 20 74 79 70 65 20 69 73 20 76 61  eturn type is va
0310: 72 69 61 62 6c 65 2c 20 6e 6f 74 20 76 6f 69 64  riable, not void
0320: 21 20 2a 2f 0a 5f 5f 76 61 63 61 6c 6c 20 28 5f  ! */.__vacall (_
0330: 5f 76 61 77 6f 72 64 20 66 69 72 73 74 77 6f 72  _vaword firstwor
0340: 64 29 0a 7b 0a 20 20 5f 5f 76 61 5f 61 6c 69 73  d).{.  __va_alis
0350: 74 20 6c 69 73 74 3b 0a 20 20 2f 2a 20 50 72 65  t list;.  /* Pre
0360: 70 61 72 65 20 74 68 65 20 76 61 5f 61 6c 69 73  pare the va_alis
0370: 74 2e 20 2a 2f 0a 20 20 6c 69 73 74 2e 66 6c 61  t. */.  list.fla
0380: 67 73 20 3d 20 30 3b 0a 20 20 6c 69 73 74 2e 61  gs = 0;.  list.a
0390: 70 74 72 20 3d 20 28 6c 6f 6e 67 29 26 66 69 72  ptr = (long)&fir
03a0: 73 74 77 6f 72 64 3b 0a 20 20 6c 69 73 74 2e 72  stword;.  list.r
03b0: 61 64 64 72 20 3d 20 28 76 6f 69 64 2a 29 30 3b  addr = (void*)0;
03c0: 0a 20 20 6c 69 73 74 2e 72 74 79 70 65 20 3d 20  .  list.rtype = 
03d0: 5f 5f 56 41 76 6f 69 64 3b 0a 20 20 2f 2a 20 43  __VAvoid;.  /* C
03e0: 61 6c 6c 20 76 61 63 61 6c 6c 5f 66 75 6e 63 74  all vacall_funct
03f0: 69 6f 6e 2e 20 54 68 65 20 6d 61 63 72 6f 73 20  ion. The macros 
0400: 64 6f 20 61 6c 6c 20 74 68 65 20 72 65 73 74 2e  do all the rest.
0410: 20 2a 2f 0a 23 69 66 6e 64 65 66 20 52 45 45 4e   */.#ifndef REEN
0420: 54 52 41 4e 54 0a 20 20 28 2a 76 61 63 61 6c 6c  TRANT.  (*vacall
0430: 5f 66 75 6e 63 74 69 6f 6e 29 20 28 26 6c 69 73  _function) (&lis
0440: 74 29 3b 0a 23 65 6c 73 65 20 2f 2a 20 52 45 45  t);.#else /* REE
0450: 4e 54 52 41 4e 54 20 2a 2f 0a 20 20 28 2a 65 6e  NTRANT */.  (*en
0460: 76 2d 3e 76 61 63 61 6c 6c 5f 66 75 6e 63 74 69  v->vacall_functi
0470: 6f 6e 29 20 28 65 6e 76 2d 3e 61 72 67 2c 26 6c  on) (env->arg,&l
0480: 69 73 74 29 3b 0a 23 65 6e 64 69 66 0a 20 20 2f  ist);.#endif.  /
0490: 2a 20 50 75 74 20 72 65 74 75 72 6e 20 76 61 6c  * Put return val
04a0: 75 65 20 69 6e 74 6f 20 70 72 6f 70 65 72 20 72  ue into proper r
04b0: 65 67 69 73 74 65 72 2e 20 2a 2f 0a 20 20 69 66  egister. */.  if
04c0: 20 28 6c 69 73 74 2e 72 74 79 70 65 20 3d 3d 20   (list.rtype == 
04d0: 5f 5f 56 41 76 6f 69 64 29 20 7b 0a 20 20 7d 20  __VAvoid) {.  } 
04e0: 65 6c 73 65 0a 20 20 69 66 20 28 6c 69 73 74 2e  else.  if (list.
04f0: 72 74 79 70 65 20 3d 3d 20 5f 5f 56 41 63 68 61  rtype == __VAcha
0500: 72 29 20 7b 0a 20 20 20 20 69 72 65 74 20 3d 20  r) {.    iret = 
0510: 6c 69 73 74 2e 74 6d 70 2e 5f 63 68 61 72 3b 0a  list.tmp._char;.
0520: 20 20 7d 20 65 6c 73 65 0a 20 20 69 66 20 28 6c    } else.  if (l
0530: 69 73 74 2e 72 74 79 70 65 20 3d 3d 20 5f 5f 56  ist.rtype == __V
0540: 41 73 63 68 61 72 29 20 7b 0a 20 20 20 20 69 72  Aschar) {.    ir
0550: 65 74 20 3d 20 6c 69 73 74 2e 74 6d 70 2e 5f 73  et = list.tmp._s
0560: 63 68 61 72 3b 0a 20 20 7d 20 65 6c 73 65 0a 20  char;.  } else. 
0570: 20 69 66 20 28 6c 69 73 74 2e 72 74 79 70 65 20   if (list.rtype 
0580: 3d 3d 20 5f 5f 56 41 75 63 68 61 72 29 20 7b 0a  == __VAuchar) {.
0590: 20 20 20 20 69 72 65 74 20 3d 20 6c 69 73 74 2e      iret = list.
05a0: 74 6d 70 2e 5f 75 63 68 61 72 3b 0a 20 20 7d 20  tmp._uchar;.  } 
05b0: 65 6c 73 65 0a 20 20 69 66 20 28 6c 69 73 74 2e  else.  if (list.
05c0: 72 74 79 70 65 20 3d 3d 20 5f 5f 56 41 73 68 6f  rtype == __VAsho
05d0: 72 74 29 20 7b 0a 20 20 20 20 69 72 65 74 20 3d  rt) {.    iret =
05e0: 20 6c 69 73 74 2e 74 6d 70 2e 5f 73 68 6f 72 74   list.tmp._short
05f0: 3b 0a 20 20 7d 20 65 6c 73 65 0a 20 20 69 66 20  ;.  } else.  if 
0600: 28 6c 69 73 74 2e 72 74 79 70 65 20 3d 3d 20 5f  (list.rtype == _
0610: 5f 56 41 75 73 68 6f 72 74 29 20 7b 0a 20 20 20  _VAushort) {.   
0620: 20 69 72 65 74 20 3d 20 6c 69 73 74 2e 74 6d 70   iret = list.tmp
0630: 2e 5f 75 73 68 6f 72 74 3b 0a 20 20 7d 20 65 6c  ._ushort;.  } el
0640: 73 65 0a 20 20 69 66 20 28 6c 69 73 74 2e 72 74  se.  if (list.rt
0650: 79 70 65 20 3d 3d 20 5f 5f 56 41 69 6e 74 29 20  ype == __VAint) 
0660: 7b 0a 20 20 20 20 69 72 65 74 20 3d 20 6c 69 73  {.    iret = lis
0670: 74 2e 74 6d 70 2e 5f 69 6e 74 3b 0a 20 20 7d 20  t.tmp._int;.  } 
0680: 65 6c 73 65 0a 20 20 69 66 20 28 6c 69 73 74 2e  else.  if (list.
0690: 72 74 79 70 65 20 3d 3d 20 5f 5f 56 41 75 69 6e  rtype == __VAuin
06a0: 74 29 20 7b 0a 20 20 20 20 69 72 65 74 20 3d 20  t) {.    iret = 
06b0: 6c 69 73 74 2e 74 6d 70 2e 5f 75 69 6e 74 3b 0a  list.tmp._uint;.
06c0: 20 20 7d 20 65 6c 73 65 0a 20 20 69 66 20 28 6c    } else.  if (l
06d0: 69 73 74 2e 72 74 79 70 65 20 3d 3d 20 5f 5f 56  ist.rtype == __V
06e0: 41 6c 6f 6e 67 29 20 7b 0a 20 20 20 20 69 72 65  Along) {.    ire
06f0: 74 20 3d 20 6c 69 73 74 2e 74 6d 70 2e 5f 6c 6f  t = list.tmp._lo
0700: 6e 67 3b 0a 20 20 7d 20 65 6c 73 65 0a 20 20 69  ng;.  } else.  i
0710: 66 20 28 6c 69 73 74 2e 72 74 79 70 65 20 3d 3d  f (list.rtype ==
0720: 20 5f 5f 56 41 75 6c 6f 6e 67 29 20 7b 0a 20 20   __VAulong) {.  
0730: 20 20 69 72 65 74 20 3d 20 6c 69 73 74 2e 74 6d    iret = list.tm
0740: 70 2e 5f 75 6c 6f 6e 67 3b 0a 20 20 7d 20 65 6c  p._ulong;.  } el
0750: 73 65 0a 20 20 69 66 20 28 6c 69 73 74 2e 72 74  se.  if (list.rt
0760: 79 70 65 20 3d 3d 20 5f 5f 56 41 6c 6f 6e 67 6c  ype == __VAlongl
0770: 6f 6e 67 29 20 7b 0a 20 20 20 20 69 72 65 74 20  ong) {.    iret 
0780: 3d 20 6c 69 73 74 2e 74 6d 70 2e 5f 6c 6f 6e 67  = list.tmp._long
0790: 6c 6f 6e 67 3b 0a 20 20 7d 20 65 6c 73 65 0a 20  long;.  } else. 
07a0: 20 69 66 20 28 6c 69 73 74 2e 72 74 79 70 65 20   if (list.rtype 
07b0: 3d 3d 20 5f 5f 56 41 75 6c 6f 6e 67 6c 6f 6e 67  == __VAulonglong
07c0: 29 20 7b 0a 20 20 20 20 69 72 65 74 20 3d 20 6c  ) {.    iret = l
07d0: 69 73 74 2e 74 6d 70 2e 5f 75 6c 6f 6e 67 6c 6f  ist.tmp._ulonglo
07e0: 6e 67 3b 0a 20 20 7d 20 65 6c 73 65 0a 20 20 69  ng;.  } else.  i
07f0: 66 20 28 6c 69 73 74 2e 72 74 79 70 65 20 3d 3d  f (list.rtype ==
0800: 20 5f 5f 56 41 66 6c 6f 61 74 29 20 7b 0a 20 20   __VAfloat) {.  
0810: 20 20 66 72 65 74 20 3d 20 6c 69 73 74 2e 74 6d    fret = list.tm
0820: 70 2e 5f 66 6c 6f 61 74 3b 0a 20 20 7d 20 65 6c  p._float;.  } el
0830: 73 65 0a 20 20 69 66 20 28 6c 69 73 74 2e 72 74  se.  if (list.rt
0840: 79 70 65 20 3d 3d 20 5f 5f 56 41 64 6f 75 62 6c  ype == __VAdoubl
0850: 65 29 20 7b 0a 20 20 20 20 64 72 65 74 20 3d 20  e) {.    dret = 
0860: 6c 69 73 74 2e 74 6d 70 2e 5f 64 6f 75 62 6c 65  list.tmp._double
0870: 3b 0a 20 20 7d 20 65 6c 73 65 0a 20 20 69 66 20  ;.  } else.  if 
0880: 28 6c 69 73 74 2e 72 74 79 70 65 20 3d 3d 20 5f  (list.rtype == _
0890: 5f 56 41 76 6f 69 64 70 29 20 7b 0a 20 20 20 20  _VAvoidp) {.    
08a0: 69 72 65 74 20 3d 20 28 6c 6f 6e 67 29 6c 69 73  iret = (long)lis
08b0: 74 2e 74 6d 70 2e 5f 70 74 72 3b 0a 20 20 7d 20  t.tmp._ptr;.  } 
08c0: 65 6c 73 65 0a 20 20 69 66 20 28 6c 69 73 74 2e  else.  if (list.
08d0: 72 74 79 70 65 20 3d 3d 20 5f 5f 56 41 73 74 72  rtype == __VAstr
08e0: 75 63 74 29 20 7b 0a 20 20 20 20 69 66 20 28 6c  uct) {.    if (l
08f0: 69 73 74 2e 66 6c 61 67 73 20 26 20 5f 5f 56 41  ist.flags & __VA
0900: 5f 50 43 43 5f 53 54 52 55 43 54 5f 52 45 54 55  _PCC_STRUCT_RETU
0910: 52 4e 29 20 7b 0a 20 20 20 20 20 20 2f 2a 20 70  RN) {.      /* p
0920: 63 63 20 73 74 72 75 63 74 20 72 65 74 75 72 6e  cc struct return
0930: 20 63 6f 6e 76 65 6e 74 69 6f 6e 20 2a 2f 0a 20   convention */. 
0940: 20 20 20 20 20 69 72 65 74 20 3d 20 28 6c 6f 6e       iret = (lon
0950: 67 29 20 6c 69 73 74 2e 72 61 64 64 72 3b 0a 20  g) list.raddr;. 
0960: 20 20 20 7d 20 65 6c 73 65 20 7b 0a 20 20 20 20     } else {.    
0970: 20 20 2f 2a 20 6e 6f 72 6d 61 6c 20 73 74 72 75    /* normal stru
0980: 63 74 20 72 65 74 75 72 6e 20 63 6f 6e 76 65 6e  ct return conven
0990: 74 69 6f 6e 20 2a 2f 0a 20 20 20 20 20 20 69 66  tion */.      if
09a0: 20 28 6c 69 73 74 2e 66 6c 61 67 73 20 26 20 5f   (list.flags & _
09b0: 5f 56 41 5f 52 45 47 49 53 54 45 52 5f 53 54 52  _VA_REGISTER_STR
09c0: 55 43 54 5f 52 45 54 55 52 4e 29 20 7b 0a 20 20  UCT_RETURN) {.  
09d0: 20 20 20 20 20 20 69 66 20 28 6c 69 73 74 2e 72        if (list.r
09e0: 73 69 7a 65 20 3d 3d 20 73 69 7a 65 6f 66 28 63  size == sizeof(c
09f0: 68 61 72 29 29 20 7b 0a 20 20 20 20 20 20 20 20  har)) {.        
0a00: 20 20 69 72 65 74 20 3d 20 2a 28 75 6e 73 69 67    iret = *(unsig
0a10: 6e 65 64 20 63 68 61 72 20 2a 29 20 6c 69 73 74  ned char *) list
0a20: 2e 72 61 64 64 72 3b 0a 20 20 20 20 20 20 20 20  .raddr;.        
0a30: 7d 20 65 6c 73 65 0a 20 20 20 20 20 20 20 20 69  } else.        i
0a40: 66 20 28 6c 69 73 74 2e 72 73 69 7a 65 20 3d 3d  f (list.rsize ==
0a50: 20 73 69 7a 65 6f 66 28 73 68 6f 72 74 29 29 20   sizeof(short)) 
0a60: 7b 0a 20 20 20 20 20 20 20 20 20 20 69 72 65 74  {.          iret
0a70: 20 3d 20 2a 28 75 6e 73 69 67 6e 65 64 20 73 68   = *(unsigned sh
0a80: 6f 72 74 20 2a 29 20 6c 69 73 74 2e 72 61 64 64  ort *) list.radd
0a90: 72 3b 0a 20 20 20 20 20 20 20 20 7d 20 65 6c 73  r;.        } els
0aa0: 65 0a 20 20 20 20 20 20 20 20 69 66 20 28 6c 69  e.        if (li
0ab0: 73 74 2e 72 73 69 7a 65 20 3d 3d 20 73 69 7a 65  st.rsize == size
0ac0: 6f 66 28 69 6e 74 29 29 20 7b 0a 20 20 20 20 20  of(int)) {.     
0ad0: 20 20 20 20 20 69 72 65 74 20 3d 20 2a 28 75 6e       iret = *(un
0ae0: 73 69 67 6e 65 64 20 69 6e 74 20 2a 29 20 6c 69  signed int *) li
0af0: 73 74 2e 72 61 64 64 72 3b 0a 20 20 20 20 20 20  st.raddr;.      
0b00: 20 20 7d 20 65 6c 73 65 0a 20 20 20 20 20 20 20    } else.       
0b10: 20 69 66 20 28 6c 69 73 74 2e 72 73 69 7a 65 20   if (list.rsize 
0b20: 3d 3d 20 32 2a 73 69 7a 65 6f 66 28 5f 5f 76 61  == 2*sizeof(__va
0b30: 77 6f 72 64 29 29 20 7b 0a 20 20 20 20 20 20 20  word)) {.       
0b40: 20 20 20 6c 6c 72 65 74 20 3d 20 2a 28 6c 6f 6e     llret = *(lon
0b50: 67 20 6c 6f 6e 67 20 2a 29 20 6c 69 73 74 2e 72  g long *) list.r
0b60: 61 64 64 72 3b 0a 20 20 20 20 20 20 20 20 7d 0a  addr;.        }.
0b70: 20 20 20 20 20 20 7d 0a 20 20 20 20 7d 0a 20 20        }.    }.  
0b80: 7d 0a 7d 0a                                      }.}.