3 * Copyright (c) 1999-2002, Larry Wall
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
11 * "Perilous to us all are the devices of an art deeper than we possess
12 * ourselves." --Gandalf
17 #define PERL_IN_XSUTILS_C
21 * Contributed by Spider Boardman (spider.boardman@orb.nashua.nh.us).
24 /* package attributes; */
25 void XS_attributes__warn_reserved(pTHX_ CV *cv);
26 void XS_attributes_reftype(pTHX_ CV *cv);
27 void XS_attributes__modify_attrs(pTHX_ CV *cv);
28 void XS_attributes__guess_stash(pTHX_ CV *cv);
29 void XS_attributes__fetch_attrs(pTHX_ CV *cv);
30 void XS_attributes_bootstrap(pTHX_ CV *cv);
34 * Note that only ${pkg}::bootstrap definitions should go here.
35 * This helps keep down the start-up time, which is especially
36 * relevant for users who don't invoke any features which are
37 * (partially) implemented here.
39 * The various bootstrap definitions can take care of doing
40 * package-specific newXS() calls. Since the layout of the
41 * bundled *.pm files is in a version-specific directory,
42 * version checks in these bootstrap calls are optional.
46 Perl_boot_core_xsutils(pTHX)
48 char *file = __FILE__;
50 newXS("attributes::bootstrap", XS_attributes_bootstrap, file);
56 modify_SV_attributes(pTHX_ SV *sv, SV **retlist, SV **attrlist, int numattrs)
64 for (nret = 0 ; numattrs && (attr = *attrlist++); numattrs--) {
65 name = SvPV(attr, len);
66 if ((negated = (*name == '-'))) {
77 if (strEQ(name, "lvalue")) {
79 CvFLAGS((CV*)sv) &= ~CVf_LVALUE;
81 CvFLAGS((CV*)sv) |= CVf_LVALUE;
84 #endif /* defined CVf_LVALUE */
85 if (strEQ(name, "locked")) {
87 CvFLAGS((CV*)sv) &= ~CVf_LOCKED;
89 CvFLAGS((CV*)sv) |= CVf_LOCKED;
94 if (strEQ(name, "method")) {
96 CvFLAGS((CV*)sv) &= ~CVf_METHOD;
98 CvFLAGS((CV*)sv) |= CVf_METHOD;
103 if (strEQ(name, "unique")) {
105 GvUNIQUE_off(CvGV((CV*)sv));
107 GvUNIQUE_on(CvGV((CV*)sv));
120 if (strEQ(name, "shared")) {
122 Perl_croak(aTHX_ "A variable may not be unshared");
128 if (strEQ(name, "unique")) {
129 if (SvTYPE(sv) == SVt_PVGV) {
135 /* Hope this came from toke.c if not a GV. */
142 /* anything recognized had a 'continue' above */
152 /* package attributes; */
154 XS(XS_attributes_bootstrap)
157 char *file = __FILE__;
160 Perl_croak(aTHX_ "Usage: attributes::bootstrap $module");
162 newXSproto("attributes::_warn_reserved", XS_attributes__warn_reserved, file, "");
163 newXS("attributes::_modify_attrs", XS_attributes__modify_attrs, file);
164 newXSproto("attributes::_guess_stash", XS_attributes__guess_stash, file, "$");
165 newXSproto("attributes::_fetch_attrs", XS_attributes__fetch_attrs, file, "$");
166 newXSproto("attributes::reftype", XS_attributes_reftype, file, "$");
171 XS(XS_attributes__modify_attrs)
179 "Usage: attributes::_modify_attrs $reference, @attributes");
183 if (!(SvOK(rv) && SvROK(rv)))
187 XSRETURN(modify_SV_attributes(aTHX_ sv, &ST(0), &ST(1), items-1));
192 XS(XS_attributes__fetch_attrs)
201 "Usage: attributes::_fetch_attrs $reference");
206 if (!(SvOK(rv) && SvROK(rv)))
210 switch (SvTYPE(sv)) {
212 cvflags = CvFLAGS((CV*)sv);
213 if (cvflags & CVf_LOCKED)
214 XPUSHs(sv_2mortal(newSVpvn("locked", 6)));
216 if (cvflags & CVf_LVALUE)
217 XPUSHs(sv_2mortal(newSVpvn("lvalue", 6)));
219 if (cvflags & CVf_METHOD)
220 XPUSHs(sv_2mortal(newSVpvn("method", 6)));
221 if (GvUNIQUE(CvGV((CV*)sv)))
222 XPUSHs(sv_2mortal(newSVpvn("unique", 6)));
226 XPUSHs(sv_2mortal(newSVpvn("unique", 6)));
235 XS(XS_attributes__guess_stash)
242 SV * TARG = sv_newmortal();
248 "Usage: attributes::_guess_stash $reference");
253 if (!(SvOK(rv) && SvROK(rv)))
258 sv_setpv(TARG, HvNAME(SvSTASH(sv)));
259 #if 0 /* this was probably a bad idea */
260 else if (SvPADMY(sv))
261 sv_setsv(TARG, &PL_sv_no); /* unblessed lexical */
265 switch (SvTYPE(sv)) {
267 if (CvGV(sv) && isGV(CvGV(sv)) && GvSTASH(CvGV(sv)))
268 stash = GvSTASH(CvGV(sv));
269 else if (/* !CvANON(sv) && */ CvSTASH(sv))
273 if (!(SvFAKE(sv) && SvTIED_mg(sv, PERL_MAGIC_glob)))
277 if (GvGP(sv) && GvESTASH((GV*)sv))
278 stash = GvESTASH((GV*)sv);
284 sv_setpv(TARG, HvNAME(stash));
293 XS(XS_attributes_reftype)
300 SV * TARG = sv_newmortal();
306 "Usage: attributes::reftype $reference");
313 if (!(SvOK(rv) && SvROK(rv)))
316 sv_setpv(TARG, sv_reftype(sv, 0));
324 XS(XS_attributes__warn_reserved)
330 SV * TARG = sv_newmortal();
335 "Usage: attributes::_warn_reserved ()");
340 sv_setiv(TARG, ckWARN(WARN_RESERVED) != 0);