Commit b916faf6 authored by Guido van Rossum's avatar Guido van Rossum

Upgraded new.function() contributed by Tommy. Also got rid of #if 0'ed code.

parent 40a172c7
...@@ -79,11 +79,8 @@ new_instancemethod(unused, args) ...@@ -79,11 +79,8 @@ new_instancemethod(unused, args)
return newinstancemethodobject(func, self, classObj); return newinstancemethodobject(func, self, classObj);
} }
/* XXX These internal interfaces have changed -- who'll fix this code? */
#if 0
static char new_function_doc[] = static char new_function_doc[] =
"Create a function object from (CODE, GLOBALS, [NAME, ARGCOUNT, ARGDEFS])."; "Create a function object from (CODE, GLOBALS, [NAME, ARGDEFS]).";
static object * static object *
new_function(unused, args) new_function(unused, args)
...@@ -93,16 +90,14 @@ new_function(unused, args) ...@@ -93,16 +90,14 @@ new_function(unused, args)
object* code; object* code;
object* globals; object* globals;
object* name = None; object* name = None;
int argcount = -1; object* defaults = None;
object* argdefs = None;
funcobject* newfunc; funcobject* newfunc;
if (!newgetargs(args, "O!O!|SiO!", if (!newgetargs(args, "O!O!|SO!",
&Codetype, &code, &Codetype, &code,
&Mappingtype, &globals, &Mappingtype, &globals,
&name, &name,
&argcount, &Tupletype, &defaults))
&Tupletype, &argdefs))
return NULL; return NULL;
newfunc = (funcobject *)newfuncobject(code, globals); newfunc = (funcobject *)newfuncobject(code, globals);
...@@ -114,16 +109,14 @@ new_function(unused, args) ...@@ -114,16 +109,14 @@ new_function(unused, args)
XDECREF(newfunc->func_name); XDECREF(newfunc->func_name);
newfunc->func_name = name; newfunc->func_name = name;
} }
newfunc->func_argcount = argcount; if (defaults != NULL) {
if (argdefs != NULL) { XINCREF(defaults);
XINCREF(argdefs); XDECREF(newfunc->func_defaults);
XDECREF(newfunc->func_argdefs); newfunc->func_defaults = defaults;
newfunc->func_argdefs = argdefs;
} }
return (object *)newfunc; return (object *)newfunc;
} }
#endif
static char new_code_doc[] = static char new_code_doc[] =
"Create a code object from (ARGCOUNT, NLOCALS, FLAGS, CODESTRING, CONSTANTS, NAMES, VARNAMES, FILENAME, NAME)."; "Create a code object from (ARGCOUNT, NLOCALS, FLAGS, CODESTRING, CONSTANTS, NAMES, VARNAMES, FILENAME, NAME).";
...@@ -143,13 +136,6 @@ new_code(unused, args) ...@@ -143,13 +136,6 @@ new_code(unused, args)
object* filename; object* filename;
object* name; object* name;
#if 0
if (!newgetargs(args, "SO!O!SS",
&code, &Tupletype, &consts, &Tupletype, &names,
&filename, &name))
return NULL;
return (object *)newcodeobject(code, consts, names, filename, name);
#else
if (!newgetargs(args, "iiiSO!O!O!SS", if (!newgetargs(args, "iiiSO!O!O!SS",
&argcount, &nlocals, &flags, /* These are new */ &argcount, &nlocals, &flags, /* These are new */
&code, &Tupletype, &consts, &Tupletype, &names, &code, &Tupletype, &consts, &Tupletype, &names,
...@@ -158,7 +144,6 @@ new_code(unused, args) ...@@ -158,7 +144,6 @@ new_code(unused, args)
return NULL; return NULL;
return (object *)newcodeobject(argcount, nlocals, flags, return (object *)newcodeobject(argcount, nlocals, flags,
code, consts, names, varnames, filename, name); code, consts, names, varnames, filename, name);
#endif
} }
static char new_module_doc[] = static char new_module_doc[] =
...@@ -197,9 +182,7 @@ new_class(unused, args) ...@@ -197,9 +182,7 @@ new_class(unused, args)
static struct methodlist new_methods[] = { static struct methodlist new_methods[] = {
{"instance", new_instance, 1, new_instance_doc}, {"instance", new_instance, 1, new_instance_doc},
{"instancemethod", new_instancemethod, 1, new_im_doc}, {"instancemethod", new_instancemethod, 1, new_im_doc},
#if 0
{"function", new_function, 1, new_function_doc}, {"function", new_function, 1, new_function_doc},
#endif
{"code", new_code, 1, new_code_doc}, {"code", new_code, 1, new_code_doc},
{"module", new_module, 1, new_module_doc}, {"module", new_module, 1, new_module_doc},
{"classobj", new_class, 1, new_class_doc}, {"classobj", new_class, 1, new_class_doc},
......
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