summaryrefslogtreecommitdiffstats
path: root/Python/compile.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-01-18 08:02:57 (GMT)
committerGuido van Rossum <guido@python.org>1997-01-18 08:02:57 (GMT)
commit7b89b6a6608c4ac4387e12401fde5a0ac8fb9fcd (patch)
treeba33df7f10cb854d597fd65a630632b65819f641 /Python/compile.c
parenta412d24be056bebb77f54681c4490954759739fe (diff)
downloadcpython-7b89b6a6608c4ac4387e12401fde5a0ac8fb9fcd.zip
cpython-7b89b6a6608c4ac4387e12401fde5a0ac8fb9fcd.tar.gz
cpython-7b89b6a6608c4ac4387e12401fde5a0ac8fb9fcd.tar.bz2
Intern all names and varnames in newcodeobject(), plus those string
literals that look like identifiers. Also intern all strings used as names during the compilation.
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/Python/compile.c b/Python/compile.c
index 5562751..a772d79 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -205,13 +205,14 @@ newcodeobject(argcount, nlocals, stacksize, flags,
err_badcall();
return NULL;
}
- /* Make sure names and varnames are all strings */
+ /* Make sure names and varnames are all strings, & intern them */
for (i = gettuplesize(names); --i >= 0; ) {
object *v = gettupleitem(names, i);
if (v == NULL || !is_stringobject(v)) {
err_badcall();
return NULL;
}
+ PyString_InternInPlace(&PyTuple_GET_ITEM(names, i));
}
for (i = gettuplesize(varnames); --i >= 0; ) {
object *v = gettupleitem(varnames, i);
@@ -219,6 +220,20 @@ newcodeobject(argcount, nlocals, stacksize, flags,
err_badcall();
return NULL;
}
+ PyString_InternInPlace(&PyTuple_GET_ITEM(varnames, i));
+ }
+ /* Intern selected string constants */
+ for (i = gettuplesize(consts); --i >= 0; ) {
+ object *v = gettupleitem(consts, i);
+ int n;
+ char *p;
+ if (!is_stringobject(v))
+ continue;
+ p = getstringvalue(v);
+ if (strspn(p, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz")
+ != getstringsize(v))
+ continue;
+ PyString_InternInPlace(&PyTuple_GET_ITEM(consts, i));
}
co = NEWOBJ(codeobject, &Codetype);
if (co != NULL) {
@@ -620,7 +635,7 @@ com_addopnamestr(c, op, name)
com_mangle(c, name, buffer, (int)sizeof(buffer)))
name = buffer;
#endif
- if (name == NULL || (v = newstringobject(name)) == NULL) {
+ if (name == NULL || (v = PyString_InternFromString(name)) == NULL) {
c->c_errors++;
i = 255;
}
@@ -986,7 +1001,7 @@ com_argument(c, n, pkeywords)
com_error(c, SyntaxError, "keyword can't be an expression");
}
else {
- object *v = newstringobject(STR(m));
+ object *v = PyString_InternFromString(STR(m));
if (v != NULL && *pkeywords == NULL)
*pkeywords = newdictobject();
if (v == NULL || *pkeywords == NULL)
@@ -1973,7 +1988,7 @@ com_newlocal(c, name)
struct compiling *c;
char *name;
{
- object *nameval = newstringobject(name);
+ object *nameval = PyString_InternFromString(name);
int i;
if (nameval == NULL) {
c->c_errors++;
@@ -2563,7 +2578,7 @@ com_classdef(c, n)
object *v;
REQ(n, classdef);
/* classdef: class NAME ['(' testlist ')'] ':' suite */
- if ((v = newstringobject(STR(CHILD(n, 1)))) == NULL) {
+ if ((v = PyString_InternFromString(STR(CHILD(n, 1)))) == NULL) {
c->c_errors++;
return;
}
@@ -3186,8 +3201,8 @@ jcompile(n, filename, base)
consts = listtuple(sc.c_consts);
names = listtuple(sc.c_names);
varnames = listtuple(sc.c_varnames);
- filename = newstringobject(sc.c_filename);
- name = newstringobject(sc.c_name);
+ filename = PyString_InternFromString(sc.c_filename);
+ name = PyString_InternFromString(sc.c_name);
if (!err_occurred())
co = newcodeobject(sc.c_argcount,
sc.c_nlocals,