/
GlobalPhase.xs
83 lines (73 loc) · 2.05 KB
/
GlobalPhase.xs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
*
* Copyright (c) 2018, Nicolas R.
*
* This is free software; you can redistribute it and/or modify it under the
* same terms as Perl itself.
*
*/
#include <EXTERN.h>
#include <perl.h>
#include <XSUB.h>
#include <embed.h>
#if PERL_REVISION >= 5 && PERL_VERSION >= 10
# define CAN_USE_IX_FOR_PERL_PHASE 1
#else
# define CAN_USE_IX_FOR_PERL_PHASE 0
#endif
MODULE = Check__GlobalPhase PACKAGE = Check::GlobalPhase
SV*
in_global_phase_construct()
ALIAS:
in_global_phase_start = 1
in_global_phase_check = 2
in_global_phase_init = 3
in_global_phase_run = 4
in_global_phase_end = 5
in_global_phase_destruct = 6
PPCODE:
{
/* using ix when we can -- probably most/all versions? */
#if CAN_USE_IX_FOR_PERL_PHASE
int phase = ix;
#else
int phase = PERL_PHASE_CONSTRUCT;
if ( ix == 1 ) {
phase = PERL_PHASE_START;
} else if ( ix == 2 ) {
phase = PERL_PHASE_CHECK;
} else if ( ix == 3 ) {
phase = PERL_PHASE_INIT;
} else if ( ix == 4 ) {
phase = PERL_PHASE_RUN;
} else if ( ix == 5 ) {
phase = PERL_PHASE_END;
} else if ( ix == 6 ) {
phase = PERL_PHASE_DESTRUCT;
}
#endif
if ( PL_phase == phase ) {
XSRETURN_YES;
} else {
XSRETURN_NO;
}
}
SV*
current_phase()
PPCODE:
{
XPUSHs(newSViv(PL_phase));
}
BOOT:
{
HV *stash;
stash = gv_stashpvn("Check::GlobalPhase", 18, TRUE);
newCONSTSUB(stash, "_loaded", &PL_sv_yes );
newCONSTSUB(stash, "PERL_PHASE_CONSTRUCT", newSViv(PERL_PHASE_CONSTRUCT) );
newCONSTSUB(stash, "PERL_PHASE_START", newSViv(PERL_PHASE_START) );
newCONSTSUB(stash, "PERL_PHASE_CHECK", newSViv(PERL_PHASE_CHECK) );
newCONSTSUB(stash, "PERL_PHASE_INIT", newSViv(PERL_PHASE_INIT) );
newCONSTSUB(stash, "PERL_PHASE_RUN", newSViv(PERL_PHASE_RUN) );
newCONSTSUB(stash, "PERL_PHASE_END", newSViv(PERL_PHASE_END) );
newCONSTSUB(stash, "PERL_PHASE_DESTRUCT", newSViv(PERL_PHASE_DESTRUCT) );
}