annotate Modules/newmodule.c @ 8831:00a6bb65ff29 legacy-trunk

Getting rid of this ancient stuff.
author Guido van Rossum <guido@python.org>
date Wed, 05 Aug 1998 21:10:09 +0000
parents 4ba9b70ca56e
children 0a67db47e1d0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
1 /***********************************************************
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
3 The Netherlands.
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
4
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
5 All Rights Reserved
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
6
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3678
diff changeset
7 Permission to use, copy, modify, and distribute this software and its
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3678
diff changeset
8 documentation for any purpose and without fee is hereby granted,
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
9 provided that the above copyright notice appear in all copies and that
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3678
diff changeset
10 both that copyright notice and this permission notice appear in
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
11 supporting documentation, and that the names of Stichting Mathematisch
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3678
diff changeset
12 Centrum or CWI or Corporation for National Research Initiatives or
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3678
diff changeset
13 CNRI not be used in advertising or publicity pertaining to
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3678
diff changeset
14 distribution of the software without specific, written prior
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3678
diff changeset
15 permission.
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
16
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3678
diff changeset
17 While CWI is the initial source for this software, a modified version
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3678
diff changeset
18 is made available by the Corporation for National Research Initiatives
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3678
diff changeset
19 (CNRI) at the Internet address ftp://ftp.python.org.
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3678
diff changeset
20
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3678
diff changeset
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3678
diff changeset
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3678
diff changeset
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3678
diff changeset
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3678
diff changeset
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3678
diff changeset
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3678
diff changeset
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 3678
diff changeset
28 PERFORMANCE OF THIS SOFTWARE.
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
29
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
30 ******************************************************************/
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
31
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
32 /* Module new -- create new objects of various types */
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
33
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
34 #include "Python.h"
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 #include "compile.h"
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
36
3678
bddbaa51aa5a Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents: 3337
diff changeset
37 static char new_instance_doc[] =
bddbaa51aa5a Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents: 3337
diff changeset
38 "Create an instance object from (CLASS, DICT) without calling its __init__().";
bddbaa51aa5a Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents: 3337
diff changeset
39
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
40 static PyObject *
3678
bddbaa51aa5a Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents: 3337
diff changeset
41 new_instance(unused, args)
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
42 PyObject* unused;
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
43 PyObject* args;
3678
bddbaa51aa5a Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents: 3337
diff changeset
44 {
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
45 PyObject* klass;
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
46 PyObject *dict;
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
47 PyInstanceObject *inst;
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
48 if (!PyArg_ParseTuple(args, "O!O!",
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
49 &PyClass_Type, &klass,
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
50 &PyDict_Type, &dict))
3678
bddbaa51aa5a Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents: 3337
diff changeset
51 return NULL;
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
52 inst = PyObject_NEW(PyInstanceObject, &PyInstance_Type);
3678
bddbaa51aa5a Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents: 3337
diff changeset
53 if (inst == NULL)
bddbaa51aa5a Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents: 3337
diff changeset
54 return NULL;
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
55 Py_INCREF(klass);
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
56 Py_INCREF(dict);
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
57 inst->in_class = (PyClassObject *)klass;
3678
bddbaa51aa5a Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents: 3337
diff changeset
58 inst->in_dict = dict;
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
59 return (PyObject *)inst;
3678
bddbaa51aa5a Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents: 3337
diff changeset
60 }
bddbaa51aa5a Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents: 3337
diff changeset
61
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
62 static char new_im_doc[] =
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
63 "Create a instance method object from (FUNCTION, INSTANCE, CLASS).";
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
64
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
65 static PyObject *
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 new_instancemethod(unused, args)
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
67 PyObject* unused;
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
68 PyObject* args;
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 {
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
70 PyObject* func;
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
71 PyObject* self;
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
72 PyObject* classObj;
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
73
8651
4ba9b70ca56e Marc-Andre Lemburg's patch to support instance methods with other
Guido van Rossum <guido@python.org>
parents: 8409
diff changeset
74 if (!PyArg_ParseTuple(args, "OOO!",
4ba9b70ca56e Marc-Andre Lemburg's patch to support instance methods with other
Guido van Rossum <guido@python.org>
parents: 8409
diff changeset
75 &func,
4ba9b70ca56e Marc-Andre Lemburg's patch to support instance methods with other
Guido van Rossum <guido@python.org>
parents: 8409
diff changeset
76 &self,
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
77 &PyClass_Type, &classObj))
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
78 return NULL;
8651
4ba9b70ca56e Marc-Andre Lemburg's patch to support instance methods with other
Guido van Rossum <guido@python.org>
parents: 8409
diff changeset
79 if (!PyCallable_Check(func)) {
4ba9b70ca56e Marc-Andre Lemburg's patch to support instance methods with other
Guido van Rossum <guido@python.org>
parents: 8409
diff changeset
80 PyErr_SetString(PyExc_TypeError,
4ba9b70ca56e Marc-Andre Lemburg's patch to support instance methods with other
Guido van Rossum <guido@python.org>
parents: 8409
diff changeset
81 "first argument must be callable");
4ba9b70ca56e Marc-Andre Lemburg's patch to support instance methods with other
Guido van Rossum <guido@python.org>
parents: 8409
diff changeset
82 return NULL;
4ba9b70ca56e Marc-Andre Lemburg's patch to support instance methods with other
Guido van Rossum <guido@python.org>
parents: 8409
diff changeset
83 }
4ba9b70ca56e Marc-Andre Lemburg's patch to support instance methods with other
Guido van Rossum <guido@python.org>
parents: 8409
diff changeset
84 if (self == Py_None)
4ba9b70ca56e Marc-Andre Lemburg's patch to support instance methods with other
Guido van Rossum <guido@python.org>
parents: 8409
diff changeset
85 self = NULL;
4ba9b70ca56e Marc-Andre Lemburg's patch to support instance methods with other
Guido van Rossum <guido@python.org>
parents: 8409
diff changeset
86 else if (!PyInstance_Check(self)) {
4ba9b70ca56e Marc-Andre Lemburg's patch to support instance methods with other
Guido van Rossum <guido@python.org>
parents: 8409
diff changeset
87 PyErr_SetString(PyExc_TypeError,
4ba9b70ca56e Marc-Andre Lemburg's patch to support instance methods with other
Guido van Rossum <guido@python.org>
parents: 8409
diff changeset
88 "second argument must be instance or None");
4ba9b70ca56e Marc-Andre Lemburg's patch to support instance methods with other
Guido van Rossum <guido@python.org>
parents: 8409
diff changeset
89 return NULL;
4ba9b70ca56e Marc-Andre Lemburg's patch to support instance methods with other
Guido van Rossum <guido@python.org>
parents: 8409
diff changeset
90 }
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
91 return PyMethod_New(func, self, classObj);
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 }
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
93
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
94 static char new_function_doc[] =
4562
d030ea533e63 Upgraded new.function() contributed by Tommy. Also got rid of #if 0'ed code.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
95 "Create a function object from (CODE, GLOBALS, [NAME, ARGDEFS]).";
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
96
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
97 static PyObject *
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 new_function(unused, args)
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
99 PyObject* unused;
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
100 PyObject* args;
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 {
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
102 PyObject* code;
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
103 PyObject* globals;
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
104 PyObject* name = Py_None;
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
105 PyObject* defaults = Py_None;
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
106 PyFunctionObject* newfunc;
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
107
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
108 if (!PyArg_ParseTuple(args, "O!O!|SO!",
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
109 &PyCode_Type, &code,
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
110 &PyDict_Type, &globals,
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
111 &name,
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
112 &PyTuple_Type, &defaults))
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
113 return NULL;
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
114
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
115 newfunc = (PyFunctionObject *)PyFunction_New(code, globals);
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
116 if (newfunc == NULL)
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
117 return NULL;
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
118
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
119 if (name != Py_None) {
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
120 Py_XINCREF(name);
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
121 Py_XDECREF(newfunc->func_name);
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
122 newfunc->func_name = name;
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
123 }
8409
f21867f8035b I think there was a tiny bug in new_function() -- the 'defaults'
Guido van Rossum <guido@python.org>
parents: 5044
diff changeset
124 if (defaults != Py_None) {
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
125 Py_XINCREF(defaults);
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
126 Py_XDECREF(newfunc->func_defaults);
4562
d030ea533e63 Upgraded new.function() contributed by Tommy. Also got rid of #if 0'ed code.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
127 newfunc->func_defaults = defaults;
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
128 }
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
129
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
130 return (PyObject *)newfunc;
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
131 }
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
132
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
133 static char new_code_doc[] =
5044
ee3ac9e0a032 Two more arguments to newcodeobject -- first lineno and lineno table.
Guido van Rossum <guido@python.org>
parents: 4997
diff changeset
134 "Create a code object from (ARGCOUNT, NLOCALS, STACKSIZE, FLAGS, CODESTRING, CONSTANTS, NAMES, VARNAMES, FILENAME, NAME, FIRSTLINENO, LNOTAB).";
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
135
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
136 static PyObject *
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 new_code(unused, args)
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
138 PyObject* unused;
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
139 PyObject* args;
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 {
3135
999fcce496f8 re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents: 2871
diff changeset
141 int argcount;
999fcce496f8 re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents: 2871
diff changeset
142 int nlocals;
4997
58bbaf284ad6 Add stacksize argument to new.code().
Guido van Rossum <guido@python.org>
parents: 4661
diff changeset
143 int stacksize;
3135
999fcce496f8 re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents: 2871
diff changeset
144 int flags;
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
145 PyObject* code;
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
146 PyObject* consts;
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
147 PyObject* names;
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
148 PyObject* varnames;
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
149 PyObject* filename;
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
150 PyObject* name;
5044
ee3ac9e0a032 Two more arguments to newcodeobject -- first lineno and lineno table.
Guido van Rossum <guido@python.org>
parents: 4997
diff changeset
151 int firstlineno;
ee3ac9e0a032 Two more arguments to newcodeobject -- first lineno and lineno table.
Guido van Rossum <guido@python.org>
parents: 4997
diff changeset
152 PyObject* lnotab;
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
153
5044
ee3ac9e0a032 Two more arguments to newcodeobject -- first lineno and lineno table.
Guido van Rossum <guido@python.org>
parents: 4997
diff changeset
154 if (!PyArg_ParseTuple(args, "iiiiSO!O!O!SSiS",
4997
58bbaf284ad6 Add stacksize argument to new.code().
Guido van Rossum <guido@python.org>
parents: 4661
diff changeset
155 &argcount, &nlocals, &stacksize, &flags,
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
156 &code,
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
157 &PyTuple_Type, &consts,
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
158 &PyTuple_Type, &names,
4997
58bbaf284ad6 Add stacksize argument to new.code().
Guido van Rossum <guido@python.org>
parents: 4661
diff changeset
159 &PyTuple_Type, &varnames,
5044
ee3ac9e0a032 Two more arguments to newcodeobject -- first lineno and lineno table.
Guido van Rossum <guido@python.org>
parents: 4997
diff changeset
160 &filename, &name,
ee3ac9e0a032 Two more arguments to newcodeobject -- first lineno and lineno table.
Guido van Rossum <guido@python.org>
parents: 4997
diff changeset
161 &firstlineno, &lnotab))
3135
999fcce496f8 re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents: 2871
diff changeset
162 return NULL;
4997
58bbaf284ad6 Add stacksize argument to new.code().
Guido van Rossum <guido@python.org>
parents: 4661
diff changeset
163 return (PyObject *)PyCode_New(argcount, nlocals, stacksize, flags,
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
164 code, consts, names, varnames,
5044
ee3ac9e0a032 Two more arguments to newcodeobject -- first lineno and lineno table.
Guido van Rossum <guido@python.org>
parents: 4997
diff changeset
165 filename, name, firstlineno, lnotab);
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 }
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
167
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
168 static char new_module_doc[] =
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
169 "Create a module object from (NAME).";
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
170
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
171 static PyObject *
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
172 new_module(unused, args)
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
173 PyObject* unused;
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
174 PyObject* args;
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
175 {
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
176 char *name;
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
177
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
178 if (!PyArg_ParseTuple(args, "s", &name))
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
179 return NULL;
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
180 return PyModule_New(name);
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
181 }
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
182
3337
201de8455c2b added new.classobj()
Guido van Rossum <guido@python.org>
parents: 3135
diff changeset
183 static char new_class_doc[] =
201de8455c2b added new.classobj()
Guido van Rossum <guido@python.org>
parents: 3135
diff changeset
184 "Create a class object from (NAME, BASE_CLASSES, DICT).";
201de8455c2b added new.classobj()
Guido van Rossum <guido@python.org>
parents: 3135
diff changeset
185
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
186 static PyObject *
3337
201de8455c2b added new.classobj()
Guido van Rossum <guido@python.org>
parents: 3135
diff changeset
187 new_class(unused, args)
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
188 PyObject* unused;
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
189 PyObject* args;
3337
201de8455c2b added new.classobj()
Guido van Rossum <guido@python.org>
parents: 3135
diff changeset
190 {
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
191 PyObject * name;
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
192 PyObject * classes;
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
193 PyObject * dict;
3337
201de8455c2b added new.classobj()
Guido van Rossum <guido@python.org>
parents: 3135
diff changeset
194
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
195 if (!PyArg_ParseTuple(args, "SO!O!", &name, &PyTuple_Type, &classes,
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
196 &PyDict_Type, &dict))
3337
201de8455c2b added new.classobj()
Guido van Rossum <guido@python.org>
parents: 3135
diff changeset
197 return NULL;
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
198 return PyClass_New(classes, dict, name);
3337
201de8455c2b added new.classobj()
Guido van Rossum <guido@python.org>
parents: 3135
diff changeset
199 }
201de8455c2b added new.classobj()
Guido van Rossum <guido@python.org>
parents: 3135
diff changeset
200
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
201 static PyMethodDef new_methods[] = {
3678
bddbaa51aa5a Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents: 3337
diff changeset
202 {"instance", new_instance, 1, new_instance_doc},
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
203 {"instancemethod", new_instancemethod, 1, new_im_doc},
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
204 {"function", new_function, 1, new_function_doc},
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
205 {"code", new_code, 1, new_code_doc},
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
206 {"module", new_module, 1, new_module_doc},
3337
201de8455c2b added new.classobj()
Guido van Rossum <guido@python.org>
parents: 3135
diff changeset
207 {"classobj", new_class, 1, new_class_doc},
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
208 {NULL, NULL} /* sentinel */
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
209 };
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
210
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
211 char new_doc[] =
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
212 "Functions to create new objects used by the interpreter.\n\
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
213 \n\
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
214 You need to know a great deal about the interpreter to use this!";
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
215
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
216 void
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
217 initnew()
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
218 {
4661
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
219 Py_InitModule4("new", new_methods, new_doc, (PyObject *)NULL,
d5023d0c5502 Renamed.
Barry Warsaw <barry@python.org>
parents: 4562
diff changeset
220 PYTHON_API_VERSION);
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
221 }