X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2Findirect.git;a=blobdiff_plain;f=xsh%2Fops.h;fp=xsh%2Fops.h;h=2e3c06c3a66ef91c49abd65d8fec93d083529131;hp=0000000000000000000000000000000000000000;hb=7b9a8ae944bb32360e3a8807ec6cb05376fd4183;hpb=dac575f9b1194a2f6fdec8b07b27bac62ecbe30c diff --git a/xsh/ops.h b/xsh/ops.h new file mode 100644 index 0000000..2e3c06c --- /dev/null +++ b/xsh/ops.h @@ -0,0 +1,83 @@ +#ifndef XSH_OPS_H +#define XSH_OPS_H 1 + +#include "caps.h" /* XSH_HAS_PERL() */ +#include "util.h" /* NOOP */ + +#ifdef XSH_THREADS_H +# error threads.h must be loaded at the very end +#endif + +#ifndef XSH_THREADS_GLOBAL_SETUP +# define XSH_THREADS_GLOBAL_SETUP 1 +#endif + +#ifndef XSH_THREADS_GLOBAL_TEARDOWN +# define XSH_THREADS_GLOBAL_TEARDOWN 1 +#endif + +#ifndef OpSIBLING +# ifdef OP_SIBLING +# define OpSIBLING(O) OP_SIBLING(O) +# else +# define OpSIBLING(O) ((O)->op_sibling) +# endif +#endif + +#ifndef OpMAYBESIB_set +# define OpMAYBESIB_set(O, S, P) ((O)->op_sibling = (S)) +#endif + +#ifndef OP_NAME +# define OP_NAME(O) (PL_op_name[(O)->op_type]) +#endif + +#ifndef OP_CLASS +# define OP_CLASS(O) (PL_opargs[(O)->op_type] & OA_CLASS_MASK) +#endif + +#if defined(OP_CHECK_MUTEX_LOCK) && defined(OP_CHECK_MUTEX_UNLOCK) +# define XSH_CHECK_LOCK OP_CHECK_MUTEX_LOCK +# define XSH_CHECK_UNLOCK OP_CHECK_MUTEX_UNLOCK +#elif XSH_HAS_PERL(5, 9, 3) +# define XSH_CHECK_LOCK OP_REFCNT_LOCK +# define XSH_CHECK_UNLOCK OP_REFCNT_UNLOCK +#else +/* Before perl 5.9.3, da_ck_*() calls are already protected by the XSH_LOADED + * mutex, which falls back to the OP_REFCNT mutex. Make sure we don't lock it + * twice. */ +# define XSH_CHECK_LOCK NOOP +# define XSH_CHECK_UNLOCK NOOP +#endif + +typedef OP *(*xsh_check_t)(pTHX_ OP *); + +#ifdef wrap_op_checker + +# define xsh_ck_replace(T, NC, OCP) wrap_op_checker((T), (NC), (OCP)) + +#else + +static void xsh_ck_replace(pTHX_ OPCODE type, xsh_check_t new_ck, xsh_check_t *old_ck_p) { +#define xsh_ck_replace(T, NC, OCP) xsh_ck_replace(aTHX_ (T), (NC), (OCP)) + XSH_CHECK_LOCK; + if (!*old_ck_p) { + *old_ck_p = PL_check[type]; + PL_check[type] = new_ck; + } + XSH_CHECK_UNLOCK; +} + +#endif + +static void xsh_ck_restore(pTHX_ OPCODE type, xsh_check_t *old_ck_p) { +#define xsh_ck_restore(T, OCP) xsh_ck_restore(aTHX_ (T), (OCP)) + XSH_CHECK_LOCK; + if (*old_ck_p) { + PL_check[type] = *old_ck_p; + *old_ck_p = 0; + } + XSH_CHECK_UNLOCK; +} + +#endif /* XSH_OPS_H */