Mercurial > cpython-lru_cache-weakref
annotate Modules/newmodule.c @ 3546:3f7cdf1663f7 legacy-trunk
A version of swed that can import html files. Also demonstrates
implementing object handlers in Python.
| author | Jack Jansen <jack.jansen@cwi.nl> |
|---|---|
| date | Tue, 07 May 1996 15:25:36 +0000 |
| parents | 201de8455c2b |
| children | bddbaa51aa5a |
| rev | line source |
|---|---|
| 2077 | 1 /*********************************************************** |
| 2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, | |
| 3 The Netherlands. | |
| 4 | |
| 5 All Rights Reserved | |
| 6 | |
| 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. | |
| 14 | |
| 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. | |
| 22 | |
| 23 ******************************************************************/ | |
| 24 | |
| 25 /* Module new -- create new objects of various types */ | |
| 26 | |
| 1650 | 27 #include "allobjects.h" |
| 28 #include "compile.h" | |
| 29 | |
| 2077 | 30 static char new_im_doc[] = |
| 31 "Create a instance method object from (FUNCTION, INSTANCE, CLASS)."; | |
| 1650 | 32 |
| 2077 | 33 static object * |
| 1650 | 34 new_instancemethod(unused, args) |
| 2077 | 35 object* unused; |
| 36 object* args; | |
| 1650 | 37 { |
| 2077 | 38 object* func; |
| 39 object* self; | |
| 40 object* classObj; | |
| 41 | |
| 42 if (!newgetargs(args, "O!O!O!", | |
| 43 &Functype, &func, | |
| 44 &Instancetype, &self, | |
| 45 &Classtype, &classObj)) | |
| 46 return NULL; | |
| 47 return newinstancemethodobject(func, self, classObj); | |
| 1650 | 48 } |
| 49 | |
|
2871
0534025cefe5
\temporary 'fix' for brokenness
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
50 /* XXX These internal interfaces have changed -- who'll fix this code? */ |
|
0534025cefe5
\temporary 'fix' for brokenness
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
51 #if 0 |
|
0534025cefe5
\temporary 'fix' for brokenness
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
52 |
| 2077 | 53 static char new_function_doc[] = |
| 54 "Create a function object from (CODE, GLOBALS, [NAME, ARGCOUNT, ARGDEFS])."; | |
| 55 | |
| 56 static object * | |
| 1650 | 57 new_function(unused, args) |
| 2077 | 58 object* unused; |
| 59 object* args; | |
| 1650 | 60 { |
| 2077 | 61 object* code; |
| 62 object* globals; | |
| 63 object* name = None; | |
| 64 int argcount = -1; | |
| 65 object* argdefs = None; | |
| 66 funcobject* newfunc; | |
| 1650 | 67 |
| 2077 | 68 if (!newgetargs(args, "O!O!|SiO!", |
| 69 &Codetype, &code, | |
| 70 &Mappingtype, &globals, | |
| 71 &name, | |
| 72 &argcount, | |
| 73 &Tupletype, &argdefs)) | |
| 74 return NULL; | |
| 1650 | 75 |
| 2077 | 76 newfunc = (funcobject *)newfuncobject(code, globals); |
| 77 if (newfunc == NULL) | |
| 78 return NULL; | |
| 1650 | 79 |
| 2077 | 80 if (name != None) { |
| 81 XINCREF(name); | |
| 82 XDECREF(newfunc->func_name); | |
| 83 newfunc->func_name = name; | |
| 84 } | |
| 85 newfunc->func_argcount = argcount; | |
| 86 if (argdefs != NULL) { | |
| 87 XINCREF(argdefs); | |
| 88 XDECREF(newfunc->func_argdefs); | |
| 89 newfunc->func_argdefs = argdefs; | |
| 90 } | |
| 1650 | 91 |
| 2077 | 92 return (object *)newfunc; |
| 93 } | |
|
3135
999fcce496f8
re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents:
2871
diff
changeset
|
94 #endif |
| 2077 | 95 |
| 96 static char new_code_doc[] = | |
|
3135
999fcce496f8
re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents:
2871
diff
changeset
|
97 "Create a code object from (ARGCOUNT, NLOCALS, FLAGS, CODESTRING, CONSTANTS, NAMES, VARNAMES, FILENAME, NAME)."; |
| 2077 | 98 |
| 99 static object * | |
| 1650 | 100 new_code(unused, args) |
| 2077 | 101 object* unused; |
| 102 object* args; | |
| 1650 | 103 { |
|
3135
999fcce496f8
re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents:
2871
diff
changeset
|
104 int argcount; |
|
999fcce496f8
re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents:
2871
diff
changeset
|
105 int nlocals; |
|
999fcce496f8
re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents:
2871
diff
changeset
|
106 int flags; |
| 2077 | 107 object* code; |
| 108 object* consts; | |
| 109 object* names; | |
|
3135
999fcce496f8
re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents:
2871
diff
changeset
|
110 object* varnames; |
| 2077 | 111 object* filename; |
| 112 object* name; | |
| 1650 | 113 |
|
3135
999fcce496f8
re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents:
2871
diff
changeset
|
114 #if 0 |
| 2077 | 115 if (!newgetargs(args, "SO!O!SS", |
| 116 &code, &Tupletype, &consts, &Tupletype, &names, | |
| 117 &filename, &name)) | |
| 118 return NULL; | |
| 119 return (object *)newcodeobject(code, consts, names, filename, name); | |
|
3135
999fcce496f8
re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents:
2871
diff
changeset
|
120 #else |
|
999fcce496f8
re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents:
2871
diff
changeset
|
121 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
|
122 &argcount, &nlocals, &flags, /* These are new */ |
|
999fcce496f8
re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents:
2871
diff
changeset
|
123 &code, &Tupletype, &consts, &Tupletype, &names, |
|
999fcce496f8
re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents:
2871
diff
changeset
|
124 &Tupletype, &varnames, /* These are new */ |
|
999fcce496f8
re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents:
2871
diff
changeset
|
125 &filename, &name)) |
|
999fcce496f8
re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents:
2871
diff
changeset
|
126 return NULL; |
|
999fcce496f8
re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents:
2871
diff
changeset
|
127 return (object *)newcodeobject(argcount, nlocals, flags, |
|
999fcce496f8
re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents:
2871
diff
changeset
|
128 code, consts, names, varnames, filename, name); |
|
999fcce496f8
re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents:
2871
diff
changeset
|
129 #endif |
| 1650 | 130 } |
| 2077 | 131 |
| 132 static char new_module_doc[] = | |
| 133 "Create a module object from (NAME)."; | |
| 1650 | 134 |
| 2077 | 135 static object * |
| 1650 | 136 new_module(unused, args) |
| 2077 | 137 object* unused; |
| 138 object* args; | |
| 1650 | 139 { |
| 2077 | 140 char *name; |
| 1650 | 141 |
| 2077 | 142 if (!newgetargs(args, "s", &name)) |
| 143 return NULL; | |
| 144 return newmoduleobject(name); | |
| 1650 | 145 } |
| 146 | |
| 3337 | 147 static char new_class_doc[] = |
| 148 "Create a class object from (NAME, BASE_CLASSES, DICT)."; | |
| 149 | |
| 150 static object * | |
| 151 new_class(unused, args) | |
| 152 object* unused; | |
| 153 object* args; | |
| 154 { | |
| 155 object * name; | |
| 156 object * classes; | |
| 157 object * dict; | |
| 158 | |
| 159 if (!newgetargs(args, "SO!O!", &name, &Tupletype, &classes, | |
| 160 &Mappingtype, &dict)) | |
| 161 return NULL; | |
| 162 return newclassobject(classes, dict, name); | |
| 163 } | |
| 164 | |
| 1650 | 165 static struct methodlist new_methods[] = { |
| 2077 | 166 {"instancemethod", new_instancemethod, 1, new_im_doc}, |
|
2871
0534025cefe5
\temporary 'fix' for brokenness
Guido van Rossum <guido@python.org>
parents:
2150
diff
changeset
|
167 #if 0 |
| 2077 | 168 {"function", new_function, 1, new_function_doc}, |
|
3135
999fcce496f8
re-enable new.code(...) with new args
Guido van Rossum <guido@python.org>
parents:
2871
diff
changeset
|
169 #endif |
| 2077 | 170 {"code", new_code, 1, new_code_doc}, |
| 171 {"module", new_module, 1, new_module_doc}, | |
| 3337 | 172 {"classobj", new_class, 1, new_class_doc}, |
| 2077 | 173 {NULL, NULL} /* sentinel */ |
| 1650 | 174 }; |
| 175 | |
| 2077 | 176 char new_doc[] = |
| 177 "Functions to create new objects used by the interpreter.\n\ | |
| 178 \n\ | |
| 179 You need to know a great deal about the interpreter to use this!"; | |
| 180 | |
| 1650 | 181 void |
| 182 initnew() | |
| 183 { | |
|
2096
d5c935b9a7b5
initmodule3 -> initmodule3
Guido van Rossum <guido@python.org>
parents:
2077
diff
changeset
|
184 initmodule4("new", new_methods, new_doc, (object *)NULL, |
|
d5c935b9a7b5
initmodule3 -> initmodule3
Guido van Rossum <guido@python.org>
parents:
2077
diff
changeset
|
185 PYTHON_API_VERSION); |
| 1650 | 186 } |
