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
18 #define PERL_IN_XSUTILS_C
22 * Contributed by Spider Boardman (spider.boardman@orb.nashua.nh.us).
25 /* package attributes; */
26 PERL_XS_EXPORT_C void XS_attributes_reftype(pTHX_ CV *cv);
27 PERL_XS_EXPORT_C void XS_attributes__modify_attrs(pTHX_ CV *cv);
28 PERL_XS_EXPORT_C void XS_attributes__guess_stash(pTHX_ CV *cv);
29 PERL_XS_EXPORT_C void XS_attributes__fetch_attrs(pTHX_ CV *cv);
30 PERL_XS_EXPORT_C 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.
45 static const char file[] = __FILE__;
48 Perl_boot_core_xsutils(pTHX)
50 newXS("attributes::bootstrap", XS_attributes_bootstrap, file);
56 modify_SV_attributes(pTHX_ SV *sv, SV **retlist, SV **attrlist, int numattrs)
62 for (nret = 0 ; numattrs && (attr = *attrlist++); numattrs--) {
64 const char *name = SvPV_const(attr, len);
65 const bool negated = (*name == '-');
78 if (memEQ(name, "lvalue", 6)) {
80 CvFLAGS(MUTABLE_CV(sv)) &= ~CVf_LVALUE;
82 CvFLAGS(MUTABLE_CV(sv)) |= CVf_LVALUE;
88 if (memEQ(name, "locked", 6)) {
90 CvFLAGS(MUTABLE_CV(sv)) &= ~CVf_LOCKED;
92 CvFLAGS(MUTABLE_CV(sv)) |= CVf_LOCKED;
97 if (memEQ(name, "method", 6)) {
99 CvFLAGS(MUTABLE_CV(sv)) &= ~CVf_METHOD;
101 CvFLAGS(MUTABLE_CV(sv)) |= CVf_METHOD;
114 if (memEQ(name, "share", 5)) {
116 Perl_croak(aTHX_ "A variable may not be unshared");
122 if (memEQ(name, "uniqu", 5)) {
123 if (isGV_with_GP(sv)) {
130 /* Hope this came from toke.c if not a GV. */
137 /* anything recognized had a 'continue' above */
147 /* package attributes; */
149 XS(XS_attributes_bootstrap)
155 croak_xs_usage(cv, "$module");
157 newXS("attributes::_modify_attrs", XS_attributes__modify_attrs, file);
158 newXSproto("attributes::_guess_stash", XS_attributes__guess_stash, file, "$");
159 newXSproto("attributes::_fetch_attrs", XS_attributes__fetch_attrs, file, "$");
160 newXSproto("attributes::reftype", XS_attributes_reftype, file, "$");
165 XS(XS_attributes__modify_attrs)
173 croak_xs_usage(cv, "@attributes");
177 if (!(SvOK(rv) && SvROK(rv)))
181 XSRETURN(modify_SV_attributes(aTHX_ sv, &ST(0), &ST(1), items-1));
186 XS(XS_attributes__fetch_attrs)
195 croak_xs_usage(cv, "$reference");
200 if (!(SvOK(rv) && SvROK(rv)))
204 switch (SvTYPE(sv)) {
206 cvflags = CvFLAGS((const CV *)sv);
207 if (cvflags & CVf_LOCKED)
208 XPUSHs(newSVpvs_flags("locked", SVs_TEMP));
210 if (cvflags & CVf_LVALUE)
211 XPUSHs(newSVpvs_flags("lvalue", SVs_TEMP));
213 if (cvflags & CVf_METHOD)
214 XPUSHs(newSVpvs_flags("method", SVs_TEMP));
215 if (GvUNIQUE(CvGV((const CV *)sv)))
216 XPUSHs(newSVpvs_flags("unique", SVs_TEMP));
219 if (isGV_with_GP(sv) && GvUNIQUE(sv))
220 XPUSHs(newSVpvs_flags("unique", SVs_TEMP));
229 XS(XS_attributes__guess_stash)
238 croak_xs_usage(cv, "$reference");
243 if (!(SvOK(rv) && SvROK(rv)))
248 sv_setpvn(TARG, HvNAME_get(SvSTASH(sv)), HvNAMELEN_get(SvSTASH(sv)));
249 #if 0 /* this was probably a bad idea */
250 else if (SvPADMY(sv))
251 sv_setsv(TARG, &PL_sv_no); /* unblessed lexical */
254 const HV *stash = NULL;
255 switch (SvTYPE(sv)) {
257 if (CvGV(sv) && isGV(CvGV(sv)) && GvSTASH(CvGV(sv)))
258 stash = GvSTASH(CvGV(sv));
259 else if (/* !CvANON(sv) && */ CvSTASH(sv))
263 if (isGV_with_GP(sv) && GvGP(sv) && GvESTASH(MUTABLE_GV(sv)))
264 stash = GvESTASH(MUTABLE_GV(sv));
270 sv_setpvn(TARG, HvNAME_get(stash), HvNAMELEN_get(stash));
277 XS(XS_attributes_reftype)
286 croak_xs_usage(cv, "$reference");
292 if (!(SvOK(rv) && SvROK(rv)))
295 sv_setpv(TARG, sv_reftype(sv, 0));
303 * c-indentation-style: bsd
305 * indent-tabs-mode: t
308 * ex: set ts=8 sts=4 sw=4 noet: