]> git.vpit.fr Git - perl/modules/Scope-Upper.git/blob - xsh/util.h
2e4009212e9567eee0e31b3110bf64efeffb35e6
[perl/modules/Scope-Upper.git] / xsh / util.h
1 #ifndef XSH_UTIL_H
2 #define XSH_UTIL_H 1
3
4 #include "caps.h" /* XSH_HAS_PERL() */
5
6 #ifndef XSH_PACKAGE
7 # error XSH_PACKAGE must be defined
8 #endif
9
10 #define XSH_PACKAGE_LEN (sizeof(XSH_PACKAGE)-1)
11
12 #ifdef DEBUGGING
13 # if XSH_HAS_PERL(5, 8, 9) || XSH_HAS_PERL(5, 9, 3)
14 #  define XSH_ASSERT(C) assert(C)
15 # else
16 #  ifdef PERL_DEB
17 #   define XSH_DEB(X) PERL_DEB(X)
18 #  else
19 #   define XSH_DEB(X) (X)
20 #  endif
21 #  define XSH_ASSERT(C) XSH_DEB( \
22    ((C) ? ((void) 0)           \
23         : (Perl_croak_nocontext("Assertion %s failed: file \"" __FILE__  \
24                                  "\", line %d", STRINGIFY(C), __LINE__), \
25            (void) 0)))
26 # endif
27 #else
28 # define XSH_ASSERT(C)
29 #endif
30
31 #undef VOID2
32 #ifdef __cplusplus
33 # define VOID2(T, P) static_cast<T>(P)
34 #else
35 # define VOID2(T, P) (P)
36 #endif
37
38 #ifndef STMT_START
39 # define STMT_START do
40 #endif
41
42 #ifndef STMT_END
43 # define STMT_END while (0)
44 #endif
45
46 #ifndef dNOOP
47 # define dNOOP
48 #endif
49
50 #ifndef NOOP
51 # define NOOP
52 #endif
53
54 #if XSH_HAS_PERL(5, 13, 2)
55 # define XSH_DUP_PARAMS_TYPE       CLONE_PARAMS *
56 # define xsh_dup_params_init(P, O) ((P) = Perl_clone_params_new((O), aTHX))
57 # define xsh_dup_params_deinit(P)  Perl_clone_params_del(P)
58 # define xsh_dup_params_ptr(P)     (P)
59 #else
60 # define XSH_DUP_PARAMS_TYPE       CLONE_PARAMS
61 # define xsh_dup_params_init(P, O) \
62       ((P).stashes = newAV()); (P).flags = 0; ((P).proto_perl = (O))
63 # define xsh_dup_params_deinit(P)  SvREFCNT_dec((P).stashes)
64 # define xsh_dup_params_ptr(P)     &(P)
65 #endif
66 #define xsh_dup(S, P)     sv_dup((S), (P))
67 #define xsh_dup_inc(S, P) SvREFCNT_inc(xsh_dup((S), (P)))
68
69 /* Context for PerlMemShared_*() functions */
70 #ifdef PERL_IMPLICIT_SYS
71 # define pPMS  pTHX
72 # define pPMS_ pTHX_
73 # define aPMS  aTHX
74 # define aPMS_ aTHX_
75 #else
76 # define pPMS  void
77 # define pPMS_
78 # define aPMS
79 # define aPMS_
80 #endif
81
82 #ifdef USE_ITHREADS
83 # define XSH_LOCK(M)   MUTEX_LOCK(M)
84 # define XSH_UNLOCK(M) MUTEX_UNLOCK(M)
85 #else
86 # define XSH_LOCK(M)   NOOP
87 # define XSH_UNLOCK(M) NOOP
88 #endif
89
90 #ifndef PTR2nat
91 # define PTR2nat(p) (PTRV)(p)
92 #endif
93
94 #ifndef DPTR2FPTR
95 # define DPTR2FPTR(t,p) ((t)PTR2nat(p))
96 #endif
97
98 #ifndef FPTR2DPTR
99 # define FPTR2DPTR(t,p) ((t)PTR2nat(p))
100 #endif
101
102 #endif /* XSH_UTIL_H */