forked from moose/Moose
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Moose.xs
102 lines (81 loc) · 1.71 KB
/
Moose.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"
#ifndef MGf_COPY
# define MGf_COPY 0
#endif
#ifndef MGf_DUP
# define MGf_DUP 0
#endif
#ifndef MGf_LOCAL
# define MGf_LOCAL 0
#endif
STATIC int unset_export_flag (pTHX_ SV *sv, MAGIC *mg);
STATIC MGVTBL export_flag_vtbl = {
NULL, /* get */
unset_export_flag, /* set */
NULL, /* len */
NULL, /* clear */
NULL, /* free */
#if MGf_COPY
NULL, /* copy */
#endif
#if MGf_DUP
NULL, /* dup */
#endif
#if MGf_LOCAL
NULL, /* local */
#endif
};
STATIC bool
export_flag_is_set (pTHX_ SV *sv)
{
MAGIC *mg, *moremagic;
if (SvTYPE(SvRV(sv)) != SVt_PVGV) {
return 0;
}
for (mg = SvMAGIC(SvRV(sv)); mg; mg = moremagic) {
moremagic = mg->mg_moremagic;
if (mg->mg_type == PERL_MAGIC_ext && mg->mg_virtual == &export_flag_vtbl) {
break;
}
}
return !!mg;
}
STATIC int
unset_export_flag (pTHX_ SV *sv, MAGIC *mymg)
{
MAGIC *mg, *prevmagic = NULL, *moremagic = NULL;
for (mg = SvMAGIC(sv); mg; prevmagic = mg, mg = moremagic) {
moremagic = mg->mg_moremagic;
if (mg == mymg) {
break;
}
}
if (!mg) {
return 0;
}
if (prevmagic) {
prevmagic->mg_moremagic = moremagic;
}
else {
SvMAGIC_set(sv, moremagic);
}
mg->mg_moremagic = NULL;
Safefree (mg);
return 0;
}
MODULE = Moose PACKAGE = Moose::Exporter
void
_flag_as_reexport (SV *sv)
PROTOTYPE: \*
CODE:
sv_magicext(SvRV(sv), NULL, PERL_MAGIC_ext, &export_flag_vtbl, NULL, 0);
bool
_export_is_flagged (SV *sv)
PROTOTYPE: \*
CODE:
RETVAL = export_flag_is_set(aTHX_ sv);
OUTPUT:
RETVAL