improve treatment of multi-line replies, ignore empty lines
[python/dscho.git] / Modules / newmodule.c
blob4c8b16d19d3f3138a9658589cd5b29ff181e94e0
1 /***********************************************************
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
3 The Netherlands.
5 All Rights Reserved
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the names of Stichting Mathematisch
12 Centrum or CWI not be used in advertising or publicity pertaining to
13 distribution of the software without specific, written prior permission.
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 ******************************************************************/
25 /* Module new -- create new objects of various types */
27 #include "allobjects.h"
28 #include "compile.h"
29 #include "modsupport.h"
31 static char new_im_doc[] =
32 "Create a instance method object from (FUNCTION, INSTANCE, CLASS).";
34 static object *
35 new_instancemethod(unused, args)
36 object* unused;
37 object* args;
39 object* func;
40 object* self;
41 object* classObj;
43 if (!newgetargs(args, "O!O!O!",
44 &Functype, &func,
45 &Instancetype, &self,
46 &Classtype, &classObj))
47 return NULL;
48 return newinstancemethodobject(func, self, classObj);
51 static char new_function_doc[] =
52 "Create a function object from (CODE, GLOBALS, [NAME, ARGCOUNT, ARGDEFS]).";
54 static object *
55 new_function(unused, args)
56 object* unused;
57 object* args;
59 object* code;
60 object* globals;
61 object* name = None;
62 int argcount = -1;
63 object* argdefs = None;
64 funcobject* newfunc;
66 if (!newgetargs(args, "O!O!|SiO!",
67 &Codetype, &code,
68 &Mappingtype, &globals,
69 &name,
70 &argcount,
71 &Tupletype, &argdefs))
72 return NULL;
74 newfunc = (funcobject *)newfuncobject(code, globals);
75 if (newfunc == NULL)
76 return NULL;
78 if (name != None) {
79 XINCREF(name);
80 XDECREF(newfunc->func_name);
81 newfunc->func_name = name;
83 newfunc->func_argcount = argcount;
84 if (argdefs != NULL) {
85 XINCREF(argdefs);
86 XDECREF(newfunc->func_argdefs);
87 newfunc->func_argdefs = argdefs;
90 return (object *)newfunc;
93 static char new_code_doc[] =
94 "Create a code object from (CODESTRING, CONSTANTS, NAMES, FILENAME, NAME).";
96 static object *
97 new_code(unused, args)
98 object* unused;
99 object* args;
101 object* code;
102 object* consts;
103 object* names;
104 object* filename;
105 object* name;
107 if (!newgetargs(args, "SO!O!SS",
108 &code, &Tupletype, &consts, &Tupletype, &names,
109 &filename, &name))
110 return NULL;
111 return (object *)newcodeobject(code, consts, names, filename, name);
114 static char new_module_doc[] =
115 "Create a module object from (NAME).";
117 static object *
118 new_module(unused, args)
119 object* unused;
120 object* args;
122 char *name;
124 if (!newgetargs(args, "s", &name))
125 return NULL;
126 return newmoduleobject(name);
129 static struct methodlist new_methods[] = {
130 {"instancemethod", new_instancemethod, 1, new_im_doc},
131 {"function", new_function, 1, new_function_doc},
132 {"code", new_code, 1, new_code_doc},
133 {"module", new_module, 1, new_module_doc},
134 {NULL, NULL} /* sentinel */
137 char new_doc[] =
138 "Functions to create new objects used by the interpreter.\n\
140 You need to know a great deal about the interpreter to use this!";
142 void
143 initnew()
145 initmodule4("new", new_methods, new_doc, (object *)NULL,
146 PYTHON_API_VERSION);