Kaydet (Commit) 681d79aa authored tarafından Guido van Rossum's avatar Guido van Rossum

keyword arguments and faster calls

üst 11a3f0c2
......@@ -80,15 +80,20 @@ builtin_apply(self, args)
object *self;
object *args;
{
object *func, *alist;
object *func, *alist, *kwdict = NULL;
if (!newgetargs(args, "OO:apply", &func, &alist))
if (!newgetargs(args, "O|OO:apply", &func, &alist, &kwdict))
return NULL;
if (!is_tupleobject(alist)) {
if (alist != NULL && !is_tupleobject(alist)) {
err_setstr(TypeError, "apply() 2nd argument must be tuple");
return NULL;
}
return call_object(func, alist);
if (kwdict != NULL && !is_dictobject(kwdict)) {
err_setstr(TypeError,
"apply() 3rd argument must be dictionary");
return NULL;
}
return PyEval_CallObjectWithKeywords(func, alist, kwdict);
}
static object *
......@@ -373,8 +378,7 @@ builtin_eval(self, args)
return NULL;
}
if (is_codeobject(cmd))
return eval_code((codeobject *) cmd, globals, locals,
(object *)NULL, (object *)NULL);
return eval_code((codeobject *) cmd, globals, locals);
if (!is_stringobject(cmd)) {
err_setstr(TypeError,
"eval() argument 1 must be string or code object");
......
This diff is collapsed.
This diff is collapsed.
......@@ -54,7 +54,7 @@ extern long getmtime(); /* In getmtime.c */
Apple MPW compiler swaps their values, botching string constants */
/* XXX Perhaps the magic number should be frozen and a version field
added to the .pyc file header? */
#define MAGIC (0x4127L | ((long)'\r'<<16) | ((long)'\n'<<24))
#define MAGIC (11913 | ((long)'\r'<<16) | ((long)'\n'<<24))
object *import_modules; /* This becomes sys.modules */
......@@ -159,7 +159,7 @@ exec_code_module(name, co)
if (dictinsert(d, "__builtins__", getbuiltins()) != 0)
return NULL;
}
v = eval_code((codeobject *)co, d, d, d, (object *)NULL);
v = eval_code((codeobject *)co, d, d); /* XXX owner? */
if (v == NULL)
return NULL;
DECREF(v);
......
......@@ -44,7 +44,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define TYPE_TUPLE '('
#define TYPE_LIST '['
#define TYPE_DICT '{'
#define TYPE_CODE 'C'
#define TYPE_CODE 'c'
#define TYPE_UNKNOWN '?'
typedef struct {
......@@ -187,9 +187,13 @@ w_object(v, p)
else if (is_codeobject(v)) {
codeobject *co = (codeobject *)v;
w_byte(TYPE_CODE, p);
w_short(co->co_argcount, p);
w_short(co->co_nlocals, p);
w_short(co->co_flags, p);
w_object((object *)co->co_code, p);
w_object(co->co_consts, p);
w_object(co->co_names, p);
w_object(co->co_varnames, p);
w_object(co->co_filename, p);
w_object(co->co_name, p);
}
......@@ -374,14 +378,20 @@ r_object(p)
case TYPE_CODE:
{
int argcount = r_short(p);
int nlocals = r_short(p);
int flags = r_short(p);
object *code = r_object(p);
object *consts = r_object(p);
object *names = r_object(p);
object *varnames = r_object(p);
object *filename = r_object(p);
object *name = r_object(p);
if (!err_occurred()) {
v = (object *) newcodeobject(code,
consts, names, filename, name);
v = (object *) newcodeobject(
argcount, nlocals, flags,
code, consts, names, varnames,
filename, name);
}
else
v = NULL;
......
......@@ -430,7 +430,7 @@ run_node(n, filename, globals, locals)
freetree(n);
if (co == NULL)
return NULL;
v = eval_code(co, globals, locals, (object *)NULL, (object *)NULL);
v = eval_code(co, globals, locals);
DECREF(co);
return v;
}
......@@ -462,7 +462,7 @@ run_pyc_file(fp, filename, globals, locals)
return NULL;
}
co = (codeobject *)v;
v = eval_code(co, globals, locals, (object *)NULL, (object *)NULL);
v = eval_code(co, globals, locals);
DECREF(co);
return v;
}
......@@ -603,16 +603,9 @@ cleanup()
object *exitfunc = sysget("exitfunc");
if (exitfunc) {
object *arg;
object *res;
sysset("exitfunc", (object *)NULL);
arg = newtupleobject(0);
if (arg == NULL)
res = NULL;
else {
res = call_object(exitfunc, arg);
DECREF(arg);
}
res = call_object(exitfunc, (object *)NULL);
if (res == NULL) {
fprintf(stderr, "Error in sys.exitfunc:\n");
print_error();
......
......@@ -68,7 +68,10 @@ tb_dealloc(tb)
DEL(tb);
}
static typeobject Tracebacktype = {
#define Tracebacktype PyTraceback_Type
#define is_tracebackobject PyTraceback_Check
typeobject Tracebacktype = {
OB_HEAD_INIT(&Typetype)
0,
"traceback",
......@@ -85,8 +88,6 @@ static typeobject Tracebacktype = {
0, /*tp_as_mapping*/
};
#define is_tracebackobject(v) ((v)->ob_type == &Tracebacktype)
static tracebackobject *
newtracebackobject(next, frame, lasti, lineno)
tracebackobject *next;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment