1 #ifndef XSH_OPS_H
2 #define XSH_OPS_H 1
3 
4 #include "caps.h" /* XSH_HAS_PERL() */
5 #include "util.h" /* NOOP */
6 
7 #ifdef XSH_THREADS_H
8 # error threads.h must be loaded at the very end
9 #endif
10 
11 #ifndef XSH_THREADS_GLOBAL_SETUP
12 # define XSH_THREADS_GLOBAL_SETUP 1
13 #endif
14 
15 #ifndef XSH_THREADS_GLOBAL_TEARDOWN
16 # define XSH_THREADS_GLOBAL_TEARDOWN 1
17 #endif
18 
19 #ifndef OpSIBLING
20 # ifdef OP_SIBLING
21 #  define OpSIBLING(O) OP_SIBLING(O)
22 # else
23 #  define OpSIBLING(O) ((O)->op_sibling)
24 # endif
25 #endif
26 
27 #ifndef OpMAYBESIB_set
28 # define OpMAYBESIB_set(O, S, P) ((O)->op_sibling = (S))
29 #endif
30 
31 #ifndef OP_NAME
32 # define OP_NAME(O) (PL_op_name[(O)->op_type])
33 #endif
34 
35 #ifndef OP_CLASS
36 # define OP_CLASS(O) (PL_opargs[(O)->op_type] & OA_CLASS_MASK)
37 #endif
38 
39 #if defined(OP_CHECK_MUTEX_LOCK) && defined(OP_CHECK_MUTEX_UNLOCK)
40 # define XSH_CHECK_LOCK   OP_CHECK_MUTEX_LOCK
41 # define XSH_CHECK_UNLOCK OP_CHECK_MUTEX_UNLOCK
42 #elif XSH_HAS_PERL(5, 9, 3)
43 # define XSH_CHECK_LOCK   OP_REFCNT_LOCK
44 # define XSH_CHECK_UNLOCK OP_REFCNT_UNLOCK
45 #else
46 /* Before perl 5.9.3, da_ck_*() calls are already protected by the XSH_LOADED
47  * mutex, which falls back to the OP_REFCNT mutex. Make sure we don't lock it
48  * twice. */
49 # define XSH_CHECK_LOCK   NOOP
50 # define XSH_CHECK_UNLOCK NOOP
51 #endif
52 
53 typedef OP *(*xsh_check_t)(pTHX_ OP *);
54 
55 #ifdef wrap_op_checker
56 
57 # define xsh_ck_replace(T, NC, OCP) wrap_op_checker((T), (NC), (OCP))
58 
59 #else
60 
xsh_ck_replace(pTHX_ OPCODE type,xsh_check_t new_ck,xsh_check_t * old_ck_p)61 static void xsh_ck_replace(pTHX_ OPCODE type, xsh_check_t new_ck, xsh_check_t *old_ck_p) {
62 #define xsh_ck_replace(T, NC, OCP) xsh_ck_replace(aTHX_ (T), (NC), (OCP))
63  XSH_CHECK_LOCK;
64  if (!*old_ck_p) {
65   *old_ck_p      = PL_check[type];
66   PL_check[type] = new_ck;
67  }
68  XSH_CHECK_UNLOCK;
69 }
70 
71 #endif
72 
xsh_ck_restore(pTHX_ OPCODE type,xsh_check_t * old_ck_p)73 static void xsh_ck_restore(pTHX_ OPCODE type, xsh_check_t *old_ck_p) {
74 #define xsh_ck_restore(T, OCP) xsh_ck_restore(aTHX_ (T), (OCP))
75  XSH_CHECK_LOCK;
76  if (*old_ck_p) {
77   PL_check[type] = *old_ck_p;
78   *old_ck_p      = 0;
79  }
80  XSH_CHECK_UNLOCK;
81 }
82 
83 #endif /* XSH_OPS_H */
84