]> git.vpit.fr Git - perl/modules/VPIT-XSHelpers.git/blob - xsh/util.h
c4be169306c4c7255a4dffb99f74e4471bf39a66
[perl/modules/VPIT-XSHelpers.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 #  define XSH_ASSERT(C) PERL_DEB( \
17    ((C) ? ((void) 0)           \
18         : (Perl_croak_nocontext("Assertion %s failed: file \"" __FILE__  \
19                                  "\", line %d", STRINGIFY(C), __LINE__), \
20            (void) 0)))
21 # endif
22 #else
23 # define XSH_ASSERT(C)
24 #endif
25
26 #undef VOID2
27 #ifdef __cplusplus
28 # define VOID2(T, P) static_cast<T>(P)
29 #else
30 # define VOID2(T, P) (P)
31 #endif
32
33 #ifndef STMT_START
34 # define STMT_START do
35 #endif
36
37 #ifndef STMT_END
38 # define STMT_END while (0)
39 #endif
40
41 #ifndef dNOOP
42 # define dNOOP
43 #endif
44
45 #ifndef NOOP
46 # define NOOP
47 #endif
48
49 #if XSH_HAS_PERL(5, 13, 2)
50 # define XSH_DUP_PARAMS_TYPE       CLONE_PARAMS *
51 # define xsh_dup_params_init(P, O) ((P) = Perl_clone_params_new((O), aTHX))
52 # define xsh_dup_params_deinit(P)  Perl_clone_params_del(P)
53 # define xsh_dup_params_ptr(P)     (P)
54 #else
55 # define XSH_DUP_PARAMS_TYPE       CLONE_PARAMS
56 # define xsh_dup_params_init(P, O) \
57       ((P).stashes = newAV()); (P).flags = 0; ((P).proto_perl = (O))
58 # define xsh_dup_params_deinit(P)  SvREFCNT_dec((P).stashes)
59 # define xsh_dup_params_ptr(P)     &(P)
60 #endif
61 #define xsh_dup(S, P)     sv_dup((S), (P))
62 #define xsh_dup_inc(S, P) SvREFCNT_inc(xsh_dup((S), (P)))
63
64 #ifdef USE_ITHREADS
65 # define XSH_LOCK(M)   MUTEX_LOCK(M)
66 # define XSH_UNLOCK(M) MUTEX_UNLOCK(M)
67 #else
68 # define XSH_LOCK(M)   NOOP
69 # define XSH_UNLOCK(M) NOOP
70 #endif
71
72 #ifndef PTR2nat
73 # define PTR2nat(p) (PTRV)(p)
74 #endif
75
76 #ifndef DPTR2FPTR
77 # define DPTR2FPTR(t,p) ((t)PTR2nat(p))
78 #endif
79
80 #ifndef FPTR2DPTR
81 # define FPTR2DPTR(t,p) ((t)PTR2nat(p))
82 #endif
83
84 #endif /* XSH_UTIL_H */