annotate Modules/newmodule.c @ 4566:6403c94de50d legacy-trunk

Added safeguard against failure in __del__.
author Guido van Rossum <guido@python.org>
date Wed, 27 Nov 1996 19:39:58 +0000
parents d030ea533e63
children d5023d0c5502
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
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 #include "allobjects.h"
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
bddbaa51aa5a Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents: 3337
diff changeset
40 static object *
bddbaa51aa5a Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents: 3337
diff changeset
41 new_instance(unused, args)
bddbaa51aa5a Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents: 3337
diff changeset
42 object* unused;
bddbaa51aa5a Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents: 3337
diff changeset
43 object* args;
bddbaa51aa5a Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents: 3337
diff changeset
44 {
bddbaa51aa5a Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents: 3337
diff changeset
45 object* klass;
bddbaa51aa5a Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents: 3337
diff changeset
46 object *dict;
bddbaa51aa5a Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents: 3337
diff changeset
47 instanceobject *inst;
bddbaa51aa5a Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents: 3337
diff changeset
48 if (!newgetargs(args, "O!O!",
bddbaa51aa5a Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents: 3337
diff changeset
49 &Classtype, &klass,
bddbaa51aa5a Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents: 3337
diff changeset
50 &Dicttype, &dict))
bddbaa51aa5a Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents: 3337
diff changeset
51 return NULL;
bddbaa51aa5a Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents: 3337
diff changeset
52 inst = NEWOBJ(instanceobject, &Instancetype);
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;
bddbaa51aa5a Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents: 3337
diff changeset
55 INCREF(klass);
bddbaa51aa5a Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents: 3337
diff changeset
56 INCREF(dict);
bddbaa51aa5a Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents: 3337
diff changeset
57 inst->in_class = (classobject *)klass;
bddbaa51aa5a Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents: 3337
diff changeset
58 inst->in_dict = dict;
bddbaa51aa5a Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents: 3337
diff changeset
59 return (object *)inst;
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
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
65 static object *
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 new_instancemethod(unused, args)
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
67 object* unused;
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
68 object* args;
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 {
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
70 object* func;
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
71 object* self;
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
72 object* classObj;
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
73
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
74 if (!newgetargs(args, "O!O!O!",
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
75 &Functype, &func,
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
76 &Instancetype, &self,
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
77 &Classtype, &classObj))
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
78 return NULL;
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
79 return newinstancemethodobject(func, self, classObj);
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 }
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
81
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
82 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
83 "Create a function object from (CODE, GLOBALS, [NAME, ARGDEFS]).";
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
84
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
85 static object *
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 new_function(unused, args)
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
87 object* unused;
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
88 object* args;
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 {
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
90 object* code;
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
91 object* globals;
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
92 object* name = None;
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
93 object* defaults = None;
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
94 funcobject* newfunc;
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
95
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
96 if (!newgetargs(args, "O!O!|SO!",
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
97 &Codetype, &code,
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
98 &Mappingtype, &globals,
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
99 &name,
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
100 &Tupletype, &defaults))
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
101 return NULL;
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
102
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
103 newfunc = (funcobject *)newfuncobject(code, globals);
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
104 if (newfunc == NULL)
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
105 return NULL;
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
106
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
107 if (name != None) {
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
108 XINCREF(name);
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
109 XDECREF(newfunc->func_name);
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
110 newfunc->func_name = name;
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
111 }
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
112 if (defaults != NULL) {
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
113 XINCREF(defaults);
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
114 XDECREF(newfunc->func_defaults);
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
115 newfunc->func_defaults = defaults;
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
116 }
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
117
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
118 return (object *)newfunc;
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
119 }
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
120
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
121 static char new_code_doc[] =
3135
999fcce496f8 re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents: 2871
diff changeset
122 "Create a code object from (ARGCOUNT, NLOCALS, FLAGS, CODESTRING, CONSTANTS, NAMES, VARNAMES, FILENAME, NAME).";
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
123
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
124 static object *
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 new_code(unused, args)
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
126 object* unused;
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
127 object* args;
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 {
3135
999fcce496f8 re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents: 2871
diff changeset
129 int argcount;
999fcce496f8 re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents: 2871
diff changeset
130 int nlocals;
999fcce496f8 re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents: 2871
diff changeset
131 int flags;
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
132 object* code;
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
133 object* consts;
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
134 object* names;
3135
999fcce496f8 re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents: 2871
diff changeset
135 object* varnames;
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
136 object* filename;
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
137 object* name;
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
138
3135
999fcce496f8 re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents: 2871
diff changeset
139 if (!newgetargs(args, "iiiSO!O!O!SS",
999fcce496f8 re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents: 2871
diff changeset
140 &argcount, &nlocals, &flags, /* These are new */
999fcce496f8 re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents: 2871
diff changeset
141 &code, &Tupletype, &consts, &Tupletype, &names,
999fcce496f8 re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents: 2871
diff changeset
142 &Tupletype, &varnames, /* These are new */
999fcce496f8 re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents: 2871
diff changeset
143 &filename, &name))
999fcce496f8 re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents: 2871
diff changeset
144 return NULL;
999fcce496f8 re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents: 2871
diff changeset
145 return (object *)newcodeobject(argcount, nlocals, flags,
999fcce496f8 re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents: 2871
diff changeset
146 code, consts, names, varnames, filename, name);
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
147 }
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
148
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
149 static char new_module_doc[] =
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
150 "Create a module object from (NAME).";
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
151
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
152 static object *
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 new_module(unused, args)
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
154 object* unused;
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
155 object* args;
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
156 {
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
157 char *name;
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
158
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
159 if (!newgetargs(args, "s", &name))
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
160 return NULL;
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
161 return newmoduleobject(name);
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 }
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
163
3337
201de8455c2b added new.classobj()
Guido van Rossum <guido@python.org>
parents: 3135
diff changeset
164 static char new_class_doc[] =
201de8455c2b added new.classobj()
Guido van Rossum <guido@python.org>
parents: 3135
diff changeset
165 "Create a class object from (NAME, BASE_CLASSES, DICT).";
201de8455c2b added new.classobj()
Guido van Rossum <guido@python.org>
parents: 3135
diff changeset
166
201de8455c2b added new.classobj()
Guido van Rossum <guido@python.org>
parents: 3135
diff changeset
167 static object *
201de8455c2b added new.classobj()
Guido van Rossum <guido@python.org>
parents: 3135
diff changeset
168 new_class(unused, args)
201de8455c2b added new.classobj()
Guido van Rossum <guido@python.org>
parents: 3135
diff changeset
169 object* unused;
201de8455c2b added new.classobj()
Guido van Rossum <guido@python.org>
parents: 3135
diff changeset
170 object* args;
201de8455c2b added new.classobj()
Guido van Rossum <guido@python.org>
parents: 3135
diff changeset
171 {
201de8455c2b added new.classobj()
Guido van Rossum <guido@python.org>
parents: 3135
diff changeset
172 object * name;
201de8455c2b added new.classobj()
Guido van Rossum <guido@python.org>
parents: 3135
diff changeset
173 object * classes;
201de8455c2b added new.classobj()
Guido van Rossum <guido@python.org>
parents: 3135
diff changeset
174 object * dict;
201de8455c2b added new.classobj()
Guido van Rossum <guido@python.org>
parents: 3135
diff changeset
175
201de8455c2b added new.classobj()
Guido van Rossum <guido@python.org>
parents: 3135
diff changeset
176 if (!newgetargs(args, "SO!O!", &name, &Tupletype, &classes,
201de8455c2b added new.classobj()
Guido van Rossum <guido@python.org>
parents: 3135
diff changeset
177 &Mappingtype, &dict))
201de8455c2b added new.classobj()
Guido van Rossum <guido@python.org>
parents: 3135
diff changeset
178 return NULL;
201de8455c2b added new.classobj()
Guido van Rossum <guido@python.org>
parents: 3135
diff changeset
179 return newclassobject(classes, dict, name);
201de8455c2b added new.classobj()
Guido van Rossum <guido@python.org>
parents: 3135
diff changeset
180 }
201de8455c2b added new.classobj()
Guido van Rossum <guido@python.org>
parents: 3135
diff changeset
181
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
182 static struct methodlist new_methods[] = {
3678
bddbaa51aa5a Added new.instance(class, dict).
Guido van Rossum <guido@python.org>
parents: 3337
diff changeset
183 {"instance", new_instance, 1, new_instance_doc},
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
184 {"instancemethod", new_instancemethod, 1, new_im_doc},
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
185 {"function", new_function, 1, new_function_doc},
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
186 {"code", new_code, 1, new_code_doc},
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
187 {"module", new_module, 1, new_module_doc},
3337
201de8455c2b added new.classobj()
Guido van Rossum <guido@python.org>
parents: 3135
diff changeset
188 {"classobj", new_class, 1, new_class_doc},
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
189 {NULL, NULL} /* sentinel */
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
190 };
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
191
2077
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
192 char new_doc[] =
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
193 "Functions to create new objects used by the interpreter.\n\
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
194 \n\
3848094f259c totally revamped
Guido van Rossum <guido@python.org>
parents: 2008
diff changeset
195 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
196
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
197 void
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
198 initnew()
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
199 {
2096
d5c935b9a7b5 initmodule3 -> initmodule3
Guido van Rossum <guido@python.org>
parents: 2077
diff changeset
200 initmodule4("new", new_methods, new_doc, (object *)NULL,
d5c935b9a7b5 initmodule3 -> initmodule3
Guido van Rossum <guido@python.org>
parents: 2077
diff changeset
201 PYTHON_API_VERSION);
1650
51a06fdfff78 Added some new modules
Guido van Rossum <guido@python.org>
parents:
diff changeset
202 }