Mercurial > cpython-lru_cache-weakref
annotate Objects/funcobject.c @ 892:11ea669c231e legacy-trunk
Documented new contents of lib5.tex
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 03 Jun 1992 17:56:44 +0000 |
| parents | 0cd197947d81 |
| children | 1cabc2b6c970 |
| rev | line source |
|---|---|
| 145 | 1 /*********************************************************** |
|
795
0cd197947d81
Copyright for 1992 added
Guido van Rossum <guido@python.org>
parents:
588
diff
changeset
|
2 Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The |
| 145 | 3 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 | |
| 6 | 25 /* Function object implementation */ |
| 26 | |
| 86 | 27 #include "allobjects.h" |
| 6 | 28 |
| 86 | 29 #include "structmember.h" |
| 6 | 30 |
| 31 typedef struct { | |
| 32 OB_HEAD | |
|
84
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
33 object *func_code; |
| 6 | 34 object *func_globals; |
| 35 } funcobject; | |
| 36 | |
| 37 object * | |
|
84
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
38 newfuncobject(code, globals) |
|
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
39 object *code; |
| 6 | 40 object *globals; |
| 41 { | |
| 42 funcobject *op = NEWOBJ(funcobject, &Functype); | |
| 43 if (op != NULL) { | |
|
84
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
44 INCREF(code); |
|
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
45 op->func_code = code; |
|
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
46 INCREF(globals); |
| 6 | 47 op->func_globals = globals; |
| 48 } | |
| 49 return (object *)op; | |
| 50 } | |
| 51 | |
|
84
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
52 object * |
|
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
53 getfunccode(op) |
| 6 | 54 object *op; |
| 55 { | |
| 56 if (!is_funcobject(op)) { | |
| 27 | 57 err_badcall(); |
| 6 | 58 return NULL; |
| 59 } | |
|
84
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
60 return ((funcobject *) op) -> func_code; |
| 6 | 61 } |
| 62 | |
| 63 object * | |
| 64 getfuncglobals(op) | |
| 65 object *op; | |
| 66 { | |
| 67 if (!is_funcobject(op)) { | |
| 27 | 68 err_badcall(); |
| 6 | 69 return NULL; |
| 70 } | |
| 71 return ((funcobject *) op) -> func_globals; | |
| 72 } | |
| 73 | |
| 74 /* Methods */ | |
| 75 | |
| 86 | 76 #define OFF(x) offsetof(funcobject, x) |
| 77 | |
| 78 static struct memberlist func_memberlist[] = { | |
|
588
7d24de643fb5
Added READONLY specifier to data members.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
79 {"func_code", T_OBJECT, OFF(func_code), READONLY}, |
|
7d24de643fb5
Added READONLY specifier to data members.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
80 {"func_globals",T_OBJECT, OFF(func_globals), READONLY}, |
| 86 | 81 {NULL} /* Sentinel */ |
| 82 }; | |
| 83 | |
| 84 static object * | |
| 85 func_getattr(op, name) | |
| 86 funcobject *op; | |
| 87 char *name; | |
| 88 { | |
| 89 return getmember((char *)op, func_memberlist, name); | |
| 90 } | |
| 91 | |
| 6 | 92 static void |
| 86 | 93 func_dealloc(op) |
| 6 | 94 funcobject *op; |
| 95 { | |
|
84
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
96 DECREF(op->func_code); |
| 6 | 97 DECREF(op->func_globals); |
|
84
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
98 DEL(op); |
| 6 | 99 } |
| 100 | |
| 101 typeobject Functype = { | |
| 102 OB_HEAD_INIT(&Typetype) | |
| 103 0, | |
| 104 "function", | |
| 105 sizeof(funcobject), | |
| 106 0, | |
| 86 | 107 func_dealloc, /*tp_dealloc*/ |
|
84
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
108 0, /*tp_print*/ |
| 86 | 109 func_getattr, /*tp_getattr*/ |
| 6 | 110 0, /*tp_setattr*/ |
| 111 0, /*tp_compare*/ | |
|
84
a79cbb2655ba
Function objects no longer contain a parse tree node, but intermediate
Guido van Rossum <guido@python.org>
parents:
27
diff
changeset
|
112 0, /*tp_repr*/ |
| 6 | 113 }; |
