gv_fetchfile(name)
char *name;
{
- char tmpbuf[1200];
+ char smallbuf[256];
+ char *tmpbuf;
STRLEN tmplen;
GV *gv;
- sprintf(tmpbuf, "_<%s", name);
- tmplen = strlen(tmpbuf);
+ tmplen = strlen(name) + 2;
+ if (tmplen < sizeof smallbuf)
+ tmpbuf = smallbuf;
+ else
+ New(603, tmpbuf, tmplen + 1, char);
+ tmpbuf[0] = '_';
+ tmpbuf[1] = '<';
+ strcpy(tmpbuf + 2, name);
gv = *(GV**)hv_fetch(defstash, tmpbuf, tmplen, TRUE);
if (!isGV(gv))
gv_init(gv, defstash, tmpbuf, tmplen, FALSE);
+ if (tmpbuf != smallbuf)
+ Safefree(tmpbuf);
sv_setpv(GvSV(gv), name);
if (*name == '/' && (instr(name, "/lib/") || instr(name, ".pm")))
GvMULTI_on(gv);
--nsplit;
if ((nsplit - origname) == 5 && strnEQ(origname, "SUPER", 5)) {
/* ->SUPER::method should really be looked up in original stash */
- SV *tmpstr = sv_2mortal(newSVpv(HvNAME(curcop->cop_stash), 0));
- sv_catpvn(tmpstr, "::SUPER", 7);
+ SV *tmpstr = sv_2mortal(newSVpvf("%s::SUPER",
+ HvNAME(curcop->cop_stash)));
stash = gv_stashpvn(SvPVX(tmpstr), SvCUR(tmpstr), TRUE);
DEBUG_o( deb("Treating %s as %s::%s\n",
origname, HvNAME(stash), name) );
U32 namelen;
I32 create;
{
- char tmpbuf[1203];
+ char smallbuf[256];
+ char *tmpbuf;
HV *stash;
GV *tmpgv;
- if (namelen > 1200) {
- namelen = 1200;
-#ifdef VMS
- warn("Weird package name \"%s\" truncated", name);
-#else
- warn("Weird package name \"%.*s...\" truncated", (int)namelen, name);
-#endif
- }
+ if (namelen + 3 < sizeof smallbuf)
+ tmpbuf = smallbuf;
+ else
+ New(606, tmpbuf, namelen + 3, char);
Copy(name,tmpbuf,namelen,char);
tmpbuf[namelen++] = ':';
tmpbuf[namelen++] = ':';
tmpbuf[namelen] = '\0';
- tmpgv = gv_fetchpv(tmpbuf,create, SVt_PVHV);
+ tmpgv = gv_fetchpv(tmpbuf, create, SVt_PVHV);
+ if (tmpbuf != smallbuf)
+ Safefree(tmpbuf);
if (!tmpgv)
return 0;
if (!GvHV(tmpgv))
newGVgen(pack)
char *pack;
{
- (void)sprintf(tokenbuf,"%s::_GEN_%ld",pack,(long)gensym++);
- return gv_fetchpv(tokenbuf,TRUE, SVt_PVGV);
+ return gv_fetchpv(form("%s::_GEN_%ld", pack, (long)gensym++),
+ TRUE, SVt_PVGV);
}
/* hopefully this is only called on local symbol table entries */
}
for (i = 1; i < NofAMmeth; i++) {
- cv = 0;
- cp = AMG_names[i];
-
- *buf = '('; /* A cookie: "(". */
- strcpy(buf + 1, cp);
+ SV *cookie = sv_2mortal(newSVpvf("(%s", cp = AMG_names[i]));
DEBUG_o( deb("Checking overloading of `%s' in package `%.256s'\n",
cp, HvNAME(stash)) );
- gv = gv_fetchmeth(stash, buf, strlen(buf), -1); /* no filling stash! */
+ /* don't fill the cache while looking up! */
+ gv = gv_fetchmeth(stash, SvPVX(cookie), SvCUR(cookie), -1);
+ cv = 0;
if(gv && (cv = GvCV(gv))) {
- char *name = buf;
if (GvNAMELEN(CvGV(cv)) == 3 && strEQ(GvNAME(CvGV(cv)), "nil")
&& strEQ(HvNAME(GvSTASH(CvGV(cv))), "overload")) {
/* GvSV contains the name of the method. */
(SvPOK(GvSV(gv)) ? SvPVX(GvSV(gv)) : "???" ),
cp, HvNAME(stash));
}
- name = SvPVX(GvSV(gv));
cv = GvCV(gv = ngv);
}
DEBUG_o( deb("Overloading `%s' in package `%.256s' via `%.256s::%.256s' \n",
case copy_amg:
{
SV* ref=SvRV(left);
- if (!SvROK(ref) && SvTYPE(ref) <= SVt_PVMG) { /* Just to be
- * extra
- * causious,
- * maybe in some
- * additional
- * cases sv_setsv
- * is safe too */
+ if (!SvROK(ref) && SvTYPE(ref) <= SVt_PVMG) {
+ /*
+ * Just to be extra cautious. Maybe in some
+ * additional cases sv_setsv is safe, too.
+ */
SV* newref = newSVsv(ref);
SvOBJECT_on(newref);
SvSTASH(newref) = (HV*)SvREFCNT_inc(SvSTASH(ref));
&& !(flags & AMGf_unary)) {
/* We look for substitution for
* comparison operations and
- * concatendation */
+ * concatenation */
if (method==concat_amg || method==concat_ass_amg
|| method==repeat_amg || method==repeat_ass_amg) {
return NULL; /* Delegate operation to string conversion */
} else if (cvp && (cv=cvp[nomethod_amg])) {
notfound = 1; lr = 1;
} else {
+ SV *msg;
if (off==-1) off=method;
- sprintf(buf,
- "Operation `%s': no method found,%sargument %s%.256s%s%.256s",
+ msg = sv_2mortal(newSVpvf(
+ "Operation `%s': no method found,%sargument %s%s%s%s",
AMG_names[method + assignshift],
(flags & AMGf_unary ? " " : "\n\tleft "),
SvAMAGIC(left)?
: ",\n\tright argument has no overloaded magic"),
SvAMAGIC(right)?
HvNAME(SvSTASH(SvRV(right))):
- "");
+ ""));
if (amtp && amtp->fallback >= AMGfallYES) {
- DEBUG_o( deb(buf) );
+ DEBUG_o( deb("%s", SvPVX(msg)) );
} else {
- croak(buf);
+ croak("%_", msg);
}
return NULL;
}
}
if (!notfound) {
DEBUG_o( deb(
- "Overloaded operator `%s'%s%s%s:\n\tmethod%s found%s in package %.256s%s\n",
+ "Overloaded operator `%s'%s%s%s:\n\tmethod%s found%s in package %s%s\n",
AMG_names[off],
method+assignshift==off? "" :
" (initially `",