Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b916faf

Browse files
committed
Upgraded new.function() contributed by Tommy. Also got rid of #if 0'ed code.
1 parent 40a172c commit b916faf

1 file changed

Lines changed: 8 additions & 25 deletions

File tree

Modules/newmodule.c

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,8 @@ new_instancemethod(unused, args)
7979
return newinstancemethodobject(func, self, classObj);
8080
}
8181

82-
/* XXX These internal interfaces have changed -- who'll fix this code? */
83-
#if 0
84-
8582
static char new_function_doc[] =
86-
"Create a function object from (CODE, GLOBALS, [NAME, ARGCOUNT, ARGDEFS]).";
83+
"Create a function object from (CODE, GLOBALS, [NAME, ARGDEFS]).";
8784

8885
static object *
8986
new_function(unused, args)
@@ -93,16 +90,14 @@ new_function(unused, args)
9390
object* code;
9491
object* globals;
9592
object* name = None;
96-
int argcount = -1;
97-
object* argdefs = None;
93+
object* defaults = None;
9894
funcobject* newfunc;
9995

100-
if (!newgetargs(args, "O!O!|SiO!",
96+
if (!newgetargs(args, "O!O!|SO!",
10197
&Codetype, &code,
10298
&Mappingtype, &globals,
10399
&name,
104-
&argcount,
105-
&Tupletype, &argdefs))
100+
&Tupletype, &defaults))
106101
return NULL;
107102

108103
newfunc = (funcobject *)newfuncobject(code, globals);
@@ -114,16 +109,14 @@ new_function(unused, args)
114109
XDECREF(newfunc->func_name);
115110
newfunc->func_name = name;
116111
}
117-
newfunc->func_argcount = argcount;
118-
if (argdefs != NULL) {
119-
XINCREF(argdefs);
120-
XDECREF(newfunc->func_argdefs);
121-
newfunc->func_argdefs = argdefs;
112+
if (defaults != NULL) {
113+
XINCREF(defaults);
114+
XDECREF(newfunc->func_defaults);
115+
newfunc->func_defaults = defaults;
122116
}
123117

124118
return (object *)newfunc;
125119
}
126-
#endif
127120

128121
static char new_code_doc[] =
129122
"Create a code object from (ARGCOUNT, NLOCALS, FLAGS, CODESTRING, CONSTANTS, NAMES, VARNAMES, FILENAME, NAME).";
@@ -143,13 +136,6 @@ new_code(unused, args)
143136
object* filename;
144137
object* name;
145138

146-
#if 0
147-
if (!newgetargs(args, "SO!O!SS",
148-
&code, &Tupletype, &consts, &Tupletype, &names,
149-
&filename, &name))
150-
return NULL;
151-
return (object *)newcodeobject(code, consts, names, filename, name);
152-
#else
153139
if (!newgetargs(args, "iiiSO!O!O!SS",
154140
&argcount, &nlocals, &flags, /* These are new */
155141
&code, &Tupletype, &consts, &Tupletype, &names,
@@ -158,7 +144,6 @@ new_code(unused, args)
158144
return NULL;
159145
return (object *)newcodeobject(argcount, nlocals, flags,
160146
code, consts, names, varnames, filename, name);
161-
#endif
162147
}
163148

164149
static char new_module_doc[] =
@@ -197,9 +182,7 @@ new_class(unused, args)
197182
static struct methodlist new_methods[] = {
198183
{"instance", new_instance, 1, new_instance_doc},
199184
{"instancemethod", new_instancemethod, 1, new_im_doc},
200-
#if 0
201185
{"function", new_function, 1, new_function_doc},
202-
#endif
203186
{"code", new_code, 1, new_code_doc},
204187
{"module", new_module, 1, new_module_doc},
205188
{"classobj", new_class, 1, new_class_doc},

0 commit comments

Comments
 (0)