Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

400 lines
14 KiB

  1. #ifndef _INC_PERL_XSUB_H
  2. #define _INC_PERL_XSUB_H 1
  3. /* first, some documentation for xsubpp-generated items */
  4. /*
  5. =for apidoc Amn|char*|CLASS
  6. Variable which is setup by C<xsubpp> to indicate the
  7. class name for a C++ XS constructor. This is always a C<char*>. See C<THIS>.
  8. =for apidoc Amn|(whatever)|RETVAL
  9. Variable which is setup by C<xsubpp> to hold the return value for an
  10. XSUB. This is always the proper type for the XSUB. See
  11. L<perlxs/"The RETVAL Variable">.
  12. =for apidoc Amn|(whatever)|THIS
  13. Variable which is setup by C<xsubpp> to designate the object in a C++
  14. XSUB. This is always the proper type for the C++ object. See C<CLASS> and
  15. L<perlxs/"Using XS With C++">.
  16. =for apidoc Amn|I32|items
  17. Variable which is setup by C<xsubpp> to indicate the number of
  18. items on the stack. See L<perlxs/"Variable-length Parameter Lists">.
  19. =for apidoc Amn|I32|ix
  20. Variable which is setup by C<xsubpp> to indicate which of an
  21. XSUB's aliases was used to invoke it. See L<perlxs/"The ALIAS: Keyword">.
  22. =for apidoc Am|SV*|ST|int ix
  23. Used to access elements on the XSUB's stack.
  24. =for apidoc AmU||XS
  25. Macro to declare an XSUB and its C parameter list. This is handled by
  26. C<xsubpp>.
  27. =for apidoc Ams||dXSARGS
  28. Sets up stack and mark pointers for an XSUB, calling dSP and dMARK. This
  29. is usually handled automatically by C<xsubpp>. Declares the C<items>
  30. variable to indicate the number of items on the stack.
  31. =for apidoc Ams||dXSI32
  32. Sets up the C<ix> variable for an XSUB which has aliases. This is usually
  33. handled automatically by C<xsubpp>.
  34. =cut
  35. */
  36. #define ST(off) PL_stack_base[ax + (off)]
  37. #if defined(__CYGWIN__) && defined(USE_DYNAMIC_LOADING)
  38. # define XS(name) __declspec(dllexport) void name(pTHXo_ CV* cv)
  39. #else
  40. # define XS(name) void name(pTHXo_ CV* cv)
  41. #endif
  42. #define dXSARGS \
  43. dSP; dMARK; \
  44. I32 ax = mark - PL_stack_base + 1; \
  45. I32 items = sp - mark
  46. #define dXSTARG SV * targ = ((PL_op->op_private & OPpENTERSUB_HASTARG) \
  47. ? PAD_SV(PL_op->op_targ) : sv_newmortal())
  48. /* Should be used before final PUSHi etc. if not in PPCODE section. */
  49. #define XSprePUSH (sp = PL_stack_base + ax - 1)
  50. #define XSANY CvXSUBANY(cv)
  51. #define dXSI32 I32 ix = XSANY.any_i32
  52. #ifdef __cplusplus
  53. # define XSINTERFACE_CVT(ret,name) ret (*name)(...)
  54. #else
  55. # define XSINTERFACE_CVT(ret,name) ret (*name)()
  56. #endif
  57. #define dXSFUNCTION(ret) XSINTERFACE_CVT(ret,XSFUNCTION)
  58. #define XSINTERFACE_FUNC(ret,cv,f) ((XSINTERFACE_CVT(ret,cv))(f))
  59. #define XSINTERFACE_FUNC_SET(cv,f) \
  60. CvXSUBANY(cv).any_dptr = (void (*) (pTHXo_ void*))(f)
  61. /* Simple macros to put new mortal values onto the stack. */
  62. /* Typically used to return values from XS functions. */
  63. /*
  64. =for apidoc Am|void|XST_mIV|int pos|IV iv
  65. Place an integer into the specified position C<pos> on the stack. The
  66. value is stored in a new mortal SV.
  67. =for apidoc Am|void|XST_mNV|int pos|NV nv
  68. Place a double into the specified position C<pos> on the stack. The value
  69. is stored in a new mortal SV.
  70. =for apidoc Am|void|XST_mPV|int pos|char* str
  71. Place a copy of a string into the specified position C<pos> on the stack.
  72. The value is stored in a new mortal SV.
  73. =for apidoc Am|void|XST_mNO|int pos
  74. Place C<&PL_sv_no> into the specified position C<pos> on the
  75. stack.
  76. =for apidoc Am|void|XST_mYES|int pos
  77. Place C<&PL_sv_yes> into the specified position C<pos> on the
  78. stack.
  79. =for apidoc Am|void|XST_mUNDEF|int pos
  80. Place C<&PL_sv_undef> into the specified position C<pos> on the
  81. stack.
  82. =for apidoc Am|void|XSRETURN|int nitems
  83. Return from XSUB, indicating number of items on the stack. This is usually
  84. handled by C<xsubpp>.
  85. =for apidoc Am|void|XSRETURN_IV|IV iv
  86. Return an integer from an XSUB immediately. Uses C<XST_mIV>.
  87. =for apidoc Am|void|XSRETURN_NV|NV nv
  88. Return an double from an XSUB immediately. Uses C<XST_mNV>.
  89. =for apidoc Am|void|XSRETURN_PV|char* str
  90. Return a copy of a string from an XSUB immediately. Uses C<XST_mPV>.
  91. =for apidoc Ams||XSRETURN_NO
  92. Return C<&PL_sv_no> from an XSUB immediately. Uses C<XST_mNO>.
  93. =for apidoc Ams||XSRETURN_YES
  94. Return C<&PL_sv_yes> from an XSUB immediately. Uses C<XST_mYES>.
  95. =for apidoc Ams||XSRETURN_UNDEF
  96. Return C<&PL_sv_undef> from an XSUB immediately. Uses C<XST_mUNDEF>.
  97. =for apidoc Ams||XSRETURN_EMPTY
  98. Return an empty list from an XSUB immediately.
  99. =for apidoc AmU||newXSproto
  100. Used by C<xsubpp> to hook up XSUBs as Perl subs. Adds Perl prototypes to
  101. the subs.
  102. =for apidoc AmU||XS_VERSION
  103. The version identifier for an XS module. This is usually
  104. handled automatically by C<ExtUtils::MakeMaker>. See C<XS_VERSION_BOOTCHECK>.
  105. =for apidoc Ams||XS_VERSION_BOOTCHECK
  106. Macro to verify that a PM module's $VERSION variable matches the XS
  107. module's C<XS_VERSION> variable. This is usually handled automatically by
  108. C<xsubpp>. See L<perlxs/"The VERSIONCHECK: Keyword">.
  109. =cut
  110. */
  111. #define XST_mIV(i,v) (ST(i) = sv_2mortal(newSViv(v)) )
  112. #define XST_mNV(i,v) (ST(i) = sv_2mortal(newSVnv(v)) )
  113. #define XST_mPV(i,v) (ST(i) = sv_2mortal(newSVpv(v,0)))
  114. #define XST_mPVN(i,v,n) (ST(i) = sv_2mortal(newSVpvn(v,n)))
  115. #define XST_mNO(i) (ST(i) = &PL_sv_no )
  116. #define XST_mYES(i) (ST(i) = &PL_sv_yes )
  117. #define XST_mUNDEF(i) (ST(i) = &PL_sv_undef)
  118. #define XSRETURN(off) \
  119. STMT_START { \
  120. PL_stack_sp = PL_stack_base + ax + ((off) - 1); \
  121. return; \
  122. } STMT_END
  123. #define XSRETURN_IV(v) STMT_START { XST_mIV(0,v); XSRETURN(1); } STMT_END
  124. #define XSRETURN_NV(v) STMT_START { XST_mNV(0,v); XSRETURN(1); } STMT_END
  125. #define XSRETURN_PV(v) STMT_START { XST_mPV(0,v); XSRETURN(1); } STMT_END
  126. #define XSRETURN_PVN(v,n) STMT_START { XST_mPVN(0,v,n); XSRETURN(1); } STMT_END
  127. #define XSRETURN_NO STMT_START { XST_mNO(0); XSRETURN(1); } STMT_END
  128. #define XSRETURN_YES STMT_START { XST_mYES(0); XSRETURN(1); } STMT_END
  129. #define XSRETURN_UNDEF STMT_START { XST_mUNDEF(0); XSRETURN(1); } STMT_END
  130. #define XSRETURN_EMPTY STMT_START { XSRETURN(0); } STMT_END
  131. #define newXSproto(a,b,c,d) sv_setpv((SV*)newXS(a,b,c), d)
  132. #ifdef XS_VERSION
  133. # define XS_VERSION_BOOTCHECK \
  134. STMT_START { \
  135. SV *tmpsv; STRLEN n_a; \
  136. char *vn = Nullch, *module = SvPV(ST(0),n_a); \
  137. if (items >= 2) /* version supplied as bootstrap arg */ \
  138. tmpsv = ST(1); \
  139. else { \
  140. /* XXX GV_ADDWARN */ \
  141. tmpsv = get_sv(Perl_form(aTHX_ "%s::%s", module, \
  142. vn = "XS_VERSION"), FALSE); \
  143. if (!tmpsv || !SvOK(tmpsv)) \
  144. tmpsv = get_sv(Perl_form(aTHX_ "%s::%s", module, \
  145. vn = "VERSION"), FALSE); \
  146. } \
  147. if (tmpsv && (!SvOK(tmpsv) || strNE(XS_VERSION, SvPV(tmpsv, n_a)))) \
  148. Perl_croak(aTHX_ "%s object version %s does not match %s%s%s%s %"SVf,\
  149. module, XS_VERSION, \
  150. vn ? "$" : "", vn ? module : "", vn ? "::" : "", \
  151. vn ? vn : "bootstrap parameter", tmpsv); \
  152. } STMT_END
  153. #else
  154. # define XS_VERSION_BOOTCHECK
  155. #endif
  156. #if 1 /* for compatibility */
  157. # define VTBL_sv &PL_vtbl_sv
  158. # define VTBL_env &PL_vtbl_env
  159. # define VTBL_envelem &PL_vtbl_envelem
  160. # define VTBL_sig &PL_vtbl_sig
  161. # define VTBL_sigelem &PL_vtbl_sigelem
  162. # define VTBL_pack &PL_vtbl_pack
  163. # define VTBL_packelem &PL_vtbl_packelem
  164. # define VTBL_dbline &PL_vtbl_dbline
  165. # define VTBL_isa &PL_vtbl_isa
  166. # define VTBL_isaelem &PL_vtbl_isaelem
  167. # define VTBL_arylen &PL_vtbl_arylen
  168. # define VTBL_glob &PL_vtbl_glob
  169. # define VTBL_mglob &PL_vtbl_mglob
  170. # define VTBL_nkeys &PL_vtbl_nkeys
  171. # define VTBL_taint &PL_vtbl_taint
  172. # define VTBL_substr &PL_vtbl_substr
  173. # define VTBL_vec &PL_vtbl_vec
  174. # define VTBL_pos &PL_vtbl_pos
  175. # define VTBL_bm &PL_vtbl_bm
  176. # define VTBL_fm &PL_vtbl_fm
  177. # define VTBL_uvar &PL_vtbl_uvar
  178. # define VTBL_defelem &PL_vtbl_defelem
  179. # define VTBL_regexp &PL_vtbl_regexp
  180. # define VTBL_regdata &PL_vtbl_regdata
  181. # define VTBL_regdatum &PL_vtbl_regdatum
  182. # ifdef USE_LOCALE_COLLATE
  183. # define VTBL_collxfrm &PL_vtbl_collxfrm
  184. # endif
  185. # define VTBL_amagic &PL_vtbl_amagic
  186. # define VTBL_amagicelem &PL_vtbl_amagicelem
  187. #endif
  188. #include "perlapi.h"
  189. #include "objXSUB.h"
  190. #if defined(PERL_IMPLICIT_CONTEXT) && !defined(PERL_NO_GET_CONTEXT) && !defined(PERL_CORE)
  191. # undef aTHX
  192. # undef aTHX_
  193. # define aTHX PERL_GET_THX
  194. # define aTHX_ aTHX,
  195. #endif
  196. #if (defined(PERL_CAPI) || defined(PERL_IMPLICIT_SYS)) && !defined(PERL_CORE)
  197. # ifndef NO_XSLOCKS
  198. # undef closedir
  199. # undef opendir
  200. # undef stdin
  201. # undef stdout
  202. # undef stderr
  203. # undef feof
  204. # undef ferror
  205. # undef fgetpos
  206. # undef ioctl
  207. # undef getlogin
  208. # undef setjmp
  209. # undef getc
  210. # undef ungetc
  211. # undef fileno
  212. # define mkdir PerlDir_mkdir
  213. # define chdir PerlDir_chdir
  214. # define rmdir PerlDir_rmdir
  215. # define closedir PerlDir_close
  216. # define opendir PerlDir_open
  217. # define readdir PerlDir_read
  218. # define rewinddir PerlDir_rewind
  219. # define seekdir PerlDir_seek
  220. # define telldir PerlDir_tell
  221. # define putenv PerlEnv_putenv
  222. # define getenv PerlEnv_getenv
  223. # define uname PerlEnv_uname
  224. # define stdin PerlIO_stdin()
  225. # define stdout PerlIO_stdout()
  226. # define stderr PerlIO_stderr()
  227. # define fopen PerlIO_open
  228. # define fclose PerlIO_close
  229. # define feof PerlIO_eof
  230. # define ferror PerlIO_error
  231. # define fclearerr PerlIO_clearerr
  232. # define getc PerlIO_getc
  233. # define fputc(c, f) PerlIO_putc(f,c)
  234. # define fputs(s, f) PerlIO_puts(f,s)
  235. # define fflush PerlIO_flush
  236. # define ungetc(c, f) PerlIO_ungetc((f),(c))
  237. # define fileno PerlIO_fileno
  238. # define fdopen PerlIO_fdopen
  239. # define freopen PerlIO_reopen
  240. # define fread(b,s,c,f) PerlIO_read((f),(b),(s*c))
  241. # define fwrite(b,s,c,f) PerlIO_write((f),(b),(s*c))
  242. # define setbuf PerlIO_setbuf
  243. # define setvbuf PerlIO_setvbuf
  244. # define setlinebuf PerlIO_setlinebuf
  245. # define stdoutf PerlIO_stdoutf
  246. # define vfprintf PerlIO_vprintf
  247. # define ftell PerlIO_tell
  248. # define fseek PerlIO_seek
  249. # define fgetpos PerlIO_getpos
  250. # define fsetpos PerlIO_setpos
  251. # define frewind PerlIO_rewind
  252. # define tmpfile PerlIO_tmpfile
  253. # define access PerlLIO_access
  254. # define chmod PerlLIO_chmod
  255. # define chsize PerlLIO_chsize
  256. # define close PerlLIO_close
  257. # define dup PerlLIO_dup
  258. # define dup2 PerlLIO_dup2
  259. # define flock PerlLIO_flock
  260. # define fstat PerlLIO_fstat
  261. # define ioctl PerlLIO_ioctl
  262. # define isatty PerlLIO_isatty
  263. # define link PerlLIO_link
  264. # define lseek PerlLIO_lseek
  265. # define lstat PerlLIO_lstat
  266. # define mktemp PerlLIO_mktemp
  267. # define open PerlLIO_open
  268. # define read PerlLIO_read
  269. # define rename PerlLIO_rename
  270. # define setmode PerlLIO_setmode
  271. # define stat(buf,sb) PerlLIO_stat(buf,sb)
  272. # define tmpnam PerlLIO_tmpnam
  273. # define umask PerlLIO_umask
  274. # define unlink PerlLIO_unlink
  275. # define utime PerlLIO_utime
  276. # define write PerlLIO_write
  277. # define malloc PerlMem_malloc
  278. # define realloc PerlMem_realloc
  279. # define free PerlMem_free
  280. # define abort PerlProc_abort
  281. # define exit PerlProc_exit
  282. # define _exit PerlProc__exit
  283. # define execl PerlProc_execl
  284. # define execv PerlProc_execv
  285. # define execvp PerlProc_execvp
  286. # define getuid PerlProc_getuid
  287. # define geteuid PerlProc_geteuid
  288. # define getgid PerlProc_getgid
  289. # define getegid PerlProc_getegid
  290. # define getlogin PerlProc_getlogin
  291. # define kill PerlProc_kill
  292. # define killpg PerlProc_killpg
  293. # define pause PerlProc_pause
  294. # define popen PerlProc_popen
  295. # define pclose PerlProc_pclose
  296. # define pipe PerlProc_pipe
  297. # define setuid PerlProc_setuid
  298. # define setgid PerlProc_setgid
  299. # define sleep PerlProc_sleep
  300. # define times PerlProc_times
  301. # define wait PerlProc_wait
  302. # define setjmp PerlProc_setjmp
  303. # define longjmp PerlProc_longjmp
  304. # define signal PerlProc_signal
  305. # define getpid PerlProc_getpid
  306. # define htonl PerlSock_htonl
  307. # define htons PerlSock_htons
  308. # define ntohl PerlSock_ntohl
  309. # define ntohs PerlSock_ntohs
  310. # define accept PerlSock_accept
  311. # define bind PerlSock_bind
  312. # define connect PerlSock_connect
  313. # define endhostent PerlSock_endhostent
  314. # define endnetent PerlSock_endnetent
  315. # define endprotoent PerlSock_endprotoent
  316. # define endservent PerlSock_endservent
  317. # define gethostbyaddr PerlSock_gethostbyaddr
  318. # define gethostbyname PerlSock_gethostbyname
  319. # define gethostent PerlSock_gethostent
  320. # define gethostname PerlSock_gethostname
  321. # define getnetbyaddr PerlSock_getnetbyaddr
  322. # define getnetbyname PerlSock_getnetbyname
  323. # define getnetent PerlSock_getnetent
  324. # define getpeername PerlSock_getpeername
  325. # define getprotobyname PerlSock_getprotobyname
  326. # define getprotobynumber PerlSock_getprotobynumber
  327. # define getprotoent PerlSock_getprotoent
  328. # define getservbyname PerlSock_getservbyname
  329. # define getservbyport PerlSock_getservbyport
  330. # define getservent PerlSock_getservent
  331. # define getsockname PerlSock_getsockname
  332. # define getsockopt PerlSock_getsockopt
  333. # define inet_addr PerlSock_inet_addr
  334. # define inet_ntoa PerlSock_inet_ntoa
  335. # define listen PerlSock_listen
  336. # define recv PerlSock_recv
  337. # define recvfrom PerlSock_recvfrom
  338. # define select PerlSock_select
  339. # define send PerlSock_send
  340. # define sendto PerlSock_sendto
  341. # define sethostent PerlSock_sethostent
  342. # define setnetent PerlSock_setnetent
  343. # define setprotoent PerlSock_setprotoent
  344. # define setservent PerlSock_setservent
  345. # define setsockopt PerlSock_setsockopt
  346. # define shutdown PerlSock_shutdown
  347. # define socket PerlSock_socket
  348. # define socketpair PerlSock_socketpair
  349. # endif /* NO_XSLOCKS */
  350. #endif /* PERL_CAPI */
  351. #endif /* _INC_PERL_XSUB_H */ /* include guard */