home *** CD-ROM | disk | FTP | other *** search
/ Chip: Windows 2000 Professional Resource Kit / W2KPRK.iso / apps / perl / ActivePerl.exe / data.z / XSUB.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-14  |  5.3 KB  |  158 lines

  1. #define ST(off) PL_stack_base[ax + (off)]
  2.  
  3. #ifdef CAN_PROTOTYPE
  4. #ifdef PERL_OBJECT
  5. #define XS(name) void name(CV* cv, CPerlObj* pPerl)
  6. #else
  7. #define XS(name) void name(CV* cv)
  8. #endif
  9. #else
  10. #define XS(name) void name(cv) CV* cv;
  11. #endif
  12.  
  13. #define dXSARGS                \
  14.     dSP; dMARK;            \
  15.     I32 ax = mark - PL_stack_base + 1;    \
  16.     I32 items = sp - mark
  17.  
  18. #define XSANY CvXSUBANY(cv)
  19.  
  20. #define dXSI32 I32 ix = XSANY.any_i32
  21.  
  22. #ifdef __cplusplus
  23. #  define XSINTERFACE_CVT(ret,name) ret (*name)(...)
  24. #else
  25. #  define XSINTERFACE_CVT(ret,name) ret (*name)()
  26. #endif
  27. #define dXSFUNCTION(ret)        XSINTERFACE_CVT(ret,XSFUNCTION)
  28. #define XSINTERFACE_FUNC(ret,cv,f)    ((XSINTERFACE_CVT(ret,))(f))
  29. #define XSINTERFACE_FUNC_SET(cv,f)    \
  30.         CvXSUBANY(cv).any_dptr = (void (*) _((void*)))(f)
  31.  
  32. #define XSRETURN(off)                    \
  33.     STMT_START {                    \
  34.     PL_stack_sp = PL_stack_base + ax + ((off) - 1);    \
  35.     return;                        \
  36.     } STMT_END
  37.  
  38. /* Simple macros to put new mortal values onto the stack.   */
  39. /* Typically used to return values from XS functions.       */
  40. #define XST_mIV(i,v)  (ST(i) = sv_2mortal(newSViv(v))  )
  41. #define XST_mNV(i,v)  (ST(i) = sv_2mortal(newSVnv(v))  )
  42. #define XST_mPV(i,v)  (ST(i) = sv_2mortal(newSVpv(v,0)))
  43. #define XST_mNO(i)    (ST(i) = &PL_sv_no   )
  44. #define XST_mYES(i)   (ST(i) = &PL_sv_yes  )
  45. #define XST_mUNDEF(i) (ST(i) = &PL_sv_undef)
  46.  
  47. #define XSRETURN_IV(v) STMT_START { XST_mIV(0,v);  XSRETURN(1); } STMT_END
  48. #define XSRETURN_NV(v) STMT_START { XST_mNV(0,v);  XSRETURN(1); } STMT_END
  49. #define XSRETURN_PV(v) STMT_START { XST_mPV(0,v);  XSRETURN(1); } STMT_END
  50. #define XSRETURN_NO    STMT_START { XST_mNO(0);    XSRETURN(1); } STMT_END
  51. #define XSRETURN_YES   STMT_START { XST_mYES(0);   XSRETURN(1); } STMT_END
  52. #define XSRETURN_UNDEF STMT_START { XST_mUNDEF(0); XSRETURN(1); } STMT_END
  53. #define XSRETURN_EMPTY STMT_START {                XSRETURN(0); } STMT_END
  54.  
  55. #define newXSproto(a,b,c,d)    sv_setpv((SV*)newXS(a,b,c), d)
  56.  
  57. #ifdef XS_VERSION
  58. # define XS_VERSION_BOOTCHECK \
  59.     STMT_START {                            \
  60.     SV *tmpsv; STRLEN n_a;                        \
  61.     char *vn = Nullch, *module = SvPV(ST(0),n_a);            \
  62.     if (items >= 2)     /* version supplied as bootstrap arg */    \
  63.         tmpsv = ST(1);                        \
  64.     else {                                \
  65.         /* XXX GV_ADDWARN */                    \
  66.         tmpsv = perl_get_sv(form("%s::%s", module,            \
  67.                   vn = "XS_VERSION"), FALSE);        \
  68.         if (!tmpsv || !SvOK(tmpsv))                    \
  69.         tmpsv = perl_get_sv(form("%s::%s", module,        \
  70.                       vn = "VERSION"), FALSE);        \
  71.     }                                \
  72.     if (tmpsv && (!SvOK(tmpsv) || strNE(XS_VERSION, SvPV(tmpsv, n_a))))    \
  73.         croak("%s object version %s does not match %s%s%s%s %_",    \
  74.           module, XS_VERSION,                    \
  75.           vn ? "$" : "", vn ? module : "", vn ? "::" : "",    \
  76.           vn ? vn : "bootstrap parameter", tmpsv);        \
  77.     } STMT_END
  78. #else
  79. # define XS_VERSION_BOOTCHECK
  80. #endif
  81.  
  82. #ifdef PERL_CAPI
  83. #  define VTBL_sv        get_vtbl(want_vtbl_sv)
  84. #  define VTBL_env        get_vtbl(want_vtbl_env)
  85. #  define VTBL_envelem        get_vtbl(want_vtbl_envelem)
  86. #  define VTBL_sig        get_vtbl(want_vtbl_sig)
  87. #  define VTBL_sigelem        get_vtbl(want_vtbl_sigelem)
  88. #  define VTBL_pack        get_vtbl(want_vtbl_pack)
  89. #  define VTBL_packelem        get_vtbl(want_vtbl_packelem)
  90. #  define VTBL_dbline        get_vtbl(want_vtbl_dbline)
  91. #  define VTBL_isa        get_vtbl(want_vtbl_isa)
  92. #  define VTBL_isaelem        get_vtbl(want_vtbl_isaelem)
  93. #  define VTBL_arylen        get_vtbl(want_vtbl_arylen)
  94. #  define VTBL_glob        get_vtbl(want_vtbl_glob)
  95. #  define VTBL_mglob        get_vtbl(want_vtbl_mglob)
  96. #  define VTBL_nkeys        get_vtbl(want_vtbl_nkeys)
  97. #  define VTBL_taint        get_vtbl(want_vtbl_taint)
  98. #  define VTBL_substr        get_vtbl(want_vtbl_substr)
  99. #  define VTBL_vec        get_vtbl(want_vtbl_vec)
  100. #  define VTBL_pos        get_vtbl(want_vtbl_pos)
  101. #  define VTBL_bm        get_vtbl(want_vtbl_bm)
  102. #  define VTBL_fm        get_vtbl(want_vtbl_fm)
  103. #  define VTBL_uvar        get_vtbl(want_vtbl_uvar)
  104. #  define VTBL_defelem        get_vtbl(want_vtbl_defelem)
  105. #  define VTBL_regexp        get_vtbl(want_vtbl_regexp)
  106. #  ifdef USE_LOCALE_COLLATE
  107. #    define VTBL_collxfrm    get_vtbl(want_vtbl_collxfrm)
  108. #  endif
  109. #  ifdef OVERLOAD
  110. #    define VTBL_amagic        get_vtbl(want_vtbl_amagic)
  111. #    define VTBL_amagicelem    get_vtbl(want_vtbl_amagicelem)
  112. #  endif
  113. #else
  114. #  define VTBL_sv        &vtbl_sv
  115. #  define VTBL_env        &vtbl_env
  116. #  define VTBL_envelem        &vtbl_envelem
  117. #  define VTBL_sig        &vtbl_sig
  118. #  define VTBL_sigelem        &vtbl_sigelem
  119. #  define VTBL_pack        &vtbl_pack
  120. #  define VTBL_packelem        &vtbl_packelem
  121. #  define VTBL_dbline        &vtbl_dbline
  122. #  define VTBL_isa        &vtbl_isa
  123. #  define VTBL_isaelem        &vtbl_isaelem
  124. #  define VTBL_arylen        &vtbl_arylen
  125. #  define VTBL_glob        &vtbl_glob
  126. #  define VTBL_mglob        &vtbl_mglob
  127. #  define VTBL_nkeys        &vtbl_nkeys
  128. #  define VTBL_taint        &vtbl_taint
  129. #  define VTBL_substr        &vtbl_substr
  130. #  define VTBL_vec        &vtbl_vec
  131. #  define VTBL_pos        &vtbl_pos
  132. #  define VTBL_bm        &vtbl_bm
  133. #  define VTBL_fm        &vtbl_fm
  134. #  define VTBL_uvar        &vtbl_uvar
  135. #  define VTBL_defelem        &vtbl_defelem
  136. #  define VTBL_regexp        &vtbl_regexp
  137. #  ifdef USE_LOCALE_COLLATE
  138. #    define VTBL_collxfrm    &vtbl_collxfrm
  139. #  endif
  140. #  ifdef OVERLOAD
  141. #    define VTBL_amagic        &vtbl_amagic
  142. #    define VTBL_amagicelem    &vtbl_amagicelem
  143. #  endif
  144. #endif
  145.  
  146. #ifdef PERL_OBJECT
  147. #include "objXSUB.h"
  148. #ifndef NO_XSLOCKS
  149. #ifdef WIN32
  150. #include "XSlock.h"
  151. #endif  /* WIN32 */
  152. #endif  /* NO_XSLOCKS */
  153. #else
  154. #ifdef PERL_CAPI
  155. #include "perlCAPI.h"
  156. #endif
  157. #endif    /* PERL_OBJECT */
  158.