]> granicus.if.org Git - python/commitdiff
move extra arguments to the back of the new.code() arglist
authorJeremy Hylton <jeremy@alum.mit.edu>
Thu, 1 Feb 2001 19:50:29 +0000 (19:50 +0000)
committerJeremy Hylton <jeremy@alum.mit.edu>
Thu, 1 Feb 2001 19:50:29 +0000 (19:50 +0000)
Lib/test/test_new.py
Modules/newmodule.c

index 30433aefb1f0dc605f0dd04e2fe51ea66d704c35..6ea7707d2cea6bffc944c236dbe4c0dc9e6dfbe4 100644 (file)
@@ -66,7 +66,10 @@ verify(g['c'] == 3,
 
 # bogus test of new.code()
 print 'new.code()'
-d = new.code(3, 3, 3, 3, codestr, (), (), (), (), (),
+d = new.code(3, 3, 3, 3, codestr, (), (), (), 
+             "<string>", "<name>", 1, "", (), ())
+# test backwards-compatibility version with no freevars or cellvars
+d = new.code(3, 3, 3, 3, codestr, (), (), (), 
              "<string>", "<name>", 1, "")
 if verbose:
     print d
index 7c7bee713bcd5717f371b23883c4e7a049659da8..7b91fb8bc3ef8f0226e10ccead87f17c9ba7cfc8 100644 (file)
@@ -103,7 +103,9 @@ new_function(PyObject* unused, PyObject* args)
 }
 
 static char new_code_doc[] =
-"Create a code object from (ARGCOUNT, NLOCALS, STACKSIZE, FLAGS, CODESTRING, CONSTANTS, NAMES, VARNAMES, FREEVARS, CELLVARS, FILENAME, NAME, FIRSTLINENO, LNOTAB).";
+"Create a code object from (ARGCOUNT, NLOCALS, STACKSIZE, FLAGS, CODESTRING,\n"
+"CONSTANTS, NAMES, VARNAMES, FILENAME, NAME, FIRSTLINENO, LNOTAB, FREEVARS,\n"
+"CELLVARS).";
 
 static PyObject *
 new_code(PyObject* unused, PyObject* args)
@@ -116,26 +118,41 @@ new_code(PyObject* unused, PyObject* args)
        PyObject* consts;
        PyObject* names;
        PyObject* varnames;
-       PyObject* freevars;
-       PyObject* cellvars;
+       PyObject* freevars = NULL;
+       PyObject* cellvars = NULL;
        PyObject* filename;
        PyObject* name;
        int firstlineno;
        PyObject* lnotab;
        PyBufferProcs *pb;
 
-       if (!PyArg_ParseTuple(args, "iiiiOO!O!O!O!O!SSiS:code",
+       if (!PyArg_ParseTuple(args, "iiiiSO!O!O!SSiS|O!O!:code",
                              &argcount, &nlocals, &stacksize, &flags,
                              &code,
                              &PyTuple_Type, &consts,
                              &PyTuple_Type, &names,
                              &PyTuple_Type, &varnames,
-                             &PyTuple_Type, &freevars,
-                             &PyTuple_Type, &cellvars,
                              &filename, &name,
-                             &firstlineno, &lnotab))
+                             &firstlineno, &lnotab,
+                             &PyTuple_Type, &freevars,
+                             &PyTuple_Type, &cellvars))
                return NULL;
 
+       if (freevars == NULL || cellvars == NULL) {
+               PyObject *empty = PyTuple_New(0);
+               if (empty == NULL)
+                   return NULL;
+               if (freevars == NULL) {
+                   freevars = empty;
+                   Py_INCREF(freevars);
+               }
+               if (cellvars == NULL) {
+                   cellvars = empty;
+                   Py_INCREF(cellvars);
+               }
+               Py_DECREF(empty);
+       }
+
        pb = code->ob_type->tp_as_buffer;
        if (pb == NULL ||
            pb->bf_getreadbuffer == NULL ||