3 * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
4 * by Larry Wall and others
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
12 * "Perilous to us all are the devices of an art deeper than we possess
13 * ourselves." --Gandalf
18 #define PERL_IN_XSUTILS_C
22 * Contributed by Spider Boardman (spider.boardman@orb.nashua.nh.us).
25 /* package attributes; */
26 void XS_attributes__warn_reserved(pTHX_ CV *cv);
27 void XS_attributes_reftype(pTHX_ CV *cv);
28 void XS_attributes__modify_attrs(pTHX_ CV *cv);
29 void XS_attributes__guess_stash(pTHX_ CV *cv);
30 void XS_attributes__fetch_attrs(pTHX_ CV *cv);
31 void XS_attributes_bootstrap(pTHX_ CV *cv);
35 * Note that only ${pkg}::bootstrap definitions should go here.
36 * This helps keep down the start-up time, which is especially
37 * relevant for users who don't invoke any features which are
38 * (partially) implemented here.
40 * The various bootstrap definitions can take care of doing
41 * package-specific newXS() calls. Since the layout of the
42 * bundled *.pm files is in a version-specific directory,
43 * version checks in these bootstrap calls are optional.
47 Perl_boot_core_xsutils(pTHX)
49 char *file = __FILE__;
51 newXS("attributes::bootstrap", XS_attributes_bootstrap, file);
57 modify_SV_attributes(pTHX_ SV *sv, SV **retlist, SV **attrlist, int numattrs)
65 for (nret = 0 ; numattrs && (attr = *attrlist++); numattrs--) {
66 name = SvPV(attr, len);
67 if ((negated = (*name == '-'))) {
77 if (strEQ(name, "assertion")) {
79 CvFLAGS((CV*)sv) &= ~CVf_ASSERTION;
81 CvFLAGS((CV*)sv) |= CVf_ASSERTION;
87 if (strEQ(name, "lvalue")) {
89 CvFLAGS((CV*)sv) &= ~CVf_LVALUE;
91 CvFLAGS((CV*)sv) |= CVf_LVALUE;
94 #endif /* defined CVf_LVALUE */
95 if (strEQ(name, "locked")) {
97 CvFLAGS((CV*)sv) &= ~CVf_LOCKED;
99 CvFLAGS((CV*)sv) |= CVf_LOCKED;
104 if (strEQ(name, "method")) {
106 CvFLAGS((CV*)sv) &= ~CVf_METHOD;
108 CvFLAGS((CV*)sv) |= CVf_METHOD;
121 if (strEQ(name, "shared")) {
123 Perl_croak(aTHX_ "A variable may not be unshared");
129 if (strEQ(name, "unique")) {
130 if (SvTYPE(sv) == SVt_PVGV) {
136 /* Hope this came from toke.c if not a GV. */
143 /* anything recognized had a 'continue' above */
153 /* package attributes; */
155 XS(XS_attributes_bootstrap)
158 char *file = __FILE__;
161 Perl_croak(aTHX_ "Usage: attributes::bootstrap $module");
163 newXSproto("attributes::_warn_reserved", XS_attributes__warn_reserved, file, "");
164 newXS("attributes::_modify_attrs", XS_attributes__modify_attrs, file);
165 newXSproto("attributes::_guess_stash", XS_attributes__guess_stash, file, "$");
166 newXSproto("attributes::_fetch_attrs", XS_attributes__fetch_attrs, file, "$");
167 newXSproto("attributes::reftype", XS_attributes_reftype, file, "$");
172 XS(XS_attributes__modify_attrs)
180 "Usage: attributes::_modify_attrs $reference, @attributes");
184 if (!(SvOK(rv) && SvROK(rv)))
188 XSRETURN(modify_SV_attributes(aTHX_ sv, &ST(0), &ST(1), items-1));
193 XS(XS_attributes__fetch_attrs)
202 "Usage: attributes::_fetch_attrs $reference");
207 if (!(SvOK(rv) && SvROK(rv)))
211 switch (SvTYPE(sv)) {
213 cvflags = CvFLAGS((CV*)sv);
214 if (cvflags & CVf_LOCKED)
215 XPUSHs(sv_2mortal(newSVpvn("locked", 6)));
217 if (cvflags & CVf_LVALUE)
218 XPUSHs(sv_2mortal(newSVpvn("lvalue", 6)));
220 if (cvflags & CVf_METHOD)
221 XPUSHs(sv_2mortal(newSVpvn("method", 6)));
222 if (GvUNIQUE(CvGV((CV*)sv)))
223 XPUSHs(sv_2mortal(newSVpvn("unique", 6)));
224 if (cvflags & CVf_ASSERTION)
225 XPUSHs(sv_2mortal(newSVpvn("assertion", 9)));
229 XPUSHs(sv_2mortal(newSVpvn("unique", 6)));
238 XS(XS_attributes__guess_stash)
245 SV * TARG = sv_newmortal();
251 "Usage: attributes::_guess_stash $reference");
256 if (!(SvOK(rv) && SvROK(rv)))
261 sv_setpv(TARG, HvNAME(SvSTASH(sv)));
262 #if 0 /* this was probably a bad idea */
263 else if (SvPADMY(sv))
264 sv_setsv(TARG, &PL_sv_no); /* unblessed lexical */
268 switch (SvTYPE(sv)) {
270 if (CvGV(sv) && isGV(CvGV(sv)) && GvSTASH(CvGV(sv)))
271 stash = GvSTASH(CvGV(sv));
272 else if (/* !CvANON(sv) && */ CvSTASH(sv))
276 if (!(SvFAKE(sv) && SvTIED_mg(sv, PERL_MAGIC_glob)))
280 if (GvGP(sv) && GvESTASH((GV*)sv))
281 stash = GvESTASH((GV*)sv);
287 sv_setpv(TARG, HvNAME(stash));
296 XS(XS_attributes_reftype)
303 SV * TARG = sv_newmortal();
309 "Usage: attributes::reftype $reference");
316 if (!(SvOK(rv) && SvROK(rv)))
319 sv_setpv(TARG, sv_reftype(sv, 0));
327 XS(XS_attributes__warn_reserved)
333 SV * TARG = sv_newmortal();
338 "Usage: attributes::_warn_reserved ()");
343 sv_setiv(TARG, ckWARN(WARN_RESERVED) != 0);