Mercurial > cpython-lru_cache-weakref
annotate Modules/newmodule.c @ 16798:258dcafe2d0b legacy-trunk
Gustavo Niemeyer <niemeyer@conectiva.com>:
Fixed recno support (keys are integers rather than strings).
Work around DB bug that cause stdin to be closed by rnopen() when the
DB file needed to exist but did not (no longer segfaults).
This closes SF tracker patch #403445.
Also wrapped some long lines and added whitespace around operators -- FLD.
| author | Fred Drake <fdrake@acm.org> |
|---|---|
| date | Tue, 27 Feb 2001 18:56:46 +0000 |
| parents | 2ab28b213d70 |
| children | 2bf2690966ff |
| rev | line source |
|---|---|
| 2077 | 1 |
| 2 /* Module new -- create new objects of various types */ | |
| 3 | |
| 4661 | 4 #include "Python.h" |
| 1650 | 5 #include "compile.h" |
| 6 | |
|
3678
bddbaa51aa5a
Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents:
3337
diff
changeset
|
7 static char new_instance_doc[] = |
|
16315
28c60ef48fa3
new_instance(): Use PyInstance_NewRaw() instead of knowing too much
Fred Drake <fdrake@acm.org>
parents:
16259
diff
changeset
|
8 "Create an instance object from (CLASS [, DICT]) without calling its\n\ |
|
28c60ef48fa3
new_instance(): Use PyInstance_NewRaw() instead of knowing too much
Fred Drake <fdrake@acm.org>
parents:
16259
diff
changeset
|
9 __init__() method. DICT must be a dictionary or None."; |
|
3678
bddbaa51aa5a
Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents:
3337
diff
changeset
|
10 |
| 4661 | 11 static PyObject * |
|
13499
046799a08057
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
12 new_instance(PyObject* unused, PyObject* args) |
|
3678
bddbaa51aa5a
Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents:
3337
diff
changeset
|
13 { |
|
16315
28c60ef48fa3
new_instance(): Use PyInstance_NewRaw() instead of knowing too much
Fred Drake <fdrake@acm.org>
parents:
16259
diff
changeset
|
14 PyObject *klass; |
|
28c60ef48fa3
new_instance(): Use PyInstance_NewRaw() instead of knowing too much
Fred Drake <fdrake@acm.org>
parents:
16259
diff
changeset
|
15 PyObject *dict = NULL; |
|
28c60ef48fa3
new_instance(): Use PyInstance_NewRaw() instead of knowing too much
Fred Drake <fdrake@acm.org>
parents:
16259
diff
changeset
|
16 |
|
28c60ef48fa3
new_instance(): Use PyInstance_NewRaw() instead of knowing too much
Fred Drake <fdrake@acm.org>
parents:
16259
diff
changeset
|
17 if (!PyArg_ParseTuple(args, "O!|O:instance", |
|
28c60ef48fa3
new_instance(): Use PyInstance_NewRaw() instead of knowing too much
Fred Drake <fdrake@acm.org>
parents:
16259
diff
changeset
|
18 &PyClass_Type, &klass, &dict)) |
|
3678
bddbaa51aa5a
Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents:
3337
diff
changeset
|
19 return NULL; |
|
16315
28c60ef48fa3
new_instance(): Use PyInstance_NewRaw() instead of knowing too much
Fred Drake <fdrake@acm.org>
parents:
16259
diff
changeset
|
20 |
|
28c60ef48fa3
new_instance(): Use PyInstance_NewRaw() instead of knowing too much
Fred Drake <fdrake@acm.org>
parents:
16259
diff
changeset
|
21 if (dict == Py_None) |
|
28c60ef48fa3
new_instance(): Use PyInstance_NewRaw() instead of knowing too much
Fred Drake <fdrake@acm.org>
parents:
16259
diff
changeset
|
22 dict = NULL; |
|
28c60ef48fa3
new_instance(): Use PyInstance_NewRaw() instead of knowing too much
Fred Drake <fdrake@acm.org>
parents:
16259
diff
changeset
|
23 else if (dict == NULL) |
|
28c60ef48fa3
new_instance(): Use PyInstance_NewRaw() instead of knowing too much
Fred Drake <fdrake@acm.org>
parents:
16259
diff
changeset
|
24 /* do nothing */; |
|
28c60ef48fa3
new_instance(): Use PyInstance_NewRaw() instead of knowing too much
Fred Drake <fdrake@acm.org>
parents:
16259
diff
changeset
|
25 else if (!PyDict_Check(dict)) { |
|
28c60ef48fa3
new_instance(): Use PyInstance_NewRaw() instead of knowing too much
Fred Drake <fdrake@acm.org>
parents:
16259
diff
changeset
|
26 PyErr_SetString(PyExc_TypeError, |
|
28c60ef48fa3
new_instance(): Use PyInstance_NewRaw() instead of knowing too much
Fred Drake <fdrake@acm.org>
parents:
16259
diff
changeset
|
27 "new.instance() second arg must be dictionary or None"); |
|
3678
bddbaa51aa5a
Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents:
3337
diff
changeset
|
28 return NULL; |
|
16315
28c60ef48fa3
new_instance(): Use PyInstance_NewRaw() instead of knowing too much
Fred Drake <fdrake@acm.org>
parents:
16259
diff
changeset
|
29 } |
|
28c60ef48fa3
new_instance(): Use PyInstance_NewRaw() instead of knowing too much
Fred Drake <fdrake@acm.org>
parents:
16259
diff
changeset
|
30 return PyInstance_NewRaw(klass, dict); |
|
3678
bddbaa51aa5a
Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents:
3337
diff
changeset
|
31 } |
|
bddbaa51aa5a
Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents:
3337
diff
changeset
|
32 |
| 2077 | 33 static char new_im_doc[] = |
| 34 "Create a instance method object from (FUNCTION, INSTANCE, CLASS)."; | |
| 1650 | 35 |
| 4661 | 36 static PyObject * |
|
13499
046799a08057
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
37 new_instancemethod(PyObject* unused, PyObject* args) |
| 1650 | 38 { |
| 4661 | 39 PyObject* func; |
| 40 PyObject* self; | |
| 41 PyObject* classObj; | |
| 2077 | 42 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
43 if (!PyArg_ParseTuple(args, "OOO!:instancemethod", |
|
8651
4ba9b70ca56e
Marc-Andre Lemburg's patch to support instance methods with other
Guido van Rossum <guido@python.org>
parents:
8409
diff
changeset
|
44 &func, |
|
4ba9b70ca56e
Marc-Andre Lemburg's patch to support instance methods with other
Guido van Rossum <guido@python.org>
parents:
8409
diff
changeset
|
45 &self, |
| 4661 | 46 &PyClass_Type, &classObj)) |
| 2077 | 47 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
|
48 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
|
49 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
|
50 "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
|
51 return NULL; |
|
4ba9b70ca56e
Marc-Andre Lemburg's patch to support instance methods with other
Guido van Rossum <guido@python.org>
parents:
8409
diff
changeset
|
52 } |
|
4ba9b70ca56e
Marc-Andre Lemburg's patch to support instance methods with other
Guido van Rossum <guido@python.org>
parents:
8409
diff
changeset
|
53 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
|
54 self = NULL; |
|
4ba9b70ca56e
Marc-Andre Lemburg's patch to support instance methods with other
Guido van Rossum <guido@python.org>
parents:
8409
diff
changeset
|
55 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
|
56 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
|
57 "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
|
58 return NULL; |
|
4ba9b70ca56e
Marc-Andre Lemburg's patch to support instance methods with other
Guido van Rossum <guido@python.org>
parents:
8409
diff
changeset
|
59 } |
| 4661 | 60 return PyMethod_New(func, self, classObj); |
| 1650 | 61 } |
| 62 | |
| 2077 | 63 static char new_function_doc[] = |
|
15150
486f3ff14d95
Fix the docstring for new.function().
Fred Drake <fdrake@acm.org>
parents:
14375
diff
changeset
|
64 "Create a function object from (CODE, GLOBALS, [NAME [, ARGDEFS]])."; |
| 2077 | 65 |
| 4661 | 66 static PyObject * |
|
13499
046799a08057
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
67 new_function(PyObject* unused, PyObject* args) |
| 1650 | 68 { |
| 4661 | 69 PyObject* code; |
| 70 PyObject* globals; | |
| 71 PyObject* name = Py_None; | |
| 72 PyObject* defaults = Py_None; | |
| 73 PyFunctionObject* newfunc; | |
| 1650 | 74 |
|
15405
af1e9e64ed9d
Allow new.function() called with explicit 3rd arg of None, as
Guido van Rossum <guido@python.org>
parents:
15150
diff
changeset
|
75 if (!PyArg_ParseTuple(args, "O!O!|OO!:function", |
| 4661 | 76 &PyCode_Type, &code, |
| 77 &PyDict_Type, &globals, | |
| 78 &name, | |
| 79 &PyTuple_Type, &defaults)) | |
| 2077 | 80 return NULL; |
|
15405
af1e9e64ed9d
Allow new.function() called with explicit 3rd arg of None, as
Guido van Rossum <guido@python.org>
parents:
15150
diff
changeset
|
81 if (name != Py_None && !PyString_Check(name)) { |
|
af1e9e64ed9d
Allow new.function() called with explicit 3rd arg of None, as
Guido van Rossum <guido@python.org>
parents:
15150
diff
changeset
|
82 PyErr_SetString(PyExc_TypeError, |
|
af1e9e64ed9d
Allow new.function() called with explicit 3rd arg of None, as
Guido van Rossum <guido@python.org>
parents:
15150
diff
changeset
|
83 "arg 3 (name) must be None or string"); |
|
af1e9e64ed9d
Allow new.function() called with explicit 3rd arg of None, as
Guido van Rossum <guido@python.org>
parents:
15150
diff
changeset
|
84 return NULL; |
|
af1e9e64ed9d
Allow new.function() called with explicit 3rd arg of None, as
Guido van Rossum <guido@python.org>
parents:
15150
diff
changeset
|
85 } |
| 1650 | 86 |
| 4661 | 87 newfunc = (PyFunctionObject *)PyFunction_New(code, globals); |
| 2077 | 88 if (newfunc == NULL) |
| 89 return NULL; | |
| 1650 | 90 |
| 4661 | 91 if (name != Py_None) { |
| 92 Py_XINCREF(name); | |
| 93 Py_XDECREF(newfunc->func_name); | |
| 2077 | 94 newfunc->func_name = name; |
| 95 } | |
|
8409
f21867f8035b
I think there was a tiny bug in new_function() -- the 'defaults'
Guido van Rossum <guido@python.org>
parents:
5044
diff
changeset
|
96 if (defaults != Py_None) { |
| 4661 | 97 Py_XINCREF(defaults); |
| 98 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
|
99 newfunc->func_defaults = defaults; |
| 2077 | 100 } |
| 1650 | 101 |
| 4661 | 102 return (PyObject *)newfunc; |
| 2077 | 103 } |
| 104 | |
| 105 static char new_code_doc[] = | |
|
16391
2ab28b213d70
move extra arguments to the back of the new.code() arglist
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16315
diff
changeset
|
106 "Create a code object from (ARGCOUNT, NLOCALS, STACKSIZE, FLAGS, CODESTRING,\n" |
|
2ab28b213d70
move extra arguments to the back of the new.code() arglist
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16315
diff
changeset
|
107 "CONSTANTS, NAMES, VARNAMES, FILENAME, NAME, FIRSTLINENO, LNOTAB, FREEVARS,\n" |
|
2ab28b213d70
move extra arguments to the back of the new.code() arglist
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16315
diff
changeset
|
108 "CELLVARS)."; |
| 2077 | 109 |
| 4661 | 110 static PyObject * |
|
13499
046799a08057
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
111 new_code(PyObject* unused, PyObject* args) |
| 1650 | 112 { |
|
3135
999fcce496f8
re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents:
2871
diff
changeset
|
113 int argcount; |
|
999fcce496f8
re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents:
2871
diff
changeset
|
114 int nlocals; |
|
4997
58bbaf284ad6
Add stacksize argument to new.code().
Guido van Rossum <guido@python.org>
parents:
4661
diff
changeset
|
115 int stacksize; |
|
3135
999fcce496f8
re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents:
2871
diff
changeset
|
116 int flags; |
| 4661 | 117 PyObject* code; |
| 118 PyObject* consts; | |
| 119 PyObject* names; | |
| 120 PyObject* varnames; | |
|
16391
2ab28b213d70
move extra arguments to the back of the new.code() arglist
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16315
diff
changeset
|
121 PyObject* freevars = NULL; |
|
2ab28b213d70
move extra arguments to the back of the new.code() arglist
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16315
diff
changeset
|
122 PyObject* cellvars = NULL; |
| 4661 | 123 PyObject* filename; |
| 124 PyObject* name; | |
|
5044
ee3ac9e0a032
Two more arguments to newcodeobject -- first lineno and lineno table.
Guido van Rossum <guido@python.org>
parents:
4997
diff
changeset
|
125 int firstlineno; |
|
ee3ac9e0a032
Two more arguments to newcodeobject -- first lineno and lineno table.
Guido van Rossum <guido@python.org>
parents:
4997
diff
changeset
|
126 PyObject* lnotab; |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8651
diff
changeset
|
127 PyBufferProcs *pb; |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8651
diff
changeset
|
128 |
|
16391
2ab28b213d70
move extra arguments to the back of the new.code() arglist
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16315
diff
changeset
|
129 if (!PyArg_ParseTuple(args, "iiiiSO!O!O!SSiS|O!O!:code", |
|
4997
58bbaf284ad6
Add stacksize argument to new.code().
Guido van Rossum <guido@python.org>
parents:
4661
diff
changeset
|
130 &argcount, &nlocals, &stacksize, &flags, |
| 4661 | 131 &code, |
| 132 &PyTuple_Type, &consts, | |
| 133 &PyTuple_Type, &names, | |
|
4997
58bbaf284ad6
Add stacksize argument to new.code().
Guido van Rossum <guido@python.org>
parents:
4661
diff
changeset
|
134 &PyTuple_Type, &varnames, |
|
16391
2ab28b213d70
move extra arguments to the back of the new.code() arglist
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16315
diff
changeset
|
135 &filename, &name, |
|
2ab28b213d70
move extra arguments to the back of the new.code() arglist
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16315
diff
changeset
|
136 &firstlineno, &lnotab, |
|
16259
9386b32bff1d
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15405
diff
changeset
|
137 &PyTuple_Type, &freevars, |
|
16391
2ab28b213d70
move extra arguments to the back of the new.code() arglist
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16315
diff
changeset
|
138 &PyTuple_Type, &cellvars)) |
|
3135
999fcce496f8
re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents:
2871
diff
changeset
|
139 return NULL; |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8651
diff
changeset
|
140 |
|
16391
2ab28b213d70
move extra arguments to the back of the new.code() arglist
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16315
diff
changeset
|
141 if (freevars == NULL || cellvars == NULL) { |
|
2ab28b213d70
move extra arguments to the back of the new.code() arglist
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16315
diff
changeset
|
142 PyObject *empty = PyTuple_New(0); |
|
2ab28b213d70
move extra arguments to the back of the new.code() arglist
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16315
diff
changeset
|
143 if (empty == NULL) |
|
2ab28b213d70
move extra arguments to the back of the new.code() arglist
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16315
diff
changeset
|
144 return NULL; |
|
2ab28b213d70
move extra arguments to the back of the new.code() arglist
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16315
diff
changeset
|
145 if (freevars == NULL) { |
|
2ab28b213d70
move extra arguments to the back of the new.code() arglist
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16315
diff
changeset
|
146 freevars = empty; |
|
2ab28b213d70
move extra arguments to the back of the new.code() arglist
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16315
diff
changeset
|
147 Py_INCREF(freevars); |
|
2ab28b213d70
move extra arguments to the back of the new.code() arglist
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16315
diff
changeset
|
148 } |
|
2ab28b213d70
move extra arguments to the back of the new.code() arglist
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16315
diff
changeset
|
149 if (cellvars == NULL) { |
|
2ab28b213d70
move extra arguments to the back of the new.code() arglist
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16315
diff
changeset
|
150 cellvars = empty; |
|
2ab28b213d70
move extra arguments to the back of the new.code() arglist
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16315
diff
changeset
|
151 Py_INCREF(cellvars); |
|
2ab28b213d70
move extra arguments to the back of the new.code() arglist
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16315
diff
changeset
|
152 } |
|
2ab28b213d70
move extra arguments to the back of the new.code() arglist
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16315
diff
changeset
|
153 Py_DECREF(empty); |
|
2ab28b213d70
move extra arguments to the back of the new.code() arglist
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16315
diff
changeset
|
154 } |
|
2ab28b213d70
move extra arguments to the back of the new.code() arglist
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16315
diff
changeset
|
155 |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8651
diff
changeset
|
156 pb = code->ob_type->tp_as_buffer; |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8651
diff
changeset
|
157 if (pb == NULL || |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8651
diff
changeset
|
158 pb->bf_getreadbuffer == NULL || |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8651
diff
changeset
|
159 pb->bf_getsegcount == NULL || |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8651
diff
changeset
|
160 (*pb->bf_getsegcount)(code, NULL) != 1) |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8651
diff
changeset
|
161 { |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8651
diff
changeset
|
162 PyErr_SetString(PyExc_TypeError, |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8651
diff
changeset
|
163 "bytecode object must be a single-segment read-only buffer"); |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8651
diff
changeset
|
164 return NULL; |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8651
diff
changeset
|
165 } |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8651
diff
changeset
|
166 |
|
4997
58bbaf284ad6
Add stacksize argument to new.code().
Guido van Rossum <guido@python.org>
parents:
4661
diff
changeset
|
167 return (PyObject *)PyCode_New(argcount, nlocals, stacksize, flags, |
| 4661 | 168 code, consts, names, varnames, |
|
16259
9386b32bff1d
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15405
diff
changeset
|
169 freevars, cellvars, filename, name, |
|
9386b32bff1d
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15405
diff
changeset
|
170 firstlineno, lnotab); |
| 1650 | 171 } |
| 2077 | 172 |
| 173 static char new_module_doc[] = | |
| 174 "Create a module object from (NAME)."; | |
| 1650 | 175 |
| 4661 | 176 static PyObject * |
|
13499
046799a08057
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
177 new_module(PyObject* unused, PyObject* args) |
| 1650 | 178 { |
| 2077 | 179 char *name; |
| 1650 | 180 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
181 if (!PyArg_ParseTuple(args, "s:module", &name)) |
| 2077 | 182 return NULL; |
| 4661 | 183 return PyModule_New(name); |
| 1650 | 184 } |
| 185 | |
| 3337 | 186 static char new_class_doc[] = |
| 187 "Create a class object from (NAME, BASE_CLASSES, DICT)."; | |
| 188 | |
| 4661 | 189 static PyObject * |
|
13499
046799a08057
ANSI-fication
Peter Schneider-Kamp <nowonder@nowonder.de>
parents:
13256
diff
changeset
|
190 new_class(PyObject* unused, PyObject* args) |
| 3337 | 191 { |
| 4661 | 192 PyObject * name; |
| 193 PyObject * classes; | |
| 194 PyObject * dict; | |
| 3337 | 195 |
|
11882
dc65c5f6ad7c
Massive patch by Skip Montanaro to add ":name" to as many
Guido van Rossum <guido@python.org>
parents:
9588
diff
changeset
|
196 if (!PyArg_ParseTuple(args, "SO!O!:class", &name, &PyTuple_Type, &classes, |
| 4661 | 197 &PyDict_Type, &dict)) |
| 3337 | 198 return NULL; |
| 4661 | 199 return PyClass_New(classes, dict, name); |
| 3337 | 200 } |
| 201 | |
| 4661 | 202 static PyMethodDef new_methods[] = { |
|
13817
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13651
diff
changeset
|
203 {"instance", new_instance, |
|
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13651
diff
changeset
|
204 METH_VARARGS, new_instance_doc}, |
|
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13651
diff
changeset
|
205 {"instancemethod", new_instancemethod, |
|
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13651
diff
changeset
|
206 METH_VARARGS, new_im_doc}, |
|
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13651
diff
changeset
|
207 {"function", new_function, |
|
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13651
diff
changeset
|
208 METH_VARARGS, new_function_doc}, |
|
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13651
diff
changeset
|
209 {"code", new_code, |
|
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13651
diff
changeset
|
210 METH_VARARGS, new_code_doc}, |
|
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13651
diff
changeset
|
211 {"module", new_module, |
|
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13651
diff
changeset
|
212 METH_VARARGS, new_module_doc}, |
|
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13651
diff
changeset
|
213 {"classobj", new_class, |
|
3c0f75a2198f
Use METH_VARARGS instead of numeric constant 1 in method def. tables
Andrew M. Kuchling <amk@amk.ca>
parents:
13651
diff
changeset
|
214 METH_VARARGS, new_class_doc}, |
| 2077 | 215 {NULL, NULL} /* sentinel */ |
| 1650 | 216 }; |
| 217 | |
| 2077 | 218 char new_doc[] = |
| 219 "Functions to create new objects used by the interpreter.\n\ | |
| 220 \n\ | |
| 221 You need to know a great deal about the interpreter to use this!"; | |
| 222 | |
|
9588
38023a425e48
Add DL_EXPORT() to all modules that could possibly be used
Guido van Rossum <guido@python.org>
parents:
9293
diff
changeset
|
223 DL_EXPORT(void) |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13499
diff
changeset
|
224 initnew(void) |
| 1650 | 225 { |
| 4661 | 226 Py_InitModule4("new", new_methods, new_doc, (PyObject *)NULL, |
| 227 PYTHON_API_VERSION); | |
| 1650 | 228 } |
