3 * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
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
15 * [p.597 of _The Lord of the Rings_, III/xi: "The PalantÃr"]
20 #define PERL_IN_XSUTILS_C
24 * Contributed by Spider Boardman (spider.boardman@orb.nashua.nh.us).
27 /* package attributes; */
28 PERL_XS_EXPORT_C void XS_attributes_reftype(pTHX_ CV *cv);
29 PERL_XS_EXPORT_C void XS_attributes__modify_attrs(pTHX_ CV *cv);
30 PERL_XS_EXPORT_C void XS_attributes__guess_stash(pTHX_ CV *cv);
31 PERL_XS_EXPORT_C void XS_attributes__fetch_attrs(pTHX_ CV *cv);
32 PERL_XS_EXPORT_C void XS_attributes_bootstrap(pTHX_ CV *cv);
36 * Note that only ${pkg}::bootstrap definitions should go here.
37 * This helps keep down the start-up time, which is especially
38 * relevant for users who don't invoke any features which are
39 * (partially) implemented here.
41 * The various bootstrap definitions can take care of doing
42 * package-specific newXS() calls. Since the layout of the
43 * bundled *.pm files is in a version-specific directory,
44 * version checks in these bootstrap calls are optional.
47 static const char file[] = __FILE__;
50 Perl_boot_core_xsutils(pTHX)
52 newXS("attributes::bootstrap", XS_attributes_bootstrap, file);
58 modify_SV_attributes(pTHX_ SV *sv, SV **retlist, SV **attrlist, int numattrs)
64 for (nret = 0 ; numattrs && (attr = *attrlist++); numattrs--) {
66 const char *name = SvPV_const(attr, len);
67 const bool negated = (*name == '-');
80 if (memEQ(name, "lvalue", 6)) {
82 CvFLAGS(MUTABLE_CV(sv)) &= ~CVf_LVALUE;
84 CvFLAGS(MUTABLE_CV(sv)) |= CVf_LVALUE;
90 if (memEQ(name, "locked", 6)) {
92 CvFLAGS(MUTABLE_CV(sv)) &= ~CVf_LOCKED;
94 CvFLAGS(MUTABLE_CV(sv)) |= CVf_LOCKED;
99 if (memEQ(name, "method", 6)) {
101 CvFLAGS(MUTABLE_CV(sv)) &= ~CVf_METHOD;
103 CvFLAGS(MUTABLE_CV(sv)) |= CVf_METHOD;
116 if (memEQ(name, "share", 5)) {
118 Perl_croak(aTHX_ "A variable may not be unshared");
124 if (memEQ(name, "uniqu", 5)) {
125 if (isGV_with_GP(sv)) {
132 /* Hope this came from toke.c if not a GV. */
139 /* anything recognized had a 'continue' above */
149 /* package attributes; */
151 XS(XS_attributes_bootstrap)
157 croak_xs_usage(cv, "$module");
159 newXS("attributes::_modify_attrs", XS_attributes__modify_attrs, file);
160 newXSproto("attributes::_guess_stash", XS_attributes__guess_stash, file, "$");
161 newXSproto("attributes::_fetch_attrs", XS_attributes__fetch_attrs, file, "$");
162 newXSproto("attributes::reftype", XS_attributes_reftype, file, "$");
167 XS(XS_attributes__modify_attrs)
175 croak_xs_usage(cv, "@attributes");
179 if (!(SvOK(rv) && SvROK(rv)))
183 XSRETURN(modify_SV_attributes(aTHX_ sv, &ST(0), &ST(1), items-1));
188 XS(XS_attributes__fetch_attrs)
197 croak_xs_usage(cv, "$reference");
202 if (!(SvOK(rv) && SvROK(rv)))
206 switch (SvTYPE(sv)) {
208 cvflags = CvFLAGS((const CV *)sv);
209 if (cvflags & CVf_LOCKED)
210 XPUSHs(newSVpvs_flags("locked", SVs_TEMP));
212 if (cvflags & CVf_LVALUE)
213 XPUSHs(newSVpvs_flags("lvalue", SVs_TEMP));
215 if (cvflags & CVf_METHOD)
216 XPUSHs(newSVpvs_flags("method", SVs_TEMP));
217 if (GvUNIQUE(CvGV((const CV *)sv)))
218 XPUSHs(newSVpvs_flags("unique", SVs_TEMP));
221 if (isGV_with_GP(sv) && GvUNIQUE(sv))
222 XPUSHs(newSVpvs_flags("unique", SVs_TEMP));
231 XS(XS_attributes__guess_stash)
240 croak_xs_usage(cv, "$reference");
245 if (!(SvOK(rv) && SvROK(rv)))
250 sv_setpvn(TARG, HvNAME_get(SvSTASH(sv)), HvNAMELEN_get(SvSTASH(sv)));
251 #if 0 /* this was probably a bad idea */
252 else if (SvPADMY(sv))
253 sv_setsv(TARG, &PL_sv_no); /* unblessed lexical */
256 const HV *stash = NULL;
257 switch (SvTYPE(sv)) {
259 if (CvGV(sv) && isGV(CvGV(sv)) && GvSTASH(CvGV(sv)))
260 stash = GvSTASH(CvGV(sv));
261 else if (/* !CvANON(sv) && */ CvSTASH(sv))
265 if (isGV_with_GP(sv) && GvGP(sv) && GvESTASH(MUTABLE_GV(sv)))
266 stash = GvESTASH(MUTABLE_GV(sv));
272 sv_setpvn(TARG, HvNAME_get(stash), HvNAMELEN_get(stash));
279 XS(XS_attributes_reftype)
288 croak_xs_usage(cv, "$reference");
294 if (!(SvOK(rv) && SvROK(rv)))
297 sv_setpv(TARG, sv_reftype(sv, 0));
305 * c-indentation-style: bsd
307 * indent-tabs-mode: t
310 * ex: set ts=8 sts=4 sw=4 noet: